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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them. | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "9",
"output": "ROYGBIVGB"
},
{
"input": "11",
"output": "ROYGBIVYGBI"
},
{
"input": "12",
"output": "ROYGBIVOYGBI"
},
{
"input": "15",
"output": "ROYGBIVROYGBIVG"
},
{
"input": "16",
"output": "ROYGBIVROYGBIVGB"
},
{
"input": "17",
"output": "ROYGBIVROYGBIVYGB"
},
{
"input": "18",
"output": "ROYGBIVROYGBIVYGBI"
},
{
"input": "19",
"output": "ROYGBIVROYGBIVOYGBI"
},
{
"input": "20",
"output": "ROYGBIVROYGBIVOYGBIV"
},
{
"input": "21",
"output": "ROYGBIVROYGBIVROYGBIV"
},
{
"input": "22",
"output": "ROYGBIVROYGBIVROYGBIVG"
},
{
"input": "23",
"output": "ROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "24",
"output": "ROYGBIVROYGBIVROYGBIVYGB"
},
{
"input": "25",
"output": "ROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "28",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "29",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "34",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "43",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "61",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "79",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "81",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "92",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "95",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "96",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "97",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "98",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "99",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "100",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
}
] | 1,595,544,343 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 156 | 6,656,000 | a=int(input())
b='VIBGYOR'
c='VIBG'
d=0
for i in range(a):
if(i<7):
print(b[i%7],end='')
else:
print(c[d%4],end='')
d+=1 | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input Specification:
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Output Specification:
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Demo Input:
['8\n', '13\n']
Demo Output:
['ROYGRBIV\n', 'ROYGBIVGBIVYG\n']
Note:
The way the eggs will be painted in the first sample is shown on the picture: | ```python
a=int(input())
b='VIBGYOR'
c='VIBG'
d=0
for i in range(a):
if(i<7):
print(b[i%7],end='')
else:
print(c[d%4],end='')
d+=1
``` | 0 |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162",
"output": "2 23"
},
{
"input": "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 234 4 231 150 110 22 823 193",
"output": "2 43"
},
{
"input": "63\n93 180 116 7 8 179 268 279 136 94 221 153 264 190 278 19 19 63 153 26 158 225 25 49 89 218 111 149 255 225 197 122 243 80 3 224 107 178 202 17 53 92 69 42 228 24 81 205 95 8 265 82 228 156 127 241 172 159 106 60 67 155 111",
"output": "2 57"
},
{
"input": "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 134 403 972 940 371 6 642",
"output": "2 80"
},
{
"input": "105\n246 57 12 204 165 123 246 68 191 310 3 152 386 333 374 257 158 104 333 50 80 290 8 340 101 76 221 316 388 289 138 359 316 26 93 290 105 178 81 195 41 196 218 180 244 292 187 97 315 323 174 119 248 239 92 312 31 2 101 180 307 170 338 314 163 281 217 31 142 238 280 190 190 156 70 74 329 113 151 8 141 313 366 40 253 116 168 124 135 230 294 266 353 389 371 359 195 200 183 237 93 102 315 118 188",
"output": "2 92"
},
{
"input": "123\n112 277 170 247 252 115 157 293 256 143 196 90 12 164 164 42 8 223 167 109 175 232 239 111 148 51 9 254 93 32 268 162 231 91 47 162 161 191 195 145 247 292 129 199 230 94 144 217 18 205 176 20 143 198 121 243 211 262 230 277 195 255 108 290 220 275 158 2 286 200 60 267 278 207 123 150 123 116 131 13 12 226 33 244 30 275 263 45 158 192 254 149 242 176 62 224 221 288 250 160 155 225 132 143 276 293 218 145 197 175 33 129 79 206 210 192 222 262 190 52 274 243 233",
"output": "3 101"
},
{
"input": "5\n5 5 5 5 5",
"output": "5 1"
},
{
"input": "3\n1000 1000 1000",
"output": "3 1"
},
{
"input": "1\n1000",
"output": "1 1"
},
{
"input": "1\n1",
"output": "1 1"
},
{
"input": "5\n1 1000 1000 1000 1000",
"output": "4 2"
},
{
"input": "5\n1000 1000 1000 8 7",
"output": "3 3"
}
] | 1,592,988,274 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 218 | 6,963,200 | n=int(input())
x=list(map(int, input().split()))
y=set(x)
maxx=[]
for i in y:
maxx.append(x.count(i))
print(max(maxx), len(y)) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
Input Specification:
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
Output Specification:
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
Demo Input:
['3\n1 2 3\n', '4\n6 5 6 7\n']
Demo Output:
['1 3\n', '2 3\n']
Note:
none | ```python
n=int(input())
x=list(map(int, input().split()))
y=set(x)
maxx=[]
for i in y:
maxx.append(x.count(i))
print(max(maxx), len(y))
``` | 3.93253 |
259 | A | Little Elephant and Chess | PROGRAMMING | 1,000 | [
"brute force",
"strings"
] | null | null | The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard. | The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns — from 1 to 8 from left to right. The given board can initially be a proper chessboard. | In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. | [
"WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n",
"WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | 500 | [
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB",
"output": "YES"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nBWWWBWBW",
"output": "NO"
},
{
"input": "BBBBBWWW\nWBBWBWWB\nWWWWWBWW\nBWBWWBWW\nBBBWWBWW\nBBBBBWBW\nWBBBWBWB\nWBWBWWWB",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nBWWWWWBB\nBBWBWBWB\nWBWBWBWB\nWWBWWBWW\nBWBWBWBW\nWBWWBBBB",
"output": "NO"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWWBWBB",
"output": "NO"
},
{
"input": "WBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW",
"output": "YES"
},
{
"input": "WWWWBWWB\nBWBWBWBW\nBWBWBWBW\nWWBWBBBB\nBBWWBBBB\nBBBWWBBW\nBWWWWWWB\nBWWBBBWW",
"output": "NO"
},
{
"input": "WBBWWBWB\nBBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBBW\nWBWBBBBW\nBWWWWBWB\nBBBBBBBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nBBWWWBBB\nWBBBBBWW\nWBBBBWBB\nWBWBWBWB\nWBWWBWWB\nWBBWBBWW",
"output": "NO"
},
{
"input": "WBBBBBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBBBBBWBB\nWBBWWBWB\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBBWWBWB",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWWWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBBW",
"output": "NO"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "WWBBWWBB\nBWWBBWWB\nBWBWBWBW\nWWBBWWWB\nWBWWWWBB\nWBWWBBWB\nBWBBWBWW\nBWBWWWWW",
"output": "NO"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nWWBBWBBB\nWBWBWBWB\nWWWWBWWB\nWBBBBWWW\nBWBWWWBW\nWWWBWBBB",
"output": "NO"
},
{
"input": "WBWBWBWB\nBWWBWWWW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWWBBBBBW\nWWWBWWBW\nWWBBBBWW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBBBWWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "NO"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "NO"
},
{
"input": "BWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB",
"output": "NO"
},
{
"input": "WWBWWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "NO"
},
{
"input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nBBBBBBBB\nWWWWWWWW\nBBBBBBBB\nWWWWWWWW\nBBBBBBBB",
"output": "NO"
},
{
"input": "BBBBBBBB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "NO"
},
{
"input": "BBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW",
"output": "NO"
},
{
"input": "BBBWWWWW\nWWWBBBBB\nBBBWWWWW\nWWWBBBBB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "NO"
}
] | 1,593,849,132 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 280 | 0 | c=0
a,b=0,0
for _ in range(8):
s=input()
for x in range(8):
if s[x]=='W':
a+=1
else:
b+=1
ch=''
if (_+x)&1:
ch='B'
else:
ch='W'
if s[x]!=ch:
c+=1
# print(a,b,c)
dp=[0]*100
dp[0]=1
for i in range(1,65):
if i-8>=0:
if dp[i-8]==1:
dp[i]=1
if i-6>=0:
if dp[i-6]==1:
dp[i]=1
if a==b and dp[c]:
print("YES")
else:
print("NO")
| Title: Little Elephant and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input Specification:
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns — from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output Specification:
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Demo Input:
['WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n', 'WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | ```python
c=0
a,b=0,0
for _ in range(8):
s=input()
for x in range(8):
if s[x]=='W':
a+=1
else:
b+=1
ch=''
if (_+x)&1:
ch='B'
else:
ch='W'
if s[x]!=ch:
c+=1
# print(a,b,c)
dp=[0]*100
dp[0]=1
for i in range(1,65):
if i-8>=0:
if dp[i-8]==1:
dp[i]=1
if i-6>=0:
if dp[i-6]==1:
dp[i]=1
if a==b and dp[c]:
print("YES")
else:
print("NO")
``` | 0 |
|
347 | B | Fixed Points | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points.
You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34 73 29 70 83 58 79 82 28 77 67",
"output": "3"
},
{
"input": "3\n0 1 2",
"output": "3"
},
{
"input": "3\n2 1 0",
"output": "3"
},
{
"input": "3\n1 2 0",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 1 2 3 4",
"output": "5"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "7\n0 1 2 4 3 6 5",
"output": "5"
},
{
"input": "6\n0 1 2 3 5 4",
"output": "6"
}
] | 1,600,005,802 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 7,065,600 | _ = input()
inp = list(map(int, input().split(' ')))
def countpoints(l: list) -> int:
count = 0
for i, e in enumerate(l):
if i == e:
count += 1
return count
_m = countpoints(inp)
m = 0
for i, e in enumerate(inp):
if i == e:
continue
if inp.index(i) == e and inp[e] == i:
m = max(m, _m + 2)
else:
m = max(m, _m + 1)
print(m)
| Title: Fixed Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points.
You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation.
Output Specification:
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
Demo Input:
['5\n0 1 3 4 2\n']
Demo Output:
['3\n']
Note:
none | ```python
_ = input()
inp = list(map(int, input().split(' ')))
def countpoints(l: list) -> int:
count = 0
for i, e in enumerate(l):
if i == e:
count += 1
return count
_m = countpoints(inp)
m = 0
for i, e in enumerate(inp):
if i == e:
continue
if inp.index(i) == e and inp[e] == i:
m = max(m, _m + 2)
else:
m = max(m, _m + 1)
print(m)
``` | 0 |
|
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details. | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them. | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
},
{
"input": "1\nXO|OX",
"output": "NO"
},
{
"input": "1\nOO|OO",
"output": "YES\n++|OO"
},
{
"input": "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO",
"output": "NO"
},
{
"input": "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX",
"output": "YES\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|++\nOX|OX\nOX|XO\nOX|OX"
},
{
"input": "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO|XO\nOX|XO\nXO|OX\nXX|XX\nXX|XX\nOX|OX\nXX|OX\nOX|XO\nOX|XO\nXO|OX\nXO|XX\nOX|XX\nOX|XX\nXO|OX\nXO|XX\nXO|XX\nOX|XX\nXX|XX\nXX|XO\nXO|XX\nXX|XX\nXO|OX\nXX|XO\nXO|XX\nXO|XO\nXO|OX\nXX|OX\nXO|OX\nOX|XX\nXX|OX\nXX|XX\nOX|XO\nOX|XX\nXO|OX\nOX|XX\nOX|XX\nXO|XO\nXO|XX\nOX|XX\nXO|XO\nOX|XX\nXX|XX\nOX|XO\nXO|XO\nXO|XO\nOX|OX\nXX|OX\nXX|OX\nOX|XO\nOX|XX\nOX|OX\nXO|XX\nOX|XX",
"output": "NO"
},
{
"input": "1\nOO|XX",
"output": "YES\n++|XX"
},
{
"input": "10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX",
"output": "YES\n++|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX"
},
{
"input": "10\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|OO",
"output": "YES\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|++"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nOO|OX\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\n++|OX\nOX|XO"
},
{
"input": "6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX",
"output": "YES\n++|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX"
}
] | 1,667,372,699 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | c=0
l=[]
for _ in range(int(input())):
x=input()
if c==0:
if 'OO' in x:
c=1
x=x.replace('OO','++')
l.append(x)
if c==0: print('NO')
else:
print('YES')
for i in l:
print(i) | 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
c=0
l=[]
for _ in range(int(input())):
x=input()
if c==0:
if 'OO' in x:
c=1
x=x.replace('OO','++')
l.append(x)
if c==0: print('NO')
else:
print('YES')
for i in l:
print(i)
``` | 0 |
|
628 | C | Bear and String Distance | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .
Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, , and .
Limak gives you a nice string *s* and an integer *k*. He challenges you to find any nice string *s*' that . Find any *s*' satisfying the given conditions, or print "-1" if it's impossible to do so.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=106).
The second line contains a string *s* of length *n*, consisting of lowercase English letters. | If there is no string satisfying the given conditions then print "-1" (without the quotes).
Otherwise, print any nice string *s*' that . | [
"4 26\nbear\n",
"2 7\naf\n",
"3 1000\nhey\n"
] | [
"roar",
"db\n",
"-1\n"
] | none | 0 | [
{
"input": "4 26\nbear",
"output": "zcar"
},
{
"input": "2 7\naf",
"output": "hf"
},
{
"input": "3 1000\nhey",
"output": "-1"
},
{
"input": "5 50\nkzsij",
"output": "zaiij"
},
{
"input": "5 500\nvsdxg",
"output": "-1"
},
{
"input": "1 0\na",
"output": "a"
},
{
"input": "1 1\ng",
"output": "f"
},
{
"input": "1 25\nr",
"output": "-1"
},
{
"input": "1 15\no",
"output": "-1"
},
{
"input": "10 100\naddaiyssyp",
"output": "zzzzcyssyp"
},
{
"input": "50 100\ntewducenaqgpilgftjcmzttrgebnyldwfgbtttrygaiqtkgbjb",
"output": "azazecenaqgpilgftjcmzttrgebnyldwfgbtttrygaiqtkgbjb"
},
{
"input": "2 1\nzz",
"output": "yz"
},
{
"input": "8 8\nabcdefgh",
"output": "ibcdefgh"
},
{
"input": "1 25\nz",
"output": "a"
},
{
"input": "1 24\nz",
"output": "b"
},
{
"input": "1 24\ny",
"output": "a"
},
{
"input": "2 49\nzz",
"output": "ab"
},
{
"input": "1 26\na",
"output": "-1"
},
{
"input": "1 25\na",
"output": "z"
},
{
"input": "4 17\nrzsq",
"output": "azsq"
},
{
"input": "69 1701\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaax"
},
{
"input": "2 9\nbc",
"output": "kc"
},
{
"input": "2 48\nab",
"output": "zy"
},
{
"input": "1 8\nc",
"output": "k"
},
{
"input": "2 25\nyd",
"output": "ac"
},
{
"input": "5 24\nizrqp",
"output": "zsrqp"
},
{
"input": "1 13\nn",
"output": "a"
},
{
"input": "5 21\nfmmqh",
"output": "zlmqh"
}
] | 1,590,471,882 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 218 | 716,800 | n, k = map(int, input().split())
s = input()
ans = ''
for j in range(n):
a = ord(s[j]) - 97
z = 25 - a
if a > z:
v = min(a, k)
ans += chr(ord(s[j]) - v)
k -= v
else:
v = min(z, k)
ans += chr(ord(s[j]) + v)
k -= v
print(ans if k == 0 else -1) | Title: Bear and String Distance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .
Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, , and .
Limak gives you a nice string *s* and an integer *k*. He challenges you to find any nice string *s*' that . Find any *s*' satisfying the given conditions, or print "-1" if it's impossible to do so.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=106).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Output Specification:
If there is no string satisfying the given conditions then print "-1" (without the quotes).
Otherwise, print any nice string *s*' that .
Demo Input:
['4 26\nbear\n', '2 7\naf\n', '3 1000\nhey\n']
Demo Output:
['roar', 'db\n', '-1\n']
Note:
none | ```python
n, k = map(int, input().split())
s = input()
ans = ''
for j in range(n):
a = ord(s[j]) - 97
z = 25 - a
if a > z:
v = min(a, k)
ans += chr(ord(s[j]) - v)
k -= v
else:
v = min(z, k)
ans += chr(ord(s[j]) + v)
k -= v
print(ans if k == 0 else -1)
``` | 3 |
|
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*. | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "100000",
"output": "50000\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "7",
"output": "3\n2 2 3"
},
{
"input": "4",
"output": "2\n2 2"
},
{
"input": "8",
"output": "4\n2 2 2 2"
},
{
"input": "9",
"output": "4\n2 2 2 3"
},
{
"input": "99995",
"output": "49997\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99996",
"output": "49998\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "10",
"output": "5\n2 2 2 2 2"
},
{
"input": "11",
"output": "5\n2 2 2 2 3"
},
{
"input": "99997",
"output": "49998\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99998",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "12",
"output": "6\n2 2 2 2 2 2"
},
{
"input": "13",
"output": "6\n2 2 2 2 2 3"
},
{
"input": "99993",
"output": "49996\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99994",
"output": "49997\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "14",
"output": "7\n2 2 2 2 2 2 2"
},
{
"input": "15",
"output": "7\n2 2 2 2 2 2 3"
},
{
"input": "53",
"output": "26\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 3"
},
{
"input": "57",
"output": "28\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 3"
},
{
"input": "61",
"output": "30\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 3"
},
{
"input": "774",
"output": "387\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "202",
"output": "101\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2"
},
{
"input": "530",
"output": "265\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "7166",
"output": "3583\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "9294",
"output": "4647\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "2422",
"output": "1211\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "15326",
"output": "7663\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "11454",
"output": "5727\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "14878",
"output": "7439\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "90672",
"output": "45336\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99544",
"output": "49772\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "90472",
"output": "45236\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "23",
"output": "11\n2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "93",
"output": "46\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "19",
"output": "9\n2 2 2 2 2 2 2 2 3"
},
{
"input": "11110",
"output": "5555\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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,636,186,885 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 109 | 22,835,200 | n = int(input())
if(n%2==0):
ans=n//2
arr=[2]*ans
else:
n=n-3
ans=1
ans = ans +n//2
arr=[2]*(ans-1) + [3]
print(ans)
print(*arr) | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*.
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
Output Specification:
The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
Demo Input:
['5\n', '6\n']
Demo Output:
['2\n2 3\n', '3\n2 2 2\n']
Note:
none | ```python
n = int(input())
if(n%2==0):
ans=n//2
arr=[2]*ans
else:
n=n-3
ans=1
ans = ans +n//2
arr=[2]*(ans-1) + [3]
print(ans)
print(*arr)
``` | 3 |
|
560 | A | Currency System in Geraldion | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum? | The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. | Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. | [
"5\n1 2 3 4 5\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837",
"output": "-1"
},
{
"input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264",
"output": "1"
},
{
"input": "50\n110876 835020 859879 999908 712969 788264 287153 921820 330355 499311 209594 484829 296329 940051 174081 931503 1 780512 390075 97866 124255 950067 697612 244256 782385 789882 37608 82153 399889 598867 416717 377988 535636 511221 792568 683271 131077 290194 496712 330720 587436 563481 645817 942562 654093 980561 382937 48293 582608 116156",
"output": "-1"
},
{
"input": "50\n474421 421097 217233 156339 27075 733996 281778 863492 184707 956857 288561 70997 393786 337382 663642 131184 637 273801 799870 295017 392338 842567 161819 297705 102013 930684 375703 838048 154915 138503 629056 256591 893619 19263 787927 684541 320265 841090 421423 490879 394582 493952 619247 633202 612928 50907 276653 407819 489945 153173",
"output": "1"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "1\n1000000",
"output": "1"
},
{
"input": "2\n3 2",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
}
] | 1,687,400,060 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 46 | 0 | n, a = int(input()), (int(i) for i in input().split())
res = -1 if 1 in a else 1
print(res)
| Title: Currency System in Geraldion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum?
Input Specification:
The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes.
Output Specification:
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1.
Demo Input:
['5\n1 2 3 4 5\n']
Demo Output:
['-1\n']
Note:
none | ```python
n, a = int(input()), (int(i) for i in input().split())
res = -1 if 1 in a else 1
print(res)
``` | 3 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,693,068,600 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n = int(input())
for i in range(n):
word = input().strip()
length=len(word)
if length>10:
abbr = word[0]+str(length-2)+word[-1]
print(abbr)
else:
print(word) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
n = int(input())
for i in range(n):
word = input().strip()
length=len(word)
if length>10:
abbr = word[0]+str(length-2)+word[-1]
print(abbr)
else:
print(word)
``` | 3.977 |
451 | B | Sort the Array | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | [
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] | [
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become:
*a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*]. | 1,000 | [
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 27 4 2",
"output": "yes\n1 5"
},
{
"input": "9\n6 78 63 59 28 24 8 96 99",
"output": "yes\n2 7"
},
{
"input": "6\n19517752 43452931 112792556 68417469 779722934 921694415",
"output": "yes\n3 4"
},
{
"input": "6\n169793171 335736854 449917902 513287332 811627074 938727967",
"output": "yes\n1 1"
},
{
"input": "6\n509329 173849943 297546987 591032670 796346199 914588283",
"output": "yes\n1 1"
},
{
"input": "25\n46 45 37 35 26 25 21 19 11 3 1 51 54 55 57 58 59 62 66 67 76 85 88 96 100",
"output": "yes\n1 11"
},
{
"input": "46\n10 12 17 19 20 21 22 24 25 26 27 28 29 30 32 37 42 43 47 48 50 51 52 56 87 86 81 79 74 71 69 67 66 65 60 59 57 89 91 92 94 96 97 98 99 100",
"output": "yes\n25 37"
},
{
"input": "96\n1 2 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 68 69 70 71 72 73 74 75 76 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "yes\n3 22"
},
{
"input": "2\n404928771 698395106",
"output": "yes\n1 1"
},
{
"input": "2\n699573624 308238132",
"output": "yes\n1 2"
},
{
"input": "5\n75531609 242194958 437796493 433259361 942142185",
"output": "yes\n3 4"
},
{
"input": "5\n226959376 840957605 833410429 273566427 872976052",
"output": "yes\n2 4"
},
{
"input": "5\n373362086 994096202 767275079 734424844 515504383",
"output": "yes\n2 5"
},
{
"input": "5\n866379155 593548704 259097686 216134784 879911740",
"output": "yes\n1 4"
},
{
"input": "5\n738083041 719956102 420866851 307749161 257917459",
"output": "yes\n1 5"
},
{
"input": "5\n90786760 107075352 139104198 424911569 858427981",
"output": "yes\n1 1"
},
{
"input": "6\n41533825 525419745 636375901 636653266 879043107 967434399",
"output": "yes\n1 1"
},
{
"input": "40\n22993199 75843013 76710455 99749069 105296587 122559115 125881005 153961749 163646706 175409222 185819807 214465092 264449243 278246513 295514446 322935239 370349154 375773209 390474983 775646826 767329655 740310077 718820037 708508595 693119912 680958422 669537382 629123011 607511013 546574974 546572137 511951383 506996390 493995578 458256840 815612821 881161983 901337648 962275390 986568907",
"output": "yes\n20 35"
},
{
"input": "40\n3284161 23121669 24630274 33434127 178753820 231503277 271972002 272578266 346450638 355655265 372217434 376132047 386622863 387235708 389799554 427160037 466577363 491873718 492746058 502535866 535768673 551570285 557477055 583643014 586216753 588981593 592960633 605923775 611051145 643142759 632768011 634888864 736715552 750574599 867737742 924365786 927179496 934453020 954090860 977765165",
"output": "no"
},
{
"input": "40\n42131757 49645896 49957344 78716964 120937785 129116222 172128600 211446903 247833196 779340466 717548386 709969818 696716905 636153997 635635467 614115746 609201167 533608141 521874836 273044950 291514539 394083281 399369419 448830087 485128983 487192341 488673105 497678164 501864738 265305156 799595875 831638598 835155840 845617770 847736630 851436542 879757553 885618675 964068808 969215471",
"output": "no"
},
{
"input": "40\n25722567 28250400 47661056 108729970 119887370 142272261 145287693 178946020 182917658 187405805 209478929 278713296 312035195 393514697 403876943 410188367 413061616 420619615 477231590 511200584 560288373 571690007 603093961 615463729 631624043 723138759 726089658 728151980 756393077 785590533 809755752 823601179 828357990 866942019 869575503 877310377 881382070 901314141 929048602 947139655",
"output": "yes\n1 1"
},
{
"input": "40\n17927221 33153935 60257083 110553879 114654567 119809916 163899753 167741765 182812464 188486743 220036903 220127072 227545828 229552200 244963635 248298934 299478582 354141058 371400641 430054473 452548736 458695269 466968129 469000714 478004472 478693873 509342093 750631027 609759323 669427158 688490225 690701652 696893030 704668825 749028408 557906039 545356441 926901326 955586118 972642992",
"output": "no"
},
{
"input": "4\n1 4 2 3",
"output": "no"
},
{
"input": "6\n1 2 5 4 3 6",
"output": "yes\n3 5"
},
{
"input": "1\n1",
"output": "yes\n1 1"
},
{
"input": "6\n1 5 3 4 2 6",
"output": "no"
},
{
"input": "4\n3 4 1 2",
"output": "no"
},
{
"input": "5\n2 5 4 3 1",
"output": "no"
},
{
"input": "4\n2 1 4 3",
"output": "no"
},
{
"input": "6\n2 1 4 3 5 6",
"output": "no"
}
] | 1,692,947,915 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a = int(input())
b = list(map(int , input().split()))
c = [0 for i in range(a)]
check = 0
for i in range(a):
if b[i] != i + 1 and (b[i] - i) % 2 == 1 and check == 0:
check = b[i]
index = i + 1
for j in range((check - 1 - i) // 2):
temp = b[i + j]
b[i + j] = b[check - j - 1]
b[check - j - 1] = temp
elif b[i] != i + 1 and (b[i] - i) % 2 == 0 and check == 0:
check = b[i]
index = i + 1
for j in range((check - i) // 2):
temp = b[i + j]
b[i + j] = b[check - j - 1]
b[check - j - 1] = temp
for i in range(a):
if b[i] != i + 1:
print("NO")
break
else:
print("YES")
if check == 0:
print("1 1")
else:
print(index , check) | Title: Sort the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109).
Output Specification:
Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.
Demo Input:
['3\n3 2 1\n', '4\n2 1 3 4\n', '4\n3 1 2 4\n', '2\n1 2\n']
Demo Output:
['yes\n1 3\n', 'yes\n1 2\n', 'no\n', 'yes\n1 1\n']
Note:
Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become:
*a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*]. | ```python
a = int(input())
b = list(map(int , input().split()))
c = [0 for i in range(a)]
check = 0
for i in range(a):
if b[i] != i + 1 and (b[i] - i) % 2 == 1 and check == 0:
check = b[i]
index = i + 1
for j in range((check - 1 - i) // 2):
temp = b[i + j]
b[i + j] = b[check - j - 1]
b[check - j - 1] = temp
elif b[i] != i + 1 and (b[i] - i) % 2 == 0 and check == 0:
check = b[i]
index = i + 1
for j in range((check - i) // 2):
temp = b[i + j]
b[i + j] = b[check - j - 1]
b[check - j - 1] = temp
for i in range(a):
if b[i] != i + 1:
print("NO")
break
else:
print("YES")
if check == 0:
print("1 1")
else:
print(index , check)
``` | 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,893,535 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 280 | 4,710,400 | n,k = map(int, input().split())
print("YES" if max([len(s) for s in input().split('.')])<k else "NO") | 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("YES" if max([len(s) for s in input().split('.')])<k else "NO")
``` | 3 |
|
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"input": "24 22 9235",
"output": "34"
},
{
"input": "74 8 417",
"output": "1"
},
{
"input": "972 1 203",
"output": "0"
},
{
"input": "550 1 754",
"output": "1"
},
{
"input": "860 1 884",
"output": "1"
},
{
"input": "358 2 809",
"output": "2"
},
{
"input": "33 27 216",
"output": "0"
},
{
"input": "2940 1 9311",
"output": "3"
},
{
"input": "4624 1 1953",
"output": "0"
},
{
"input": "2696 2 7345",
"output": "2"
},
{
"input": "3443 2 6701",
"output": "0"
},
{
"input": "3 613 2275",
"output": "1"
},
{
"input": "1 10000 10000",
"output": "1"
},
{
"input": "10000 1 10000",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1 10000",
"output": "10000"
},
{
"input": "34 27 10000",
"output": "10"
},
{
"input": "2 2 9999",
"output": "4999"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "6 4 36",
"output": "3"
},
{
"input": "33 6 3005",
"output": "45"
},
{
"input": "5 1 20",
"output": "4"
},
{
"input": "1 2 10",
"output": "5"
},
{
"input": "2 1 100",
"output": "50"
},
{
"input": "10 20 10000",
"output": "500"
},
{
"input": "8 12 12",
"output": "0"
}
] | 1,624,787,305 | 85 | Python 3 | RUNTIME_ERROR | TESTS | 13 | 62 | 409,600 | def gcd(a,b):
if (a == 0):
return b
if (b == 0):
return a
if (a == b):
return a
if (a > b):
return gcd(a-b, b)
return gcd(a, b-a)
n,m,z=map(int,input().split())
if n>m:
g=gcd(n,m)
else:
g=gcd(m,n)
lcm=n*m//g
print(z//lcm) | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
Input Specification:
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Output Specification:
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
Demo Input:
['1 1 10\n', '1 2 5\n', '2 3 9\n']
Demo Output:
['10\n', '2\n', '1\n']
Note:
Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | ```python
def gcd(a,b):
if (a == 0):
return b
if (b == 0):
return a
if (a == b):
return a
if (a > b):
return gcd(a-b, b)
return gcd(a, b-a)
n,m,z=map(int,input().split())
if n>m:
g=gcd(n,m)
else:
g=gcd(m,n)
lcm=n*m//g
print(z//lcm)
``` | -1 |
|
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 1,691,949,443 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 11 | 61 | 409,600 | n = int(input())
num = int(input())
arr = []
temp = num
i=0
while temp!=0:
arr.append(temp%10)
temp=int(temp/10)
i=i+1
while i<=(n-1):
i=i+1
arr.append(0)
arr=list(reversed(arr))
i=1
while i<n:
if arr[i]+arr[i-1]==1:
tempnum=i
arr.pop(tempnum)
arr.pop(tempnum-1)
n=n-2
i=1
else:
i=i+1
print(len(arr)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n = int(input())
num = int(input())
arr = []
temp = num
i=0
while temp!=0:
arr.append(temp%10)
temp=int(temp/10)
i=i+1
while i<=(n-1):
i=i+1
arr.append(0)
arr=list(reversed(arr))
i=1
while i<n:
if arr[i]+arr[i-1]==1:
tempnum=i
arr.pop(tempnum)
arr.pop(tempnum-1)
n=n-2
i=1
else:
i=i+1
print(len(arr))
``` | -1 |
|
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4",
"output": "9 2"
},
{
"input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8",
"output": "31 68"
},
{
"input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1",
"output": "15 15"
},
{
"input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2",
"output": "27 13"
},
{
"input": "4\n1 3 2 4\n4\n3 1 2 3",
"output": "8 12"
},
{
"input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2",
"output": "15 17"
}
] | 1,650,885,668 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 9,318,400 | n = int(input())
list = [int(i) for i in input().split()]
amount = int(input())
search_list = [int(i) for i in input().split()]
Vasya, Petya = 0,0
for elements in search_list:
Vasya += list.index(elements) + 1
Petya += len(list) - list.index(elements)
print(Vasya, Petya) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Output Specification:
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Demo Input:
['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n']
Demo Output:
['1 2\n', '2 1\n', '6 6\n']
Note:
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | ```python
n = int(input())
list = [int(i) for i in input().split()]
amount = int(input())
search_list = [int(i) for i in input().split()]
Vasya, Petya = 0,0
for elements in search_list:
Vasya += list.index(elements) + 1
Petya += len(list) - list.index(elements)
print(Vasya, Petya)
``` | 0 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,693,968,094 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 186 | 0 | s=input()
g=input()
r=s[::-1]
if(g==r):
print('YES')
else:
print('NO')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
s=input()
g=input()
r=s[::-1]
if(g==r):
print('YES')
else:
print('NO')
``` | 3.9535 |
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1. | The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input": "18 8",
"output": "888888888888888888"
},
{
"input": "1 5",
"output": "5"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "100 5",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "10 2",
"output": "2222222222"
},
{
"input": "18 10",
"output": "111111111111111110"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "7 6",
"output": "6666666"
},
{
"input": "4 4",
"output": "4444"
},
{
"input": "14 7",
"output": "77777777777777"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "2 8",
"output": "88"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 9",
"output": "99999"
},
{
"input": "4 8",
"output": "8888"
},
{
"input": "3 4",
"output": "444"
},
{
"input": "9 4",
"output": "444444444"
},
{
"input": "8 10",
"output": "11111110"
},
{
"input": "1 6",
"output": "6"
},
{
"input": "20 3",
"output": "33333333333333333333"
},
{
"input": "15 10",
"output": "111111111111110"
},
{
"input": "31 4",
"output": "4444444444444444444444444444444"
},
{
"input": "18 9",
"output": "999999999999999999"
},
{
"input": "72 4",
"output": "444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "76 8",
"output": "8888888888888888888888888888888888888888888888888888888888888888888888888888"
},
{
"input": "12 5",
"output": "555555555555"
},
{
"input": "54 5",
"output": "555555555555555555555555555555555555555555555555555555"
},
{
"input": "96 10",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "15 9",
"output": "999999999999999"
},
{
"input": "100 2",
"output": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
},
{
"input": "99 3",
"output": "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"
},
{
"input": "98 4",
"output": "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "97 5",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "100 6",
"output": "6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
},
{
"input": "99 7",
"output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "98 8",
"output": "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
},
{
"input": "97 9",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "100 10",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "3 10",
"output": "110"
},
{
"input": "2 4",
"output": "44"
},
{
"input": "2 10",
"output": "10"
},
{
"input": "10 10",
"output": "1111111110"
},
{
"input": "4 10",
"output": "1110"
},
{
"input": "25 10",
"output": "1111111111111111111111110"
},
{
"input": "50 10",
"output": "11111111111111111111111111111111111111111111111110"
},
{
"input": "5 10",
"output": "11110"
},
{
"input": "99 10",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "100 10",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "20 10",
"output": "11111111111111111110"
},
{
"input": "99 7",
"output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "89 5",
"output": "55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "6 10",
"output": "111110"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "100 7",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
}
] | 1,693,713,712 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | n, t = map(int, input().split())
low = 10 ** (n - 1)
high = 10 ** n - 1
rem = low % t
num = low + rem if (low + rem) <= high else -1
print(num) | Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1.
Input Specification:
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Output Specification:
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
Demo Input:
['3 2\n']
Demo Output:
['712']
Note:
none | ```python
n, t = map(int, input().split())
low = 10 ** (n - 1)
high = 10 ** n - 1
rem = low % t
num = low + rem if (low + rem) <= high else -1
print(num)
``` | 0 |
|
303 | A | Lucky Permutation Triple | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not.
A permutation triple of permutations of length *n* (*a*,<=*b*,<=*c*) is called a Lucky Permutation Triple if and only if . The sign *a**i* denotes the *i*-th element of permutation *a*. The modular equality described above denotes that the remainders after dividing *a**i*<=+<=*b**i* by *n* and dividing *c**i* by *n* are equal.
Now, he has an integer *n* and wants to find a Lucky Permutation Triple. Could you please help him? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | If no Lucky Permutation Triple of length *n* exists print -1.
Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line — permutation *b*, the third — permutation *c*.
If there are multiple solutions, print any of them. | [
"5\n",
"2\n"
] | [
"1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3\n",
"-1\n"
] | In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6bf1b9b57809dbec5021f65f89616f259587c07.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/48cc13134296b68f459f69d78e0240859aaec702.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ac44412de7b46833e90348a6b3298f9796e3977c.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3825b0bb758208dda2ead1c5224c05d89ad9ab55.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0a72e2da40048a507839927a211267ac01c9bf89.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In Sample 2, you can easily notice that no lucky permutation triple exists. | 500 | [
{
"input": "5",
"output": "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3"
},
{
"input": "2",
"output": "-1"
},
{
"input": "8",
"output": "-1"
},
{
"input": "9",
"output": "0 1 2 3 4 5 6 7 8 \n0 1 2 3 4 5 6 7 8 \n0 2 4 6 8 1 3 5 7 "
},
{
"input": "2",
"output": "-1"
},
{
"input": "77",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 4..."
},
{
"input": "6",
"output": "-1"
},
{
"input": "87",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 \n0 2 4..."
},
{
"input": "72",
"output": "-1"
},
{
"input": "1",
"output": "0 \n0 \n0 "
},
{
"input": "23",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 2 4 6 8 10 12 14 16 18 20 22 1 3 5 7 9 11 13 15 17 19 21 "
},
{
"input": "52",
"output": "-1"
},
{
"input": "32",
"output": "-1"
},
{
"input": "25",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \n0 2 4 6 8 10 12 14 16 18 20 22 24 1 3 5 7 9 11 13 15 17 19 21 23 "
},
{
"input": "54",
"output": "-1"
},
{
"input": "39",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 "
},
{
"input": "20",
"output": "-1"
},
{
"input": "53",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 "
},
{
"input": "34",
"output": "-1"
},
{
"input": "23",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 2 4 6 8 10 12 14 16 18 20 22 1 3 5 7 9 11 13 15 17 19 21 "
},
{
"input": "37123",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "41904",
"output": "-1"
},
{
"input": "46684",
"output": "-1"
},
{
"input": "67817",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "72598",
"output": "-1"
},
{
"input": "85891",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "74320",
"output": "-1"
},
{
"input": "11805",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "16586",
"output": "-1"
},
{
"input": "5014",
"output": "-1"
},
{
"input": "73268",
"output": "-1"
},
{
"input": "61697",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "99182",
"output": "-1"
},
{
"input": "79771",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "68199",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "5684",
"output": "-1"
},
{
"input": "10465",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "31598",
"output": "-1"
},
{
"input": "36379",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "16968",
"output": "-1"
},
{
"input": "93061",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "73650",
"output": "-1"
},
{
"input": "94783",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "99564",
"output": "-1"
},
{
"input": "37049",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "25478",
"output": "-1"
},
{
"input": "30259",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "43551",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "31980",
"output": "-1"
},
{
"input": "69465",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "1",
"output": "0 \n0 \n0 "
},
{
"input": "100000",
"output": "-1"
},
{
"input": "99999",
"output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..."
},
{
"input": "99998",
"output": "-1"
}
] | 1,546,164,501 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 1,154 | 7,475,200 |
n=int(input())
if n%2:
a=[i for i in range(n)]
b=[i for i in range(n)]
c=[(a[i]+b[i])%n for i in range(n)]
print(*a)
print(*b)
print(*c)
else:
print(-1) | Title: Lucky Permutation Triple
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not.
A permutation triple of permutations of length *n* (*a*,<=*b*,<=*c*) is called a Lucky Permutation Triple if and only if . The sign *a**i* denotes the *i*-th element of permutation *a*. The modular equality described above denotes that the remainders after dividing *a**i*<=+<=*b**i* by *n* and dividing *c**i* by *n* are equal.
Now, he has an integer *n* and wants to find a Lucky Permutation Triple. Could you please help him?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105).
Output Specification:
If no Lucky Permutation Triple of length *n* exists print -1.
Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line — permutation *b*, the third — permutation *c*.
If there are multiple solutions, print any of them.
Demo Input:
['5\n', '2\n']
Demo Output:
['1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3\n', '-1\n']
Note:
In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6bf1b9b57809dbec5021f65f89616f259587c07.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/48cc13134296b68f459f69d78e0240859aaec702.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ac44412de7b46833e90348a6b3298f9796e3977c.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3825b0bb758208dda2ead1c5224c05d89ad9ab55.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0a72e2da40048a507839927a211267ac01c9bf89.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In Sample 2, you can easily notice that no lucky permutation triple exists. | ```python
n=int(input())
if n%2:
a=[i for i in range(n)]
b=[i for i in range(n)]
c=[(a[i]+b[i])%n for i in range(n)]
print(*a)
print(*b)
print(*c)
else:
print(-1)
``` | 3 |
|
7 | A | Kalevitch and Chess | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms"
] | A. Kalevitch and Chess | 2 | 64 | A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.
As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.
Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.
It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task. | The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black.
It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row). | Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. | [
"WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n",
"WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n"
] | [
"3\n",
"1\n"
] | none | 0 | [
{
"input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW",
"output": "3"
},
{
"input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "1"
},
{
"input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "0"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "8"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBW",
"output": "14"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "14"
},
{
"input": "BBBBBBBB\nWBBBWBBW\nBBBBBBBB\nWBBBWBBW\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW",
"output": "9"
},
{
"input": "BBBBBBBB\nWBBWWWBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB",
"output": "9"
},
{
"input": "BBBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB",
"output": "8"
},
{
"input": "WWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "8"
},
{
"input": "BBBBBBBB\nWBWWBBBW\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nBBBBBBBB",
"output": "7"
},
{
"input": "WBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW",
"output": "9"
},
{
"input": "BBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "11"
},
{
"input": "WWBWBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nWWBWBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB",
"output": "10"
},
{
"input": "WBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nBBBBBBBB\nWBBWBBBW\nWBBWBBBW",
"output": "6"
},
{
"input": "BBBWBBBW\nBBBWBBBW\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB\nBBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB",
"output": "9"
},
{
"input": "BBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "9"
},
{
"input": "WBBBBBWB\nBBBBBBBB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nBBBBBBBB",
"output": "8"
},
{
"input": "WBBBWWBW\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nWBBBWWBW\nWBBBWWBW",
"output": "6"
},
{
"input": "WBBBBWBB\nBBBBBBBB\nBBBBBBBB\nWBBBBWBB\nWBBBBWBB\nBBBBBBBB\nWBBBBWBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB",
"output": "11"
},
{
"input": "BBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW",
"output": "9"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB",
"output": "9"
},
{
"input": "BWBBBWWB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB",
"output": "12"
},
{
"input": "BWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB",
"output": "7"
},
{
"input": "WWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB\nWWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB",
"output": "6"
},
{
"input": "BWBBWWWW\nBWBBWWWW\nBWBBWWWW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWWWW\nBBBBBBBB",
"output": "7"
}
] | 1,385,466,055 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | #!/usr/bin/python3
def readln(): return tuple(map(int, input().split()))
b = [list(input()) for _ in range(8)]
cnt1 = sum([1 for s in b if s == ['B'] * 8])
cnt2 = sum([1 for s in zip(*b) if list(s) == ['B'] * 8])
print(8 if cnt1 == 8 else cnt1 + cnt2)
| Title: Kalevitch and Chess
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.
As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.
Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.
It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.
Input Specification:
The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black.
It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).
Output Specification:
Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.
Demo Input:
['WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n', 'WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
#!/usr/bin/python3
def readln(): return tuple(map(int, input().split()))
b = [list(input()) for _ in range(8)]
cnt1 = sum([1 for s in b if s == ['B'] * 8])
cnt2 = sum([1 for s in zip(*b) if list(s) == ['B'] * 8])
print(8 if cnt1 == 8 else cnt1 + cnt2)
``` | 3.969 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,679,498,526 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | n, m, a = map(int, input().split())
if n % a == 0:
r1 = n // a
else: r1 = (n // a) + 1
if m % a == 0:
r2 = m // a
else: r2 = (m // a) + 1
print(r1 * r2) | 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())
if n % a == 0:
r1 = n // a
else: r1 = (n // a) + 1
if m % a == 0:
r2 = m // a
else: r2 = (m // a) + 1
print(r1 * r2)
``` | 3.9845 |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides? | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "10 2 1 1",
"output": "5"
},
{
"input": "1 1000 1 2",
"output": "1"
},
{
"input": "1 1000 3 2",
"output": "2"
},
{
"input": "10 3 1 2",
"output": "7"
},
{
"input": "995 1 2 1",
"output": "995"
},
{
"input": "556 2 16 15",
"output": "4170"
},
{
"input": "477 2 16 14",
"output": "3346"
},
{
"input": "101 110 1 100",
"output": "100"
},
{
"input": "9 3 3 10",
"output": "27"
},
{
"input": "100 8 10 1",
"output": "13"
},
{
"input": "6 4 1 3",
"output": "5"
},
{
"input": "8 5 2 8",
"output": "14"
},
{
"input": "1000 2 1 1000",
"output": "1000"
}
] | 1,684,173,206 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | x = input().split(' ')
x = (int(a) for a in x)
n, m, a, b = x
cost = n//m * b
cost += (n - n//m * m) * a
print(cost) | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides?
Input Specification:
The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket.
Output Specification:
Print a single integer — the minimum sum in rubles that Ann will need to spend.
Demo Input:
['6 2 1 2\n', '5 2 2 3\n']
Demo Output:
['6\n', '8\n']
Note:
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | ```python
x = input().split(' ')
x = (int(a) for a in x)
n, m, a, b = x
cost = n//m * b
cost += (n - n//m * m) * a
print(cost)
``` | 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,645,618,106 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | s = str(inout())
l = s.lower()
u = s.upper()
l_count = 0
u_count = 0
for i in range(len(s)):
if s[i] == l[i]:
l_count += 1
else:
pass
for i in range(len(s)):
if s[i] == u[i]:
u_count += 1
else:
pass
if l_count >= u_count:
print(l)
else:
print(u)
| 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 = str(inout())
l = s.lower()
u = s.upper()
l_count = 0
u_count = 0
for i in range(len(s)):
if s[i] == l[i]:
l_count += 1
else:
pass
for i in range(len(s)):
if s[i] == u[i]:
u_count += 1
else:
pass
if l_count >= u_count:
print(l)
else:
print(u)
``` | -1 |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal. | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B. | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input": "A>B\nB>C\nC<A",
"output": "CBA"
},
{
"input": "A>C\nA>B\nB<C",
"output": "BCA"
},
{
"input": "C<B\nB>A\nA<C",
"output": "ACB"
},
{
"input": "C<B\nA>B\nC<A",
"output": "CBA"
},
{
"input": "C>B\nB>A\nA<C",
"output": "ABC"
},
{
"input": "C<B\nB<A\nC>A",
"output": "Impossible"
},
{
"input": "B<C\nC<A\nA>B",
"output": "BCA"
},
{
"input": "A>B\nC<B\nC<A",
"output": "CBA"
},
{
"input": "B>A\nC>B\nA>C",
"output": "Impossible"
},
{
"input": "B<A\nC>B\nC>A",
"output": "BAC"
},
{
"input": "A<B\nC>B\nA<C",
"output": "ABC"
},
{
"input": "A<B\nC<A\nB<C",
"output": "Impossible"
},
{
"input": "A>C\nC<B\nB>A",
"output": "CAB"
},
{
"input": "C>A\nA<B\nB>C",
"output": "ACB"
},
{
"input": "C>A\nC<B\nB>A",
"output": "ACB"
},
{
"input": "B>C\nB>A\nA<C",
"output": "ACB"
},
{
"input": "C<B\nC<A\nB<A",
"output": "CBA"
},
{
"input": "A<C\nA<B\nB>C",
"output": "ACB"
},
{
"input": "B>A\nA>C\nB>C",
"output": "CAB"
},
{
"input": "B<A\nA<C\nC<B",
"output": "Impossible"
},
{
"input": "A<C\nB>C\nA>B",
"output": "Impossible"
},
{
"input": "B>A\nC<A\nC>B",
"output": "Impossible"
},
{
"input": "A>C\nC>B\nB<A",
"output": "BCA"
},
{
"input": "B<C\nB<A\nA>C",
"output": "BCA"
},
{
"input": "A>B\nC>B\nA<C",
"output": "BAC"
},
{
"input": "C<B\nC<A\nB<A",
"output": "CBA"
},
{
"input": "A<C\nA>B\nB>C",
"output": "Impossible"
},
{
"input": "B>A\nB>C\nA<C",
"output": "ACB"
},
{
"input": "B>C\nC<A\nB<A",
"output": "CBA"
},
{
"input": "C>A\nB>A\nB>C",
"output": "ACB"
},
{
"input": "B<A\nB>C\nA<C",
"output": "Impossible"
},
{
"input": "B<C\nA<B\nC>A",
"output": "ABC"
},
{
"input": "C<B\nB>A\nA>C",
"output": "CAB"
},
{
"input": "A>B\nC>A\nB<C",
"output": "BAC"
},
{
"input": "A>B\nB>C\nC<A",
"output": "CBA"
},
{
"input": "B>C\nC>A\nA>B",
"output": "Impossible"
},
{
"input": "B<A\nB>C\nC<A",
"output": "CBA"
},
{
"input": "C>B\nB>A\nC>A",
"output": "ABC"
},
{
"input": "A>C\nA>B\nB>C",
"output": "CBA"
},
{
"input": "B<C\nA>B\nA<C",
"output": "BAC"
},
{
"input": "C>A\nC<B\nB>A",
"output": "ACB"
},
{
"input": "C>B\nA<B\nC<A",
"output": "Impossible"
},
{
"input": "A<C\nC<B\nA>B",
"output": "Impossible"
},
{
"input": "B>C\nA<B\nA<C",
"output": "ACB"
},
{
"input": "C>A\nA<B\nC>B",
"output": "ABC"
}
] | 1,655,206,924 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 124 | 512,000 | a = b = c = 0
for i in range(3):
s = input()
if s[0] == "A" and s[1] == ">":
a += 1
elif s[0] == "A" and s[1] == "<" and s[2] == "B":
b += 1
elif s[0] == "A" and s[1] == "<" and s[2] == "C":
c += 1
elif s[0] == "B" and s[1] == ">":
b += 1
elif s[0] == "B" and s[1] == "<" and s[2] == "A":
a += 1
elif s[0] == "B" and s[1] == "<" and s[2] == "C":
c += 1
elif s[0] == "C" and s[1] == ">":
c += 1
elif s[0] == "C" and s[1] == "<" and s[2] == "B":
b += 1
elif s[0] == "C" and s[1] == "<" and s[2] == "A":
a += 1
if a == b or a == c or b == c:
print("Impossible")
else:
if a == max(a, b, c) and b == max(b, c):
print("CBA")
elif a == max(a, b, c) and c == max(b, c):
print("BCA")
elif b == max(a, b, c) and c == max(a, c):
print("ACB")
elif b == max(a, b, c) and a == max(a, c):
print("CAB")
elif c == max(a, b, c) and b == max(b, a):
print("ABC")
elif c == max(a, b, c) and a == max(b, a):
print("BAC") | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.
Input Specification:
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.
Output Specification:
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
Demo Input:
['A>B\nC<B\nA>C\n', 'A<B\nB>C\nC>A\n']
Demo Output:
['CBA', 'ACB']
Note:
none | ```python
a = b = c = 0
for i in range(3):
s = input()
if s[0] == "A" and s[1] == ">":
a += 1
elif s[0] == "A" and s[1] == "<" and s[2] == "B":
b += 1
elif s[0] == "A" and s[1] == "<" and s[2] == "C":
c += 1
elif s[0] == "B" and s[1] == ">":
b += 1
elif s[0] == "B" and s[1] == "<" and s[2] == "A":
a += 1
elif s[0] == "B" and s[1] == "<" and s[2] == "C":
c += 1
elif s[0] == "C" and s[1] == ">":
c += 1
elif s[0] == "C" and s[1] == "<" and s[2] == "B":
b += 1
elif s[0] == "C" and s[1] == "<" and s[2] == "A":
a += 1
if a == b or a == c or b == c:
print("Impossible")
else:
if a == max(a, b, c) and b == max(b, c):
print("CBA")
elif a == max(a, b, c) and c == max(b, c):
print("BCA")
elif b == max(a, b, c) and c == max(a, c):
print("ACB")
elif b == max(a, b, c) and a == max(a, c):
print("CAB")
elif c == max(a, b, c) and b == max(b, a):
print("ABC")
elif c == max(a, b, c) and a == max(b, a):
print("BAC")
``` | 3.968046 |
88 | B | Keyboard | PROGRAMMING | 1,500 | [
"implementation"
] | B. Keyboard | 1 | 256 | Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they make lowercase letters uppercase.
Vasya can press one or two keys with one hand. However, he can only press two keys if the Euclidean distance between the centers of the keys does not exceed *x*. The keys are considered as squares with a side equal to 1. There are no empty spaces between neighbouring keys.
Vasya is a very lazy boy, that's why he tries to type with one hand as he eats chips with his other one. However, it is possible that some symbol can't be typed with one hand only, because the distance between it and the closest "Shift" key is strictly larger than *x*. In this case he will have to use his other hand. Having typed the symbol, Vasya returns other hand back to the chips.
You are given Vasya's keyboard and the text. Count the minimum number of times Vasya will have to use the other hand. | The first line contains three integers *n*, *m*, *x* (1<=≤<=*n*,<=*m*<=≤<=30,<=1<=≤<=*x*<=≤<=50).
Next *n* lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly *m* keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys are marked with the "S" symbol.
Then follow the length of the text *q* (1<=≤<=*q*<=≤<=5·105). The last line contains the text *T*, which consists of *q* symbols, which are uppercase and lowercase Latin letters. | If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes). | [
"2 2 1\nab\ncd\n1\nA\n",
"2 2 1\nab\ncd\n1\ne\n",
"2 2 1\nab\ncS\n5\nabcBA\n",
"3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n"
] | [
"-1\n",
"-1\n",
"1\n",
"2\n"
] | In the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard.
In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard.
In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the keyboard can be printed. Those symbols come up in the text twice, thus, the answer is 2. | 1,000 | [
{
"input": "2 2 1\nab\ncd\n1\nA",
"output": "-1"
},
{
"input": "2 2 1\nab\ncd\n1\ne",
"output": "-1"
},
{
"input": "2 2 1\nab\ncS\n5\nabcBA",
"output": "1"
},
{
"input": "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG",
"output": "2"
},
{
"input": "10 9 3\noboxlgpey\nyxcuwkkmp\njuqeflhwq\nsfnxqtjqS\nkkudcnyjl\nhgjlcrkjq\njnofqksxn\nqbhsnuguv\nlvahnifao\nebwnnlrwe\n35\nCodeforcesBetaRoundproblemAtestfive",
"output": "4"
},
{
"input": "2 7 4\niuqtieo\nysxcgmS\n2\nsQ",
"output": "1"
},
{
"input": "1 2 4\nbS\n8\nbBbbbBbb",
"output": "0"
},
{
"input": "7 8 5\nfqiubjpm\nqbshcsyk\ncjbxpbef\nptwpmapx\nryazscbm\nqnvsgzrf\nhtardzkz\n9\nuxrmwkayy",
"output": "0"
},
{
"input": "8 6 4\nefvmov\nkeofnw\npwajpe\nknptky\nSibruu\nrgdukk\nbsxosd\nhovgSe\n10\nECreruXmsC",
"output": "-1"
},
{
"input": "10 3 2\nukk\neqt\nfex\nqSh\ntvz\nfjn\niol\nehd\nnte\ngyx\n5\ncgQxI",
"output": "-1"
},
{
"input": "10 10 19\nowqjcaSpqn\nvgrhboqahn\nbzziocjmbu\npurqsmiSop\nxcsifctjhy\nycyytwoamk\nrnjfxsxowl\nnkgcywcdff\nbazljrisqv\nkcakigSekq\n100\nzewpATtssQVicNrlRrcoifTutTAfFMUEfDFKoNyQbSrSYxTGMadNkRpmJvoEqUsqPYgAdQreaUrwDKMNFWiwdRRCcJBPorfMVMoK",
"output": "0"
},
{
"input": "10 10 26\nwxmssptheb\nzpxbxsyxsy\nqbjkpaywqp\nfwhnuzjcgq\nycgaanzedz\njrycrbzqfs\ngswwakybus\nfhtxhljedz\noSepmyjosv\ndwviycevdn\n100\nyapwUfnyPzgZyFvAHGKWVbXQHkuhJDoUTvCAtdMMCQmKchxKkilUTECOqYJFUSHPqKiRKhDXZgHxwApDWlShdwakmVCgaeKCLOMX",
"output": "0"
},
{
"input": "10 10 3\nrvouufmnqu\nbyukrnmnhr\nzjggwxgvkz\ntcagkSitiw\nhryajgtpwc\njragfhqoks\nkgroxxkuvp\nbpgrkqiyns\njbuhjjkziw\nomjmbaggsw\n100\nCpRzrPqPngYvrVJFCWRPMRwrpXcbtiwfoFcAkRaNjzpMMKOQAzBxSrxGbIHaYgmSqhhxhZTmhFttKnhFzRfKxYXshUZRvtKJIzZq",
"output": "12"
},
{
"input": "10 10 2\nfriuxvShvg\nerslojqtgu\nzeqsmdewry\nwvhbeeyeSu\ngkofbjaavr\ntwkcdxugps\nnzlylSmafu\nstamkpxnzt\nuwxwximkrm\nmzxyboazbl\n100\nmRIfAtrLKmztpVkAmojDCiIgseBwlUilBIixDQhqNhNAqVLLIobuCIretLdSvixNNdCiouFMXtwHZFlObCeaygmIiFBfaCirbmCa",
"output": "19"
},
{
"input": "10 10 2\nbddahSqkmk\npxbocxayjs\nottvdazstk\nlaxuidqlqb\nkfjwdpdfat\nxlipuubkgv\niqyomzfktm\niwbgidmwyu\nrngqkeupsf\nbqndtekryw\n100\nMNQgWFLhHycqwjSsbTkbgMYAIHFYARRmOsinYMFjOxxnLjiKfeiBbMpoeTdzUMORPaAxRNfvdAPFaKkPdxdAjjJgGCxkDzmSasqq",
"output": "37"
},
{
"input": "10 10 2\nnxcwdrsmrv\nSyjahsosvp\nvkrqbxhgbv\nwkxywavtnn\nepkyoviqbi\nsfmpvhuwwq\nnlsostrotx\ntcdguorhny\nimixrqzSdu\nxzhdhdwibt\n100\nUzzaWiRFYbAqxIDMrRBBDoGQhSzSqSLEddAiJsZcxbemdeuddamNYdWOvzlYSCuHIRpnuxdNxAsnZMiLXBYwnrMcrbNeLrUYhZOB",
"output": "17"
},
{
"input": "10 10 23\nhtyvouoiqi\nvySvsfqadv\nxvqyqjyutq\npjcrrphzbk\nhlqfyoqfmo\nezcSwleoew\nxkwqrajxyg\nngSiftgoso\njyndgicccr\nlgjvokydhp\n100\nJzVVfotldIRcyjhTNRcFlTxFeZKRwavZxYcvdDOQyUvTmryFRuRBcRvmscegtspkPuchqlFEKbrfpTOSlSFOARsbbvSenMwNmaRj",
"output": "0"
},
{
"input": "10 10 7\nifcwalsdbj\njpykymrbei\nrylzgkyefh\noilvvexpjp\niptgodpfim\ndSrqejaixu\npksxlsniwa\nmoSenxtfbc\noqssptcenz\nqdhmouvyas\n100\nqtMDVUXJpSEFgPsLKyRJVRbfVoYaCKJDnQDLFVngVjSPzzVyMnMyuyahMRiBJuNhKtgpVqvukUolLvYEmidvXotgQUJukYwIweUW",
"output": "0"
},
{
"input": "10 10 1\nmdxafehbkr\nyuhenybjps\ntvfwmiwcoh\njmzrepzjvx\nnqyorkSnuk\ntSmztmwidv\ncmmajnlqrw\nfiqewpdwax\nuesmkdcplt\nlgkomdcqbo\n100\nmcEQmAvFqKYMXLHQUDeIulkmAMRkIUtbKihTFJwJYQfcAelNrZWSAwHunwZTrdHaRWokgCyLqbubOpEHuZiDVoFHjvkMSoBPyGOI",
"output": "39"
},
{
"input": "10 10 2\nnhfafdwqhh\neyvitpcthk\nrpiotuoqzh\nnxxnhuaxee\nyevrtirzwf\nkbtSsamyel\nfeenjvxsmo\nkqpenxjmde\nlqsamthlwp\njdyyqsbtbk\n100\nUHucxPWDaKonVpXEctuqYUAQnrFEZaTYxhoacNbHIMevlbDejXjitEzyVrTfcfBHWRMdJvaTkbkqccyHjtzpTbKmRAXwlXCtFKNX",
"output": "29"
},
{
"input": "10 10 1\nsufnxxpdnx\nvttibpllhv\nlvbrjmfdjx\ngmtexvrnfh\nygsqrsSwxd\nkxbbjxgbzs\nedutwocmzd\nfebjgknyai\nvcvquagvrs\ndrdoarhgoc\n100\nZoZJXhUWyaLgBTpgbznABKHuyFcKzJmGaMhoKkKfyOGacLwBspaKtAEdwMZJFYiZUFNDxdDIDgKSCRvsbGUOXRqalbpuEqkduYpW",
"output": "44"
},
{
"input": "10 10 2\ncstcrltzsl\nblotmquzvj\nuiitiytlgx\nwumpfdaprd\ntfxohqpztn\nvfrpsccddo\nneegusrkxw\niijfjozqjq\nioegbvuhew\npjjpqdxvqu\n100\nkPCBONfZLkeXzWVuSgvinPENazcnRoBcUHXwRzPyvNIiDlDSeKOYmiUmjooXuzTCtIRxKDAYeTLgjsenxHoymVazMALUADQpjVjV",
"output": "-1"
},
{
"input": "10 10 1\nqztnjglyrc\nnukswgzajl\nqnpbdwjvbb\nliiakzcrlz\nnolwfzzvxd\nmqvhiySttx\nqwuizSjuto\nqbgwiwjukx\nkomyvblgkc\ntkzlxzgsru\n100\nYUzTZDzLFkMUhjQWbwljJCRyZGFzgJcozvROiwPktRGxkMKiPyiTvhDrtusPYhMgVAOFIjAvlpzcrUvrMrMbhkpUiyAytKfYOGTF",
"output": "37"
},
{
"input": "10 10 1\nmgziiihbkq\niobjknuogh\nvntwahSopu\nsjsxjpaqvm\nwqgrodizst\nselzugktoi\nvbhfzvgjfn\nliqlfdcjhf\nbpbtpmimxb\npksfiydpfw\n100\nwAVZXEhKTuajdCauVTIwgnfbxWuUSmtXkjHZtNVcfTsiSAPLdpdEFdTJLZRjptUcRhAmrNjKMXmuDGatAQoaIpbddnzRGHsJrhoq",
"output": "39"
},
{
"input": "10 10 2\nshbqxycvfm\notydudkttw\nqhatsxsngz\nixvyujtyjc\nsbvqhnjbak\neggcguuuka\nxcydfgjzeb\nytpdkcdrsq\nefqlpywggu\nfcnfrhnouo\n100\nHPqtuVckdUOhsnuhnbpekWvWKUnAEaOCihpeEvmaOKOPcIZiMixGJGEuXAaOxuUNyrIesmldLEqGnvyDKPDvFkCbRebCORHmUgeV",
"output": "-1"
},
{
"input": "1 1 50\nS\n29\nargjhoaiogjiSjqfhjksdvjkSvcvn",
"output": "-1"
},
{
"input": "1 1 50\nS\n1\nS",
"output": "-1"
},
{
"input": "1 1 50\na\n29\nargjhoaiogjiSjqfhjksdvjkSvcvn",
"output": "-1"
},
{
"input": "1 1 50\nz\n29\nargjhoaiogjiSjqfhjksdvjkSvcvn",
"output": "-1"
},
{
"input": "2 1 2\nS\nc\n4\nCSSA",
"output": "-1"
}
] | 1,656,900,356 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 46 | 0 | from math import sqrt
n,m,x = map(int,input().split())
keyboard = [-1] *26
shifts = []
for i in range(n):
row = input()
for j in range(m):
c = row[j]
if c == 'S':
shifts.append((i,j))
else :
pos = ord(c)-97
keyboard[pos] = (i,j)
m = int(input())
text = input()
res = 0
for c in text :
if keyboard[ord(c.lower())-97] == -1 or c.isupper() and len(shifts) == 0:
res = -1
break
a = keyboard[ord(c.lower())-97]
if c.isupper():
res +=1
for shift in shifts :
if sqrt((shift[0]-a[0])**2+(shift[1]-a[1])**2) <=x :
res-=1
# print('one hand ', c)
break
print(res)
# print(keyboard)
# print(shifts) | Title: Keyboard
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they make lowercase letters uppercase.
Vasya can press one or two keys with one hand. However, he can only press two keys if the Euclidean distance between the centers of the keys does not exceed *x*. The keys are considered as squares with a side equal to 1. There are no empty spaces between neighbouring keys.
Vasya is a very lazy boy, that's why he tries to type with one hand as he eats chips with his other one. However, it is possible that some symbol can't be typed with one hand only, because the distance between it and the closest "Shift" key is strictly larger than *x*. In this case he will have to use his other hand. Having typed the symbol, Vasya returns other hand back to the chips.
You are given Vasya's keyboard and the text. Count the minimum number of times Vasya will have to use the other hand.
Input Specification:
The first line contains three integers *n*, *m*, *x* (1<=≤<=*n*,<=*m*<=≤<=30,<=1<=≤<=*x*<=≤<=50).
Next *n* lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly *m* keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys are marked with the "S" symbol.
Then follow the length of the text *q* (1<=≤<=*q*<=≤<=5·105). The last line contains the text *T*, which consists of *q* symbols, which are uppercase and lowercase Latin letters.
Output Specification:
If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes).
Demo Input:
['2 2 1\nab\ncd\n1\nA\n', '2 2 1\nab\ncd\n1\ne\n', '2 2 1\nab\ncS\n5\nabcBA\n', '3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n']
Demo Output:
['-1\n', '-1\n', '1\n', '2\n']
Note:
In the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard.
In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard.
In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the keyboard can be printed. Those symbols come up in the text twice, thus, the answer is 2. | ```python
from math import sqrt
n,m,x = map(int,input().split())
keyboard = [-1] *26
shifts = []
for i in range(n):
row = input()
for j in range(m):
c = row[j]
if c == 'S':
shifts.append((i,j))
else :
pos = ord(c)-97
keyboard[pos] = (i,j)
m = int(input())
text = input()
res = 0
for c in text :
if keyboard[ord(c.lower())-97] == -1 or c.isupper() and len(shifts) == 0:
res = -1
break
a = keyboard[ord(c.lower())-97]
if c.isupper():
res +=1
for shift in shifts :
if sqrt((shift[0]-a[0])**2+(shift[1]-a[1])**2) <=x :
res-=1
# print('one hand ', c)
break
print(res)
# print(keyboard)
# print(shifts)
``` | 0 |
12 | C | Fruits | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | C. Fruits | 1 | 256 | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). | The first line of the input contains two integer number *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following *m* lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to *n*. Also it is known that the seller has in stock all fruits that Valera wants to buy. | Print two numbers *a* and *b* (*a*<=≤<=*b*) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. | [
"5 3\n4 2 1 10 5\napple\norange\nmango\n",
"6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n"
] | [
"7 19\n",
"11 30\n"
] | none | 0 | [
{
"input": "5 3\n4 2 1 10 5\napple\norange\nmango",
"output": "7 19"
},
{
"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange",
"output": "11 30"
},
{
"input": "2 2\n91 82\neiiofpfpmemlakcystpun\nmcnzeiiofpfpmemlakcystpunfl",
"output": "173 173"
},
{
"input": "1 4\n1\nu\nu\nu\nu",
"output": "4 4"
},
{
"input": "3 3\n4 2 3\nwivujdxzjm\nawagljmtc\nwivujdxzjm",
"output": "7 11"
},
{
"input": "3 4\n10 10 10\nodchpcsdhldqnkbhwtwnx\nldqnkbhwtwnxk\nodchpcsdhldqnkbhwtwnx\nldqnkbhwtwnxk",
"output": "40 40"
},
{
"input": "3 1\n14 26 22\naag",
"output": "14 26"
},
{
"input": "2 2\n5 5\ndcypj\npiyqiagzjlvbhgfndhfu",
"output": "10 10"
},
{
"input": "4 3\n5 3 10 3\nxzjhplrzkbbzkypfazf\nxzjhplrzkbbzkypfazf\nh",
"output": "9 25"
},
{
"input": "5 5\n10 10 6 7 9\niyerjkvzibxhllkeuagptnoqrzm\nvzibxhllkeuag\niyerjkvzibxhllkeuagptnoqrzm\nnoq\nnoq",
"output": "35 49"
},
{
"input": "10 8\n19 18 20 13 19 13 11 10 19 16\nkayangqlsqmcd\nqls\nqydawlbludrgrjfjrhd\nfjrh\nqls\nqls\nrnmmayh\nkayangqlsqmcd",
"output": "94 154"
},
{
"input": "5 15\n61 56 95 42 85\noq\ndwxivk\ntxdxzsfdj\noq\noq\ndwxivk\ntxdxzsfdj\ndwxivk\ntxdxzsfdj\nk\nk\ndwxivk\noq\nk\ntxdxzsfdj",
"output": "891 1132"
},
{
"input": "12 18\n42 44 69 16 81 64 12 68 70 75 75 67\nfm\nqamklzfmrjnqgdspwfasjnplg\nqamklzfmrjnqgdspwfasjnplg\nqamklzfmrjnqgdspwfasjnplg\nl\nl\nl\nfm\nqamklzfmrjnqgdspwfasjnplg\nl\nnplgwotfm\np\nl\namklzfm\ntkpubqamklzfmrjn\npwf\nfm\np",
"output": "606 1338"
},
{
"input": "24 24\n34 69 89 45 87 30 78 14 53 16 27 54 75 95 10 69 80 71 43 3 91 9 8 7\nswtcofrcpeyszydwkrg\nszyd\npeyszyd\nrcpeyszydwkrgfj\npeyszydwkrgf\nzydw\nsmzginydyrtua\nj\nj\ntzwsw\ngfj\nyssoqnlpsm\ninydyrtuatzw\ninydy\nlpsmzginydyrtuatzwswtcofrcpeyszy\nyssoqnlpsm\npeyszyd\nyssoqnlpsm\ninydy\npeyszyd\ninydyrtuatzw\nat\nfj\nswtcofrcpeyszydwkrg",
"output": "552 1769"
}
] | 1,698,064,885 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 31 | 0 | enter1 = list(map(int, input().split()))
n = enter1[0]
m = enter1[1]
li = list(map(int, input().split()))
fruits = list()
for i in range(m):
fruits.append(input())
se = set(fruits)
kol_vo = []
li_se = list(se)
for i in range(len(li_se)):
kol_vo.append(fruits.count(li_se[i]))
kol_vo.sort()
kol_vo.reverse()
li.sort()
sum1 = 0
sum2 = 0
for i in range(len(kol_vo)):
sum1 += (li[i]*kol_vo[i])
li.reverse()
for j in range(len(kol_vo)):
sum2 += (li[j]*kol_vo[j])
print(sum1, sum2)
| Title: Fruits
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags).
Input Specification:
The first line of the input contains two integer number *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following *m* lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to *n*. Also it is known that the seller has in stock all fruits that Valera wants to buy.
Output Specification:
Print two numbers *a* and *b* (*a*<=≤<=*b*) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
Demo Input:
['5 3\n4 2 1 10 5\napple\norange\nmango\n', '6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n']
Demo Output:
['7 19\n', '11 30\n']
Note:
none | ```python
enter1 = list(map(int, input().split()))
n = enter1[0]
m = enter1[1]
li = list(map(int, input().split()))
fruits = list()
for i in range(m):
fruits.append(input())
se = set(fruits)
kol_vo = []
li_se = list(se)
for i in range(len(li_se)):
kol_vo.append(fruits.count(li_se[i]))
kol_vo.sort()
kol_vo.reverse()
li.sort()
sum1 = 0
sum2 = 0
for i in range(len(kol_vo)):
sum1 += (li[i]*kol_vo[i])
li.reverse()
for j in range(len(kol_vo)):
sum2 += (li[j]*kol_vo[j])
print(sum1, sum2)
``` | 3.9845 |
0 | none | none | none | 0 | [
"none"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits. Petya can perform operations of two types:
- replace any one digit from string *a* by its opposite (i.e., replace 4 by 7 and 7 by 4); - swap any pair of digits in string *a*.
Petya is interested in the minimum number of operations that are needed to make string *a* equal to string *b*. Help him with the task. | The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. | Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*. | [
"47\n74\n",
"774\n744\n",
"777\n444\n"
] | [
"1\n",
"1\n",
"3\n"
] | In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites. | 0 | [
{
"input": "47\n74",
"output": "1"
},
{
"input": "774\n744",
"output": "1"
},
{
"input": "777\n444",
"output": "3"
},
{
"input": "74747474\n77777777",
"output": "4"
},
{
"input": "444444444444\n777777777777",
"output": "12"
},
{
"input": "4744744447774474447474774\n4477774777444444444777447",
"output": "8"
},
{
"input": "7\n4",
"output": "1"
},
{
"input": "4\n7",
"output": "1"
},
{
"input": "7777777777\n7777777774",
"output": "1"
},
{
"input": "47777777777\n77777777774",
"output": "1"
},
{
"input": "47747477747744447774774444444777444747474747777774\n44777444774477447777444774477777477774444477447777",
"output": "14"
},
{
"input": "44447777447744444777777747477444777444447744444\n47444747774774744474747744447744477747777777447",
"output": "13"
},
{
"input": "4447744774744774744747744774474474444447477477444747477444\n7477477444744774744744774774744474744447744774744477744477",
"output": "14"
},
{
"input": "44747744777777444\n47774747747744777",
"output": "6"
},
{
"input": "44447774444474477747774774477777474774744744477444447777477477744747477774744444744777777777747777477447744774744444747477744744\n77777474477477747774777777474474477444474777477747747777477747747744474474747774747747444777474444744744444477477777747744747477",
"output": "37"
},
{
"input": "774774747744474477447477777447477747477474777477744744747444774474477477747474477447774444774744777\n744477444747477447477777774477447444447747477747477747774477474447474477477474444777444444447474747",
"output": "27"
},
{
"input": "4747447477\n4747444744",
"output": "3"
},
{
"input": "47744447444\n74477447744",
"output": "4"
},
{
"input": "447444777744\n777747744477",
"output": "6"
},
{
"input": "474777477774444\n774747777774477",
"output": "4"
},
{
"input": "47744474447747744777777447\n44744747477474777744777477",
"output": "7"
},
{
"input": "77447447444777777744744747744747774747477774777774447447777474477477774774777\n74777777444744447447474474477747747444444447447774444444747777444747474777447",
"output": "28"
},
{
"input": "7\n7",
"output": "0"
},
{
"input": "444\n444",
"output": "0"
},
{
"input": "77747\n47474",
"output": "3"
}
] | 1,470,928,572 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 186 | 5,017,600 | a=input()
b=input()
k1=0
k2=0
for i in range (len(a)):
if a[i]!=b[i]:
if a[i]=='4':
k1+=1
else:
k2+=1
d=max(k1,k2)
print (d) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits. Petya can perform operations of two types:
- replace any one digit from string *a* by its opposite (i.e., replace 4 by 7 and 7 by 4); - swap any pair of digits in string *a*.
Petya is interested in the minimum number of operations that are needed to make string *a* equal to string *b*. Help him with the task.
Input Specification:
The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.
Output Specification:
Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*.
Demo Input:
['47\n74\n', '774\n744\n', '777\n444\n']
Demo Output:
['1\n', '1\n', '3\n']
Note:
In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites. | ```python
a=input()
b=input()
k1=0
k2=0
for i in range (len(a)):
if a[i]!=b[i]:
if a[i]=='4':
k1+=1
else:
k2+=1
d=max(k1,k2)
print (d)
``` | 3 |
|
371 | A | K-Periodic Array | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"math"
] | null | null | This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it has period of length *k*.
For example, any array is *n*-periodic, where *n* is the array length. Array [2,<=1,<=2,<=1,<=2,<=1] is at the same time 2-periodic and 6-periodic and array [1,<=2,<=1,<=1,<=2,<=1,<=1,<=2,<=1] is at the same time 3-periodic and 9-periodic.
For the given array *a*, consisting only of numbers one and two, find the minimum number of elements to change to make the array *k*-periodic. If the array already is *k*-periodic, then the required value equals 0. | The first line of the input contains a pair of integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), *a**i* is the *i*-th element of the array. | Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0. | [
"6 2\n2 1 2 2 2 1\n",
"8 4\n1 1 2 1 1 1 2 1\n",
"9 3\n2 1 1 1 2 1 1 1 2\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1].
In the second sample, the given array already is 4-periodic.
In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1, 1, 1, 1, 1, 1] — this array is simultaneously 1-, 3- and 9-periodic. | 500 | [
{
"input": "6 2\n2 1 2 2 2 1",
"output": "1"
},
{
"input": "8 4\n1 1 2 1 1 1 2 1",
"output": "0"
},
{
"input": "9 3\n2 1 1 1 2 1 1 1 2",
"output": "3"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "0"
},
{
"input": "100 1\n1 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "8"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "2 2\n2 1",
"output": "0"
},
{
"input": "3 1\n2 1 2",
"output": "1"
},
{
"input": "3 3\n1 2 1",
"output": "0"
},
{
"input": "4 2\n2 1 2 2",
"output": "1"
},
{
"input": "10 2\n2 2 2 1 1 2 2 2 2 1",
"output": "3"
},
{
"input": "10 5\n2 2 1 2 1 1 2 1 1 1",
"output": "2"
},
{
"input": "20 4\n2 2 1 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 1 2",
"output": "0"
},
{
"input": "20 5\n2 2 1 1 1 2 1 1 1 1 2 2 1 1 2 2 2 1 1 2",
"output": "3"
},
{
"input": "20 10\n1 2 2 2 2 1 1 1 2 1 1 2 2 2 2 1 2 2 2 1",
"output": "2"
},
{
"input": "100 2\n2 2 1 2 1 2 1 2 1 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100 4\n1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 2 2 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 1 1 2 1 1",
"output": "8"
},
{
"input": "100 5\n2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 2 2",
"output": "16"
},
{
"input": "100 10\n2 1 1 1 1 2 2 2 1 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 1 2 2 2 1 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 2 2 1 2 1 1",
"output": "6"
},
{
"input": "100 20\n2 2 2 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 2 1 2 2 2 2 1 2 1 2 1 1 1 1 2 2 2 2 1 2 1 1 2 2 2 2 1 2 1 2 1 2 1 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 2 1 1 1 1 2 2 2 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 2 2 1 1 1",
"output": "13"
},
{
"input": "100 25\n2 2 1 2 2 2 2 2 1 2 2 1 2 1 1 2 1 2 1 2 2 2 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 2 1 1 2 2 2 1 2 2 1 2 2 2 2 1 1 2 1 2 2 1 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 1 2 1 1 2 2 2 2 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 2 2 2",
"output": "15"
},
{
"input": "100 10\n2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1",
"output": "0"
}
] | 1,616,853,440 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 62 | 0 | n, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(k):
s1, s2 = 0, 0
for j in range(i, n, k):
if A[j] == 1:
s1+=1
else:
s2+=1
ans = ans + min(s1, s2)
print(ans) | Title: K-Periodic Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it has period of length *k*.
For example, any array is *n*-periodic, where *n* is the array length. Array [2,<=1,<=2,<=1,<=2,<=1] is at the same time 2-periodic and 6-periodic and array [1,<=2,<=1,<=1,<=2,<=1,<=1,<=2,<=1] is at the same time 3-periodic and 9-periodic.
For the given array *a*, consisting only of numbers one and two, find the minimum number of elements to change to make the array *k*-periodic. If the array already is *k*-periodic, then the required value equals 0.
Input Specification:
The first line of the input contains a pair of integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), *a**i* is the *i*-th element of the array.
Output Specification:
Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0.
Demo Input:
['6 2\n2 1 2 2 2 1\n', '8 4\n1 1 2 1 1 1 2 1\n', '9 3\n2 1 1 1 2 1 1 1 2\n']
Demo Output:
['1\n', '0\n', '3\n']
Note:
In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1].
In the second sample, the given array already is 4-periodic.
In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1, 1, 1, 1, 1, 1] — this array is simultaneously 1-, 3- and 9-periodic. | ```python
n, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(k):
s1, s2 = 0, 0
for j in range(i, n, k):
if A[j] == 1:
s1+=1
else:
s2+=1
ans = ans + min(s1, s2)
print(ans)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*. | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 0 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "2"
},
{
"input": "100 0",
"output": "100"
},
{
"input": "1000000000 0",
"output": "1000000000"
},
{
"input": "160 2",
"output": "800"
},
{
"input": "3 0",
"output": "3"
},
{
"input": "10 0",
"output": "10"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "3 1",
"output": "30"
},
{
"input": "4 1",
"output": "20"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "6 1",
"output": "30"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "8 1",
"output": "40"
},
{
"input": "9 1",
"output": "90"
},
{
"input": "10 1",
"output": "10"
},
{
"input": "11 1",
"output": "110"
},
{
"input": "12 1",
"output": "60"
},
{
"input": "16 2",
"output": "400"
},
{
"input": "2 2",
"output": "100"
},
{
"input": "1 2",
"output": "100"
},
{
"input": "5 2",
"output": "100"
},
{
"input": "15 2",
"output": "300"
},
{
"input": "36 2",
"output": "900"
},
{
"input": "1 8",
"output": "100000000"
},
{
"input": "8 8",
"output": "100000000"
},
{
"input": "96 8",
"output": "300000000"
},
{
"input": "175 8",
"output": "700000000"
},
{
"input": "9999995 8",
"output": "199999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "12345678 8",
"output": "617283900000000"
},
{
"input": "78125 8",
"output": "100000000"
},
{
"input": "390625 8",
"output": "100000000"
},
{
"input": "1953125 8",
"output": "500000000"
},
{
"input": "9765625 8",
"output": "2500000000"
},
{
"input": "68359375 8",
"output": "17500000000"
},
{
"input": "268435456 8",
"output": "104857600000000"
},
{
"input": "125829120 8",
"output": "9830400000000"
},
{
"input": "128000 8",
"output": "400000000"
},
{
"input": "300000 8",
"output": "300000000"
},
{
"input": "3711871 8",
"output": "371187100000000"
},
{
"input": "55555 8",
"output": "1111100000000"
},
{
"input": "222222222 8",
"output": "11111111100000000"
},
{
"input": "479001600 8",
"output": "7484400000000"
},
{
"input": "655360001 7",
"output": "6553600010000000"
},
{
"input": "655360001 8",
"output": "65536000100000000"
},
{
"input": "1000000000 1",
"output": "1000000000"
},
{
"input": "1000000000 7",
"output": "1000000000"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "10000000 8",
"output": "100000000"
},
{
"input": "1000000 8",
"output": "100000000"
},
{
"input": "10000009 8",
"output": "1000000900000000"
},
{
"input": "10000005 8",
"output": "200000100000000"
},
{
"input": "10000002 8",
"output": "500000100000000"
},
{
"input": "999999997 8",
"output": "99999999700000000"
},
{
"input": "999999997 7",
"output": "9999999970000000"
},
{
"input": "999999995 8",
"output": "19999999900000000"
},
{
"input": "123 8",
"output": "12300000000"
},
{
"input": "24 2",
"output": "600"
},
{
"input": "16 4",
"output": "10000"
},
{
"input": "123456787 8",
"output": "12345678700000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "101 1",
"output": "1010"
},
{
"input": "50 2",
"output": "100"
},
{
"input": "999999818 1",
"output": "4999999090"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "123 1",
"output": "1230"
},
{
"input": "16 1",
"output": "80"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "15304 6",
"output": "1913000000"
},
{
"input": "3 8",
"output": "300000000"
},
{
"input": "4 2",
"output": "100"
},
{
"input": "100000 7",
"output": "10000000"
},
{
"input": "5 8",
"output": "100000000"
},
{
"input": "16724 6",
"output": "4181000000"
},
{
"input": "999999999 1",
"output": "9999999990"
},
{
"input": "999999990 8",
"output": "9999999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "100000 1",
"output": "100000"
},
{
"input": "8 3",
"output": "1000"
},
{
"input": "16768 6",
"output": "262000000"
},
{
"input": "123456789 1",
"output": "1234567890"
},
{
"input": "2 8",
"output": "100000000"
},
{
"input": "999999937 8",
"output": "99999993700000000"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "2000000 7",
"output": "10000000"
},
{
"input": "1999998 2",
"output": "99999900"
},
{
"input": "125 3",
"output": "1000"
}
] | 1,553,602,653 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 | entrada = input()
a = int(entrada.split()[0])
k = int(entrada.split()[1])
#fatorar: colocar o numero em produto de numeros primos(forma fatorada)
def fatorar(x): #simulado-> fatorar(6)
A=[] #A=[]
for y in range(2,x): #for y in range(2,6): y=[2,3,4,5]
while x%y==0: #enquanto resto da divisao 6/y for 0:
x=x/y #x=6/y-> 6/2,6/3,6/4,6/5-> 6/3=3 e 3/3=1, por isso usar while.
A.append(y) #A=[6/2,6/3,3/3]=[3,2,1]
if sum(A)==0: #se x fosse numero primo, a sua forma fatoriada seria ele mesmo.
A.append(x) #se sum(A)==0 i.e, x%y nunca é 0, entao x é primo
return A
if(k <= 1):
print(a)
else:
s = 10**k
fatoresa = fatorar(a)
mmc = a*s
for i in fatoresa:
if s%i == 0:
mmc = int(mmc/i)
print(mmc) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*.
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Output Specification:
Print the *k*-rounding of *n*.
Demo Input:
['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n']
Demo Output:
['30000\n', '10000\n', '38101\n', '12345678900000000\n']
Note:
none | ```python
entrada = input()
a = int(entrada.split()[0])
k = int(entrada.split()[1])
#fatorar: colocar o numero em produto de numeros primos(forma fatorada)
def fatorar(x): #simulado-> fatorar(6)
A=[] #A=[]
for y in range(2,x): #for y in range(2,6): y=[2,3,4,5]
while x%y==0: #enquanto resto da divisao 6/y for 0:
x=x/y #x=6/y-> 6/2,6/3,6/4,6/5-> 6/3=3 e 3/3=1, por isso usar while.
A.append(y) #A=[6/2,6/3,3/3]=[3,2,1]
if sum(A)==0: #se x fosse numero primo, a sua forma fatoriada seria ele mesmo.
A.append(x) #se sum(A)==0 i.e, x%y nunca é 0, entao x é primo
return A
if(k <= 1):
print(a)
else:
s = 10**k
fatoresa = fatorar(a)
mmc = a*s
for i in fatoresa:
if s%i == 0:
mmc = int(mmc/i)
print(mmc)
``` | 0 |
|
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (*n*<=-<=1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1,<=2,<=1] after the first step, the sequence [1,<=2,<=1,<=3,<=1,<=2,<=1] after the second step.
The task is to find the value of the element with index *k* (the elements are numbered from 1) in the obtained sequence, i. e. after (*n*<=-<=1) steps.
Please help Chloe to solve the problem! | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 671088640",
"output": "28"
},
{
"input": "38 137438953472",
"output": "38"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "3 3",
"output": "1"
},
{
"input": "4 12",
"output": "3"
},
{
"input": "8 224",
"output": "6"
},
{
"input": "13 1368",
"output": "4"
},
{
"input": "16 49152",
"output": "15"
},
{
"input": "19 1024",
"output": "11"
},
{
"input": "24 15204352",
"output": "20"
},
{
"input": "27 6586544",
"output": "5"
},
{
"input": "31 536870912",
"output": "30"
},
{
"input": "38 94489280512",
"output": "34"
},
{
"input": "42 215268308020",
"output": "3"
},
{
"input": "42 3452074721280",
"output": "21"
},
{
"input": "46 34394312982528",
"output": "15"
},
{
"input": "48 133865540681728",
"output": "39"
},
{
"input": "49 76541041985542",
"output": "2"
},
{
"input": "49 104822971826176",
"output": "34"
},
{
"input": "49 351843720888320",
"output": "47"
},
{
"input": "50 743042492421629",
"output": "1"
},
{
"input": "50 666266740436818",
"output": "2"
},
{
"input": "50 704239287953456",
"output": "5"
},
{
"input": "50 116938486513664",
"output": "17"
},
{
"input": "50 806423059496960",
"output": "37"
},
{
"input": "50 985162418487296",
"output": "48"
},
{
"input": "50 844424930131968",
"output": "49"
},
{
"input": "50 562949953421312",
"output": "50"
},
{
"input": "50 1",
"output": "1"
},
{
"input": "50 1125899906842623",
"output": "1"
},
{
"input": "50 1125899906842620",
"output": "3"
},
{
"input": "39 549755813887",
"output": "1"
},
{
"input": "50 100000000000",
"output": "12"
}
] | 1,642,921,961 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 93 | 0 | def getAns(n, k):
c = 1 << (n - 1)
if k == c: return n
if k < c: return getAns(n - 1, k)
return getAns(n - 1, k - c)
if __name__ == '__main__':
n, k = map(int, input().strip().split())
print(getAns(n, k))
| Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (*n*<=-<=1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1,<=2,<=1] after the first step, the sequence [1,<=2,<=1,<=3,<=1,<=2,<=1] after the second step.
The task is to find the value of the element with index *k* (the elements are numbered from 1) in the obtained sequence, i. e. after (*n*<=-<=1) steps.
Please help Chloe to solve the problem!
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1).
Output Specification:
Print single integer — the integer at the *k*-th position in the obtained sequence.
Demo Input:
['3 2\n', '4 8\n']
Demo Output:
['2', '4']
Note:
In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | ```python
def getAns(n, k):
c = 1 << (n - 1)
if k == c: return n
if k < c: return getAns(n - 1, k)
return getAns(n - 1, k - c)
if __name__ == '__main__':
n, k = map(int, input().strip().split())
print(getAns(n, k))
``` | 3 |
|
776 | C | Molly's Chemicals | PROGRAMMING | 1,800 | [
"binary search",
"brute force",
"data structures",
"implementation",
"math"
] | null | null | Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of *k*. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments. | The first line of input contains two integers, *n* and *k*, the number of chemicals and the number, such that the total affection value is a non-negative power of this number *k*. (1<=≤<=*n*<=≤<=105, 1<=≤<=|*k*|<=≤<=10).
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — affection values of chemicals. | Output a single integer — the number of valid segments. | [
"4 2\n2 2 2 2\n",
"4 -3\n3 -6 -3 12\n"
] | [
"8\n",
"3\n"
] | Do keep in mind that *k*<sup class="upper-index">0</sup> = 1.
In the first sample, Molly can get following different affection values:
- 2: segments [1, 1], [2, 2], [3, 3], [4, 4]; - 4: segments [1, 2], [2, 3], [3, 4]; - 6: segments [1, 3], [2, 4]; - 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of *k* = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | 1,500 | [
{
"input": "4 2\n2 2 2 2",
"output": "8"
},
{
"input": "4 -3\n3 -6 -3 12",
"output": "3"
},
{
"input": "14 -9\n-2 -4 62 53 90 41 35 21 85 74 85 57 10 39",
"output": "0"
},
{
"input": "20 9\n90 21 -6 -61 14 -21 -17 -65 -84 -75 -48 56 67 -50 16 65 -79 -61 92 85",
"output": "1"
},
{
"input": "89 -7\n5972 4011 3914 670 3727 2913 6935 6927 2118 6645 7141 3585 9811 2859 459 8870 6578 8667 468 5152 3241 7455 7323 8817 4866 1040 5102 9146 621 5002 396 4967 9822 4200 3899 4416 5225 9415 9606 4802 5589 1798 9094 5453 7163 264 1026 6187 3918 4237 -17 4306 8960 3321 2927 9205 6248 7607 564 364 3503 8149 2235 8278 6249 3987 524 5718 9359 3549 1474 9204 3870 6996 3932 8295 612 6310 4461 1129 6441 3465 4654 7583 3274 6309 4831 4918 558",
"output": "0"
},
{
"input": "10 2\n2 4 8 16 32 64 128 256 512 1024",
"output": "10"
},
{
"input": "10 1\n-1 1 -1 1 -1 1 -1 1 -1 1",
"output": "15"
},
{
"input": "32 2\n8 16384 32768 65536 32 8388608 1048576 16777216 65536 8 16384 128 2097152 1024 16777216 4 8192 8388608 65536 1024 1024 16 8 16 128 2 1024 128 8 33554432 32768 2048",
"output": "33"
},
{
"input": "1 2\n2",
"output": "1"
},
{
"input": "14 2\n2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "45"
},
{
"input": "2 1\n1 1",
"output": "2"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "10"
},
{
"input": "4 1\n1 1 1 1",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "3"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "10 -1\n1 0 -1 1 0 -1 1 0 -1 1",
"output": "28"
},
{
"input": "4 1\n-1 -2 3 1",
"output": "3"
},
{
"input": "26 -1\n0 0 1 1 -1 -1 0 0 1 0 0 0 -1 1 0 0 -1 1 -1 1 -1 1 0 0 5 -4",
"output": "168"
},
{
"input": "1 -1\n-1",
"output": "1"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "1 2\n1048576",
"output": "1"
},
{
"input": "4 -1\n1 1 1 1",
"output": "4"
},
{
"input": "5 -1\n1 1 1 1 1",
"output": "5"
},
{
"input": "33 2\n536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912",
"output": "141"
},
{
"input": "1 1\n-1",
"output": "0"
}
] | 1,625,461,320 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 17 | 577 | 14,745,600 | from sys import stdin
input = stdin.readline
def f(a, k):
pref = 0
ans = 0
d = {0: 1}
t = 1
s = sum(a)
fac = [1]
for i in range(50):
t *= k
fac.append(t)
for i in a:
pref += i
for num in fac:
need = pref - num
ans += d.get(need, 0)
d[pref] = d.get(pref, 0) + 1
return ans
n, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
print(f(a, k)) | Title: Molly's Chemicals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of *k*. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input Specification:
The first line of input contains two integers, *n* and *k*, the number of chemicals and the number, such that the total affection value is a non-negative power of this number *k*. (1<=≤<=*n*<=≤<=105, 1<=≤<=|*k*|<=≤<=10).
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — affection values of chemicals.
Output Specification:
Output a single integer — the number of valid segments.
Demo Input:
['4 2\n2 2 2 2\n', '4 -3\n3 -6 -3 12\n']
Demo Output:
['8\n', '3\n']
Note:
Do keep in mind that *k*<sup class="upper-index">0</sup> = 1.
In the first sample, Molly can get following different affection values:
- 2: segments [1, 1], [2, 2], [3, 3], [4, 4]; - 4: segments [1, 2], [2, 3], [3, 4]; - 6: segments [1, 3], [2, 4]; - 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of *k* = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | ```python
from sys import stdin
input = stdin.readline
def f(a, k):
pref = 0
ans = 0
d = {0: 1}
t = 1
s = sum(a)
fac = [1]
for i in range(50):
t *= k
fac.append(t)
for i in a:
pref += i
for num in fac:
need = pref - num
ans += d.get(need, 0)
d[pref] = d.get(pref, 0) + 1
return ans
n, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
print(f(a, k))
``` | 0 |
|
989 | B | A Tide of Riverscape | PROGRAMMING | 1,200 | [
"constructive algorithms",
"strings"
] | null | null | "Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$. | The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character. | Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)). | [
"10 7\n1.0.1.0.1.\n",
"10 6\n1.0.1.1000\n",
"10 9\n1........1\n"
] | [
"1000100010\n",
"1001101000\n",
"No\n"
] | In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | 1,000 | [
{
"input": "10 7\n1.0.1.0.1.",
"output": "1000100010"
},
{
"input": "10 6\n1.0.1.1000",
"output": "1001101000"
},
{
"input": "10 9\n1........1",
"output": "No"
},
{
"input": "1 1\n.",
"output": "No"
},
{
"input": "5 1\n0...1",
"output": "00001"
},
{
"input": "17 10\n..1.100..1..0.100",
"output": "00101000010000100"
},
{
"input": "2 1\n0.",
"output": "01"
},
{
"input": "2 1\n..",
"output": "01"
},
{
"input": "3 1\n.0.",
"output": "001"
},
{
"input": "3 1\n00.",
"output": "001"
},
{
"input": "3 2\n0..",
"output": "001"
},
{
"input": "3 2\n0.0",
"output": "No"
},
{
"input": "3 2\n1..",
"output": "100"
},
{
"input": "3 2\n.1.",
"output": "011"
},
{
"input": "3 2\n1.0",
"output": "100"
},
{
"input": "3 3\n1..",
"output": "No"
},
{
"input": "3 3\n.00",
"output": "No"
},
{
"input": "5 3\n0.000",
"output": "01000"
},
{
"input": "10 6\n10010.1001",
"output": "No"
},
{
"input": "75 38\n00.0.1.0.0110.1.00010..100.1110..110..00.0.1.0.0110.1.00010..100.1110..110.",
"output": "000001000011001000010001000111000110000000010000110010000100010001110001101"
},
{
"input": "128 108\n01100.110...000.0001.1.11.11.010010.01100.0.1.01.0.0011.11001.000101...1.0.0..100.0110.0110.0.0101.0.0.0001.01100.110...100.0001",
"output": "01100011000000000001010110110010010001100000100100000110110010000101000100000010000110001100000101000000001001100011000010000001"
},
{
"input": "5 4\n.101.",
"output": "01011"
},
{
"input": "4 2\n101.",
"output": "1011"
},
{
"input": "5 4\n.1011",
"output": "01011"
},
{
"input": "2 1\n..",
"output": "01"
},
{
"input": "5 3\n00.11",
"output": "00011"
},
{
"input": "10 8\n1111.00000",
"output": "1111000000"
},
{
"input": "10 3\n11111111.1",
"output": "1111111101"
},
{
"input": "3 2\n1.0",
"output": "100"
},
{
"input": "6 4\n11..10",
"output": "110010"
},
{
"input": "4 2\n.111",
"output": "0111"
},
{
"input": "3 2\n01.",
"output": "011"
},
{
"input": "5 4\n10.00",
"output": "10000"
},
{
"input": "10 9\n1........0",
"output": "1000000000"
},
{
"input": "2 1\n0.",
"output": "01"
},
{
"input": "8 4\n111111..",
"output": "11111100"
},
{
"input": "3 2\n0.1",
"output": "001"
},
{
"input": "4 1\n111.",
"output": "1110"
},
{
"input": "3 1\n01.",
"output": "010"
},
{
"input": "10 7\n000....111",
"output": "0000000111"
}
] | 1,528,725,608 | 1,508 | Python 3 | OK | TESTS | 59 | 109 | 0 | n, p = map(int, input().split())
s = input()
A = [list() for i in range(p)]
for i in range(len(s)):
A[(i % p)].append(s[i])
bad_index = -1
change = False
change1 = '0'
change2 = '0'
for i in range(p):
if '.' in A[i] and A[i] != ['.']:
bad_index = i
change = True
if '0' in A[i]:
change1 = '1'
change2 = '0'
else:
change1 = '0'
change2 = '1'
if '0' in A[i] and '1' in A[i]:
bad_index = i
change = False
if bad_index == -1:
print('No')
else:
ans = list(s)
cnt = 0
for i in range(len(s)):
if i % p == bad_index:
if not change:
if s[i] == '.':
ans[i] = '0'
if change:
if s[i] == '.':
if cnt == 0:
ans[i] = change1
cnt += 1
else:
ans[i] = change2
else:
if s[i] == '.':
ans[i] = change1
print(''.join(ans)) | Title: A Tide of Riverscape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$.
Input Specification:
The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character.
Output Specification:
Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Demo Input:
['10 7\n1.0.1.0.1.\n', '10 6\n1.0.1.1000\n', '10 9\n1........1\n']
Demo Output:
['1000100010\n', '1001101000\n', 'No\n']
Note:
In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | ```python
n, p = map(int, input().split())
s = input()
A = [list() for i in range(p)]
for i in range(len(s)):
A[(i % p)].append(s[i])
bad_index = -1
change = False
change1 = '0'
change2 = '0'
for i in range(p):
if '.' in A[i] and A[i] != ['.']:
bad_index = i
change = True
if '0' in A[i]:
change1 = '1'
change2 = '0'
else:
change1 = '0'
change2 = '1'
if '0' in A[i] and '1' in A[i]:
bad_index = i
change = False
if bad_index == -1:
print('No')
else:
ans = list(s)
cnt = 0
for i in range(len(s)):
if i % p == bad_index:
if not change:
if s[i] == '.':
ans[i] = '0'
if change:
if s[i] == '.':
if cnt == 0:
ans[i] = change1
cnt += 1
else:
ans[i] = change2
else:
if s[i] == '.':
ans[i] = change1
print(''.join(ans))
``` | 3 |
|
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally. | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6",
"output": "100"
},
{
"input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611",
"output": "127184126241438168"
},
{
"input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974",
"output": "922371547895579571"
},
{
"input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410",
"output": "663200522440413120"
},
{
"input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682",
"output": "883931400924882950"
},
{
"input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106",
"output": "910849554065102112"
},
{
"input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544",
"output": "504117593849498724"
},
{
"input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617",
"output": "534123411186652380"
},
{
"input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478",
"output": "848714444125692276"
},
{
"input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867",
"output": "866064226130454915"
},
{
"input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081",
"output": "501307028237810934"
},
{
"input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625",
"output": "822104826327386019"
},
{
"input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542",
"output": "941783658451562540"
},
{
"input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604",
"output": "-1288212069119760"
},
{
"input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017",
"output": "-18990884587723"
},
{
"input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528",
"output": "-1464096896176096"
},
{
"input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396",
"output": "-120782803247464704"
},
{
"input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983",
"output": "-640647347631440"
},
{
"input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "-1000000000000000000"
}
] | 1,571,962,840 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 1,536,000 | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = int(1e9) + 1
for i in range(n):
s = int(-1e9) - 1
for j in range(n):
if i == j:
continue
for k in range(m):
s = max(s, a[j] * b[k])
t = min(t, s)
print(t)
| Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally.
Input Specification:
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109.
Output Specification:
Print a single integer — the brightness of the chosen pair.
Demo Input:
['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n']
Demo Output:
['252\n', '2\n']
Note:
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = int(1e9) + 1
for i in range(n):
s = int(-1e9) - 1
for j in range(n):
if i == j:
continue
for k in range(m):
s = max(s, a[j] * b[k])
t = min(t, s)
print(t)
``` | 0 |
|
593 | A | 2Char | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.
Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length. | The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input. | Print a single integer — the maximum possible total length of words in Andrew's article. | [
"4\nabb\ncacc\naaa\nbbb\n",
"5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n"
] | [
"9",
"6"
] | In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}. | 250 | [
{
"input": "4\nabb\ncacc\naaa\nbbb",
"output": "9"
},
{
"input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa",
"output": "6"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\nz\nz",
"output": "2"
},
{
"input": "5\nabcde\nfghij\nklmno\npqrst\nuvwxy",
"output": "0"
},
{
"input": "6\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg",
"output": "36"
},
{
"input": "6\naaaaaa\naaaaaa\nbbbbbb\nbbbbbb\naaabbb\nababab",
"output": "36"
},
{
"input": "1\nabc",
"output": "0"
},
{
"input": "2\nabc\nbca",
"output": "0"
},
{
"input": "3\nab\nba\nzzz",
"output": "4"
},
{
"input": "3\nab\nba\nzzzzz",
"output": "5"
},
{
"input": "5\nzzz\nzzzz\nzz\nz\naaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "37"
},
{
"input": "26\nq\nw\ne\nr\nt\ny\nu\ni\no\np\na\ns\nd\nf\ng\nh\nj\nk\nl\nz\nx\nc\nv\nb\nn\nm",
"output": "2"
},
{
"input": "5\nzzz\nzzzz\nzz\nz\naaaaaaaaaaaaaaaaaaaaaaaaaaaf",
"output": "28"
},
{
"input": "7\npavel\nerika\nalexxxxxxx\ngracio\nzhenya\nsudarev\nchelyaba",
"output": "0"
},
{
"input": "31\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml",
"output": "0"
},
{
"input": "5\nzloyfreid\ngraciocode\nschooldiary\nkazakov\nevgesha",
"output": "0"
},
{
"input": "4\nurkop\nvisualac\ngnutl\nwtf",
"output": "0"
},
{
"input": "3\naa\nb\nccc",
"output": "5"
},
{
"input": "3\na\nbd\ncaaaaaaa",
"output": "9"
},
{
"input": "4\naa\nax\nay\nxxxx",
"output": "8"
},
{
"input": "5\nc\nbb\ne\ndd\nf",
"output": "4"
},
{
"input": "2\naaaaa\naaaaa",
"output": "10"
}
] | 1,446,662,460 | 6,960 | Python 3 | RUNTIME_ERROR | PRETESTS | 4 | 46 | 204,800 | def cnt_letters(x):
if str.isdigit(x[0]) or (x[0] == '\n'):
return 42
d = {}
cnt = 0
for c in x:
if not (c in d.keys()):
d[c] = 0
cnt += 1
else:
d[c] += 1
return cnt
import sys
words = []
for x in sys.stdin.readlines():
if cnt_letters(x.strip()) < 3:
words.append(x.strip())
d = {}
for x in words:
for c in x:
if not c in d.keys():
d[c] = 0
else:
d[c] += 1
d = sorted(d.items(), key=lambda x: -x[1])
maxl = d[0][0]
if len(d) > 9000:
smaxl = list(d.keys())[1]
else:
smaxl = ''
res = 0
for x in words:
if cnt_letters(x) == 2:
if str.find(x, maxl) > -1 and str.find(x, smaxl) > -1:
res += len(x)
else:
if str.find(x, maxl) > -1 or str.find(x, smaxl) > -1:
res += len(x)
print(res) | Title: 2Char
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.
Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.
Input Specification:
The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.
Output Specification:
Print a single integer — the maximum possible total length of words in Andrew's article.
Demo Input:
['4\nabb\ncacc\naaa\nbbb\n', '5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n']
Demo Output:
['9', '6']
Note:
In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}. | ```python
def cnt_letters(x):
if str.isdigit(x[0]) or (x[0] == '\n'):
return 42
d = {}
cnt = 0
for c in x:
if not (c in d.keys()):
d[c] = 0
cnt += 1
else:
d[c] += 1
return cnt
import sys
words = []
for x in sys.stdin.readlines():
if cnt_letters(x.strip()) < 3:
words.append(x.strip())
d = {}
for x in words:
for c in x:
if not c in d.keys():
d[c] = 0
else:
d[c] += 1
d = sorted(d.items(), key=lambda x: -x[1])
maxl = d[0][0]
if len(d) > 9000:
smaxl = list(d.keys())[1]
else:
smaxl = ''
res = 0
for x in words:
if cnt_letters(x) == 2:
if str.find(x, maxl) > -1 and str.find(x, smaxl) > -1:
res += len(x)
else:
if str.find(x, maxl) > -1 or str.find(x, smaxl) > -1:
res += len(x)
print(res)
``` | -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,660,801,846 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 409,600 | n , m = map(int , input().split())
a = {}
for i in range(m):
aa, bb = input().split()
a[aa] = bb
for i in input().split():
print(min(i , a[i], key = len ) , end=' ') | 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())
a = {}
for i in range(m):
aa, bb = input().split()
a[aa] = bb
for i in input().split():
print(min(i , a[i], key = len ) , end=' ')
``` | 3 |
|
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,666,550,125 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 62 | 0 |
t = int(input())
rj = []
for i in range(t):
a = int(input())
if a < 60:
rj.append('NO')
else:
n = 3
kut = ((n-2)*180)/n
while a >= kut:
if a == kut:
rj.append('YES')
break
n+=1
kut = ((n-2)*180)/n
else:
rj.append('NO')
print(*rj, sep = "\n") | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
Input Specification:
The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees.
Output Specification:
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
Demo Input:
['3\n30\n60\n90\n']
Demo Output:
['NO\nYES\nYES\n']
Note:
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | ```python
t = int(input())
rj = []
for i in range(t):
a = int(input())
if a < 60:
rj.append('NO')
else:
n = 3
kut = ((n-2)*180)/n
while a >= kut:
if a == kut:
rj.append('YES')
break
n+=1
kut = ((n-2)*180)/n
else:
rj.append('NO')
print(*rj, sep = "\n")
``` | 3 |
|
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds.
If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows:
1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game. | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw. | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
{
"input": "8 8 1 1 1",
"output": "Second"
},
{
"input": "15 14 32 65 28",
"output": "First"
},
{
"input": "894 197 325 232 902",
"output": "First"
},
{
"input": "1 2 8 8 5",
"output": "Friendship"
},
{
"input": "37 261 207 1 1000",
"output": "Friendship"
},
{
"input": "29 344 406 900 1",
"output": "Friendship"
},
{
"input": "1 2 8 9 8",
"output": "First"
},
{
"input": "2 9 8 8 9",
"output": "Friendship"
},
{
"input": "213 480 811 134 745",
"output": "First"
},
{
"input": "2 313 856 964 421",
"output": "Friendship"
},
{
"input": "1 10 2 6 10",
"output": "Friendship"
},
{
"input": "2 7 6 2 3",
"output": "Friendship"
},
{
"input": "637 324 69 612 998",
"output": "Second"
},
{
"input": "13 849 819 723 918",
"output": "Friendship"
},
{
"input": "9 5 7 8 7",
"output": "First"
},
{
"input": "6 5 7 10 4",
"output": "Friendship"
},
{
"input": "61 464 623 89 548",
"output": "First"
},
{
"input": "641 31 29 161 802",
"output": "Friendship"
},
{
"input": "3 3 1 6 9",
"output": "Friendship"
},
{
"input": "2 3 9 8 2",
"output": "Friendship"
},
{
"input": "485 117 368 567 609",
"output": "First"
},
{
"input": "4 202 512 995 375",
"output": "Friendship"
},
{
"input": "424 41 41 909 909",
"output": "Friendship"
},
{
"input": "884 913 263 641 265",
"output": "Second"
},
{
"input": "12 462 8 311 327",
"output": "Second"
},
{
"input": "436 306 266 493 580",
"output": "Second"
},
{
"input": "69 1 2 1 2",
"output": "First"
}
] | 1,597,752,384 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 0 | s, v1, v2, t1, t2 = map(int, input().split())
first = (2*t1) + (s*v1)
second = (2*t2) + (s*v2)
if first == second:
print("Friendship")
elif first > second:
print("Second")
else:
print("First") | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds.
If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows:
1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game.
Input Specification:
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
Output Specification:
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
Demo Input:
['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n']
Demo Output:
['First\n', 'Second\n', 'Friendship\n']
Note:
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw. | ```python
s, v1, v2, t1, t2 = map(int, input().split())
first = (2*t1) + (s*v1)
second = (2*t2) + (s*v2)
if first == second:
print("Friendship")
elif first > second:
print("Second")
else:
print("First")
``` | 3 |
|
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20 1 80",
"output": "1 20 40 60 80 100 "
},
{
"input": "10\n10 8 6 7 5 3 4 2 9 1",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 "
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 1 2 3 4 6 7 7 8 9 "
},
{
"input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59",
"output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 "
},
{
"input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12",
"output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 "
},
{
"input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84",
"output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 "
},
{
"input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1",
"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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 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": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52",
"output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 "
},
{
"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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1",
"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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3",
"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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 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": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3",
"output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 "
},
{
"input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32",
"output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 "
},
{
"input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41",
"output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 "
},
{
"input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82",
"output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 "
},
{
"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": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "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": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 "
},
{
"input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 "
},
{
"input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88",
"output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 "
},
{
"input": "100\n100 51 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"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 2 51 100 "
},
{
"input": "10\n100 90 80 70 60 50 40 30 20 10",
"output": "10 20 30 40 50 60 70 80 90 100 "
},
{
"input": "1\n10",
"output": "10 "
}
] | 1,694,881,200 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | n = int(input())
m = input().split()
x = ''
for i in range(n):
m[i] = int(m[i])
for i in sorted(m):
x += str(i)+' '
print(x) | Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
Input Specification:
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output Specification:
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
Demo Input:
['4\n3 2 1 2\n', '3\n2 3 8\n']
Demo Output:
['1 2 2 3 \n', '2 3 8 \n']
Note:
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | ```python
n = int(input())
m = input().split()
x = ''
for i in range(n):
m[i] = int(m[i])
for i in sorted(m):
x += str(i)+' '
print(x)
``` | 3 |
|
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 1,638,892,647 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 204,800 | n=int(input())
str1=str(input())
a=str1.count('0')
b=str1.count('1')
print(abs(a-b))
| Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n=int(input())
str1=str(input())
a=str1.count('0')
b=str1.count('1')
print(abs(a-b))
``` | 3 |
|
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 539 896 668 36 896",
"output": "YES"
},
{
"input": "7\n674 712 674 674 674 674 674",
"output": "NO"
},
{
"input": "8\n742 742 742 742 742 289 742 742",
"output": "NO"
},
{
"input": "9\n730 351 806 806 806 630 85 757 967",
"output": "YES"
},
{
"input": "10\n324 539 83 440 834 640 440 440 440 440",
"output": "YES"
},
{
"input": "7\n925 830 925 98 987 162 356",
"output": "YES"
},
{
"input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808",
"output": "YES"
},
{
"input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94",
"output": "YES"
},
{
"input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402",
"output": "NO"
},
{
"input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187",
"output": "YES"
},
{
"input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103",
"output": "YES"
},
{
"input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925",
"output": "NO"
},
{
"input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353",
"output": "YES"
},
{
"input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285",
"output": "NO"
},
{
"input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99",
"output": "YES"
},
{
"input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26",
"output": "YES"
},
{
"input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516",
"output": "YES"
},
{
"input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314",
"output": "NO"
},
{
"input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800",
"output": "NO"
},
{
"input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317",
"output": "NO"
},
{
"input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784",
"output": "YES"
},
{
"input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474",
"output": "YES"
},
{
"input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499",
"output": "NO"
},
{
"input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816",
"output": "NO"
},
{
"input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167",
"output": "YES"
},
{
"input": "100\n1000 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",
"output": "NO"
},
{
"input": "99\n1000 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",
"output": "NO"
},
{
"input": "100\n1000 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "YES"
},
{
"input": "99\n1000 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "YES"
},
{
"input": "2\n1 1",
"output": "NO"
},
{
"input": "1\n1000",
"output": "YES"
},
{
"input": "12\n2 2 4 4 4 4 6 6 6 6 6 6",
"output": "YES"
}
] | 1,698,810,716 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 122 | 2,867,200 | from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
def answer():
count = [0 for i in range(n + 1)]
for i in range(n):
count[a[i]] += 1
if(max(count) > ((n + 1) // 2)):
return 'NO'
return 'YES'
for T in range(1):
n = int(input())
a = inp()
print(answer())
| Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
Output Specification:
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
Demo Input:
['1\n1\n', '3\n1 1 2\n', '4\n7 7 7 7\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | ```python
from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
def answer():
count = [0 for i in range(n + 1)]
for i in range(n):
count[a[i]] += 1
if(max(count) > ((n + 1) // 2)):
return 'NO'
return 'YES'
for T in range(1):
n = int(input())
a = inp()
print(answer())
``` | -1 |
|
359 | C | Prime Number | PROGRAMMING | 1,900 | [
"math",
"number theory"
] | null | null | Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=...<=+<=*a**n*. Now Simon wants to reduce the resulting fraction.
Help him, find the greatest common divisor of numbers *s* and *t*. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (109<=+<=7). | The first line contains two positive integers *n* and *x* (1<=≤<=*n*<=≤<=105, 2<=≤<=*x*<=≤<=109) — the size of the array and the prime number.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*<=≤<=109). | Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"2 2\n2 2\n",
"3 3\n1 2 3\n",
"2 2\n29 29\n",
"4 5\n0 0 0 0\n"
] | [
"8\n",
"27\n",
"73741817\n",
"1\n"
] | In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7745f7cc87c6c5f753e3414fad9baa3b1e3fea48.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 8.
In the second sample, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/acb3d7990f024100be499bcb59828fa6e23a867d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.
In the third sample the answer to the problem is 1073741824 *mod* 1000000007 = 73741817.
In the fourth sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/05a5fca3fb4690369838ff6dfeda521c959aa937.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 1. | 1,500 | [
{
"input": "2 2\n2 2",
"output": "8"
},
{
"input": "3 3\n1 2 3",
"output": "27"
},
{
"input": "2 2\n29 29",
"output": "73741817"
},
{
"input": "4 5\n0 0 0 0",
"output": "1"
},
{
"input": "1 2\n1000000000",
"output": "1"
},
{
"input": "26 2\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2",
"output": "8"
},
{
"input": "26 7\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2",
"output": "49"
},
{
"input": "3 2\n0 1 1",
"output": "4"
},
{
"input": "1 127\n1000000000",
"output": "1"
},
{
"input": "1 800000011\n800000011",
"output": "1"
},
{
"input": "1 800000011\n999999999",
"output": "1"
},
{
"input": "3 3\n1 1 1",
"output": "27"
}
] | 1,689,442,033 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689442033.2122488")# 1689442033.2122836 | Title: Prime Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=...<=+<=*a**n*. Now Simon wants to reduce the resulting fraction.
Help him, find the greatest common divisor of numbers *s* and *t*. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (109<=+<=7).
Input Specification:
The first line contains two positive integers *n* and *x* (1<=≤<=*n*<=≤<=105, 2<=≤<=*x*<=≤<=109) — the size of the array and the prime number.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*<=≤<=109).
Output Specification:
Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7).
Demo Input:
['2 2\n2 2\n', '3 3\n1 2 3\n', '2 2\n29 29\n', '4 5\n0 0 0 0\n']
Demo Output:
['8\n', '27\n', '73741817\n', '1\n']
Note:
In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7745f7cc87c6c5f753e3414fad9baa3b1e3fea48.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 8.
In the second sample, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/acb3d7990f024100be499bcb59828fa6e23a867d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.
In the third sample the answer to the problem is 1073741824 *mod* 1000000007 = 73741817.
In the fourth sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/05a5fca3fb4690369838ff6dfeda521c959aa937.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 1. | ```python
print("_RANDOM_GUESS_1689442033.2122488")# 1689442033.2122836
``` | 0 |
|
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv",
"output": "NO"
},
{
"input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "YES"
},
{
"input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod",
"output": "NO"
},
{
"input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl",
"output": "YES"
},
{
"input": "18 6\njzwtnkvmscqhmdlsxy",
"output": "YES"
},
{
"input": "21 2\nfscegcqgzesefghhwcexs",
"output": "NO"
},
{
"input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc",
"output": "YES"
},
{
"input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd",
"output": "YES"
},
{
"input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv",
"output": "YES"
},
{
"input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul",
"output": "YES"
},
{
"input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii",
"output": "NO"
},
{
"input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq",
"output": "YES"
},
{
"input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb",
"output": "YES"
},
{
"input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc",
"output": "YES"
},
{
"input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab",
"output": "YES"
},
{
"input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia",
"output": "NO"
},
{
"input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf",
"output": "YES"
},
{
"input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb",
"output": "YES"
},
{
"input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa",
"output": "NO"
},
{
"input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo",
"output": "YES"
},
{
"input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib",
"output": "YES"
},
{
"input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf",
"output": "YES"
},
{
"input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci",
"output": "YES"
},
{
"input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn",
"output": "YES"
},
{
"input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev",
"output": "YES"
},
{
"input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss",
"output": "YES"
},
{
"input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs",
"output": "NO"
},
{
"input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc",
"output": "NO"
},
{
"input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi",
"output": "NO"
},
{
"input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah",
"output": "NO"
},
{
"input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka",
"output": "YES"
},
{
"input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq",
"output": "YES"
},
{
"input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb",
"output": "YES"
},
{
"input": "14 5\nfssmmsfffmfmmm",
"output": "NO"
},
{
"input": "2 1\nff",
"output": "NO"
},
{
"input": "2 1\nhw",
"output": "YES"
},
{
"input": "2 2\nss",
"output": "YES"
},
{
"input": "1 1\nl",
"output": "YES"
},
{
"input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp",
"output": "YES"
},
{
"input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj",
"output": "YES"
},
{
"input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj",
"output": "YES"
},
{
"input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "YES"
},
{
"input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq",
"output": "YES"
},
{
"input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt",
"output": "YES"
},
{
"input": "1 2\na",
"output": "YES"
},
{
"input": "3 1\nabb",
"output": "NO"
},
{
"input": "2 1\naa",
"output": "NO"
},
{
"input": "2 1\nab",
"output": "YES"
},
{
"input": "6 2\naaaaaa",
"output": "NO"
},
{
"input": "8 4\naaaaaaaa",
"output": "NO"
},
{
"input": "4 2\naaaa",
"output": "NO"
},
{
"input": "4 3\naaaa",
"output": "NO"
},
{
"input": "1 3\na",
"output": "YES"
},
{
"input": "4 3\nzzzz",
"output": "NO"
},
{
"input": "4 1\naaaa",
"output": "NO"
},
{
"input": "3 4\nabc",
"output": "YES"
},
{
"input": "2 5\nab",
"output": "YES"
},
{
"input": "2 4\nab",
"output": "YES"
},
{
"input": "1 10\na",
"output": "YES"
},
{
"input": "5 2\nzzzzz",
"output": "NO"
},
{
"input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO"
},
{
"input": "4 1\nabab",
"output": "NO"
},
{
"input": "4 1\nabcb",
"output": "NO"
},
{
"input": "4 2\nabbb",
"output": "NO"
},
{
"input": "5 2\nabccc",
"output": "NO"
},
{
"input": "2 3\nab",
"output": "YES"
},
{
"input": "4 3\nbbbs",
"output": "YES"
},
{
"input": "10 2\nazzzzzzzzz",
"output": "NO"
},
{
"input": "1 2\nb",
"output": "YES"
},
{
"input": "1 3\nb",
"output": "YES"
},
{
"input": "4 5\nabcd",
"output": "YES"
},
{
"input": "4 6\naabb",
"output": "YES"
},
{
"input": "5 2\naaaab",
"output": "NO"
},
{
"input": "3 5\naaa",
"output": "YES"
},
{
"input": "5 3\nazzzz",
"output": "NO"
},
{
"input": "4 100\naabb",
"output": "YES"
},
{
"input": "3 10\naaa",
"output": "YES"
},
{
"input": "3 4\naaa",
"output": "YES"
},
{
"input": "12 5\naaaaabbbbbbb",
"output": "NO"
},
{
"input": "5 2\naabbb",
"output": "NO"
},
{
"input": "10 5\nzzzzzzzzzz",
"output": "NO"
},
{
"input": "2 4\naa",
"output": "YES"
},
{
"input": "1 5\na",
"output": "YES"
},
{
"input": "10 5\naaaaaaaaaa",
"output": "NO"
},
{
"input": "6 3\naaaaaa",
"output": "NO"
},
{
"input": "7 1\nabcdeee",
"output": "NO"
},
{
"input": "18 3\naaaaaabbbbbbcccccc",
"output": "NO"
},
{
"input": "8 2\naabbccdd",
"output": "YES"
},
{
"input": "4 2\nzzzz",
"output": "NO"
},
{
"input": "4 2\nabaa",
"output": "NO"
},
{
"input": "3 2\naaa",
"output": "NO"
},
{
"input": "3 1\nzzz",
"output": "NO"
},
{
"input": "5 4\nzzzzz",
"output": "NO"
},
{
"input": "6 2\naabbbc",
"output": "NO"
},
{
"input": "3 6\naaa",
"output": "YES"
},
{
"input": "2 1\nzz",
"output": "NO"
},
{
"input": "10 3\naaaeeeeeee",
"output": "NO"
},
{
"input": "4 5\naabb",
"output": "YES"
},
{
"input": "3 1\naaa",
"output": "NO"
},
{
"input": "5 2\naazzz",
"output": "NO"
},
{
"input": "6 2\nabbbbc",
"output": "NO"
},
{
"input": "4 2\nxxxx",
"output": "NO"
},
{
"input": "6 3\nzzzzzz",
"output": "NO"
},
{
"input": "3 2\nabb",
"output": "YES"
},
{
"input": "3 2\nzzz",
"output": "NO"
},
{
"input": "6 5\nzzzzzz",
"output": "NO"
},
{
"input": "6 3\nbcaaaa",
"output": "NO"
},
{
"input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "3 6\nabc",
"output": "YES"
}
] | 1,617,173,587 | 2,147,483,647 | PyPy 3 | OK | TESTS | 114 | 140 | 2,150,400 | import string
a , b = map(int , input().split())
s = input()
f = True
for i in string.ascii_lowercase:
if s.count(i) > b:
f = False
break
if f: print("YES")
else: print("NO") | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons.
Output Specification:
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Demo Input:
['4 2\naabb\n', '6 3\naacaab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | ```python
import string
a , b = map(int , input().split())
s = input()
f = True
for i in string.ascii_lowercase:
if s.count(i) > b:
f = False
break
if f: print("YES")
else: print("NO")
``` | 3 |
|
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
{
"input": "7\n3 2 1 6 5 7 4",
"output": "8"
},
{
"input": "8\n2 8 3 7 6 9 1 5",
"output": "4"
},
{
"input": "9\n10 5 9 3 8 7 1 2 4",
"output": "6"
},
{
"input": "10\n7 2 3 8 9 6 5 4 1 10",
"output": "11"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 4 1",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "5"
},
{
"input": "5\n3 1 4 2 5",
"output": "6"
},
{
"input": "6\n1 3 6 7 2 4",
"output": "5"
},
{
"input": "7\n1 5 4 7 2 3 6",
"output": "8"
},
{
"input": "8\n12 1 6 5 2 8 3 4",
"output": "7"
},
{
"input": "9\n3 2 7 5 6 4 1 9 10",
"output": "8"
},
{
"input": "10\n1 7 13 6 5 10 3 8 2 4",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n3000",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
},
{
"input": "2\n3000 1",
"output": "2"
}
] | 1,629,539,943 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 184 | 20,172,800 | n=int(input())
l=list(map(int,input().split(" ")))
l.sort()
for i in range(0,len(l)-1):
if (l[i+1]-l[i])!=1:
print(l[i]+1) | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output Specification:
Output the required default value for the next test index.
Demo Input:
['3\n1 7 2\n']
Demo Output:
['3\n']
Note:
none | ```python
n=int(input())
l=list(map(int,input().split(" ")))
l.sort()
for i in range(0,len(l)-1):
if (l[i+1]-l[i])!=1:
print(l[i]+1)
``` | 0 |
952 | B | A Map of the Cat | PROGRAMMING | 1,900 | [
"brute force",
"interactive"
] | null | null | If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.
You have met a cat. Can you figure out whether it's normal or grumpy? | none | none | [] | [] | Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer. | 0 | [
{
"input": "5 0 1 2 5 3 5 4 5 5",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 5 6 6 7 8 9 10 11",
"output": "Correct answer 'grumpy'"
},
{
"input": "10 6 5 7 5 6 11 5 8 9",
"output": "Correct answer 'grumpy'"
},
{
"input": "7 10 8 9 6 5 5 11 5 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 5 4 5 2 5 5 0 1 3",
"output": "Correct answer 'normal'"
},
{
"input": "0 4 3 5 5 5 2 1 5 5",
"output": "Correct answer 'normal'"
},
{
"input": "3 5 5 0 5 5 2 5 4 1",
"output": "Correct answer 'normal'"
},
{
"input": "5 4 5 1 5 5 0 5 2 3",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 1 2 5 5 4 3 0 5",
"output": "Correct answer 'normal'"
},
{
"input": "7 10 5 5 11 6 5 9 6 8",
"output": "Correct answer 'grumpy'"
},
{
"input": "6 5 10 5 5 7 8 11 9 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 5 5 5 5 0 4 2 3 1",
"output": "Correct answer 'normal'"
},
{
"input": "11 5 6 5 9 5 10 8 7 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 9 8 10 7 11 5 6 5 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 8 10 11 5 6 5 6 7 9",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 5 6 11 6 10 9 5 8 7",
"output": "Correct answer 'grumpy'"
},
{
"input": "1 5 5 2 5 0 3 5 5 4",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 2 5 4 5 3 1 0 5",
"output": "Correct answer 'normal'"
}
] | 1,617,093,818 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | certain=False
i=0
while certain==False:
print(i, flush=True)
r=input()
if r in ['cool','not bad', 'great!','don\'t touch me!', 'don\'t think so']:
certain=True
print('normal', flush=True)
elif r=='no':
i+=1
else:
certain=True
print('grumpy', flush=True)
| Title: A Map of the Cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.
You have met a cat. Can you figure out whether it's normal or grumpy?
Input Specification:
none
Output Specification:
none
Note:
Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer. | ```python
certain=False
i=0
while certain==False:
print(i, flush=True)
r=input()
if r in ['cool','not bad', 'great!','don\'t touch me!', 'don\'t think so']:
certain=True
print('normal', flush=True)
elif r=='no':
i+=1
else:
certain=True
print('grumpy', flush=True)
``` | 0 |
|
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.
He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position.
GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position. | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4 4 4 2"
},
{
"input": "1\n2000",
"output": "1"
},
{
"input": "2\n2000 2000",
"output": "1 1"
},
{
"input": "3\n500 501 502",
"output": "3 2 1"
},
{
"input": "10\n105 106 1 1 1 11 1000 999 1000 999",
"output": "6 5 8 8 8 7 1 3 1 3"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "6 5 4 3 2 1"
},
{
"input": "7\n6 5 4 3 2 1 1",
"output": "1 2 3 4 5 6 6"
},
{
"input": "8\n153 100 87 14 10 8 6 5",
"output": "1 2 3 4 5 6 7 8"
},
{
"input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10",
"output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63"
},
{
"input": "5\n1 2000 1 1 2000",
"output": "3 1 3 3 1"
}
] | 1,434,912,870 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 409,600 | n = int(input())
a = list(map(int, input().split()))
p = [0] * (max(a) + 1)
for i in range(n):
p[a[i]] += 1
col = 0
for i in range(len(p) - 1, -1, -1):
t = p[i]
p[i] = col + 1
col += t
for i in range(len(a)):
print(p[a[i]], end = ' ')
| Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.
He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position.
GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
Output Specification:
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
Demo Input:
['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n']
Demo Output:
['3 1 1\n', '1\n', '4 1 4 3 1\n']
Note:
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position. | ```python
n = int(input())
a = list(map(int, input().split()))
p = [0] * (max(a) + 1)
for i in range(n):
p[a[i]] += 1
col = 0
for i in range(len(p) - 1, -1, -1):
t = p[i]
p[i] = col + 1
col += t
for i in range(len(a)):
print(p[a[i]], end = ' ')
``` | 3 |
|
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team. | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person). | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n2 2 1 1 1",
"output": "2"
},
{
"input": "7\n1 1 2 2 1 2 1",
"output": "3"
},
{
"input": "10\n1 2 2 1 2 2 1 2 1 1",
"output": "5"
},
{
"input": "5\n2 2 2 1 2",
"output": "1"
},
{
"input": "43\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2",
"output": "10"
},
{
"input": "72\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2",
"output": "34"
},
{
"input": "64\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2",
"output": "32"
},
{
"input": "20\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2",
"output": "9"
},
{
"input": "23\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1",
"output": "11"
},
{
"input": "201\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2",
"output": "100"
},
{
"input": "247\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2",
"output": "123"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "3\n2 2 1",
"output": "1"
},
{
"input": "4\n1 1 1 2",
"output": "1"
},
{
"input": "4\n1 1 2 2",
"output": "2"
},
{
"input": "4\n1 2 2 2",
"output": "1"
},
{
"input": "4\n2 1 1 1",
"output": "1"
},
{
"input": "5\n1 1 1 1 2",
"output": "2"
},
{
"input": "14\n1 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "1"
},
{
"input": "38\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "30\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 1",
"output": "1"
},
{
"input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "26\n2 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",
"output": "1"
},
{
"input": "6\n1 1 1 2 2 2",
"output": "3"
},
{
"input": "5\n2 1 1 1 1",
"output": "2"
},
{
"input": "9\n1 1 1 1 1 1 2 2 2",
"output": "4"
},
{
"input": "10\n2 2 1 1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "2"
}
] | 1,513,669,473 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 108 | 9,523,200 | n = int(input())
list_ = list(map(int,input().split()))
nof_2 = list_.count(2)
nof_1 = list_.count(1)
sum = 0
#print(nof_1,nof_2)
if nof_2<=nof_1:
sum+=nof_2
nof_1-=nof_2
sum+=(nof_1//3)
else:
sum+=nof_1
print(sum) | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input Specification:
The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*.
Output Specification:
Print the maximum number of teams of three people the coach can form.
Demo Input:
['4\n1 1 2 1\n', '2\n2 2\n', '7\n2 2 2 1 1 1 1\n', '3\n1 1 1\n']
Demo Output:
['1\n', '0\n', '3\n', '1\n']
Note:
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person). | ```python
n = int(input())
list_ = list(map(int,input().split()))
nof_2 = list_.count(2)
nof_1 = list_.count(1)
sum = 0
#print(nof_1,nof_2)
if nof_2<=nof_1:
sum+=nof_2
nof_1-=nof_2
sum+=(nof_1//3)
else:
sum+=nof_1
print(sum)
``` | 3 |
|
746 | A | Compote | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.
Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. | The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has. | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | 500 | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
},
{
"input": "1\n1\n4",
"output": "0"
},
{
"input": "1\n2\n3",
"output": "0"
},
{
"input": "1\n1000\n1000",
"output": "7"
},
{
"input": "1000\n1\n1000",
"output": "0"
},
{
"input": "1000\n2\n1000",
"output": "7"
},
{
"input": "1000\n500\n1000",
"output": "1750"
},
{
"input": "1000\n1000\n4",
"output": "7"
},
{
"input": "1000\n1000\n3",
"output": "0"
},
{
"input": "4\n8\n12",
"output": "21"
},
{
"input": "10\n20\n40",
"output": "70"
},
{
"input": "100\n200\n399",
"output": "693"
},
{
"input": "200\n400\n800",
"output": "1400"
},
{
"input": "199\n400\n800",
"output": "1393"
},
{
"input": "201\n400\n800",
"output": "1400"
},
{
"input": "200\n399\n800",
"output": "1393"
},
{
"input": "200\n401\n800",
"output": "1400"
},
{
"input": "200\n400\n799",
"output": "1393"
},
{
"input": "200\n400\n801",
"output": "1400"
},
{
"input": "139\n252\n871",
"output": "882"
},
{
"input": "109\n346\n811",
"output": "763"
},
{
"input": "237\n487\n517",
"output": "903"
},
{
"input": "161\n331\n725",
"output": "1127"
},
{
"input": "39\n471\n665",
"output": "273"
},
{
"input": "9\n270\n879",
"output": "63"
},
{
"input": "137\n422\n812",
"output": "959"
},
{
"input": "15\n313\n525",
"output": "105"
},
{
"input": "189\n407\n966",
"output": "1323"
},
{
"input": "18\n268\n538",
"output": "126"
},
{
"input": "146\n421\n978",
"output": "1022"
},
{
"input": "70\n311\n685",
"output": "490"
},
{
"input": "244\n405\n625",
"output": "1092"
},
{
"input": "168\n454\n832",
"output": "1176"
},
{
"input": "46\n344\n772",
"output": "322"
},
{
"input": "174\n438\n987",
"output": "1218"
},
{
"input": "144\n387\n693",
"output": "1008"
},
{
"input": "22\n481\n633",
"output": "154"
},
{
"input": "196\n280\n848",
"output": "980"
},
{
"input": "190\n454\n699",
"output": "1218"
},
{
"input": "231\n464\n928",
"output": "1617"
},
{
"input": "151\n308\n616",
"output": "1057"
},
{
"input": "88\n182\n364",
"output": "616"
},
{
"input": "12\n26\n52",
"output": "84"
},
{
"input": "204\n412\n824",
"output": "1428"
},
{
"input": "127\n256\n512",
"output": "889"
},
{
"input": "224\n446\n896",
"output": "1561"
},
{
"input": "146\n291\n584",
"output": "1015"
},
{
"input": "83\n164\n332",
"output": "574"
},
{
"input": "20\n38\n80",
"output": "133"
},
{
"input": "198\n393\n792",
"output": "1372"
},
{
"input": "120\n239\n480",
"output": "833"
},
{
"input": "208\n416\n831",
"output": "1449"
},
{
"input": "130\n260\n517",
"output": "903"
},
{
"input": "67\n134\n267",
"output": "462"
},
{
"input": "245\n490\n979",
"output": "1708"
},
{
"input": "182\n364\n727",
"output": "1267"
},
{
"input": "104\n208\n413",
"output": "721"
},
{
"input": "10\n2\n100",
"output": "7"
},
{
"input": "2\n100\n100",
"output": "14"
},
{
"input": "2\n3\n8",
"output": "7"
},
{
"input": "1\n2\n8",
"output": "7"
},
{
"input": "1\n2\n200",
"output": "7"
},
{
"input": "5\n4\n16",
"output": "14"
},
{
"input": "1\n10\n10",
"output": "7"
},
{
"input": "1\n4\n8",
"output": "7"
},
{
"input": "100\n4\n1000",
"output": "14"
},
{
"input": "2\n6\n12",
"output": "14"
},
{
"input": "10\n7\n4",
"output": "7"
},
{
"input": "2\n10\n100",
"output": "14"
},
{
"input": "2\n3\n4",
"output": "7"
},
{
"input": "1\n2\n999",
"output": "7"
},
{
"input": "1\n10\n20",
"output": "7"
},
{
"input": "100\n18\n20",
"output": "35"
},
{
"input": "100\n1\n100",
"output": "0"
},
{
"input": "3\n7\n80",
"output": "21"
},
{
"input": "2\n8\n24",
"output": "14"
},
{
"input": "1\n100\n100",
"output": "7"
},
{
"input": "2\n1\n8",
"output": "0"
},
{
"input": "10\n5\n23",
"output": "14"
}
] | 1,620,052,854 | 2,147,483,647 | PyPy 3 | OK | TESTS | 84 | 109 | 0 | a = int(input())
b = int(input())
c = int(input())
ans = 0
for aa in range(a + 1):
bb, cc = 2 * aa, 4 * aa
if bb <= b and cc <= c:
ans = aa + bb + cc
print(ans) | Title: Compote
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.
Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.
Input Specification:
The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has.
Output Specification:
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
Demo Input:
['2\n5\n7\n', '4\n7\n13\n', '2\n3\n2\n']
Demo Output:
['7\n', '21\n', '0\n']
Note:
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | ```python
a = int(input())
b = int(input())
c = int(input())
ans = 0
for aa in range(a + 1):
bb, cc = 2 * aa, 4 * aa
if bb <= b and cc <= c:
ans = aa + bb + cc
print(ans)
``` | 3 |
|
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
"output": "2"
},
{
"input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730",
"output": "6"
},
{
"input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624",
"output": "6"
},
{
"input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987",
"output": "6"
},
{
"input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222",
"output": "6"
},
{
"input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485",
"output": "8"
},
{
"input": "1\n1000 1000",
"output": "1"
},
{
"input": "1\n500 1000",
"output": "1"
},
{
"input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11",
"output": "11"
},
{
"input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2",
"output": "0"
},
{
"input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330",
"output": "30"
},
{
"input": "2\n7 7\n5 359",
"output": "2"
},
{
"input": "2\n465 706\n706 706",
"output": "1"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "1"
},
{
"input": "5\n1 1\n1 2\n2 3\n3 4\n4 3",
"output": "1"
},
{
"input": "3\n1 2\n1 2\n1 1",
"output": "1"
}
] | 1,608,712,405 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 0 | N=int(input());a=[];b=[];c=0
for i in range(N):
n,m=list(map(int,input().split()))
a.append(n);b.append(m)
for i in range(N):
t=a.pop(i)
if b[i] not in a:
c=c+1
a.insert(i, t)
print(c)
| Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['4\n1 1\n2 2\n3 3\n4 4\n', '4\n1 2\n2 3\n3 4\n4 1\n']
Demo Output:
['4\n', '0\n']
Note:
none | ```python
N=int(input());a=[];b=[];c=0
for i in range(N):
n,m=list(map(int,input().split()))
a.append(n);b.append(m)
for i in range(N):
t=a.pop(i)
if b[i] not in a:
c=c+1
a.insert(i, t)
print(c)
``` | 0 |
|
61 | C | Capture Valerian | PROGRAMMING | 2,000 | [
"math"
] | C. Capture Valerian | 2 | 256 | It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.
Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captured by Shapur and Shapur is now going to capture Valerian, the Roman emperor.
Being defeated, the cowardly Valerian hid in a room at the top of one of his castles. To capture him, Shapur has to open many doors. Fortunately Valerian was too scared to make impenetrable locks for the doors.
Each door has 4 parts. The first part is an integer number *a*. The second part is either an integer number *b* or some really odd sign which looks like R. The third one is an integer *c* and the fourth part is empty! As if it was laid for writing something. Being extremely gifted, after opening the first few doors, Shapur found out the secret behind the locks.
*c* is an integer written in base *a*, to open the door we should write it in base *b*. The only bad news is that this R is some sort of special numbering system that is used only in Roman empire, so opening the doors is not just a piece of cake!
Here's an explanation of this really weird number system that even doesn't have zero:
Roman numerals are based on seven symbols: a stroke (identified with the letter I) for a unit, a chevron (identified with the letter V) for a five, a cross-stroke (identified with the letter X) for a ten, a C (identified as an abbreviation of Centum) for a hundred, etc.:
- I=1- V=5- X=10- L=50- C=100- D=500- M=1000
Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1,<=000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I 1, II 2, III 3, V 5, VI 6, VII 7, etc., and the same for other bases: X 10, XX 20, XXX 30, L 50, LXXX 80; CC 200, DCC 700, etc. At the fourth and ninth iteration, a subtractive principle must be employed, with the base placed before the higher base: IV 4, IX 9, XL 40, XC 90, CD 400, CM 900.
Also in bases greater than 10 we use A for 10, B for 11, etc.
Help Shapur capture Valerian and bring peace back to Persia, especially Armenia. | The first line contains two integers *a* and *b* (2<=≤<=*a*,<=*b*<=≤<=25). Only *b* may be replaced by an R which indicates Roman numbering system.
The next line contains a single non-negative integer *c* in base *a* which may contain leading zeros but its length doesn't exceed 103.
It is guaranteed that if we have Roman numerals included the number would be less than or equal to 300010 and it won't be 0. In any other case the number won't be greater than 101510. | Write a single line that contains integer *c* in base *b*. You must omit leading zeros. | [
"10 2\n1\n",
"16 R\n5\n",
"5 R\n4\n",
"2 2\n1111001\n",
"12 13\nA\n"
] | [
"1\n",
"V\n",
"IV\n",
"1111001\n",
"A\n"
] | You can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals | 1,500 | [
{
"input": "10 2\n1",
"output": "1"
},
{
"input": "16 R\n5",
"output": "V"
},
{
"input": "5 R\n4",
"output": "IV"
},
{
"input": "2 2\n1111001",
"output": "1111001"
},
{
"input": "12 13\nA",
"output": "A"
},
{
"input": "6 7\n12345",
"output": "5303"
},
{
"input": "25 12\nABG",
"output": "3951"
},
{
"input": "17 10\nABACG",
"output": "892363"
},
{
"input": "18 R\nGH",
"output": "CCCV"
},
{
"input": "20 25\n4E32BB21D812",
"output": "A2II7CL2HDM"
},
{
"input": "15 11\n760595A635B24",
"output": "258AA2604713696"
},
{
"input": "10 22\n956512026633000",
"output": "1E06A57IC4H2"
},
{
"input": "5 9\n1102101401441324123301",
"output": "2733824152181178"
},
{
"input": "23 4\nDL5K6H78CAH",
"output": "2003021332111213003322000"
},
{
"input": "18 R\n36E",
"output": "MXCIV"
},
{
"input": "13 2\n1B579528314B30",
"output": "10000001011010101001110000001110001011010111010010"
},
{
"input": "8 13\n20043013541570572",
"output": "1B35CBA6B32102"
},
{
"input": "19 24\n1BH47I158EII",
"output": "2NHBDL4ECN2"
},
{
"input": "14 19\n33BC51B817C55",
"output": "1B573FFHHH12"
},
{
"input": "24 10\nE2E3EA6MJ05",
"output": "894488519782085"
},
{
"input": "25 2\nIBGNAB3C0H",
"output": "10000000001001000010100000111011000110101000001"
},
{
"input": "3 R\n2",
"output": "II"
},
{
"input": "20 20\n3HBAH9JA9EDE",
"output": "3HBAH9JA9EDE"
},
{
"input": "21 21\n2G3DK3F23905",
"output": "2G3DK3F23905"
},
{
"input": "23 R\n57F",
"output": "MMDCCCXXI"
},
{
"input": "16 6\n27774848D1D9F",
"output": "10500345245142230115"
},
{
"input": "18 7\nD9D42E745C5A",
"output": "351206225505021115"
},
{
"input": "11 R\n1A8A",
"output": "MMDCXXXIX"
},
{
"input": "12 17\n567872838B15A5",
"output": "105CA323BC110"
},
{
"input": "12 19\n78613621478844",
"output": "71A1E1HB01EB"
},
{
"input": "12 25\n51B878A1B3A7B8",
"output": "5JLBAF5JBEA"
},
{
"input": "12 R\n17BB",
"output": "MMDCCCLXXIX"
},
{
"input": "20 R\nFI",
"output": "CCCXVIII"
},
{
"input": "20 5\n1FAD98HHG13G",
"output": "340143030243121422401"
},
{
"input": "19 12\nEHIAG4GG072",
"output": "A33B813901970"
},
{
"input": "3 R\n2201120",
"output": "MCMLXXXVI"
},
{
"input": "3 R\n10210211",
"output": "MMDCCLXXVI"
},
{
"input": "3 R\n21222",
"output": "CCXV"
},
{
"input": "11 22\n172A57412774400",
"output": "11G8KLBCI95B"
},
{
"input": "17 4\n1509D9E003C5C",
"output": "2223230302121200303102203"
},
{
"input": "2 R\n101110110111",
"output": "MMCMXCIX"
},
{
"input": "25 R\n2JA",
"output": "MDCCXXXV"
},
{
"input": "23 R\n3HK",
"output": "MCMXCVIII"
},
{
"input": "10 22\n1000000000000000",
"output": "1FE6KH3A0F7A"
},
{
"input": "10 2\n999999999999993",
"output": "11100011010111111010100100110001100111111111111001"
},
{
"input": "4 21\n112233030100132210003330",
"output": "5KIIKBEFE1G"
},
{
"input": "4 10\n112233030100132210003330",
"output": "100000000000252"
},
{
"input": "4 5\n112233030100132210003330",
"output": "101101400000000002002"
},
{
"input": "2 R\n1",
"output": "I"
},
{
"input": "13 15\n33BCA79805767B",
"output": "7A924652EB469"
},
{
"input": "2 10\n0",
"output": "0"
},
{
"input": "25 2\n0",
"output": "0"
},
{
"input": "25 10\n001",
"output": "1"
},
{
"input": "17 17\n00000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "0"
},
{
"input": "10 R\n999",
"output": "CMXCIX"
},
{
"input": "2 2\n0",
"output": "0"
},
{
"input": "10 10\n100000000000",
"output": "100000000000"
},
{
"input": "10 10\n0",
"output": "0"
},
{
"input": "10 R\n900",
"output": "CM"
},
{
"input": "10 11\n12345678912345",
"output": "3A2A855993029"
},
{
"input": "10 2\n100000000000000",
"output": "10110101111001100010000011110100100000000000000"
},
{
"input": "10 R\n1983",
"output": "MCMLXXXIII"
},
{
"input": "2 R\n101110111000",
"output": "MMM"
},
{
"input": "2 R\n101110111000",
"output": "MMM"
},
{
"input": "10 11\n1000000000000000",
"output": "26A6A368906563A"
},
{
"input": "10 R\n1137",
"output": "MCXXXVII"
},
{
"input": "10 R\n100",
"output": "C"
},
{
"input": "10 25\n12343456543435",
"output": "35M8JNIJCA"
},
{
"input": "16 10\n0523456789ABC",
"output": "90384742521532"
}
] | 1,591,318,431 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 124 | 307,200 | numbers = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'A':10,'B':11,'C':12,'D':13,'E':14,'F':15,'G':16,'H':17,'I':18,'J':19,'K':20,'L':21,'M':22,'N':23,'O':24,'P':25,'Q':26,'R':27,'S':28,'T':29,'U':30,'V':31,'W':32,'X':33,'Y':34,'Z':35}
characters = {0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8',9:'9',10:'A',11:'B',12:'C',13:'D',14:'E',15:'F',16:'G',17:'H',18:'I',19:'J',20:'K',21:'L',22:'M',23:'N',24:'O',25:'P',26:'Q',27:'R',28:'S',29:'T',30:'U',31:'V',32:'W',33:'X',34:'Y',35:'Z'}
def ConvertToDecimal(number, base):
newnumber = 0
for digit in range(-1,(0-len(number))-1,-1):
if(numbers[number[digit]] >= int(base)):
return -1
newnumber += numbers[number[digit]]*(int(base)**(0-digit-1))
return newnumber
def ConvertToBase(number, base):
newnumber = ''
if(number == 0):
return '0'
while number > 0:
newnumber = characters[number%base] + newnumber
number = number//base
return newnumber
def ConvertToRoman(number):
newnumber = ''
for i in range(4,0,-1):
currentnumber = (number%(10**i) - number%(10**(i-1)))//(10**(i-1))
if(currentnumber > 0):
if(i==4):
newnumber += 'M'*currentnumber
elif(i==3):
if(currentnumber == 9):
newnumber += 'CM'
elif(currentnumber>=5):
newnumber += 'D' + 'C'*(currentnumber-5)
elif currentnumber == 4:
newnumber += 'CD'
else:
newnumber += 'C'*currentnumber
elif(i==2):
if(currentnumber == 9):
newnumber += 'XC'
elif(currentnumber>=5):
newnumber += 'L' + 'X'*(currentnumber-5)
elif currentnumber == 4:
newnumber += 'XL'
else:
newnumber += 'X'*currentnumber
elif(i==1):
if(currentnumber == 9):
newnumber += 'IX'
elif(currentnumber>=5):
newnumber += 'V' + 'I'*(currentnumber-5)
elif currentnumber == 4:
newnumber += 'IV'
else:
newnumber += 'I'*currentnumber
return newnumber
a,b = [x for x in input().split()]
c = input()
if b == 'R':
print(ConvertToRoman(ConvertToDecimal(c,int(a))))
else:
print(ConvertToBase(ConvertToDecimal(c,int(a)),int(b))) | Title: Capture Valerian
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.
Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captured by Shapur and Shapur is now going to capture Valerian, the Roman emperor.
Being defeated, the cowardly Valerian hid in a room at the top of one of his castles. To capture him, Shapur has to open many doors. Fortunately Valerian was too scared to make impenetrable locks for the doors.
Each door has 4 parts. The first part is an integer number *a*. The second part is either an integer number *b* or some really odd sign which looks like R. The third one is an integer *c* and the fourth part is empty! As if it was laid for writing something. Being extremely gifted, after opening the first few doors, Shapur found out the secret behind the locks.
*c* is an integer written in base *a*, to open the door we should write it in base *b*. The only bad news is that this R is some sort of special numbering system that is used only in Roman empire, so opening the doors is not just a piece of cake!
Here's an explanation of this really weird number system that even doesn't have zero:
Roman numerals are based on seven symbols: a stroke (identified with the letter I) for a unit, a chevron (identified with the letter V) for a five, a cross-stroke (identified with the letter X) for a ten, a C (identified as an abbreviation of Centum) for a hundred, etc.:
- I=1- V=5- X=10- L=50- C=100- D=500- M=1000
Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1,<=000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I 1, II 2, III 3, V 5, VI 6, VII 7, etc., and the same for other bases: X 10, XX 20, XXX 30, L 50, LXXX 80; CC 200, DCC 700, etc. At the fourth and ninth iteration, a subtractive principle must be employed, with the base placed before the higher base: IV 4, IX 9, XL 40, XC 90, CD 400, CM 900.
Also in bases greater than 10 we use A for 10, B for 11, etc.
Help Shapur capture Valerian and bring peace back to Persia, especially Armenia.
Input Specification:
The first line contains two integers *a* and *b* (2<=≤<=*a*,<=*b*<=≤<=25). Only *b* may be replaced by an R which indicates Roman numbering system.
The next line contains a single non-negative integer *c* in base *a* which may contain leading zeros but its length doesn't exceed 103.
It is guaranteed that if we have Roman numerals included the number would be less than or equal to 300010 and it won't be 0. In any other case the number won't be greater than 101510.
Output Specification:
Write a single line that contains integer *c* in base *b*. You must omit leading zeros.
Demo Input:
['10 2\n1\n', '16 R\n5\n', '5 R\n4\n', '2 2\n1111001\n', '12 13\nA\n']
Demo Output:
['1\n', 'V\n', 'IV\n', '1111001\n', 'A\n']
Note:
You can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals | ```python
numbers = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'A':10,'B':11,'C':12,'D':13,'E':14,'F':15,'G':16,'H':17,'I':18,'J':19,'K':20,'L':21,'M':22,'N':23,'O':24,'P':25,'Q':26,'R':27,'S':28,'T':29,'U':30,'V':31,'W':32,'X':33,'Y':34,'Z':35}
characters = {0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8',9:'9',10:'A',11:'B',12:'C',13:'D',14:'E',15:'F',16:'G',17:'H',18:'I',19:'J',20:'K',21:'L',22:'M',23:'N',24:'O',25:'P',26:'Q',27:'R',28:'S',29:'T',30:'U',31:'V',32:'W',33:'X',34:'Y',35:'Z'}
def ConvertToDecimal(number, base):
newnumber = 0
for digit in range(-1,(0-len(number))-1,-1):
if(numbers[number[digit]] >= int(base)):
return -1
newnumber += numbers[number[digit]]*(int(base)**(0-digit-1))
return newnumber
def ConvertToBase(number, base):
newnumber = ''
if(number == 0):
return '0'
while number > 0:
newnumber = characters[number%base] + newnumber
number = number//base
return newnumber
def ConvertToRoman(number):
newnumber = ''
for i in range(4,0,-1):
currentnumber = (number%(10**i) - number%(10**(i-1)))//(10**(i-1))
if(currentnumber > 0):
if(i==4):
newnumber += 'M'*currentnumber
elif(i==3):
if(currentnumber == 9):
newnumber += 'CM'
elif(currentnumber>=5):
newnumber += 'D' + 'C'*(currentnumber-5)
elif currentnumber == 4:
newnumber += 'CD'
else:
newnumber += 'C'*currentnumber
elif(i==2):
if(currentnumber == 9):
newnumber += 'XC'
elif(currentnumber>=5):
newnumber += 'L' + 'X'*(currentnumber-5)
elif currentnumber == 4:
newnumber += 'XL'
else:
newnumber += 'X'*currentnumber
elif(i==1):
if(currentnumber == 9):
newnumber += 'IX'
elif(currentnumber>=5):
newnumber += 'V' + 'I'*(currentnumber-5)
elif currentnumber == 4:
newnumber += 'IV'
else:
newnumber += 'I'*currentnumber
return newnumber
a,b = [x for x in input().split()]
c = input()
if b == 'R':
print(ConvertToRoman(ConvertToDecimal(c,int(a))))
else:
print(ConvertToBase(ConvertToDecimal(c,int(a)),int(b)))
``` | 3.968428 |
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions:
1. *x* doesn't contain neither digit 0 nor digit 1.
2. = .
Help friends find such number. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
"input": "8\n68931246",
"output": "77553333332222222"
},
{
"input": "7\n4424368",
"output": "75333332222222222"
},
{
"input": "6\n576825",
"output": "7755532222"
},
{
"input": "5\n97715",
"output": "7775332"
},
{
"input": "3\n915",
"output": "75332"
},
{
"input": "2\n26",
"output": "532"
},
{
"input": "1\n4",
"output": "322"
},
{
"input": "15\n028745260720699",
"output": "7777755533333332222222222"
},
{
"input": "13\n5761790121605",
"output": "7775555333322"
},
{
"input": "10\n3312667105",
"output": "755533332"
},
{
"input": "1\n7",
"output": "7"
},
{
"input": "15\n989898989898989",
"output": "777777777777777333333333333333322222222222222222222222222222"
},
{
"input": "15\n000000000000007",
"output": "7"
},
{
"input": "15\n999999999999990",
"output": "77777777777777333333333333333333333333333322222222222222"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "1\n4",
"output": "322"
},
{
"input": "1\n5",
"output": "5"
},
{
"input": "1\n6",
"output": "53"
},
{
"input": "1\n7",
"output": "7"
},
{
"input": "1\n9",
"output": "7332"
},
{
"input": "2\n09",
"output": "7332"
},
{
"input": "13\n1337251172966",
"output": "777555333333222"
},
{
"input": "15\n987654329876543",
"output": "777777555533333333332222222222222"
},
{
"input": "9\n234567899",
"output": "777755333333322222222"
},
{
"input": "2\n99",
"output": "77333322"
},
{
"input": "2\n66",
"output": "5533"
},
{
"input": "3\n999",
"output": "777333333222"
},
{
"input": "5\n99999",
"output": "77777333333333322222"
},
{
"input": "9\n123456789",
"output": "77755333332222222"
},
{
"input": "9\n987654321",
"output": "77755333332222222"
},
{
"input": "3\n666",
"output": "555333"
},
{
"input": "2\n26",
"output": "532"
},
{
"input": "6\n555777",
"output": "777555"
},
{
"input": "10\n1234567899",
"output": "777755333333322222222"
},
{
"input": "4\n6666",
"output": "55553333"
},
{
"input": "4\n9754",
"output": "775333222"
},
{
"input": "2\n95",
"output": "75332"
},
{
"input": "14\n11122233344455",
"output": "55333333222222222"
},
{
"input": "12\n836544897832",
"output": "77777553333333222222222222222"
}
] | 1,656,497,700 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n = int(input())
m = { 2:2, 3:3, 4:322, 5:5, 6:53, 7: 7, 8:7222, 9:7332 }
k = n
r = 0
while(k > 0):
d = int(k % 10)
k-=d
k/=10
if(d != 1 and d != 0):
r = int(str(r) + str(m[d]))
print("".join(sorted(str(r)), reverse=True)) | Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions:
1. *x* doesn't contain neither digit 0 nor digit 1.
2. = .
Help friends find such number.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes.
Output Specification:
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Demo Input:
['4\n1234\n', '3\n555\n']
Demo Output:
['33222\n', '555\n']
Note:
In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
n = int(input())
m = { 2:2, 3:3, 4:322, 5:5, 6:53, 7: 7, 8:7222, 9:7332 }
k = n
r = 0
while(k > 0):
d = int(k % 10)
k-=d
k/=10
if(d != 1 and d != 0):
r = int(str(r) + str(m[d]))
print("".join(sorted(str(r)), reverse=True))
``` | -1 |
|
862 | C | Mahmoud and Ehab and the xor | PROGRAMMING | 1,900 | [
"constructive algorithms"
] | null | null | Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to find a set of *n* distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly *x*. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. | The only line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105, 0<=≤<=*x*<=≤<=105) — the number of elements in the set and the desired bitwise-xor, respectively. | If there is no such set, print "NO" (without quotes).
Otherwise, on the first line print "YES" (without quotes) and on the second line print *n* distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. | [
"5 5\n",
"3 6\n"
] | [
"YES\n1 2 4 5 7",
"YES\n1 2 5"
] | You can read more about the bitwise-xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
For the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb8ccd05d3a7a41eff93c98f79d158cf85e702f9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d05d19f05b03f8ac89b7f86ef830eeccc0050c42.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,500 | [
{
"input": "5 5",
"output": "YES\n1 2 131072 131078 0 "
},
{
"input": "3 6",
"output": "YES\n131072 131078 0 "
},
{
"input": "3 0",
"output": "YES\n393216 131072 262144"
},
{
"input": "1 0",
"output": "YES\n0"
},
{
"input": "3 3",
"output": "YES\n131072 131075 0 "
},
{
"input": "100000 41243",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 100000",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "32 32",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 131072 131105 0 "
},
{
"input": "32 31",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 131072 131102 0 "
},
{
"input": "1 1",
"output": "YES\n1"
},
{
"input": "2 0",
"output": "NO"
},
{
"input": "3 1",
"output": "YES\n131072 131073 0 "
},
{
"input": "3 2",
"output": "YES\n131072 131074 0 "
},
{
"input": "3 5",
"output": "YES\n131072 131077 0 "
},
{
"input": "3 4",
"output": "YES\n131072 131076 0 "
},
{
"input": "3 10203",
"output": "YES\n131072 141275 0 "
},
{
"input": "3 10100",
"output": "YES\n131072 141172 0 "
},
{
"input": "5 0",
"output": "YES\n1 2 131072 131075 0 "
},
{
"input": "5 1",
"output": "YES\n1 2 131072 131074 0 "
},
{
"input": "5 2",
"output": "YES\n1 2 131072 131073 0 "
},
{
"input": "5 3",
"output": "YES\n1 2 393216 131072 262144"
},
{
"input": "5 4",
"output": "YES\n1 2 131072 131079 0 "
},
{
"input": "5 6",
"output": "YES\n1 2 131072 131077 0 "
},
{
"input": "5 7",
"output": "YES\n1 2 131072 131076 0 "
},
{
"input": "5 8",
"output": "YES\n1 2 131072 131083 0 "
},
{
"input": "5 9",
"output": "YES\n1 2 131072 131082 0 "
},
{
"input": "100000 1",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 0",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 21323",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 65536",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 65537",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 65535",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "4 2",
"output": "YES\n1 131072 131075 0 "
},
{
"input": "10 2",
"output": "YES\n1 2 3 4 5 6 7 131072 131074 0 "
},
{
"input": "1 2",
"output": "YES\n2"
},
{
"input": "1 3",
"output": "YES\n3"
},
{
"input": "2 1",
"output": "YES\n0 1"
},
{
"input": "2 2",
"output": "YES\n0 2"
},
{
"input": "2 3",
"output": "YES\n0 3"
},
{
"input": "4 0",
"output": "YES\n1 131072 131073 0 "
},
{
"input": "4 1",
"output": "YES\n1 393216 131072 262144"
},
{
"input": "4 3",
"output": "YES\n1 131072 131074 0 "
},
{
"input": "6 0",
"output": "YES\n1 2 3 393216 131072 262144"
},
{
"input": "7 1",
"output": "YES\n1 2 3 4 131072 131077 0 "
}
] | 1,689,643,742 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689643742.1409497")# 1689643742.1409714 | Title: Mahmoud and Ehab and the xor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to find a set of *n* distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly *x*. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106.
Input Specification:
The only line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105, 0<=≤<=*x*<=≤<=105) — the number of elements in the set and the desired bitwise-xor, respectively.
Output Specification:
If there is no such set, print "NO" (without quotes).
Otherwise, on the first line print "YES" (without quotes) and on the second line print *n* distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.
Demo Input:
['5 5\n', '3 6\n']
Demo Output:
['YES\n1 2 4 5 7', 'YES\n1 2 5']
Note:
You can read more about the bitwise-xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
For the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb8ccd05d3a7a41eff93c98f79d158cf85e702f9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d05d19f05b03f8ac89b7f86ef830eeccc0050c42.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
print("_RANDOM_GUESS_1689643742.1409497")# 1689643742.1409714
``` | 0 |
|
31 | B | Sysadmin Bob | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"strings"
] | B. Sysadmin Bob | 0 | 256 | Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.
Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. | The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». | If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. | [
"a@aa@a\n",
"a@a@a\n",
"@aa@a\n"
] | [
"a@a,a@a\n",
"No solution\n",
"No solution\n"
] | none | 1,000 | [
{
"input": "a@aa@a",
"output": "a@a,a@a"
},
{
"input": "a@a@a",
"output": "No solution"
},
{
"input": "@aa@a",
"output": "No solution"
},
{
"input": "aba@caba@daba",
"output": "aba@c,aba@daba"
},
{
"input": "asd@qwasd@qwasd@qwasd@qwasd@qw",
"output": "asd@q,wasd@q,wasd@q,wasd@q,wasd@qw"
},
{
"input": "qwer@ty",
"output": "qwer@ty"
},
{
"input": "@",
"output": "No solution"
},
{
"input": "g",
"output": "No solution"
},
{
"input": "@@",
"output": "No solution"
},
{
"input": "@@@",
"output": "No solution"
},
{
"input": "r@@",
"output": "No solution"
},
{
"input": "@@r",
"output": "No solution"
},
{
"input": "@r@",
"output": "No solution"
},
{
"input": "w@",
"output": "No solution"
},
{
"input": "@e",
"output": "No solution"
},
{
"input": "jj",
"output": "No solution"
},
{
"input": "@gh",
"output": "No solution"
},
{
"input": "n@m",
"output": "n@m"
},
{
"input": "kl@",
"output": "No solution"
},
{
"input": "fpm",
"output": "No solution"
},
{
"input": "@@@@",
"output": "No solution"
},
{
"input": "q@@@",
"output": "No solution"
},
{
"input": "@d@@",
"output": "No solution"
},
{
"input": "@@v@",
"output": "No solution"
},
{
"input": "@@@c",
"output": "No solution"
},
{
"input": "@@zx",
"output": "No solution"
},
{
"input": "@x@a",
"output": "No solution"
},
{
"input": "@pq@",
"output": "No solution"
},
{
"input": "w@@e",
"output": "No solution"
},
{
"input": "e@s@",
"output": "No solution"
},
{
"input": "ec@@",
"output": "No solution"
},
{
"input": "@hjk",
"output": "No solution"
},
{
"input": "e@vb",
"output": "e@vb"
},
{
"input": "tg@q",
"output": "tg@q"
},
{
"input": "jkl@",
"output": "No solution"
},
{
"input": "werb",
"output": "No solution"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "No solution"
},
{
"input": "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
"output": "No solution"
},
{
"input": "duk@rufrxjzqbwkfrzf@sjp@mdpyrokdfmcmexxtjqaalruvtzwfsqabi@tjkxilrhkwzfeuqm@lpwnxgebirdvwplsvrtxvhmzv",
"output": "duk@r,ufrxjzqbwkfrzf@s,jp@m,dpyrokdfmcmexxtjqaalruvtzwfsqabi@t,jkxilrhkwzfeuqm@lpwnxgebirdvwplsvrtxvhmzv"
},
{
"input": "umegsn@qlmkpkyrmuclefdpfhzuhyjcoqthnvpwzhkwrdvlzfbrqpzlg@ebzycyaofyyetwcepe@nxjwyeaqbuxxbohfzrnmebuy",
"output": "umegsn@q,lmkpkyrmuclefdpfhzuhyjcoqthnvpwzhkwrdvlzfbrqpzlg@e,bzycyaofyyetwcepe@nxjwyeaqbuxxbohfzrnmebuy"
},
{
"input": "l@snuoytgflrtuexpx@txzhhdwbakfhfro@syxistypegfvdmurvuubrj@grsznzhcotagqueuxtnjgfaywzkbglwwiptjyocxcs",
"output": "l@s,nuoytgflrtuexpx@t,xzhhdwbakfhfro@s,yxistypegfvdmurvuubrj@grsznzhcotagqueuxtnjgfaywzkbglwwiptjyocxcs"
},
{
"input": "crvjlke@yqsdofatzuuspt@@uumdkiwhtg@crxiabnujfmcquylyklxaedniwnq@@f@@rfnsjtylurexmdaaykvxmgeij@jkjsyi",
"output": "No solution"
},
{
"input": "ukpcivvjubgalr@bdxangokpaxzxuxe@qlemwpvywfudffafsqlmmhhalaaolktmgmhmrwvkdcvwxcfbytnz@jgmbhpwqcmecnxc",
"output": "ukpcivvjubgalr@b,dxangokpaxzxuxe@q,lemwpvywfudffafsqlmmhhalaaolktmgmhmrwvkdcvwxcfbytnz@jgmbhpwqcmecnxc"
},
{
"input": "mehxghlvnnazggvpnjdbchdolqguiurrfghwxpwhphdbhloltwnnqovsnsdmfevlikmrlvwvkcqysefvoraorhamchghqaooxaxz",
"output": "No solution"
},
{
"input": "whazbewtogyre@wqlsswhygx@osevwzytuaukqpp@gfjbtwnhpnlxwci@ovaaat@ookd@@o@bss@wyrrwzysubw@utyltkk@hlkx",
"output": "No solution"
},
{
"input": "vpulcessdotvylvmkeonzbpncjxaaigotkyvngsbkicomikyavpsjcphlznjtdmvbqiroxvfcmcczfmqbyedujvrupzlaswbzanv",
"output": "No solution"
},
{
"input": "mhxapzklriiincpnysmegjzaxdngifbowkzivvgisqbekprdmdoqezdsrsrwwmht@hwywjqflvqdevpqisncwbftlttfkgsyetop",
"output": "mhxapzklriiincpnysmegjzaxdngifbowkzivvgisqbekprdmdoqezdsrsrwwmht@hwywjqflvqdevpqisncwbftlttfkgsyetop"
},
{
"input": "dxzqftcghawwcwh@iepanbiclstbsxbrsoep@@jwhrptgiu@zfykoravtaykvkzseqfnlsbvjnsgiajgjtgucvewlpxmqwvkghlo",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@",
"output": "No solution"
},
{
"input": "@rierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "e@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@d",
"output": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@d"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjt@h@",
"output": "No solution"
},
{
"input": "@r@erjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@i@rjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierj@g@d",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@@",
"output": "No solution"
},
{
"input": "@@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@@erjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjt@@d",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierj@@dderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "a@rierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderirjtghderierjtghderierjtghderierjthderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@a",
"output": "a@r,ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderirjtghderierjtghderierjtghderierjthderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@a"
},
{
"input": "d@nt@om@zz@ut@tr@ta@ap@ou@sy@sv@fg@el@rp@qr@nl@j",
"output": "d@n,t@o,m@z,z@u,t@t,r@t,a@a,p@o,u@s,y@s,v@f,g@e,l@r,p@q,r@n,l@j"
},
{
"input": "a@mc@ks@gu@rl@gq@zq@iz@da@uq@mi@nf@zs@hi@we@ej@ke@vb@az@yz@yl@rr@gh@um@nv@qe@qq@de@dy@op@gt@vx@ak@q",
"output": "a@m,c@k,s@g,u@r,l@g,q@z,q@i,z@d,a@u,q@m,i@n,f@z,s@h,i@w,e@e,j@k,e@v,b@a,z@y,z@y,l@r,r@g,h@u,m@n,v@q,e@q,q@d,e@d,y@o,p@g,t@v,x@a,k@q"
},
{
"input": "c@ir@xf@ap@fk@sp@wm@ec@qw@vg@by@iu@tr@wu@pv@lj@dd@tc@qj@ok@hm@bs@ul@ez@cg@ht@xf@ag@tr@hz@ap@tx@ly@dg@hu@nd@uv@il@ii@cn@nc@nb@cy@kp@dk@xa@da@ta@yr@yv@qg@db@je@wz@rn@yh@xi@mj@kc@uj@yu@cf@ps@ao@fo@le@d",
"output": "c@i,r@x,f@a,p@f,k@s,p@w,m@e,c@q,w@v,g@b,y@i,u@t,r@w,u@p,v@l,j@d,d@t,c@q,j@o,k@h,m@b,s@u,l@e,z@c,g@h,t@x,f@a,g@t,r@h,z@a,p@t,x@l,y@d,g@h,u@n,d@u,v@i,l@i,i@c,n@n,c@n,b@c,y@k,p@d,k@x,a@d,a@t,a@y,r@y,v@q,g@d,b@j,e@w,z@r,n@y,h@x,i@m,j@k,c@u,j@y,u@c,f@p,s@a,o@f,o@l,e@d"
},
{
"input": "m@us@ru@mg@rq@ed@ot@gt@fo@gs@lm@cx@au@rq@zt@zk@jr@xd@oa@py@kf@lk@zr@ko@lj@wv@fl@yl@gk@cx@px@kl@ic@sr@xn@hm@xs@km@tk@ui@ya@pa@xx@ze@py@ir@xj@cr@dq@lr@cm@zu@lt@bx@kq@kx@fr@lu@vb@rz@hg@iw@dl@pf@pl@wv@z",
"output": "m@u,s@r,u@m,g@r,q@e,d@o,t@g,t@f,o@g,s@l,m@c,x@a,u@r,q@z,t@z,k@j,r@x,d@o,a@p,y@k,f@l,k@z,r@k,o@l,j@w,v@f,l@y,l@g,k@c,x@p,x@k,l@i,c@s,r@x,n@h,m@x,s@k,m@t,k@u,i@y,a@p,a@x,x@z,e@p,y@i,r@x,j@c,r@d,q@l,r@c,m@z,u@l,t@b,x@k,q@k,x@f,r@l,u@v,b@r,z@h,g@i,w@d,l@p,f@p,l@w,v@z"
},
{
"input": "gjkjqjrks@eyqiia@qfijelnmigoditxjrtuhukalfl@nmwancimlqtfekzkxgjioedhtdivqajwbmu@hpdxuiwurpgenxaiqaqkcqimcvitljuisfiojlylveie@neqdjzeqdbiatjpuhujgykl@gmmlrhnlghsoeyrccygigtkjrjxdwmnkouaiaqpquluwcdqlxqb",
"output": "gjkjqjrks@e,yqiia@q,fijelnmigoditxjrtuhukalfl@n,mwancimlqtfekzkxgjioedhtdivqajwbmu@h,pdxuiwurpgenxaiqaqkcqimcvitljuisfiojlylveie@n,eqdjzeqdbiatjpuhujgykl@gmmlrhnlghsoeyrccygigtkjrjxdwmnkouaiaqpquluwcdqlxqb"
},
{
"input": "uakh@chpowdmvdywosakyyknpriverjjgklmdrgwufpawgvhabjbnemimjktgbkx@fzvqcodbceqnihl@kpsslhwwndad@@yavjafrwkqyt@urhnwgnqamn@xkc@vngzlssmtheuxkpzjlbbjq@mwiojmvpilm@hlrmxheszskhxritsieubjjazrngxlqeedfkiuwny",
"output": "No solution"
},
{
"input": "usmjophufnkamnvowbauu@wfoyceknkgeaejlbbqhtucbl@wurukjezj@irhdgrfhyfkz@fbmqgxvtxcebztirvwjf@fnav@@f@paookujny@z@fmcxgvab@@kpqbwuxxwxhsrbivlbunmdjzk@afjznrjjtkq@cafetoinfleecjqvlzpkqlspoufwmidvoblti@jbg",
"output": "No solution"
},
{
"input": "axkxcgcmlxq@v@ynnjximcujikloyls@lqvxiyca@feimaioavacmquasneqbrqftknpbrzpahtcc@ijwqmyzsuidqkm@dffuiitpugbvty@izbnqxhdjasihhlt@gjrol@vy@vnqpxuqbofzzwl@toywomxopbuttczszx@fuowtjmtqy@gypx@la@@tweln@jgyktb",
"output": "No solution"
},
{
"input": "mplxc@crww@gllecngcsbmxmksrgcb@lbrcnkwxclkcgvfeqeoymproppxhxbgm@q@bfxxvuymnnjolqklabcinwpdlxj@jcevvilhmpyiwggvlmdanfhhlgbkobnmei@bvqtdq@osijfdsuouvcqpcjxjqiuhgts@xapp@cpqvlhlfrxtgunbbjwhuafovbcbqyhmlu",
"output": "No solution"
},
{
"input": "aglvesxsmivijisod@mxcnbfcfgqfwjouidlsueaswf@obehqpvbkmukxkicyoknkbol@kutunggpoxxfpbe@qkhv@llddqqoyjeex@byvtlhbifqmvlukmrvgvpwrscwfhpuwyknwchqhrdqgarmnsdlqgf@lseltghg@bhuwbfjpsvayzk@fvwow@zapklumefauly",
"output": "aglvesxsmivijisod@m,xcnbfcfgqfwjouidlsueaswf@o,behqpvbkmukxkicyoknkbol@k,utunggpoxxfpbe@q,khv@l,lddqqoyjeex@b,yvtlhbifqmvlukmrvgvpwrscwfhpuwyknwchqhrdqgarmnsdlqgf@l,seltghg@b,huwbfjpsvayzk@f,vwow@zapklumefauly"
},
{
"input": "gbllovyerhudm@aluhtnstcp@uwgvejnmqpt@nez@ltzqjrcgwkkpzicb@ihh@wldhvjbrl@efbdzbeg@zyovsta@n@c@jutail@nclsbcihabzr@snowxeyl@jewen@aduffvhr@ifufzzt@i@kptygveumwaknmrn@edsapqpcwsqypmutggztum@ewzakeamobzxt",
"output": "No solution"
},
{
"input": "dokshhqwmtbefrynupvusfxroggoqkjqfyabzkbccjmavumncorbcoairybeknhnpnwftrlbopsvqlgjbrowmfmoeebqseneabvgbcxmujmcqomoawrooixmqmyspfgafudfdfyrnujhgnbtsehgsnvdztjdpnskyquwdtkbfjtvrfjcqzmourvqsnfgjfqjgndydpch",
"output": "No solution"
},
{
"input": "jrlhtwmotdhtgcqokodparuqypwlkbhfsxvmdpfiraokekrolwtlsqjzcuvjfnvblznyngasauzln@gjypvjcwljnotgjlxketfgtntbotwjehea@vppouyoujujlhjrxbhvltfdslaqwynwjefbdbnuehmipqmtsrivlnippgftgnkhdgqiqbfvgrtoxrznncncqcvf",
"output": "jrlhtwmotdhtgcqokodparuqypwlkbhfsxvmdpfiraokekrolwtlsqjzcuvjfnvblznyngasauzln@g,jypvjcwljnotgjlxketfgtntbotwjehea@vppouyoujujlhjrxbhvltfdslaqwynwjefbdbnuehmipqmtsrivlnippgftgnkhdgqiqbfvgrtoxrznncncqcvf"
},
{
"input": "oxkvgnggznlfhminxkkhictpiaokdsfrewnxiujpjpstlyxovfwugrsqnpooalknjnfugxojozizlicwvnbflhdevpvnvwztnfiapairpigexbaeshondqdecduewmfrxunphikvlfwmrpsxrhxyjlsgqfiaqnwzlzxcyuudhzr@twllmhyfclybxqazhrmxdtokxawc",
"output": "oxkvgnggznlfhminxkkhictpiaokdsfrewnxiujpjpstlyxovfwugrsqnpooalknjnfugxojozizlicwvnbflhdevpvnvwztnfiapairpigexbaeshondqdecduewmfrxunphikvlfwmrpsxrhxyjlsgqfiaqnwzlzxcyuudhzr@twllmhyfclybxqazhrmxdtokxawc"
}
] | 1,627,053,261 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 6,963,200 | string=input()
lst=string.split('@')
middle=lst[1:-1]
if not( lst[0].isalpha() and lst[-1].isalpha()):
print('No solution')
exit()
if not all(list(map(lambda x:len(x)>1 and x.isalpha(),middle))):
print('No solution')
exit()
first=lst[0]
emails=[]
for i in middle:
last=i[0]
emails.append(first+'@'+last)
first=i[1:]
emails.append(first+'@'+lst[-1])
print(','.join(emails))
| Title: Sysadmin Bob
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.
Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that.
Input Specification:
The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@».
Output Specification:
If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them.
Demo Input:
['a@aa@a\n', 'a@a@a\n', '@aa@a\n']
Demo Output:
['a@a,a@a\n', 'No solution\n', 'No solution\n']
Note:
none | ```python
string=input()
lst=string.split('@')
middle=lst[1:-1]
if not( lst[0].isalpha() and lst[-1].isalpha()):
print('No solution')
exit()
if not all(list(map(lambda x:len(x)>1 and x.isalpha(),middle))):
print('No solution')
exit()
first=lst[0]
emails=[]
for i in middle:
last=i[0]
emails.append(first+'@'+last)
first=i[1:]
emails.append(first+'@'+lst[-1])
print(','.join(emails))
``` | 0 |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo"
},
{
"input": "805",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1000",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1",
"output": "O"
},
{
"input": "2",
"output": "OO"
},
{
"input": "3",
"output": "OOO"
},
{
"input": "5",
"output": "OOOoO"
},
{
"input": "17",
"output": "OOOoOooOooooOoooo"
},
{
"input": "49",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo"
},
{
"input": "256",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo"
},
{
"input": "512",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "933",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "61",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo"
},
{
"input": "781",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "999",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
}
] | 1,584,964,724 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 109 | 0 | s = ""
def fibo(i):
if i == 1:
return 0
elif i == 2:
return 0
a = 0
b = 1
c = 0
while c < i:
c = a + b
a = b
b = c
if c == i:
return 0
return 1
for i in range(1,int(input())+1):
if fibo(i) == 0:
s += "O"
else:
s += "o"
print(s) | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
Input Specification:
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
Print Eleven's new name on the first and only line of output.
Demo Input:
['8\n', '15\n']
Demo Output:
['OOOoOooO\n', 'OOOoOooOooooOoo\n']
Note:
none | ```python
s = ""
def fibo(i):
if i == 1:
return 0
elif i == 2:
return 0
a = 0
b = 1
c = 0
while c < i:
c = a + b
a = b
b = c
if c == i:
return 0
return 1
for i in range(1,int(input())+1):
if fibo(i) == 0:
s += "O"
else:
s += "o"
print(s)
``` | 3 |
|
830 | A | Office Keys | PROGRAMMING | 1,800 | [
"binary search",
"brute force",
"dp",
"greedy",
"sortings"
] | null | null | There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all *n* people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it. | The first line contains three integers *n*, *k* and *p* (1<=≤<=*n*<=≤<=1<=000, *n*<=≤<=*k*<=≤<=2<=000, 1<=≤<=*p*<=≤<=109) — the number of people, the number of keys and the office location.
The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — positions in which people are located initially. The positions are given in arbitrary order.
The third line contains *k* distinct integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**j*<=≤<=109) — positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point. | Print the minimum time (in seconds) needed for all *n* to reach the office with keys. | [
"2 4 50\n20 100\n60 10 40 80\n",
"1 2 10\n11\n15 7\n"
] | [
"50\n",
"7\n"
] | In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | 500 | [
{
"input": "2 4 50\n20 100\n60 10 40 80",
"output": "50"
},
{
"input": "1 2 10\n11\n15 7",
"output": "7"
},
{
"input": "2 5 15\n10 4\n29 23 21 22 26",
"output": "23"
},
{
"input": "3 10 1500\n106 160 129\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163",
"output": "1394"
},
{
"input": "5 20 1\n314 316 328 323 321\n30 61 11 83 19 63 97 87 14 79 43 57 75 48 47 95 41 27 8 88",
"output": "327"
},
{
"input": "20 20 1000000000\n911196469 574676950 884047241 984218701 641693148 352743122 616364857 455260052 702604347 921615943 671695009 544819698 768892858 254148055 379968391 65297129 178692403 575557323 307174510 63022600\n1621 106 6866 6420 9307 6985 2741 9477 9837 5909 6757 3085 6139 1876 3726 9334 4321 1531 8534 560",
"output": "1984199027"
},
{
"input": "40 45 1000\n6 55 34 32 20 76 2 84 47 68 31 60 14 70 99 72 21 61 81 79 26 51 96 86 10 1 43 69 87 78 13 11 80 67 50 52 9 29 94 12\n1974 1232 234 28 1456 626 408 1086 1525 1209 1096 940 795 1867 548 1774 1993 1199 1112 1087 1923 1156 876 1715 1815 1027 1658 955 398 910 620 1164 749 996 113 109 500 328 800 826 766 518 1474 1038 1029",
"output": "2449"
},
{
"input": "50 55 2000\n9518 9743 9338 9956 9827 9772 9094 9644 9242 9292 9148 9205 9907 9860 9530 9814 9662 9482 9725 9227 9105 9424 9268 9427 9470 9578 9808 9976 9143 9070 9079 9896 9367 9235 9925 9009 9619 9012 9669 9077 9870 9766 9479 9598 9055 9988 9792 9197 9377 9610\n828 656 345 412 69 506 274 994 384 766 587 126 720 227 66 839 997 602 646 955 256 262 243 676 459 83 507 88 559 595 71 154 867 276 487 895 857 888 368 179 813 407 973 780 588 112 815 290 554 230 768 804 974 3 745",
"output": "10833"
},
{
"input": "1 1 1\n1\n1000000000",
"output": "1999999998"
},
{
"input": "1 1 1\n1000000000\n1",
"output": "999999999"
},
{
"input": "1 1 1000000000\n1000000000\n1",
"output": "1999999998"
},
{
"input": "1 1 1000000000\n1\n1000000000",
"output": "999999999"
},
{
"input": "2 2 4\n3 4\n5 6",
"output": "4"
},
{
"input": "2 2 5\n1 2\n3 1000000000",
"output": "1999999993"
},
{
"input": "1 1 1000000000\n1000000000\n1",
"output": "1999999998"
},
{
"input": "2 2 1\n2 3\n4 100",
"output": "196"
},
{
"input": "2 2 10\n3 12\n1 9",
"output": "11"
},
{
"input": "3 3 1\n1 2 3\n999 1000000000 1",
"output": "1999999996"
},
{
"input": "1 1 1\n1\n1",
"output": "0"
},
{
"input": "1 1 1\n1\n1000000000",
"output": "1999999998"
},
{
"input": "1 1 1000000000\n1000000000\n10",
"output": "1999999980"
},
{
"input": "2 2 7122\n123 456\n1 4444",
"output": "7243"
},
{
"input": "1 1 10\n5\n15",
"output": "15"
},
{
"input": "2 4 1000\n1000 999\n1 1000 2 999",
"output": "1"
},
{
"input": "2 2 1000\n10 1010\n1 1001",
"output": "1008"
},
{
"input": "1 1 1\n2\n1000000000",
"output": "1999999997"
},
{
"input": "2 2 3\n1 5\n5 1",
"output": "2"
},
{
"input": "2 2 5\n2 3\n4 6",
"output": "4"
},
{
"input": "2 2 10\n5 6\n4 6",
"output": "7"
},
{
"input": "3 4 10\n5 7 9\n6 8 14 4",
"output": "7"
},
{
"input": "1 1 10\n10\n10",
"output": "0"
},
{
"input": "1 1 50\n1\n1000000000",
"output": "1999999949"
},
{
"input": "1 1 42\n666\n1337",
"output": "1966"
},
{
"input": "2 2 10\n9 11\n11 8",
"output": "3"
},
{
"input": "3 10 5\n1 2 3\n10000 9999 9998 9997 9996 9995 9994 7 6 5",
"output": "6"
},
{
"input": "1 1 2\n1\n1000000000",
"output": "1999999997"
},
{
"input": "2 2 100\n99 150\n1 150",
"output": "197"
},
{
"input": "3 3 4\n1 101 102\n2 3 100",
"output": "99"
}
] | 1,689,823,769 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | import sys
from math import inf
input = sys.stdin.readline
n, k, p = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
ans = inf
for l in range(k - n + 1):
f = 0
j = l
for i in range(n):
if(a[i] <= b[j] <= p):
f = max(f, p - a[i])
elif(a[i] <= p <= b[j]):
f = max(f, p + b[j] - 2 * a[i])
elif(b[j] <= a[i] <= p):
f = max(f, p + a[i] - 2 * b[j])
elif(b[j] <= p <= a[i]):
f = max(f, p + a[i] - 2 * b[j])
elif(p <= b[j] <= a[i]):
f = max(f, a[i] - p)
else:
f = max(f, 2 * b[j] - p - a[i])
j += 1
ans = min(ans, f)
print(ans)
| Title: Office Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all *n* people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input Specification:
The first line contains three integers *n*, *k* and *p* (1<=≤<=*n*<=≤<=1<=000, *n*<=≤<=*k*<=≤<=2<=000, 1<=≤<=*p*<=≤<=109) — the number of people, the number of keys and the office location.
The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — positions in which people are located initially. The positions are given in arbitrary order.
The third line contains *k* distinct integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**j*<=≤<=109) — positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output Specification:
Print the minimum time (in seconds) needed for all *n* to reach the office with keys.
Demo Input:
['2 4 50\n20 100\n60 10 40 80\n', '1 2 10\n11\n15 7\n']
Demo Output:
['50\n', '7\n']
Note:
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | ```python
import sys
from math import inf
input = sys.stdin.readline
n, k, p = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
ans = inf
for l in range(k - n + 1):
f = 0
j = l
for i in range(n):
if(a[i] <= b[j] <= p):
f = max(f, p - a[i])
elif(a[i] <= p <= b[j]):
f = max(f, p + b[j] - 2 * a[i])
elif(b[j] <= a[i] <= p):
f = max(f, p + a[i] - 2 * b[j])
elif(b[j] <= p <= a[i]):
f = max(f, p + a[i] - 2 * b[j])
elif(p <= b[j] <= a[i]):
f = max(f, a[i] - p)
else:
f = max(f, 2 * b[j] - p - a[i])
j += 1
ans = min(ans, f)
print(ans)
``` | 0 |
|
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
"input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ",
"output": "1077"
},
{
"input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA",
"output": "568"
},
{
"input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA",
"output": "70"
},
{
"input": "W",
"output": "0"
},
{
"input": "DBA",
"output": "0"
},
{
"input": "RQAWNACASAAKAGAAAAQ",
"output": "10"
},
{
"input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA",
"output": "111"
},
{
"input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA",
"output": "411"
},
{
"input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ",
"output": "625"
},
{
"input": "QORZOYAQ",
"output": "1"
},
{
"input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA",
"output": "13174"
},
{
"input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT",
"output": "10420"
},
{
"input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ",
"output": "12488"
},
{
"input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA",
"output": "9114"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "35937"
},
{
"input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE",
"output": "254"
},
{
"input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE",
"output": "2174"
},
{
"input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ",
"output": "2962"
},
{
"input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA",
"output": "2482"
},
{
"input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ",
"output": "7768"
},
{
"input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA",
"output": "5422"
},
{
"input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ",
"output": "3024"
},
{
"input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ",
"output": "4527"
},
{
"input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH",
"output": "6416"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ",
"output": "13136"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA",
"output": "14231"
},
{
"input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "15296"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA",
"output": "20825"
},
{
"input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ",
"output": "20825"
},
{
"input": "Q",
"output": "0"
},
{
"input": "A",
"output": "0"
},
{
"input": "FFF",
"output": "0"
},
{
"input": "AAAAAA",
"output": "0"
}
] | 1,595,448,555 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 140 | 22,118,400 | n = input()
n = n.lower()
t = 0
for i in range(len(n)-2):
for j in range(i+1,len(n)-1):
for k in range(j+1,len(n)):
if n[i] == 'q' and n[j] == 'a' and n[k] == 'q':
t+=1
print(t) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
Input Specification:
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Output Specification:
Print a single integer — the number of subsequences "QAQ" in the string.
Demo Input:
['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n']
Demo Output:
['4\n', '3\n']
Note:
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | ```python
n = input()
n = n.lower()
t = 0
for i in range(len(n)-2):
for j in range(i+1,len(n)-1):
for k in range(j+1,len(n)):
if n[i] == 'q' and n[j] == 'a' and n[k] == 'q':
t+=1
print(t)
``` | 3 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,608,886,520 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | import sys
multiple = 1
for line in sys.stdin:
line = line.replace(" ","")
list1 = list(line)
for x in range(len(list1) - 1):
list1[x] = int(list1[x])
print(list1)
multiple *= list1[x]
print(multiple)
print(int (multiple / 2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
import sys
multiple = 1
for line in sys.stdin:
line = line.replace(" ","")
list1 = list(line)
for x in range(len(list1) - 1):
list1[x] = int(list1[x])
print(list1)
multiple *= list1[x]
print(multiple)
print(int (multiple / 2))
``` | 0 |
8 | B | Obsession with Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"graphs",
"implementation"
] | B. Obsession with Robots | 2 | 64 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. | The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. | In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). | [
"LLUUUR\n",
"RRUULLDD\n"
] | [
"OK\n",
"BUG\n"
] | none | 0 | [
{
"input": "LLUUUR",
"output": "OK"
},
{
"input": "RRUULLDD",
"output": "BUG"
},
{
"input": "L",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "RR",
"output": "OK"
},
{
"input": "DL",
"output": "OK"
},
{
"input": "LD",
"output": "OK"
},
{
"input": "RUL",
"output": "BUG"
},
{
"input": "ULD",
"output": "BUG"
},
{
"input": "DDR",
"output": "OK"
},
{
"input": "RRDD",
"output": "OK"
},
{
"input": "RRLR",
"output": "BUG"
},
{
"input": "RRDL",
"output": "BUG"
},
{
"input": "LRUD",
"output": "BUG"
},
{
"input": "RDRLL",
"output": "BUG"
},
{
"input": "DRDRD",
"output": "OK"
},
{
"input": "ULURL",
"output": "BUG"
},
{
"input": "LUUDU",
"output": "BUG"
},
{
"input": "RDLUR",
"output": "BUG"
},
{
"input": "DLDLDDRR",
"output": "OK"
},
{
"input": "RDRDDD",
"output": "OK"
},
{
"input": "UULLDLUR",
"output": "BUG"
},
{
"input": "LULU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "URRRRRURRURUURRRRRDDDDLDDDRDDDDLLDLL",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "UL",
"output": "OK"
},
{
"input": "UDR",
"output": "BUG"
},
{
"input": "DDDR",
"output": "OK"
},
{
"input": "UUUDU",
"output": "BUG"
},
{
"input": "LULULL",
"output": "OK"
},
{
"input": "DLURUUU",
"output": "BUG"
},
{
"input": "UURUURRUUU",
"output": "OK"
},
{
"input": "DDDDRDDLDDDDDDDRDDLD",
"output": "OK"
},
{
"input": "URRRLULUURURLRLLLLULLRLRURLULRLULLULRRUU",
"output": "BUG"
},
{
"input": "RURRRRLURRRURRUURRRRRRRRDDULULRRURRRDRRRRRRRRRRLDR",
"output": "BUG"
},
{
"input": "RLRRRRRDRRDRRRRDLRRRRRRRDLRLDDLRRRRLDLDRDRRRRDRDRDRDLRRURRLRRRRDRRRRRRRRLDDRLRRDRRRRRRRDRDRLDRDDDRDR",
"output": "BUG"
},
{
"input": "DDUL",
"output": "BUG"
},
{
"input": "UUULLLLRDD",
"output": "BUG"
},
{
"input": "LLLLLLLLRRRRDDDDDDDUUUUUU",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDUUUUUUUUUUUURRRRRRRRRRRRRLLLLLLLLLLLLLLL",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "BUG"
},
{
"input": "DLUR",
"output": "BUG"
},
{
"input": "UUUURDLLLL",
"output": "BUG"
},
{
"input": "RRRRRRRRRRRURLLLLLLLLLLLL",
"output": "BUG"
},
{
"input": "LLLLLLLLLLLLLLLLLLLLLLLLLLRUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "BUG"
},
{
"input": "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "BUG"
},
{
"input": "DDLDRRR",
"output": "BUG"
},
{
"input": "RRUULLD",
"output": "BUG"
},
{
"input": "LUUUULLLLDDDDRRRD",
"output": "BUG"
},
{
"input": "DDDDLLLDDDRRRUURRRR",
"output": "BUG"
},
{
"input": "DDDDDDDLLDDRRURRRRRRR",
"output": "BUG"
},
{
"input": "DDDDDDDDDDLLLLLLLLLLLDDDDDDDDDDDRRRRRRRRRRRUUUUUUUUUURRRRRRRRRR",
"output": "BUG"
},
{
"input": "DDDLLLLLLLDDDDDDDRRRRRRRUUUUUURRR",
"output": "BUG"
},
{
"input": "RRRUUULLLDD",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLLLLDDDDRRRRUUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "BUG"
},
{
"input": "RRRRRRRRRRRDDDDDDDDDDDDDDDDDDDRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLUUUUUUUUUUU",
"output": "BUG"
}
] | 1,594,388,313 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 248 | 20,172,800 | moves = list(input())
n = len(moves)
#real (0,0) = list(n-1,n-1)
#2n -1 --> n-1 0 n -1 --> 0 n -1 2n - 1
visited = [[False] * (2*n + 1)] * (2*n + 1)
visited[n][n] = True
curr_pos_x = curr_pos_y = n
collision_detected = False
curr_move_num = 0
while not collision_detected:
#move
move = moves[curr_move_num]
if move == 'R': curr_pos_x += 1
elif move == 'L': curr_pos_x -= 1
elif move == 'U': curr_pos_y += 1
else: curr_pos_y -= 1
collision_detected = (visited[curr_pos_y][curr_pos_x] == True)
visited[curr_pos_y][curr_pos_x] = True
curr_move_num += 1
if collision_detected:
print('BUG')
else:
print('OK') | Title: Obsession with Robots
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.
Input Specification:
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
Output Specification:
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
Demo Input:
['LLUUUR\n', 'RRUULLDD\n']
Demo Output:
['OK\n', 'BUG\n']
Note:
none | ```python
moves = list(input())
n = len(moves)
#real (0,0) = list(n-1,n-1)
#2n -1 --> n-1 0 n -1 --> 0 n -1 2n - 1
visited = [[False] * (2*n + 1)] * (2*n + 1)
visited[n][n] = True
curr_pos_x = curr_pos_y = n
collision_detected = False
curr_move_num = 0
while not collision_detected:
#move
move = moves[curr_move_num]
if move == 'R': curr_pos_x += 1
elif move == 'L': curr_pos_x -= 1
elif move == 'U': curr_pos_y += 1
else: curr_pos_y -= 1
collision_detected = (visited[curr_pos_y][curr_pos_x] == True)
visited[curr_pos_y][curr_pos_x] = True
curr_move_num += 1
if collision_detected:
print('BUG')
else:
print('OK')
``` | 0 |
837 | B | Flag of Berland | PROGRAMMING | 1,600 | [
"brute force",
"implementation"
] | null | null | The flag of Berland is such rectangular field *n*<=×<=*m* that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. - Each color should be used in exactly one stripe.
You are given a field *n*<=×<=*m*, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the field.
Each of the following *n* lines consisting of *m* characters 'R', 'G' and 'B' — the description of the field. | Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). | [
"6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n",
"4 3\nBRG\nBRG\nBRG\nBRG\n",
"6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n",
"4 4\nRRRR\nRRRR\nBBBB\nGGGG\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | 0 | [
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG",
"output": "YES"
},
{
"input": "4 3\nBRG\nBRG\nBRG\nBRG",
"output": "YES"
},
{
"input": "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB",
"output": "NO"
},
{
"input": "4 4\nRRRR\nRRRR\nBBBB\nGGGG",
"output": "NO"
},
{
"input": "1 3\nGRB",
"output": "YES"
},
{
"input": "3 1\nR\nG\nB",
"output": "YES"
},
{
"input": "4 3\nRGB\nGRB\nGRB\nGRB",
"output": "NO"
},
{
"input": "4 6\nGGRRBB\nGGRRBB\nGGRRBB\nRRGGBB",
"output": "NO"
},
{
"input": "100 3\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nGRB",
"output": "NO"
},
{
"input": "3 100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRG",
"output": "NO"
},
{
"input": "3 1\nR\nR\nB",
"output": "NO"
},
{
"input": "3 2\nRR\nBB\nRR",
"output": "NO"
},
{
"input": "3 2\nRR\nBG\nBG",
"output": "NO"
},
{
"input": "3 2\nBB\nRR\nBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nRRR\nRRR",
"output": "NO"
},
{
"input": "3 3\nGGG\nGGG\nGGG",
"output": "NO"
},
{
"input": "1 3\nRGG",
"output": "NO"
},
{
"input": "4 3\nRGR\nRGR\nRGR\nRGR",
"output": "NO"
},
{
"input": "3 4\nRRGG\nRRGG\nBBBB",
"output": "NO"
},
{
"input": "3 3\nBRG\nBRG\nBRG",
"output": "YES"
},
{
"input": "3 1\nR\nG\nR",
"output": "NO"
},
{
"input": "5 3\nBBG\nBBG\nBBG\nBBG\nBBG",
"output": "NO"
},
{
"input": "3 3\nRRR\nGGG\nRRR",
"output": "NO"
},
{
"input": "1 3\nRGR",
"output": "NO"
},
{
"input": "3 6\nRRBBGG\nRRBBGG\nRRBBGG",
"output": "YES"
},
{
"input": "6 6\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG",
"output": "YES"
},
{
"input": "4 3\nRRR\nGGG\nBBB\nBBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nBBB\nRRR",
"output": "NO"
},
{
"input": "3 1\nB\nR\nB",
"output": "NO"
},
{
"input": "1 3\nBGB",
"output": "NO"
},
{
"input": "3 1\nB\nB\nB",
"output": "NO"
},
{
"input": "3 4\nRRRR\nBBBB\nRRRR",
"output": "NO"
},
{
"input": "1 6\nRGGGBB",
"output": "NO"
},
{
"input": "9 3\nBBB\nBBB\nBBB\nGGG\nGGG\nGRG\nRGR\nRRR\nRRR",
"output": "NO"
},
{
"input": "4 4\nRGBB\nRGBB\nRGBB\nRGBB",
"output": "NO"
},
{
"input": "3 3\nRBR\nRBR\nRBR",
"output": "NO"
},
{
"input": "1 6\nRRRRBB",
"output": "NO"
},
{
"input": "1 6\nRRRRRR",
"output": "NO"
},
{
"input": "1 6\nRRGGGG",
"output": "NO"
},
{
"input": "4 4\nRRRR\nRRRR\nRRRR\nRRRR",
"output": "NO"
},
{
"input": "3 1\nB\nG\nB",
"output": "NO"
},
{
"input": "3 1\nR\nR\nR",
"output": "NO"
},
{
"input": "1 9\nRRRGGGBBB",
"output": "YES"
},
{
"input": "1 3\nRRR",
"output": "NO"
},
{
"input": "3 5\nRRRRR\nBBBBB\nBBBBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nGGG\nGGG",
"output": "NO"
},
{
"input": "1 1\nR",
"output": "NO"
},
{
"input": "3 3\nRGR\nRGR\nRGR",
"output": "NO"
},
{
"input": "1 3\nGGG",
"output": "NO"
},
{
"input": "3 3\nRBG\nGBR\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGB\nRGB\nRGB",
"output": "YES"
},
{
"input": "1 3\nBRB",
"output": "NO"
},
{
"input": "2 1\nR\nB",
"output": "NO"
},
{
"input": "1 3\nRBR",
"output": "NO"
},
{
"input": "3 5\nRRGBB\nRRGBB\nRRGBB",
"output": "NO"
},
{
"input": "5 3\nBBR\nBBR\nBBR\nBBR\nBBR",
"output": "NO"
},
{
"input": "3 3\nRGB\nRBG\nRGB",
"output": "NO"
},
{
"input": "1 2\nRB",
"output": "NO"
},
{
"input": "4 3\nBBB\nBBB\nBBB\nBBB",
"output": "NO"
},
{
"input": "36 6\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR",
"output": "NO"
},
{
"input": "4 1\nR\nB\nG\nR",
"output": "NO"
},
{
"input": "13 12\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR",
"output": "NO"
},
{
"input": "2 2\nRR\nRR",
"output": "NO"
},
{
"input": "6 6\nRRGGBB\nGRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "NO"
},
{
"input": "70 3\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG",
"output": "NO"
},
{
"input": "4 3\nBBG\nBBG\nBBG\nBBG",
"output": "NO"
},
{
"input": "6 3\nBBB\nGGG\nRRR\nBRG\nBRG\nBRG",
"output": "NO"
},
{
"input": "3 6\nRRBBGG\nRBBBGG\nRBBBGG",
"output": "NO"
},
{
"input": "6 6\nGGGGGG\nGGGGGG\nBBBBBB\nBBBBBB\nGGGGGG\nGGGGGG",
"output": "NO"
},
{
"input": "6 1\nR\nB\nG\nR\nB\nG",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nBBBBB\nGGGGG\nRRRRR\nBBBBB\nGGGGG",
"output": "NO"
},
{
"input": "6 3\nRRR\nGGG\nBBB\nRRR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nRRRRR\nGGGGG\nGGGGG\nGGGGG",
"output": "NO"
},
{
"input": "15 28\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "NO"
},
{
"input": "21 10\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBGBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG",
"output": "NO"
},
{
"input": "3 2\nRR\nGB\nGB",
"output": "NO"
},
{
"input": "3 2\nRG\nRG\nBB",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nRRRRR\nRRRRR",
"output": "NO"
},
{
"input": "3 3\nRGB\nGBR\nBRG",
"output": "NO"
},
{
"input": "1 3\nRBB",
"output": "NO"
},
{
"input": "3 3\nBGR\nBGR\nBGR",
"output": "YES"
},
{
"input": "6 6\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "YES"
},
{
"input": "4 2\nRR\nGG\nRR\nBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nRRR\nGGG",
"output": "NO"
},
{
"input": "8 6\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR",
"output": "NO"
},
{
"input": "3 4\nRRRR\nRRRR\nGGGG",
"output": "NO"
},
{
"input": "3 4\nRRRR\nRRRR\nRRRR",
"output": "NO"
},
{
"input": "6 1\nR\nR\nR\nR\nR\nR",
"output": "NO"
},
{
"input": "1 6\nRRBBGG",
"output": "YES"
},
{
"input": "1 6\nRGBRGB",
"output": "NO"
},
{
"input": "3 4\nRRRR\nGGGG\nRRRR",
"output": "NO"
},
{
"input": "3 3\nRRB\nGRG\nGBB",
"output": "NO"
},
{
"input": "3 7\nRRGGBBB\nRRGGBBB\nRRGGBBB",
"output": "NO"
},
{
"input": "3 1\nG\nR\nR",
"output": "NO"
},
{
"input": "2 3\nRGG\nRBB",
"output": "NO"
},
{
"input": "3 3\nRRG\nGGG\nBBB",
"output": "NO"
},
{
"input": "3 3\nRGB\nRBB\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGR\nRGB\nRGB",
"output": "NO"
},
{
"input": "3 1\nB\nR\nR",
"output": "NO"
},
{
"input": "1 3\nGRR",
"output": "NO"
},
{
"input": "4 4\nRRRR\nGGGG\nBBBB\nBBBB",
"output": "NO"
},
{
"input": "1 3\nGGR",
"output": "NO"
},
{
"input": "3 3\nRGB\nGGB\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nGGGGGG\nGGGGGG\nGGGGGG\nBBBBBB\nBBBBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nGGGGGG\nBBBBBB\nBBBBBB\nBBBBBB",
"output": "NO"
},
{
"input": "3 1\nG\nB\nR",
"output": "YES"
},
{
"input": "3 3\nGGB\nRGB\nRGB",
"output": "NO"
},
{
"input": "3 3\nGRR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nGGGGGG\nGGGGGG\nBBBBBB\nRRRRRR",
"output": "NO"
},
{
"input": "3 3\nRRR\nGBG\nBBB",
"output": "NO"
},
{
"input": "3 8\nRRGGBBBB\nRRGGBBBB\nRRGGBBBB",
"output": "NO"
},
{
"input": "2 2\nRR\nGG",
"output": "NO"
},
{
"input": "3 3\nRGB\nRGR\nRGB",
"output": "NO"
},
{
"input": "1 3\nRBG",
"output": "YES"
},
{
"input": "2 6\nRRGGBB\nGGRRBB",
"output": "NO"
},
{
"input": "6 2\nRR\nGG\nBB\nRR\nGG\nBB",
"output": "NO"
},
{
"input": "1 5\nRRGGB",
"output": "NO"
},
{
"input": "1 2\nRG",
"output": "NO"
},
{
"input": "1 6\nRGBRBG",
"output": "NO"
},
{
"input": "1 6\nRRRGGB",
"output": "NO"
},
{
"input": "1 3\nRGB",
"output": "YES"
},
{
"input": "4 3\nRRR\nBBR\nGBB\nGGG",
"output": "NO"
},
{
"input": "6 3\nRRR\nBBB\nBBB\nBBB\nGGG\nGGG",
"output": "NO"
},
{
"input": "3 3\nRBG\nRBG\nRBG",
"output": "YES"
},
{
"input": "6 3\nRRR\nBBB\nGGG\nRRR\nBBB\nGGG",
"output": "NO"
},
{
"input": "1 4\nRGBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nGGGGG\nGGGGG\nRRRRR\nRRRRR",
"output": "NO"
},
{
"input": "3 3\nRGB\nBRG\nGBR",
"output": "NO"
},
{
"input": "6 10\nRRRRRRRRRR\nGGGGGGGGGG\nBBBBBBBBBB\nRRRRRRRRRR\nGGGGGGGGGG\nBBBBBBBBBB",
"output": "NO"
},
{
"input": "20 6\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "YES"
},
{
"input": "4 1\nR\nG\nB\nR",
"output": "NO"
},
{
"input": "1 4\nRGBR",
"output": "NO"
},
{
"input": "2 4\nRGBB\nRRGB",
"output": "NO"
}
] | 1,503,262,321 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 62 | 204,800 | n,_=map(int,input().split())
s=input()
n-=1
a=''
k=0
if 'R' in s:
k+=1
if 'G' in s:
k+=1
if 'B' in s:
k+=1
t=1
if k>1:
for _ in range(n):
s1=input()
if s1!=s:
t=0
break
elif k==1:
a+=s[0]
for _ in range(n):
s=input()
a+=s[0]
k = 0
if 'R' in s:
k += 1
if 'G' in s:
k += 1
if 'B' in s:
k += 1
if k!=1:
t=0
break
def f(a):
if len(a)%3>0:
return 1
b=len(a)//3
if a[0]*b+a[b]*b+a[-1]*b!=a:
return 1
k = 0
if 'R' in a:
k += 1
if 'G' in a:
k += 1
if 'B' in a:
k += 1
if k!=3:
return 1
return 0
if t==0 or f(a):
print('NO')
else:
print('YES')
#print(' '.join([str(a[i]) for i in range(len(a))])) | Title: Flag of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The flag of Berland is such rectangular field *n*<=×<=*m* that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. - Each color should be used in exactly one stripe.
You are given a field *n*<=×<=*m*, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input Specification:
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the field.
Each of the following *n* lines consisting of *m* characters 'R', 'G' and 'B' — the description of the field.
Output Specification:
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Demo Input:
['6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n', '4 3\nBRG\nBRG\nBRG\nBRG\n', '6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n', '4 4\nRRRR\nRRRR\nBBBB\nGGGG\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'NO\n']
Note:
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | ```python
n,_=map(int,input().split())
s=input()
n-=1
a=''
k=0
if 'R' in s:
k+=1
if 'G' in s:
k+=1
if 'B' in s:
k+=1
t=1
if k>1:
for _ in range(n):
s1=input()
if s1!=s:
t=0
break
elif k==1:
a+=s[0]
for _ in range(n):
s=input()
a+=s[0]
k = 0
if 'R' in s:
k += 1
if 'G' in s:
k += 1
if 'B' in s:
k += 1
if k!=1:
t=0
break
def f(a):
if len(a)%3>0:
return 1
b=len(a)//3
if a[0]*b+a[b]*b+a[-1]*b!=a:
return 1
k = 0
if 'R' in a:
k += 1
if 'G' in a:
k += 1
if 'B' in a:
k += 1
if k!=3:
return 1
return 0
if t==0 or f(a):
print('NO')
else:
print('YES')
#print(' '.join([str(a[i]) for i in range(len(a))]))
``` | -1 |
|
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
{
"input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1",
"output": "10"
},
{
"input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1",
"output": "29"
},
{
"input": "1\n1 1 1",
"output": "1"
},
{
"input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1",
"output": "4"
},
{
"input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "16"
}
] | 1,699,303,695 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 154 | 1,843,200 | print(len(list(filter(lambda x: x.count('1') >= 2, [input() for i in range(int(input()))]))))
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Output Specification:
Print a single integer — the number of problems the friends will implement on the contest.
Demo Input:
['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | ```python
print(len(list(filter(lambda x: x.count('1') >= 2, [input() for i in range(int(input()))]))))
``` | 3 |
|
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 1,668,111,829 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 154 | 0 | '''A. Football'''
n = input()
x=0
if '1111111' in n or '0000000' in n:
print('YES')
else:
print('NO') | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
Input Specification:
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Output Specification:
Print "YES" if the situation is dangerous. Otherwise, print "NO".
Demo Input:
['001001\n', '1000000001\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
'''A. Football'''
n = input()
x=0
if '1111111' in n or '0000000' in n:
print('YES')
else:
print('NO')
``` | 3.9615 |
697 | A | Pineapple Incident | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time. | The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. | Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. | [
"3 10 4\n",
"3 10 3\n",
"3 8 51\n",
"3 8 52\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52. | 500 | [
{
"input": "3 10 4",
"output": "NO"
},
{
"input": "3 10 3",
"output": "YES"
},
{
"input": "3 8 51",
"output": "YES"
},
{
"input": "3 8 52",
"output": "YES"
},
{
"input": "456947336 740144 45",
"output": "NO"
},
{
"input": "33 232603 599417964",
"output": "YES"
},
{
"input": "4363010 696782227 701145238",
"output": "YES"
},
{
"input": "9295078 2 6",
"output": "NO"
},
{
"input": "76079 281367 119938421",
"output": "YES"
},
{
"input": "93647 7 451664565",
"output": "YES"
},
{
"input": "5 18553 10908",
"output": "NO"
},
{
"input": "6 52 30",
"output": "NO"
},
{
"input": "6431 855039 352662",
"output": "NO"
},
{
"input": "749399100 103031711 761562532",
"output": "NO"
},
{
"input": "21 65767 55245",
"output": "NO"
},
{
"input": "4796601 66897 4860613",
"output": "NO"
},
{
"input": "8 6728951 860676",
"output": "NO"
},
{
"input": "914016 6 914019",
"output": "NO"
},
{
"input": "60686899 78474 60704617",
"output": "NO"
},
{
"input": "3 743604 201724",
"output": "NO"
},
{
"input": "571128 973448796 10",
"output": "NO"
},
{
"input": "688051712 67 51",
"output": "NO"
},
{
"input": "74619 213344 6432326",
"output": "NO"
},
{
"input": "6947541 698167 6",
"output": "NO"
},
{
"input": "83 6 6772861",
"output": "NO"
},
{
"input": "251132 67561 135026988",
"output": "NO"
},
{
"input": "8897216 734348516 743245732",
"output": "YES"
},
{
"input": "50 64536 153660266",
"output": "YES"
},
{
"input": "876884 55420 971613604",
"output": "YES"
},
{
"input": "0 6906451 366041903",
"output": "YES"
},
{
"input": "11750 8 446010134",
"output": "YES"
},
{
"input": "582692707 66997 925047377",
"output": "YES"
},
{
"input": "11 957526890 957526901",
"output": "YES"
},
{
"input": "556888 514614196 515171084",
"output": "YES"
},
{
"input": "6 328006 584834704",
"output": "YES"
},
{
"input": "4567998 4 204966403",
"output": "YES"
},
{
"input": "60 317278 109460971",
"output": "YES"
},
{
"input": "906385 342131991 685170368",
"output": "YES"
},
{
"input": "1 38 902410512",
"output": "YES"
},
{
"input": "29318 787017 587931018",
"output": "YES"
},
{
"input": "351416375 243431 368213115",
"output": "YES"
},
{
"input": "54 197366062 197366117",
"output": "YES"
},
{
"input": "586389 79039 850729874",
"output": "YES"
},
{
"input": "723634470 2814619 940360134",
"output": "YES"
},
{
"input": "0 2 0",
"output": "YES"
},
{
"input": "0 2 1",
"output": "NO"
},
{
"input": "0 2 2",
"output": "YES"
},
{
"input": "0 2 3",
"output": "YES"
},
{
"input": "0 2 1000000000",
"output": "YES"
},
{
"input": "0 10 23",
"output": "NO"
},
{
"input": "0 2 999999999",
"output": "YES"
},
{
"input": "10 5 11",
"output": "NO"
},
{
"input": "1 2 1000000000",
"output": "YES"
},
{
"input": "1 10 20",
"output": "NO"
},
{
"input": "1 2 999999937",
"output": "YES"
},
{
"input": "10 3 5",
"output": "NO"
},
{
"input": "3 2 5",
"output": "YES"
},
{
"input": "0 4 0",
"output": "YES"
},
{
"input": "0 215 403",
"output": "NO"
},
{
"input": "5 2 10",
"output": "YES"
},
{
"input": "0 2 900000000",
"output": "YES"
},
{
"input": "0 79 4000",
"output": "NO"
},
{
"input": "5 1000 1000",
"output": "NO"
},
{
"input": "1 5 103",
"output": "NO"
},
{
"input": "5 2 6",
"output": "NO"
},
{
"input": "120 2 1000000000",
"output": "YES"
},
{
"input": "2 2 1000000000",
"output": "YES"
},
{
"input": "5 5 13",
"output": "NO"
},
{
"input": "10 5 15",
"output": "YES"
},
{
"input": "11 2 0",
"output": "NO"
},
{
"input": "3 8 53",
"output": "NO"
},
{
"input": "2 2 4",
"output": "YES"
},
{
"input": "4 4 0",
"output": "NO"
},
{
"input": "1 2 3",
"output": "YES"
},
{
"input": "5 3 9",
"output": "YES"
},
{
"input": "5 6 19",
"output": "NO"
},
{
"input": "3 10 125",
"output": "NO"
},
{
"input": "5 3 8",
"output": "YES"
},
{
"input": "6 3 9",
"output": "YES"
},
{
"input": "0 3 5",
"output": "NO"
},
{
"input": "5 3 300000035",
"output": "YES"
},
{
"input": "5 2 7",
"output": "YES"
},
{
"input": "1 5 6",
"output": "YES"
},
{
"input": "4 2 6",
"output": "YES"
},
{
"input": "0 3 999999998",
"output": "NO"
},
{
"input": "0 10001 0",
"output": "YES"
},
{
"input": "6 5 3",
"output": "NO"
},
{
"input": "1 5 1000000000",
"output": "NO"
},
{
"input": "1 3 6",
"output": "NO"
},
{
"input": "3 3 1000000000",
"output": "YES"
},
{
"input": "3 3 4",
"output": "NO"
},
{
"input": "3 3 5",
"output": "NO"
},
{
"input": "3 3 0",
"output": "NO"
},
{
"input": "1 2 4",
"output": "YES"
},
{
"input": "5 5 10",
"output": "YES"
}
] | 1,698,489,635 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | t,s,x=map(int,input().split())
i=0
sum=0
if t==x:
print("YES")
check=True
else:
for i in range(1,x+1):
sum=t
if sum+(s*i)==x or sum+(s*i)+1==x:
check=True
print("YES")
break
if check==False:
print("NO") | Title: Pineapple Incident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time.
Input Specification:
The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.
Output Specification:
Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output.
Demo Input:
['3 10 4\n', '3 10 3\n', '3 8 51\n', '3 8 52\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n', 'YES\n']
Note:
In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52. | ```python
t,s,x=map(int,input().split())
i=0
sum=0
if t==x:
print("YES")
check=True
else:
for i in range(1,x+1):
sum=t
if sum+(s*i)==x or sum+(s*i)+1==x:
check=True
print("YES")
break
if check==False:
print("NO")
``` | -1 |
|
493 | A | Vasya and Football | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number *n* (1<=≤<=*n*<=≤<=90) — the number of fouls.
Each of the following *n* lines contains information about a foul in the following form:
- first goes number *t* (1<=≤<=*t*<=≤<=90) — the minute when the foul occurs; - then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; - then goes the player's number *m* (1<=≤<=*m*<=≤<=99); - then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given.
The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card.
If no player received a card, then you do not need to print anything.
It is possible case that the program will not print anything to the output (if there were no red cards). | [
"MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r\n"
] | [
"MC 25 70\nMC 42 82\nCSKA 13 90\n"
] | none | 500 | [
{
"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r",
"output": "MC 25 70\nMC 42 82\nCSKA 13 90"
},
{
"input": "REAL\nBARCA\n3\n27 h 7 y\n44 a 10 y\n87 h 3 r",
"output": "REAL 3 87"
},
{
"input": "MASFF\nSAFBDSRG\n5\n1 h 1 y\n15 h 1 r\n27 a 1 y\n58 a 1 y\n69 h 10 y",
"output": "MASFF 1 15\nSAFBDSRG 1 58"
},
{
"input": "ARMENIA\nBULGARIA\n12\n33 h 17 y\n42 h 21 y\n56 a 17 y\n58 a 6 y\n61 a 7 y\n68 a 10 y\n72 h 13 y\n73 h 21 y\n74 a 8 r\n75 a 4 y\n77 a 10 y\n90 a 23 y",
"output": "ARMENIA 21 73\nBULGARIA 8 74\nBULGARIA 10 77"
},
{
"input": "PORTUGAL\nNETHERLANDS\n16\n2 a 18 y\n7 a 3 y\n20 h 18 y\n31 h 6 y\n45 h 6 y\n50 h 8 y\n59 a 5 y\n60 h 7 y\n63 a 3 y\n72 a 20 y\n73 h 20 y\n74 a 10 y\n75 h 1 y\n76 h 14 y\n78 h 20 y\n90 a 5 y",
"output": "PORTUGAL 6 45\nNETHERLANDS 3 63\nPORTUGAL 20 78\nNETHERLANDS 5 90"
},
{
"input": "TANC\nXNCOR\n2\n15 h 27 r\n28 h 27 r",
"output": "TANC 27 15"
},
{
"input": "ASGDFJH\nAHGRSDXGER\n3\n23 h 15 r\n68 h 15 y\n79 h 15 y",
"output": "ASGDFJH 15 23"
},
{
"input": "ASFSHDSG\nADGYRTJNG\n5\n1 h 1 y\n2 h 1 y\n3 h 1 y\n4 h 1 r\n5 h 1 y",
"output": "ASFSHDSG 1 2"
},
{
"input": "A\nB\n42\n5 a 84 y\n8 h 28 r\n10 a 9 r\n11 h 93 y\n13 a 11 r\n15 h 3 r\n20 a 88 r\n23 a 41 y\n25 a 14 y\n27 a 38 r\n28 a 33 y\n29 h 66 r\n31 a 16 r\n32 a 80 y\n34 a 54 r\n35 a 50 y\n36 a 9 y\n39 a 22 y\n42 h 81 y\n43 a 10 y\n44 a 27 r\n47 h 39 y\n48 a 80 y\n50 h 5 y\n52 a 67 y\n54 h 63 y\n56 h 7 y\n57 h 44 y\n58 h 41 y\n61 h 32 y\n64 h 91 y\n67 a 56 y\n69 h 83 y\n71 h 59 y\n72 a 76 y\n75 h 41 y\n76 a 49 r\n77 a 4 r\n78 a 69 y\n79 a 96 r\n80 h 81 y\n86 h 85 r",
"output": "A 28 8\nB 9 10\nB 11 13\nA 3 15\nB 88 20\nB 38 27\nA 66 29\nB 16 31\nB 54 34\nB 27 44\nB 80 48\nA 41 75\nB 49 76\nB 4 77\nB 96 79\nA 81 80\nA 85 86"
},
{
"input": "ARM\nAZE\n45\n2 a 13 r\n3 a 73 r\n4 a 10 y\n5 h 42 y\n8 h 56 y\n10 h 15 y\n11 a 29 r\n13 a 79 y\n14 a 77 r\n18 h 7 y\n20 a 69 r\n22 h 19 y\n25 h 88 r\n26 a 78 y\n27 a 91 r\n28 h 10 r\n30 h 13 r\n31 a 26 r\n33 a 43 r\n34 a 91 y\n40 h 57 y\n44 h 18 y\n46 a 25 r\n48 a 29 y\n51 h 71 y\n57 a 16 r\n58 h 37 r\n59 h 92 y\n60 h 11 y\n61 a 88 y\n64 a 28 r\n65 h 71 r\n68 h 39 y\n70 h 8 r\n71 a 10 y\n72 a 32 y\n73 h 95 r\n74 a 33 y\n75 h 48 r\n78 a 44 y\n79 a 22 r\n80 h 50 r\n84 a 50 y\n88 a 90 y\n89 h 42 r",
"output": "AZE 13 2\nAZE 73 3\nAZE 29 11\nAZE 77 14\nAZE 69 20\nARM 88 25\nAZE 91 27\nARM 10 28\nARM 13 30\nAZE 26 31\nAZE 43 33\nAZE 25 46\nAZE 16 57\nARM 37 58\nAZE 28 64\nARM 71 65\nARM 8 70\nAZE 10 71\nARM 95 73\nARM 48 75\nAZE 22 79\nARM 50 80\nARM 42 89"
},
{
"input": "KASFLS\nASJBGGDLJFDDFHHTHJH\n42\n2 a 68 y\n4 h 64 r\n5 a 24 y\n6 h 20 r\n8 a 16 r\n9 a 96 y\n10 h 36 r\n12 a 44 y\n13 h 69 r\n16 a 62 r\n18 a 99 r\n20 h 12 r\n21 a 68 y\n25 h 40 y\n26 h 54 r\n28 h 91 r\n29 a 36 r\n33 a 91 y\n36 h 93 r\n37 h 60 r\n38 a 82 r\n41 a 85 y\n42 a 62 r\n46 a 22 r\n48 a 88 r\n49 a 8 r\n51 h 45 y\n54 a 84 y\n57 a 8 y\n59 h 24 y\n61 h 22 r\n64 h 11 r\n69 a 89 y\n72 h 44 r\n75 h 57 r\n76 h 80 y\n77 h 54 r\n79 a 1 y\n81 a 31 r\n82 h 8 y\n83 a 28 r\n86 h 56 y",
"output": "KASFLS 64 4\nKASFLS 20 6\nASJBGGDLJFDDFHHTHJH 16 8\nKASFLS 36 10\nKASFLS 69 13\nASJBGGDLJFDDFHHTHJH 62 16\nASJBGGDLJFDDFHHTHJH 99 18\nKASFLS 12 20\nASJBGGDLJFDDFHHTHJH 68 21\nKASFLS 54 26\nKASFLS 91 28\nASJBGGDLJFDDFHHTHJH 36 29\nKASFLS 93 36\nKASFLS 60 37\nASJBGGDLJFDDFHHTHJH 82 38\nASJBGGDLJFDDFHHTHJH 22 46\nASJBGGDLJFDDFHHTHJH 88 48\nASJBGGDLJFDDFHHTHJH 8 49\nKASFLS 22 61\nKASFLS 11 64\nKASFLS 44 72\nKASFLS 57 75\nASJBGGDLJFDDFHHTHJH 31 81\nASJBGGDLJFDDFHHTHJH 28 83"
},
{
"input": "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r",
"output": "AB 1 2"
}
] | 1,434,230,247 | 747 | Python 3 | OK | TESTS | 18 | 155 | 5,836,800 | __author__ = 'DK Wang'
from fractions import gcd
#Matrix = [[0 for x in range(5)] for x in range(5)]
home = input()
away = input()
n = int(input())
time = [[0 for x in range(105)] for x in range(2)]
for x in range(n):
t, ha, num, type = [x for x in input().split()]
hora = 0 if ha == 'h' else 1
add = 1 if type == 'y' else 2
num = int(num)
if(time[hora][num] < 2):
time[hora][num] += add;
if(time[hora][num] >= 2):
print((home if hora == 0 else away) + " " + str(num) + " " + t)
| Title: Vasya and Football
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya.
Input Specification:
The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number *n* (1<=≤<=*n*<=≤<=90) — the number of fouls.
Each of the following *n* lines contains information about a foul in the following form:
- first goes number *t* (1<=≤<=*t*<=≤<=90) — the minute when the foul occurs; - then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; - then goes the player's number *m* (1<=≤<=*m*<=≤<=99); - then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given.
The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.
Output Specification:
For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card.
If no player received a card, then you do not need to print anything.
It is possible case that the program will not print anything to the output (if there were no red cards).
Demo Input:
['MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r\n']
Demo Output:
['MC 25 70\nMC 42 82\nCSKA 13 90\n']
Note:
none | ```python
__author__ = 'DK Wang'
from fractions import gcd
#Matrix = [[0 for x in range(5)] for x in range(5)]
home = input()
away = input()
n = int(input())
time = [[0 for x in range(105)] for x in range(2)]
for x in range(n):
t, ha, num, type = [x for x in input().split()]
hora = 0 if ha == 'h' else 1
add = 1 if type == 'y' else 2
num = int(num)
if(time[hora][num] < 2):
time[hora][num] += add;
if(time[hora][num] >= 2):
print((home if hora == 0 else away) + " " + str(num) + " " + t)
``` | 3 |
|
269 | B | Greenhouse Effect | PROGRAMMING | 1,700 | [
"dp"
] | null | null | Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length.
Over the years Emuskald has cultivated *n* plants in his greenhouse, of *m* different plant species numbered from 1 to *m*. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.
Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange *m*<=-<=1 borders that would divide the greenhouse into *m* sections numbered from 1 to *m* from left to right with each section housing a single species. He is free to place the borders, but in the end all of the *i*-th species plants must reside in *i*-th section from the left.
Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | The first line of input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5000, *n*<=≥<=*m*), the number of plants and the number of different species. Each of the following *n* lines contain two space-separated numbers: one integer number *s**i* (1<=≤<=*s**i*<=≤<=*m*), and one real number *x**i* (0<=≤<=*x**i*<=≤<=109), the species and position of the *i*-th plant. Each *x**i* will contain no more than 6 digits after the decimal point.
It is guaranteed that all *x**i* are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their *x**i* coordinates (*x**i*<=<<=*x**i*<=+<=1,<=1<=≤<=*i*<=<<=*n*). | Output a single integer — the minimum number of plants to be replanted. | [
"3 2\n2 1\n1 2.0\n1 3.100\n",
"3 3\n1 5.0\n2 5.5\n3 6.0\n",
"6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.
In the second test case, the species are already in the correct order, so no replanting is needed. | 1,000 | [
{
"input": "3 2\n2 1\n1 2.0\n1 3.100",
"output": "1"
},
{
"input": "3 3\n1 5.0\n2 5.5\n3 6.0",
"output": "0"
},
{
"input": "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125",
"output": "2"
},
{
"input": "1 1\n1 0",
"output": "0"
},
{
"input": "8 2\n1 0.000000\n1 1.000000\n1 2.000000\n2 2.000001\n1 999999997.000000\n2 999999998.000000\n2 999999999.999999\n2 1000000000.000000",
"output": "1"
},
{
"input": "15 5\n4 6.039627\n2 7.255149\n2 14.469785\n2 15.108572\n4 22.570081\n5 26.642253\n5 32.129202\n5 44.288220\n5 53.231909\n5 60.548042\n4 62.386581\n2 77.828816\n1 87.998512\n3 96.163559\n2 99.412872",
"output": "6"
},
{
"input": "10 7\n4 70882.412953\n1 100461.912159\n3 100813.254090\n7 121632.112636\n2 424085.529781\n6 510966.713362\n6 543441.105338\n7 680094.776949\n1 721404.212606\n5 838754.272757",
"output": "5"
},
{
"input": "5 5\n5 0\n4 1\n3 2\n2 3\n1 4",
"output": "4"
},
{
"input": "12 5\n2 0\n2 1\n3 2\n3 3\n3 4\n1 5\n5 6\n3 7\n3 8\n3 9\n4 999999999\n4 1000000000",
"output": "2"
},
{
"input": "3 3\n2 0\n1 1\n3 2",
"output": "1"
},
{
"input": "3 3\n3 0\n1 1\n2 2",
"output": "1"
},
{
"input": "4 2\n1 10\n2 20\n1 30\n2 40",
"output": "1"
},
{
"input": "20 10\n1 0.000000\n2 0.000001\n3 0.000002\n4 0.000003\n5 0.000004\n6 0.000005\n7 0.000006\n8 0.000007\n9 0.000008\n10 0.000009\n1 999999999.999990\n2 999999999.999991\n3 999999999.999992\n4 999999999.999993\n5 999999999.999994\n6 999999999.999995\n7 999999999.999996\n8 999999999.999997\n9 999999999.999998\n10 999999999.999999",
"output": "9"
},
{
"input": "12 4\n3 0\n3 1\n3 2\n3 3\n3 4\n1 5\n1 6\n2 7\n4 8\n4 9\n2 10\n3 11",
"output": "5"
},
{
"input": "16 2\n1 0\n1 1\n2 2\n2 3\n2 4\n2 5\n1 6\n1 7\n2 8\n2 9\n1 10\n1 11\n2 12\n2 13\n2 14\n2 15",
"output": "4"
},
{
"input": "10 10\n1 100\n2 101\n3 102\n5 103\n9 1000\n8 10000\n6 100000\n7 1000000\n4 10000000\n10 100000000",
"output": "3"
},
{
"input": "10 6\n5 50837.108162\n3 111993.624183\n1 207268.919250\n6 567963.419694\n1 621364.247371\n2 630118.065585\n1 642135.221942\n6 642673.884754\n5 647004.198361\n4 735196.102629",
"output": "6"
},
{
"input": "20 2\n1 39277.770446\n1 131242.472574\n2 131745.437889\n1 261920.593789\n2 323611.256365\n1 341693.666730\n2 378611.498102\n2 568433.562368\n1 667757.789581\n1 674662.040626\n2 690065.099817\n2 724737.429934\n1 774858.513301\n2 783681.914774\n1 808327.402925\n2 867697.070403\n1 880911.396984\n1 929807.064277\n2 942269.265950\n1 999503.792481",
"output": "9"
},
{
"input": "20 15\n6 8719.787178\n10 13066.663722\n15 58623.690996\n9 184321.819759\n3 227999.294560\n2 279836.330518\n9 282806.308675\n8 311056.507765\n1 312315.562927\n5 459200.373445\n14 563454.265947\n7 647364.984868\n13 679761.613732\n4 684192.647497\n1 733119.607626\n7 748637.778398\n12 828048.945890\n11 893690.736585\n8 965323.895167\n5 967641.708962",
"output": "15"
},
{
"input": "15 3\n1 0\n2 1\n3 2\n1 3\n2 4\n3 5\n1 6\n2 7\n3 8\n1 9\n2 10\n3 11\n1 12\n2 13\n3 14",
"output": "8"
},
{
"input": "10 2\n2 0\n2 1\n2 2\n2 3\n2 4\n1 5\n1 6\n1 7\n1 8\n1 9",
"output": "5"
},
{
"input": "11 3\n2 0\n2 1\n2 2\n2 3\n2 4\n3 5\n1 6\n1 7\n1 8\n1 9\n1 10",
"output": "5"
}
] | 1,463,998,730 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 4,608,000 | n, m = map( int, input().split() )
s = [0]
for i in range(n):
x, y = input().split()
s.append(int(x))
f = [0] * (n+1)
for i in range(1, n+1):
for j in range(i):
if s[i] >= s[j]:
f[i] = max( f[i], f[j] + 1 )
else:
f[i] = max( f[i], f[j] )
print(n-f[n])
| Title: Greenhouse Effect
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length.
Over the years Emuskald has cultivated *n* plants in his greenhouse, of *m* different plant species numbered from 1 to *m*. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.
Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange *m*<=-<=1 borders that would divide the greenhouse into *m* sections numbered from 1 to *m* from left to right with each section housing a single species. He is free to place the borders, but in the end all of the *i*-th species plants must reside in *i*-th section from the left.
Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders.
Input Specification:
The first line of input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5000, *n*<=≥<=*m*), the number of plants and the number of different species. Each of the following *n* lines contain two space-separated numbers: one integer number *s**i* (1<=≤<=*s**i*<=≤<=*m*), and one real number *x**i* (0<=≤<=*x**i*<=≤<=109), the species and position of the *i*-th plant. Each *x**i* will contain no more than 6 digits after the decimal point.
It is guaranteed that all *x**i* are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their *x**i* coordinates (*x**i*<=<<=*x**i*<=+<=1,<=1<=≤<=*i*<=<<=*n*).
Output Specification:
Output a single integer — the minimum number of plants to be replanted.
Demo Input:
['3 2\n2 1\n1 2.0\n1 3.100\n', '3 3\n1 5.0\n2 5.5\n3 6.0\n', '6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.
In the second test case, the species are already in the correct order, so no replanting is needed. | ```python
n, m = map( int, input().split() )
s = [0]
for i in range(n):
x, y = input().split()
s.append(int(x))
f = [0] * (n+1)
for i in range(1, n+1):
for j in range(i):
if s[i] >= s[j]:
f[i] = max( f[i], f[j] + 1 )
else:
f[i] = max( f[i], f[j] )
print(n-f[n])
``` | 0 |
|
4 | B | Before an Exam | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy"
] | B. Before an Exam | 0 | 64 | Tomorrow Peter has a Biology exam. He does not like this subject much, but *d* days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than *minTime**i* and not more than *maxTime**i* hours per each *i*-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours *sumTime* spent him on preparation, and now he wants to know if he can show his parents a timetable *sсhedule* with *d* numbers, where each number *sсhedule**i* stands for the time in hours spent by Peter each *i*-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all *schedule**i* should equal to *sumTime*. | The first input line contains two integer numbers *d*,<=*sumTime* (1<=≤<=*d*<=≤<=30,<=0<=≤<=*sumTime*<=≤<=240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following *d* lines contains two integer numbers *minTime**i*,<=*maxTime**i* (0<=≤<=*minTime**i*<=≤<=*maxTime**i*<=≤<=8), separated by a space — minimum and maximum amount of hours that Peter could spent in the *i*-th day. | In the first line print YES, and in the second line print *d* numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them. | [
"1 48\n5 7\n",
"2 5\n0 1\n3 5\n"
] | [
"NO\n",
"YES\n1 4 "
] | none | 0 | [
{
"input": "1 48\n5 7",
"output": "NO"
},
{
"input": "2 5\n0 1\n3 5",
"output": "YES\n1 4 "
},
{
"input": "1 1\n5 6",
"output": "NO"
},
{
"input": "1 4\n2 4",
"output": "YES\n4 "
},
{
"input": "2 5\n4 6\n0 0",
"output": "YES\n5 0 "
},
{
"input": "27 97\n2 8\n0 5\n5 6\n3 6\n5 5\n1 2\n3 5\n1 8\n0 4\n3 3\n0 2\n0 0\n4 8\n5 6\n5 8\n0 7\n1 4\n0 4\n1 5\n3 7\n2 5\n5 6\n4 7\n3 8\n0 1\n3 4\n5 7",
"output": "YES\n8 5 6 6 5 2 5 8 4 3 2 0 6 5 5 0 1 0 1 3 2 5 4 3 0 3 5 "
},
{
"input": "30 92\n4 5\n4 7\n2 6\n8 8\n7 8\n4 5\n1 5\n7 8\n1 2\n6 8\n2 7\n2 4\n0 0\n1 3\n4 5\n1 1\n0 7\n2 5\n2 5\n3 3\n1 2\n1 7\n5 5\n5 8\n6 7\n0 3\n2 6\n0 7\n5 6\n2 5",
"output": "YES\n5 7 2 8 7 4 1 7 1 6 2 2 0 1 4 1 0 2 2 3 1 1 5 5 6 0 2 0 5 2 "
},
{
"input": "30 178\n1 6\n2 7\n2 5\n2 8\n1 6\n2 8\n3 4\n2 7\n0 2\n0 8\n0 3\n0 2\n2 4\n4 8\n6 8\n0 8\n0 6\n1 8\n0 3\n6 7\n4 8\n2 7\n1 1\n3 7\n3 6\n2 5\n4 7\n2 2\n1 8\n5 6",
"output": "NO"
},
{
"input": "30 71\n1 3\n0 6\n3 5\n3 6\n2 4\n2 8\n2 4\n3 8\n3 5\n2 4\n2 3\n3 7\n0 0\n5 7\n0 2\n5 8\n0 8\n4 7\n0 3\n3 7\n2 3\n4 5\n7 8\n7 7\n2 7\n1 3\n0 1\n1 5\n6 7\n5 8",
"output": "NO"
},
{
"input": "30 119\n2 7\n1 3\n0 3\n3 4\n7 7\n7 7\n0 5\n2 3\n0 8\n0 8\n0 5\n5 7\n2 2\n2 6\n2 5\n3 7\n0 8\n0 2\n1 3\n2 3\n1 4\n0 1\n3 7\n7 8\n1 2\n0 6\n1 8\n1 7\n4 8\n1 4",
"output": "YES\n7 3 3 4 7 7 5 3 8 8 5 7 2 6 5 7 8 2 1 2 1 0 3 7 1 0 1 1 4 1 "
},
{
"input": "1 0\n0 0",
"output": "YES\n0 "
},
{
"input": "30 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "YES\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 "
},
{
"input": "30 240\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8",
"output": "YES\n8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 "
},
{
"input": "30 64\n7 7\n3 4\n0 4\n5 8\n1 3\n1 1\n0 2\n0 4\n7 7\n3 5\n4 4\n0 4\n4 5\n1 4\n4 6\n5 7\n1 4\n1 2\n3 3\n0 2\n3 7\n3 4\n0 3\n3 8\n0 8\n0 1\n0 3\n4 5\n1 5\n0 3",
"output": "YES\n7 3 0 5 1 1 0 0 7 3 4 0 4 1 4 5 1 1 3 0 3 3 0 3 0 0 0 4 1 0 "
},
{
"input": "30 189\n0 8\n3 8\n5 8\n2 2\n7 7\n2 8\n7 8\n2 5\n1 7\n0 1\n3 4\n1 7\n1 6\n5 6\n3 7\n4 7\n4 7\n4 7\n5 5\n0 5\n4 7\n3 5\n0 6\n4 8\n2 5\n5 6\n5 6\n2 8\n0 7\n7 8",
"output": "YES\n8 8 8 2 7 8 8 5 7 1 4 7 6 6 7 7 7 7 5 5 7 5 6 8 5 6 6 8 7 8 "
}
] | 1,691,265,362 | 2,162 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | sentinel = ''
arr=[]
for line in iter(input, ''):
a,b=map(int,str(line).split(" "))
arr.append([a,b])
d,sumTime=arr[0]
tesMa=0
tesMi=0
for i in range(1,len(arr)):
tesMa+=arr[i][1]
tesMi += arr[i][0]
if tesMi<=sumTime<=tesMa:
print("YES")
else:
print("NO") | Title: Before an Exam
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
Tomorrow Peter has a Biology exam. He does not like this subject much, but *d* days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than *minTime**i* and not more than *maxTime**i* hours per each *i*-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours *sumTime* spent him on preparation, and now he wants to know if he can show his parents a timetable *sсhedule* with *d* numbers, where each number *sсhedule**i* stands for the time in hours spent by Peter each *i*-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all *schedule**i* should equal to *sumTime*.
Input Specification:
The first input line contains two integer numbers *d*,<=*sumTime* (1<=≤<=*d*<=≤<=30,<=0<=≤<=*sumTime*<=≤<=240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following *d* lines contains two integer numbers *minTime**i*,<=*maxTime**i* (0<=≤<=*minTime**i*<=≤<=*maxTime**i*<=≤<=8), separated by a space — minimum and maximum amount of hours that Peter could spent in the *i*-th day.
Output Specification:
In the first line print YES, and in the second line print *d* numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.
Demo Input:
['1 48\n5 7\n', '2 5\n0 1\n3 5\n']
Demo Output:
['NO\n', 'YES\n1 4 ']
Note:
none | ```python
sentinel = ''
arr=[]
for line in iter(input, ''):
a,b=map(int,str(line).split(" "))
arr.append([a,b])
d,sumTime=arr[0]
tesMa=0
tesMi=0
for i in range(1,len(arr)):
tesMa+=arr[i][1]
tesMi += arr[i][0]
if tesMi<=sumTime<=tesMa:
print("YES")
else:
print("NO")
``` | -1 |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any *n*. | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not a prime number. | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "6",
"output": "4"
},
{
"input": "7",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "11",
"output": "1"
},
{
"input": "998",
"output": "1"
},
{
"input": "996",
"output": "3"
},
{
"input": "36",
"output": "4"
},
{
"input": "210",
"output": "4"
},
{
"input": "270",
"output": "4"
},
{
"input": "306",
"output": "4"
},
{
"input": "330",
"output": "5"
},
{
"input": "336",
"output": "4"
},
{
"input": "600",
"output": "4"
},
{
"input": "726",
"output": "4"
},
{
"input": "988",
"output": "1"
},
{
"input": "12",
"output": "2"
},
{
"input": "987",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "986",
"output": "1"
},
{
"input": "14",
"output": "1"
},
{
"input": "985",
"output": "1"
},
{
"input": "15",
"output": "1"
},
{
"input": "984",
"output": "1"
},
{
"input": "16",
"output": "2"
},
{
"input": "983",
"output": "1"
},
{
"input": "17",
"output": "1"
},
{
"input": "982",
"output": "2"
},
{
"input": "18",
"output": "3"
},
{
"input": "981",
"output": "1"
},
{
"input": "19",
"output": "1"
},
{
"input": "980",
"output": "1"
},
{
"input": "20",
"output": "1"
},
{
"input": "979",
"output": "1"
},
{
"input": "21",
"output": "1"
},
{
"input": "978",
"output": "1"
},
{
"input": "22",
"output": "2"
},
{
"input": "977",
"output": "1"
},
{
"input": "23",
"output": "1"
},
{
"input": "976",
"output": "2"
},
{
"input": "24",
"output": "1"
},
{
"input": "975",
"output": "1"
},
{
"input": "25",
"output": "1"
},
{
"input": "2",
"output": "4"
},
{
"input": "6",
"output": "4"
},
{
"input": "996",
"output": "3"
},
{
"input": "8",
"output": "1"
},
{
"input": "998",
"output": "1"
},
{
"input": "330",
"output": "5"
},
{
"input": "18",
"output": "3"
},
{
"input": "12",
"output": "2"
},
{
"input": "24",
"output": "1"
},
{
"input": "999",
"output": "1"
},
{
"input": "726",
"output": "4"
},
{
"input": "876",
"output": "3"
}
] | 1,610,434,873 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 78 | 0 | from math import sqrt
n=int(input())
m=1
while True:
x=(n*m)+1
flag=0
for _ in range(2,int(sqrt(x))+1):
if x%_==0:
flag=1
break
if flag==1:
print(m)
break
m+=1
| Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any *n*.
Input Specification:
The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis.
Output Specification:
Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists.
Demo Input:
['3\n', '4\n']
Demo Output:
['1', '2']
Note:
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not a prime number. | ```python
from math import sqrt
n=int(input())
m=1
while True:
x=(n*m)+1
flag=0
for _ in range(2,int(sqrt(x))+1):
if x%_==0:
flag=1
break
if flag==1:
print(m)
break
m+=1
``` | 3 |
|
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible. | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them. | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51"
},
{
"input": "4\n82 46 8 44",
"output": "3 1\n4 2"
},
{
"input": "2\n35 50",
"output": "1 2"
},
{
"input": "8\n24 39 49 38 44 64 44 50",
"output": "1 6\n4 8\n2 3\n5 7"
},
{
"input": "100\n23 44 35 88 10 78 8 84 46 19 69 36 81 60 46 12 53 22 83 73 6 18 80 14 54 39 74 42 34 20 91 70 32 11 80 53 70 21 24 12 87 68 35 39 8 84 81 70 8 54 73 2 60 71 4 33 65 48 69 58 55 57 78 61 45 50 55 72 86 37 5 11 12 81 32 19 22 11 22 82 23 56 61 84 47 59 31 38 31 90 57 1 24 38 68 27 80 9 37 14",
"output": "92 31\n52 90\n55 4\n71 41\n21 69\n7 84\n45 46\n49 8\n98 19\n5 80\n34 74\n72 47\n78 13\n16 97\n40 35\n73 23\n24 63\n100 6\n22 27\n10 51\n76 20\n30 68\n38 54\n18 48\n77 37\n79 32\n1 59\n81 11\n39 95\n93 42\n96 57\n87 83\n89 64\n33 53\n75 14\n56 86\n29 60\n3 91\n43 62\n12 82\n70 67\n99 61\n88 50\n94 25\n26 36\n44 17\n28 66\n2 58\n65 85\n9 15"
},
{
"input": "12\n22 83 2 67 55 12 40 93 83 73 12 28",
"output": "3 8\n6 9\n11 2\n1 10\n12 4\n7 5"
},
{
"input": "16\n10 33 36 32 48 25 31 27 45 13 37 26 22 21 15 43",
"output": "1 5\n10 9\n15 16\n14 11\n13 3\n6 2\n12 4\n8 7"
},
{
"input": "20\n18 13 71 60 28 10 20 65 65 12 13 14 64 68 6 50 72 7 66 58",
"output": "15 17\n18 3\n6 14\n10 19\n2 9\n11 8\n12 13\n1 4\n7 20\n5 16"
},
{
"input": "24\n59 39 25 22 46 21 24 70 60 11 46 42 44 37 13 37 41 58 72 23 25 61 58 62",
"output": "10 19\n15 8\n6 24\n4 22\n20 9\n7 1\n3 23\n21 18\n14 11\n16 5\n2 13\n17 12"
},
{
"input": "28\n22 1 51 31 83 35 3 64 59 10 61 25 19 53 55 80 78 8 82 22 67 4 27 64 33 6 85 76",
"output": "2 27\n7 5\n22 19\n26 16\n18 17\n10 28\n13 21\n1 24\n20 8\n12 11\n23 9\n4 15\n25 14\n6 3"
},
{
"input": "32\n41 42 22 68 40 52 66 16 73 25 41 21 36 60 46 30 24 55 35 10 54 52 70 24 20 56 3 34 35 6 51 8",
"output": "27 9\n30 23\n32 4\n20 7\n8 14\n25 26\n12 18\n3 21\n17 22\n24 6\n10 31\n16 15\n28 2\n19 11\n29 1\n13 5"
},
{
"input": "36\n1 10 61 43 27 49 55 33 7 30 45 78 69 34 38 19 36 49 55 11 30 63 46 24 16 68 71 18 11 52 72 24 60 68 8 41",
"output": "1 12\n9 31\n35 27\n2 13\n20 34\n29 26\n25 22\n28 3\n16 33\n24 19\n32 7\n5 30\n10 18\n21 6\n8 23\n14 11\n17 4\n15 36"
},
{
"input": "40\n7 30 13 37 37 56 45 28 61 28 23 33 44 63 58 52 21 2 42 19 10 32 9 7 61 15 58 20 45 4 46 24 35 17 50 4 20 48 41 55",
"output": "18 14\n30 25\n36 9\n1 27\n24 15\n23 6\n21 40\n3 16\n26 35\n34 38\n20 31\n28 29\n37 7\n17 13\n11 19\n32 39\n8 5\n10 4\n2 33\n22 12"
},
{
"input": "44\n7 12 46 78 24 68 86 22 71 79 85 14 58 72 26 46 54 39 35 13 31 45 81 21 15 8 47 64 69 87 57 6 18 80 47 29 36 62 34 67 59 48 75 25",
"output": "32 30\n1 7\n26 11\n2 23\n20 34\n12 10\n25 4\n33 43\n24 14\n8 9\n5 29\n44 6\n15 40\n36 28\n21 38\n39 41\n19 13\n37 31\n18 17\n22 42\n3 35\n16 27"
},
{
"input": "48\n57 38 16 25 34 57 29 38 60 51 72 78 22 39 10 33 20 16 12 3 51 74 9 88 4 70 56 65 86 18 33 12 77 78 52 87 68 85 81 5 61 2 52 39 80 13 74 30",
"output": "42 24\n20 36\n25 29\n40 38\n23 39\n15 45\n19 34\n32 12\n46 33\n3 47\n18 22\n30 11\n17 26\n13 37\n4 28\n7 41\n48 9\n16 6\n31 1\n5 27\n2 43\n8 35\n14 21\n44 10"
},
{
"input": "52\n57 12 13 40 68 31 18 4 31 18 65 3 62 32 6 3 49 48 51 33 53 40 9 32 47 53 58 19 14 23 32 38 39 69 19 20 62 52 68 17 39 22 54 59 3 2 52 9 67 68 24 39",
"output": "46 34\n12 50\n16 39\n45 5\n8 49\n15 11\n23 37\n48 13\n2 44\n3 27\n29 1\n40 43\n7 26\n10 21\n28 47\n35 38\n36 19\n42 17\n30 18\n51 25\n6 22\n9 4\n14 52\n24 41\n31 33\n20 32"
},
{
"input": "56\n53 59 66 68 71 25 48 32 12 61 72 69 30 6 56 55 25 49 60 47 46 46 66 19 31 9 23 15 10 12 71 53 51 32 39 31 66 66 17 52 12 7 7 22 49 12 71 29 63 7 47 29 18 39 27 26",
"output": "14 11\n42 47\n43 31\n50 5\n26 12\n29 4\n9 38\n30 37\n41 23\n46 3\n28 49\n39 10\n53 19\n24 2\n44 15\n27 16\n6 32\n17 1\n56 40\n55 33\n48 45\n52 18\n13 7\n25 51\n36 20\n8 22\n34 21\n35 54"
},
{
"input": "60\n47 63 20 68 46 12 45 44 14 38 28 73 60 5 20 18 70 64 37 47 26 47 37 61 29 61 23 28 30 68 55 22 25 60 38 7 63 12 38 15 14 30 11 5 70 15 53 52 7 57 49 45 55 37 45 28 50 2 31 30",
"output": "58 12\n14 45\n44 17\n36 30\n49 4\n43 18\n6 37\n38 2\n9 26\n41 24\n40 34\n46 13\n16 50\n3 53\n15 31\n32 47\n27 48\n33 57\n21 51\n11 22\n28 20\n56 1\n25 5\n29 55\n42 52\n60 7\n59 8\n19 39\n23 35\n54 10"
},
{
"input": "64\n63 39 19 5 48 56 49 45 29 68 25 59 37 69 62 26 60 44 60 6 67 68 2 40 56 6 19 12 17 70 23 11 59 37 41 55 30 68 72 14 38 34 3 71 2 4 55 15 31 66 15 51 36 72 18 7 6 14 43 33 8 35 57 18",
"output": "23 54\n45 39\n43 44\n46 30\n4 14\n20 38\n26 22\n57 10\n56 21\n61 50\n32 1\n28 15\n40 19\n58 17\n48 33\n51 12\n29 63\n55 25\n64 6\n3 47\n27 36\n31 52\n11 7\n16 5\n9 8\n37 18\n49 59\n60 35\n42 24\n62 2\n53 41\n13 34"
},
{
"input": "68\n58 68 40 55 62 15 10 54 19 18 69 27 15 53 8 18 8 33 15 49 20 9 70 8 18 64 14 59 9 64 3 35 46 11 5 65 58 55 28 58 4 55 64 5 68 24 4 58 23 45 58 50 38 68 5 15 20 9 5 53 20 63 69 68 15 53 65 65",
"output": "31 23\n41 63\n47 11\n35 64\n44 54\n55 45\n59 2\n15 68\n17 67\n24 36\n22 43\n29 30\n58 26\n7 62\n34 5\n27 28\n6 51\n13 48\n19 40\n56 37\n65 1\n10 42\n16 38\n25 4\n9 8\n21 66\n57 60\n61 14\n49 52\n46 20\n12 33\n39 50\n18 3\n32 53"
},
{
"input": "72\n61 13 55 23 24 55 44 33 59 19 14 17 66 40 27 33 29 37 28 74 50 56 59 65 64 17 42 56 73 51 64 23 22 26 38 22 36 47 60 14 52 28 14 12 6 41 73 5 64 67 61 74 54 34 45 34 44 4 34 49 18 72 44 47 31 19 11 31 5 4 45 50",
"output": "58 52\n70 20\n48 47\n69 29\n45 62\n67 50\n44 13\n2 24\n11 49\n40 31\n43 25\n12 51\n26 1\n61 39\n10 23\n66 9\n33 28\n36 22\n4 6\n32 3\n5 53\n34 41\n15 30\n19 72\n42 21\n17 60\n65 64\n68 38\n8 71\n16 55\n54 63\n56 57\n59 7\n37 27\n18 46\n35 14"
},
{
"input": "76\n73 37 73 67 26 45 43 74 47 31 43 81 4 3 39 79 48 81 67 39 67 66 43 67 80 51 34 79 5 58 45 10 39 50 9 78 6 18 75 17 45 17 51 71 34 53 33 11 17 15 11 69 50 41 13 74 10 33 77 41 11 64 36 74 17 32 3 10 27 20 5 73 52 41 7 57",
"output": "14 18\n67 12\n13 25\n29 28\n71 16\n37 36\n75 59\n35 39\n32 64\n57 56\n68 8\n48 72\n51 3\n61 1\n55 44\n50 52\n40 24\n42 21\n49 19\n65 4\n38 22\n70 62\n5 30\n69 76\n10 46\n66 73\n47 43\n58 26\n27 53\n45 34\n63 17\n2 9\n15 41\n20 31\n33 6\n54 23\n60 11\n74 7"
},
{
"input": "80\n18 38 65 1 20 9 57 2 36 26 15 17 33 61 65 27 10 35 49 42 40 32 19 33 12 36 56 31 10 41 8 54 56 60 5 47 61 43 23 19 20 30 7 6 38 60 29 58 35 64 30 51 6 17 30 24 47 1 37 47 34 36 48 28 5 25 47 19 30 39 36 23 31 28 46 46 59 43 19 49",
"output": "4 15\n58 3\n8 50\n35 37\n65 14\n44 46\n53 34\n43 77\n31 48\n6 7\n17 33\n29 27\n25 32\n11 52\n12 80\n54 19\n1 63\n23 67\n40 60\n68 57\n79 36\n5 76\n41 75\n39 78\n72 38\n56 20\n66 30\n10 21\n16 70\n64 45\n74 2\n47 59\n42 71\n51 62\n55 26\n69 9\n28 49\n73 18\n22 61\n13 24"
},
{
"input": "84\n59 41 54 14 42 55 29 28 41 73 40 15 1 1 66 49 76 59 68 60 42 81 19 23 33 12 80 81 42 22 54 54 2 22 22 28 27 60 36 57 17 76 38 20 40 65 23 9 81 50 25 13 46 36 59 53 6 35 47 40 59 19 67 46 63 49 12 33 23 49 33 23 32 62 60 70 44 1 6 63 28 16 70 69",
"output": "13 49\n14 28\n78 22\n33 27\n57 42\n79 17\n48 10\n26 83\n67 76\n52 84\n4 19\n12 63\n82 15\n41 46\n23 80\n62 65\n44 74\n30 75\n34 38\n35 20\n24 61\n47 55\n69 18\n72 1\n51 40\n37 6\n8 32\n36 31\n81 3\n7 56\n73 50\n25 70\n68 66\n71 16\n58 59\n39 64\n54 53\n43 77\n11 29\n45 21\n60 5\n2 9"
},
{
"input": "88\n10 28 71 6 58 66 45 52 13 71 39 1 10 29 30 70 14 17 15 38 4 60 5 46 66 41 40 58 2 57 32 44 21 26 13 40 64 63 56 33 46 8 30 43 67 55 44 28 32 62 14 58 42 67 45 59 32 68 10 31 51 6 42 34 9 12 51 27 20 14 62 42 16 5 1 14 30 62 40 59 58 26 25 15 27 47 21 57",
"output": "12 10\n75 3\n29 16\n21 58\n23 54\n74 45\n4 25\n62 6\n42 37\n65 38\n1 78\n13 71\n59 50\n66 22\n9 80\n35 56\n17 81\n51 52\n70 28\n76 5\n19 88\n84 30\n73 39\n18 46\n69 8\n33 67\n87 61\n83 86\n34 41\n82 24\n68 55\n85 7\n2 47\n48 32\n14 44\n15 72\n43 63\n77 53\n60 26\n31 79\n49 36\n57 27\n40 11\n64 20"
},
{
"input": "92\n17 37 81 15 29 70 73 42 49 23 44 77 27 44 74 11 43 66 15 41 60 36 33 11 2 76 16 51 45 21 46 16 85 29 76 79 16 6 60 13 25 44 62 28 43 35 63 24 76 71 62 15 57 72 45 10 71 59 74 14 53 13 58 72 14 72 73 11 25 1 57 42 86 63 50 30 64 38 10 77 75 24 58 8 54 12 43 30 27 71 52 34",
"output": "70 73\n25 33\n38 3\n84 36\n56 80\n79 12\n16 49\n24 35\n68 26\n86 81\n40 59\n62 15\n60 67\n65 7\n4 66\n19 64\n52 54\n27 90\n32 57\n37 50\n1 6\n30 18\n10 77\n48 74\n82 47\n41 51\n69 43\n13 39\n89 21\n44 58\n5 83\n34 63\n76 71\n88 53\n23 85\n92 61\n46 91\n22 28\n2 75\n78 9\n20 31\n8 55\n72 29\n17 42\n45 14\n87 11"
},
{
"input": "96\n77 7 47 19 73 31 46 13 89 69 52 9 26 77 6 87 55 45 71 2 79 1 80 20 4 82 64 20 75 86 84 24 77 56 16 54 53 35 74 73 40 29 63 20 83 39 58 16 31 41 40 16 11 90 30 48 62 39 55 8 50 3 77 73 75 66 14 90 18 54 38 10 53 22 67 38 27 91 62 37 85 13 92 7 18 83 10 3 86 54 80 59 34 16 39 43",
"output": "22 83\n20 78\n62 68\n88 54\n25 9\n15 16\n2 89\n84 30\n60 81\n12 31\n72 86\n87 45\n53 26\n8 91\n82 23\n67 21\n35 63\n48 33\n52 14\n94 1\n69 65\n85 29\n4 39\n24 64\n28 40\n44 5\n74 19\n32 10\n13 75\n77 66\n42 27\n55 43\n6 79\n49 57\n93 92\n38 47\n80 34\n71 59\n76 17\n46 90\n58 70\n95 36\n41 73\n51 37\n50 11\n96 61\n18 56\n7 3"
},
{
"input": "4\n100 100 1 1",
"output": "3 2\n4 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 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51"
},
{
"input": "4\n3 4 4 5",
"output": "1 4\n2 3"
},
{
"input": "4\n1 1 2 2",
"output": "1 4\n2 3"
},
{
"input": "4\n1 2 3 4",
"output": "1 4\n2 3"
}
] | 1,585,652,968 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 307,200 | n = int(input())
a = list(map(int, input().split()))
b = [0]*n
k = sum(a)/n*2
for j in range(len(a)):
for i in range(j+1, len(a)):
if a[j]+a[i]==k and b[j]==0 and b[i]==0:
print(j+1, i+1)
b[j]=1
b[i]=1
break | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card.
Output Specification:
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.
Demo Input:
['6\n1 5 7 4 4 3\n', '4\n10 10 10 10\n']
Demo Output:
['1 3\n6 2\n4 5\n', '1 2\n3 4\n']
Note:
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | ```python
n = int(input())
a = list(map(int, input().split()))
b = [0]*n
k = sum(a)/n*2
for j in range(len(a)):
for i in range(j+1, len(a)):
if a[j]+a[i]==k and b[j]==0 and b[i]==0:
print(j+1, i+1)
b[j]=1
b[i]=1
break
``` | 3 |
|
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20 1 80",
"output": "1 20 40 60 80 100 "
},
{
"input": "10\n10 8 6 7 5 3 4 2 9 1",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 "
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 1 2 3 4 6 7 7 8 9 "
},
{
"input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59",
"output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 "
},
{
"input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12",
"output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 "
},
{
"input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84",
"output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 "
},
{
"input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1",
"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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 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": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52",
"output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 "
},
{
"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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1",
"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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3",
"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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 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": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3",
"output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 "
},
{
"input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32",
"output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 "
},
{
"input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41",
"output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 "
},
{
"input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82",
"output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 "
},
{
"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": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "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": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 "
},
{
"input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 "
},
{
"input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88",
"output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 "
},
{
"input": "100\n100 51 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"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 2 51 100 "
},
{
"input": "10\n100 90 80 70 60 50 40 30 20 10",
"output": "10 20 30 40 50 60 70 80 90 100 "
},
{
"input": "1\n10",
"output": "10 "
}
] | 1,697,016,278 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | t=int(input())
for _ in range(t):
n=int(input())
arr=list(map(int, input().split()))
c=list()
for i in range(n):
c.append(0)
for i in range(n):
c[arr[i]]+=1
for i in range(n):
if c[i]>=2:
print(i,end=' ')
print()
| Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
Input Specification:
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output Specification:
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
Demo Input:
['4\n3 2 1 2\n', '3\n2 3 8\n']
Demo Output:
['1 2 2 3 \n', '2 3 8 \n']
Note:
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | ```python
t=int(input())
for _ in range(t):
n=int(input())
arr=list(map(int, input().split()))
c=list()
for i in range(n):
c.append(0)
for i in range(n):
c[arr[i]]+=1
for i in range(n):
if c[i]>=2:
print(i,end=' ')
print()
``` | -1 |
|
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days? | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697681824",
"output": "14"
},
{
"input": "41313494",
"output": "14"
},
{
"input": "673935585",
"output": "13"
},
{
"input": "117422204",
"output": "19"
},
{
"input": "954746654",
"output": "15"
},
{
"input": "536838144",
"output": "14"
},
{
"input": "1000000000",
"output": "13"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "1"
},
{
"input": "6",
"output": "2"
},
{
"input": "7",
"output": "3"
},
{
"input": "9",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "999999999",
"output": "21"
},
{
"input": "999999998",
"output": "20"
},
{
"input": "999999997",
"output": "20"
},
{
"input": "999999996",
"output": "19"
},
{
"input": "999999995",
"output": "20"
},
{
"input": "999999994",
"output": "19"
},
{
"input": "999999993",
"output": "19"
},
{
"input": "999999992",
"output": "18"
},
{
"input": "999999991",
"output": "20"
},
{
"input": "999999990",
"output": "19"
},
{
"input": "536870910",
"output": "28"
},
{
"input": "536870912",
"output": "1"
},
{
"input": "536870913",
"output": "2"
},
{
"input": "536870914",
"output": "2"
},
{
"input": "22",
"output": "3"
},
{
"input": "14",
"output": "3"
}
] | 1,697,098,653 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | n=int(input())
s=1
while n!=1:
if n%2==0:
n//=2
else:
s+=1
n-=1
print(s) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days?
Input Specification:
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
Output Specification:
The only line containing one integer: the answer.
Demo Input:
['5\n', '8\n']
Demo Output:
['2\n', '1\n']
Note:
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | ```python
n=int(input())
s=1
while n!=1:
if n%2==0:
n//=2
else:
s+=1
n-=1
print(s)
``` | 3 |
|
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides? | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "10 2 1 1",
"output": "5"
},
{
"input": "1 1000 1 2",
"output": "1"
},
{
"input": "1 1000 3 2",
"output": "2"
},
{
"input": "10 3 1 2",
"output": "7"
},
{
"input": "995 1 2 1",
"output": "995"
},
{
"input": "556 2 16 15",
"output": "4170"
},
{
"input": "477 2 16 14",
"output": "3346"
},
{
"input": "101 110 1 100",
"output": "100"
},
{
"input": "9 3 3 10",
"output": "27"
},
{
"input": "100 8 10 1",
"output": "13"
},
{
"input": "6 4 1 3",
"output": "5"
},
{
"input": "8 5 2 8",
"output": "14"
},
{
"input": "1000 2 1 1000",
"output": "1000"
}
] | 1,698,589,321 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | import math
n, m, a, b = input().split()
n, m, a, b = int(n), int(m), int(a), int(b)
cost = [(n%m)*a + int(n/m)*b, n*a, math.ceil(n/m*b)]
cost.sort()
print(cost[0])
| Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides?
Input Specification:
The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket.
Output Specification:
Print a single integer — the minimum sum in rubles that Ann will need to spend.
Demo Input:
['6 2 1 2\n', '5 2 2 3\n']
Demo Output:
['6\n', '8\n']
Note:
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | ```python
import math
n, m, a, b = input().split()
n, m, a, b = int(n), int(m), int(a), int(b)
cost = [(n%m)*a + int(n/m)*b, n*a, math.ceil(n/m*b)]
cost.sort()
print(cost[0])
``` | 0 |
|
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.
How many times can Artem give presents to Masha? | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"
},
{
"input": "1000000000",
"output": "666666667"
},
{
"input": "5",
"output": "3"
},
{
"input": "6",
"output": "4"
},
{
"input": "999999999",
"output": "666666666"
},
{
"input": "999999998",
"output": "666666665"
},
{
"input": "999999997",
"output": "666666665"
},
{
"input": "999999996",
"output": "666666664"
},
{
"input": "999999995",
"output": "666666663"
},
{
"input": "999999994",
"output": "666666663"
},
{
"input": "999999993",
"output": "666666662"
},
{
"input": "999999992",
"output": "666666661"
},
{
"input": "999999991",
"output": "666666661"
},
{
"input": "1000",
"output": "667"
},
{
"input": "10000",
"output": "6667"
},
{
"input": "100000",
"output": "66667"
},
{
"input": "1000000",
"output": "666667"
},
{
"input": "10000000",
"output": "6666667"
},
{
"input": "100000000",
"output": "66666667"
},
{
"input": "7",
"output": "5"
}
] | 1,461,944,705 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 4,608,000 | def main():
n = int(input())
return solver(n)
def solver(n):
if n % 3 == 0:
return n // 3 * 2
elif n % 3 == 1:
return (2 * n + 1) // 3
else:
return (2 * (n - 1) + 1) // 3
main()
| Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.
How many times can Artem give presents to Masha?
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Output Specification:
Print the maximum possible number of times Artem can give presents to Masha.
Demo Input:
['1\n', '2\n', '3\n', '4\n']
Demo Output:
['1\n', '1\n', '2\n', '3\n']
Note:
In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. | ```python
def main():
n = int(input())
return solver(n)
def solver(n):
if n % 3 == 0:
return n // 3 * 2
elif n % 3 == 1:
return (2 * n + 1) // 3
else:
return (2 * (n - 1) + 1) // 3
main()
``` | 0 |
|
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "100 100 100",
"output": "300"
},
{
"input": "1 1 1",
"output": "2"
},
{
"input": "30 70 35",
"output": "130"
},
{
"input": "89 44 76",
"output": "208"
},
{
"input": "0 100 100",
"output": "200"
},
{
"input": "100 0 100",
"output": "200"
},
{
"input": "100 1 100",
"output": "200"
},
{
"input": "1 100 100",
"output": "200"
},
{
"input": "100 100 0",
"output": "200"
},
{
"input": "100 100 1",
"output": "200"
},
{
"input": "1 2 1",
"output": "4"
},
{
"input": "0 0 100",
"output": "100"
},
{
"input": "0 100 0",
"output": "0"
},
{
"input": "100 0 0",
"output": "0"
},
{
"input": "10 8 7",
"output": "24"
},
{
"input": "45 47 16",
"output": "108"
},
{
"input": "59 43 100",
"output": "202"
},
{
"input": "34 1 30",
"output": "62"
},
{
"input": "14 81 1",
"output": "30"
},
{
"input": "53 96 94",
"output": "242"
},
{
"input": "62 81 75",
"output": "218"
},
{
"input": "21 71 97",
"output": "188"
},
{
"input": "49 82 73",
"output": "204"
},
{
"input": "88 19 29",
"output": "96"
},
{
"input": "89 4 62",
"output": "132"
},
{
"input": "58 3 65",
"output": "126"
},
{
"input": "27 86 11",
"output": "76"
},
{
"input": "35 19 80",
"output": "134"
},
{
"input": "4 86 74",
"output": "156"
},
{
"input": "32 61 89",
"output": "182"
},
{
"input": "68 60 98",
"output": "226"
},
{
"input": "37 89 34",
"output": "142"
},
{
"input": "92 9 28",
"output": "74"
},
{
"input": "79 58 98",
"output": "234"
},
{
"input": "35 44 88",
"output": "166"
},
{
"input": "16 24 19",
"output": "58"
},
{
"input": "74 71 75",
"output": "220"
},
{
"input": "83 86 99",
"output": "268"
},
{
"input": "97 73 15",
"output": "176"
},
{
"input": "77 76 73",
"output": "226"
},
{
"input": "48 85 55",
"output": "188"
},
{
"input": "1 2 2",
"output": "4"
},
{
"input": "2 2 2",
"output": "6"
},
{
"input": "2 1 2",
"output": "4"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "3 2 1",
"output": "6"
},
{
"input": "1 2 3",
"output": "6"
},
{
"input": "1 3 2",
"output": "6"
},
{
"input": "2 1 3",
"output": "6"
},
{
"input": "2 3 1",
"output": "6"
},
{
"input": "3 1 2",
"output": "6"
},
{
"input": "99 99 99",
"output": "296"
},
{
"input": "99 99 100",
"output": "298"
},
{
"input": "99 100 99",
"output": "298"
},
{
"input": "99 100 100",
"output": "298"
},
{
"input": "100 99 99",
"output": "298"
},
{
"input": "100 99 100",
"output": "298"
},
{
"input": "100 100 99",
"output": "298"
},
{
"input": "89 32 23",
"output": "110"
},
{
"input": "4 5 0",
"output": "8"
},
{
"input": "3 0 3",
"output": "6"
},
{
"input": "0 0 2",
"output": "2"
},
{
"input": "97 97 0",
"output": "194"
},
{
"input": "1 4 0",
"output": "2"
},
{
"input": "5 2 0",
"output": "4"
},
{
"input": "0 5 10",
"output": "14"
},
{
"input": "0 1 2",
"output": "2"
},
{
"input": "5 2 3",
"output": "10"
},
{
"input": "5 5 0",
"output": "10"
},
{
"input": "0 0 10",
"output": "10"
},
{
"input": "0 1 1",
"output": "2"
},
{
"input": "0 0 1",
"output": "0"
}
] | 1,679,085,243 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 46 | 0 | l,r,a = input().split()
l,r,a = int(l),int(r),int(a)
if ((l==0 and a==0) or (r==0 and a==0) or a == 0):
print(0)
else:
if(l+a < r):
print((l+a)*2)
elif(r+a<l):
print((r+a)*2)
else:
print(((l+r+a)//2)*2)
| Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
Input Specification:
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Output Specification:
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
Demo Input:
['1 4 2\n', '5 5 5\n', '0 2 0\n']
Demo Output:
['6\n', '14\n', '0\n']
Note:
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | ```python
l,r,a = input().split()
l,r,a = int(l),int(r),int(a)
if ((l==0 and a==0) or (r==0 and a==0) or a == 0):
print(0)
else:
if(l+a < r):
print((l+a)*2)
elif(r+a<l):
print((r+a)*2)
else:
print(((l+r+a)//2)*2)
``` | 0 |
|
401 | A | Vanya and Cards | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*. | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value. | Print a single number — the answer to the problem. | [
"3 2\n-1 1 2\n",
"2 3\n-2 -2\n"
] | [
"1\n",
"2\n"
] | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | 500 | [
{
"input": "3 2\n-1 1 2",
"output": "1"
},
{
"input": "2 3\n-2 -2",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "2 2\n-1 -1",
"output": "1"
},
{
"input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2",
"output": "4"
},
{
"input": "15 16\n-15 -5 -15 -14 -8 15 -15 -12 -5 -3 5 -7 3 8 -15",
"output": "6"
},
{
"input": "1 4\n-3",
"output": "1"
},
{
"input": "10 7\n6 4 6 6 -3 4 -1 2 3 3",
"output": "5"
},
{
"input": "2 1\n1 -1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "8 13\n-11 -1 -11 12 -2 -2 -10 -11",
"output": "3"
},
{
"input": "16 11\n3 -7 7 -9 -2 -3 -4 -2 -6 8 10 7 1 4 6 7",
"output": "2"
},
{
"input": "67 15\n-2 -2 6 -4 -7 4 3 13 -9 -4 11 -7 -6 -11 1 11 -1 11 14 10 -8 7 5 11 -13 1 -1 7 -14 9 -11 -11 13 -4 12 -11 -8 -5 -11 6 10 -2 6 9 9 6 -11 -2 7 -10 -1 9 -8 -5 1 -7 -2 3 -1 -13 -6 -9 -8 10 13 -3 9",
"output": "1"
},
{
"input": "123 222\n44 -190 -188 -185 -55 17 190 176 157 176 -24 -113 -54 -61 -53 53 -77 68 -12 -114 -217 163 -122 37 -37 20 -108 17 -140 -210 218 19 -89 54 18 197 111 -150 -36 -131 -172 36 67 16 -202 72 169 -137 -34 -122 137 -72 196 -17 -104 180 -102 96 -69 -184 21 -15 217 -61 175 -221 62 173 -93 -106 122 -135 58 7 -110 -108 156 -141 -102 -50 29 -204 -46 -76 101 -33 -190 99 52 -197 175 -71 161 -140 155 10 189 -217 -97 -170 183 -88 83 -149 157 -208 154 -3 77 90 74 165 198 -181 -166 -4 -200 -89 -200 131 100 -61 -149",
"output": "8"
},
{
"input": "130 142\n58 -50 43 -126 84 -92 -108 -92 57 127 12 -135 -49 89 141 -112 -31 47 75 -19 80 81 -5 17 10 4 -26 68 -102 -10 7 -62 -135 -123 -16 55 -72 -97 -34 21 21 137 130 97 40 -18 110 -52 73 52 85 103 -134 -107 88 30 66 97 126 82 13 125 127 -87 81 22 45 102 13 95 4 10 -35 39 -43 -112 -5 14 -46 19 61 -44 -116 137 -116 -80 -39 92 -75 29 -65 -15 5 -108 -114 -129 -5 52 -21 118 -41 35 -62 -125 130 -95 -11 -75 19 108 108 127 141 2 -130 54 96 -81 -102 140 -58 -102 132 50 -126 82 6 45 -114 -42",
"output": "5"
},
{
"input": "7 12\n2 5 -1 -4 -7 4 3",
"output": "1"
},
{
"input": "57 53\n-49 7 -41 7 38 -51 -23 8 45 1 -24 26 37 28 -31 -40 38 25 -32 -47 -3 20 -40 -32 -44 -36 5 33 -16 -5 28 10 -22 3 -10 -51 -32 -51 27 -50 -22 -12 41 3 15 24 30 -12 -34 -15 -29 38 -10 -35 -9 6 -51",
"output": "8"
},
{
"input": "93 273\n-268 -170 -163 19 -69 18 -244 35 -34 125 -224 -48 179 -247 127 -150 271 -49 -102 201 84 -151 -70 -46 -16 216 240 127 3 218 -209 223 -227 -201 228 -8 203 46 -100 -207 126 255 40 -58 -217 93 172 -97 23 183 102 -92 -157 -117 173 47 144 -235 -227 -62 -128 13 -151 158 110 -116 68 -2 -148 -206 -52 79 -152 -223 74 -149 -69 232 38 -70 -256 -213 -236 132 -189 -200 199 -57 -108 -53 269 -101 -134",
"output": "8"
},
{
"input": "1 1000\n997",
"output": "1"
},
{
"input": "4 3\n2 -1 -2 -1",
"output": "1"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 2\n1 -1",
"output": "0"
},
{
"input": "2 2\n-1 1",
"output": "0"
},
{
"input": "2 3\n-1 1",
"output": "0"
},
{
"input": "2 2\n-2 2",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "2"
},
{
"input": "4 2\n-1 -1 -1 -1",
"output": "2"
},
{
"input": "4 1\n-1 -1 -1 1",
"output": "2"
},
{
"input": "3 2\n2 2 2",
"output": "3"
},
{
"input": "10 300\n300 300 300 300 300 300 300 300 300 300",
"output": "10"
}
] | 1,620,889,291 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 6,656,000 | import math
n,x=map(int,input().split())
l=sum(list(map(int,input().split())))
print(math.ceil(l/x)) | Title: Vanya and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*.
Input Specification:
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['3 2\n-1 1 2\n', '2 3\n-2 -2\n']
Demo Output:
['1\n', '2\n']
Note:
In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | ```python
import math
n,x=map(int,input().split())
l=sum(list(map(int,input().split())))
print(math.ceil(l/x))
``` | 0 |
|
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,694,156,504 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | # Read the input
w = int(input())
# Check if it's possible to divide the watermelon
if w >= 4 and w % 2 == 0:
print("YES")
else:
print("NO")
| Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input Specification:
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Output Specification:
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Demo Input:
['8\n']
Demo Output:
['YES\n']
Note:
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | ```python
# Read the input
w = int(input())
# Check if it's possible to divide the watermelon
if w >= 4 and w % 2 == 0:
print("YES")
else:
print("NO")
``` | 3.954 |
1,009 | A | Game Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.
When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop.
Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.
For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 > a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$.
Your task is to get the number of games Maxim will buy. | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet. | Print a single integer — the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | 0 | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n1000",
"output": "1"
},
{
"input": "5 1\n100 100 100 100 100\n100",
"output": "1"
},
{
"input": "2 1\n2 1\n1",
"output": "1"
},
{
"input": "2 3\n3 1\n2 4 2",
"output": "1"
},
{
"input": "1 5\n4\n1 4 3 3 2",
"output": "0"
},
{
"input": "5 3\n4 2 3 1 1\n2 1 3",
"output": "3"
},
{
"input": "3 5\n5 2 5\n1 4 1 4 2",
"output": "0"
},
{
"input": "7 3\n9 7 10 2 1 1 1\n8 9 6",
"output": "3"
},
{
"input": "5 3\n2 5 3 3 2\n2 5 3",
"output": "3"
}
] | 1,587,239,232 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 155 | 0 | n, m = [int(x) for x in input().split(' ')]
c = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
cnt = 0
for i in range(n):
if c[i] <= a[0]:
a.pop(0)
cnt += 1
if len(a) <= 0: break
print(cnt)
| Title: Game Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.
When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop.
Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.
For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 > a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$.
Your task is to get the number of games Maxim will buy.
Input Specification:
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet.
Output Specification:
Print a single integer — the number of games Maxim will buy.
Demo Input:
['5 4\n2 4 5 2 4\n5 3 4 6\n', '5 2\n20 40 50 20 40\n19 20\n', '6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n']
Demo Output:
['3\n', '0\n', '4\n']
Note:
The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | ```python
n, m = [int(x) for x in input().split(' ')]
c = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
cnt = 0
for i in range(n):
if c[i] <= a[0]:
a.pop(0)
cnt += 1
if len(a) <= 0: break
print(cnt)
``` | 3 |
|
127 | A | Wasted Time | PROGRAMMING | 900 | [
"geometry"
] | null | null | Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters. | Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6. | [
"2 1\n0 0\n10 0\n",
"5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n",
"6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n"
] | [
"0.200000000",
"6.032163204",
"3.000000000"
] | none | 500 | [
{
"input": "2 1\n0 0\n10 0",
"output": "0.200000000"
},
{
"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0",
"output": "6.032163204"
},
{
"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0",
"output": "3.000000000"
},
{
"input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n14 -15\n-13 14\n19 8",
"output": "429.309294877"
},
{
"input": "30 1000\n4 -13\n14 13\n-14 -16\n-9 18\n17 11\n2 -8\n2 15\n8 -1\n-9 13\n8 -12\n-2 20\n11 -12\n19 8\n9 -15\n-20 -5\n-18 20\n-13 14\n-12 -17\n-4 3\n13 -12\n11 -10\n18 7\n-6 11\n10 13\n10 3\n6 -14\n-1 10\n14 -15\n2 11\n-8 10",
"output": "13629.282573522"
},
{
"input": "2 1\n-20 -10\n-10 -6",
"output": "0.215406592"
},
{
"input": "2 13\n13 -10\n-3 -2",
"output": "4.651021393"
},
{
"input": "2 21\n13 8\n14 10",
"output": "0.939148551"
},
{
"input": "2 75\n-3 12\n1 12",
"output": "6.000000000"
},
{
"input": "2 466\n10 16\n-6 -3",
"output": "231.503997374"
},
{
"input": "2 999\n6 16\n-17 -14",
"output": "755.286284531"
},
{
"input": "2 1000\n-17 -14\n-14 -8",
"output": "134.164078650"
},
{
"input": "3 384\n-4 -19\n-17 -2\n3 4",
"output": "324.722285390"
},
{
"input": "5 566\n-11 8\n2 -7\n7 0\n-7 -9\n-7 5",
"output": "668.956254495"
},
{
"input": "7 495\n-10 -13\n-9 -5\n4 9\n8 13\n-4 2\n2 10\n-18 15",
"output": "789.212495576"
},
{
"input": "10 958\n7 13\n20 19\n12 -7\n10 -10\n-13 -15\n-10 -7\n20 -5\n-11 19\n-7 3\n-4 18",
"output": "3415.618464093"
},
{
"input": "13 445\n-15 16\n-8 -14\n8 7\n4 15\n8 -13\n15 -11\n-12 -4\n2 -13\n-5 0\n-20 -14\n-8 -7\n-10 -18\n18 -5",
"output": "2113.552527680"
},
{
"input": "18 388\n11 -8\n13 10\n18 -17\n-15 3\n-13 -15\n20 -7\n1 -10\n-13 -12\n-12 -15\n-17 -8\n1 -2\n3 -20\n-8 -9\n15 -13\n-19 -6\n17 3\n-17 2\n6 6",
"output": "2999.497312668"
},
{
"input": "25 258\n-5 -3\n-18 -14\n12 3\n6 11\n4 2\n-19 -3\n19 -7\n-15 19\n-19 -12\n-11 -10\n-5 17\n10 15\n-4 1\n-3 -20\n6 16\n18 -19\n11 -19\n-17 10\n-17 17\n-2 -17\n-3 -9\n18 13\n14 8\n-2 -5\n-11 4",
"output": "2797.756635934"
},
{
"input": "29 848\n11 -10\n-19 1\n18 18\n19 -19\n0 -5\n16 10\n-20 -14\n7 15\n6 8\n-15 -16\n9 3\n16 -20\n-12 12\n18 -1\n-11 14\n18 10\n11 -20\n-20 -16\n-1 11\n13 10\n-6 13\n-7 -10\n-11 -10\n-10 3\n15 -13\n-4 11\n-13 -11\n-11 -17\n11 -5",
"output": "12766.080247922"
},
{
"input": "36 3\n-11 20\n-11 13\n-17 9\n15 9\n-6 9\n-1 11\n12 -11\n16 -10\n-20 7\n-18 6\n-15 -2\n20 -20\n16 4\n-20 -8\n-12 -15\n-13 -6\n-9 -4\n0 -10\n8 -1\n1 4\n5 8\n8 -15\n16 -12\n19 1\n0 -4\n13 -4\n17 -13\n-7 11\n14 9\n-14 -9\n5 -8\n11 -8\n-17 -5\n1 -3\n-16 -17\n2 -3",
"output": "36.467924851"
},
{
"input": "48 447\n14 9\n9 -17\n-17 11\n-14 14\n19 -8\n-14 -17\n-7 10\n-6 -11\n-9 -19\n19 10\n-4 2\n-5 16\n20 9\n-10 20\n-7 -17\n14 -16\n-2 -10\n-18 -17\n14 12\n-6 -19\n5 -18\n-3 2\n-3 10\n-5 5\n13 -12\n10 -18\n10 -12\n-2 4\n7 -15\n-5 -5\n11 14\n11 10\n-6 -9\n13 -4\n13 9\n6 12\n-13 17\n-9 -12\n14 -19\n10 12\n-15 8\n-1 -11\n19 8\n11 20\n-9 -3\n16 1\n-14 19\n8 -4",
"output": "9495.010556306"
},
{
"input": "50 284\n-17 -13\n7 12\n-13 0\n13 1\n14 6\n14 -9\n-5 -1\n0 -10\n12 -3\n-14 6\n-8 10\n-16 17\n0 -1\n4 -9\n2 6\n1 8\n-8 -14\n3 9\n1 -15\n-4 -19\n-7 -20\n18 10\n3 -11\n10 16\n2 -6\n-9 19\n-3 -1\n20 9\n-12 -5\n-10 -2\n16 -7\n-16 -18\n-2 17\n2 8\n7 -15\n4 1\n6 -17\n19 9\n-10 -20\n5 2\n10 -2\n3 7\n20 0\n8 -14\n-16 -1\n-20 7\n20 -19\n17 18\n-11 -18\n-16 14",
"output": "6087.366930474"
},
{
"input": "57 373\n18 3\n-4 -1\n18 5\n-7 -15\n-6 -10\n-19 1\n20 15\n15 4\n-1 -2\n13 -14\n0 12\n10 3\n-16 -17\n-14 -9\n-11 -10\n17 19\n-2 6\n-12 -15\n10 20\n16 7\n9 -1\n4 13\n8 -2\n-1 -16\n-3 8\n14 11\n-12 3\n-5 -6\n3 4\n5 7\n-9 9\n11 4\n-19 10\n-7 4\n-20 -12\n10 16\n13 11\n13 -11\n7 -1\n17 18\n-19 7\n14 13\n5 -1\n-7 6\n-1 -6\n6 20\n-16 2\n4 17\n16 -11\n-4 -20\n19 -18\n17 16\n-14 -8\n3 2\n-6 -16\n10 -10\n-13 -11",
"output": "8929.162822862"
},
{
"input": "60 662\n15 17\n-2 -19\n-4 -17\n10 0\n15 10\n-8 -14\n14 9\n-15 20\n6 5\n-9 0\n-13 20\n13 -2\n10 9\n7 5\n4 18\n-10 1\n6 -15\n15 -16\n6 13\n4 -6\n2 5\n18 19\n8 3\n-7 14\n-12 -20\n14 19\n-15 0\n-2 -12\n9 18\n14 4\n2 -20\n3 0\n20 9\n-5 11\n-11 1\n2 -19\n-14 -4\n18 6\n16 16\n15 3\n-1 -5\n9 20\n12 -8\n-1 10\n-4 -9\n3 6\n3 -12\n14 -10\n-8 10\n-18 6\n14 -2\n-14 -12\n-10 -7\n10 -6\n14 1\n6 14\n15 19\n4 14\n3 -14\n-9 -13",
"output": "16314.207721932"
},
{
"input": "61 764\n-9 15\n11 -8\n-6 -7\n-13 -19\n16 -16\n-5 -1\n20 -19\n-14 -1\n-11 4\n7 -2\n-3 2\n-14 -17\n15 18\n20 15\n-13 -2\n15 8\n3 13\n19 -10\n2 -6\n15 -3\n-12 11\n4 -16\n-14 20\n0 2\n11 -7\n-6 -11\n16 7\n8 -3\n16 -10\n-3 9\n9 5\n4 -1\n-17 9\n14 -4\n8 6\n-19 12\n10 -17\n-5 7\n7 -3\n5 3\n6 -14\n9 9\n-16 -19\n11 -16\n-17 15\n8 5\n16 -19\n-7 10\n14 -15\n15 19\n-20 -16\n6 -2\n-4 6\n7 -15\n1 -8\n20 -17\n3 7\n10 12\n10 -11\n-19 10\n0 -11",
"output": "22153.369189802"
}
] | 1,578,306,034 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 248 | 0 | #127A
from math import sqrt
[n,k] = list(map(int,input().split()))
s = 0
[xprev,yprev] = list(map(float,input().split()))
for i in range(1,n):
print('s = ', s)
[x,y] = list(map(float,input().split()))
s += sqrt((x-xprev)**2+(y-yprev)**2)
xprev = x
yprev = y
s *= k
s /= 50.
print(s) | Title: Wasted Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
Output Specification:
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6.
Demo Input:
['2 1\n0 0\n10 0\n', '5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n', '6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n']
Demo Output:
['0.200000000', '6.032163204', '3.000000000']
Note:
none | ```python
#127A
from math import sqrt
[n,k] = list(map(int,input().split()))
s = 0
[xprev,yprev] = list(map(float,input().split()))
for i in range(1,n):
print('s = ', s)
[x,y] = list(map(float,input().split()))
s += sqrt((x-xprev)**2+(y-yprev)**2)
xprev = x
yprev = y
s *= k
s /= 50.
print(s)
``` | 0 |
|
667 | B | Coat of Anticubism | PROGRAMMING | 1,100 | [
"constructive algorithms",
"geometry"
] | null | null | As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon.
Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The *i*-th rod is a segment of length *l**i*.
The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle .
Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.
Help sculptor! | The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso already has. | Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods. | [
"3\n1 2 1\n",
"5\n20 4 3 2 1\n"
] | [
"1\n",
"11\n"
] | In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.
In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}. | 1,000 | [
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n20 4 3 2 1",
"output": "11"
},
{
"input": "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086",
"output": "70407571"
},
{
"input": "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 88059371 53742651 8489205 3528194",
"output": "360142248"
},
{
"input": "19\n479740 7703374 196076708 180202968 579604 17429 16916 11989886 30832424 6384983 8937497 431 62955 48167457 898566333 29534955 1485775 848444 372839845",
"output": "2404943"
},
{
"input": "35\n306260 278 43508628 54350745 222255 842526 39010821 10627 14916465 3059978 61449 503809 2820 1609513 196062 65695 270869 15079297 2885093 189306 4682268 422616382 1642346 82340 6 2 975464673 1388191 70110665 272855 253160079 1849635 7837751 274070 10394",
"output": "34445194"
},
{
"input": "53\n1014364 40727 75774 243769 314 406417 5272684 14138 10640282 64955 2763 5667043 2121887 204672692 567643 60183 5183 11361359 2792918 199155 174809 16182540 21 392221 19434423 9140891 159733 15438 67903 3816799 616 429181 30392293 413992581 10847741 20771 16366654 1163 414283 156163 55907108 310278 95949614 185865 976650886 197610 87 61264 4586815 107764 26390852 331828 541",
"output": "25390787"
},
{
"input": "3\n1 1 1000000000",
"output": "999999999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 1000000000",
"output": "999999956"
},
{
"input": "5\n100000000 100000000 100000000 100000000 500000000",
"output": "100000001"
},
{
"input": "3\n300000000 300000000 600000000",
"output": "1"
},
{
"input": "5\n10 4 3 2 1",
"output": "1"
},
{
"input": "3\n800000000 1 1",
"output": "799999999"
},
{
"input": "3\n1000000000 1 1",
"output": "999999999"
}
] | 1,461,949,206 | 1,505 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 5,120,000 | n = int(input())
temp = input().split(' ')
rod = []
for i in range(n):
rod.append(int(temp[i]))
mrod = max(rod)
s = sum(rod) - mrod
if mrod > s:
print(str(s+1))
elif mrod == s:
print('1')
else:
print(str(mrod - s + 1)) | Title: Coat of Anticubism
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon.
Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The *i*-th rod is a segment of length *l**i*.
The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle .
Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.
Help sculptor!
Input Specification:
The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso already has.
Output Specification:
Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods.
Demo Input:
['3\n1 2 1\n', '5\n20 4 3 2 1\n']
Demo Output:
['1\n', '11\n']
Note:
In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.
In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}. | ```python
n = int(input())
temp = input().split(' ')
rod = []
for i in range(n):
rod.append(int(temp[i]))
mrod = max(rod)
s = sum(rod) - mrod
if mrod > s:
print(str(s+1))
elif mrod == s:
print('1')
else:
print(str(mrod - s + 1))
``` | 0 |
|
232 | A | Cycles | PROGRAMMING | 1,600 | [
"binary search",
"constructive algorithms",
"graphs",
"greedy"
] | null | null | John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly *k* cycles of length 3.
A cycle of length 3 is an unordered group of three distinct graph vertices *a*, *b* and *c*, such that each pair of them is connected by a graph edge.
John has been painting for long, but he has not been a success. Help him find such graph. Note that the number of vertices there shouldn't exceed 100, or else John will have problems painting it. | A single line contains an integer *k* (1<=≤<=*k*<=≤<=105) — the number of cycles of length 3 in the required graph. | In the first line print integer *n* (3<=≤<=*n*<=≤<=100) — the number of vertices in the found graph. In each of next *n* lines print *n* characters "0" and "1": the *i*-th character of the *j*-th line should equal "0", if vertices *i* and *j* do not have an edge between them, otherwise it should equal "1". Note that as the required graph is undirected, the *i*-th character of the *j*-th line must equal the *j*-th character of the *i*-th line. The graph shouldn't contain self-loops, so the *i*-th character of the *i*-th line must equal "0" for all *i*. | [
"1\n",
"10\n"
] | [
"3\n011\n101\n110\n",
"5\n01111\n10111\n11011\n11101\n11110\n"
] | none | 500 | [
{
"input": "1",
"output": "3\n011\n101\n110"
},
{
"input": "10",
"output": "5\n01111\n10111\n11011\n11101\n11110"
},
{
"input": "2",
"output": "4\n0111\n1011\n1100\n1100"
},
{
"input": "3",
"output": "5\n01001\n10111\n01001\n01001\n11110"
},
{
"input": "4",
"output": "4\n0111\n1011\n1101\n1110"
},
{
"input": "5",
"output": "5\n01001\n10111\n01011\n01101\n11110"
},
{
"input": "6",
"output": "6\n010010\n101111\n010110\n011010\n111101\n010010"
},
{
"input": "7",
"output": "5\n01011\n10111\n01011\n11101\n11110"
},
{
"input": "8",
"output": "6\n010110\n101111\n010110\n111010\n111101\n010010"
},
{
"input": "9",
"output": "7\n0101100\n1011111\n0100100\n1100101\n1111011\n0100100\n0101100"
},
{
"input": "12",
"output": "7\n0101101\n1011111\n0100100\n1100101\n1111011\n0100100\n1101100"
},
{
"input": "29257",
"output": "60\n011111011111111111111110111111111111111111111111101111111111\n101111111111111111111111111111111111111111111111111111111111\n110111011111111111111111111111111111111111111111101111111111\n111011011111111111111110111111111111111111111111101111111111\n111101111111111111111111111111111111111111111111111111111111\n111110011111111111111110111111111111111111111111101111111111\n010010000000000000000000000000100000010000000000000000000000\n111111001111111111111110111111111111111111111111101111111111\n11111101011..."
},
{
"input": "99990",
"output": "90\n011111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n111011110111111111111111111111111111110111111111111111111111111111111110111111011111110111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111011111111..."
},
{
"input": "99000",
"output": "90\n011111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n111011110111111111111111111111111111110111111111111111111111111111111110111111011111110111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111011111111..."
},
{
"input": "99001",
"output": "86\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11101111011111111111111111111111111111111111111111111111111111111111111111111111111111\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "99002",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99003",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99004",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99005",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99006",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99007",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99008",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99009",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99010",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99011",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99012",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99013",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99014",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99015",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99016",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99017",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99018",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99019",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99020",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111011\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99021",
"output": "90\n011111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111110111111111111111111111111111111110111111011111111111\n111011110111111111111111111111111111110111111111111111111111111111111110111111011111110111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111011111111..."
},
{
"input": "99022",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99023",
"output": "86\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11101111011111111111111111111111111111111111111111111111111111111111111111111111111111\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "99024",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "99025",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "98770",
"output": "85\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "100000",
"output": "89\n01111111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11101111011111111111111111111111111111011111111111111111111111111111111111111101111111111\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101101111111111111111111111111111101111111111111..."
},
{
"input": "99999",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "97560",
"output": "87\n011111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011011111111111111111111111111111111111111111111111111111..."
},
{
"input": "98685",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "99994",
"output": "88\n0111111101111111111111111111111111111101111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111101111111111111111111111111111111111111111111111111\n1110111101111111111111111111111111111101111111111111111111111111111111111111111111111101\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110110111111111111111111111111111110111111111111111111..."
},
{
"input": "19",
"output": "7\n0101101\n1011111\n0101100\n1110111\n1111011\n0101101\n1101110"
}
] | 1,391,263,287 | 1,887 | Python 3 | OK | TESTS | 46 | 156 | 102,400 | import sys
import math
c=int(input())
Ans=[]
F=[1]
for i in range(1,101):
F.append(F[-1]*i)
for i in range(100):
Ans.append([0]*100)
print(100)
cycles=1
Ans[0][1]=1
Ans[1][0]=1
Ans[1][2]=1
Ans[2][1]=1
Ans[0][2]=1
Ans[2][0]=1
m=3
while(cycles<c):
Ans[0][m]=1
Ans[m][0]=1
inc=1
for j in range(1,m):
Ans[j][m]=1
Ans[m][j]=1
cycles+=inc
inc+=1
if(cycles+inc>c):
break
m+=1
A=""
for i in range(100):
for j in range(100):
A+=str(Ans[i][j])
A+="\n"
sys.stdout.write(A)
| Title: Cycles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly *k* cycles of length 3.
A cycle of length 3 is an unordered group of three distinct graph vertices *a*, *b* and *c*, such that each pair of them is connected by a graph edge.
John has been painting for long, but he has not been a success. Help him find such graph. Note that the number of vertices there shouldn't exceed 100, or else John will have problems painting it.
Input Specification:
A single line contains an integer *k* (1<=≤<=*k*<=≤<=105) — the number of cycles of length 3 in the required graph.
Output Specification:
In the first line print integer *n* (3<=≤<=*n*<=≤<=100) — the number of vertices in the found graph. In each of next *n* lines print *n* characters "0" and "1": the *i*-th character of the *j*-th line should equal "0", if vertices *i* and *j* do not have an edge between them, otherwise it should equal "1". Note that as the required graph is undirected, the *i*-th character of the *j*-th line must equal the *j*-th character of the *i*-th line. The graph shouldn't contain self-loops, so the *i*-th character of the *i*-th line must equal "0" for all *i*.
Demo Input:
['1\n', '10\n']
Demo Output:
['3\n011\n101\n110\n', '5\n01111\n10111\n11011\n11101\n11110\n']
Note:
none | ```python
import sys
import math
c=int(input())
Ans=[]
F=[1]
for i in range(1,101):
F.append(F[-1]*i)
for i in range(100):
Ans.append([0]*100)
print(100)
cycles=1
Ans[0][1]=1
Ans[1][0]=1
Ans[1][2]=1
Ans[2][1]=1
Ans[0][2]=1
Ans[2][0]=1
m=3
while(cycles<c):
Ans[0][m]=1
Ans[m][0]=1
inc=1
for j in range(1,m):
Ans[j][m]=1
Ans[m][j]=1
cycles+=inc
inc+=1
if(cycles+inc>c):
break
m+=1
A=""
for i in range(100):
for j in range(100):
A+=str(Ans[i][j])
A+="\n"
sys.stdout.write(A)
``` | 3 |
|
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divides *c*.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has groups of three.
Help Xenia, find the required partition or else say that it doesn't exist. | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "9\n1 3 6 6 3 1 3 1 6",
"output": "1 3 6\n1 3 6\n1 3 6"
},
{
"input": "6\n1 2 4 1 3 5",
"output": "-1"
},
{
"input": "3\n1 3 7",
"output": "-1"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "9\n1 2 4 1 2 4 1 3 6",
"output": "1 2 4\n1 2 4\n1 3 6"
},
{
"input": "12\n3 6 1 1 3 6 1 1 2 6 2 6",
"output": "1 3 6\n1 3 6\n1 2 6\n1 2 6"
},
{
"input": "9\n1 1 1 4 4 4 6 2 2",
"output": "-1"
},
{
"input": "9\n1 2 4 6 3 1 3 1 5",
"output": "-1"
},
{
"input": "15\n2 1 2 1 3 6 1 2 1 6 1 3 4 6 4",
"output": "1 2 4\n1 2 4\n1 3 6\n1 3 6\n1 2 6"
},
{
"input": "3\n2 3 6",
"output": "-1"
},
{
"input": "3\n2 4 6",
"output": "-1"
},
{
"input": "3\n2 5 6",
"output": "-1"
},
{
"input": "3\n2 4 7",
"output": "-1"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "-1"
},
{
"input": "3\n7 7 7",
"output": "-1"
},
{
"input": "6\n1 2 4 7 7 7",
"output": "-1"
},
{
"input": "6\n1 1 2 6 6 6",
"output": "-1"
},
{
"input": "9\n1 1 1 3 3 2 4 4 6",
"output": "-1"
},
{
"input": "6\n1 2 4 5 5 5",
"output": "-1"
},
{
"input": "15\n1 1 1 1 1 2 2 2 2 4 4 6 6 6 6",
"output": "-1"
},
{
"input": "6\n1 1 5 5 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 2 3 4 5 6 7",
"output": "-1"
},
{
"input": "6\n1 1 4 4 7 7",
"output": "-1"
},
{
"input": "24\n1 1 1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 4 4 4 6 6 6",
"output": "-1"
},
{
"input": "3\n1 7 6",
"output": "-1"
},
{
"input": "6\n1 1 2 4 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 7 7 7 7 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 2 3 4 6 5 5",
"output": "-1"
}
] | 1,651,243,940 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 46 | 0 | nums=[0]*8
n=int(input())
for i in map(int,input().split()):
nums[i]+=1
if nums[1] == n//3 and nums[2] + nums[3] + nums[4] + nums[6] == nums[1]*2 and nums[3] <= nums[6]:
print('1 2 4\n'*nums[4] + '1 3 6\n'*nums[3] + '1 2 6\n'*(nums[6]-nums[3]) )
else:
print(-1)
| Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divides *c*.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3.
Output Specification:
If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Demo Input:
['6\n1 1 1 2 2 2\n', '6\n2 2 1 1 4 6\n']
Demo Output:
['-1\n', '1 2 4\n1 2 6\n']
Note:
none | ```python
nums=[0]*8
n=int(input())
for i in map(int,input().split()):
nums[i]+=1
if nums[1] == n//3 and nums[2] + nums[3] + nums[4] + nums[6] == nums[1]*2 and nums[3] <= nums[6]:
print('1 2 4\n'*nums[4] + '1 3 6\n'*nums[3] + '1 2 6\n'*(nums[6]-nums[3]) )
else:
print(-1)
``` | 0 |
|
559 | A | Gerald's Hexagon | PROGRAMMING | 1,600 | [
"brute force",
"geometry",
"math"
] | null | null | Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. | The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. | Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. | [
"1 1 1 1 1 1\n",
"1 2 1 2 1 2\n"
] | [
"6\n",
"13\n"
] | This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 500 | [
{
"input": "1 1 1 1 1 1",
"output": "6"
},
{
"input": "1 2 1 2 1 2",
"output": "13"
},
{
"input": "2 4 5 3 3 6",
"output": "83"
},
{
"input": "45 19 48 18 46 21",
"output": "6099"
},
{
"input": "66 6 65 6 66 5",
"output": "5832"
},
{
"input": "7 5 4 8 4 5",
"output": "175"
},
{
"input": "3 2 1 4 1 2",
"output": "25"
},
{
"input": "7 1 7 3 5 3",
"output": "102"
},
{
"input": "9 2 9 3 8 3",
"output": "174"
},
{
"input": "1 6 1 5 2 5",
"output": "58"
},
{
"input": "41 64 48 61 44 68",
"output": "17488"
},
{
"input": "1 59 2 59 1 60",
"output": "3838"
},
{
"input": "30 36 36 32 34 38",
"output": "7052"
},
{
"input": "50 40 46 38 52 34",
"output": "11176"
},
{
"input": "4 60 4 60 4 60",
"output": "4576"
},
{
"input": "718 466 729 470 714 481",
"output": "2102808"
},
{
"input": "131 425 143 461 95 473",
"output": "441966"
},
{
"input": "125 7 128 8 124 11",
"output": "20215"
},
{
"input": "677 303 685 288 692 296",
"output": "1365807"
},
{
"input": "1 577 7 576 2 582",
"output": "342171"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "6000000"
},
{
"input": "1 1 1000 1 1 1000",
"output": "4002"
},
{
"input": "1000 1000 1 1000 1000 1",
"output": "2004000"
},
{
"input": "1000 1 1000 999 2 999",
"output": "2003997"
},
{
"input": "1 1000 1 1 1000 1",
"output": "4002"
},
{
"input": "888 888 888 887 889 887",
"output": "4729487"
}
] | 1,582,741,291 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 155 | 0 | a = list(map(int, input().split(' ')))
print((a[0]+a[1]+a[2])**2 - (a[0]**2 + a[2]**2 +a[4]**2)) | Title: Gerald's Hexagon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.
Input Specification:
The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.
Output Specification:
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
Demo Input:
['1 1 1 1 1 1\n', '1 2 1 2 1 2\n']
Demo Output:
['6\n', '13\n']
Note:
This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
a = list(map(int, input().split(' ')))
print((a[0]+a[1]+a[2])**2 - (a[0]**2 + a[2]**2 +a[4]**2))
``` | 3 |
|
719 | B | Anatoly and Cockroaches | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0. | 1,000 | [
{
"input": "5\nrbbrr",
"output": "1"
},
{
"input": "5\nbbbbb",
"output": "2"
},
{
"input": "3\nrbr",
"output": "0"
},
{
"input": "13\nrbbbrbrrbrrbb",
"output": "3"
},
{
"input": "18\nrrrrrrrrrrrrrrrrrb",
"output": "8"
},
{
"input": "100\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbrbbbbbbbbbbbbbbbbrrrrbbbbrrrbbbbbbbrbrrbrbbbbrrrbbbbrbbrbbbrb",
"output": "34"
},
{
"input": "166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb",
"output": "70"
},
{
"input": "1\nr",
"output": "0"
},
{
"input": "1\nb",
"output": "0"
},
{
"input": "2\nrb",
"output": "0"
},
{
"input": "2\nbr",
"output": "0"
},
{
"input": "2\nrr",
"output": "1"
},
{
"input": "2\nbb",
"output": "1"
},
{
"input": "8\nrbbrbrbr",
"output": "1"
},
{
"input": "7\nrrbrbrb",
"output": "1"
}
] | 1,588,676,080 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 124 | 409,600 | N = int(input())
This, Ans = input(), []
for i in ['rb', 'br']:
Should = i * (N // 2) + i[:N % 2]
WasR = This.count('r')
NowR = Should.count('r')
Diff = sum(1 for i, j in zip(This, Should) if i != j)
Ans.append((Diff - abs(WasR - NowR)) // 2 + abs(WasR - NowR))
print(min(Ans))
# Hope the best for Ravens
# Never give up
| Title: Anatoly and Cockroaches
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output Specification:
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Demo Input:
['5\nrbbrr\n', '5\nbbbbb\n', '3\nrbr\n']
Demo Output:
['1\n', '2\n', '0\n']
Note:
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0. | ```python
N = int(input())
This, Ans = input(), []
for i in ['rb', 'br']:
Should = i * (N // 2) + i[:N % 2]
WasR = This.count('r')
NowR = Should.count('r')
Diff = sum(1 for i, j in zip(This, Should) if i != j)
Ans.append((Diff - abs(WasR - NowR)) // 2 + abs(WasR - NowR))
print(min(Ans))
# Hope the best for Ravens
# Never give up
``` | 3 |
|
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
{
"input": "20\n44444444444444444444",
"output": "YES"
},
{
"input": "2\n44",
"output": "YES"
},
{
"input": "10\n4745474547",
"output": "NO"
},
{
"input": "14\n77770004444444",
"output": "NO"
},
{
"input": "10\n4747777744",
"output": "YES"
},
{
"input": "10\n1234567890",
"output": "NO"
},
{
"input": "50\n44444444444444444444444444444444444444444444444444",
"output": "YES"
},
{
"input": "50\n44444444444444444444444444444444444444444444444447",
"output": "NO"
},
{
"input": "50\n74444444444444444444444444444444444444444444444444",
"output": "NO"
},
{
"input": "50\n07777777777777777777777777777777777777777777777770",
"output": "NO"
},
{
"input": "50\n77777777777777777777777777777777777777777777777777",
"output": "YES"
},
{
"input": "50\n44747747774474747747747447777447774747447477444474",
"output": "YES"
},
{
"input": "48\n447474444777444474747747744774447444747474774474",
"output": "YES"
},
{
"input": "32\n74474474777444474444747774474774",
"output": "YES"
},
{
"input": "40\n4747777444447747777447447747447474774777",
"output": "YES"
},
{
"input": "10\n4477477444",
"output": "YES"
},
{
"input": "18\n447747474447744747",
"output": "YES"
},
{
"input": "26\n44747744444774744774474447",
"output": "YES"
},
{
"input": "50\n44707747774474747747747447777447774747447477444474",
"output": "NO"
},
{
"input": "40\n4747777444447737777447447747447474774777",
"output": "NO"
},
{
"input": "36\n764477744747444444447747747474744444",
"output": "NO"
},
{
"input": "22\n4477407474777477744447",
"output": "NO"
},
{
"input": "32\n74274474777444474444747774474774",
"output": "NO"
},
{
"input": "16\n4744447974444747",
"output": "NO"
},
{
"input": "2\n11",
"output": "NO"
},
{
"input": "2\n22",
"output": "NO"
},
{
"input": "2\n33",
"output": "NO"
},
{
"input": "2\n74",
"output": "NO"
},
{
"input": "2\n55",
"output": "NO"
},
{
"input": "2\n66",
"output": "NO"
},
{
"input": "2\n77",
"output": "YES"
},
{
"input": "2\n88",
"output": "NO"
},
{
"input": "2\n99",
"output": "NO"
},
{
"input": "4\n4004",
"output": "NO"
},
{
"input": "14\n00077774444444",
"output": "NO"
},
{
"input": "6\n004444",
"output": "NO"
},
{
"input": "4\n0044",
"output": "NO"
},
{
"input": "14\n77771114444444",
"output": "NO"
},
{
"input": "14\n44444447777000",
"output": "NO"
},
{
"input": "6\n004774",
"output": "NO"
}
] | 1,670,681,628 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 216 | 0 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
s = list(input().rstrip())
m = n // 2
ans = "YES" if sum(s[:m]) == sum(s[m:]) else "NO"
for i in s:
if i ^ 52 and i ^ 55:
ans = "NO"
break
print(ans) | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
Input Specification:
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
Output Specification:
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['2\n47\n', '4\n4738\n', '4\n4774\n']
Demo Output:
['NO\n', 'NO\n', 'YES\n']
Note:
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
s = list(input().rstrip())
m = n // 2
ans = "YES" if sum(s[:m]) == sum(s[m:]) else "NO"
for i in s:
if i ^ 52 and i ^ 55:
ans = "NO"
break
print(ans)
``` | 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,631,207,703 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 6,963,200 |
arr= []
for i in range(3):
l=list(map(int,input().split()))
arr.append(l)
ans=[["1","1","1"],["1","1","1"],["1","1","1"]]
for r in range(3):
for c in range(3):
row=r
col=c
temp= arr[row][col]
if row-1>=0:
temp+=arr[row-1][col]
if row+1<=2:
temp+=arr[row+1][col]
if col+1<=2:
temp+=arr[row][col+1]
if col-1>=0:
temp+=arr[row][col-1]
if temp%2 !=0:
ans[r][c]='0'
print(''.join(ans[0]))
print(''.join(ans[1]))
print(''.join(ans[2]))
| 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
arr= []
for i in range(3):
l=list(map(int,input().split()))
arr.append(l)
ans=[["1","1","1"],["1","1","1"],["1","1","1"]]
for r in range(3):
for c in range(3):
row=r
col=c
temp= arr[row][col]
if row-1>=0:
temp+=arr[row-1][col]
if row+1<=2:
temp+=arr[row+1][col]
if col+1<=2:
temp+=arr[row][col+1]
if col-1>=0:
temp+=arr[row][col-1]
if temp%2 !=0:
ans[r][c]='0'
print(''.join(ans[0]))
print(''.join(ans[1]))
print(''.join(ans[2]))
``` | 3 |
|
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,586,742,867 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | n = int(input()) + 1
tot = sum(map(int, input().split()))
ans = 0
for i in range(1, 6):
if (tot + i) % n != 1:
ans += 1
print(ans)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
n = int(input()) + 1
tot = sum(map(int, input().split()))
ans = 0
for i in range(1, 6):
if (tot + i) % n != 1:
ans += 1
print(ans)
``` | 3 |
|
754 | B | Ilya and tic-tac-toe game | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Ilya is an experienced player in tic-tac-toe on the 4<=×<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4<=×<=4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal). | The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn. | Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise. | [
"xx..\n.oo.\nx...\noox.\n",
"x.ox\nox..\nx.o.\noo.x\n",
"x..x\n..oo\no...\nx.xo\n",
"o.x.\no...\n.x..\nooxx\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | 1,000 | [
{
"input": "xx..\n.oo.\nx...\noox.",
"output": "YES"
},
{
"input": "x.ox\nox..\nx.o.\noo.x",
"output": "NO"
},
{
"input": "x..x\n..oo\no...\nx.xo",
"output": "YES"
},
{
"input": "o.x.\no...\n.x..\nooxx",
"output": "NO"
},
{
"input": ".xox\no.x.\nx.o.\n..o.",
"output": "YES"
},
{
"input": "o.oo\n.x.o\nx.x.\n.x..",
"output": "YES"
},
{
"input": "xxox\no.x.\nx.oo\nxo.o",
"output": "YES"
},
{
"input": ".xox\n.x..\nxoo.\noox.",
"output": "NO"
},
{
"input": "...x\n.x.o\n.o..\n.x.o",
"output": "NO"
},
{
"input": "oo.x\nxo.o\no.xx\n.oxx",
"output": "YES"
},
{
"input": ".x.o\n..o.\n..ox\nxox.",
"output": "NO"
},
{
"input": "....\n.x..\nx...\n..oo",
"output": "YES"
},
{
"input": "....\n....\n.x.o\n..xo",
"output": "YES"
},
{
"input": "o..o\nx..x\n.o.x\nxo..",
"output": "YES"
},
{
"input": "ox.o\nx..x\nx..o\noo.x",
"output": "NO"
},
{
"input": ".xox\n.x.o\nooxo\n..x.",
"output": "YES"
},
{
"input": "x..o\no..o\n..x.\nx.xo",
"output": "YES"
},
{
"input": "xxoo\no.oo\n...x\nx..x",
"output": "NO"
},
{
"input": "xoox\n.xx.\no..o\n..xo",
"output": "YES"
},
{
"input": "..o.\nxxox\n....\n.oxo",
"output": "YES"
},
{
"input": "xoox\nxxox\noo..\n.ox.",
"output": "YES"
},
{
"input": "..ox\n.o..\nx..o\n.oxx",
"output": "NO"
},
{
"input": ".oo.\n.x..\nx...\nox..",
"output": "YES"
},
{
"input": "o.xx\nxo.o\n...o\n..x.",
"output": "YES"
},
{
"input": "x...\n.ox.\n.oo.\n.xox",
"output": "NO"
},
{
"input": "xoxx\n..x.\no.oo\nx.o.",
"output": "YES"
},
{
"input": ".x.x\n.o.o\no.xx\nx.oo",
"output": "YES"
},
{
"input": "...o\nxo.x\n.x..\nxoo.",
"output": "YES"
},
{
"input": "o...\n...o\noxx.\n.xxo",
"output": "YES"
},
{
"input": "xxox\no..o\nx..o\noxox",
"output": "NO"
},
{
"input": "x.x.\nox.o\n.o.o\nxox.",
"output": "YES"
},
{
"input": "xxo.\n...x\nooxx\n.o.o",
"output": "YES"
},
{
"input": "xoxo\no..x\n.xo.\nox..",
"output": "YES"
},
{
"input": ".o..\nox..\n.o.x\n.x..",
"output": "NO"
},
{
"input": ".oxo\nx...\n.o..\n.xox",
"output": "NO"
},
{
"input": ".oxx\n..o.\n.o.x\n.ox.",
"output": "YES"
},
{
"input": ".xxo\n...o\n..ox\nox..",
"output": "YES"
},
{
"input": "x...\nxo..\noxo.\n..ox",
"output": "NO"
},
{
"input": "xoxo\nx.ox\n....\noxo.",
"output": "YES"
},
{
"input": "x..o\nxo.x\no.xo\nxoox",
"output": "NO"
},
{
"input": ".x..\no..x\n.oo.\nxox.",
"output": "NO"
},
{
"input": "xxox\no.x.\nxo.o\nxo.o",
"output": "NO"
},
{
"input": ".xo.\nx.oo\n...x\n.o.x",
"output": "NO"
},
{
"input": "ox.o\n...x\n..oo\nxxox",
"output": "NO"
},
{
"input": "oox.\nxoo.\no.x.\nx..x",
"output": "NO"
},
{
"input": "oxox\nx.oo\nooxx\nxxo.",
"output": "NO"
},
{
"input": "....\nxo.x\n..x.\noo..",
"output": "NO"
},
{
"input": ".ox.\nx..o\nxo.x\noxo.",
"output": "YES"
},
{
"input": ".xox\nxo..\n..oo\n.x..",
"output": "NO"
},
{
"input": "xxo.\n.oo.\n..x.\n..xo",
"output": "NO"
},
{
"input": "ox..\n..oo\n..x.\nxxo.",
"output": "NO"
},
{
"input": "xxo.\nx..x\noo.o\noxox",
"output": "YES"
},
{
"input": "xx..\noxxo\nxo.o\noox.",
"output": "YES"
},
{
"input": "x..o\no..o\no..x\nxxox",
"output": "NO"
},
{
"input": "oxo.\nxx.x\nooxx\n.o.o",
"output": "YES"
},
{
"input": ".o.x\no..o\nx..x\n..xo",
"output": "NO"
},
{
"input": "xo..\n....\nx...\n..o.",
"output": "YES"
},
{
"input": ".x..\no...\n...x\n.o..",
"output": "YES"
},
{
"input": "...x\n....\n.x.o\n..o.",
"output": "YES"
},
{
"input": "o..x\n....\n...x\n..o.",
"output": "YES"
},
{
"input": ".oo.\nx...\n....\n..x.",
"output": "YES"
},
{
"input": ".o..\n.x..\n..o.\n.x..",
"output": "YES"
},
{
"input": "..o.\n.x..\n....\no..x",
"output": "YES"
},
{
"input": "..o.\n..x.\n....\n.ox.",
"output": "YES"
},
{
"input": ".o..\no..x\n....\n.x..",
"output": "YES"
},
{
"input": "....\n..ox\n....\n.o.x",
"output": "YES"
},
{
"input": ".o..\n....\no...\nx.x.",
"output": "YES"
},
{
"input": "....\n.o..\n....\nox.x",
"output": "YES"
},
{
"input": "oxo.\nxxox\noo.o\nxoxx",
"output": "YES"
},
{
"input": ".xx.\n...x\noo.o\no..x",
"output": "YES"
},
{
"input": "x...\n.x..\n....\noo..",
"output": "YES"
},
{
"input": "oxox\n..ox\nxoxo\nxoxo",
"output": "YES"
},
{
"input": "....\n...x\n...x\noo..",
"output": "YES"
}
] | 1,487,422,040 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 33 | 93 | 4,915,200 | m = []
for i in range(4):
m.append(input())
def match(r,c, r2, c2):
if r > 3 or c > 3 or r < 0 or c < 0 or r2 > 3 or c2 > 3 or r2 < 0 or c2 < 0:
return False
return m[r][c] == "x" and m[r2][c2] == "x"
def check(r,c):
if(match(r,c+1,r,c-1) or\
match(r,c+1,r,c+2) or\
match(r,c-1,r,c-2) or\
match(r+1,c,r-1,c) or\
match(r+1,c,r+2,c) or\
match(r-1,c,r-2,c) or\
match(r+1,c+1,r-1,c-1) or\
match(r+1,c+1,r+2,c+2) or\
match(r-1,c-1,r-2,c-2) or\
match(r-1,c+1,r+1,c-1) or\
match(r-1,c+1,r-2,c-2) or\
match(r+1,c-1,r+2,c-2)):
return True
return False
def solve():
for row in range(4):
for column in range(4):
if m[row][column] == ".":
if check(row,column):
return "YES"
return "NO"
print(solve())
| Title: Ilya and tic-tac-toe game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is an experienced player in tic-tac-toe on the 4<=×<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4<=×<=4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input Specification:
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output Specification:
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Demo Input:
['xx..\n.oo.\nx...\noox.\n', 'x.ox\nox..\nx.o.\noo.x\n', 'x..x\n..oo\no...\nx.xo\n', 'o.x.\no...\n.x..\nooxx\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n']
Note:
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | ```python
m = []
for i in range(4):
m.append(input())
def match(r,c, r2, c2):
if r > 3 or c > 3 or r < 0 or c < 0 or r2 > 3 or c2 > 3 or r2 < 0 or c2 < 0:
return False
return m[r][c] == "x" and m[r2][c2] == "x"
def check(r,c):
if(match(r,c+1,r,c-1) or\
match(r,c+1,r,c+2) or\
match(r,c-1,r,c-2) or\
match(r+1,c,r-1,c) or\
match(r+1,c,r+2,c) or\
match(r-1,c,r-2,c) or\
match(r+1,c+1,r-1,c-1) or\
match(r+1,c+1,r+2,c+2) or\
match(r-1,c-1,r-2,c-2) or\
match(r-1,c+1,r+1,c-1) or\
match(r-1,c+1,r-2,c-2) or\
match(r+1,c-1,r+2,c-2)):
return True
return False
def solve():
for row in range(4):
for column in range(4):
if m[row][column] == ".":
if check(row,column):
return "YES"
return "NO"
print(solve())
``` | 0 |
|
869 | B | The Eternal Immortality | PROGRAMMING | 1,100 | [
"math"
] | null | null | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge. | The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). | Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. | [
"2 4\n",
"0 10\n",
"107 109\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0;
In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2. | 1,000 | [
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
"output": "0"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "3 15",
"output": "0"
},
{
"input": "24 26",
"output": "0"
},
{
"input": "14 60",
"output": "0"
},
{
"input": "11 79",
"output": "0"
},
{
"input": "1230 1232",
"output": "2"
},
{
"input": "2633 2634",
"output": "4"
},
{
"input": "535 536",
"output": "6"
},
{
"input": "344319135 396746843",
"output": "0"
},
{
"input": "696667767 696667767",
"output": "1"
},
{
"input": "419530302 610096911",
"output": "0"
},
{
"input": "238965115 821731161",
"output": "0"
},
{
"input": "414626436 728903812",
"output": "0"
},
{
"input": "274410639 293308324",
"output": "0"
},
{
"input": "650636673091305697 650636673091305702",
"output": "0"
},
{
"input": "651240548333620923 651240548333620924",
"output": "4"
},
{
"input": "500000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "999999999999999999 1000000000000000000",
"output": "0"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1"
},
{
"input": "0 4",
"output": "4"
},
{
"input": "50000000062000007 50000000062000011",
"output": "0"
},
{
"input": "0 0",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "0 2",
"output": "2"
},
{
"input": "10000000000012 10000000000015",
"output": "0"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "12 23",
"output": "0"
},
{
"input": "0 11",
"output": "0"
},
{
"input": "11111234567890 11111234567898",
"output": "0"
},
{
"input": "0 3",
"output": "6"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "999999999999999997 999999999999999999",
"output": "2"
},
{
"input": "4 5",
"output": "5"
},
{
"input": "0 1",
"output": "1"
},
{
"input": "101 1002",
"output": "0"
},
{
"input": "0 100000000000000001",
"output": "0"
},
{
"input": "99999999999999997 99999999999999999",
"output": "2"
},
{
"input": "14 15",
"output": "5"
},
{
"input": "8 19",
"output": "0"
},
{
"input": "12 22",
"output": "0"
},
{
"input": "999999999999996 999999999999999",
"output": "4"
},
{
"input": "1 3",
"output": "6"
},
{
"input": "124 125",
"output": "5"
},
{
"input": "11 32",
"output": "0"
},
{
"input": "0 5",
"output": "0"
},
{
"input": "0 999999",
"output": "0"
},
{
"input": "151151151515 151151151526",
"output": "0"
},
{
"input": "6 107",
"output": "0"
},
{
"input": "5 16",
"output": "0"
},
{
"input": "7 16",
"output": "0"
},
{
"input": "6 19",
"output": "0"
},
{
"input": "11113111111111 13111111111111",
"output": "0"
},
{
"input": "1 1000",
"output": "0"
},
{
"input": "24 25",
"output": "5"
},
{
"input": "0 100000000000",
"output": "0"
},
{
"input": "1 22",
"output": "0"
},
{
"input": "999999999999999996 999999999999999999",
"output": "4"
}
] | 1,507,655,321 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 1,638,400 | from math import factorial
n, m = [int(i) for i in input().split()]
print(int((factorial(m)/factorial(n)))%10) | Title: The Eternal Immortality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input Specification:
The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018).
Output Specification:
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Demo Input:
['2 4\n', '0 10\n', '107 109\n']
Demo Output:
['2\n', '0\n', '2\n']
Note:
In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0;
In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2. | ```python
from math import factorial
n, m = [int(i) for i in input().split()]
print(int((factorial(m)/factorial(n)))%10)
``` | 0 |
|
810 | B | Summer sell-off | PROGRAMMING | 1,300 | [
"greedy",
"sortings"
] | null | null | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.
For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out.
Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem. | The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day. | Print a single integer denoting the maximal number of products that shop can sell. | [
"4 2\n2 1\n3 5\n2 3\n1 5\n",
"4 1\n0 2\n0 3\n3 5\n0 6\n"
] | [
"10",
"5"
] | In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the second example it is possible to sell 5 products, if you choose third day for sell-out. | 1,000 | [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5",
"output": "10"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6",
"output": "5"
},
{
"input": "1 1\n5 8",
"output": "8"
},
{
"input": "2 1\n8 12\n6 11",
"output": "19"
},
{
"input": "2 1\n6 7\n5 7",
"output": "13"
},
{
"input": "2 1\n5 7\n6 7",
"output": "13"
},
{
"input": "2 1\n7 8\n3 6",
"output": "13"
},
{
"input": "2 1\n9 10\n5 8",
"output": "17"
},
{
"input": "2 1\n3 6\n7 8",
"output": "13"
},
{
"input": "1 0\n10 20",
"output": "10"
},
{
"input": "2 1\n99 100\n3 6",
"output": "105"
},
{
"input": "4 2\n2 10\n3 10\n9 9\n5 10",
"output": "27"
},
{
"input": "2 1\n3 4\n2 8",
"output": "7"
},
{
"input": "50 2\n74 90\n68 33\n49 88\n52 13\n73 21\n77 63\n27 62\n8 52\n60 57\n42 83\n98 15\n79 11\n77 46\n55 91\n72 100\n70 86\n50 51\n57 39\n20 54\n64 95\n66 22\n79 64\n31 28\n11 89\n1 36\n13 4\n75 62\n16 62\n100 35\n43 96\n97 54\n86 33\n62 63\n94 24\n19 6\n20 58\n38 38\n11 76\n70 40\n44 24\n32 96\n28 100\n62 45\n41 68\n90 52\n16 0\n98 32\n81 79\n67 82\n28 2",
"output": "1889"
},
{
"input": "2 1\n10 5\n2 4",
"output": "9"
},
{
"input": "2 1\n50 51\n30 40",
"output": "90"
},
{
"input": "3 2\n5 10\n5 10\n7 9",
"output": "27"
},
{
"input": "3 1\n1000 1000\n50 100\n2 2",
"output": "1102"
},
{
"input": "2 1\n2 4\n12 12",
"output": "16"
},
{
"input": "2 1\n4 4\n1 2",
"output": "6"
},
{
"input": "2 1\n4000 4000\n1 2",
"output": "4002"
},
{
"input": "2 1\n5 6\n2 4",
"output": "9"
},
{
"input": "3 2\n10 10\n10 10\n1 2",
"output": "22"
},
{
"input": "10 5\n9 1\n11 1\n12 1\n13 1\n14 1\n2 4\n2 4\n2 4\n2 4\n2 4",
"output": "25"
},
{
"input": "2 1\n30 30\n10 20",
"output": "50"
},
{
"input": "1 1\n1 1",
"output": "1"
},
{
"input": "2 1\n10 2\n2 10",
"output": "6"
},
{
"input": "2 1\n4 5\n3 9",
"output": "10"
},
{
"input": "2 1\n100 100\n5 10",
"output": "110"
},
{
"input": "2 1\n14 28\n15 28",
"output": "43"
},
{
"input": "2 1\n100 1\n20 40",
"output": "41"
},
{
"input": "2 1\n5 10\n6 10",
"output": "16"
},
{
"input": "2 1\n29 30\n10 20",
"output": "49"
},
{
"input": "1 0\n12 12",
"output": "12"
},
{
"input": "2 1\n7 8\n4 7",
"output": "14"
},
{
"input": "2 1\n5 5\n2 4",
"output": "9"
},
{
"input": "2 1\n1 2\n228 2",
"output": "4"
},
{
"input": "2 1\n5 10\n100 20",
"output": "30"
},
{
"input": "2 1\n1000 1001\n2 4",
"output": "1004"
},
{
"input": "2 1\n3 9\n7 7",
"output": "13"
},
{
"input": "2 0\n1 1\n1 1",
"output": "2"
},
{
"input": "4 1\n10 10\n10 10\n10 10\n4 6",
"output": "36"
},
{
"input": "18 13\n63 8\n87 100\n18 89\n35 29\n66 81\n27 85\n64 51\n60 52\n32 94\n74 22\n86 31\n43 78\n12 2\n36 2\n67 23\n2 16\n78 71\n34 64",
"output": "772"
},
{
"input": "2 1\n10 18\n17 19",
"output": "35"
},
{
"input": "3 0\n1 1\n1 1\n1 1",
"output": "3"
},
{
"input": "2 1\n4 7\n8 9",
"output": "15"
},
{
"input": "4 2\n2 10\n3 10\n9 10\n5 10",
"output": "27"
},
{
"input": "2 1\n5 7\n3 6",
"output": "11"
},
{
"input": "2 1\n3 4\n12 12",
"output": "16"
},
{
"input": "2 1\n10 11\n9 20",
"output": "28"
},
{
"input": "2 1\n7 8\n2 4",
"output": "11"
},
{
"input": "2 1\n5 10\n7 10",
"output": "17"
},
{
"input": "4 2\n2 10\n3 10\n5 10\n9 10",
"output": "27"
},
{
"input": "2 1\n99 100\n5 10",
"output": "109"
},
{
"input": "4 2\n2 10\n3 10\n5 10\n9 9",
"output": "27"
},
{
"input": "2 1\n3 7\n5 7",
"output": "11"
},
{
"input": "2 1\n10 10\n3 6",
"output": "16"
},
{
"input": "2 1\n100 1\n2 4",
"output": "5"
},
{
"input": "5 0\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "5"
},
{
"input": "3 1\n3 7\n4 5\n2 3",
"output": "12"
},
{
"input": "2 1\n3 9\n7 8",
"output": "13"
},
{
"input": "2 1\n10 2\n3 4",
"output": "6"
},
{
"input": "2 1\n40 40\n3 5",
"output": "45"
},
{
"input": "2 1\n5 3\n1 2",
"output": "5"
},
{
"input": "10 5\n9 5\n10 5\n11 5\n12 5\n13 5\n2 4\n2 4\n2 4\n2 4\n2 4",
"output": "45"
},
{
"input": "3 1\n1 5\n1 5\n4 4",
"output": "7"
},
{
"input": "4 0\n1 1\n1 1\n1 1\n1 1",
"output": "4"
},
{
"input": "4 1\n1000 1001\n1000 1001\n2 4\n1 2",
"output": "2005"
},
{
"input": "2 1\n15 30\n50 59",
"output": "80"
},
{
"input": "2 1\n8 8\n3 5",
"output": "13"
},
{
"input": "2 1\n4 5\n2 5",
"output": "8"
},
{
"input": "3 2\n3 3\n1 2\n1 2",
"output": "7"
},
{
"input": "3 1\n2 5\n2 5\n4 4",
"output": "10"
},
{
"input": "2 1\n3 10\n50 51",
"output": "56"
},
{
"input": "4 2\n2 4\n2 4\n9 10\n9 10",
"output": "26"
},
{
"input": "2 1\n3 5\n8 8",
"output": "13"
},
{
"input": "2 1\n100 150\n70 150",
"output": "240"
},
{
"input": "2 1\n4 5\n3 6",
"output": "10"
},
{
"input": "2 1\n20 10\n3 5",
"output": "15"
},
{
"input": "15 13\n76167099 92301116\n83163126 84046805\n45309500 65037149\n29982002 77381688\n76738161 52935441\n37889502 25466134\n55955619 14197941\n31462620 12999429\n64648384 8824773\n3552934 68992494\n2823376 9338427\n86832070 3763091\n67753633 2162190\n302887 92011825\n84894984 410533",
"output": "435467000"
},
{
"input": "2 1\n8 7\n3 6",
"output": "13"
},
{
"input": "2 1\n7 8\n3 5",
"output": "12"
},
{
"input": "2 1\n10 10\n1 3",
"output": "12"
},
{
"input": "2 1\n9 10\n2 4",
"output": "13"
},
{
"input": "3 1\n10 11\n12 13\n8 10",
"output": "32"
},
{
"input": "2 1\n5 10\n7 7",
"output": "17"
},
{
"input": "4 2\n90 91\n2 10\n2 10\n2 10",
"output": "100"
},
{
"input": "2 1\n2 4\n4 4",
"output": "8"
},
{
"input": "2 1\n2 3\n4 3",
"output": "6"
},
{
"input": "2 1\n40 45\n50 52",
"output": "95"
},
{
"input": "3 1\n1 4\n2 4\n3 4",
"output": "8"
},
{
"input": "2 1\n1 2\n1000 1000",
"output": "1002"
},
{
"input": "2 1\n80 100\n70 95",
"output": "175"
}
] | 1,599,152,070 | 2,147,483,647 | PyPy 3 | OK | TESTS | 159 | 966 | 9,625,600 | n,f = list(map(int,input().split()))
out = []
data = []
ans = 0
for i in range(n):
a,b = list(map(int,input().split()))
ans += min(a,b)
out.append(min(a*2,b)- min(a,b))
out.sort(reverse=True)
for i in range(f):
ans+=out[i]
print(ans) | Title: Summer sell-off
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.
For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out.
Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem.
Input Specification:
The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day.
Output Specification:
Print a single integer denoting the maximal number of products that shop can sell.
Demo Input:
['4 2\n2 1\n3 5\n2 3\n1 5\n', '4 1\n0 2\n0 3\n3 5\n0 6\n']
Demo Output:
['10', '5']
Note:
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the second example it is possible to sell 5 products, if you choose third day for sell-out. | ```python
n,f = list(map(int,input().split()))
out = []
data = []
ans = 0
for i in range(n):
a,b = list(map(int,input().split()))
ans += min(a,b)
out.append(min(a*2,b)- min(a,b))
out.sort(reverse=True)
for i in range(f):
ans+=out[i]
print(ans)
``` | 3 |
|
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
"input": "2 6 4 5 6 5 1 3",
"output": "0"
},
{
"input": "1 7 3 5 3 6 2 1",
"output": "6"
},
{
"input": "2 4 5 4 5 7 3 2",
"output": "1"
},
{
"input": "2 3 6 5 7 8 2 1",
"output": "4"
},
{
"input": "1 4 5 5 3 10 3 1",
"output": "6"
},
{
"input": "1 4 6 7 3 5 1 3",
"output": "1"
},
{
"input": "1 6 5 5 5 8 3 1",
"output": "8"
},
{
"input": "1 7 5 3 3 9 2 1",
"output": "9"
},
{
"input": "3 5 3 7 6 10 3 1",
"output": "1"
},
{
"input": "3 6 3 5 3 6 3 1",
"output": "2"
},
{
"input": "1 7 5 5 5 5 2 2",
"output": "2"
},
{
"input": "2 5 3 5 6 9 2 1",
"output": "3"
},
{
"input": "3 4 3 5 3 6 2 1",
"output": "2"
},
{
"input": "1 5 5 4 7 6 3 1",
"output": "6"
},
{
"input": "2 3 7 6 5 9 3 1",
"output": "3"
},
{
"input": "2 6 5 3 3 8 1 1",
"output": "4"
},
{
"input": "2 4 7 3 4 10 2 1",
"output": "5"
},
{
"input": "1 1000 1000 1000 1000 1000 1 1",
"output": "1000"
},
{
"input": "17 1000 1000 1000 1000 1000 3 7",
"output": "8"
},
{
"input": "115 1000 1000 1000 1000 1000 17 15",
"output": "0"
},
{
"input": "1 587 981 1 2 1 1 1",
"output": "1"
},
{
"input": "1 1 2 1 2 2 1 1",
"output": "2"
}
] | 1,690,609,189 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n, k, l, c, d, p, nl, np=map(int,input().split())
x=(k*l)//n
y=c*d
z=p//np
print(min(x,y,z)//nl) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
Input Specification:
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Output Specification:
Print a single integer — the number of toasts each friend can make.
Demo Input:
['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n']
Demo Output:
['2\n', '3\n', '0\n']
Note:
A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | ```python
n, k, l, c, d, p, nl, np=map(int,input().split())
x=(k*l)//n
y=c*d
z=p//np
print(min(x,y,z)//nl)
``` | 0 |
|
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 7",
"output": "5"
},
{
"input": "14 5 5",
"output": "6"
},
{
"input": "16 6 9",
"output": "10"
},
{
"input": "20 13 17",
"output": "7"
},
{
"input": "22 4 8",
"output": "9"
},
{
"input": "23 8 14",
"output": "15"
},
{
"input": "26 18 22",
"output": "8"
},
{
"input": "28 6 1",
"output": "2"
},
{
"input": "29 5 23",
"output": "24"
},
{
"input": "32 27 15",
"output": "5"
},
{
"input": "33 11 5",
"output": "6"
},
{
"input": "37 21 15",
"output": "16"
},
{
"input": "39 34 33",
"output": "5"
},
{
"input": "41 27 11",
"output": "12"
},
{
"input": "42 25 16",
"output": "17"
},
{
"input": "45 7 43",
"output": "38"
},
{
"input": "47 16 17",
"output": "18"
},
{
"input": "49 11 37",
"output": "38"
},
{
"input": "51 38 39",
"output": "13"
},
{
"input": "52 29 7",
"output": "8"
},
{
"input": "56 43 12",
"output": "13"
},
{
"input": "58 57 28",
"output": "1"
},
{
"input": "59 12 39",
"output": "40"
},
{
"input": "62 9 52",
"output": "53"
},
{
"input": "63 29 44",
"output": "34"
},
{
"input": "65 30 22",
"output": "23"
},
{
"input": "66 27 38",
"output": "39"
},
{
"input": "71 33 53",
"output": "38"
},
{
"input": "73 14 12",
"output": "13"
},
{
"input": "73 37 35",
"output": "36"
},
{
"input": "76 69 44",
"output": "7"
},
{
"input": "79 25 20",
"output": "21"
},
{
"input": "81 60 20",
"output": "21"
},
{
"input": "81 79 14",
"output": "2"
},
{
"input": "84 0 42",
"output": "43"
},
{
"input": "88 79 8",
"output": "9"
},
{
"input": "90 76 59",
"output": "14"
},
{
"input": "92 2 22",
"output": "23"
},
{
"input": "94 5 88",
"output": "89"
},
{
"input": "94 62 48",
"output": "32"
},
{
"input": "96 22 72",
"output": "73"
},
{
"input": "100 11 88",
"output": "89"
},
{
"input": "100 81 91",
"output": "19"
},
{
"input": "1 0 0",
"output": "1"
}
] | 1,685,635,772 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n=input("how many people are in queue?")
x=input("how many people are infront?")
y=input("how many people are in back?")
print(int(n)-int(x))
| Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
Input Specification:
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100).
Output Specification:
Print the single number — the number of the sought positions.
Demo Input:
['3 1 1\n', '5 2 3\n']
Demo Output:
['2\n', '3\n']
Note:
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | ```python
n=input("how many people are in queue?")
x=input("how many people are infront?")
y=input("how many people are in back?")
print(int(n)-int(x))
``` | -1 |
|
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,673,092,871 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 3,379,200 | {
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "fa1a81ed",
"metadata": {},
"outputs": [],
"source": [
"def theatre_square(n, m, a):\n",
" if n//a == n/a and m//a == m/a:\n",
" s1 = n/a\n",
" s2 = m/a\n",
" elif n//a == n/a and m//a != m/a:\n",
" s1 = s1/n\n",
" s2 = m//a + 1\n",
" elif n//a != n/a and m//a == m/a:\n",
" s1 = n//a + 1\n",
" s2 = m/a\n",
" else:\n",
" s1 = n//a + 1\n",
" s2 = m//a + 1\n",
" return s1 * s2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2d41b786",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"theatre_square(6,6,4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "43546a58",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
| 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
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "fa1a81ed",
"metadata": {},
"outputs": [],
"source": [
"def theatre_square(n, m, a):\n",
" if n//a == n/a and m//a == m/a:\n",
" s1 = n/a\n",
" s2 = m/a\n",
" elif n//a == n/a and m//a != m/a:\n",
" s1 = s1/n\n",
" s2 = m//a + 1\n",
" elif n//a != n/a and m//a == m/a:\n",
" s1 = n//a + 1\n",
" s2 = m/a\n",
" else:\n",
" s1 = n//a + 1\n",
" s2 = m//a + 1\n",
" return s1 * s2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2d41b786",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"theatre_square(6,6,4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "43546a58",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
``` | -1 |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{
"input": "1022 584 112",
"output": "380"
},
{
"input": "66 174 319",
"output": "184"
},
{
"input": "912 276 1748",
"output": "444"
},
{
"input": "65 156 60",
"output": "120"
},
{
"input": "1 10000 10000",
"output": "40008"
},
{
"input": "1485 55 27",
"output": "332"
},
{
"input": "152 108 4104",
"output": "528"
},
{
"input": "1656 6900 1350",
"output": "740"
},
{
"input": "12 14 42",
"output": "60"
},
{
"input": "615 18 1230",
"output": "856"
},
{
"input": "680 60 408",
"output": "336"
},
{
"input": "644 966 6",
"output": "1308"
},
{
"input": "1 432 432",
"output": "1736"
},
{
"input": "2239 2239 1",
"output": "8964"
},
{
"input": "4106 8212 2",
"output": "16436"
},
{
"input": "10000 10000 10000",
"output": "1200"
},
{
"input": "3623 3623 1",
"output": "14500"
},
{
"input": "9801 9801 9801",
"output": "1188"
},
{
"input": "10000 1 10000",
"output": "40008"
},
{
"input": "9 9 9",
"output": "36"
},
{
"input": "9801 9702 9702",
"output": "1184"
}
] | 1,608,146,022 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 216 | 0 | inp=list(map(int,input().split()))
a,b,c=inp
x=pow(a*b*c,0.5)
print (4*(x//a+x//b+x//c)) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input Specification:
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output Specification:
Print a single number — the sum of all edges of the parallelepiped.
Demo Input:
['1 1 1\n', '4 6 6\n']
Demo Output:
['12\n', '28\n']
Note:
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | ```python
inp=list(map(int,input().split()))
a,b,c=inp
x=pow(a*b*c,0.5)
print (4*(x//a+x//b+x//c))
``` | 0 |
|
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole? | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$) — the sizes of the holes. | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole. | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 96",
"output": "8"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 2 1\n1",
"output": "0"
},
{
"input": "2 2 2\n1 10000",
"output": "1"
},
{
"input": "2 10000 1\n1 9999",
"output": "0"
}
] | 1,617,514,270 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 12,288,000 | def volume(s,a,b):
return(((a*s[0])/sum(s))>=b)
n,a,b=map(int,input().split())
s=list(map(int,input().split()))
x=len(s)
while not volume(s,a,b):
s.pop(s.index(max(s[1:])))
print(x-len(s))
| Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole?
Input Specification:
The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$) — the sizes of the holes.
Output Specification:
Print a single integer — the number of holes Arkady should block.
Demo Input:
['4 10 3\n2 2 2 2\n', '4 80 20\n3 2 1 4\n', '5 10 10\n1000 1 1 1 1\n']
Demo Output:
['1\n', '0\n', '4\n']
Note:
In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole. | ```python
def volume(s,a,b):
return(((a*s[0])/sum(s))>=b)
n,a,b=map(int,input().split())
s=list(map(int,input().split()))
x=len(s)
while not volume(s,a,b):
s.pop(s.index(max(s[1:])))
print(x-len(s))
``` | 0 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,644,400,246 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | s=input()
t=input()
n=len(s)
m=len(t)
if(n==m):
c=0
for i in range(m):
if(s[i]!=t[m-1-i]):
c=1
if(c==1):
print("NO")
else:
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
s=input()
t=input()
n=len(s)
m=len(t)
if(n==m):
c=0
for i in range(m):
if(s[i]!=t[m-1-i]):
c=1
if(c==1):
print("NO")
else:
print("YES")
else:
print("NO")
``` | 3.977 |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,698,151,771 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | k, n, w = (int(i) for i in input().split())
sum = 0
for i in range(w):sum += (i+1)*k
print(sum - n if sum >= n else 0) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
k, n, w = (int(i) for i in input().split())
sum = 0
for i in range(w):sum += (i+1)*k
print(sum - n if sum >= n else 0)
``` | 3 |
|
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "100"
},
{
"input": "9 3\n9 5 2 3 7 1 8 4 6",
"output": "7"
},
{
"input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58",
"output": "16"
},
{
"input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54",
"output": "48"
},
{
"input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1",
"output": "44"
},
{
"input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3",
"output": "46"
},
{
"input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78",
"output": "40"
},
{
"input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69",
"output": "11"
},
{
"input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95",
"output": "50"
},
{
"input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9",
"output": "86"
},
{
"input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7",
"output": "93"
},
{
"input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42",
"output": "77"
},
{
"input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48",
"output": "97"
},
{
"input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78",
"output": "20"
},
{
"input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41",
"output": "97"
},
{
"input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82",
"output": "51"
},
{
"input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58",
"output": "97"
},
{
"input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88",
"output": "47"
},
{
"input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51",
"output": "98"
},
{
"input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67",
"output": "94"
},
{
"input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19",
"output": "95"
},
{
"input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49",
"output": "88"
},
{
"input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1",
"output": "99"
},
{
"input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95",
"output": "100"
},
{
"input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15",
"output": "98"
},
{
"input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16",
"output": "100"
},
{
"input": "1 3\n5",
"output": "1"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 3\n4 2",
"output": "1"
},
{
"input": "2 5\n99 97",
"output": "2"
},
{
"input": "3 4\n7 5 2",
"output": "2"
},
{
"input": "3 50\n47 86 51",
"output": "3"
},
{
"input": "5 100\n82 100 85 1 37",
"output": "5"
},
{
"input": "5 20\n40 39 21 5 20",
"output": "3"
},
{
"input": "1 27\n81",
"output": "1"
},
{
"input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1",
"output": "7"
},
{
"input": "2 1\n100 2",
"output": "1"
},
{
"input": "2 2\n6 4",
"output": "1"
},
{
"input": "5 2\n6 4 4 1 1",
"output": "1"
},
{
"input": "1 4\n3",
"output": "1"
},
{
"input": "3 2\n1 5 3",
"output": "2"
},
{
"input": "3 1\n3 2 2",
"output": "1"
},
{
"input": "3 1\n2 3 2",
"output": "2"
},
{
"input": "5 1\n5 1 1 1 1",
"output": "1"
},
{
"input": "2 3\n7 4",
"output": "1"
}
] | 1,690,972,252 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 93 | 1,331,200 | n,m = map(int,input().split())
arr = [i for i in range(n)]
v = list(map(int,input().split()))
while len(arr)>1:
# print(arr)
v[arr[0]]-=m
if v[arr[0]]<=0:
arr.pop(0)
else:
n = arr.pop(0)
arr.append(n)
print(arr[0]+1)
| Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
Output a single integer, representing the number of the last child.
Demo Input:
['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n']
Demo Output:
['4\n', '6\n']
Note:
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | ```python
n,m = map(int,input().split())
arr = [i for i in range(n)]
v = list(map(int,input().split()))
while len(arr)>1:
# print(arr)
v[arr[0]]-=m
if v[arr[0]]<=0:
arr.pop(0)
else:
n = arr.pop(0)
arr.append(n)
print(arr[0]+1)
``` | 3 |
|
55 | B | Smallest number | PROGRAMMING | 1,600 | [
"brute force"
] | B. Smallest number | 2 | 256 | Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. | First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) | Output one integer number — the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | [
"1 1 1 1\n+ + *\n",
"2 2 2 2\n* * +\n",
"1 2 3 4\n* + +\n"
] | [
"3\n",
"8\n",
"9\n"
] | none | 1,000 | [
{
"input": "1 1 1 1\n+ + *",
"output": "3"
},
{
"input": "2 2 2 2\n* * +",
"output": "8"
},
{
"input": "1 2 3 4\n* + +",
"output": "9"
},
{
"input": "15 1 3 1\n* * +",
"output": "18"
},
{
"input": "8 1 7 14\n+ + +",
"output": "30"
},
{
"input": "7 17 3 25\n+ * +",
"output": "63"
},
{
"input": "13 87 4 17\n* * *",
"output": "76908"
},
{
"input": "7 0 8 15\n+ + *",
"output": "0"
},
{
"input": "52 0 43 239\n+ + +",
"output": "334"
},
{
"input": "1000 1000 999 1000\n* * *",
"output": "999000000000"
},
{
"input": "720 903 589 804\n* * *",
"output": "307887168960"
},
{
"input": "631 149 496 892\n* * +",
"output": "445884"
},
{
"input": "220 127 597 394\n* + +",
"output": "28931"
},
{
"input": "214 862 466 795\n+ + +",
"output": "2337"
},
{
"input": "346 290 587 525\n* * *",
"output": "30922279500"
},
{
"input": "323 771 559 347\n+ * *",
"output": "149067730"
},
{
"input": "633 941 836 254\n* + +",
"output": "162559"
},
{
"input": "735 111 769 553\n+ * *",
"output": "92320032"
},
{
"input": "622 919 896 120\n* * +",
"output": "667592"
},
{
"input": "652 651 142 661\n+ + +",
"output": "2106"
},
{
"input": "450 457 975 35\n* * *",
"output": "7017806250"
},
{
"input": "883 954 804 352\n* * +",
"output": "1045740"
},
{
"input": "847 206 949 358\n* + *",
"output": "62660050"
},
{
"input": "663 163 339 76\n+ + +",
"output": "1241"
},
{
"input": "990 330 253 553\n+ * +",
"output": "85033"
},
{
"input": "179 346 525 784\n* * *",
"output": "25492034400"
},
{
"input": "780 418 829 778\n+ + *",
"output": "997766"
},
{
"input": "573 598 791 124\n* * *",
"output": "33608874936"
},
{
"input": "112 823 202 223\n* * +",
"output": "137222"
},
{
"input": "901 166 994 315\n* + *",
"output": "47278294"
},
{
"input": "393 342 840 486\n+ * *",
"output": "178222356"
},
{
"input": "609 275 153 598\n+ + *",
"output": "226746"
},
{
"input": "56 828 386 57\n+ * *",
"output": "3875088"
},
{
"input": "944 398 288 986\n+ + *",
"output": "670464"
},
{
"input": "544 177 162 21\n+ + *",
"output": "18543"
},
{
"input": "105 238 316 265\n+ + +",
"output": "924"
},
{
"input": "31 353 300 911\n* * *",
"output": "2990721900"
},
{
"input": "46 378 310 194\n* * +",
"output": "77528"
},
{
"input": "702 534 357 657\n+ * *",
"output": "259077042"
},
{
"input": "492 596 219 470\n+ + *",
"output": "341202"
},
{
"input": "482 842 982 902\n+ * +",
"output": "407728"
},
{
"input": "827 578 394 351\n* * *",
"output": "66105361764"
},
{
"input": "901 884 426 451\n* + *",
"output": "170223210"
},
{
"input": "210 295 12 795\n* * +",
"output": "71490"
},
{
"input": "40 734 948 202\n+ * *",
"output": "13590560"
},
{
"input": "136 611 963 195\n+ + *",
"output": "240584"
},
{
"input": "695 74 871 760\n+ * +",
"output": "53061"
},
{
"input": "666 884 772 54\n* + +",
"output": "37620"
},
{
"input": "975 785 753 224\n+ * +",
"output": "170432"
},
{
"input": "35 187 126 596\n+ + +",
"output": "944"
},
{
"input": "243 386 431 35\n* + *",
"output": "3298015"
},
{
"input": "229 602 133 635\n* * +",
"output": "222313"
},
{
"input": "916 207 238 891\n+ + *",
"output": "423315"
},
{
"input": "922 145 883 357\n+ + *",
"output": "313490"
},
{
"input": "69 355 762 111\n* + +",
"output": "8776"
},
{
"input": "209 206 34 67\n* + *",
"output": "476374"
},
{
"input": "693 824 375 361\n* * +",
"output": "557339"
},
{
"input": "45 712 635 467\n* + +",
"output": "22362"
},
{
"input": "426 283 179 211\n+ + +",
"output": "1099"
},
{
"input": "802 387 686 12\n+ + +",
"output": "1887"
}
] | 1,617,142,971 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 102,400 | '''''
arr= [1,3,4,3]
i=0
for k in range(8):
if i!=arr[i]-1:
if arr[i]!=arr[arr[i]-1]:
print(arr[i],arr[arr[i]-1],arr,i)
arr[i],arr[arr[i]-1]=arr[arr[i]-1],arr[i]
else:
i+=1
else:
i+=1
print(arr)
'''''
'''
def AllParenthesis(n):
def backtrack(ans,curr,openp,closep,maxp):
if len(curr)==2*maxp:
ans.append(curr)
return
if openp<maxp:
backtrack(ans,curr+"(",openp+1,closep,maxp)
if closep<openp:
backtrack(ans,curr+")",openp,closep+1,maxp)
ans = []
openp, closep = 0, 0
curr = ''
backtrack(ans, curr, openp, closep, n)
return ans
print(AllParenthesis(3))
'''
#mat = [[1,2,3],[4,5,6],[7,8,9]]
'''temp=[[0 for x in range(len(mat[0]))]for x in range(len(mat))]
for i in range(len(mat)):
temp[i][0]=mat[i][0]
for j in range(1,len(mat[0])):
temp[i][j]=temp[i][j-1]+mat[i][j]
for i in range(1,len(mat)):
for j in range(len(mat[0])):
temp[i][j]=temp[i-1][j]+temp[i][j]
k=3
lr=0
lc=0
rr=0
rc=0
ans=[[0 for x in range(len(mat[0]))]for x in range(len(mat))]
for i in range(len(mat)):
for j in range(len(mat[0])):
area1 = 0
area2 = 0
area3 = 0
lr=i
lc=j
if i-k>=0:
lr=i-k
else:
lr=0
if j-k>=0:
lc=j-k
else:
lc=0
rr=i
rc=j
if i+k<len(mat):
rr=i+k
else:
rr=len(mat)-1
if j+k<len(mat[0]):
rc=j+k
else:
rc=len(mat[0])-1
if lc-1>=0:
area1=temp[rr][lc-1]
if lr-1>=0:
area2=temp[lr-1][rc]
if lr-1>=0 and lc-1>=0:
area3=temp[lr-1][lc-1]
ans[i][j]=temp[rr][rc]-area1-area2+area3'''
'''print(ans)'''
'''
nums = [-1,0,1,2,-1,-4] #-1,0,1,2,-1,-4,-2,-3,3,0,4
nums.sort()
print(nums)
seen = set()
length=len(nums)
ans=[]
i=0
while i<length-2:
l=i+1
r=length-1
target=nums[i]
while l<r:
if nums[l]+nums[r]==-target:
seen.add((target,nums[l],nums[r]))
while l < r and nums[l + 1] == nums[l]:
l += 1
while l < r and nums[r - 1] == nums[r]:
r -= 1
l+=1
r-=1
elif nums[l]+nums[r]>-target:
r-=1
else:
l+=1
i+=1
print(seen)
'''
import os
import sys
from io import BytesIO, IOBase
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
'''
def letterCombinations(digits):
digitsmap = [0,0,['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l'], ['m', 'n', 'o'], ['p', 'q', 'r', 's'],
['t', 'u', 'v'], ['w', 'x', 'y', 'z']]
temp=''
n=len(digits)
i=0
ans=[]
def allcombination(temp,i):
if i == n:
ans.append(temp)
return
for j in range(len(digitsmap[int(digits[i])])):
allcombination(temp+digitsmap[int(digits[i])][j],i+1)
allcombination(temp,i)
return ans
print(letterCombinations('23'))
'''
'''
count=0
steps=0
ans=[]
def convert(a,b):
global count,steps
steps += 1
#ans.append(a)
if a>b:
# print(a,steps)
steps-=1
# print(ans)
return
elif a==b:
count+=1
# print(a,steps)
#print(count)
ans.append(a)
return
# print(a)
ans.append(a)
convert(a*2,b)
convert((a*10)+1,b)
convert(2,162)
if count>0:
print(count,"YES")
elif count==0:
print('NO')
print(ans)
'''
'''N=3
n=2
i=0
box1=N
box2=0
box3=0
count=0
def move(i,N,box1,box2,box3):
global count
if N==0:
#print(box1,box2,box3)
count+=1
return
move(i+1,N-1,box1,box3,box2)
print(box1,box3)
move(i+1,N-1,box2,box1,box3)
move(i,N,box1,box2,box3)
print(count)
'''
'''
def numberOfPaths(n, m,count):
def path(i, j,count):
if i == n - 1 or j == m - 1:
count += 1
return
path(i + 1, j,count)
path(i, j +1,count)
count=0
path(0,0,count)
return count
print(numberOfPaths(5,1,count))
'''
ans=999999999
def number(temp,nums,i,m,a):
global ans
if m==0 and a==0:
ans=min(ans,eval(temp))
return
if a>0:
number(temp+'+'+str(nums[i]),nums,i+1,m,a-1)
if m>0:
number(temp+'*'+str(nums[i]), nums, i+1, m-1, a)
nums=list(map(int,input().split()))
a=0
m=0
para=list(map(str,input().split()))
for k in para:
if k=='+':
a+=1
elif k=='*':
m+=1
temp=str(nums[0])
i=1
number(temp,nums,i,m,a)
print(ans) | Title: Smallest number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations.
Input Specification:
First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication)
Output Specification:
Output one integer number — the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
Demo Input:
['1 1 1 1\n+ + *\n', '2 2 2 2\n* * +\n', '1 2 3 4\n* + +\n']
Demo Output:
['3\n', '8\n', '9\n']
Note:
none | ```python
'''''
arr= [1,3,4,3]
i=0
for k in range(8):
if i!=arr[i]-1:
if arr[i]!=arr[arr[i]-1]:
print(arr[i],arr[arr[i]-1],arr,i)
arr[i],arr[arr[i]-1]=arr[arr[i]-1],arr[i]
else:
i+=1
else:
i+=1
print(arr)
'''''
'''
def AllParenthesis(n):
def backtrack(ans,curr,openp,closep,maxp):
if len(curr)==2*maxp:
ans.append(curr)
return
if openp<maxp:
backtrack(ans,curr+"(",openp+1,closep,maxp)
if closep<openp:
backtrack(ans,curr+")",openp,closep+1,maxp)
ans = []
openp, closep = 0, 0
curr = ''
backtrack(ans, curr, openp, closep, n)
return ans
print(AllParenthesis(3))
'''
#mat = [[1,2,3],[4,5,6],[7,8,9]]
'''temp=[[0 for x in range(len(mat[0]))]for x in range(len(mat))]
for i in range(len(mat)):
temp[i][0]=mat[i][0]
for j in range(1,len(mat[0])):
temp[i][j]=temp[i][j-1]+mat[i][j]
for i in range(1,len(mat)):
for j in range(len(mat[0])):
temp[i][j]=temp[i-1][j]+temp[i][j]
k=3
lr=0
lc=0
rr=0
rc=0
ans=[[0 for x in range(len(mat[0]))]for x in range(len(mat))]
for i in range(len(mat)):
for j in range(len(mat[0])):
area1 = 0
area2 = 0
area3 = 0
lr=i
lc=j
if i-k>=0:
lr=i-k
else:
lr=0
if j-k>=0:
lc=j-k
else:
lc=0
rr=i
rc=j
if i+k<len(mat):
rr=i+k
else:
rr=len(mat)-1
if j+k<len(mat[0]):
rc=j+k
else:
rc=len(mat[0])-1
if lc-1>=0:
area1=temp[rr][lc-1]
if lr-1>=0:
area2=temp[lr-1][rc]
if lr-1>=0 and lc-1>=0:
area3=temp[lr-1][lc-1]
ans[i][j]=temp[rr][rc]-area1-area2+area3'''
'''print(ans)'''
'''
nums = [-1,0,1,2,-1,-4] #-1,0,1,2,-1,-4,-2,-3,3,0,4
nums.sort()
print(nums)
seen = set()
length=len(nums)
ans=[]
i=0
while i<length-2:
l=i+1
r=length-1
target=nums[i]
while l<r:
if nums[l]+nums[r]==-target:
seen.add((target,nums[l],nums[r]))
while l < r and nums[l + 1] == nums[l]:
l += 1
while l < r and nums[r - 1] == nums[r]:
r -= 1
l+=1
r-=1
elif nums[l]+nums[r]>-target:
r-=1
else:
l+=1
i+=1
print(seen)
'''
import os
import sys
from io import BytesIO, IOBase
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
'''
def letterCombinations(digits):
digitsmap = [0,0,['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l'], ['m', 'n', 'o'], ['p', 'q', 'r', 's'],
['t', 'u', 'v'], ['w', 'x', 'y', 'z']]
temp=''
n=len(digits)
i=0
ans=[]
def allcombination(temp,i):
if i == n:
ans.append(temp)
return
for j in range(len(digitsmap[int(digits[i])])):
allcombination(temp+digitsmap[int(digits[i])][j],i+1)
allcombination(temp,i)
return ans
print(letterCombinations('23'))
'''
'''
count=0
steps=0
ans=[]
def convert(a,b):
global count,steps
steps += 1
#ans.append(a)
if a>b:
# print(a,steps)
steps-=1
# print(ans)
return
elif a==b:
count+=1
# print(a,steps)
#print(count)
ans.append(a)
return
# print(a)
ans.append(a)
convert(a*2,b)
convert((a*10)+1,b)
convert(2,162)
if count>0:
print(count,"YES")
elif count==0:
print('NO')
print(ans)
'''
'''N=3
n=2
i=0
box1=N
box2=0
box3=0
count=0
def move(i,N,box1,box2,box3):
global count
if N==0:
#print(box1,box2,box3)
count+=1
return
move(i+1,N-1,box1,box3,box2)
print(box1,box3)
move(i+1,N-1,box2,box1,box3)
move(i,N,box1,box2,box3)
print(count)
'''
'''
def numberOfPaths(n, m,count):
def path(i, j,count):
if i == n - 1 or j == m - 1:
count += 1
return
path(i + 1, j,count)
path(i, j +1,count)
count=0
path(0,0,count)
return count
print(numberOfPaths(5,1,count))
'''
ans=999999999
def number(temp,nums,i,m,a):
global ans
if m==0 and a==0:
ans=min(ans,eval(temp))
return
if a>0:
number(temp+'+'+str(nums[i]),nums,i+1,m,a-1)
if m>0:
number(temp+'*'+str(nums[i]), nums, i+1, m-1, a)
nums=list(map(int,input().split()))
a=0
m=0
para=list(map(str,input().split()))
for k in para:
if k=='+':
a+=1
elif k=='*':
m+=1
temp=str(nums[0])
i=1
number(temp,nums,i,m,a)
print(ans)
``` | 0 |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.?
Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3"
},
{
"input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2",
"output": "7\n7"
},
{
"input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1",
"output": "7"
},
{
"input": "2 2\n8 4\n1\n1",
"output": "2\n2"
},
{
"input": "1 5\n5\n1\n1\n1\n1\n1",
"output": "1\n1\n1\n1\n1"
},
{
"input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4",
"output": "1\n4\n3\n2\n3\n1\n1"
},
{
"input": "4 3\n9 1 7 1\n1\n4\n2",
"output": "3\n1\n2"
},
{
"input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7",
"output": "4\n3\n2"
},
{
"input": "1 1\n1\n1",
"output": "1"
}
] | 1,668,045,309 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 5,222,400 | n,m=map(int,input().split())
a=[int(x) for x in input().split()]
for i1 in range(m):
num=int(input())
l=set(a[num-1:])
print(len(l)) | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.?
Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Output Specification:
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
Demo Input:
['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n']
Demo Output:
['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n']
Note:
none | ```python
n,m=map(int,input().split())
a=[int(x) for x in input().split()]
for i1 in range(m):
num=int(input())
l=set(a[num-1:])
print(len(l))
``` | 0 |
|
250 | B | Restoring IPv6 | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef". We'll call such format of recording an IPv6-address full.
Besides the full record of an IPv6 address there is a short record format. The record of an IPv6 address can be shortened by removing one or more leading zeroes at the beginning of each block. However, each block should contain at least one digit in the short format. For example, the leading zeroes can be removed like that: "a56f:00d3:0000:0124:0001:f19a:1000:0000" <=→<= "a56f:d3:0:0124:01:f19a:1000:00". There are more ways to shorten zeroes in this IPv6 address.
Some IPv6 addresses contain long sequences of zeroes. Continuous sequences of 16-bit zero blocks can be shortened to "::". A sequence can consist of one or several consecutive blocks, with all 16 bits equal to 0.
You can see examples of zero block shortenings below:
- "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::"; - "a56f:0000:0000:0124:0001:0000:1234:0ff0" <=→<= "a56f::0124:0001:0000:1234:0ff0"; - "a56f:0000:0000:0000:0001:0000:1234:0ff0" <=→<= "a56f:0000::0000:0001:0000:1234:0ff0"; - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::0000"; - "0000:0000:0000:0000:0000:0000:0000:0000" <=→<= "::".
It is not allowed to shorten zero blocks in the address more than once. This means that the short record can't contain the sequence of characters "::" more than once. Otherwise, it will sometimes be impossible to determine the number of zero blocks, each represented by a double colon.
The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short.
You've got several short records of IPv6 addresses. Restore their full record. | The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100).
Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address. | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | [
"6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n"
] | [
"a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n"
] | none | 1,000 | [
{
"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0",
"output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000"
},
{
"input": "20\n0:0:9e39:9:b21:c9b:c:0\n0:0:0:0:0:a27:6b:cb0a\n2:7:4d:b:0:3:2:f401\n17:2dc6::0:89e3:0:dc:0\nca:4:0:0:d6:b999:e:0\n4af:553:b29:dd7:2:5b:0:7\n0:c981:8f:a4d:0:d4:0:f61\n0:0:1:0:dc33:0:1964:0\n84:da:0:6d6:0ecc:1:f:0\n4:fb:4d37:0:8c:4:4a52:24\nc:e:a:0:0:0:e:0\n0:3761:72ed:b7:3b0:ff7:fc:102\n5ae:8ca7:10::0:9b2:0:525a\n0::ab:8d64:86:767:2\ne6b:3cb:0:81ce:0ac4:11::1\n4:0:5238:7b:591d:ff15:0:e\n0:f9a5:0::118e:dde:0\n0:d4c:feb:b:10a:0:d:e\n0:0:0:ff38:b5d:a3c2:f3:0\n2:a:6:c50:83:4f:7f0d::",
"output": "0000:0000:9e39:0009:0b21:0c9b:000c:0000\n0000:0000:0000:0000:0000:0a27:006b:cb0a\n0002:0007:004d:000b:0000:0003:0002:f401\n0017:2dc6:0000:0000:89e3:0000:00dc:0000\n00ca:0004:0000:0000:00d6:b999:000e:0000\n04af:0553:0b29:0dd7:0002:005b:0000:0007\n0000:c981:008f:0a4d:0000:00d4:0000:0f61\n0000:0000:0001:0000:dc33:0000:1964:0000\n0084:00da:0000:06d6:0ecc:0001:000f:0000\n0004:00fb:4d37:0000:008c:0004:4a52:0024\n000c:000e:000a:0000:0000:0000:000e:0000\n0000:3761:72ed:00b7:03b0:0ff7:00fc:0102\n05ae:8ca7:0010:0000..."
},
{
"input": "10\n1::7\n0:0::1\n::1ed\n::30:44\n::eaf:ff:000b\n56fe::\ndf0:3df::\nd03:ab:0::\n85::0485:0\n::",
"output": "0001:0000:0000:0000:0000:0000:0000:0007\n0000:0000:0000:0000:0000:0000:0000:0001\n0000:0000:0000:0000:0000:0000:0000:01ed\n0000:0000:0000:0000:0000:0000:0030:0044\n0000:0000:0000:0000:0000:0eaf:00ff:000b\n56fe:0000:0000:0000:0000:0000:0000:0000\n0df0:03df:0000:0000:0000:0000:0000:0000\n0d03:00ab:0000:0000:0000:0000:0000:0000\n0085:0000:0000:0000:0000:0000:0485:0000\n0000:0000:0000:0000:0000:0000:0000:0000"
},
{
"input": "6\n0:00:000:0000::\n1:01:001:0001::\nf:0f:00f:000f::\n1:10:100:1000::\nf:f0:f00:f000::\nf:ff:fff:ffff::",
"output": "0000:0000:0000:0000:0000:0000:0000:0000\n0001:0001:0001:0001:0000:0000:0000:0000\n000f:000f:000f:000f:0000:0000:0000:0000\n0001:0010:0100:1000:0000:0000:0000:0000\n000f:00f0:0f00:f000:0000:0000:0000:0000\n000f:00ff:0fff:ffff:0000:0000:0000:0000"
},
{
"input": "3\n::\n::\n::",
"output": "0000:0000:0000:0000:0000:0000:0000:0000\n0000:0000:0000:0000:0000:0000:0000:0000\n0000:0000:0000:0000:0000:0000:0000:0000"
},
{
"input": "4\n1:2:3:4:5:6:7:8\n0:0:0:0:0:0:0:0\nf:0f:00f:000f:ff:0ff:00ff:fff\n0fff:0ff0:0f0f:f0f:0f0:f0f0:f00f:ff0f",
"output": "0001:0002:0003:0004:0005:0006:0007:0008\n0000:0000:0000:0000:0000:0000:0000:0000\n000f:000f:000f:000f:00ff:00ff:00ff:0fff\n0fff:0ff0:0f0f:0f0f:00f0:f0f0:f00f:ff0f"
}
] | 1,683,228,651 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | t = int(input()) # number of test cases
for _ in range(t):
ip = input() # read the input IPv6 address
ip = ip.split(":") # split the address into groups
# pad each group with leading zeros if necessary
for i in range(len(ip)):
if len(ip[i]) < 4:
ip[i] = "0"*(4-len(ip[i])) + ip[i]
# add missing groups with zeros
while len(ip) < 8:
ip.insert(ip.index(""), "0000")
# join the groups and print the IPv6 address
print(":".join(ip))
| Title: Restoring IPv6
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef". We'll call such format of recording an IPv6-address full.
Besides the full record of an IPv6 address there is a short record format. The record of an IPv6 address can be shortened by removing one or more leading zeroes at the beginning of each block. However, each block should contain at least one digit in the short format. For example, the leading zeroes can be removed like that: "a56f:00d3:0000:0124:0001:f19a:1000:0000" <=→<= "a56f:d3:0:0124:01:f19a:1000:00". There are more ways to shorten zeroes in this IPv6 address.
Some IPv6 addresses contain long sequences of zeroes. Continuous sequences of 16-bit zero blocks can be shortened to "::". A sequence can consist of one or several consecutive blocks, with all 16 bits equal to 0.
You can see examples of zero block shortenings below:
- "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::"; - "a56f:0000:0000:0124:0001:0000:1234:0ff0" <=→<= "a56f::0124:0001:0000:1234:0ff0"; - "a56f:0000:0000:0000:0001:0000:1234:0ff0" <=→<= "a56f:0000::0000:0001:0000:1234:0ff0"; - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::0000"; - "0000:0000:0000:0000:0000:0000:0000:0000" <=→<= "::".
It is not allowed to shorten zero blocks in the address more than once. This means that the short record can't contain the sequence of characters "::" more than once. Otherwise, it will sometimes be impossible to determine the number of zero blocks, each represented by a double colon.
The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short.
You've got several short records of IPv6 addresses. Restore their full record.
Input Specification:
The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100).
Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address.
Output Specification:
For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input.
Demo Input:
['6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n']
Demo Output:
['a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n']
Note:
none | ```python
t = int(input()) # number of test cases
for _ in range(t):
ip = input() # read the input IPv6 address
ip = ip.split(":") # split the address into groups
# pad each group with leading zeros if necessary
for i in range(len(ip)):
if len(ip[i]) < 4:
ip[i] = "0"*(4-len(ip[i])) + ip[i]
# add missing groups with zeros
while len(ip) < 8:
ip.insert(ip.index(""), "0000")
# join the groups and print the IPv6 address
print(":".join(ip))
``` | -1 |
|
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
},
{
"input": "4\n5 4 5 4",
"output": "-1"
},
{
"input": "7\n3 4 5 5 5 1 2",
"output": "2"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "5\n5 4 1 2 3",
"output": "-1"
},
{
"input": "4\n6 1 2 7",
"output": "-1"
},
{
"input": "5\n4 5 6 2 3",
"output": "2"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "4\n1 2 2 1",
"output": "1"
},
{
"input": "9\n4 5 6 7 1 2 3 4 10",
"output": "-1"
},
{
"input": "7\n2 3 4 1 2 3 4",
"output": "-1"
},
{
"input": "6\n1 2 1 2 1 2",
"output": "-1"
},
{
"input": "3\n3 2 1",
"output": "-1"
},
{
"input": "4\n1 4 4 1",
"output": "1"
},
{
"input": "5\n1 2 1 1 1",
"output": "3"
},
{
"input": "5\n4 6 7 3 5",
"output": "-1"
},
{
"input": "4\n2 3 1 4",
"output": "-1"
},
{
"input": "5\n5 4 3 2 1",
"output": "-1"
},
{
"input": "4\n2 4 1 4",
"output": "-1"
},
{
"input": "6\n4 5 6 1 2 7",
"output": "-1"
},
{
"input": "6\n1 2 3 1 1 1",
"output": "3"
},
{
"input": "5\n1 3 3 3 1",
"output": "1"
},
{
"input": "6\n5 6 7 5 5 5",
"output": "3"
},
{
"input": "5\n3 4 2 1 2",
"output": "-1"
},
{
"input": "3\n3 4 2",
"output": "1"
},
{
"input": "6\n1 1 2 2 1 1",
"output": "2"
},
{
"input": "4\n2 3 4 2",
"output": "1"
},
{
"input": "5\n3 5 7 7 3",
"output": "1"
},
{
"input": "4\n1 1 4 1",
"output": "1"
},
{
"input": "7\n1 5 6 1 1 1 1",
"output": "4"
},
{
"input": "5\n7 8 6 7 8",
"output": "-1"
},
{
"input": "4\n2 4 1 3",
"output": "-1"
}
] | 1,606,544,680 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 32 | 155 | 7,680,000 |
a=int(input())
arr=list(map(int,input().split()))
minn=min(arr)
maxx=max(arr)
k=-1
for i in range(0,len(arr)-1):
if(arr[i]==maxx and arr[i+1]==minn):
k=i
break
if(arr[len(arr)-1]==maxx and arr[0]==minn):
k=0
if(k==-1):
print(-1)
else:
bef=arr[:k+1]
af=arr[k+1:]
if(sorted(arr)==arr):
print(0)
elif(sorted(bef)==bef and sorted(af)==af):
print(len(arr)-k-1)
else:
print(-1)
| Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
Demo Input:
['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['1\n', '-1\n', '0\n']
Note:
none | ```python
a=int(input())
arr=list(map(int,input().split()))
minn=min(arr)
maxx=max(arr)
k=-1
for i in range(0,len(arr)-1):
if(arr[i]==maxx and arr[i+1]==minn):
k=i
break
if(arr[len(arr)-1]==maxx and arr[0]==minn):
k=0
if(k==-1):
print(-1)
else:
bef=arr[:k+1]
af=arr[k+1:]
if(sorted(arr)==arr):
print(0)
elif(sorted(bef)==bef and sorted(af)==af):
print(len(arr)-k-1)
else:
print(-1)
``` | 0 |
|
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible.
Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where:
- *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=<<=*i*<=≤<=*k*).
If there are multiple answers, print any of them. | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
{
"input": "1 1000000000",
"output": "NO"
},
{
"input": "999999999 1000000000",
"output": "NO"
},
{
"input": "1 2",
"output": "YES\n2\n1 2 "
},
{
"input": "1 536870912",
"output": "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 "
},
{
"input": "11111 11111111",
"output": "YES\n4\n11111 111111 1111111 11111111 "
},
{
"input": "59139 946224",
"output": "YES\n5\n59139 118278 236556 473112 946224 "
},
{
"input": "9859 19718",
"output": "YES\n2\n9859 19718 "
},
{
"input": "25987 51974222",
"output": "YES\n5\n25987 259871 2598711 25987111 51974222 "
},
{
"input": "9411 188222222",
"output": "YES\n6\n9411 94111 941111 9411111 94111111 188222222 "
},
{
"input": "25539 510782222",
"output": "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 "
},
{
"input": "76259 610072",
"output": "YES\n4\n76259 152518 305036 610072 "
},
{
"input": "92387 184774",
"output": "YES\n2\n92387 184774 "
},
{
"input": "8515 85151111",
"output": "YES\n5\n8515 85151 851511 8515111 85151111 "
},
{
"input": "91939 9193911",
"output": "YES\n3\n91939 919391 9193911 "
},
{
"input": "30518 610361",
"output": "YES\n3\n30518 61036 610361 "
},
{
"input": "46646 373168844",
"output": "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 "
},
{
"input": "30070 300701",
"output": "YES\n2\n30070 300701 "
},
{
"input": "13494 1079528",
"output": "YES\n5\n13494 134941 269882 539764 1079528 "
},
{
"input": "96918 775344422",
"output": "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 "
},
{
"input": "13046 260921",
"output": "YES\n3\n13046 26092 260921 "
},
{
"input": "29174 5834811",
"output": "YES\n4\n29174 58348 583481 5834811 "
},
{
"input": "79894 319576421",
"output": "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 "
},
{
"input": "96022 1920442",
"output": "YES\n3\n96022 960221 1920442 "
},
{
"input": "79446 6355681",
"output": "YES\n5\n79446 158892 317784 635568 6355681 "
},
{
"input": "5440 27853056",
"output": "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 "
},
{
"input": "250000000 705032705",
"output": "NO"
},
{
"input": "17 35",
"output": "NO"
},
{
"input": "1 3",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
}
] | 1,616,600,838 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 186 | 9,318,400 | def fc(a,b,re,bl,tmp):
if(a>b):
return
if(a==b):
bl[0]=False
# tmp.append(a)
re.append(tmp)
return
if(bl[0]):
fc(a*2,b,re,bl,tmp+[a*2])
fc(a*10+1,b,re,bl,tmp+[a*10+1])
re=[]
bl=[True]
# fc(2,162,re,bl,[])
a,b=map(int,input().split())
fc(a,b,re,bl,[])
if(len(re)==0):
print("NO")
else:
print("YES")
print(1+len(re[0]))
ans=[[a]+re[0]]
print(a,end=" ")
for i in re[0]:
print(i,end=" ")
print() | Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible.
Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*.
Input Specification:
The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have.
Output Specification:
If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where:
- *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=<<=*i*<=≤<=*k*).
If there are multiple answers, print any of them.
Demo Input:
['2 162\n', '4 42\n', '100 40021\n']
Demo Output:
['YES\n5\n2 4 8 81 162 \n', 'NO\n', 'YES\n5\n100 200 2001 4002 40021 \n']
Note:
none | ```python
def fc(a,b,re,bl,tmp):
if(a>b):
return
if(a==b):
bl[0]=False
# tmp.append(a)
re.append(tmp)
return
if(bl[0]):
fc(a*2,b,re,bl,tmp+[a*2])
fc(a*10+1,b,re,bl,tmp+[a*10+1])
re=[]
bl=[True]
# fc(2,162,re,bl,[])
a,b=map(int,input().split())
fc(a,b,re,bl,[])
if(len(re)==0):
print("NO")
else:
print("YES")
print(1+len(re[0]))
ans=[[a]+re[0]]
print(a,end=" ")
for i in re[0]:
print(i,end=" ")
print()
``` | 3 |
|
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "1 1 1 1 1 1",
"output": "Elephant"
},
{
"input": "9 9 9 9 9 9",
"output": "Elephant"
},
{
"input": "1 8 9 1 1 1",
"output": "Bear"
},
{
"input": "9 9 9 1 9 9",
"output": "Bear"
},
{
"input": "1 2 3 8 9 7",
"output": "Alien"
},
{
"input": "5 5 5 6 6 6",
"output": "Alien"
},
{
"input": "1 1 2 2 3 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 2",
"output": "Bear"
},
{
"input": "2 2 3 3 4 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 5",
"output": "Bear"
},
{
"input": "1 1 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 2 5 5 5 5",
"output": "Bear"
},
{
"input": "4 4 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 1 2",
"output": "Bear"
},
{
"input": "2 2 4 4 4 4",
"output": "Elephant"
},
{
"input": "4 4 4 4 4 3",
"output": "Bear"
},
{
"input": "4 4 5 6 7 8",
"output": "Alien"
},
{
"input": "4 4 4 4 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 2 2",
"output": "Elephant"
},
{
"input": "1 1 3 3 3 5",
"output": "Alien"
},
{
"input": "1 2 2 3 3 3",
"output": "Alien"
},
{
"input": "1 2 2 2 2 2",
"output": "Bear"
},
{
"input": "1 3 3 3 4 5",
"output": "Alien"
},
{
"input": "5 1 1 1 1 1",
"output": "Bear"
}
] | 1,453,290,037 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 62 | 0 | ip=list(map(int,input().split()))
op=0
for j in ip:
if ip.count(j)>=4:
op+=j
break
if op==0:
print('Alien')
else:
if ip.count(op)==4:
ip.remove(op)
ip.remove(op)
ip.remove(op)
ip.remove(op)
[a,b]=ip
if a==b:
print('Elephant')
else:
print('Bear')
elif ip.count(op)==6:
print('Elephant')
else:
ip.remove(op)
ip.remove(op)
ip.remove(op)
ip.remove(op)
ip.remove(op)
[a]=ip
if a<op:
print('Bear')
else:
print('Alien')
| Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
Input Specification:
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
Output Specification:
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
Demo Input:
['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n']
Demo Output:
['Bear', 'Elephant', 'Alien']
Note:
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | ```python
ip=list(map(int,input().split()))
op=0
for j in ip:
if ip.count(j)>=4:
op+=j
break
if op==0:
print('Alien')
else:
if ip.count(op)==4:
ip.remove(op)
ip.remove(op)
ip.remove(op)
ip.remove(op)
[a,b]=ip
if a==b:
print('Elephant')
else:
print('Bear')
elif ip.count(op)==6:
print('Elephant')
else:
ip.remove(op)
ip.remove(op)
ip.remove(op)
ip.remove(op)
ip.remove(op)
[a]=ip
if a<op:
print('Bear')
else:
print('Alien')
``` | 0 |
|
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*. | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"output": "50"
},
{
"input": "50 250",
"output": "0"
},
{
"input": "29 116",
"output": "0"
},
{
"input": "20 69",
"output": "0"
},
{
"input": "46 127",
"output": "11"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "36 99",
"output": "9"
},
{
"input": "45 104",
"output": "31"
},
{
"input": "13 57",
"output": "0"
},
{
"input": "25 106",
"output": "0"
},
{
"input": "8 19",
"output": "5"
},
{
"input": "20 69",
"output": "0"
},
{
"input": "13 32",
"output": "7"
},
{
"input": "47 128",
"output": "13"
},
{
"input": "17 73",
"output": "0"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "16 70",
"output": "0"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "38 137",
"output": "0"
},
{
"input": "7 20",
"output": "1"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "36 155",
"output": "0"
},
{
"input": "5 15",
"output": "0"
},
{
"input": "27 75",
"output": "6"
},
{
"input": "21 73",
"output": "0"
},
{
"input": "2 5",
"output": "1"
},
{
"input": "49 177",
"output": "0"
},
{
"input": "7 20",
"output": "1"
},
{
"input": "44 173",
"output": "0"
},
{
"input": "49 219",
"output": "0"
},
{
"input": "16 70",
"output": "0"
},
{
"input": "10 28",
"output": "2"
}
] | 1,578,660,536 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 248 | 307,200 | n, m = map(int, input().split())
print(max(0, n*3-m))
# FMZJMSOMPMSL
| Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*.
Input Specification:
The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*.
Output Specification:
Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*.
Demo Input:
['4 8\n', '4 10\n', '1 3\n']
Demo Output:
['4\n', '2\n', '0\n']
Note:
In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | ```python
n, m = map(int, input().split())
print(max(0, n*3-m))
# FMZJMSOMPMSL
``` | 3 |
|
492 | A | Vanya and Cubes | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes.
Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes. | The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. | Print the maximum possible height of the pyramid in the single line. | [
"1\n",
"25\n"
] | [
"1\n",
"4\n"
] | Illustration to the second sample: | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"output": "33"
},
{
"input": "4",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "19",
"output": "3"
},
{
"input": "20",
"output": "4"
},
{
"input": "9880",
"output": "38"
},
{
"input": "9879",
"output": "37"
},
{
"input": "7770",
"output": "35"
},
{
"input": "7769",
"output": "34"
},
{
"input": "2925",
"output": "25"
},
{
"input": "220",
"output": "10"
},
{
"input": "219",
"output": "9"
},
{
"input": "3046",
"output": "25"
},
{
"input": "7590",
"output": "34"
},
{
"input": "1014",
"output": "17"
},
{
"input": "7142",
"output": "34"
},
{
"input": "9999",
"output": "38"
},
{
"input": "10000",
"output": "38"
}
] | 1,685,712,744 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 0 | n = int(input())
levels = 0
prev, current = 0, 0
add = 0
s = 0
while True:
if levels % 2 == 1: add += 1
current = prev + 1 + 2 * add if levels % 2 == 0 else prev + 2 * add
s += current
if s > n: break
prev = current
levels += 1
print(levels) | Title: Vanya and Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes.
Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
Output Specification:
Print the maximum possible height of the pyramid in the single line.
Demo Input:
['1\n', '25\n']
Demo Output:
['1\n', '4\n']
Note:
Illustration to the second sample: | ```python
n = int(input())
levels = 0
prev, current = 0, 0
add = 0
s = 0
while True:
if levels % 2 == 1: add += 1
current = prev + 1 + 2 * add if levels % 2 == 0 else prev + 2 * add
s += current
if s > n: break
prev = current
levels += 1
print(levels)
``` | 3 |