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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
735 | A | Ostap and Grasshopper | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect. | The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once. | If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). | [
"5 2\n#G#T#\n",
"6 1\nT....G\n",
"7 3\nT..#..G\n",
"6 2\n..GT..\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | 500 | [
{
"input": "5 2\n#G#T#",
"output": "YES"
},
{
"input": "6 1\nT....G",
"output": "YES"
},
{
"input": "7 3\nT..#..G",
"output": "NO"
},
{
"input": "6 2\n..GT..",
"output": "NO"
},
{
"input": "2 1\nGT",
"output": "YES"
},
{
"input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####",
"output": "YES"
},
{
"input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####",
"output": "NO"
},
{
"input": "2 1\nTG",
"output": "YES"
},
{
"input": "99 1\n...T.............................................................................................G.",
"output": "YES"
},
{
"input": "100 2\nG............#.....#...........#....#...........##............#............#......................T.",
"output": "NO"
},
{
"input": "100 1\n#.#.#.##..#..##.#....##.##.##.#....####..##.#.##..GT..##...###.#.##.#..#..##.###..#.####..#.#.##..##",
"output": "YES"
},
{
"input": "100 2\n..#####.#.#.......#.#.#...##..####..###..#.#######GT####.#.#...##...##.#..###....##.#.#..#.###....#.",
"output": "NO"
},
{
"input": "100 3\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 3\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 3\nG..................................#......#......#.......#.#..........#........#......#..........#.T",
"output": "NO"
},
{
"input": "100 3\nG..............#..........#...#..............#.#.....................#......#........#.........#...T",
"output": "NO"
},
{
"input": "100 3\nG##################################################################################################T",
"output": "NO"
},
{
"input": "100 33\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 33\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 33\nG.........#........#..........#..............#.................#............................#.#....T",
"output": "YES"
},
{
"input": "100 33\nG.......#..................#..............................#............................#..........T.",
"output": "NO"
},
{
"input": "100 33\nG#..........##...#.#.....................#.#.#.........##..#...........#....#...........##...#..###T",
"output": "YES"
},
{
"input": "100 33\nG..#.#..#..####......#......##...##...#.##........#...#...#.##....###..#...###..##.#.....#......#.T.",
"output": "NO"
},
{
"input": "100 33\nG#....#..#..##.##..#.##.#......#.#.##..##.#.#.##.##....#.#.....####..##...#....##..##..........#...T",
"output": "NO"
},
{
"input": "100 33\nG#######.#..##.##.#...#..#.###.#.##.##.#..#.###..####.##.#.##....####...##..####.#..##.##.##.#....#T",
"output": "NO"
},
{
"input": "100 33\nG#####.#.##.###########.##..##..#######..########..###.###..#.####.######.############..####..#####T",
"output": "NO"
},
{
"input": "100 99\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 99\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 99\nT.#...............................#............#..............................##...................G",
"output": "YES"
},
{
"input": "100 99\nT..#....#.##...##########.#.#.#.#...####..#.....#..##..#######.######..#.....###..###...#.......#.#G",
"output": "YES"
},
{
"input": "100 99\nG##################################################################################################T",
"output": "YES"
},
{
"input": "100 9\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 9\nT.................................................................................................G.",
"output": "NO"
},
{
"input": "100 9\nT................................................................................................G..",
"output": "NO"
},
{
"input": "100 1\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 1\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 1\n##########G.........T###############################################################################",
"output": "YES"
},
{
"input": "100 1\n#################################################################################################G.T",
"output": "YES"
},
{
"input": "100 17\n##########G################.################.################.################T#####################",
"output": "YES"
},
{
"input": "100 17\n####.#..#.G######.#########.##..##########.#.################.################T######.####.#########",
"output": "YES"
},
{
"input": "100 17\n.########.G##.####.#.######.###############..#.###########.##.#####.##.#####.#T.###..###.########.##",
"output": "YES"
},
{
"input": "100 1\nG.............................................#....................................................T",
"output": "NO"
},
{
"input": "100 1\nT.#................................................................................................G",
"output": "NO"
},
{
"input": "100 1\n##########G....#....T###############################################################################",
"output": "NO"
},
{
"input": "100 1\n#################################################################################################G#T",
"output": "NO"
},
{
"input": "100 17\nG################.#################################.################T###############################",
"output": "NO"
},
{
"input": "100 17\nG################.###############..###.######.#######.###.#######.##T######################.###.####",
"output": "NO"
},
{
"input": "100 17\nG####.##.##.#####.####....##.####.#########.##.#..#.###############.T############.#########.#.####.#",
"output": "NO"
},
{
"input": "48 1\nT..............................................G",
"output": "YES"
},
{
"input": "23 1\nT.....................G",
"output": "YES"
},
{
"input": "49 1\nG...............................................T",
"output": "YES"
},
{
"input": "3 1\nTG#",
"output": "YES"
},
{
"input": "6 2\n..TG..",
"output": "NO"
},
{
"input": "14 3\n...G.....#..T.",
"output": "NO"
},
{
"input": "5 4\n##GT#",
"output": "NO"
},
{
"input": "6 2\nT#..G.",
"output": "YES"
},
{
"input": "5 2\nT.G.#",
"output": "YES"
},
{
"input": "6 1\nT...G#",
"output": "YES"
},
{
"input": "5 1\nTG###",
"output": "YES"
},
{
"input": "5 4\n.G..T",
"output": "NO"
},
{
"input": "7 2\nT#...#G",
"output": "YES"
},
{
"input": "7 1\n##TG###",
"output": "YES"
},
{
"input": "7 1\n###GT##",
"output": "YES"
},
{
"input": "5 2\nG..T.",
"output": "NO"
},
{
"input": "5 1\nG.T##",
"output": "YES"
},
{
"input": "6 2\nG.T###",
"output": "YES"
},
{
"input": "6 2\nG#T###",
"output": "YES"
},
{
"input": "10 2\n####T..G..",
"output": "NO"
},
{
"input": "3 1\nGT#",
"output": "YES"
},
{
"input": "4 1\nTG##",
"output": "YES"
},
{
"input": "6 1\n.G..T.",
"output": "YES"
},
{
"input": "10 3\n......G..T",
"output": "YES"
},
{
"input": "3 2\nG.T",
"output": "YES"
},
{
"input": "4 1\n#G.T",
"output": "YES"
},
{
"input": "5 2\nT#G##",
"output": "YES"
},
{
"input": "4 2\nG#.T",
"output": "NO"
},
{
"input": "4 1\nGT##",
"output": "YES"
}
] | 1,549,503,676 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 11 | 93 | 0 | box_len, hop_len = [int(x) for x in input().split()]
cells = input()
grasshopper = target = -1
# find G and T positions
for idx in range(box_len):
if cells[idx] == "G":
grasshopper = idx
elif cells[idx] == "T":
target = idx
# find hop direction
if target < grasshopper:
hop_len *= -1 # move left (towards 0)
# see if G can reach T
reached = False
for idx in range(grasshopper, target, hop_len):
if cells[idx + hop_len] == "T":
reached = True
break
elif cells[idx + hop_len] == "#":
break
if reached:
print("YES")
else:
print("NO") # jumped past target, can't reach | Title: Ostap and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input Specification:
The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output Specification:
If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Demo Input:
['5 2\n#G#T#\n', '6 1\nT....G\n', '7 3\nT..#..G\n', '6 2\n..GT..\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'NO\n']
Note:
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | ```python
box_len, hop_len = [int(x) for x in input().split()]
cells = input()
grasshopper = target = -1
# find G and T positions
for idx in range(box_len):
if cells[idx] == "G":
grasshopper = idx
elif cells[idx] == "T":
target = idx
# find hop direction
if target < grasshopper:
hop_len *= -1 # move left (towards 0)
# see if G can reach T
reached = False
for idx in range(grasshopper, target, hop_len):
if cells[idx + hop_len] == "T":
reached = True
break
elif cells[idx + hop_len] == "#":
break
if reached:
print("YES")
else:
print("NO") # jumped past target, can't reach
``` | -1 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,594,685,155 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 278 | 20,172,800 | x , y= map(int,input().split())
if (6-max(x,y)+1) %2 ==0:
print(str(int((6-max(x,y)+1)/2))+'/'+str(int(6/2)))
elif (6-max(x,y)+1)%3 ==0:
print('1/2')
elif x == y:
print('1/1')
else:
print(str((6-max(x,y)+1))+'/'+'6') | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
x , y= map(int,input().split())
if (6-max(x,y)+1) %2 ==0:
print(str(int((6-max(x,y)+1)/2))+'/'+str(int(6/2)))
elif (6-max(x,y)+1)%3 ==0:
print('1/2')
elif x == y:
print('1/1')
else:
print(str((6-max(x,y)+1))+'/'+'6')
``` | 0 |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39 75",
"output": "48.142857142857"
},
{
"input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22",
"output": "11.615384615385"
},
{
"input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18",
"output": "12.761904761905"
},
{
"input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84",
"output": "69.538461538462"
},
{
"input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94",
"output": "91.551724137931"
},
{
"input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100",
"output": "99.515151515152"
},
{
"input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2",
"output": "8.147058823529"
},
{
"input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93",
"output": "91.921052631579"
},
{
"input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100",
"output": "97.019230769231"
},
{
"input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6",
"output": "50.965517241379"
},
{
"input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10",
"output": "7.505882352941"
},
{
"input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6",
"output": "10.418918918919"
},
{
"input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41",
"output": "20.928571428571"
},
{
"input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96",
"output": "49.191919191919"
},
{
"input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92",
"output": "73.484848484848"
},
{
"input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6",
"output": "7.640000000000"
},
{
"input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100",
"output": "77.660000000000"
},
{
"input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81",
"output": "91.480000000000"
},
{
"input": "1\n0",
"output": "0.000000000000"
},
{
"input": "1\n100",
"output": "100.000000000000"
},
{
"input": "1\n78",
"output": "78.000000000000"
},
{
"input": "2\n0 100",
"output": "50.000000000000"
},
{
"input": "2\n100 100",
"output": "100.000000000000"
},
{
"input": "5\n0 0 0 0 1",
"output": "0.200000000000"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99",
"output": "99.990000000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "0.010000000000"
},
{
"input": "5\n100 100 100 100 100",
"output": "100.000000000000"
}
] | 1,683,999,591 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 124 | 0 | n = int(input())
p = list(map(int,input().split(maxsplit = n)))
c = 0
for i in range(n):
c += p[i]
print(c/n) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Output Specification:
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
Demo Input:
['3\n50 50 100\n', '4\n0 25 50 75\n']
Demo Output:
['66.666666666667\n', '37.500000000000\n']
Note:
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | ```python
n = int(input())
p = list(map(int,input().split(maxsplit = n)))
c = 0
for i in range(n):
c += p[i]
print(c/n)
``` | 3 |
|
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input": "5\n5 4 3 2 1",
"output": "5 4 3 2 1"
},
{
"input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19"
},
{
"input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19",
"output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19"
},
{
"input": "10\n3 4 5 6 7 8 9 10 1 2",
"output": "9 10 1 2 3 4 5 6 7 8"
},
{
"input": "8\n1 5 3 7 2 6 4 8",
"output": "1 5 3 7 2 6 4 8"
},
{
"input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47",
"output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19"
},
{
"input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17",
"output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25"
},
{
"input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85",
"output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30"
},
{
"input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49",
"output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49"
},
{
"input": "12\n3 8 7 4 6 5 2 1 11 9 10 12",
"output": "8 7 1 4 6 5 3 2 10 11 9 12"
},
{
"input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76",
"output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4"
},
{
"input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43",
"output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1"
},
{
"input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27",
"output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3"
},
{
"input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22",
"output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53"
},
{
"input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13",
"output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24"
},
{
"input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21",
"output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61"
},
{
"input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33",
"output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14"
},
{
"input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23",
"output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21"
},
{
"input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12",
"output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9"
},
{
"input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31",
"output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13"
},
{
"input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3",
"output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16"
},
{
"input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8",
"output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6"
},
{
"input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71",
"output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90"
},
{
"input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9",
"output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9"
},
{
"input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44",
"output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20"
},
{
"input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17",
"output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28"
},
{
"input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7",
"output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5"
},
{
"input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16",
"output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43"
},
{
"input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65",
"output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43"
},
{
"input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16",
"output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45"
},
{
"input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51",
"output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64"
},
{
"input": "12\n12 3 1 5 11 6 7 10 2 8 9 4",
"output": "3 9 2 12 4 6 7 10 11 8 5 1"
},
{
"input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17",
"output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44"
},
{
"input": "8\n1 3 5 2 4 8 6 7",
"output": "1 4 2 5 3 7 8 6"
},
{
"input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14",
"output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12"
},
{
"input": "10\n2 9 4 6 10 1 7 5 3 8",
"output": "6 1 9 3 8 4 7 10 2 5"
},
{
"input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3",
"output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7"
},
{
"input": "10\n2 4 9 3 6 8 10 5 1 7",
"output": "9 1 4 2 8 5 10 6 3 7"
},
{
"input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15",
"output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23"
},
{
"input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1",
"output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27"
},
{
"input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30",
"output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23"
},
{
"input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52",
"output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50"
},
{
"input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18",
"output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98"
},
{
"input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16",
"output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25"
},
{
"input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37",
"output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54"
},
{
"input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71",
"output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71"
},
{
"input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22",
"output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8"
},
{
"input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12",
"output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51"
},
{
"input": "7\n2 1 5 7 3 4 6",
"output": "2 1 5 6 3 7 4"
},
{
"input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35",
"output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31"
},
{
"input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16",
"output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21"
},
{
"input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52",
"output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11"
},
{
"input": "9\n8 5 2 6 1 9 4 7 3",
"output": "5 3 9 7 2 4 8 1 6"
},
{
"input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27",
"output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13"
},
{
"input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34",
"output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6"
},
{
"input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29",
"output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14"
},
{
"input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7",
"output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16"
},
{
"input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34",
"output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24"
},
{
"input": "9\n4 8 6 5 3 9 2 7 1",
"output": "9 7 5 1 4 3 8 2 6"
},
{
"input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29",
"output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32"
},
{
"input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47",
"output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11"
},
{
"input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6",
"output": "10 4 1 8 6 13 12 5 3 11 9 2 7"
},
{
"input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29",
"output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37"
},
{
"input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3",
"output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25"
},
{
"input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20",
"output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24"
},
{
"input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42",
"output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59"
},
{
"input": "6\n4 3 6 5 1 2",
"output": "5 6 2 1 4 3"
},
{
"input": "9\n7 8 5 3 1 4 2 9 6",
"output": "5 7 4 6 3 9 1 2 8"
},
{
"input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37",
"output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11",
"output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13"
},
{
"input": "2\n2 1",
"output": "2 1"
},
{
"input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28",
"output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18"
},
{
"input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13",
"output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1"
},
{
"input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14",
"output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36"
},
{
"input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29",
"output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32"
},
{
"input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5",
"output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40"
},
{
"input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54",
"output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21"
},
{
"input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29",
"output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4"
},
{
"input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23",
"output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50"
},
{
"input": "10\n2 10 7 4 1 5 8 6 3 9",
"output": "5 1 9 4 6 8 3 7 10 2"
},
{
"input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13",
"output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1"
},
{
"input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2",
"output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11"
},
{
"input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53",
"output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37"
},
{
"input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53",
"output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53"
},
{
"input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64",
"output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49"
},
{
"input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86",
"output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38"
},
{
"input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75",
"output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2"
},
{
"input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53",
"output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5"
},
{
"input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39",
"output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12"
},
{
"input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87",
"output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82"
},
{
"input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25",
"output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97"
},
{
"input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61",
"output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96"
},
{
"input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92",
"output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96"
},
{
"input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6",
"output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 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": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 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"
}
] | 1,690,218,886 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | k=int(input())
t=list(map(int,input().split()))
p=[0]*k
for i in range(k):
p[t[i]-1]=i+1
print(' '.join(map(str,p))) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Output Specification:
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
Demo Input:
['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['4 1 2 3\n', '1 3 2\n', '1 2\n']
Note:
none | ```python
k=int(input())
t=list(map(int,input().split()))
p=[0]*k
for i in range(k):
p[t[i]-1]=i+1
print(' '.join(map(str,p)))
``` | 3 |
|
526 | B | Om Nom and Dark Park | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"implementation"
] | null | null | Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so that the scheme of the park is a full binary tree of depth *n*. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2*n*,<=2*n*<=+<=1,<=...,<=2*n*<=+<=1<=-<=1 and these exits lead straight to the Om Nom friends' houses. From each square *i* (2<=≤<=*i*<=<<=2*n*<=+<=1) there is a road to the square . Thus, it is possible to go from the park entrance to each of the exits by walking along exactly *n* roads.
Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.
He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads. | The first line contains integer *n* (1<=≤<=*n*<=≤<=10) — the number of roads on the path from the entrance to any exit.
The next line contains 2*n*<=+<=1<=-<=2 numbers *a*2,<=*a*3,<=... *a*2*n*<=+<=1<=-<=1 — the initial numbers of street lights on each road of the park. Here *a**i* is the number of street lights on the road between squares *i* and . All numbers *a**i* are positive integers, not exceeding 100. | Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe. | [
"2\n1 2 3 4 5 6\n"
] | [
"5\n"
] | Picture for the sample test. Green color denotes the additional street lights. | 500 | [
{
"input": "2\n1 2 3 4 5 6",
"output": "5"
},
{
"input": "2\n1 2 3 3 2 2",
"output": "0"
},
{
"input": "1\n39 52",
"output": "13"
},
{
"input": "2\n59 96 34 48 8 72",
"output": "139"
},
{
"input": "3\n87 37 91 29 58 45 51 74 70 71 47 38 91 89",
"output": "210"
},
{
"input": "5\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82 91 20 64 52 70 6 88 53 47 30 47 34 14 11 22 42 15 28 54 37 48 29 3 14 13 18 77 90 58 54 38 94 49 45 66 13 74 11 14 64 72 95 54 73 79 41 35",
"output": "974"
},
{
"input": "1\n49 36",
"output": "13"
},
{
"input": "1\n77 88",
"output": "11"
},
{
"input": "1\n1 33",
"output": "32"
},
{
"input": "2\n72 22 81 23 14 75",
"output": "175"
},
{
"input": "2\n100 70 27 1 68 52",
"output": "53"
},
{
"input": "2\n24 19 89 82 22 21",
"output": "80"
},
{
"input": "3\n86 12 92 91 3 68 57 56 76 27 33 62 71 84",
"output": "286"
},
{
"input": "3\n14 56 53 61 57 45 40 44 31 9 73 2 61 26",
"output": "236"
},
{
"input": "3\n35 96 7 43 10 14 16 36 95 92 16 50 59 55",
"output": "173"
},
{
"input": "4\n1 97 18 48 96 65 24 91 17 45 36 27 74 93 78 86 39 55 53 21 26 68 31 33 79 63 80 92 1 26",
"output": "511"
},
{
"input": "4\n25 42 71 29 50 30 99 79 77 24 76 66 68 23 97 99 65 17 75 62 66 46 48 4 40 71 98 57 21 92",
"output": "603"
},
{
"input": "4\n49 86 17 7 3 6 86 71 36 10 27 10 58 64 12 16 88 67 93 3 15 20 58 87 97 91 11 6 34 62",
"output": "470"
},
{
"input": "5\n16 87 36 16 81 53 87 35 63 56 47 91 81 95 80 96 91 7 58 99 25 28 47 60 7 69 49 14 51 52 29 30 83 23 21 52 100 26 91 14 23 94 72 70 40 12 50 32 54 52 18 74 5 15 62 3 48 41 24 25 56 43",
"output": "1060"
},
{
"input": "5\n40 27 82 94 38 22 66 23 18 34 87 31 71 28 95 5 14 61 76 52 66 6 60 40 68 77 70 63 64 18 47 13 82 55 34 64 30 1 29 24 24 9 65 17 29 96 61 76 72 23 32 26 90 39 54 41 35 66 71 29 75 48",
"output": "1063"
},
{
"input": "5\n64 72 35 68 92 95 45 15 77 16 26 74 61 65 18 22 32 19 98 97 14 84 70 23 29 1 87 28 88 89 73 79 69 88 43 60 64 64 66 39 17 27 46 71 18 83 73 20 90 77 49 70 84 63 50 72 26 87 26 37 78 65",
"output": "987"
},
{
"input": "6\n35 61 54 77 70 50 53 70 4 66 58 47 76 100 78 5 43 50 55 93 13 93 59 92 30 74 22 23 98 70 19 56 90 92 19 7 28 53 45 77 42 91 71 56 19 83 100 53 13 93 37 13 70 60 16 13 76 3 12 22 17 26 50 6 63 7 25 41 92 29 36 80 11 4 10 14 77 75 53 82 46 24 56 46 82 36 80 75 8 45 24 22 90 34 45 76 18 38 86 43 7 49 80 56 90 53 12 51 98 47 44 58 32 4 2 6 3 60 38 72 74 46 30 86 1 98",
"output": "2499"
},
{
"input": "6\n63 13 100 54 31 15 29 58 59 44 2 99 70 33 97 14 70 12 73 42 65 71 68 67 87 83 43 84 18 41 37 22 81 24 27 11 57 28 83 92 39 1 56 15 16 67 16 97 31 52 50 65 63 89 8 52 55 20 71 27 28 35 86 92 94 60 10 65 83 63 89 71 34 20 78 40 34 62 2 86 100 81 87 69 25 4 52 17 57 71 62 38 1 3 54 71 34 85 20 60 80 23 82 47 4 19 7 18 14 18 28 27 4 55 26 71 45 9 2 40 67 28 32 19 81 92",
"output": "2465"
},
{
"input": "6\n87 62 58 32 81 92 12 50 23 27 38 39 64 74 16 35 84 59 91 87 14 48 90 47 44 95 64 45 31 11 67 5 80 60 36 15 91 3 21 2 40 24 37 69 5 50 23 37 49 19 68 21 49 9 100 94 45 41 22 31 31 48 25 70 25 25 95 88 82 1 37 53 49 31 57 74 94 45 55 93 43 37 13 85 59 72 15 68 3 90 96 55 100 64 63 69 43 33 66 84 57 97 87 34 23 89 97 77 39 89 8 92 68 13 50 36 95 61 71 96 73 13 30 49 57 89",
"output": "2513"
}
] | 1,684,464,712 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 77 | 3,481,600 | n=int(input())
a=[0,0]+list(map(int,input().split()))
# print(a)
ans=0
def dfs(i,d):
global ans
if d==n+1: return 0
# print(i,d)
left=dfs(2*i,d+1)
right=dfs(2*i+1,d+1)
ans+=abs(left-right)
return max(left,right)+a[i]
dfs(1,0)
print(ans) | Title: Om Nom and Dark Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so that the scheme of the park is a full binary tree of depth *n*. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2*n*,<=2*n*<=+<=1,<=...,<=2*n*<=+<=1<=-<=1 and these exits lead straight to the Om Nom friends' houses. From each square *i* (2<=≤<=*i*<=<<=2*n*<=+<=1) there is a road to the square . Thus, it is possible to go from the park entrance to each of the exits by walking along exactly *n* roads.
Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.
He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=10) — the number of roads on the path from the entrance to any exit.
The next line contains 2*n*<=+<=1<=-<=2 numbers *a*2,<=*a*3,<=... *a*2*n*<=+<=1<=-<=1 — the initial numbers of street lights on each road of the park. Here *a**i* is the number of street lights on the road between squares *i* and . All numbers *a**i* are positive integers, not exceeding 100.
Output Specification:
Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.
Demo Input:
['2\n1 2 3 4 5 6\n']
Demo Output:
['5\n']
Note:
Picture for the sample test. Green color denotes the additional street lights. | ```python
n=int(input())
a=[0,0]+list(map(int,input().split()))
# print(a)
ans=0
def dfs(i,d):
global ans
if d==n+1: return 0
# print(i,d)
left=dfs(2*i,d+1)
right=dfs(2*i+1,d+1)
ans+=abs(left-right)
return max(left,right)+a[i]
dfs(1,0)
print(ans)
``` | 3 |
|
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him. | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length. | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 5 6 11",
"output": "TRIANGLE"
},
{
"input": "1 1 1 1",
"output": "TRIANGLE"
},
{
"input": "10 20 30 40",
"output": "TRIANGLE"
},
{
"input": "45 25 5 15",
"output": "IMPOSSIBLE"
},
{
"input": "20 5 8 13",
"output": "TRIANGLE"
},
{
"input": "10 30 7 20",
"output": "SEGMENT"
},
{
"input": "3 2 3 2",
"output": "TRIANGLE"
},
{
"input": "70 10 100 30",
"output": "SEGMENT"
},
{
"input": "4 8 16 2",
"output": "IMPOSSIBLE"
},
{
"input": "3 3 3 10",
"output": "TRIANGLE"
},
{
"input": "1 5 5 5",
"output": "TRIANGLE"
},
{
"input": "13 25 12 1",
"output": "SEGMENT"
},
{
"input": "10 100 7 3",
"output": "SEGMENT"
},
{
"input": "50 1 50 100",
"output": "TRIANGLE"
},
{
"input": "50 1 100 49",
"output": "SEGMENT"
},
{
"input": "49 51 100 1",
"output": "SEGMENT"
},
{
"input": "5 11 2 25",
"output": "IMPOSSIBLE"
},
{
"input": "91 50 9 40",
"output": "IMPOSSIBLE"
},
{
"input": "27 53 7 97",
"output": "IMPOSSIBLE"
},
{
"input": "51 90 24 8",
"output": "IMPOSSIBLE"
},
{
"input": "3 5 1 1",
"output": "IMPOSSIBLE"
},
{
"input": "13 49 69 15",
"output": "IMPOSSIBLE"
},
{
"input": "16 99 9 35",
"output": "IMPOSSIBLE"
},
{
"input": "27 6 18 53",
"output": "IMPOSSIBLE"
},
{
"input": "57 88 17 8",
"output": "IMPOSSIBLE"
},
{
"input": "95 20 21 43",
"output": "IMPOSSIBLE"
},
{
"input": "6 19 32 61",
"output": "IMPOSSIBLE"
},
{
"input": "100 21 30 65",
"output": "IMPOSSIBLE"
},
{
"input": "85 16 61 9",
"output": "IMPOSSIBLE"
},
{
"input": "5 6 19 82",
"output": "IMPOSSIBLE"
},
{
"input": "1 5 1 3",
"output": "IMPOSSIBLE"
},
{
"input": "65 10 36 17",
"output": "IMPOSSIBLE"
},
{
"input": "81 64 9 7",
"output": "IMPOSSIBLE"
},
{
"input": "11 30 79 43",
"output": "IMPOSSIBLE"
},
{
"input": "1 1 5 3",
"output": "IMPOSSIBLE"
},
{
"input": "21 94 61 31",
"output": "IMPOSSIBLE"
},
{
"input": "49 24 9 74",
"output": "IMPOSSIBLE"
},
{
"input": "11 19 5 77",
"output": "IMPOSSIBLE"
},
{
"input": "52 10 19 71",
"output": "SEGMENT"
},
{
"input": "2 3 7 10",
"output": "SEGMENT"
},
{
"input": "1 2 6 3",
"output": "SEGMENT"
},
{
"input": "2 6 1 8",
"output": "SEGMENT"
},
{
"input": "1 2 4 1",
"output": "SEGMENT"
},
{
"input": "4 10 6 2",
"output": "SEGMENT"
},
{
"input": "2 10 7 3",
"output": "SEGMENT"
},
{
"input": "5 2 3 9",
"output": "SEGMENT"
},
{
"input": "6 1 4 10",
"output": "SEGMENT"
},
{
"input": "10 6 4 1",
"output": "SEGMENT"
},
{
"input": "3 2 9 1",
"output": "SEGMENT"
},
{
"input": "22 80 29 7",
"output": "SEGMENT"
},
{
"input": "2 6 3 9",
"output": "SEGMENT"
},
{
"input": "3 1 2 1",
"output": "SEGMENT"
},
{
"input": "3 4 7 1",
"output": "SEGMENT"
},
{
"input": "8 4 3 1",
"output": "SEGMENT"
},
{
"input": "2 8 3 5",
"output": "SEGMENT"
},
{
"input": "4 1 2 1",
"output": "SEGMENT"
},
{
"input": "8 1 3 2",
"output": "SEGMENT"
},
{
"input": "6 2 1 8",
"output": "SEGMENT"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "3 6 3 3",
"output": "TRIANGLE"
},
{
"input": "4 10 4 4",
"output": "TRIANGLE"
},
{
"input": "1 1 2 1",
"output": "TRIANGLE"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "5 4 5 5",
"output": "TRIANGLE"
},
{
"input": "8 7 8 8",
"output": "TRIANGLE"
},
{
"input": "3 3 3 1",
"output": "TRIANGLE"
},
{
"input": "1 1 6 6",
"output": "TRIANGLE"
},
{
"input": "1 9 1 9",
"output": "TRIANGLE"
},
{
"input": "7 2 2 7",
"output": "TRIANGLE"
},
{
"input": "7 2 3 2",
"output": "TRIANGLE"
},
{
"input": "4 4 10 10",
"output": "TRIANGLE"
},
{
"input": "7 7 10 7",
"output": "TRIANGLE"
},
{
"input": "4 4 4 5",
"output": "TRIANGLE"
},
{
"input": "1 10 9 2",
"output": "TRIANGLE"
},
{
"input": "1 8 2 7",
"output": "TRIANGLE"
},
{
"input": "4 3 2 8",
"output": "TRIANGLE"
},
{
"input": "5 9 5 3",
"output": "TRIANGLE"
},
{
"input": "4 10 3 5",
"output": "TRIANGLE"
}
] | 1,613,769,956 | 2,147,483,647 | PyPy 3 | OK | TESTS | 83 | 186 | 0 | '''
Jana Goodman6
6a construct triangle from 4 stick
'''
SPACE = ' '
TRI = 'TRIANGLE'
SEG = 'SEGMENT'
IMP = 'IMPOSSIBLE'
def case(a, b, c):
# good: long side < sum(2 shortest)
# SEGMENT: long side = sum(2 shortest)
if c < a + b:
return TRI
if c == a + b:
return SEG
return IMP
def construct(sides):
sides.sort()
a, b, c, d = sides
cases = [case(a, b, c), case(a, b, d), case(b, c, d)]
if TRI in cases:
return TRI
if SEG in cases:
return SEG
return IMP
if __name__ == '__main__':
print(construct(list(map(int, input().split(SPACE)))))
| Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input Specification:
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output Specification:
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Demo Input:
['4 2 1 3\n', '7 2 2 4\n', '3 5 9 1\n']
Demo Output:
['TRIANGLE\n', 'SEGMENT\n', 'IMPOSSIBLE\n']
Note:
none | ```python
'''
Jana Goodman6
6a construct triangle from 4 stick
'''
SPACE = ' '
TRI = 'TRIANGLE'
SEG = 'SEGMENT'
IMP = 'IMPOSSIBLE'
def case(a, b, c):
# good: long side < sum(2 shortest)
# SEGMENT: long side = sum(2 shortest)
if c < a + b:
return TRI
if c == a + b:
return SEG
return IMP
def construct(sides):
sides.sort()
a, b, c, d = sides
cases = [case(a, b, c), case(a, b, d), case(b, c, d)]
if TRI in cases:
return TRI
if SEG in cases:
return SEG
return IMP
if __name__ == '__main__':
print(construct(list(map(int, input().split(SPACE)))))
``` | 3.9535 |
909 | B | Segments | PROGRAMMING | 1,300 | [
"constructive algorithms",
"math"
] | null | null | You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.
Find the minimal number of layers you have to use for the given *N*. | The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100). | Output a single integer - the minimal number of layers required to draw the segments for the given *N*. | [
"2\n",
"3\n",
"4\n"
] | [
"2\n",
"4\n",
"6\n"
] | As an example, here are the segments and their optimal arrangement into layers for *N* = 4. | 1,000 | [
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "4"
},
{
"input": "4",
"output": "6"
},
{
"input": "21",
"output": "121"
},
{
"input": "100",
"output": "2550"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "9"
},
{
"input": "6",
"output": "12"
},
{
"input": "7",
"output": "16"
},
{
"input": "8",
"output": "20"
},
{
"input": "9",
"output": "25"
},
{
"input": "10",
"output": "30"
},
{
"input": "11",
"output": "36"
},
{
"input": "12",
"output": "42"
},
{
"input": "13",
"output": "49"
},
{
"input": "14",
"output": "56"
},
{
"input": "15",
"output": "64"
},
{
"input": "16",
"output": "72"
},
{
"input": "17",
"output": "81"
},
{
"input": "18",
"output": "90"
},
{
"input": "19",
"output": "100"
},
{
"input": "20",
"output": "110"
},
{
"input": "22",
"output": "132"
},
{
"input": "23",
"output": "144"
},
{
"input": "24",
"output": "156"
},
{
"input": "25",
"output": "169"
},
{
"input": "26",
"output": "182"
},
{
"input": "27",
"output": "196"
},
{
"input": "28",
"output": "210"
},
{
"input": "29",
"output": "225"
},
{
"input": "30",
"output": "240"
},
{
"input": "31",
"output": "256"
},
{
"input": "32",
"output": "272"
},
{
"input": "33",
"output": "289"
},
{
"input": "34",
"output": "306"
},
{
"input": "35",
"output": "324"
},
{
"input": "36",
"output": "342"
},
{
"input": "37",
"output": "361"
},
{
"input": "38",
"output": "380"
},
{
"input": "39",
"output": "400"
},
{
"input": "40",
"output": "420"
},
{
"input": "41",
"output": "441"
},
{
"input": "42",
"output": "462"
},
{
"input": "43",
"output": "484"
},
{
"input": "44",
"output": "506"
},
{
"input": "45",
"output": "529"
},
{
"input": "46",
"output": "552"
},
{
"input": "47",
"output": "576"
},
{
"input": "48",
"output": "600"
},
{
"input": "49",
"output": "625"
},
{
"input": "50",
"output": "650"
},
{
"input": "51",
"output": "676"
},
{
"input": "52",
"output": "702"
},
{
"input": "53",
"output": "729"
},
{
"input": "54",
"output": "756"
},
{
"input": "55",
"output": "784"
},
{
"input": "56",
"output": "812"
},
{
"input": "57",
"output": "841"
},
{
"input": "58",
"output": "870"
},
{
"input": "59",
"output": "900"
},
{
"input": "60",
"output": "930"
},
{
"input": "61",
"output": "961"
},
{
"input": "62",
"output": "992"
},
{
"input": "63",
"output": "1024"
},
{
"input": "64",
"output": "1056"
},
{
"input": "65",
"output": "1089"
},
{
"input": "66",
"output": "1122"
},
{
"input": "67",
"output": "1156"
},
{
"input": "68",
"output": "1190"
},
{
"input": "69",
"output": "1225"
},
{
"input": "70",
"output": "1260"
},
{
"input": "71",
"output": "1296"
},
{
"input": "72",
"output": "1332"
},
{
"input": "73",
"output": "1369"
},
{
"input": "74",
"output": "1406"
},
{
"input": "75",
"output": "1444"
},
{
"input": "76",
"output": "1482"
},
{
"input": "77",
"output": "1521"
},
{
"input": "78",
"output": "1560"
},
{
"input": "79",
"output": "1600"
},
{
"input": "80",
"output": "1640"
},
{
"input": "81",
"output": "1681"
},
{
"input": "82",
"output": "1722"
},
{
"input": "83",
"output": "1764"
},
{
"input": "84",
"output": "1806"
},
{
"input": "85",
"output": "1849"
},
{
"input": "86",
"output": "1892"
},
{
"input": "87",
"output": "1936"
},
{
"input": "88",
"output": "1980"
},
{
"input": "89",
"output": "2025"
},
{
"input": "90",
"output": "2070"
},
{
"input": "91",
"output": "2116"
},
{
"input": "92",
"output": "2162"
},
{
"input": "93",
"output": "2209"
},
{
"input": "94",
"output": "2256"
},
{
"input": "95",
"output": "2304"
},
{
"input": "96",
"output": "2352"
},
{
"input": "97",
"output": "2401"
},
{
"input": "98",
"output": "2450"
},
{
"input": "99",
"output": "2500"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "9"
}
] | 1,514,452,611 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 5,529,600 | n = int(input())
print(round((n/2+1)*n/2))
| Title: Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.
Find the minimal number of layers you have to use for the given *N*.
Input Specification:
The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100).
Output Specification:
Output a single integer - the minimal number of layers required to draw the segments for the given *N*.
Demo Input:
['2\n', '3\n', '4\n']
Demo Output:
['2\n', '4\n', '6\n']
Note:
As an example, here are the segments and their optimal arrangement into layers for *N* = 4. | ```python
n = int(input())
print(round((n/2+1)*n/2))
``` | 3 |
|
610 | C | Harmony Analysis | PROGRAMMING | 1,800 | [
"constructive algorithms"
] | null | null | The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vector is 1 or <=-<=1 and any two vectors are orthogonal. Just as a reminder, two vectors in *n*-dimensional space are considered to be orthogonal if and only if their scalar product is equal to zero, that is:
Danil quickly managed to come up with the solution for this problem and the teacher noticed that the problem can be solved in a more general case for 2*k* vectors in 2*k*-dimensinoal space. When Danil came home, he quickly came up with the solution for this problem. Can you cope with it? | The only line of the input contains a single integer *k* (0<=≤<=*k*<=≤<=9). | Print 2*k* lines consisting of 2*k* characters each. The *j*-th character of the *i*-th line must be equal to '<=*<=' if the *j*-th coordinate of the *i*-th vector is equal to <=-<=1, and must be equal to '<=+<=' if it's equal to <=+<=1. It's guaranteed that the answer always exists.
If there are many correct answers, print any. | [
"2\n"
] | [
"++**\n+*+*\n++++\n+**+"
] | Consider all scalar products in example:
- Vectors 1 and 2: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( + 1) + ( - 1)·( - 1) = 0 - Vectors 1 and 3: ( + 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) + ( - 1)·( + 1) = 0 - Vectors 1 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( - 1) + ( - 1)·( + 1) = 0 - Vectors 2 and 3: ( + 1)·( + 1) + ( - 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) = 0 - Vectors 2 and 4: ( + 1)·( + 1) + ( - 1)·( - 1) + ( + 1)·( - 1) + ( - 1)·( + 1) = 0 - Vectors 3 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( + 1)·( - 1) + ( + 1)·( + 1) = 0 | 1,500 | [
{
"input": "2",
"output": "++++\n+*+*\n++**\n+**+"
},
{
"input": "1",
"output": "++\n+*"
},
{
"input": "3",
"output": "++++++++\n+*+*+*+*\n++**++**\n+**++**+\n++++****\n+*+**+*+\n++****++\n+**+*++*"
},
{
"input": "0",
"output": "+"
},
{
"input": "4",
"output": "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\n++****++++****++\n+**+*++*+**+*++*\n++++++++********\n+*+*+*+**+*+*+*+\n++**++****++**++\n+**++**+*++**++*\n++++********++++\n+*+**+*+*+*++*+*\n++****++**++++**\n+**+*++**++*+**+"
},
{
"input": "5",
"output": "++++++++++++++++++++++++++++++++\n+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*\n++**++**++**++**++**++**++**++**\n+**++**++**++**++**++**++**++**+\n++++****++++****++++****++++****\n+*+**+*++*+**+*++*+**+*++*+**+*+\n++****++++****++++****++++****++\n+**+*++*+**+*++*+**+*++*+**+*++*\n++++++++********++++++++********\n+*+*+*+**+*+*+*++*+*+*+**+*+*+*+\n++**++****++**++++**++****++**++\n+**++**+*++**++*+**++**+*++**++*\n++++********++++++++********++++\n+*+**+*+*+*++*+*+*+**+*+*+*++*+*\n++****++**++++**++****++**++++**\n+..."
},
{
"input": "6",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*\n++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**\n+**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**+\n++++****++++****++++****++++****++++****++++****++++****++++****\n+*+**+*++*+**+*++*+**+*++*+**+*++*+**+*++*+**+*++*+**+*++*+**+*+\n++****++++****++++****++++****++++****++++****++++****++++****++\n+**+*++*+**+*++*+**+*++*+**+*++*+**+*++*+**+*++*+..."
},
{
"input": "7",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*\n++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**\n+**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++..."
},
{
"input": "8",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+..."
},
{
"input": "9",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++..."
}
] | 1,451,584,006 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | k = int(input())
answer = [['+', '+'], ['+', '*']]
length = 2
for i in range(k - 1):
new = []
for i in answer:
temp = []
for j in range(length):
if i[j] == '+':
temp += ['+', '+']
else:
temp += ['*', '*']
new.append(temp)
for i in answer:
temp = []
for j in range(length):
if i[j] == '+':
temp += ['+', '*']
else:
temp += ['*', '+']
new.append(temp)
answer = new
length *= 2
print('\n'.join([''.join(i) for i in answer]))
| Title: Harmony Analysis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vector is 1 or <=-<=1 and any two vectors are orthogonal. Just as a reminder, two vectors in *n*-dimensional space are considered to be orthogonal if and only if their scalar product is equal to zero, that is:
Danil quickly managed to come up with the solution for this problem and the teacher noticed that the problem can be solved in a more general case for 2*k* vectors in 2*k*-dimensinoal space. When Danil came home, he quickly came up with the solution for this problem. Can you cope with it?
Input Specification:
The only line of the input contains a single integer *k* (0<=≤<=*k*<=≤<=9).
Output Specification:
Print 2*k* lines consisting of 2*k* characters each. The *j*-th character of the *i*-th line must be equal to '<=*<=' if the *j*-th coordinate of the *i*-th vector is equal to <=-<=1, and must be equal to '<=+<=' if it's equal to <=+<=1. It's guaranteed that the answer always exists.
If there are many correct answers, print any.
Demo Input:
['2\n']
Demo Output:
['++**\n+*+*\n++++\n+**+']
Note:
Consider all scalar products in example:
- Vectors 1 and 2: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( + 1) + ( - 1)·( - 1) = 0 - Vectors 1 and 3: ( + 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) + ( - 1)·( + 1) = 0 - Vectors 1 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( - 1) + ( - 1)·( + 1) = 0 - Vectors 2 and 3: ( + 1)·( + 1) + ( - 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) = 0 - Vectors 2 and 4: ( + 1)·( + 1) + ( - 1)·( - 1) + ( + 1)·( - 1) + ( - 1)·( + 1) = 0 - Vectors 3 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( + 1)·( - 1) + ( + 1)·( + 1) = 0 | ```python
k = int(input())
answer = [['+', '+'], ['+', '*']]
length = 2
for i in range(k - 1):
new = []
for i in answer:
temp = []
for j in range(length):
if i[j] == '+':
temp += ['+', '+']
else:
temp += ['*', '*']
new.append(temp)
for i in answer:
temp = []
for j in range(length):
if i[j] == '+':
temp += ['+', '*']
else:
temp += ['*', '+']
new.append(temp)
answer = new
length *= 2
print('\n'.join([''.join(i) for i in answer]))
``` | 0 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,650,399,759 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 92 | 0 | i = int(input())
res = []
while i > 0:
x = [int(i) for i in input().split()]
res.extend(x)
i-=1
if sum(res) == 0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
i = int(input())
res = []
while i > 0:
x = [int(i) for i in input().split()]
res.extend(x)
i-=1
if sum(res) == 0:
print("YES")
else:
print("NO")
``` | 0 |
1,009 | B | Minimum Ternary String | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
- "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201".
Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. | The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). | Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). | [
"100210\n",
"11222121\n",
"20\n"
] | [
"001120\n",
"11112222\n",
"20\n"
] | none | 0 | [
{
"input": "100210",
"output": "001120"
},
{
"input": "11222121",
"output": "11112222"
},
{
"input": "20",
"output": "20"
},
{
"input": "1002",
"output": "0012"
},
{
"input": "10",
"output": "01"
},
{
"input": "000021",
"output": "000012"
},
{
"input": "021",
"output": "012"
},
{
"input": "2",
"output": "2"
},
{
"input": "201",
"output": "120"
},
{
"input": "2112120",
"output": "1112220"
},
{
"input": "102",
"output": "012"
},
{
"input": "202",
"output": "202"
},
{
"input": "220201",
"output": "122020"
},
{
"input": "12",
"output": "12"
},
{
"input": "100022202",
"output": "000122202"
},
{
"input": "01",
"output": "01"
},
{
"input": "1",
"output": "1"
}
] | 1,564,988,946 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 1,843,200 | from collections import Counter
def main():
s = [c for c in input().strip()]
n = len(s)
start = 0
cnt = Counter()
found2 = False
for i in range(n):
cnt[s[i]] += 1
if s[i] == '2':
found2 = True
if s[i] == '0' and found2:
cnt['2'] -= 1
cnt['0'] -= 1
replaced_str = ['0'] * cnt['0']
replaced_str += ['1'] * cnt['1']
replaced_str += ['2'] * cnt['2']
replaced_str += ['2', '0']
s[start:i + 1] = replaced_str
start = i + 1
found2 = False
cnt = Counter()
s[start:n] = ['0'] * cnt['0'] + ['1'] * cnt['1'] + ['2'] * cnt['2']
print(''.join(s))
if __name__ == "__main__":
main() | Title: Minimum Ternary String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
- "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201".
Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$.
Input Specification:
The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive).
Output Specification:
Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Demo Input:
['100210\n', '11222121\n', '20\n']
Demo Output:
['001120\n', '11112222\n', '20\n']
Note:
none | ```python
from collections import Counter
def main():
s = [c for c in input().strip()]
n = len(s)
start = 0
cnt = Counter()
found2 = False
for i in range(n):
cnt[s[i]] += 1
if s[i] == '2':
found2 = True
if s[i] == '0' and found2:
cnt['2'] -= 1
cnt['0'] -= 1
replaced_str = ['0'] * cnt['0']
replaced_str += ['1'] * cnt['1']
replaced_str += ['2'] * cnt['2']
replaced_str += ['2', '0']
s[start:i + 1] = replaced_str
start = i + 1
found2 = False
cnt = Counter()
s[start:n] = ['0'] * cnt['0'] + ['1'] * cnt['1'] + ['2'] * cnt['2']
print(''.join(s))
if __name__ == "__main__":
main()
``` | 0 |
|
844 | B | Rectangles | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black. | Output single integer — the number of non-empty sets from the problem description. | [
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] | [
"1\n",
"8\n"
] | In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | 1,000 | [
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"
},
{
"input": "10 11\n1 1 0 1 1 0 0 0 1 0 0\n1 0 0 1 1 1 0 0 1 1 0\n0 0 1 0 1 1 0 1 0 1 1\n0 1 1 1 0 1 0 1 0 0 0\n1 1 1 1 1 1 1 0 1 0 0\n1 1 0 1 1 1 1 0 0 1 1\n1 0 1 0 1 0 0 1 1 1 0\n1 1 0 0 0 0 0 1 0 1 1\n1 1 0 1 1 1 0 0 1 1 0\n1 0 1 1 0 0 1 0 0 1 1",
"output": "2444"
},
{
"input": "50 1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n0\n1\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n0\n1",
"output": "142606334"
},
{
"input": "1 50\n0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 1 1 0 1",
"output": "142606334"
},
{
"input": "2 20\n0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0",
"output": "589853"
},
{
"input": "5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "285"
},
{
"input": "6 6\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1",
"output": "720"
},
{
"input": "21 2\n0 1\n1 1\n0 1\n0 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "1310745"
},
{
"input": "3 15\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 1 0 0 0 0 0 1 0\n1 0 0 1 0 0 0 0 0 0 0 0 1 0 1",
"output": "22587"
},
{
"input": "10 11\n0 1 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 0 1 0 0 0 0\n0 0 0 0 0 0 1 1 1 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 1 0\n0 0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 1 0\n0 0 1 0 0 0 1 1 0 0 0\n0 0 0 0 0 0 0 0 1 0 0\n0 0 1 0 1 0 0 0 0 1 1",
"output": "12047"
},
{
"input": "14 15\n0 1 0 0 0 0 0 0 1 0 0 0 1 0 1\n0 0 0 1 1 1 1 0 1 0 0 1 1 0 0\n1 0 0 0 0 1 1 0 0 0 0 0 0 0 0\n0 1 0 0 0 1 0 1 1 0 0 1 0 0 0\n0 0 1 1 0 1 0 1 0 1 1 0 1 0 0\n0 0 0 1 1 0 0 0 0 0 1 1 0 1 0\n0 0 1 0 0 0 0 0 0 1 0 0 1 1 0\n1 1 0 0 0 1 0 0 0 0 0 0 1 1 0\n0 0 0 0 1 0 1 1 1 0 0 0 1 0 1\n1 0 1 1 0 1 0 0 1 0 0 1 1 1 0\n1 0 0 0 0 1 0 0 0 0 0 1 0 0 0\n0 0 0 1 0 1 0 0 0 0 1 0 0 0 1\n0 0 1 0 1 0 0 0 1 1 1 1 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0",
"output": "53166"
},
{
"input": "1 50\n0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0",
"output": "1099511628798"
},
{
"input": "50 1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1",
"output": "35184372088862"
},
{
"input": "1 50\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",
"output": "1125899906842623"
},
{
"input": "5 50\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\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\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\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\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",
"output": "5629499534214415"
},
{
"input": "32 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "8589934622"
},
{
"input": "1 50\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "562949953421312"
},
{
"input": "50 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "1125899906842623"
},
{
"input": "1 49\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",
"output": "562949953421311"
},
{
"input": "2 50\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\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",
"output": "2251799813685296"
},
{
"input": "3 50\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\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\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",
"output": "3377699720528069"
},
{
"input": "1 50\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",
"output": "1125899906842623"
},
{
"input": "1 40\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",
"output": "1099511627775"
},
{
"input": "1 33\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "8589934591"
},
{
"input": "2 40\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\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",
"output": "2199023255590"
},
{
"input": "1 35\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",
"output": "34359738367"
},
{
"input": "50 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0",
"output": "1125899906842623"
}
] | 1,649,221,295 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | N,M = map(int ,input().split())
A = []
for _ in range(N):
A.append(list(map(int, input().split())))
ans = N*M
for k in range(N):
for i in range(M):
for j in range(i+1,M):
if A[k][i]==A[k][j]:
ans += 1
for k in range(M):
for i in range(N):
for j in range(i+1,N):
if A[i][k]==A[j][k]:
ans += 1
print(ans)
| Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column.
Input Specification:
The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.
Output Specification:
Output single integer — the number of non-empty sets from the problem description.
Demo Input:
['1 1\n0\n', '2 3\n1 0 1\n0 1 0\n']
Demo Output:
['1\n', '8\n']
Note:
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | ```python
N,M = map(int ,input().split())
A = []
for _ in range(N):
A.append(list(map(int, input().split())))
ans = N*M
for k in range(N):
for i in range(M):
for j in range(i+1,M):
if A[k][i]==A[k][j]:
ans += 1
for k in range(M):
for i in range(N):
for j in range(i+1,N):
if A[i][k]==A[j][k]:
ans += 1
print(ans)
``` | 0 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,694,247,993 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | str_list = input().split()
m = int(str_list[0])
n = int(str_list[1])
a = int(str_list[2])
if m % a = 0:
length = m // a
else:
length = m // a + 1
if n % a = 0:
width = n // a
else:
width = n // a + 1
result = length * width
print(result) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
str_list = input().split()
m = int(str_list[0])
n = int(str_list[1])
a = int(str_list[2])
if m % a = 0:
length = m // a
else:
length = m // a + 1
if n % a = 0:
width = n // a
else:
width = n // a + 1
result = length * width
print(result)
``` | -1 |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n1 2 3 3 4",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "2"
},
{
"input": "11\n1 2 3 1 2 3 2 1 2 3 4",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "1\n1234394",
"output": "1"
}
] | 1,695,822,659 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n = int(input())
first_list = list(map(int, input().split()))
ans_list = 0
max_len = 1
for i in range(len(first_list)):
if first_list[i - 1] < first_list[i]:
ans_list += 1
else:
ans_list = 1
print(ans_list)
| Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Input Specification:
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the maximum length of an increasing subarray of the given array.
Demo Input:
['5\n1 7 2 11 15\n', '6\n100 100 100 100 100 100\n', '3\n1 2 3\n']
Demo Output:
['3\n', '1\n', '3\n']
Note:
none | ```python
n = int(input())
first_list = list(map(int, input().split()))
ans_list = 0
max_len = 1
for i in range(len(first_list)):
if first_list[i - 1] < first_list[i]:
ans_list += 1
else:
ans_list = 1
print(ans_list)
``` | 0 |
|
369 | B | Valera and Contest | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
- each student in the team scored at least *l* points and at most *r* points; - in total, all members of the team scored exactly *s**all* points; - the total score of the *k* members of the team who scored the most points is equal to exactly *s**k*; more formally, if *a*1,<=*a*2,<=...,<=*a**n* is the sequence of points earned by the team of students in the non-increasing order (*a*1<=≥<=*a*2<=≥<=...<=≥<=*a**n*), then *s**k*<==<=*a*1<=+<=*a*2<=+<=...<=+<=*a**k*.
However, Valera did not find out exactly how many points each of *n* students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met. | The first line of the input contains exactly six integers *n*,<=*k*,<=*l*,<=*r*,<=*s**all*,<=*s**k* (1<=≤<=*n*,<=*k*,<=*l*,<=*r*<=≤<=1000; *l*<=≤<=*r*; *k*<=≤<=*n*; 1<=≤<=*s**k*<=≤<=*s**all*<=≤<=106).
It's guaranteed that the input is such that the answer exists. | Print exactly *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order. | [
"5 3 1 3 13 9\n",
"5 3 1 3 15 9\n"
] | [
"2 3 2 3 3 ",
"3 3 3 3 3 "
] | none | 1,000 | [
{
"input": "5 3 1 3 13 9",
"output": "2 3 2 3 3 "
},
{
"input": "5 3 1 3 15 9",
"output": "3 3 3 3 3 "
},
{
"input": "50 25 1 1 50 25",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1000 700 782 1000 892330 648282",
"output": "926 926 926 814 926 926 926 926 926 813 926 814 926 813 813 926 814 926 926 926 814 926 814 926 813 927 814 926 813 926 926 813 926 926 926 927 926 813 926 813 926 926 926 926 813 926 926 926 813 813 926 926 814 926 926 926 814 926 813 927 926 926 927 926 926 926 926 926 926 926 927 813 926 814 926 926 926 926 813 813 814 926 927 814 926 926 813 926 813 926 926 814 926 926 926 926 926 926 814 926 926 927 926 926 926 926 926 814 926 926 813 926 926 926 926 927 813 926 926 927 926 926 926 926 926 926 926 926..."
},
{
"input": "1000 999 500 503 501513 501013",
"output": "501 502 502 501 501 502 502 502 501 501 502 501 502 501 501 501 501 502 502 502 501 502 501 502 501 502 501 502 501 501 502 501 501 502 502 502 501 501 502 501 502 501 502 502 501 501 502 502 501 501 502 502 501 502 502 501 501 502 501 502 501 502 502 502 502 502 502 501 502 502 502 501 502 501 502 502 501 502 501 501 501 501 502 501 502 502 501 502 501 501 502 501 502 502 501 502 502 501 501 502 502 502 501 501 502 502 502 501 502 502 501 501 501 501 502 502 500 501 502 502 502 502 502 502 501 502 501 502..."
},
{
"input": "999 998 500 501 500009 499509",
"output": "500 501 501 500 500 501 501 501 500 500 501 500 501 500 500 500 500 501 501 501 500 501 500 501 500 501 500 501 500 500 501 500 500 501 501 501 500 500 501 500 501 500 501 501 500 500 501 501 500 500 501 501 500 501 501 500 500 501 500 501 500 501 501 501 501 501 501 500 501 501 501 500 501 500 501 501 500 501 500 500 500 500 501 500 501 501 500 501 500 500 501 500 501 501 500 501 501 500 500 501 501 501 500 500 501 501 501 500 501 501 500 500 500 500 501 501 501 500 501 501 501 501 501 501 500 501 500 501..."
},
{
"input": "999 998 500 500 499500 499000",
"output": "500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500..."
},
{
"input": "999 997 500 502 500516 499516",
"output": "501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 502 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 502 501 501 501 501 501 501 501 501 500 501 501 501 501 501 502 501 501 501 501 501 501 501 501 501 501 501..."
},
{
"input": "1000 300 50 500 269795 127658",
"output": "203 204 203 203 203 203 203 426 203 203 204 203 425 203 203 203 203 204 203 203 203 425 203 204 203 426 203 203 203 203 203 203 203 426 203 426 203 203 426 203 203 203 203 203 203 203 203 204 203 203 425 203 203 425 425 203 203 425 203 426 203 204 426 426 425 426 203 203 425 203 426 203 425 203 425 425 203 425 203 203 203 203 426 203 425 203 203 425 203 203 203 203 203 203 203 203 426 203 203 203 425 426 203 203 203 203 203 203 425 425 203 203 203 203 203 426 203 203 203 426 204 203 203 203 203 203 203 426..."
},
{
"input": "50 25 1000 1000 50000 25000",
"output": "1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 "
},
{
"input": "100 100 500 1000 75589 75589",
"output": "756 756 756 755 755 756 756 756 756 755 756 756 756 756 756 756 755 756 755 756 756 756 756 756 756 756 756 756 756 755 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 755 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 755 756 756 756 756 756 755 756 756 756 755 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 755 756 756 756 756 756 756 756 "
},
{
"input": "1 1 1000 1000 1000 1000",
"output": "1000 "
},
{
"input": "2 2 500 1000 1000 1000",
"output": "500 500 "
},
{
"input": "1000 500 1 1000 500500 500000",
"output": "1 1000 1000 1 1 1000 1000 1000 1 1 1000 1 1000 1 1 1 1 1000 1000 1000 1 1000 1 1000 1 1000 1 1000 1 1 1000 1 1 1000 1000 1000 1 1 1000 1 1000 1 1000 1000 1 1 1 1000 1 1 1000 1000 1 1000 1000 1 1 1000 1 1000 1 1000 1000 1000 1000 1000 1000 1 1000 1000 1000 1 1000 1 1000 1000 1 1000 1 1 1 1 1000 1 1000 1000 1 1000 1 1 1000 1 1000 1000 1 1000 1000 1 1 1000 1000 1000 1 1 1000 1000 1000 1 1000 1000 1 1 1 1 1000 1000 1 1 1000 1000 1000 1000 1000 1000 1 1000 1 1000 1 1 1 1 1000 1 1 1000 1000 1000 1000 1000 1 1 1 ..."
},
{
"input": "1000 500 500 1000 750000 375000",
"output": "750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750..."
},
{
"input": "300 100 1 3 600 200",
"output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "300 100 1 3 900 300",
"output": "3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3..."
},
{
"input": "300 100 1 3 300 100",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "1 1 1 1 1 1",
"output": "1 "
},
{
"input": "432 32 13 123 28942 3824",
"output": "63 63 63 63 63 63 62 63 63 63 63 63 63 63 62 63 63 63 62 62 63 63 62 63 62 120 62 62 63 63 62 63 63 63 63 63 119 120 63 63 63 62 63 62 63 63 63 63 63 63 63 63 63 63 63 120 63 63 63 63 63 63 63 63 63 63 63 63 63 62 63 63 63 63 63 63 62 63 63 63 63 63 63 63 63 62 63 63 63 63 63 63 63 62 63 63 63 63 63 63 63 119 63 62 62 62 63 63 63 63 63 120 63 63 62 63 120 63 62 63 63 62 62 63 63 62 63 63 63 120 63 120 63 63 63 62 63 63 63 63 62 63 62 62 63 63 63 62 63 63 63 63 63 63 63 62 63 62 63 63 63 62 63 119 62 63 62 ..."
},
{
"input": "504 32 13 123 33704 3791",
"output": "64 63 63 63 63 63 63 64 63 63 63 64 63 63 63 64 63 63 63 63 64 63 63 63 63 119 63 63 64 64 63 63 63 64 63 64 118 119 64 64 63 63 63 63 63 64 63 63 64 64 64 63 63 63 64 118 63 64 63 64 63 63 64 64 63 64 63 64 64 63 64 64 64 64 63 63 63 64 63 64 64 64 64 64 63 63 63 64 64 64 63 63 63 63 64 63 64 63 63 63 63 118 63 63 63 63 63 63 64 63 63 119 63 63 63 64 119 63 63 64 63 63 63 63 64 63 64 64 64 119 63 119 64 64 63 63 63 64 63 63 63 64 63 63 63 63 64 63 64 63 64 64 63 64 63 63 63 63 64 64 64 63 64 118 63 63 63 ..."
},
{
"input": "999 32 13 123 68122 3876",
"output": "66 67 67 66 66 67 67 67 66 66 67 66 67 66 66 66 66 67 67 66 66 67 66 67 66 121 66 66 66 66 67 66 66 67 67 67 66 66 67 66 66 66 66 67 66 66 66 67 66 66 67 67 66 67 67 66 66 67 66 67 66 67 67 67 67 67 67 66 67 67 67 66 67 66 67 67 66 67 66 66 66 66 67 66 67 67 66 67 66 66 66 66 66 66 66 67 67 66 66 66 67 121 66 66 67 67 67 66 67 67 66 66 66 66 67 67 122 66 67 67 67 67 67 66 66 67 66 67 66 66 66 66 67 66 66 67 67 67 67 67 66 66 66 67 67 66 67 67 66 66 66 67 66 67 66 66 66 66 67 67 66 66 66 121 67 66 66 67 66 ..."
},
{
"input": "489 32 13 123 33009 3885",
"output": "64 64 64 64 63 64 63 64 64 64 64 64 64 64 63 64 64 64 63 63 64 64 63 64 63 122 63 63 64 64 63 64 64 64 63 64 121 122 64 64 63 63 63 63 64 64 64 64 64 64 64 64 64 64 64 121 63 64 64 64 64 64 64 64 64 64 63 64 64 63 64 64 64 64 64 64 63 64 63 64 64 64 64 64 64 63 64 64 64 64 63 63 63 63 64 63 64 64 64 63 64 121 64 63 63 64 63 64 64 64 64 122 64 64 63 64 122 64 64 64 64 63 64 64 64 64 64 64 64 122 64 122 64 64 64 63 64 64 64 64 63 64 63 64 64 64 64 63 64 63 64 64 64 64 64 63 64 63 64 64 64 64 64 121 63 64 63 ..."
},
{
"input": "234 32 13 123 16337 3715",
"output": "62 63 62 62 63 62 62 62 62 63 62 63 63 62 63 62 63 63 63 116 62 63 63 63 63 116 62 63 62 63 63 63 62 62 63 63 116 116 62 63 63 63 62 62 116 62 63 116 62 62 62 63 116 62 62 116 63 62 62 63 63 63 63 63 63 63 62 62 62 116 63 62 62 62 62 62 62 62 63 63 62 63 63 63 63 62 62 62 62 62 63 62 63 62 62 63 63 63 63 116 63 116 63 63 116 62 63 63 62 62 62 116 116 63 62 63 117 63 62 63 63 62 63 62 62 116 62 63 63 117 62 116 62 63 62 63 62 62 116 63 62 63 63 62 62 62 63 63 63 62 63 63 62 62 62 62 63 63 63 62 63 62 63 116..."
},
{
"input": "998 997 13 13 12974 12961",
"output": "13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 1..."
},
{
"input": "999 999 13 333 169609 169609",
"output": "170 170 170 170 170 170 170 170 170 169 170 170 170 169 169 170 169 170 170 170 170 170 169 170 169 170 169 170 169 170 170 169 170 170 170 170 170 169 170 169 170 170 170 170 169 170 170 170 169 169 170 170 169 170 170 170 170 170 169 170 170 170 170 170 170 170 170 170 170 170 170 169 170 170 170 170 170 170 169 169 170 170 170 170 170 170 169 170 169 170 170 169 170 170 170 170 170 170 169 170 170 170 170 170 170 170 170 169 170 170 169 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170..."
},
{
"input": "999 998 13 533 270345 270332",
"output": "271 271 271 271 271 271 271 271 271 270 271 271 271 270 270 271 271 271 271 271 271 271 271 271 270 271 271 271 270 271 271 270 271 271 271 271 271 271 271 270 271 271 271 271 270 271 271 271 270 270 271 271 271 271 271 271 271 271 270 271 271 271 271 271 271 271 271 271 271 271 271 270 271 271 271 271 271 271 270 270 271 271 271 271 271 271 270 271 270 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 13 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 ..."
},
{
"input": "998 123 13 293 151330 33752",
"output": "134 135 135 134 134 135 135 135 134 134 135 134 135 134 134 134 134 135 135 134 134 135 134 135 134 275 134 134 134 134 135 134 134 135 135 275 134 134 135 134 134 134 134 135 134 134 134 135 134 134 135 135 134 135 135 134 134 135 134 275 134 135 275 274 135 274 135 134 135 135 274 134 135 134 135 135 134 135 134 134 134 134 274 134 135 135 134 135 134 134 134 134 134 134 134 135 274 134 134 134 135 275 134 134 135 135 135 134 135 135 135 134 134 134 135 274 275 134 135 275 135 135 135 134 134 135 134 274..."
},
{
"input": "995 993 123 743 437780 437534",
"output": "440 441 441 440 440 441 441 441 440 440 441 440 441 440 440 440 440 441 441 441 440 441 440 441 440 441 440 441 440 440 441 440 440 441 441 441 440 440 441 440 441 441 441 441 440 440 441 441 440 440 441 441 440 441 441 441 440 441 440 441 440 441 441 441 441 441 441 441 441 441 441 440 441 440 441 441 440 441 440 440 440 441 441 440 441 441 440 441 440 440 441 440 441 441 441 441 441 440 440 441 441 441 441 440 441 441 441 440 441 441 441 440 441 441 441 441 441 440 441 441 441 441 441 441 440 441 441 441..."
},
{
"input": "999 999 111 111 110889 110889",
"output": "111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111..."
},
{
"input": "1000 1000 111 111 111000 111000",
"output": "111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111..."
},
{
"input": "1000 567 999 1000 999489 566922",
"output": "999 1000 1000 999 999 1000 1000 1000 999 999 1000 999 1000 999 999 999 999 1000 1000 1000 999 1000 999 1000 999 1000 999 1000 999 999 1000 999 999 1000 1000 1000 999 999 1000 999 1000 999 1000 1000 999 999 999 1000 999 999 1000 1000 999 1000 1000 999 999 1000 999 1000 999 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 999 1000 999 1000 1000 999 1000 999 999 999 999 1000 999 1000 1000 999 1000 999 999 1000 999 1000 1000 999 1000 1000 999 999 1000 1000 1000 999 999 1000 1000 1000 999 1000 1000 999 999 999 ..."
},
{
"input": "1000 567 998 1000 998981 566754",
"output": "998 1000 999 998 999 999 999 1000 999 998 1000 998 1000 998 998 999 998 999 999 999 998 1000 998 1000 998 1000 998 999 998 998 999 998 999 1000 999 1000 998 998 1000 998 999 999 999 999 998 998 999 1000 998 998 1000 999 998 1000 1000 999 998 1000 998 1000 998 1000 1000 1000 1000 1000 999 999 1000 999 1000 998 1000 998 1000 1000 999 1000 998 998 998 999 1000 998 1000 999 998 1000 998 998 999 998 999 999 999 999 1000 998 998 999 1000 1000 999 999 999 999 999 998 1000 1000 998 998 999 999 999 1000 998 998 999..."
},
{
"input": "1000 567 996 1000 997986 566445",
"output": "997 999 999 997 997 999 999 999 997 996 999 997 999 996 996 997 997 999 999 999 997 999 997 999 996 1000 997 999 996 997 999 996 997 999 999 999 997 996 999 996 999 999 999 999 996 997 999 999 996 996 999 999 997 999 999 997 997 999 996 999 997 999 999 999 999 999 999 999 999 999 999 996 999 997 999 999 997 999 996 996 997 997 999 997 999 999 996 999 996 997 999 997 999 999 999 999 999 997 997 999 999 999 999 997 999 999 999 997 999 999 996 997 997 999 999 999 996 997 999 999 999 999 999 999 997 999 999 99..."
},
{
"input": "1000 567 996 1000 997986 566445",
"output": "997 999 999 997 997 999 999 999 997 996 999 997 999 996 996 997 997 999 999 999 997 999 997 999 996 1000 997 999 996 997 999 996 997 999 999 999 997 996 999 996 999 999 999 999 996 997 999 999 996 996 999 999 997 999 999 997 997 999 996 999 997 999 999 999 999 999 999 999 999 999 999 996 999 997 999 999 997 999 996 996 997 997 999 997 999 999 996 999 996 997 999 997 999 999 999 999 999 997 997 999 999 999 999 997 999 999 999 997 999 999 996 997 997 999 999 999 996 997 999 999 999 999 999 999 997 999 999 99..."
},
{
"input": "1 1 1 1000 656 656",
"output": "656 "
},
{
"input": "2 1 1 1000 683 550",
"output": "550 133 "
},
{
"input": "3 2 1 1000 1816 1652",
"output": "826 826 164 "
},
{
"input": "5 5 1 1000 3288 3288",
"output": "657 658 657 658 658 "
},
{
"input": "5 3 1 1000 2732 2055",
"output": "338 685 339 685 685 "
},
{
"input": "1 1 10 100 50 50",
"output": "50 "
},
{
"input": "3 3 1 5 14 14",
"output": "5 5 4 "
},
{
"input": "1 1 1 100 50 50",
"output": "50 "
},
{
"input": "5 5 1 5 5 5",
"output": "1 1 1 1 1 "
},
{
"input": "1 1 1 10 10 10",
"output": "10 "
},
{
"input": "5 5 1 3 5 5",
"output": "1 1 1 1 1 "
},
{
"input": "1000 1000 1 1000 1000000 1000000",
"output": "1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1..."
},
{
"input": "3 3 1 3 9 9",
"output": "3 3 3 "
},
{
"input": "1000 1000 389 999 686847 686847",
"output": "687 687 687 687 687 687 687 687 687 686 687 687 687 686 686 687 687 687 687 687 687 687 687 687 686 687 687 687 686 687 687 686 687 687 687 687 687 686 687 686 687 687 687 687 686 687 687 687 686 686 687 687 687 687 687 687 687 687 686 687 687 687 687 687 687 687 687 687 687 687 687 686 687 687 687 687 687 687 686 686 687 687 687 687 687 687 686 687 686 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 686 687 687 687 687 687 686 687 687 687 687 687 687 687 687 687 687 687..."
},
{
"input": "2 2 2 2 4 4",
"output": "2 2 "
}
] | 1,589,473,051 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 140 | 20,172,800 | n,k,l,r,sa,s=map(int,input().split())
rm=s%k
print((( (str(s//k)) +' ' )*(k-rm))+((str((s//k)+1)+' ')*rm),end='')
if sa !=s:
re=sa-s
z2=re%(n-k)
print(((str(re//(n-k))+' ')*(n-k-z2))+((str((re//(n-k))+1)+' ')*z2))
| Title: Valera and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
- each student in the team scored at least *l* points and at most *r* points; - in total, all members of the team scored exactly *s**all* points; - the total score of the *k* members of the team who scored the most points is equal to exactly *s**k*; more formally, if *a*1,<=*a*2,<=...,<=*a**n* is the sequence of points earned by the team of students in the non-increasing order (*a*1<=≥<=*a*2<=≥<=...<=≥<=*a**n*), then *s**k*<==<=*a*1<=+<=*a*2<=+<=...<=+<=*a**k*.
However, Valera did not find out exactly how many points each of *n* students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.
Input Specification:
The first line of the input contains exactly six integers *n*,<=*k*,<=*l*,<=*r*,<=*s**all*,<=*s**k* (1<=≤<=*n*,<=*k*,<=*l*,<=*r*<=≤<=1000; *l*<=≤<=*r*; *k*<=≤<=*n*; 1<=≤<=*s**k*<=≤<=*s**all*<=≤<=106).
It's guaranteed that the input is such that the answer exists.
Output Specification:
Print exactly *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
Demo Input:
['5 3 1 3 13 9\n', '5 3 1 3 15 9\n']
Demo Output:
['2 3 2 3 3 ', '3 3 3 3 3 ']
Note:
none | ```python
n,k,l,r,sa,s=map(int,input().split())
rm=s%k
print((( (str(s//k)) +' ' )*(k-rm))+((str((s//k)+1)+' ')*rm),end='')
if sa !=s:
re=sa-s
z2=re%(n-k)
print(((str(re//(n-k))+' ')*(n-k-z2))+((str((re//(n-k))+1)+' ')*z2))
``` | 3 |
|
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{
"input": "24 54 37\n60 63 6\n1 84 26",
"output": "110\n101\n011"
},
{
"input": "23 10 40\n15 6 40\n92 80 77",
"output": "101\n100\n000"
},
{
"input": "62 74 80\n95 74 93\n2 47 95",
"output": "010\n001\n110"
},
{
"input": "80 83 48\n26 0 66\n47 76 37",
"output": "000\n000\n010"
},
{
"input": "32 15 65\n7 54 36\n5 51 3",
"output": "111\n101\n001"
},
{
"input": "22 97 12\n71 8 24\n100 21 64",
"output": "100\n001\n100"
},
{
"input": "46 37 13\n87 0 50\n90 8 55",
"output": "111\n011\n000"
},
{
"input": "57 43 58\n20 82 83\n66 16 52",
"output": "111\n010\n110"
},
{
"input": "45 56 93\n47 51 59\n18 51 63",
"output": "101\n011\n100"
},
{
"input": "47 66 67\n14 1 37\n27 81 69",
"output": "001\n001\n110"
},
{
"input": "26 69 69\n85 18 23\n14 22 74",
"output": "110\n001\n010"
},
{
"input": "10 70 65\n94 27 25\n74 66 30",
"output": "111\n010\n100"
},
{
"input": "97 1 74\n15 99 1\n88 68 86",
"output": "001\n011\n000"
},
{
"input": "36 48 42\n45 41 66\n26 64 1",
"output": "001\n111\n010"
},
{
"input": "52 81 97\n29 77 71\n66 11 2",
"output": "100\n100\n111"
},
{
"input": "18 66 33\n19 49 49\n48 46 26",
"output": "011\n100\n000"
},
{
"input": "68 79 52\n51 39 100\n29 14 26",
"output": "110\n000\n111"
},
{
"input": "91 69 77\n91 26 64\n91 88 57",
"output": "001\n011\n110"
},
{
"input": "16 69 64\n48 21 80\n81 51 51",
"output": "010\n101\n111"
},
{
"input": "96 14 2\n100 18 12\n65 34 89",
"output": "111\n010\n010"
},
{
"input": "93 95 90\n8 59 42\n53 13 19",
"output": "100\n001\n111"
},
{
"input": "71 84 18\n100 19 67\n9 76 15",
"output": "010\n010\n001"
},
{
"input": "38 93 85\n21 88 64\n4 96 25",
"output": "111\n011\n000"
},
{
"input": "75 20 20\n60 5 78\n77 4 69",
"output": "011\n001\n000"
},
{
"input": "65 70 96\n19 6 83\n33 37 82",
"output": "100\n000\n011"
},
{
"input": "11 13 60\n17 13 46\n42 21 39",
"output": "000\n011\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 0",
"output": "111\n111\n111"
},
{
"input": "0 0 0\n0 1 0\n0 0 0",
"output": "101\n000\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 1",
"output": "111\n110\n100"
}
] | 1,643,612,701 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | l=[[1,1,1],[1,1,1],[1,1,1]]
for i in range(3):
z=list(map(int,input().split()))
for j in range(3):
if z[j]%2==1:
if j+1<3:
l[i][j+1]=(l[i][j+1]+1)%2
if i+1<3:
l[i+1][j]=(l[i+1][j]+1)%2
if j-1>=0:
l[i][j-1]=(l[i][j-1]+1)%2
if i-1>=0:
l[i-1][j]=(l[i-1][j]+1)%2
l[i][j]=(l[i][j]+1)%2
for i in l:
print(''.join(list(map(lambda t:str(t),i)))) | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
Input Specification:
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Output Specification:
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
Demo Input:
['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n']
Demo Output:
['001\n010\n100\n', '010\n011\n100\n']
Note:
none | ```python
l=[[1,1,1],[1,1,1],[1,1,1]]
for i in range(3):
z=list(map(int,input().split()))
for j in range(3):
if z[j]%2==1:
if j+1<3:
l[i][j+1]=(l[i][j+1]+1)%2
if i+1<3:
l[i+1][j]=(l[i+1][j]+1)%2
if j-1>=0:
l[i][j-1]=(l[i][j-1]+1)%2
if i-1>=0:
l[i-1][j]=(l[i-1][j]+1)%2
l[i][j]=(l[i][j]+1)%2
for i in l:
print(''.join(list(map(lambda t:str(t),i))))
``` | 3 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,593,680,498 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 280 | 0 | a, b = map(int, input().split(' '))
a = max(a, b)
if a == 1:
a = '1/1'
elif a == 2:
a = '5/6'
elif a == 3:
a = '2/3'
elif a == 4:
a = '1/2'
elif a == 5:
a = '1/3'
elif a == 6:
a = '1/6'
print(a)
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
a, b = map(int, input().split(' '))
a = max(a, b)
if a == 1:
a = '1/1'
elif a == 2:
a = '5/6'
elif a == 3:
a = '2/3'
elif a == 4:
a = '1/2'
elif a == 5:
a = '1/3'
elif a == 6:
a = '1/6'
print(a)
``` | 3.86 |
920 | B | Tea Queue | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it). | The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every condition *l**i*<=-<=1<=≤<=*l**i* holds.
The sum of *n* over all test cases doesn't exceed 1000.
Note that in hacks you have to set *t*<==<=1. | For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea. | [
"2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n"
] | [
"1 2 \n1 0 2 \n"
] | The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea. | 0 | [
{
"input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3",
"output": "1 2 \n1 0 2 "
},
{
"input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2 2000\n2 2\n2\n2 2\n2 2000",
"output": "1 \n1 \n1 \n1 \n2 \n2 \n2 \n2 \n1999 \n1999 \n2000 \n1 0 \n1 2 \n1 0 \n1 0 \n1 2 \n1 2 \n2 0 \n2 3 "
},
{
"input": "1\n11\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "1 0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "1\n5\n1 1\n1 2\n1 5\n1 1\n1 1",
"output": "1 2 3 0 0 "
}
] | 1,517,583,268 | 1,168 | Python 3 | OK | TESTS | 8 | 61 | 5,734,400 | t = int(input())
ans1 = []
for i in range(t):
n=int(input())
st=[]
for i in range(n):
l,r = map(int,input().split())
st.append((l,r,i))
st = sorted(st, key=lambda x: (x[0], x[2]))
ans = []
f = -1
for s in st:
if s[1] < f:
ans.append(0)
else:
ans.append(max(f, s[0]))
f = ans[-1]+1
ans1.append(ans)
for ans2 in ans1:
print(' '.join([str(i) for i in ans2])) | Title: Tea Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it).
Input Specification:
The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every condition *l**i*<=-<=1<=≤<=*l**i* holds.
The sum of *n* over all test cases doesn't exceed 1000.
Note that in hacks you have to set *t*<==<=1.
Output Specification:
For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea.
Demo Input:
['2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n']
Demo Output:
['1 2 \n1 0 2 \n']
Note:
The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea. | ```python
t = int(input())
ans1 = []
for i in range(t):
n=int(input())
st=[]
for i in range(n):
l,r = map(int,input().split())
st.append((l,r,i))
st = sorted(st, key=lambda x: (x[0], x[2]))
ans = []
f = -1
for s in st:
if s[1] < f:
ans.append(0)
else:
ans.append(max(f, s[0]))
f = ans[-1]+1
ans1.append(ans)
for ans2 in ans1:
print(' '.join([str(i) for i in ans2]))
``` | 3 |
|
557 | C | Arthur and Table | PROGRAMMING | 1,900 | [
"brute force",
"data structures",
"dp",
"greedy",
"math",
"sortings"
] | null | null | Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d**i* — the amount of energy that he spends to remove the *i*-th leg.
A table with *k* legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.
Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the initial number of legs in the table Arthur bought.
The second line of the input contains a sequence of *n* integers *l**i* (1<=≤<=*l**i*<=≤<=105), where *l**i* is equal to the length of the *i*-th leg of the table.
The third line of the input contains a sequence of *n* integers *d**i* (1<=≤<=*d**i*<=≤<=200), where *d**i* is the number of energy units that Arthur spends on removing the *i*-th leg off the table. | Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable. | [
"2\n1 5\n3 2\n",
"3\n2 4 4\n1 1 1\n",
"6\n2 2 1 1 3 3\n4 3 5 5 2 1\n"
] | [
"2\n",
"0\n",
"8\n"
] | none | 1,500 | [
{
"input": "2\n1 5\n3 2",
"output": "2"
},
{
"input": "3\n2 4 4\n1 1 1",
"output": "0"
},
{
"input": "6\n2 2 1 1 3 3\n4 3 5 5 2 1",
"output": "8"
},
{
"input": "10\n20 1 15 17 11 2 15 3 16 3\n129 114 183 94 169 16 18 104 49 146",
"output": "652"
},
{
"input": "10\n15 16 19 5 14 19 6 17 7 19\n140 183 186 195 67 25 70 56 54 132",
"output": "387"
},
{
"input": "20\n24 15 7 18 6 18 11 22 18 20 28 8 23 17 22 22 23 23 30 23\n24 137 173 189 43 164 2 11 142 153 16 200 53 58 150 199 169 172 38 78",
"output": "1111"
},
{
"input": "30\n20 27 26 17 29 9 25 13 6 21 15 1 14 22 26 2 15 18 20 23 27 9 15 29 11 2 19 23 14 12\n133 199 22 151 9 134 196 119 197 189 117 84 156 6 61 195 98 197 145 75 142 85 187 24 159 3 60 138 156 161",
"output": "2804"
},
{
"input": "5\n1 1 2 2 3\n2 2 2 2 3",
"output": "5"
},
{
"input": "5\n1 1 2 2 3\n2 2 2 2 7",
"output": "8"
},
{
"input": "10\n1 1 3 4 5 6 7 8 9 10\n10 10 4 2 3 4 2 2 2 2",
"output": "21"
},
{
"input": "1\n5\n4",
"output": "0"
},
{
"input": "2\n3 3\n4 5",
"output": "0"
},
{
"input": "2\n4 5\n3 3",
"output": "3"
},
{
"input": "3\n3 3 3\n1 2 3",
"output": "0"
},
{
"input": "3\n1 2 3\n3 3 3",
"output": "6"
}
] | 1,435,683,339 | 6,939 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 0 | class Noha:
def __init__(self, dlzka, celkova_cena, pocet, vsetky_nohy):
self.dlzka = dlzka
self.celkova_cena = celkova_cena
self.pocet = pocet
self.vsetky_nohy = vsetky_nohy
def __repr__(self):
return 'D: {} - C: {} - P: {}\n'.format(self.dlzka, self.celkova_cena, self.pocet)
n = int(input())
legs = [(int(x), int(y)) for x, y in zip(input().split(), input().split())]
legs.sort(reverse=True)
najlacnejsie_nohy = [(noha[1], noha[0]) for noha in legs]
najlacnejsie_nohy.sort()
# Cena odstranenia noh...
cena_nohy = {}
pocet_noh = {}
rozne_nohy = {}
for noha in legs:
dlzka, cena = noha
cena_nohy[dlzka] = cena_nohy.get(dlzka, 0) + cena
pocet_noh[dlzka] = pocet_noh.get(dlzka, 0) + 1
rozne_nohy[dlzka] = rozne_nohy.get(dlzka, []) + [cena] # todo: optimalizovat
#print(rozne_nohy)
nohy = []
for key in cena_nohy.keys():
nohy.append(Noha(dlzka=key, celkova_cena=cena_nohy[key], pocet=pocet_noh[key], vsetky_nohy=rozne_nohy[key]))
nohy.sort(key=lambda x: x.dlzka)
pocet_lacnych_noh = [0] * 220
for noha in legs:
pocet_lacnych_noh[noha[1]] += 1
# Pome odstranovat nohy....
answer = float('inf')
pocet_noh_doteraz = 0
cena_noh_doteraz = 0
for i in range(len(nohy)-1, -1, -1):
dlzka = nohy[i].dlzka
cenaa = nohy[i].celkova_cena
pocet = nohy[i].pocet
vymaz_tieto_nohy = nohy[i].vsetky_nohy
nohy_na_vymazanie = n - ((pocet * 2)-1) - pocet_noh_doteraz
#print(pocet_lacnych_noh[:10])
for noha in vymaz_tieto_nohy:
pocet_lacnych_noh[noha] -= 1
tmp = cena_noh_doteraz
for cena, pocet in enumerate(pocet_lacnych_noh):
if pocet == 0: continue
#print('cena', cena)
#print('pocet', pocet)
if pocet <= nohy_na_vymazanie:
nohy_na_vymazanie -= pocet
tmp += pocet * cena
else:
tmp += nohy_na_vymazanie * cena
break
answer = min(tmp, answer)
pocet_noh_doteraz += pocet
cena_noh_doteraz += cenaa
print(answer) | Title: Arthur and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d**i* — the amount of energy that he spends to remove the *i*-th leg.
A table with *k* legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.
Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the initial number of legs in the table Arthur bought.
The second line of the input contains a sequence of *n* integers *l**i* (1<=≤<=*l**i*<=≤<=105), where *l**i* is equal to the length of the *i*-th leg of the table.
The third line of the input contains a sequence of *n* integers *d**i* (1<=≤<=*d**i*<=≤<=200), where *d**i* is the number of energy units that Arthur spends on removing the *i*-th leg off the table.
Output Specification:
Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.
Demo Input:
['2\n1 5\n3 2\n', '3\n2 4 4\n1 1 1\n', '6\n2 2 1 1 3 3\n4 3 5 5 2 1\n']
Demo Output:
['2\n', '0\n', '8\n']
Note:
none | ```python
class Noha:
def __init__(self, dlzka, celkova_cena, pocet, vsetky_nohy):
self.dlzka = dlzka
self.celkova_cena = celkova_cena
self.pocet = pocet
self.vsetky_nohy = vsetky_nohy
def __repr__(self):
return 'D: {} - C: {} - P: {}\n'.format(self.dlzka, self.celkova_cena, self.pocet)
n = int(input())
legs = [(int(x), int(y)) for x, y in zip(input().split(), input().split())]
legs.sort(reverse=True)
najlacnejsie_nohy = [(noha[1], noha[0]) for noha in legs]
najlacnejsie_nohy.sort()
# Cena odstranenia noh...
cena_nohy = {}
pocet_noh = {}
rozne_nohy = {}
for noha in legs:
dlzka, cena = noha
cena_nohy[dlzka] = cena_nohy.get(dlzka, 0) + cena
pocet_noh[dlzka] = pocet_noh.get(dlzka, 0) + 1
rozne_nohy[dlzka] = rozne_nohy.get(dlzka, []) + [cena] # todo: optimalizovat
#print(rozne_nohy)
nohy = []
for key in cena_nohy.keys():
nohy.append(Noha(dlzka=key, celkova_cena=cena_nohy[key], pocet=pocet_noh[key], vsetky_nohy=rozne_nohy[key]))
nohy.sort(key=lambda x: x.dlzka)
pocet_lacnych_noh = [0] * 220
for noha in legs:
pocet_lacnych_noh[noha[1]] += 1
# Pome odstranovat nohy....
answer = float('inf')
pocet_noh_doteraz = 0
cena_noh_doteraz = 0
for i in range(len(nohy)-1, -1, -1):
dlzka = nohy[i].dlzka
cenaa = nohy[i].celkova_cena
pocet = nohy[i].pocet
vymaz_tieto_nohy = nohy[i].vsetky_nohy
nohy_na_vymazanie = n - ((pocet * 2)-1) - pocet_noh_doteraz
#print(pocet_lacnych_noh[:10])
for noha in vymaz_tieto_nohy:
pocet_lacnych_noh[noha] -= 1
tmp = cena_noh_doteraz
for cena, pocet in enumerate(pocet_lacnych_noh):
if pocet == 0: continue
#print('cena', cena)
#print('pocet', pocet)
if pocet <= nohy_na_vymazanie:
nohy_na_vymazanie -= pocet
tmp += pocet * cena
else:
tmp += nohy_na_vymazanie * cena
break
answer = min(tmp, answer)
pocet_noh_doteraz += pocet
cena_noh_doteraz += cenaa
print(answer)
``` | 0 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,590,820,384 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 184 | 0 | n=int(input())
sumat=0
for i in range(n):
z=list(map(int,input().split()))
sumat=sumat+sum(z)
if suma==0:
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n=int(input())
sumat=0
for i in range(n):
z=list(map(int,input().split()))
sumat=sumat+sum(z)
if suma==0:
print('YES')
else:
print('NO')
``` | -1 |
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next, the *i*-th line contains *k**i* integers — *a**ij* (1<=≤<=*a**ij*<=≤<=*m*) — the identifiers of languages the *i*-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces. | Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4 1\n0",
"output": "4"
},
{
"input": "6 2\n0\n0\n2 1 2\n1 1\n1 1\n0",
"output": "3"
},
{
"input": "7 3\n3 1 3 2\n3 2 1 3\n2 2 3\n1 1\n2 2 3\n3 3 2 1\n3 2 3 1",
"output": "0"
},
{
"input": "8 4\n0\n0\n4 2 3 1 4\n4 2 1 4 3\n3 4 3 1\n1 2\n2 4 1\n2 4 2",
"output": "2"
},
{
"input": "10 10\n5 7 5 2 8 1\n7 10 6 9 5 8 2 4\n2 2 7\n5 8 6 9 10 1\n2 9 5\n3 6 5 2\n6 5 8 7 9 10 4\n0\n1 1\n2 8 6",
"output": "1"
},
{
"input": "11 42\n4 20 26 9 24\n14 34 7 28 32 12 15 26 4 10 38 21 20 8 11\n4 21 8 36 6\n11 32 1 39 11 21 10 25 17 26 15 4\n2 8 12\n2 21 31\n8 17 10 3 39 32 30 5 15\n20 24 20 38 17 4 7 21 19 32 28 31 22 30 37 10 5 33 2 13 9\n7 38 34 42 27 20 11 6\n3 40 3 39\n14 39 40 4 30 33 8 36 28 14 23 16 7 25 9",
"output": "0"
},
{
"input": "100 100\n1 33\n0\n2 35 4\n2 40 78\n1 69\n0\n1 2\n0\n0\n2 81 34\n1 45\n0\n1 87\n1 50\n1 97\n0\n2 100 59\n0\n0\n0\n1 45\n0\n0\n0\n1 6\n1 54\n0\n0\n0\n4 79 96 52 84\n1 86\n0\n0\n0\n0\n0\n0\n0\n0\n3 90 2 80\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 2\n0\n1 64\n0\n1 78\n1 82\n0\n0\n0\n0\n0\n1 6\n0\n0\n2 47 57\n1 95\n0\n2 91 79\n0\n1 27\n0\n1 74\n0\n0\n1 14\n0\n0\n2 90 19\n0\n1 10\n0\n0\n0\n0\n0\n1 57\n0\n2 28 50\n0\n0\n0\n1 47\n0\n0\n1 14\n0\n1 84\n1 1\n0\n0",
"output": "87"
},
{
"input": "2 2\n2 1 2\n2 1 2",
"output": "0"
},
{
"input": "2 2\n2 1 2\n1 1",
"output": "0"
},
{
"input": "2 2\n1 2\n1 1",
"output": "1"
},
{
"input": "3 100\n0\n0\n0",
"output": "3"
},
{
"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": "100"
},
{
"input": "3 3\n0\n0\n0",
"output": "3"
}
] | 1,672,814,063 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 186 | 3,379,200 | def main():
n, m = read_ints()
languages_per_employee = []
for _ in range(n):
k, *languages = read_ints()
languages_per_employee.append(set(languages))
if all(len(languages) == 0 for languages in languages_per_employee):
print(n)
return
dsu = DisjointSetUnion(n)
for i in range(n):
for j in range(i+1, n):
if languages_per_employee[i] & languages_per_employee[j]:
dsu.union(i, j)
print(dsu.count_ccomps() - 1)
class DisjointSetUnion:
def __init__(self, n):
self.p = list(range(n))
self.rank = [0] * n
self._size = [1] * n
def get(self, elm):
rep = elm
while self.p[rep] != rep:
rep = self.p[rep]
while self.p[elm] != rep:
self.p[elm], elm = rep, self.p[elm]
return rep
def size(self, elm):
rep = self.get(elm)
return self._size[rep]
def union(self, a, b):
arep = self.get(a)
brep = self.get(b)
if arep != brep:
if self.rank[arep] > self.rank[brep]:
arep, brep = brep, arep
if self.rank[arep] == self.rank[brep]:
self.rank[brep] += 1
self.p[arep] = brep
self._size[brep] += self._size[arep]
self._size[arep] = self.rank[arep] = 0
def count_ccomps(self):
return sum(1 for si in self._size if si > 0)
def input(): return next(test).strip()
def read_ints(): return [int(c) for c in input().split()]
def print_lines(lst): print('\n'.join(map(str, lst)))
if __name__ == "__main__":
import sys
from os import environ as env
if 'COMPUTERNAME' in env and 'L2A6HRI' in env['COMPUTERNAME']:
sys.stdout = open('out.txt', 'w')
sys.stdin = open('in.txt', 'r')
test = iter(sys.stdin.readlines())
main()
| Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next, the *i*-th line contains *k**i* integers — *a**ij* (1<=≤<=*a**ij*<=≤<=*m*) — the identifiers of languages the *i*-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces.
Output Specification:
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
Demo Input:
['5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n', '8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n', '2 2\n1 2\n0\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | ```python
def main():
n, m = read_ints()
languages_per_employee = []
for _ in range(n):
k, *languages = read_ints()
languages_per_employee.append(set(languages))
if all(len(languages) == 0 for languages in languages_per_employee):
print(n)
return
dsu = DisjointSetUnion(n)
for i in range(n):
for j in range(i+1, n):
if languages_per_employee[i] & languages_per_employee[j]:
dsu.union(i, j)
print(dsu.count_ccomps() - 1)
class DisjointSetUnion:
def __init__(self, n):
self.p = list(range(n))
self.rank = [0] * n
self._size = [1] * n
def get(self, elm):
rep = elm
while self.p[rep] != rep:
rep = self.p[rep]
while self.p[elm] != rep:
self.p[elm], elm = rep, self.p[elm]
return rep
def size(self, elm):
rep = self.get(elm)
return self._size[rep]
def union(self, a, b):
arep = self.get(a)
brep = self.get(b)
if arep != brep:
if self.rank[arep] > self.rank[brep]:
arep, brep = brep, arep
if self.rank[arep] == self.rank[brep]:
self.rank[brep] += 1
self.p[arep] = brep
self._size[brep] += self._size[arep]
self._size[arep] = self.rank[arep] = 0
def count_ccomps(self):
return sum(1 for si in self._size if si > 0)
def input(): return next(test).strip()
def read_ints(): return [int(c) for c in input().split()]
def print_lines(lst): print('\n'.join(map(str, lst)))
if __name__ == "__main__":
import sys
from os import environ as env
if 'COMPUTERNAME' in env and 'L2A6HRI' in env['COMPUTERNAME']:
sys.stdout = open('out.txt', 'w')
sys.stdin = open('in.txt', 'r')
test = iter(sys.stdin.readlines())
main()
``` | 3 |
|
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 2 5 3 4",
"output": "chest"
},
{
"input": "8\n7 2 9 10 3 8 10 6",
"output": "chest"
},
{
"input": "9\n5 4 2 3 4 4 5 2 2",
"output": "chest"
},
{
"input": "10\n4 9 8 5 3 8 8 10 4 2",
"output": "biceps"
},
{
"input": "11\n10 9 7 6 1 3 9 7 1 3 5",
"output": "chest"
},
{
"input": "12\n24 22 6 16 5 21 1 7 2 19 24 5",
"output": "chest"
},
{
"input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24",
"output": "chest"
},
{
"input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7",
"output": "back"
},
{
"input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12",
"output": "chest"
},
{
"input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8",
"output": "biceps"
},
{
"input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19",
"output": "chest"
},
{
"input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21",
"output": "back"
},
{
"input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24",
"output": "chest"
},
{
"input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20",
"output": "chest"
},
{
"input": "1\n10",
"output": "chest"
},
{
"input": "2\n15 3",
"output": "chest"
},
{
"input": "3\n21 11 19",
"output": "chest"
},
{
"input": "4\n19 24 13 15",
"output": "chest"
},
{
"input": "5\n4 24 1 9 19",
"output": "biceps"
},
{
"input": "6\n6 22 24 7 15 24",
"output": "back"
},
{
"input": "7\n10 8 23 23 14 18 14",
"output": "chest"
},
{
"input": "8\n5 16 8 9 17 16 14 7",
"output": "biceps"
},
{
"input": "9\n12 3 10 23 6 4 22 13 12",
"output": "chest"
},
{
"input": "10\n1 9 20 18 20 17 7 24 23 2",
"output": "back"
},
{
"input": "11\n22 25 8 2 18 15 1 13 1 11 4",
"output": "biceps"
},
{
"input": "12\n20 12 14 2 15 6 24 3 11 8 11 14",
"output": "chest"
},
{
"input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18",
"output": "back"
},
{
"input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22",
"output": "biceps"
},
{
"input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6",
"output": "back"
},
{
"input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14",
"output": "chest"
},
{
"input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10",
"output": "biceps"
},
{
"input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17",
"output": "chest"
},
{
"input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14",
"output": "back"
},
{
"input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6",
"output": "back"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "2\n1 7",
"output": "biceps"
},
{
"input": "3\n18 18 23",
"output": "back"
},
{
"input": "4\n12 15 1 13",
"output": "chest"
},
{
"input": "5\n11 14 25 21 21",
"output": "biceps"
},
{
"input": "6\n11 9 12 11 22 18",
"output": "biceps"
},
{
"input": "7\n11 1 16 20 21 25 20",
"output": "chest"
},
{
"input": "8\n1 2 20 9 3 22 17 4",
"output": "back"
},
{
"input": "9\n19 2 10 19 15 20 3 1 13",
"output": "back"
},
{
"input": "10\n11 2 11 8 21 16 2 3 19 9",
"output": "back"
},
{
"input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24",
"output": "chest"
},
{
"input": "12\n4 24 21 3 13 24 22 13 12 21 1 15",
"output": "back"
},
{
"input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3",
"output": "biceps"
},
{
"input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11",
"output": "biceps"
},
{
"input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17",
"output": "back"
},
{
"input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17",
"output": "chest"
},
{
"input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8",
"output": "chest"
},
{
"input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22",
"output": "chest"
},
{
"input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24",
"output": "chest"
},
{
"input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23",
"output": "biceps"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22",
"output": "biceps"
}
] | 1,639,293,096 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | n = int(input())
a = list(map(int, input().split()))
eil = [sum(a[i::3]) for i in [0, 1, 2]]
if eil[0] == max(eil):
print("chest")
elif eil[1] == max(eil):
print("biceps")
else:
print("back") | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Output Specification:
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous.
Demo Input:
['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n']
Demo Output:
['biceps\n', 'back\n', 'chest\n']
Note:
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | ```python
n = int(input())
a = list(map(int, input().split()))
eil = [sum(a[i::3]) for i in [0, 1, 2]]
if eil[0] == max(eil):
print("chest")
elif eil[1] == max(eil):
print("biceps")
else:
print("back")
``` | 3 |
|
553 | C | Love Triangles | PROGRAMMING | 2,200 | [
"dfs and similar",
"dsu",
"graphs"
] | null | null | There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has *n* characters. The characters are labeled from 1 to *n*. Every pair of two characters can either mutually love each other or mutually hate each other (there is no neutral state).
You hate love triangles (A-B are in love and B-C are in love, but A-C hate each other), and you also hate it when nobody is in love. So, considering any three characters, you will be happy if exactly one pair is in love (A and B love each other, and C hates both A and B), or if all three pairs are in love (A loves B, B loves C, C loves A).
You are given a list of *m* known relationships in the anime. You know for sure that certain pairs love each other, and certain pairs hate each other. You're wondering how many ways you can fill in the remaining relationships so you are happy with every triangle. Two ways are considered different if two characters are in love in one way but hate each other in the other. Print this count modulo 1<=000<=000<=007. | The first line of input will contain two integers *n*,<=*m* (3<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000).
The next *m* lines will contain the description of the known relationships. The *i*-th line will contain three integers *a**i*,<=*b**i*,<=*c**i*. If *c**i* is 1, then *a**i* and *b**i* are in love, otherwise, they hate each other (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*, ).
Each pair of people will be described no more than once. | Print a single integer equal to the number of ways to fill in the remaining pairs so that you are happy with every triangle modulo 1<=000<=000<=007. | [
"3 0\n",
"4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n",
"4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1\n"
] | [
"4\n",
"1\n",
"0\n"
] | In the first sample, the four ways are to:
- Make everyone love each other - Make 1 and 2 love each other, and 3 hate 1 and 2 (symmetrically, we get 3 ways from this).
In the second sample, the only possible solution is to make 1 and 3 love each other and 2 and 4 hate each other. | 1,000 | [
{
"input": "3 0",
"output": "4"
},
{
"input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0",
"output": "1"
},
{
"input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1",
"output": "0"
},
{
"input": "100000 0",
"output": "303861760"
},
{
"input": "100 3\n1 2 0\n2 3 0\n3 1 0",
"output": "0"
},
{
"input": "9 2\n1 2 0\n2 3 0",
"output": "64"
},
{
"input": "28567 13\n28079 24675 1\n18409 26720 1\n980 10815 1\n20794 16571 1\n7376 19861 1\n11146 706 1\n4255 16391 1\n27376 18263 1\n10019 28444 1\n6574 28053 1\n5036 16610 1\n3543 7122 1\n512 9554 1",
"output": "928433852"
},
{
"input": "4 4\n1 2 0\n2 3 0\n2 4 0\n3 4 0",
"output": "0"
},
{
"input": "4 3\n2 3 0\n3 4 0\n2 4 0",
"output": "0"
},
{
"input": "6 6\n1 2 0\n2 3 1\n3 4 0\n4 5 1\n5 6 0\n6 1 1",
"output": "0"
},
{
"input": "5 5\n1 2 0\n2 3 0\n3 4 0\n4 5 0\n1 5 0",
"output": "0"
}
] | 1,549,726,130 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 889 | 35,635,200 | class Node(object):
def __init__(self, label):
self.label = label
self.par = self
self.rank = 0
class DisjointSet(object):
def __init__(self, n):
self.n = n
self.nodes = [Node(i) for i in range(n)]
def find(self, u):
if u == u.par:
return u
return self.find(u.par)
def union(self, u, v):
u, v = self.find(u), self.find(v)
if u == v:
return False
if u.rank > v.rank:
u, v = v, u
u.par = v
if u.rank == v.rank:
v.rank += 1
return True
def size(self):
cnt = 0
for node in self.nodes:
if node.par == node:
cnt += 1
return cnt
def color(adj, colors, root):
neighbor_color = 1 - colors[root]
for neighbor in adj[root]:
if colors[neighbor] == -1:
colors[neighbor] = neighbor_color
x = color(adj, colors, neighbor)
if not x:
return False
else:
if colors[neighbor] != neighbor_color:
return False
return True
if __name__ == "__main__":
mod = 1000000007
n, m = map(int, input().split(" "))
dsu = DisjointSet(n)
reds = []
for _ in range(m):
a, b, c = map(int, input().split(" "))
if c == 0:
reds.append((a - 1, b - 1))
else:
dsu.union(dsu.nodes[a - 1], dsu.nodes[b - 1])
new_graph = {}
for i in range(n):
comp = dsu.find(dsu.nodes[i])
if comp not in new_graph.keys():
new_graph[comp] = len(new_graph)
dsu2 = DisjointSet(len(new_graph))
x = len(new_graph)
adj = [[] for _ in range(x)]
colors = [-1 for _ in range(x)]
for a, b in reds:
comp1 = dsu.find(dsu.nodes[a])
comp2 = dsu.find(dsu.nodes[b])
if comp1 == comp2:
print(0)
exit(0)
else:
index1 = new_graph[comp1]
index2 = new_graph[comp2]
dsu2.union(dsu2.nodes[index1], dsu2.nodes[index2])
adj[index1].append(index2)
adj[index2].append(index1)
for i in range(x):
if colors[i] == -1:
x = color(adj, colors, i)
if not x:
print(0)
exit(0)
comps = dsu2.size()
ans = 1
for _ in range(comps - 1):
ans *= 2
ans %= mod
print(ans)
| Title: Love Triangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has *n* characters. The characters are labeled from 1 to *n*. Every pair of two characters can either mutually love each other or mutually hate each other (there is no neutral state).
You hate love triangles (A-B are in love and B-C are in love, but A-C hate each other), and you also hate it when nobody is in love. So, considering any three characters, you will be happy if exactly one pair is in love (A and B love each other, and C hates both A and B), or if all three pairs are in love (A loves B, B loves C, C loves A).
You are given a list of *m* known relationships in the anime. You know for sure that certain pairs love each other, and certain pairs hate each other. You're wondering how many ways you can fill in the remaining relationships so you are happy with every triangle. Two ways are considered different if two characters are in love in one way but hate each other in the other. Print this count modulo 1<=000<=000<=007.
Input Specification:
The first line of input will contain two integers *n*,<=*m* (3<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000).
The next *m* lines will contain the description of the known relationships. The *i*-th line will contain three integers *a**i*,<=*b**i*,<=*c**i*. If *c**i* is 1, then *a**i* and *b**i* are in love, otherwise, they hate each other (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*, ).
Each pair of people will be described no more than once.
Output Specification:
Print a single integer equal to the number of ways to fill in the remaining pairs so that you are happy with every triangle modulo 1<=000<=000<=007.
Demo Input:
['3 0\n', '4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n', '4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1\n']
Demo Output:
['4\n', '1\n', '0\n']
Note:
In the first sample, the four ways are to:
- Make everyone love each other - Make 1 and 2 love each other, and 3 hate 1 and 2 (symmetrically, we get 3 ways from this).
In the second sample, the only possible solution is to make 1 and 3 love each other and 2 and 4 hate each other. | ```python
class Node(object):
def __init__(self, label):
self.label = label
self.par = self
self.rank = 0
class DisjointSet(object):
def __init__(self, n):
self.n = n
self.nodes = [Node(i) for i in range(n)]
def find(self, u):
if u == u.par:
return u
return self.find(u.par)
def union(self, u, v):
u, v = self.find(u), self.find(v)
if u == v:
return False
if u.rank > v.rank:
u, v = v, u
u.par = v
if u.rank == v.rank:
v.rank += 1
return True
def size(self):
cnt = 0
for node in self.nodes:
if node.par == node:
cnt += 1
return cnt
def color(adj, colors, root):
neighbor_color = 1 - colors[root]
for neighbor in adj[root]:
if colors[neighbor] == -1:
colors[neighbor] = neighbor_color
x = color(adj, colors, neighbor)
if not x:
return False
else:
if colors[neighbor] != neighbor_color:
return False
return True
if __name__ == "__main__":
mod = 1000000007
n, m = map(int, input().split(" "))
dsu = DisjointSet(n)
reds = []
for _ in range(m):
a, b, c = map(int, input().split(" "))
if c == 0:
reds.append((a - 1, b - 1))
else:
dsu.union(dsu.nodes[a - 1], dsu.nodes[b - 1])
new_graph = {}
for i in range(n):
comp = dsu.find(dsu.nodes[i])
if comp not in new_graph.keys():
new_graph[comp] = len(new_graph)
dsu2 = DisjointSet(len(new_graph))
x = len(new_graph)
adj = [[] for _ in range(x)]
colors = [-1 for _ in range(x)]
for a, b in reds:
comp1 = dsu.find(dsu.nodes[a])
comp2 = dsu.find(dsu.nodes[b])
if comp1 == comp2:
print(0)
exit(0)
else:
index1 = new_graph[comp1]
index2 = new_graph[comp2]
dsu2.union(dsu2.nodes[index1], dsu2.nodes[index2])
adj[index1].append(index2)
adj[index2].append(index1)
for i in range(x):
if colors[i] == -1:
x = color(adj, colors, i)
if not x:
print(0)
exit(0)
comps = dsu2.size()
ans = 1
for _ in range(comps - 1):
ans *= 2
ans %= mod
print(ans)
``` | -1 |
|
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that.
Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them.
The English alphabet vowels are: A, E, I, O, U, Y
The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
"output": "NO"
},
{
"input": "sZecYdUvZHrXx?",
"output": "NO"
},
{
"input": "uMtXK?",
"output": "NO"
},
{
"input": "U?",
"output": "YES"
},
{
"input": "aqFDkCUKeHMyvZFcAyWlMUSQTFomtaWjoKLVyxLCw vcufPBFbaljOuHWiDCROYTcmbgzbaqHXKPOYEbuEtRqqoxBbOETCsQzhw?",
"output": "NO"
},
{
"input": "dJcNqQiFXzcbsj fItCpBLyXOnrSBPebwyFHlxUJHqCUzzCmcAvMiKL NunwOXnKeIxUZmBVwiCUfPkjRAkTPbkYCmwRRnDSLaz?",
"output": "NO"
},
{
"input": "gxzXbdcAQMuFKuuiPohtMgeypr wpDIoDSyOYTdvylcg SoEBZjnMHHYZGEqKgCgBeTbyTwyGuPZxkxsnSczotBdYyfcQsOVDVC?",
"output": "NO"
},
{
"input": "FQXBisXaJFMiHFQlXjixBDMaQuIbyqSBKGsBfTmBKCjszlGVZxEOqYYqRTUkGpSDDAoOXyXcQbHcPaegeOUBNeSD JiKOdECPOF?",
"output": "NO"
},
{
"input": "YhCuZnrWUBEed?",
"output": "NO"
},
{
"input": "hh?",
"output": "NO"
},
{
"input": "whU?",
"output": "YES"
},
{
"input": "fgwg?",
"output": "NO"
},
{
"input": "GlEmEPKrYcOnBNJUIFjszWUyVdvWw DGDjoCMtRJUburkPToCyDrOtMr?",
"output": "NO"
},
{
"input": "n?",
"output": "NO"
},
{
"input": "BueDOlxgzeNlxrzRrMbKiQdmGujEKmGxclvaPpTuHmTqBp?",
"output": "NO"
},
{
"input": "iehvZNQXDGCuVmJPOEysLyUryTdfaIxIuTzTadDbqRQGoCLXkxnyfWSGoLXebNnQQNTqAQJebbyYvHOfpUnXeWdjx?",
"output": "NO"
},
{
"input": " J ?",
"output": "NO"
},
{
"input": " j ?",
"output": "NO"
},
{
"input": " o ?",
"output": "YES"
},
{
"input": " T ?",
"output": "NO"
},
{
"input": " q ?",
"output": "NO"
},
{
"input": " j ?",
"output": "NO"
},
{
"input": " c ?",
"output": "NO"
},
{
"input": " B ?",
"output": "NO"
},
{
"input": "LuhxDHVwMPTtUIUMIQTuQETgXCOQPsfdFlyHvpfOVedjUTpGLAZGOHloIjJJtOLAlHPivzA?",
"output": "YES"
},
{
"input": "wmztmzFfwbGyOmNHENUFMTsFEMWYA?",
"output": "YES"
},
{
"input": "wGsfZCSwN PEUhNUrLfABrxA?",
"output": "YES"
},
{
"input": "mCDHENXjYbgMdBimAdPnewaHfpGWowjWrVAdvWczjw iDcUbyzMsmsnwbviiKiAyGVA?",
"output": "YES"
},
{
"input": "ARIWnwqFqxsQXsXXzHqvFjxOCttAGPUzDtWzsenPYdNXuFOIUGYZsLLK IaoxiyjBBRThoelwdPTkuCQfcBLUEJpCPIrVZlvUWA?",
"output": "YES"
},
{
"input": " PslvVpgpN BXkMFBEVXsyZFIQbBEFxGkYTeXKrOdcmhbiTUatYRUoYAayrchqbksswIlfIjerZPqptvCGnMUhyrQSvwltRhFzA?",
"output": "YES"
},
{
"input": "HpBkttwSjBXDmyleGiRWNUMPaAIE uzTrp KJDzaUiCdsMYOoWKHoUhWUoecCPmACymMUUbGav UMRpCytPETwNFAObZJA?",
"output": "YES"
}
] | 1,561,744,728 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 280 | 0 | s = input()
letters = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']
for i in range(len(s)):
if s[-i - 1].isalpha() and s[-i - 1] in letters:
print('YES')
exit()
if s[-i - 1].isalpha() and s[-i - 1] not in letters:
print('NO')
exit()
| Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that.
Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them.
The English alphabet vowels are: A, E, I, O, U, Y
The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z
Input Specification:
The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter.
Output Specification:
Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.
Demo Input:
['Is it a melon?\n', 'Is it an apple?\n', 'Is it a banana ?\n', 'Is it an apple and a banana simultaneouSLY?\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n', 'YES\n']
Note:
none | ```python
s = input()
letters = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']
for i in range(len(s)):
if s[-i - 1].isalpha() and s[-i - 1] in letters:
print('YES')
exit()
if s[-i - 1].isalpha() and s[-i - 1] not in letters:
print('NO')
exit()
``` | 3.93 |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,693,499,985 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 122 | 0 | import math
a, b = map(int, input().split())
if b < math.ceil(a/2):
print(2*(b-1)+1)
else:
print(2*(a-math.ceil(a/2))) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
Input Specification:
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the number that will stand at the position number *k* after Volodya's manipulations.
Demo Input:
['10 3\n', '7 7\n']
Demo Output:
['5', '6']
Note:
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | ```python
import math
a, b = map(int, input().split())
if b < math.ceil(a/2):
print(2*(b-1)+1)
else:
print(2*(a-math.ceil(a/2)))
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the *i*-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.
Formally, he or she selects a prime *p*<=<<=*X**i*<=-<=1 and then finds the minimum *X**i*<=≥<=*X**i*<=-<=1 such that *p* divides *X**i*. Note that if the selected prime *p* already divides *X**i*<=-<=1, then the number does not change.
Eve has witnessed the state of the game after two turns. Given *X*2, help her determine what is the smallest possible starting number *X*0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions. | The input contains a single integer *X*2 (4<=≤<=*X*2<=≤<=106). It is guaranteed that the integer *X*2 is composite, that is, is not prime. | Output a single integer — the minimum possible *X*0. | [
"14\n",
"20\n",
"8192\n"
] | [
"6\n",
"15\n",
"8191\n"
] | In the first test, the smallest possible starting number is *X*<sub class="lower-index">0</sub> = 6. One possible course of the game is as follows:
- Alice picks prime 5 and announces *X*<sub class="lower-index">1</sub> = 10 - Bob picks prime 7 and announces *X*<sub class="lower-index">2</sub> = 14.
In the second case, let *X*<sub class="lower-index">0</sub> = 15.
- Alice picks prime 2 and announces *X*<sub class="lower-index">1</sub> = 16 - Bob picks prime 5 and announces *X*<sub class="lower-index">2</sub> = 20. | 0 | [
{
"input": "14",
"output": "6"
},
{
"input": "20",
"output": "15"
},
{
"input": "8192",
"output": "8191"
},
{
"input": "1000000",
"output": "998677"
},
{
"input": "959806",
"output": "239958"
},
{
"input": "1452",
"output": "1206"
},
{
"input": "4",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "8",
"output": "7"
},
{
"input": "9",
"output": "7"
},
{
"input": "10",
"output": "4"
},
{
"input": "12",
"output": "6"
},
{
"input": "15",
"output": "8"
},
{
"input": "16",
"output": "11"
},
{
"input": "110880",
"output": "55440"
},
{
"input": "166320",
"output": "110879"
},
{
"input": "221760",
"output": "110880"
},
{
"input": "277200",
"output": "138600"
},
{
"input": "332640",
"output": "166320"
},
{
"input": "498960",
"output": "332639"
},
{
"input": "554400",
"output": "415798"
},
{
"input": "665280",
"output": "498958"
},
{
"input": "720720",
"output": "540538"
},
{
"input": "510510",
"output": "255248"
},
{
"input": "570570",
"output": "285282"
},
{
"input": "690690",
"output": "460455"
},
{
"input": "959818",
"output": "239958"
},
{
"input": "959878",
"output": "239978"
},
{
"input": "959902",
"output": "239978"
},
{
"input": "974847",
"output": "324954"
},
{
"input": "974859",
"output": "324978"
},
{
"input": "974931",
"output": "324980"
},
{
"input": "885481",
"output": "442272"
},
{
"input": "896809",
"output": "447944"
},
{
"input": "908209",
"output": "453632"
},
{
"input": "935089",
"output": "467064"
},
{
"input": "720721",
"output": "355298"
},
{
"input": "690691",
"output": "342864"
},
{
"input": "959903",
"output": "479702"
},
{
"input": "974932",
"output": "470060"
},
{
"input": "935090",
"output": "463950"
},
{
"input": "524288",
"output": "524287"
},
{
"input": "524289",
"output": "174768"
},
{
"input": "524286",
"output": "262110"
},
{
"input": "531441",
"output": "526737"
},
{
"input": "531442",
"output": "262490"
},
{
"input": "531440",
"output": "265704"
},
{
"input": "81",
"output": "76"
},
{
"input": "999958",
"output": "250008"
},
{
"input": "2048",
"output": "1959"
}
] | 1,520,700,670 | 4,570 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 62 | 5,632,000 | prime_number = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71
,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173
,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281
,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409
,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541
,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659
,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809
,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941
,947,953,967,971,977,983,991,997,1009]
num = int(input())
prev= 0
for prime in reversed(prime_number):
if (prime > num):
continue
if num % prime == 0:
prev = prime
break
val = 10000000
for i in range(num - prev +1, num + 1):
if i in prime_number:
continue
else:
for prime in reversed(prime_number):
if (prime > i):
continue
if i % prime== 0:
val = min(val, i - prime + 1)
break
print(val) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the *i*-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.
Formally, he or she selects a prime *p*<=<<=*X**i*<=-<=1 and then finds the minimum *X**i*<=≥<=*X**i*<=-<=1 such that *p* divides *X**i*. Note that if the selected prime *p* already divides *X**i*<=-<=1, then the number does not change.
Eve has witnessed the state of the game after two turns. Given *X*2, help her determine what is the smallest possible starting number *X*0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions.
Input Specification:
The input contains a single integer *X*2 (4<=≤<=*X*2<=≤<=106). It is guaranteed that the integer *X*2 is composite, that is, is not prime.
Output Specification:
Output a single integer — the minimum possible *X*0.
Demo Input:
['14\n', '20\n', '8192\n']
Demo Output:
['6\n', '15\n', '8191\n']
Note:
In the first test, the smallest possible starting number is *X*<sub class="lower-index">0</sub> = 6. One possible course of the game is as follows:
- Alice picks prime 5 and announces *X*<sub class="lower-index">1</sub> = 10 - Bob picks prime 7 and announces *X*<sub class="lower-index">2</sub> = 14.
In the second case, let *X*<sub class="lower-index">0</sub> = 15.
- Alice picks prime 2 and announces *X*<sub class="lower-index">1</sub> = 16 - Bob picks prime 5 and announces *X*<sub class="lower-index">2</sub> = 20. | ```python
prime_number = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71
,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173
,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281
,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409
,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541
,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659
,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809
,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941
,947,953,967,971,977,983,991,997,1009]
num = int(input())
prev= 0
for prime in reversed(prime_number):
if (prime > num):
continue
if num % prime == 0:
prev = prime
break
val = 10000000
for i in range(num - prev +1, num + 1):
if i in prime_number:
continue
else:
for prime in reversed(prime_number):
if (prime > i):
continue
if i % prime== 0:
val = min(val, i - prime + 1)
break
print(val)
``` | 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,504,554,302 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 204,800 | from sys import stdin, stdout
INF = float('inf')
def angle(a, b):
return (a[0] * b[1] - a[1] * b[0])
def find_coordinates(x1, y1, x2, y2, x3, y3):
A = x2 - x1
B = y2 - y1
C = x3 - x1
D = y3 - y1
E = A * (x1 + x2) + B * (y1 + y2)
F = C * (x1 + x3) + D * (y1 + y3)
G = 2 * (A * (y3 - y2) - B * (x3 - x2))
if not G:
return (INF, INF)
x = (D * E - B * F) / G
y = (A * F - C * E) / G
return (x, y)
def find_R(x1, y1, x2, y2, x3, y3):
first, second, third = (x2 - x1, y2 - y1), (x3 - x2, y3 - y2), (x1 - x3, y1 - y3)
a = (first[0] ** 2 + first[1] ** 2) ** 0.5
b = (second[0] ** 2 + second[1] ** 2) ** 0.5
c = (third[0] ** 2 + third[1] ** 2) ** 0.5
if not angle(first, second):
return 1
else:
return (a * b * c) / (2 * abs(angle(first, second)))
x1, y1, x2, y2, x3, y3 = map(int, stdin.readline().split())
challengers = [find_coordinates(x1, y1, x2, y2, x3, y3), find_coordinates(x1, y1, x3, y3, x2, y2), find_coordinates(x2, y2, x1, y1, x3, y3), find_coordinates(x2, y2, x3, y3, x1, y1), find_coordinates(x3, y3, x1, y1, x2, y2), find_coordinates(x3, y3, x2, y2, x1, y1)]
R = find_R(x1, y1, x2, y2, x3, y3)
label = 0
for x, y in challengers:
if x == INF:
continue
first, second, third = (x1 - x, y1 - y), (x2 - x, y2 - y), (x3 - x, y3 - y)
print(((x - x1) ** 2 + (y - y1) ** 2) ** 0.5)
if angle(first, second) == angle(second, third) and ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5 == R and ((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 == R and ((x - x3) ** 2 + (y - y3) ** 2) ** 0.5 == R:
label = 1
if label:
stdout.write('Yes')
else:
stdout.write('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
from sys import stdin, stdout
INF = float('inf')
def angle(a, b):
return (a[0] * b[1] - a[1] * b[0])
def find_coordinates(x1, y1, x2, y2, x3, y3):
A = x2 - x1
B = y2 - y1
C = x3 - x1
D = y3 - y1
E = A * (x1 + x2) + B * (y1 + y2)
F = C * (x1 + x3) + D * (y1 + y3)
G = 2 * (A * (y3 - y2) - B * (x3 - x2))
if not G:
return (INF, INF)
x = (D * E - B * F) / G
y = (A * F - C * E) / G
return (x, y)
def find_R(x1, y1, x2, y2, x3, y3):
first, second, third = (x2 - x1, y2 - y1), (x3 - x2, y3 - y2), (x1 - x3, y1 - y3)
a = (first[0] ** 2 + first[1] ** 2) ** 0.5
b = (second[0] ** 2 + second[1] ** 2) ** 0.5
c = (third[0] ** 2 + third[1] ** 2) ** 0.5
if not angle(first, second):
return 1
else:
return (a * b * c) / (2 * abs(angle(first, second)))
x1, y1, x2, y2, x3, y3 = map(int, stdin.readline().split())
challengers = [find_coordinates(x1, y1, x2, y2, x3, y3), find_coordinates(x1, y1, x3, y3, x2, y2), find_coordinates(x2, y2, x1, y1, x3, y3), find_coordinates(x2, y2, x3, y3, x1, y1), find_coordinates(x3, y3, x1, y1, x2, y2), find_coordinates(x3, y3, x2, y2, x1, y1)]
R = find_R(x1, y1, x2, y2, x3, y3)
label = 0
for x, y in challengers:
if x == INF:
continue
first, second, third = (x1 - x, y1 - y), (x2 - x, y2 - y), (x3 - x, y3 - y)
print(((x - x1) ** 2 + (y - y1) ** 2) ** 0.5)
if angle(first, second) == angle(second, third) and ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5 == R and ((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 == R and ((x - x3) ** 2 + (y - y3) ** 2) ** 0.5 == R:
label = 1
if label:
stdout.write('Yes')
else:
stdout.write('No')
``` | 0 |
|
257 | A | Sockets | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | null | null | Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of *k* electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) — number *a**i* stands for the number of sockets on the *i*-th supply-line filter. | Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1. | [
"3 5 3\n3 1 2\n",
"4 7 2\n3 3 2 4\n",
"5 5 1\n1 3 1 2 1\n"
] | [
"1\n",
"2\n",
"-1\n"
] | In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter. | 500 | [
{
"input": "3 5 3\n3 1 2",
"output": "1"
},
{
"input": "4 7 2\n3 3 2 4",
"output": "2"
},
{
"input": "5 5 1\n1 3 1 2 1",
"output": "-1"
},
{
"input": "4 5 8\n3 2 4 3",
"output": "0"
},
{
"input": "5 10 1\n4 3 4 2 4",
"output": "3"
},
{
"input": "7 13 2\n5 3 4 1 2 1 2",
"output": "5"
},
{
"input": "7 17 5\n1 6 2 1 1 4 3",
"output": "-1"
},
{
"input": "10 25 7\n5 7 4 8 3 3 5 4 5 5",
"output": "4"
},
{
"input": "10 8 4\n1 1 2 1 3 1 3 1 4 2",
"output": "2"
},
{
"input": "13 20 9\n2 9 2 2 5 11 10 10 13 4 6 11 14",
"output": "1"
},
{
"input": "9 30 8\n3 6 10 8 1 5 3 9 3",
"output": "3"
},
{
"input": "15 26 4\n3 6 7 1 5 2 4 4 7 3 8 7 2 4 8",
"output": "4"
},
{
"input": "20 20 3\n6 6 5 1 7 8 8 6 10 7 8 5 6 8 1 7 10 6 2 7",
"output": "2"
},
{
"input": "10 30 5\n4 5 3 3 4 4 4 3 5 1",
"output": "9"
},
{
"input": "20 30 1\n12 19 16 2 11 19 1 15 13 13 3 10 1 18 7 5 6 8 9 1",
"output": "2"
},
{
"input": "50 50 2\n2 2 4 5 2 1 5 4 5 4 5 2 1 2 3 3 5 1 2 2 1 3 4 5 5 4 3 2 2 1 3 2 3 2 4 4 1 3 5 4 3 2 4 3 4 4 4 4 3 4",
"output": "14"
},
{
"input": "5 50 6\n2 1 3 1 3",
"output": "-1"
},
{
"input": "20 50 10\n5 4 3 6 3 7 2 3 7 8 6 3 8 3 3 5 1 9 6 2",
"output": "7"
},
{
"input": "40 40 3\n2 1 4 2 4 2 3 3 3 3 1 2 3 2 2 3 4 2 3 1 2 4 1 4 1 4 3 3 1 1 3 1 3 4 4 3 1 1 2 4",
"output": "14"
},
{
"input": "33 49 16\n40 16 48 49 30 28 8 6 48 39 48 6 24 28 30 35 12 23 49 29 31 8 40 18 16 34 43 15 12 33 14 24 13",
"output": "1"
},
{
"input": "10 49 11\n5 18 1 19 11 11 16 5 6 6",
"output": "3"
},
{
"input": "50 30 1\n2 1 2 1 2 3 3 1 2 2 3 2 1 3 1 3 1 2 2 3 2 1 3 1 1 2 3 2 2 1 1 3 3 2 2 2 3 2 3 3 3 3 1 1 3 1 1 3 1 3",
"output": "15"
},
{
"input": "50 50 2\n1 2 3 2 1 2 4 2 3 4 3 1 3 2 2 3 1 4 2 1 4 4 2 2 2 3 2 3 1 1 4 4 1 1 2 3 4 2 2 3 4 3 4 3 3 3 2 3 1 1",
"output": "19"
},
{
"input": "49 49 3\n8 8 8 7 5 6 6 8 1 3 1 8 8 3 2 1 2 2 5 4 4 7 8 7 6 4 2 5 7 3 4 2 3 2 3 4 5 7 3 3 4 5 5 8 2 5 1 1 7",
"output": "7"
},
{
"input": "4 50 1\n3 11 5 5",
"output": "-1"
},
{
"input": "50 5 1\n1 1 1 1 1 1 1 2 1 1 2 2 2 2 1 2 1 2 1 2 2 1 1 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 1 2 1 1 2 1 1 2 1 2",
"output": "4"
},
{
"input": "50 23 2\n2 1 2 2 3 2 1 2 3 3 3 1 3 1 3 2 1 3 2 2 1 1 3 2 2 1 1 3 2 1 2 3 2 2 2 2 1 3 1 2 2 3 3 1 3 3 3 1 2 3",
"output": "11"
},
{
"input": "49 19 2\n3 2 3 2 3 3 2 3 3 1 2 1 2 3 2 3 1 3 1 3 1 3 2 2 2 2 3 3 1 1 2 3 2 3 1 2 3 3 1 1 3 1 1 3 1 1 1 2 3",
"output": "9"
},
{
"input": "10 50 5\n23 18 15 23 26 23 4 29 15 25",
"output": "2"
},
{
"input": "15 38 3\n3 5 5 5 4 1 3 1 5 4 2 4 3 1 1",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "3 6 3\n2 2 2",
"output": "3"
},
{
"input": "1 7 4\n1",
"output": "-1"
},
{
"input": "47 7 4\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",
"output": "-1"
}
] | 1,585,747,495 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 280 | 0 | from sys import stdin,stdout
ii1 = lambda: int(stdin.readline())
is1 = lambda: stdin.readline()
iia = lambda : map(int, stdin.readline().split())
isa = lambda: stdin.readline().split()
n, m, k = iia()
arr = sorted(iia(),reverse = True)
count = 0
for i in arr:
if m <= k:
print(count)
break
elif m - i <= 0 and k>0:
print(count+1)
break
else:
count += 1
m -= i
k -= 1
else:
if m <= 0 and k>0:
print(count)
else:
print(-1) | Title: Sockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of *k* electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) — number *a**i* stands for the number of sockets on the *i*-th supply-line filter.
Output Specification:
Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Demo Input:
['3 5 3\n3 1 2\n', '4 7 2\n3 3 2 4\n', '5 5 1\n1 3 1 2 1\n']
Demo Output:
['1\n', '2\n', '-1\n']
Note:
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter. | ```python
from sys import stdin,stdout
ii1 = lambda: int(stdin.readline())
is1 = lambda: stdin.readline()
iia = lambda : map(int, stdin.readline().split())
isa = lambda: stdin.readline().split()
n, m, k = iia()
arr = sorted(iia(),reverse = True)
count = 0
for i in arr:
if m <= k:
print(count)
break
elif m - i <= 0 and k>0:
print(count+1)
break
else:
count += 1
m -= i
k -= 1
else:
if m <= 0 and k>0:
print(count)
else:
print(-1)
``` | 3 |
|
617 | B | Chocolate | PROGRAMMING | 1,300 | [
"combinatorics"
] | null | null | Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.
You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't.
Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of pieces in the chocolate bar.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1), where 0 represents a piece without the nut and 1 stands for a piece with the nut. | Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut. | [
"3\n0 1 0\n",
"5\n1 0 1 0 1\n"
] | [
"1\n",
"4\n"
] | In the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks.
In the second sample you can break the bar in four ways:
10|10|1
1|010|1
10|1|01
1|01|01 | 1,000 | [
{
"input": "3\n0 1 0",
"output": "1"
},
{
"input": "5\n1 0 1 0 1",
"output": "4"
},
{
"input": "10\n0 0 1 0 0 0 1 1 0 1",
"output": "8"
},
{
"input": "20\n0 0 0 0 1 1 1 0 1 0 0 1 0 1 1 0 1 1 1 0",
"output": "24"
},
{
"input": "50\n0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 0 1 0 1 1 0 1 0 0 1 1 1 1 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0",
"output": "11520"
},
{
"input": "99\n0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 0 0 0 0 0 1 1 0 1 0 0 0 1 0 1 1 0 1 1 0 0 0 1 0 1 0 0 0 0 1 1 1 1 1 0 0 1 0 1 0 0 0 0 0 0 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": "17694720"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "100\n1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1",
"output": "5559060566555523"
},
{
"input": "41\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",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "18\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"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": "1"
},
{
"input": "10\n0 1 0 0 0 0 1 0 0 1",
"output": "15"
},
{
"input": "10\n1 1 0 0 0 1 1 1 1 0",
"output": "4"
},
{
"input": "50\n1 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 1 1",
"output": "186624"
},
{
"input": "50\n0 0 1 1 0 0 0 1 0 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 1 1 1 1 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1",
"output": "122880"
},
{
"input": "99\n1 1 1 1 0 1 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 1 1 0 0 0 1 0 1 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0 1 0 0 1 1 0 0 0 0 1 1 1 1 1 0 1 0 0 1 1 1 0 0",
"output": "27869184000"
},
{
"input": "99\n1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1 0 0 1 0 0 1 1 1 0 1 1 0 0 1 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 0 1 1 0 0 1 0 0 1 1 1",
"output": "123834728448"
},
{
"input": "100\n1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 1 0 1 0",
"output": "773967052800"
},
{
"input": "100\n0 1 1 0 1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0 1 1 1 1 0 1 1 1 1 0 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 0 1",
"output": "38698352640"
},
{
"input": "100\n1 1 1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0",
"output": "72236924928"
},
{
"input": "100\n1 1 0 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 1 1 1 1 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1",
"output": "58047528960"
},
{
"input": "100\n0 1 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 1 0 1 1 1 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 1 0 1 0 1 0 0 0 1 1 0 1 1 0 1 1 1 1 0",
"output": "73987522560"
},
{
"input": "100\n1 1 0 1 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 1 0 1 0 1 1 1 0 1 1 0 1 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 1 1 1 1 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 1 0",
"output": "180592312320"
},
{
"input": "100\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1",
"output": "1900000000"
}
] | 1,694,574,135 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | def break_chocolate(n, pieces):
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
dp[i] = 0
for j in range(i):
if pieces[i - 1] == 1 or (i == n and j == 0):
dp[i] += dp[j]
return dp[n]
n = int(input())
chocolate = list(map(int, input().split()))
print(break_chocolate(n, chocolate))
| Title: Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.
You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't.
Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of pieces in the chocolate bar.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.
Output Specification:
Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.
Demo Input:
['3\n0 1 0\n', '5\n1 0 1 0 1\n']
Demo Output:
['1\n', '4\n']
Note:
In the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks.
In the second sample you can break the bar in four ways:
10|10|1
1|010|1
10|1|01
1|01|01 | ```python
def break_chocolate(n, pieces):
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
dp[i] = 0
for j in range(i):
if pieces[i - 1] == 1 or (i == n and j == 0):
dp[i] += dp[j]
return dp[n]
n = int(input())
chocolate = list(map(int, input().split()))
print(break_chocolate(n, chocolate))
``` | 0 |
|
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded.
Determine the number of ways to choose a subset of participants that will receive the diplomas. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero scores cannot get anything. | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
"input": "100\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600",
"output": "94"
},
{
"input": "100\n600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600",
"output": "1"
},
{
"input": "78\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12",
"output": "13"
},
{
"input": "34\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391",
"output": "33"
},
{
"input": "100\n1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3",
"output": "3"
},
{
"input": "100\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55",
"output": "93"
},
{
"input": "99\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13",
"output": "13"
},
{
"input": "99\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1",
"output": "1"
},
{
"input": "99\n21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37",
"output": "61"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n0 600",
"output": "1"
},
{
"input": "4\n1 1 1 2",
"output": "2"
},
{
"input": "4\n0 0 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "2\n0 5",
"output": "1"
},
{
"input": "5\n1 0 0 1 2",
"output": "2"
}
] | 1,584,684,029 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 0 | n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(len(l)):
if l[i]==0:
count += 1
for j in range(count):
l.remove(0)
print(len(set(l)))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded.
Determine the number of ways to choose a subset of participants that will receive the diplomas.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score.
Output Specification:
Print a single integer — the desired number of ways.
Demo Input:
['4\n1 3 3 2\n', '3\n1 1 1\n', '4\n42 0 0 42\n']
Demo Output:
['3\n', '1\n', '1\n']
Note:
There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero scores cannot get anything. | ```python
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(len(l)):
if l[i]==0:
count += 1
for j in range(count):
l.remove(0)
print(len(set(l)))
``` | 3 |
|
979 | B | Treasure Hunt | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $7$ because its subribbon a appears $7$ times, and the ribbon abcdabc has the beauty of $2$ because its subribbon abc appears twice.
The rules are simple. The game will have $n$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $n$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally? | The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors. | Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". | [
"3\nKuroo\nShiro\nKatie\n",
"7\ntreasurehunt\nthreefriends\nhiCodeforces\n",
"1\nabcabc\ncbabac\nababca\n",
"15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n"
] | [
"Kuro\n",
"Shiro\n",
"Katie\n",
"Draw\n"
] | In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is $9$ and the number of turn is $15$, everyone can change their ribbons in some way to reach the maximal beauty of $9$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw. | 1,000 | [
{
"input": "3\nKuroo\nShiro\nKatie",
"output": "Kuro"
},
{
"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces",
"output": "Shiro"
},
{
"input": "1\nabcabc\ncbabac\nababca",
"output": "Katie"
},
{
"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE",
"output": "Draw"
},
{
"input": "1\naaaaaaaaaa\nAAAAAAcAAA\nbbbbbbzzbb",
"output": "Shiro"
},
{
"input": "60\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ",
"output": "Draw"
},
{
"input": "9174\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd",
"output": "Draw"
},
{
"input": "727\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef",
"output": "Draw"
},
{
"input": "61\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub",
"output": "Katie"
},
{
"input": "30\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr",
"output": "Draw"
},
{
"input": "3\nabcabcabcabcdddabc\nzxytzytxxtytxyzxyt\nfgffghfghffgghghhh",
"output": "Katie"
},
{
"input": "3\naaaaa\naaaaa\naaaab",
"output": "Draw"
},
{
"input": "3\naaaaaaa\naaaabcd\nabcdefg",
"output": "Draw"
},
{
"input": "3\naaaaaaa\naaabcde\nabcdefg",
"output": "Kuro"
},
{
"input": "3\naaaaaaa\naaaabbb\nabcdefg",
"output": "Draw"
},
{
"input": "3\naaa\nbbb\nabc",
"output": "Draw"
},
{
"input": "3\naaaaa\nabcde\nabcde",
"output": "Kuro"
},
{
"input": "3\naaaaa\nqwert\nlkjhg",
"output": "Kuro"
},
{
"input": "3\naaaaa\nbbbbb\naabcd",
"output": "Draw"
},
{
"input": "3\nabcde\nfghij\nkkkkk",
"output": "Katie"
},
{
"input": "4\naaaabcd\naaaabcd\naaaaaaa",
"output": "Draw"
},
{
"input": "3\naaaabb\naabcde\nabcdef",
"output": "Kuro"
},
{
"input": "2\naaab\nabcd\naaaa",
"output": "Draw"
},
{
"input": "3\naaaaaa\naaaaaa\nabcdef",
"output": "Draw"
},
{
"input": "1\nAAAAA\nBBBBB\nABCDE",
"output": "Draw"
},
{
"input": "1\nabcde\naaaaa\naaaaa",
"output": "Draw"
},
{
"input": "4\naaabbb\nabfcde\nabfcde",
"output": "Kuro"
},
{
"input": "0\naaa\naab\nccd",
"output": "Kuro"
},
{
"input": "3\naaaaa\naaaaa\naabbb",
"output": "Draw"
},
{
"input": "3\nxxxxxx\nxxxooo\nabcdef",
"output": "Draw"
},
{
"input": "2\noooo\naaac\nabcd",
"output": "Draw"
},
{
"input": "1\naaaaaaa\naaabcde\nabcdefg",
"output": "Kuro"
},
{
"input": "3\nooooo\naaabb\nabcde",
"output": "Draw"
},
{
"input": "3\naaaaa\nqwert\nqwery",
"output": "Kuro"
},
{
"input": "2\naaaaaa\nbbbbbb\naaaaab",
"output": "Draw"
},
{
"input": "3\naabb\naabb\naabc",
"output": "Draw"
},
{
"input": "2\naaa\naab\naab",
"output": "Draw"
},
{
"input": "3\nbbbbcc\nbbbbbb\nsadfgh",
"output": "Draw"
},
{
"input": "3\naaaaaacc\nxxxxkkkk\nxxxxkkkk",
"output": "Kuro"
},
{
"input": "2\naaaac\nbbbbc\nccccc",
"output": "Draw"
},
{
"input": "3\naaaaaaaaa\naaabbbbbb\nabcdewert",
"output": "Draw"
},
{
"input": "3\naaabc\naaaab\nabcde",
"output": "Draw"
},
{
"input": "3\naaaaaaaa\naaaaaaab\naaaabbbb",
"output": "Draw"
},
{
"input": "2\nabcdefg\nabccccc\nacccccc",
"output": "Draw"
},
{
"input": "3\naaaaa\naabcd\nabcde",
"output": "Draw"
},
{
"input": "4\naaabbb\nabcdef\nabcdef",
"output": "Kuro"
},
{
"input": "4\naaabbb\naabdef\nabcdef",
"output": "Draw"
},
{
"input": "3\nabba\nbbbb\naaaa",
"output": "Draw"
},
{
"input": "3\naaaaa\nbbaaa\nabcde",
"output": "Draw"
},
{
"input": "2\naaa\naaa\nabc",
"output": "Draw"
},
{
"input": "3\naaaaa\nabcda\nabcde",
"output": "Draw"
},
{
"input": "3\naaaaa\nabcde\nbcdef",
"output": "Kuro"
},
{
"input": "3\naaabb\naabbc\nqwert",
"output": "Draw"
},
{
"input": "3\naaaaaa\naabbcc\naabbcc",
"output": "Kuro"
},
{
"input": "3\nAAAAAA\nAAAAAB\nABCDEF",
"output": "Draw"
},
{
"input": "3\nabc\naac\nbbb",
"output": "Draw"
},
{
"input": "2\naaaab\naabbc\naabbc",
"output": "Kuro"
},
{
"input": "2\naaaaaab\naaaaabb\nabcdefg",
"output": "Draw"
},
{
"input": "3\naaaaaaaaaaa\nbbbbbbbbaaa\nqwertyuiasd",
"output": "Draw"
},
{
"input": "3\naaaa\nbbbb\naabb",
"output": "Draw"
},
{
"input": "3\naaaabb\naaabcd\nabcdef",
"output": "Draw"
},
{
"input": "3\naaa\nabc\nbbb",
"output": "Draw"
},
{
"input": "1\naa\nab\nbb",
"output": "Shiro"
},
{
"input": "1\naacb\nabcd\naaaa",
"output": "Draw"
},
{
"input": "3\naaaabb\naaabbb\nabcdef",
"output": "Draw"
},
{
"input": "3\naaaa\naaaa\nabcd",
"output": "Draw"
},
{
"input": "2\nabcd\nabcd\naaad",
"output": "Katie"
},
{
"input": "3\naaa\nbbb\naab",
"output": "Draw"
},
{
"input": "3\naaaaaa\naaaaab\naaaaaa",
"output": "Draw"
},
{
"input": "2\naaab\nabcd\nabcd",
"output": "Kuro"
},
{
"input": "3\nooooo\nShiro\nKatie",
"output": "Kuro"
},
{
"input": "3\naaabb\naabcd\nabcde",
"output": "Draw"
},
{
"input": "4\nabcd\nabcd\naaaa",
"output": "Draw"
},
{
"input": "4\naaa\nbbb\naab",
"output": "Draw"
},
{
"input": "2\nxxxx\nyyyx\nabcd",
"output": "Draw"
},
{
"input": "3\nAAAAA\nAAAAB\nABCDE",
"output": "Draw"
},
{
"input": "3\naaaacdc\naaaaabc\naaaaabc",
"output": "Draw"
},
{
"input": "3\naaaaaa\naabcde\naabcde",
"output": "Kuro"
},
{
"input": "3\naaabb\naaabb\naaaaa",
"output": "Draw"
},
{
"input": "5\nabbbbb\ncbbbbb\nabcdef",
"output": "Draw"
},
{
"input": "3\naaaaaaaaa\naaaaabbbb\naaaaabbbb",
"output": "Kuro"
},
{
"input": "4\naaaaaab\naaabbbb\naaabbbb",
"output": "Draw"
},
{
"input": "3\naaaabb\naaaabb\naaabbb",
"output": "Draw"
},
{
"input": "2\naaaabb\naaaaab\nabcdef",
"output": "Draw"
},
{
"input": "2\naaaaa\naaaae\nabcde",
"output": "Draw"
},
{
"input": "3\naaaaaa\nbbbcde\nabcdef",
"output": "Draw"
},
{
"input": "4\naaaabbb\naabcdef\naabcdef",
"output": "Kuro"
},
{
"input": "2\naaaaa\naaaab\nabcde",
"output": "Draw"
},
{
"input": "3\naabbbbb\naaabbbb\nabcdefg",
"output": "Draw"
},
{
"input": "3\nabcde\naabcd\naaaaa",
"output": "Draw"
},
{
"input": "5\naaabbcc\nabcdefg\nabcdefg",
"output": "Kuro"
},
{
"input": "3\naabbb\nabcde\nabcde",
"output": "Kuro"
},
{
"input": "0\nbbb\nabb\nqer",
"output": "Kuro"
},
{
"input": "5\naabbbbb\naaaaaaa\nabcdefg",
"output": "Draw"
},
{
"input": "2\naaaab\naaaab\naaabb",
"output": "Draw"
},
{
"input": "2\naaaaaab\naaaabbb\naaaaccc",
"output": "Kuro"
},
{
"input": "3\naaaaaaaaaaaa\naaaaaaaaaaab\naaaaaabbbbbb",
"output": "Draw"
},
{
"input": "3\naaabb\nabcde\naaaaa",
"output": "Draw"
},
{
"input": "3\naaaaaac\naaaaebc\naaaaaac",
"output": "Draw"
},
{
"input": "3\naaaaaa\naaabbb\nqwerty",
"output": "Draw"
},
{
"input": "3\ncccca\nabcde\nabcde",
"output": "Kuro"
},
{
"input": "100005\nAA\nBC\nCC",
"output": "Draw"
},
{
"input": "3\naaaa\nbbbb\nccca",
"output": "Draw"
},
{
"input": "3\naaaaa\nbcdef\nbcdef",
"output": "Kuro"
},
{
"input": "2\naaab\naabb\nqwer",
"output": "Draw"
},
{
"input": "3\nabcddd\nabcdef\nbbaaaa",
"output": "Draw"
},
{
"input": "2\naaaa\naaaa\naabc",
"output": "Draw"
},
{
"input": "3\naaaa\naaaa\naaab",
"output": "Draw"
},
{
"input": "3\nabcddd\nabcdef\naaaaaa",
"output": "Draw"
},
{
"input": "1\naaaa\nabcd\naaab",
"output": "Katie"
}
] | 1,666,098,147 | 1,047 | PyPy 3 | OK | TESTS | 184 | 93 | 4,505,600 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
x = [0] * 3
for i in range(3):
s = list(input().rstrip())
cnt = [0] * 130
for j in s:
cnt[j] += 1
m = max(cnt)
c = min(m + n, len(s))
if m == len(s) and n == 1:
c = m - 1
x[i] = c
ma = max(x)
ans = []
d = ["Kuro", "Shiro", "Katie"]
for i in range(3):
if ma == x[i]:
ans.append(d[i])
if len(ans) ^ 1:
ans = ["Draw"]
ans = ans[0]
print(ans) | Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $7$ because its subribbon a appears $7$ times, and the ribbon abcdabc has the beauty of $2$ because its subribbon abc appears twice.
The rules are simple. The game will have $n$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $n$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
Input Specification:
The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
Output Specification:
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
Demo Input:
['3\nKuroo\nShiro\nKatie\n', '7\ntreasurehunt\nthreefriends\nhiCodeforces\n', '1\nabcabc\ncbabac\nababca\n', '15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n']
Demo Output:
['Kuro\n', 'Shiro\n', 'Katie\n', 'Draw\n']
Note:
In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is $9$ and the number of turn is $15$, everyone can change their ribbons in some way to reach the maximal beauty of $9$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw. | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
x = [0] * 3
for i in range(3):
s = list(input().rstrip())
cnt = [0] * 130
for j in s:
cnt[j] += 1
m = max(cnt)
c = min(m + n, len(s))
if m == len(s) and n == 1:
c = m - 1
x[i] = c
ma = max(x)
ans = []
d = ["Kuro", "Shiro", "Katie"]
for i in range(3):
if ma == x[i]:
ans.append(d[i])
if len(ans) ^ 1:
ans = ["Draw"]
ans = ans[0]
print(ans)
``` | 3 |
|
818 | E | Card Game Again | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"number theory",
"two pointers"
] | null | null | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck.
After receiving the deck and the magic number, Vova removes *x* (possibly *x*<==<=0) cards from the top of the deck, *y* (possibly *y*<==<=0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards *x*<=+<=1, *x*<=+<=2, ... *n*<=-<=*y*<=-<=1, *n*<=-<=*y* from the original deck.
Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by *k*. So Vova received a deck (possibly not a valid one) and a number *k*, and now he wonders, how many ways are there to choose *x* and *y* so the deck he will get after removing *x* cards from the top and *y* cards from the bottom is valid? | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the numbers written on the cards. | Print the number of ways to choose *x* and *y* so the resulting deck is valid. | [
"3 4\n6 2 8\n",
"3 6\n9 1 14\n"
] | [
"4\n",
"1\n"
] | In the first example the possible values of *x* and *y* are:
1. *x* = 0, *y* = 0; 1. *x* = 1, *y* = 0; 1. *x* = 2, *y* = 0; 1. *x* = 0, *y* = 1. | 0 | [
{
"input": "3 4\n6 2 8",
"output": "4"
},
{
"input": "3 6\n9 1 14",
"output": "1"
},
{
"input": "5 1\n1 3 1 3 1",
"output": "15"
},
{
"input": "5 1\n5 5 5 5 5",
"output": "15"
},
{
"input": "5 1\n5 4 4 4 4",
"output": "15"
},
{
"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "5050"
},
{
"input": "100 1\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1",
"output": "5050"
},
{
"input": "100 5\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5",
"output": "4713"
},
{
"input": "100 6\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3",
"output": "4580"
},
{
"input": "100 72\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5",
"output": "4549"
},
{
"input": "100 72\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3",
"output": "4123"
},
{
"input": "2 999634589\n31607 31627",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 2\n1",
"output": "0"
},
{
"input": "1 3\n1",
"output": "0"
},
{
"input": "1 4\n1",
"output": "0"
},
{
"input": "1 5\n3",
"output": "0"
},
{
"input": "1 6\n4",
"output": "0"
},
{
"input": "1 7\n2",
"output": "0"
},
{
"input": "1 8\n3",
"output": "0"
},
{
"input": "1 9\n5",
"output": "0"
},
{
"input": "1 10\n3",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "3"
},
{
"input": "2 2\n2 2",
"output": "3"
},
{
"input": "2 3\n1 2",
"output": "0"
},
{
"input": "2 4\n1 2",
"output": "0"
},
{
"input": "2 5\n1 1",
"output": "0"
},
{
"input": "2 6\n2 1",
"output": "0"
},
{
"input": "2 7\n1 4",
"output": "0"
},
{
"input": "2 8\n5 3",
"output": "0"
},
{
"input": "2 9\n2 2",
"output": "0"
},
{
"input": "2 10\n6 1",
"output": "0"
},
{
"input": "3 1\n1 1 1",
"output": "6"
},
{
"input": "3 2\n2 2 1",
"output": "5"
},
{
"input": "3 3\n2 1 2",
"output": "0"
},
{
"input": "3 4\n2 2 2",
"output": "3"
},
{
"input": "3 5\n1 1 2",
"output": "0"
},
{
"input": "3 6\n4 3 2",
"output": "3"
},
{
"input": "3 7\n3 4 1",
"output": "0"
},
{
"input": "3 8\n5 1 4",
"output": "0"
},
{
"input": "3 9\n3 2 1",
"output": "0"
},
{
"input": "3 10\n6 5 5",
"output": "2"
},
{
"input": "4 1\n1 1 1 1",
"output": "10"
},
{
"input": "4 2\n2 2 1 2",
"output": "9"
},
{
"input": "4 3\n2 1 1 1",
"output": "0"
},
{
"input": "4 4\n2 2 1 1",
"output": "3"
},
{
"input": "4 5\n2 3 2 1",
"output": "0"
},
{
"input": "4 6\n1 1 3 3",
"output": "0"
},
{
"input": "4 7\n1 1 2 2",
"output": "0"
},
{
"input": "4 8\n5 4 5 5",
"output": "0"
},
{
"input": "4 9\n1 1 4 2",
"output": "0"
},
{
"input": "4 10\n2 6 2 1",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "15"
},
{
"input": "5 2\n2 2 1 2 1",
"output": "13"
},
{
"input": "5 3\n2 1 1 2 1",
"output": "0"
},
{
"input": "5 4\n2 2 1 3 1",
"output": "4"
},
{
"input": "5 5\n2 3 1 1 3",
"output": "0"
},
{
"input": "5 6\n3 4 3 4 3",
"output": "10"
},
{
"input": "5 7\n3 1 3 2 4",
"output": "0"
},
{
"input": "5 8\n2 2 3 3 1",
"output": "0"
},
{
"input": "5 9\n3 1 3 3 4",
"output": "7"
},
{
"input": "5 10\n3 6 6 1 5",
"output": "3"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "21"
},
{
"input": "6 2\n1 2 2 1 1 1",
"output": "14"
},
{
"input": "6 3\n2 2 2 2 1 2",
"output": "0"
},
{
"input": "6 4\n1 3 3 3 3 2",
"output": "0"
},
{
"input": "6 5\n2 3 3 2 1 2",
"output": "0"
},
{
"input": "6 6\n1 2 4 1 4 4",
"output": "0"
},
{
"input": "6 7\n2 2 4 3 2 1",
"output": "0"
},
{
"input": "6 8\n3 2 3 5 5 3",
"output": "0"
},
{
"input": "6 9\n1 4 1 2 1 1",
"output": "0"
},
{
"input": "6 10\n1 2 5 6 6 6",
"output": "11"
},
{
"input": "7 1\n1 1 1 1 1 1 1",
"output": "28"
},
{
"input": "7 2\n1 1 2 2 2 2 1",
"output": "24"
},
{
"input": "7 3\n2 2 1 1 2 2 2",
"output": "0"
},
{
"input": "7 4\n3 2 1 2 1 1 1",
"output": "8"
},
{
"input": "7 5\n2 3 3 3 2 3 2",
"output": "0"
},
{
"input": "7 6\n3 4 4 1 4 3 2",
"output": "15"
},
{
"input": "7 7\n4 2 4 4 1 4 4",
"output": "0"
},
{
"input": "7 8\n4 4 2 4 2 5 3",
"output": "18"
},
{
"input": "7 9\n2 1 3 4 4 5 4",
"output": "0"
},
{
"input": "7 10\n6 3 3 5 3 6 1",
"output": "10"
},
{
"input": "8 1\n1 1 1 1 1 1 1 1",
"output": "36"
},
{
"input": "8 2\n1 1 1 1 1 1 1 2",
"output": "8"
},
{
"input": "8 3\n1 1 2 2 1 1 2 2",
"output": "0"
},
{
"input": "8 4\n2 3 2 3 3 3 2 3",
"output": "10"
},
{
"input": "8 5\n1 3 1 2 2 2 1 3",
"output": "0"
},
{
"input": "8 6\n4 2 4 2 1 2 1 4",
"output": "0"
},
{
"input": "8 7\n2 2 1 4 4 4 2 2",
"output": "0"
},
{
"input": "8 8\n5 2 1 2 4 2 2 4",
"output": "21"
},
{
"input": "8 9\n4 4 2 2 5 5 4 1",
"output": "0"
},
{
"input": "8 10\n2 1 4 4 3 4 4 6",
"output": "0"
},
{
"input": "9 1\n1 1 1 1 1 1 1 1 1",
"output": "45"
},
{
"input": "9 2\n1 1 1 2 1 1 2 2 2",
"output": "36"
},
{
"input": "9 3\n1 1 1 2 2 1 1 2 1",
"output": "0"
},
{
"input": "9 4\n1 1 2 1 2 1 1 1 1",
"output": "15"
},
{
"input": "9 5\n3 2 3 2 3 1 1 3 2",
"output": "0"
},
{
"input": "9 6\n2 1 1 3 2 4 1 2 2",
"output": "21"
},
{
"input": "9 7\n4 3 2 1 2 3 3 4 4",
"output": "0"
},
{
"input": "9 8\n5 5 2 1 3 1 3 1 3",
"output": "0"
},
{
"input": "9 9\n2 4 1 4 4 3 3 4 1",
"output": "18"
},
{
"input": "9 10\n4 3 2 5 2 2 2 2 6",
"output": "23"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "55"
},
{
"input": "10 2\n2 2 2 2 2 2 2 1 2 1",
"output": "53"
},
{
"input": "10 3\n2 2 1 1 2 2 2 2 1 2",
"output": "0"
},
{
"input": "10 4\n1 1 2 3 3 1 2 2 2 3",
"output": "26"
},
{
"input": "10 5\n3 3 2 2 3 1 1 1 3 1",
"output": "0"
},
{
"input": "10 6\n4 4 4 3 2 1 1 1 2 4",
"output": "27"
},
{
"input": "10 7\n4 2 2 2 3 3 2 4 4 3",
"output": "0"
},
{
"input": "10 8\n5 4 1 4 3 2 1 2 3 3",
"output": "24"
},
{
"input": "10 9\n1 2 3 4 5 2 3 5 5 4",
"output": "12"
},
{
"input": "10 10\n5 3 2 5 1 2 5 1 5 1",
"output": "35"
},
{
"input": "1 1000000000\n1",
"output": "0"
},
{
"input": "1 1000000000\n1000000000",
"output": "1"
},
{
"input": "1 100000000\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
}
] | 1,630,601,457 | 3,657 | PyPy 3 | OK | TESTS | 135 | 373 | 31,744,000 | import bisect
import sys
input = sys.stdin.readline
def prime_factorize(n):
ans = []
for i in range(2, int(n ** (1 / 2)) + 1):
while True:
if n % i:
break
ans.append(i)
n //= i
if n == 1:
break
if not n == 1:
ans.append(n)
return ans
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = list(set(prime_factorize(k)))
l = len(s)
cnt = []
for i in s:
cnt0 = [0] * (n + 1)
c = 0
for j in range(n):
aj = a[j]
while not aj % i:
aj //= i
c += 1
cnt0[j + 1] = c
cnt.append(cnt0)
t = []
for i in s:
c = 0
while not k % i:
k //= i
c += 1
t.append(c)
ans = 0
for i in range(1, n + 1):
m = i
for j in range(l):
m = min(m, bisect.bisect_left(cnt[j], cnt[j][i] - t[j] + 0.5))
ans += m
print(ans) | Title: Card Game Again
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck.
After receiving the deck and the magic number, Vova removes *x* (possibly *x*<==<=0) cards from the top of the deck, *y* (possibly *y*<==<=0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards *x*<=+<=1, *x*<=+<=2, ... *n*<=-<=*y*<=-<=1, *n*<=-<=*y* from the original deck.
Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by *k*. So Vova received a deck (possibly not a valid one) and a number *k*, and now he wonders, how many ways are there to choose *x* and *y* so the deck he will get after removing *x* cards from the top and *y* cards from the bottom is valid?
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the numbers written on the cards.
Output Specification:
Print the number of ways to choose *x* and *y* so the resulting deck is valid.
Demo Input:
['3 4\n6 2 8\n', '3 6\n9 1 14\n']
Demo Output:
['4\n', '1\n']
Note:
In the first example the possible values of *x* and *y* are:
1. *x* = 0, *y* = 0; 1. *x* = 1, *y* = 0; 1. *x* = 2, *y* = 0; 1. *x* = 0, *y* = 1. | ```python
import bisect
import sys
input = sys.stdin.readline
def prime_factorize(n):
ans = []
for i in range(2, int(n ** (1 / 2)) + 1):
while True:
if n % i:
break
ans.append(i)
n //= i
if n == 1:
break
if not n == 1:
ans.append(n)
return ans
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = list(set(prime_factorize(k)))
l = len(s)
cnt = []
for i in s:
cnt0 = [0] * (n + 1)
c = 0
for j in range(n):
aj = a[j]
while not aj % i:
aj //= i
c += 1
cnt0[j + 1] = c
cnt.append(cnt0)
t = []
for i in s:
c = 0
while not k % i:
k //= i
c += 1
t.append(c)
ans = 0
for i in range(1, n + 1):
m = i
for j in range(l):
m = min(m, bisect.bisect_left(cnt[j], cnt[j][i] - t[j] + 0.5))
ans += m
print(ans)
``` | 3 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,678,966,619 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n,m,a = map(int,input().split())
print(((n+a-1)/a)*((m+a-1)/a))
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
n,m,a = map(int,input().split())
print(((n+a-1)/a)*((m+a-1)/a))
``` | 0 |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party? | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "9 240",
"output": "0"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "9 235",
"output": "1"
},
{
"input": "9 236",
"output": "0"
},
{
"input": "5 225",
"output": "2"
},
{
"input": "5 226",
"output": "1"
},
{
"input": "4 210",
"output": "3"
},
{
"input": "4 211",
"output": "2"
},
{
"input": "4 191",
"output": "3"
},
{
"input": "10 165",
"output": "5"
},
{
"input": "10 166",
"output": "4"
},
{
"input": "8 100",
"output": "7"
},
{
"input": "8 101",
"output": "6"
},
{
"input": "8 60",
"output": "8"
},
{
"input": "8 61",
"output": "7"
},
{
"input": "10 15",
"output": "9"
},
{
"input": "10 16",
"output": "8"
},
{
"input": "4 100",
"output": "4"
},
{
"input": "4 101",
"output": "4"
},
{
"input": "7 167",
"output": "4"
},
{
"input": "10 164",
"output": "5"
},
{
"input": "9 170",
"output": "4"
},
{
"input": "8 160",
"output": "5"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "8 123",
"output": "6"
},
{
"input": "2 99",
"output": "2"
},
{
"input": "10 88",
"output": "7"
},
{
"input": "1 235",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 240",
"output": "0"
},
{
"input": "1 55",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "3 240",
"output": "0"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "2 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "2 236",
"output": "0"
},
{
"input": "10 2",
"output": "9"
},
{
"input": "3 239",
"output": "0"
},
{
"input": "1 237",
"output": "0"
},
{
"input": "7 8",
"output": "7"
},
{
"input": "10 235",
"output": "1"
}
] | 1,696,410,709 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n, k = map(int, input().split())
time = int((240 - k)/5)
p = 0
while time>0:
time -= p+1
p+=1
if p > n:
print(n)
else:
print(p) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party?
Input Specification:
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Output Specification:
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
Demo Input:
['3 222\n', '4 190\n', '7 1\n']
Demo Output:
['2\n', '4\n', '7\n']
Note:
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | ```python
n, k = map(int, input().split())
time = int((240 - k)/5)
p = 0
while time>0:
time -= p+1
p+=1
if p > n:
print(n)
else:
print(p)
``` | 0 |
|
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
},
{
"input": "8",
"output": "1641"
},
{
"input": "9",
"output": "4920"
},
{
"input": "10",
"output": "14763"
},
{
"input": "15",
"output": "3587226"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "100",
"output": "721510432"
},
{
"input": "300",
"output": "327873818"
},
{
"input": "900",
"output": "295068084"
},
{
"input": "1500",
"output": "451187545"
},
{
"input": "3000",
"output": "645417275"
},
{
"input": "5000",
"output": "755610910"
},
{
"input": "10000",
"output": "723907367"
},
{
"input": "50000",
"output": "969527595"
},
{
"input": "90000",
"output": "548978368"
},
{
"input": "99999",
"output": "909741855"
},
{
"input": "100000",
"output": "729225554"
},
{
"input": "300000",
"output": "93822635"
},
{
"input": "800000",
"output": "178940616"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "4000000",
"output": "882155933"
},
{
"input": "9000000",
"output": "295060537"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "9999998",
"output": "576926295"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "31",
"output": "347990060"
}
] | 1,616,150,137 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 154 | 0 | n=int(input())
print(((2*n-1)%1000000007)*((n-1)%1000000007)%1000000007) | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Output Specification:
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
Demo Input:
['2\n', '4\n']
Demo Output:
['3\n', '21\n']
Note:
The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | ```python
n=int(input())
print(((2*n-1)%1000000007)*((n-1)%1000000007)%1000000007)
``` | 0 |
|
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input": "5\n5 4 3 2 1",
"output": "5 4 3 2 1"
},
{
"input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19"
},
{
"input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19",
"output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19"
},
{
"input": "10\n3 4 5 6 7 8 9 10 1 2",
"output": "9 10 1 2 3 4 5 6 7 8"
},
{
"input": "8\n1 5 3 7 2 6 4 8",
"output": "1 5 3 7 2 6 4 8"
},
{
"input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47",
"output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19"
},
{
"input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17",
"output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25"
},
{
"input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85",
"output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30"
},
{
"input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49",
"output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49"
},
{
"input": "12\n3 8 7 4 6 5 2 1 11 9 10 12",
"output": "8 7 1 4 6 5 3 2 10 11 9 12"
},
{
"input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76",
"output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4"
},
{
"input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43",
"output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1"
},
{
"input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27",
"output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3"
},
{
"input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22",
"output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53"
},
{
"input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13",
"output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24"
},
{
"input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21",
"output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61"
},
{
"input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33",
"output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14"
},
{
"input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23",
"output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21"
},
{
"input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12",
"output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9"
},
{
"input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31",
"output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13"
},
{
"input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3",
"output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16"
},
{
"input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8",
"output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6"
},
{
"input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71",
"output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90"
},
{
"input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9",
"output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9"
},
{
"input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44",
"output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20"
},
{
"input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17",
"output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28"
},
{
"input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7",
"output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5"
},
{
"input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16",
"output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43"
},
{
"input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65",
"output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43"
},
{
"input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16",
"output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45"
},
{
"input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51",
"output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64"
},
{
"input": "12\n12 3 1 5 11 6 7 10 2 8 9 4",
"output": "3 9 2 12 4 6 7 10 11 8 5 1"
},
{
"input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17",
"output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44"
},
{
"input": "8\n1 3 5 2 4 8 6 7",
"output": "1 4 2 5 3 7 8 6"
},
{
"input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14",
"output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12"
},
{
"input": "10\n2 9 4 6 10 1 7 5 3 8",
"output": "6 1 9 3 8 4 7 10 2 5"
},
{
"input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3",
"output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7"
},
{
"input": "10\n2 4 9 3 6 8 10 5 1 7",
"output": "9 1 4 2 8 5 10 6 3 7"
},
{
"input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15",
"output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23"
},
{
"input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1",
"output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27"
},
{
"input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30",
"output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23"
},
{
"input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52",
"output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50"
},
{
"input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18",
"output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98"
},
{
"input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16",
"output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25"
},
{
"input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37",
"output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54"
},
{
"input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71",
"output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71"
},
{
"input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22",
"output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8"
},
{
"input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12",
"output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51"
},
{
"input": "7\n2 1 5 7 3 4 6",
"output": "2 1 5 6 3 7 4"
},
{
"input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35",
"output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31"
},
{
"input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16",
"output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21"
},
{
"input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52",
"output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11"
},
{
"input": "9\n8 5 2 6 1 9 4 7 3",
"output": "5 3 9 7 2 4 8 1 6"
},
{
"input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27",
"output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13"
},
{
"input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34",
"output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6"
},
{
"input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29",
"output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14"
},
{
"input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7",
"output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16"
},
{
"input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34",
"output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24"
},
{
"input": "9\n4 8 6 5 3 9 2 7 1",
"output": "9 7 5 1 4 3 8 2 6"
},
{
"input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29",
"output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32"
},
{
"input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47",
"output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11"
},
{
"input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6",
"output": "10 4 1 8 6 13 12 5 3 11 9 2 7"
},
{
"input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29",
"output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37"
},
{
"input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3",
"output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25"
},
{
"input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20",
"output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24"
},
{
"input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42",
"output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59"
},
{
"input": "6\n4 3 6 5 1 2",
"output": "5 6 2 1 4 3"
},
{
"input": "9\n7 8 5 3 1 4 2 9 6",
"output": "5 7 4 6 3 9 1 2 8"
},
{
"input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37",
"output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11",
"output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13"
},
{
"input": "2\n2 1",
"output": "2 1"
},
{
"input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28",
"output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18"
},
{
"input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13",
"output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1"
},
{
"input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14",
"output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36"
},
{
"input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29",
"output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32"
},
{
"input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5",
"output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40"
},
{
"input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54",
"output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21"
},
{
"input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29",
"output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4"
},
{
"input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23",
"output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50"
},
{
"input": "10\n2 10 7 4 1 5 8 6 3 9",
"output": "5 1 9 4 6 8 3 7 10 2"
},
{
"input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13",
"output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1"
},
{
"input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2",
"output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11"
},
{
"input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53",
"output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37"
},
{
"input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53",
"output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53"
},
{
"input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64",
"output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49"
},
{
"input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86",
"output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38"
},
{
"input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75",
"output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2"
},
{
"input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53",
"output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5"
},
{
"input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39",
"output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12"
},
{
"input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87",
"output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82"
},
{
"input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25",
"output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97"
},
{
"input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61",
"output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96"
},
{
"input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92",
"output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96"
},
{
"input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6",
"output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 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": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 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"
}
] | 1,695,069,925 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 101 | 124 | 1,536,000 | n=int(input())
d={}
l=""
x=list(map(int, input().split(" ")))
for i in range(len(x)):
d[x[i]]=i+1
for i in range(1,n+1,1):
for j,k in d.items():
if j==i:
l+=str(k)+" "
print(l)
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Output Specification:
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
Demo Input:
['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['4 1 2 3\n', '1 3 2\n', '1 2\n']
Note:
none | ```python
n=int(input())
d={}
l=""
x=list(map(int, input().split(" ")))
for i in range(len(x)):
d[x[i]]=i+1
for i in range(1,n+1,1):
for j,k in d.items():
if j==i:
l+=str(k)+" "
print(l)
``` | 3 |
|
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": "8"
},
{
"input": "6",
"output": "4"
},
{
"input": "999999999",
"output": "2"
},
{
"input": "1378",
"output": "4"
},
{
"input": "13781378",
"output": "4"
},
{
"input": "51202278",
"output": "4"
},
{
"input": "999999998",
"output": "4"
},
{
"input": "999999997",
"output": "8"
},
{
"input": "12193721",
"output": "8"
},
{
"input": "0",
"output": "1"
},
{
"input": "989898989",
"output": "8"
},
{
"input": "7",
"output": "2"
},
{
"input": "8",
"output": "6"
},
{
"input": "9",
"output": "8"
},
{
"input": "10",
"output": "4"
},
{
"input": "11",
"output": "2"
},
{
"input": "12",
"output": "6"
},
{
"input": "13",
"output": "8"
},
{
"input": "14",
"output": "4"
},
{
"input": "15",
"output": "2"
},
{
"input": "16",
"output": "6"
},
{
"input": "999999996",
"output": "6"
},
{
"input": "999999995",
"output": "2"
},
{
"input": "999999994",
"output": "4"
}
] | 1,643,999,696 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 23,859,200 | n = input()
y = str(pow(1378,int (n)))
print(y[len(y)-1])
| Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input Specification:
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Output Specification:
Print single integer — the last digit of 1378*n*.
Demo Input:
['1\n', '2\n']
Demo Output:
['8', '4']
Note:
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | ```python
n = input()
y = str(pow(1378,int (n)))
print(y[len(y)-1])
``` | 0 |
|
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,680,722,091 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 62 | 0 | from math import floor
a,b = map(int,input().split())
f= min(a,b)
c= max(a,b)
c-=f
c= floor(c/2)
print(f,c) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
from math import floor
a,b = map(int,input().split())
f= min(a,b)
c= max(a,b)
c-=f
c= floor(c/2)
print(f,c)
``` | 3 |
|
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a regular bracket sequence is well-known, so you can be familiar with it.
Let's define a regular bracket sequence (RBS). Empty string is RBS. Let *s*1 and *s*2 be a RBS then the strings <*s*1>*s*2, {*s*1}*s*2, [*s*1]*s*2, (*s*1)*s*2 are also RBS.
For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.
Determine the least number of replaces to make the string *s* RBS. | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{]",
"output": "1"
},
{
"input": "{]",
"output": "1"
},
{
"input": "{]",
"output": "1"
},
{
"input": "[]{[]({)([",
"output": "Impossible"
},
{
"input": "(([{>}{[{[)]]>>]",
"output": "7"
},
{
"input": "((<>)[]<]><]",
"output": "3"
},
{
"input": "[[([[(>]>)))[<)>",
"output": "6"
},
{
"input": "({)[}<)](}",
"output": "5"
},
{
"input": "(}{)[<][)(]}",
"output": "6"
},
{
"input": ">}({>]{[}<{<{{)[]]{)]>]]]<(][{)<<<{<<)>)()[>{<]]{}<>}}}}(>}<})(][>{((<{<)]}>)))][>[}[])<]){]]][<[)([",
"output": "Impossible"
},
{
"input": "<<[<{{<([({<<[)<>(]]){})>[](])[)))[[}>]<)>[[>{>>>[<]}<>>)[>]<{)<[><(<]][>(>]>][(<][{]}(()<[()[>><<])<]})]<]}{)",
"output": "45"
},
{
"input": "[<<{{((}[}<<)<)>})(][{>}})((>)<[)[>}[})[)>()[()[((}<<(>)<>](<>(}[>})[[[{)<}<<(}{>>}[<([[])<><)]<{>}[>>>{({>)}]})>)",
"output": "42"
},
{
"input": "(<[([(<({>(}{]>[(})])}])()<<}{]{[>]>(>>[(>>}[){(}<[{(()]{{<(<{][[{<><{<{)<>>]}}}{)(}{})}[<))>>}((({>){({}{{]}]>>}})>))",
"output": "43"
},
{
"input": "{(]}<([]<]{>]<{<({{{<>))}[({(}{)[}({>]}}<<)}<]))(<>(>{>{{{)<}({<]<>{)(>[)>{({}<([<[[)]><>{]}}(>]{}<)[})]}]]}]}>}",
"output": "40"
},
{
"input": "<(([)]<[}>{)>][[(<()({{{>>((]<}<{{<>}><<[)}[[)([[)[)}<]<{(<>){([)><{[([[][({])})<][(}]}>>[){)[({>){(}[}})>}>]>)]}))})>}]",
"output": "45"
},
{
"input": ")(",
"output": "Impossible"
},
{
"input": "[[[[[[[[",
"output": "Impossible"
}
] | 1,685,522,163 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 31 | 0 | s=input()
sl=[]
sll=[]
o={'>':'<','}':'{',']':'[',')':'('}
def of(c):
if o[c]==sl[-1]:
del sl[-1]
return
sl.append(c)
flag=0
for i in s:
if i in '<{[(':
sl.append(i)
continue
if []==sl:
print('Impossible')
flag=1
break
of(i)
cnt=0
if 0==flag:
for i in sl:
if i in '<{[(':
sll.append(i)
continue
if []==sll:
print('Impossible')
flag=1
break
if sll[-1] in '<{[(':
del sll[-1]
cnt+=1
continue
sll.append(i)
print('Impossible') if 1==flag or []!=sll else print(cnt)
| Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a regular bracket sequence is well-known, so you can be familiar with it.
Let's define a regular bracket sequence (RBS). Empty string is RBS. Let *s*1 and *s*2 be a RBS then the strings <*s*1>*s*2, {*s*1}*s*2, [*s*1]*s*2, (*s*1)*s*2 are also RBS.
For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.
Determine the least number of replaces to make the string *s* RBS.
Input Specification:
The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106.
Output Specification:
If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*.
Demo Input:
['[<}){}\n', '{()}[]\n', ']]\n']
Demo Output:
['2', '0', 'Impossible']
Note:
none | ```python
s=input()
sl=[]
sll=[]
o={'>':'<','}':'{',']':'[',')':'('}
def of(c):
if o[c]==sl[-1]:
del sl[-1]
return
sl.append(c)
flag=0
for i in s:
if i in '<{[(':
sl.append(i)
continue
if []==sl:
print('Impossible')
flag=1
break
of(i)
cnt=0
if 0==flag:
for i in sl:
if i in '<{[(':
sll.append(i)
continue
if []==sll:
print('Impossible')
flag=1
break
if sll[-1] in '<{[(':
del sll[-1]
cnt+=1
continue
sll.append(i)
print('Impossible') if 1==flag or []!=sll else print(cnt)
``` | 0 |
|
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input": "1\nqvwli hz",
"output": "1"
},
{
"input": "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab",
"output": "2"
},
{
"input": "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syded",
"output": "3"
},
{
"input": "17\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw",
"output": "1"
},
{
"input": "18\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nb d\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp",
"output": "2"
},
{
"input": "13\nsvpzwtwn rykzfdce\nqweiyeck jkreouy\nhk nnli\ntwxrnbbdt vtuv\nxokqjtylly sz\nesdt dbfidjslq\ng ybqgomvw\nxcpfjmf zcqvz\nifajadhj invzueip\nvdemdnxifb hckwebmi\nsdpnhipam wvowzavh\nuqdlfskhgo vunbpghae\ne dtigwnb",
"output": "13"
},
{
"input": "20\nm vkfh\nvptikamead mvx\nitu mf\nklruxckw aqega\nekqkd enjllwol\ncc uybfdh\nimrfdngvo u\ne uh\ntwt jsslcfuogk\nbljwqsag tuqbdn\nqcv q\nasx gzhvwwmajj\nqcv q\nekqkd enjllwol\nasx gzhvwwmajj\nks vv\nkzyfi cn\ncc uybfdh\nitu mf\ncjbjhtbyvk vatwfmux",
"output": "15"
},
{
"input": "2\nab ab\na bab",
"output": "2"
}
] | 1,645,889,819 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 124 | 0 | a=int(input())
d={}
for i in range(a):
a,b=map(str,input().split())
d.setdefault(b,[])
d[b].append(a)
c=0
for i,j in d.items():
j=set(j)
c+=len(j)
print(c)
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output Specification:
Output the single number — the number of Alyona's leaves.
Demo Input:
['5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n', '3\noak yellow\noak yellow\noak yellow\n']
Demo Output:
['4\n', '1\n']
Note:
none | ```python
a=int(input())
d={}
for i in range(a):
a,b=map(str,input().split())
d.setdefault(b,[])
d[b].append(a)
c=0
for i,j in d.items():
j=set(j)
c+=len(j)
print(c)
``` | 3.969 |
384 | A | Coder | PROGRAMMING | 800 | [
"implementation"
] | null | null | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any. | [
"2\n"
] | [
"2\nC.\n.C\n"
] | none | 500 | [
{
"input": "2",
"output": "2\nC.\n.C"
},
{
"input": "3",
"output": "5\nC.C\n.C.\nC.C"
},
{
"input": "4",
"output": "8\nC.C.\n.C.C\nC.C.\n.C.C"
},
{
"input": "10",
"output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C"
},
{
"input": "15",
"output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C"
},
{
"input": "100",
"output": "5000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "101",
"output": "5101\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "500",
"output": "125000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n...."
},
{
"input": "501",
"output": "125501\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n..."
},
{
"input": "755",
"output": "285013\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "888",
"output": "394272\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "998",
"output": "498002\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "999",
"output": "499001\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "1000",
"output": "500000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "1",
"output": "1\nC"
}
] | 1,575,618,962 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | n=int(input())
print(((n**2)+1)//2)
for x in range(1,n+1):
for y in range(1,n+1):
if x%2==1:
if y!=n:
if y%2==1:print("C",end="")
else:print(".",end="")
else:
print(".")
else:
if y!=n:
if y%2==1:print(".",end="")
else:print("C",end="")
else:
print("C") | Title: Coder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any.
Demo Input:
['2\n']
Demo Output:
['2\nC.\n.C\n']
Note:
none | ```python
n=int(input())
print(((n**2)+1)//2)
for x in range(1,n+1):
for y in range(1,n+1):
if x%2==1:
if y!=n:
if y%2==1:print("C",end="")
else:print(".",end="")
else:
print(".")
else:
if y!=n:
if y%2==1:print(".",end="")
else:print("C",end="")
else:
print("C")
``` | 0 |
|
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "3 2",
"output": "5"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "999 2",
"output": "1997"
},
{
"input": "1000 3",
"output": "1499"
},
{
"input": "1000 4",
"output": "1333"
},
{
"input": "1 1000",
"output": "1"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "10 4",
"output": "13"
},
{
"input": "4 3",
"output": "5"
},
{
"input": "91 5",
"output": "113"
},
{
"input": "777 17",
"output": "825"
},
{
"input": "100 4",
"output": "133"
},
{
"input": "5 3",
"output": "7"
},
{
"input": "6 4",
"output": "7"
},
{
"input": "26 8",
"output": "29"
},
{
"input": "9 4",
"output": "11"
},
{
"input": "20 3",
"output": "29"
},
{
"input": "17 3",
"output": "25"
}
] | 1,658,038,820 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 1,000 | 102,400 | a,b=map(int,input().split())
ans=a
while a//b!=0:
ans+=a//b
a%=b
a+=ans
print(ans) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
Input Specification:
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Output Specification:
Print a single integer — the number of hours Vasily can light up the room for.
Demo Input:
['4 2\n', '6 3\n']
Demo Output:
['7\n', '8\n']
Note:
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | ```python
a,b=map(int,input().split())
ans=a
while a//b!=0:
ans+=a//b
a%=b
a+=ans
print(ans)
``` | 0 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,587,913,127 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 307,200 | n = int(input())
li = list(input().split())
le=[]
lo=[]
for i in li:
if(int(i)%2 == 0):
le.append(i)
else:
lo.append(i)
if(len(le) == 1):
for i in range(len(li)):
if(le[0] == li[i]):
print(i+1)
elif(len(lo) == 1):
for i in range(len(li)):
if(lo[0] == li[i]):
print(i+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n = int(input())
li = list(input().split())
le=[]
lo=[]
for i in li:
if(int(i)%2 == 0):
le.append(i)
else:
lo.append(i)
if(len(le) == 1):
for i in range(len(li)):
if(le[0] == li[i]):
print(i+1)
elif(len(lo) == 1):
for i in range(len(li)):
if(lo[0] == li[i]):
print(i+1)
``` | 3.944928 |
0 | none | none | none | 0 | [
"none"
] | null | null | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* queries on a piece of paper. Each query has the following form: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*). That means that one should apply operations with numbers *x**i*,<=*x**i*<=+<=1,<=...,<=*y**i* to the array.
Now Greg is wondering, what the array *a* will be after all the queries are executed. Help Greg. | The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), (0<=≤<=*d**i*<=≤<=105).
Next *k* lines contain the queries, the query number *i* is written as two integers: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*).
The numbers in the lines are separated by single spaces. | On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | [
"3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n",
"1 1 1\n1\n1 1 1\n1 1\n",
"4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n"
] | [
"9 18 17\n",
"2\n",
"5 18 31 20\n"
] | none | 0 | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3",
"output": "9 18 17"
},
{
"input": "1 1 1\n1\n1 1 1\n1 1",
"output": "2"
},
{
"input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3",
"output": "5 18 31 20"
},
{
"input": "1 1 1\n0\n1 1 0\n1 1",
"output": "0"
}
] | 1,674,294,191 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 10 | 109 | 3,788,800 | import heapq
from collections import *
import math
def solve():
n, m, k = map(int, input().split())
arr = [int(i) for i in input().split()]
a = [0] * n
t = []
for _ in range(m):
l, r, d = map(int, input().split())
t.append([l, r, d])
for _ in range(k):
x, y = map(int, input().split())
a[x-1] += 1
if y != n:
a[y] -= 1
for i in range(1, n):
a[i] += a[i-1]
ans = [0]*n
for i in range(m):
ans[t[i][0]-1] += a[i] * t[i][2]
if t[i][1] != n:
ans[t[i][1]] -= a[i] * t[i][2]
for i in range(1, n):
ans[i] += ans[i-1]
for i in range(n):
arr[i]+=ans[i]
print(*arr)
# t = int(input())
# for _ in range(t):
# solve()
solve() | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* queries on a piece of paper. Each query has the following form: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*). That means that one should apply operations with numbers *x**i*,<=*x**i*<=+<=1,<=...,<=*y**i* to the array.
Now Greg is wondering, what the array *a* will be after all the queries are executed. Help Greg.
Input Specification:
The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), (0<=≤<=*d**i*<=≤<=105).
Next *k* lines contain the queries, the query number *i* is written as two integers: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*).
The numbers in the lines are separated by single spaces.
Output Specification:
On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Demo Input:
['3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n', '1 1 1\n1\n1 1 1\n1 1\n', '4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n']
Demo Output:
['9 18 17\n', '2\n', '5 18 31 20\n']
Note:
none | ```python
import heapq
from collections import *
import math
def solve():
n, m, k = map(int, input().split())
arr = [int(i) for i in input().split()]
a = [0] * n
t = []
for _ in range(m):
l, r, d = map(int, input().split())
t.append([l, r, d])
for _ in range(k):
x, y = map(int, input().split())
a[x-1] += 1
if y != n:
a[y] -= 1
for i in range(1, n):
a[i] += a[i-1]
ans = [0]*n
for i in range(m):
ans[t[i][0]-1] += a[i] * t[i][2]
if t[i][1] != n:
ans[t[i][1]] -= a[i] * t[i][2]
for i in range(1, n):
ans[i] += ans[i-1]
for i in range(n):
arr[i]+=ans[i]
print(*arr)
# t = int(input())
# for _ in range(t):
# solve()
solve()
``` | -1 |
|
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "NO"
},
{
"input": "256\n16777217",
"output": "NO"
},
{
"input": "4638\n21511044",
"output": "YES\n1"
},
{
"input": "24\n191102976",
"output": "YES\n5"
},
{
"input": "52010\n557556453",
"output": "NO"
},
{
"input": "61703211\n1750753082",
"output": "NO"
},
{
"input": "137\n2571353",
"output": "YES\n2"
},
{
"input": "8758\n1746157336",
"output": "NO"
},
{
"input": "2\n64",
"output": "YES\n5"
},
{
"input": "96\n884736",
"output": "YES\n2"
},
{
"input": "1094841453\n1656354409",
"output": "NO"
},
{
"input": "1154413\n1229512809",
"output": "NO"
},
{
"input": "2442144\n505226241",
"output": "NO"
},
{
"input": "11548057\n1033418098",
"output": "NO"
},
{
"input": "581\n196122941",
"output": "YES\n2"
},
{
"input": "146\n1913781536",
"output": "NO"
},
{
"input": "945916\n1403881488",
"output": "NO"
},
{
"input": "68269\n365689065",
"output": "NO"
},
{
"input": "30\n900",
"output": "YES\n1"
},
{
"input": "6\n1296",
"output": "YES\n3"
},
{
"input": "1470193122\n1420950405",
"output": "NO"
},
{
"input": "90750\n1793111557",
"output": "NO"
},
{
"input": "1950054\n1664545956",
"output": "NO"
},
{
"input": "6767692\n123762320",
"output": "NO"
},
{
"input": "1437134\n1622348229",
"output": "NO"
},
{
"input": "444103\n1806462642",
"output": "NO"
},
{
"input": "2592\n6718464",
"output": "YES\n1"
},
{
"input": "50141\n366636234",
"output": "NO"
},
{
"input": "835\n582182875",
"output": "YES\n2"
},
{
"input": "156604\n902492689",
"output": "NO"
},
{
"input": "27385965\n1742270058",
"output": "NO"
},
{
"input": "3\n9",
"output": "YES\n1"
},
{
"input": "35\n1838265625",
"output": "YES\n5"
},
{
"input": "8\n4096",
"output": "YES\n3"
},
{
"input": "85955\n945811082",
"output": "NO"
},
{
"input": "54958832\n956670209",
"output": "NO"
},
{
"input": "1475381\n1348159738",
"output": "NO"
},
{
"input": "7313241\n413670642",
"output": "NO"
},
{
"input": "582470\n2116368165",
"output": "NO"
},
{
"input": "26859739\n595086170",
"output": "NO"
},
{
"input": "249766393\n1582130",
"output": "NO"
},
{
"input": "11734\n137686756",
"output": "YES\n1"
},
{
"input": "925093\n1098566745",
"output": "NO"
},
{
"input": "40\n1600",
"output": "YES\n1"
},
{
"input": "2147483647\n2147483647",
"output": "YES\n0"
},
{
"input": "2147483646\n2147483647",
"output": "NO"
},
{
"input": "2147483647\n2147483646",
"output": "NO"
},
{
"input": "2\n2147483647",
"output": "NO"
},
{
"input": "2\n1073741825",
"output": "NO"
},
{
"input": "2\n1073741824",
"output": "YES\n29"
},
{
"input": "10000\n10",
"output": "NO"
},
{
"input": "10\n10000",
"output": "YES\n3"
},
{
"input": "10\n2000000000",
"output": "NO"
},
{
"input": "10\n1000000000",
"output": "YES\n8"
},
{
"input": "5\n1808548329",
"output": "NO"
},
{
"input": "2\n2147483646",
"output": "NO"
},
{
"input": "25\n125",
"output": "NO"
},
{
"input": "6\n18",
"output": "NO"
},
{
"input": "5\n30",
"output": "NO"
}
] | 1,621,701,849 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | import math
n,x,y = map(int,input().split())
a = int(math.ceil((y/100)*n)) - x
print(a) | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
Input Specification:
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
Output Specification:
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
Demo Input:
['5\n25\n', '3\n8\n']
Demo Output:
['YES\n1\n', 'NO\n']
Note:
none | ```python
import math
n,x,y = map(int,input().split())
a = int(math.ceil((y/100)*n)) - x
print(a)
``` | -1 |
|
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
"output": "50"
},
{
"input": "101",
"output": "-51"
},
{
"input": "102",
"output": "51"
},
{
"input": "103",
"output": "-52"
},
{
"input": "104",
"output": "52"
},
{
"input": "105",
"output": "-53"
},
{
"input": "106",
"output": "53"
},
{
"input": "107",
"output": "-54"
},
{
"input": "108",
"output": "54"
},
{
"input": "109",
"output": "-55"
},
{
"input": "208170109961052",
"output": "104085054980526"
},
{
"input": "46017661651072",
"output": "23008830825536"
},
{
"input": "4018154546667",
"output": "-2009077273334"
},
{
"input": "288565475053",
"output": "-144282737527"
},
{
"input": "3052460231",
"output": "-1526230116"
},
{
"input": "29906716",
"output": "14953358"
},
{
"input": "87897701693326",
"output": "43948850846663"
},
{
"input": "8240",
"output": "4120"
},
{
"input": "577935",
"output": "-288968"
},
{
"input": "62",
"output": "31"
},
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "1"
},
{
"input": "9999999999999",
"output": "-5000000000000"
},
{
"input": "1000000000000",
"output": "500000000000"
},
{
"input": "99999999999999",
"output": "-50000000000000"
},
{
"input": "999999999999999",
"output": "-500000000000000"
},
{
"input": "42191359342",
"output": "21095679671"
},
{
"input": "100000000000000",
"output": "50000000000000"
},
{
"input": "145645214654154",
"output": "72822607327077"
},
{
"input": "4294967296",
"output": "2147483648"
},
{
"input": "3037000499",
"output": "-1518500250"
},
{
"input": "10000000000001",
"output": "-5000000000001"
},
{
"input": "100000017040846",
"output": "50000008520423"
},
{
"input": "98979894985999",
"output": "-49489947493000"
}
] | 1,696,159,145 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 46 | 0 | n = int(input())
ans = (n+1)//2
if n % 2 == 1:
print(-ans)
else:
print(ans)
| Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Output Specification:
Print *f*(*n*) in a single line.
Demo Input:
['4\n', '5\n']
Demo Output:
['2\n', '-3\n']
Note:
*f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | ```python
n = int(input())
ans = (n+1)//2
if n % 2 == 1:
print(-ans)
else:
print(ans)
``` | 3 |
|
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros. | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3 2 1 4\n3 7 2 4 8\n9 2 8 9 10\n2 3 6 10 1\n8 2 2 8 4",
"output": "0\nDDDDRRRR"
},
{
"input": "6\n5 5 4 10 5 5\n7 10 8 7 6 6\n7 1 7 9 7 8\n5 5 3 3 10 9\n5 8 10 6 3 8\n3 10 5 4 3 4",
"output": "1\nDDRRDRDDRR"
},
{
"input": "7\n2 9 8 2 7 4 8\n9 5 4 4 8 5 3\n5 7 2 10 8 1 8\n2 7 10 7 5 7 7\n9 2 7 6 4 8 4\n7 2 4 7 4 1 8\n9 5 3 10 1 6 2",
"output": "0\nRRDRRDRDDDDR"
},
{
"input": "8\n1 1 10 1 8 4 8 7\n9 3 3 2 2 6 2 4\n7 4 3 5 10 3 5 1\n8 4 4 10 4 5 9 4\n5 5 5 2 6 7 1 8\n4 10 1 3 2 4 8 3\n8 1 10 2 8 2 2 4\n2 10 6 8 10 2 8 4",
"output": "0\nDRRRRRRRDDDDDD"
},
{
"input": "9\n8 3 3 3 10 3 10 5 6\n2 1 6 1 8 1 9 1 6\n6 1 5 4 2 2 10 4 9\n1 9 1 3 10 6 10 5 5\n1 10 5 4 7 2 5 9 10\n6 6 1 3 1 9 4 9 9\n5 3 7 6 4 6 2 10 2\n9 3 3 10 5 6 7 6 4\n4 9 6 7 4 3 7 6 5",
"output": "1\nDDDDDRDDDRRRRRRR"
},
{
"input": "10\n10 8 6 5 9 8 2 5 3 2\n3 1 8 6 8 10 5 5 7 8\n5 9 7 7 4 9 7 2 5 2\n5 9 9 5 4 2 6 6 8 1\n10 6 9 9 10 5 6 3 5 9\n6 7 10 3 1 4 3 6 7 6\n10 10 4 7 4 4 8 6 7 4\n10 5 8 2 2 7 4 4 1 4\n8 4 6 10 10 6 1 3 3 1\n9 9 7 2 9 5 1 8 6 3",
"output": "1\nDRDDDRRDDDRRDRDRRR"
}
] | 1,398,182,675 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | # -*- coding: utf-8 -*-
n = int(input())
def arrayWent(array, variants):
for variant in variants:
pos = [0,0]
mul = array[pos[0]][pos[1]]
for elem in variant:
if elem == 'R':
pos[1] += 1
elif elem == 'D':
pos[0] += 1
mul *= array[pos[0]][pos[1]]
muls.append(mul)
return muls
def takeWay(muls):
zeroNum = []
for mul in muls:
testMul = list(reversed(list(str(mul))))
zero = 0
i = 0
print(testMul)
while True:
if testMul[i] == '0':
zero += 1
i += 1
else: break
zeroNum.append(zero)
print(zeroNum)
print(min(zeroNum))
return variants[zeroNum.index(min(zeroNum))]
array = []
variants = []
muls = []
steps = 2*(n-1)
numChar = len(bin(2**steps).split('b')[1]) - 1
for i in range(n):
line = list(map(int,input().split(' ')))
array.append(line)
for j in range(0, 2**steps):
b = bin(j).split('b')[1]
if len(b) < numChar:
b = (numChar - len(b))*'0' + b
if b.count('0') == b.count('1'):
variants.append(b.replace('1','R').replace('0','D'))
variants.reverse()
muls = arrayWent(array, variants)
print(muls)
print(takeWay(muls))
| Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.
Input Specification:
The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109).
Output Specification:
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
Demo Input:
['3\n1 2 3\n4 5 6\n7 8 9\n']
Demo Output:
['0\nDDRR\n']
Note:
none | ```python
# -*- coding: utf-8 -*-
n = int(input())
def arrayWent(array, variants):
for variant in variants:
pos = [0,0]
mul = array[pos[0]][pos[1]]
for elem in variant:
if elem == 'R':
pos[1] += 1
elif elem == 'D':
pos[0] += 1
mul *= array[pos[0]][pos[1]]
muls.append(mul)
return muls
def takeWay(muls):
zeroNum = []
for mul in muls:
testMul = list(reversed(list(str(mul))))
zero = 0
i = 0
print(testMul)
while True:
if testMul[i] == '0':
zero += 1
i += 1
else: break
zeroNum.append(zero)
print(zeroNum)
print(min(zeroNum))
return variants[zeroNum.index(min(zeroNum))]
array = []
variants = []
muls = []
steps = 2*(n-1)
numChar = len(bin(2**steps).split('b')[1]) - 1
for i in range(n):
line = list(map(int,input().split(' ')))
array.append(line)
for j in range(0, 2**steps):
b = bin(j).split('b')[1]
if len(b) < numChar:
b = (numChar - len(b))*'0' + b
if b.count('0') == b.count('1'):
variants.append(b.replace('1','R').replace('0','D'))
variants.reverse()
muls = arrayWent(array, variants)
print(muls)
print(takeWay(muls))
``` | 0 |
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length.
He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length. | The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output": "YES"
},
{
"input": "princeofpersia\n1",
"output": "NO"
},
{
"input": "xhwbdoryfiaxglripavycmxmcejbcpzidrqsqvikfzjyfnmedxrvlnusavyhillaxrblkynwdrlhthtqzjktzkullgrqsolqssocpfwcaizhovajlhmeibhiuwtxpljkyyiwykzpmazkkzampzkywiyykjlpxtwuihbiemhljavohziacwfpcossqlosqrgllukztkjzqththlrdwnyklbrxallihyvasunlvrxdemnfyjzfkivqsqrdizpcbjecmxmcyvapirlgxaifyrodbwhx\n1",
"output": "YES"
},
{
"input": "yfhqnbzaqeqmcvtsbcdn\n456",
"output": "NO"
},
{
"input": "lgsdfiforlqrohhjyzrigewkigiiffvbyrapzmjvtkklndeyuqpuukajgtguhlarjdqlxksyekbjgrmhuyiqdlzjqqzlxufffpelyptodwhvkfbalxbufrlcsjgxmfxeqsszqghcustqrqjljattgvzynyvfbjgbuynbcguqtyfowgtcbbaywvcrgzrulqpghwoflutswu\n584",
"output": "NO"
},
{
"input": "awlrhmxxivqbntvtapwkdkunamcqoerfncfmookhdnuxtttlxmejojpwbdyxirdsjippzjhdrpjepremruczbedxrjpodlyyldopjrxdebzcurmerpejprdhjzppijsdrixydbwpjojemxltttxundhkoomfcnfreoqcmanukdkwpatvtnbqvixxmhrlwa\n1",
"output": "YES"
},
{
"input": "kafzpsglcpzludxojtdhzynpbekzssvhzizfrboxbhqvojiqtjitrackqccxgenwwnegxccqkcartijtqijovqhbxobrfzizhvsszkebpnyzhdtjoxdulzpclgspzfakvcbbjejeubvrrzlvjjgrcprntbyuakoxowoybbxgdugjffgbtfwrfiobifrshyaqqayhsrfiboifrwftbgffjgudgxbbyowoxokauybtnrpcrgjjvlzrrvbuejejbbcv\n2",
"output": "YES"
},
{
"input": "zieqwmmbrtoxysvavwdemmdeatfrolsqvvlgphhhmojjfxfurtuiqdiilhlcwwqedlhblrzmvuoaczcwrqzyymiggpvbpkycibsvkhytrzhguksxyykkkvfljbbnjblylftmqxkojithwsegzsaexlpuicexbdzpwesrkzbqltxhifwqcehzsjgsqbwkujvjbjpqxdpmlimsusumizizpyigmkxwuberthdghnepyrxzvvidxeafwylegschhtywvqsxuqmsddhkzgkdiekodqpnftdyhnpicsnbhfxemxllvaurkmjvtrmqkulerxtaolmokiqqvqgechkqxmendpmgxwiaffcajmqjmvrwryzxujmiasuqtosuisiclnv\n8",
"output": "NO"
},
{
"input": "syghzncbi\n829",
"output": "NO"
},
{
"input": "ljpdpstntznciejqqtpysskztdfawuncqzwwfefrfsihyrdopwawowshquqnjhesxszuywezpebpzhtopgngrnqgwnoqhyrykojguybvdbjpfpmvkxscocywzsxcivysfrrzsonayztzzuybrkiombhqcfkszyscykzistiobrpavezedgobowjszfadcccmxyqehmkgywiwxffibzetb\n137",
"output": "NO"
},
{
"input": "eytuqriplfczwsqlsnjetfpzehzvzayickkbnfqddaisfpasvigwtnvbybwultsgrtjbaebktvubwofysgidpufzteuhuaaqkhmhguockoczlrmlrrzouvqtwbcchxxiydbohnvrmtqjzhkfmvdulojhdvgwudvidpausvfujkjprxsobliuauxleqvsmz\n253",
"output": "NO"
},
{
"input": "xkaqgwabuilhuqwhnrdtyattmqcjfbiqodjlwzgcyvghqncklbhnlmagvjvwysrfryrlmclninogumjfmyenkmydlmifxpkvlaapgnfarejaowftxxztshsesjtsgommaeslrhronruqdurvjesydrzmxirmxumrcqezznqltngsgdcthivdnjnshjfujtiqsltpttgbljfcbqsfwbzokciqlavrthgaqbzikpwwsebzwddlvdwrmztwmhcxdinwlbklwmteeybbdbzevfbsrtldapulwgusuvnreiflkytonzmervyrlbqhzapgxepwauaiwygpxarfeyqhimzlxntjuaaigeisgrvwgbhqemqetzyallzaoqprhzpjibkutgwrodruqu\n857",
"output": "NO"
},
{
"input": "rbehjxpblnzfgeebpkvzznwtzszghjuuxovreapmwehqyjymrkmksffbdpbdyegulabsmjiykeeqtuvqqyxlitpxjdpwmqtlmudqsksgwqekvwfjdsggzajcpsyserkctpbajgzdbiqaekfaepnecezdzamqszpwfvhlannszgaiewvcdnnvzhblmuzjtqeyjcqjqoxatavavokyxokuxwuqueskktxnxraihnqovrfykpzsyjmrhqsvbobzsnfqwvdwatvjxaubtiwhgvrqwjhgfnauqegqmcwnaruinplmtmxhvohhqgvcatsdqiwkvslhqzqevdgdhpijjevuyuitnixdjhwlmjsstmugownjdhvxueg\n677",
"output": "NO"
},
{
"input": "a\n3",
"output": "NO"
},
{
"input": "aa\n2",
"output": "YES"
},
{
"input": "abcaabca\n2",
"output": "NO"
},
{
"input": "aaaaaaaaab\n5",
"output": "NO"
},
{
"input": "aabbb\n3",
"output": "NO"
},
{
"input": "abcde\n5",
"output": "YES"
},
{
"input": "aabc\n2",
"output": "NO"
},
{
"input": "aabcaa\n3",
"output": "NO"
}
] | 1,622,871,302 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 11 | 202 | 2,048,000 | s=input()
n=int(input())
c=0
for i in range(0,len(s),len(s)//n):
#print(s[i:i+len(s)//n],s[i:i+len(s)//n][::-1])
if s[i:i+len(s)//n]==s[i:i+len(s)//n][::-1]:
c+=1
if c==n and len(s)%n==0:
print('YES')
else:
print('NO') | Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length.
He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length.
Input Specification:
The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000).
Output Specification:
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
Demo Input:
['saba\n2\n', 'saddastavvat\n2\n']
Demo Output:
['NO\n', 'YES\n']
Note:
Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | ```python
s=input()
n=int(input())
c=0
for i in range(0,len(s),len(s)//n):
#print(s[i:i+len(s)//n],s[i:i+len(s)//n][::-1])
if s[i:i+len(s)//n]==s[i:i+len(s)//n][::-1]:
c+=1
if c==n and len(s)%n==0:
print('YES')
else:
print('NO')
``` | -1 |
|
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b",
"output": "f jpggvr b hnxsd b"
},
{
"input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb",
"output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs"
},
{
"input": "1 1\namit am\namit",
"output": "am"
},
{
"input": "1 1\na c\na",
"output": "a"
}
] | 1,595,941,624 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 7,372,800 | n, m = map(int, input().split())
words = {}
for _ in range(m):
a, b = map(str, input().split())
if len(a) < len(b) or len(a) == len(b):
words[b] = a
else:
words[a] = b
a = list(map(str, input().split()))
for i in range(n):
if a[i] in words:
a[i] = words[a[i]]
print(*a) | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input Specification:
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output Specification:
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Demo Input:
['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n']
Demo Output:
['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n']
Note:
none | ```python
n, m = map(int, input().split())
words = {}
for _ in range(m):
a, b = map(str, input().split())
if len(a) < len(b) or len(a) == len(b):
words[b] = a
else:
words[a] = b
a = list(map(str, input().split()))
for i in range(n):
if a[i] in words:
a[i] = words[a[i]]
print(*a)
``` | 3 |
|
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"input": "10\n68 47 67 29 63 71 71 65 54 56",
"output": "10"
},
{
"input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92",
"output": "4"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14",
"output": "0"
},
{
"input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42",
"output": "7"
},
{
"input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99",
"output": "47"
},
{
"input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57",
"output": "50"
},
{
"input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13",
"output": "3"
},
{
"input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36",
"output": "3"
},
{
"input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73",
"output": "73"
},
{
"input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68",
"output": "7"
},
{
"input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94",
"output": "15"
},
{
"input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64",
"output": "104"
},
{
"input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97",
"output": "33"
},
{
"input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43",
"output": "145"
},
{
"input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26",
"output": "76"
},
{
"input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34",
"output": "15"
},
{
"input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81",
"output": "11"
},
{
"input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95",
"output": "13"
},
{
"input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15",
"output": "104"
},
{
"input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67",
"output": "100"
},
{
"input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32",
"output": "107"
},
{
"input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22",
"output": "50"
},
{
"input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61",
"output": "59"
},
{
"input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95",
"output": "99"
},
{
"input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "2\n100 99",
"output": "0"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "197"
},
{
"input": "100\n87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87",
"output": "0"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 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": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 3 2",
"output": "2"
}
] | 1,689,936,402 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 62 | 0 | n = int(input())
height = list(map(int, input().split()))
max = height[0]
min = height[0]
max_i = 0
min_i = 0
for i in range(n):
if height[i] > max: # 가장 앞에 있는 최댓값 구하기
max = height[i]
max_i = i
if height[i] <= min: # 가장 뒤에 있는 최댓값 구하기
min = height[i]
min_i = i
if min_i < max_i: # 제일 작은 친구가 max인 친구보다 앞에 있으면,
print(max_i + (n-1 - min_i) -1 )
else:
print(max_i + (n-1 - min_i) )
| Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
Input Specification:
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Output Specification:
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
Demo Input:
['4\n33 44 11 22\n', '7\n10 10 58 31 63 40 76\n']
Demo Output:
['2\n', '10\n']
Note:
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | ```python
n = int(input())
height = list(map(int, input().split()))
max = height[0]
min = height[0]
max_i = 0
min_i = 0
for i in range(n):
if height[i] > max: # 가장 앞에 있는 최댓값 구하기
max = height[i]
max_i = i
if height[i] <= min: # 가장 뒤에 있는 최댓값 구하기
min = height[i]
min_i = i
if min_i < max_i: # 제일 작은 친구가 max인 친구보다 앞에 있으면,
print(max_i + (n-1 - min_i) -1 )
else:
print(max_i + (n-1 - min_i) )
``` | 3 |
|
990 | A | Commentary Boxes | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)? | The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. | Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. | [
"9 7 3 8\n",
"2 7 3 7\n",
"30 6 17 19\n"
] | [
"15\n",
"14\n",
"0\n"
] | In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes. | 0 | [
{
"input": "9 7 3 8",
"output": "15"
},
{
"input": "2 7 3 7",
"output": "14"
},
{
"input": "30 6 17 19",
"output": "0"
},
{
"input": "500000000001 1000000000000 100 100",
"output": "49999999999900"
},
{
"input": "1000000000000 750000000001 10 100",
"output": "5000000000020"
},
{
"input": "1000000000000 750000000001 100 10",
"output": "2499999999990"
},
{
"input": "42 1 1 1",
"output": "0"
},
{
"input": "1 1000000000000 1 100",
"output": "100"
},
{
"input": "7 2 3 7",
"output": "3"
},
{
"input": "999999999 2 1 1",
"output": "1"
},
{
"input": "999999999999 10000000007 100 100",
"output": "70100"
},
{
"input": "10000000001 2 1 1",
"output": "1"
},
{
"input": "29 6 1 2",
"output": "1"
},
{
"input": "99999999999 6 100 100",
"output": "300"
},
{
"input": "1000000000000 7 3 8",
"output": "8"
},
{
"input": "99999999999 2 1 1",
"output": "1"
},
{
"input": "1 2 1 1",
"output": "1"
},
{
"input": "999999999999 2 1 1",
"output": "1"
},
{
"input": "9 2 1 1",
"output": "1"
},
{
"input": "17 4 5 5",
"output": "5"
},
{
"input": "100000000000 3 1 1",
"output": "1"
},
{
"input": "100 7 1 1",
"output": "2"
},
{
"input": "1000000000000 3 100 100",
"output": "100"
},
{
"input": "70 3 10 10",
"output": "10"
},
{
"input": "1 2 5 1",
"output": "1"
},
{
"input": "1000000000000 3 1 1",
"output": "1"
},
{
"input": "804289377 846930887 78 16",
"output": "3326037780"
},
{
"input": "1000000000000 9 55 55",
"output": "55"
},
{
"input": "957747787 424238336 87 93",
"output": "10162213695"
},
{
"input": "25 6 1 2",
"output": "2"
},
{
"input": "22 7 3 8",
"output": "8"
},
{
"input": "10000000000 1 1 1",
"output": "0"
},
{
"input": "999999999999 2 10 10",
"output": "10"
},
{
"input": "999999999999 2 100 100",
"output": "100"
},
{
"input": "100 3 3 8",
"output": "6"
},
{
"input": "99999 2 1 1",
"output": "1"
},
{
"input": "100 3 2 5",
"output": "4"
},
{
"input": "1000000000000 13 10 17",
"output": "17"
},
{
"input": "7 2 1 2",
"output": "1"
},
{
"input": "10 3 1 2",
"output": "2"
},
{
"input": "5 2 2 2",
"output": "2"
},
{
"input": "100 3 5 2",
"output": "2"
},
{
"input": "7 2 1 1",
"output": "1"
},
{
"input": "70 4 1 1",
"output": "2"
},
{
"input": "10 4 1 1",
"output": "2"
},
{
"input": "6 7 41 42",
"output": "41"
},
{
"input": "10 3 10 1",
"output": "1"
},
{
"input": "5 5 2 3",
"output": "0"
},
{
"input": "1000000000000 3 99 99",
"output": "99"
},
{
"input": "7 3 100 1",
"output": "1"
},
{
"input": "7 2 100 5",
"output": "5"
},
{
"input": "1000000000000 1 23 33",
"output": "0"
},
{
"input": "30 7 1 1",
"output": "2"
},
{
"input": "100 3 1 1",
"output": "1"
},
{
"input": "90001 300 100 1",
"output": "1"
},
{
"input": "13 4 1 2",
"output": "2"
},
{
"input": "1000000000000 6 1 3",
"output": "2"
},
{
"input": "50 4 5 100",
"output": "10"
},
{
"input": "999 2 1 1",
"output": "1"
},
{
"input": "5 2 5 5",
"output": "5"
},
{
"input": "20 3 3 3",
"output": "3"
},
{
"input": "3982258181 1589052704 87 20",
"output": "16083055460"
},
{
"input": "100 3 1 3",
"output": "2"
},
{
"input": "7 3 1 1",
"output": "1"
},
{
"input": "19 10 100 100",
"output": "100"
},
{
"input": "23 3 100 1",
"output": "2"
},
{
"input": "25 7 100 1",
"output": "4"
},
{
"input": "100 9 1 2",
"output": "2"
},
{
"input": "9999999999 2 1 100",
"output": "1"
},
{
"input": "1000000000000 2 1 1",
"output": "0"
},
{
"input": "10000 3 1 1",
"output": "1"
},
{
"input": "22 7 1 6",
"output": "6"
},
{
"input": "100000000000 1 1 1",
"output": "0"
},
{
"input": "18 7 100 1",
"output": "4"
},
{
"input": "10003 4 1 100",
"output": "1"
},
{
"input": "3205261341 718648876 58 11",
"output": "3637324207"
},
{
"input": "8 3 100 1",
"output": "2"
},
{
"input": "15 7 1 1",
"output": "1"
},
{
"input": "1000000000000 1 20 20",
"output": "0"
},
{
"input": "16 7 3 2",
"output": "4"
},
{
"input": "1000000000000 1 1 1",
"output": "0"
},
{
"input": "7 3 1 100",
"output": "2"
},
{
"input": "16 3 1 100",
"output": "2"
},
{
"input": "13 4 1 10",
"output": "3"
},
{
"input": "10 4 5 5",
"output": "10"
},
{
"input": "14 3 1 100",
"output": "1"
},
{
"input": "100 33 100 1",
"output": "1"
},
{
"input": "22 7 1 8",
"output": "6"
},
{
"input": "10 4 2 1",
"output": "2"
},
{
"input": "6 4 2 2",
"output": "4"
},
{
"input": "17 4 2 1",
"output": "1"
},
{
"input": "7 3 100 10",
"output": "10"
},
{
"input": "702 7 3 2",
"output": "4"
},
{
"input": "8 3 1 5",
"output": "1"
},
{
"input": "3 2 5 2",
"output": "2"
},
{
"input": "99 19 1 7",
"output": "15"
},
{
"input": "16 3 100 1",
"output": "1"
},
{
"input": "100 34 1 100",
"output": "2"
},
{
"input": "100 33 1 1",
"output": "1"
},
{
"input": "2 3 4 3",
"output": "4"
},
{
"input": "15 4 4 10",
"output": "4"
},
{
"input": "1144108931 470211273 45 79",
"output": "11993619960"
},
{
"input": "2 3 3 4",
"output": "3"
},
{
"input": "29 5 4 9",
"output": "4"
},
{
"input": "15 7 1 5",
"output": "5"
},
{
"input": "1 1 1 1",
"output": "0"
},
{
"input": "1 1 3 4",
"output": "0"
},
{
"input": "10 12 2 1",
"output": "4"
},
{
"input": "1 2 3 4",
"output": "3"
}
] | 1,535,703,058 | 2,147,483,647 | Python 3 | OK | TESTS | 109 | 124 | 0 | n, m, a, b = map(int, input().split())
aa = m - (n % m)
bb = n % m
print(min(aa*a, bb*b)) | Title: Commentary Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)?
Input Specification:
The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box.
Output Specification:
Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$.
Demo Input:
['9 7 3 8\n', '2 7 3 7\n', '30 6 17 19\n']
Demo Output:
['15\n', '14\n', '0\n']
Note:
In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes. | ```python
n, m, a, b = map(int, input().split())
aa = m - (n % m)
bb = n % m
print(min(aa*a, bb*b))
``` | 3 |
|
475 | A | Bayan Bus | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The event coordinator has a list of *k* participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one.
In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by *k* participants. Your task is to draw the figure representing occupied seats. | The only line of input contains integer *k*, (0<=≤<=*k*<=≤<=34), denoting the number of participants. | Print the figure of a bus with *k* passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters. | [
"9\n",
"20\n"
] | [
"+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n",
"+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+\n"
] | none | 500 | [
{
"input": "9",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "20",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "30",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.#.|D|)\n|O.O.O.O.O.O.O.O.O.O.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.#.#.|.|)\n+------------------------+"
},
{
"input": "5",
"output": "+------------------------+\n|O.O.#.#.#.#.#.#.#.#.#.|D|)\n|O.#.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "0",
"output": "+------------------------+\n|#.#.#.#.#.#.#.#.#.#.#.|D|)\n|#.#.#.#.#.#.#.#.#.#.#.|.|\n|#.......................|\n|#.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "1",
"output": "+------------------------+\n|O.#.#.#.#.#.#.#.#.#.#.|D|)\n|#.#.#.#.#.#.#.#.#.#.#.|.|\n|#.......................|\n|#.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "2",
"output": "+------------------------+\n|O.#.#.#.#.#.#.#.#.#.#.|D|)\n|O.#.#.#.#.#.#.#.#.#.#.|.|\n|#.......................|\n|#.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "3",
"output": "+------------------------+\n|O.#.#.#.#.#.#.#.#.#.#.|D|)\n|O.#.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|#.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "4",
"output": "+------------------------+\n|O.#.#.#.#.#.#.#.#.#.#.|D|)\n|O.#.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "6",
"output": "+------------------------+\n|O.O.#.#.#.#.#.#.#.#.#.|D|)\n|O.O.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "7",
"output": "+------------------------+\n|O.O.#.#.#.#.#.#.#.#.#.|D|)\n|O.O.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "8",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "10",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "11",
"output": "+------------------------+\n|O.O.O.O.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "12",
"output": "+------------------------+\n|O.O.O.O.#.#.#.#.#.#.#.|D|)\n|O.O.O.O.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "13",
"output": "+------------------------+\n|O.O.O.O.#.#.#.#.#.#.#.|D|)\n|O.O.O.O.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "14",
"output": "+------------------------+\n|O.O.O.O.O.#.#.#.#.#.#.|D|)\n|O.O.O.O.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "15",
"output": "+------------------------+\n|O.O.O.O.O.#.#.#.#.#.#.|D|)\n|O.O.O.O.O.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "16",
"output": "+------------------------+\n|O.O.O.O.O.#.#.#.#.#.#.|D|)\n|O.O.O.O.O.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "17",
"output": "+------------------------+\n|O.O.O.O.O.O.#.#.#.#.#.|D|)\n|O.O.O.O.O.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "18",
"output": "+------------------------+\n|O.O.O.O.O.O.#.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "19",
"output": "+------------------------+\n|O.O.O.O.O.O.#.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "21",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.O.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "22",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.O.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "23",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.#.#.#.|D|)\n|O.O.O.O.O.O.O.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "24",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.#.#.#.|D|)\n|O.O.O.O.O.O.O.O.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "25",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.#.#.#.|D|)\n|O.O.O.O.O.O.O.O.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.#.#.#.|.|)\n+------------------------+"
},
{
"input": "26",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.#.#.|D|)\n|O.O.O.O.O.O.O.O.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.#.#.#.|.|)\n+------------------------+"
},
{
"input": "27",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.#.#.|D|)\n|O.O.O.O.O.O.O.O.O.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.#.#.#.|.|)\n+------------------------+"
},
{
"input": "28",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.#.#.|D|)\n|O.O.O.O.O.O.O.O.O.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.#.#.|.|)\n+------------------------+"
},
{
"input": "29",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.#.|D|)\n|O.O.O.O.O.O.O.O.O.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.#.#.|.|)\n+------------------------+"
},
{
"input": "31",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.#.|D|)\n|O.O.O.O.O.O.O.O.O.O.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.O.#.|.|)\n+------------------------+"
},
{
"input": "32",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.O.|D|)\n|O.O.O.O.O.O.O.O.O.O.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.O.#.|.|)\n+------------------------+"
},
{
"input": "33",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.O.|D|)\n|O.O.O.O.O.O.O.O.O.O.O.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.O.#.|.|)\n+------------------------+"
},
{
"input": "34",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.O.|D|)\n|O.O.O.O.O.O.O.O.O.O.O.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.O.O.|.|)\n+------------------------+"
}
] | 1,414,050,618 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 0 | from sys import stdin
def main():
n=int(stdin.readline().strip())
b=[['+','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','+'],['|','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','|','D','|',')'],['|','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','|','.','|'],['|','#','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','|'],['|','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','|','.','|',')'],['+','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','+']]
i=1
while (n>0):
j=0
while (n>0) and (j<5):
if (b[j][i]=='#'):
b[j][i]='O'
n=n-1
j=j+1
i=i+1
for i in range (len(b)):
for j in range (len(b[i])):
print(b[i][j],end='')
print()
main() | Title: Bayan Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The event coordinator has a list of *k* participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one.
In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by *k* participants. Your task is to draw the figure representing occupied seats.
Input Specification:
The only line of input contains integer *k*, (0<=≤<=*k*<=≤<=34), denoting the number of participants.
Output Specification:
Print the figure of a bus with *k* passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters.
Demo Input:
['9\n', '20\n']
Demo Output:
['+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n', '+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+\n']
Note:
none | ```python
from sys import stdin
def main():
n=int(stdin.readline().strip())
b=[['+','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','+'],['|','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','|','D','|',')'],['|','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','|','.','|'],['|','#','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','|'],['|','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','|','.','|',')'],['+','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','+']]
i=1
while (n>0):
j=0
while (n>0) and (j<5):
if (b[j][i]=='#'):
b[j][i]='O'
n=n-1
j=j+1
i=i+1
for i in range (len(b)):
for j in range (len(b[i])):
print(b[i][j],end='')
print()
main()
``` | 3 |
|
598 | D | Igor In the Museum | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture.
At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one.
For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see. | First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum.
Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells. | Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. | [
"5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n",
"4 4 1\n****\n*..*\n*.**\n****\n3 2\n"
] | [
"6\n4\n10\n",
"8\n"
] | none | 0 | [
{
"input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3",
"output": "6\n4\n10"
},
{
"input": "4 4 1\n****\n*..*\n*.**\n****\n3 2",
"output": "8"
},
{
"input": "3 3 1\n***\n*.*\n***\n2 2",
"output": "4"
},
{
"input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\n2 4\n4 2\n2 2\n2 3\n2 2\n2 2\n2 4\n3 2\n2 2\n2 2",
"output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12"
},
{
"input": "10 3 10\n***\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n***\n2 2\n2 2\n2 2\n2 2\n8 2\n2 2\n2 2\n7 2\n8 2\n6 2",
"output": "6\n6\n6\n6\n10\n6\n6\n10\n10\n10"
},
{
"input": "3 10 10\n**********\n***.*.*..*\n**********\n2 6\n2 6\n2 9\n2 9\n2 4\n2 9\n2 6\n2 6\n2 4\n2 6",
"output": "4\n4\n6\n6\n4\n6\n4\n4\n4\n4"
},
{
"input": "10 10 50\n**********\n*......***\n***..**..*\n***....***\n**..***..*\n**..**.*.*\n*****..***\n*.***..***\n*..****.**\n**********\n5 9\n5 9\n7 7\n6 4\n6 7\n8 7\n6 7\n9 2\n3 9\n9 2\n4 7\n4 6\n2 7\n9 2\n7 7\n5 8\n8 7\n8 6\n7 7\n5 9\n8 7\n3 8\n3 8\n5 9\n9 8\n9 3\n8 7\n5 9\n9 2\n9 8\n9 3\n3 8\n9 2\n8 6\n2 4\n6 9\n6 3\n9 8\n3 9\n9 8\n4 5\n8 6\n3 8\n5 9\n8 7\n5 8\n6 9\n8 2\n3 9\n3 9",
"output": "8\n8\n10\n28\n10\n10\n10\n8\n6\n8\n28\n28\n28\n8\n10\n8\n10\n10\n10\n8\n10\n6\n6\n8\n4\n8\n10\n8\n8\n4\n8\n6\n8\n10\n28\n8\n28\n4\n6\n4\n28\n10\n6\n8\n10\n8\n8\n8\n6\n6"
},
{
"input": "5 5 21\n*****\n*.***\n*****\n*****\n*****\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2",
"output": "4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4"
}
] | 1,682,109,320 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n, m = map(int, input().split())
s = [input() for i in range(n)]
vis = [[0] * m for i in range(n)]
vis2 = [[0] * m for i in range(n)]
dist = [[0] * m for i in range(n)]
def DFS(i, j):
if (vis[i][j] and s[i][j] == '.') or i < 0 or j < 0 or i >= n or j >= m:
return 0
if s[i][j] == '*':
vis[i][j] = 1
return 1
cnt = 0
vis[i][j] = 1
cnt += DFS(i + 1, j)
cnt += DFS(i - 1, j)
cnt += DFS(i, j + 1)
cnt += DFS(i, j - 1)
return cnt
def DFS_2(i, j, c):
if vis2[i][j] or i < 0 or j < 0 or i >= n or j >= m or s[i][j] == '*':
return
vis2[i][j] = 1
dist[i][j] = c
DFS_2(i + 1, j, c)
DFS_2(i - 1, j, c)
DFS_2(i, j + 1, c)
DFS_2(i, j - 1, c)
k = int(input())
for i in range(k):
r, c = map(int, input().split())
r -= 1
c -= 1
if vis2[r][c]:
print(dist[r][c])
else:
x = DFS(r, c)
DFS_2(r, c, x)
print(x)
| Title: Igor In the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture.
At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one.
For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see.
Input Specification:
First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum.
Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.
Output Specification:
Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.
Demo Input:
['5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n', '4 4 1\n****\n*..*\n*.**\n****\n3 2\n']
Demo Output:
['6\n4\n10\n', '8\n']
Note:
none | ```python
n, m = map(int, input().split())
s = [input() for i in range(n)]
vis = [[0] * m for i in range(n)]
vis2 = [[0] * m for i in range(n)]
dist = [[0] * m for i in range(n)]
def DFS(i, j):
if (vis[i][j] and s[i][j] == '.') or i < 0 or j < 0 or i >= n or j >= m:
return 0
if s[i][j] == '*':
vis[i][j] = 1
return 1
cnt = 0
vis[i][j] = 1
cnt += DFS(i + 1, j)
cnt += DFS(i - 1, j)
cnt += DFS(i, j + 1)
cnt += DFS(i, j - 1)
return cnt
def DFS_2(i, j, c):
if vis2[i][j] or i < 0 or j < 0 or i >= n or j >= m or s[i][j] == '*':
return
vis2[i][j] = 1
dist[i][j] = c
DFS_2(i + 1, j, c)
DFS_2(i - 1, j, c)
DFS_2(i, j + 1, c)
DFS_2(i, j - 1, c)
k = int(input())
for i in range(k):
r, c = map(int, input().split())
r -= 1
c -= 1
if vis2[r][c]:
print(dist[r][c])
else:
x = DFS(r, c)
DFS_2(r, c, x)
print(x)
``` | -1 |
|
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,633,402,160 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 61 | 6,963,200 | #https://codeforces.com/problemset/problem/58/A
s = input()
j = 0
if s[0] == "h":
j += 1
l_flag = True
for i in range(1, len(s)):
if s[i] == s[i-1] and l_flag:
continue
if s[i] == "hello"[j]:
if j == 4:
j += 1
break
j += 1
if j == 3: l_flag = False
else: l_flag = True
continue
if j == 5:
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
#https://codeforces.com/problemset/problem/58/A
s = input()
j = 0
if s[0] == "h":
j += 1
l_flag = True
for i in range(1, len(s)):
if s[i] == s[i-1] and l_flag:
continue
if s[i] == "hello"[j]:
if j == 4:
j += 1
break
j += 1
if j == 3: l_flag = False
else: l_flag = True
continue
if j == 5:
print("YES")
else:
print("NO")
``` | 3.95653 |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"input": "2 3",
"output": "2 0 4"
},
{
"input": "5 6",
"output": "5 0 1"
},
{
"input": "4 4",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
},
{
"input": "6 4",
"output": "1 1 4"
},
{
"input": "1 4",
"output": "2 0 4"
},
{
"input": "5 5",
"output": "0 6 0"
},
{
"input": "4 5",
"output": "4 0 2"
},
{
"input": "4 3",
"output": "3 0 3"
},
{
"input": "1 5",
"output": "2 1 3"
},
{
"input": "6 5",
"output": "1 0 5"
},
{
"input": "2 2",
"output": "0 6 0"
},
{
"input": "1 3",
"output": "1 1 4"
},
{
"input": "3 6",
"output": "4 0 2"
},
{
"input": "3 1",
"output": "4 1 1"
},
{
"input": "3 2",
"output": "4 0 2"
},
{
"input": "3 5",
"output": "3 1 2"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "6 2",
"output": "2 1 3"
},
{
"input": "4 1",
"output": "4 0 2"
},
{
"input": "5 2",
"output": "3 0 3"
},
{
"input": "4 2",
"output": "3 1 2"
},
{
"input": "2 1",
"output": "5 0 1"
},
{
"input": "6 1",
"output": "3 0 3"
},
{
"input": "4 6",
"output": "4 1 1"
},
{
"input": "2 6",
"output": "3 1 2"
},
{
"input": "3 4",
"output": "3 0 3"
},
{
"input": "1 2",
"output": "1 0 5"
},
{
"input": "6 6",
"output": "0 6 0"
},
{
"input": "5 4",
"output": "2 0 4"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
}
] | 1,624,332,947 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 62 | 0 |
a,b = [int(i) for i in input().split()]
pa =0
pb = 0
pd = 0
if a > b:
numdis = a-b-1
if numdis%2 !=0:
pd+=1
max_ = b + int(numdis/2)
pb = max_
pa = 6- max_ -pd
elif a == b:
pd = 6
else:
numdis = b-a-1
if numdis%2 !=0:
pd+=1
max_ = a + int(numdis/2)
pa = max_
pb = 6- max_ - pd
print(pa,pd,pb)
| Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
Input Specification:
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Output Specification:
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
Demo Input:
['2 5\n', '2 4\n']
Demo Output:
['3 0 3\n', '2 1 3\n']
Note:
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | ```python
a,b = [int(i) for i in input().split()]
pa =0
pb = 0
pd = 0
if a > b:
numdis = a-b-1
if numdis%2 !=0:
pd+=1
max_ = b + int(numdis/2)
pb = max_
pa = 6- max_ -pd
elif a == b:
pd = 6
else:
numdis = b-a-1
if numdis%2 !=0:
pd+=1
max_ = a + int(numdis/2)
pa = max_
pb = 6- max_ - pd
print(pa,pd,pb)
``` | 3 |
|
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City? | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,698,637,184 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def last_two_digits_of_5_power_n(n):
result = pow(5, n, 100)
result_str = str(result)
if result < 10:
result_str = "0" + result_str
return result_str
def main():
n = int(input("Enter the value of n: "))
result = last_two_digits_of_5_power_n(n)
print(result)
if __name__ == "__main__":
main()
| Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City?
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5.
Output Specification:
Output the last two digits of 5*n* without spaces between them.
Demo Input:
['2\n']
Demo Output:
['25']
Note:
none | ```python
def last_two_digits_of_5_power_n(n):
result = pow(5, n, 100)
result_str = str(result)
if result < 10:
result_str = "0" + result_str
return result_str
def main():
n = int(input("Enter the value of n: "))
result = last_two_digits_of_5_power_n(n)
print(result)
if __name__ == "__main__":
main()
``` | 0 |
|
656 | F | Ace It! | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer. | The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). | Output a single integer. | [
"A221033\n",
"A223635\n",
"A232726\n"
] | [
"21\n",
"22\n",
"23\n"
] | none | 0 | [
{
"input": "A221033",
"output": "21"
},
{
"input": "A223635",
"output": "22"
},
{
"input": "A232726",
"output": "23"
},
{
"input": "A102210",
"output": "25"
},
{
"input": "A231010",
"output": "26"
},
{
"input": "A222222",
"output": "13"
},
{
"input": "A555555",
"output": "31"
},
{
"input": "A102222",
"output": "19"
},
{
"input": "A234567",
"output": "28"
},
{
"input": "A987654",
"output": "40"
},
{
"input": "A101010",
"output": "31"
},
{
"input": "A246810",
"output": "31"
},
{
"input": "A210210",
"output": "25"
},
{
"input": "A458922",
"output": "31"
},
{
"input": "A999999",
"output": "55"
},
{
"input": "A888888",
"output": "49"
},
{
"input": "A232232",
"output": "15"
},
{
"input": "A222210",
"output": "19"
},
{
"input": "A710210",
"output": "30"
},
{
"input": "A342987",
"output": "34"
},
{
"input": "A987623",
"output": "36"
},
{
"input": "A109109",
"output": "39"
},
{
"input": "A910109",
"output": "39"
},
{
"input": "A292992",
"output": "34"
},
{
"input": "A388338",
"output": "34"
},
{
"input": "A764598",
"output": "40"
},
{
"input": "A332567",
"output": "27"
},
{
"input": "A108888",
"output": "43"
},
{
"input": "A910224",
"output": "28"
},
{
"input": "A321046",
"output": "26"
},
{
"input": "A767653",
"output": "35"
},
{
"input": "A101099",
"output": "39"
},
{
"input": "A638495",
"output": "36"
}
] | 1,459,579,249 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 4,608,000 | #5
k = str(int(input(), 16))
t = sum(map(int, k))
was = False
result = str(t)
while t > 32:
t -= 1
was = True
if was:
result = str(t)
result = result[1] + result[0]
print(result) | Title: Ace It!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer.
Input Specification:
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output Specification:
Output a single integer.
Demo Input:
['A221033\n', 'A223635\n', 'A232726\n']
Demo Output:
['21\n', '22\n', '23\n']
Note:
none | ```python
#5
k = str(int(input(), 16))
t = sum(map(int, k))
was = False
result = str(t)
while t > 32:
t -= 1
was = True
if was:
result = str(t)
result = result[1] + result[0]
print(result)
``` | 0 |
|
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City? | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,695,383,519 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | z = int(input())
print (5**z) | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City?
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5.
Output Specification:
Output the last two digits of 5*n* without spaces between them.
Demo Input:
['2\n']
Demo Output:
['25']
Note:
none | ```python
z = int(input())
print (5**z)
``` | 0 |
|
779 | A | Pupils Redistribution | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and 5.
The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.
To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class *A* and one student of class *B*. After that, they both change their groups.
Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance. | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=100) — number of students in both groups.
The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5), where *a**i* is academic performance of the *i*-th student of the group *A*.
The third line contains sequence of integer numbers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=5), where *b**i* is academic performance of the *i*-th student of the group *B*. | Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. | [
"4\n5 4 4 4\n5 5 4 5\n",
"6\n1 1 1 1 1 1\n5 5 5 5 5 5\n",
"1\n5\n3\n",
"9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n"
] | [
"1\n",
"3\n",
"-1\n",
"4\n"
] | none | 500 | [
{
"input": "4\n5 4 4 4\n5 5 4 5",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5",
"output": "3"
},
{
"input": "1\n5\n3",
"output": "-1"
},
{
"input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1",
"output": "4"
},
{
"input": "1\n1\n2",
"output": "-1"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "8\n1 1 2 2 3 3 4 4\n4 4 5 5 1 1 1 1",
"output": "2"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1\n2 2 2 2 2 2 2 2 2 2",
"output": "5"
},
{
"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\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": "0"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "2\n1 2\n1 1",
"output": "-1"
},
{
"input": "2\n2 2\n1 1",
"output": "1"
},
{
"input": "2\n1 2\n2 1",
"output": "0"
},
{
"input": "2\n1 1\n2 2",
"output": "1"
},
{
"input": "5\n5 5 5 5 5\n5 5 5 5 5",
"output": "0"
},
{
"input": "5\n5 5 5 3 5\n5 3 5 5 5",
"output": "0"
},
{
"input": "5\n2 3 2 3 3\n2 3 2 2 2",
"output": "1"
},
{
"input": "5\n4 4 1 4 2\n1 2 4 2 2",
"output": "1"
},
{
"input": "50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "0"
},
{
"input": "50\n1 3 1 3 3 3 1 3 3 3 3 1 1 1 3 3 3 1 3 1 1 1 3 1 3 1 3 3 3 1 3 1 1 3 3 3 1 1 1 1 3 3 1 1 1 3 3 1 1 1\n1 3 1 3 3 1 1 3 1 3 3 1 1 1 1 3 3 1 3 1 1 3 1 1 3 1 1 1 1 3 3 1 3 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 3 1",
"output": "0"
},
{
"input": "50\n1 1 1 4 1 1 4 1 4 1 1 4 1 1 4 1 1 4 1 1 4 1 4 4 4 1 1 4 1 4 4 4 4 4 4 4 1 4 1 1 1 1 4 1 4 4 1 1 1 4\n1 4 4 1 1 4 1 4 4 1 1 4 1 4 1 1 4 1 1 1 4 4 1 1 4 1 4 1 1 4 4 4 4 1 1 4 4 1 1 1 4 1 4 1 4 1 1 1 4 4",
"output": "0"
},
{
"input": "50\n3 5 1 3 3 4 3 4 2 5 2 1 2 2 5 5 4 5 4 2 1 3 4 2 3 3 3 2 4 3 5 5 5 5 5 5 2 5 2 2 5 4 4 1 5 3 4 2 1 3\n3 5 3 2 5 3 4 4 5 2 3 4 4 4 2 2 4 4 4 3 3 5 5 4 3 1 4 4 5 5 4 1 2 5 5 4 1 2 3 4 5 5 3 2 3 4 3 5 1 1",
"output": "3"
},
{
"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\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": "0"
},
{
"input": "100\n1 1 3 1 3 1 1 3 1 1 3 1 3 1 1 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 1 1 1 3 1 1 1 3 1 1 3 3 1 3 3 1 3 1 3 3 3 3 1 1 3 3 3 1 1 3 1 3 3 3 1 3 3 3 3 3 1 3 3 3 3 1 3 1 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 1 1 3 1 1 1\n1 1 1 3 3 3 3 3 3 3 1 3 3 3 1 3 3 3 3 3 3 1 3 3 1 3 3 1 1 1 3 3 3 3 3 3 3 1 1 3 3 3 1 1 3 3 1 1 1 3 3 3 1 1 3 1 1 3 3 1 1 3 3 3 3 3 3 1 3 3 3 1 1 3 3 3 1 1 3 3 1 3 1 3 3 1 1 3 3 1 1 3 1 3 3 3 1 3 1 3",
"output": "0"
},
{
"input": "100\n2 4 5 2 5 5 4 4 5 4 4 5 2 5 5 4 5 2 5 2 2 4 5 4 4 4 2 4 2 2 4 2 4 2 2 2 4 5 5 5 4 2 4 5 4 4 2 5 4 2 5 4 5 4 5 4 5 5 5 4 2 2 4 5 2 5 5 2 5 2 4 4 4 5 5 2 2 2 4 4 2 2 2 5 5 2 2 4 5 4 2 4 4 2 5 2 4 4 4 4\n4 4 2 5 2 2 4 2 5 2 5 4 4 5 2 4 5 4 5 2 2 2 2 5 4 5 2 4 2 2 5 2 5 2 4 5 5 5 2 5 4 4 4 4 5 2 2 4 2 4 2 4 5 5 5 4 5 4 5 5 5 2 5 4 4 4 4 4 2 5 5 4 2 4 4 5 5 2 4 4 4 2 2 2 5 4 2 2 4 5 4 4 4 4 2 2 4 5 5 2",
"output": "0"
},
{
"input": "100\n3 3 4 3 3 4 3 1 4 2 1 3 1 1 2 4 4 4 4 1 1 4 1 4 4 1 1 2 3 3 3 2 4 2 3 3 3 1 3 4 2 2 1 3 4 4 3 2 2 2 4 2 1 2 1 2 2 1 1 4 2 1 3 2 4 4 4 2 3 1 3 1 3 2 2 2 2 4 4 1 3 1 1 4 2 3 3 4 4 2 4 4 2 4 3 3 1 3 2 4\n3 1 4 4 2 1 1 1 1 1 1 3 1 1 3 4 3 2 2 4 2 1 4 4 4 4 1 2 3 4 2 3 3 4 3 3 2 4 2 2 2 1 2 4 4 4 2 1 3 4 3 3 4 2 4 4 3 2 4 2 4 2 4 4 1 4 3 1 4 3 3 3 3 1 2 2 2 2 4 1 2 1 3 4 3 1 3 3 4 2 3 3 2 1 3 4 2 1 1 2",
"output": "0"
},
{
"input": "100\n2 4 5 2 1 5 5 2 1 5 1 5 1 1 1 3 4 5 1 1 2 3 3 1 5 5 4 4 4 1 1 1 5 2 3 5 1 2 2 1 1 1 2 2 1 2 4 4 5 1 3 2 5 3 5 5 3 2 2 2 1 3 4 4 4 4 4 5 3 1 4 1 5 4 4 5 4 5 2 4 4 3 1 2 1 4 5 3 3 3 3 2 2 2 3 5 3 1 3 4\n3 2 5 1 5 4 4 3 5 5 5 2 1 4 4 3 2 3 3 5 5 4 5 5 2 1 2 4 4 3 5 1 1 5 1 3 2 5 2 4 4 2 4 2 4 2 3 2 5 1 4 4 1 1 1 5 3 5 1 1 4 5 1 1 2 2 5 3 5 1 1 1 2 3 3 2 3 2 4 4 5 4 2 1 3 4 1 1 2 4 1 5 3 1 2 1 3 4 1 3",
"output": "0"
},
{
"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\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": "0"
},
{
"input": "100\n1 4 4 1 4 4 1 1 4 1 1 1 1 4 4 4 4 1 1 1 1 1 1 4 4 4 1 1 4 4 1 1 1 1 4 4 4 4 4 1 1 4 4 1 1 1 4 1 1 1 1 4 4 4 4 4 4 1 4 4 4 4 1 1 1 4 1 4 1 1 1 1 4 1 1 1 4 4 4 1 4 4 1 4 4 4 4 4 1 4 1 1 4 1 4 1 1 1 4 4\n4 1 1 4 4 4 1 4 4 4 1 1 4 1 1 4 1 4 4 4 1 1 4 1 4 1 1 1 4 4 1 4 1 4 1 4 4 1 1 4 1 4 1 1 1 4 1 4 4 4 1 4 1 4 4 4 4 1 4 1 1 4 1 1 4 4 4 1 4 1 4 1 4 4 4 1 1 4 1 4 4 4 4 1 1 1 1 1 4 4 1 4 1 4 1 1 1 4 4 1",
"output": "1"
},
{
"input": "100\n5 2 5 2 2 3 3 2 5 3 2 5 3 3 3 5 2 2 5 5 3 3 5 3 2 2 2 3 2 2 2 2 3 5 3 3 2 3 2 5 3 3 5 3 2 2 5 5 5 5 5 2 3 2 2 2 2 3 2 5 2 2 2 3 5 5 5 3 2 2 2 3 5 3 2 5 5 3 5 5 5 3 2 5 2 3 5 3 2 5 5 3 5 2 3 3 2 2 2 2\n5 3 5 3 3 5 2 5 3 2 3 3 5 2 5 2 2 5 2 5 2 5 3 3 5 3 2 2 2 3 5 3 2 2 3 2 2 5 5 2 3 2 3 3 5 3 2 5 2 2 2 3 3 5 3 3 5 2 2 2 3 3 2 2 3 5 3 5 5 3 3 2 5 3 5 2 3 2 5 5 3 2 5 5 2 2 2 2 3 2 2 5 2 5 2 2 3 3 2 5",
"output": "1"
},
{
"input": "100\n4 4 5 4 3 5 5 2 4 5 5 5 3 4 4 2 5 2 5 3 3 3 3 5 3 2 2 2 4 4 4 4 3 3 4 5 3 2 2 2 4 4 5 3 4 5 4 5 5 2 4 2 5 2 3 4 4 5 2 2 4 4 5 5 5 3 5 4 5 5 5 4 3 3 2 4 3 5 5 5 2 4 2 5 4 3 5 3 2 3 5 2 5 2 2 5 4 5 4 3\n5 4 2 4 3 5 2 5 5 3 4 5 4 5 3 3 5 5 2 3 4 2 3 5 2 2 2 4 2 5 2 4 4 5 2 2 4 4 5 5 2 3 4 2 4 5 2 5 2 2 4 5 5 3 5 5 5 4 3 4 4 3 5 5 3 4 5 3 2 3 4 3 4 4 2 5 3 4 5 5 3 5 3 3 4 3 5 3 2 2 4 5 4 5 5 2 3 4 3 5",
"output": "1"
},
{
"input": "100\n1 4 2 2 2 1 4 5 5 5 4 4 5 5 1 3 2 1 4 5 2 3 4 4 5 4 4 4 4 5 1 3 5 5 3 3 3 3 5 1 4 3 5 1 2 4 1 3 5 5 1 3 3 3 1 3 5 4 4 2 2 5 5 5 2 3 2 5 1 3 5 4 5 3 2 2 3 2 3 3 2 5 2 4 2 3 4 1 3 1 3 1 5 1 5 2 3 5 4 5\n1 2 5 3 2 3 4 2 5 1 2 5 3 4 3 3 4 1 5 5 1 3 3 1 1 4 1 4 2 5 4 1 3 4 5 3 2 2 1 4 5 5 2 3 3 5 5 4 2 3 3 5 3 3 5 4 4 5 3 5 1 1 4 4 4 1 3 5 5 5 4 2 4 5 3 2 2 2 5 5 5 1 4 3 1 3 1 2 2 4 5 1 3 2 4 5 1 5 2 5",
"output": "1"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "100\n5 2 2 2 5 2 5 5 5 2 5 2 5 5 5 5 5 5 2 2 2 5 5 2 5 2 2 5 2 5 5 2 5 2 5 2 5 5 5 5 5 2 2 2 2 5 5 2 5 5 5 2 5 5 5 2 5 5 5 2 2 2 5 2 2 2 5 5 2 5 5 5 2 5 2 2 5 2 2 2 5 5 5 5 2 5 2 5 2 2 5 2 5 2 2 2 2 5 5 2\n5 5 2 2 5 5 2 5 2 2 5 5 5 5 2 5 5 2 5 2 2 5 2 2 5 2 5 2 2 5 2 5 2 5 5 2 2 5 5 5 2 5 5 2 5 5 5 2 2 5 5 5 2 5 5 5 2 2 2 5 5 5 2 2 5 5 2 2 2 5 2 5 5 2 5 2 5 2 2 5 5 2 2 5 5 2 2 5 2 2 5 2 2 2 5 5 2 2 2 5",
"output": "1"
},
{
"input": "100\n3 3 2 2 1 2 3 3 2 2 1 1 3 3 1 1 1 2 1 2 3 2 3 3 3 1 2 3 1 2 1 2 3 3 2 1 1 1 1 1 2 2 3 2 1 1 3 3 1 3 3 1 3 1 3 3 3 2 1 2 3 1 3 2 2 2 2 2 2 3 1 3 1 2 2 1 2 3 2 3 3 1 2 1 1 3 1 1 1 2 1 2 2 2 3 2 3 2 1 1\n1 3 1 2 1 1 1 1 1 2 1 2 1 3 2 2 3 2 1 1 2 2 2 1 1 3 2 3 2 1 2 2 3 2 3 1 3 1 1 2 3 1 2 1 3 2 1 2 3 2 3 3 3 2 2 2 3 1 3 1 1 2 1 3 1 3 1 3 3 3 1 3 3 2 1 3 3 3 3 3 2 1 2 2 3 3 2 1 2 2 1 3 3 1 3 2 2 1 1 3",
"output": "1"
},
{
"input": "100\n5 3 3 2 5 3 2 4 2 3 3 5 3 4 5 4 3 3 4 3 2 3 3 4 5 4 2 4 2 4 5 3 3 4 5 3 5 3 5 3 3 2 5 3 4 5 2 5 2 2 4 2 2 2 2 5 4 5 4 3 5 4 2 5 5 3 4 5 2 3 2 2 2 5 3 2 2 2 3 3 5 2 3 2 4 5 3 3 3 5 2 3 3 3 5 4 5 5 5 2\n4 4 4 5 5 3 5 5 4 3 5 4 3 4 3 3 5 3 5 5 3 3 3 5 5 4 4 3 2 5 4 3 3 4 5 3 5 2 4 2 2 2 5 3 5 2 5 5 3 3 2 3 3 4 2 5 2 5 2 4 2 4 2 3 3 4 2 2 2 4 4 3 3 3 4 3 3 3 5 5 3 4 2 2 3 5 5 2 3 4 5 4 5 3 4 2 5 3 2 4",
"output": "3"
},
{
"input": "100\n5 3 4 4 2 5 1 1 4 4 3 5 5 1 4 4 2 5 3 2 1 1 3 2 4 4 4 2 5 2 2 3 1 4 1 4 4 5 3 5 1 4 1 4 1 5 5 3 5 5 1 5 3 5 1 3 3 4 5 3 2 2 4 5 2 5 4 2 4 4 1 1 4 2 4 1 2 2 4 3 4 1 1 1 4 3 5 1 2 1 4 5 4 4 2 1 4 1 3 2\n1 1 1 1 4 2 1 4 1 1 3 5 4 3 5 2 2 4 2 2 4 1 3 4 4 5 1 1 2 2 2 1 4 1 4 4 1 5 5 2 3 5 1 5 4 2 3 2 2 5 4 1 1 4 5 2 4 5 4 4 3 3 2 4 3 4 5 5 4 2 4 2 1 2 3 2 2 5 5 3 1 3 4 3 4 4 5 3 1 1 3 5 1 4 4 2 2 1 4 5",
"output": "2"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "100\n3 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 4 4 3 3 3 3 3 3 4 3 3 4 3 3 3 3 4 3 3 3 4 4 4 3 3 4 4 4 3 4 4 3 3 4 3 3 3 4 4 4 3 4 3 3 3 3 3 3 3 4 4 3 3 3 3 4 3 3 3 3 3 4 4 3 3 3 3 3 4 3 4 4 4 4 3 4 3 4 4 4 4 3 3\n4 3 3 3 3 4 4 3 4 4 4 3 3 4 4 3 4 4 4 4 3 4 3 3 3 4 4 4 3 4 3 4 4 3 3 4 3 3 3 3 3 4 3 3 3 3 4 4 4 3 3 4 3 4 4 4 4 3 4 4 3 3 4 3 3 4 3 4 3 4 4 4 4 3 3 4 3 4 4 4 3 3 4 4 4 4 4 3 3 3 4 3 3 4 3 3 3 3 3 3",
"output": "5"
},
{
"input": "100\n4 2 5 2 5 4 2 5 5 4 4 2 4 4 2 4 4 5 2 5 5 2 2 4 4 5 4 5 5 5 2 2 2 2 4 4 5 2 4 4 4 2 2 5 5 4 5 4 4 2 4 5 4 2 4 5 4 2 4 5 4 4 4 4 4 5 4 2 5 2 5 5 5 5 4 2 5 5 4 4 2 5 2 5 2 5 4 2 4 2 4 5 2 5 2 4 2 4 2 4\n5 4 5 4 5 2 2 4 5 2 5 5 5 5 5 4 4 4 4 5 4 5 5 2 4 4 4 4 5 2 4 4 5 5 2 5 2 5 5 4 4 5 2 5 2 5 2 5 4 5 2 5 2 5 2 4 4 5 4 2 5 5 4 2 2 2 5 4 2 2 4 4 4 5 5 2 5 2 2 4 4 4 2 5 4 5 2 2 5 4 4 5 5 4 5 5 4 5 2 5",
"output": "5"
},
{
"input": "100\n3 4 5 3 5 4 5 4 4 4 2 4 5 4 3 2 3 4 3 5 2 5 2 5 4 3 4 2 5 2 5 3 4 5 2 5 4 2 4 5 4 3 2 4 4 5 2 5 5 3 3 5 2 4 4 2 3 3 2 5 5 5 2 4 5 5 4 2 2 5 3 3 2 4 4 2 4 5 5 2 5 5 3 2 5 2 4 4 3 3 5 4 5 5 2 5 4 5 4 3\n4 3 5 5 2 4 2 4 5 5 5 2 3 3 3 3 5 5 5 5 3 5 2 3 5 2 3 2 2 5 5 3 5 3 4 2 2 5 3 3 3 3 5 2 4 5 3 5 3 4 4 4 5 5 3 4 4 2 2 4 4 5 3 2 4 5 5 4 5 2 2 3 5 4 5 5 2 5 4 3 2 3 2 5 4 5 3 4 5 5 3 5 2 2 4 4 3 2 5 2",
"output": "4"
},
{
"input": "100\n4 1 1 2 1 4 4 1 4 5 5 5 2 2 1 3 5 2 1 5 2 1 2 4 4 2 1 2 2 2 4 3 1 4 2 2 3 1 1 4 4 5 4 4 4 5 1 4 1 4 3 1 2 1 2 4 1 2 5 2 1 4 3 4 1 4 2 1 1 1 5 3 3 1 4 1 3 1 4 1 1 2 2 2 3 1 4 3 4 4 5 2 5 4 3 3 3 2 2 1\n5 1 4 4 3 4 4 5 2 3 3 4 4 2 3 2 3 1 3 1 1 4 1 5 4 3 2 4 3 3 3 2 3 4 1 5 4 2 4 2 2 2 5 3 1 2 5 3 2 2 1 1 2 2 3 5 1 2 5 3 2 1 1 2 1 2 4 3 5 4 5 3 2 4 1 3 4 1 4 4 5 4 4 5 4 2 5 3 4 1 4 2 4 2 4 5 4 5 4 2",
"output": "6"
},
{
"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\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": "0"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 1 4 4 4 4 4 4 4 4 4 4\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "0"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "1"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 4 3 3 3 3 3 3 3 3 3 3 1 3 1 3 3 3 3 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 4 3 3 3 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 1 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3",
"output": "1"
},
{
"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\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "100\n3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5\n3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1",
"output": "25"
},
{
"input": "100\n3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5\n2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4",
"output": "50"
},
{
"input": "100\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\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": "40"
},
{
"input": "100\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3",
"output": "30"
},
{
"input": "5\n4 4 4 4 5\n4 5 5 5 5",
"output": "-1"
},
{
"input": "4\n1 1 1 1\n3 3 3 3",
"output": "2"
},
{
"input": "6\n1 1 2 2 3 4\n1 2 3 3 4 4",
"output": "-1"
},
{
"input": "4\n1 1 1 2\n3 3 3 3",
"output": "-1"
},
{
"input": "3\n2 2 2\n4 4 4",
"output": "-1"
},
{
"input": "2\n1 2\n3 4",
"output": "-1"
},
{
"input": "6\n1 1 1 3 3 3\n2 2 2 4 4 4",
"output": "-1"
},
{
"input": "5\n1 2 2 2 2\n1 1 1 1 3",
"output": "-1"
},
{
"input": "2\n1 3\n2 2",
"output": "-1"
},
{
"input": "2\n1 3\n4 5",
"output": "-1"
},
{
"input": "4\n1 2 3 4\n5 5 5 5",
"output": "-1"
},
{
"input": "2\n1 3\n2 4",
"output": "-1"
},
{
"input": "2\n1 2\n4 4",
"output": "-1"
},
{
"input": "2\n1 2\n3 3",
"output": "-1"
},
{
"input": "10\n4 4 4 4 2 3 3 3 3 1\n2 2 2 2 4 1 1 1 1 3",
"output": "-1"
},
{
"input": "6\n1 2 3 3 4 4\n1 1 2 2 3 4",
"output": "-1"
},
{
"input": "5\n3 3 3 3 1\n1 1 1 1 3",
"output": "-1"
},
{
"input": "2\n1 1\n2 3",
"output": "-1"
},
{
"input": "8\n1 1 2 2 3 3 3 3\n2 2 2 2 1 1 1 1",
"output": "2"
},
{
"input": "5\n1 1 1 3 3\n1 1 1 1 2",
"output": "-1"
},
{
"input": "6\n2 2 3 3 4 4\n2 3 4 5 5 5",
"output": "-1"
},
{
"input": "6\n1 1 2 2 3 4\n3 3 4 4 1 2",
"output": "-1"
},
{
"input": "4\n1 2 3 3\n3 3 3 3",
"output": "-1"
},
{
"input": "3\n1 2 3\n3 3 3",
"output": "-1"
},
{
"input": "5\n3 3 3 2 2\n2 2 2 3 3",
"output": "-1"
},
{
"input": "10\n1 2 3 4 1 2 3 4 1 2\n1 2 3 4 1 2 3 4 3 4",
"output": "-1"
},
{
"input": "2\n2 2\n1 3",
"output": "-1"
},
{
"input": "3\n1 2 3\n1 1 4",
"output": "-1"
},
{
"input": "4\n3 4 4 4\n3 3 4 4",
"output": "-1"
}
] | 1,488,814,382 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | '''
http://codeforces.com/problemset/problem/779/A
'''
n = int(input())
groupA = list(map(int, input().split()))
groupB = list(map(int, input().split()))
def num_switches(n, groupA, groupB):
diff = [0, 0, 0, 0, 0]
for score in range(1, 6):
if abs(groupA.count(score) - groupB.count(score)) % 2 == 1:
return -1
else:
diff[score - 1] = abs(groupA.count(score) - groupB.count(score))
if sum(diff) % 4 != 0:
return -1
else:
return sum(diff) / 4
print(num_switches(n, groupA, groupB))
| Title: Pupils Redistribution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and 5.
The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.
To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class *A* and one student of class *B*. After that, they both change their groups.
Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.
Input Specification:
The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=100) — number of students in both groups.
The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5), where *a**i* is academic performance of the *i*-th student of the group *A*.
The third line contains sequence of integer numbers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=5), where *b**i* is academic performance of the *i*-th student of the group *B*.
Output Specification:
Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.
Demo Input:
['4\n5 4 4 4\n5 5 4 5\n', '6\n1 1 1 1 1 1\n5 5 5 5 5 5\n', '1\n5\n3\n', '9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n']
Demo Output:
['1\n', '3\n', '-1\n', '4\n']
Note:
none | ```python
'''
http://codeforces.com/problemset/problem/779/A
'''
n = int(input())
groupA = list(map(int, input().split()))
groupB = list(map(int, input().split()))
def num_switches(n, groupA, groupB):
diff = [0, 0, 0, 0, 0]
for score in range(1, 6):
if abs(groupA.count(score) - groupB.count(score)) % 2 == 1:
return -1
else:
diff[score - 1] = abs(groupA.count(score) - groupB.count(score))
if sum(diff) % 4 != 0:
return -1
else:
return sum(diff) / 4
print(num_switches(n, groupA, groupB))
``` | 0 |
|
604 | B | More Cowbell | PROGRAMMING | 1,400 | [
"binary search",
"greedy"
] | null | null | Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection.
Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=><=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*. | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order. | Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*. | [
"2 1\n2 5\n",
"4 3\n2 3 5 9\n",
"3 2\n3 5 7\n"
] | [
"7\n",
"9\n",
"8\n"
] | In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | 1,000 | [
{
"input": "2 1\n2 5",
"output": "7"
},
{
"input": "4 3\n2 3 5 9",
"output": "9"
},
{
"input": "3 2\n3 5 7",
"output": "8"
},
{
"input": "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10 10\n3 15 31 61 63 63 68 94 98 100",
"output": "100"
},
{
"input": "100 97\n340 402 415 466 559 565 649 689 727 771 774 776 789 795 973 1088 1212 1293 1429 1514 1587 1599 1929 1997 2278 2529 2656 2677 2839 2894 2951 3079 3237 3250 3556 3568 3569 3578 3615 3641 3673 3892 4142 4418 4515 4766 4846 4916 5225 5269 5352 5460 5472 5635 5732 5886 5941 5976 5984 6104 6113 6402 6409 6460 6550 6563 6925 7006 7289 7401 7441 7451 7709 7731 7742 7750 7752 7827 8101 8154 8376 8379 8432 8534 8578 8630 8706 8814 8882 8972 9041 9053 9109 9173 9473 9524 9547 9775 9791 9983",
"output": "9983"
},
{
"input": "10 9\n7 29 35 38 41 47 54 56 73 74",
"output": "74"
},
{
"input": "1 2342\n12345",
"output": "12345"
},
{
"input": "10 5\n15 15 20 28 38 44 46 52 69 94",
"output": "109"
},
{
"input": "10 9\n6 10 10 32 36 38 69 80 82 93",
"output": "93"
},
{
"input": "10 10\n4 19 22 24 25 43 49 56 78 88",
"output": "88"
},
{
"input": "100 89\n474 532 759 772 803 965 1043 1325 1342 1401 1411 1452 1531 1707 1906 1928 2034 2222 2335 2606 2757 2968 2978 3211 3513 3734 3772 3778 3842 3948 3976 4038 4055 4113 4182 4267 4390 4408 4478 4595 4668 4792 4919 5133 5184 5255 5312 5341 5476 5628 5683 5738 5767 5806 5973 6051 6134 6254 6266 6279 6314 6342 6599 6676 6747 6777 6827 6842 7057 7097 7259 7340 7378 7405 7510 7520 7698 7796 8148 8351 8507 8601 8805 8814 8826 8978 9116 9140 9174 9338 9394 9403 9407 9423 9429 9519 9764 9784 9838 9946",
"output": "9946"
},
{
"input": "100 74\n10 211 323 458 490 592 979 981 1143 1376 1443 1499 1539 1612 1657 1874 2001 2064 2123 2274 2346 2471 2522 2589 2879 2918 2933 2952 3160 3164 3167 3270 3382 3404 3501 3522 3616 3802 3868 3985 4007 4036 4101 4580 4687 4713 4714 4817 4955 5257 5280 5343 5428 5461 5566 5633 5727 5874 5925 6233 6309 6389 6500 6701 6731 6847 6916 7088 7088 7278 7296 7328 7564 7611 7646 7887 7887 8065 8075 8160 8300 8304 8316 8355 8404 8587 8758 8794 8890 9038 9163 9235 9243 9339 9410 9587 9868 9916 9923 9986",
"output": "9986"
},
{
"input": "100 61\n82 167 233 425 432 456 494 507 562 681 683 921 1218 1323 1395 1531 1586 1591 1675 1766 1802 1842 2116 2625 2697 2735 2739 3337 3349 3395 3406 3596 3610 3721 4059 4078 4305 4330 4357 4379 4558 4648 4651 4784 4819 4920 5049 5312 5361 5418 5440 5463 5547 5594 5821 5951 5972 6141 6193 6230 6797 6842 6853 6854 7017 7026 7145 7322 7391 7460 7599 7697 7756 7768 7872 7889 8094 8215 8408 8440 8462 8714 8756 8760 8881 9063 9111 9184 9281 9373 9406 9417 9430 9511 9563 9634 9660 9788 9883 9927",
"output": "9927"
},
{
"input": "100 84\n53 139 150 233 423 570 786 861 995 1017 1072 1196 1276 1331 1680 1692 1739 1748 1826 2067 2280 2324 2368 2389 2607 2633 2760 2782 2855 2996 3030 3093 3513 3536 3557 3594 3692 3707 3823 3832 4009 4047 4088 4095 4408 4537 4565 4601 4784 4878 4935 5029 5252 5322 5389 5407 5511 5567 5857 6182 6186 6198 6280 6290 6353 6454 6458 6567 6843 7166 7216 7257 7261 7375 7378 7539 7542 7762 7771 7797 7980 8363 8606 8612 8663 8801 8808 8823 8918 8975 8997 9240 9245 9259 9356 9755 9759 9760 9927 9970",
"output": "9970"
},
{
"input": "100 50\n130 248 312 312 334 589 702 916 921 1034 1047 1346 1445 1500 1585 1744 1951 2123 2273 2362 2400 2455 2496 2530 2532 2944 3074 3093 3094 3134 3698 3967 4047 4102 4109 4260 4355 4466 4617 4701 4852 4892 4915 4917 4936 4981 4999 5106 5152 5203 5214 5282 5412 5486 5525 5648 5897 5933 5969 6251 6400 6421 6422 6558 6805 6832 6908 6924 6943 6980 7092 7206 7374 7417 7479 7546 7672 7756 7973 8020 8028 8079 8084 8085 8137 8153 8178 8239 8639 8667 8829 9263 9333 9370 9420 9579 9723 9784 9841 9993",
"output": "11103"
},
{
"input": "100 50\n156 182 208 409 496 515 659 761 772 794 827 912 1003 1236 1305 1388 1412 1422 1428 1465 1613 2160 2411 2440 2495 2684 2724 2925 3033 3035 3155 3260 3378 3442 3483 3921 4031 4037 4091 4113 4119 4254 4257 4442 4559 4614 4687 4839 4896 5054 5246 5316 5346 5859 5928 5981 6148 6250 6422 6433 6448 6471 6473 6485 6503 6779 6812 7050 7064 7074 7141 7378 7424 7511 7574 7651 7808 7858 8286 8291 8446 8536 8599 8628 8636 8768 8900 8981 9042 9055 9114 9146 9186 9411 9480 9590 9681 9749 9757 9983",
"output": "10676"
},
{
"input": "100 50\n145 195 228 411 577 606 629 775 1040 1040 1058 1187 1307 1514 1784 1867 1891 2042 2042 2236 2549 2555 2560 2617 2766 2807 2829 2917 3070 3072 3078 3095 3138 3147 3149 3196 3285 3287 3309 3435 3531 3560 3563 3769 3830 3967 4081 4158 4315 4387 4590 4632 4897 4914 5128 5190 5224 5302 5402 5416 5420 5467 5517 5653 5820 5862 5941 6053 6082 6275 6292 6316 6490 6530 6619 6632 6895 7071 7234 7323 7334 7412 7626 7743 8098 8098 8136 8158 8264 8616 8701 8718 8770 8803 8809 8983 9422 9530 9811 9866",
"output": "10011"
},
{
"input": "100 50\n56 298 387 456 518 532 589 792 870 1041 1055 1122 1141 1166 1310 1329 1523 1548 1626 1730 1780 1833 1850 1911 2006 2157 2303 2377 2403 2442 2450 2522 2573 2822 2994 3200 3238 3252 3280 3311 3345 3422 3429 3506 3526 3617 3686 3791 4134 4467 4525 4614 4633 4792 5017 5220 5243 5338 5445 5536 5639 5675 5763 5875 6129 6220 6228 6287 6385 6616 6789 6822 6940 6959 6985 7297 7304 7391 7443 7580 7824 7884 7981 8055 8063 8223 8280 8322 8346 8473 8688 8986 9087 9323 9477 9489 9518 9621 9699 9804",
"output": "10009"
},
{
"input": "100 49990\n221 257 543 613 818 855 884 1195 1233 1293 1327 1474 1567 1568 1728 1789 1809 1957 1994 2198 2217 2289 2298 2360 2441 2454 2517 2519 2597 2652 2909 2958 2970 3271 3310 3409 3450 3646 3950 3965 4016 4116 4134 4159 4462 4624 4631 4783 4804 5031 5276 5538 5729 5845 5880 5894 5959 5961 6028 6105 6184 6335 6370 6523 6532 6677 6762 6868 6998 7066 7245 7360 7490 7492 7645 7677 7786 7804 8038 8131 8207 8400 8507 8556 8575 8599 8673 8676 8712 8816 9123 9158 9216 9369 9628 9707 9768 9800 9876 9934",
"output": "9934"
},
{
"input": "1 50000\n2",
"output": "2"
},
{
"input": "1 40000\n23456",
"output": "23456"
},
{
"input": "1 2\n10",
"output": "10"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 2\n2 3",
"output": "3"
},
{
"input": "4 2\n1 2 8 9",
"output": "10"
}
] | 1,587,384,683 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 8 | 202 | 10,547,200 | from sys import stdin,stdout
from math import gcd,ceil
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
n, k = iia()
arr = iia()
res = []
l, r = 0, 1
if n % 2 != 0:
r = 2
res.append([arr[-1],0,arr[-1]])
for i in range(n // 2):
a, b = arr[l], arr[-r]
res.append([a + b, a, b])
l += 1
r -= 1
res.sort(reverse=True)
if len(res) == k:
print(res[0][0])
else:
ans = 0
for i in range(k - len(res)):
ans = max(res[i][1], res[i][2], ans)
if k-len(res)<len(res):
ans = max(res[k - len(res)][0], ans)
print(ans)
| Title: More Cowbell
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection.
Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=><=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*.
Input Specification:
The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order.
Output Specification:
Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*.
Demo Input:
['2 1\n2 5\n', '4 3\n2 3 5 9\n', '3 2\n3 5 7\n']
Demo Output:
['7\n', '9\n', '8\n']
Note:
In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | ```python
from sys import stdin,stdout
from math import gcd,ceil
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
n, k = iia()
arr = iia()
res = []
l, r = 0, 1
if n % 2 != 0:
r = 2
res.append([arr[-1],0,arr[-1]])
for i in range(n // 2):
a, b = arr[l], arr[-r]
res.append([a + b, a, b])
l += 1
r -= 1
res.sort(reverse=True)
if len(res) == k:
print(res[0][0])
else:
ans = 0
for i in range(k - len(res)):
ans = max(res[i][1], res[i][2], ans)
if k-len(res)<len(res):
ans = max(res[k - len(res)][0], ans)
print(ans)
``` | -1 |
|
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so. | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"output": "-1"
},
{
"input": "2 2 4\n5 5\n5 5",
"output": "0"
},
{
"input": "7 4 5\n7 7 7 12\n7 12 12 7\n7 7 7 7\n7 7 12 7\n7 7 12 12\n12 12 7 12\n7 7 7 7",
"output": "9"
},
{
"input": "7 7 47\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91",
"output": "0"
},
{
"input": "7 7 47\n47 47 47 47 47 47 47\n47 47 47 47 77 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 127 47",
"output": "-1"
},
{
"input": "7 5 47\n9583 1734 4601 5353 2110\n3802 5165 7985 6293 324\n7045 653 9160 7891 4930\n1781 3520 4178 2298 3943\n1405 2956 5447 5494 6528\n3097 1640 7750 4883 8032\n4225 8455 1875 4789 4366",
"output": "1508"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 1 8\n12",
"output": "0"
}
] | 1,594,832,126 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 6,860,800 | str_inp=[int(ele) for ele in input().split(" ")]
n=str_inp[0]
m=str_inp[1]
d=str_inp[1]
flag=0
main_array=[]
count_for_moves=0
average=0
for i_index in range(0,n):
list_temp=[int(element) for element in input().split()]
main_array.append(list_temp)
average+=sum(list_temp)
# print(average)
average=(average//(n*m))
# print(average)
check_diff=((average//d)*d)
# print(check_diff)
for i_index in range(0,n):
for j_index in range(0,m):
if (main_array[i_index][j_index]-check_diff) % d != 0:
flag=1
break
else:
count_for_moves+=((main_array[i_index][j_index]-check_diff)//d)
if flag==1:
break
if flag==1:
print(-1)
else:
print(count_for_moves)
| Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so.
Input Specification:
The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104).
Output Specification:
In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
Demo Input:
['2 2 2\n2 4\n6 8\n', '1 2 7\n6 7\n']
Demo Output:
['4\n', '-1\n']
Note:
none | ```python
str_inp=[int(ele) for ele in input().split(" ")]
n=str_inp[0]
m=str_inp[1]
d=str_inp[1]
flag=0
main_array=[]
count_for_moves=0
average=0
for i_index in range(0,n):
list_temp=[int(element) for element in input().split()]
main_array.append(list_temp)
average+=sum(list_temp)
# print(average)
average=(average//(n*m))
# print(average)
check_diff=((average//d)*d)
# print(check_diff)
for i_index in range(0,n):
for j_index in range(0,m):
if (main_array[i_index][j_index]-check_diff) % d != 0:
flag=1
break
else:
count_for_moves+=((main_array[i_index][j_index]-check_diff)//d)
if flag==1:
break
if flag==1:
print(-1)
else:
print(count_for_moves)
``` | 0 |
|
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "19",
"output": "6"
},
{
"input": "40",
"output": "19"
},
{
"input": "77",
"output": "41"
},
{
"input": "222",
"output": "125"
},
{
"input": "987",
"output": "501"
},
{
"input": "1000",
"output": "508"
},
{
"input": "2000",
"output": "958"
},
{
"input": "3000",
"output": "1375"
},
{
"input": "2999",
"output": "1375"
},
{
"input": "2998",
"output": "1375"
},
{
"input": "2997",
"output": "1374"
},
{
"input": "1429",
"output": "706"
},
{
"input": "1673",
"output": "808"
},
{
"input": "1500",
"output": "732"
},
{
"input": "500",
"output": "266"
},
{
"input": "856",
"output": "439"
}
] | 1,677,242,305 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 92 | 0 | n = int(input())
sieve = [0 for i in range(n+1)]
for i in range(2,n+1):
if(sieve[i]==0):
x = 2*i
while(x<=n):
sieve[x]+=1
x+=i
c=0
for i in range(1,n+1):
if(sieve[i]==2):
c+=1
print(c) | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive.
Input Specification:
Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000).
Output Specification:
Output the amount of almost prime numbers between 1 and *n*, inclusive.
Demo Input:
['10\n', '21\n']
Demo Output:
['2\n', '8\n']
Note:
none | ```python
n = int(input())
sieve = [0 for i in range(n+1)]
for i in range(2,n+1):
if(sieve[i]==0):
x = 2*i
while(x<=n):
sieve[x]+=1
x+=i
c=0
for i in range(1,n+1):
if(sieve[i]==2):
c+=1
print(c)
``` | 3.977 |
697 | B | Barnicle | PROGRAMMING | 1,400 | [
"brute force",
"implementation",
"math",
"strings"
] | null | null | Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number *x* is the notation of form *AeB*, where *A* is a real number and *B* is an integer and *x*<==<=*A*<=×<=10*B* is true. In our case *A* is between 0 and 9 and *B* is non-negative.
Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding. | The first and only line of input contains a single string of form *a*.*deb* where *a*, *d* and *b* are integers and *e* is usual character 'e' (0<=≤<=*a*<=≤<=9,<=0<=≤<=*d*<=<<=10100,<=0<=≤<=*b*<=≤<=100) — the scientific notation of the desired distance value.
*a* and *b* contain no leading zeros and *d* contains no trailing zeros (but may be equal to 0). Also, *b* can not be non-zero if *a* is zero. | Print the only real number *x* (the desired distance value) in the only line in its decimal notation.
Thus if *x* is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.
Otherwise print *x* in a form of *p*.*q* such that *p* is an integer that have no leading zeroes (but may be equal to zero), and *q* is an integer that have no trailing zeroes (and may not be equal to zero). | [
"8.549e2\n",
"8.549e3\n",
"0.33e0\n"
] | [
"854.9\n",
"8549\n",
"0.33\n"
] | none | 1,000 | [
{
"input": "8.549e2",
"output": "854.9"
},
{
"input": "8.549e3",
"output": "8549"
},
{
"input": "0.33e0",
"output": "0.33"
},
{
"input": "1.31e1",
"output": "13.1"
},
{
"input": "1.038e0",
"output": "1.038"
},
{
"input": "8.25983e5",
"output": "825983"
},
{
"input": "8.77056e6",
"output": "8770560"
},
{
"input": "4.28522890224373996236468418851564462623381500262405e30",
"output": "4285228902243739962364684188515.64462623381500262405"
},
{
"input": "4.09336275522154223604344399571355118601483591618747e85",
"output": "40933627552215422360434439957135511860148359161874700000000000000000000000000000000000"
},
{
"input": "2.0629094807595491132306264747042243928486303384791951220362096240931158821630792563855724946791054152e85",
"output": "20629094807595491132306264747042243928486303384791951220362096240931158821630792563855.724946791054152"
},
{
"input": "0.7e0",
"output": "0.7"
},
{
"input": "0.75e0",
"output": "0.75"
},
{
"input": "0.3299209894804593859495773277850971828150469972132991597085582244596065712639531451e0",
"output": "0.3299209894804593859495773277850971828150469972132991597085582244596065712639531451"
},
{
"input": "0.1438410315232821898580886049593487999249997483354329425897344341660326482795266134253882860655873197e0",
"output": "0.1438410315232821898580886049593487999249997483354329425897344341660326482795266134253882860655873197"
},
{
"input": "1.7282220592677586155528202123627915992640276211396528871e0",
"output": "1.7282220592677586155528202123627915992640276211396528871"
},
{
"input": "1.91641639840522198229453882518758458881136053577016034847369545687354908120008812644841021662133251e89",
"output": "191641639840522198229453882518758458881136053577016034847369545687354908120008812644841021.662133251"
},
{
"input": "7.0e100",
"output": "70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "1.7390193766535948887334396973270576641602486903095355363287177932797263236084900516267835886881779051e100",
"output": "17390193766535948887334396973270576641602486903095355363287177932797263236084900516267835886881779051"
},
{
"input": "4.6329496401734172195e50",
"output": "463294964017341721950000000000000000000000000000000"
},
{
"input": "2.806303180541991592302230754797823269634e39",
"output": "2806303180541991592302230754797823269634"
},
{
"input": "5.8743505652112692964508303637002e64",
"output": "58743505652112692964508303637002000000000000000000000000000000000"
},
{
"input": "6.8778661934058405217475274375560252344373481358834598914724956711e31",
"output": "68778661934058405217475274375560.252344373481358834598914724956711"
},
{
"input": "9.4e100",
"output": "94000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "3.2371070627618799335840070613481911588919091676203766004638236894609230433739617153911544972468224113e50",
"output": "323710706276187993358400706134819115889190916762037.66004638236894609230433739617153911544972468224113"
},
{
"input": "4.8133196117786711780806656271869913331127534865038175322117213586960112955982462632332925275690064929e0",
"output": "4.8133196117786711780806656271869913331127534865038175322117213586960112955982462632332925275690064929"
},
{
"input": "7.7060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625e1",
"output": "77.060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625"
},
{
"input": "8.1089882894234341219420177467603732503076124872188628349726911362800974096687340341040683238197289136e31",
"output": "81089882894234341219420177467603.732503076124872188628349726911362800974096687340341040683238197289136"
},
{
"input": "9.6576660076120385279859051742522204516365367878315639937449558670629833997839913220859648564428655877e99",
"output": "9657666007612038527985905174252220451636536787831563993744955867062983399783991322085964856442865587.7"
},
{
"input": "0.0e0",
"output": "0"
},
{
"input": "1.0e0",
"output": "1"
},
{
"input": "8.0e0",
"output": "8"
},
{
"input": "3.0e0",
"output": "3"
},
{
"input": "4.0e0",
"output": "4"
},
{
"input": "2.0e0",
"output": "2"
},
{
"input": "9.0e0",
"output": "9"
},
{
"input": "0.888888e0",
"output": "0.888888"
},
{
"input": "9.99999999999999999999999999999999999999999999999999999999999999999999999999999999e100",
"output": "99999999999999999999999999999999999999999999999999999999999999999999999999999999900000000000000000000"
},
{
"input": "5.0e0",
"output": "5"
},
{
"input": "1.0e10",
"output": "10000000000"
},
{
"input": "1.0e5",
"output": "100000"
},
{
"input": "6.0e0",
"output": "6"
},
{
"input": "1.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111e1",
"output": "11.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
}
] | 1,468,600,861 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 61 | 921,600 | from decimal import Decimal,getcontext
getcontext().prec=250
s = "{:.250f}".format(Decimal(input()))
print(s)
if '.' in s:
while s[-1] == '0':
s = s[:-1]
if s[-1] == '.':
s = s[:-1]
print(s) | Title: Barnicle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number *x* is the notation of form *AeB*, where *A* is a real number and *B* is an integer and *x*<==<=*A*<=×<=10*B* is true. In our case *A* is between 0 and 9 and *B* is non-negative.
Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.
Input Specification:
The first and only line of input contains a single string of form *a*.*deb* where *a*, *d* and *b* are integers and *e* is usual character 'e' (0<=≤<=*a*<=≤<=9,<=0<=≤<=*d*<=<<=10100,<=0<=≤<=*b*<=≤<=100) — the scientific notation of the desired distance value.
*a* and *b* contain no leading zeros and *d* contains no trailing zeros (but may be equal to 0). Also, *b* can not be non-zero if *a* is zero.
Output Specification:
Print the only real number *x* (the desired distance value) in the only line in its decimal notation.
Thus if *x* is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.
Otherwise print *x* in a form of *p*.*q* such that *p* is an integer that have no leading zeroes (but may be equal to zero), and *q* is an integer that have no trailing zeroes (and may not be equal to zero).
Demo Input:
['8.549e2\n', '8.549e3\n', '0.33e0\n']
Demo Output:
['854.9\n', '8549\n', '0.33\n']
Note:
none | ```python
from decimal import Decimal,getcontext
getcontext().prec=250
s = "{:.250f}".format(Decimal(input()))
print(s)
if '.' in s:
while s[-1] == '0':
s = s[:-1]
if s[-1] == '.':
s = s[:-1]
print(s)
``` | 0 |
|
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner. | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output": "I hate that I love that I hate that I love that I hate it"
},
{
"input": "10",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "18",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "19",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "76",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "77",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "81",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "82",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "85",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "86",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "99",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "98",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "33",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "34",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "57",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
}
] | 1,695,355,058 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | n=int(input())
a=[]
for i in range(n):
if i%2==0:
a.append("I hate")
else:
a.append("I love")
if i!=n-1:
a.append("that")
a.append("it")
print(" ".join(a)) | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Output Specification:
Print Dr.Banner's feeling in one line.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['I hate it\n', 'I hate that I love it\n', 'I hate that I love that I hate it\n']
Note:
none | ```python
n=int(input())
a=[]
for i in range(n):
if i%2==0:
a.append("I hate")
else:
a.append("I love")
if i!=n-1:
a.append("that")
a.append("it")
print(" ".join(a))
``` | 3 |
|
1,006 | A | Adjacent Replacements | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:
- Replace each occurrence of $1$ in the array $a$ with $2$; - Replace each occurrence of $2$ in the array $a$ with $1$; - Replace each occurrence of $3$ in the array $a$ with $4$; - Replace each occurrence of $4$ in the array $a$ with $3$; - Replace each occurrence of $5$ in the array $a$ with $6$; - Replace each occurrence of $6$ in the array $a$ with $5$; - $\dots$ - Replace each occurrence of $10^9 - 1$ in the array $a$ with $10^9$; - Replace each occurrence of $10^9$ in the array $a$ with $10^9 - 1$.
Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($2i - 1, 2i$) for each $i \in\{1, 2, \ldots, 5 \cdot 10^8\}$ as described above.
For example, for the array $a = [1, 2, 4, 5, 10]$, the following sequence of arrays represents the algorithm:
$[1, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $1$ with $2$) $\rightarrow$ $[2, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $2$ with $1$) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $3$ with $4$) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $4$ with $3$) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $5$ with $6$) $\rightarrow$ $[1, 1, 3, 6, 10]$ $\rightarrow$ (replace all occurrences of $6$ with $5$) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ $\dots$ $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $10$ with $9$) $\rightarrow$ $[1, 1, 3, 5, 9]$. The later steps of the algorithm do not change the array.
Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) — the number of elements in Mishka's birthday present (surprisingly, an array).
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array. | Print $n$ integers — $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array. | [
"5\n1 2 4 5 10\n",
"10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n"
] | [
"1 1 3 5 9\n",
"9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "5\n1 2 4 5 10",
"output": "1 1 3 5 9"
},
{
"input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000",
"output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"
},
{
"input": "1\n999999999",
"output": "999999999"
},
{
"input": "1\n1000000000",
"output": "999999999"
},
{
"input": "1\n210400",
"output": "210399"
},
{
"input": "5\n100000000 100000000 100000000 100000000 100000000",
"output": "99999999 99999999 99999999 99999999 99999999"
},
{
"input": "1\n2441139",
"output": "2441139"
},
{
"input": "2\n2 2",
"output": "1 1"
},
{
"input": "3\n2 2 2",
"output": "1 1 1"
},
{
"input": "2\n4 4",
"output": "3 3"
}
] | 1,637,763,233 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def replace(a):
return (a-1) if (a%2==0) else (a+1)
def solve(arr,n):
for i in arr:
for j in range (0,n):
if arr[j]==i:
arr[j]=replace(arr[j]);
return " ".join(str(_) for _ in arr)
def main():
n = int(input())
arr = list(map(int, input().split(" ")))
print(solve(arr,n))
if __name__ == '__main__':
main() | Title: Adjacent Replacements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:
- Replace each occurrence of $1$ in the array $a$ with $2$; - Replace each occurrence of $2$ in the array $a$ with $1$; - Replace each occurrence of $3$ in the array $a$ with $4$; - Replace each occurrence of $4$ in the array $a$ with $3$; - Replace each occurrence of $5$ in the array $a$ with $6$; - Replace each occurrence of $6$ in the array $a$ with $5$; - $\dots$ - Replace each occurrence of $10^9 - 1$ in the array $a$ with $10^9$; - Replace each occurrence of $10^9$ in the array $a$ with $10^9 - 1$.
Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($2i - 1, 2i$) for each $i \in\{1, 2, \ldots, 5 \cdot 10^8\}$ as described above.
For example, for the array $a = [1, 2, 4, 5, 10]$, the following sequence of arrays represents the algorithm:
$[1, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $1$ with $2$) $\rightarrow$ $[2, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $2$ with $1$) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $3$ with $4$) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $4$ with $3$) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $5$ with $6$) $\rightarrow$ $[1, 1, 3, 6, 10]$ $\rightarrow$ (replace all occurrences of $6$ with $5$) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ $\dots$ $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $10$ with $9$) $\rightarrow$ $[1, 1, 3, 5, 9]$. The later steps of the algorithm do not change the array.
Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it.
Input Specification:
The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) — the number of elements in Mishka's birthday present (surprisingly, an array).
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array.
Output Specification:
Print $n$ integers — $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array.
Demo Input:
['5\n1 2 4 5 10\n', '10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n']
Demo Output:
['1 1 3 5 9\n', '9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n']
Note:
The first example is described in the problem statement. | ```python
def replace(a):
return (a-1) if (a%2==0) else (a+1)
def solve(arr,n):
for i in arr:
for j in range (0,n):
if arr[j]==i:
arr[j]=replace(arr[j]);
return " ".join(str(_) for _ in arr)
def main():
n = int(input())
arr = list(map(int, input().split(" ")))
print(solve(arr,n))
if __name__ == '__main__':
main()
``` | 0 |
|
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula .
The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=<<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances. | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
"input": "2\n315 845\n-669 -762",
"output": "0"
},
{
"input": "3\n8911 7861\n-6888 7861\n8911 7861",
"output": "3"
},
{
"input": "2\n-1 1000000000\n0 -1",
"output": "0"
},
{
"input": "2\n1000000000 0\n-7 1",
"output": "0"
},
{
"input": "2\n1 4\n2 1",
"output": "0"
},
{
"input": "2\n1 0\n0 2333333",
"output": "0"
},
{
"input": "2\n2 1\n1 2",
"output": "0"
},
{
"input": "2\n1 1000000000\n2 -1000000000",
"output": "0"
},
{
"input": "2\n0 1000000000\n1 -7",
"output": "0"
},
{
"input": "2\n1 0\n0 19990213",
"output": "0"
}
] | 1,578,466,177 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 1,980 | 49,971,200 | from collections import defaultdict
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
xCnt = defaultdict(int)
yCnt = defaultdict(int)
same = defaultdict(int)
for x, y in a:
xCnt[x] += 1
yCnt[y] += 1
same[(x, y)] += 1
ret = 0
for cnt in xCnt.values():
ret += cnt * (cnt - 1) // 2
for cnt in yCnt.values():
ret += cnt * (cnt - 1) // 2
for cnt in same.values():
ret -= cnt * (cnt - 1) // 2
print(ret) | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula .
The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=<<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input Specification:
The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide.
Output Specification:
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Demo Input:
['3\n1 1\n7 5\n1 5\n', '6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n']
Demo Output:
['2\n', '11\n']
Note:
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances. | ```python
from collections import defaultdict
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
xCnt = defaultdict(int)
yCnt = defaultdict(int)
same = defaultdict(int)
for x, y in a:
xCnt[x] += 1
yCnt[y] += 1
same[(x, y)] += 1
ret = 0
for cnt in xCnt.values():
ret += cnt * (cnt - 1) // 2
for cnt in yCnt.values():
ret += cnt * (cnt - 1) // 2
for cnt in same.values():
ret -= cnt * (cnt - 1) // 2
print(ret)
``` | 3 |
|
948 | A | Protect Sheep | PROGRAMMING | 900 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog.
Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number. | First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell. | If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf.
If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs. | [
"6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n",
"1 2\nSW\n",
"5 5\n.S...\n...S.\nS....\n...S.\n.S...\n"
] | [
"Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n",
"No\n",
"Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n"
] | In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him. | 500 | [
{
"input": "1 2\nSW",
"output": "No"
},
{
"input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S",
"output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSDDSDSDS\nSSDDDDDDDS"
},
{
"input": "10 10\n....W.W.W.\n...W.....S\n.S.S...S..\nW......WSS\n.W..W.....\n.W...W....\nS..S...S.S\n...WWW..S.\n..S..S.S.S\nSS.......S",
"output": "No"
},
{
"input": "1 50\nW...S..............W.....S..S...............S...W.",
"output": "Yes\nWDDDSDDDDDDDDDDDDDDWDDDDDSDDSDDDDDDDDDDDDDDDSDDDWD"
},
{
"input": "2 4\n...S\n...W",
"output": "No"
},
{
"input": "4 2\n..\n..\n..\nSW",
"output": "No"
},
{
"input": "4 2\n..\n..\n..\nWS",
"output": "No"
},
{
"input": "2 4\n...W\n...S",
"output": "No"
},
{
"input": "50 1\nS\n.\n.\n.\n.\n.\n.\nS\n.\n.\n.\n.\n.\n.\n.\n.\nS\n.\nW\n.\nS\n.\n.\n.\n.\nS\n.\n.\n.\n.\n.\n.\n.\nW\n.\n.\n.\nW\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "Yes\nS\nD\nD\nD\nD\nD\nD\nS\nD\nD\nD\nD\nD\nD\nD\nD\nS\nD\nW\nD\nS\nD\nD\nD\nD\nS\nD\nD\nD\nD\nD\nD\nD\nW\nD\nD\nD\nW\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD"
},
{
"input": "4 4\nW..S\nW..S\nW..S\nW..S",
"output": "Yes\nWDDS\nWDDS\nWDDS\nWDDS"
},
{
"input": "4 4\nSSSS\n....\n....\nWWWW",
"output": "Yes\nSSSS\nDDDD\nDDDD\nWWWW"
},
{
"input": "4 4\nWWWW\n....\n....\nSSSS",
"output": "Yes\nWWWW\nDDDD\nDDDD\nSSSS"
},
{
"input": "4 4\nS..W\nS..W\nS..W\nS..W",
"output": "Yes\nSDDW\nSDDW\nSDDW\nSDDW"
},
{
"input": "1 1\n.",
"output": "Yes\nD"
},
{
"input": "1 1\nW",
"output": "Yes\nW"
},
{
"input": "1 1\nS",
"output": "Yes\nS"
},
{
"input": "4 2\n..\n..\n.W\n.S",
"output": "No"
},
{
"input": "4 2\n..\n..\n.S\n.W",
"output": "No"
},
{
"input": "4 2\n..\n..\nW.\nS.",
"output": "No"
},
{
"input": "4 2\n..\n..\nS.\nW.",
"output": "No"
},
{
"input": "2 4\n....\n..SW",
"output": "No"
},
{
"input": "2 4\n....\n..WS",
"output": "No"
},
{
"input": "1 2\nS.",
"output": "Yes\nSD"
}
] | 1,520,752,704 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def check(r,c):
if row[r][c+1]=='W' or row[r][c-1]=='W' or row[r+1][c]=='W' or row[r-1][c]=='W':
return 1
else:
return 0
r,c=map(int,raw_input().split())
row=[' '*1000]
for i in range(1,r+1):
row.append(raw_input())
row[i]=' '+row[i]
flag=0
for i in range(1,r+1):
for j in range(1,c+1):
if row[i][j]=='S':
if(check(i,j)):
flag=1
break
if flag:
break
if flag:
print ("No")
else:
print ("Yes\n")
for i in range(1,r+1):
for j in range(1,c+1):
if row[i][j]=='.':
print ('D',end='')
else:
print (row[i][j], end='')
print''
| Title: Protect Sheep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog.
Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number.
Input Specification:
First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell.
Output Specification:
If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf.
If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs.
Demo Input:
['6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n', '1 2\nSW\n', '5 5\n.S...\n...S.\nS....\n...S.\n.S...\n']
Demo Output:
['Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n', 'No\n', 'Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n']
Note:
In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him. | ```python
def check(r,c):
if row[r][c+1]=='W' or row[r][c-1]=='W' or row[r+1][c]=='W' or row[r-1][c]=='W':
return 1
else:
return 0
r,c=map(int,raw_input().split())
row=[' '*1000]
for i in range(1,r+1):
row.append(raw_input())
row[i]=' '+row[i]
flag=0
for i in range(1,r+1):
for j in range(1,c+1):
if row[i][j]=='S':
if(check(i,j)):
flag=1
break
if flag:
break
if flag:
print ("No")
else:
print ("Yes\n")
for i in range(1,r+1):
for j in range(1,c+1):
if row[i][j]=='.':
print ('D',end='')
else:
print (row[i][j], end='')
print''
``` | -1 |
|
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"input": "4",
"output": "Rajesh"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "10",
"output": "Penny"
},
{
"input": "534",
"output": "Rajesh"
},
{
"input": "5033",
"output": "Howard"
},
{
"input": "10010",
"output": "Howard"
},
{
"input": "500000000",
"output": "Penny"
},
{
"input": "63",
"output": "Rajesh"
},
{
"input": "841",
"output": "Leonard"
},
{
"input": "3667",
"output": "Penny"
},
{
"input": "38614",
"output": "Howard"
},
{
"input": "282798",
"output": "Rajesh"
},
{
"input": "9266286",
"output": "Rajesh"
},
{
"input": "27385966",
"output": "Leonard"
},
{
"input": "121580142",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "300",
"output": "Howard"
},
{
"input": "1745",
"output": "Leonard"
},
{
"input": "8302",
"output": "Rajesh"
},
{
"input": "184518",
"output": "Sheldon"
},
{
"input": "1154414",
"output": "Rajesh"
},
{
"input": "28643950",
"output": "Leonard"
},
{
"input": "159222638",
"output": "Howard"
},
{
"input": "24",
"output": "Penny"
},
{
"input": "505",
"output": "Penny"
},
{
"input": "4425",
"output": "Rajesh"
},
{
"input": "12079",
"output": "Sheldon"
},
{
"input": "469726",
"output": "Penny"
},
{
"input": "3961838",
"output": "Penny"
},
{
"input": "57710446",
"output": "Leonard"
},
{
"input": "80719470",
"output": "Howard"
},
{
"input": "1000000000",
"output": "Penny"
},
{
"input": "999999999",
"output": "Penny"
},
{
"input": "999999998",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
}
] | 1,621,610,265 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 0 | k=int(input())
a=["Sheldon","Leonard","Penny","Rajesh","Howard"]
r=1
while(r*5<k):
k-=r*5
r*=2
print(a[(k-1)//r])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
Input Specification:
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Output Specification:
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
Demo Input:
['1\n', '6\n', '1802\n']
Demo Output:
['Sheldon\n', 'Sheldon\n', 'Penny\n']
Note:
none | ```python
k=int(input())
a=["Sheldon","Leonard","Penny","Rajesh","Howard"]
r=1
while(r*5<k):
k-=r*5
r*=2
print(a[(k-1)//r])
``` | 3.969 |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11. | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481 554 1000 821",
"output": "15"
},
{
"input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396",
"output": "144"
},
{
"input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366",
"output": "145"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19",
"output": "63"
},
{
"input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386",
"output": "31"
},
{
"input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518",
"output": "75"
},
{
"input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397",
"output": "41"
},
{
"input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118",
"output": "116"
}
] | 1,697,544,972 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 62 | 0 | tmp = input()
tmp = tmp.split()
n = int(tmp[0])
h = int(tmp[1])
friends = input()
friends = friends.split()
width = 0
for friend in friends:
if int(friend) > h:
width += 2
print(int(0.5 * width + len(friends))) | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
Input Specification:
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Output Specification:
Print a single integer — the minimum possible valid width of the road.
Demo Input:
['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n']
Demo Output:
['4\n', '6\n', '11\n']
Note:
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11. | ```python
tmp = input()
tmp = tmp.split()
n = int(tmp[0])
h = int(tmp[1])
friends = input()
friends = friends.split()
width = 0
for friend in friends:
if int(friend) > h:
width += 2
print(int(0.5 * width + len(friends)))
``` | 3 |
|
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands? | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.
Lengths of two strings are equal and do not exceed 10. | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0. | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n??????????",
"output": "0.205078125000"
},
{
"input": "+--+++--+-\n??????????",
"output": "0.246093750000"
},
{
"input": "+\n+",
"output": "1.000000000000"
},
{
"input": "-\n?",
"output": "0.500000000000"
},
{
"input": "+\n-",
"output": "0.000000000000"
},
{
"input": "-\n-",
"output": "1.000000000000"
},
{
"input": "-\n+",
"output": "0.000000000000"
},
{
"input": "+\n?",
"output": "0.500000000000"
},
{
"input": "++++++++++\n++++++++++",
"output": "1.000000000000"
},
{
"input": "++++++++++\n++++-+++++",
"output": "0.000000000000"
},
{
"input": "----------\n++++++++++",
"output": "0.000000000000"
},
{
"input": "++++++++++\n++++??++++",
"output": "0.250000000000"
},
{
"input": "----------\n+++?++++-+",
"output": "0.000000000000"
},
{
"input": "++++++++++\n++++++++?+",
"output": "0.500000000000"
},
{
"input": "--++++--+\n?-+?-??+-",
"output": "0.250000000000"
},
{
"input": "----------\n??????????",
"output": "0.000976562500"
},
{
"input": "+--++\n+--+-",
"output": "0.000000000000"
},
{
"input": "-----++---\n????????+?",
"output": "0.017578125000"
},
{
"input": "------+--+\n??????????",
"output": "0.043945312500"
},
{
"input": "---++--\n???????",
"output": "0.164062500000"
},
{
"input": "-----++\n???????",
"output": "0.164062500000"
},
{
"input": "+---+--\n???????",
"output": "0.164062500000"
},
{
"input": "---+-+\n??????",
"output": "0.234375000000"
},
{
"input": "+++-+\n---++",
"output": "0.000000000000"
},
{
"input": "++-+--+\n?-?+??+",
"output": "0.375000000000"
},
{
"input": "----+++--\n-+?+++?--",
"output": "0.000000000000"
},
{
"input": "+-----\n+?----",
"output": "0.500000000000"
}
] | 1,653,754,588 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 512,000 | class Solution:
def solve(self, a, b):
pos_a, pos_b, n = 0, 0, 0
for char_a, char_b in zip(a, b):
if char_a == "+":
pos_a += 1
else:
pos_a -= 1
if char_b == "+":
pos_b += 1
elif char_b == "-":
pos_b -= 1
else:
n += 1
target = abs(pos_b-pos_a)
if n == 0 and target == 0:
print("1")
return
if n == 0 and target != 0:
print("0")
return
if n < target:
print("0")
return
expr1 = (n+target) // 2
expr2 = (n-target) // 2
answer = self.factorial(n)**2 / ((self.factorial(expr1)**2) * (self.factorial(expr2)**2))
answer = answer / (2**(n+1))
print(answer)
def factorial(self, value):
val = 1
for num in range(2, value+1):
val *= num
return val
if __name__ == "__main__":
str1 = input()
str2 = input()
t = Solution()
t.solve(str1, str2)
| Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?
Input Specification:
The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.
Lengths of two strings are equal and do not exceed 10.
Output Specification:
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9.
Demo Input:
['++-+-\n+-+-+\n', '+-+-\n+-??\n', '+++\n??-\n']
Demo Output:
['1.000000000000\n', '0.500000000000\n', '0.000000000000\n']
Note:
For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0. | ```python
class Solution:
def solve(self, a, b):
pos_a, pos_b, n = 0, 0, 0
for char_a, char_b in zip(a, b):
if char_a == "+":
pos_a += 1
else:
pos_a -= 1
if char_b == "+":
pos_b += 1
elif char_b == "-":
pos_b -= 1
else:
n += 1
target = abs(pos_b-pos_a)
if n == 0 and target == 0:
print("1")
return
if n == 0 and target != 0:
print("0")
return
if n < target:
print("0")
return
expr1 = (n+target) // 2
expr2 = (n-target) // 2
answer = self.factorial(n)**2 / ((self.factorial(expr1)**2) * (self.factorial(expr2)**2))
answer = answer / (2**(n+1))
print(answer)
def factorial(self, value):
val = 1
for num in range(2, value+1):
val *= num
return val
if __name__ == "__main__":
str1 = input()
str2 = input()
t = Solution()
t.solve(str1, str2)
``` | 0 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,613,121,128 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | s = input()
p = 0
c = 0
for x in s:
if x.islower() == True: c += 1
else: p += 1
if p > c: print(s.upper())
if p < c or p == c: print(s.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
s = input()
p = 0
c = 0
for x in s:
if x.islower() == True: c += 1
else: p += 1
if p > c: print(s.upper())
if p < c or p == c: print(s.lower())
``` | 3.969 |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "414",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "144144144",
"output": "YES"
},
{
"input": "1444",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "141414141",
"output": "YES"
},
{
"input": "11110111",
"output": "NO"
},
{
"input": "114114144",
"output": "YES"
},
{
"input": "444",
"output": "NO"
},
{
"input": "9999",
"output": "NO"
},
{
"input": "111444",
"output": "NO"
},
{
"input": "11114",
"output": "YES"
},
{
"input": "41111",
"output": "NO"
},
{
"input": "114414441",
"output": "NO"
},
{
"input": "144414441",
"output": "NO"
},
{
"input": "144244144",
"output": "NO"
},
{
"input": "111111111",
"output": "YES"
},
{
"input": "144444444",
"output": "NO"
},
{
"input": "444444444",
"output": "NO"
},
{
"input": "141441441",
"output": "YES"
},
{
"input": "441",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "14444",
"output": "NO"
},
{
"input": "11444",
"output": "NO"
},
{
"input": "144",
"output": "YES"
},
{
"input": "1414414",
"output": "YES"
},
{
"input": "141444",
"output": "NO"
},
{
"input": "14144",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "1144",
"output": "YES"
},
{
"input": "141111444",
"output": "NO"
},
{
"input": "14414414",
"output": "YES"
},
{
"input": "141414144",
"output": "YES"
},
{
"input": "1414",
"output": "YES"
},
{
"input": "1441",
"output": "YES"
},
{
"input": "12",
"output": "NO"
},
{
"input": "144144141",
"output": "YES"
},
{
"input": "144144",
"output": "YES"
},
{
"input": "14414411",
"output": "YES"
},
{
"input": "14414",
"output": "YES"
}
] | 1,658,570,821 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=input()
if 0 and 2 and 3 and 5 and 6 and 7 and 8 and 9 in n:print('No')
else:print('Yes') | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input Specification:
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Output Specification:
Print "YES" if *n* is a magic number or print "NO" if it's not.
Demo Input:
['114114\n', '1111\n', '441231\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
n=input()
if 0 and 2 and 3 and 5 and 6 and 7 and 8 and 9 in n:print('No')
else:print('Yes')
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.
Let's define $x$ as the distance to Mars. Unfortunately, Natasha does not know $x$. But it is known that $1 \le x \le m$, where Natasha knows the number $m$. Besides, $x$ and $m$ are positive integers.
Natasha can ask the rocket questions. Every question is an integer $y$ ($1 \le y \le m$). The correct answer to the question is $-1$, if $x<y$, $0$, if $x=y$, and $1$, if $x>y$. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to $t$, then, if the rocket answers this question correctly, then it will answer $t$, otherwise it will answer $-t$.
In addition, the rocket has a sequence $p$ of length $n$. Each element of the sequence is either $0$ or $1$. The rocket processes this sequence in the cyclic order, that is $1$-st element, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $1$-st, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $\ldots$. If the current element is $1$, the rocket answers correctly, if $0$ — lies. Natasha doesn't know the sequence $p$, but she knows its length — $n$.
You can ask the rocket no more than $60$ questions.
Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.
Your solution will not be accepted, if it does not receive an answer $0$ from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers). | The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$. | none | [
"5 2\n1\n-1\n-1\n1\n0\n"
] | [
"1\n2\n4\n5\n3\n"
] | In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket answered correctly: $1$;
on the second query ($2$) the correct answer is $1$, the rocket answered incorrectly: $-1$;
on the third query ($4$) the correct answer is $-1$, the rocket answered correctly: $-1$;
on the fourth query ($5$) the correct answer is $-1$, the rocket answered incorrectly: $1$;
on the fifth query ($3$) the correct and incorrect answer is $0$. | 0 | [
{
"input": "5 2 3\n1 0",
"output": "3 queries, x=3"
},
{
"input": "1 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "3 2 3\n1 0",
"output": "4 queries, x=3"
},
{
"input": "6 3 5\n1 1 1",
"output": "5 queries, x=5"
},
{
"input": "10 4 3\n0 0 1 0",
"output": "6 queries, x=3"
},
{
"input": "30 5 16\n0 1 1 1 0",
"output": "6 queries, x=16"
},
{
"input": "60 6 21\n1 0 0 1 0 1",
"output": "11 queries, x=21"
},
{
"input": "100 7 73\n0 0 0 1 0 1 1",
"output": "14 queries, x=73"
},
{
"input": "1000000000 29 958572235\n1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0",
"output": "58 queries, x=958572235"
},
{
"input": "738009704 30 116044407\n0 0 1 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 1",
"output": "59 queries, x=116044407"
},
{
"input": "300 8 165\n1 1 1 0 0 1 1 0",
"output": "16 queries, x=165"
},
{
"input": "600 9 150\n0 0 1 0 1 0 1 0 1",
"output": "19 queries, x=150"
},
{
"input": "1000 10 140\n0 0 0 0 1 0 0 0 0 0",
"output": "20 queries, x=140"
},
{
"input": "3000 11 1896\n1 0 1 1 0 0 0 0 1 1 1",
"output": "21 queries, x=1896"
},
{
"input": "6000 12 4679\n1 0 1 1 1 1 1 0 0 0 0 1",
"output": "23 queries, x=4679"
},
{
"input": "10000 13 4977\n1 0 1 1 0 0 0 1 0 0 1 1 0",
"output": "26 queries, x=4977"
},
{
"input": "30000 14 60\n1 1 1 0 0 1 0 1 0 0 1 0 0 0",
"output": "28 queries, x=60"
},
{
"input": "60000 15 58813\n0 1 1 0 1 1 0 0 0 1 1 1 1 0 1",
"output": "27 queries, x=58813"
},
{
"input": "100000 16 79154\n1 1 1 0 0 0 0 0 1 1 0 1 0 1 0 1",
"output": "32 queries, x=79154"
},
{
"input": "300000 17 11107\n1 0 0 0 1 0 0 0 1 1 1 0 0 1 1 1 0",
"output": "34 queries, x=11107"
},
{
"input": "600000 18 146716\n0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1",
"output": "37 queries, x=146716"
},
{
"input": "1000000 19 418016\n1 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 0 0",
"output": "38 queries, x=418016"
},
{
"input": "3000000 20 642518\n1 0 0 1 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1",
"output": "41 queries, x=642518"
},
{
"input": "6000000 21 3516807\n0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 1 1 1 0 0 0",
"output": "43 queries, x=3516807"
},
{
"input": "10000000 22 8115129\n1 0 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1",
"output": "42 queries, x=8115129"
},
{
"input": "30000000 23 10362635\n0 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0",
"output": "48 queries, x=10362635"
},
{
"input": "60000000 24 52208533\n1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 1 1 1 0",
"output": "46 queries, x=52208533"
},
{
"input": "100000000 25 51744320\n0 1 1 1 1 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1",
"output": "50 queries, x=51744320"
},
{
"input": "300000000 26 264009490\n1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 1",
"output": "54 queries, x=264009490"
},
{
"input": "600000000 27 415720732\n1 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 1 0",
"output": "56 queries, x=415720732"
},
{
"input": "1000000000 28 946835863\n0 0 1 0 1 1 1 0 1 0 1 1 0 1 0 1 1 0 0 0 1 0 1 0 1 1 0 0",
"output": "58 queries, x=946835863"
},
{
"input": "1000000000 29 124919287\n0 0 1 0 0 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 1 1 0 1 0 0",
"output": "59 queries, x=124919287"
},
{
"input": "1000000000 30 202669473\n1 1 0 1 1 1 0 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0 0",
"output": "58 queries, x=202669473"
},
{
"input": "1000000000 13 532121080\n1 1 1 0 1 1 0 0 0 0 1 0 1",
"output": "42 queries, x=532121080"
},
{
"input": "1000000000 27 105669924\n0 1 1 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 1 0 0 1 0 1 1 1 1",
"output": "57 queries, x=105669924"
},
{
"input": "1000000000 11 533994576\n0 0 1 0 1 1 1 1 0 1 0",
"output": "38 queries, x=533994576"
},
{
"input": "1000000000 9 107543421\n1 0 0 1 1 1 1 1 1",
"output": "39 queries, x=107543421"
},
{
"input": "1000000000 23 976059561\n1 0 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 1",
"output": "53 queries, x=976059561"
},
{
"input": "1000000000 7 549608406\n1 1 1 0 1 1 1",
"output": "36 queries, x=549608406"
},
{
"input": "1000000000 21 123157250\n0 1 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 0 0 1",
"output": "49 queries, x=123157250"
},
{
"input": "1000000000 19 696706094\n0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0",
"output": "47 queries, x=696706094"
},
{
"input": "1000000000 3 125030747\n0 0 0",
"output": "33 queries, x=125030747"
},
{
"input": "1000000000 17 993546887\n1 0 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1",
"output": "46 queries, x=993546887"
},
{
"input": "1000000000 15 567095731\n1 1 1 0 0 1 1 1 0 1 0 0 1 0 0",
"output": "45 queries, x=567095731"
},
{
"input": "1000000000 29 140644576\n1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 0 0",
"output": "58 queries, x=140644576"
},
{
"input": "1000000000 13 714193420\n0 1 0 0 0 1 0 0 0 0 1 1 1",
"output": "43 queries, x=714193420"
},
{
"input": "1000000000 27 142518072\n0 0 0 1 0 1 1 0 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 0",
"output": "52 queries, x=142518072"
},
{
"input": "1000000000 25 11034213\n0 0 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0",
"output": "54 queries, x=11034213"
},
{
"input": "1000000000 9 584583057\n1 1 1 0 0 1 0 0 0",
"output": "35 queries, x=584583057"
},
{
"input": "1000000000 23 863164606\n1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 1 1 1 0 0 1 1",
"output": "53 queries, x=863164606"
},
{
"input": "1000000000 21 731680746\n1 1 0 0 1 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1",
"output": "51 queries, x=731680746"
},
{
"input": "1000000000 5 305229590\n0 0 1 1 0",
"output": "35 queries, x=305229590"
},
{
"input": "1000000000 3 28521539\n0 0 1",
"output": "31 queries, x=28521539"
},
{
"input": "1000000000 3 602070383\n0 1 1",
"output": "32 queries, x=602070383"
},
{
"input": "1000000000 2 880651931\n1 1",
"output": "30 queries, x=880651931"
},
{
"input": "1000000000 16 749168072\n1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0",
"output": "46 queries, x=749168072"
},
{
"input": "1000000000 30 322716916\n1 0 1 1 1 1 0 1 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0",
"output": "58 queries, x=322716916"
},
{
"input": "1000000000 14 191233057\n0 0 1 0 0 1 1 1 1 0 0 0 1 1",
"output": "43 queries, x=191233057"
},
{
"input": "1000000000 30 1\n1 1 0 1 1 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 0 0 0 0 1 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 0 1 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 0 0 0 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 1 0 1 1 0 0 1 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 1 0 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1000000000\n1 1 1 0 0 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n1 1 1 0 0 1 1 1 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 1 0 1 1 1 0",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 0 1 0 1 1 1 1 1 1 0 0 1 0 1 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 0 1 1 1 0 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 1 1 0 0 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1 30 1\n1 1 1 0 1 0 0 0 0 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 0 0 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 1 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0 1 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 1 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "2 1 2\n1",
"output": "2 queries, x=2"
},
{
"input": "1000000000 1 1000000000\n1",
"output": "31 queries, x=1000000000"
},
{
"input": "10000 1 10000\n1",
"output": "15 queries, x=10000"
},
{
"input": "1000000000 1 999999999\n1",
"output": "30 queries, x=999999999"
},
{
"input": "100000 2 15\n1 0",
"output": "19 queries, x=15"
},
{
"input": "200000 1 110000\n1",
"output": "17 queries, x=110000"
},
{
"input": "123456789 1 42\n1",
"output": "27 queries, x=42"
},
{
"input": "1000000000 1 9\n1",
"output": "30 queries, x=9"
},
{
"input": "200000 2 100002\n1 0",
"output": "19 queries, x=100002"
},
{
"input": "1000000000 3 234567890\n0 1 0",
"output": "31 queries, x=234567890"
},
{
"input": "1000000000 5 321732193\n1 1 0 1 0",
"output": "35 queries, x=321732193"
},
{
"input": "1000000000 1 804289384\n1",
"output": "27 queries, x=804289384"
},
{
"input": "1000000000 2 999999998\n1 0",
"output": "32 queries, x=999999998"
},
{
"input": "1000000000 5 384618761\n0 1 1 0 1",
"output": "33 queries, x=384618761"
},
{
"input": "100000000 1 100\n0",
"output": "28 queries, x=100"
},
{
"input": "1000000000 1 804289384\n0",
"output": "27 queries, x=804289384"
},
{
"input": "100000000 1 100000000\n1",
"output": "28 queries, x=100000000"
},
{
"input": "40 1 4\n0",
"output": "6 queries, x=4"
},
{
"input": "1000000000 2 999999998\n0 1",
"output": "32 queries, x=999999998"
},
{
"input": "1000000000 1 1000000000\n0",
"output": "31 queries, x=1000000000"
},
{
"input": "1000000000 2 255555555\n1 0",
"output": "31 queries, x=255555555"
},
{
"input": "1000000000 2 1000000000\n0 1",
"output": "32 queries, x=1000000000"
},
{
"input": "1000000000 1 999999999\n0",
"output": "30 queries, x=999999999"
},
{
"input": "1000000000 2 888888888\n0 1",
"output": "31 queries, x=888888888"
},
{
"input": "1000000000 1 77000000\n1",
"output": "31 queries, x=77000000"
},
{
"input": "1000000000 1 123456789\n1",
"output": "27 queries, x=123456789"
},
{
"input": "10000 1 228\n0",
"output": "14 queries, x=228"
},
{
"input": "1000000000 1 12345\n1",
"output": "31 queries, x=12345"
},
{
"input": "1000000000 1 77000000\n0",
"output": "31 queries, x=77000000"
},
{
"input": "1000000000 1 23333\n0",
"output": "31 queries, x=23333"
},
{
"input": "1000000000 4 100\n0 1 0 1",
"output": "34 queries, x=100"
},
{
"input": "100000000 1 200\n1",
"output": "27 queries, x=200"
},
{
"input": "1000000000 3 5\n0 1 0",
"output": "33 queries, x=5"
},
{
"input": "1000000000 12 2\n1 1 1 1 1 1 0 0 1 1 1 1",
"output": "41 queries, x=2"
},
{
"input": "1000000000 1 5\n0",
"output": "31 queries, x=5"
},
{
"input": "100000 2 99999\n0 0",
"output": "18 queries, x=99999"
},
{
"input": "100000 2 2\n0 1",
"output": "18 queries, x=2"
},
{
"input": "1000000 1 91923\n0",
"output": "21 queries, x=91923"
},
{
"input": "1000000 2 1235\n0 1",
"output": "22 queries, x=1235"
},
{
"input": "1000000000 1 5\n1",
"output": "31 queries, x=5"
},
{
"input": "100000000 2 1234567\n0 1",
"output": "28 queries, x=1234567"
},
{
"input": "1000000000 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 4 999999999\n1 0 0 1",
"output": "33 queries, x=999999999"
},
{
"input": "1000000000 4 1000000000\n1 0 1 0",
"output": "34 queries, x=1000000000"
},
{
"input": "1000000000 4 1\n1 0 1 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 5 500\n1 1 0 0 1",
"output": "34 queries, x=500"
},
{
"input": "1000 1 13\n1",
"output": "11 queries, x=13"
},
{
"input": "999999999 2 123456789\n1 0",
"output": "31 queries, x=123456789"
},
{
"input": "1000000000 5 1000000000\n1 1 1 1 1",
"output": "35 queries, x=1000000000"
},
{
"input": "1000000000 3 123456789\n1 0 1",
"output": "29 queries, x=123456789"
},
{
"input": "1000000000 1 123\n1",
"output": "29 queries, x=123"
},
{
"input": "10 1 9\n1",
"output": "4 queries, x=9"
},
{
"input": "1000000000 1 1\n0",
"output": "1 queries, x=1"
},
{
"input": "100000000 2 12345678\n0 1",
"output": "28 queries, x=12345678"
},
{
"input": "1000000000 30 1000000000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "60 queries, x=1000000000"
},
{
"input": "805306369 30 805306369\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "60 queries, x=805306369"
},
{
"input": "1000000000 2 123\n0 1",
"output": "30 queries, x=123"
},
{
"input": "1000000000 1 9\n0",
"output": "30 queries, x=9"
},
{
"input": "100000 2 90000\n1 0",
"output": "18 queries, x=90000"
},
{
"input": "1000000000 2 123456789\n1 0",
"output": "28 queries, x=123456789"
},
{
"input": "1000000000 2 804289384\n1 0",
"output": "28 queries, x=804289384"
},
{
"input": "1000000000 30 999999970\n1 0 0 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 0 1",
"output": "60 queries, x=999999970"
}
] | 1,534,893,248 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 | import sys
n = [int(i) for i in input().split()]
low1 = 1
high1 = n[0]
low2 = 1
high2 = n[0]
count = 0
while(1>0):
mid1 = (low1 + high1)//2
mid2 = (low2 + high2)//2
if(count%n[1] == 0):
print(mid1)
sys.stdout.flush()
x = int(input())
if(x==1):
low1 = mid1 + 1
elif(x==-1):
high1 = mid1 - 1
else:
break
count+=1
if(count%n[1] == 1):
print(mid2)
sys.stdout.flush()
x = int(input())
if(x==1):
low2 = mid2 + 1
elif(x==-1):
high2 = mid2 - 1
else:
break
count+=1
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.
Let's define $x$ as the distance to Mars. Unfortunately, Natasha does not know $x$. But it is known that $1 \le x \le m$, where Natasha knows the number $m$. Besides, $x$ and $m$ are positive integers.
Natasha can ask the rocket questions. Every question is an integer $y$ ($1 \le y \le m$). The correct answer to the question is $-1$, if $x<y$, $0$, if $x=y$, and $1$, if $x>y$. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to $t$, then, if the rocket answers this question correctly, then it will answer $t$, otherwise it will answer $-t$.
In addition, the rocket has a sequence $p$ of length $n$. Each element of the sequence is either $0$ or $1$. The rocket processes this sequence in the cyclic order, that is $1$-st element, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $1$-st, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $\ldots$. If the current element is $1$, the rocket answers correctly, if $0$ — lies. Natasha doesn't know the sequence $p$, but she knows its length — $n$.
You can ask the rocket no more than $60$ questions.
Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.
Your solution will not be accepted, if it does not receive an answer $0$ from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers).
Input Specification:
The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$.
Output Specification:
none
Demo Input:
['5 2\n1\n-1\n-1\n1\n0\n']
Demo Output:
['1\n2\n4\n5\n3\n']
Note:
In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket answered correctly: $1$;
on the second query ($2$) the correct answer is $1$, the rocket answered incorrectly: $-1$;
on the third query ($4$) the correct answer is $-1$, the rocket answered correctly: $-1$;
on the fourth query ($5$) the correct answer is $-1$, the rocket answered incorrectly: $1$;
on the fifth query ($3$) the correct and incorrect answer is $0$. | ```python
import sys
n = [int(i) for i in input().split()]
low1 = 1
high1 = n[0]
low2 = 1
high2 = n[0]
count = 0
while(1>0):
mid1 = (low1 + high1)//2
mid2 = (low2 + high2)//2
if(count%n[1] == 0):
print(mid1)
sys.stdout.flush()
x = int(input())
if(x==1):
low1 = mid1 + 1
elif(x==-1):
high1 = mid1 - 1
else:
break
count+=1
if(count%n[1] == 1):
print(mid2)
sys.stdout.flush()
x = int(input())
if(x==1):
low2 = mid2 + 1
elif(x==-1):
high2 = mid2 - 1
else:
break
count+=1
``` | 0 |
|
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -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": "13"
},
{
"input": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 1,680,575,580 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 77 | 13,107,200 | I, IN, M, R, LN, LS, P, S, ST, A, SO, MX, MN = int, input, map, range, len, list, print, sum, str, abs, sorted, max, min; inp = lambda: LS(M(I, IN().split()))
n, a, s, m = I(IN()), inp(), 0, 0
for i in a: s += i; m = MN(m, s)
P(A(m)) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input Specification:
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output Specification:
Print a single integer, the number of crimes which will go untreated.
Demo Input:
['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n']
Demo Output:
['2\n', '1\n', '8\n']
Note:
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | ```python
I, IN, M, R, LN, LS, P, S, ST, A, SO, MX, MN = int, input, map, range, len, list, print, sum, str, abs, sorted, max, min; inp = lambda: LS(M(I, IN().split()))
n, a, s, m = I(IN()), inp(), 0, 0
for i in a: s += i; m = MN(m, s)
P(A(m))
``` | 3 |
|
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:
1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake.
Help Ivan to calculate this number *x*! | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"input": "3 70 58",
"output": "35"
},
{
"input": "5 7 10",
"output": "3"
},
{
"input": "5 30 22",
"output": "10"
},
{
"input": "5 5 6",
"output": "2"
},
{
"input": "2 4 3",
"output": "3"
},
{
"input": "10 10 31",
"output": "3"
},
{
"input": "2 1 1",
"output": "1"
},
{
"input": "10 98 99",
"output": "19"
},
{
"input": "4 10 16",
"output": "5"
},
{
"input": "11 4 8",
"output": "1"
},
{
"input": "5 10 14",
"output": "4"
},
{
"input": "6 7 35",
"output": "7"
},
{
"input": "5 6 7",
"output": "2"
},
{
"input": "4 15 3",
"output": "3"
},
{
"input": "7 48 77",
"output": "16"
},
{
"input": "4 4 10",
"output": "3"
},
{
"input": "4 7 20",
"output": "6"
},
{
"input": "5 2 8",
"output": "2"
},
{
"input": "3 2 3",
"output": "1"
},
{
"input": "14 95 1",
"output": "1"
},
{
"input": "99 82 53",
"output": "1"
},
{
"input": "10 71 27",
"output": "9"
},
{
"input": "5 7 8",
"output": "2"
},
{
"input": "11 77 77",
"output": "12"
},
{
"input": "10 5 28",
"output": "3"
},
{
"input": "7 3 12",
"output": "2"
},
{
"input": "10 15 17",
"output": "3"
},
{
"input": "7 7 7",
"output": "1"
},
{
"input": "4 11 18",
"output": "6"
},
{
"input": "3 3 4",
"output": "2"
},
{
"input": "9 2 10",
"output": "1"
},
{
"input": "100 90 20",
"output": "1"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "12 45 60",
"output": "8"
},
{
"input": "3 94 79",
"output": "47"
},
{
"input": "41 67 34",
"output": "2"
},
{
"input": "9 3 23",
"output": "2"
},
{
"input": "10 20 57",
"output": "7"
},
{
"input": "55 27 30",
"output": "1"
},
{
"input": "100 100 10",
"output": "1"
},
{
"input": "20 8 70",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 9 15",
"output": "5"
},
{
"input": "3 1 3",
"output": "1"
},
{
"input": "2 94 94",
"output": "94"
},
{
"input": "5 3 11",
"output": "2"
},
{
"input": "4 3 2",
"output": "1"
},
{
"input": "12 12 100",
"output": "9"
},
{
"input": "6 75 91",
"output": "25"
},
{
"input": "3 4 3",
"output": "2"
},
{
"input": "3 2 5",
"output": "2"
},
{
"input": "6 5 15",
"output": "3"
},
{
"input": "4 3 6",
"output": "2"
},
{
"input": "3 9 9",
"output": "4"
},
{
"input": "26 93 76",
"output": "6"
},
{
"input": "41 34 67",
"output": "2"
},
{
"input": "6 12 6",
"output": "3"
},
{
"input": "5 20 8",
"output": "5"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "35 66 99",
"output": "4"
},
{
"input": "30 7 91",
"output": "3"
},
{
"input": "5 22 30",
"output": "10"
},
{
"input": "8 19 71",
"output": "10"
},
{
"input": "3 5 6",
"output": "3"
},
{
"input": "5 3 8",
"output": "2"
},
{
"input": "2 4 2",
"output": "2"
},
{
"input": "4 3 7",
"output": "2"
},
{
"input": "5 20 10",
"output": "5"
},
{
"input": "5 100 50",
"output": "25"
},
{
"input": "6 3 10",
"output": "2"
},
{
"input": "2 90 95",
"output": "90"
},
{
"input": "4 8 6",
"output": "3"
},
{
"input": "6 10 3",
"output": "2"
},
{
"input": "3 3 5",
"output": "2"
},
{
"input": "5 33 33",
"output": "11"
},
{
"input": "5 5 8",
"output": "2"
},
{
"input": "19 24 34",
"output": "3"
},
{
"input": "5 5 12",
"output": "3"
},
{
"input": "8 7 10",
"output": "2"
},
{
"input": "5 56 35",
"output": "17"
},
{
"input": "4 3 5",
"output": "1"
},
{
"input": "18 100 50",
"output": "8"
},
{
"input": "5 6 8",
"output": "2"
},
{
"input": "5 98 100",
"output": "33"
},
{
"input": "6 5 8",
"output": "2"
},
{
"input": "3 40 80",
"output": "40"
},
{
"input": "4 8 11",
"output": "4"
},
{
"input": "66 100 99",
"output": "3"
},
{
"input": "17 100 79",
"output": "10"
},
{
"input": "3 2 10",
"output": "2"
},
{
"input": "99 100 99",
"output": "2"
},
{
"input": "21 100 5",
"output": "5"
},
{
"input": "3 10 2",
"output": "2"
},
{
"input": "4 100 63",
"output": "33"
},
{
"input": "2 2 10",
"output": "2"
},
{
"input": "5 94 79",
"output": "31"
},
{
"input": "4 12 5",
"output": "4"
},
{
"input": "5 5 40",
"output": "5"
},
{
"input": "99 99 99",
"output": "1"
},
{
"input": "8 97 44",
"output": "16"
},
{
"input": "11 4 10",
"output": "1"
},
{
"input": "6 3 3",
"output": "1"
},
{
"input": "7 3 4",
"output": "1"
},
{
"input": "8 4 4",
"output": "1"
},
{
"input": "9 4 5",
"output": "1"
},
{
"input": "12 6 6",
"output": "1"
},
{
"input": "4 48 89",
"output": "29"
},
{
"input": "8 3 6",
"output": "1"
},
{
"input": "4 6 3",
"output": "2"
},
{
"input": "5 5 1",
"output": "1"
},
{
"input": "11 6 5",
"output": "1"
},
{
"input": "4 5 4",
"output": "2"
},
{
"input": "6 6 4",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "4 1 3",
"output": "1"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "9 4 6",
"output": "1"
},
{
"input": "6 5 6",
"output": "1"
},
{
"input": "2 2 3",
"output": "2"
},
{
"input": "4 5 1",
"output": "1"
},
{
"input": "13 6 7",
"output": "1"
},
{
"input": "14 7 7",
"output": "1"
},
{
"input": "12 97 13",
"output": "8"
},
{
"input": "4 2 9",
"output": "2"
},
{
"input": "10 20 59",
"output": "7"
},
{
"input": "12 34 56",
"output": "7"
},
{
"input": "4 5 9",
"output": "3"
},
{
"input": "2 2 2",
"output": "2"
},
{
"input": "4 66 41",
"output": "22"
}
] | 1,549,286,894 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | s=list(map(int,input.split()))
a=min(s[1],s[2])
print(min(a-(s[1]*s[2])//s[0],(s[1]*s[2])//s[0])) | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:
1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake.
Help Ivan to calculate this number *x*!
Input Specification:
The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
Output Specification:
Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake.
Demo Input:
['5 2 3\n', '4 7 10\n']
Demo Output:
['1\n', '3\n']
Note:
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | ```python
s=list(map(int,input.split()))
a=min(s[1],s[2])
print(min(a-(s[1]*s[2])//s[0],(s[1]*s[2])//s[0]))
``` | -1 |
|
79 | B | Colorful Field | PROGRAMMING | 1,400 | [
"implementation",
"sortings"
] | B. Colorful Field | 2 | 256 | Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
- Assume that the rows are numbered 1 to *n* from top to bottom and the columns are numbered 1 to *m* from left to right, and a cell in row *i* and column *j* is represented as (*i*,<=*j*). - First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1,<=1)<=→<=...<=→<=(1,<=*m*)<=→<=(2,<=1)<=→<=...<=→<=(2,<=*m*)<=→<=...<=→<=(*n*,<=1)<=→<=...<=→<=(*n*,<=*m*). Waste cells will be ignored. - Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
Now she is wondering how to determine the crop plants in some certain cells. | In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each *k* lines contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*n*,<=1<=≤<=*b*<=≤<=*m*), which denotes a cell (*a*,<=*b*) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each *t* lines contains two integers *i*,<=*j* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*j*<=≤<=*m*), which is a query that asks you the kind of crop plants of a cell (*i*,<=*j*). | For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. | [
"4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n"
] | [
"Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n"
] | The sample corresponds to the figure in the statement. | 1,000 | [
{
"input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1",
"output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots"
},
{
"input": "2 3 2 2\n1 1\n2 2\n2 1\n2 2",
"output": "Grapes\nWaste"
},
{
"input": "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8\n9 7\n9 1\n2 3\n5 2\n21 16\n20 19\n23 14\n27 6\n25 21\n14 1\n18 14\n7 2\n19 12\n30 27\n4 27\n24 12\n25 20\n26 22\n21 17\n11 6\n5 28\n28 24\n17 30\n2 5\n30 10\n4 21",
"output": "Kiwis\nCarrots\nGrapes\nGrapes"
},
{
"input": "39898 39898 3 1\n4567 8901\n12345 23456\n24680 35679\n29292 12121",
"output": "Grapes"
},
{
"input": "1 1 1 1\n1 1\n1 1",
"output": "Waste"
},
{
"input": "1 2 1 2\n1 1\n1 2\n1 1",
"output": "Carrots\nWaste"
},
{
"input": "1 6 3 12\n1 2\n1 4\n1 6\n1 1\n1 2\n1 6\n1 2\n1 5\n1 3\n1 4\n1 5\n1 5\n1 4\n1 6\n1 3",
"output": "Carrots\nWaste\nWaste\nWaste\nGrapes\nKiwis\nWaste\nGrapes\nGrapes\nWaste\nWaste\nKiwis"
},
{
"input": "1 10 1 3\n1 5\n1 5\n1 5\n1 5",
"output": "Waste\nWaste\nWaste"
},
{
"input": "5 5 1 3\n2 2\n2 2\n2 2\n2 2",
"output": "Waste\nWaste\nWaste"
},
{
"input": "3 3 3 5\n1 1\n2 2\n3 3\n1 1\n2 2\n2 2\n2 2\n3 3",
"output": "Waste\nWaste\nWaste\nWaste\nWaste"
},
{
"input": "1 10 2 4\n1 9\n1 5\n1 5\n1 6\n1 9\n1 10",
"output": "Waste\nKiwis\nWaste\nKiwis"
},
{
"input": "5 2 2 1\n3 2\n4 2\n5 2",
"output": "Kiwis"
}
] | 1,697,011,094 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,969,600 | from collections import deque
from sys import stdin, stdout
input = stdin.readline
n,m,k,t = map(int, input().split().strip)
matrix = []
column = [None]
for i in range (n):
matrix.append(column*m)
for i in range(k):
a,b = map(int, input().split())
matrix[a-1][b-1] = 0
veggies = deque(['Carrots', 'Kiwis', 'Grapes'])
for row in range(n):
for column in range(m):
if matrix[row][column] is None:
if not veggies:
veggies.extendleft(['Carrots', 'Kiwis', 'Grapes'])
matrix[row][column] = veggies.pop()
answer = []
for i in range(t):
i,j = map(int, input().split())
if matrix[i-1][j-1] == 0:
answer.append('Waste')
else:
answer.append(matrix[i-1][j-1])
for vegetable in answer:
print(vegetable)
| Title: Colorful Field
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
- Assume that the rows are numbered 1 to *n* from top to bottom and the columns are numbered 1 to *m* from left to right, and a cell in row *i* and column *j* is represented as (*i*,<=*j*). - First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1,<=1)<=→<=...<=→<=(1,<=*m*)<=→<=(2,<=1)<=→<=...<=→<=(2,<=*m*)<=→<=...<=→<=(*n*,<=1)<=→<=...<=→<=(*n*,<=*m*). Waste cells will be ignored. - Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
Now she is wondering how to determine the crop plants in some certain cells.
Input Specification:
In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each *k* lines contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*n*,<=1<=≤<=*b*<=≤<=*m*), which denotes a cell (*a*,<=*b*) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each *t* lines contains two integers *i*,<=*j* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*j*<=≤<=*m*), which is a query that asks you the kind of crop plants of a cell (*i*,<=*j*).
Output Specification:
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
Demo Input:
['4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n']
Demo Output:
['Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n']
Note:
The sample corresponds to the figure in the statement. | ```python
from collections import deque
from sys import stdin, stdout
input = stdin.readline
n,m,k,t = map(int, input().split().strip)
matrix = []
column = [None]
for i in range (n):
matrix.append(column*m)
for i in range(k):
a,b = map(int, input().split())
matrix[a-1][b-1] = 0
veggies = deque(['Carrots', 'Kiwis', 'Grapes'])
for row in range(n):
for column in range(m):
if matrix[row][column] is None:
if not veggies:
veggies.extendleft(['Carrots', 'Kiwis', 'Grapes'])
matrix[row][column] = veggies.pop()
answer = []
for i in range(t):
i,j = map(int, input().split())
if matrix[i-1][j-1] == 0:
answer.append('Waste')
else:
answer.append(matrix[i-1][j-1])
for vegetable in answer:
print(vegetable)
``` | -1 |
254 | A | Cards with Numbers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"sortings"
] | null | null | Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces. | If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them. | [
"3\n20 30 10 30 20 10\n",
"1\n1 2\n"
] | [
"4 2\n1 5\n6 3\n",
"-1"
] | none | 500 | [
{
"input": "3\n20 30 10 30 20 10",
"output": "4 2\n1 5\n6 3"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "5\n2 2 2 2 2 1 2 2 1 2",
"output": "2 1\n3 4\n7 5\n6 9\n10 8"
},
{
"input": "5\n2 1 2 2 1 1 1 1 1 2",
"output": "3 1\n2 5\n7 6\n8 9\n10 4"
},
{
"input": "5\n1 2 2 2 1 2 2 1 2 1",
"output": "3 2\n1 5\n6 4\n7 9\n10 8"
},
{
"input": "5\n3 3 1 1 1 3 2 3 1 2",
"output": "2 1\n3 4\n8 6\n5 9\n10 7"
},
{
"input": "5\n1 1 3 1 3 3 3 1 1 1",
"output": "2 1\n3 5\n7 6\n4 8\n10 9"
},
{
"input": "5\n3 1 1 1 2 3 3 3 2 1",
"output": "3 2\n1 6\n8 7\n5 9\n10 4"
},
{
"input": "5\n3 3 2 2 3 3 1 3 1 3",
"output": "2 1\n3 4\n6 5\n7 9\n10 8"
},
{
"input": "5\n4 1 3 1 4 1 2 2 3 1",
"output": "4 2\n1 5\n8 7\n3 9\n10 6"
},
{
"input": "100\n8 6 7 8 7 9 1 7 3 3 5 8 7 8 5 4 8 4 8 1 2 8 3 7 8 7 6 5 7 9 6 10 7 6 7 8 6 8 9 5 1 5 6 1 4 8 4 8 7 2 6 2 6 6 2 8 2 8 7 1 5 4 4 6 4 9 7 5 1 8 1 3 9 2 3 2 4 7 6 10 5 3 4 10 8 9 6 7 2 7 10 1 8 10 4 1 1 1 2 7 5 4 9 10 6 8 3 1 10 9 9 6 1 5 8 6 6 3 3 4 10 10 8 9 7 10 9 3 7 6 3 2 10 8 5 8 5 5 5 10 8 5 7 6 10 7 7 9 10 10 9 9 3 6 5 6 8 1 9 8 2 4 8 8 6 8 10 2 3 5 2 6 8 4 8 6 4 5 10 8 1 10 5 2 5 6 8 2 6 8 1 3 4 5 7 5 6 9 2 8",
"output": "4 1\n3 5\n10 9\n8 13\n14 12\n11 15\n18 16\n17 19\n20 7\n22 25\n26 24\n2 27\n30 6\n29 33\n34 31\n36 38\n40 28\n37 43\n44 41\n45 47\n48 46\n35 49\n50 21\n51 53\n55 52\n56 58\n61 42\n62 63\n64 54\n39 66\n67 59\n60 69\n72 23\n57 74\n77 65\n32 80\n81 68\n75 82\n85 70\n73 86\n87 79\n78 88\n89 76\n84 91\n92 71\n83 95\n97 96\n90 100\n104 94\n93 106\n108 98\n103 110\n112 105\n101 114\n117 116\n107 118\n120 102\n109 121\n123 115\n111 124\n126 122\n119 128\n129 125\n99 132\n136 134\n135 137\n139 138\n133 140\n144 130..."
},
{
"input": "100\n7 3 8 8 1 9 6 6 3 3 8 2 7 9 9 10 2 10 4 4 9 3 6 5 2 6 3 6 3 5 2 3 8 2 5 10 3 9 7 2 1 6 7 4 8 3 9 10 9 4 3 3 7 1 4 2 2 5 6 6 1 7 9 1 8 1 2 2 5 9 7 7 6 4 6 10 1 1 8 1 5 6 4 9 5 4 4 10 6 4 5 1 9 1 7 8 6 10 3 2 4 7 10 4 8 10 6 7 8 4 1 3 8 3 2 1 9 4 2 4 3 1 6 8 6 2 2 5 6 8 6 10 1 6 4 2 7 3 6 10 6 5 6 6 3 9 4 6 4 1 5 4 4 2 8 4 10 3 7 6 6 10 2 5 5 6 1 6 1 9 9 1 10 5 10 1 1 5 7 5 2 1 4 2 3 3 3 5 1 8 10 3 3 5 9 6 3 6 8 1",
"output": "4 3\n7 8\n9 2\n1 13\n14 6\n12 17\n18 16\n19 20\n21 15\n10 22\n26 23\n27 29\n30 24\n25 31\n33 11\n32 37\n40 34\n5 41\n42 28\n39 43\n47 38\n36 48\n50 44\n46 51\n57 56\n35 58\n60 59\n54 61\n62 53\n49 63\n65 45\n64 66\n68 67\n71 72\n74 55\n73 75\n78 77\n69 81\n84 70\n83 86\n88 76\n82 89\n90 87\n85 91\n92 80\n79 96\n99 52\n95 102\n103 98\n101 104\n107 97\n105 109\n111 94\n112 114\n115 100\n93 117\n118 110\n116 122\n124 113\n123 125\n126 119\n129 131\n132 106\n120 135\n136 127\n108 137\n138 121\n134 139\n142 128..."
},
{
"input": "100\n6 3 6 8 8 4 3 7 10 3 1 3 9 5 10 10 6 7 6 6 2 3 8 8 7 6 4 9 6 7 4 4 10 4 7 3 2 7 10 8 6 7 9 1 3 5 3 7 9 1 1 7 1 1 7 7 8 3 2 7 4 8 7 8 10 3 1 7 2 7 9 8 8 8 5 2 8 1 2 7 8 7 8 8 5 10 10 4 9 10 8 7 8 8 7 7 3 6 4 3 4 8 10 8 6 3 7 1 8 6 3 3 7 10 3 9 3 5 10 9 9 2 8 7 2 3 2 1 10 9 6 2 8 7 2 2 5 3 10 6 7 2 1 1 5 10 7 5 4 9 7 7 8 1 1 3 3 7 10 5 9 8 6 8 2 2 1 7 8 9 6 2 2 6 2 9 10 2 10 9 6 3 3 10 6 5 3 6 6 3 6 10 8 7 4 8 6 3 4 7",
"output": "-1"
},
{
"input": "1\n2 2",
"output": "2 1"
},
{
"input": "2\n1 2 4 7",
"output": "-1"
}
] | 1,655,485,591 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 47,923,200 | import math as mth
from collections import defaultdict,deque
from bisect import bisect_left as b_l
from bisect import bisect_right as b_r
import sys
sys.stdin=open("input.txt")
sys.stdout=open("output.txt",'w')
n=int(input())
a=[int(x) for x in input().split()]
cnt=defaultdict(int)
for i in a:
cnt[i]+=1
flag=True
for i in cnt:
if(cnt[i]&1):
flag=False
break
if(flag):
finl=[]
cnt2=defaultdict(list)
for i,val in enumerate(a):
if(len(cnt2[val])<2):
cnt2[val].append(i+1)
if(len(cnt2[val])==2):
finl.append(cnt2[val])
del cnt2[val]
for i in finl:
print(*i)
else:
print(-1) | Title: Cards with Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
Output Specification:
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
Demo Input:
['3\n20 30 10 30 20 10\n', '1\n1 2\n']
Demo Output:
['4 2\n1 5\n6 3\n', '-1']
Note:
none | ```python
import math as mth
from collections import defaultdict,deque
from bisect import bisect_left as b_l
from bisect import bisect_right as b_r
import sys
sys.stdin=open("input.txt")
sys.stdout=open("output.txt",'w')
n=int(input())
a=[int(x) for x in input().split()]
cnt=defaultdict(int)
for i in a:
cnt[i]+=1
flag=True
for i in cnt:
if(cnt[i]&1):
flag=False
break
if(flag):
finl=[]
cnt2=defaultdict(list)
for i,val in enumerate(a):
if(len(cnt2[val])<2):
cnt2[val].append(i+1)
if(len(cnt2[val])==2):
finl.append(cnt2[val])
del cnt2[val]
for i in finl:
print(*i)
else:
print(-1)
``` | 0 |
|
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime. | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "640097987171091792 640097987171091793 640097987171091794"
},
{
"input": "19534350415104721 19534350415104725",
"output": "19534350415104722 19534350415104723 19534350415104724"
},
{
"input": "933700505788726243 933700505788726280",
"output": "933700505788726244 933700505788726245 933700505788726246"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "2 3 4"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "266540997167959130 266540997167959164",
"output": "266540997167959130 266540997167959131 266540997167959132"
},
{
"input": "267367244641009850 267367244641009899",
"output": "267367244641009850 267367244641009851 267367244641009852"
},
{
"input": "268193483524125978 268193483524125993",
"output": "268193483524125978 268193483524125979 268193483524125980"
},
{
"input": "269019726702209402 269019726702209432",
"output": "269019726702209402 269019726702209403 269019726702209404"
},
{
"input": "269845965585325530 269845965585325576",
"output": "269845965585325530 269845965585325531 269845965585325532"
},
{
"input": "270672213058376250 270672213058376260",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492378",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608523",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691962",
"output": "273150934002691930 273150934002691931 273150934002691932"
},
{
"input": "996517375802030516 996517375802030524",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146694",
"output": "997343614685146644 997343614685146645 997343614685146646"
},
{
"input": "998169857863230068 998169857863230083",
"output": "998169857863230068 998169857863230069 998169857863230070"
},
{
"input": "998996101041313492 998996101041313522",
"output": "998996101041313492 998996101041313493 998996101041313494"
},
{
"input": "999822344219396916 999822344219396961",
"output": "999822344219396916 999822344219396917 999822344219396918"
},
{
"input": "648583102513043 648583102513053",
"output": "648583102513044 648583102513045 648583102513046"
},
{
"input": "266540997167959130 266540997167959131",
"output": "-1"
},
{
"input": "267367244641009850 267367244641009850",
"output": "-1"
},
{
"input": "268193483524125978 268193483524125979",
"output": "-1"
},
{
"input": "269019726702209402 269019726702209402",
"output": "-1"
},
{
"input": "269845965585325530 269845965585325530",
"output": "-1"
},
{
"input": "270672213058376250 270672213058376254",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492379",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608508",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691931",
"output": "-1"
},
{
"input": "996517375802030516 996517375802030518",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146644",
"output": "-1"
},
{
"input": "2147483647 2147483649",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "1 7",
"output": "2 3 4"
},
{
"input": "9 12",
"output": "9 11 12"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "11 13",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
}
] | 1,687,466,425 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 46 | 0 | minimum_number, maximum_number = map(int, input().split())
insuficient_number_in_interval = maximum_number - minimum_number + 1 < 3
is_minimum_number_odd = minimum_number % 2 == 1
if insuficient_number_in_interval or (is_minimum_number_odd and maximum_number - minimum_number + 1 < 4):
print('-1')
elif is_minimum_number_odd:
print(minimum_number + 1, minimum_number + 2, minimum_number + 3)
else:
print(minimum_number, minimum_number + 1, minimum_number + 2)
| Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime.
Input Specification:
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Output Specification:
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Demo Input:
['2 4\n', '10 11\n', '900000000000000009 900000000000000029\n']
Demo Output:
['2 3 4\n', '-1\n', '900000000000000009 900000000000000010 900000000000000021\n']
Note:
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | ```python
minimum_number, maximum_number = map(int, input().split())
insuficient_number_in_interval = maximum_number - minimum_number + 1 < 3
is_minimum_number_odd = minimum_number % 2 == 1
if insuficient_number_in_interval or (is_minimum_number_odd and maximum_number - minimum_number + 1 < 4):
print('-1')
elif is_minimum_number_odd:
print(minimum_number + 1, minimum_number + 2, minimum_number + 3)
else:
print(minimum_number, minimum_number + 1, minimum_number + 2)
``` | 3 |
|
612 | D | The Union of k-Segments | PROGRAMMING | 1,800 | [
"greedy",
"sortings"
] | null | null | You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=106) — the number of segments and the value of *k*.
The next *n* lines contain two integers *l**i*,<=*r**i* (<=-<=109<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) each — the endpoints of the *i*-th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order. | First line contains integer *m* — the smallest number of segments.
Next *m* lines contain two integers *a**j*,<=*b**j* (*a**j*<=≤<=*b**j*) — the ends of *j*-th segment in the answer. The segments should be listed in the order from left to right. | [
"3 2\n0 5\n-3 2\n3 8\n",
"3 2\n0 5\n-3 3\n3 8\n"
] | [
"2\n0 2\n3 5\n",
"1\n0 5\n"
] | none | 0 | [
{
"input": "3 2\n0 5\n-3 2\n3 8",
"output": "2\n0 2\n3 5"
},
{
"input": "3 2\n0 5\n-3 3\n3 8",
"output": "1\n0 5"
},
{
"input": "1 1\n-1 1",
"output": "1\n-1 1"
},
{
"input": "10 2\n27 96\n-22 45\n-68 26\n46 69\n-91 86\n12 73\n-89 76\n-11 33\n17 47\n-57 78",
"output": "1\n-89 86"
},
{
"input": "10 1\n3 60\n-73 -37\n59 69\n-56 1\n-84 -24\n-14 46\n-65 -23\n-66 -57\n-87 -80\n-21 20",
"output": "1\n-87 69"
},
{
"input": "10 10\n-92 87\n-100 -67\n-88 80\n-82 -59\n-72 81\n-50 30\n30 77\n65 92\n-76 -60\n-29 -15",
"output": "0"
},
{
"input": "1 1\n-941727901 756748222",
"output": "1\n-941727901 756748222"
},
{
"input": "1 1\n-990637865 387517231",
"output": "1\n-990637865 387517231"
},
{
"input": "1 1\n-870080964 571991746",
"output": "1\n-870080964 571991746"
},
{
"input": "10 8\n-749560329 759073394\n-186423470 816422576\n-674251064 742056817\n-342947007 954589677\n-306243234 999298121\n-448636479 409818446\n-885248428 624359061\n-936960294 754851875\n-781500924 984124751\n-342740564 618223559",
"output": "1\n-342740564 624359061"
},
{
"input": "10 1\n-260424665 -168566709\n299109864 663179811\n769984405 942516913\n-998905510 -707148023\n-167958021 60599275\n658861231 718845364\n79407402 279078536\n13652788 79756488\n-676213666 -339118351\n-349156760 -258185154",
"output": "5\n-998905510 -707148023\n-676213666 -168566709\n-167958021 279078536\n299109864 718845364\n769984405 942516913"
},
{
"input": "10 8\n-278661264 757623461\n-751226975 996393413\n-721476675 863607399\n-228431002 643113689\n-209293138 701503607\n-433870703 932866969\n-385182911 667745533\n-661057075 783312740\n-617789923 657076219\n-890369225 990071765",
"output": "1\n-278661264 667745533"
},
{
"input": "4 2\n2 2\n2 2\n2 3\n3 3",
"output": "2\n2 2\n3 3"
},
{
"input": "2 2\n-3 1\n-4 -1",
"output": "1\n-3 -1"
},
{
"input": "1 1\n2 2",
"output": "1\n2 2"
},
{
"input": "2 1\n0 2\n-1 0",
"output": "1\n-1 2"
},
{
"input": "2 2\n-1000000000 1000000000\n-1000000000 100",
"output": "1\n-1000000000 100"
}
] | 1,552,829,213 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 186 | 1,024,000 | n,k=[int(i) for i in input().split()]
otr=[]
st=[]
f=[]
for i in range(n):
s=[int(i) for i in input().split()]
st.append(s[0])
f.append(s[1])
res=0
line=min(st)
ends=[]
ressa=0
sign=0
while line<max(f):
ressa+=st.count(line)
ressa-=f.count(line)
if ressa>=k:
if sign==0:
ends.append(line)
sign=1
else:
if sign==1:
ends.append(line)
sign=0
line+=1
print(len(ends)//2)
for i in range(0,len(ends),2):
print(ends[i],ends[i+1])
| Title: The Union of k-Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=106) — the number of segments and the value of *k*.
The next *n* lines contain two integers *l**i*,<=*r**i* (<=-<=109<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) each — the endpoints of the *i*-th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order.
Output Specification:
First line contains integer *m* — the smallest number of segments.
Next *m* lines contain two integers *a**j*,<=*b**j* (*a**j*<=≤<=*b**j*) — the ends of *j*-th segment in the answer. The segments should be listed in the order from left to right.
Demo Input:
['3 2\n0 5\n-3 2\n3 8\n', '3 2\n0 5\n-3 3\n3 8\n']
Demo Output:
['2\n0 2\n3 5\n', '1\n0 5\n']
Note:
none | ```python
n,k=[int(i) for i in input().split()]
otr=[]
st=[]
f=[]
for i in range(n):
s=[int(i) for i in input().split()]
st.append(s[0])
f.append(s[1])
res=0
line=min(st)
ends=[]
ressa=0
sign=0
while line<max(f):
ressa+=st.count(line)
ressa-=f.count(line)
if ressa>=k:
if sign==0:
ends.append(line)
sign=1
else:
if sign==1:
ends.append(line)
sign=0
line+=1
print(len(ends)//2)
for i in range(0,len(ends),2):
print(ends[i],ends[i+1])
``` | -1 |
|
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*. | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output": "I become the guy."
},
{
"input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5",
"output": "I become the guy."
},
{
"input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23",
"output": "Oh, my keyboard!"
},
{
"input": "1\n1 1\n1 1",
"output": "I become the guy."
},
{
"input": "1\n0\n1 1",
"output": "I become the guy."
},
{
"input": "1\n1 1\n0",
"output": "I become the guy."
},
{
"input": "1\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11",
"output": "I become the guy."
},
{
"input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60",
"output": "I become the guy."
},
{
"input": "2\n2 2 1\n0",
"output": "I become the guy."
},
{
"input": "2\n1 2\n2 1 2",
"output": "I become the guy."
},
{
"input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54",
"output": "Oh, my keyboard!"
},
{
"input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33",
"output": "Oh, my keyboard!"
},
{
"input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61",
"output": "I become the guy."
},
{
"input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58",
"output": "I become the guy."
},
{
"input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76",
"output": "Oh, my keyboard!"
},
{
"input": "3\n1 2\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "4\n1 2\n3 1 3 4",
"output": "I become the guy."
},
{
"input": "6\n2 1 2\n3 4 5 6",
"output": "Oh, my keyboard!"
}
] | 1,697,382,290 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 26 | 31 | 0 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = sorted(set(a + b))
ans = "I become the guy."
for i in range(1,n+1):
if i in x:
continue
else:
ans = "Oh, my keyboard!"
break
print(ans)
| Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input Specification:
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
Output Specification:
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
Demo Input:
['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n']
Demo Output:
['I become the guy.\n', 'Oh, my keyboard!\n']
Note:
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = sorted(set(a + b))
ans = "I become the guy."
for i in range(1,n+1):
if i in x:
continue
else:
ans = "Oh, my keyboard!"
break
print(ans)
``` | 0 |
|
569 | A | Music | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start. | The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=<<=*T*<=≤<=105). | Print a single integer — the number of times the song will be restarted. | [
"5 2 2\n",
"5 4 7\n",
"6 2 3\n"
] | [
"2\n",
"1\n",
"1\n"
] | In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case. | 500 | [
{
"input": "5 2 2",
"output": "2"
},
{
"input": "5 4 7",
"output": "1"
},
{
"input": "6 2 3",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "2 1 10000",
"output": "1"
},
{
"input": "12326 6163 2",
"output": "1"
},
{
"input": "10000 2500 4",
"output": "1"
},
{
"input": "100000 99999 4",
"output": "1"
},
{
"input": "12351 1223 6",
"output": "2"
},
{
"input": "100000 1 10000",
"output": "2"
},
{
"input": "10028 13 10000",
"output": "1"
},
{
"input": "100000 99999 2",
"output": "1"
},
{
"input": "100000 99999 3",
"output": "1"
},
{
"input": "100000 1 2",
"output": "17"
},
{
"input": "100000 1 3",
"output": "11"
},
{
"input": "100000 1 4",
"output": "9"
},
{
"input": "100000 1 5",
"output": "8"
},
{
"input": "100000 3125 2",
"output": "5"
},
{
"input": "12628 1804 7",
"output": "1"
},
{
"input": "100000 45 13",
"output": "4"
},
{
"input": "100000 500 3",
"output": "5"
},
{
"input": "356 2 3",
"output": "5"
},
{
"input": "50 2 2",
"output": "5"
},
{
"input": "65465 12 3",
"output": "8"
},
{
"input": "10033 3 8",
"output": "4"
},
{
"input": "100000 3 2",
"output": "16"
},
{
"input": "64 1 8",
"output": "2"
},
{
"input": "10000 9 2",
"output": "11"
},
{
"input": "25 2 2",
"output": "4"
},
{
"input": "129 2 2",
"output": "7"
},
{
"input": "6562 1 3",
"output": "9"
},
{
"input": "100000 1 10",
"output": "5"
}
] | 1,685,431,460 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | if __name__ == "__main__":
target = int(input())
bacteria = 1
a = target % 2
print(bacteria + a) | Title: Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start.
Input Specification:
The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=<<=*T*<=≤<=105).
Output Specification:
Print a single integer — the number of times the song will be restarted.
Demo Input:
['5 2 2\n', '5 4 7\n', '6 2 3\n']
Demo Output:
['2\n', '1\n', '1\n']
Note:
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case. | ```python
if __name__ == "__main__":
target = int(input())
bacteria = 1
a = target % 2
print(bacteria + a)
``` | -1 |
|
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times. | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 21 73839",
"output": "9999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99991 623 36438",
"output": "9999150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 334 94854",
"output": "9999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99252 9827 84849",
"output": "9925270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99313 9833 10561",
"output": "9931330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "94885 55815 11417",
"output": "9488550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99492 58525 53481",
"output": "9949250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99858 28531 79193",
"output": "9985850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99136 47208 42607",
"output": "9913680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "63270 19953 5555",
"output": "-1"
},
{
"input": "10240 128 100000",
"output": "1024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "12 11 3",
"output": "12100"
},
{
"input": "14 12 99998",
"output": "1440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "1 11 3",
"output": "1100"
},
{
"input": "3 40 1",
"output": "-1"
},
{
"input": "150 100 10",
"output": "1500000000000"
},
{
"input": "5 10 1",
"output": "50"
},
{
"input": "1 15 10",
"output": "15000000000"
},
{
"input": "3 13 2",
"output": "390"
}
] | 1,586,250,461 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a,n,m=map(str,input().split())
for i in range(10):
b=a+str(i)
if int(b)%int(n)==0:
for j in range(int(m)-1):
b=str(b)
b=b+"0"
break
else:
b=a
if b==a:
print("-1)
else:
print(b)
| Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times.
Input Specification:
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
Output Specification:
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Demo Input:
['5 4 5\n', '12 11 1\n', '260 150 10\n']
Demo Output:
['524848\n', '121\n', '-1\n']
Note:
none | ```python
a,n,m=map(str,input().split())
for i in range(10):
b=a+str(i)
if int(b)%int(n)==0:
for j in range(int(m)-1):
b=str(b)
b=b+"0"
break
else:
b=a
if b==a:
print("-1)
else:
print(b)
``` | -1 |
|
740 | B | Alyona and flowers | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.
For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then:
- the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays.
Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!
Alyona can choose any number of the subarrays, even 0 or all suggested by her mother. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
Each subarray can encounter more than once. | Print single integer — the maximum possible value added to the Alyona's happiness. | [
"5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n",
"4 3\n1 2 3 4\n1 3\n2 4\n1 1\n",
"2 2\n-1 -2\n1 1\n1 2\n"
] | [
"7\n",
"16\n",
"0\n"
] | The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | 1,000 | [
{
"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4",
"output": "7"
},
{
"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1",
"output": "16"
},
{
"input": "2 2\n-1 -2\n1 1\n1 2",
"output": "0"
},
{
"input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5",
"output": "8"
},
{
"input": "8 3\n5 -4 -2 5 3 -4 -2 6\n3 8\n4 6\n2 3",
"output": "10"
},
{
"input": "10 10\n0 0 0 0 0 0 0 0 0 0\n5 9\n1 9\n5 7\n3 8\n1 6\n1 9\n1 6\n6 9\n1 10\n3 8",
"output": "0"
},
{
"input": "3 6\n0 0 0\n1 1\n1 1\n1 3\n3 3\n2 3\n1 2",
"output": "0"
},
{
"input": "3 3\n1 -1 3\n1 2\n2 3\n1 3",
"output": "5"
},
{
"input": "6 8\n0 6 -5 8 -3 -2\n6 6\n2 3\n5 6\n4 6\n3 4\n2 5\n3 3\n5 6",
"output": "13"
},
{
"input": "10 4\n6 5 5 -1 0 5 0 -3 5 -4\n3 6\n4 9\n1 6\n1 4",
"output": "50"
},
{
"input": "9 1\n-1 -1 -1 -1 2 -1 2 0 0\n2 5",
"output": "0"
},
{
"input": "3 8\n3 4 4\n1 2\n1 3\n2 3\n1 2\n2 2\n1 1\n2 3\n1 3",
"output": "59"
},
{
"input": "3 8\n6 7 -1\n1 1\n1 3\n2 2\n1 3\n1 3\n1 1\n2 3\n2 3",
"output": "67"
},
{
"input": "53 7\n-43 57 92 97 85 -29 28 -8 -37 -47 51 -53 -95 -50 -39 -87 43 36 60 -95 93 8 67 -22 -78 -46 99 93 27 -72 -84 77 96 -47 1 -12 21 -98 -34 -88 57 -43 5 -15 20 -66 61 -29 30 -85 52 53 82\n15 26\n34 43\n37 41\n22 34\n19 43\n2 15\n13 35",
"output": "170"
},
{
"input": "20 42\n61 86 5 -87 -33 51 -79 17 -3 65 -42 74 -94 40 -35 22 58 81 -75 5\n3 6\n12 13\n3 16\n3 16\n5 7\n5 16\n2 15\n6 18\n4 18\n10 17\n14 16\n4 15\n4 11\n13 20\n5 6\n5 15\n16 17\n3 14\n9 10\n5 19\n5 14\n2 4\n17 20\n10 11\n5 18\n10 11\n1 14\n1 6\n1 10\n8 16\n11 14\n12 20\n11 13\n4 5\n2 13\n1 5\n11 15\n1 18\n3 8\n8 20\n1 4\n10 13",
"output": "1502"
},
{
"input": "64 19\n-47 13 19 51 -25 72 38 32 54 7 -49 -50 -59 73 45 -87 -15 -72 -32 -10 -7 47 -34 35 48 -73 79 25 -80 -34 4 77 60 30 61 -25 23 17 -73 -73 69 29 -50 -55 53 15 -33 7 -46 -5 85 -86 77 -51 87 -69 -64 -24 -64 29 -20 -58 11 -26\n6 53\n13 28\n15 47\n20 52\n12 22\n6 49\n31 54\n2 39\n32 49\n27 64\n22 63\n33 48\n49 58\n39 47\n6 29\n21 44\n24 59\n20 24\n39 54",
"output": "804"
},
{
"input": "1 10\n-46\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "10 7\n44 18 9 -22 -23 7 -25 -2 15 35\n6 8\n6 7\n3 3\n2 6\n9 10\n2 2\n1 5",
"output": "103"
},
{
"input": "4 3\n10 -2 68 35\n4 4\n1 1\n1 3",
"output": "121"
},
{
"input": "3 6\n27 -31 -81\n2 3\n2 3\n1 1\n1 2\n1 2\n2 2",
"output": "27"
},
{
"input": "7 3\n-24 -12 16 -43 -30 31 16\n3 6\n3 4\n1 7",
"output": "0"
},
{
"input": "10 7\n-33 -24 -86 -20 5 -91 38 -12 -90 -67\n7 8\n7 10\n4 7\n1 3\n6 10\n6 6\n3 5",
"output": "26"
},
{
"input": "4 4\n95 35 96 -27\n3 4\n3 3\n4 4\n3 3",
"output": "261"
},
{
"input": "7 7\n-33 26 -25 44 -20 -50 33\n4 6\n4 4\n3 7\n5 7\n1 4\n2 5\n4 6",
"output": "81"
},
{
"input": "5 3\n-35 -39 93 59 -4\n2 2\n2 3\n2 5",
"output": "163"
},
{
"input": "3 7\n0 0 0\n1 2\n1 2\n2 3\n3 3\n1 3\n1 2\n2 3",
"output": "0"
},
{
"input": "8 2\n17 32 30 -6 -39 -15 33 74\n6 6\n8 8",
"output": "74"
},
{
"input": "8 1\n-20 -15 21 -21 1 -12 -7 9\n4 7",
"output": "0"
},
{
"input": "7 9\n-23 -4 -44 -47 -35 47 25\n1 6\n3 5\n4 7\n6 7\n2 4\n2 3\n2 7\n1 2\n5 5",
"output": "72"
},
{
"input": "8 8\n0 6 -25 -15 29 -24 31 23\n2 8\n5 5\n3 3\n2 8\n6 6\n3 6\n3 4\n2 4",
"output": "79"
},
{
"input": "4 3\n-39 -63 9 -16\n1 4\n1 3\n2 4",
"output": "0"
},
{
"input": "9 1\n-3 -13 -13 -19 -4 -11 8 -11 -3\n9 9",
"output": "0"
},
{
"input": "9 6\n25 18 -62 0 33 62 -23 4 -15\n7 9\n2 3\n1 4\n2 6\n1 6\n2 3",
"output": "127"
},
{
"input": "4 5\n-12 39 8 -12\n1 4\n3 4\n1 3\n1 3\n2 3",
"output": "140"
},
{
"input": "3 9\n-9 7 3\n1 2\n1 1\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n3 3",
"output": "22"
},
{
"input": "10 7\n0 4 3 3 -2 -2 -4 -2 -3 -2\n5 6\n1 10\n2 10\n7 10\n1 1\n6 7\n3 4",
"output": "6"
},
{
"input": "86 30\n16 -12 11 16 8 14 7 -29 18 30 -32 -10 20 29 -14 -21 23 -19 -15 17 -2 25 -22 2 26 15 -7 -12 -4 -28 21 -4 -2 22 28 -32 9 -20 23 38 -21 21 37 -13 -30 25 31 6 18 29 29 29 27 38 -15 -32 32 -7 -8 -33 -11 24 23 -19 -36 -36 -18 9 -1 32 -34 -26 1 -1 -16 -14 17 -17 15 -24 38 5 -27 -12 8 -38\n60 66\n29 48\n32 51\n38 77\n17 79\n23 74\n39 50\n14 29\n26 76\n9 76\n2 67\n23 48\n17 68\n33 75\n59 78\n46 78\n9 69\n16 83\n18 21\n17 34\n24 61\n15 79\n4 31\n62 63\n46 76\n79 82\n25 39\n5 81\n19 77\n26 71",
"output": "3076"
},
{
"input": "33 17\n11 6 -19 14 23 -23 21 15 29 19 13 -18 -19 20 16 -10 26 -22 3 17 13 -10 19 22 -5 21 12 6 28 -13 -27 25 6\n4 17\n12 16\n9 17\n25 30\n31 32\n4 28\n11 24\n16 19\n3 27\n7 17\n1 16\n15 28\n30 33\n9 31\n14 30\n13 23\n27 27",
"output": "1366"
},
{
"input": "16 44\n32 23 -27 -2 -10 -42 32 -14 -13 4 9 -2 19 35 16 22\n6 12\n8 11\n13 15\n12 12\n3 10\n9 13\n7 15\n2 11\n1 13\n5 6\n9 14\n3 16\n10 13\n3 15\n6 10\n14 16\n4 5\n7 10\n5 14\n1 16\n2 5\n1 6\n9 10\n4 7\n4 12\n2 5\n7 10\n7 9\n2 8\n9 10\n4 10\n7 12\n10 11\n6 6\n15 15\n8 12\n9 10\n3 3\n4 15\n10 12\n7 16\n4 14\n14 16\n5 6",
"output": "777"
},
{
"input": "63 24\n-23 -46 0 33 24 13 39 -6 -4 49 19 -18 -11 -38 0 -3 -33 -17 -4 -44 -22 -12 -16 42 16 -10 7 37 -6 16 -41 -18 -20 51 -49 28 -14 -22 -37 -7 -50 31 -41 -47 18 -8 -39 -29 35 -32 14 -29 44 -29 -19 -25 -47 -8 16 11 20 12 38\n21 61\n35 61\n29 61\n21 34\n12 48\n32 33\n9 27\n4 42\n4 60\n37 61\n19 44\n46 60\n51 53\n31 34\n23 32\n5 29\n43 59\n7 31\n29 48\n15 50\n19 51\n7 28\n17 41\n1 62",
"output": "82"
},
{
"input": "6 51\n45 -33 -17 -48 2 2\n2 5\n1 1\n1 3\n5 5\n4 6\n1 2\n2 3\n3 4\n1 6\n4 6\n3 5\n1 5\n2 2\n2 6\n4 6\n1 5\n1 5\n1 5\n1 6\n6 6\n3 5\n6 6\n1 6\n3 4\n3 3\n2 4\n3 3\n1 4\n2 4\n5 6\n4 5\n2 4\n1 5\n1 2\n4 5\n1 5\n5 6\n2 2\n3 4\n1 3\n1 2\n2 5\n3 6\n4 6\n3 4\n2 4\n1 4\n1 1\n4 6\n3 5\n1 4",
"output": "140"
},
{
"input": "3 5\n2 -1 3\n2 3\n2 3\n2 3\n2 3\n1 2",
"output": "9"
},
{
"input": "4 30\n1 1 1 1\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4",
"output": "120"
}
] | 1,480,175,592 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
f=-101
e=0
for x in range (a[1]):
c=list(map(int,input().split(' ')))
d=sum(b[c[0]-1:c[1]])
if d>0:
e+=d
if d<=0 and d>f:
f=d
if e>0:
print(e)
else:
print(f)
| Title: Alyona and flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.
For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then:
- the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays.
Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!
Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
Each subarray can encounter more than once.
Output Specification:
Print single integer — the maximum possible value added to the Alyona's happiness.
Demo Input:
['5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n', '4 3\n1 2 3 4\n1 3\n2 4\n1 1\n', '2 2\n-1 -2\n1 1\n1 2\n']
Demo Output:
['7\n', '16\n', '0\n']
Note:
The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | ```python
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
f=-101
e=0
for x in range (a[1]):
c=list(map(int,input().split(' ')))
d=sum(b[c[0]-1:c[1]])
if d>0:
e+=d
if d<=0 and d>f:
f=d
if e>0:
print(e)
else:
print(f)
``` | 0 |
|
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": "8"
},
{
"input": "6",
"output": "4"
},
{
"input": "999999999",
"output": "2"
},
{
"input": "1378",
"output": "4"
},
{
"input": "13781378",
"output": "4"
},
{
"input": "51202278",
"output": "4"
},
{
"input": "999999998",
"output": "4"
},
{
"input": "999999997",
"output": "8"
},
{
"input": "12193721",
"output": "8"
},
{
"input": "0",
"output": "1"
},
{
"input": "989898989",
"output": "8"
},
{
"input": "7",
"output": "2"
},
{
"input": "8",
"output": "6"
},
{
"input": "9",
"output": "8"
},
{
"input": "10",
"output": "4"
},
{
"input": "11",
"output": "2"
},
{
"input": "12",
"output": "6"
},
{
"input": "13",
"output": "8"
},
{
"input": "14",
"output": "4"
},
{
"input": "15",
"output": "2"
},
{
"input": "16",
"output": "6"
},
{
"input": "999999996",
"output": "6"
},
{
"input": "999999995",
"output": "2"
},
{
"input": "999999994",
"output": "4"
}
] | 1,698,076,967 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 8,704,000 | a=int(input())
x=pow(1378,a)
print(x%10) | Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input Specification:
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Output Specification:
Print single integer — the last digit of 1378*n*.
Demo Input:
['1\n', '2\n']
Demo Output:
['8', '4']
Note:
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | ```python
a=int(input())
x=pow(1378,a)
print(x%10)
``` | 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,674,885,734 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a=int(input())
while(t-->0):
s=input()
if(s.len()>10):
print(s[0],s.len()-2,s[s.len()-1])
else:
print(s) | 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())
while(t-->0):
s=input()
if(s.len()>10):
print(s[0],s.len()-2,s[s.len()-1])
else:
print(s)
``` | -1 |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "414",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "144144144",
"output": "YES"
},
{
"input": "1444",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "141414141",
"output": "YES"
},
{
"input": "11110111",
"output": "NO"
},
{
"input": "114114144",
"output": "YES"
},
{
"input": "444",
"output": "NO"
},
{
"input": "9999",
"output": "NO"
},
{
"input": "111444",
"output": "NO"
},
{
"input": "11114",
"output": "YES"
},
{
"input": "41111",
"output": "NO"
},
{
"input": "114414441",
"output": "NO"
},
{
"input": "144414441",
"output": "NO"
},
{
"input": "144244144",
"output": "NO"
},
{
"input": "111111111",
"output": "YES"
},
{
"input": "144444444",
"output": "NO"
},
{
"input": "444444444",
"output": "NO"
},
{
"input": "141441441",
"output": "YES"
},
{
"input": "441",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "14444",
"output": "NO"
},
{
"input": "11444",
"output": "NO"
},
{
"input": "144",
"output": "YES"
},
{
"input": "1414414",
"output": "YES"
},
{
"input": "141444",
"output": "NO"
},
{
"input": "14144",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "1144",
"output": "YES"
},
{
"input": "141111444",
"output": "NO"
},
{
"input": "14414414",
"output": "YES"
},
{
"input": "141414144",
"output": "YES"
},
{
"input": "1414",
"output": "YES"
},
{
"input": "1441",
"output": "YES"
},
{
"input": "12",
"output": "NO"
},
{
"input": "144144141",
"output": "YES"
},
{
"input": "144144",
"output": "YES"
},
{
"input": "14414411",
"output": "YES"
},
{
"input": "14414",
"output": "YES"
}
] | 1,642,108,986 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 124 | 409,600 | from re import match
print(match(r"^(14?4?)*$", input()) and 'YES' or 'NO') | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input Specification:
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Output Specification:
Print "YES" if *n* is a magic number or print "NO" if it's not.
Demo Input:
['114114\n', '1111\n', '441231\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
from re import match
print(match(r"^(14?4?)*$", input()) and 'YES' or 'NO')
``` | 3 |
|
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number. | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": "919067153",
"output": "5"
},
{
"input": "690422411",
"output": "7"
},
{
"input": "-408490162",
"output": "1"
},
{
"input": "-8",
"output": "16"
},
{
"input": "-6",
"output": "14"
},
{
"input": "-4",
"output": "12"
},
{
"input": "-2",
"output": "10"
},
{
"input": "0",
"output": "8"
},
{
"input": "2",
"output": "6"
},
{
"input": "4",
"output": "4"
},
{
"input": "6",
"output": "2"
},
{
"input": "8",
"output": "10"
},
{
"input": "1000000000",
"output": "8"
},
{
"input": "-1000000000",
"output": "2"
},
{
"input": "88888",
"output": "1"
},
{
"input": "89",
"output": "9"
},
{
"input": "-80000000",
"output": "2"
},
{
"input": "-8888",
"output": "1"
},
{
"input": "-17",
"output": "9"
},
{
"input": "78",
"output": "2"
},
{
"input": "-19",
"output": "1"
},
{
"input": "-999999998",
"output": "9"
},
{
"input": "-999999997",
"output": "8"
},
{
"input": "999999997",
"output": "1"
},
{
"input": "811111111",
"output": "1"
},
{
"input": "-8",
"output": "16"
},
{
"input": "-5",
"output": "13"
},
{
"input": "-7",
"output": "15"
},
{
"input": "1000000000",
"output": "8"
}
] | 1,489,747,757 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 4,608,000 | import sys
a = int(input())
p = 0
if a==0:
print(8)
sys.exit()
while True:
a+=1
p+=1
j=a
while j!=0:
if j%10==8:
print(p)
sys.exit()
else:
j=j//10
| Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number.
Input Specification:
The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109).
Output Specification:
Print the minimum *b* in a line.
Demo Input:
['179\n', '-1\n', '18\n']
Demo Output:
['1\n', '9\n', '10\n']
Note:
For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | ```python
import sys
a = int(input())
p = 0
if a==0:
print(8)
sys.exit()
while True:
a+=1
p+=1
j=a
while j!=0:
if j%10==8:
print(p)
sys.exit()
else:
j=j//10
``` | 0 |
|
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible. | The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "3",
"output": "1 1 1"
},
{
"input": "5",
"output": "1 1 3"
},
{
"input": "8",
"output": "1 2 5"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "21",
"output": "3 5 13"
},
{
"input": "34",
"output": "5 8 21"
},
{
"input": "55",
"output": "8 13 34"
},
{
"input": "89",
"output": "13 21 55"
},
{
"input": "144",
"output": "21 34 89"
},
{
"input": "233",
"output": "34 55 144"
},
{
"input": "377",
"output": "55 89 233"
},
{
"input": "610",
"output": "89 144 377"
},
{
"input": "987",
"output": "144 233 610"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "2584",
"output": "377 610 1597"
},
{
"input": "4181",
"output": "610 987 2584"
},
{
"input": "6765",
"output": "987 1597 4181"
},
{
"input": "10946",
"output": "1597 2584 6765"
},
{
"input": "17711",
"output": "2584 4181 10946"
},
{
"input": "28657",
"output": "4181 6765 17711"
},
{
"input": "46368",
"output": "6765 10946 28657"
},
{
"input": "75025",
"output": "10946 17711 46368"
},
{
"input": "121393",
"output": "17711 28657 75025"
},
{
"input": "196418",
"output": "28657 46368 121393"
},
{
"input": "317811",
"output": "46368 75025 196418"
},
{
"input": "514229",
"output": "75025 121393 317811"
},
{
"input": "832040",
"output": "121393 196418 514229"
},
{
"input": "1346269",
"output": "196418 317811 832040"
},
{
"input": "2178309",
"output": "317811 514229 1346269"
},
{
"input": "3524578",
"output": "514229 832040 2178309"
},
{
"input": "5702887",
"output": "832040 1346269 3524578"
},
{
"input": "9227465",
"output": "1346269 2178309 5702887"
},
{
"input": "14930352",
"output": "2178309 3524578 9227465"
},
{
"input": "24157817",
"output": "3524578 5702887 14930352"
},
{
"input": "39088169",
"output": "5702887 9227465 24157817"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "165580141",
"output": "24157817 39088169 102334155"
},
{
"input": "267914296",
"output": "39088169 63245986 165580141"
},
{
"input": "433494437",
"output": "63245986 102334155 267914296"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
}
] | 1,692,965,408 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 62 | 0 | import math
def squ(x) :
if x>0 :
s=int(math.sqrt(x))
return s*s==x
n=int(input())
k=[]
for i in range(n-1,0,-1) :
if squ((i*i*5)-4) or squ((i*i*5)+4) :
k.append(i)
break
l=n-k[0]
k.append(k[0]-l)
k.append(l-k[1])
if n==0 :
print(0,0,0)
elif n==1 :
print(0,0,1)
elif n==2 :
print(0,1,1)
else :
print(k[2],k[1],k[0]) | Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible.
Input Specification:
The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output Specification:
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Demo Input:
['3\n', '13\n']
Demo Output:
['1 1 1\n', '2 3 8\n']
Note:
none | ```python
import math
def squ(x) :
if x>0 :
s=int(math.sqrt(x))
return s*s==x
n=int(input())
k=[]
for i in range(n-1,0,-1) :
if squ((i*i*5)-4) or squ((i*i*5)+4) :
k.append(i)
break
l=n-k[0]
k.append(k[0]-l)
k.append(l-k[1])
if n==0 :
print(0,0,0)
elif n==1 :
print(0,0,1)
elif n==2 :
print(0,1,1)
else :
print(k[2],k[1],k[0])
``` | -1 |
|
371 | D | Vessels | PROGRAMMING | 1,800 | [
"data structures",
"dsu",
"implementation",
"trees"
] | null | null | There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters.
Initially, all the vessels are empty. In some vessels water is poured. All the water that overflows from the *i*-th vessel goes to the (*i*<=+<=1)-th one. The liquid that overflows from the *n*-th vessel spills on the floor.
Your task is to simulate pouring water into the vessels. To do this, you will need to handle two types of queries:
1. Add *x**i* liters of water to the *p**i*-th vessel; 1. Print the number of liters of water in the *k**i*-th vessel.
When you reply to the second request you can assume that all the water poured up to this point, has already overflown between the vessels. | The first line contains integer *n* — the number of vessels (1<=≤<=*n*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the vessels' capacities (1<=≤<=*a**i*<=≤<=109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The third line contains integer *m* — the number of queries (1<=≤<=*m*<=≤<=2·105). Each of the next *m* lines contains the description of one query. The query of the first type is represented as "1 *p**i* *x**i*", the query of the second type is represented as "2 *k**i*" (1<=≤<=*p**i*<=≤<=*n*, 1<=≤<=*x**i*<=≤<=109, 1<=≤<=*k**i*<=≤<=*n*). | For each query, print on a single line the number of liters of water in the corresponding vessel. | [
"2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2\n",
"3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3\n"
] | [
"4\n5\n8\n",
"7\n10\n5\n"
] | none | 2,000 | [
{
"input": "2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2",
"output": "4\n5\n8"
},
{
"input": "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3",
"output": "7\n10\n5"
},
{
"input": "10\n71 59 88 55 18 98 38 73 53 58\n20\n1 5 93\n1 7 69\n2 3\n1 1 20\n2 10\n1 6 74\n1 7 100\n1 9 14\n2 3\n2 4\n2 7\n1 3 31\n2 4\n1 6 64\n2 2\n2 2\n1 3 54\n2 9\n2 1\n1 6 86",
"output": "0\n0\n0\n0\n38\n0\n0\n0\n53\n20"
},
{
"input": "10\n3 7 10 1 5 4 4 3 3 1\n20\n2 4\n2 4\n1 1 10\n1 1 10\n2 4\n2 3\n1 4 2\n1 4 6\n2 2\n1 8 9\n2 2\n2 5\n2 9\n1 2 1\n1 6 9\n1 1 6\n2 5\n2 2\n2 3\n1 4 10",
"output": "0\n0\n0\n10\n7\n7\n5\n3\n5\n7\n10"
},
{
"input": "50\n57 63 98 44 22 63 5 65 36 69 49 54 61 15 29 79 50 30 43 93 18 94 46 92 72 67 67 51 34 40 50 77 58 53 79 72 72 34 91 75 83 67 71 80 11 51 85 20 6 3\n20\n2 40\n1 14 102\n2 22\n2 15\n2 43\n1 29 532\n2 27\n2 47\n1 24 107\n1 20 720\n1 21 315\n2 20\n1 2 787\n1 27 532\n2 38\n1 32 445\n1 38 17\n1 26 450\n2 40\n1 45 192",
"output": "0\n0\n29\n0\n0\n0\n93\n34\n75"
},
{
"input": "1\n1\n1\n2 1",
"output": "0"
}
] | 1,617,463,378 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 307,200 | n = int(input())
string = input().split()
vessels = []
transbordaEm = 300000
for i in range(n):
vessels.append([0,int(string[i])])
m = int(input())
for q in range(m):
query = input().split()
if(query[0] == '2'):
position = int(query[1]) - 1
print(vessels[position][0])
elif(query[0] == '1'):
position = int(query[1]) - 1
x = int(query[2])
if(position > transbordaEm): #não cabe mais
break
entered = False
for v in range(position, n):
c = vessels[v][1]
t = vessels[v][0]
if(x > (c-t)):
x = x - (c-t)
vessels[v][0] = c # t = c
else:
entered = True
vessels[v][0] = t + x # t = x
break
if(entered == False):# transbordou no chao
transbordaEm = position
| Title: Vessels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters.
Initially, all the vessels are empty. In some vessels water is poured. All the water that overflows from the *i*-th vessel goes to the (*i*<=+<=1)-th one. The liquid that overflows from the *n*-th vessel spills on the floor.
Your task is to simulate pouring water into the vessels. To do this, you will need to handle two types of queries:
1. Add *x**i* liters of water to the *p**i*-th vessel; 1. Print the number of liters of water in the *k**i*-th vessel.
When you reply to the second request you can assume that all the water poured up to this point, has already overflown between the vessels.
Input Specification:
The first line contains integer *n* — the number of vessels (1<=≤<=*n*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the vessels' capacities (1<=≤<=*a**i*<=≤<=109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The third line contains integer *m* — the number of queries (1<=≤<=*m*<=≤<=2·105). Each of the next *m* lines contains the description of one query. The query of the first type is represented as "1 *p**i* *x**i*", the query of the second type is represented as "2 *k**i*" (1<=≤<=*p**i*<=≤<=*n*, 1<=≤<=*x**i*<=≤<=109, 1<=≤<=*k**i*<=≤<=*n*).
Output Specification:
For each query, print on a single line the number of liters of water in the corresponding vessel.
Demo Input:
['2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2\n', '3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3\n']
Demo Output:
['4\n5\n8\n', '7\n10\n5\n']
Note:
none | ```python
n = int(input())
string = input().split()
vessels = []
transbordaEm = 300000
for i in range(n):
vessels.append([0,int(string[i])])
m = int(input())
for q in range(m):
query = input().split()
if(query[0] == '2'):
position = int(query[1]) - 1
print(vessels[position][0])
elif(query[0] == '1'):
position = int(query[1]) - 1
x = int(query[2])
if(position > transbordaEm): #não cabe mais
break
entered = False
for v in range(position, n):
c = vessels[v][1]
t = vessels[v][0]
if(x > (c-t)):
x = x - (c-t)
vessels[v][0] = c # t = c
else:
entered = True
vessels[v][0] = t + x # t = x
break
if(entered == False):# transbordou no chao
transbordaEm = position
``` | 0 |
|
148 | B | Escape | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at *v**p* miles per hour, and the dragon flies at *v**d* miles per hour. The dragon will discover the escape after *t* hours and will chase the princess immediately. Looks like there's no chance to success, but the princess noticed that the dragon is very greedy and not too smart. To delay him, the princess decides to borrow a couple of bijous from his treasury. Once the dragon overtakes the princess, she will drop one bijou to distract him. In this case he will stop, pick up the item, return to the cave and spend *f* hours to straighten the things out in the treasury. Only after this will he resume the chase again from the very beginning.
The princess is going to run on the straight. The distance between the cave and the king's castle she's aiming for is *c* miles. How many bijous will she need to take from the treasury to be able to reach the castle? If the dragon overtakes the princess at exactly the same moment she has reached the castle, we assume that she reached the castle before the dragon reached her, and doesn't need an extra bijou to hold him off. | The input data contains integers *v**p*,<=*v**d*,<=*t*,<=*f* and *c*, one per line (1<=≤<=*v**p*,<=*v**d*<=≤<=100, 1<=≤<=*t*,<=*f*<=≤<=10, 1<=≤<=*c*<=≤<=1000). | Output the minimal number of bijous required for the escape to succeed. | [
"1\n2\n1\n1\n10\n",
"1\n2\n1\n1\n8\n"
] | [
"2\n",
"1\n"
] | In the first case one hour after the escape the dragon will discover it, and the princess will be 1 mile away from the cave. In two hours the dragon will overtake the princess 2 miles away from the cave, and she will need to drop the first bijou. Return to the cave and fixing the treasury will take the dragon two more hours; meanwhile the princess will be 4 miles away from the cave. Next time the dragon will overtake the princess 8 miles away from the cave, and she will need the second bijou, but after this she will reach the castle without any further trouble.
The second case is similar to the first one, but the second time the dragon overtakes the princess when she has reached the castle, and she won't need the second bijou. | 1,000 | [
{
"input": "1\n2\n1\n1\n10",
"output": "2"
},
{
"input": "1\n2\n1\n1\n8",
"output": "1"
},
{
"input": "5\n8\n1\n2\n100",
"output": "2"
},
{
"input": "2\n100\n10\n10\n739",
"output": "22"
},
{
"input": "17\n99\n2\n3\n293",
"output": "3"
},
{
"input": "5\n5\n1\n1\n1000",
"output": "0"
},
{
"input": "100\n99\n1\n1\n1000",
"output": "0"
},
{
"input": "1\n100\n1\n1\n1",
"output": "0"
},
{
"input": "1\n100\n1\n1\n1000",
"output": "152"
},
{
"input": "10\n1\n10\n1\n11",
"output": "0"
},
{
"input": "98\n94\n4\n3\n437",
"output": "0"
},
{
"input": "58\n4\n1\n10\n392",
"output": "0"
},
{
"input": "74\n11\n8\n7\n835",
"output": "0"
},
{
"input": "86\n21\n7\n2\n982",
"output": "0"
},
{
"input": "2\n27\n4\n9\n937",
"output": "15"
},
{
"input": "62\n89\n8\n1\n83",
"output": "0"
},
{
"input": "78\n7\n7\n6\n38",
"output": "0"
},
{
"input": "94\n14\n2\n3\n481",
"output": "0"
},
{
"input": "6\n24\n9\n8\n628",
"output": "3"
},
{
"input": "59\n7\n8\n10\n357",
"output": "0"
},
{
"input": "75\n26\n4\n3\n504",
"output": "0"
},
{
"input": "87\n32\n3\n8\n754",
"output": "0"
},
{
"input": "51\n42\n10\n4\n901",
"output": "0"
},
{
"input": "63\n4\n7\n1\n48",
"output": "0"
},
{
"input": "79\n10\n4\n6\n3",
"output": "0"
},
{
"input": "95\n20\n9\n3\n149",
"output": "0"
},
{
"input": "55\n35\n5\n10\n592",
"output": "0"
},
{
"input": "71\n45\n2\n6\n547",
"output": "0"
},
{
"input": "83\n7\n7\n7\n46",
"output": "0"
},
{
"input": "100\n32\n1\n8\n537",
"output": "0"
},
{
"input": "17\n42\n10\n5\n684",
"output": "1"
},
{
"input": "77\n1\n6\n8\n831",
"output": "0"
},
{
"input": "93\n19\n3\n3\n82",
"output": "0"
},
{
"input": "5\n25\n8\n9\n228",
"output": "2"
},
{
"input": "21\n35\n5\n6\n535",
"output": "1"
},
{
"input": "85\n45\n2\n1\n682",
"output": "0"
},
{
"input": "97\n4\n8\n8\n829",
"output": "0"
},
{
"input": "13\n14\n3\n3\n79",
"output": "0"
},
{
"input": "25\n28\n4\n9\n226",
"output": "0"
},
{
"input": "34\n9\n6\n6\n70",
"output": "0"
},
{
"input": "50\n15\n1\n3\n216",
"output": "0"
},
{
"input": "10\n25\n9\n8\n363",
"output": "1"
},
{
"input": "26\n36\n4\n7\n318",
"output": "0"
},
{
"input": "38\n50\n1\n8\n761",
"output": "1"
},
{
"input": "2\n12\n6\n4\n907",
"output": "10"
},
{
"input": "14\n18\n5\n9\n862",
"output": "1"
},
{
"input": "30\n28\n4\n6\n9",
"output": "0"
},
{
"input": "46\n39\n8\n3\n964",
"output": "0"
},
{
"input": "6\n45\n7\n8\n407",
"output": "4"
},
{
"input": "67\n34\n7\n4\n954",
"output": "0"
},
{
"input": "31\n40\n6\n1\n397",
"output": "0"
},
{
"input": "43\n50\n1\n8\n544",
"output": "1"
},
{
"input": "59\n9\n7\n3\n498",
"output": "0"
},
{
"input": "71\n19\n2\n10\n645",
"output": "0"
},
{
"input": "35\n37\n9\n5\n792",
"output": "0"
},
{
"input": "47\n43\n10\n9\n43",
"output": "0"
},
{
"input": "63\n53\n5\n4\n189",
"output": "0"
},
{
"input": "79\n11\n2\n1\n144",
"output": "0"
},
{
"input": "39\n22\n8\n6\n291",
"output": "0"
},
{
"input": "49\n7\n2\n5\n326",
"output": "0"
},
{
"input": "2\n1\n1\n1\n1000",
"output": "0"
},
{
"input": "100\n1\n1\n1\n1000",
"output": "0"
},
{
"input": "2\n1\n1\n1\n100",
"output": "0"
},
{
"input": "2\n1\n1\n1\n10",
"output": "0"
},
{
"input": "5\n3\n3\n3\n999",
"output": "0"
}
] | 1,698,301,128 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 62 | 0 | vp = int(input())
vd = int(input())
t = int(input())
f = int(input())
c = int(input())
iss = False
l = vp*t
ans = 0
if vp >= vd:
print(0)
iss = True
while True:
x = l*1/(vd-vp)
l += vp*x
if l - c >=0:
break
else:
ans += 1
l += (x + f) *vp
if iss==False:
print(ans) | Title: Escape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at *v**p* miles per hour, and the dragon flies at *v**d* miles per hour. The dragon will discover the escape after *t* hours and will chase the princess immediately. Looks like there's no chance to success, but the princess noticed that the dragon is very greedy and not too smart. To delay him, the princess decides to borrow a couple of bijous from his treasury. Once the dragon overtakes the princess, she will drop one bijou to distract him. In this case he will stop, pick up the item, return to the cave and spend *f* hours to straighten the things out in the treasury. Only after this will he resume the chase again from the very beginning.
The princess is going to run on the straight. The distance between the cave and the king's castle she's aiming for is *c* miles. How many bijous will she need to take from the treasury to be able to reach the castle? If the dragon overtakes the princess at exactly the same moment she has reached the castle, we assume that she reached the castle before the dragon reached her, and doesn't need an extra bijou to hold him off.
Input Specification:
The input data contains integers *v**p*,<=*v**d*,<=*t*,<=*f* and *c*, one per line (1<=≤<=*v**p*,<=*v**d*<=≤<=100, 1<=≤<=*t*,<=*f*<=≤<=10, 1<=≤<=*c*<=≤<=1000).
Output Specification:
Output the minimal number of bijous required for the escape to succeed.
Demo Input:
['1\n2\n1\n1\n10\n', '1\n2\n1\n1\n8\n']
Demo Output:
['2\n', '1\n']
Note:
In the first case one hour after the escape the dragon will discover it, and the princess will be 1 mile away from the cave. In two hours the dragon will overtake the princess 2 miles away from the cave, and she will need to drop the first bijou. Return to the cave and fixing the treasury will take the dragon two more hours; meanwhile the princess will be 4 miles away from the cave. Next time the dragon will overtake the princess 8 miles away from the cave, and she will need the second bijou, but after this she will reach the castle without any further trouble.
The second case is similar to the first one, but the second time the dragon overtakes the princess when she has reached the castle, and she won't need the second bijou. | ```python
vp = int(input())
vd = int(input())
t = int(input())
f = int(input())
c = int(input())
iss = False
l = vp*t
ans = 0
if vp >= vd:
print(0)
iss = True
while True:
x = l*1/(vd-vp)
l += vp*x
if l - c >=0:
break
else:
ans += 1
l += (x + f) *vp
if iss==False:
print(ans)
``` | -1 |
|
962 | B | Students in Railway Carriage | PROGRAMMING | 1,300 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of students from all $a+b$ students, which you can put in the railway carriage so that:
- no student-programmer is sitting next to the student-programmer; - and no student-athlete is sitting next to the student-athlete.
In the other words, there should not be two consecutive (adjacent) places where two student-athletes or two student-programmers are sitting.
Consider that initially occupied seat places are occupied by jury members (who obviously are not students at all). | The first line contain three integers $n$, $a$ and $b$ ($1 \le n \le 2\cdot10^{5}$, $0 \le a, b \le 2\cdot10^{5}$, $a + b > 0$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.
The second line contains a string with length $n$, consisting of characters "." and "*". The dot means that the corresponding place is empty. The asterisk means that the corresponding place is occupied by the jury member. | Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete. | [
"5 1 1\n*...*\n",
"6 2 3\n*...*.\n",
"11 3 10\n.*....**.*.\n",
"3 2 3\n***\n"
] | [
"2\n",
"4\n",
"7\n",
"0\n"
] | In the first example you can put all student, for example, in the following way: *.AB*
In the second example you can put four students, for example, in the following way: *BAB*B
In the third example you can put seven students, for example, in the following way: B*ABAB**A*B
The letter A means a student-programmer, and the letter B — student-athlete. | 0 | [
{
"input": "5 1 1\n*...*",
"output": "2"
},
{
"input": "6 2 3\n*...*.",
"output": "4"
},
{
"input": "11 3 10\n.*....**.*.",
"output": "7"
},
{
"input": "3 2 3\n***",
"output": "0"
},
{
"input": "9 5 3\n*...*...*",
"output": "6"
},
{
"input": "9 2 4\n*...*...*",
"output": "6"
},
{
"input": "9 2 200000\n*...*...*",
"output": "6"
},
{
"input": "1 0 1\n.",
"output": "1"
},
{
"input": "14 3 7\n.*.......*..*.",
"output": "10"
},
{
"input": "6 1 3\n*....*",
"output": "3"
},
{
"input": "5 1 2\n...*.",
"output": "3"
},
{
"input": "2 2 0\n..",
"output": "1"
},
{
"input": "2 0 2\n..",
"output": "1"
},
{
"input": "5 3 3\n...**",
"output": "3"
},
{
"input": "3 0 1\n.*.",
"output": "1"
},
{
"input": "13 3 3\n*...*...*...*",
"output": "6"
},
{
"input": "7 0 4\n...*..*",
"output": "3"
},
{
"input": "20 5 5\n.*.*.............*..",
"output": "10"
},
{
"input": "64 59 2\n.*.***......****.*..**..**..****.*.*.*.**...**..***.***.*..*..*.",
"output": "23"
},
{
"input": "2 1 1\n..",
"output": "2"
},
{
"input": "10 7 0\n.*...*..*.",
"output": "5"
},
{
"input": "4 1 1\n..*.",
"output": "2"
},
{
"input": "10 4 3\n.*..*...*.",
"output": "7"
},
{
"input": "5 0 1\n*.*.*",
"output": "1"
},
{
"input": "6 1 1\n*...*.",
"output": "2"
},
{
"input": "1 1 1\n.",
"output": "1"
},
{
"input": "11 6 2\n.*...*...*.",
"output": "8"
},
{
"input": "11 7 1\n.*...*...*.",
"output": "7"
}
] | 1,699,578,301 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sz(s) (int)s.size()
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
ll oo = 1e12;
int ioo = 1e9 + 7;
int mod = 1e9 + 7;
const char el = '\n';
int dr[] = {1,-1,0, 0,1,-1,-1, 1};
int dc[] = {0, 0,1,-1,1, 1,-1,-1};
string abc = "abcdefghijklmnopqrstuvwxyz";
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, a, b; cin >> n >> a >> b;
string s; cin >> s;
deque<int> d;
if (a>b) d.push_back(a), d.push_back(b);
else d.push_back(b), d.push_back(a);
int ans = 0;
for (char c:s) {
if (c == '*') {
a = d.front(); d.pop_front();
b = d.front(); d.pop_front();
if (a>b) d.push_back(a), d.push_back(b);
else d.push_back(b), d.push_back(a);
continue;
}
int curr = d.front(); d.pop_front();
if (!curr) break;
curr--;
ans++;
d.push_back(curr);
}
cout << ans << el;
return 0;
}
| Title: Students in Railway Carriage
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of students from all $a+b$ students, which you can put in the railway carriage so that:
- no student-programmer is sitting next to the student-programmer; - and no student-athlete is sitting next to the student-athlete.
In the other words, there should not be two consecutive (adjacent) places where two student-athletes or two student-programmers are sitting.
Consider that initially occupied seat places are occupied by jury members (who obviously are not students at all).
Input Specification:
The first line contain three integers $n$, $a$ and $b$ ($1 \le n \le 2\cdot10^{5}$, $0 \le a, b \le 2\cdot10^{5}$, $a + b > 0$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.
The second line contains a string with length $n$, consisting of characters "." and "*". The dot means that the corresponding place is empty. The asterisk means that the corresponding place is occupied by the jury member.
Output Specification:
Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete.
Demo Input:
['5 1 1\n*...*\n', '6 2 3\n*...*.\n', '11 3 10\n.*....**.*.\n', '3 2 3\n***\n']
Demo Output:
['2\n', '4\n', '7\n', '0\n']
Note:
In the first example you can put all student, for example, in the following way: *.AB*
In the second example you can put four students, for example, in the following way: *BAB*B
In the third example you can put seven students, for example, in the following way: B*ABAB**A*B
The letter A means a student-programmer, and the letter B — student-athlete. | ```python
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sz(s) (int)s.size()
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
ll oo = 1e12;
int ioo = 1e9 + 7;
int mod = 1e9 + 7;
const char el = '\n';
int dr[] = {1,-1,0, 0,1,-1,-1, 1};
int dc[] = {0, 0,1,-1,1, 1,-1,-1};
string abc = "abcdefghijklmnopqrstuvwxyz";
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, a, b; cin >> n >> a >> b;
string s; cin >> s;
deque<int> d;
if (a>b) d.push_back(a), d.push_back(b);
else d.push_back(b), d.push_back(a);
int ans = 0;
for (char c:s) {
if (c == '*') {
a = d.front(); d.pop_front();
b = d.front(); d.pop_front();
if (a>b) d.push_back(a), d.push_back(b);
else d.push_back(b), d.push_back(a);
continue;
}
int curr = d.front(); d.pop_front();
if (!curr) break;
curr--;
ans++;
d.push_back(curr);
}
cout << ans << el;
return 0;
}
``` | -1 |
|
602 | A | Two Bases | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations.
You're given a number *X* represented in base *b**x* and a number *Y* represented in base *b**y*. Compare those two numbers. | The first line of the input contains two space-separated integers *n* and *b**x* (1<=≤<=*n*<=≤<=10, 2<=≤<=*b**x*<=≤<=40), where *n* is the number of digits in the *b**x*-based representation of *X*.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=<<=*b**x*) — the digits of *X*. They are given in the order from the most significant digit to the least significant one.
The following two lines describe *Y* in the same way: the third line contains two space-separated integers *m* and *b**y* (1<=≤<=*m*<=≤<=10, 2<=≤<=*b**y*<=≤<=40, *b**x*<=≠<=*b**y*), where *m* is the number of digits in the *b**y*-based representation of *Y*, and the fourth line contains *m* space-separated integers *y*1,<=*y*2,<=...,<=*y**m* (0<=≤<=*y**i*<=<<=*b**y*) — the digits of *Y*.
There will be no leading zeroes. Both *X* and *Y* will be positive. All digits of both numbers are given in the standard decimal numeral system. | Output a single character (quotes for clarity):
- '<' if *X*<=<<=*Y* - '>' if *X*<=><=*Y* - '=' if *X*<==<=*Y* | [
"6 2\n1 0 1 1 1 1\n2 10\n4 7\n",
"3 3\n1 0 2\n2 5\n2 4\n",
"7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n"
] | [
"=\n",
"<\n",
">\n"
] | In the first sample, *X* = 101111<sub class="lower-index">2</sub> = 47<sub class="lower-index">10</sub> = *Y*.
In the second sample, *X* = 102<sub class="lower-index">3</sub> = 21<sub class="lower-index">5</sub> and *Y* = 24<sub class="lower-index">5</sub> = 112<sub class="lower-index">3</sub>, thus *X* < *Y*.
In the third sample, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/603a342b0ae3e56fed542d1c50c0a5ff6ce2cbaa.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *Y* = 4803150<sub class="lower-index">9</sub>. We may notice that *X* starts with much larger digits and *b*<sub class="lower-index">*x*</sub> is much larger than *b*<sub class="lower-index">*y*</sub>, so *X* is clearly larger than *Y*. | 500 | [
{
"input": "6 2\n1 0 1 1 1 1\n2 10\n4 7",
"output": "="
},
{
"input": "3 3\n1 0 2\n2 5\n2 4",
"output": "<"
},
{
"input": "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0",
"output": ">"
},
{
"input": "2 2\n1 0\n2 3\n1 0",
"output": "<"
},
{
"input": "2 2\n1 0\n1 3\n1",
"output": ">"
},
{
"input": "10 2\n1 0 1 0 1 0 1 0 1 0\n10 3\n2 2 2 2 2 2 2 2 2 2",
"output": "<"
},
{
"input": "10 16\n15 15 4 0 0 0 0 7 10 9\n7 9\n4 8 0 3 1 5 0",
"output": ">"
},
{
"input": "5 5\n4 4 4 4 4\n4 6\n5 5 5 5",
"output": ">"
},
{
"input": "2 8\n1 0\n4 2\n1 0 0 0",
"output": "="
},
{
"input": "5 2\n1 0 0 0 1\n6 8\n1 4 7 2 0 0",
"output": "<"
},
{
"input": "6 7\n1 1 2 1 2 1\n6 6\n2 3 2 2 2 2",
"output": "="
},
{
"input": "9 35\n34 3 20 29 27 30 2 8 5\n7 33\n17 3 22 31 1 11 6",
"output": ">"
},
{
"input": "1 8\n5\n9 27\n23 23 23 23 23 23 23 23 23",
"output": "<"
},
{
"input": "4 7\n3 0 6 6\n3 11\n7 10 10",
"output": ">"
},
{
"input": "1 40\n1\n2 5\n1 0",
"output": "<"
},
{
"input": "1 36\n35\n4 5\n2 4 4 1",
"output": "<"
},
{
"input": "1 30\n1\n1 31\n1",
"output": "="
},
{
"input": "1 3\n1\n1 2\n1",
"output": "="
},
{
"input": "1 2\n1\n1 40\n1",
"output": "="
},
{
"input": "6 29\n1 1 1 1 1 1\n10 21\n1 1 1 1 1 1 1 1 1 1",
"output": "<"
},
{
"input": "3 5\n1 0 0\n3 3\n2 2 2",
"output": "<"
},
{
"input": "2 8\n1 0\n2 3\n2 2",
"output": "="
},
{
"input": "2 4\n3 3\n2 15\n1 0",
"output": "="
},
{
"input": "2 35\n1 0\n2 6\n5 5",
"output": "="
},
{
"input": "2 6\n5 5\n2 34\n1 0",
"output": ">"
},
{
"input": "2 7\n1 0\n2 3\n2 2",
"output": "<"
},
{
"input": "2 2\n1 0\n1 3\n2",
"output": "="
},
{
"input": "2 9\n5 5\n4 3\n1 0 0 0",
"output": ">"
},
{
"input": "1 24\n6\n3 9\n1 1 1",
"output": "<"
},
{
"input": "5 37\n9 9 9 9 9\n6 27\n13 0 0 0 0 0",
"output": "<"
},
{
"input": "10 2\n1 1 1 1 1 1 1 1 1 1\n10 34\n14 14 14 14 14 14 14 14 14 14",
"output": "<"
},
{
"input": "7 26\n8 0 0 0 0 0 0\n9 9\n3 3 3 3 3 3 3 3 3",
"output": ">"
},
{
"input": "2 40\n2 0\n5 13\n4 0 0 0 0",
"output": "<"
},
{
"input": "1 22\n15\n10 14\n3 3 3 3 3 3 3 3 3 3",
"output": "<"
},
{
"input": "10 22\n3 3 3 3 3 3 3 3 3 3\n3 40\n19 19 19",
"output": ">"
},
{
"input": "2 29\n11 11\n6 26\n11 11 11 11 11 11",
"output": "<"
},
{
"input": "5 3\n1 0 0 0 0\n4 27\n1 0 0 0",
"output": "<"
},
{
"input": "10 3\n1 0 0 0 0 0 0 0 0 0\n8 13\n1 0 0 0 0 0 0 0",
"output": "<"
},
{
"input": "4 20\n1 1 1 1\n5 22\n1 1 1 1 1",
"output": "<"
},
{
"input": "10 39\n34 2 24 34 11 6 33 12 22 21\n10 36\n25 35 17 24 30 0 1 32 14 35",
"output": ">"
},
{
"input": "10 39\n35 12 31 35 28 27 25 8 22 25\n10 40\n23 21 18 12 15 29 38 32 4 8",
"output": ">"
},
{
"input": "10 38\n16 19 37 32 16 7 14 33 16 11\n10 39\n10 27 35 15 31 15 17 16 38 35",
"output": ">"
},
{
"input": "10 39\n20 12 10 32 24 14 37 35 10 38\n9 40\n1 13 0 10 22 20 1 5 35",
"output": ">"
},
{
"input": "10 40\n18 1 2 25 28 2 10 2 17 37\n10 39\n37 8 12 8 21 11 23 11 25 21",
"output": "<"
},
{
"input": "9 39\n10 20 16 36 30 29 28 9 8\n9 38\n12 36 10 22 6 3 19 12 34",
"output": "="
},
{
"input": "7 39\n28 16 13 25 19 23 4\n7 38\n33 8 2 19 3 21 14",
"output": "="
},
{
"input": "10 16\n15 15 4 0 0 0 0 7 10 9\n10 9\n4 8 0 3 1 5 4 8 1 0",
"output": ">"
},
{
"input": "7 22\n1 13 9 16 7 13 3\n4 4\n3 0 2 1",
"output": ">"
},
{
"input": "10 29\n10 19 8 27 1 24 13 15 13 26\n2 28\n20 14",
"output": ">"
},
{
"input": "6 16\n2 13 7 13 15 6\n10 22\n17 17 21 9 16 11 4 4 13 17",
"output": "<"
},
{
"input": "8 26\n6 6 17 25 24 8 8 25\n4 27\n24 7 5 24",
"output": ">"
},
{
"input": "10 23\n5 21 4 15 12 7 10 7 16 21\n4 17\n3 11 1 14",
"output": ">"
},
{
"input": "10 21\n4 7 7 2 13 7 19 19 18 19\n3 31\n6 11 28",
"output": ">"
},
{
"input": "1 30\n9\n7 37\n20 11 18 14 0 36 27",
"output": "<"
},
{
"input": "5 35\n22 18 28 29 11\n2 3\n2 0",
"output": ">"
},
{
"input": "7 29\n14 26 14 22 11 11 8\n6 28\n2 12 10 17 0 14",
"output": ">"
},
{
"input": "2 37\n25 2\n3 26\n13 13 12",
"output": "<"
},
{
"input": "8 8\n4 0 4 3 4 1 5 6\n8 24\n19 8 15 6 10 7 2 18",
"output": "<"
},
{
"input": "4 22\n18 16 1 2\n10 26\n23 0 12 24 16 2 24 25 1 11",
"output": "<"
},
{
"input": "7 31\n14 6 16 6 26 18 17\n7 24\n22 10 4 5 14 6 9",
"output": ">"
},
{
"input": "10 29\n15 22 0 5 11 12 17 22 4 27\n4 22\n9 2 8 14",
"output": ">"
},
{
"input": "2 10\n6 0\n10 26\n16 14 8 18 24 4 9 5 22 25",
"output": "<"
},
{
"input": "7 2\n1 0 0 0 1 0 1\n9 6\n1 1 5 1 2 5 3 5 3",
"output": "<"
},
{
"input": "3 9\n2 5 4\n1 19\n15",
"output": ">"
},
{
"input": "6 16\n4 9 13 4 2 8\n4 10\n3 5 2 4",
"output": ">"
},
{
"input": "2 12\n1 4\n8 16\n4 4 10 6 15 10 8 15",
"output": "<"
},
{
"input": "3 19\n9 18 16\n4 10\n4 3 5 4",
"output": "<"
},
{
"input": "7 3\n1 1 2 1 2 0 2\n2 2\n1 0",
"output": ">"
},
{
"input": "3 2\n1 1 1\n1 3\n1",
"output": ">"
},
{
"input": "4 4\n1 3 1 3\n9 3\n1 1 0 1 2 2 2 2 1",
"output": "<"
},
{
"input": "9 3\n1 0 0 1 1 0 0 1 2\n6 4\n1 2 0 1 3 2",
"output": ">"
},
{
"input": "3 5\n1 1 3\n10 4\n3 3 2 3 0 0 0 3 1 1",
"output": "<"
},
{
"input": "6 4\n3 3 2 2 0 2\n6 5\n1 1 1 1 0 3",
"output": ">"
},
{
"input": "6 5\n4 4 4 3 1 3\n7 6\n4 2 2 2 5 0 4",
"output": "<"
},
{
"input": "2 5\n3 3\n6 6\n4 2 0 1 1 0",
"output": "<"
},
{
"input": "10 6\n3 5 4 2 4 2 3 5 4 2\n10 7\n3 2 1 1 3 1 0 3 4 5",
"output": "<"
},
{
"input": "9 7\n2 0 3 2 6 6 1 4 3\n9 6\n4 4 1 1 4 5 5 0 2",
"output": ">"
},
{
"input": "1 7\n2\n4 8\n3 2 3 2",
"output": "<"
},
{
"input": "2 8\n4 1\n1 7\n1",
"output": ">"
},
{
"input": "1 10\n7\n3 9\n2 1 7",
"output": "<"
},
{
"input": "9 9\n2 2 3 6 3 6 3 8 4\n6 10\n4 7 7 0 3 8",
"output": ">"
},
{
"input": "3 11\n6 5 2\n8 10\n5 0 1 8 3 5 1 4",
"output": "<"
},
{
"input": "6 11\n10 6 1 0 2 2\n9 10\n4 3 4 1 1 6 3 4 1",
"output": "<"
},
{
"input": "2 19\n4 8\n8 18\n7 8 6 8 4 11 9 1",
"output": "<"
},
{
"input": "2 24\n20 9\n10 23\n21 10 15 11 6 8 20 16 14 11",
"output": "<"
},
{
"input": "8 36\n23 5 27 1 10 7 26 27\n10 35\n28 33 9 22 10 28 26 4 27 29",
"output": "<"
},
{
"input": "6 37\n22 15 14 10 1 8\n6 36\n18 5 28 10 1 17",
"output": ">"
},
{
"input": "5 38\n1 31 2 21 21\n9 37\n8 36 32 30 13 9 24 2 35",
"output": "<"
},
{
"input": "3 39\n27 4 3\n8 38\n32 15 11 34 35 27 30 15",
"output": "<"
},
{
"input": "2 40\n22 38\n5 39\n8 9 32 4 1",
"output": "<"
},
{
"input": "9 37\n1 35 7 33 20 21 26 24 5\n10 40\n39 4 11 9 33 12 26 32 11 8",
"output": "<"
},
{
"input": "4 39\n13 25 23 35\n6 38\n19 36 20 4 12 33",
"output": "<"
},
{
"input": "5 37\n29 29 5 7 27\n3 39\n13 1 10",
"output": ">"
},
{
"input": "7 28\n1 10 7 0 13 14 11\n6 38\n8 11 27 5 14 35",
"output": "="
},
{
"input": "2 34\n1 32\n2 33\n2 0",
"output": "="
},
{
"input": "7 5\n4 0 4 1 3 0 4\n4 35\n1 18 7 34",
"output": "="
},
{
"input": "9 34\n5 8 4 4 26 1 30 5 24\n10 27\n1 6 3 10 8 13 22 3 12 8",
"output": "="
},
{
"input": "10 36\n1 13 13 23 31 35 5 32 18 21\n9 38\n32 1 20 14 12 37 13 15 23",
"output": "="
},
{
"input": "10 40\n1 1 14 5 6 3 3 11 3 25\n10 39\n1 11 24 33 25 34 38 29 27 33",
"output": "="
},
{
"input": "9 37\n2 6 1 9 19 6 11 28 35\n9 40\n1 6 14 37 1 8 31 4 9",
"output": "="
},
{
"input": "4 5\n1 4 2 0\n4 4\n3 2 2 3",
"output": "="
},
{
"input": "6 4\n1 1 1 2 2 2\n7 3\n1 2 2 0 1 0 0",
"output": "="
},
{
"input": "2 5\n3 3\n5 2\n1 0 0 1 0",
"output": "="
},
{
"input": "1 9\n2\n1 10\n2",
"output": "="
},
{
"input": "6 19\n4 9 14 1 3 1\n8 10\n1 1 1 7 3 7 3 0",
"output": "="
},
{
"input": "7 15\n8 5 8 10 13 6 13\n8 13\n1 6 9 10 12 3 12 8",
"output": "="
},
{
"input": "8 18\n1 1 4 15 7 4 9 3\n8 17\n1 10 2 10 3 11 14 10",
"output": "="
},
{
"input": "8 21\n5 19 0 14 13 13 10 5\n10 13\n1 0 0 6 11 10 8 2 8 1",
"output": "="
},
{
"input": "8 28\n3 1 10 19 10 14 21 15\n8 21\n14 0 18 13 2 1 18 6",
"output": ">"
},
{
"input": "7 34\n21 22 28 16 30 4 27\n7 26\n5 13 21 10 8 12 10",
"output": ">"
},
{
"input": "6 26\n7 6 4 18 6 1\n6 25\n5 3 11 1 8 15",
"output": ">"
},
{
"input": "10 31\n6 27 17 22 14 16 25 9 13 26\n10 39\n6 1 3 26 12 32 28 19 9 19",
"output": "<"
},
{
"input": "3 5\n2 2 3\n3 6\n4 3 5",
"output": "<"
},
{
"input": "2 24\n4 18\n2 40\n29 24",
"output": "<"
},
{
"input": "5 38\n2 24 34 14 17\n8 34\n4 24 31 2 14 15 8 15",
"output": "<"
},
{
"input": "9 40\n39 39 39 39 39 39 39 39 39\n6 35\n34 34 34 34 34 34",
"output": ">"
},
{
"input": "10 40\n39 39 39 39 39 39 39 39 39 39\n10 8\n7 7 7 7 7 7 7 7 7 7",
"output": ">"
},
{
"input": "10 40\n39 39 39 39 39 39 39 39 39 39\n10 39\n38 38 38 38 38 38 38 38 38 38",
"output": ">"
}
] | 1,579,853,129 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 109 | 0 | Answer = []
for i in range(2):
Temp = list(map(int, input().split()))
Num = input().replace(" ", "")
Answer.append(int(Num, Temp[1]))
print("=" if Answer[1] == Answer[0] else ("<" if Answer[0] < Answer[1] else ">"))
# Show you deserve being the best to whom doesn't believe in you.
| Title: Two Bases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations.
You're given a number *X* represented in base *b**x* and a number *Y* represented in base *b**y*. Compare those two numbers.
Input Specification:
The first line of the input contains two space-separated integers *n* and *b**x* (1<=≤<=*n*<=≤<=10, 2<=≤<=*b**x*<=≤<=40), where *n* is the number of digits in the *b**x*-based representation of *X*.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=<<=*b**x*) — the digits of *X*. They are given in the order from the most significant digit to the least significant one.
The following two lines describe *Y* in the same way: the third line contains two space-separated integers *m* and *b**y* (1<=≤<=*m*<=≤<=10, 2<=≤<=*b**y*<=≤<=40, *b**x*<=≠<=*b**y*), where *m* is the number of digits in the *b**y*-based representation of *Y*, and the fourth line contains *m* space-separated integers *y*1,<=*y*2,<=...,<=*y**m* (0<=≤<=*y**i*<=<<=*b**y*) — the digits of *Y*.
There will be no leading zeroes. Both *X* and *Y* will be positive. All digits of both numbers are given in the standard decimal numeral system.
Output Specification:
Output a single character (quotes for clarity):
- '<' if *X*<=<<=*Y* - '>' if *X*<=><=*Y* - '=' if *X*<==<=*Y*
Demo Input:
['6 2\n1 0 1 1 1 1\n2 10\n4 7\n', '3 3\n1 0 2\n2 5\n2 4\n', '7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n']
Demo Output:
['=\n', '<\n', '>\n']
Note:
In the first sample, *X* = 101111<sub class="lower-index">2</sub> = 47<sub class="lower-index">10</sub> = *Y*.
In the second sample, *X* = 102<sub class="lower-index">3</sub> = 21<sub class="lower-index">5</sub> and *Y* = 24<sub class="lower-index">5</sub> = 112<sub class="lower-index">3</sub>, thus *X* < *Y*.
In the third sample, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/603a342b0ae3e56fed542d1c50c0a5ff6ce2cbaa.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *Y* = 4803150<sub class="lower-index">9</sub>. We may notice that *X* starts with much larger digits and *b*<sub class="lower-index">*x*</sub> is much larger than *b*<sub class="lower-index">*y*</sub>, so *X* is clearly larger than *Y*. | ```python
Answer = []
for i in range(2):
Temp = list(map(int, input().split()))
Num = input().replace(" ", "")
Answer.append(int(Num, Temp[1]))
print("=" if Answer[1] == Answer[0] else ("<" if Answer[0] < Answer[1] else ">"))
# Show you deserve being the best to whom doesn't believe in you.
``` | 0 |
|
614 | B | Gena's Code | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!
There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.
Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case. | The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000. | Print a single number without leading zeroes — the product of the number of tanks presented by each country. | [
"3\n5 10 1\n",
"4\n1 1 10 11\n",
"5\n0 3 1 100 1\n"
] | [
"50",
"110",
"0"
] | In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | 1,000 | [
{
"input": "3\n5 10 1",
"output": "50"
},
{
"input": "4\n1 1 10 11",
"output": "110"
},
{
"input": "5\n0 3 1 100 1",
"output": "0"
},
{
"input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100",
"output": "1824868942000000000000000000000000000000000000000000000000000"
},
{
"input": "6\n1000000000000000000000000000000000000 6643573784 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000",
"output": "6643573784000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n9",
"output": "9"
},
{
"input": "2\n10 50",
"output": "500"
},
{
"input": "3\n500 1 10",
"output": "5000"
}
] | 1,474,461,722 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n = int(input())
ll = input().split()
zero = 0
nb = ''
flag = 1
for x in ll:
if x == '0':
flag = 0
break
else:
if x.count('1') == 1:
zero += len(x) - 1
else:
nb = x
if flag == 0:
print(0)
else:
print(nb + ('0' * zero)) | Title: Gena's Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!
There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.
Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.
Input Specification:
The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000.
Output Specification:
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
Demo Input:
['3\n5 10 1\n', '4\n1 1 10 11\n', '5\n0 3 1 100 1\n']
Demo Output:
['50', '110', '0']
Note:
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | ```python
n = int(input())
ll = input().split()
zero = 0
nb = ''
flag = 1
for x in ll:
if x == '0':
flag = 0
break
else:
if x.count('1') == 1:
zero += len(x) - 1
else:
nb = x
if flag == 0:
print(0)
else:
print(nb + ('0' * zero))
``` | 0 |
|
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks.
Help Ivan to answer this question for several values of *x*! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100",
"output": "NO\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "3\n6\n6\n6",
"output": "YES\nYES\nYES"
},
{
"input": "47\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n1\n52\n76",
"output": "NO\nYES\nYES"
},
{
"input": "87\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "3\n3\n2\n1",
"output": "YES\nNO\nNO"
},
{
"input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,568,638,820 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
for testcase in range(n):
a=int(input())
if a%3==0:
print("YES")
elif a%7==0
print("YES")
else
r=a%7
if r%3==0
print("YES")
else
print("NO") | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks.
Help Ivan to answer this question for several values of *x*!
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat.
Output Specification:
Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO.
Demo Input:
['2\n6\n5\n']
Demo Output:
['YES\nNO\n']
Note:
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | ```python
n=int(input())
for testcase in range(n):
a=int(input())
if a%3==0:
print("YES")
elif a%7==0
print("YES")
else
r=a%7
if r%3==0
print("YES")
else
print("NO")
``` | -1 |
|
719 | A | Vitya in the Countryside | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.
As there is no internet in the countryside, Vitya has been watching the moon for *n* consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records.
It's guaranteed that the input data is consistent. | If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. | [
"5\n3 4 5 6 7\n",
"7\n12 13 14 15 14 13 12\n",
"1\n8\n"
] | [
"UP\n",
"DOWN\n",
"-1\n"
] | In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. | 500 | [
{
"input": "5\n3 4 5 6 7",
"output": "UP"
},
{
"input": "7\n12 13 14 15 14 13 12",
"output": "DOWN"
},
{
"input": "1\n8",
"output": "-1"
},
{
"input": "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10",
"output": "DOWN"
},
{
"input": "92\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4",
"output": "UP"
},
{
"input": "6\n10 11 12 13 14 15",
"output": "DOWN"
},
{
"input": "27\n11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "DOWN"
},
{
"input": "6\n8 7 6 5 4 3",
"output": "DOWN"
},
{
"input": "27\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10",
"output": "UP"
},
{
"input": "79\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5",
"output": "DOWN"
},
{
"input": "25\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7",
"output": "DOWN"
},
{
"input": "21\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7",
"output": "DOWN"
},
{
"input": "56\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6",
"output": "DOWN"
},
{
"input": "19\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14",
"output": "UP"
},
{
"input": "79\n5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13",
"output": "UP"
},
{
"input": "87\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10",
"output": "UP"
},
{
"input": "13\n10 9 8 7 6 5 4 3 2 1 0 1 2",
"output": "UP"
},
{
"input": "2\n8 9",
"output": "UP"
},
{
"input": "3\n10 11 12",
"output": "UP"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "1\n2",
"output": "-1"
},
{
"input": "1\n3",
"output": "-1"
},
{
"input": "1\n4",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n6",
"output": "-1"
},
{
"input": "1\n7",
"output": "-1"
},
{
"input": "1\n9",
"output": "-1"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "1\n11",
"output": "-1"
},
{
"input": "1\n12",
"output": "-1"
},
{
"input": "1\n13",
"output": "-1"
},
{
"input": "1\n14",
"output": "-1"
},
{
"input": "1\n15",
"output": "DOWN"
},
{
"input": "1\n0",
"output": "UP"
},
{
"input": "3\n11 12 13",
"output": "UP"
},
{
"input": "2\n10 9",
"output": "DOWN"
},
{
"input": "92\n10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11",
"output": "UP"
},
{
"input": "92\n7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6",
"output": "DOWN"
},
{
"input": "2\n14 15",
"output": "DOWN"
},
{
"input": "2\n1 0",
"output": "UP"
},
{
"input": "2\n15 14",
"output": "DOWN"
},
{
"input": "92\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8",
"output": "UP"
},
{
"input": "92\n13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12",
"output": "DOWN"
},
{
"input": "92\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3",
"output": "DOWN"
},
{
"input": "92\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "DOWN"
},
{
"input": "92\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "UP"
},
{
"input": "2\n2 1",
"output": "DOWN"
},
{
"input": "3\n2 1 0",
"output": "UP"
},
{
"input": "5\n4 3 2 1 0",
"output": "UP"
},
{
"input": "2\n5 4",
"output": "DOWN"
},
{
"input": "4\n3 2 1 0",
"output": "UP"
},
{
"input": "3\n13 12 11",
"output": "DOWN"
},
{
"input": "2\n1 2",
"output": "UP"
},
{
"input": "2\n0 1",
"output": "UP"
},
{
"input": "2\n13 14",
"output": "UP"
},
{
"input": "14\n13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "UP"
}
] | 1,535,644,781 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 0 | import sys
'''
'''
def main():
n = int(sys.stdin.readline())
moon = [int(x) for x in sys.stdin.readline().split()]
if n is 1:
print(-1)
else:
last1 = moon[n-1]
last2 = moon[n-2]
if last1 != 0:
if last2 > last1:
print("DOWN")
else:
print("UP")
else:
if (last1 == 0 and last2 == 1):
print("UP")
else:
print("DOWN")
if __name__ == ("__main__"):
main()
| Title: Vitya in the Countryside
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.
As there is no internet in the countryside, Vitya has been watching the moon for *n* consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records.
It's guaranteed that the input data is consistent.
Output Specification:
If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.
Demo Input:
['5\n3 4 5 6 7\n', '7\n12 13 14 15 14 13 12\n', '1\n8\n']
Demo Output:
['UP\n', 'DOWN\n', '-1\n']
Note:
In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. | ```python
import sys
'''
'''
def main():
n = int(sys.stdin.readline())
moon = [int(x) for x in sys.stdin.readline().split()]
if n is 1:
print(-1)
else:
last1 = moon[n-1]
last2 = moon[n-2]
if last1 != 0:
if last2 > last1:
print("DOWN")
else:
print("UP")
else:
if (last1 == 0 and last2 == 1):
print("UP")
else:
print("DOWN")
if __name__ == ("__main__"):
main()
``` | 0 |
|
299 | B | Ksusha the Squirrel | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".". | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "YES"
},
{
"input": "2 100000\n..",
"output": "YES"
},
{
"input": "3 1\n.#.",
"output": "NO"
},
{
"input": "3 2\n.#.",
"output": "YES"
},
{
"input": "3 10000\n.#.",
"output": "YES"
}
] | 1,622,127,460 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 154 | 1,024,000 | n,k=map(int,input().split())
print('YNEOS'['#'*k in input()::2]) | Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)?
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".".
Output Specification:
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
Demo Input:
['2 1\n..\n', '5 2\n.#.#.\n', '7 3\n.#.###.\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
n,k=map(int,input().split())
print('YNEOS'['#'*k in input()::2])
``` | 3 |
|
680 | A | Bear and Five Cards | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards? | The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. | Print the minimum possible sum of numbers written on remaining cards. | [
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] | [
"26\n",
"28\n",
"20\n"
] | In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20. | 500 | [
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output": "4"
},
{
"input": "8 8 2 2 2",
"output": "6"
},
{
"input": "5 50 5 5 60",
"output": "110"
},
{
"input": "100 100 100 100 100",
"output": "200"
},
{
"input": "1 1 1 1 1",
"output": "2"
},
{
"input": "29 29 20 20 20",
"output": "58"
},
{
"input": "20 29 20 29 20",
"output": "58"
},
{
"input": "31 31 20 20 20",
"output": "60"
},
{
"input": "20 20 20 31 31",
"output": "60"
},
{
"input": "20 31 20 31 20",
"output": "60"
},
{
"input": "20 20 20 30 30",
"output": "60"
},
{
"input": "30 30 20 20 20",
"output": "60"
},
{
"input": "8 1 8 8 8",
"output": "9"
},
{
"input": "1 1 1 8 1",
"output": "9"
},
{
"input": "1 2 3 4 5",
"output": "15"
},
{
"input": "100 99 98 97 96",
"output": "490"
},
{
"input": "1 1 100 100 100",
"output": "2"
},
{
"input": "100 100 99 99 98",
"output": "296"
},
{
"input": "98 99 100 99 100",
"output": "296"
},
{
"input": "1 90 1 91 1",
"output": "181"
},
{
"input": "60 1 75 1 92",
"output": "227"
},
{
"input": "15 40 90 40 90",
"output": "95"
},
{
"input": "1 1 15 20 20",
"output": "17"
},
{
"input": "90 11 11 10 10",
"output": "110"
},
{
"input": "20 21 22 23 24",
"output": "110"
},
{
"input": "1 1 2 98 99",
"output": "199"
},
{
"input": "3 7 7 7 10",
"output": "13"
},
{
"input": "1 3 3 3 1",
"output": "2"
},
{
"input": "1 9 9 9 10",
"output": "11"
},
{
"input": "100 1 1 1 1",
"output": "101"
},
{
"input": "2 2 2 100 100",
"output": "6"
},
{
"input": "1 2 2 2 2",
"output": "3"
},
{
"input": "1 1 2 2 5",
"output": "7"
},
{
"input": "1 2 3 4 1",
"output": "9"
},
{
"input": "11 10 10 10 10",
"output": "21"
},
{
"input": "2 2 2 10 10",
"output": "6"
},
{
"input": "1 1 1 1 4",
"output": "5"
},
{
"input": "98 98 98 98 23",
"output": "121"
},
{
"input": "1 2 3 100 100",
"output": "6"
},
{
"input": "2 2 5 10 10",
"output": "9"
},
{
"input": "2 2 3 3 3",
"output": "4"
},
{
"input": "1 1 1 1 2",
"output": "3"
},
{
"input": "12 12 7 7 7",
"output": "21"
}
] | 1,583,400,380 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 155 | 0 | cards = list(map(int, input().split()))
cards.sort()
test=[]
for i in cards:
if cards.count(i)>1 and i not in test:
test.append(i)
compare=0
check=0
number=0
if test==[]:
print(sum(cards))
else:
for i in test:
compare= cards.count(i)*i
check=max(check, compare)
if check==compare:
number=i
x= cards.count(number)
x=min(x,3)
for j in range(int(x)):
cards.remove(number)
print(sum(cards)) | Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
Input Specification:
The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards.
Output Specification:
Print the minimum possible sum of numbers written on remaining cards.
Demo Input:
['7 3 7 3 20\n', '7 9 3 1 8\n', '10 10 10 10 10\n']
Demo Output:
['26\n', '28\n', '20\n']
Note:
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20. | ```python
cards = list(map(int, input().split()))
cards.sort()
test=[]
for i in cards:
if cards.count(i)>1 and i not in test:
test.append(i)
compare=0
check=0
number=0
if test==[]:
print(sum(cards))
else:
for i in test:
compare= cards.count(i)*i
check=max(check, compare)
if check==compare:
number=i
x= cards.count(number)
x=min(x,3)
for j in range(int(x)):
cards.remove(number)
print(sum(cards))
``` | 3 |
|
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details. | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them. | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
},
{
"input": "1\nXO|OX",
"output": "NO"
},
{
"input": "1\nOO|OO",
"output": "YES\n++|OO"
},
{
"input": "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO",
"output": "NO"
},
{
"input": "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX",
"output": "YES\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|++\nOX|OX\nOX|XO\nOX|OX"
},
{
"input": "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO|XO\nOX|XO\nXO|OX\nXX|XX\nXX|XX\nOX|OX\nXX|OX\nOX|XO\nOX|XO\nXO|OX\nXO|XX\nOX|XX\nOX|XX\nXO|OX\nXO|XX\nXO|XX\nOX|XX\nXX|XX\nXX|XO\nXO|XX\nXX|XX\nXO|OX\nXX|XO\nXO|XX\nXO|XO\nXO|OX\nXX|OX\nXO|OX\nOX|XX\nXX|OX\nXX|XX\nOX|XO\nOX|XX\nXO|OX\nOX|XX\nOX|XX\nXO|XO\nXO|XX\nOX|XX\nXO|XO\nOX|XX\nXX|XX\nOX|XO\nXO|XO\nXO|XO\nOX|OX\nXX|OX\nXX|OX\nOX|XO\nOX|XX\nOX|OX\nXO|XX\nOX|XX",
"output": "NO"
},
{
"input": "1\nOO|XX",
"output": "YES\n++|XX"
},
{
"input": "10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX",
"output": "YES\n++|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX"
},
{
"input": "10\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|OO",
"output": "YES\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|++"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nOO|OX\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\n++|OX\nOX|XO"
},
{
"input": "6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX",
"output": "YES\n++|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX"
}
] | 1,621,773,518 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 77 | 0 | t=int(input())
rows=[]
flag=0
for temp in range(t):
rows.append(input())
for i in range(len(rows)):
if 'OO' in rows[i]:
print("YES")
idx=rows[i].index('OO')
temp=rows[i][:idx]+'++'+rows[i][idx+2:]
rows[i]=temp
flag=1
break
if flag==1:
for i in rows:
print(i)
else:
print("NO") | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
Output Specification:
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
Demo Input:
['6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', '4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n', '5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n']
Demo Output:
['YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', 'NO\n', 'YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n']
Note:
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | ```python
t=int(input())
rows=[]
flag=0
for temp in range(t):
rows.append(input())
for i in range(len(rows)):
if 'OO' in rows[i]:
print("YES")
idx=rows[i].index('OO')
temp=rows[i][:idx]+'++'+rows[i][idx+2:]
rows[i]=temp
flag=1
break
if flag==1:
for i in rows:
print(i)
else:
print("NO")
``` | 3 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,628,655,988 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 154 | 6,963,200 | n = int(input(""))
l = []
for i in range(0,n):
o,m,p = str(input("")).split(" ")
o,m,p = int(o),int(m),int(p)
k = [o,m,p]
l.append(k)
x = 0
for i in range(0,len(l)):
x = 0
for j in range(0,3):
x += l[j][i]
if x != 0:
print("NO")
break
else:
print("YES")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input(""))
l = []
for i in range(0,n):
o,m,p = str(input("")).split(" ")
o,m,p = int(o),int(m),int(p)
k = [o,m,p]
l.append(k)
x = 0
for i in range(0,len(l)):
x = 0
for j in range(0,3):
x += l[j][i]
if x != 0:
print("NO")
break
else:
print("YES")
``` | 0 |
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question. | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5",
"output": "0"
},
{
"input": "555 777 1 1000000",
"output": "257"
},
{
"input": "1000 1000 1 32323",
"output": "32"
},
{
"input": "45 125 93451125 100000000",
"output": "5821"
},
{
"input": "101 171 1 1000000000",
"output": "57900"
},
{
"input": "165 255 69696 1000000000",
"output": "356482"
},
{
"input": "555 777 666013 1000000000",
"output": "257229"
},
{
"input": "23 46 123321 900000000",
"output": "19562537"
},
{
"input": "321 123 15 1000000",
"output": "75"
},
{
"input": "819 1000 9532 152901000",
"output": "186"
},
{
"input": "819 1000 10000 1000000",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 1000003",
"output": "500001"
},
{
"input": "1 1 1 1000000000",
"output": "1000000000"
},
{
"input": "10 15 69 195610342",
"output": "6520342"
},
{
"input": "2 1 1 1000000000",
"output": "500000000"
},
{
"input": "1000 1000 1 20",
"output": "0"
},
{
"input": "1 1 1 2000000000",
"output": "2000000000"
},
{
"input": "1 2 1 2000000000",
"output": "1000000000"
},
{
"input": "2 1 1 2000000000",
"output": "1000000000"
},
{
"input": "2 3 1 1000000000",
"output": "166666666"
},
{
"input": "2 3 1 2000000000",
"output": "333333333"
},
{
"input": "3 7 1 1000000000",
"output": "47619047"
},
{
"input": "1 1 1000000000 2000000000",
"output": "1000000001"
},
{
"input": "2 2 1 2000000000",
"output": "1000000000"
},
{
"input": "1 1 2 2000000000",
"output": "1999999999"
},
{
"input": "3 2 1 2000000000",
"output": "333333333"
},
{
"input": "1 1 2000000000 2000000000",
"output": "1"
},
{
"input": "2 3 7 7",
"output": "0"
},
{
"input": "3 3 3 7",
"output": "2"
}
] | 1,698,350,185 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | import math
x, y, a, b = map(int, input().split())
lcms = x * y // math.gcd(x, y)
num_multiple = (b // lcms) - ((a - 1) // lcms)
print(num_multiple)
| Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question.
Input Specification:
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*).
Output Specification:
Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
Demo Input:
['2 3 6 18\n']
Demo Output:
['3']
Note:
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | ```python
import math
x, y, a, b = map(int, input().split())
lcms = x * y // math.gcd(x, y)
num_multiple = (b // lcms) - ((a - 1) // lcms)
print(num_multiple)
``` | 3 |
|
412 | C | Pattern | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.
In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ???, ??a, a?a, aba.
Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given *n* patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns.
It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters. | In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them. | [
"2\n?ab\n??b\n",
"2\na\nb\n",
"1\n?a?b\n"
] | [
"xab\n",
"?\n",
"cacb\n"
] | Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aab, bab, cab, dab and so on. | 1,500 | [
{
"input": "2\n?ab\n??b",
"output": "xab"
},
{
"input": "2\na\nb",
"output": "?"
},
{
"input": "1\n?a?b",
"output": "cacb"
},
{
"input": "1\n?",
"output": "x"
},
{
"input": "3\nabacaba\nabacaba\nabacaba",
"output": "abacaba"
},
{
"input": "3\nabc?t\n?bc?z\nab??t",
"output": "abcx?"
},
{
"input": "4\nabc\ndef\n???\nxyz",
"output": "???"
},
{
"input": "2\n?????\n?????",
"output": "xxxxx"
},
{
"input": "2\na\na",
"output": "a"
},
{
"input": "3\nabc\n???\naxc",
"output": "a?c"
},
{
"input": "1\n?m??x?xxexxx?xxmxx??",
"output": "cmccxcxxexxxcxxmxxcc"
},
{
"input": "2\nhszhh?zszs\nhhzhz?zzhs",
"output": "h?zh?cz??s"
},
{
"input": "3\neddzde\needded\nzdde?z",
"output": "??d???"
},
{
"input": "4\nff?o?\nfk?of\nk?kof\nfk?oo",
"output": "??ko?"
},
{
"input": "5\nyigi\ne?gi\niig?\n?eg?\n??gi",
"output": "??gi"
},
{
"input": "100\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz",
"output": "z"
},
{
"input": "100\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?",
"output": "bc"
},
{
"input": "1\nq",
"output": "q"
},
{
"input": "2\n?\n?",
"output": "x"
},
{
"input": "2\n?\na",
"output": "a"
},
{
"input": "2\n?\nb",
"output": "b"
},
{
"input": "3\n?\na\na",
"output": "a"
},
{
"input": "3\na\n?\na",
"output": "a"
},
{
"input": "3\na\nb\n?",
"output": "?"
},
{
"input": "3\n?\na\nb",
"output": "?"
},
{
"input": "3\nb\n?\na",
"output": "?"
},
{
"input": "2\n???\naaa",
"output": "aaa"
},
{
"input": "2\n??\nss",
"output": "ss"
}
] | 1,398,852,335 | 4,835 | Python 3 | OK | TESTS | 70 | 421 | 6,758,400 | n = int(input())
S = [0] * n
A = ''
for i in range(n):
S[i] = list(input())
for j in range(len(S[0])):
set0 = set()
for i in range(n):
set0.add(S[i][j])
set0 = ''.join(map(str, list(set0)))
if set0 == '?':
A += 'x'
elif len(set0) == 1:
A += set0
elif len(set0) == 2:
if set0[0] != '?' and set0[1] != '?':
A += '?'
elif set0[0] != '?':
A += set0[0]
else:
A += set0[1]
else:
A += '?'
print(A) | Title: Pattern
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.
In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ???, ??a, a?a, aba.
Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given *n* patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns.
It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters.
Output Specification:
In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them.
Demo Input:
['2\n?ab\n??b\n', '2\na\nb\n', '1\n?a?b\n']
Demo Output:
['xab\n', '?\n', 'cacb\n']
Note:
Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aab, bab, cab, dab and so on. | ```python
n = int(input())
S = [0] * n
A = ''
for i in range(n):
S[i] = list(input())
for j in range(len(S[0])):
set0 = set()
for i in range(n):
set0.add(S[i][j])
set0 = ''.join(map(str, list(set0)))
if set0 == '?':
A += 'x'
elif len(set0) == 1:
A += set0
elif len(set0) == 2:
if set0[0] != '?' and set0[1] != '?':
A += '?'
elif set0[0] != '?':
A += set0[0]
else:
A += set0[1]
else:
A += '?'
print(A)
``` | 3 |
Subsets and Splits