contestId
int64
0
1.01k
name
stringlengths
2
58
tags
sequencelengths
0
11
title
stringclasses
523 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
test_cases
listlengths
0
402
timeConsumedMillis
int64
0
8k
memoryConsumedBytes
int64
0
537M
score
float64
-1
3.99
__index_level_0__
int64
0
621k
12
Start of the session
[ "constructive algorithms" ]
E. Start of the season
2
256
Before the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the size *n*<=×<=*n* (*n* is even number). Gods will never allow to start the championship without it. Matrix should contain integers from 0 to *n*<=-<=1, main diagonal should contain only zeroes and matrix should be symmetric. Moreover, all numbers in each row should be different. Magicians are very tired of the thinking process, so they ask you to write a program to find such matrix.
The first line contains one integer *n* (2<=≤<=*n*<=≤<=1000), *n* is even.
Output *n* lines with *n* numbers each — the required matrix. Separate numbers with spaces. If there are several solutions, output any.
[ "2\n", "4\n" ]
[ "0 1\n1 0\n", "0 1 3 2\n1 0 2 3\n3 2 0 1\n2 3 1 0\n" ]
none
[ { "input": "2", "output": "0 1\n1 0" }, { "input": "4", "output": "0 1 3 2\n1 0 2 3\n3 2 0 1\n2 3 1 0" }, { "input": "6", "output": "0 1 4 2 5 3\n1 0 2 5 3 4\n4 2 0 3 1 5\n2 5 3 0 4 1\n5 3 1 4 0 2\n3 4 5 1 2 0" }, { "input": "8", "output": "0 1 5 2 6 3 7 4\n1 0 2 6 3 7 4 5\n5 2 0 3 7 4 1 6\n2 6 3 0 4 1 5 7\n6 3 7 4 0 5 2 1\n3 7 4 1 5 0 6 2\n7 4 1 5 2 6 0 3\n4 5 6 7 1 2 3 0" }, { "input": "10", "output": "0 1 6 2 7 3 8 4 9 5\n1 0 2 7 3 8 4 9 5 6\n6 2 0 3 8 4 9 5 1 7\n2 7 3 0 4 9 5 1 6 8\n7 3 8 4 0 5 1 6 2 9\n3 8 4 9 5 0 6 2 7 1\n8 4 9 5 1 6 0 7 3 2\n4 9 5 1 6 2 7 0 8 3\n9 5 1 6 2 7 3 8 0 4\n5 6 7 8 9 1 2 3 4 0" }, { "input": "12", "output": "0 1 7 2 8 3 9 4 10 5 11 6\n1 0 2 8 3 9 4 10 5 11 6 7\n7 2 0 3 9 4 10 5 11 6 1 8\n2 8 3 0 4 10 5 11 6 1 7 9\n8 3 9 4 0 5 11 6 1 7 2 10\n3 9 4 10 5 0 6 1 7 2 8 11\n9 4 10 5 11 6 0 7 2 8 3 1\n4 10 5 11 6 1 7 0 8 3 9 2\n10 5 11 6 1 7 2 8 0 9 4 3\n5 11 6 1 7 2 8 3 9 0 10 4\n11 6 1 7 2 8 3 9 4 10 0 5\n6 7 8 9 10 11 1 2 3 4 5 0" }, { "input": "14", "output": "0 1 8 2 9 3 10 4 11 5 12 6 13 7\n1 0 2 9 3 10 4 11 5 12 6 13 7 8\n8 2 0 3 10 4 11 5 12 6 13 7 1 9\n2 9 3 0 4 11 5 12 6 13 7 1 8 10\n9 3 10 4 0 5 12 6 13 7 1 8 2 11\n3 10 4 11 5 0 6 13 7 1 8 2 9 12\n10 4 11 5 12 6 0 7 1 8 2 9 3 13\n4 11 5 12 6 13 7 0 8 2 9 3 10 1\n11 5 12 6 13 7 1 8 0 9 3 10 4 2\n5 12 6 13 7 1 8 2 9 0 10 4 11 3\n12 6 13 7 1 8 2 9 3 10 0 11 5 4\n6 13 7 1 8 2 9 3 10 4 11 0 12 5\n13 7 1 8 2 9 3 10 4 11 5 12 0 6\n7 8 9 10 11 12 13 1 2 3 4 5 6 0" }, { "input": "16", "output": "0 1 9 2 10 3 11 4 12 5 13 6 14 7 15 8\n1 0 2 10 3 11 4 12 5 13 6 14 7 15 8 9\n9 2 0 3 11 4 12 5 13 6 14 7 15 8 1 10\n2 10 3 0 4 12 5 13 6 14 7 15 8 1 9 11\n10 3 11 4 0 5 13 6 14 7 15 8 1 9 2 12\n3 11 4 12 5 0 6 14 7 15 8 1 9 2 10 13\n11 4 12 5 13 6 0 7 15 8 1 9 2 10 3 14\n4 12 5 13 6 14 7 0 8 1 9 2 10 3 11 15\n12 5 13 6 14 7 15 8 0 9 2 10 3 11 4 1\n5 13 6 14 7 15 8 1 9 0 10 3 11 4 12 2\n13 6 14 7 15 8 1 9 2 10 0 11 4 12 5 3\n6 14 7 15 8 1 9 2 10 3 11 0 12 5 13 4\n14 7 15 8 1 9 2 10 3 11 4 12 0 13 6 5\n7 15..." }, { "input": "18", "output": "0 1 10 2 11 3 12 4 13 5 14 6 15 7 16 8 17 9\n1 0 2 11 3 12 4 13 5 14 6 15 7 16 8 17 9 10\n10 2 0 3 12 4 13 5 14 6 15 7 16 8 17 9 1 11\n2 11 3 0 4 13 5 14 6 15 7 16 8 17 9 1 10 12\n11 3 12 4 0 5 14 6 15 7 16 8 17 9 1 10 2 13\n3 12 4 13 5 0 6 15 7 16 8 17 9 1 10 2 11 14\n12 4 13 5 14 6 0 7 16 8 17 9 1 10 2 11 3 15\n4 13 5 14 6 15 7 0 8 17 9 1 10 2 11 3 12 16\n13 5 14 6 15 7 16 8 0 9 1 10 2 11 3 12 4 17\n5 14 6 15 7 16 8 17 9 0 10 2 11 3 12 4 13 1\n14 6 15 7 16 8 17 9 1 10 0 11 3 12 4 13 5 2\n6 15 7 16 8 17 9..." }, { "input": "20", "output": "0 1 11 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10\n1 0 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10 11\n11 2 0 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10 1 12\n2 12 3 0 4 14 5 15 6 16 7 17 8 18 9 19 10 1 11 13\n12 3 13 4 0 5 15 6 16 7 17 8 18 9 19 10 1 11 2 14\n3 13 4 14 5 0 6 16 7 17 8 18 9 19 10 1 11 2 12 15\n13 4 14 5 15 6 0 7 17 8 18 9 19 10 1 11 2 12 3 16\n4 14 5 15 6 16 7 0 8 18 9 19 10 1 11 2 12 3 13 17\n14 5 15 6 16 7 17 8 0 9 19 10 1 11 2 12 3 13 4 18\n5 15 6 16 7 17 8 18 9 0 10 1 11 2 12 3 13 4 14 19\n1..." }, { "input": "32", "output": "0 1 17 2 18 3 19 4 20 5 21 6 22 7 23 8 24 9 25 10 26 11 27 12 28 13 29 14 30 15 31 16\n1 0 2 18 3 19 4 20 5 21 6 22 7 23 8 24 9 25 10 26 11 27 12 28 13 29 14 30 15 31 16 17\n17 2 0 3 19 4 20 5 21 6 22 7 23 8 24 9 25 10 26 11 27 12 28 13 29 14 30 15 31 16 1 18\n2 18 3 0 4 20 5 21 6 22 7 23 8 24 9 25 10 26 11 27 12 28 13 29 14 30 15 31 16 1 17 19\n18 3 19 4 0 5 21 6 22 7 23 8 24 9 25 10 26 11 27 12 28 13 29 14 30 15 31 16 1 17 2 20\n3 19 4 20 5 0 6 22 7 23 8 24 9 25 10 26 11 27 12 28 13 29 14 30 15 31 16 1 1..." }, { "input": "40", "output": "0 1 21 2 22 3 23 4 24 5 25 6 26 7 27 8 28 9 29 10 30 11 31 12 32 13 33 14 34 15 35 16 36 17 37 18 38 19 39 20\n1 0 2 22 3 23 4 24 5 25 6 26 7 27 8 28 9 29 10 30 11 31 12 32 13 33 14 34 15 35 16 36 17 37 18 38 19 39 20 21\n21 2 0 3 23 4 24 5 25 6 26 7 27 8 28 9 29 10 30 11 31 12 32 13 33 14 34 15 35 16 36 17 37 18 38 19 39 20 1 22\n2 22 3 0 4 24 5 25 6 26 7 27 8 28 9 29 10 30 11 31 12 32 13 33 14 34 15 35 16 36 17 37 18 38 19 39 20 1 21 23\n22 3 23 4 0 5 25 6 26 7 27 8 28 9 29 10 30 11 31 12 32 13 33 14 34 ..." }, { "input": "666", "output": "0 1 334 2 335 3 336 4 337 5 338 6 339 7 340 8 341 9 342 10 343 11 344 12 345 13 346 14 347 15 348 16 349 17 350 18 351 19 352 20 353 21 354 22 355 23 356 24 357 25 358 26 359 27 360 28 361 29 362 30 363 31 364 32 365 33 366 34 367 35 368 36 369 37 370 38 371 39 372 40 373 41 374 42 375 43 376 44 377 45 378 46 379 47 380 48 381 49 382 50 383 51 384 52 385 53 386 54 387 55 388 56 389 57 390 58 391 59 392 60 393 61 394 62 395 63 396 64 397 65 398 66 399 67 400 68 401 69 402 70 403 71 404 72 405 73 406 74 407 ..." }, { "input": "66", "output": "0 1 34 2 35 3 36 4 37 5 38 6 39 7 40 8 41 9 42 10 43 11 44 12 45 13 46 14 47 15 48 16 49 17 50 18 51 19 52 20 53 21 54 22 55 23 56 24 57 25 58 26 59 27 60 28 61 29 62 30 63 31 64 32 65 33\n1 0 2 35 3 36 4 37 5 38 6 39 7 40 8 41 9 42 10 43 11 44 12 45 13 46 14 47 15 48 16 49 17 50 18 51 19 52 20 53 21 54 22 55 23 56 24 57 25 58 26 59 27 60 28 61 29 62 30 63 31 64 32 65 33 34\n34 2 0 3 36 4 37 5 38 6 39 7 40 8 41 9 42 10 43 11 44 12 45 13 46 14 47 15 48 16 49 17 50 18 51 19 52 20 53 21 54 22 55 23 56 24 57 2..." }, { "input": "80", "output": "0 1 41 2 42 3 43 4 44 5 45 6 46 7 47 8 48 9 49 10 50 11 51 12 52 13 53 14 54 15 55 16 56 17 57 18 58 19 59 20 60 21 61 22 62 23 63 24 64 25 65 26 66 27 67 28 68 29 69 30 70 31 71 32 72 33 73 34 74 35 75 36 76 37 77 38 78 39 79 40\n1 0 2 42 3 43 4 44 5 45 6 46 7 47 8 48 9 49 10 50 11 51 12 52 13 53 14 54 15 55 16 56 17 57 18 58 19 59 20 60 21 61 22 62 23 63 24 64 25 65 26 66 27 67 28 68 29 69 30 70 31 71 32 72 33 73 34 74 35 75 36 76 37 77 38 78 39 79 40 41\n41 2 0 3 43 4 44 5 45 6 46 7 47 8 48 9 49 10 50 1..." }, { "input": "88", "output": "0 1 45 2 46 3 47 4 48 5 49 6 50 7 51 8 52 9 53 10 54 11 55 12 56 13 57 14 58 15 59 16 60 17 61 18 62 19 63 20 64 21 65 22 66 23 67 24 68 25 69 26 70 27 71 28 72 29 73 30 74 31 75 32 76 33 77 34 78 35 79 36 80 37 81 38 82 39 83 40 84 41 85 42 86 43 87 44\n1 0 2 46 3 47 4 48 5 49 6 50 7 51 8 52 9 53 10 54 11 55 12 56 13 57 14 58 15 59 16 60 17 61 18 62 19 63 20 64 21 65 22 66 23 67 24 68 25 69 26 70 27 71 28 72 29 73 30 74 31 75 32 76 33 77 34 78 35 79 36 80 37 81 38 82 39 83 40 84 41 85 42 86 43 87 44 45\n4..." }, { "input": "96", "output": "0 1 49 2 50 3 51 4 52 5 53 6 54 7 55 8 56 9 57 10 58 11 59 12 60 13 61 14 62 15 63 16 64 17 65 18 66 19 67 20 68 21 69 22 70 23 71 24 72 25 73 26 74 27 75 28 76 29 77 30 78 31 79 32 80 33 81 34 82 35 83 36 84 37 85 38 86 39 87 40 88 41 89 42 90 43 91 44 92 45 93 46 94 47 95 48\n1 0 2 50 3 51 4 52 5 53 6 54 7 55 8 56 9 57 10 58 11 59 12 60 13 61 14 62 15 63 16 64 17 65 18 66 19 67 20 68 21 69 22 70 23 71 24 72 25 73 26 74 27 75 28 76 29 77 30 78 31 79 32 80 33 81 34 82 35 83 36 84 37 85 38 86 39 87 40 88 41..." }, { "input": "100", "output": "0 1 51 2 52 3 53 4 54 5 55 6 56 7 57 8 58 9 59 10 60 11 61 12 62 13 63 14 64 15 65 16 66 17 67 18 68 19 69 20 70 21 71 22 72 23 73 24 74 25 75 26 76 27 77 28 78 29 79 30 80 31 81 32 82 33 83 34 84 35 85 36 86 37 87 38 88 39 89 40 90 41 91 42 92 43 93 44 94 45 95 46 96 47 97 48 98 49 99 50\n1 0 2 52 3 53 4 54 5 55 6 56 7 57 8 58 9 59 10 60 11 61 12 62 13 63 14 64 15 65 16 66 17 67 18 68 19 69 20 70 21 71 22 72 23 73 24 74 25 75 26 76 27 77 28 78 29 79 30 80 31 81 32 82 33 83 34 84 35 85 36 86 37 87 38 88 39..." }, { "input": "128", "output": "0 1 65 2 66 3 67 4 68 5 69 6 70 7 71 8 72 9 73 10 74 11 75 12 76 13 77 14 78 15 79 16 80 17 81 18 82 19 83 20 84 21 85 22 86 23 87 24 88 25 89 26 90 27 91 28 92 29 93 30 94 31 95 32 96 33 97 34 98 35 99 36 100 37 101 38 102 39 103 40 104 41 105 42 106 43 107 44 108 45 109 46 110 47 111 48 112 49 113 50 114 51 115 52 116 53 117 54 118 55 119 56 120 57 121 58 122 59 123 60 124 61 125 62 126 63 127 64\n1 0 2 66 3 67 4 68 5 69 6 70 7 71 8 72 9 73 10 74 11 75 12 76 13 77 14 78 15 79 16 80 17 81 18 82 19 83 20 8..." }, { "input": "144", "output": "0 1 73 2 74 3 75 4 76 5 77 6 78 7 79 8 80 9 81 10 82 11 83 12 84 13 85 14 86 15 87 16 88 17 89 18 90 19 91 20 92 21 93 22 94 23 95 24 96 25 97 26 98 27 99 28 100 29 101 30 102 31 103 32 104 33 105 34 106 35 107 36 108 37 109 38 110 39 111 40 112 41 113 42 114 43 115 44 116 45 117 46 118 47 119 48 120 49 121 50 122 51 123 52 124 53 125 54 126 55 127 56 128 57 129 58 130 59 131 60 132 61 133 62 134 63 135 64 136 65 137 66 138 67 139 68 140 69 141 70 142 71 143 72\n1 0 2 74 3 75 4 76 5 77 6 78 7 79 8 80 9 81 ..." }, { "input": "250", "output": "0 1 126 2 127 3 128 4 129 5 130 6 131 7 132 8 133 9 134 10 135 11 136 12 137 13 138 14 139 15 140 16 141 17 142 18 143 19 144 20 145 21 146 22 147 23 148 24 149 25 150 26 151 27 152 28 153 29 154 30 155 31 156 32 157 33 158 34 159 35 160 36 161 37 162 38 163 39 164 40 165 41 166 42 167 43 168 44 169 45 170 46 171 47 172 48 173 49 174 50 175 51 176 52 177 53 178 54 179 55 180 56 181 57 182 58 183 59 184 60 185 61 186 62 187 63 188 64 189 65 190 66 191 67 192 68 193 69 194 70 195 71 196 72 197 73 198 74 199 ..." }, { "input": "284", "output": "0 1 143 2 144 3 145 4 146 5 147 6 148 7 149 8 150 9 151 10 152 11 153 12 154 13 155 14 156 15 157 16 158 17 159 18 160 19 161 20 162 21 163 22 164 23 165 24 166 25 167 26 168 27 169 28 170 29 171 30 172 31 173 32 174 33 175 34 176 35 177 36 178 37 179 38 180 39 181 40 182 41 183 42 184 43 185 44 186 45 187 46 188 47 189 48 190 49 191 50 192 51 193 52 194 53 195 54 196 55 197 56 198 57 199 58 200 59 201 60 202 61 203 62 204 63 205 64 206 65 207 66 208 67 209 68 210 69 211 70 212 71 213 72 214 73 215 74 216 ..." }, { "input": "332", "output": "0 1 167 2 168 3 169 4 170 5 171 6 172 7 173 8 174 9 175 10 176 11 177 12 178 13 179 14 180 15 181 16 182 17 183 18 184 19 185 20 186 21 187 22 188 23 189 24 190 25 191 26 192 27 193 28 194 29 195 30 196 31 197 32 198 33 199 34 200 35 201 36 202 37 203 38 204 39 205 40 206 41 207 42 208 43 209 44 210 45 211 46 212 47 213 48 214 49 215 50 216 51 217 52 218 53 219 54 220 55 221 56 222 57 223 58 224 59 225 60 226 61 227 62 228 63 229 64 230 65 231 66 232 67 233 68 234 69 235 70 236 71 237 72 238 73 239 74 240 ..." }, { "input": "400", "output": "0 1 201 2 202 3 203 4 204 5 205 6 206 7 207 8 208 9 209 10 210 11 211 12 212 13 213 14 214 15 215 16 216 17 217 18 218 19 219 20 220 21 221 22 222 23 223 24 224 25 225 26 226 27 227 28 228 29 229 30 230 31 231 32 232 33 233 34 234 35 235 36 236 37 237 38 238 39 239 40 240 41 241 42 242 43 243 44 244 45 245 46 246 47 247 48 248 49 249 50 250 51 251 52 252 53 253 54 254 55 255 56 256 57 257 58 258 59 259 60 260 61 261 62 262 63 263 64 264 65 265 66 266 67 267 68 268 69 269 70 270 71 271 72 272 73 273 74 274 ..." }, { "input": "600", "output": "0 1 301 2 302 3 303 4 304 5 305 6 306 7 307 8 308 9 309 10 310 11 311 12 312 13 313 14 314 15 315 16 316 17 317 18 318 19 319 20 320 21 321 22 322 23 323 24 324 25 325 26 326 27 327 28 328 29 329 30 330 31 331 32 332 33 333 34 334 35 335 36 336 37 337 38 338 39 339 40 340 41 341 42 342 43 343 44 344 45 345 46 346 47 347 48 348 49 349 50 350 51 351 52 352 53 353 54 354 55 355 56 356 57 357 58 358 59 359 60 360 61 361 62 362 63 363 64 364 65 365 66 366 67 367 68 368 69 369 70 370 71 371 72 372 73 373 74 374 ..." }, { "input": "700", "output": "0 1 351 2 352 3 353 4 354 5 355 6 356 7 357 8 358 9 359 10 360 11 361 12 362 13 363 14 364 15 365 16 366 17 367 18 368 19 369 20 370 21 371 22 372 23 373 24 374 25 375 26 376 27 377 28 378 29 379 30 380 31 381 32 382 33 383 34 384 35 385 36 386 37 387 38 388 39 389 40 390 41 391 42 392 43 393 44 394 45 395 46 396 47 397 48 398 49 399 50 400 51 401 52 402 53 403 54 404 55 405 56 406 57 407 58 408 59 409 60 410 61 411 62 412 63 413 64 414 65 415 66 416 67 417 68 418 69 419 70 420 71 421 72 422 73 423 74 424 ..." }, { "input": "780", "output": "0 1 391 2 392 3 393 4 394 5 395 6 396 7 397 8 398 9 399 10 400 11 401 12 402 13 403 14 404 15 405 16 406 17 407 18 408 19 409 20 410 21 411 22 412 23 413 24 414 25 415 26 416 27 417 28 418 29 419 30 420 31 421 32 422 33 423 34 424 35 425 36 426 37 427 38 428 39 429 40 430 41 431 42 432 43 433 44 434 45 435 46 436 47 437 48 438 49 439 50 440 51 441 52 442 53 443 54 444 55 445 56 446 57 447 58 448 59 449 60 450 61 451 62 452 63 453 64 454 65 455 66 456 67 457 68 458 69 459 70 460 71 461 72 462 73 463 74 464 ..." }, { "input": "846", "output": "0 1 424 2 425 3 426 4 427 5 428 6 429 7 430 8 431 9 432 10 433 11 434 12 435 13 436 14 437 15 438 16 439 17 440 18 441 19 442 20 443 21 444 22 445 23 446 24 447 25 448 26 449 27 450 28 451 29 452 30 453 31 454 32 455 33 456 34 457 35 458 36 459 37 460 38 461 39 462 40 463 41 464 42 465 43 466 44 467 45 468 46 469 47 470 48 471 49 472 50 473 51 474 52 475 53 476 54 477 55 478 56 479 57 480 58 481 59 482 60 483 61 484 62 485 63 486 64 487 65 488 66 489 67 490 68 491 69 492 70 493 71 494 72 495 73 496 74 497 ..." }, { "input": "902", "output": "0 1 452 2 453 3 454 4 455 5 456 6 457 7 458 8 459 9 460 10 461 11 462 12 463 13 464 14 465 15 466 16 467 17 468 18 469 19 470 20 471 21 472 22 473 23 474 24 475 25 476 26 477 27 478 28 479 29 480 30 481 31 482 32 483 33 484 34 485 35 486 36 487 37 488 38 489 39 490 40 491 41 492 42 493 43 494 44 495 45 496 46 497 47 498 48 499 49 500 50 501 51 502 52 503 53 504 54 505 55 506 56 507 57 508 58 509 59 510 60 511 61 512 62 513 63 514 64 515 65 516 66 517 67 518 68 519 69 520 70 521 71 522 72 523 73 524 74 525 ..." }, { "input": "1000", "output": "0 1 501 2 502 3 503 4 504 5 505 6 506 7 507 8 508 9 509 10 510 11 511 12 512 13 513 14 514 15 515 16 516 17 517 18 518 19 519 20 520 21 521 22 522 23 523 24 524 25 525 26 526 27 527 28 528 29 529 30 530 31 531 32 532 33 533 34 534 35 535 36 536 37 537 38 538 39 539 40 540 41 541 42 542 43 543 44 544 45 545 46 546 47 547 48 548 49 549 50 550 51 551 52 552 53 553 54 554 55 555 56 556 57 557 58 558 59 559 60 560 61 561 62 562 63 563 64 564 65 565 66 566 67 567 68 568 69 569 70 570 71 571 72 572 73 573 74 574 ..." } ]
2,000
22,118,400
0
20,163
235
Let's Play Osu!
[ "dp", "math", "probabilities" ]
null
null
You're playing a game called Osu! Here's a simplified version of it. There are *n* clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence of *n* characters "O" and "X". Using the play sequence you can calculate the score for the play as follows: for every maximal consecutive "O"s block, add the square of its length (the number of characters "O") to the score. For example, if your play can be encoded as "OOXOOOXXOO", then there's three maximal consecutive "O"s block "OO", "OOO", "OO", so your score will be 22<=+<=32<=+<=22<==<=17. If there are no correct clicks in a play then the score for the play equals to 0. You know that the probability to click the *i*-th (1<=≤<=*i*<=≤<=*n*) click correctly is *p**i*. In other words, the *i*-th character in the play sequence has *p**i* probability to be "O", 1<=-<=*p**i* to be "X". You task is to calculate the expected score for your play.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of clicks. The second line contains *n* space-separated real numbers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=1). There will be at most six digits after the decimal point in the given *p**i*.
Print a single real number — the expected score for your play. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
[ "3\n0.5 0.5 0.5\n", "4\n0.7 0.2 0.1 0.9\n", "5\n1 1 1 1 1\n" ]
[ "2.750000000000000\n", "2.489200000000000\n", "25.000000000000000\n" ]
For the first example. There are 8 possible outcomes. Each has a probability of 0.125. - "OOO"  →  3<sup class="upper-index">2</sup> = 9; - "OOX"  →  2<sup class="upper-index">2</sup> = 4; - "OXO"  →  1<sup class="upper-index">2</sup> + 1<sup class="upper-index">2</sup> = 2; - "OXX"  →  1<sup class="upper-index">2</sup> = 1; - "XOO"  →  2<sup class="upper-index">2</sup> = 4; - "XOX"  →  1<sup class="upper-index">2</sup> = 1; - "XXO"  →  1<sup class="upper-index">2</sup> = 1; - "XXX"  →  0. So the expected score is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9aa477286058d4dd02d6f78cad11a658e4f37440.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "3\n0.5 0.5 0.5", "output": "2.750000000000000" }, { "input": "4\n0.7 0.2 0.1 0.9", "output": "2.489200000000000" }, { "input": "5\n1 1 1 1 1", "output": "25.000000000000000" }, { "input": "10\n0.684846 0.156794 0.153696 0.714526 0.281868 0.628256 0.745339 0.123854 0.748936 0.856333", "output": "10.721778814471227" }, { "input": "10\n0.684488 0.834971 0.834886 0.643646 0.162710 0.119851 0.659401 0.743950 0.220986 0.839665", "output": "15.401334613504345" }, { "input": "10\n0.684416 0.170607 0.491124 0.469470 0.458879 0.658170 0.322214 0.707969 0.275396 0.836331", "output": "11.404416796704293" }, { "input": "10\n0.684631 0.563700 0.722410 0.191998 0.370373 0.643213 0.533776 0.815911 0.112166 0.846332", "output": "12.888929008957161" }, { "input": "10\n0.684559 0.699336 0.378648 0.817822 0.666542 0.381532 0.196589 0.779930 0.166576 0.842998", "output": "14.036752909261951" }, { "input": "10\n0.999453 0.999188 0.998398 0.999609 0.999113 0.999426 0.998026 0.999244 0.998842 0.999807", "output": "99.590738622894690" }, { "input": "10\n0.000733 0.000769 0.000772 0.000595 0.000930 0.000395 0.000596 0.000584 0.000496 0.000905", "output": "0.006782723279203" }, { "input": "30\n0.684344 0.306242 0.147362 0.295294 0.755047 0.396489 0.785026 0.671988 0.329806 0.832998 0.106621 0.452498 0.125067 0.838169 0.869683 0.740625 0.449522 0.751800 0.272185 0.865612 0.272859 0.416162 0.339155 0.478441 0.401937 0.626148 0.305498 0.716523 0.734322 0.751335", "output": "44.576745047411691" }, { "input": "30\n0.684273 0.441878 0.603600 0.121118 0.251216 0.134808 0.447839 0.636007 0.384215 0.829664 0.204397 0.627395 0.243031 0.424765 0.525065 0.585464 0.893844 0.377080 0.246110 0.356372 0.836239 0.670558 0.546182 0.310427 0.343287 0.868653 0.269521 0.432699 0.288850 0.848816", "output": "36.478162706163317" }, { "input": "30\n0.683914 0.320055 0.484789 0.850238 0.132058 0.426403 0.361901 0.456102 0.656265 0.812996 0.693279 0.701878 0.832853 0.757747 0.401974 0.609660 0.715452 0.103482 0.115733 0.210174 0.453140 0.342538 0.781317 0.270359 0.850037 0.481183 0.889637 0.613578 0.461492 0.536221", "output": "53.227679791398110" }, { "input": "30\n0.683843 0.455691 0.141027 0.676062 0.428227 0.164722 0.824714 0.420121 0.710675 0.809662 0.791055 0.876775 0.150817 0.344344 0.857356 0.454499 0.359774 0.528762 0.889658 0.500934 0.216520 0.596934 0.188344 0.102346 0.791387 0.723689 0.853660 0.329754 0.816020 0.633702", "output": "49.054872575308515" }, { "input": "30\n0.684058 0.848784 0.372313 0.398590 0.339721 0.149765 0.236276 0.528064 0.547445 0.819663 0.497726 0.352085 0.596924 0.784554 0.291210 0.119982 0.626809 0.852921 0.167884 0.428653 0.126380 0.633746 0.367263 0.606386 0.167337 0.796171 0.161591 0.381226 0.552435 0.341259", "output": "33.125615383310461" }, { "input": "30\n0.999453 0.998210 0.999812 0.998309 0.999333 0.999463 0.999490 0.998975 0.999248 0.999782 0.999233 0.999062 0.999530 0.998674 0.999608 0.999654 0.998426 0.998941 0.998104 0.999541 0.999467 0.999961 0.999180 0.998842 0.998022 0.998345 0.998064 0.999984 0.998017 0.998843", "output": "891.219052952586820" }, { "input": "30\n0.000735 0.000533 0.000518 0.000044 0.000677 0.000571 0.000138 0.000707 0.000793 0.000018 0.000326 0.000635 0.000789 0.000298 0.000445 0.000077 0.000226 0.000128 0.000933 0.000961 0.000726 0.000405 0.000610 0.000102 0.000990 0.000989 0.000254 0.000580 0.000053 0.000142", "output": "0.014416714297575" } ]
374
9,318,400
3
20,164
960
Full Binary Tree Queries
[ "brute force", "implementation", "trees" ]
null
null
You have a full binary tree having infinite levels. Each node has an initial value. If a node has value *x*, then its left child has value 2·*x* and its right child has value 2·*x*<=+<=1. The value of the root is 1. You need to answer *Q* queries. There are 3 types of queries: 1. Cyclically shift the values of all nodes on the same level as node with value *X* by *K* units. (The values/nodes of any other level are not affected).1. Cyclically shift the nodes on the same level as node with value *X* by *K* units. (The subtrees of these nodes will move along with them).1. Print the value of every node encountered on the simple path from the node with value *X* to the root. Positive *K* implies right cyclic shift and negative *K* implies left cyclic shift. It is guaranteed that atleast one type 3 query is present.
The first line contains a single integer *Q* (1<=≤<=*Q*<=≤<=105). Then *Q* queries follow, one per line: - Queries of type 1 and 2 have the following format: *T* *X* *K* (1<=≤<=*T*<=≤<=2; 1<=≤<=*X*<=≤<=1018; 0<=≤<=|*K*|<=≤<=1018), where *T* is type of the query.- Queries of type 3 have the following format: 3 *X* (1<=≤<=*X*<=≤<=1018).
For each query of type 3, print the values of all nodes encountered in descending order.
[ "5\n3 12\n1 2 1\n3 12\n2 4 -1\n3 8\n", "5\n3 14\n1 5 -3\n3 14\n1 3 1\n3 14\n" ]
[ "12 6 3 1 \n12 6 2 1 \n8 4 2 1 \n", "14 7 3 1 \n14 6 3 1 \n14 6 2 1 \n" ]
Following are the images of the first 4 levels of the tree in the first test case: Original: After query 1 2 1: After query 2 4 -1:
[ { "input": "5\n3 12\n1 2 1\n3 12\n2 4 -1\n3 8", "output": "12 6 3 1 \n12 6 2 1 \n8 4 2 1 " }, { "input": "5\n3 14\n1 5 -3\n3 14\n1 3 1\n3 14", "output": "14 7 3 1 \n14 6 3 1 \n14 6 2 1 " }, { "input": "6\n3 1\n2 1 0\n3 10\n2 1 -4\n3 10\n2 10 -5", "output": "1 \n10 5 2 1 \n10 5 2 1 " }, { "input": "3\n3 1000000000000000000\n1 12345 13\n3 1000000000000000000", "output": "1000000000000000000 500000000000000000 250000000000000000 125000000000000000 62500000000000000 31250000000000000 15625000000000000 7812500000000000 3906250000000000 1953125000000000 976562500000000 488281250000000 244140625000000 122070312500000 61035156250000 30517578125000 15258789062500 7629394531250 3814697265625 1907348632812 953674316406 476837158203 238418579101 119209289550 59604644775 29802322387 14901161193 7450580596 3725290298 1862645149 931322574 465661287 232830643 116415321 58207660 29103830..." }, { "input": "10\n3 999\n3 822\n2 339 -75\n2 924 -56\n3 863\n3 311\n1 269 84\n2 604 9\n2 788 -98\n1 233 60", "output": "999 499 249 124 62 31 15 7 3 1 \n822 411 205 102 51 25 12 6 3 1 \n863 403 164 82 41 20 10 5 2 1 \n311 246 123 61 30 15 7 3 1 " }, { "input": "10\n2 64324170 41321444786551040\n2 58204973 -73473234074970084\n1 56906279 -33102897753191948\n1 50660486 43066512304447265\n2 5614300 55244615832513844\n3 63044213\n3 27109227\n3 65485686\n3 36441490\n1 59699160 -19214308468046677", "output": "63044213 19585619 9792809 4896404 4125156 2062578 1031289 515644 257822 128911 64455 32227 16113 8056 4028 2014 1007 503 251 125 62 31 15 7 3 1 \n27109227 13554613 6777306 2968455 1484227 742113 371056 185528 92764 46382 23191 11595 5797 2898 1449 724 362 181 90 45 22 11 5 2 1 \n65485686 20806355 10403177 5201588 2180596 1090298 545149 272574 136287 68143 34071 17035 8517 4258 2129 1064 532 266 133 66 33 16 8 4 2 1 \n36441490 23061473 11530736 5765368 2462486 1231243 615621 307810 153905 76952 38476 19238 ..." }, { "input": "2\n2 1 100000000000000000\n3 1000000000000000", "output": "1000000000000000 500000000000000 250000000000000 125000000000000 62500000000000 31250000000000 15625000000000 7812500000000 3906250000000 1953125000000 976562500000 488281250000 244140625000 122070312500 61035156250 30517578125 15258789062 7629394531 3814697265 1907348632 953674316 476837158 238418579 119209289 59604644 29802322 14901161 7450580 3725290 1862645 931322 465661 232830 116415 58207 29103 14551 7275 3637 1818 909 454 227 113 56 28 14 7 3 1 " } ]
0
0
-1
20,204
0
none
[ "none" ]
null
null
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library. Some long and uninteresting story was removed... The alphabet of Bookland is so large that its letters are denoted by positive integers. Each letter can be small or large, the large version of a letter *x* is denoted by *x*'. BSCII encoding, which is used everywhere in Bookland, is made in that way so that large letters are presented in the order of the numbers they are denoted by, and small letters are presented in the order of the numbers they are denoted by, but all large letters are before all small letters. For example, the following conditions hold: 2<=&lt;<=3, 2'<=&lt;<=3', 3'<=&lt;<=2. A word *x*1,<=*x*2,<=...,<=*x**a* is not lexicographically greater than *y*1,<=*y*2,<=...,<=*y**b* if one of the two following conditions holds: - *a*<=≤<=*b* and *x*1<==<=*y*1,<=...,<=*x**a*<==<=*y**a*, i.e. the first word is the prefix of the second word; - there is a position 1<=≤<=*j*<=≤<=*min*(*a*,<=*b*), such that *x*1<==<=*y*1,<=...,<=*x**j*<=-<=1<==<=*y**j*<=-<=1 and *x**j*<=&lt;<=*y**j*, i.e. at the first position where the words differ the first word has a smaller letter than the second word has. For example, the word "3' 7 5" is before the word "2 4' 6" in lexicographical order. It is said that sequence of words is in lexicographical order if each word is not lexicographically greater than the next word in the sequence. Denis has a sequence of words consisting of small letters only. He wants to change some letters to large (let's call this process a capitalization) in such a way that the sequence of words is in lexicographical order. However, he soon realized that for some reason he can't change a single letter in a single word. He only can choose a letter and change all of its occurrences in all words to large letters. He can perform this operation any number of times with arbitrary letters of Bookland's alphabet. Help Denis to choose which letters he needs to capitalize (make large) in order to make the sequence of words lexicographically ordered, or determine that it is impossible. Note that some words can be equal.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of words and the number of letters in Bookland's alphabet, respectively. The letters of Bookland's alphabet are denoted by integers from 1 to *m*. Each of the next *n* lines contains a description of one word in format *l**i*,<=*s**i*,<=1,<=*s**i*,<=2,<=...,<=*s**i*,<=*l**i* (1<=≤<=*l**i*<=≤<=100<=000, 1<=≤<=*s**i*,<=*j*<=≤<=*m*), where *l**i* is the length of the word, and *s**i*,<=*j* is the sequence of letters in the word. The words are given in the order Denis has them in the sequence. It is guaranteed that the total length of all words is not greater than 100<=000.
In the first line print "Yes" (without quotes), if it is possible to capitalize some set of letters in such a way that the sequence of words becomes lexicographically ordered. Otherwise, print "No" (without quotes). If the required is possible, in the second line print *k* — the number of letters Denis has to capitalize (make large), and in the third line print *k* distinct integers — these letters. Note that you don't need to minimize the value *k*. You can print the letters in any order. If there are multiple answers, print any of them.
[ "4 3\n1 2\n1 1\n3 1 3 2\n2 1 1\n", "6 5\n2 1 2\n2 1 2\n3 1 2 3\n2 1 5\n2 4 4\n2 4 4\n", "4 3\n4 3 2 2 1\n3 1 1 3\n3 2 3 3\n2 3 1\n" ]
[ "Yes\n2\n2 3 ", "Yes\n0\n", "No\n" ]
In the first example after Denis makes letters 2 and 3 large, the sequence looks like the following: - 2' - 1 - 1 3' 2' - 1 1 The condition 2' &lt; 1 holds, so the first word is not lexicographically larger than the second word. The second word is the prefix of the third word, so the are in lexicographical order. As the first letters of the third and the fourth words are the same, and 3' &lt; 1, then the third word is not lexicographically larger than the fourth word. In the second example the words are in lexicographical order from the beginning, so Denis can do nothing. In the third example there is no set of letters such that if Denis capitalizes them, the sequence becomes lexicographically ordered.
[ { "input": "4 3\n1 2\n1 1\n3 1 3 2\n2 1 1", "output": "Yes\n2\n2 3 " }, { "input": "6 5\n2 1 2\n2 1 2\n3 1 2 3\n2 1 5\n2 4 4\n2 4 4", "output": "Yes\n0" }, { "input": "4 3\n4 3 2 2 1\n3 1 1 3\n3 2 3 3\n2 3 1", "output": "No" }, { "input": "4 4\n3 3 4 1\n4 3 4 2 2\n4 2 1 2 3\n3 4 2 2", "output": "Yes\n1\n3 " }, { "input": "3 5\n2 1 2\n2 1 5\n2 4 4", "output": "Yes\n0" }, { "input": "2 1\n10 1 1 1 1 1 1 1 1 1 1\n25 1 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\n0" }, { "input": "10 3\n2 3 2\n1 3\n3 1 3 3\n1 2\n2 1 2\n3 2 2 3\n3 3 2 1\n1 2\n2 1 2\n4 1 2 2 3", "output": "No" }, { "input": "10 3\n2 3 1\n1 2\n1 1\n1 1\n2 3 1\n1 2\n2 3 1\n1 1\n1 3\n2 3 2", "output": "No" }, { "input": "10 10\n8 1 1 6 10 2 2 9 7\n6 2 7 1 9 5 10\n1 5\n7 3 6 9 6 3 7 6\n10 3 9 10 3 6 7 10 6 9 6\n10 4 4 9 8 2 10 3 6 2 9\n8 4 8 6 4 6 4 8 6\n2 7 5\n6 8 6 2 1 9 8\n3 10 2 10", "output": "Yes\n3\n1 2 5 " }, { "input": "10 10\n8 2 1 3 2 10 5 4 1\n6 2 1 7 5 7 1\n9 2 1 7 5 8 2 8 2 9\n3 2 1 9\n7 2 9 2 2 10 1 7\n10 2 9 2 2 10 1 7 4 1 10\n5 3 5 2 4 4\n7 3 5 9 6 6 5 4\n2 5 6\n6 5 9 8 7 6 9", "output": "Yes\n0" }, { "input": "10 4\n2 1 4\n2 1 4\n9 1 4 1 2 3 1 4 4 2\n1 4\n4 4 1 4 3\n7 4 4 4 4 1 4 2\n4 4 2 4 3\n4 2 4 4 4\n1 3\n9 3 3 3 4 2 3 3 2 4", "output": "Yes\n2\n1 4 " }, { "input": "3 3\n1 3\n1 2\n1 1", "output": "No" }, { "input": "2 2\n2 1 2\n1 1", "output": "No" }, { "input": "2 3\n3 1 2 3\n2 1 2", "output": "No" }, { "input": "2 100000\n5 1 2 3 1 5\n3 1 2 3", "output": "No" }, { "input": "4 5\n2 1 5\n2 1 4\n2 2 3\n2 2 5", "output": "Yes\n2\n3 5 " }, { "input": "2 100\n3 1 2 3\n1 1", "output": "No" }, { "input": "5 5\n1 5\n1 4\n1 3\n1 2\n1 1", "output": "No" }, { "input": "2 1\n2 1 1\n1 1", "output": "No" }, { "input": "2 3\n2 1 3\n1 1", "output": "No" }, { "input": "6 100\n1 3\n1 5\n2 7 5\n2 7 2\n3 7 7 2\n3 7 7 3", "output": "No" } ]
30
0
0
20,232
113
Grammar Lessons
[ "implementation", "strings" ]
A. Grammar Lessons
5
256
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: - There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. - There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. - Masculine adjectives end with -lios, and feminine adjectives end with -liala. - Masculine nouns end with -etr, and feminime nouns end with -etra. - Masculine verbs end with -initis, and feminime verbs end with -inites. - Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. - It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. - There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. - A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: - Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. - All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.
The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.
If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).
[ "petr\n", "etis atis animatis etis atis amatis\n", "nataliala kataliala vetra feinites\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
[ { "input": "petr", "output": "YES" }, { "input": "etis atis animatis etis atis amatis", "output": "NO" }, { "input": "nataliala kataliala vetra feinites", "output": "YES" }, { "input": "qweasbvflios", "output": "YES" }, { "input": "lios lios petr initis qwe", "output": "NO" }, { "input": "lios initis", "output": "NO" }, { "input": "petr initis lios", "output": "NO" }, { "input": "petra petra petra", "output": "NO" }, { "input": "in", "output": "NO" }, { "input": "liala petra initis", "output": "NO" }, { "input": "liala petra inites", "output": "YES" }, { "input": "liala initis", "output": "NO" }, { "input": "liala petra petr inites", "output": "NO" }, { "input": "liala petr inites", "output": "NO" }, { "input": "llilitos", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzentsphxqhdungbylhnikwviuhccbstghhxlmvcjznnkjqkugsdysjbedwpmsmxmgxlrlxctnebtbwrsvgjktkrosffwymovxvsgfmmqwfflpvbumozikroxrdgwjrnstngstxbiyyuxehrhviteptedlmyetr", "output": "YES" }, { "input": "i i i i i i i i i i i i i i i a a a a a a v v v v v v v v v v v", "output": "NO" }, { "input": "fbvzqonvdlqdanwliolaqfj sbauorbinites xkbfnfinitespjy phbexglblzpobtqpisyijycmtliola aosinites lbpjiwcjoqyuhglthloiniteswb mjtxhoofohzzgefvhsywojcuxtetxmojrlktodhbgyrkeejgjzxkzyvrxwmyaqkeoqnvusnlrsfffrzeoqjdfumolhksqkrtzwhnforgpenziokrxlnhcapbbupctlmuetrani pigxerwetupjbkvlmgnjhdfjliolanz tqhaidxbqmdaeincxjuliola", "output": "NO" }, { "input": "mfrmqetr", "output": "YES" }, { "input": "hnwvfllholxfialiola cknjtxpliola daliola gqfapnhmmworliola qhetra qrisbexsrefcwzoxqwxrevinites wwldqkqhvrgwplqinites nqdpoauitczttxoinites fgbmdfpxkhahkinites", "output": "NO" }, { "input": "kcymcpgqdxkudadewddualeemhixhsdazudnjdmuvxvrlrbrpsdpxpagmrogplltnifrtomdtahxwadguvetxaqkvsvnoyhowirnluhmyewzapirnpfdisvhtbenxmfezahqoflkjrfqjubwdfktnpeirodwubftzlcczzavfiooihzvnqincndisudihvbcaxptrwovekmhiiwsgzgbxydvuldlnktxtltrlajjzietkxbnhetra", "output": "YES" }, { "input": "dosiydnwxemojaavfdvlwsyhzqywqjutovygtlcleklhybczhjqfzxwdmlwqwcqqyfjkzhsizlmdarrfronxqkcknwpkvhdlgatdyjisjoopvngpjggldxjfxaauoxmqirkuphydyweoixftstlozaoywnxgriscudwlokncbmaebpssccmmmfjennyjaryqlzjknnklqketra", "output": "YES" }, { "input": "etretra linites", "output": "YES" }, { "input": "petretra petr", "output": "NO" }, { "input": "lialalios petraveryfunnypetr", "output": "YES" }, { "input": "petropetrapetr petra", "output": "NO" }, { "input": "lios petrnonono", "output": "NO" }, { "input": "lios petr initisandinitisandliala petrainitis", "output": "NO" }, { "input": "petro", "output": "NO" }, { "input": "petr initesinitis", "output": "YES" }, { "input": "lios initis", "output": "NO" }, { "input": "liala initespetra", "output": "YES" }, { "input": "lios petrapetr", "output": "YES" }, { "input": "initis petr", "output": "NO" }, { "input": "lioslialapetrpetrainitisinitesliosliala initesinitislioslialapetrpetrainitisinitetra", "output": "YES" }, { "input": "veryfunnyprefixpetr", "output": "YES" }, { "input": "veryfunnyprefixpetra", "output": "YES" }, { "input": "veryfunnyprefixinitis", "output": "YES" }, { "input": "veryfunnyprefixinites", "output": "YES" }, { "input": "veryfunnyprefixliala", "output": "YES" }, { "input": "veryfunnyprefixlios", "output": "YES" }, { "input": "veryfunnyprefixlialas", "output": "NO" }, { "input": "veryfunnyprefixliala veryfunnyprefixpetretra", "output": "YES" }, { "input": "veryfunnyprefixlios veryfunnyprefixinitisetr", "output": "YES" }, { "input": "veryfunnyprefixlios aabbinitis", "output": "NO" }, { "input": "veryfunnyprefixlios inites", "output": "NO" }, { "input": "lios petr initis", "output": "YES" }, { "input": "liala etra inites", "output": "YES" }, { "input": "lios", "output": "YES" }, { "input": "liala", "output": "YES" }, { "input": "initis", "output": "YES" }, { "input": "inites", "output": "YES" }, { "input": "tes", "output": "NO" }, { "input": "tr", "output": "NO" }, { "input": "a", "output": "NO" }, { "input": "lios lios", "output": "NO" }, { "input": "lios", "output": "YES" }, { "input": "liala", "output": "YES" }, { "input": "petr", "output": "YES" }, { "input": "petra", "output": "YES" }, { "input": "pinitis", "output": "YES" }, { "input": "pinites", "output": "YES" }, { "input": "plios pliala", "output": "NO" }, { "input": "plios petr", "output": "YES" }, { "input": "plios petra", "output": "NO" }, { "input": "plios plios", "output": "NO" }, { "input": "plios initis", "output": "NO" }, { "input": "plios pinites", "output": "NO" }, { "input": "pliala plios", "output": "NO" }, { "input": "pliala ppliala", "output": "NO" }, { "input": "pliala petr", "output": "NO" }, { "input": "pliala petra", "output": "YES" }, { "input": "pliala pinitis", "output": "NO" }, { "input": "pliala pinites", "output": "NO" }, { "input": "petr plios", "output": "NO" }, { "input": "petr pliala", "output": "NO" }, { "input": "petr petr", "output": "NO" }, { "input": "petr petra", "output": "NO" }, { "input": "petr pinitis", "output": "YES" }, { "input": "petr pinites", "output": "NO" }, { "input": "petra lios", "output": "NO" }, { "input": "petra liala", "output": "NO" }, { "input": "petra petr", "output": "NO" }, { "input": "petra petra", "output": "NO" }, { "input": "petra initis", "output": "NO" }, { "input": "petra inites", "output": "YES" }, { "input": "initis lios", "output": "NO" }, { "input": "initis liala", "output": "NO" }, { "input": "initis petr", "output": "NO" }, { "input": "initis petra", "output": "NO" }, { "input": "initis initis", "output": "NO" }, { "input": "initis inites", "output": "NO" }, { "input": "inites lios", "output": "NO" }, { "input": "inites liala", "output": "NO" }, { "input": "inites petr", "output": "NO" }, { "input": "inites petra", "output": "NO" }, { "input": "inites initis", "output": "NO" }, { "input": "inites inites", "output": "NO" }, { "input": "lios lios lios", "output": "NO" }, { "input": "lios lios liala", "output": "NO" }, { "input": "lios lios etr", "output": "YES" }, { "input": "lios lios etra", "output": "NO" }, { "input": "lios lios initis", "output": "NO" }, { "input": "lios lios inites", "output": "NO" }, { "input": "lios liala lios", "output": "NO" }, { "input": "lios liala liala", "output": "NO" }, { "input": "lios liala etr", "output": "NO" }, { "input": "lios liala etra", "output": "NO" }, { "input": "lios liala initis", "output": "NO" }, { "input": "lios liala inites", "output": "NO" }, { "input": "lios etr lios", "output": "NO" }, { "input": "lios etr liala", "output": "NO" }, { "input": "lios etr etr", "output": "NO" }, { "input": "lios etr etra", "output": "NO" }, { "input": "lios etr initis", "output": "YES" }, { "input": "lios etr inites", "output": "NO" }, { "input": "lios etra lios", "output": "NO" }, { "input": "lios etra liala", "output": "NO" }, { "input": "lios etra etr", "output": "NO" }, { "input": "lios etra etra", "output": "NO" }, { "input": "lios etra initis", "output": "NO" }, { "input": "lios etra inites", "output": "NO" }, { "input": "lios initis lios", "output": "NO" }, { "input": "lios initis liala", "output": "NO" }, { "input": "lios initis etr", "output": "NO" }, { "input": "lios initis etra", "output": "NO" }, { "input": "lios initis initis", "output": "NO" }, { "input": "lios initis inites", "output": "NO" }, { "input": "lios inites lios", "output": "NO" }, { "input": "lios inites liala", "output": "NO" }, { "input": "lios inites etr", "output": "NO" }, { "input": "lios inites etra", "output": "NO" }, { "input": "lios inites initis", "output": "NO" }, { "input": "lios inites inites", "output": "NO" }, { "input": "liala lios lios", "output": "NO" }, { "input": "liala lios liala", "output": "NO" }, { "input": "liala lios etr", "output": "NO" }, { "input": "liala lios etra", "output": "NO" }, { "input": "liala lios initis", "output": "NO" }, { "input": "liala lios inites", "output": "NO" }, { "input": "liala liala lios", "output": "NO" }, { "input": "liala liala liala", "output": "NO" }, { "input": "liala liala etr", "output": "NO" }, { "input": "liala liala etra", "output": "YES" }, { "input": "liala liala initis", "output": "NO" }, { "input": "liala liala inites", "output": "NO" }, { "input": "liala etr lios", "output": "NO" }, { "input": "liala etr liala", "output": "NO" }, { "input": "liala etr etr", "output": "NO" }, { "input": "liala etr etra", "output": "NO" }, { "input": "liala etr initis", "output": "NO" }, { "input": "liala etr inites", "output": "NO" }, { "input": "liala etra lios", "output": "NO" }, { "input": "liala etra liala", "output": "NO" }, { "input": "liala etra etr", "output": "NO" }, { "input": "liala etra etra", "output": "NO" }, { "input": "liala etra initis", "output": "NO" }, { "input": "liala etra inites", "output": "YES" }, { "input": "liala initis lios", "output": "NO" }, { "input": "liala initis liala", "output": "NO" }, { "input": "liala initis etr", "output": "NO" }, { "input": "liala initis etra", "output": "NO" }, { "input": "liala initis initis", "output": "NO" }, { "input": "liala initis inites", "output": "NO" }, { "input": "liala inites lios", "output": "NO" }, { "input": "liala inites liala", "output": "NO" }, { "input": "liala inites etr", "output": "NO" }, { "input": "liala inites etra", "output": "NO" }, { "input": "liala inites initis", "output": "NO" }, { "input": "liala inites inites", "output": "NO" }, { "input": "etr lios lios", "output": "NO" }, { "input": "etr lios liala", "output": "NO" }, { "input": "etr lios etr", "output": "NO" }, { "input": "etr lios etra", "output": "NO" }, { "input": "etr lios initis", "output": "NO" }, { "input": "etr lios inites", "output": "NO" }, { "input": "etr liala lios", "output": "NO" }, { "input": "etr liala liala", "output": "NO" }, { "input": "etr liala etr", "output": "NO" }, { "input": "etr liala etra", "output": "NO" }, { "input": "etr liala initis", "output": "NO" }, { "input": "etr liala inites", "output": "NO" }, { "input": "etr etr lios", "output": "NO" }, { "input": "etr etr liala", "output": "NO" }, { "input": "etr etr etr", "output": "NO" }, { "input": "etr etr etra", "output": "NO" }, { "input": "etr etr initis", "output": "NO" }, { "input": "etr etr inites", "output": "NO" }, { "input": "etr etra lios", "output": "NO" }, { "input": "etr etra liala", "output": "NO" }, { "input": "etr etra etr", "output": "NO" }, { "input": "etr etra etra", "output": "NO" }, { "input": "etr etra initis", "output": "NO" }, { "input": "etr etra inites", "output": "NO" }, { "input": "etr initis lios", "output": "NO" }, { "input": "etr initis liala", "output": "NO" }, { "input": "etr initis etr", "output": "NO" }, { "input": "etr initis etra", "output": "NO" }, { "input": "etr initis initis", "output": "YES" }, { "input": "etr initis inites", "output": "NO" }, { "input": "etr inites lios", "output": "NO" }, { "input": "etr inites liala", "output": "NO" }, { "input": "etr inites etr", "output": "NO" }, { "input": "etr inites etra", "output": "NO" }, { "input": "etr inites initis", "output": "NO" }, { "input": "etr inites inites", "output": "NO" }, { "input": "etra lios lios", "output": "NO" }, { "input": "etra lios liala", "output": "NO" }, { "input": "etra lios etr", "output": "NO" }, { "input": "etra lios etra", "output": "NO" }, { "input": "etra lios initis", "output": "NO" }, { "input": "etra lios inites", "output": "NO" }, { "input": "etra liala lios", "output": "NO" }, { "input": "etra liala liala", "output": "NO" }, { "input": "etra liala etr", "output": "NO" }, { "input": "etra liala etra", "output": "NO" }, { "input": "etra liala initis", "output": "NO" }, { "input": "etra liala inites", "output": "NO" }, { "input": "etra etr lios", "output": "NO" }, { "input": "etra etr liala", "output": "NO" }, { "input": "etra etr etr", "output": "NO" }, { "input": "etra etr etra", "output": "NO" }, { "input": "etra etr initis", "output": "NO" }, { "input": "etra etr inites", "output": "NO" }, { "input": "etra etra lios", "output": "NO" }, { "input": "etra etra liala", "output": "NO" }, { "input": "etra etra etr", "output": "NO" }, { "input": "etra etra etra", "output": "NO" }, { "input": "etra etra initis", "output": "NO" }, { "input": "etra etra inites", "output": "NO" }, { "input": "etra initis lios", "output": "NO" }, { "input": "etra initis liala", "output": "NO" }, { "input": "etra initis etr", "output": "NO" }, { "input": "etra initis etra", "output": "NO" }, { "input": "etra initis initis", "output": "NO" }, { "input": "etra initis inites", "output": "NO" }, { "input": "etra inites lios", "output": "NO" }, { "input": "etra inites liala", "output": "NO" }, { "input": "etra inites etr", "output": "NO" }, { "input": "etra inites etra", "output": "NO" }, { "input": "etra inites initis", "output": "NO" }, { "input": "etra inites inites", "output": "YES" }, { "input": "initis lios lios", "output": "NO" }, { "input": "initis lios liala", "output": "NO" }, { "input": "initis lios etr", "output": "NO" }, { "input": "initis lios etra", "output": "NO" }, { "input": "initis lios initis", "output": "NO" }, { "input": "initis lios inites", "output": "NO" }, { "input": "initis liala lios", "output": "NO" }, { "input": "initis liala liala", "output": "NO" }, { "input": "initis liala etr", "output": "NO" }, { "input": "initis liala etra", "output": "NO" }, { "input": "initis liala initis", "output": "NO" }, { "input": "initis liala inites", "output": "NO" }, { "input": "initis etr lios", "output": "NO" }, { "input": "initis etr liala", "output": "NO" }, { "input": "initis etr etr", "output": "NO" }, { "input": "initis etr etra", "output": "NO" }, { "input": "initis etr initis", "output": "NO" }, { "input": "initis etr inites", "output": "NO" }, { "input": "initis etra lios", "output": "NO" }, { "input": "initis etra liala", "output": "NO" }, { "input": "initis etra etr", "output": "NO" }, { "input": "initis etra etra", "output": "NO" }, { "input": "initis etra initis", "output": "NO" }, { "input": "initis etra inites", "output": "NO" }, { "input": "initis initis lios", "output": "NO" }, { "input": "initis initis liala", "output": "NO" }, { "input": "initis initis etr", "output": "NO" }, { "input": "initis initis etra", "output": "NO" }, { "input": "initis initis initis", "output": "NO" }, { "input": "initis initis inites", "output": "NO" }, { "input": "initis inites lios", "output": "NO" }, { "input": "initis inites liala", "output": "NO" }, { "input": "initis inites etr", "output": "NO" }, { "input": "initis inites etra", "output": "NO" }, { "input": "initis inites initis", "output": "NO" }, { "input": "initis inites inites", "output": "NO" }, { "input": "inites lios lios", "output": "NO" }, { "input": "inites lios liala", "output": "NO" }, { "input": "inites lios etr", "output": "NO" }, { "input": "inites lios etra", "output": "NO" }, { "input": "inites lios initis", "output": "NO" }, { "input": "inites lios inites", "output": "NO" }, { "input": "inites liala lios", "output": "NO" }, { "input": "inites liala liala", "output": "NO" }, { "input": "inites liala etr", "output": "NO" }, { "input": "inites liala etra", "output": "NO" }, { "input": "inites liala initis", "output": "NO" }, { "input": "inites liala inites", "output": "NO" }, { "input": "inites etr lios", "output": "NO" }, { "input": "inites etr liala", "output": "NO" }, { "input": "inites etr etr", "output": "NO" }, { "input": "inites etr etra", "output": "NO" }, { "input": "inites etr initis", "output": "NO" }, { "input": "inites etr inites", "output": "NO" }, { "input": "inites etra lios", "output": "NO" }, { "input": "inites etra liala", "output": "NO" }, { "input": "inites etra etr", "output": "NO" }, { "input": "inites etra etra", "output": "NO" }, { "input": "inites etra initis", "output": "NO" }, { "input": "inites etra inites", "output": "NO" }, { "input": "inites initis lios", "output": "NO" }, { "input": "inites initis liala", "output": "NO" }, { "input": "inites initis etr", "output": "NO" }, { "input": "inites initis etra", "output": "NO" }, { "input": "inites initis initis", "output": "NO" }, { "input": "inites initis inites", "output": "NO" }, { "input": "inites inites lios", "output": "NO" }, { "input": "inites inites liala", "output": "NO" }, { "input": "inites inites etr", "output": "NO" }, { "input": "inites inites etra", "output": "NO" }, { "input": "inites inites initis", "output": "NO" }, { "input": "inites inites inites", "output": "NO" } ]
60
0
-1
20,260
404
Restore Graph
[ "dfs and similar", "graphs", "sortings" ]
null
null
Valera had an undirected connected graph without self-loops and multiple edges consisting of *n* vertices. The graph had an interesting property: there were at most *k* edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to *n*. One day Valera counted the shortest distances from one of the graph vertices to all other ones and wrote them out in array *d*. Thus, element *d*[*i*] of the array shows the shortest distance from the vertex Valera chose to vertex number *i*. Then something irreparable terrible happened. Valera lost the initial graph. However, he still has the array *d*. Help him restore the lost graph.
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=&lt;<=*n*<=≤<=105). Number *n* shows the number of vertices in the original graph. Number *k* shows that at most *k* edges were adjacent to each vertex in the original graph. The second line contains space-separated integers *d*[1],<=*d*[2],<=...,<=*d*[*n*] (0<=≤<=*d*[*i*]<=&lt;<=*n*). Number *d*[*i*] shows the shortest distance from the vertex Valera chose to the vertex number *i*.
If Valera made a mistake in his notes and the required graph doesn't exist, print in the first line number -1. Otherwise, in the first line print integer *m* (0<=≤<=*m*<=≤<=106) — the number of edges in the found graph. In each of the next *m* lines print two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*), denoting the edge that connects vertices with numbers *a**i* and *b**i*. The graph shouldn't contain self-loops and multiple edges. If there are multiple possible answers, print any of them.
[ "3 2\n0 1 1\n", "4 2\n2 0 1 3\n", "3 1\n0 0 0\n" ]
[ "3\n1 2\n1 3\n3 2\n", "3\n1 3\n1 4\n2 3\n", "-1\n" ]
none
[ { "input": "3 2\n0 1 1", "output": "2\n1 2\n1 3" }, { "input": "4 2\n2 0 1 3", "output": "3\n1 3\n1 4\n2 3" }, { "input": "3 1\n0 0 0", "output": "-1" }, { "input": "5 3\n0 2 1 2 1", "output": "4\n1 3\n1 5\n2 5\n4 5" }, { "input": "7 3\n2 2 0 1 3 2 1", "output": "6\n1 7\n2 7\n3 4\n3 7\n4 6\n5 6" }, { "input": "9 4\n2 1 1 3 1 2 2 1 0", "output": "8\n1 8\n2 9\n3 9\n4 7\n5 9\n6 8\n7 8\n8 9" }, { "input": "3 1\n0 1 2", "output": "-1" }, { "input": "2 1\n1 0", "output": "1\n1 2" }, { "input": "2 1\n1 1", "output": "-1" }, { "input": "2 1\n0 0", "output": "-1" }, { "input": "4 2\n0 1 0 1", "output": "-1" }, { "input": "5 3\n3 1 4 2 1", "output": "-1" }, { "input": "5 4\n1 2 2 2 3", "output": "-1" }, { "input": "4 3\n1 1 1 2", "output": "-1" }, { "input": "4 3\n1 2 2 3", "output": "-1" }, { "input": "4 3\n1 2 3 3", "output": "-1" }, { "input": "7 6\n1 1 2 2 3 3 3", "output": "-1" }, { "input": "10 5\n0 1 1 1 1 1 1 2 2 2", "output": "-1" }, { "input": "5 4\n0 1 1 1 4", "output": "-1" } ]
483
36,044,800
3
20,266
576
Points on Plane
[ "constructive algorithms", "divide and conquer", "geometry", "greedy", "sortings" ]
null
null
On a plane are *n* points (*x**i*, *y**i*) with integer coordinates between 0 and 106. The distance between the two points with numbers *a* and *b* is said to be the following value: (the distance calculated by such formula is called Manhattan distance). We call a hamiltonian path to be some permutation *p**i* of numbers from 1 to *n*. We say that the length of this path is value . Find some hamiltonian path with a length of no more than 25<=×<=108. Note that you do not have to minimize the path length.
The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The *i*<=+<=1-th line contains the coordinates of the *i*-th point: *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=106). It is guaranteed that no two points coincide.
Print the permutation of numbers *p**i* from 1 to *n* — the sought Hamiltonian path. The permutation must meet the inequality . If there are multiple possible answers, print any of them. It is guaranteed that the answer exists.
[ "5\n0 7\n8 10\n3 4\n5 0\n9 12\n" ]
[ "4 3 1 2 5 \n" ]
In the sample test the total distance is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c772e61c616e1c27114e3facb9e6db6c5cf93b82.png" style="max-width: 100.0%;max-height: 100.0%;"/> (|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 + 8 + 3 + 1 + 2 = 26
[]
2,000
116,531,200
0
20,344
936
World of Tank
[ "dp", "greedy" ]
null
null
Vitya loves programming and problem solving, but sometimes, to distract himself a little, he plays computer games. Once he found a new interesting game about tanks, and he liked it so much that he went through almost all levels in one day. Remained only the last level, which was too tricky. Then Vitya remembered that he is a programmer, and wrote a program that helped him to pass this difficult level. Try do the same. The game is organized as follows. There is a long road, two cells wide and *n* cells long. Some cells have obstacles. You control a tank that occupies one cell. Initially, the tank is located before the start of the road, in a cell with coordinates (0,<=1). Your task is to move the tank to the end of the road, to the cell (*n*<=+<=1,<=1) or (*n*<=+<=1,<=2). Every second the tank moves one cell to the right: the coordinate *x* is increased by one. When you press the up or down arrow keys, the tank instantly changes the lane, that is, the *y* coordinate. When you press the spacebar, the tank shoots, and the nearest obstacle along the lane in which the tank rides is instantly destroyed. In order to load a gun, the tank needs *t* seconds. Initially, the gun is not loaded, that means, the first shot can be made only after *t* seconds after the tank starts to move. If at some point the tank is in the same cell with an obstacle not yet destroyed, it burns out. If you press the arrow exactly at the moment when the tank moves forward, the tank will first move forward, and then change the lane, so it will not be possible to move diagonally. Your task is to find out whether it is possible to pass the level, and if possible, to find the order of actions the player need to make.
The first line contains four integers *n*, *m*1, *m*2 and *t*, the length of the field, the number of obstacles in the first lane, the number of obstacles in the second lane and the number of tank steps before reloading, respectively (1<=≤<=*n*<=≤<=109; 0<=≤<=*m*1,<=*m*2<=≤<=*n*; 0<=≤<=*m*1<=+<=*m*2<=≤<=106; 1<=≤<=*t*<=≤<=*n*). The next two lines contain a description of the obstacles. The first of these lines contains *m*1 numbers *x**i* — the obstacle coordinates in the first lane (1<=≤<=*x**i*<=≤<=*n*; *x**i*<=&lt;<=*x**i*<=+<=1). The *y* coordinate for all these obstacles will be 1. The second line contains *m*2 numbers describing the obstacles of the second lane in the same format. The *y* coordinate of all these obstacles will be 2.
In the first line print «Yes», if it is possible to pass the level, or «No», otherwise. If it is possible, then in the second line print the number of times the tank moves from one lane to another, and in the next line print the coordinates of the transitions, one number per transition: the coordinate *x* (0<=≤<=*x*<=≤<=*n*<=+<=1). All transition coordinates coordinates must be distinct and should be output in strictly increasing order.The number of transitions should not exceed 2·106. If the tank can pass the level, then it can do it using no more than 2·106 transitions. In the fourth line print the number of shots that the tank makes during the movement, in the following lines print two numbers, *x* and *y* coordinates of the point (1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=2), from which the tank fired a shot, the number of shots must not exceed *m*1<=+<=*m*2. Shots must be output in the order in which they are fired. If there are several solutions, output any one.
[ "6 2 3 2\n2 6\n3 5 6\n", "1 1 1 1\n1\n1\n", "9 5 2 5\n1 2 7 8 9\n4 6\n" ]
[ "Yes\n2\n0 3 \n2\n2 2\n4 1\n", "No\n", "Yes\n4\n0 3 5 10 \n1\n5 2\n" ]
Picture for the first sample test.
[]
77
0
0
20,350
710
Generate a String
[ "dfs and similar", "dp" ]
null
null
zscoder wants to generate an input file for some programming competition problem. His input is a string consisting of *n* letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor. Initially, the text editor is empty. It takes him *x* seconds to insert or delete a letter 'a' from the text file and *y* seconds to copy the contents of the entire text file, and duplicate it. zscoder wants to find the minimum amount of time needed for him to create the input file of exactly *n* letters 'a'. Help him to determine the amount of time needed to generate the input.
The only line contains three integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=107, 1<=≤<=*x*,<=*y*<=≤<=109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Print the only integer *t* — the minimum amount of time needed to generate the input file.
[ "8 1 1\n", "8 1 10\n" ]
[ "4\n", "8\n" ]
none
[ { "input": "8 1 1", "output": "4" }, { "input": "8 1 10", "output": "8" }, { "input": "10 62 99", "output": "384" }, { "input": "88 417 591", "output": "4623" }, { "input": "57 5289 8444", "output": "60221" }, { "input": "382 81437847 324871127", "output": "2519291691" }, { "input": "244 575154303 436759189", "output": "5219536421" }, { "input": "85 902510038 553915152", "output": "6933531064" }, { "input": "1926 84641582 820814219", "output": "7184606427" }, { "input": "3768 561740421 232937477", "output": "5042211408" }, { "input": "2313 184063453 204869248", "output": "2969009745" }, { "input": "35896 278270961 253614967", "output": "5195579310" }, { "input": "483867 138842067 556741142", "output": "10712805143" }, { "input": "4528217 187553422 956731625", "output": "21178755627" }, { "input": "10000000 1000000000 1", "output": "8000000023" }, { "input": "10000000 1 100", "output": "1757" }, { "input": "10000000 1 1000000000", "output": "10000000" }, { "input": "10000000 1 1000", "output": "14224" }, { "input": "10000000 1 10", "output": "214" }, { "input": "1 1 1", "output": "1" }, { "input": "10000000 998 998", "output": "30938" }, { "input": "9999999 987654321 123456789", "output": "11728395036" }, { "input": "9999999 1 2", "output": "54" }, { "input": "10000000 1 1", "output": "31" }, { "input": "11478 29358 26962", "output": "556012" }, { "input": "4314870 1000000000 1", "output": "7000000022" }, { "input": "7186329 608148870 290497442", "output": "12762929866" }, { "input": "9917781 1 1", "output": "35" }, { "input": "7789084 807239576 813643932", "output": "25165322688" }, { "input": "58087 1 100000000", "output": "58087" }, { "input": "9999991 2 3", "output": "88" } ]
0
0
-1
20,352
491
Up the hill
[ "constructive algorithms", "implementation" ]
null
null
Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through. It is known that there were *N* stops, all on different integer heights between 1 and *N* kilometers (inclusive) above the sea level. On the first day they've traveled from the first stop to the second stop, on the second day they've traveled from the second to the third and so on, and on the last day they've traveled from the stop *N*<=-<=1 to the stop *N* and successfully finished their expedition. They are trying to find out which heights were their stops located at. They have an entry in a travel journal specifying how many days did they travel up the hill, and how many days did they walk down the hill. Help them by suggesting some possible stop heights satisfying numbers from the travel journal.
In the first line there is an integer non-negative number *A* denoting the number of days of climbing up the hill. Second line contains an integer non-negative number *B* — the number of days of walking down the hill (*A*<=+<=*B*<=+<=1<==<=*N*, 1<=≤<=*N*<=≤<=100<=000).
Output *N* space-separated distinct integers from 1 to *N* inclusive, denoting possible heights of the stops in order of visiting.
[ "0\n1\n", "2\n1" ]
[ "2 1 \n", "1 3 4 2" ]
none
[ { "input": "0\n1", "output": "2 1 " }, { "input": "2\n1", "output": "2 3 4 1 " }, { "input": "0\n3", "output": "4 3 2 1 " }, { "input": "1\n1", "output": "2 3 1 " }, { "input": "3\n7", "output": "8 9 10 11 7 6 5 4 3 2 1 " }, { "input": "700\n300", "output": "301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428..." }, { "input": "37\n29", "output": "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 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 " }, { "input": "177\n191", "output": "192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319..." }, { "input": "50000\n3", "output": "4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 1..." }, { "input": "99999\n0", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "0\n99999", "output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..." }, { "input": "24999\n74997", "output": "74998 74999 75000 75001 75002 75003 75004 75005 75006 75007 75008 75009 75010 75011 75012 75013 75014 75015 75016 75017 75018 75019 75020 75021 75022 75023 75024 75025 75026 75027 75028 75029 75030 75031 75032 75033 75034 75035 75036 75037 75038 75039 75040 75041 75042 75043 75044 75045 75046 75047 75048 75049 75050 75051 75052 75053 75054 75055 75056 75057 75058 75059 75060 75061 75062 75063 75064 75065 75066 75067 75068 75069 75070 75071 75072 75073 75074 75075 75076 75077 75078 75079 75080 75081 75082 7..." }, { "input": "17\n61111", "output": "61112 61113 61114 61115 61116 61117 61118 61119 61120 61121 61122 61123 61124 61125 61126 61127 61128 61129 61111 61110 61109 61108 61107 61106 61105 61104 61103 61102 61101 61100 61099 61098 61097 61096 61095 61094 61093 61092 61091 61090 61089 61088 61087 61086 61085 61084 61083 61082 61081 61080 61079 61078 61077 61076 61075 61074 61073 61072 61071 61070 61069 61068 61067 61066 61065 61064 61063 61062 61061 61060 61059 61058 61057 61056 61055 61054 61053 61052 61051 61050 61049 61048 61047 61046 61045 6..." }, { "input": "50021\n40009", "output": "40010 40011 40012 40013 40014 40015 40016 40017 40018 40019 40020 40021 40022 40023 40024 40025 40026 40027 40028 40029 40030 40031 40032 40033 40034 40035 40036 40037 40038 40039 40040 40041 40042 40043 40044 40045 40046 40047 40048 40049 40050 40051 40052 40053 40054 40055 40056 40057 40058 40059 40060 40061 40062 40063 40064 40065 40066 40067 40068 40069 40070 40071 40072 40073 40074 40075 40076 40077 40078 40079 40080 40081 40082 40083 40084 40085 40086 40087 40088 40089 40090 40091 40092 40093 40094 4..." }, { "input": "49999\n49997", "output": "49998 49999 50000 50001 50002 50003 50004 50005 50006 50007 50008 50009 50010 50011 50012 50013 50014 50015 50016 50017 50018 50019 50020 50021 50022 50023 50024 50025 50026 50027 50028 50029 50030 50031 50032 50033 50034 50035 50036 50037 50038 50039 50040 50041 50042 50043 50044 50045 50046 50047 50048 50049 50050 50051 50052 50053 50054 50055 50056 50057 50058 50059 50060 50061 50062 50063 50064 50065 50066 50067 50068 50069 50070 50071 50072 50073 50074 50075 50076 50077 50078 50079 50080 50081 50082 5..." }, { "input": "6777\n57897", "output": "57898 57899 57900 57901 57902 57903 57904 57905 57906 57907 57908 57909 57910 57911 57912 57913 57914 57915 57916 57917 57918 57919 57920 57921 57922 57923 57924 57925 57926 57927 57928 57929 57930 57931 57932 57933 57934 57935 57936 57937 57938 57939 57940 57941 57942 57943 57944 57945 57946 57947 57948 57949 57950 57951 57952 57953 57954 57955 57956 57957 57958 57959 57960 57961 57962 57963 57964 57965 57966 57967 57968 57969 57970 57971 57972 57973 57974 57975 57976 57977 57978 57979 57980 57981 57982 5..." }, { "input": "49999\n49999", "output": "50000 50001 50002 50003 50004 50005 50006 50007 50008 50009 50010 50011 50012 50013 50014 50015 50016 50017 50018 50019 50020 50021 50022 50023 50024 50025 50026 50027 50028 50029 50030 50031 50032 50033 50034 50035 50036 50037 50038 50039 50040 50041 50042 50043 50044 50045 50046 50047 50048 50049 50050 50051 50052 50053 50054 50055 50056 50057 50058 50059 50060 50061 50062 50063 50064 50065 50066 50067 50068 50069 50070 50071 50072 50073 50074 50075 50076 50077 50078 50079 50080 50081 50082 50083 50084 5..." }, { "input": "1\n0", "output": "1 2 " }, { "input": "0\n1", "output": "2 1 " }, { "input": "0\n0", "output": "1 " }, { "input": "2\n0", "output": "1 2 3 " }, { "input": "5\n0", "output": "1 2 3 4 5 6 " }, { "input": "90000\n1", "output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1..." }, { "input": "100\n4", "output": "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 4 3 2 1 " } ]
124
9,011,200
3
20,375
452
4-point polyline
[ "brute force", "constructive algorithms", "geometry", "trees" ]
null
null
You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible. A polyline defined by points *p*1,<=*p*2,<=*p*3,<=*p*4 consists of the line segments *p*1<=*p*2,<=*p*2<=*p*3,<=*p*3<=*p*4, and its length is the sum of the lengths of the individual line segments.
The only line of the input contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1000). It is guaranteed that grid contains at least 4 different points.
Print 4 lines with two integers per line separated by space — coordinates of points *p*1,<=*p*2,<=*p*3,<=*p*4 in order which represent the longest possible polyline. Judge program compares your answer and jury's answer with 10<=-<=6 precision.
[ "1 1\n", "0 10\n" ]
[ "1 1\n0 0\n1 0\n0 1\n", "0 1\n0 10\n0 0\n0 9\n" ]
none
[ { "input": "1 1", "output": "0 0\n1 1\n0 1\n1 0" }, { "input": "0 10", "output": "0 1\n0 10\n0 0\n0 9" }, { "input": "10 10", "output": "10 9\n0 0\n10 10\n1 0" }, { "input": "100 100", "output": "0 1\n100 100\n0 0\n99 100" }, { "input": "10 100", "output": "9 100\n0 0\n10 100\n1 0" }, { "input": "20 1000", "output": "19 1000\n0 0\n20 1000\n1 0" }, { "input": "1000 20", "output": "1000 19\n0 0\n1000 20\n0 1" }, { "input": "100 10", "output": "100 9\n0 0\n100 10\n0 1" }, { "input": "2 2", "output": "0 0\n2 2\n0 2\n2 0" }, { "input": "3 3", "output": "3 3\n0 0\n3 0\n0 3" }, { "input": "2 15", "output": "2 15\n0 0\n0 15\n2 0" }, { "input": "15 2", "output": "15 2\n0 0\n15 0\n0 2" }, { "input": "1000 1000", "output": "0 1\n1000 1000\n0 0\n999 1000" }, { "input": "1000 999", "output": "1000 998\n0 0\n1000 999\n0 1" }, { "input": "999 1000", "output": "998 1000\n0 0\n999 1000\n1 0" }, { "input": "987 567", "output": "0 1\n987 567\n0 0\n987 566" }, { "input": "555 555", "output": "0 1\n555 555\n0 0\n554 555" }, { "input": "555 1", "output": "555 1\n0 0\n555 0\n0 1" }, { "input": "1 4", "output": "0 0\n1 4\n1 0\n0 4" }, { "input": "955 956", "output": "1 0\n955 956\n0 0\n954 956" }, { "input": "4 0", "output": "1 0\n4 0\n0 0\n3 0" }, { "input": "0 3", "output": "0 1\n0 3\n0 0\n0 2" }, { "input": "3 0", "output": "1 0\n3 0\n0 0\n2 0" }, { "input": "2 3", "output": "0 0\n2 3\n2 0\n0 3" }, { "input": "3 2", "output": "0 0\n3 2\n0 2\n3 0" }, { "input": "3 4", "output": "0 0\n3 4\n3 0\n0 4" }, { "input": "4 3", "output": "0 0\n4 3\n0 3\n4 0" }, { "input": "3 5", "output": "0 0\n3 5\n3 0\n0 5" }, { "input": "5 3", "output": "0 0\n5 3\n0 3\n5 0" }, { "input": "3 6", "output": "0 0\n3 6\n3 0\n0 6" }, { "input": "6 3", "output": "0 0\n6 3\n0 3\n6 0" }, { "input": "4 4", "output": "4 3\n0 0\n4 4\n1 0" }, { "input": "4 5", "output": "1 0\n4 5\n0 0\n3 5" }, { "input": "5 4", "output": "0 1\n5 4\n0 0\n5 3" }, { "input": "4 6", "output": "1 0\n4 6\n0 0\n3 6" }, { "input": "6 4", "output": "0 1\n6 4\n0 0\n6 3" }, { "input": "4 7", "output": "1 0\n4 7\n0 0\n3 7" }, { "input": "7 4", "output": "0 1\n7 4\n0 0\n7 3" }, { "input": "3 100", "output": "0 0\n3 100\n3 0\n0 100" }, { "input": "100 3", "output": "0 0\n100 3\n0 3\n100 0" }, { "input": "4 100", "output": "1 0\n4 100\n0 0\n3 100" }, { "input": "100 4", "output": "0 1\n100 4\n0 0\n100 3" }, { "input": "30 1000", "output": "1 0\n30 1000\n0 0\n29 1000" }, { "input": "1000 30", "output": "0 1\n1000 30\n0 0\n1000 29" }, { "input": "1000 40", "output": "0 1\n1000 40\n0 0\n1000 39" }, { "input": "40 1000", "output": "1 0\n40 1000\n0 0\n39 1000" }, { "input": "2 10", "output": "2 10\n0 0\n0 10\n2 0" }, { "input": "9 3", "output": "0 0\n9 3\n0 3\n9 0" }, { "input": "2 1000", "output": "2 1000\n0 0\n0 1000\n2 0" }, { "input": "100 2", "output": "0 0\n100 2\n0 2\n100 0" }, { "input": "3 1", "output": "3 1\n0 0\n3 0\n0 1" }, { "input": "2 100", "output": "0 0\n2 100\n2 0\n0 100" }, { "input": "3 7", "output": "0 0\n3 7\n3 0\n0 7" }, { "input": "2 50", "output": "0 0\n2 50\n2 0\n0 50" }, { "input": "1 5", "output": "1 5\n0 0\n0 5\n1 0" }, { "input": "3 1000", "output": "0 0\n3 1000\n3 0\n0 1000" }, { "input": "5 2", "output": "5 2\n0 0\n5 0\n0 2" }, { "input": "10 0", "output": "1 0\n10 0\n0 0\n9 0" }, { "input": "20 0", "output": "1 0\n20 0\n0 0\n19 0" }, { "input": "1000 3", "output": "0 0\n1000 3\n0 3\n1000 0" }, { "input": "1000 500", "output": "0 1\n1000 500\n0 0\n1000 499" }, { "input": "2 5", "output": "2 5\n0 0\n0 5\n2 0" }, { "input": "2 1", "output": "0 0\n2 1\n0 1\n2 0" }, { "input": "1000 2", "output": "1000 2\n0 0\n1000 0\n0 2" }, { "input": "6 5", "output": "0 1\n6 5\n0 0\n6 4" }, { "input": "2 4", "output": "0 0\n2 4\n2 0\n0 4" }, { "input": "20 10", "output": "20 9\n0 0\n20 10\n0 1" }, { "input": "10 1", "output": "10 1\n0 0\n10 0\n0 1" } ]
61
0
0
20,401
10
Digital Root
[ "number theory" ]
C. Digital Root
2
256
Not long ago Billy came across such a problem, where there were given three natural numbers *A*, *B* and *C* from the range [1,<=*N*], and it was asked to check whether the equation *AB*<==<=*C* is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root *d*(*x*) of the number *x* is the sum *s*(*x*) of all the digits of this number, if *s*(*x*)<=≤<=9, otherwise it is *d*(*s*(*x*)). For example, a digital root of the number 6543 is calculated as follows: *d*(6543)<==<=*d*(6<=+<=5<=+<=4<=+<=3)<==<=*d*(18)<==<=9. Billy has counted that the digital root of a product of numbers is equal to the digital root of the product of the factors' digital roots, i.e. *d*(*xy*)<==<=*d*(*d*(*x*)*d*(*y*)). And the following solution to the problem came to his mind: to calculate the digital roots and check if this condition is met. However, Billy has doubts that this condition is sufficient. That's why he asks you to find out the amount of test examples for the given problem such that the algorithm proposed by Billy makes mistakes.
The first line contains the only number *N* (1<=≤<=*N*<=≤<=106).
Output one number — the amount of required *A*, *B* and *C* from the range [1,<=*N*].
[ "4\n", "5\n" ]
[ "2\n", "6\n" ]
For the first sample the required triples are (3, 4, 3) and (4, 3, 3).
[ { "input": "4", "output": "2" }, { "input": "5", "output": "6" }, { "input": "6", "output": "14" }, { "input": "7", "output": "25" }, { "input": "1", "output": "0" }, { "input": "8", "output": "40" }, { "input": "10", "output": "82" }, { "input": "15", "output": "328" }, { "input": "16", "output": "395" }, { "input": "20", "output": "801" }, { "input": "50", "output": "13439" }, { "input": "100", "output": "110267" }, { "input": "127", "output": "226374" }, { "input": "202", "output": "911772" }, { "input": "333", "output": "4100905" }, { "input": "404", "output": "7300516" }, { "input": "411", "output": "7699373" }, { "input": "571", "output": "20657840" }, { "input": "600", "output": "23969924" }, { "input": "771", "output": "50875182" }, { "input": "10000", "output": "111107314481" }, { "input": "20000", "output": "888859064010" }, { "input": "30000", "output": "2999966359410" }, { "input": "50000", "output": "13888610595721" }, { "input": "99999", "output": "111107776644397" }, { "input": "200000", "output": "888885923513074" }, { "input": "400000", "output": "7111099254185938" }, { "input": "600000", "output": "23999973325791164" }, { "input": "800000", "output": "56888794064261806" }, { "input": "1000000", "output": "111111074060178115" }, { "input": "828282", "output": "63138169426585853" }, { "input": "729761", "output": "43181611460546198" }, { "input": "653451", "output": "31002458021265725" }, { "input": "987572", "output": "107019643962508968" }, { "input": "167590", "output": "522999083675296" }, { "input": "358712", "output": "5128538168895562" }, { "input": "498138", "output": "13734280958577573" }, { "input": "983242", "output": "105618162572849728" }, { "input": "312433", "output": "3388650642180089" }, { "input": "783472", "output": "53435215015075583" } ]
60
0
-1
20,403
63
Settlers' Training
[ "implementation" ]
B. Settlers' Training
2
256
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease. Every soldier has a rank — some natural number from 1 to *k*. 1 stands for a private and *k* stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank. To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the *n* soldiers are present. At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank *k* are present, exactly one soldier increases his rank by one. You know the ranks of all *n* soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank *k*.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains *n* numbers in the non-decreasing order. The *i*-th of them, *a**i*, represents the rank of the *i*-th soldier in the defense building (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=*k*).
Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.
[ "4 4\n1 2 2 3\n", "4 3\n1 1 1 1\n" ]
[ "4", "5" ]
In the first example the ranks will be raised in the following manner: 1 2 2 3  →  2 2 3 4  →  2 3 4 4  →  3 4 4 4  →  4 4 4 4 Thus totals to 4 training sessions that require 4 golden coins.
[ { "input": "4 4\n1 2 2 3", "output": "4" }, { "input": "4 3\n1 1 1 1", "output": "5" }, { "input": "3 3\n1 2 3", "output": "2" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 5\n1", "output": "4" }, { "input": "1 5\n4", "output": "1" }, { "input": "2 6\n2 5", "output": "4" }, { "input": "6 10\n1 1 3 4 9 9", "output": "10" }, { "input": "7 7\n1 1 1 1 1 1 7", "output": "11" }, { "input": "10 10\n1 1 1 3 3 4 7 8 8 8", "output": "11" }, { "input": "10 13\n1 1 1 1 1 1 1 1 1 1", "output": "21" }, { "input": "10 13\n2 6 6 7 9 9 9 10 12 12", "output": "11" }, { "input": "17 9\n2 3 4 5 5 5 5 5 6 6 7 7 8 8 8 8 8", "output": "17" }, { "input": "18 24\n3 3 3 4 5 7 8 8 9 9 9 9 10 10 11 11 11 11", "output": "30" }, { "input": "23 2\n1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2", "output": "12" }, { "input": "37 42\n1 1 1 1 1 2 2 2 2 2 3 4 4 4 4 5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8", "output": "70" }, { "input": "44 50\n38 38 38 38 38 38 38 39 39 39 39 39 39 39 40 40 40 40 40 41 41 41 41 41 41 41 42 42 42 43 43 43 44 44 44 44 45 45 45 46 46 46 46 46", "output": "47" }, { "input": "57 100\n2 2 4 7 8 10 12 12 14 15 16 18 19 21 21 22 25 26 26 33 38 40 44 44 44 45 47 47 50 51 51 54 54 54 54 55 56 58 61 65 67 68 68 70 74 75 78 79 83 86 89 90 92 95 96 96 97", "output": "99" }, { "input": "78 10\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 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9", "output": "78" }, { "input": "96 78\n20 20 20 20 20 21 21 21 22 23 23 24 24 25 25 27 28 29 30 30 30 32 32 32 33 33 33 33 34 34 35 36 37 37 39 39 41 41 41 41 42 42 43 43 43 44 44 45 46 46 48 48 49 50 51 51 51 52 53 55 55 56 56 56 56 57 58 59 60 61 61 61 62 62 62 63 63 64 64 64 65 65 65 66 66 67 68 69 71 72 72 73 73 75 75 75", "output": "98" }, { "input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "198" }, { "input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "0" }, { "input": "100 100\n1 1 4 4 5 5 7 9 10 10 11 11 12 12 12 13 14 15 16 16 16 17 18 18 19 20 22 25 26 27 29 32 33 34 34 35 35 35 36 36 37 37 38 39 39 40 41 42 44 44 46 47 47 47 47 50 53 53 53 55 56 56 57 57 58 58 59 59 62 64 64 64 64 68 68 68 69 70 70 71 74 77 77 77 79 80 80 81 84 86 88 88 91 93 94 96 96 99 99 99", "output": "108" }, { "input": "100 100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 8 8 8 8 8 9 9 9 9 9 9 9 10 10 10 10 10 11 11 11 11 11 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15", "output": "184" }, { "input": "100 100\n20 20 20 21 21 21 21 21 22 23 23 23 23 23 23 24 24 25 25 26 26 26 26 26 27 27 27 27 28 28 28 28 29 29 29 29 29 30 30 30 30 31 32 32 34 34 34 34 34 34 34 34 35 35 35 36 36 37 37 37 37 37 37 38 38 38 39 40 41 41 42 42 42 42 42 43 43 43 44 44 44 44 44 45 45 45 45 45 46 46 46 46 46 47 47 47 48 48 48 50", "output": "150" }, { "input": "100 2\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "59" }, { "input": "30 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 49", "output": "77" }, { "input": "40 20\n5 5 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 20 20 20 20 20 20 20 20 20 20", "output": "31" }, { "input": "81 90\n1 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90", "output": "89" }, { "input": "100 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13", "output": "106" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 100", "output": "197" }, { "input": "100 100\n49 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 51", "output": "148" }, { "input": "1 100\n1", "output": "99" }, { "input": "4 3\n1 1 2 2", "output": "4" }, { "input": "10 100\n98 99 99 99 99 99 99 100 100 100", "output": "7" }, { "input": "5 100\n1 2 2 100 100", "output": "100" } ]
310
21,606,400
3.882255
20,416
513
Second price auction
[ "bitmasks", "probabilities" ]
null
null
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random. However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot. Let's consider one such bidding. There are *n* companies competing for placing an ad. The *i*-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between *L**i* and *R**i*, inclusive. In the other words, the value of the *i*-th company bid can be any integer from the range [*L**i*,<=*R**i*] with the same probability. Determine the expected value that the winner will have to pay in a second-price auction.
The first line of input contains an integer number *n* (2<=≤<=*n*<=≤<=5). *n* lines follow, the *i*-th of them containing two numbers *L**i* and *R**i* (1<=≤<=*L**i*<=≤<=*R**i*<=≤<=10000) describing the *i*-th company's bid preferences. This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output the answer with absolute or relative error no more than 1*e*<=-<=9.
[ "3\n4 7\n8 10\n5 5\n", "3\n2 5\n3 4\n1 6\n" ]
[ "5.7500000000\n", "3.5000000000\n" ]
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5·5 + 0.25·6 + 0.25·7 = 5.75.
[ { "input": "3\n4 7\n8 10\n5 5", "output": "5.7500000000" }, { "input": "3\n2 5\n3 4\n1 6", "output": "3.5000000000" }, { "input": "5\n1 10000\n1 10000\n1 10000\n1 10000\n1 10000", "output": "6667.1666666646" }, { "input": "2\n1 2\n1 2", "output": "1.2500000000" }, { "input": "2\n1 3\n1 3", "output": "1.5555555556" }, { "input": "5\n1 7\n2 5\n3 9\n4 8\n5 6", "output": "5.9530612245" }, { "input": "5\n17 9999\n19 9992\n1 10000\n6 9\n34 99", "output": "5004.6727567145" }, { "input": "5\n3778 9170\n2657 6649\n4038 9722\n3392 7255\n4890 8961", "output": "6938.4627241727" }, { "input": "5\n2194 6947\n2062 8247\n4481 8430\n3864 9409\n3784 5996", "output": "6373.5390940730" }, { "input": "5\n2906 6249\n659 9082\n2628 8663\n4199 5799\n2678 9558", "output": "6062.1839551640" }, { "input": "5\n659 8346\n2428 8690\n2357 5783\n3528 8580\n2425 7918", "output": "6077.3178766816" }, { "input": "5\n4075 6754\n1024 8762\n504 9491\n1159 6496\n375 9191", "output": "5919.6219273821" }, { "input": "5\n4787 9531\n3133 9597\n1754 9725\n4335 7124\n4269 7752", "output": "7046.2404831920" }, { "input": "5\n1851 8833\n1730 6325\n4901 9327\n4671 9278\n3163 9789", "output": "7182.4449064090" }, { "input": "5\n2563 8898\n2487 7923\n3048 5323\n142 7194\n4760 6061", "output": "5657.2388045241" }, { "input": "5\n979 6674\n1084 8758\n2003 5556\n478 7822\n3654 9623", "output": "5721.9327862568" }, { "input": "5\n4395 5976\n489 5355\n149 5158\n4462 5738\n2548 6658", "output": "5102.0377827659" }, { "input": "5\n3755 7859\n1245 7085\n592 5392\n1285 7892\n1442 7931", "output": "5545.5391818827" }, { "input": "5\n2171 7161\n4842 8682\n4547 9100\n269 9283\n3039 6492", "output": "6641.5017309461" }, { "input": "5\n1 1\n1 1\n2 2\n3 3\n4 4", "output": "3.0000000000" }, { "input": "2\n1 1\n1 1", "output": "1.0000000000" }, { "input": "2\n1 10000\n1 9999", "output": "3333.6666666667" } ]
2,000
28,672,000
0
20,423
747
Comments
[ "dfs and similar", "expression parsing", "implementation", "strings" ]
null
null
A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed. Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment except root comments (comments of the highest level) has exactly one parent comment. When Polycarp wants to save comments to his hard drive he uses the following format. Each comment he writes in the following format: - at first, the text of the comment is written; - after that the number of comments is written, for which this comment is a parent comment (i. e. the number of the replies to this comments); - after that the comments for which this comment is a parent comment are written (the writing of these comments uses the same algorithm). For example, if the comments look like: then the first comment is written as "hello,2,ok,0,bye,0", the second is written as "test,0", the third comment is written as "one,1,two,2,a,0,b,0". The whole comments feed is written as: "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0". For a given comments feed in the format specified above print the comments in a different format: - at first, print a integer *d* — the maximum depth of nesting comments; - after that print *d* lines, the *i*-th of them corresponds to nesting level *i*; - for the *i*-th row print comments of nesting level *i* in the order of their appearance in the Policarp's comments feed, separated by space.
The first line contains non-empty comments feed in the described format. It consists of uppercase and lowercase letters of English alphabet, digits and commas. It is guaranteed that each comment is a non-empty string consisting of uppercase and lowercase English characters. Each of the number of comments is integer (consisting of at least one digit), and either equals 0 or does not contain leading zeros. The length of the whole string does not exceed 106. It is guaranteed that given structure of comments is valid.
Print comments in a format that is given in the statement. For each level of nesting, comments should be printed in the order they are given in the input.
[ "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0\n", "a,5,A,0,a,0,A,0,a,0,A,0\n", "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0\n" ]
[ "3\nhello test one \nok bye two \na b \n", "2\na \nA a A a A \n", "4\nA K M \nB F H L N O \nC D G I P \nE J \n" ]
The first example is explained in the statements.
[ { "input": "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0", "output": "3\nhello test one \nok bye two \na b " }, { "input": "a,5,A,0,a,0,A,0,a,0,A,0", "output": "2\na \nA a A a A " }, { "input": "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0", "output": "4\nA K M \nB F H L N O \nC D G I P \nE J " }, { "input": "BA,0", "output": "1\nBA " }, { "input": "Tu,1,dU,1,zncD,0", "output": "3\nTu \ndU \nzncD " }, { "input": "nwEwA,2,C,1,aG,0,xgv,0", "output": "3\nnwEwA \nC xgv \naG " }, { "input": "aa,0", "output": "1\naa " }, { "input": "ab,0,ba,0", "output": "1\nab ba " }, { "input": "aa,0,ab,1,a,0", "output": "2\naa ab \na " }, { "input": "a,0,bb,1,a,1,bb,0", "output": "3\na bb \na \nbb " }, { "input": "a,2,b,0,bb,1,a,1,a,0", "output": "4\na \nb bb \na \na " }, { "input": "bb,0,b,1,a,1,b,1,a,0,b,0", "output": "4\nbb b b \na \nb \na " }, { "input": "b,2,b,0,b,0,b,1,b,0,ba,1,b,0", "output": "2\nb b ba \nb b b b " }, { "input": "bb,0,bb,0,b,1,ab,0,b,0,a,2,ab,0,bb,0", "output": "2\nbb bb b b a \nab ab bb " }, { "input": "ba,0,aa,1,a,0,bb,1,a,0,a,0,a,0,a,1,a,0", "output": "2\nba aa bb a a a \na a a " }, { "input": "a,3,aa,0,b,0,b,0,b,0,a,0,b,2,aa,1,a,0,ab,0", "output": "3\na b a b \naa b b aa ab \na " } ]
592
98,099,200
-1
20,437
809
Glad to see you!
[ "binary search", "interactive" ]
null
null
This is an interactive problem. In the output section below you will see the information about flushing the output. On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in Vičkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building. In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of *n* dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to *n*. After a little thought, the girl ordered exactly *k* different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better. The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*). After that Noora chooses some dish *a* for the number *x* such that, at first, *a* is among the dishes Noora ordered (*x* can be equal to *a*), and, secondly, the value is the minimum possible. By the same rules the girl chooses dish *b* for *y*. After that Noora says «TAK» to Leha, if , and «NIE» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered. Help Leha to solve this problem!
There are two numbers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.
If you want to provide an answer, output a string of the form 2 *x* *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*), if you think the dishes *x* and *y* was among dishes ordered by Noora. After that, flush the output and terminate your program.
[ "3 2\nNIE\nTAK\nNIE\nTAK\nTAK\nTAK\n" ]
[ "1 1 2\n1 2 1\n1 1 3\n1 3 1\n1 2 3\n1 3 2\n2 2 3\n" ]
There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (*x* = 1), then she'll choose the second dish (*a* = 2) as the dish with the minimum value <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e5a4a1705bc256e413564795cc8b70857f0ae44c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. For the second (*x* = 2) and the third (*x* = 3) dishes themselves will be optimal, because in that case <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/79add195d023131e992b60a354fec89501759e75.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Let Leha asks Noora about the next couple of dishes: - *x* = 1, *y* = 2, then he'll recieve «NIE» answer, because |1 - 2| &gt; |2 - 2| - *x* = 2, *y* = 1, then he'll recieve «TAK» answer, because |2 - 2| ≤ |1 - 2| - *x* = 1, *y* = 3, then he'll recieve «NIE» answer, because |1 - 2| &gt; |3 - 3| - *x* = 3, *y* = 1, then he'll recieve «TAK» answer, because |3 - 3| ≤ |1 - 2| - *x* = 2, *y* = 3, then he'll recieve «TAK» answer, because |2 - 2| ≤ |3 - 3| - *x* = 3, *y* = 2, then he'll recieve «TAK» answer, because |3 - 3| ≤ |2 - 2| According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.
[]
46
5,632,000
0
20,442
350
Wrong Floyd
[ "brute force", "constructive algorithms", "dfs and similar", "graphs" ]
null
null
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it. Valera's already written the code that counts the shortest distance between any pair of vertexes in a non-directed connected graph from *n* vertexes and *m* edges, containing no loops and multiple edges. Besides, Valera's decided to mark part of the vertexes. He's marked exactly *k* vertexes *a*1,<=*a*2,<=...,<=*a**k*. Valera's code is given below. Valera has seen that his code is wrong. Help the boy. Given the set of marked vertexes *a*1,<=*a*2,<=...,<=*a**k*, find such non-directed connected graph, consisting of *n* vertexes and *m* edges, for which Valera's code counts the wrong shortest distance for at least one pair of vertexes (*i*,<=*j*). Valera is really keen to get a graph without any loops and multiple edges. If no such graph exists, print -1.
The first line of the input contains three integers *n*,<=*m*,<=*k* (3<=≤<=*n*<=≤<=300, 2<=≤<=*k*<=≤<=*n* , ) — the number of vertexes, the number of edges and the number of marked vertexes. The second line of the input contains *k* space-separated integers *a*1,<=*a*2,<=... *a**k* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of the marked vertexes. It is guaranteed that all numbers *a**i* are distinct.
If the graph doesn't exist, print -1 on a single line. Otherwise, print *m* lines, each containing two integers *u*,<=*v* — the description of the edges of the graph Valera's been looking for.
[ "3 2 2\n1 2\n", "3 3 2\n1 2\n" ]
[ "1 3\n2 3\n", "-1\n" ]
none
[ { "input": "3 2 2\n1 2", "output": "1 3\n2 3" }, { "input": "3 3 2\n1 2", "output": "-1" }, { "input": "300 43056 2\n5 6", "output": "1 2\n2 3\n3 4\n4 7\n5 300\n6 300\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "300 44849 2\n1 300", "output": "1 299\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n7..." }, { "input": "300 44850 2\n3 9", "output": "-1" }, { "input": "58 702 19\n14 29 47 15 31 5 26 57 55 16 17 24 46 58 11 28 20 56 43", "output": "1 2\n2 3\n3 4\n4 6\n5 58\n6 7\n7 8\n8 9\n9 10\n10 12\n11 54\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n1 3\n1 4\n1 6\n1 7\n1 8\n1 9\n1 10\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 ..." }, { "input": "43 76 6\n24 11 30 21 35 1", "output": "1 43\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 12\n11 43\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38" }, { "input": "6 13 6\n2 6 5 4 1 3", "output": "-1" }, { "input": "139 8017 8\n18 108 117 80 99 74 36 52", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 19\n18 139\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 37\n36 139\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n7..." }, { "input": "144 1175 121\n141 124 23 85 142 59 25 84 32 43 35 101 54 47 98 53 78 68 118 56 130 77 50 133 31 144 129 75 37 112 51 116 108 14 136 71 24 87 69 80 16 143 39 103 97 30 89 49 134 128 139 120 29 86 28 34 73 21 19 83 114 82 40 105 127 90 38 107 95 72 102 63 12 61 100 111 138 9 7 99 110 27 20 122 58 88 15 113 41 131 46 2 66 3 140 119 135 104 115 74 55 81 92 52 22 18 117 45 60 8 126 79 106 44 64 57 109 70 6 1 93", "output": "1 144\n2 137\n3 4\n3 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "300 299 23\n106 213 64 58 242 261 298 10 37 50 186 278 29 190 107 161 257 214 265 254 28 20 119", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 11\n10 300\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 21\n20 300\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n7..." }, { "input": "300 299 2\n145 191", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "300 44850 2\n34 32", "output": "-1" }, { "input": "250 300 2\n157 204", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "150 299 149\n132 120 102 149 26 107 119 39 65 83 12 25 114 77 17 113 69 144 7 86 79 60 57 99 143 30 125 92 88 28 61 3 5 94 112 137 55 51 20 140 48 22 37 52 147 66 53 148 67 100 47 96 116 111 128 129 130 32 1 138 14 23 41 27 63 139 118 64 101 18 123 89 131 8 35 95 62 19 72 110 127 126 6 16 134 146 33 45 98 122 21 108 104 11 36 93 46 38 124 74 50 56 58 70 90 115 81 73 68 40 42 105 75 71 133 29 49 142 59 117 24 87 106 85 91 10 54 15 4 44 2 136 145 76 150 109 31 43 141 34 13 78 82 9 80 84 103 121 97", "output": "1 150\n2 135\n3 4\n3 135\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n..." }, { "input": "50 78 23\n42 43 26 28 7 19 10 31 11 45 23 47 37 8 17 20 18 12 22 6 24 27 16", "output": "1 2\n2 3\n3 4\n4 5\n5 8\n6 50\n7 50\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n1 3\n1 4\n1 5\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33" }, { "input": "50 66 2\n4 3", "output": "1 2\n2 5\n3 50\n4 50\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21" }, { "input": "10 9 2\n9 7", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 8\n7 10\n8 10\n9 10" }, { "input": "56 87 2\n42 47", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 43\n42 56\n43 44\n44 45\n45 46\n46 48\n47 56\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n..." }, { "input": "300 299 3\n1 2 3", "output": "1 300\n2 300\n3 4\n3 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "243 29321 10\n229 156 19 236 158 210 86 115 227 99", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 20\n19 243\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76..." }, { "input": "21 58 21\n4 11 9 19 3 18 5 13 16 2 8 6 14 10 20 1 21 7 15 12 17", "output": "-1" }, { "input": "56 1540 3\n27 38 32", "output": "-1" }, { "input": "56 1537 3\n53 11 3", "output": "1 2\n2 4\n3 56\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 12\n11 56\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29..." }, { "input": "56 1538 3\n29 9 8", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 10\n8 56\n9 56\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n1 3\n1 4\n1 5\n1 6\n1 7\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 ..." }, { "input": "88 3828 44\n13 79 67 88 37 82 51 84 45 54 74 56 14 59 73 68 27 24 18 66 61 52 43 17 62 5 64 78 86 16 44 23 34 29 28 60 46 19 38 35 7 49 15 47", "output": "-1" }, { "input": "88 3784 44\n58 34 52 21 57 63 53 17 88 5 74 38 39 18 14 70 44 51 87 71 15 59 30 80 26 12 79 6 85 81 45 83 10 41 61 4 23 60 78 37 9 65 16 32", "output": "1 2\n2 3\n3 6\n4 88\n5 86\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n7..." }, { "input": "56 1539 3\n10 47 4", "output": "-1" }, { "input": "88 3785 44\n45 13 11 80 83 56 25 35 1 67 7 77 43 15 62 42 72 65 26 58 74 69 10 17 41 60 85 81 12 36 50 52 76 75 8 9 3 87 64 24 21 39 61 6", "output": "1 88\n2 4\n3 88\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n7..." }, { "input": "88 3786 44\n15 34 31 51 67 62 68 79 73 45 40 18 59 42 80 35 53 82 29 78 19 28 23 48 77 37 14 10 75 49 74 21 32 86 22 16 84 12 63 58 30 81 25 69", "output": "-1" }, { "input": "88 87 44\n67 3 72 4 14 76 7 28 54 32 63 65 2 77 70 59 42 1 45 39 52 22 84 8 40 37 51 88 75 49 74 15 30 58 73 33 50 57 81 69 44 46 48 87", "output": "1 88\n2 86\n3 4\n3 5\n4 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n7..." }, { "input": "88 88 44\n14 53 85 11 50 20 51 19 56 22 38 79 67 68 1 46 47 44 28 72 78 7 48 32 75 57 63 77 8 27 2 33 5 13 83 29 17 35 18 76 74 3 88 36", "output": "1 88\n2 87\n3 4\n3 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n7..." }, { "input": "159 158 34\n24 49 150 26 102 113 68 14 101 11 154 144 17 4 157 109 148 145 110 29 147 92 97 72 51 23 91 20 140 7 52 12 124 56", "output": "1 2\n2 3\n3 5\n4 159\n5 6\n6 8\n7 159\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "159 159 34\n107 11 77 149 66 99 98 100 82 65 41 87 43 83 89 14 20 2 60 157 56 25 113 96 120 8 140 132 7 64 108 51 62 26", "output": "1 3\n2 159\n3 4\n4 5\n5 6\n6 8\n7 159\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "200 199 100\n134 154 100 128 173 7 66 16 55 64 43 12 88 3 112 99 19 162 193 139 155 10 151 93 34 79 6 107 123 5 148 101 40 36 85 14 160 140 77 124 53 143 17 69 60 116 84 183 194 119 172 192 27 83 106 39 188 178 153 121 177 196 158 9 57 22 37 81 199 185 147 86 164 74 141 114 78 102 176 18 46 138 8 20 89 48 21 68 129 90 195 52 146 170 130 13 171 71 190 65", "output": "1 2\n2 4\n3 200\n4 6\n5 200\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "250 249 100\n61 175 64 104 223 67 131 19 225 109 178 194 212 134 135 140 32 17 100 22 171 60 224 211 15 152 207 238 122 6 170 21 48 132 250 30 236 75 166 201 221 190 92 247 78 8 230 198 51 111 103 55 83 98 169 117 74 242 85 44 118 69 204 188 217 82 29 45 76 137 173 124 70 34 197 79 244 231 121 156 107 235 90 145 138 176 150 210 228 168 7 101 58 108 42 112 4 160 5 86", "output": "1 2\n2 3\n3 6\n4 250\n5 249\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "100 99 98\n79 62 41 16 14 98 77 28 58 45 1 60 49 92 50 51 19 4 20 48 91 22 33 85 21 44 32 27 39 70 6 94 87 5 76 3 89 63 8 12 78 9 35 40 29 74 57 99 97 71 64 13 38 30 42 15 23 47 31 95 61 96 18 7 36 84 53 37 100 25 46 43 68 2 73 82 34 67 90 69 55 81 93 52 80 83 56 59 54 72 75 66 86 88 65 17 10 24", "output": "1 100\n2 26\n3 4\n3 11\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n7..." }, { "input": "100 100 98\n91 52 16 47 11 1 96 85 38 79 10 5 24 19 88 89 86 22 75 2 70 58 94 41 8 57 54 65 48 84 78 45 82 100 7 34 50 28 59 90 26 81 51 95 46 15 18 80 21 62 63 44 14 72 39 25 12 53 83 66 43 4 20 71 35 49 87 98 73 76 74 23 6 33 29 32 64 97 36 30 55 67 56 13 40 3 60 68 42 9 27 93 31 69 61 77 99 17", "output": "1 100\n2 92\n3 4\n3 37\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n7..." }, { "input": "100 102 98\n61 41 58 45 49 83 17 52 12 95 78 30 26 54 89 93 72 87 14 63 36 21 39 96 1 9 15 69 73 35 59 91 75 2 11 77 34 19 99 33 13 71 90 70 47 85 46 97 48 31 8 38 92 81 44 51 16 86 100 60 76 94 82 4 28 18 84 50 88 79 55 32 62 5 64 24 25 43 65 7 42 27 98 10 20 67 57 74 23 37 53 22 6 56 40 68 3 29", "output": "1 100\n2 80\n3 4\n3 66\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n7..." }, { "input": "50 49 24\n43 32 13 17 24 21 12 23 37 3 44 46 25 49 10 40 19 7 31 16 42 38 18 20", "output": "1 2\n2 4\n3 50\n4 5\n5 6\n6 8\n7 50\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50" }, { "input": "50 50 25\n20 16 36 17 24 11 48 37 45 44 10 5 7 9 42 46 15 8 30 33 31 4 50 40 19", "output": "1 2\n2 3\n3 6\n4 50\n5 49\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n1 3" }, { "input": "70 69 10\n51 42 1 8 29 52 14 3 34 50", "output": "1 70\n2 4\n3 70\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70" }, { "input": "90 100 20\n28 38 44 12 52 83 58 77 79 3 72 40 56 51 53 47 21 10 42 54", "output": "1 2\n2 4\n3 90\n4 5\n5 6\n6 7\n7 8\n8 9\n9 11\n10 90\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76..." }, { "input": "77 77 77\n64 66 76 13 50 1 42 24 10 36 57 29 72 28 46 3 47 23 21 32 31 12 20 67 30 9 25 22 75 69 48 35 73 53 34 4 44 55 33 6 49 8 45 11 41 63 39 37 17 56 71 2 77 15 61 62 18 16 51 68 58 27 54 26 59 43 38 7 52 65 14 74 70 40 60 19 5", "output": "-1" }, { "input": "88 100 87\n78 12 53 82 35 84 42 46 23 51 43 20 52 17 83 75 8 80 29 38 15 24 66 45 81 65 64 25 31 3 27 9 69 5 39 54 41 56 70 22 76 68 13 2 77 74 11 86 33 6 58 10 73 48 19 87 32 63 21 72 79 85 44 40 7 28 59 57 30 47 16 62 37 14 18 88 1 55 4 36 71 50 49 61 26 60 67", "output": "1 88\n2 34\n3 4\n3 34\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76..." }, { "input": "99 4581 98\n88 78 86 37 69 36 76 8 61 90 29 11 2 48 91 35 64 62 87 23 28 1 74 5 7 73 21 45 97 47 83 25 77 15 31 16 20 24 3 80 32 99 18 89 84 65 30 17 59 33 49 58 68 10 85 60 56 43 44 41 72 66 67 12 42 19 27 79 70 9 82 34 98 4 71 95 94 13 26 51 52 54 75 57 50 92 55 53 22 39 63 40 38 96 93 6 81 14", "output": "1 99\n2 46\n3 4\n3 46\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76..." }, { "input": "99 4754 98\n42 72 26 62 58 59 33 83 63 74 15 44 66 16 90 49 31 71 1 77 18 99 78 48 53 80 36 87 68 9 20 51 5 81 60 7 3 37 17 28 27 73 40 98 88 14 24 55 32 70 96 92 67 50 46 25 84 94 29 12 52 89 11 2 13 91 61 45 23 65 43 35 97 34 6 54 21 82 4 76 8 95 75 30 64 38 79 69 39 56 85 10 19 93 41 22 47 57", "output": "1 99\n2 86\n3 4\n3 86\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75..." }, { "input": "99 4755 98\n42 52 40 75 21 80 6 33 94 14 82 66 5 41 60 18 10 56 74 7 20 3 37 65 63 70 59 47 68 19 49 44 35 84 39 48 30 51 8 22 34 13 96 99 1 29 87 2 81 17 73 23 46 43 62 4 55 97 15 88 89 71 24 85 83 78 93 95 9 79 32 25 45 98 53 36 11 16 12 90 92 91 67 77 26 86 28 76 61 27 38 57 58 54 69 31 64 72", "output": "-1" }, { "input": "22 231 11\n15 6 16 10 17 4 18 1 3 2 22", "output": "-1" }, { "input": "22 220 11\n10 22 7 19 9 14 20 13 5 18 12", "output": "1 2\n2 3\n3 4\n4 6\n5 22\n6 8\n7 21\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n1 3\n1 4\n1 6\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n2 4\n2 6\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n3 6\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n4 18\n4 19\n4 20\n4 21\n4 2..." }, { "input": "22 221 11\n19 7 5 21 3 15 17 18 4 10 22", "output": "1 2\n2 5\n3 22\n4 20\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n5 7\n5 8\n5 9\n5 10\n5 11\n5 12\n5 13\n5 14\n5 15\n5 16\n5 17\n5 18\n5 19\n5 20\n5 21\n5 22\n6 8\n6 9\n6 10\n6 11\n6 12\n6 13\n6 14\n6 15\n6 16\n6 17\n6 18\n6 19\n6 20\n6 21\n6 2..." }, { "input": "22 222 11\n22 20 1 12 13 9 18 21 3 14 2", "output": "-1" }, { "input": "22 22 11\n12 8 1 10 3 13 19 2 15 7 5", "output": "1 22\n2 22\n3 4\n3 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n3 6" }, { "input": "22 21 11\n1 7 14 6 10 20 5 13 21 22 4", "output": "1 22\n2 3\n3 5\n4 19\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22" }, { "input": "5 10 3\n4 1 3", "output": "-1" }, { "input": "5 7 3\n5 3 2", "output": "1 4\n2 5\n3 4\n4 5\n1 5\n1 2\n1 3" }, { "input": "5 8 3\n4 5 1", "output": "1 5\n2 3\n3 4\n3 5\n2 5\n1 2\n2 4\n1 3" }, { "input": "5 7 4\n1 2 3 4", "output": "1 4\n2 5\n3 4\n3 5\n4 5\n1 3\n1 5" }, { "input": "5 4 4\n1 5 3 4", "output": "1 5\n2 3\n2 4\n4 5" }, { "input": "6 13 3\n1 2 3", "output": "1 6\n2 6\n3 4\n3 5\n5 6\n3 6\n4 5\n4 6\n1 3\n1 4\n2 4\n1 5\n2 5" } ]
592
102,400
0
20,457
961
Pair Of Lines
[ "geometry" ]
null
null
You are given *n* points on Cartesian plane. Every point is a lattice point (i.<=e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of points you are given. Then *n* lines follow, each line containing two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109)— coordinates of *i*-th point. All *n* points are distinct.
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
[ "5\n0 0\n0 1\n1 1\n1 -1\n2 2\n", "5\n0 0\n1 0\n2 1\n1 1\n2 3\n" ]
[ "YES\n", "NO\n" ]
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
[ { "input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES" }, { "input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO" }, { "input": "1\n-1000000000 1000000000", "output": "YES" }, { "input": "5\n2 -1\n-4 1\n0 -9\n5 -9\n9 -10", "output": "NO" }, { "input": "5\n6 1\n10 5\n10 -2\n-2 -10\n-4 -9", "output": "YES" }, { "input": "5\n-10 3\n4 -5\n-9 5\n-5 -3\n-4 -6", "output": "NO" }, { "input": "5\n2 9\n-1 -4\n-3 -8\n-4 8\n7 2", "output": "NO" }, { "input": "10\n315 202\n315 203\n315 204\n-138 -298\n-136 -295\n-134 -292\n-132 -289\n-130 -286\n-128 -283\n-126 -280", "output": "YES" }, { "input": "10\n416 -473\n-162 491\n-164 488\n-170 479\n-166 485\n-172 476\n416 -475\n416 -474\n-168 482\n-160 494", "output": "YES" }, { "input": "6\n0 0\n1 1\n0 1\n1 0\n0 2\n2 0", "output": "NO" }, { "input": "5\n3 3\n6 3\n0 0\n10 0\n-10 0", "output": "YES" }, { "input": "1\n0 0", "output": "YES" }, { "input": "10\n0 0\n1 0\n0 1\n0 2\n2 0\n3 0\n0 3\n0 4\n4 0\n0 -10000000", "output": "YES" }, { "input": "6\n0 0\n0 1\n0 2\n1 1\n1 2\n2 1", "output": "NO" }, { "input": "6\n0 -1\n1 -1\n3 3\n2 0\n-2 -2\n1 -2", "output": "NO" }, { "input": "5\n1000000000 1000000000\n999999999 999999999\n999999999 999999998\n-1000000000 1000000000\n-1000000000 999999999", "output": "NO" }, { "input": "5\n0 0\n1 0\n0 1\n1 1\n-1 1", "output": "YES" }, { "input": "6\n0 0\n0 1\n0 -1\n1 1\n1 -1\n2 -1", "output": "NO" }, { "input": "4\n0 0\n0 1\n1 0\n1 1", "output": "YES" }, { "input": "6\n0 0\n1 0\n2 1\n1 1\n0 1\n6 0", "output": "YES" }, { "input": "10\n536870912 536870912\n268435456 368435456\n268435456 168435456\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9", "output": "NO" }, { "input": "5\n0 0\n0 1\n100 100\n100 99\n100 98", "output": "YES" }, { "input": "8\n0 0\n1 0\n2 1\n1 1\n0 1\n6 0\n5 0\n7 0", "output": "YES" }, { "input": "5\n0 0\n2 0\n1 1\n0 2\n5 1", "output": "YES" }, { "input": "7\n0 0\n4 0\n1 1\n2 2\n3 1\n5 1\n6 2", "output": "NO" }, { "input": "6\n1 1\n2 2\n3 2\n4 1\n5 2\n6 1", "output": "YES" }, { "input": "8\n0 0\n1 0\n2 0\n3 0\n0 1\n1 1\n2 1\n3 1", "output": "YES" }, { "input": "12\n0 0\n1 1\n2 2\n3 3\n10 11\n20 11\n30 11\n40 11\n-1 1\n-2 2\n-3 3\n-4 4", "output": "NO" }, { "input": "6\n0 0\n165580141 267914296\n331160282 535828592\n267914296 433494437\n535828592 866988874\n433494437 701408733", "output": "NO" }, { "input": "5\n-1000000000 -1000000000\n-588442013 -868997024\n-182303377 -739719081\n-999999999 -999999999\n229254610 -608716105", "output": "NO" }, { "input": "5\n-1000000000 -1000000000\n229254610 -608716105\n-588442013 -868997024\n-182303377 -739719081\n-176884026 -737994048", "output": "YES" }, { "input": "6\n0 0\n0 1\n0 2\n5 0\n5 1\n5 -1", "output": "YES" }, { "input": "5\n-1 1\n1 0\n1 1\n1 -1\n-1 -1", "output": "YES" }, { "input": "5\n-1000000000 -1000000000\n229254610 -608716105\n-588442013 -868997024\n-182303377 -739719081\n-999999999 -999999999", "output": "NO" }, { "input": "6\n1 1\n0 0\n-1 -1\n1 0\n0 -1\n-1 -10", "output": "NO" }, { "input": "5\n8 8\n3303829 10\n10 1308\n4 2\n6 3", "output": "NO" }, { "input": "5\n0 0\n0 1\n0 2\n0 3\n1 0", "output": "YES" }, { "input": "5\n0 0\n165580142 267914296\n331160283 535828592\n267914296 433494437\n535828592 866988874", "output": "YES" }, { "input": "59\n1 0\n0 2\n0 3\n0 4\n0 5\n6 0\n7 0\n8 0\n9 0\n10 0\n0 11\n12 0\n13 0\n14 0\n15 0\n0 16\n0 17\n18 0\n19 0\n20 0\n21 0\n0 22\n23 0\n24 0\n0 25\n26 0\n27 0\n0 28\n0 29\n30 0\n31 0\n0 32\n33 0\n34 0\n0 35\n0 36\n37 0\n0 38\n39 0\n40 0\n0 41\n42 0\n0 43\n0 44\n0 45\n0 46\n47 0\n0 48\n0 49\n50 0\n0 51\n0 52\n53 0\n0 54\n55 0\n0 56\n57 0\n0 58\n59 0", "output": "YES" }, { "input": "5\n10000000 40000100\n3 112\n2 400000100\n1 104\n1000000 701789036", "output": "YES" }, { "input": "5\n514 2131\n312 52362\n1 1\n2 2\n3 3", "output": "YES" }, { "input": "9\n-65536 65536\n0 65536\n65536 65536\n-65536 0\n0 0\n65536 0\n-65536 -65536\n0 -65536\n65536 -65536", "output": "NO" }, { "input": "5\n0 -7\n0 10000\n1 1000000000\n100 0\n200 0", "output": "NO" }, { "input": "7\n0 0\n2 2\n2 -2\n-2 2\n-2 -2\n0 1\n0 3", "output": "NO" }, { "input": "5\n3 0\n4 1\n0 0\n1 1\n2 2", "output": "YES" }, { "input": "5\n-65536 -65536\n65536 0\n131072 0\n0 65536\n0 131072", "output": "NO" }, { "input": "4\n0 0\n1 0\n0 1\n1 1", "output": "YES" }, { "input": "6\n0 0\n2 0\n0 2\n0 -2\n-2 1\n-4 2", "output": "NO" }, { "input": "5\n-1000000000 -1000000000\n134903170 -298591267\n-566505563 -732085704\n-298591267 -566505563\n-133011126 -464171408", "output": "YES" }, { "input": "5\n-1000000000 -1000000000\n134903170 -298591267\n-566505563 -732085704\n-298591267 -566505563\n-999999999 -999999999", "output": "NO" }, { "input": "5\n1 1\n-1 0\n0 1\n-1 1\n0 0", "output": "YES" }, { "input": "5\n0 0\n-1 -1\n0 -1\n-1 1\n-1 0", "output": "YES" }, { "input": "5\n0 0\n-1 1\n-1 0\n0 -1\n-1 -1", "output": "YES" }, { "input": "6\n0 0\n-1 1\n-1 0\n1 1\n-1 -1\n0 -1", "output": "NO" }, { "input": "5\n-1 2\n-1 1\n2 1\n-2 2\n1 1", "output": "YES" }, { "input": "6\n-1 -1\n-1 -2\n-1 -3\n1000000000 1\n-1000000000 0\n999999999 1", "output": "NO" }, { "input": "6\n-1 -1\n-1 -2\n-1 -3\n0 0\n65536 65536\n65536 131072", "output": "NO" }, { "input": "6\n-1 -1\n-1 -2\n-1 -3\n1000000000 1\n999999999 1\n-1000000000 0", "output": "NO" }, { "input": "3\n-1 1\n-1 -1\n0 0", "output": "YES" }, { "input": "7\n1 -1\n3 -3\n1 2\n0 -2\n1 -3\n0 1\n0 2", "output": "NO" }, { "input": "4\n0 0\n-1 1\n-1 -1\n1 0", "output": "YES" }, { "input": "6\n0 0\n0 1\n-1 1\n0 -1\n1 0\n-1 -1", "output": "NO" }, { "input": "5\n1 1\n0 0\n-1 0\n0 1\n1 0", "output": "YES" }, { "input": "11\n-2 -2\n2 3\n3 -2\n1 -2\n2 -2\n2 0\n2 2\n-3 -2\n-1 -2\n2 -3\n2 1", "output": "YES" }, { "input": "5\n0 0\n-1 0\n-1 1\n1 0\n1 -1", "output": "YES" }, { "input": "5\n1 -1\n0 0\n0 1\n-1 1\n1 1", "output": "YES" }, { "input": "5\n0 0\n1 1\n0 -2\n1 -1\n1 2", "output": "YES" }, { "input": "5\n-999999998 -999999998\n229254612 -608716103\n-588442011 -868997022\n-182303375 -739719079\n-176884024 -737994046", "output": "YES" } ]
514
71,680,000
3
20,468
920
SUM and REPLACE
[ "brute force", "data structures", "dsu", "number theory" ]
null
null
Let *D*(*x*) be the number of positive divisors of a positive integer *x*. For example, *D*(2)<==<=2 (2 is divisible by 1 and 2), *D*(6)<==<=4 (6 is divisible by 1, 2, 3 and 6). You are given an array *a* of *n* integers. You have to process two types of queries: 1. REPLACE *l* *r* — for every replace *a**i* with *D*(*a**i*); 1. SUM *l* *r* — calculate . Print the answer for each SUM query.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the number of elements in the array and the number of queries to process, respectively. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the elements of the array. Then *m* lines follow, each containing 3 integers *t**i*, *l**i*, *r**i* denoting *i*-th query. If *t**i*<==<=1, then *i*-th query is REPLACE *l**i* *r**i*, otherwise it's SUM *l**i* *r**i* (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). There is at least one SUM query.
For each SUM query print the answer to it.
[ "7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7\n" ]
[ "30\n13\n4\n22\n" ]
none
[ { "input": "7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7", "output": "30\n13\n4\n22" }, { "input": "4 2\n1 1 1 3\n1 1 4\n2 1 4", "output": "5" }, { "input": "10 2\n1 1 1 1 1 1 1 1 1 9\n1 1 10\n2 1 10", "output": "12" }, { "input": "4 2\n1 1 3 1\n1 1 4\n2 1 4", "output": "5" }, { "input": "5 3\n1 1 1 1 3\n2 1 5\n1 1 5\n2 1 5", "output": "7\n6" }, { "input": "7 10\n1 1 1 1 1 1 1\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n2 1 7", "output": "7" } ]
2,000
15,462,400
0
20,495
976
Degree Set
[ "constructive algorithms", "graphs", "implementation" ]
null
null
You are given a sequence of *n* positive integers *d*1,<=*d*2,<=...,<=*d**n* (*d*1<=&lt;<=*d*2<=&lt;<=...<=&lt;<=*d**n*). Your task is to construct an undirected graph such that: - there are exactly *d**n*<=+<=1 vertices; - there are no self-loops; - there are no multiple edges; - there are no more than 106 edges; - its degree set is equal to *d*. Vertices should be numbered 1 through (*d**n*<=+<=1). Degree sequence is an array *a* with length equal to the number of vertices in a graph such that *a**i* is the number of vertices adjacent to *i*-th vertex. Degree set is a sorted in increasing order sequence of all distinct values from the degree sequence. It is guaranteed that there exists such a graph that all the conditions hold, and it contains no more than 106 edges. Print the resulting graph.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=300) — the size of the degree set. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=1000, *d*1<=&lt;<=*d*2<=&lt;<=...<=&lt;<=*d**n*) — the degree set.
In the first line print one integer *m* (1<=≤<=*m*<=≤<=106) — the number of edges in the resulting graph. It is guaranteed that there exists such a graph that all the conditions hold and it contains no more than 106 edges. Each of the next *m* lines should contain two integers *v**i* and *u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*d**n*<=+<=1) — the description of the *i*-th edge.
[ "3\n2 3 4\n", "3\n1 2 3\n" ]
[ "8\n3 1\n4 2\n4 5\n2 5\n5 1\n3 2\n2 1\n5 3\n", "4\n1 2\n1 3\n1 4\n2 3\n" ]
none
[ { "input": "3\n2 3 4", "output": "8\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4" }, { "input": "3\n1 2 3", "output": "4\n1 2\n1 3\n1 4\n2 3" }, { "input": "4\n1 3 4 6", "output": "11\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n3 4\n3 5" }, { "input": "1\n1", "output": "1\n1 2" }, { "input": "1\n1000", "output": "500500\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..." }, { "input": "2\n1 2", "output": "2\n1 2\n1 3" }, { "input": "2\n999 1000", "output": "500499\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..." }, { "input": "2\n1 1000", "output": "1000\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 8..." }, { "input": "3\n1 500 1000", "output": "125750\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..." }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "30\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n4 5\n4 6\n4 7\n4 8\n5 6\n5 7" }, { "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": "2550\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 8..." }, { "input": "10\n1 3 4 6 10 12 16 18 19 20", "output": "111\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n4 18\n4 19\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n5 12\n5 13\n5 14\n5 15\n5 16\n5 17\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n6 13\n6 14\n..." }, { "input": "4\n6 8 11 19", "output": "108\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n4 18\n4 19\n4 20\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n5 12\n5 13\n5 14\n5 15\n5 16\n5 17\n5 18\n5 19\n5 20\n6 7\n6 8\n6 9\n6 10\n6 11\n..." }, { "input": "2\n2 3", "output": "5\n1 2\n1 3\n1 4\n2 3\n2 4" } ]
780
58,470,400
0
20,498
466
Information Graph
[ "dfs and similar", "dsu", "graphs", "trees" ]
null
null
There are *n* employees working in company "X" (let's number them from 1 to *n* for convenience). Initially the employees didn't have any relationships among each other. On each of *m* next days one of the following events took place: - either employee *y* became the boss of employee *x* (at that, employee *x* didn't have a boss before); - or employee *x* gets a packet of documents and signs them; then he gives the packet to his boss. The boss signs the documents and gives them to his boss and so on (the last person to sign the documents sends them to the archive); - or comes a request of type "determine whether employee *x* signs certain documents". Your task is to write a program that will, given the events, answer the queries of the described type. At that, it is guaranteed that throughout the whole working time the company didn't have cyclic dependencies.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of employees and the number of events. Each of the next *m* lines contains the description of one event (the events are given in the chronological order). The first number of the line determines the type of event *t* (1<=≤<=*t*<=≤<=3). - If *t*<==<=1, then next follow two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*) — numbers of the company employees. It is guaranteed that employee *x* doesn't have the boss currently. - If *t*<==<=2, then next follow integer *x* (1<=≤<=*x*<=≤<=*n*) — the number of the employee who got a document packet. - If *t*<==<=3, then next follow two integers *x* and *i* (1<=≤<=*x*<=≤<=*n*; 1<=≤<=*i*<=≤<=[number of packets that have already been given]) — the employee and the number of the document packet for which you need to find out information. The document packets are numbered started from 1 in the chronological order. It is guaranteed that the input has at least one query of the third type.
For each query of the third type print "YES" if the employee signed the document package and "NO" otherwise. Print all the words without the quotes.
[ "4 9\n1 4 3\n2 4\n3 3 1\n1 2 3\n2 2\n3 1 2\n1 3 1\n2 2\n3 1 3\n" ]
[ "YES\nNO\nYES\n" ]
none
[]
30
0
0
20,532
929
Пограничные врата
[]
null
null
Герой Аркадий находится на узкой полоске земли, разделенной на *n* зон, пронумерованных от 1 до *n*. Из *i*-й зоны можно пройти лишь в (*i*<=-<=1)-ю зону и в (*i*<=+<=1)-ю зону, если они существуют. При этом между каждой парой соседних зон находятся пограничные врата, которые могут быть разных цветов, цвет врат между *i*-й и (*i*<=+<=1)-й зоной равен *g**i*. Аркадий может пройти пограничные врата некоторого цвета, только если он перед этим побывал в одном из шатров хранителей ключей этого цвета и взял ключ. В каждой зоне находится ровно один шатер хранителя ключей некоторого цвета, цвет шатра в *i*-й зоне равен *k**i*. После посещения шатра определенного цвета Аркадий может неограниченное число раз проходить через любые врата этого цвета. На проход через одни врата Аркадий тратит один ход, на посещение шатра и другие перемещения ходы не требуются. За какое минимальное число ходов Аркадий может попасть из зоны *a* в зону *b*, если изначально у него нет никаких ключей?
Первая строка содержит три целых числа *n*, *a*, *b* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*) — число зон, номер начальной зоны и номер конечной зоны, соответственно. Вторая строка содержит *n*<=-<=1 целое число *g*1,<=*g*2,<=...,<=*g**n*<=-<=1 (1<=≤<=*g**i*<=≤<=100<=000), где *g**i* означает цвет пограничных врат между зонами *i* и *i*<=+<=1. Третья строка содержит *n* целых чисел *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100<=000), где *k**i* означает цвет шатра хранителя ключей в *i*-й зоне.
Если Аркадий не может попасть из зоны *a* в зону *b*, не имея изначально ключей, выведите -1. Иначе выведите минимальное количество ходов, которое потребуется Аркадию.
[ "5 4 1\n3 1 1 2\n7 1 2 1 3\n", "5 1 5\n4 3 2 1\n4 3 2 5 5\n" ]
[ "7\n", "-1\n" ]
В первом примере, чтобы попасть из зоны 4 в зону 1, Аркадию нужно сначала взять ключ цвета 1, пройти в зону 3, там взять ключ цвета 2 и пройти обратно в зону 4 и затем в зону 5, взять там ключ цвета 3 и дойти до зоны 1 за четыре хода. Во втором примере Аркадий может дойти лишь до четвертой зоны, так как шатров хранителей ключей цвета 1 нет совсем.
[]
46
5,632,000
-1
20,534
758
Blown Garland
[ "brute force", "implementation", "number theory" ]
null
null
Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland. Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working. It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green. Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.
The first and the only line contains the string *s* (4<=≤<=|*s*|<=≤<=100), which describes the garland, the *i*-th symbol of which describes the color of the *i*-th light bulb in the order from the beginning of garland: - 'R' — the light bulb is red, - 'B' — the light bulb is blue, - 'Y' — the light bulb is yellow, - 'G' — the light bulb is green, - '!' — the light bulb is dead. The string *s* can not contain other symbols except those five which were described. It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'. It is guaranteed that the string *s* is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.
In the only line print four integers *k**r*,<=*k**b*,<=*k**y*,<=*k**g* — the number of dead light bulbs of red, blue, yellow and green colors accordingly.
[ "RYBGRYBGR\n", "!RGYB\n", "!!!!YGRB\n", "!GB!RG!Y!\n" ]
[ "0 0 0 0", "0 1 0 0", "1 1 1 1", "2 1 1 0" ]
In the first example there are no dead light bulbs. In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.
[ { "input": "RYBGRYBGR", "output": "0 0 0 0" }, { "input": "!RGYB", "output": "0 1 0 0" }, { "input": "!!!!YGRB", "output": "1 1 1 1" }, { "input": "!GB!RG!Y!", "output": "2 1 1 0" }, { "input": "RYBG", "output": "0 0 0 0" }, { "input": "!Y!!!Y!!G!!!G!!B!!R!!!!B!!!!!Y!!G!R!!!!!!!!!!!!B!!!!GY!B!!!!!YR!G!!!!!!B!Y!B!!!!!!R!G!!!!!!!G!R!!!!B", "output": "20 18 19 18" }, { "input": "!R!GBRYG!RYGB!!G!!YG!!Y!!", "output": "3 5 2 1" }, { "input": "RBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGY", "output": "0 0 0 0" }, { "input": "GYRB!", "output": "0 0 0 1" }, { "input": "RBYGR", "output": "0 0 0 0" }, { "input": "BRYGB", "output": "0 0 0 0" }, { "input": "YRGBY", "output": "0 0 0 0" }, { "input": "GBYRG", "output": "0 0 0 0" }, { "input": "GBYR!!!!", "output": "1 1 1 1" }, { "input": "!!!BRYG!!", "output": "2 1 1 1" }, { "input": "!!!YBGR!!!", "output": "1 2 1 2" }, { "input": "R!!Y!!B!!G!", "output": "2 2 1 2" }, { "input": "!!!!BR!!!!GY", "output": "2 2 2 2" }, { "input": "!!!!!!!!!!!!!!!!!!Y!!!!!!!!!!!!!!!!!!B!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!G!!R!!!!!!!!!!!!", "output": "24 24 24 24" }, { "input": "!!G!!!G!!!G!!!G!!!GB!!G!!!G!!YG!!!G!!!G!!!G!!!G!!!G!!!G!!!G!!!G!!!G!!!G!!!G!!!G!!!G!!!G!!!G!R!G!!!G!", "output": "24 24 24 0" }, { "input": "!!Y!!!Y!!!Y!!!Y!!!Y!!!Y!!!YR!!Y!!!Y!B!Y!!!Y!!!Y!!!Y!!!Y!!GY!!!Y!!!Y!!!Y!!!Y!!!Y!!!Y!!!Y!!!Y!!!Y!!!Y!", "output": "24 24 0 24" }, { "input": "!B!!!B!!!B!!!B!!!B!!!B!G!B!!!B!!!B!!!B!!!B!!!B!!!BR!!B!!!B!!!B!!!B!!!B!!YB!!!B!!!B!!!B!!!B!!!B!!!B!!", "output": "24 0 24 24" }, { "input": "YR!!!R!!!RB!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!!!R!G!R!!!R!!!R!!!R!!", "output": "0 24 24 24" }, { "input": "R!YBRGY!R!", "output": "0 1 0 2" }, { "input": "B!RGB!!GBYR!B!R", "output": "1 0 3 1" }, { "input": "Y!!GYB!G!!!!YB!G!!RG", "output": "4 3 2 1" }, { "input": "R!!BRYG!!YG!R!!!R!!!!!G!R!!!!!", "output": "3 6 6 4" }, { "input": "R!!!R!!!R!!!R!B!RGB!!G!!R!B!R!B!RG!YR!B!", "output": "1 5 9 7" }, { "input": "!Y!R!Y!RB!G!BY!!!!!R!YG!!YGRB!!!!!!!BYGR!!!RBYGRBY", "output": "5 7 5 7" }, { "input": "!!G!!!!!Y!!RYBGRY!!R!!!R!!!!!!!R!B!!!!!R!!!R!!!R!!!R!!!R!!!!", "output": "5 13 12 13" }, { "input": "!!BG!!B!!RBG!!B!YRB!!!B!YRBG!!BG!!B!!!BG!!BG!RB!Y!!!!!B!Y!B!Y!!!!!B!!!", "output": "14 2 13 11" }, { "input": "R!GBRYGBRYGBRYG!RY!BRYGBRYGBRYGBRYGBRYGBRYGBRYGBRYGBR!GBRY!BRY!BRYGBRYGBRYGBRYGB", "output": "0 1 2 3" }, { "input": "!!!!B!!!!G!!B!R!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!YB!R!!!!!!G!!!!!!!!", "output": "20 20 21 21" }, { "input": "G!!!GY!!GYBRGYB!GY!RG!B!GYBRGY!!GY!!GYBRGYBRGY!RGY!!GYBRGY!!G!BRGYB!GYBRGYB!GY!!G!!RGYB!GYB!G!B!GYB!", "output": "15 10 5 0" }, { "input": "R!!!!!!Y!B!!!!!!!!!!!!!!R!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Y!!G!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "output": "23 24 23 24" }, { "input": "!!YR!!YR!!YR!!YR!!YR!BYR!!YR!!YR!!YRG!YR!!YR!!YR!!YR!!YR!!YR!!YR!!YR!!YR!!YR!!YR!!YR!!YR!!YR!!YR!!YR", "output": "0 24 0 24" }, { "input": "!!!YR!B!!!B!R!!!R!!YR!BY!G!YR!B!R!BYRG!!!!BY!!!!!!B!!!B!R!!Y!!B!!GB!R!B!!!!!!G!!RG!!R!BYR!!!!!B!!!!!", "output": "13 12 17 20" }, { "input": "B!RG!!R!B!R!B!R!B!R!!!R!B!RG!!RGB!R!!!RGB!!!!YR!B!!!!!RGB!R!B!R!B!!!!!RGBY!!B!RG!Y!GB!!!B!!GB!RGB!R!", "output": "7 8 22 15" }, { "input": "!B!YR!!YR!!YRB!Y!B!Y!B!Y!!!YR!GYR!!YRB!YR!!Y!!!YR!!YRB!YR!!Y!B!Y!!!Y!!!YR!!Y!B!YRB!YR!!YR!!Y!B!Y!B!Y", "output": "11 14 0 24" }, { "input": "!RBYGRBYGRBY!!!!GRBYGRB!GRBY!R!YGRBYG!BYGRBYG!!Y!!BYGRB!G!B!G!!!G!BY!RBYGRB!!R!!GR!YG!BY!!B!GR!Y!!!!", "output": "10 8 9 8" }, { "input": "BRG!!RGYBRGYBRG!B!GY!!GYB!GY!!G!BRGY!RGYB!G!!RGYBRGYB!GY!!GYB!GYBRGY!!GYB!GY!!GYB!GY!!GYBRGY!!GYB!G", "output": "15 10 4 0" }, { "input": "!Y!!!!!!!!!!!!!!!!!GB!!!!!!!!!!!!Y!!!!!!!!!!!!!!!!!!!!!!!!!!!!R!!!!!!!!!!!!!!!!!!!!!!!!!!!R!!!!!!!", "output": "22 24 23 23" }, { "input": "!R!!Y!G!!!!BYR!!!!G!!!!!!R!!!!!!!!!B!!!B!R!BY!!B!!GB!!G!!!G!!!G!!!!!!R!!!!G!!!!!Y!!BY!!!!!!!Y!!!", "output": "19 17 18 17" }, { "input": "!!GYRBGY!BGY!BGY!BGYR!G!RBGYRBGYR!G!RBGY!BGY!!GY!BGY!BGYRBGYR!GYRBGYR!G!!BGY!!GY!!GY!BGY!!GY!BG", "output": "14 9 3 0" }, { "input": "!!!!!!!!Y!!!!!!!!!GR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!B!!!!!!Y!!!!!!R!!!!!!!!!!!!!!!!!!!!!!!!!!", "output": "21 23 22 22" }, { "input": "!B!!Y!!GY!RGY!!!!!!!!!!!Y!!!!!!!!!!!!!!!!!RG!BR!!!!!!!!G!!!!!B!!!!R!!B!G!B!!YB!!Y!!!!BRG!!!G", "output": "18 16 17 16" }, { "input": "YB!!Y!GR!B!!YB!RYBG!!!!RY!GR!!!R!B!R!B!R!!!R!B!R!B!!!B!!YB!R!!G!YB!!Y!!R!BG!!!!!!B!!!!!R!!!", "output": "10 10 15 18" }, { "input": "R!G!R!GBR!!BR!GB!!!B!!!BR!GBRYG!R!!!R!GBRYGBR!GBR!!BR!GBR!GBRY!B!!!!R!!BR!!BR!!!!!!B!!!BR!", "output": "5 5 20 12" }, { "input": "YRB!Y!B!YRB!Y!!!Y!B!YR!!YR!!Y!!!YRB!YR!!YRB!Y!B!YRB!YR!!Y!!!YR!!YRB!YR!!Y!B!YRB!Y!!GYR!!Y", "output": "8 11 0 21" }, { "input": "!!GBRY!!!YG!R!GBR!G!RY!B!YGB!!G!RYGBRYGB!Y!BR!G!RYGBRYGBRYGBRYGBRYGBRYGB!Y!B!YGBR!!BRYGB", "output": "7 5 6 5" }, { "input": "G!!!!Y!!!!R!!!!B", "output": "3 3 3 3" }, { "input": "!Y!!!!!!G!!!!!!!!!B!!!!!!!!!!!!R", "output": "7 7 7 7" }, { "input": "RGBYRGBYRGBY", "output": "0 0 0 0" }, { "input": "!!!!!!!!!GBYRGBY", "output": "3 2 2 2" }, { "input": "RBYGRBYGRBYGRB!", "output": "0 0 1 0" }, { "input": "R!!!!!!!!!!!!B!!!!!!!!!!!!Y!!!!!!!!!!!!G", "output": "9 9 9 9" }, { "input": "GY!!!!R!!Y!B", "output": "2 2 1 2" }, { "input": "R!!!!!!!!!!!!!!!!!!!!!!!!Y!!!!!!!!!!!!!!!!!!!!!!!!G!!!!!!!!!!!!!!!!!!!!!!!!B!!!!!!!!!!!!!!!!!!!!!!!!", "output": "24 24 24 24" }, { "input": "R!!!!G!!!!B!!!!Y", "output": "3 3 3 3" }, { "input": "R!!!!B!!!!Y!!!!G!!!!", "output": "4 4 4 4" }, { "input": "!R!B!!!!G!Y", "output": "2 1 2 2" }, { "input": "!!!!!R!!!!G!!!!B!!!!Y!!!!!!!!!", "output": "7 6 7 6" }, { "input": "R!!!!B!!!!Y!!!!G", "output": "3 3 3 3" }, { "input": "!!!!!R!!!!G!!!!B!!!!!!!!Y!!!!!!!!!", "output": "8 7 8 7" }, { "input": "!!!!!!!!R!!!!!!!!B!!!!!!!!G!!!!!!!!Y!!!!!!!!", "output": "10 10 10 10" } ]
46
4,505,600
3
20,541
144
Meeting
[ "implementation" ]
null
null
The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose sides are parallel to the coordinate axes and whose vertexes are located at the integer points of the plane. At each integer point which belongs to the table perimeter there is a chair in which a general sits. Some points on the plane contain radiators for the generals not to freeze in winter. Each radiator is characterized by the number *r**i* — the radius of the area this radiator can heat. That is, if the distance between some general and the given radiator is less than or equal to *r**i*, than the general feels comfortable and warm. Here distance is defined as Euclidean distance, so the distance between points (*x*1,<=*y*1) and (*x*2,<=*y*2) is Each general who is located outside the radiators' heating area can get sick. Thus, you should bring him a warm blanket. Your task is to count the number of warm blankets you should bring to the Super Duper Secret Place. The generals who are already comfortable do not need a blanket. Also the generals never overheat, ever if they are located in the heating area of several radiators. The radiators can be located at any integer points on the plane, even inside the rectangle (under the table) or on the perimeter (directly under some general). Even in this case their radius does not change.
The first input line contains coordinates of two opposite table corners *x**a*, *y**a*, *x**b*, *y**b* (*x**a*<=≠<=*x**b*,<=*y**a*<=≠<=*y**b*). The second line contains integer *n* — the number of radiators (1<=≤<=*n*<=≤<=103). Then *n* lines contain the heaters' coordinates as "*x**i* *y**i* *r**i*", the numbers are separated by spaces. All input data numbers are integers. The absolute value of all coordinates does not exceed 1000, 1<=≤<=*r**i*<=≤<=1000. Several radiators can be located at the same point.
Print the only number — the number of blankets you should bring.
[ "2 5 4 2\n3\n3 1 2\n5 3 1\n1 3 2\n", "5 2 6 3\n2\n6 2 2\n6 5 3\n" ]
[ "4\n", "0\n" ]
In the first sample the generals are sitting at points: (2, 2), (2, 3), (2, 4), (2, 5), (3, 2), (3, 5), (4, 2), (4, 3), (4, 4), (4, 5). Among them, 4 generals are located outside the heating range. They are the generals at points: (2, 5), (3, 5), (4, 4), (4, 5). In the second sample the generals are sitting at points: (5, 2), (5, 3), (6, 2), (6, 3). All of them are located inside the heating range.
[ { "input": "2 5 4 2\n3\n3 1 2\n5 3 1\n1 3 2", "output": "4" }, { "input": "5 2 6 3\n2\n6 2 2\n6 5 3", "output": "0" }, { "input": "-705 595 -702 600\n1\n-589 365 261", "output": "4" }, { "input": "-555 674 -553 774\n5\n-656 128 631\n597 -220 999\n-399 793 155\n-293 -363 1000\n-557 -914 1000", "output": "49" }, { "input": "-210 783 -260 833\n10\n406 551 1000\n372 -373 999\n-12 -532 999\n371 -30 999\n258 480 558\n648 -957 1000\n-716 654 473\n156 813 366\n-870 425 707\n-288 -426 1000", "output": "0" }, { "input": "671 244 771 1000\n20\n701 904 662\n170 -806 1000\n-330 586 1000\n466 467 205\n-736 266 999\n629 734 42\n-616 630 999\n-94 416 765\n-98 280 770\n288 597 384\n-473 266 999\n-330 969 999\n492 -445 713\n352 -967 1000\n401 -340 645\n400 -80 425\n-177 560 848\n361 -7 400\n-564 -807 1000\n621 333 51", "output": "20" }, { "input": "-343 -444 -419 -421\n30\n363 -249 790\n704 57 999\n-316 -305 119\n-778 -543 373\n-589 466 904\n516 -174 893\n-742 -662 390\n-382 825 1000\n520 -732 909\n-220 -985 555\n-39 -697 396\n-701 -882 520\n-105 227 691\n-113 -470 231\n-503 98 525\n236 69 759\n150 393 951\n414 381 1000\n849 530 999\n-357 485 905\n432 -616 794\n123 -465 467\n768 -875 1000\n61 -932 634\n375 -410 718\n-860 -624 477\n49 264 789\n-409 -874 429\n876 -169 999\n-458 345 767", "output": "42" }, { "input": "0 0 1 1\n1\n-1 -1000 1000", "output": "4" }, { "input": "1 1 1000 1000\n1\n50 50 1", "output": "3996" } ]
2,000
204,800
0
20,574
623
Electric Charges
[ "binary search", "dp" ]
null
null
Programmer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals. A laboratory unit is a plane with standard coordinate axes marked on it. Physicists from Moscow Institute of Physics and Technology charged the axes by large electric charges: axis *X* is positive and axis *Y* is negative. Experienced laboratory worker marked *n* points with integer coordinates (*x**i*,<=*y**i*) on the plane and stopped the time. Sasha should use "atomic tweezers" to place elementary particles in these points. He has an unlimited number of electrons (negatively charged elementary particles) and protons (positively charged elementary particles). He can put either an electron or a proton at each marked point. As soon as all marked points are filled with particles, laboratory worker will turn on the time again and the particles will come in motion and after some time they will stabilize in equilibrium. The objective of the laboratory work is to arrange the particles in such a way, that the diameter of the resulting state (the maximum distance between the pairs of points of the set) is as small as possible. Since Sasha is a programmer, he naively thinks that all the particles will simply "fall" into their projections on the corresponding axes: electrons will fall on axis *X*, while protons will fall on axis *Y*. As we are programmers too, we will consider the same model as Sasha. That is, a particle gets from point (*x*,<=*y*) to point (*x*,<=0) if it is an electron and to point (0,<=*y*) if it is a proton. As the laboratory has high background radiation and Sasha takes care of his laptop, he did not take it with him, and now he can't write a program that computes the minimum possible diameter of the resulting set. Therefore, you will have to do it for him. Print a square of the minimum possible diameter of the set.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of points marked on the plane. Each of the next *n* lines contains two integers *x**i* and *y**i* (<=-<=108<=≤<=*x**i*,<=*y**i*<=≤<=108) — the coordinates of the *i*-th point. It is guaranteed that no two points coincide.
Print a single integer — the square of the minimum possible diameter of the set.
[ "3\n1 10\n1 20\n1 30\n", "2\n1 10\n10 1\n" ]
[ "0\n", "2\n" ]
In the first sample Sasha puts electrons at all points, all particles eventually fall at a single point (1, 0). In the second sample Sasha puts an electron at point (1, 10), and a proton at point (10, 1). The result is a set of two points (1, 0) and (0, 1), which has a diameter of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bfe16f27ebc966df6f10ba356a1547b6e7242dd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
[ { "input": "3\n1 10\n1 20\n1 30", "output": "0" }, { "input": "2\n1 10\n10 1", "output": "2" }, { "input": "10\n1 6\n2 2\n-1 9\n-8 8\n-4 10\n-10 -6\n5 -1\n-3 -7\n-4 3\n9 4", "output": "100" }, { "input": "18\n-14 -745\n87 -4611\n89 -3748\n-77 273\n-21 -4654\n-86 -5108\n-70 3232\n25 -6313\n-71 -4846\n88 -1894\n-65 9707\n-51 -3290\n-19 -580\n-62 -2408\n1 -6832\n52 -4279\n21 -7322\n55 9392", "output": "30625" }, { "input": "12\n996 -72\n-145 68\n-514 79\n743 -96\n765 -52\n720 86\n-615 -57\n690 81\n-885 -5\n265 4\n-533 -23\n-693 -72", "output": "33124" }, { "input": "17\n-10 -36\n1 -10\n53 -2\n-23 5\n7 -19\n10 -33\n9 78\n-7 -3\n70 2\n5 -1\n7 -93\n9 -2\n2 -82\n16 2\n8 48\n52 2\n-76 -6", "output": "400" }, { "input": "16\n22 -370\n90 -8\n46 235\n336 51\n-447 5\n-105 -53\n212 87\n245 -90\n7 -63\n-44 -56\n-426 2\n-485 26\n-31 37\n-93 -410\n39 -108\n-202 -85", "output": "31329" }, { "input": "20\n857 286\n-653 -1302\n761 1685\n-783 -94\n208 -1381\n-229 -1333\n664 -296\n-1157 -189\n-2124 956\n837 -2086\n-1872 16\n474 797\n-984 -1224\n188 -1104\n2017 850\n-2211 222\n955 -2275\n-100 1708\n152 199\n-1340 -462", "output": "3759721" }, { "input": "10\n-594331 634748\n-438198 823828\n-1450064 -200132\n-832505 -718261\n-830561 867133\n1104363 -90870\n696748 -925127\n-755002 -110409\n-1721605 -870036\n344418 -761993", "output": "1545691540850" }, { "input": "14\n17434000 -29825809\n3349481 -27203247\n79083185 21513757\n-53052180 -83100420\n543299 -43187896\n-30785780 18551223\n9271044 -77707401\n65259560 -30266930\n-65672492 -20223080\n-37161541 -4703585\n99525015 2119039\n-13413357 -52673928\n83407206 -6063556\n3333364 -56550616", "output": "3884184249754176" }, { "input": "14\n3 44\n-99 -1\n-11 -9\n3 -57\n83 5\n4 -45\n4 -62\n46 -4\n36 6\n3 -22\n-69 -2\n3 75\n-3 -37\n46 -8", "output": "225" }, { "input": "19\n174 17\n-65 458\n460 -6\n141 8\n53 -441\n-71 -1\n415 -3\n46 -337\n-4 319\n307 -17\n-84 208\n-428 5\n-91 336\n-301 -12\n40 -5\n218 -13\n423 8\n-110 -6\n-24 -20", "output": "20736" }, { "input": "1\n42 100000000", "output": "0" }, { "input": "2\n-100000000 100000000\n1 -35", "output": "10000000000000001" }, { "input": "4\n100000000 100000000\n100000000 -100000000\n-100000000 100000000\n-100000000 -100000000", "output": "40000000000000000" }, { "input": "5\n25367999 -12921025\n88213873 -62251536\n29698878 -60793556\n69696879 -57681615\n4150867 -42378134", "output": "2433499315521121" }, { "input": "10\n52725948 -50921428\n22965991 -854605\n19081182 -54959209\n46359108 -78898591\n12280123 -98335714\n96326175 -61967241\n36354396 -64148342\n8164394 -70121916\n94434246 -46350207\n6706998 -57888515", "output": "5989105851707745" }, { "input": "10\n6 -50790171\n-2 218761\n-1 6364807\n-5 -96100004\n6 13672536\n-31685933 2\n-87361182 6\n6 79979970\n-4 20223120\n3 -33646313", "output": "121" }, { "input": "20\n544 -4618768\n8229332 791\n-19838403 912\n714 81730211\n685 86922721\n976 74377764\n691 -75144278\n767 -14551029\n592 52209892\n868 -16289108\n652 44552695\n963 -60723986\n-98704842 668\n900 28147242\n49913319 735\n534 -69309373\n841 -1918555\n571 -70059713\n821 -70358434\n605 81860132", "output": "1784320" }, { "input": "9\n-99999999 -99999999\n-99999999 -100000000\n99999999 99999999\n100000000 -99999999\n-99999999 100000000\n-100000000 100000000\n-99999999 99999999\n99999999 100000000\n99999999 -99999999", "output": "39999999600000001" }, { "input": "1\n100000000 100000000", "output": "0" }, { "input": "2\n100000000 100000000\n100000000 -100000000", "output": "0" }, { "input": "2\n-100000000 100000000\n100000000 100000000", "output": "0" }, { "input": "4\n100000000 -100000000\n-100000000 -100000000\n100000000 100000000\n-100000000 100000000", "output": "40000000000000000" }, { "input": "5\n46954043 53045957\n86519258 13480742\n12941533 87058467\n53212386 46787614\n57186237 42813763", "output": "2981356830435938" }, { "input": "5\n635720 157\n702516 142\n286757 348\n756308 132\n751562 133", "output": "46656" }, { "input": "5\n99857497 5336678\n78010540 62564811\n51604294 85656271\n88779790 46023350\n99288757 11905571", "output": "2328371599759209" }, { "input": "10\n-88884243 11115757\n-38391053 61608947\n-67774598 32225402\n-62658046 37341954\n-32014021 67985979\n-49601142 50398858\n-13046283 86953717\n-91869075 8130925\n-85955759 14044241\n-81154428 18845572", "output": "3854694816242280" }, { "input": "10\n484 206445\n417 239562\n135 736435\n100 995898\n669 149428\n148148 675\n162 615397\n400 249827\n102 973876\n173 575939", "output": "903186" }, { "input": "10\n22080299 -97531842\n99982368 -1877760\n82007780 -57225204\n95632512 -29230506\n40850397 -91275654\n39838009 -91722041\n2527763 -99968046\n30181880 -95336530\n59384374 -80458039\n32198040 -94674633", "output": "6801227848213492" }, { "input": "13\n-2 0\n0 2\n2 0\n-1 1\n0 0\n0 -1\n1 -1\n0 -2\n0 1\n1 0\n1 1\n-1 0\n-1 -1", "output": "4" }, { "input": "81\n-2 -1\n-3 1\n2 1\n1 0\n-3 -1\n1 2\n-1 1\n-3 3\n0 -3\n3 1\n-1 -2\n2 3\n2 2\n1 -2\n3 -1\n-1 -4\n1 3\n3 3\n2 -3\n0 -4\n1 -1\n0 3\n-2 0\n-4 1\n0 -5\n-4 3\n2 -4\n4 2\n-3 -4\n-3 4\n-3 0\n-2 4\n1 1\n4 1\n-4 0\n0 -1\n0 4\n4 0\n-4 -1\n3 -4\n-2 1\n3 2\n0 2\n-1 0\n-3 -2\n3 -3\n0 1\n2 0\n2 -1\n-2 3\n1 -3\n-1 -1\n-2 -3\n3 4\n2 -2\n1 -4\n3 -2\n4 -1\n4 -3\n1 4\n3 0\n-3 -3\n-1 2\n-5 0\n-2 -2\n-4 -2\n4 3\n0 -2\n-4 -3\n-4 2\n-2 2\n-1 -3\n5 0\n-1 3\n2 4\n0 5\n-2 -4\n-3 2\n4 -2\n0 0\n-1 4", "output": "36" }, { "input": "21\n5 0\n2 2\n0 1\n0 2\n2 0\n4 0\n1 1\n3 0\n3 2\n1 0\n1 2\n3 1\n1 3\n2 3\n0 3\n0 5\n0 4\n0 0\n2 1\n1 4\n4 1", "output": "8" }, { "input": "66\n3 0\n2 7\n0 5\n5 1\n6 4\n0 2\n3 1\n3 4\n4 1\n7 0\n10 0\n0 6\n7 1\n7 2\n5 0\n1 1\n6 0\n2 3\n3 5\n0 10\n3 6\n4 0\n1 8\n2 2\n1 6\n6 2\n0 3\n0 9\n2 0\n8 1\n4 4\n2 4\n1 3\n1 9\n3 3\n9 0\n7 3\n2 8\n4 5\n0 8\n5 4\n3 7\n8 2\n5 5\n1 4\n1 5\n4 2\n4 3\n3 2\n1 7\n6 1\n1 0\n0 0\n6 3\n2 1\n8 0\n9 1\n0 1\n0 7\n2 6\n1 2\n4 6\n0 4\n5 2\n5 3\n2 5", "output": "41" }, { "input": "1\n-32222 98", "output": "0" }, { "input": "1\n-1 -1", "output": "0" }, { "input": "3\n10 10\n10 20\n20 10", "output": "100" }, { "input": "2\n5 5\n1000 1000", "output": "990025" }, { "input": "2\n1 1\n-1 -1", "output": "2" }, { "input": "3\n-1 7\n8 2\n5 -3", "output": "25" }, { "input": "11\n86252958 -8453022\n20979758 -6495116\n-78204472 -7527274\n66289339 9784937\n-15941740 412492\n58997345 9109992\n90222551 -4687529\n12732746 9064427\n-85673028 -8886670\n37578830 -8279001\n59212726 788692", "output": "348628907962449" }, { "input": "10\n-8055884 -28179455\n-9336503 98988615\n19433716 53975448\n58614993 -69147933\n-53287109 35247908\n-75259375 94365460\n43802543 96926279\n53740260 -15640682\n-97179864 -25661311\n-17951783 -51266382", "output": "14175740317838724" }, { "input": "14\n-66 7\n2 71\n3 -36\n5 26\n-21 6\n41 -5\n32 -2\n-26 -5\n2 -60\n86 -6\n34 -8\n-24 9\n-75 -8\n-92 1", "output": "289" }, { "input": "16\n-68 259\n-90 65\n65 454\n242 74\n358 -86\n-441 -80\n44 -422\n67 178\n15 -425\n88 109\n-66 -246\n-24 285\n-131 60\n-152 52\n-18 -129\n204 -11", "output": "25600" }, { "input": "10\n622 1946\n422 1399\n165 -203\n-903 -2133\n-1152 964\n-842 -1150\n1849 5\n-11 471\n1966 -379\n67 776", "output": "2325625" }, { "input": "15\n-128458 573454\n751293 1852055\n1546241 438377\n642614 -1677745\n1768534 -919019\n205820 357582\n-877851 792499\n313687 -491257\n1334705 533906\n-136082 -42692\n-1948794 304398\n-602602 -557714\n-847986 -1248897\n-1915382 76977\n-1118694 -705173", "output": "2654110172736" }, { "input": "12\n-3979966 -64785636\n54498897 11255152\n52322390 -67233168\n32879609 -16571480\n50371826 19645523\n-68348841 22478633\n3424248 90696875\n-42961539 -43574884\n36163900 62201849\n-53982801 42129019\n-55804340 70782236\n13142275 39447287", "output": "8458157168697600" }, { "input": "18\n3 -55\n-54 -2\n2 -42\n-8 68\n82 4\n-2 -73\n1 44\n-29 3\n-48 -3\n91 4\n4 -16\n24 -2\n-5 36\n46 -2\n24 -3\n76 4\n51 1\n-76 -1", "output": "144" }, { "input": "17\n337 -16\n-53 16\n-247 -10\n-88 -224\n62 -426\n67 2\n320 19\n239 3\n82 269\n76 -237\n-8 -1\n195 -18\n82 131\n31 -276\n48 -2\n-66 228\n-463 -18", "output": "28900" }, { "input": "18\n745 1353\n248 -68\n-636 -647\n-335 712\n270 5\n-402 128\n29 -1871\n648 -182\n-403 -469\n616 -1341\n898 2358\n361 2296\n1074 9\n-452 1480\n993 -2039\n-491 1690\n-656 1759\n2087 30", "output": "2719201" }, { "input": "14\n88 242\n-1763 920\n-160 -1921\n2368 562\n123 -2003\n165 656\n-20 2333\n-1786 -771\n-1648 -242\n-1842 150\n-2078 -428\n-1865 860\n-140 -311\n-2453 571", "output": "2859481" }, { "input": "20\n-691166 1857437\n308748 757809\n-908302 1208183\n213496 81845\n1882976 -9001\n-1459847 -58718\n902599 -1235585\n499018 1161414\n658542 -86418\n-803191 -1737709\n1682313 -49632\n-166179 1387536\n-203007 18260\n1579851 -79901\n128002 906577\n-57584 -70366\n-493935 -15924\n1900231 6581\n894309 851468\n954724 1678804", "output": "3090265147225" }, { "input": "16\n840204 -563586\n-1482 -306408\n-45167 -1969028\n73804 525097\n69604 198191\n65491 -1345144\n-1609018 -285663\n404867 -210266\n255601 832851\n4999 1764313\n541223 736278\n-20170 1911573\n-281805 251017\n52312 1029263\n72529 -38660\n32894 1380373", "output": "663578047609" }, { "input": "12\n-44489842 18113240\n-2081704 -1338672\n-3803741 36271320\n40239596 12868007\n-97939521 33357113\n60348507 -45490328\n59546944 -64898105\n1073008 86908503\n5160027 39955776\n1531464 64470852\n51713010 -35029180\n43419463 -8413764", "output": "4754639284823818" }, { "input": "14\n-4788460 -58174715\n3667616 -42701029\n58801800 -67135593\n-27712521 33013050\n70162832 21395449\n430668 18516811\n27425137 13550355\n73782530 -33761391\n-3092363 29002645\n-79768595 21183779\n-434563 -46164603\n3072648 -44934958\n2954859 6384655\n-9768771 -50164937", "output": "4701923207266041" }, { "input": "1\n0 0", "output": "0" }, { "input": "2\n0 0\n-1 5", "output": "1" } ]
530
20,684,800
0
20,579
375
Tree and Queries
[ "data structures", "dfs and similar", "trees" ]
null
null
You have a rooted tree consisting of *n* vertices. Each vertex of the tree has some color. We will assume that the tree vertices are numbered by integers from 1 to *n*. Then we represent the color of vertex *v* as *c**v*. The tree root is a vertex with number 1. In this problem you need to answer to *m* queries. Each query is described by two integers *v**j*,<=*k**j*. The answer to query *v**j*,<=*k**j* is the number of such colors of vertices *x*, that the subtree of vertex *v**j* contains at least *k**j* vertices of color *x*. You can find the definition of a rooted tree by the following link: http://en.wikipedia.org/wiki/Tree_(graph_theory).
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=105). The next line contains a sequence of integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). The next *n*<=-<=1 lines contain the edges of the tree. The *i*-th line contains the numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*) — the vertices connected by an edge of the tree. Next *m* lines contain the queries. The *j*-th line contains two integers *v**j*,<=*k**j* (1<=≤<=*v**j*<=≤<=*n*; 1<=≤<=*k**j*<=≤<=105).
Print *m* integers — the answers to the queries in the order the queries appear in the input.
[ "8 5\n1 2 2 3 3 2 3 3\n1 2\n1 5\n2 3\n2 4\n5 6\n5 7\n5 8\n1 2\n1 3\n1 4\n2 3\n5 3\n", "4 1\n1 2 3 4\n1 2\n2 3\n3 4\n1 1\n" ]
[ "2\n2\n1\n0\n1\n", "4\n" ]
A subtree of vertex *v* in a rooted tree with root *r* is a set of vertices {*u* : *dist*(*r*, *v*) + *dist*(*v*, *u*) = *dist*(*r*, *u*)}. Where *dist*(*x*, *y*) is the length (in edges) of the shortest path between vertices *x* and *y*.
[ { "input": "8 5\n1 2 2 3 3 2 3 3\n1 2\n1 5\n2 3\n2 4\n5 6\n5 7\n5 8\n1 2\n1 3\n1 4\n2 3\n5 3", "output": "2\n2\n1\n0\n1" }, { "input": "4 1\n1 2 3 4\n1 2\n2 3\n3 4\n1 1", "output": "4" } ]
1,000
5,120,000
0
20,632
518
Anya and Smartphone
[ "constructive algorithms", "data structures", "implementation" ]
null
null
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly *n* applications, each application has its own icon. The icons are located on different screens, one screen contains *k* icons. The icons from the first to the *k*-th one are located on the first screen, from the (*k*<=+<=1)-th to the 2*k*-th ones are on the second screen and so on (the last screen may be partially empty). Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen *t*, Anya needs to make the following gestures: first she scrolls to the required screen number *t*, by making *t*<=-<=1 gestures (if the icon is on the screen *t*), and then make another gesture — press the icon of the required application exactly once to launch it. After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1. All applications are numbered from 1 to *n*. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change. Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order? Note that one application may be launched multiple times.
The first line of the input contains three numbers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen. The next line contains *n* integers, permutation *a*1,<=*a*2,<=...,<=*a**n* — the initial order of icons from left to right in the menu (from the first to the last one), *a**i* —  is the id of the application, whose icon goes *i*-th in the menu. Each integer from 1 to *n* occurs exactly once among *a**i*. The third line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m*(1<=≤<=*b**i*<=≤<=*n*) — the ids of the launched applications in the planned order. One application may be launched multiple times.
Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.
[ "8 3 3\n1 2 3 4 5 6 7 8\n7 8 1\n", "5 4 2\n3 1 5 2 4\n4 4 4 4\n" ]
[ "7\n", "8\n" ]
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8. After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch it Anya makes 3 gestures. After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures. After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture. In total, Anya makes 7 gestures.
[ { "input": "8 3 3\n1 2 3 4 5 6 7 8\n7 8 1", "output": "7" }, { "input": "5 4 2\n3 1 5 2 4\n4 4 4 4", "output": "8" }, { "input": "10 10 3\n1 2 3 4 5 6 7 8 9 10\n2 3 4 5 6 7 8 9 10 1", "output": "25" }, { "input": "10 12 3\n6 1 2 9 3 10 8 5 7 4\n3 9 9 4 8 2 3 8 10 8 3 4", "output": "29" }, { "input": "16 12 8\n6 11 12 5 1 10 16 3 13 15 9 4 8 2 14 7\n6 13 8 12 8 15 12 16 8 11 3 16", "output": "18" }, { "input": "4 3 5\n3 1 4 2\n4 2 4", "output": "3" }, { "input": "4 2 15\n2 4 3 1\n1 2", "output": "2" }, { "input": "71 96 75634\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\n27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26", "output": "96" }, { "input": "71 81 2149\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 29 28 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\n29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29", "output": "81" } ]
358
15,769,600
3
20,639
374
Inna and Dima
[ "dfs and similar", "dp", "graphs", "implementation" ]
null
null
Inna and Dima bought a table of size *n*<=×<=*m* in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A". Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows: 1. initially, Inna chooses some cell of the table where letter "D" is written; 1. then Inna can move to some side-adjacent table cell that contains letter "I"; then from this cell she can go to one of the side-adjacent table cells that contains the written letter "M"; then she can go to a side-adjacent cell that contains letter "A". Then Inna assumes that she has gone through her sweetheart's name; 1. Inna's next move can be going to one of the side-adjacent table cells that contains letter "D" and then walk on through name DIMA in the similar manner. Inna never skips a letter. So, from the letter "D" she always goes to the letter "I", from the letter "I" she always goes the to letter "M", from the letter "M" she always goes to the letter "A", and from the letter "A" she always goes to the letter "D". Depending on the choice of the initial table cell, Inna can go through name DIMA either an infinite number of times or some positive finite number of times or she can't go through his name once. Help Inna find out what maximum number of times she can go through name DIMA.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103). Then follow *n* lines that describe Inna and Dima's table. Each line contains *m* characters. Each character is one of the following four characters: "D", "I", "M", "A". Note that it is not guaranteed that the table contains at least one letter "D".
If Inna cannot go through name DIMA once, print on a single line "Poor Dima!" without the quotes. If there is the infinite number of names DIMA Inna can go through, print "Poor Inna!" without the quotes. Otherwise print a single integer — the maximum number of times Inna can go through name DIMA.
[ "1 2\nDI\n", "2 2\nMA\nID\n", "5 5\nDIMAD\nDIMAI\nDIMAM\nDDMAA\nAAMID\n" ]
[ "Poor Dima!\n", "Poor Inna!\n", "4\n" ]
Notes to the samples: In the first test sample, Inna cannot go through name DIMA a single time. In the second test sample, Inna can go through the infinite number of words DIMA. For that, she should move in the clockwise direction starting from the lower right corner. In the third test sample the best strategy is to start from the cell in the upper left corner of the table. Starting from this cell, Inna can go through name DIMA four times.
[ { "input": "1 2\nDI", "output": "Poor Dima!" }, { "input": "2 2\nMA\nID", "output": "Poor Inna!" }, { "input": "5 5\nDIMAD\nDIMAI\nDIMAM\nDDMAA\nAAMID", "output": "4" }, { "input": "1 1\nI", "output": "Poor Dima!" }, { "input": "5 5\nDIMAD\nADDDI\nMDDDM\nIDDDA\nDAMID", "output": "Poor Inna!" }, { "input": "5 5\nAAAAA\nAAAAA\nAAAAA\nAAAAA\nAAAAA", "output": "Poor Dima!" }, { "input": "1 1\nD", "output": "Poor Dima!" }, { "input": "1 4\nDIMA", "output": "1" }, { "input": "4 1\nD\nI\nM\nA", "output": "1" }, { "input": "2 2\nDI\nAM", "output": "Poor Inna!" }, { "input": "2 2\nDI\nMA", "output": "Poor Dima!" }, { "input": "5 5\nDIADD\nDMADD\nDDDID\nAMMMD\nMIDAD", "output": "3" }, { "input": "10 10\nDIDDIMDIDD\nDMDDAADIDD\nDADDDDDMDD\nDDDDDDDADD\nDIDDDDIDDD\nDMDDDDMDDD\nDADDDDADID\nDDIMDDDDMD\nDDAADDIAAD\nDDDDDDMADD", "output": "4" }, { "input": "14 34\nDDDDDDDDDDDDIMADDDDDDDDDDDDDDDIMAD\nDDDDDDIMADDDDDDDDDDDDDDDDDDDDDIMAD\nDDDDDDDDDDDDDIDDDDDDDDDDDIDIMIDIMA\nDDDDDDIMDDDDDDDDDDDDDIDDDDDDDDDDDD\nDDDDDDDDDDDDDDDDDMADDDDDDDDDDDDDMD\nDDDDDDIMIDDDDDDDDDDDDIMIDIMIDDDIDD\nDDDDDDDDDDDDDDDDDMIMDDDDIMDDIMADIM\nDDDDDDDDDDDADIMADIDDDDDDIDIMADADDD\nDDDDDDDDIDDDDDDDDDDDDDDDDMADIMDDAM\nDMDDDDDDDDDDDDIMADIMDDDDDMADDDMIDI\nDDDDDDDDIMDDDDDDDDDDIDIMADIDDDDMAD\nDDDIDDDDDDDDDDMIDIMADADADIMADIMAAD\nDDDADDDDDDDDDIMIMADIDDMDMAMIDMDDDM\nDIDIDDDDDDIIAAMMAIMIDADAAAMDIDDDID", "output": "Poor Inna!" }, { "input": "9 6\nDIMADD\nIDDDDD\nMDDDDD\nADDDDD\nDIMADD\nIDDDDD\nMDDDDD\nADDDDD\nDDDDDD", "output": "2" }, { "input": "1 1\nM", "output": "Poor Dima!" }, { "input": "1 1\nA", "output": "Poor Dima!" }, { "input": "1 4\nIMAD", "output": "Poor Dima!" } ]
0
0
-1
20,657
757
Felicity is Coming!
[ "data structures", "hashing", "sortings", "strings" ]
null
null
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has *n* gyms. The *i*-th gym has *g**i* Pokemon in it. There are *m* distinct Pokemon types in the Himalayan region numbered from 1 to *m*. There is a special evolution camp set up in the fest which claims to evolve any Pokemon. The type of a Pokemon could change after evolving, subject to the constraint that if two Pokemon have the same type before evolving, they will have the same type after evolving. Also, if two Pokemon have different types before evolving, they will have different types after evolving. It is also possible that a Pokemon has the same type before and after evolving. Formally, an evolution plan is a permutation *f* of {1,<=2,<=...,<=*m*}, such that *f*(*x*)<==<=*y* means that a Pokemon of type *x* evolves into a Pokemon of type *y*. The gym leaders are intrigued by the special evolution camp and all of them plan to evolve their Pokemons. The protocol of the mountain states that in each gym, for every type of Pokemon, the number of Pokemon of that type before evolving any Pokemon should be equal the number of Pokemon of that type after evolving all the Pokemons according to the evolution plan. They now want to find out how many distinct evolution plans exist which satisfy the protocol. Two evolution plans *f*1 and *f*2 are distinct, if they have at least one Pokemon type evolving into a different Pokemon type in the two plans, i. e. there exists an *i* such that *f*1(*i*)<=≠<=*f*2(*i*). Your task is to find how many distinct evolution plans are possible such that if all Pokemon in all the gyms are evolved, the number of Pokemon of each type in each of the gyms remains the same. As the answer can be large, output it modulo 109<=+<=7.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=106) — the number of gyms and the number of Pokemon types. The next *n* lines contain the description of Pokemons in the gyms. The *i*-th of these lines begins with the integer *g**i* (1<=≤<=*g**i*<=≤<=105) — the number of Pokemon in the *i*-th gym. After that *g**i* integers follow, denoting types of the Pokemons in the *i*-th gym. Each of these integers is between 1 and *m*. The total number of Pokemons (the sum of all *g**i*) does not exceed 5·105.
Output the number of valid evolution plans modulo 109<=+<=7.
[ "2 3\n2 1 2\n2 2 3\n", "1 3\n3 1 2 3\n", "2 4\n2 1 2\n3 2 3 4\n", "2 2\n3 2 2 1\n2 1 2\n", "3 7\n2 1 2\n2 3 4\n3 5 6 7\n" ]
[ "1\n", "6\n", "2\n", "1\n", "24\n" ]
In the first case, the only possible evolution plan is: In the second case, any permutation of (1,  2,  3) is valid. In the third case, there are two possible plans: In the fourth case, the only possible evolution plan is:
[ { "input": "2 3\n2 1 2\n2 2 3", "output": "1" }, { "input": "1 3\n3 1 2 3", "output": "6" }, { "input": "2 4\n2 1 2\n3 2 3 4", "output": "2" }, { "input": "2 2\n3 2 2 1\n2 1 2", "output": "1" }, { "input": "3 7\n2 1 2\n2 3 4\n3 5 6 7", "output": "24" }, { "input": "10 100\n16 25 7 48 43 16 23 66 3 17 31 64 27 7 17 11 60\n62 76 82 99 77 19 26 66 46 9 54 77 8 34 76 70 48 53 35 69 29 84 22 16 53 36 27 24 81 2 86 67 45 22 54 96 37 8 3 22 9 30 63 61 86 19 16 47 3 72 39 36 1 50 1 18 7 44 52 66 90 3 63\n3 22 61 39\n9 28 69 91 62 98 23 45 9 10\n2 42 20\n3 90 46 55\n2 71 9\n1 7\n1 44\n1 94", "output": "732842622" }, { "input": "10 100\n26 69 60 30 8 89 7 54 66 100 75 4 17 48 40 20 78 56 94 23 48 55 40 9 23 55 30\n3 94 78 64\n50 57 81 62 43 95 4 22 29 9 67 17 82 13 69 13 30 85 3 44 5 85 70 4 50 9 30 85 67 64 7 59 98 78 68 61 63 35 35 94 87 37 18 12 83 26 77 48 67 72 82\n7 59 52 92 41 37 11 17\n1 65\n2 75 82\n4 28 66 33 70\n1 81\n2 4 31\n1 12", "output": "510562296" }, { "input": "10 100\n53 9 10 7 62 66 82 38 22 82 14 48 7 77 51 37 5 10 12 68 88 36 49 80 80 71 48 72 6 49 87 21 48 17 75 43 25 75 55 36 10 82 2 28 14 53 25 66 7 70 58 53 74 86\n32 84 95 55 32 79 75 12 94 80 13 29 49 87 26 69 51 73 52 30 87 17 75 60 1 82 15 34 26 83 95 60 13\n8 61 39 91 78 19 32 91 26\n1 22\n1 87\n1 55\n1 87\n1 39\n1 70\n1 40", "output": "51603121" }, { "input": "10 100\n46 62 64 81 19 35 65 30 81 64 54 95 98 18 78 54 19 68 34 16 37 22 55 63 41 87 65 33 22 15 5 99 35 49 79 47 54 50 97 54 3 100 86 91 3 24 36\n36 25 29 71 1 64 18 92 22 86 76 91 87 79 29 33 61 36 87 22 10 25 7 96 56 67 38 66 43 35 55 54 90 65 83 56 11\n4 36 73 34 11\n2 28 94\n2 97 100\n5 52 69 13 11 78\n1 78\n2 71 8\n1 33\n1 11", "output": "166939681" }, { "input": "10 100\n73 10 13 55 73 7 41 18 37 47 97 43 96 52 97 75 42 23 52 61 89 100 64 43 98 95 86 86 39 85 31 74 30 82 84 51 84 21 35 61 3 15 71 45 99 12 48 54 39 96 85 57 45 35 92 57 65 97 42 91 86 47 64 35 67 52 11 34 24 41 45 42 87 50\n9 77 91 42 99 98 20 43 82 35\n10 96 48 77 64 81 66 3 38 58 9\n1 61\n2 47 35\n1 7\n1 61\n1 70\n1 88\n1 83", "output": "8656282" }, { "input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "1" }, { "input": "100 2\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 1\n1 1\n1 2\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 2\n1 1\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 2", "output": "1" }, { "input": "2 1000000\n1 1\n1 2", "output": "44455173" }, { "input": "5 262143\n1 1\n1 2\n1 3\n1 4\n1 5", "output": "943283753" }, { "input": "65 3\n1 1\n1 1\n1 1\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n1 1\n2 1 2\n1 1\n1 1\n1 1\n1 1\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n1 1\n1 1\n2 1 2", "output": "1" }, { "input": "1 1000000\n1 1", "output": "128233642" }, { "input": "20 3\n4 1 3 3 3\n6 1 3 3 3 3 3\n1 1\n2 1 3\n2 1 2\n1 1\n8 1 2 2 2 2 2 2 2\n3 1 3 3\n3 1 3 3\n5 1 2 2 2 2\n10 1 3 3 3 3 3 3 3 3 3\n15 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n10 1 2 2 2 2 2 2 2 2 2\n3 1 2 2\n1 1\n1 1\n7 1 3 3 3 3 3 3\n1 1\n1 1\n1 1", "output": "1" }, { "input": "20 3\n1 1\n5 1 2 2 2 2\n6 1 3 3 3 3 3\n2 1 2\n3 1 3 3\n3 1 3 3\n4 1 3 3 3\n2 1 3\n3 1 3 3\n5 1 2 2 2 2\n3 1 3 3\n7 1 2 2 2 2 2 2\n3 1 2 2\n6 1 3 3 3 3 3\n3 1 3 3\n2 1 2\n3 1 3 3\n2 1 2\n1 1\n1 1", "output": "1" }, { "input": "65 3\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n2 1 2", "output": "1" }, { "input": "20 3\n2 1 2\n8 1 3 3 3 3 3 3 3\n4 1 3 3 3\n2 1 2\n3 1 2 2\n9 1 3 3 3 3 3 3 3 3\n2 1 2\n3 1 2 2\n2 1 2\n3 1 3 3\n9 1 3 3 3 3 3 3 3 3\n2 1 2\n15 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n2 1 3\n4 1 3 3 3\n2 1 2\n1 1\n1 1\n1 1\n1 1", "output": "1" }, { "input": "20 3\n2 1 3\n3 1 2 2\n5 1 3 3 3 3\n3 1 2 2\n1 1\n5 1 3 3 3 3\n4 1 3 3 3\n5 1 3 3 3 3\n4 1 3 3 3\n3 1 2 2\n2 1 3\n5 1 3 3 3 3\n5 1 2 2 2 2\n6 1 2 2 2 2 2\n3 1 2 2\n5 1 3 3 3 3\n5 1 2 2 2 2\n3 1 3 3\n4 1 2 2 2\n2 1 2", "output": "1" }, { "input": "3 3\n6 1 1 1 1 1 1\n6 2 2 2 2 2 2\n2 1 1", "output": "1" } ]
1,372
111,001,600
-1
20,682
392
Three Arrays
[ "data structures" ]
null
null
There are three arrays *a*, *b* and *c*. Each of them consists of *n* integers. SmallY wants to find three integers *u*, *v*, *w* (0<=≤<=*u*,<=*v*,<=*w*<=≤<=*n*) such that the following condition holds: each number that appears in the union of *a*, *b* and *c*, appears either in the first *u* elements of *a*, or in the first *v* elements of *b*, or in the first *w* elements of *c*. Of course, SmallY doesn't want to have huge numbers *u*, *v* and *w*, so she wants sum *u*<=+<=*v*<=+<=*w* to be as small as possible. Please, help her to find the minimal possible sum of *u*<=+<=*v*<=+<=*w*.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — array *a*. The third line contains the description of array *b* in the same format. The fourth line contains the description of array *c* in the same format. The following constraint holds: 1<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=109.
Print a single integer — the minimum possible sum of *u*<=+<=*v*<=+<=*w*.
[ "3\n1 1 101\n1 2 1\n3 2 1\n", "5\n1 1 2 2 3\n2 2 4 3 3\n3 3 1 1 1\n" ]
[ "5", "5" ]
In the first example you should choose *u* = 3, *v* = 0, *w* = 2. In the second example you should choose *u* = 1, *v* = 3, *w* = 1.
[]
109
0
0
20,760
916
Jamie and Interesting Graph
[ "constructive algorithms", "graphs", "shortest paths" ]
null
null
Jamie has recently found undirected weighted graphs with the following properties very interesting: - The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integers and are in range [1,<=109] inclusive. - The length of shortest path from 1 to *n* is a prime number. - The sum of edges' weights in the minimum spanning tree (MST) of the graph is a prime number. - The graph contains no loops or multi-edges. If you are not familiar with some terms from the statement you can find definitions of them in notes section. Help Jamie construct any graph with given number of vertices and edges that is interesting!
First line of input contains 2 integers *n*, *m*  — the required number of vertices and edges.
In the first line output 2 integers *sp*, *mstw* (1<=≤<=*sp*,<=*mstw*<=≤<=1014) — the length of the shortest path and the sum of edges' weights in the minimum spanning tree. In the next *m* lines output the edges of the graph. In each line output 3 integers *u*, *v*, *w* (1<=≤<=*u*,<=*v*<=≤<=*n*,<=1<=≤<=*w*<=≤<=109) describing the edge connecting *u* and *v* and having weight *w*.
[ "4 4\n", "5 4\n" ]
[ "7 7\n1 2 3\n2 3 2\n3 4 2\n2 4 4\n", "7 13\n1 2 2\n1 3 4\n1 4 3\n4 5 4\n" ]
The graph of sample 1: <img class="tex-graphics" src="https://espresso.codeforces.com/42f9750de41b0d9a6b21e8615170113cfe19b0f2.png" style="max-width: 100.0%;max-height: 100.0%;"/> Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*). Definition of terms used in the problem statement: A shortest path in an undirected graph is a sequence of vertices (*v*<sub class="lower-index">1</sub>, *v*<sub class="lower-index">2</sub>, ... , *v*<sub class="lower-index">*k*</sub>) such that *v*<sub class="lower-index">*i*</sub> is adjacent to *v*<sub class="lower-index">*i* + 1</sub> 1 ≤ *i* &lt; *k* and the sum of weight <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e7f62cfd5c2c3b81dc80aaf2f512898495354f03.png" style="max-width: 100.0%;max-height: 100.0%;"/> is minimized where *w*(*i*, *j*) is the edge weight between *i* and *j*. ([https://en.wikipedia.org/wiki/Shortest_path_problem](https://en.wikipedia.org/wiki/Shortest_path_problem)) A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. ([https://en.wikipedia.org/wiki/Prime_number](https://en.wikipedia.org/wiki/Prime_number)) A minimum spanning tree (MST) is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight. ([https://en.wikipedia.org/wiki/Minimum_spanning_tree](https://en.wikipedia.org/wiki/Minimum_spanning_tree)) [https://en.wikipedia.org/wiki/Multiple_edges](https://en.wikipedia.org/wiki/Multiple_edges)
[ { "input": "4 4", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000" }, { "input": "5 4", "output": "100003 100003\n1 2 100000\n2 3 1\n3 4 1\n4 5 1" }, { "input": "2 1", "output": "100003 100003\n1 2 100003" }, { "input": "10 19", "output": "100003 100003\n1 2 99995\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000\n1 8 1000000000\n1 9 1000000000\n1 10 1000000000\n2 4 1000000000\n2 5 1000000000" }, { "input": "9 18", "output": "100003 100003\n1 2 99996\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000\n1 8 1000000000\n1 9 1000000000\n2 4 1000000000\n2 5 1000000000\n2 6 1000000000" }, { "input": "92 280", "output": "100003 100003\n1 2 99913\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "89 3439", "output": "100003 100003\n1 2 99916\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "926 31057", "output": "100003 100003\n1 2 99079\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "753 98686", "output": "100003 100003\n1 2 99252\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9724 31045", "output": "100003 100003\n1 2 90281\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "8732 93395", "output": "100003 100003\n1 2 91273\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "80297 83088", "output": "100003 100003\n1 2 19708\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "86549 98929", "output": "100003 100003\n1 2 13456\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "87 109", "output": "100003 100003\n1 2 99918\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "95 3582", "output": "100003 100003\n1 2 99910\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "96 557", "output": "100003 100003\n1 2 99909\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "85 3106", "output": "100003 100003\n1 2 99920\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "98 367", "output": "100003 100003\n1 2 99907\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "77 2344", "output": "100003 100003\n1 2 99928\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "84 286", "output": "100003 100003\n1 2 99921\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "100 4665", "output": "100003 100003\n1 2 99905\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "94 350", "output": "100003 100003\n1 2 99911\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "100 4309", "output": "100003 100003\n1 2 99905\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "88 666", "output": "100003 100003\n1 2 99917\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "93 4075", "output": "100003 100003\n1 2 99912\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "100 342", "output": "100003 100003\n1 2 99905\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "84 3482", "output": "100003 100003\n1 2 99921\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "943 51645", "output": "100003 100003\n1 2 99062\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "808 63768", "output": "100003 100003\n1 2 99197\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "898 1882", "output": "100003 100003\n1 2 99107\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "662 76813", "output": "100003 100003\n1 2 99343\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "681 13806", "output": "100003 100003\n1 2 99324\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "991 92176", "output": "100003 100003\n1 2 99014\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "745 4986", "output": "100003 100003\n1 2 99260\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "954 94880", "output": "100003 100003\n1 2 99051\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "965 5451", "output": "100003 100003\n1 2 99040\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "943 95302", "output": "100003 100003\n1 2 99062\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "879 8524", "output": "100003 100003\n1 2 99126\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "953 98192", "output": "100003 100003\n1 2 99052\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "806 1771", "output": "100003 100003\n1 2 99199\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "790 97497", "output": "100003 100003\n1 2 99215\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9492 36483", "output": "100003 100003\n1 2 90513\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "5839 48668", "output": "100003 100003\n1 2 94166\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9029 15632", "output": "100003 100003\n1 2 90976\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "5127 53185", "output": "100003 100003\n1 2 94878\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "7044 33010", "output": "100003 100003\n1 2 92961\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9637 98924", "output": "100003 100003\n1 2 90368\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "7837 45130", "output": "100003 100003\n1 2 92168\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9603 99398", "output": "100003 100003\n1 2 90402\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9204 11722", "output": "100003 100003\n1 2 90801\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "6996 90227", "output": "100003 100003\n1 2 93009\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9897 21204", "output": "100003 100003\n1 2 90108\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9051 92600", "output": "100003 100003\n1 2 90954\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9880 13424", "output": "100003 100003\n1 2 90125\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9811 89446", "output": "100003 100003\n1 2 90194\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "90498 92256", "output": "100003 100003\n1 2 9507\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "99840 99968", "output": "100003 100003\n1 2 165\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1..." }, { "input": "92340 92571", "output": "100003 100003\n1 2 7665\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "99019 99681", "output": "100003 100003\n1 2 986\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1..." }, { "input": "93750 94653", "output": "100003 100003\n1 2 6255\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "99831 99956", "output": "100003 100003\n1 2 174\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1..." }, { "input": "95373 95859", "output": "100003 100003\n1 2 4632\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "95519 99837", "output": "100003 100003\n1 2 4486\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "94183 94638", "output": "100003 100003\n1 2 5822\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "84935 98326", "output": "100003 100003\n1 2 15070\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "94995 95821", "output": "100003 100003\n1 2 5010\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "88804 99911", "output": "100003 100003\n1 2 11201\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "93394 94036", "output": "100003 100003\n1 2 6611\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "97796 99885", "output": "100003 100003\n1 2 2209\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "3 2", "output": "100003 100003\n1 2 100002\n2 3 1" }, { "input": "3 3", "output": "100003 100003\n1 2 100002\n2 3 1\n1 3 1000000000" }, { "input": "4 3", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1" }, { "input": "4 5", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000\n1 4 1000000000" }, { "input": "4 6", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000\n1 4 1000000000\n2 4 1000000000" }, { "input": "100000 100000", "output": "100003 100003\n1 2 5\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1\n..." }, { "input": "50000 100000", "output": "100003 100003\n1 2 50005\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "1415 100000", "output": "100003 100003\n1 2 98590\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "13 17", "output": "100003 100003\n1 2 99992\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000" }, { "input": "19 31", "output": "100003 100003\n1 2 99986\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000\n1 8 1000000000\n1 9 1000000000\n1 10 1000000000\n1 11 1000000000\n1 12 1000000000\n1 13 1000000000\n1 14 1000000000\n1 15 1000000000" } ]
30
5,632,000
0
20,802
116
Little Pigs and Wolves
[ "greedy", "implementation" ]
null
null
Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size *n*<=×<=*m*. Each cell in this grid was either empty, containing one little pig, or containing one wolf. A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid of wolves, so there will be at most one wolf adjacent to each little pig. But each wolf may be adjacent to any number of little pigs. They have been living peacefully for several years. But today the wolves got hungry. One by one, each wolf will choose one of the little pigs adjacent to it (if any), and eats the poor little pig. This process is not repeated. That is, each wolf will get to eat at most one little pig. Once a little pig gets eaten, it disappears and cannot be eaten by any other wolf. What is the maximum number of little pigs that may be eaten by the wolves?
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=10) which denotes the number of rows and columns in our two-dimensional grid, respectively. Then follow *n* lines containing *m* characters each — that is the grid description. "." means that this cell is empty. "P" means that this cell contains a little pig. "W" means that this cell contains a wolf. It is guaranteed that there will be at most one wolf adjacent to any little pig.
Print a single number — the maximal number of little pigs that may be eaten by the wolves.
[ "2 3\nPPW\nW.P\n", "3 3\nP.W\n.P.\nW.P\n" ]
[ "2\n", "0\n" ]
In the first example, one possible scenario in which two little pigs get eaten by the wolves is as follows.
[ { "input": "2 3\nPPW\nW.P", "output": "2" }, { "input": "3 3\nP.W\n.P.\nW.P", "output": "0" }, { "input": "1 1\nP", "output": "0" }, { "input": "2 6\nWW..WW\n.PPPP.", "output": "2" }, { "input": "6 2\n.W\n.W\n.P\nWP\n.P\nPW", "output": "3" }, { "input": "2 10\nW..WWP.P.P\nW..PP.WWP.", "output": "3" }, { "input": "10 2\nP.\n.W\nPW\n..\nW.\nW.\n..\nP.\nWP\nPP", "output": "2" }, { "input": "3 4\nWPPW\n.P..\nPWW.", "output": "3" }, { "input": "4 3\n.WW\n..P\nP.P\nPWW", "output": "3" }, { "input": "3 10\nWPPP...PP.\n.P...WW..W\n.WWP.PP.PW", "output": "6" }, { "input": "10 3\n...\nPWW\n..P\n..P\nP.P\nWP.\nPPW\n..W\nW..\nWPP", "output": "5" }, { "input": "4 8\n..PW..WW\nWWPP.PP.\nP...PW.P\nP.WW...P", "output": "5" }, { "input": "8 4\nP.WW\nW..P\nP..P\nP.WW\n..P.\nW.P.\nWP.W\nP..P", "output": "6" }, { "input": "1 1\nW", "output": "0" }, { "input": "4 10\n..P.PW.P.P\nP.WP.W..WP\nW..P.P..WP\nW.PWW.P.P.", "output": "7" }, { "input": "10 4\nWPPP\nP.PW\n...W\nW..P\n..W.\n.PP.\nW..P\nW.PW\n..P.\nPPW.", "output": "6" }, { "input": "5 1\n.\nP\n.\n.\nW", "output": "0" }, { "input": "5 10\nP.PPWWP.PP\n.W....P.PP\nPWPP..WW..\n...W..P.P.\nWP.W...PWW", "output": "7" }, { "input": "10 5\n..PWW\nWWP.P\n.PP..\nP..WW\nPW...\n.W..P\n..P.W\nP.PP.\nW..WP\nWPPP.", "output": "8" }, { "input": "6 5\n..WP.\nWP..W\nW.PP.\n.PWW.\nP.PPP\nWP..W", "output": "6" }, { "input": "5 6\nP...PW\n.WWP.W\n.P...P\nWP..W.\nWPPPWP", "output": "7" }, { "input": "6 10\nPPP.WW..PW\n.W.....WP.\n.W.PP..WP.\n.PP..WPP.P\nW.PW.P.PWW\nWP.P..P.P.", "output": "10" }, { "input": "10 6\n.WW.PW\n......\nWP..W.\nPPWP.P\n.PW.PW\nPP.P.W\nP.PWPP\nW..W.P\nWPP..W\n.PWP.W", "output": "11" }, { "input": "7 3\nWPP\nW.P\n...\nPWP\nPW.\n..P\n..W", "output": "4" }, { "input": "3 7\nWP...PW\n.PW.P..\nPPW.PW.", "output": "5" }, { "input": "7 10\nW..W.PWW.P\nW.P.P.PP.W\nP...W.....\nPWPPW..WW.\n....PPP..P\nWP.WPP.P.P\nPP..PWP.WW", "output": "11" }, { "input": "10 7\n.PW..WP\nW...PW.\n..PW...\nPW..PP.\n.W.P.WW\n.P.P...\nP.PPW..\n.PW...P\nW.P.PPP\nW.PPWPP", "output": "10" }, { "input": "8 8\nWP.W...P\nW.P..WW.\nP.W.P.P.\nPPPPPPPP\nWW..WP.W\nP.P.PP..\n..WW..W.\nPP....W.", "output": "9" }, { "input": "8 10\nPWW..P..W.\nPP.PP...W.\nWP..PWW.P.\nP.P.....P.\nPPW.P.P.WW\nPPP.WW.PP.\nW.P....P.P\n..WWPPW..W", "output": "12" }, { "input": "10 8\n.PPW.PWW\nW.PWP.P.\nWP..PP..\n..WP.PPP\n..PP.WW.\n.WP...P.\n..PWW..W\nW.P..PPW\n...P...P\nPWP.WWP.", "output": "12" }, { "input": "9 8\nPP..W..W\n.PP.W..W\n..W...PP\nWP.P.WW.\nW..W.P..\nP.PP..P.\n...PW.PP\n.WPPW..W\nPWP.PPPP", "output": "12" }, { "input": "8 9\nPWWPPW..W\nP.P..WP.P\nW..WPP.PP\nP.PP....W\n.....WWP.\nP.WWP.P..\nW......WW\nPP.PWPP.P", "output": "13" }, { "input": "10 10\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP", "output": "0" }, { "input": "9 10\nW.PPWW..P.\nW.P.....WP\nP..W......\n..P.PP.W.P\n.PW.P..W..\n..P...PPPP\nPPP.W..PPP\nWW.PW...PP\n.PPP..WW.P", "output": "8" }, { "input": "10 9\nWWP.P.WPP\n..PWP.P.W\n....PWP..\nWW...P.WP\n.P.WP..W.\nPP...W.P.\nP.W..WP.W\n.PWPP..P.\n.PPPPPWW.\nPW..W..PP", "output": "15" }, { "input": "10 1\n.\nW\nW\nP\nP\n.\n.\n.\nW\nP", "output": "2" }, { "input": "1 10\nP.PW.PW..W", "output": "2" }, { "input": "10 10\nPWPP...PPW\n.P.W...W..\nW.P.PW....\nP.P.PW..WP\nPP.W.PP.P.\n.P.P..WP.W\n.WW.PPP..P\n..P...PPP.\nP.P..WW..W\n.WWP...PPW", "output": "16" }, { "input": "10 10\n.PW...P.PW\n....W..PPW\nWWP.W..P.P\n.P..PP.P..\n...W...WW.\nPWP..W....\nPW...W..PW\n.P..P.PP.P\nPPPPWP..W.\nPPPPP.W.PP", "output": "11" }, { "input": "10 10\nPP..PPWPPW\nPPPPPPPP..\n.PPPPPPP.P\nPPPPPPPPPP\nPWP.PPP.PP\nPW.PP.PPPP\nPPPPPP.PPW\n..PPWPPP.P\nWPPPPPPPPP\nWP.WPPPWPP", "output": "10" }, { "input": "10 10\nPPPPPPPPPP\nPPPPPPPWPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP", "output": "1" }, { "input": "10 10\nPPPPPPPPWP\nPPPWPPPPPP\nPPPPPPPPPP\nPWWPPWPPPP\nPPPPPPPPPP\nPPPPWPPPPP\nPPPPPPPPPP\nPPPPPPWPPW\nPPPPPPPPPP\nPPWPPPPPWP", "output": "10" }, { "input": "10 10\n.PWWP..W..\n.....W...W\nWP........\nW...WP....\nP.W..P..WW\n..W...WP.P\nW...W.....\n....WP..P.\n.W....W..W\n.W....W..W", "output": "8" }, { "input": "10 10\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW", "output": "0" }, { "input": "10 10\nW..W..W...\nW..P..W...\n..W.....WW\n....WW....\nWW.....W..\n.........W\n..WW......\n.......WW.\nW.........\nW..WW....W", "output": "1" }, { "input": "10 10\n..P..WWP.W\nPP.WPPPPPP\nWWPP.PPWPP\nPPPPW..PPW\nPP.PW.P.PW\nWW..PPWWP.\n..PW...PP.\n.PPPP.PPPW\nPP.PWP..P.\nPWPPP..WWP", "output": "20" }, { "input": "10 10\n......W...\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n........P.", "output": "0" }, { "input": "10 10\n.P.PPPP..W\nPWW.PPWPPW\n...PPP.P..\nW..P...WP.\n.PPWPP.W..\n...PPWPPPP\nWP..PW..W.\nPPW.....P.\nP.P...PP.W\nWPPWW.PPPW", "output": "14" }, { "input": "10 10\nW...W.....\n..W...WW..\n.........W\n...WW....W\nWW.....W..\n.....W....\n..W.....W.\nW...W.....\nW.....W..W\n..WW..W..W", "output": "0" }, { "input": "10 10\nWW..W...WW\n....W.....\n......WW..\n.W.....P..\n.W...W..WW\n...W......\nW..W......\nW....WW..P\nP.........\n...WW...WW", "output": "2" }, { "input": "10 10\nP.PPP.PP.P\nPPP.PPP.P.\nP.PPPP..PW\nP.PPP.PP.P\nPPPPPP.P.P\nPPPP.PP.P.\n.PPWPPPPP.\nPPP...PPPP\nPPP.PPPP.P\n.WPPPP.P.P", "output": "3" }, { "input": "1 4\nW..P", "output": "0" }, { "input": "10 10\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W", "output": "0" }, { "input": "10 10\nWPPPWPPPWP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nWPPPWPPPWP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nWPPPWPPPWP\nPPPPPPPPPP", "output": "9" }, { "input": "10 10\nPPPPPPPPPP\nWWWWWWWWWW\nWWWWWWWWWW\nPPPPPPPPPP\nPPPPPPPPPP\nWWWWWWWWWW\nWWWWWWWWWW\nPPPPPPPPPP\nPPPPPPPPPP\nWWWWWWWWWW", "output": "50" }, { "input": "4 1\n.\nW\nP\n.", "output": "1" }, { "input": "1 10\nP..W.PPWW.", "output": "1" }, { "input": "10 1\nP\nP\nW\nW\n.\nP\n.\n.\n.\nW", "output": "1" }, { "input": "1 1\n.", "output": "0" }, { "input": "10 10\nPPPWPPPWPP\nPWPPPWPPPP\nPPPPPPPPPP\nWPPWPPWPPW\nPPPPPPPPPP\nPWPPWPPWPP\nPPPPPPPPPP\nPPWPPWPPWP\nPPPPPPPPPP\nWPPWPPWPPW", "output": "18" }, { "input": "10 10\nWPPPPWPPWP\nPPPWPPPPPP\nPWPPPPWPPP\nPPPPWPPPWP\nWPPPPPPPPP\nPPPWPPWPPP\nPWPPPPPPWP\nPPPPWPPPPP\nWPPPPPWPPP\nPPPWPPPPWP", "output": "18" }, { "input": "4 4\n.P..\n.W..\n.P..\n..W.", "output": "1" }, { "input": "4 1\n.\n.\nW\nP", "output": "1" }, { "input": "10 10\nWPPPPWPPWP\nPPPWPPPPPP\nPWPPPPWPPP\nPPPPWPPPWP\nWPPPPPPPPP\nPPPWPPWPPP\nPWPPPPPPWP\nPPPPWPPPPP\nWPPPPPWPPP\nPPPWPPPPWP", "output": "18" }, { "input": "3 3\nPWP\n...\nW..", "output": "1" }, { "input": "2 3\nWWP\nPPP", "output": "2" } ]
124
0
3
20,827
74
Train
[ "dp", "games", "greedy" ]
B. Train
2
256
A stowaway and a controller play the following game. The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle. Every minute the players move. The controller's move is as follows. The controller has the movement direction — to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the *n*-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move. The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of *n* wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back. Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train. If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again. At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner.
The first line contains three integers *n*, *m* and *k*. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2<=≤<=*n*<=≤<=50, 1<=≤<=*m*,<=*k*<=≤<=*n*, *m*<=≠<=*k*). The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon *n* is the tail. The third line has the length from 1 to 200 and consists of symbols "0" and "1". The *i*-th symbol contains information about the train's state at the *i*-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" — that's the terminal train station.
If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught.
[ "5 3 2\nto head\n0001001\n", "3 2 1\nto tail\n0001\n" ]
[ "Stowaway", "Controller 2" ]
none
[ { "input": "5 3 2\nto head\n0001001", "output": "Stowaway" }, { "input": "3 2 1\nto tail\n0001", "output": "Controller 2" }, { "input": "4 2 1\nto tail\n1000001", "output": "Controller 6" }, { "input": "2 1 2\nto head\n111111", "output": "Stowaway" }, { "input": "4 1 4\nto head\n010001", "output": "Stowaway" }, { "input": "10 2 1\nto tail\n000000001", "output": "Stowaway" }, { "input": "5 5 3\nto tail\n01010000000001", "output": "Controller 10" }, { "input": "4 3 1\nto tail\n1000001001101", "output": "Controller 6" }, { "input": "4 1 3\nto head\n011000011000001", "output": "Controller 14" }, { "input": "20 13 9\nto head\n1111111111111111111111111111111111111111", "output": "Stowaway" }, { "input": "2 1 2\nto head\n1101", "output": "Controller 3" }, { "input": "2 2 1\nto tail\n1101", "output": "Controller 3" }, { "input": "2 1 2\nto head\n01", "output": "Controller 1" }, { "input": "2 2 1\nto tail\n01", "output": "Controller 1" }, { "input": "5 4 2\nto tail\n1", "output": "Stowaway" }, { "input": "8 8 7\nto head\n0000000000001", "output": "Stowaway" }, { "input": "8 8 7\nto head\n0000000000000100101000110101011", "output": "Controller 13" }, { "input": "10 3 8\nto head\n01", "output": "Stowaway" }, { "input": "5 1 4\nto head\n1000000000001", "output": "Controller 7" }, { "input": "5 1 3\nto head\n1000000000001", "output": "Controller 6" }, { "input": "3 3 1\nto tail\n1001000001", "output": "Controller 6" }, { "input": "4 3 1\nto tail\n00011110000000010001", "output": "Controller 3" }, { "input": "5 3 4\nto tail\n0001000000101000010010010000100110011", "output": "Controller 9" }, { "input": "6 4 5\nto tail\n0010000101101011001000000100111101101001010011001", "output": "Stowaway" }, { "input": "7 1 7\nto head\n011001001000100000000000000100001100000001100000000010000010011", "output": "Controller 24" }, { "input": "8 5 6\nto tail\n01110101111111111111111111001111111011011111111111101111111111011111101", "output": "Stowaway" }, { "input": "9 7 2\nto head\n1000100010110000101010010000000000010010000010100000001001000000001000000101100000000001", "output": "Controller 33" }, { "input": "10 8 2\nto tail\n0000000000000001000000000000000000000000001000000000010000000000001000000000000000100000000000000001", "output": "Controller 8" }, { "input": "10 1 8\nto tail\n0000000000000000001000010000000001000001000000010000000000000000010010001000001000110010000001010011", "output": "Controller 11" }, { "input": "10 3 6\nto head\n0000001001010100000001010001000110001100011100000100100001100000001100000000000010000001000100100011", "output": "Controller 5" }, { "input": "13 9 8\nto tail\n000000000000000000000000000010011100000000000100100000000010000100000000000000000000000000000000000000010000011", "output": "Controller 5" }, { "input": "17 14 17\nto head\n0000001010000000000000100011000000100000001010000001011000000000001000100000000010100000010001000000000000000100000000000001", "output": "Stowaway" }, { "input": "20 15 7\nto head\n10011111001101010111101110101101101111011110111101001000101111011111011001110010001111111111111101111101011011111010011111111101111011111111", "output": "Stowaway" }, { "input": "26 10 11\nto head\n0000000001001000100000010000110000000011100001000010000000000010000000000000110100000001000000010000110011000000100000000010001100010000000100001110001", "output": "Stowaway" }, { "input": "31 7 15\nto tail\n0010000000000000100000010000010000100000000000000000000001000001100100000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000100001", "output": "Controller 106" }, { "input": "38 7 18\nto tail\n00000000000000000000000000000000000000000000000000000000000000000000000000000001001000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "Controller 57" }, { "input": "42 24 17\nto head\n00000000000000000000100010000000000000000000001000100000000000000000001000000000000010000100100000100000001000000010010000000000101000000000000000010000000000000000000000000011001", "output": "Stowaway" }, { "input": "45 21 37\nto tail\n00000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "Controller 96" }, { "input": "49 44 14\nto head\n0000000000000000000000000000000000100000100000000000000000000000010000000000001000000000000000100000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000111001", "output": "Controller 157" }, { "input": "50 4 12\nto tail\n00000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000001000100000000000000000000000000000000000000010000000010000000000000000000000000000000000000000001", "output": "Stowaway" }, { "input": "50 9 39\nto tail\n00000000000000001000000000000000000000000000000000000000000010000000100000000000000001000100000000000000010000000001000000000000000000000000010000000000000000000000000000000000001000000000000000000101", "output": "Stowaway" }, { "input": "50 43 15\nto tail\n00000000000001000000000000000000000000001000000000000000000000001010000000000000000000000010000001000000000000100000000000000000000000000000100000000100000000000001000000000011000000101000010000000001", "output": "Stowaway" }, { "input": "2 2 1\nto tail\n11111101111111011111111111111111111111111111110111111110111111111101111111111001111110111111101011101110110011111011111011101011111111101111111110111111011111111111111111110111111111111111101111101111", "output": "Controller 7" }, { "input": "2 2 1\nto tail\n10111111111111111110111011111111111111111111111111111110111111111110111111101111111111111111111111011111111111111011111111110111111101111111111101111111111111111101111111111111111111111111111001111111", "output": "Controller 2" }, { "input": "3 1 3\nto head\n11111111101111101111011011001011101100101101111111111011011111110011110101010111111101101010010111110110111111011111111111111111111110011111011011101110111111111111100111001110111110111011100111111111", "output": "Controller 28" }, { "input": "3 1 3\nto head\n10111111111111111011110110111111110111011111111111111111110101111111111111101111111111011110111110111111111111111111111111111110111111111111111110001011101111101110111111111111111111110101111111110011", "output": "Controller 148" }, { "input": "4 2 4\nto head\n01101111110010111111111111011110111101000011111110111100111010111110111011010111010110011101101010111100000011001011011101101111010111101001001011101111111111100011110110011010111010111011001011111001", "output": "Controller 42" }, { "input": "50 50 14\nto head\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "Stowaway" }, { "input": "50 42 13\nto head\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "Controller 61" }, { "input": "50 43 39\nto head\n01100111001110101111000001011111111100101101011010010001000001110001010011001010010100101100110011010011110110011111011101001111110001111001001100011110000111100100010001000011001001100000000010001111", "output": "Stowaway" }, { "input": "3 3 2\nto tail\n0001", "output": "Controller 1" }, { "input": "3 2 3\nto head\n0000000000000000001", "output": "Controller 2" } ]
92
0
3.977
20,903
906
Reverses
[ "dp", "string suffix structures", "strings" ]
null
null
Hurricane came to Berland and to suburbs Stringsvill. You are going to it to check if it's all right with you favorite string. Hurrinace broke it a bit by reversing some of its non-intersecting substrings. You have a photo of this string before hurricane and you want to restore it to original state using reversing minimum possible number of its substrings and find out which substrings you should reverse. You are given a string *s* — original state of your string and string *t* — state of the string after hurricane. You should select *k* non-intersecting substrings of *t* in such a way that after reverse of these substrings string will be equal *s* and *k* is minimum possible.
First line of input contains string *s* and second line contains string *t*. Both strings have same length and consist of lowercase English letters. 1<=≤<=|*s*|<==<=|*t*|<=≤<=5·105
In first line print *k* — minimum number of substrings you should reverse. Next output *k* lines. Each line should contain two integers *l**i*, *r**i* meaning that you should reverse substring from symbol number *l**i* to symbol *r**i* (strings are 1-indexed). These substrings shouldn't intersect. If there are multiple answers print any. If it's impossible to restore string output -1.
[ "abcxxxdef\ncbaxxxfed\n" ]
[ "2\n7 9\n1 3\n" ]
none
[]
30
0
0
20,974
986
Perfect Encoding
[ "fft", "math" ]
null
null
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID of some object in the system is an array of integers $[a_{1}, a_{2}, \ldots, a_{m}]$ where $1 \le a_{i} \le b_{i}$ holds for every $1 \le i \le m$. Developers say that production costs are proportional to $\sum_{i=1}^{m} b_{i}$. You are asked to choose parameters $m$ and $b_{i}$ so that the system will be able to assign unique IDs to $n$ different objects and production costs are minimized. Note that you don't have to use all available IDs.
In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros.
Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$.
[ "36\n", "37\n", "12345678901234567890123456789\n" ]
[ "10\n", "11\n", "177\n" ]
none
[ { "input": "36", "output": "10" }, { "input": "37", "output": "11" }, { "input": "12345678901234567890123456789", "output": "177" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "3" }, { "input": "4", "output": "4" }, { "input": "7421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798", "output": "629" }, { "input": "71057885893313745806894531138592341136175030511382512555364579061229040750815096670263802546201989828165866147027119861863385397179695224216202346062872417111920113483747119385957051753101263769591892062039112567316036455789217245754461225443096439906225767290690128677713047690686004149082311677134836383178262318973298581951974863511315252485252083010690948164456205330279738760034861583874764199950445592461479109814313530332776429627014232776723160331462731018692207739471347664936326394313671025", "output": "3144" }, { "input": "515377520732011331036461129765621272702107522001", "output": "300" }, { "input": "515377520732011331036461129765621272702107522002", "output": "301" }, { "input": "515377520732011331036461129765621272702107522000", "output": "300" }, { "input": "2644141638961613273780910519504288731930844065504296335329840736453657194693409799081556627701216123927819555393745164711901909164201237823730685450515907348055240450396641607756029548457929682548780800235177236082257895631246188876123132346108173348981012356250960688811094108794077791634930736509832272441660537127557164580456832796615775793837112808169797875218746484343692719877391033530037881176218120852179342877728205628700771297494331664021228732264346205537805710440002", "output": "3002" } ]
2,000
21,401,600
0
21,046
626
Group Projects
[ "dp" ]
null
null
There are *n* students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the *i*-th student *a**i* minutes to finish his/her independent piece. If students work at different paces, it can be frustrating for the faster students and stressful for the slower ones. In particular, the imbalance of a group is defined as the maximum *a**i* in the group minus the minimum *a**i* in the group. Note that a group containing a single student has an imbalance of 0. How many ways are there for the students to divide into groups so that the total imbalance of all groups is at most *k*? Two divisions are considered distinct if there exists a pair of students who work in the same group in one division but different groups in the other.
The first line contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=200, 0<=≤<=*k*<=≤<=1000) — the number of students and the maximum total imbalance allowed, respectively. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=500) — the time it takes the *i*-th student to complete his/her independent piece of work.
Print a single integer, the number of ways the students can form groups. As the answer may be large, print its value modulo 109<=+<=7.
[ "3 2\n2 4 5\n", "4 3\n7 8 9 10\n", "4 0\n5 10 20 21\n" ]
[ "3\n", "13\n", "1\n" ]
In the first sample, we have three options: - The first and second students form a group, and the third student forms a group. Total imbalance is 2 + 0 = 2. - The first student forms a group, and the second and third students form a group. Total imbalance is 0 + 1 = 1. - All three students form their own groups. Total imbalance is 0. In the third sample, the total imbalance must be 0, so each student must work individually.
[ { "input": "3 2\n2 4 5", "output": "3" }, { "input": "4 3\n7 8 9 10", "output": "13" }, { "input": "4 0\n5 10 20 21", "output": "1" }, { "input": "20 1000\n50 50 100 100 150 150 200 200 250 250 300 300 350 350 400 400 450 450 500 500", "output": "97456952" }, { "input": "5 222\n58 369 477 58 90", "output": "10" }, { "input": "9 222\n304 142 38 334 73 122 252 381 438", "output": "423" }, { "input": "9 247\n359 350 140 26 293 488 57 481 71", "output": "414" }, { "input": "5 341\n412 32 189 303 172", "output": "26" }, { "input": "200 0\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "380668983" }, { "input": "121 19\n1 1 1 1 2 1 1 2 2 1 1 2 2 2 2 1 1 2 1 1 1 1 2 2 2 2 1 1 2 1 1 2 1 1 1 1 1 2 2 1 2 2 1 2 1 1 2 2 2 1 2 1 1 1 1 2 1 1 2 2 1 1 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 1 2 1 2 2 2 2 2 1 1 2 2 1 2 2 2 1 2 1 1 1 1 2 2 2 2 2 1 1 2 2 2 2 2 1 1 1 1 1 2 2 1 2 1", "output": "378568711" }, { "input": "3 4\n10 7 10", "output": "5" }, { "input": "1 5\n3", "output": "1" }, { "input": "1 5\n9", "output": "1" }, { "input": "5 2\n3 10 5 6 5", "output": "8" }, { "input": "1 2\n2", "output": "1" }, { "input": "166 7\n9 8 7 2 9 9 7 7 3 1 9 9 9 7 1 5 5 6 6 2 3 2 10 9 3 5 8 8 6 3 10 3 4 8 6 5 1 7 2 9 1 4 9 10 6 8 6 7 8 3 2 1 10 5 6 6 3 7 4 9 10 3 1 10 9 9 2 10 3 2 4 8 9 6 1 9 10 10 10 9 5 8 9 7 9 6 7 5 4 7 8 9 8 5 10 5 4 10 8 5 10 10 10 8 7 3 2 6 3 1 7 5 7 10 7 8 8 8 5 5 8 10 2 10 2 4 10 2 3 1 1 4 5 8 7 9 4 10 2 9 8 1 1 5 9 5 2 1 7 7 9 10 2 2 10 10 6 8 5 5 9 4 3 1 10 5", "output": "194851520" }, { "input": "94 17\n9 10 10 5 2 7 10 9 5 5 7 7 6 10 4 10 3 7 4 9 2 5 1 5 4 2 9 8 4 3 9 5 7 10 10 6 3 1 9 9 2 8 8 8 7 2 4 5 2 5 7 7 4 9 4 9 4 10 5 10 9 7 3 6 10 3 1 10 6 4 8 9 4 10 7 2 9 8 7 10 2 2 4 1 4 6 10 7 2 4 9 4 8 5", "output": "650765262" }, { "input": "14 26\n3 7 8 4 7 5 10 8 4 4 1 6 7 7", "output": "190894282" }, { "input": "142 24\n8 1 10 6 5 3 9 4 4 8 2 7 4 4 1 2 7 4 7 3 3 9 9 6 6 10 8 5 3 2 3 4 7 9 9 8 4 7 8 6 9 1 7 9 10 2 6 1 9 9 1 10 2 10 6 5 10 2 3 8 3 7 1 8 9 10 1 8 10 7 2 5 1 1 4 6 5 7 6 10 4 4 7 4 10 5 10 9 8 7 4 10 4 4 3 4 10 6 1 4 8 5 10 6 3 8 8 4 2 3 2 1 7 5 2 4 2 3 10 7 8 3 10 9 1 7 7 5 5 5 10 8 8 2 6 9 7 2 4 7 7 3", "output": "287439553" }, { "input": "166 34\n6 5 3 3 4 5 4 6 4 6 2 6 5 1 7 4 5 5 6 1 2 2 6 4 3 7 4 5 1 7 3 1 6 5 1 3 6 4 9 7 6 6 6 5 8 6 2 4 5 6 10 10 4 8 3 6 1 4 7 9 8 5 2 9 8 10 2 2 6 1 3 6 6 9 10 8 10 5 8 10 5 9 2 4 8 2 9 2 1 9 5 9 3 8 1 10 4 1 1 4 9 6 10 6 2 1 4 5 5 8 10 10 5 6 3 10 1 8 5 10 3 3 10 9 7 4 1 9 9 10 8 3 4 2 8 10 6 3 10 10 4 6 8 7 9 7 10 3 1 10 4 10 5 2 7 9 4 10 6 2 6 3 9 10 9 10", "output": "772974256" }, { "input": "171 302\n64 51 53 35 36 42 67 27 55 85 97 23 47 8 59 69 50 15 28 36 22 12 49 99 54 11 10 91 91 78 59 65 68 5 20 77 42 59 85 65 69 35 59 86 45 96 41 82 89 93 80 25 16 22 68 8 23 57 48 53 16 21 50 44 70 75 33 32 43 32 77 40 8 41 23 82 61 51 26 88 58 23 6 69 11 95 89 41 70 95 81 50 99 81 48 36 62 85 64 58 25 30 23 27 30 87 45 42 67 47 1 1 86 33 43 78 41 57 72 86 55 25 69 36 77 97 48 24 9 20 50 5 2 84 80 62 7 5 49 2 16 3 62 8 40 24 94 60 9 95 22 27 58 20 22 95 16 53 6 8 74 54 94 65 62 90 95 17 77 32 99", "output": "49555477" }, { "input": "158 396\n10 33 14 7 23 30 23 9 99 41 88 56 70 25 85 27 68 60 73 14 32 87 6 16 71 64 22 66 9 48 46 93 81 9 50 48 80 70 78 76 49 89 56 74 56 40 67 45 3 41 77 49 8 56 55 29 78 69 52 70 55 99 85 6 59 99 24 66 4 23 4 51 84 67 79 65 6 67 80 36 85 47 45 37 75 38 39 59 7 11 81 7 12 79 56 87 9 97 30 32 27 21 42 85 17 50 69 13 51 12 73 60 14 94 93 31 10 9 70 67 52 63 45 38 37 13 46 50 53 29 50 57 49 81 71 79 58 74 19 47 19 14 16 82 18 11 71 90 28 21 48 16 41 52 24 6 4 23", "output": "757778575" }, { "input": "169 129\n66 70 83 26 65 94 1 56 17 64 58 68 23 73 45 93 30 94 22 55 68 29 73 44 35 39 71 76 76 76 19 98 99 26 43 73 96 6 72 23 8 56 34 17 91 64 17 33 56 92 41 22 92 59 23 96 35 94 82 1 61 41 75 89 10 74 13 64 50 78 49 83 6 62 43 22 61 95 28 4 76 14 54 41 83 81 83 23 13 57 10 2 44 54 89 41 27 58 57 47 26 82 97 82 5 35 27 31 89 6 73 36 94 89 29 96 3 88 82 27 50 56 73 24 17 56 25 9 2 47 71 86 96 79 35 42 31 73 13 89 52 30 88 96 46 91 23 60 79 2 19 7 73 40 6 29 61 29 67 85 75 11 8 34 60 19 87 23 55", "output": "538924707" }, { "input": "195 110\n3 4 5 1 3 5 4 1 2 4 3 2 4 4 3 2 5 5 5 3 3 3 5 3 5 4 2 5 1 1 2 3 4 5 5 2 2 4 3 4 2 4 4 3 4 2 3 3 3 5 2 1 3 2 5 5 2 2 1 2 2 5 4 2 4 2 4 1 4 2 4 4 4 4 3 5 3 1 2 2 3 4 3 4 4 1 2 1 2 4 5 2 4 3 4 1 4 4 4 5 1 2 4 5 3 5 3 4 2 4 5 2 5 2 5 4 1 5 1 4 2 5 1 2 4 1 3 3 5 5 4 2 3 4 5 4 4 5 2 3 4 2 5 3 2 1 5 3 5 3 5 2 3 2 5 3 5 4 5 1 5 3 3 2 2 5 4 3 3 2 5 5 5 5 2 1 2 3 1 3 5 2 4 5 3 2 2 5 5 2 3 1 3 4 5", "output": "21311661" }, { "input": "196 17\n4 4 2 2 4 2 2 4 4 3 4 1 5 4 4 5 4 1 1 1 5 1 1 4 3 4 4 1 1 1 5 3 2 4 2 1 5 3 4 2 4 2 5 4 1 4 1 2 3 5 3 5 3 2 5 5 5 2 2 1 1 2 2 2 5 4 5 2 5 5 3 1 5 3 5 5 1 3 3 2 3 2 2 1 5 1 2 5 4 5 4 3 4 4 4 1 5 5 2 2 2 5 3 4 5 3 3 2 4 4 4 3 1 1 1 5 2 5 1 5 1 2 3 3 4 4 5 4 2 5 4 2 3 3 4 5 2 2 4 5 5 2 2 1 3 3 4 3 2 3 4 4 5 2 5 1 4 5 2 3 2 4 4 3 4 4 2 5 5 5 5 4 1 3 2 1 4 5 3 2 3 3 5 4 3 1 4 4 5 2 5 2 2 1 4 3", "output": "140496580" }, { "input": "200 558\n1 1 1 3 2 1 1 5 1 2 1 1 2 2 1 5 2 5 2 5 3 2 4 1 5 2 3 2 3 1 2 2 1 4 4 2 5 1 4 3 2 2 4 5 4 5 2 5 5 4 3 5 4 5 5 2 3 4 3 1 5 4 3 3 3 3 2 2 3 4 1 3 1 4 5 2 3 4 1 5 2 3 3 5 5 3 3 1 2 5 3 4 2 5 2 3 3 1 3 2 3 5 1 2 1 1 3 4 1 3 2 1 1 4 2 5 1 2 1 2 2 2 2 2 3 4 2 2 4 4 2 1 3 3 2 4 1 3 5 4 5 1 5 2 1 4 2 3 4 1 4 5 1 1 5 2 4 5 5 4 4 5 3 1 1 5 4 2 2 5 1 3 3 3 4 1 1 2 3 4 1 5 2 2 3 1 4 3 5 1 5 3 2 1 3 2 1 1 3 2", "output": "380668983" }, { "input": "190 152\n2 2 4 4 4 2 2 1 2 3 5 5 4 3 5 1 2 2 2 2 3 3 5 2 1 1 3 4 3 2 2 4 2 3 1 4 2 2 3 2 3 5 3 2 4 1 4 1 2 4 1 3 4 4 3 4 4 4 4 5 2 4 5 3 3 5 4 4 3 4 1 4 1 4 3 3 5 5 2 3 2 2 2 5 4 4 2 4 3 4 2 2 1 4 1 2 3 3 3 5 1 5 5 1 4 3 2 5 2 5 5 5 2 3 3 4 1 1 3 2 5 5 2 5 2 3 5 1 1 5 4 1 1 3 5 2 3 4 3 4 2 1 4 3 5 2 1 1 1 5 2 5 3 4 5 5 2 3 5 5 5 5 1 5 2 5 5 2 4 4 4 3 1 1 2 1 4 4 3 4 2 5 5 3 4 5 5 2 1 4", "output": "3475416" }, { "input": "191 640\n20 10 14 20 13 9 16 5 14 1 11 18 16 17 7 4 15 18 17 3 3 15 14 20 18 2 4 14 20 17 7 2 3 9 5 10 7 6 7 17 3 5 10 1 18 13 15 4 15 7 19 1 17 6 15 12 4 19 1 9 18 18 9 13 3 15 9 3 17 14 18 4 9 3 9 19 20 15 18 11 3 1 12 8 11 10 20 14 14 6 2 14 16 1 7 2 11 15 1 9 20 4 1 1 3 20 20 4 11 7 19 3 3 6 15 10 18 9 13 14 16 12 3 1 15 10 5 14 19 17 9 10 10 15 12 12 5 2 11 6 5 6 7 14 7 6 5 10 13 10 18 20 18 20 12 7 6 10 4 4 3 13 14 5 9 10 4 6 11 11 15 15 12 19 4 7 20 3 12 4 16 6 4 9 17 10 18 11 13 12 18", "output": "66598866" }, { "input": "197 344\n5 11 3 17 16 1 12 7 13 5 9 11 15 14 13 7 13 11 5 9 20 11 11 9 19 3 20 4 6 15 2 14 16 5 19 5 5 5 12 12 12 19 18 1 5 17 13 7 17 14 4 5 9 20 14 13 15 3 8 2 13 16 20 10 20 14 8 17 14 4 9 16 8 13 5 2 13 11 9 7 9 5 11 20 3 17 9 12 12 3 9 19 6 3 15 9 5 11 2 3 13 14 15 7 9 19 16 11 6 8 11 18 11 11 16 18 3 5 10 19 10 6 3 19 3 18 16 16 7 3 10 13 13 16 19 13 4 7 1 7 12 9 6 8 6 1 6 20 7 12 9 13 13 12 10 10 10 16 9 6 11 14 14 7 2 1 16 15 12 7 15 18 8 4 6 18 2 17 6 5 13 19 12 7 1 9 15 9 18 5 8 3 7 8 4 15 8", "output": "132934747" }, { "input": "200 0\n2 5 2 7 6 10 10 4 7 9 1 5 7 1 8 5 9 8 5 2 6 4 9 10 5 4 4 4 8 7 7 5 9 7 7 4 9 8 5 8 10 5 1 2 8 4 3 7 9 6 9 3 9 2 1 9 2 7 4 10 4 7 10 6 1 6 7 4 4 9 10 3 5 5 1 2 8 6 6 2 2 8 6 3 6 1 4 6 10 6 4 8 3 9 6 7 7 8 5 2 10 9 2 7 3 6 10 6 8 9 6 6 8 4 6 9 2 10 9 4 2 3 4 1 3 9 4 2 4 10 10 1 2 3 9 8 2 1 10 7 8 3 10 5 3 10 9 1 9 2 6 7 2 1 10 4 4 9 9 1 8 1 10 9 8 9 9 7 4 3 6 7 10 9 2 7 8 10 2 7 7 6 9 5 9 7 3 1 7 1 5 9 7 3 10 3 10 8 5 7", "output": "563633437" }, { "input": "107 59\n416 332 455 497 251 13 496 46 176 382 357 268 441 302 305 11 274 61 412 18 225 332 173 371 54 179 378 85 471 176 439 36 81 275 452 212 261 488 166 274 89 183 478 337 313 196 130 87 14 223 341 46 45 306 175 488 113 354 107 411 469 122 436 293 311 60 453 245 184 13 425 360 302 205 151 89 433 285 119 301 274 64 127 496 350 354 262 2 148 232 117 28 11 398 237 460 421 347 142 76 391 317 164 484 35 310 453", "output": "955755252" }, { "input": "27 383\n161 2 16 478 438 205 151 229 116 230 447 497 456 219 28 57 200 6 161 400 338 11 426 283 275 40 190", "output": "258971846" }, { "input": "107 497\n218 342 381 296 272 169 321 275 435 461 422 209 413 366 295 332 458 253 302 245 70 353 405 420 439 314 232 466 364 374 4 469 116 291 75 500 212 127 157 440 429 396 53 68 151 264 2 134 73 31 494 148 426 459 27 175 225 287 241 60 14 437 457 446 51 350 233 177 88 455 497 303 107 130 76 125 441 229 325 318 187 459 178 172 226 236 465 289 491 494 146 280 456 475 286 457 277 224 435 365 100 77 145 448 118 454 431", "output": "480907144" }, { "input": "27 209\n272 116 134 369 255 453 477 162 78 1 12 142 236 283 209 390 476 493 51 23 387 32 262 128 160 71 56", "output": "415376034" }, { "input": "85 655\n411 473 456 4 14 135 49 240 191 230 60 375 373 115 301 20 421 187 267 347 207 428 81 318 10 370 428 272 247 322 294 477 274 110 238 244 72 399 146 392 207 83 164 87 257 341 97 94 286 375 25 271 177 270 169 149 279 105 387 92 352 342 274 247 236 344 35 336 419 465 169 371 62 112 490 48 36 343 248 428 241 223 369 296 86", "output": "275193712" }, { "input": "107 19\n2 5 2 5 4 4 1 5 3 3 4 3 2 5 3 1 4 1 4 1 3 1 4 4 1 5 4 1 2 3 3 3 4 2 5 2 3 4 5 2 1 5 3 1 5 5 1 5 3 3 3 5 5 2 4 3 3 4 5 4 2 5 2 4 3 5 2 5 2 1 1 1 1 2 1 4 2 3 4 3 2 4 4 2 2 3 5 5 1 4 1 2 4 4 1 3 3 5 2 3 4 1 2 3 1 5 2", "output": "114012476" }, { "input": "186 35\n4 4 3 2 4 3 1 2 2 2 4 2 5 3 1 3 1 1 2 4 2 5 5 5 1 3 4 1 5 3 5 5 2 4 5 3 1 1 2 1 2 4 2 3 3 4 4 3 3 5 3 1 4 5 5 4 5 2 3 1 2 2 2 4 3 4 1 4 1 2 1 1 1 5 1 1 4 5 3 5 3 3 4 1 5 1 1 4 5 3 3 2 5 3 5 1 5 2 5 1 4 2 4 5 4 4 4 5 4 4 2 5 2 4 4 5 3 2 5 4 1 1 5 5 5 5 1 3 2 5 5 4 3 2 2 5 5 3 1 4 3 4 3 1 2 5 4 4 2 2 5 3 2 1 2 1 1 3 1 4 1 2 3 2 1 5 5 2 2 1 2 1 5 2 4 4 3 2 5 5 2 3 4 5 5 3", "output": "273232004" }, { "input": "150 978\n34 20 7 39 15 14 39 49 36 13 12 12 30 40 4 17 8 2 48 10 16 2 33 36 41 30 4 35 32 35 12 14 28 3 7 3 36 46 43 19 7 38 48 24 19 21 9 31 3 3 8 23 21 49 44 29 15 6 11 40 39 12 44 40 41 37 7 39 40 17 34 21 22 19 30 21 14 3 16 50 38 38 27 7 4 33 20 23 27 32 14 50 33 36 38 22 27 27 14 2 27 37 33 6 21 44 25 17 28 22 43 10 33 21 42 4 7 42 10 20 22 49 14 18 26 19 43 4 31 18 13 17 5 46 19 35 31 14 28 29 48 9 9 4 10 15 30 5 9 23", "output": "338032038" }, { "input": "115 588\n39 133 47 175 120 1 183 148 115 9 196 101 18 156 156 74 43 149 95 56 72 84 32 104 16 188 88 168 164 18 36 105 131 60 26 151 46 160 16 45 76 16 157 190 120 37 102 29 190 57 178 38 89 75 143 2 80 7 11 31 101 28 171 46 93 100 23 163 146 135 12 73 140 144 177 43 19 158 26 20 39 173 97 8 169 139 23 105 7 171 79 11 156 77 164 63 165 124 126 108 125 118 58 129 146 152 31 133 5 160 89 136 174 121 185", "output": "27195433" } ]
1,762
25,190,400
3
21,065
786
Till I Collapse
[ "data structures", "divide and conquer" ]
null
null
Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. They Have generated *n* Mr. Meeseeks, standing in a line numbered from 1 to *n*. Each of them has his own color. *i*-th Mr. Meeseeks' color is *a**i*. Rick and Morty are gathering their army and they want to divide Mr. Meeseeks into some squads. They don't want their squads to be too colorful, so each squad should have Mr. Meeseeks of at most *k* different colors. Also each squad should be a continuous subarray of Mr. Meeseeks in the line. Meaning that for each 1<=≤<=*i*<=≤<=*e*<=≤<=*j*<=≤<=*n*, if Mr. Meeseeks number *i* and Mr. Meeseeks number *j* are in the same squad then Mr. Meeseeks number *e* should be in that same squad. Also, each squad needs its own presidio, and building a presidio needs money, so they want the total number of squads to be minimized. Rick and Morty haven't finalized the exact value of *k*, so in order to choose it, for each *k* between 1 and *n* (inclusive) need to know the minimum number of presidios needed.
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105) — number of Mr. Meeseeks. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* separated by spaces (1<=≤<=*a**i*<=≤<=*n*) — colors of Mr. Meeseeks in order they standing in a line.
In the first and only line of input print *n* integers separated by spaces. *i*-th integer should be the minimum number of presidios needed if the value of *k* is *i*.
[ "5\n1 3 4 3 3\n", "8\n1 5 7 8 1 7 6 1\n" ]
[ "4 2 1 1 1 \n", "8 4 3 2 1 1 1 1 \n" ]
For the first sample testcase, some optimal ways of dividing army into squads for each *k* are: 1. [1], [3], [4], [3, 3] 1. [1], [3, 4, 3, 3] 1. [1, 3, 4, 3, 3] 1. [1, 3, 4, 3, 3] 1. [1, 3, 4, 3, 3] For the second testcase, some optimal ways of dividing army into squads for each *k* are: 1. [1], [5], [7], [8], [1], [7], [6], [1] 1. [1, 5], [7, 8], [1, 7], [6, 1] 1. [1, 5, 7], [8], [1, 7, 6, 1] 1. [1, 5, 7, 8], [1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1]
[ { "input": "5\n1 3 4 3 3", "output": "4 2 1 1 1 " }, { "input": "8\n1 5 7 8 1 7 6 1", "output": "8 4 3 2 1 1 1 1 " }, { "input": "10\n4 1 2 6 8 5 3 9 3 9", "output": "10 4 3 2 2 2 2 1 1 1 " }, { "input": "85\n23 11 69 1 49 10 7 13 66 35 81 4 51 2 62 55 31 18 85 34 59 44 20 28 27 5 6 79 43 78 45 64 61 56 12 40 54 52 24 14 26 65 75 72 30 46 67 80 38 70 25 60 50 8 17 84 41 71 58 76 19 47 73 29 3 48 82 33 39 63 15 37 83 36 9 32 16 57 68 53 21 77 22 42 74", "output": "85 43 29 22 17 15 13 11 10 9 8 8 7 7 6 6 5 5 5 5 5 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 " }, { "input": "100\n39 78 71 61 54 13 17 81 30 33 83 98 44 10 45 87 75 47 70 84 41 86 49 94 85 91 37 64 5 56 67 79 28 89 50 53 77 93 81 14 97 67 58 6 48 60 89 62 29 3 38 8 88 19 66 63 100 17 43 97 21 12 58 76 2 78 25 73 99 11 27 18 57 46 4 72 68 45 74 18 2 80 51 52 42 59 55 35 1 95 42 92 36 40 59 15 7 21 97 53", "output": "100 50 34 25 20 17 15 13 11 10 10 9 8 7 7 6 6 6 6 5 5 5 5 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "1\n1", "output": "1 " } ]
31
0
-1
21,088
543
Road Improvement
[ "dp", "trees" ]
null
null
The country has *n* cities and *n*<=-<=1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to *n* inclusive. All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that the citizens are happy about road improvement if the path from the capital located in city *x* to any other city contains at most one bad road. Your task is — for every possible *x* determine the number of ways of improving the quality of some roads in order to meet the citizens' condition. As those values can be rather large, you need to print each value modulo 1<=000<=000<=007 (109<=+<=7).
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in the country. Next line contains *n*<=-<=1 positive integers *p*2,<=*p*3,<=*p*4,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*i*<=-<=1) — the description of the roads in the country. Number *p**i* means that the country has a road connecting city *p**i* and city *i*.
Print *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the sought number of ways to improve the quality of the roads modulo 1<=000<=000<=007 (109<=+<=7), if the capital of the country is at city number *i*.
[ "3\n1 1\n", "5\n1 2 3 4\n" ]
[ "4 3 3", "5 8 9 8 5" ]
none
[ { "input": "3\n1 1", "output": "4 3 3" }, { "input": "5\n1 2 3 4", "output": "5 8 9 8 5" }, { "input": "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "73741817 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913" }, { "input": "29\n1 2 2 4 4 6 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28", "output": "191 380 191 470 236 506 254 506 504 500 494 486 476 464 450 434 416 396 374 350 324 296 266 234 200 164 126 86 44" }, { "input": "70\n1 2 2 4 4 6 6 8 9 9 11 11 13 13 15 15 17 17 19 19 21 22 22 24 24 26 27 27 29 29 31 31 33 34 34 36 37 37 39 39 41 42 42 44 44 46 47 47 49 50 50 52 52 54 54 56 57 57 59 60 60 62 63 63 65 65 67 68 68", "output": "0 1000000005 0 499999996 249999999 749999986 374999994 874999963 999999938 499999970 62499881 531249945 93749781 546874895 109374581 554687295 117186681 558593345 121092131 560546070 123043656 124995179 562497594 125968539 562984274 126450416 126932291 563466150 127163621 563581815 127260071 563630040 127269866 127279659 563639834 127207694 127135727 563567868 126946019 563473014 126543716 126141411 563070710 125325359 562662684 123687534 122049707 561024858 118771194 115492679 557746344 108934221 55446711..." }, { "input": "59\n1 2 2 4 4 5 7 7 8 8 10 10 11 11 15 15 9 18 18 20 20 21 23 22 22 26 6 6 28 30 30 31 31 33 34 34 32 32 38 40 39 39 29 44 44 45 47 47 46 46 50 52 52 54 51 51 57 58", "output": "0 1000000005 0 499999996 499259752 500131906 498519506 453903141 456877573 963122521 230821046 981561265 981561265 115410524 784656845 892328427 892328427 415235638 207617820 331951678 748963765 998815735 165975843 582987926 999407872 332543823 666271916 492735403 494450227 485338898 330005231 366989446 553336825 864004193 776668417 932002101 932002101 775242091 893591565 183494727 591747368 946795787 946795787 488768546 73973791 454675898 659179041 829589525 829589525 147841416 181934138 841006939 9205034..." }, { "input": "2\n1", "output": "2 2" }, { "input": "3\n1 2", "output": "3 4 3" }, { "input": "69\n1 1 3 3 5 5 7 8 8 10 10 12 12 14 14 16 16 18 18 20 21 21 23 23 25 26 26 28 28 30 30 32 33 33 35 36 36 38 38 40 41 41 43 43 45 46 46 48 49 49 51 51 53 53 55 56 56 58 59 59 61 62 62 64 64 66 67 67", "output": "1000000006 500000004 499999999 750000004 749999993 875000001 874999978 999999961 999999985 62499920 31249961 93749852 46874927 109374716 54687359 117186944 58593473 121092650 60546326 123044687 124996722 62498362 125971106 62985554 126455031 126938954 63469478 127174380 63587191 127279022 63639512 127305201 127331378 63665690 127292181 127252982 63626492 127128810 63564406 126857579 126586346 63293174 126032438 63016220 124918901 123805362 61902682 121575425 119345486 59672744 114884180 57442091 105960854 ..." }, { "input": "137\n1 1 3 3 5 5 7 8 8 10 10 12 12 14 14 16 16 18 18 20 21 21 23 23 25 26 26 28 28 30 30 32 33 33 35 36 36 38 38 40 41 41 43 43 45 46 46 48 49 49 51 51 53 53 55 56 56 58 59 59 61 62 62 64 64 66 67 67 1 1 71 71 73 73 75 76 76 78 78 80 80 82 82 84 84 86 86 88 89 89 91 91 93 94 94 96 96 98 98 100 101 101 103 104 104 106 106 108 109 109 111 111 113 114 114 116 117 117 119 119 121 121 123 124 124 126 127 127 129 130 130 132 132 134 135 135", "output": "1 500000005 500000005 750000007 750000007 875000008 875000008 0 1 62499998 31250000 93749994 46874998 109374986 54687494 117187470 58593736 121093688 60546845 123046749 124999808 62499905 125976240 62988121 126464261 126952280 63476141 127195898 63597950 127316924 63658463 127375871 127434816 63717409 127461155 127487492 63743747 127494392 63747197 127485305 127476216 63738109 127446596 63723299 127381635 127316672 63658337 127183887 127051100 63525551 126784098 63392050 126249380 63124691 125179587 124109..." }, { "input": "150\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 14 15 15 15 16 16 16 17 17 17 18 18 18 19 19 19 20 20 20 21 21 21 22 22 22 23 23 23 24 24 24 25 25 25 26 26 26 27 27 27 28 28 28 28 29 29 29 29 30 30 30 30 31 31 31 31 31 32 32 32 32 32 33 33 33 33 33 33 34 34 34 34 34 34 35 35 35 35 35 35 35 36 36 36 36 36 36 36 37 37 37 37 37 37 37 37 37", "output": "0 1000000005 0 0 0 0 800000008 800000008 800000008 800000008 800000008 800000008 800000008 222222230 222222230 222222230 222222230 222222230 222222230 222222230 222222230 222222230 222222230 222222230 222222230 222222230 222222230 705882372 705882372 705882372 878787915 878787915 61538524 61538524 596899355 596899355 196881603 400000005 400000005 400000005 400000005 400000005 400000005 400000005 400000005 400000005 400000005 400000005 400000005 400000005 400000005 111111116 111111116 111111116 111111116 11..." } ]
514
72,294,400
3
21,108
515
Drazil and His Happy Friends
[ "brute force", "dsu", "meet-in-the-middle", "number theory" ]
null
null
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are *n* boys and *m* girls among his friends. Let's number them from 0 to *n*<=-<=1 and 0 to *m*<=-<=1 separately. In *i*-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, *i* starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever. Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
The first line contains two integer *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains integer *b* (0<=≤<=*b*<=≤<=*n*), denoting the number of happy boys among friends of Drazil, and then follow *b* distinct integers *x*1,<=*x*2,<=...,<=*x**b* (0<=≤<=*x**i*<=&lt;<=*n*), denoting the list of indices of happy boys. The third line conatins integer *g* (0<=≤<=*g*<=≤<=*m*), denoting the number of happy girls among friends of Drazil, and then follow *g* distinct integers *y*1,<=*y*2,<=... ,<=*y**g* (0<=≤<=*y**j*<=&lt;<=*m*), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
[ "2 3\n0\n1 0\n", "2 4\n1 0\n1 2\n", "2 3\n1 0\n1 1\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
By <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/169ade208e6eb4f9263c57aaff716529d59c3288.png" style="max-width: 100.0%;max-height: 100.0%;"/> we define the remainder of integer division of *i* by *k*. In first sample case: - On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. - On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. - On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. - On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. - On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
[ { "input": "2 3\n0\n1 0", "output": "Yes" }, { "input": "2 4\n1 0\n1 2", "output": "No" }, { "input": "2 3\n1 0\n1 1", "output": "Yes" }, { "input": "16 88\n6 5 14 2 0 12 7\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82", "output": "Yes" }, { "input": "52 91\n13 26 1 3 43 17 19 32 46 33 48 23 37 50\n25 78 26 1 40 2 67 42 4 56 30 70 84 32 20 85 59 8 86 34 73 23 10 88 24 11", "output": "No" }, { "input": "26 52\n8 0 14 16 17 7 9 10 11\n15 39 15 2 41 42 30 17 18 31 6 21 35 48 50 51", "output": "No" }, { "input": "50 50\n0\n0", "output": "No" }, { "input": "27 31\n4 25 5 19 20\n26 5 28 17 2 1 0 26 23 12 29 6 4 25 19 15 13 20 24 8 27 22 30 3 10 9 7", "output": "Yes" }, { "input": "55 79\n5 51 27 36 45 53\n30 15 28 0 5 38 3 34 30 35 1 32 12 27 42 39 69 33 10 63 16 29 76 19 60 70 67 31 78 68 45", "output": "Yes" }, { "input": "79 23\n35 31 62 14 9 46 18 68 69 42 13 50 77 23 76 5 53 40 16 32 74 54 38 25 45 39 26 37 66 78 3 48 10 17 56 59\n13 16 0 8 6 18 14 21 11 20 4 15 13 22", "output": "Yes" }, { "input": "7 72\n1 4\n3 49 32 28", "output": "Yes" }, { "input": "100 50\n31 52 54 8 60 61 62 63 64 16 19 21 73 25 76 77 79 30 81 32 33 34 37 88 39 40 91 42 94 95 96 98\n18 0 1 3 5 6 7 9 15 18 20 22 24 28 35 36 43 47 49", "output": "No" }, { "input": "98 49\n33 0 51 52 6 57 10 12 63 15 16 19 20 21 72 73 74 76 77 78 30 31 81 33 83 37 38 39 40 92 44 45 95 97\n15 4 5 7 9 11 13 17 18 22 26 35 36 41 42 47", "output": "No" }, { "input": "50 50\n14 7 8 12 16 18 22 23 24 28 30 35 40 46 49\n35 0 1 2 3 4 5 6 9 10 11 13 14 15 17 19 20 21 25 26 27 29 31 32 33 34 36 37 38 39 41 43 44 45 47 48", "output": "No" }, { "input": "30 44\n3 8 26 28\n6 2 30 38 26 8 6", "output": "No" }, { "input": "69 72\n18 58 46 52 43 1 55 16 7 4 38 68 14 32 53 41 29 2 59\n21 22 43 55 13 70 4 7 31 10 23 56 44 62 17 50 53 5 41 11 65 32", "output": "No" }, { "input": "76 28\n10 24 13 61 45 29 57 41 21 37 11\n2 12 9", "output": "No" }, { "input": "65 75\n15 25 60 12 62 37 22 47 52 3 63 58 13 14 49 34\n18 70 10 2 52 22 47 72 57 38 48 13 73 3 19 4 74 49 34", "output": "No" }, { "input": "6 54\n1 5\n14 13 49 31 37 44 2 15 51 52 22 28 10 35 47", "output": "No" }, { "input": "96 36\n34 84 24 0 48 85 13 61 37 62 38 86 75 3 16 64 40 28 76 53 5 17 42 6 7 91 67 55 68 92 57 11 71 35 59\n9 1 14 15 17 18 30 6 8 35", "output": "No" }, { "input": "40 40\n23 0 2 3 4 5 7 11 15 16 17 18 19 22 25 28 29 30 31 32 34 35 36 37\n16 1 6 8 9 10 12 13 14 20 21 23 24 26 27 38 39", "output": "No" }, { "input": "66 66\n24 2 35 3 36 4 5 10 45 14 48 18 51 19 21 55 22 23 24 25 26 63 31 65 32\n21 0 1 37 6 40 7 8 42 45 13 15 16 50 53 23 24 60 28 62 63 31", "output": "No" }, { "input": "20 20\n9 0 3 4 6 7 8 10 12 13\n10 1 2 5 9 11 14 15 16 18 19", "output": "No" }, { "input": "75 30\n18 46 47 32 33 3 34 35 21 51 7 9 54 39 72 42 59 29 14\n8 0 17 5 6 23 26 27 13", "output": "No" }, { "input": "100 50\n30 50 54 7 8 59 60 61 62 63 64 15 16 18 19 20 22 73 27 79 83 86 87 89 42 93 94 45 46 97 98\n20 1 2 3 5 6 17 21 24 25 26 28 30 31 32 34 35 38 40 41 49", "output": "Yes" }, { "input": "98 98\n43 49 1 51 3 53 4 55 56 8 9 10 60 11 12 61 64 16 65 17 19 20 21 72 24 74 25 77 78 31 34 35 36 37 87 88 89 42 92 43 44 94 46 96\n34 50 2 52 5 54 9 62 63 15 18 68 70 22 72 75 26 27 77 30 81 82 83 35 36 37 87 88 89 90 41 93 95 96 48", "output": "No" }, { "input": "100 100\n45 50 1 4 5 55 7 8 10 60 61 62 63 14 65 66 17 18 20 21 22 24 25 27 78 28 29 30 31 82 83 33 84 36 37 38 39 40 41 42 44 45 46 48 98 49\n34 50 1 2 52 3 54 56 7 9 59 61 14 16 67 18 69 22 73 24 76 79 81 82 84 35 36 38 39 90 43 44 45 47 49", "output": "No" }, { "input": "76 72\n29 4 64 68 20 8 12 50 42 46 0 70 11 37 75 47 45 29 17 19 73 9 41 31 35 67 65 39 51 55\n25 60 32 48 42 8 6 9 7 31 19 25 5 33 51 61 67 55 49 27 29 53 39 65 35 13", "output": "Yes" }, { "input": "39 87\n16 18 15 30 33 21 9 3 31 16 10 34 20 35 8 26 23\n36 33 75 81 24 42 54 78 39 57 60 30 36 63 4 76 25 1 40 73 22 58 49 85 31 74 59 20 44 83 65 23 41 71 47 14 35", "output": "Yes" }, { "input": "36 100\n10 0 32 4 5 33 30 18 14 35 7\n29 60 32 20 4 16 69 5 38 50 46 74 94 18 82 2 66 22 42 55 51 91 67 75 35 95 43 79 3 27", "output": "Yes" }, { "input": "90 25\n26 55 30 35 20 15 26 6 1 41 81 76 46 57 17 12 67 77 27 47 62 8 43 63 3 48 19\n9 10 16 21 7 17 12 13 19 9", "output": "Yes" }, { "input": "66 66\n26 0 54 6 37 43 13 25 38 2 32 56 20 50 39 27 51 9 64 4 16 17 65 11 5 47 23\n15 6 24 43 49 25 20 14 63 27 3 58 52 53 11 41", "output": "No" }, { "input": "24 60\n4 0 2 19 23\n15 12 24 49 2 14 3 52 28 5 6 19 32 33 34 35", "output": "Yes" }, { "input": "80 40\n27 0 41 44 45 6 47 8 10 52 13 14 16 17 18 59 21 62 23 64 26 68 29 32 75 37 78 39\n13 2 3 9 11 15 20 25 27 30 31 33 34 36", "output": "Yes" }, { "input": "66 99\n23 33 35 36 38 8 10 44 11 45 46 47 50 19 54 22 55 23 58 59 27 61 30 65\n32 33 67 69 4 70 38 6 39 7 74 42 9 43 12 13 14 15 81 82 84 85 20 87 89 90 24 58 59 27 95 97 31", "output": "Yes" }, { "input": "100 40\n25 61 42 2 3 25 46 66 68 69 49 9 10 50 91 72 92 33 73 53 14 15 55 96 36 39\n12 0 22 3 23 4 6 27 11 35 37 38 39", "output": "Yes" }, { "input": "90 30\n27 15 16 2 32 78 49 64 65 50 6 66 21 22 82 23 39 84 85 10 86 56 27 87 13 58 44 74\n7 19 4 20 24 25 12 27", "output": "No" }, { "input": "75 75\n33 30 74 57 23 19 42 71 11 44 29 58 43 48 61 63 13 27 50 17 18 70 64 39 12 32 36 10 40 51 49 1 54 73\n8 43 23 0 7 63 47 74 28", "output": "No" }, { "input": "98 98\n23 6 81 90 28 38 51 23 69 13 95 15 16 88 58 10 26 42 44 54 92 27 45 39\n18 20 70 38 82 72 61 37 78 74 23 15 56 59 35 93 64 28 57", "output": "No" }, { "input": "75 75\n19 48 3 5 67 23 8 70 45 63 36 38 56 15 10 37 52 11 9 27\n21 13 9 45 28 59 36 30 43 5 38 27 40 50 17 41 71 8 51 63 1 33", "output": "No" }, { "input": "3 20\n0\n1 19", "output": "Yes" }, { "input": "41 2\n1 33\n0", "output": "Yes" }, { "input": "50 49\n1 49\n0", "output": "Yes" }, { "input": "3 50\n0\n1 49", "output": "Yes" }, { "input": "100 100\n50 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\n49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98", "output": "No" }, { "input": "100 100\n50 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\n50 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99", "output": "Yes" }, { "input": "91 98\n78 0 1 2 3 4 5 7 8 9 10 11 12 14 15 16 17 18 19 21 22 23 24 25 26 28 29 30 31 32 33 35 36 37 38 39 40 42 43 44 45 46 47 49 50 51 52 53 54 56 57 58 59 60 61 63 64 65 66 67 68 70 71 72 73 74 75 77 78 79 80 81 82 84 85 86 87 88 89\n84 0 1 2 3 4 5 7 8 9 10 11 12 14 15 16 17 18 19 21 22 23 24 25 26 28 29 30 31 32 33 35 36 37 38 39 40 42 43 44 45 46 47 49 50 51 52 53 54 56 57 58 59 60 61 63 64 65 66 67 68 70 71 72 73 74 75 77 78 79 80 81 82 84 85 86 87 88 89 91 92 93 94 95 96", "output": "No" }, { "input": "99 84\n66 0 2 3 5 6 8 9 11 12 14 15 17 18 20 21 23 24 26 27 29 30 32 33 35 36 38 39 41 42 44 45 47 48 50 51 53 54 56 57 59 60 62 63 65 66 68 69 71 72 74 75 77 78 80 81 83 84 86 87 89 90 92 93 95 96 98\n56 0 2 3 5 6 8 9 11 12 14 15 17 18 20 21 23 24 26 27 29 30 32 33 35 36 38 39 41 42 44 45 47 48 50 51 53 54 56 57 59 60 62 63 65 66 68 69 71 72 74 75 77 78 80 81 83", "output": "No" }, { "input": "75 90\n60 0 2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20 22 23 24 25 27 28 29 30 32 33 34 35 37 38 39 40 42 43 44 45 47 48 49 50 52 53 54 55 57 58 59 60 62 63 64 65 67 68 69 70 72 73 74\n72 0 2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20 22 23 24 25 27 28 29 30 32 33 34 35 37 38 39 40 42 43 44 45 47 48 49 50 52 53 54 55 57 58 59 60 62 63 64 65 67 68 69 70 72 73 74 75 77 78 79 80 82 83 84 85 87 88 89", "output": "No" }, { "input": "5 7\n1 0\n1 0", "output": "Yes" }, { "input": "100 1\n1 99\n0", "output": "Yes" }, { "input": "4 1\n1 3\n0", "output": "Yes" }, { "input": "4 5\n3 0 1 3\n4 0 1 3 4", "output": "Yes" }, { "input": "100 99\n1 99\n0", "output": "Yes" }, { "input": "2 3\n1 0\n2 0 2", "output": "Yes" } ]
46
2,867,200
-1
21,206
0
none
[ "none" ]
null
null
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible. There are *n* (*n* is always even) possible starting positions for characters marked along the *Ox* axis. The positions are given by their distinct coordinates *x*1,<=*x*2,<=...,<=*x**n*, two characters cannot end up at the same position. Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be *n*<=-<=2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting. Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally.
The first line on the input contains a single integer *n* (2<=≤<=*n*<=≤<=200<=000, *n* is even) — the number of positions available initially. The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109), giving the coordinates of the corresponding positions.
Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally.
[ "6\n0 1 3 7 15 31\n", "2\n73 37\n" ]
[ "7\n", "36\n" ]
In the first sample one of the optimum behavior of the players looks like that: 1. Vova bans the position at coordinate 15; 1. Lesha bans the position at coordinate 3; 1. Vova bans the position at coordinate 31; 1. Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7. In the second sample there are only two possible positions, so there will be no bans.
[ { "input": "6\n0 1 3 7 15 31", "output": "7" }, { "input": "2\n73 37", "output": "36" }, { "input": "2\n0 1000000000", "output": "1000000000" }, { "input": "8\n729541013 135019377 88372488 319157478 682081360 558614617 258129110 790518782", "output": "470242129" }, { "input": "2\n0 1", "output": "1" }, { "input": "8\n552283832 997699491 89302459 301640204 288141798 31112026 710831619 862166501", "output": "521171806" }, { "input": "4\n0 500000000 500000001 1000000000", "output": "500000000" }, { "input": "18\n515925896 832652240 279975694 570998878 28122427 209724246 898414431 709461320 358922485 439508829 403574907 358500312 596248410 968234748 187793884 728450713 30350176 528924900", "output": "369950401" }, { "input": "20\n713900269 192811911 592111899 609607891 585084800 601258511 223103775 876894656 751583891 230837577 971499807 312977833 344314550 397998873 558637732 216574673 913028292 762852863 464376621 61315042", "output": "384683838" }, { "input": "10\n805513144 38998401 16228409 266085559 293487744 471510400 138613792 649258082 904651590 244678415", "output": "277259335" }, { "input": "6\n0 166666666 333333333 499999998 666666665 833333330", "output": "499999997" }, { "input": "16\n1 62500001 125000001 187500000 250000000 312500000 375000000 437500001 500000000 562500000 625000000 687500001 750000001 812500002 875000002 937500000", "output": "499999999" }, { "input": "12\n5 83333336 166666669 250000001 333333336 416666670 500000004 583333336 666666667 750000001 833333334 916666671", "output": "499999998" }, { "input": "20\n54 50000046 100000041 150000049 200000061 250000039 300000043 350000054 400000042 450000045 500000076 550000052 600000064 650000065 700000055 750000046 800000044 850000042 900000052 950000054", "output": "499999988" } ]
46
102,400
0
21,235
860
Arkady and a Nobody-men
[ "data structures", "dfs and similar", "trees" ]
null
null
Arkady words in a large company. There are *n* employees working in a system of a strict hierarchy. Namely, each employee, with an exception of the CEO, has exactly one immediate manager. The CEO is a manager (through a chain of immediate managers) of all employees. Each employee has an integer rank. The CEO has rank equal to 1, each other employee has rank equal to the rank of his immediate manager plus 1. Arkady has a good post in the company, however, he feels that he is nobody in the company's structure, and there are a lot of people who can replace him. He introduced the value of replaceability. Consider an employee *a* and an employee *b*, the latter being manager of *a* (not necessarily immediate). Then the replaceability *r*(*a*,<=*b*) of *a* with respect to *b* is the number of subordinates (not necessarily immediate) of the manager *b*, whose rank is not greater than the rank of *a*. Apart from replaceability, Arkady introduced the value of negligibility. The negligibility *z**a* of employee *a* equals the sum of his replaceabilities with respect to all his managers, i.e. , where the sum is taken over all his managers *b*. Arkady is interested not only in negligibility of himself, but also in negligibility of all employees in the company. Find the negligibility of each employee for Arkady.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of employees in the company. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=*n*), where *p**i*<==<=0 if the *i*-th employee is the CEO, otherwise *p**i* equals the id of the immediate manager of the employee with id *i*. The employees are numbered from 1 to *n*. It is guaranteed that there is exactly one 0 among these values, and also that the CEO is a manager (not necessarily immediate) for all the other employees.
Print *n* integers — the negligibilities of all employees in the order of their ids: *z*1,<=*z*2,<=...,<=*z**n*.
[ "4\n0 1 2 1\n", "5\n2 3 4 5 0\n", "5\n0 1 1 1 3\n" ]
[ "0 2 4 2 \n", "10 6 3 1 0 \n", "0 3 3 3 5 \n" ]
Consider the first example: - The CEO has no managers, thus *z*<sub class="lower-index">1</sub> = 0. - *r*(2, 1) = 2 (employees 2 and 4 suit the conditions, employee 3 has too large rank). Thus *z*<sub class="lower-index">2</sub> = *r*(2, 1) = 2. - Similarly, *z*<sub class="lower-index">4</sub> = *r*(4, 1) = 2. - *r*(3, 2) = 1 (employee 3 is a subordinate of 2 and has suitable rank). *r*(3, 1) = 3 (employees 2, 3, 4 suit the conditions). Thus *z*<sub class="lower-index">3</sub> = *r*(3, 2) + *r*(3, 1) = 4.
[]
46
0
0
21,237
15
Triangles
[ "combinatorics", "dp" ]
E. Triangles
1
64
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has *n* levels, where *n* is an even number. In the local council you were given an area map, where the granny's house is marked by point *H*, parts of dense forest are marked grey (see the picture to understand better). After a long time at home Peter decided to yield to his granny's persuasions and step out for a breath of fresh air. Being prudent, Peter plans the route beforehand. The route, that Peter considers the most suitable, has the following characteristics: - it starts and ends in the same place — the granny's house; - the route goes along the forest paths only (these are the segments marked black in the picture); - the route has positive length (to step out for a breath of fresh air Peter has to cover some distance anyway); - the route cannot cross itself; - there shouldn't be any part of dense forest within the part marked out by this route; You should find the amount of such suitable oriented routes modulo 1000000009. The example of the area map for *n*<==<=12 is given in the picture. Since the map has a regular structure, you can construct it for other *n* by analogy using the example.
The input data contain the only even integer *n* (2<=≤<=*n*<=≤<=106).
Output the only number — the amount of Peter's routes modulo 1000000009.
[ "2\n", "4\n" ]
[ "10\n", "74\n" ]
none
[ { "input": "2", "output": "10" }, { "input": "4", "output": "74" }, { "input": "6", "output": "1354" }, { "input": "8", "output": "163594" }, { "input": "10", "output": "122492554" }, { "input": "966", "output": "154440215" }, { "input": "9158", "output": "481655864" }, { "input": "95576", "output": "52134285" }, { "input": "804974", "output": "830331886" }, { "input": "635758", "output": "524558133" }, { "input": "982894", "output": "610514474" }, { "input": "813678", "output": "195839973" }, { "input": "524288", "output": "858669864" }, { "input": "908550", "output": "307673807" }, { "input": "988794", "output": "57571447" }, { "input": "939636", "output": "402023314" }, { "input": "956022", "output": "864671299" }, { "input": "972408", "output": "377259665" }, { "input": "988794", "output": "57571447" }, { "input": "905180", "output": "247958166" }, { "input": "921566", "output": "838186871" }, { "input": "975778", "output": "995284797" }, { "input": "992164", "output": "184482083" }, { "input": "908550", "output": "307673807" }, { "input": "924936", "output": "867859567" }, { "input": "939636", "output": "402023314" }, { "input": "992164", "output": "184482083" }, { "input": "906864", "output": "748483990" }, { "input": "921566", "output": "838186871" }, { "input": "974094", "output": "9604500" }, { "input": "38", "output": "913760132" }, { "input": "94", "output": "45354328" }, { "input": "48", "output": "980993190" }, { "input": "54", "output": "111356740" }, { "input": "8", "output": "163594" }, { "input": "14", "output": "809112458" }, { "input": "68", "output": "940618832" }, { "input": "24", "output": "697629445" }, { "input": "30", "output": "698593821" }, { "input": "84", "output": "222712293" }, { "input": "988794", "output": "57571447" }, { "input": "941322", "output": "359985814" }, { "input": "956022", "output": "864671299" }, { "input": "908550", "output": "307673807" }, { "input": "923250", "output": "463682665" }, { "input": "939636", "output": "402023314" }, { "input": "999994", "output": "381170049" }, { "input": "999996", "output": "629260868" }, { "input": "999998", "output": "336683304" }, { "input": "1000000", "output": "958220352" }, { "input": "140", "output": "256406051" }, { "input": "168", "output": "816814227" }, { "input": "160", "output": "176472603" }, { "input": "188", "output": "249468441" }, { "input": "180", "output": "320858917" }, { "input": "448", "output": "511315133" }, { "input": "410", "output": "485353876" }, { "input": "372", "output": "993326044" }, { "input": "726", "output": "827884602" }, { "input": "716", "output": "687598196" } ]
92
0
-1
21,260
0
none
[ "none" ]
null
null
Поликарп мечтает стать программистом и фанатеет от степеней двойки. Среди двух чисел ему больше нравится то, которое делится на большую степень числа 2. По заданной последовательности целых положительных чисел *a*1,<=*a*2,<=...,<=*a**n* требуется найти *r* — максимальную степень числа 2, на которую делится хотя бы одно из чисел последовательности. Кроме того, требуется вывести количество чисел *a**i*, которые делятся на *r*.
В первой строке записано целое число *n* (1<=≤<=*n*<=≤<=100) — длина последовательности *a*. Во второй строке записана последовательность целых чисел *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Выведите два числа: - *r* — максимальную степень двойки, на которую делится хотя бы одно из чисел заданной последовательности, - количество элементов последовательности, которые делятся на *r*.
[ "5\n80 7 16 4 48\n", "4\n21 5 3 33\n" ]
[ "16 3\n", "1 4\n" ]
В первом тестовом примере максимальная степень двойки, на которую делится хотя бы одно число, равна 16 = 2<sup class="upper-index">4</sup>, на неё делятся числа 80, 16 и 48. Во втором тестовом примере все четыре числа нечётные, поэтому делятся только на 1 = 2<sup class="upper-index">0</sup>. Это и будет максимальной степенью двойки для данного примера.
[ { "input": "5\n80 7 16 4 48", "output": "16 3" }, { "input": "4\n21 5 3 33", "output": "1 4" }, { "input": "10\n8 112 52 86 93 102 24 24 100 826791168", "output": "256 1" }, { "input": "3\n458297759 18 104", "output": "8 1" }, { "input": "7\n12 14 40 8 74 104 11", "output": "8 3" }, { "input": "11\n35 16 664311776 46 48 52 63 82 84 80 23", "output": "32 1" }, { "input": "7\n67 68 58 24 96 73 72", "output": "32 1" }, { "input": "8\n48 112 40 8 112 14 80 36", "output": "16 4" }, { "input": "10\n14 6 68 8 84 949689614 91 26 80 56", "output": "16 1" }, { "input": "4\n39 56 939117699 56", "output": "8 2" }, { "input": "5\n90 18 56 64 32", "output": "64 1" }, { "input": "9\n64 95 32 64 96 80 100 96 66", "output": "64 2" }, { "input": "20\n105407881 735510073 587127085 111067442 126807503 250859170 778634763 919694130 592496831 462347734 532487590 475786023 951527598 183635985 612791353 447723541 409812454 900700354 801564406 532793851", "output": "2 9" }, { "input": "20\n850632510 530517796 700510265 454664263 131947796 418444926 921278498 251889644 705327498 892480283 884422799 479219117 399278535 80826412 496934492 448261193 39033930 49426174 621130971 808191947", "output": "4 5" }, { "input": "20\n780355354 620754888 193377552 463211662 46248927 312489308 472238901 823707535 138518748 267363170 19751630 193171944 411443343 858525221 458019868 490268043 7864848 218005780 744553112 83590041", "output": "16 2" }, { "input": "20\n29023024 579267278 217400978 121454376 235087976 154574217 708760940 84623652 195299056 329204104 527952531 822521791 513319036 285749488 292843688 389260660 498981613 835987320 444201058 251639011", "output": "16 3" }, { "input": "20\n267784376 576420580 392773522 296581728 508523192 812838532 920098710 624114448 194991560 850559568 29915376 785467756 490019770 524237000 871021232 970867040 769417893 210139479 445850586 333230268", "output": "32 2" }, { "input": "20\n860654784 630481952 430211228 13468621 33985780 279050728 782571295 83521731 818343376 508318323 550168944 763113524 152970477 502262855 934672824 712697136 451447464 732781790 71573907 50381000", "output": "64 1" }, { "input": "20\n673865536 152236510 957204496 401364096 969402746 287701920 768559538 642049008 736330680 179648832 480094052 225156558 957671104 726304328 612058916 257008256 173639040 673864512 431405191 454360662", "output": "128 3" }, { "input": "20\n706678380 597303020 176804438 146220776 485004772 799346560 692789954 737954674 398118372 231976240 957701828 556811840 74342144 966291136 893909760 745234360 44276827 878935416 975182148 322390872", "output": "256 2" }, { "input": "20\n442107036 883530112 852749824 997931232 902004480 838557324 186049792 827163136 3843737 603467472 383038751 548720704 843680384 906511492 591629504 41722624 79778650 839163077 880599104 456148480", "output": "512 3" }, { "input": "20\n667815852 318176276 693849088 724201296 188710200 39249152 929966576 651876056 580647856 575425536 367972188 647585808 833274694 578646160 593232968 747635620 973200384 608104976 754724885 832141532", "output": "1024 3" }, { "input": "20\n448394296 216942008 573160113 728121900 769966592 164290016 721604576 970539238 338262776 947927236 587084928 648622584 194610176 435895128 896641600 70371299 323855936 292543040 28980004 787518144", "output": "1024 1" }, { "input": "20\n269609216 130664082 366702720 254341120 817371149 791314720 886888448 933572608 411407552 86828928 280842240 259838684 821718144 131427072 316135424 189065544 173073728 20176393 508466777 927373184", "output": "4096 3" }, { "input": "20\n620004352 728068096 230808280 347805952 153777664 828290048 941633792 681387488 689396208 283672752 130113536 124222464 425923944 365087488 68677632 957876224 86529928 278224896 516674048 203400656", "output": "8192 2" }, { "input": "20\n957116416 938908864 254662656 28720000 829892752 344974528 22716709 493757015 729003570 868597760 675246081 648372096 233462945 949382272 600301600 979810000 695847936 383948336 388551600 125714432", "output": "16384 2" }, { "input": "20\n793801200 316289782 968725504 765722788 172605440 945717248 613921792 54457344 725727714 598109120 390593416 438184064 245627755 91785071 855031808 778218454 34154240 686966990 736207232 674856960", "output": "32768 2" }, { "input": "20\n356744192 260087808 498705408 60572928 360008038 968932864 66422016 929599488 973047264 426826855 483623936 826974208 487705600 787624960 951492608 343212032 661494459 244741040 409686016 20327511", "output": "65536 1" }, { "input": "20\n775136472 720896 585826304 479121408 116085124 608963940 286154752 103731391 192445952 745342784 887373824 351469568 201183616 579608192 26928128 861796540 579858432 30678450 359436288 476635136", "output": "65536 3" }, { "input": "20\n962265088 792592384 175088192 998003136 645410688 697606715 918541862 551100416 247733780 770750336 264468484 185550848 201588736 989953440 799341904 355386616 611975168 792208864 272619608 239038496", "output": "262144 1" }, { "input": "20\n420610048 361879464 11984896 648474908 567803904 811903488 777519104 677117952 794312704 362283008 946274304 824280862 716753756 318224096 114032640 470286336 153747456 698417152 410143376 577402584", "output": "524288 4" }, { "input": "20\n916422656 61941502 755804160 993386496 371458048 361240704 791150592 218434752 532807680 517277964 158990336 877143936 263469056 339735363 438097920 842006528 200088380 651153211 932184064 443051520", "output": "1048576 2" }, { "input": "20\n855113728 457249360 705319632 368396992 886571008 261505024 647304078 73518537 749228480 194262008 148995424 860356608 950009856 649068544 430006272 363153728 105360192 37648488 426766453 565502131", "output": "2097152 1" }, { "input": "20\n283119671 29874944 739246080 972336073 468233952 926107648 665047794 354091008 141526171 529537472 937811232 970178560 948105794 433304784 186908672 912261120 858259456 972472320 4889883 76907904", "output": "2097152 1" }, { "input": "20\n386375302 77596672 411041792 683671552 667767296 625737728 947733007 612950256 129715876 813694976 782385152 164455808 647131408 385566720 65880960 96010240 484900864 385339335 533303296 660648928", "output": "8388608 2" }, { "input": "20\n786432000 123007744 351391826 216719360 391303168 920693440 652456192 715653120 915090432 26559797 680345413 346423296 401288334 437510144 122224640 652606928 182370304 683278336 656773980 316229632", "output": "2097152 1" }, { "input": "20\n850523026 993052212 100663296 830207504 281863570 426977070 803471360 796327936 369098752 842702848 526319616 785973248 501219328 801245229 853162496 689842176 292886257 859104512 631656960 512295035", "output": "33554432 2" }, { "input": "20\n694157312 375128064 494927872 199980576 823836320 358259440 950409408 215242336 126689280 697139200 471849008 854435840 935337515 589698048 157286400 161334770 738197504 594549920 416464896 690872320", "output": "67108864 1" }, { "input": "20\n785580032 987226112 398458880 437531712 335544320 676369664 533876736 181598976 117440512 924319744 469762048 443505526 949904673 710590464 533015579 17793024 781975552 803666112 973078528 866337472", "output": "67108864 2" }, { "input": "20\n558266065 720866235 285275468 139607080 150235150 855638016 815792128 358744064 620756992 438077440 73404848 892534480 939524096 195793792 838860800 364010680 931135488 254242133 374493422 578846720", "output": "134217728 1" }, { "input": "20\n909362176 291766272 557318144 348389376 426770432 526614528 213516288 932012606 344981504 138412032 6291456 354007477 536870912 557842432 536870912 668205056 398003707 609566463 893207232 83886080", "output": "536870912 2" }, { "input": "1\n167959139", "output": "1 1" }, { "input": "2\n641009859 54748095", "output": "1 2" }, { "input": "10\n1000000 1 1000000 1 1000000 1 1000000 1 1000000 1", "output": "64 5" }, { "input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "512 5" }, { "input": "8\n1 1 1 1 1 1 1 1", "output": "1 8" }, { "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": "64 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" }, { "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": "2 100" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "1 100" }, { "input": "1\n536870912", "output": "536870912 1" } ]
62
4,608,000
3
21,263
776
The Holmes Children
[ "math", "number theory" ]
null
null
The Holmes children are fighting over who amongst them is the cleverest. Mycroft asked Sherlock and Eurus to find value of *f*(*n*), where *f*(1)<==<=1 and for *n*<=≥<=2, *f*(*n*) is the number of distinct ordered positive integer pairs (*x*,<=*y*) that satisfy *x*<=+<=*y*<==<=*n* and *gcd*(*x*,<=*y*)<==<=1. The integer *gcd*(*a*,<=*b*) is the greatest common divisor of *a* and *b*. Sherlock said that solving this was child's play and asked Mycroft to instead get the value of . Summation is done over all positive integers *d* that divide *n*. Eurus was quietly observing all this and finally came up with her problem to astonish both Sherlock and Mycroft. She defined a *k*-composite function *F**k*(*n*) recursively as follows: She wants them to tell the value of *F**k*(*n*) modulo 1000000007.
A single line of input contains two space separated integers *n* (1<=≤<=*n*<=≤<=1012) and *k* (1<=≤<=*k*<=≤<=1012) indicating that Eurus asks Sherlock and Mycroft to find the value of *F**k*(*n*) modulo 1000000007.
Output a single integer — the value of *F**k*(*n*) modulo 1000000007.
[ "7 1\n", "10 2\n" ]
[ "6", "4" ]
In the first case, there are 6 distinct ordered pairs (1, 6), (2, 5), (3, 4), (4, 3), (5, 2) and (6, 1) satisfying *x* + *y* = 7 and *gcd*(*x*, *y*) = 1. Hence, *f*(7) = 6. So, *F*<sub class="lower-index">1</sub>(7) = *f*(*g*(7)) = *f*(*f*(7) + *f*(1)) = *f*(6 + 1) = *f*(7) = 6.
[ { "input": "7 1", "output": "6" }, { "input": "10 2", "output": "4" }, { "input": "640 15", "output": "2" }, { "input": "641 17", "output": "2" }, { "input": "641 2000", "output": "1" }, { "input": "961 2", "output": "930" }, { "input": "524288 1000000000000", "output": "1" }, { "input": "557056 12", "output": "8192" }, { "input": "999961 19", "output": "512" }, { "input": "891581 1", "output": "889692" }, { "input": "500009 1", "output": "500008" }, { "input": "549755813888 2", "output": "877905026" }, { "input": "893277279607 1", "output": "275380949" }, { "input": "500000000023 2", "output": "999996529" }, { "input": "999999999937 1", "output": "999992943" }, { "input": "549755813888 38", "output": "1048576" }, { "input": "549755813888 100000", "output": "1" }, { "input": "847288609443 47", "output": "6" }, { "input": "847288609443 200", "output": "1" }, { "input": "999999999937 10000000000", "output": "1" }, { "input": "1 100", "output": "1" }, { "input": "1000000000000 1000000000000", "output": "1" }, { "input": "926517392239 2", "output": "20284739" }, { "input": "177463864070 57", "output": "4" }, { "input": "261777837818 43", "output": "1024" }, { "input": "170111505856 14", "output": "75497472" }, { "input": "135043671066 29", "output": "32768" }, { "input": "334796349382 43", "output": "1024" }, { "input": "989864800574 57", "output": "16" }, { "input": "969640267457 33", "output": "131072" }, { "input": "23566875403 23", "output": "262144" }, { "input": "730748768952 11", "output": "251658240" }, { "input": "997200247414 6", "output": "159532369" }, { "input": "331725641503 32", "output": "262144" }, { "input": "218332248232 2", "output": "570962709" }, { "input": "275876196794 19", "output": "2097152" }, { "input": "500133829908 18", "output": "16777216" }, { "input": "483154390901 6", "output": "72921411" }, { "input": "397631788999 25", "output": "2097152" }, { "input": "937746931140 51", "output": "128" }, { "input": "483650008814 18", "output": "33554432" }, { "input": "927159567 20", "output": "65536" }, { "input": "225907315952 14", "output": "50331648" }, { "input": "203821114680 58", "output": "8" }, { "input": "975624549148 18", "output": "16777216" }, { "input": "234228562369 46", "output": "1024" }, { "input": "485841800462 31", "output": "65536" }, { "input": "12120927584 7", "output": "94371840" }, { "input": "693112248210 36", "output": "16384" }, { "input": "372014205011 18", "output": "67108864" }, { "input": "371634364529 19", "output": "33554432" }, { "input": "845593725265 49", "output": "256" }, { "input": "580294660613 59", "output": "8" }, { "input": "247972832713 57", "output": "8" }, { "input": "246144568124 21", "output": "4194304" }, { "input": "955067149029 42", "output": "4096" }, { "input": "107491536450 46", "output": "512" }, { "input": "696462733578 50", "output": "256" }, { "input": "788541271619 28", "output": "1048576" }, { "input": "167797376193 26", "output": "1048576" }, { "input": "381139218512 16", "output": "50331648" }, { "input": "489124396932 38", "output": "32768" }, { "input": "619297137390 54", "output": "32" }, { "input": "766438750762 59", "output": "128" }, { "input": "662340381277 6", "output": "22476436" }, { "input": "407943488152 42", "output": "2048" }, { "input": "25185014181 30", "output": "8192" }, { "input": "939298330812 58", "output": "32" }, { "input": "78412884457 59", "output": "4" }, { "input": "338042434098 18", "output": "33554432" }, { "input": "289393192315 4", "output": "239438877" }, { "input": "175466750569 53", "output": "32" }, { "input": "340506728610 27", "output": "524288" }, { "input": "294635102279 20", "output": "4194304" }, { "input": "341753622008 21", "output": "4194304" }, { "input": "926517392239 592291529821", "output": "1" }, { "input": "177463864070 46265116367", "output": "1" }, { "input": "261777837818 37277859111", "output": "1" }, { "input": "170111505856 67720156918", "output": "1" }, { "input": "135043671066 116186285375", "output": "1" }, { "input": "334796349382 59340039141", "output": "1" }, { "input": "989864800574 265691489675", "output": "1" }, { "input": "969640267457 377175394707", "output": "1" }, { "input": "23566875403 21584772251", "output": "1" }, { "input": "730748768952 136728169835", "output": "1" }, { "input": "997200247414 829838591426", "output": "1" }, { "input": "331725641503 251068357277", "output": "1" }, { "input": "218332248232 166864935018", "output": "1" }, { "input": "275876196794 55444205659", "output": "1" }, { "input": "500133829908 188040404706", "output": "1" }, { "input": "483154390901 170937413735", "output": "1" }, { "input": "397631788999 80374663977", "output": "1" }, { "input": "937746931140 714211328211", "output": "1" }, { "input": "483650008814 63656897108", "output": "1" }, { "input": "927159567 694653032", "output": "1" }, { "input": "1 1000000000000", "output": "1" }, { "input": "1000000007 1000000007", "output": "1" }, { "input": "123456789 123", "output": "1" }, { "input": "2 100000000000", "output": "1" }, { "input": "9903870440 9831689586", "output": "1" }, { "input": "29000000261 4", "output": "879140815" }, { "input": "1000000009 3", "output": "281397888" }, { "input": "96000000673 3", "output": "999999975" } ]
389
307,200
3
21,264
926
Choose Place
[]
null
null
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right. Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture: Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard. You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'. Find any of the most convenient vacant places for Petya.
The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' — the description of the left desk in the current row; a character '-' — the aisle; two characters, each is '*' or '.' — the description of the center desk in the current row; a character '-' — the aisle; two characters, each is '*' or '.' — the description of the right desk in the current row. So, the length of each of the six lines is 8. It is guaranteed that there is at least one vacant place in the classroom.
Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input. If there are multiple answers, print any.
[ "..-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..\n", "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-..-..\n..-**-..\n", "**-**-*.\n*.-*.-**\n**-**-**\n**-**-**\n..-..-..\n..-**-..\n" ]
[ "..-**-..\n..-**-..\n..-..-..\n..-P.-..\n..-..-..\n..-..-..\n", "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-P.-..\n..-**-..\n", "**-**-*.\n*.-*P-**\n**-**-**\n**-**-**\n..-..-..\n..-**-..\n" ]
In the first example the maximum convenience is 3. In the second example the maximum convenience is 2. In the third example the maximum convenience is 4.
[ { "input": "..-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "output": "..-**-..\n..-**-..\n..-..-..\n..-P.-..\n..-..-..\n..-..-.." }, { "input": "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-..-..\n..-**-..", "output": "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-P.-..\n..-**-.." }, { "input": "**-**-*.\n*.-*.-**\n**-**-**\n**-**-**\n..-..-..\n..-**-..", "output": "**-**-*.\n*.-*P-**\n**-**-**\n**-**-**\n..-..-..\n..-**-.." }, { "input": "..-..-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "output": "..-..-..\n..-P.-..\n..-..-..\n..-..-..\n..-..-..\n..-..-.." }, { "input": "**-**-**\n**-**-**\n..-**-..\n..-**-..\n..-..-..\n..-..-..", "output": "**-**-**\n**-**-**\n..-**-..\n..-**-..\n..-..-..\n..-P.-.." }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n..-**-..\n..-**-..", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n..-**-..\nP.-**-.." }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n..-**-..\n*.-**-*.", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n..-**-..\n*P-**-*." }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n*.-**-..\n.*-**-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n*.-**-..\nP*-**-**" }, { "input": "**-**-**\n**-**-**\n.*-**-..\n..-**-..\n**-**-..\n.*-..-*.", "output": "**-**-**\n**-**-**\n.*-**-..\n..-**-..\n**-**-..\n.*-P.-*." }, { "input": "**-**-**\n**-**-**\n..-**-**\n*.-**-*.\n*.-..-.*\n*.-*.-.*", "output": "**-**-**\n**-**-**\n..-**-**\n*.-**-*.\n*.-..-.*\n*.-*P-.*" }, { "input": "*.-**-*.\n.*-**-..\n**-*.-.*\n**-*.-..\n..-.*-*.\n*.-..-..", "output": "*.-**-*.\n.*-**-..\n**-*.-.*\n**-*P-..\n..-.*-*.\n*.-..-.." }, { "input": "*.-**-.*\n**-**-.*\n*.-..-..\n..-.*-**\n*.-**-.*\n.*-..-..", "output": "*.-**-.*\n**-**-.*\n*.-..-..\n..-P*-**\n*.-**-.*\n.*-..-.." }, { "input": "..-..-*.\n*.-.*-**\n.*-..-..\n..-..-*.\n..-..-.*\n.*-**-..", "output": "..-..-*.\n*.-P*-**\n.*-..-..\n..-..-*.\n..-..-.*\n.*-**-.." }, { "input": "..-**-.*\n..-*.-*.\n**-*.-**\n..-..-*.\n.*-.*-..\n**-..-..", "output": "..-**-.*\n..-*P-*.\n**-*.-**\n..-..-*.\n.*-.*-..\n**-..-.." }, { "input": "..-.*-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "output": "..-P*-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-.." }, { "input": "..-**-..\n..-**-*.\n*.-..-..\n..-..-..\n..-**-..\n..-..-..", "output": "..-**-..\n..-**-*.\n*.-..-..\n..-P.-..\n..-**-..\n..-..-.." }, { "input": "**-.*-**\n**-**-**\n**-**-*.\n**-*.-**\n**-**-**\n**-*.-**", "output": "**-P*-**\n**-**-**\n**-**-*.\n**-*.-**\n**-**-**\n**-*.-**" }, { "input": "**-**-**\n**-**-**\n**-**-*.\n**-*.-**\n**-**-**\n**-*.-**", "output": "**-**-**\n**-**-**\n**-**-*.\n**-*P-**\n**-**-**\n**-*.-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*.\n**-*.-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*.\n**-*P-**" }, { "input": "..-**-..\n..-.*-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "output": "..-**-..\n..-P*-..\n..-..-..\n..-..-..\n..-..-..\n..-..-.." }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*.-..\n..-**-..", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*P-..\n..-**-.." }, { "input": "**-**-**\n*.-**-**\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "output": "**-**-**\n*.-**-**\n..-..-..\n..-P.-..\n..-..-..\n..-..-.." }, { "input": "**-**-**\n*.-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**", "output": "**-**-**\n*P-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-.*", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-P*" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-.*-**\n**-**-**\n**-**-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-P*-**\n**-**-**\n**-**-**" }, { "input": "**-**-**\n**-**-**\n**-**-.*\n**-**-**\n**-**-**\n..-**-..", "output": "**-**-**\n**-**-**\n**-**-P*\n**-**-**\n**-**-**\n..-**-.." }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*.\n**-**-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*P\n**-**-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*.-**\n**-**-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*P-**\n**-**-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*.-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*P-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-.*-**\n**-**-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-P*-**\n**-**-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*.", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*P" }, { "input": "**-**-**\n**-**-**\n**-*.-**\n**-**-**\n..-**-..\n..-..-..", "output": "**-**-**\n**-**-**\n**-*P-**\n**-**-**\n..-**-..\n..-..-.." } ]
93
7,065,600
3
21,291
835
Palindromic characteristics
[ "brute force", "dp", "hashing", "strings" ]
null
null
Palindromic characteristics of string *s* with length |*s*| is a sequence of |*s*| integers, where *k*-th number is the total number of non-empty substrings of *s* which are *k*-palindromes. A string is 1-palindrome if and only if it reads the same backward as forward. A string is *k*-palindrome (*k*<=&gt;<=1) if and only if: 1. Its left half equals to its right half. 1. Its left and right halfs are non-empty (*k*<=-<=1)-palindromes. The left half of string *t* is its prefix of length ⌊|*t*|<=/<=2⌋, and right half — the suffix of the same length. ⌊|*t*|<=/<=2⌋ denotes the length of string *t* divided by 2, rounded down. Note that each substring is counted as many times as it appears in the string. For example, in the string "aaa" the substring "a" appears 3 times.
The first line contains the string *s* (1<=≤<=|*s*|<=≤<=5000) consisting of lowercase English letters.
Print |*s*| integers — palindromic characteristics of string *s*.
[ "abba\n", "abacaba\n" ]
[ "6 1 0 0 \n", "12 4 1 0 0 0 0 \n" ]
In the first example 1-palindromes are substring «a», «b», «b», «a», «bb», «abba», the substring «bb» is 2-palindrome. There are no 3- and 4-palindromes here.
[ { "input": "abba", "output": "6 1 0 0 " }, { "input": "abacaba", "output": "12 4 1 0 0 0 0 " }, { "input": "qqqpvmgd", "output": "11 3 0 0 0 0 0 0 " }, { "input": "wyemcafatp", "output": "11 1 0 0 0 0 0 0 0 0 " } ]
15
0
0
21,299
670
Magic Powder - 2
[ "binary search", "implementation" ]
null
null
The term of this problem is the same as the previous one, the only exception — increased restrictions.
The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*<=≤<=109) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, needed to bake one cookie. The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=109), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, which Apollinaria has.
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
[ "1 1000000000\n1\n1000000000\n", "10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 1 1 1 1 1 1 1 1\n", "3 1\n2 1 4\n11 3 16\n", "4 3\n4 3 5 6\n11 12 14 20\n" ]
[ "2000000000\n", "0\n", "4\n", "3\n" ]
none
[ { "input": "1 1000000000\n1\n1000000000", "output": "2000000000" }, { "input": "10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3 1\n2 1 4\n11 3 16", "output": "4" }, { "input": "4 3\n4 3 5 6\n11 12 14 20", "output": "3" }, { "input": "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000", "output": "137" }, { "input": "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 898 965 807 786 670 626 873 968 745 878 359 760 781 829 882 777 740 907 779", "output": "150" }, { "input": "30 300\n1 4 2 1 2 5 6 4 1 3 2 1 1 1 1 1 2 3 1 3 4 2 2 3 2 2 2 1 1 1\n997 817 767 860 835 809 817 565 630 804 586 953 977 356 905 890 958 916 740 583 902 945 313 956 871 729 976 707 516 788", "output": "164" }, { "input": "40 538\n1 3 3 1 4 1 1 1 1 5 3 3 4 1 4 2 7 1 4 1 1 2 2 1 1 1 1 4 1 4 2 3 3 3 1 3 4 1 3 5\n975 635 795 835 982 965 639 787 688 796 988 779 839 942 491 696 396 995 718 810 796 879 957 783 844 765 968 783 647 214 995 868 318 453 989 889 504 962 945 925", "output": "104" }, { "input": "1 1\n1000000000\n1000000000", "output": "1" }, { "input": "50 530\n2 3 3 1 1 1 3 4 4 2 4 2 5 1 3 1 2 6 1 1 2 5 3 2 1 5 1 3 3 2 1 1 1 1 2 1 1 2 2 1 4 2 1 3 1 2 1 1 4 2\n959 972 201 990 675 679 972 268 976 886 488 924 795 959 647 994 969 862 898 646 763 797 978 763 995 641 923 856 829 921 934 883 904 986 728 980 1000 775 716 745 833 832 999 651 571 626 827 456 636 795", "output": "133" }, { "input": "60 735\n3 1 4 7 1 7 3 1 1 5 4 7 3 3 3 2 5 3 1 2 3 6 1 1 1 1 1 2 5 3 2 1 3 5 2 1 2 2 2 2 1 3 3 3 6 4 3 5 1 3 2 2 1 3 1 1 1 7 1 2\n596 968 975 493 665 571 598 834 948 941 737 649 923 848 950 907 929 865 227 836 956 796 861 801 746 667 539 807 405 355 501 879 994 890 573 848 597 873 130 985 924 426 999 550 586 924 601 807 994 878 410 817 922 898 982 525 611 685 806 847", "output": "103" }, { "input": "70 130\n2 1 2 2 3 3 2 5 2 2 3 3 3 1 1 4 3 5 3 2 1 3 7 1 2 7 5 2 1 6 3 4 1 2 1 1 1 1 3 6 4 2 2 8 2 2 4 1 4 2 1 4 4 3 5 1 1 1 1 1 2 3 1 5 1 3 3 4 2 2\n473 311 758 768 797 572 656 898 991 534 989 702 934 767 777 799 1000 655 806 727 718 948 834 965 832 778 706 861 799 874 745 970 772 967 984 886 835 795 832 837 950 952 475 891 947 952 903 929 689 478 725 945 585 943 771 631 729 887 557 738 824 758 999 786 669 992 918 762 964 941", "output": "119" }, { "input": "80 979\n2 1 1 1 2 1 1 1 3 1 4 4 2 1 1 3 1 1 2 1 4 1 1 2 5 4 8 1 3 6 5 7 2 3 4 1 2 2 6 1 2 2 4 1 1 2 3 2 8 1 1 3 3 4 1 1 2 1 4 4 1 4 3 2 6 5 2 1 4 1 2 3 2 1 3 3 1 2 1 3\n498 976 513 869 917 914 664 656 957 893 981 947 985 693 576 958 987 822 981 718 884 729 295 683 485 998 730 894 731 975 739 854 906 740 987 976 606 689 990 775 522 994 920 893 529 651 989 799 643 215 946 987 297 868 425 810 694 908 736 903 970 751 625 904 955 945 839 777 977 974 905 900 666 680 799 873 565 919 536 686", "output": "128" }, { "input": "1 1000\n1000\n1000", "output": "2" }, { "input": "1 1000\n1\n1000", "output": "2000" }, { "input": "1 1\n4\n6", "output": "1" }, { "input": "1 1\n1\n1", "output": "2" }, { "input": "1 1\n1000000000\n1", "output": "0" }, { "input": "1 1000000000\n1000000000\n1000000000", "output": "2" }, { "input": "1 1000000000\n100000000\n1000000000", "output": "20" }, { "input": "1 1000000000\n654321\n1000000000", "output": "3056" }, { "input": "1 786543211\n12345678\n987654321", "output": "143" }, { "input": "20 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1" }, { "input": "13 961166382\n312 781 329 6 813 68 872 146 33 382 134 744 353\n904116983 692808881 382512127 462746212 130261069 450407093 112139570 386577765 867425952 354457553 248439687 817592835 682387533", "output": "714283" }, { "input": "1 1000000000\n1\n2", "output": "1000000002" }, { "input": "6 1000000000\n1 1 1 1 1 1\n1000000000 1 1000000000 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "2 1000000000\n1 1\n1 1", "output": "500000001" }, { "input": "1 1\n10\n2", "output": "0" }, { "input": "2 1\n2 2\n1 1", "output": "0" }, { "input": "2 1000000000\n1 1\n1000000000 1000000000", "output": "1500000000" }, { "input": "2 6\n1 3\n6 2", "output": "2" } ]
171
17,612,800
3
21,309
815
Karen and Test
[ "brute force", "combinatorics", "constructive algorithms", "math" ]
null
null
Karen has just arrived at school, and she has a math test today! The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. There are *n* integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition. Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa. The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test. Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row? Since this number can be quite large, output only the non-negative remainder after dividing it by 109<=+<=7.
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=200000), the number of numbers written on the first row. The next line contains *n* integers. Specifically, the *i*-th one among these is *a**i* (1<=≤<=*a**i*<=≤<=109), the *i*-th number on the first row.
Output a single integer on a line by itself, the number on the final row after performing the process above. Since this number can be quite large, print only the non-negative remainder after dividing it by 109<=+<=7.
[ "5\n3 6 9 12 15\n", "4\n3 7 5 2\n" ]
[ "36\n", "1000000006\n" ]
In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15. Karen performs the operations as follows: The non-negative remainder after dividing the final number by 10<sup class="upper-index">9</sup> + 7 is still 36, so this is the correct output. In the second test case, the numbers written on the first row are 3, 7, 5 and 2. Karen performs the operations as follows: The non-negative remainder after dividing the final number by 10<sup class="upper-index">9</sup> + 7 is 10<sup class="upper-index">9</sup> + 6, so this is the correct output.
[ { "input": "5\n3 6 9 12 15", "output": "36" }, { "input": "4\n3 7 5 2", "output": "1000000006" }, { "input": "1\n1", "output": "1" }, { "input": "16\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004147 176573082", "output": "347261016" }, { "input": "18\n341796022 486073481 86513380 593942288 60606166 627385348 778725113 896678215 384223198 661124212 882144246 60135494 374392733 408166459 179944793 331468916 401182818 69503967", "output": "773499683" }, { "input": "17\n458679894 912524637 347508634 863280107 226481104 787939275 48953130 553494227 458256339 673787326 353107999 298575751 436592642 233596921 957974470 254020999 707869688", "output": "769845668" }, { "input": "19\n519879446 764655030 680293934 914539062 744988123 317088317 653721289 239862203 605157354 943428394 261437390 821695238 312192823 432992892 547139308 408916833 829654733 223751525 672158759", "output": "265109293" }, { "input": "1\n1000000000", "output": "1000000000" }, { "input": "3\n524125987 923264237 374288891", "output": "996365563" }, { "input": "4\n702209411 496813081 673102149 561219907", "output": "317278572" }, { "input": "5\n585325539 365329221 412106895 291882089 564718673", "output": "974257995" }, { "input": "6\n58376259 643910770 5887448 757703054 544067926 902981667", "output": "676517605" }, { "input": "7\n941492387 72235422 449924898 783332532 378192988 592684636 147499872", "output": "328894634" }, { "input": "2\n500000004 500000003", "output": "0" } ]
249
12,902,400
-1
21,322
958
Death Stars (medium)
[ "hashing", "strings" ]
null
null
The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the solar system that contains the Death Star. However, this time the Empire has hidden the Death Star very well, and Heidi needs to find a place that appears on both maps in order to detect the Death Star. The first map is an *N*<=×<=*M* grid, each cell of which shows some type of cosmic object that is present in the corresponding quadrant of space. The second map is an *M*<=×<=*N* grid. Heidi needs to align those two maps in such a way that they overlap over some *M*<=×<=*M* section in which all cosmic objects are identical. Help Heidi by identifying where such an *M*<=×<=*M* section lies within both maps.
The first line of the input contains two space-separated integers *N* and *M* (1<=≤<=*N*<=≤<=2000, 1<=≤<=*M*<=≤<=200, *M*<=≤<=*N*). The next *N* lines each contain *M* lower-case Latin characters (a-z), denoting the first map. Different characters correspond to different cosmic object types. The next *M* lines each contain *N* characters, describing the second map in the same format.
The only line of the output should contain two space-separated integers *i* and *j*, denoting that the section of size *M*<=×<=*M* in the first map that starts at the *i*-th row is equal to the section of the second map that starts at the *j*-th column. Rows and columns are numbered starting from 1. If there are several possible ways to align the maps, Heidi will be satisfied with any of those. It is guaranteed that a solution exists.
[ "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo\n" ]
[ "4 6\n" ]
The 5-by-5 grid for the first test case looks like this:
[ { "input": "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo", "output": "4 6" }, { "input": "1 1\ng\ng", "output": "1 1" } ]
93
8,294,400
-1
21,359
97
Leaders
[ "dfs and similar", "dsu", "graphs", "trees" ]
E. Leaders
2
256
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly order the citizens. However, leadership efficiency turned out to vary from person to person (i.e. while person A makes an efficient leader, person B may not be that good at it). That's why the dictator asked world-famous berland scientists for help. The scientists suggested an innovatory technology — to make the leaders work in pairs. A relationship graph is some undirected graph whose vertices correspond to people. A simple path is a path with no repeated vertices. Long and frighteningly expensive research showed that a pair of people has maximum leadership qualities if a graph of relationships has a simple path between them with an odd number of edges. The scientists decided to call such pairs of different people leader pairs. Secret services provided the scientists with the relationship graph so that the task is simple — we have to learn to tell the dictator whether the given pairs are leader pairs or not. Help the scientists cope with the task.
The first line contains integers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of vertices and edges in the relationship graph correspondingly. Next *m* lines contain pairs of integers *a* and *b* which mean that there is an edge between the *a*-th and the *b*-th vertices (the vertices are numbered starting from 1, 1<=≤<=*a*,<=*b*<=≤<=*n*). It is guaranteed that the graph has no loops or multiple edges. Next line contains number *q* (1<=≤<=*q*<=≤<=105) — the number of pairs the scientists are interested in. Next *q* lines contain these pairs (in the same format as the edges, the queries can be repeated, a query can contain a pair of the identical vertices).
For each query print on a single line "Yes" if there's a simple odd path between the pair of people; otherwise, print "No".
[ "7 7\n1 3\n1 4\n2 3\n2 4\n5 6\n6 7\n7 5\n8\n1 2\n1 3\n1 4\n2 4\n1 5\n5 6\n5 7\n6 7\n" ]
[ "No\nYes\nYes\nYes\nNo\nYes\nYes\nYes\n" ]
Notes to the samples: 1) Between vertices 1 and 2 there are 2 different simple paths in total: 1-3-2 and 1-4-2. Both of them consist of an even number of edges. 2) Vertices 1 and 3 are connected by an edge, that's why a simple odd path for them is 1-3. 5) Vertices 1 and 5 are located in different connected components, there's no path between them.
[]
218
0
-1
21,399
0
none
[ "none" ]
null
null
Vasya has *n* items lying in a line. The items are consecutively numbered by numbers from 1 to *n* in such a way that the leftmost item has number 1, the rightmost item has number *n*. Each item has a weight, the *i*-th item weights *w**i* kilograms. Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions: 1. Take the leftmost item with the left hand and spend *w**i*<=·<=*l* energy units (*w**i* is a weight of the leftmost item, *l* is some parameter). If the previous action was the same (left-hand), then the robot spends extra *Q**l* energy units; 1. Take the rightmost item with the right hand and spend *w**j*<=·<=*r* energy units (*w**j* is a weight of the rightmost item, *r* is some parameter). If the previous action was the same (right-hand), then the robot spends extra *Q**r* energy units; Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
The first line contains five integers *n*,<=*l*,<=*r*,<=*Q**l*,<=*Q**r* (1<=≤<=*n*<=≤<=105;<=1<=≤<=*l*,<=*r*<=≤<=100;<=1<=≤<=*Q**l*,<=*Q**r*<=≤<=104). The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=100).
In the single line print a single number — the answer to the problem.
[ "3 4 4 19 1\n42 3 99\n", "4 7 2 3 9\n1 2 3 4\n" ]
[ "576\n", "34\n" ]
Consider the first sample. As *l* = *r*, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units. The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
[ { "input": "3 4 4 19 1\n42 3 99", "output": "576" }, { "input": "4 7 2 3 9\n1 2 3 4", "output": "34" }, { "input": "2 100 100 10000 10000\n100 100", "output": "20000" }, { "input": "2 3 4 5 6\n1 2", "output": "11" }, { "input": "1 78 94 369 10000\n93", "output": "7254" }, { "input": "1 94 78 369 10000\n93", "output": "7254" }, { "input": "5 1 100 1 10000\n1 2 3 4 5", "output": "19" }, { "input": "5 100 1 10000 1\n1 2 3 4 5", "output": "19" }, { "input": "5 1 100 10000 1\n1 2 3 4 5", "output": "906" }, { "input": "5 100 1 1 10000\n1 2 3 4 5", "output": "312" }, { "input": "6 32 47 965 897\n7 4 1 3 5 4", "output": "948" }, { "input": "7 3 13 30 978\n1 2 3 4 5 1 7", "output": "199" }, { "input": "7 13 3 978 30\n7 1 5 4 3 2 1", "output": "199" } ]
0
0
-1
21,419
756
Long number
[ "expression parsing", "math", "number theory" ]
null
null
Consider the following grammar: - &lt;expression&gt; ::= &lt;term&gt; | &lt;expression&gt; '+' &lt;term&gt;- &lt;term&gt; ::= &lt;number&gt; | &lt;number&gt; '-' &lt;number&gt; | &lt;number&gt; '(' &lt;expression&gt; ')'- &lt;number&gt; ::= &lt;pos_digit&gt; | &lt;number&gt; &lt;digit&gt;- &lt;digit&gt; ::= '0' | &lt;pos_digit&gt;- &lt;pos_digit&gt; ::= '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' This grammar describes a number in decimal system using the following rules: - &lt;number&gt; describes itself,- &lt;number&gt;-&lt;number&gt; (l-r, *l*<=≤<=*r*) describes integer which is concatenation of all integers from *l* to *r*, written without leading zeros. For example, 8-11 describes 891011,- &lt;number&gt;(&lt;expression&gt;) describes integer which is concatenation of &lt;number&gt; copies of integer described by &lt;expression&gt;,- &lt;expression&gt;+&lt;term&gt; describes integer which is concatenation of integers described by &lt;expression&gt; and &lt;term&gt;. For example, 2(2-4+1)+2(2(17)) describes the integer 2341234117171717. You are given an expression in the given grammar. Print the integer described by it modulo 109<=+<=7.
The only line contains a non-empty string at most 105 characters long which is valid according to the given grammar. In particular, it means that in terms l-r *l*<=≤<=*r* holds.
Print single integer — the number described by the expression modulo 109<=+<=7.
[ "8-11\n", "2(2-4+1)+2(2(17))\n", "1234-5678\n", "1+2+3+4-5+6+7-9\n" ]
[ "891011\n", "100783079\n", "745428774\n", "123456789\n" ]
none
[ { "input": "8-11", "output": "891011" }, { "input": "2(2-4+1)+2(2(17))", "output": "100783079" }, { "input": "1234-5678", "output": "745428774" }, { "input": "1+2+3+4-5+6+7-9", "output": "123456789" }, { "input": "598777", "output": "598777" }, { "input": "49603501749575096738857", "output": "586922407" }, { "input": "11-57", "output": "486296559" }, { "input": "7177-57797", "output": "110843609" }, { "input": "4510812433666-7741104736713", "output": "665706430" }, { "input": "4778066503(27032-80044+16+51+58(9)+5668114736297420472+2336+6-117+8495(7265))", "output": "865860620" }, { "input": "9678329648012859556810940272201-70370609657815505164700664074744+28870231062776633852(2098997519485)", "output": "219564419" }, { "input": "52(6(1)+100000000(2-10))+777(40000000(7-20)+876543)", "output": "133241273" }, { "input": "1(1000000005(5)+4)", "output": "1000000006" }, { "input": "1-1", "output": "1" }, { "input": "10-10", "output": "10" }, { "input": "1+2", "output": "12" }, { "input": "9", "output": "9" }, { "input": "1(1)+1(1)", "output": "11" } ]
30
0
-1
21,429
370
Berland Bingo
[ "implementation" ]
null
null
Lately, a national version of a bingo game has become very popular in Berland. There are *n* players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the *i*-th player contains *m**i* numbers. During the game the host takes numbered balls one by one from a bag. He reads the number aloud in a high and clear voice and then puts the ball away. All participants cross out the number if it occurs on their cards. The person who crosses out all numbers from his card first, wins. If multiple people cross out all numbers from their cards at the same time, there are no winners in the game. At the beginning of the game the bag contains 100 balls numbered 1 through 100, the numbers of all balls are distinct. You are given the cards for each player. Write a program that determines whether a player can win the game at the most favorable for him scenario or not.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of the players. Then follow *n* lines, each line describes a player's card. The line that describes a card starts from integer *m**i* (1<=≤<=*m**i*<=≤<=100) that shows how many numbers the *i*-th player's card has. Then follows a sequence of integers *a**i*,<=1,<=*a**i*,<=2,<=...,<=*a**i*,<=*m**i* (1<=≤<=*a**i*,<=*k*<=≤<=100) — the numbers on the *i*-th player's card. The numbers in the lines are separated by single spaces. It is guaranteed that all the numbers on each card are distinct.
Print *n* lines, the *i*-th line must contain word "YES" (without the quotes), if the *i*-th player can win, and "NO" (without the quotes) otherwise.
[ "3\n1 1\n3 2 4 1\n2 10 11\n", "2\n1 1\n1 1\n" ]
[ "YES\nNO\nYES\n", "NO\nNO\n" ]
none
[ { "input": "3\n1 1\n3 2 4 1\n2 10 11", "output": "YES\nNO\nYES" }, { "input": "2\n1 1\n1 1", "output": "NO\nNO" }, { "input": "1\n1 1", "output": "YES" }, { "input": "2\n1 2\n1 3", "output": "YES\nYES" }, { "input": "2\n1 1\n2 1 2", "output": "YES\nNO" }, { "input": "2\n2 1 2\n1 1", "output": "NO\nYES" }, { "input": "2\n3 5 21 7\n6 15 5 100 21 7 17", "output": "YES\nNO" }, { "input": "2\n6 15 5 100 21 7 17\n3 5 21 7", "output": "NO\nYES" }, { "input": "10\n1 4\n1 2\n1 3\n1 5\n1 1\n1 4\n1 3\n1 5\n1 2\n1 1", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO" }, { "input": "3\n1 1\n1 2\n1 1", "output": "NO\nYES\nNO" }, { "input": "10\n3 2 3 4\n1 1\n1 1\n1 2\n1 3\n1 4\n1 1\n1 3\n2 4 5\n2 1 2", "output": "NO\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO" }, { "input": "10\n1 4\n4 3 2 4 1\n1 4\n2 4 5\n4 4 3 5 1\n1 4\n1 2\n2 3 5\n2 5 3\n3 5 2 4", "output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "20\n2 9 16\n3 1 15 2\n1 9\n3 7 12 3\n1 18\n1 14\n4 11 13 4 6\n4 7 19 9 3\n3 9 16 5\n1 9\n1 18\n4 4 15 7 19\n2 16 2\n3 7 3 15\n2 2 20\n1 1\n1 15\n5 5 2 13 4 1\n2 9 14\n2 17 8", "output": "NO\nNO\nNO\nYES\nNO\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nYES" }, { "input": "40\n2 12 19\n4 10 7 1 3\n2 15 17\n1 6\n3 17 8 20\n4 8 16 11 18\n2 2 7\n4 12 13 8 7\n3 6 1 15\n3 19 11 13\n1 2\n2 16 14\n5 1 17 8 9 5\n1 2\n3 15 17 12\n4 20 4 19 18\n1 10\n4 12 1 17 16\n4 5 10 8 11\n1 10\n1 13\n1 17\n2 19 18\n1 3\n2 6 20\n1 8\n2 3 14\n3 17 3 1\n2 4 3\n1 12\n1 15\n1 2\n2 13 9\n2 1 14\n1 1\n5 14 9 3 1 7\n2 20 16\n2 19 17\n2 4 20\n1 7", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nYES" } ]
93
0
0
21,528
0
none
[ "none" ]
null
null
You are given a sequence of positive integers *x*1,<=*x*2,<=...,<=*x**n* and two non-negative integers *a* and *b*. Your task is to transform *a* into *b*. To do that, you can perform the following moves: - subtract 1 from the current *a*; - subtract *a* mod *x**i* (1<=≤<=*i*<=≤<=*n*) from the current *a*. Operation *a* mod *x**i* means taking the remainder after division of number *a* by number *x**i*. Now you want to know the minimum number of moves needed to transform *a* into *b*.
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=105). The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (2<=≤<=<=*x**i*<=≤<=109). The third line contains two integers *a* and *b* (0<=<=≤<=*b*<=≤<=<=*a*<=≤<=109, *a*<=-<=*b*<=≤<=106).
Print a single integer — the required minimum number of moves needed to transform number *a* into number *b*.
[ "3\n3 4 5\n30 17\n", "3\n5 6 7\n1000 200\n" ]
[ "6\n", "206\n" ]
none
[]
92
0
0
21,580
792
Mages and Monsters
[ "data structures", "geometry" ]
null
null
Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells. Vova's character can learn new spells during the game. Every spell is characterized by two values *x**i* and *y**i* — damage per second and mana cost per second, respectively. Vova doesn't have to use a spell for an integer amount of seconds. More formally, if he uses a spell with damage *x* and mana cost *y* for *z* seconds, then he will deal *x*·*z* damage and spend *y*·*z* mana (no rounding). If there is no mana left (mana amount is set in the start of the game and it remains the same at the beginning of every fight), then character won't be able to use any spells. It is prohibited to use multiple spells simultaneously. Also Vova can fight monsters. Every monster is characterized by two values *t**j* and *h**j* — monster kills Vova's character in *t**j* seconds and has *h**j* health points. Mana refills after every fight (or Vova's character revives with full mana reserve), so previous fights have no influence on further ones. Vova's character kills a monster, if he deals *h**j* damage to it in no more than *t**j* seconds using his spells (it is allowed to use more than one spell in a fight) and spending no more mana than he had at the beginning of the fight. If monster's health becomes zero exactly in *t**j* seconds (it means that the monster and Vova's character kill each other at the same time), then Vova wins the fight. You have to write a program which can answer two types of queries: - 1 *x* *y* — Vova's character learns new spell which deals *x* damage per second and costs *y* mana per second. - 2 *t* *h* — Vova fights the monster which kills his character in *t* seconds and has *h* health points. Note that queries are given in a different form. Also remember that Vova's character knows no spells at the beginning of the game. For every query of second type you have to determine if Vova is able to win the fight with corresponding monster.
The first line contains two integer numbers *q* and *m* (2<=≤<=*q*<=≤<=105,<=1<=≤<=*m*<=≤<=1012) — the number of queries and the amount of mana at the beginning of every fight. *i*-th of each next *q* lines contains three numbers *k**i*, *a**i* and *b**i* (1<=≤<=*k**i*<=≤<=2,<=1<=≤<=*a**i*,<=*b**i*<=≤<=106). Using them you can restore queries this way: let *j* be the index of the last query of second type with positive answer (*j*<==<=0 if there were none of these). - If *k**i*<==<=1, then character learns spell with *x*<==<=(*a**i*<=+<=*j*) *mod* 106<=+<=1, *y*<==<=(*b**i*<=+<=*j*) *mod* 106<=+<=1. - If *k**i*<==<=2, then you have to determine if Vova is able to win the fight against monster with *t*<==<=(*a**i*<=+<=*j*) *mod* 106<=+<=1, *h*<==<=(*b**i*<=+<=*j*) *mod* 106<=+<=1.
For every query of second type print YES if Vova is able to win the fight with corresponding monster and NO otherwise.
[ "3 100\n1 4 9\n2 19 49\n2 19 49\n" ]
[ "YES\nNO\n" ]
In first example Vova's character at first learns the spell with 5 damage and 10 mana cost per second. Next query is a fight with monster which can kill character in 20 seconds and has 50 health points. Vova kills it in 10 seconds (spending 100 mana). Next monster has 52 health, so Vova can't deal that much damage with only 100 mana.
[ { "input": "3 100\n1 4 9\n2 19 49\n2 19 49", "output": "YES\nNO" }, { "input": "10 442006988299\n2 10 47\n1 9 83\n1 15 24\n2 19 47\n2 75 99\n2 85 23\n2 8 33\n2 9 82\n1 86 49\n2 71 49", "output": "NO\nYES\nYES\nYES\nYES\nYES\nYES" }, { "input": "2 424978864039\n2 7 3\n2 10 8", "output": "NO\nNO" }, { "input": "3 10\n1 1 1\n2 1 1\n2 999999 999999", "output": "YES\nYES" }, { "input": "12 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 990 290\n2 999991 11\n2 999991 10", "output": "NO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nYES" }, { "input": "15 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 990 290\n1 2 999992\n2 6 256\n2 7 256\n1 2 999988\n2 2 252", "output": "NO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nYES" }, { "input": "3 12\n1 99 9\n1 49 1\n2 1 149", "output": "YES" } ]
873
15,564,800
3
21,586
0
none
[ "none" ]
null
null
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with *n* vertices and *m* edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not. To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle. It is guaranteed that the graph contains no multiple edges and self-loops.
The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=). Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.
Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.
[ "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n", "6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n" ]
[ "FHTAGN!", "NO" ]
Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1. A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* &gt; 0). A rooted tree is a tree where one vertex is selected to be the root.
[ { "input": "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4", "output": "FHTAGN!" }, { "input": "6 5\n5 6\n4 6\n3 1\n5 1\n1 2", "output": "NO" }, { "input": "10 10\n4 10\n8 5\n2 8\n4 9\n9 3\n2 7\n10 6\n10 2\n9 8\n1 8", "output": "FHTAGN!" }, { "input": "5 4\n1 5\n1 3\n1 4\n3 2", "output": "NO" }, { "input": "12 12\n4 12\n4 7\n4 9\n7 2\n5 12\n2 1\n5 9\n8 6\n10 12\n2 5\n10 9\n12 3", "output": "NO" }, { "input": "12 15\n3 2\n11 12\n1 9\n2 1\n1 8\n9 6\n11 5\n9 5\n9 10\n11 3\n7 11\n5 6\n11 10\n4 6\n4 2", "output": "NO" }, { "input": "12 10\n1 11\n3 6\n5 7\n4 7\n6 8\n11 7\n3 12\n11 12\n7 9\n12 2", "output": "NO" }, { "input": "1 0", "output": "NO" }, { "input": "2 1\n1 2", "output": "NO" }, { "input": "3 1\n1 3", "output": "NO" }, { "input": "3 2\n1 2\n2 3", "output": "NO" }, { "input": "3 3\n1 2\n2 3\n3 1", "output": "FHTAGN!" }, { "input": "4 4\n1 2\n3 4\n4 1\n2 4", "output": "FHTAGN!" }, { "input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "NO" }, { "input": "2 0", "output": "NO" }, { "input": "3 0", "output": "NO" }, { "input": "100 0", "output": "NO" }, { "input": "100 1\n11 23", "output": "NO" }, { "input": "10 10\n5 7\n8 1\n10 3\n6 4\n10 6\n5 3\n5 6\n2 6\n4 3\n2 10", "output": "NO" }, { "input": "20 20\n9 10\n4 19\n9 20\n12 20\n1 15\n2 12\n19 10\n19 15\n4 10\n4 8\n8 9\n20 8\n6 2\n2 15\n7 19\n20 4\n3 16\n1 20\n9 1\n20 10", "output": "NO" }, { "input": "30 30\n17 6\n16 29\n16 13\n16 20\n29 26\n17 5\n27 28\n24 16\n7 18\n24 10\n1 27\n12 17\n27 30\n6 1\n3 30\n5 19\n18 13\n16 2\n30 1\n5 8\n14 16\n26 18\n7 19\n5 6\n23 14\n6 8\n23 8\n18 8\n18 3\n5 21", "output": "NO" }, { "input": "100 66\n41 14\n19 13\n70 43\n79 62\n9 62\n71 40\n53 86\n80 4\n34 33\n72 68\n40 96\n84 59\n36 77\n55 50\n40 3\n79 81\n3 43\n33 47\n22 98\n33 90\n56 49\n69 28\n73 30\n65 22\n98 20\n9 52\n54 20\n32 70\n51 80\n63 12\n21 48\n35 17\n48 87\n25 43\n65 80\n42 3\n86 35\n95 98\n43 59\n51 46\n66 37\n88 34\n32 47\n24 42\n21 44\n92 59\n81 6\n100 82\n85 6\n58 25\n66 6\n14 32\n59 85\n3 98\n44 4\n85 51\n69 41\n80 70\n81 24\n75 71\n93 9\n82 55\n70 46\n66 32\n77 58\n11 46", "output": "NO" }, { "input": "4 4\n1 2\n4 3\n2 3\n3 1", "output": "FHTAGN!" }, { "input": "5 5\n2 3\n2 4\n5 4\n4 1\n1 2", "output": "FHTAGN!" }, { "input": "10 10\n1 10\n5 9\n6 2\n8 9\n9 1\n5 4\n2 8\n1 3\n6 3\n4 1", "output": "NO" }, { "input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "NO" }, { "input": "4 3\n1 2\n2 3\n3 1", "output": "NO" }, { "input": "6 5\n1 2\n2 3\n3 1\n1 4\n1 5", "output": "NO" } ]
248
2,048,000
3
21,614
387
George and Number
[ "greedy", "implementation" ]
null
null
George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers *b*. During the game, George modifies the array by using special changes. Let's mark George's current array as *b*1,<=*b*2,<=...,<=*b*|*b*| (record |*b*| denotes the current length of the array). Then one change is a sequence of actions: - Choose two distinct indexes *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=|*b*|; *i*<=≠<=*j*), such that *b**i*<=≥<=*b**j*. - Get number *v*<==<=*concat*(*b**i*,<=*b**j*), where *concat*(*x*,<=*y*) is a number obtained by adding number *y* to the end of the decimal record of number *x*. For example, *concat*(500,<=10)<==<=50010, *concat*(2,<=2)<==<=22. - Add number *v* to the end of the array. The length of the array will increase by one. - Remove from the array numbers with indexes *i* and *j*. The length of the array will decrease by two, and elements of the array will become re-numbered from 1 to current length of the array. George played for a long time with his array *b* and received from array *b* an array consisting of exactly one number *p*. Now George wants to know: what is the maximum number of elements array *b* could contain originally? Help him find this number. Note that originally the array could contain only positive integers.
The first line of the input contains a single integer *p* (1<=≤<=*p*<=&lt;<=10100000). It is guaranteed that number *p* doesn't contain any leading zeroes.
Print an integer — the maximum number of elements array *b* could contain originally.
[ "9555\n", "10000000005\n", "800101\n", "45\n", "1000000000000001223300003342220044555\n", "19992000\n", "310200\n" ]
[ "4", "2", "3", "1", "17", "1", "2" ]
Let's consider the test examples: - Originally array *b* can be equal to {5, 9, 5, 5}. The sequence of George's changes could have been: {5, 9, 5, 5} → {5, 5, 95} → {95, 55} → {9555}. - Originally array *b* could be equal to {1000000000, 5}. Please note that the array *b* cannot contain zeros. - Originally array *b* could be equal to {800, 10, 1}. - Originally array *b* could be equal to {45}. It cannot be equal to {4, 5}, because George can get only array {54} from this array in one operation. Note that the numbers can be very large.
[ { "input": "9555", "output": "4" }, { "input": "10000000005", "output": "2" }, { "input": "800101", "output": "3" }, { "input": "45", "output": "1" }, { "input": "1000000000000001223300003342220044555", "output": "17" }, { "input": "19992000", "output": "1" }, { "input": "310200", "output": "2" }, { "input": "63100605000394089000505000600600062000170273350000", "output": "21" }, { "input": "20900000000090009000070069000026000000000000020008", "output": "10" }, { "input": "60000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "7", "output": "1" }, { "input": "6944262915652659458125599978116114458736683259866511789545994938161622536342972115877623999684282136", "output": "99" }, { "input": "45000", "output": "1" }, { "input": "10", "output": "1" }, { "input": "1", "output": "1" }, { "input": "456", "output": "2" }, { "input": "542", "output": "3" }, { "input": "54000", "output": "1" }, { "input": "999", "output": "3" }, { "input": "11", "output": "2" }, { "input": "11001000", "output": "2" }, { "input": "10001000", "output": "2" }, { "input": "112000", "output": "1" }, { "input": "1111200", "output": "5" }, { "input": "10000000000000000000000000000000000000400500000000000000000000000000000000030020010300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "2" }, { "input": "110003000054", "output": "3" } ]
124
0
0
21,642
80
Depression
[ "geometry", "math" ]
B. Depression
1
256
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels! There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle... Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock. Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll. Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00. You can only rotate the hands forward, that is, as is shown in the picture: As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction. Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
The only line of input contains current time according to the digital clock, formatted as HH:MM (00<=≤<=HH<=≤<=23, 00<=≤<=MM<=≤<=59). The mantel clock initially shows 12:00. Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Print two numbers *x* and *y* — the angles of turning the hour and minute hands, respectively (0<=≤<=*x*,<=*y*<=&lt;<=360). The absolute or relative error in the answer should not exceed 10<=-<=9.
[ "12:00\n", "04:30\n", "08:17\n" ]
[ "0 0", "135 180", "248.5 102" ]
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
[ { "input": "12:00", "output": "0 0" }, { "input": "04:30", "output": "135 180" }, { "input": "08:17", "output": "248.5 102" }, { "input": "07:20", "output": "220 120" }, { "input": "09:55", "output": "297.5 330" }, { "input": "11:59", "output": "359.5 354" }, { "input": "01:23", "output": "41.5 138" }, { "input": "11:00", "output": "330 0" }, { "input": "00:00", "output": "0 0" }, { "input": "12:30", "output": "15 180" }, { "input": "23:59", "output": "359.5 354" }, { "input": "20:00", "output": "240 0" }, { "input": "23:45", "output": "352.5 270" }, { "input": "07:14", "output": "217 84" }, { "input": "15:15", "output": "97.5 90" }, { "input": "16:05", "output": "122.5 30" }, { "input": "19:55", "output": "237.5 330" }, { "input": "23:58", "output": "359 348" }, { "input": "14:33", "output": "76.5 198" }, { "input": "18:00", "output": "180 0" }, { "input": "00:24", "output": "12 144" }, { "input": "19:45", "output": "232.5 270" }, { "input": "20:05", "output": "242.5 30" }, { "input": "21:13", "output": "276.5 78" }, { "input": "08:04", "output": "242 24" }, { "input": "07:40", "output": "230 240" }, { "input": "19:12", "output": "216 72" }, { "input": "06:36", "output": "198 216" }, { "input": "06:16", "output": "188 96" }, { "input": "11:49", "output": "354.5 294" }, { "input": "18:45", "output": "202.5 270" }, { "input": "06:44", "output": "202 264" }, { "input": "20:45", "output": "262.5 270" }, { "input": "17:48", "output": "174 288" }, { "input": "08:09", "output": "244.5 54" }, { "input": "04:12", "output": "126 72" }, { "input": "21:30", "output": "285 180" }, { "input": "12:56", "output": "28 336" }, { "input": "00:43", "output": "21.5 258" }, { "input": "02:54", "output": "87 324" }, { "input": "02:29", "output": "74.5 174" }, { "input": "17:24", "output": "162 144" }, { "input": "14:27", "output": "73.5 162" }, { "input": "16:37", "output": "138.5 222" }, { "input": "14:40", "output": "80 240" }, { "input": "01:00", "output": "30 0" }, { "input": "21:40", "output": "290 240" }, { "input": "08:47", "output": "263.5 282" }, { "input": "11:30", "output": "345 180" }, { "input": "08:31", "output": "255.5 186" }, { "input": "04:11", "output": "125.5 66" }, { "input": "19:27", "output": "223.5 162" }, { "input": "10:54", "output": "327 324" }, { "input": "01:20", "output": "40 120" }, { "input": "12:33", "output": "16.5 198" }, { "input": "11:32", "output": "346 192" }, { "input": "15:36", "output": "108 216" }, { "input": "23:45", "output": "352.5 270" }, { "input": "20:12", "output": "246 72" }, { "input": "15:28", "output": "104 168" }, { "input": "00:01", "output": "0.5 6" }, { "input": "12:01", "output": "0.5 6" }, { "input": "23:01", "output": "330.5 6" }, { "input": "00:59", "output": "29.5 354" }, { "input": "12:59", "output": "29.5 354" }, { "input": "23:00", "output": "330 0" } ]
46
0
3.977
21,656
258
Little Elephant and LCM
[ "binary search", "combinatorics", "dp", "math" ]
null
null
The Little Elephant loves the LCM (least common multiple) operation of a non-empty set of positive integers. The result of the LCM operation of *k* positive integers *x*1,<=*x*2,<=...,<=*x**k* is the minimum positive integer that is divisible by each of numbers *x**i*. Let's assume that there is a sequence of integers *b*1,<=*b*2,<=...,<=*b**n*. Let's denote their LCMs as *lcm*(*b*1,<=*b*2,<=...,<=*b**n*) and the maximum of them as *max*(*b*1,<=*b*2,<=...,<=*b**n*). The Little Elephant considers a sequence *b* good, if *lcm*(*b*1,<=*b*2,<=...,<=*b**n*)<==<=*max*(*b*1,<=*b*2,<=...,<=*b**n*). The Little Elephant has a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Help him find the number of good sequences of integers *b*1,<=*b*2,<=...,<=*b**n*, such that for all *i* (1<=≤<=*i*<=≤<=*n*) the following condition fulfills: 1<=≤<=*b**i*<=≤<=*a**i*. As the answer can be rather large, print the remainder from dividing it by 1000000007 (109<=+<=7).
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers in the sequence *a*. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — sequence *a*.
In the single line print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
[ "4\n1 4 3 2\n", "2\n6 3\n" ]
[ "15\n", "13\n" ]
none
[ { "input": "4\n1 4 3 2", "output": "15" }, { "input": "2\n6 3", "output": "13" }, { "input": "7\n1 2 1 2 3 4 1", "output": "27" }, { "input": "4\n6 7 2 3", "output": "89" }, { "input": "7\n2 1 1 1 2 2 2", "output": "16" }, { "input": "7\n7 1 9 9 10 4 4", "output": "3656" }, { "input": "10\n6 9 9 9 7 9 8 6 6 10", "output": "1349911" }, { "input": "10\n2 4 5 4 4 2 3 4 5 1", "output": "5962" }, { "input": "100\n56 61 73 53 56 55 72 52 73 65 50 48 56 54 54 73 73 53 54 49 62 52 49 74 64 65 62 68 71 55 53 49 55 47 51 54 71 49 59 61 63 62 53 47 47 65 67 68 59 72 72 56 54 57 71 65 73 67 50 72 67 60 65 55 60 58 69 73 56 52 63 63 67 63 53 47 52 67 65 65 47 62 51 67 57 65 69 55 72 60 50 49 49 60 49 50 56 68 53 70", "output": "487937148" }, { "input": "74\n2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 2 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 1 2 1", "output": "877905026" }, { "input": "47\n22 26 5 69 82 58 43 33 55 6 60 88 97 45 77 12 12 69 86 63 87 77 21 71 13 93 93 28 71 64 35 28 92 49 29 87 55 85 77 74 47 82 42 40 10 51 19", "output": "39569467" } ]
4,000
19,251,200
0
21,675
617
Chocolate
[ "combinatorics" ]
null
null
Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces. You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't. Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of pieces in the chocolate bar. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.
Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.
[ "3\n0 1 0\n", "5\n1 0 1 0 1\n" ]
[ "1\n", "4\n" ]
In the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks. In the second sample you can break the bar in four ways: 10|10|1 1|010|1 10|1|01 1|01|01
[ { "input": "3\n0 1 0", "output": "1" }, { "input": "5\n1 0 1 0 1", "output": "4" }, { "input": "10\n0 0 1 0 0 0 1 1 0 1", "output": "8" }, { "input": "20\n0 0 0 0 1 1 1 0 1 0 0 1 0 1 1 0 1 1 1 0", "output": "24" }, { "input": "50\n0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 0 1 0 1 1 0 1 0 0 1 1 1 1 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0", "output": "11520" }, { "input": "99\n0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 0 0 0 0 0 1 1 0 1 0 0 0 1 0 1 1 0 1 1 0 0 0 1 0 1 0 0 0 0 1 1 1 1 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "17694720" }, { "input": "1\n0", "output": "0" }, { "input": "100\n1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1", "output": "5559060566555523" }, { "input": "41\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "1\n1", "output": "1" }, { "input": "18\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "10\n0 1 0 0 0 0 1 0 0 1", "output": "15" }, { "input": "10\n1 1 0 0 0 1 1 1 1 0", "output": "4" }, { "input": "50\n1 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 1 1", "output": "186624" }, { "input": "50\n0 0 1 1 0 0 0 1 0 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 1 1 1 1 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1", "output": "122880" }, { "input": "99\n1 1 1 1 0 1 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 1 1 0 0 0 1 0 1 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0 1 0 0 1 1 0 0 0 0 1 1 1 1 1 0 1 0 0 1 1 1 0 0", "output": "27869184000" }, { "input": "99\n1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1 0 0 1 0 0 1 1 1 0 1 1 0 0 1 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 0 1 1 0 0 1 0 0 1 1 1", "output": "123834728448" }, { "input": "100\n1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 1 0 1 0", "output": "773967052800" }, { "input": "100\n0 1 1 0 1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0 1 1 1 1 0 1 1 1 1 0 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 0 1", "output": "38698352640" }, { "input": "100\n1 1 1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0", "output": "72236924928" }, { "input": "100\n1 1 0 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 1 1 1 1 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1", "output": "58047528960" }, { "input": "100\n0 1 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 1 0 1 1 1 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 1 0 1 0 1 0 0 0 1 1 0 1 1 0 1 1 1 1 0", "output": "73987522560" }, { "input": "100\n1 1 0 1 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 1 0 1 0 1 1 1 0 1 1 0 1 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 1 1 1 1 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 1 0", "output": "180592312320" }, { "input": "100\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1", "output": "1900000000" } ]
124
1,638,400
3
21,716
0
none
[ "none" ]
null
null
Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well. This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good. Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, *m* icons can fit in a horizontal row in any window. Igor K.'s computer contains *n* folders in the D: disk's root catalog. The folders are numbered from 1 to *n* in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from *a* to *b* inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from *a* to *b* and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders.
The only line contains four integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*<=≤<=109, 1<=≤<=*a*<=≤<=*b*<=≤<=*n*). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted.
Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from *a* to *b*.
[ "11 4 3 9\n", "20 5 2 20\n" ]
[ "3\n", "2\n" ]
The images below illustrate statement tests. The first test: <img class="tex-graphics" src="https://espresso.codeforces.com/a0e4ba690dd16e3c68210a28afd82020b23fb605.png" style="max-width: 100.0%;max-height: 100.0%;"/> In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our second selection and folder 9 with our third, last selection. The second test: <img class="tex-graphics" src="https://espresso.codeforces.com/289e2666a3d8b3dfe5b22ff3d88976df711640f7.png" style="max-width: 100.0%;max-height: 100.0%;"/> In this test we can first select all folders in the first row (2, 3, 4, 5), then — all other ones.
[ { "input": "11 4 3 9", "output": "3" }, { "input": "20 5 2 20", "output": "2" }, { "input": "1 1 1 1", "output": "1" }, { "input": "26 5 2 18", "output": "3" }, { "input": "21 5 1 15", "output": "1" }, { "input": "21 5 1 21", "output": "1" }, { "input": "21 5 8 14", "output": "2" }, { "input": "20 4 1 20", "output": "1" }, { "input": "21 5 1 13", "output": "2" }, { "input": "21 5 4 15", "output": "2" }, { "input": "17 3 1 16", "output": "2" }, { "input": "19 5 7 19", "output": "2" }, { "input": "18 2 1 13", "output": "2" }, { "input": "21 3 6 11", "output": "2" }, { "input": "21 5 3 12", "output": "2" }, { "input": "21 3 6 10", "output": "3" }, { "input": "28 5 4 26", "output": "3" }, { "input": "21 5 6 18", "output": "2" }, { "input": "21 5 4 21", "output": "2" }, { "input": "17 5 6 17", "output": "1" }, { "input": "21 5 9 12", "output": "2" }, { "input": "21 3 6 7", "output": "2" }, { "input": "21 5 7 9", "output": "1" }, { "input": "12 4 5 8", "output": "1" }, { "input": "21 3 6 8", "output": "2" }, { "input": "21 1 5 17", "output": "1" }, { "input": "5 5 2 4", "output": "1" }, { "input": "18 4 6 17", "output": "2" }, { "input": "18 4 6 18", "output": "2" }, { "input": "16 4 1 16", "output": "1" }, { "input": "20 4 7 14", "output": "2" }, { "input": "17 3 12 16", "output": "3" }, { "input": "12 4 8 9", "output": "2" }, { "input": "11 8 2 7", "output": "1" }, { "input": "27 5 4 24", "output": "3" }, { "input": "29 5 12 27", "output": "3" }, { "input": "30 5 5 29", "output": "2" }, { "input": "91 2 15 72", "output": "1" }, { "input": "41 1 8 27", "output": "1" }, { "input": "26 5 7 21", "output": "2" }, { "input": "70 5 31 33", "output": "1" }, { "input": "84 9 6 80", "output": "3" }, { "input": "79 8 41 64", "output": "1" }, { "input": "63 11 23 48", "output": "2" }, { "input": "97 9 18 54", "output": "2" }, { "input": "75 18 20 23", "output": "1" }, { "input": "66 42 43 44", "output": "1" }, { "input": "92 54 20 53", "output": "1" }, { "input": "32 90 31 32", "output": "1" }, { "input": "18 100 6 6", "output": "1" }, { "input": "458 12 203 310", "output": "2" }, { "input": "149 49 92 129", "output": "2" }, { "input": "264 2 9 63", "output": "2" }, { "input": "908 6 407 531", "output": "3" }, { "input": "410 36 109 191", "output": "2" }, { "input": "301 38 97 171", "output": "3" }, { "input": "691 27 313 499", "output": "3" }, { "input": "939 42 86 827", "output": "3" }, { "input": "280 32 64 277", "output": "3" }, { "input": "244 25 94 199", "output": "3" }, { "input": "134 110 11 52", "output": "1" }, { "input": "886 251 61 672", "output": "3" }, { "input": "261 686 243 254", "output": "1" }, { "input": "162 309 68 98", "output": "1" }, { "input": "476 398 77 256", "output": "1" }, { "input": "258 224 84 174", "output": "1" }, { "input": "357 182 73 247", "output": "2" }, { "input": "488 655 290 457", "output": "1" }, { "input": "149 334 78 105", "output": "1" }, { "input": "488 519 203 211", "output": "1" }, { "input": "192293793 2864 5278163 190776899", "output": "3" }, { "input": "38644205 2729 9325777 31658388", "output": "3" }, { "input": "268836959 6117 166683294 249843000", "output": "3" }, { "input": "831447817 8377 549549158 577671489", "output": "3" }, { "input": "444819690 3519 48280371 117052060", "output": "3" }, { "input": "729584406 8367 456501516 557088265", "output": "3" }, { "input": "629207296 3735 112288653 309364482", "output": "3" }, { "input": "775589210 6930 266348458 604992807", "output": "3" }, { "input": "249414894 1999 34827655 127026562", "output": "3" }, { "input": "566377385 227 424126063 478693454", "output": "3" }, { "input": "960442940 572344654 77422042 406189391", "output": "1" }, { "input": "291071313 592207814 6792338 181083636", "output": "1" }, { "input": "191971162 306112722 18212391 188328807", "output": "1" }, { "input": "609162932 300548167 21640850 411089609", "output": "2" }, { "input": "645010014 34698301 217620581 416292490", "output": "3" }, { "input": "51474721 867363452 12231088 43489285", "output": "1" }, { "input": "484381636 927869638 57278216 175514226", "output": "1" }, { "input": "491259590 529594367 305425951 326414536", "output": "1" }, { "input": "733405771 830380469 19971607 389270995", "output": "1" }, { "input": "446237720 920085248 296916273 439113596", "output": "1" }, { "input": "12 6 3 10", "output": "2" }, { "input": "25 2 8 11", "output": "2" }, { "input": "17 8 3 15", "output": "2" }, { "input": "9 2 4 7", "output": "2" }, { "input": "6 7 5 6", "output": "1" }, { "input": "13 2 1 6", "output": "1" }, { "input": "15 8 10 14", "output": "1" }, { "input": "27 2 5 13", "output": "2" }, { "input": "14 8 2 12", "output": "2" }, { "input": "61 1 10 38", "output": "1" }, { "input": "15 6 7 15", "output": "1" }, { "input": "100 1 2 15", "output": "1" }, { "input": "10 1 4 5", "output": "1" }, { "input": "6 3 1 6", "output": "1" }, { "input": "4 3 3 4", "output": "2" }, { "input": "5 2 1 5", "output": "1" }, { "input": "7 3 1 1", "output": "1" }, { "input": "7 3 1 2", "output": "1" }, { "input": "7 3 1 3", "output": "1" }, { "input": "7 3 1 4", "output": "2" }, { "input": "7 3 1 5", "output": "2" }, { "input": "7 3 1 6", "output": "1" }, { "input": "7 3 1 7", "output": "1" }, { "input": "7 3 2 2", "output": "1" }, { "input": "7 3 2 3", "output": "1" }, { "input": "7 3 2 4", "output": "2" }, { "input": "7 3 2 5", "output": "2" }, { "input": "7 3 2 6", "output": "2" }, { "input": "7 3 2 7", "output": "2" }, { "input": "7 3 3 3", "output": "1" }, { "input": "7 3 3 4", "output": "2" }, { "input": "7 3 3 5", "output": "2" }, { "input": "7 3 3 6", "output": "2" }, { "input": "7 3 3 7", "output": "2" }, { "input": "7 3 4 4", "output": "1" }, { "input": "7 3 4 5", "output": "1" }, { "input": "7 3 4 6", "output": "1" }, { "input": "7 3 4 7", "output": "1" }, { "input": "7 3 5 5", "output": "1" }, { "input": "7 3 5 6", "output": "1" }, { "input": "7 3 5 7", "output": "2" }, { "input": "7 3 6 6", "output": "1" }, { "input": "7 3 6 7", "output": "2" }, { "input": "7 3 7 7", "output": "1" }, { "input": "8 3 1 1", "output": "1" }, { "input": "8 3 1 2", "output": "1" }, { "input": "8 3 1 3", "output": "1" }, { "input": "8 3 1 4", "output": "2" }, { "input": "8 3 1 5", "output": "2" }, { "input": "8 3 1 6", "output": "1" }, { "input": "8 3 1 7", "output": "2" }, { "input": "8 3 1 8", "output": "1" }, { "input": "8 3 2 2", "output": "1" }, { "input": "8 3 2 3", "output": "1" }, { "input": "8 3 2 4", "output": "2" }, { "input": "8 3 2 5", "output": "2" }, { "input": "8 3 2 6", "output": "2" }, { "input": "8 3 2 7", "output": "2" }, { "input": "8 3 2 8", "output": "2" }, { "input": "8 3 3 3", "output": "1" }, { "input": "8 3 3 4", "output": "2" }, { "input": "8 3 3 5", "output": "2" }, { "input": "8 3 3 6", "output": "2" }, { "input": "8 3 3 7", "output": "3" }, { "input": "8 3 3 8", "output": "2" }, { "input": "8 3 4 4", "output": "1" }, { "input": "8 3 4 5", "output": "1" }, { "input": "8 3 4 6", "output": "1" }, { "input": "8 3 4 7", "output": "2" }, { "input": "8 3 4 8", "output": "1" }, { "input": "8 3 5 5", "output": "1" }, { "input": "8 3 5 6", "output": "1" }, { "input": "8 3 5 7", "output": "2" }, { "input": "8 3 5 8", "output": "2" }, { "input": "8 3 6 6", "output": "1" }, { "input": "8 3 6 7", "output": "2" }, { "input": "8 3 6 8", "output": "2" }, { "input": "8 3 7 7", "output": "1" }, { "input": "8 3 7 8", "output": "1" }, { "input": "8 3 8 8", "output": "1" } ]
124
0
0
21,744
710
Two Arithmetic Progressions
[ "math", "number theory" ]
null
null
You are given two arithmetic progressions: *a*1*k*<=+<=*b*1 and *a*2*l*<=+<=*b*2. Find the number of integers *x* such that *L*<=≤<=*x*<=≤<=*R* and *x*<==<=*a*1*k*'<=+<=*b*1<==<=*a*2*l*'<=+<=*b*2, for some integers *k*',<=*l*'<=≥<=0.
The only line contains six integers *a*1,<=*b*1,<=*a*2,<=*b*2,<=*L*,<=*R* (0<=&lt;<=*a*1,<=*a*2<=≤<=2·109,<=<=-<=2·109<=≤<=*b*1,<=*b*2,<=*L*,<=*R*<=≤<=2·109,<=*L*<=≤<=*R*).
Print the desired number of integers *x*.
[ "2 0 3 3 5 21\n", "2 4 3 0 6 17\n" ]
[ "3\n", "2\n" ]
none
[ { "input": "2 0 3 3 5 21", "output": "3" }, { "input": "2 4 3 0 6 17", "output": "2" }, { "input": "2 0 4 2 -39 -37", "output": "0" }, { "input": "1 9 3 11 49 109", "output": "20" }, { "input": "3 81 5 72 -1761 501", "output": "28" }, { "input": "8 -89 20 67 8771 35222", "output": "661" }, { "input": "1 -221 894 86403 -687111 141371", "output": "62" }, { "input": "1 -1074 271 17741 -2062230 1866217", "output": "6821" }, { "input": "3 2408 819 119198 -8585197 7878219", "output": "9474" }, { "input": "1 341 8581 3946733 -59420141 33253737", "output": "3416" }, { "input": "1 10497 19135 2995296 -301164547 -180830773", "output": "0" }, { "input": "8 40306 2753 1809818 254464419 340812028", "output": "3921" }, { "input": "2 21697 9076 1042855 -319348358 236269755", "output": "25918" }, { "input": "4 2963 394 577593 125523962 628140505", "output": "637839" }, { "input": "75 61736 200 200511 160330870 609945842", "output": "749358" }, { "input": "34 64314 836 5976 591751179 605203191", "output": "946" }, { "input": "1 30929 25249 95822203 -1076436442 705164517", "output": "24134" }, { "input": "3 -1208 459 933808 603490653 734283665", "output": "284952" }, { "input": "1 35769 16801 47397023 -82531776 1860450454", "output": "107914" }, { "input": "1 -3078 36929 51253687 -754589746 -53412627", "output": "0" }, { "input": "1 -32720 3649 7805027 408032642 925337350", "output": "141766" }, { "input": "1 -2000000000 1 -2000000000 -2000000000 2000000000", "output": "4000000001" }, { "input": "1 -2000000000 2 -2000000000 -2000000000 2000000000", "output": "2000000001" }, { "input": "3 -2000000000 2 -2000000000 -2000000000 2000000000", "output": "666666667" }, { "input": "999999999 999999998 1000000000 999999999 1 10000", "output": "0" }, { "input": "1 -2000000000 1 2000000000 1 10", "output": "0" }, { "input": "1 -2000000000 2 2000000000 -2000000000 2000000000", "output": "1" }, { "input": "2 0 2 1 0 1000000000", "output": "0" }, { "input": "1000000000 0 1 0 0 2000000000", "output": "3" }, { "input": "4 0 4 1 5 100", "output": "0" }, { "input": "1000000000 1 999999999 0 1 100000000", "output": "0" }, { "input": "1 30929 1 1 1 1", "output": "0" }, { "input": "1 1 1 1 -2000000000 2000000000", "output": "2000000000" }, { "input": "4 0 4 1 0 100", "output": "0" }, { "input": "1 -2000000000 1 2000000000 5 5", "output": "0" }, { "input": "51 -1981067352 71 -414801558 -737219217 1160601982", "output": "435075" }, { "input": "2 -1500000000 4 -1499999999 1600000000 1700000000", "output": "0" }, { "input": "135 -1526277729 32 1308747737 895574 1593602399", "output": "65938" }, { "input": "1098197640 6 994625382 6 -474895292 -101082478", "output": "0" }, { "input": "12 -696575903 571708420 236073275 2 14", "output": "0" }, { "input": "1 -9 2 -10 -10 -9", "output": "0" }, { "input": "2 -11 2 -9 -11 -9", "output": "1" }, { "input": "40 54 15 74 -180834723 1373530127", "output": "11446084" }, { "input": "2 57 1 56 -1773410854 414679043", "output": "207339494" }, { "input": "9 12 1 40 624782492 883541397", "output": "28750990" }, { "input": "4 -1000000000 2 4 100 1000", "output": "226" }, { "input": "66 90 48 84 -1709970247 1229724777", "output": "2329024" }, { "input": "1000000000 1 2000000000 0 -2000000000 200000000", "output": "0" }, { "input": "2 0 2 1 -1000000000 1000000000", "output": "0" }, { "input": "2 -1000000000 2 -999999999 -1000000000 1000000000", "output": "0" }, { "input": "26 1885082760 30 -1612707510 -1113844607 1168679422", "output": "0" }, { "input": "76 -19386 86 -6257 164862270 1443198941", "output": "0" }, { "input": "5 -2000000000 5 1000000000 1000000000 2000000000", "output": "200000001" }, { "input": "505086589 -4 1288924334 -4 -5 -4", "output": "1" }, { "input": "91 -193581878 2 1698062870 -819102473 1893630769", "output": "1074549" }, { "input": "8 11047 45 12730 -45077355 1727233357", "output": "4797835" }, { "input": "35 8673 6 -19687 -111709844 1321584980", "output": "6293220" }, { "input": "71 1212885043 55 1502412287 970234397 1952605611", "output": "115287" }, { "input": "274497829 -12 9 -445460655 -5 4", "output": "0" }, { "input": "1509527550 3 7 -134101853 2 7", "output": "1" }, { "input": "43 -1478944506 45 494850401 634267177 1723176461", "output": "562743" }, { "input": "25 479638866 50 -874479027 -2000000000 2000000000", "output": "0" }, { "input": "11 -10 1 -878946597 -11127643 271407906", "output": "24673447" }, { "input": "15 -738862158 12 -3 -3 12", "output": "1" }, { "input": "70 -835526513 23 687193329 -1461506792 1969698938", "output": "796587" }, { "input": "124 1413 15321 312133 3424 1443242", "output": "0" }, { "input": "75 -13580 14 4508 -67634192 1808916097", "output": "1722773" }, { "input": "915583842 -15 991339476 -12 -15 -5", "output": "0" }, { "input": "85 -18257 47 -7345 -76967244 1349252598", "output": "337737" }, { "input": "178 331734603 162 -73813367 -577552570 1005832995", "output": "46754" }, { "input": "8 -17768 34 963 -2000000000 2000000000", "output": "0" }, { "input": "26 1885082760 30 -1612707510 -2000000000 2000000000", "output": "294660" }, { "input": "4 -1999999999 6 -1999999998 -999999999 1999999999", "output": "0" }, { "input": "121826 1323 1327 304172 -1521910750 860413213", "output": "5" }, { "input": "36281 170 1917 927519 -1767064448 -177975414", "output": "0" }, { "input": "37189 -436 464 797102 -1433652908 1847752465", "output": "107" }, { "input": "81427 -688 1720 -221771 -77602716 1593447723", "output": "11" }, { "input": "11 -1609620737 1315657088 -7 -162162918 287749240", "output": "0" }, { "input": "1480269313 -1048624081 1314841531 -8 295288505 358226461", "output": "0" }, { "input": "13 -15 19 -2 -334847526 1334632952", "output": "5403373" }, { "input": "1254161381 -7 821244830 -7 -698761303 941496965", "output": "1" }, { "input": "1269100557 -5 6 -5 -12 -6", "output": "0" }, { "input": "847666888 -6 1327933031 -6 -5 -2", "output": "0" }, { "input": "1465846675 1002489474 9 -1250811979 1030017372 1391560043", "output": "0" }, { "input": "8 -1915865359 867648990 9 -5 -4", "output": "0" }, { "input": "3 -1164702220 906446587 -1868913852 222249893 1493113759", "output": "0" }, { "input": "15 -8 17 3 -393290856 231975525", "output": "909708" }, { "input": "734963978 0 17 0 -12 -5", "output": "0" }, { "input": "1090004357 5 1124063714 -840327001 -448110704 128367602", "output": "0" }, { "input": "18 -1071025614 1096150070 0 -6 0", "output": "1" }, { "input": "451525105 -8 1256335024 -8 -718788747 928640626", "output": "1" }, { "input": "4 3 5 -1292190012 -97547955 250011754", "output": "12500588" }, { "input": "14 -7 14 -1488383431 -1044342357 842171605", "output": "0" }, { "input": "1384140089 5 16 -1661922737 442287491 1568124284", "output": "0" }, { "input": "16 -11 14 -1466771835 -1192555694 -2257860", "output": "0" }, { "input": "1676164235 -1589020998 1924931103 1189158232 6 12", "output": "0" }, { "input": "15 16 12 -5 11 23", "output": "0" }, { "input": "16 -16 5 20 -9 7", "output": "0" }, { "input": "4 -9 1 -2 -13 -1", "output": "1" }, { "input": "18 -17 9 -17 -29 17", "output": "2" }, { "input": "735463638 620656007 878587644 536507630 -1556948056 1714374073", "output": "0" }, { "input": "1789433851 -633540112 1286318222 -1728151682 1438333624 1538194890", "output": "0" }, { "input": "15 -1264610276 1157160166 -336457087 -496892962 759120142", "output": "0" }, { "input": "831644204 422087925 17 -1288230412 -1090082747 1271113499", "output": "1" }, { "input": "17 -13 223959272 -1081245422 -1756575771 38924201", "output": "1" }, { "input": "1228969457 -1826233120 11 -1063855654 -819177202 1039858319", "output": "0" }, { "input": "1186536442 -1691684240 17 -1 -702600351 1121394816", "output": "1" }, { "input": "1132421757 -1481846636 515765656 -12 -622203577 552143596", "output": "0" }, { "input": "18 -1123473160 1826212361 -10 -12 1", "output": "1" }, { "input": "1197045662 7 15 -1445473718 -1406137199 800415943", "output": "1" }, { "input": "18 565032929 13 735553852 107748471 1945959489", "output": "5172673" }, { "input": "1734271904 1 19 -1826828681 0 4", "output": "1" }, { "input": "1614979757 -1237127436 12 75067457 -933537920 451911806", "output": "1" }, { "input": "8 -335942902 1179386720 -723257398 -13 -12", "output": "0" }, { "input": "989432982 2 9 366779468 -1427636085 985664909", "output": "0" }, { "input": "7 -1390956935 1404528667 -4 -15 0", "output": "1" }, { "input": "1370475975 841789607 733784598 467967887 -7 15", "output": "0" }, { "input": "6 -7 9 -1 -10 1", "output": "1" }, { "input": "960716652 1417038753 1222139305 -4 -1570098546 -931528535", "output": "0" }, { "input": "1744394473 5 1523286739 629247513 -6 1", "output": "0" }, { "input": "2627 -4960 2627 -4960 -4960 4960", "output": "4" }, { "input": "6 -364562196 7 -803430276 0 11", "output": "0" }, { "input": "1955378240 -837482305 1743607821 -1623988108 -653286850 178227154", "output": "0" }, { "input": "9 -1642366642 1499382371 -6 -822052389 1405478033", "output": "0" }, { "input": "9 -1 8 -1 -711474975 237571596", "output": "3299606" }, { "input": "1497677869 -1313800455 11 12 -1157529918 1754001465", "output": "1" }, { "input": "11 -80049925 1600186381 -1454831688 -1384227392 1621203975", "output": "0" }, { "input": "1042015302 -56794440 1727095321 -1037110962 -9 11", "output": "0" }, { "input": "13 0 1419591662 -1360930956 343359607 1283114457", "output": "0" }, { "input": "752411560 -6 857048450 -405514986 -5 0", "output": "0" }, { "input": "12 2 18 2 -6 3", "output": "1" }, { "input": "11 -1 15 -1 -13 2", "output": "1" }, { "input": "1446642133 -7 9 -1719422944 -916435667 36154654", "output": "1" }, { "input": "1689390799 501112014 13 -1621132473 398367938 709483101", "output": "0" }, { "input": "1932547151 -725726769 782679113 -10 -184530763 498112212", "output": "0" } ]
62
0
0
21,745
161
Discounts
[ "constructive algorithms", "greedy", "sortings" ]
null
null
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them! Polycarpus has *k* carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible. Polycarpus must use all *k* carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
The first input line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=103) — the number of items in the supermarket and the number of carts, correspondingly. Next *n* lines describe the items as "*c**i* *t**i*" (without the quotes), where *c**i* (1<=≤<=*c**i*<=≤<=109) is an integer denoting the price of the *i*-th item, *t**i* (1<=≤<=*t**i*<=≤<=2) is an integer representing the type of item *i* (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
In the first line print a single real number with exactly one decimal place — the minimum total price of the items, including the discounts. In the following *k* lines print the descriptions of the items in the carts. In the *i*-th line print the description of the *i*-th cart as "*t* *b*1 *b*2 ... *b**t*" (without the quotes), where *t* is the number of items in the *i*-th cart, and the sequence *b*1,<=*b*2,<=...,<=*b**t* (1<=≤<=*b**j*<=≤<=*n*) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to *n* in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them.
[ "3 2\n2 1\n3 2\n3 1\n", "4 3\n4 1\n1 2\n2 2\n3 2\n" ]
[ "5.5\n2 1 2\n1 3\n", "8.0\n1 1\n2 4 2\n1 3\n" ]
In the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5.
[ { "input": "3 2\n2 1\n3 2\n3 1", "output": "5.5\n2 1 2\n1 3" }, { "input": "4 3\n4 1\n1 2\n2 2\n3 2", "output": "8.0\n1 1\n1 2\n2 3 4" }, { "input": "1 1\n1 1", "output": "0.5\n1 1" }, { "input": "1 1\n1 2", "output": "1.0\n1 1" }, { "input": "10 1\n1 1\n2 2\n1 1\n23 2\n17 2\n1 1\n1 1\n30 2\n1 1\n9 2", "output": "85.5\n10 1 2 4 5 8 10 3 6 7 9" }, { "input": "11 11\n6 2\n6 2\n1 2\n2 2\n3 1\n6 2\n1 1\n1 1\n3 1\n3 1\n6 2", "output": "32.5\n1 5\n1 9\n1 10\n1 7\n1 8\n1 1\n1 2\n1 3\n1 4\n1 6\n1 11" }, { "input": "5 4\n24 1\n19 1\n28 2\n7 1\n23 2", "output": "76.0\n1 1\n1 2\n1 4\n2 3 5" }, { "input": "20 3\n28 1\n786180179 2\n16 1\n617105650 2\n23 1\n21 1\n22 1\n7 1\n314215182 2\n409797301 2\n14 1\n993310357 2\n372545570 2\n791297014 2\n13 1\n25 1\n307921408 2\n625842662 2\n136238241 2\n13 1", "output": "5354453716.0\n18 5 2 4 9 10 12 13 14 17 18 19 7 6 3 11 15 20 8\n1 1\n1 16" }, { "input": "21 7\n14 1\n882797755 2\n17 1\n906492329 2\n209923513 2\n802927469 2\n949195463 2\n677323647 2\n2129083 2\n2 1\n13 1\n539523264 2\n7 1\n8 1\n12 1\n363470241 2\n9838294 2\n18716193 2\n30 1\n17 1\n24 1", "output": "5362337336.5\n15 15 2 4 5 6 7 8 9 12 16 17 18 14 13 10\n1 19\n1 21\n1 3\n1 20\n1 1\n1 11" }, { "input": "21 21\n42856481 2\n562905883 2\n942536731 2\n206667673 2\n451074408 2\n27 1\n29 1\n172761267 2\n23 1\n24 1\n106235116 2\n126463249 2\n29 1\n9 1\n83859496 2\n5 1\n25 1\n337838080 2\n109402491 2\n5 1\n24 1", "output": "3142600975.0\n1 7\n1 13\n1 6\n1 17\n1 10\n1 21\n1 9\n1 14\n1 16\n1 20\n1 1\n1 2\n1 3\n1 4\n1 5\n1 8\n1 11\n1 12\n1 15\n1 18\n1 19" }, { "input": "10 1\n28 1\n1 2\n1 2\n1 2\n15 1\n16 1\n22 1\n20 1\n1 2\n1 2", "output": "105.5\n10 1 2 3 4 9 10 7 8 6 5" }, { "input": "5 4\n10 1\n10 1\n10 1\n9 1\n5 2", "output": "26.5\n2 4 5\n1 1\n1 2\n1 3" }, { "input": "7 4\n10 1\n10 1\n10 1\n9 1\n2 1\n5 2\n3 2", "output": "33.0\n4 4 6 7 5\n1 1\n1 2\n1 3" }, { "input": "7 4\n10 1\n10 1\n10 1\n9 1\n4 1\n5 2\n3 2", "output": "34.5\n4 4 6 7 5\n1 1\n1 2\n1 3" }, { "input": "7 5\n10 1\n10 1\n10 1\n9 1\n4 1\n5 2\n3 2", "output": "30.0\n3 5 6 7\n1 1\n1 2\n1 3\n1 4" } ]
248
20,172,800
0
21,788
518
Arthur and Questions
[ "greedy", "implementation", "math", "ternary search" ]
null
null
After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length *n* (*a*1,<=*a*2,<=...,<=*a**n*), consisting of integers and integer *k*, not exceeding *n*. This sequence had the following property: if you write out the sums of all its segments consisting of *k* consecutive elements (*a*1 <=+<= *a*2 ... <=+<= *a**k*,<= *a*2 <=+<= *a*3 <=+<= ... <=+<= *a**k*<=+<=1,<= ...,<= *a**n*<=-<=*k*<=+<=1 <=+<= *a**n*<=-<=*k*<=+<=2 <=+<= ... <=+<= *a**n*), then those numbers will form strictly increasing sequence. For example, for the following sample: *n*<==<=5,<= *k*<==<=3,<= *a*<==<=(1,<= 2,<= 4,<= 5,<= 6) the sequence of numbers will look as follows: (1 <=+<= 2 <=+<= 4,<= 2 <=+<= 4 <=+<= 5,<= 4 <=+<= 5 <=+<= 6) = (7,<= 11,<= 15), that means that sequence *a* meets the described property. Obviously the sequence of sums will have *n*<=-<=*k*<=+<=1 elements. Somebody (we won't say who) replaced some numbers in Arthur's sequence by question marks (if this number is replaced, it is replaced by exactly one question mark). We need to restore the sequence so that it meets the required property and also minimize the sum |*a**i*|, where |*a**i*| is the absolute value of *a**i*.
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105), showing how many numbers are in Arthur's sequence and the lengths of segments respectively. The next line contains *n* space-separated elements *a**i* (1<=≤<=*i*<=≤<=*n*). If *a**i* <==<= ?, then the *i*-th element of Arthur's sequence was replaced by a question mark. Otherwise, *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) is the *i*-th element of Arthur's sequence.
If Arthur is wrong at some point and there is no sequence that could fit the given information, print a single string "Incorrect sequence" (without the quotes). Otherwise, print *n* integers — Arthur's favorite sequence. If there are multiple such sequences, print the sequence with the minimum sum |*a**i*|, where |*a**i*| is the absolute value of *a**i*. If there are still several such sequences, you are allowed to print any of them. Print the elements of the sequence without leading zeroes.
[ "3 2\n? 1 2\n", "5 1\n-10 -9 ? -7 -6\n", "5 3\n4 6 7 2 9\n" ]
[ "0 1 2 \n", "-10 -9 -8 -7 -6 \n", "Incorrect sequence\n" ]
none
[ { "input": "3 2\n? 1 2", "output": "0 1 2 " }, { "input": "5 1\n-10 -9 ? -7 -6", "output": "-10 -9 -8 -7 -6 " }, { "input": "5 3\n4 6 7 2 9", "output": "Incorrect sequence" }, { "input": "9 3\n? ? ? ? ? ? ? ? ?", "output": "-1 -1 -1 0 0 0 1 1 1 " }, { "input": "5 1\n1000000000 ? ? ? ?", "output": "1000000000 1000000001 1000000002 1000000003 1000000004 " }, { "input": "5 1\n-3 -2 -1 0 1", "output": "-3 -2 -1 0 1 " }, { "input": "7 3\n1 ? -1000000000 ? 100 ? 3", "output": "1 0 -1000000000 2 100 0 3 " }, { "input": "7 3\n1 ? -1000000000 ? 100 ? 2", "output": "Incorrect sequence" }, { "input": "1 1\n?", "output": "0 " }, { "input": "1 1\n0", "output": "0 " }, { "input": "2 1\n-1000000000 1000000000", "output": "-1000000000 1000000000 " }, { "input": "17 1\n? -13 ? ? ? -3 ? ? ? ? ? 10 ? ? ? ? 100", "output": "-14 -13 -6 -5 -4 -3 -2 -1 0 1 2 10 11 12 13 14 100 " }, { "input": "5 2\n? ? -1000000000 ? ?", "output": "-1000000001 0 -1000000000 1 0 " }, { "input": "5 4\n-1 ? ? ? 2", "output": "-1 0 0 0 2 " }, { "input": "10 2\n3 ? 5 ? 7 ? 9 ? 11 ?", "output": "3 -2 5 -1 7 0 9 1 11 2 " }, { "input": "39 3\n-5 1 -13 ? 2 -12 ? 3 -11 -2 4 -10 ? 5 -9 0 6 -8 ? 7 -7 ? 8 -6 5 9 -5 ? 10 -4 ? 11 -3 ? 12 -2 10 13 -1", "output": "-5 1 -13 -4 2 -12 -3 3 -11 -2 4 -10 -1 5 -9 0 6 -8 1 7 -7 2 8 -6 5 9 -5 6 10 -4 7 11 -3 8 12 -2 10 13 -1 " }, { "input": "3 1\n4 ? 5", "output": "Incorrect sequence" }, { "input": "3 1\n-1 ? 1", "output": "-1 0 1 " }, { "input": "3 1\n-3 ? -2", "output": "Incorrect sequence" }, { "input": "7 1\n-4 ? ? ? ? ? 2", "output": "-4 -3 -2 -1 0 1 2 " }, { "input": "3 1\n-5 ? 0", "output": "-5 -1 0 " }, { "input": "9 3\n-5 0 -1 ? ? ? 0 5 1", "output": "-5 0 -1 -1 1 0 0 5 1 " }, { "input": "6 1\n-1 ? 1 2 3 4", "output": "-1 0 1 2 3 4 " }, { "input": "6 1\n-3 ? ? ? ? 3", "output": "-3 -1 0 1 2 3 " }, { "input": "7 1\n-3 ? ? ? ? ? 3", "output": "-3 -2 -1 0 1 2 3 " }, { "input": "7 1\n-2 ? ? ? ? ? 4", "output": "-2 -1 0 1 2 3 4 " }, { "input": "10 1\n-2 ? ? ? ? ? ? 5 ? 10", "output": "-2 -1 0 1 2 3 4 5 6 10 " }, { "input": "7 2\n-10 0 ? 1 ? 2 ?", "output": "-10 0 -1 1 0 2 1 " }, { "input": "7 2\n10 0 ? 1 ? 2 ?", "output": "10 0 11 1 12 2 13 " }, { "input": "9 2\n-10 0 ? 1 ? 2 ? 3 ?", "output": "-10 0 -1 1 0 2 1 3 2 " }, { "input": "9 2\n10 0 ? 1 ? 2 ? 3 ?", "output": "10 0 11 1 12 2 13 3 14 " }, { "input": "7 2\n-10 0 ? 1 -6 2 ?", "output": "-10 0 -7 1 -6 2 0 " }, { "input": "9 2\n-10 0 ? 1 -6 2 ? 3 ?", "output": "-10 0 -7 1 -6 2 0 3 1 " }, { "input": "7 2\n-10 0 ? 1 ? 2 10", "output": "-10 0 0 1 1 2 10 " }, { "input": "7 2\n-10 0 ? 1 ? 2 0", "output": "-10 0 -2 1 -1 2 0 " }, { "input": "9 2\n-10 0 ? 1 ? 2 ? 3 10", "output": "-10 0 -1 1 0 2 1 3 10 " }, { "input": "9 2\n-10 0 ? 1 ? 2 ? 3 0", "output": "-10 0 -3 1 -2 2 -1 3 0 " }, { "input": "7 2\n-10 0 0 1 ? 2 ?", "output": "-10 0 0 1 1 2 2 " }, { "input": "7 2\n-10 0 ? 1 6 2 ?", "output": "-10 0 0 1 6 2 7 " }, { "input": "7 2\n? ? 10 ? ? ? ?", "output": "0 -1 10 0 11 1 12 " }, { "input": "7 2\n? ? -10 ? ? ? ?", "output": "-11 -1 -10 0 0 1 1 " }, { "input": "7 2\n? ? 10 ? -10 ? ?", "output": "Incorrect sequence" }, { "input": "7 2\n? ? -10 ? 10 ? ?", "output": "-11 -1 -10 0 10 1 11 " }, { "input": "9 2\n? ? -10 ? ? ? 10 ? ?", "output": "-11 -1 -10 0 0 1 10 2 11 " } ]
217
12,595,200
3
21,852
453
Little Pony and Harmony Chest
[ "bitmasks", "brute force", "dp" ]
null
null
Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony. A sequence of positive integers *b**i* is harmony if and only if for every two elements of the sequence their greatest common divisor equals 1. According to an ancient book, the key of the chest is a harmony sequence *b**i* which minimizes the following expression: You are given sequence *a**i*, help Princess Twilight to find the key.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements of the sequences *a* and *b*. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=30).
Output the key — sequence *b**i* that minimizes the sum described above. If there are multiple optimal sequences, you can output any of them.
[ "5\n1 1 1 1 1\n", "5\n1 6 4 2 8\n" ]
[ "1 1 1 1 1 ", "1 5 3 1 8 " ]
none
[ { "input": "5\n1 1 1 1 1", "output": "1 1 1 1 1 " }, { "input": "5\n1 6 4 2 8", "output": "1 5 3 1 8 " }, { "input": "10\n16 3 16 10 12 5 14 14 15 27", "output": "19 1 17 7 11 1 16 13 15 29 " }, { "input": "10\n8 7 11 5 17 24 28 18 7 8", "output": "9 7 11 5 17 23 29 19 1 8 " }, { "input": "10\n22 17 28 14 14 26 20 28 21 27", "output": "23 17 31 13 11 25 19 29 16 27 " }, { "input": "10\n28 13 14 9 26 21 25 16 4 22", "output": "29 13 14 11 27 19 25 17 1 23 " }, { "input": "100\n11 27 18 3 26 1 23 2 28 21 28 18 7 26 13 4 12 11 1 29 9 23 6 27 15 6 26 25 11 21 26 29 29 8 18 29 3 24 2 28 7 7 11 23 26 29 30 18 30 23 17 24 25 12 16 26 2 4 30 2 19 2 27 16 17 21 30 17 10 8 16 7 1 3 27 22 23 28 16 9 15 28 10 15 26 8 20 6 21 12 24 16 13 7 12 8 23 16 29 24", "output": "11 27 17 1 25 1 23 1 19 13 1 1 1 1 1 1 1 1 1 53 1 1 1 1 1 1 1 1 1 1 1 49 47 1 1 43 1 1 1 1 1 1 1 1 1 29 41 1 37 1 1 1 1 1 1 1 1 1 32 1 1 1 1 1 1 1 31 1 1 1 1 1 1 1 1 1 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": "10\n26 25 10 6 28 11 23 22 8 23", "output": "27 25 13 7 29 11 23 19 8 17 " }, { "input": "30\n24 11 1 17 15 11 12 8 6 25 22 23 9 3 30 3 10 28 15 8 4 28 3 28 26 14 24 1 6 19", "output": "43 11 1 17 13 7 1 1 1 25 19 23 1 1 41 1 1 37 1 1 1 31 1 29 27 1 16 1 1 1 " }, { "input": "30\n11 20 1 17 6 20 22 16 20 22 21 8 3 28 30 2 27 14 10 14 29 21 13 3 13 27 11 18 2 15", "output": "11 19 1 17 1 16 25 13 7 23 1 1 1 41 37 1 31 1 1 1 29 1 1 1 1 27 1 1 1 1 " }, { "input": "30\n17 16 18 4 3 22 28 4 4 17 9 30 2 11 29 12 8 17 9 12 13 11 13 18 28 17 10 12 14 20", "output": "17 16 19 1 1 25 37 1 1 13 7 31 1 11 29 1 1 1 1 1 1 1 1 1 27 1 1 1 1 23 " }, { "input": "30\n9 26 5 7 29 17 19 22 1 28 5 6 9 8 13 9 3 4 16 16 11 24 22 20 12 9 16 22 2 11", "output": "7 41 1 1 37 17 19 31 1 29 1 1 1 1 13 1 1 1 16 11 1 27 25 1 1 1 1 23 1 1 " }, { "input": "30\n15 1 29 2 20 5 3 2 15 17 1 28 9 20 26 5 28 7 7 7 26 15 23 14 19 23 15 19 23 8", "output": "13 1 43 1 19 1 1 1 11 17 1 41 7 16 37 1 31 1 1 1 29 1 27 1 1 25 1 1 23 1 " }, { "input": "30\n15 3 16 26 17 7 8 6 29 12 27 4 16 25 10 2 9 24 6 19 10 12 23 15 3 7 13 13 27 6", "output": "13 1 16 41 17 7 1 1 37 11 31 1 1 29 1 1 1 25 1 19 1 1 23 1 1 1 1 1 27 1 " }, { "input": "30\n21 13 3 13 22 2 30 16 26 23 22 3 7 7 23 20 13 13 13 10 24 25 10 9 2 13 20 24 23 3", "output": "19 13 1 11 17 1 43 16 41 37 7 1 1 1 31 1 1 1 1 1 29 27 1 1 1 1 1 25 23 1 " }, { "input": "100\n17 7 25 13 9 17 18 17 29 7 9 25 26 3 18 25 21 14 21 21 27 30 30 24 29 30 2 14 17 17 8 19 6 20 11 9 19 21 20 25 21 11 29 26 22 8 1 30 27 20 10 16 20 10 17 2 14 21 18 15 19 6 26 8 15 19 20 8 1 23 10 11 30 14 9 9 17 9 11 22 13 5 19 26 9 10 3 9 6 24 26 27 6 14 9 24 20 13 14 23", "output": "17 7 25 13 1 11 1 1 53 1 1 23 19 1 1 1 1 1 1 1 27 47 43 1 41 37 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 1 1 1 1 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 31 1 1 1 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\n9 4 19 29 6 27 23 5 13 19 27 23 25 7 24 22 24 9 4 25 11 21 17 17 14 14 1 16 29 14 7 20 25 2 22 19 16 1 7 6 3 21 28 7 2 18 10 18 20 7 13 4 12 23 29 23 1 22 18 7 19 14 18 19 24 9 5 26 18 14 23 2 10 10 29 19 3 29 29 10 18 13 8 26 22 30 29 2 19 29 13 25 2 13 13 17 18 25 1 7", "output": "1 1 19 53 1 27 23 1 13 17 25 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 49 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 47 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 43 1 1 41 37 1 1 1 1 1 1 32 31 1 1 29 1 1 1 1 1 1 1 1 1 1 " }, { "input": "100\n15 6 12 24 10 29 15 23 27 22 9 15 24 4 15 19 5 4 11 24 17 4 18 11 20 6 29 13 11 11 6 21 7 30 24 29 5 18 8 1 1 22 10 4 20 28 28 30 27 10 24 8 5 11 5 22 3 22 9 13 11 1 25 14 10 22 3 22 28 11 19 29 19 6 19 20 3 10 18 20 1 7 11 18 14 6 3 1 26 5 30 22 5 25 18 26 8 23 26 29", "output": "13 1 11 23 7 53 1 19 27 17 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 47 1 1 1 1 1 1 43 1 41 1 1 1 1 1 1 1 1 1 25 1 37 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 31 1 1 1 1 1 1 1 1 29 " }, { "input": "100\n15 2 7 11 7 24 21 19 2 3 5 20 2 25 21 7 8 29 10 14 23 17 18 5 5 4 28 7 29 24 27 14 4 12 13 23 10 28 10 29 28 1 1 1 17 22 16 4 4 28 13 4 5 1 3 5 4 23 25 13 10 2 25 1 20 5 2 24 15 2 9 20 15 16 22 13 4 22 29 8 7 15 23 18 13 12 7 24 25 2 17 20 1 8 22 3 28 4 21 29", "output": "13 1 7 11 1 23 19 17 1 1 1 1 1 25 1 1 1 53 1 1 1 1 1 1 1 1 47 1 43 1 27 1 1 1 1 1 1 41 1 37 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 31 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 " }, { "input": "100\n26 9 21 8 11 14 9 17 4 18 24 30 19 10 6 13 3 5 1 16 21 5 22 18 26 24 13 8 1 27 18 4 30 7 10 2 3 26 24 4 20 28 20 17 29 13 25 11 4 18 26 20 16 24 13 16 21 30 7 13 24 16 1 20 1 1 24 6 20 7 27 22 8 19 13 17 9 3 4 19 22 12 21 13 8 30 22 22 4 24 30 13 13 21 26 10 29 24 7 12", "output": "25 7 19 1 11 13 1 17 1 1 23 53 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 27 1 1 47 1 1 1 1 1 1 1 1 43 1 1 41 1 1 1 1 1 1 1 1 1 1 1 1 37 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 32 1 1 1 1 31 1 1 1 1 1 29 1 1 1 " }, { "input": "100\n30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30", "output": "53 49 47 43 41 37 32 31 29 27 25 23 19 17 13 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "1\n1", "output": "1 " }, { "input": "1\n30", "output": "30 " }, { "input": "30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "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 " }, { "input": "15\n2 2 2 1 1 1 1 1 1 1 1 1 1 1 1", "output": "2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "1\n6", "output": "6 " }, { "input": "3\n2 2 15", "output": "2 1 15 " } ]
0
0
-1
21,878
556
Case of Fake Numbers
[ "brute force", "implementation" ]
null
null
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was. Its most important components are a button and a line of *n* similar gears. Each gear has *n* teeth containing all numbers from 0 to *n*<=-<=1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on. Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if *n*<==<=5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active. Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0,<=1,<=2,<=...,<=*n*<=-<=1. Write a program that determines whether the given puzzle is real or fake.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of gears. The second line contains *n* digits *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=*n*<=-<=1) — the sequence of active teeth: the active tooth of the *i*-th gear contains number *a**i*.
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
[ "3\n1 0 0\n", "5\n4 2 1 4 3\n", "4\n0 2 3 1\n" ]
[ "Yes\n", "Yes\n", "No\n" ]
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
[ { "input": "3\n1 0 0", "output": "Yes" }, { "input": "5\n4 2 1 4 3", "output": "Yes" }, { "input": "4\n0 2 3 1", "output": "No" }, { "input": "1\n0", "output": "Yes" }, { "input": "2\n1 0", "output": "Yes" }, { "input": "5\n2 4 4 1 1", "output": "Yes" }, { "input": "10\n0 1 2 3 4 5 6 7 8 9", "output": "Yes" }, { "input": "10\n1 5 1 0 6 1 3 5 9 9", "output": "No" }, { "input": "20\n10 11 12 13 14 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9", "output": "Yes" }, { "input": "20\n2 15 18 0 3 12 4 16 13 7 17 9 8 2 15 18 19 17 5 8", "output": "No" }, { "input": "50\n38 13 40 15 42 17 44 19 46 21 48 23 0 25 2 27 4 29 6 31 8 33 10 35 12 37 14 39 16 41 18 43 20 45 22 47 24 49 26 1 28 3 30 5 32 7 34 9 36 11", "output": "Yes" }, { "input": "50\n12 16 9 0 18 36 5 42 28 1 4 43 38 35 14 37 39 13 23 15 37 45 31 38 20 13 18 38 1 13 5 24 35 11 0 44 16 42 8 10 27 3 1 33 33 29 29 33 49 48", "output": "No" }, { "input": "100\n15 86 17 88 19 90 21 92 23 94 25 96 27 98 29 0 31 2 33 4 35 6 37 8 39 10 41 12 43 14 45 16 47 18 49 20 51 22 53 24 55 26 57 28 59 30 61 32 63 34 65 36 67 38 69 40 71 42 73 44 75 46 77 48 79 50 81 52 83 54 85 56 87 58 89 60 91 62 93 64 95 66 97 68 99 70 1 72 3 74 5 76 7 78 9 80 11 82 13 84", "output": "Yes" }, { "input": "15\n2 14 4 1 6 3 8 5 10 7 12 9 14 11 1", "output": "Yes" }, { "input": "30\n19 12 21 14 23 16 25 18 27 20 29 22 1 24 3 26 5 28 7 0 9 2 11 4 13 6 15 8 17 10", "output": "Yes" }, { "input": "50\n27 24 29 26 31 28 33 30 35 32 37 34 39 36 41 38 43 40 45 42 47 44 49 46 1 48 3 0 5 2 7 4 9 6 11 8 13 10 15 12 17 14 19 16 21 18 23 20 25 22", "output": "Yes" }, { "input": "50\n23 19 25 45 22 37 49 22 36 16 30 19 21 4 46 28 39 19 24 12 22 36 41 46 34 40 11 46 29 10 6 21 30 29 6 5 49 45 13 39 34 17 44 45 28 34 7 43 15 25", "output": "No" }, { "input": "100\n95 6 97 8 99 10 1 12 3 14 5 16 7 18 9 20 11 22 13 24 15 26 17 28 19 30 21 32 23 34 25 36 27 38 29 40 31 42 33 44 35 46 37 48 39 50 41 52 43 54 45 56 47 58 49 60 51 62 53 64 55 66 57 68 59 70 61 72 63 74 65 76 67 78 69 80 71 82 73 84 75 86 77 88 79 90 81 92 83 94 85 96 87 98 89 0 91 2 93 4", "output": "Yes" }, { "input": "100\n20 45 10 74 41 81 78 74 91 17 21 65 89 63 7 44 97 3 1 89 87 44 32 10 44 73 73 88 62 77 96 59 4 8 55 1 82 52 63 11 59 53 9 47 29 73 38 44 36 24 72 61 24 11 38 6 91 4 0 65 37 58 20 56 70 87 54 42 79 45 46 73 7 85 43 76 69 35 72 79 38 6 8 0 49 39 32 24 28 54 8 43 98 65 50 20 22 23 2 85", "output": "No" }, { "input": "100\n79 74 22 11 73 70 33 50 9 81 17 14 23 44 4 90 20 22 19 94 66 80 70 42 22 82 49 42 36 7 90 91 80 33 26 52 6 77 30 94 99 6 46 84 96 40 89 2 88 65 80 93 5 60 25 15 32 26 68 85 62 74 69 55 84 0 85 91 23 43 84 94 25 65 28 92 16 0 7 83 48 74 15 20 5 97 34 42 99 97 18 39 21 23 95 77 42 17 32 94", "output": "No" }, { "input": "100\n74 27 76 29 78 31 80 33 82 35 84 37 86 39 88 41 90 43 92 45 94 47 96 49 98 51 0 53 2 55 4 57 6 59 8 61 10 63 12 65 14 67 16 69 18 71 20 73 22 75 24 77 26 79 28 81 30 83 32 85 34 87 36 89 38 91 40 93 42 95 44 97 46 99 48 1 50 3 52 5 54 7 56 9 58 11 60 13 62 15 64 17 66 19 68 21 70 23 72 25", "output": "Yes" }, { "input": "2\n0 0", "output": "No" }, { "input": "2\n0 1", "output": "Yes" }, { "input": "2\n1 0", "output": "Yes" }, { "input": "2\n1 1", "output": "No" }, { "input": "3\n0 1 1", "output": "No" }, { "input": "3\n0 2 2", "output": "No" }, { "input": "4\n0 1 2 2", "output": "No" }, { "input": "3\n1 1 0", "output": "No" } ]
15
0
0
21,943
149
Division into Teams
[ "greedy", "math", "sortings" ]
null
null
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers). The key in football is to divide into teams fairly before the game begins. There are *n* boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic *a**i* (the larger it is, the better the boy plays). Let's denote the number of players in the first team as *x*, the number of players in the second team as *y*, the individual numbers of boys who play for the first team as *p**i* and the individual numbers of boys who play for the second team as *q**i*. Division *n* boys into two teams is considered fair if three conditions are fulfilled: - Each boy plays for exactly one team (*x*<=+<=*y*<==<=*n*). - The sizes of teams differ in no more than one (|*x*<=-<=*y*|<=≤<=1). - The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
The first line contains the only integer *n* (2<=≤<=*n*<=≤<=105) which represents the number of guys in the yard. The next line contains *n* positive space-separated integers, *a**i* (1<=≤<=*a**i*<=≤<=104), the *i*-th number represents the *i*-th boy's playing skills.
On the first line print an integer *x* — the number of boys playing for the first team. On the second line print *x* integers — the individual numbers of boys playing for the first team. On the third line print an integer *y* — the number of boys playing for the second team, on the fourth line print *y* integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: *x*<=+<=*y*<==<=*n*, |*x*<=-<=*y*|<=≤<=1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
[ "3\n1 2 1\n", "5\n2 3 3 1 1\n" ]
[ "2\n1 2 \n1\n3 \n", "3\n4 1 3 \n2\n5 2 \n" ]
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled.
[ { "input": "3\n1 2 1", "output": "2\n1 2 \n1\n3 " }, { "input": "5\n2 3 3 1 1", "output": "3\n4 1 3 \n2\n5 2 " }, { "input": "10\n2 2 2 2 2 2 2 1 2 2", "output": "5\n8 2 4 6 9 \n5\n1 3 5 7 10 " }, { "input": "10\n2 3 3 1 3 1 1 1 2 2", "output": "5\n4 7 1 10 3 \n5\n6 8 9 2 5 " }, { "input": "10\n2 3 2 3 3 1 1 3 1 1", "output": "5\n6 9 1 2 5 \n5\n7 10 3 4 8 " }, { "input": "11\n1 3 1 2 1 2 2 2 1 1 1", "output": "6\n1 5 10 4 7 2 \n5\n3 9 11 6 8 " }, { "input": "11\n54 83 96 75 33 27 36 35 26 22 77", "output": "6\n10 6 8 1 11 3 \n5\n9 5 7 4 2 " }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "6\n1 3 5 7 9 11 \n5\n2 4 6 8 10 " }, { "input": "2\n1 1", "output": "1\n1 \n1\n2 " }, { "input": "2\n35 36", "output": "1\n1 \n1\n2 " }, { "input": "25\n1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 2 2 1 1 2 2 1", "output": "13\n1 10 17 22 2 5 7 9 13 15 18 20 24 \n12\n4 11 21 25 3 6 8 12 14 16 19 23 " }, { "input": "27\n2 1 1 3 1 2 1 1 3 2 3 1 3 2 1 3 2 3 2 1 2 3 2 2 1 2 1", "output": "14\n2 5 8 15 25 1 10 17 21 24 4 11 16 22 \n13\n3 7 12 20 27 6 14 19 23 26 9 13 18 " }, { "input": "30\n2 2 2 3 4 3 4 4 3 2 3 2 2 4 1 4 2 4 2 2 1 4 3 2 1 3 1 1 4 3", "output": "15\n15 25 28 2 10 13 19 24 6 11 26 5 8 16 22 \n15\n21 27 1 3 12 17 20 4 9 23 30 7 14 18 29 " }, { "input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2", "output": "50\n14 27 34 63 70 89 94 23 30 44 90 1 13 20 51 59 66 88 97 7 31 53 64 21 38 87 98 11 33 43 49 62 9 18 35 52 73 84 3 45 47 78 86 26 65 4 36 69 79 85 \n50\n17 32 56 68 81 91 12 25 37 80 100 8 15 39 54 61 77 96 2 29 42 55 71 22 76 95 6 24 41 48 60 93 10 28 40 57 74 99 5 46 67 83 19 58 75 16 50 72 82 92 " }, { "input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "50\n26 20 68 7 19 89 65 93 14 62 94 3 73 8 12 43 32 18 56 28 59 15 27 96 34 51 55 41 38 48 82 72 63 5 67 47 61 99 64 33 24 80 13 17 4 90 71 74 45 95 \n50\n30 37 97 31 78 23 92 36 50 88 11 52 66 85 10 87 16 81 77 54 42 21 76 2 86 98 100 53 75 70 69 58 60 22 84 57 39 35 25 79 44 1 9 49 6 83 46 29 91 40 " }, { "input": "100\n2382 7572 9578 1364 2325 2929 7670 5574 2836 2440 6553 1751 929 8785 6894 9373 9308 7338 6380 9541 9951 6785 8993 9942 5087 7544 6582 7139 8458 7424 9759 8199 9464 8817 7625 6200 4955 9373 9500 3062 849 4210 9337 5466 2190 8150 4971 3145 869 5675 1975 161 1998 378 5229 9000 8958 761 358 434 7636 8295 4406 73 375 812 2473 3652 9067 3052 5287 2850 6987 5442 2625 8894 8733 791 9763 5258 8259 9530 2050 7334 2118 2726 8221 5527 8827 1585 8334 8898 6399 6217 7400 2576 5164 9063 6247 9433", "output": "50\n64 59 54 58 66 49 4 12 53 85 5 10 96 86 72 70 48 42 37 25 55 71 44 8 36 99 93 27 15 28 18 30 2 61 46 87 62 29 14 89 92 23 98 17 16 100 39 20 31 24 \n50\n52 65 60 78 41 13 90 51 83 45 1 67 75 9 6 40 68 63 47 97 80 74 88 50 94 19 11 22 73 84 95 26 35 7 32 81 91 77 34 76 57 56 69 43 38 33 82 3 79 21 " }, { "input": "3\n1 2 3", "output": "2\n1 3 \n1\n2 " }, { "input": "3\n10 10 10", "output": "2\n1 3 \n1\n2 " }, { "input": "3\n5 10 10", "output": "2\n1 3 \n1\n2 " }, { "input": "5\n6 1 1 1 1", "output": "3\n2 4 1 \n2\n3 5 " }, { "input": "5\n1 100 2 200 3", "output": "3\n1 5 4 \n2\n3 2 " } ]
0
0
-1
21,948
630
Area of a Star
[ "geometry" ]
null
null
It was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that depends on the area of gold-plating. Write a program that can calculate the area of a star. A "star" figure having *n*<=≥<=5 corners where *n* is a prime number is constructed the following way. On the circle of radius *r* *n* points are selected so that the distances between the adjacent ones are equal. Then every point is connected by a segment with two maximally distant points. All areas bounded by the segments parts are the figure parts.
The only line of the input contains two integers *n* (5<=≤<=*n*<=&lt;<=109, *n* is prime) and *r* (1<=≤<=*r*<=≤<=109) — the number of the star corners and the radius of the circumcircle correspondingly.
Output one number — the star area. The relative error of your answer should not be greater than 10<=-<=7.
[ "7 10\n" ]
[ "108.395919545675" ]
none
[ { "input": "7 10", "output": "108.395919545675" }, { "input": "5 1", "output": "1.122569941449" }, { "input": "7 1000", "output": "1083959.195456745256" }, { "input": "11 1000000000", "output": "1061689977712182980.125000000000" }, { "input": "999999937 1", "output": "1.047197551197" }, { "input": "999999929 2", "output": "4.188790204786" }, { "input": "999999929 1000000000", "output": "1047197551196597556.500000000000" }, { "input": "603530531 585244", "output": "358676198261.124618709087" }, { "input": "7369339 31415926", "output": "1033542520749354.968872070312" }, { "input": "2341 5001", "output": "26190419.663812126875" } ]
61
0
0
22,035
0
none
[ "none" ]
null
null
You are an assistant director in a new musical play. The play consists of *n* musical parts, each part must be performed by exactly one actor. After the casting the director chose *m* actors who can take part in the play. Your task is to assign the parts to actors. However, there are several limitations. First, each actor has a certain voice range and there are some parts that he cannot sing. Formally, there are two integers for each actor, *c**i* and *d**i* (*c**i*<=≤<=*d**i*) — the pitch of the lowest and the highest note that the actor can sing. There also are two integers for each part — *a**j* and *b**j* (*a**j*<=≤<=*b**j*) — the pitch of the lowest and the highest notes that are present in the part. The *i*-th actor can perform the *j*-th part if and only if *c**i*<=≤<=*a**j*<=≤<=*b**j*<=≤<=*d**i*, i.e. each note of the part is in the actor's voice range. According to the contract, the *i*-th actor can perform at most *k**i* parts. Besides, you are allowed not to give any part to some actors (then they take part in crowd scenes). The rehearsal starts in two hours and you need to do the assignment quickly!
The first line contains a single integer *n* — the number of parts in the play (1<=≤<=*n*<=≤<=105). Next *n* lines contain two space-separated integers each, *a**j* and *b**j* — the range of notes for the *j*-th part (1<=≤<=*a**j*<=≤<=*b**j*<=≤<=109). The next line contains a single integer *m* — the number of actors (1<=≤<=*m*<=≤<=105). Next *m* lines contain three space-separated integers each, *c**i*, *d**i* and *k**i* — the range of the *i*-th actor and the number of parts that he can perform (1<=≤<=*c**i*<=≤<=*d**i*<=≤<=109, 1<=≤<=*k**i*<=≤<=109).
If there is an assignment that meets all the criteria aboce, print a single word "YES" (without the quotes) in the first line. In the next line print *n* space-separated integers. The *i*-th integer should be the number of the actor who should perform the *i*-th part. If there are multiple correct assignments, print any of them. If there is no correct assignment, print a single word "NO" (without the quotes).
[ "3\n1 3\n2 4\n3 5\n2\n1 4 2\n2 5 1\n", "3\n1 3\n2 4\n3 5\n2\n1 3 2\n2 5 1\n" ]
[ "YES\n1 1 2\n", "NO\n" ]
none
[]
124
307,200
0
22,054
436
Feed with Candy
[ "greedy" ]
null
null
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has *n* candies of two types (fruit drops and caramel drops), the *i*-th candy hangs at the height of *h**i* centimeters above the floor of the house, its mass is *m**i*. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most *x* centimeter high jumps. When Om Nom eats a candy of mass *y*, he gets stronger and the height of his jump increases by *y* centimeters. What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)?
The first line contains two integers, *n* and *x* (1<=≤<=*n*,<=*x*<=≤<=2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following *n* lines contains three integers *t**i*,<=*h**i*,<=*m**i* (0<=≤<=*t**i*<=≤<=1; 1<=≤<=*h**i*,<=*m**i*<=≤<=2000) — the type, height and the mass of the *i*-th candy. If number *t**i* equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop.
Print a single integer — the maximum number of candies Om Nom can eat.
[ "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5\n" ]
[ "4\n" ]
One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: 1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. 1. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. 1. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. 1. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4.
[ { "input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5", "output": "4" }, { "input": "5 2\n1 15 2\n1 11 2\n0 17 2\n0 16 1\n1 18 2", "output": "0" }, { "input": "6 2\n1 17 3\n1 6 1\n0 4 2\n1 10 1\n1 7 3\n1 5 1", "output": "0" }, { "input": "7 2\n1 14 1\n1 9 2\n0 6 3\n0 20 2\n0 4 2\n0 3 1\n0 9 2", "output": "0" }, { "input": "8 2\n0 20 3\n1 5 2\n1 4 1\n1 7 1\n0 1 3\n1 5 3\n1 7 2\n1 3 1", "output": "2" }, { "input": "9 2\n0 1 1\n1 8 2\n1 11 1\n0 9 1\n1 18 2\n1 7 3\n1 8 3\n0 16 1\n0 12 2", "output": "1" }, { "input": "10 2\n0 2 3\n1 5 2\n0 7 3\n1 15 2\n0 14 3\n1 19 1\n1 5 3\n0 2 2\n0 10 2\n0 10 3", "output": "9" }, { "input": "2 1\n0 1 1\n1 2 1", "output": "2" }, { "input": "2 1\n1 1 1\n0 2 1", "output": "2" }, { "input": "2 1\n0 1 1\n0 2 1", "output": "1" }, { "input": "2 1\n1 1 1\n1 2 1", "output": "1" }, { "input": "2 1\n0 1 1\n1 3 1", "output": "1" }, { "input": "2 1\n1 1 1\n0 3 1", "output": "1" }, { "input": "1 1\n1 2 1", "output": "0" }, { "input": "3 4\n1 1 2\n1 4 100\n0 104 1", "output": "3" }, { "input": "3 4\n1 1 100\n1 4 2\n0 104 1", "output": "3" }, { "input": "3 100\n0 1 1\n1 1 1\n1 1 1", "output": "3" }, { "input": "4 20\n0 10 10\n0 20 50\n1 40 1\n1 40 1", "output": "4" }, { "input": "4 2\n0 1 1\n0 2 3\n1 4 1\n1 5 1", "output": "4" }, { "input": "3 10\n0 9 1\n0 10 10\n1 20 1", "output": "3" }, { "input": "3 5\n0 4 1\n0 5 10\n1 15 5", "output": "3" }, { "input": "3 4\n0 2 1\n0 3 3\n1 6 5", "output": "3" }, { "input": "3 3\n0 1 1\n0 2 100\n1 10 1", "output": "3" }, { "input": "3 2\n0 1 1\n0 2 2\n1 4 4", "output": "3" }, { "input": "5 3\n0 1 5\n0 1 5\n0 1 5\n1 1 10\n1 1 1", "output": "5" }, { "input": "3 2\n0 1 1\n0 2 2\n1 4 2", "output": "3" }, { "input": "4 10\n0 20 1\n1 1 9\n1 2 11\n1 3 8", "output": "3" }, { "input": "7 1\n0 1 99\n1 100 1\n0 100 1\n0 101 1000\n1 1000 1\n0 1000 1\n1 1000 1", "output": "7" }, { "input": "4 3\n0 1 1\n0 2 100\n0 3 1\n1 100 1", "output": "3" }, { "input": "3 3\n0 1 100\n0 2 1\n1 100 100", "output": "3" }, { "input": "3 2\n0 1 1\n0 2 100\n1 10 1", "output": "3" }, { "input": "3 1\n0 1 1\n1 1 5\n0 7 1", "output": "3" }, { "input": "3 5\n0 2 3\n1 9 10\n0 4 4", "output": "3" }, { "input": "3 3\n0 2 1\n0 3 2\n1 5 10", "output": "3" } ]
77
0
0
22,056
748
Santa Claus and Tangerines
[ "binary search", "data structures", "greedy", "two pointers" ]
null
null
Santa Claus has *n* tangerines, and the *i*-th of them consists of exactly *a**i* slices. Santa Claus came to a school which has *k* pupils. Santa decided to treat them with tangerines. However, there can be too few tangerines to present at least one tangerine to each pupil. So Santa decided to divide tangerines into parts so that no one will be offended. In order to do this, he can divide a tangerine or any existing part into two smaller equal parts. If the number of slices in the part he wants to split is odd, then one of the resulting parts will have one slice more than the other. It's forbidden to divide a part consisting of only one slice. Santa Claus wants to present to everyone either a whole tangerine or exactly one part of it (that also means that everyone must get a positive number of slices). One or several tangerines or their parts may stay with Santa. Let *b**i* be the number of slices the *i*-th pupil has in the end. Let Santa's joy be the minimum among all *b**i*'s. Your task is to find the maximum possible joy Santa can have after he treats everyone with tangerines (or their parts).
The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=2·109) denoting the number of tangerines and the number of pupils, respectively. The second line consists of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=107), where *a**i* stands for the number of slices the *i*-th tangerine consists of.
If there's no way to present a tangerine or a part of tangerine to everyone, print -1. Otherwise, print the maximum possible joy that Santa can have.
[ "3 2\n5 9 3\n", "2 4\n12 14\n", "2 3\n1 1\n" ]
[ "5\n", "6\n", "-1\n" ]
In the first example Santa should divide the second tangerine into two parts with 5 and 4 slices. After that he can present the part with 5 slices to the first pupil and the whole first tangerine (with 5 slices, too) to the second pupil. In the second example Santa should divide both tangerines, so that he'll be able to present two parts with 6 slices and two parts with 7 slices. In the third example Santa Claus can't present 2 slices to 3 pupils in such a way that everyone will have anything.
[]
46
4,608,000
0
22,071
45
Event Dates
[ "greedy", "meet-in-the-middle", "sortings" ]
D. Event Dates
2
256
On a history lesson the teacher asked Vasya to name the dates when *n* famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [*l**i*,<=*r**i*] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such *n* dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of known events. Then follow *n* lines containing two integers *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=107) — the earliest acceptable date and the latest acceptable date of the *i*-th event.
Print *n* numbers — the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.
[ "3\n1 2\n2 3\n3 4\n", "2\n1 3\n1 3\n" ]
[ "1 2 3 \n", "1 2 \n" ]
none
[ { "input": "3\n1 2\n2 3\n3 4", "output": "1 2 3 " }, { "input": "2\n1 3\n1 3", "output": "1 2 " }, { "input": "10\n1 10\n3 4\n8 10\n3 4\n5 9\n1 4\n7 10\n1 9\n1 8\n4 10", "output": "7 3 10 4 6 1 9 5 2 8 " }, { "input": "10\n1 1\n8 10\n1 7\n6 8\n5 7\n1 9\n8 8\n6 10\n1 4\n3 4", "output": "1 10 4 6 5 7 8 9 2 3 " }, { "input": "10\n1 2\n1 3\n1 9\n10 10\n4 4\n5 9\n2 5\n7 8\n2 10\n7 10", "output": "1 2 5 10 4 6 3 7 8 9 " }, { "input": "10\n4 12\n2 8\n1 12\n6 8\n4 6\n12 12\n3 10\n1 10\n3 3\n1 10", "output": "9 2 8 6 4 12 7 1 3 5 " }, { "input": "10\n6 7\n5 11\n5 10\n9 10\n11 12\n6 12\n7 11\n1 1\n5 9\n2 8", "output": "6 8 7 9 12 11 10 1 5 2 " }, { "input": "10\n3 11\n2 12\n7 12\n5 5\n6 6\n1 11\n11 11\n1 12\n1 10\n7 11", "output": "3 8 9 5 6 2 11 4 1 7 " }, { "input": "10\n1 4\n1 12\n5 7\n5 5\n2 5\n1 7\n1 10\n7 9\n8 9\n9 11", "output": "1 10 6 5 2 3 4 7 8 9 " }, { "input": "10\n1 2\n10 12\n5 12\n1 7\n1 6\n11 12\n3 8\n7 9\n11 12\n5 6", "output": "1 10 6 3 2 11 4 7 12 5 " }, { "input": "10\n6 9\n1 8\n6 12\n8 15\n2 5\n1 2\n7 15\n12 15\n5 12\n8 15", "output": "6 3 7 9 2 1 8 12 5 10 " }, { "input": "10\n2 4\n10 13\n1 10\n6 13\n9 12\n1 10\n13 15\n1 11\n1 7\n5 6", "output": "2 10 3 7 9 4 13 6 1 5 " }, { "input": "10\n15 15\n6 6\n1 6\n7 15\n3 13\n10 15\n6 13\n1 9\n2 14\n12 13", "output": "15 6 1 8 3 10 7 2 4 12 " }, { "input": "10\n10 10\n13 15\n6 14\n3 15\n4 15\n11 12\n11 15\n8 15\n1 11\n1 9", "output": "10 13 6 3 4 11 12 8 2 1 " }, { "input": "10\n12 12\n6 13\n5 9\n7 11\n1 12\n11 15\n3 13\n1 14\n6 8\n10 10", "output": "12 8 5 7 1 11 3 2 6 10 " }, { "input": "10\n1 6\n4 10\n1 5\n5 10\n1 8\n4 5\n1 8\n4 8\n5 10\n10 10", "output": "2 7 1 8 3 4 5 6 9 10 " }, { "input": "10\n2 8\n8 10\n1 6\n1 10\n7 10\n1 9\n6 8\n3 4\n1 3\n5 8", "output": "4 10 2 8 9 7 6 3 1 5 " } ]
92
0
0
22,072
89
Fire and Ice
[ "greedy" ]
E. Fire and Ice
0
256
The Fire Lord attacked the Frost Kingdom. He has already got to the Ice Fortress, where the Snow Queen dwells. He arranged his army on a segment *n* in length not far from the city walls. And only the frost magician Solomon can save the Frost Kingdom. The *n*-long segment is located at a distance equal exactly to 1 from the castle walls. It can be imaginarily divided into unit segments. On some of the unit segments fire demons are located — no more than one demon per position. Each demon is characterised by his strength - by some positive integer. We can regard the fire demons being idle. Initially Solomon is positioned on the fortress wall. He can perform the following actions several times in a row: - "L" — Solomon shifts one unit to the left. This movement cannot be performed on the castle wall.- "R" — Solomon shifts one unit to the left. This movement cannot be performed if there's no ice block to the right.- "A" — If there's nothing to the right of Solomon, then Solomon creates an ice block that immediately freezes to the block that Solomon is currently standing on. If there already is an ice block, then Solomon destroys it. At that the ice blocks to the right of the destroyed one can remain but they are left unsupported. Those ice blocks fall down. Solomon spends exactly a second on each of these actions. As the result of Solomon's actions, ice blocks' segments fall down. When an ice block falls on a fire demon, the block evaporates and the demon's strength is reduced by 1. When the demons' strength is equal to 0, the fire demon vanishes. The picture below shows how it happens. The ice block that falls on the position with no demon, breaks into lots of tiny pieces and vanishes without hurting anybody. Help Solomon destroy all the Fire Lord's army in minimum time.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). The next line contains *n* numbers, the *i*-th of them represents the strength of the fire demon standing of the *i*-th position, an integer from 1 to 100. If there's no demon on the *i*-th position, then the *i*-th number equals to 0. It is guaranteed that the input data have at least one fire demon.
Print a string of minimum length, containing characters "L", "R" and "A" — the succession of actions leading to the required result. If there are several possible answers, print any of them.
[ "3\n1 0 1\n", "3\n0 2 0\n" ]
[ "ARARARALLLA", "ARARALAARALA" ]
none
[ { "input": "3\n1 0 1", "output": "ARARARALLLA" }, { "input": "3\n0 2 0", "output": "ARARALAARALA" }, { "input": "5\n3 1 2 2 4", "output": "ARALAARALAARARARARARALLLAARARARALAARALAARALLLLLA" }, { "input": "4\n2 2 2 2", "output": "ARARARARALLLLAARARARARALLLLA" }, { "input": "7\n5 3 3 4 2 1 0", "output": "ARARARARARALLLLLAARARARARALLLLAARALAARALAARARARARALAARARARALLLLLLA" }, { "input": "10\n0 0 0 0 0 0 0 1 1 0", "output": "ARARARARARARARARARALLA" }, { "input": "17\n5 10 6 7 3 1 1 1 5 9 2 2 2 2 2 2 2", "output": "ARARARARARALLLLLAARARARARARALLLLLAARARARARALLLLAARARARARALLLLAARARARARALLLAARALAARALAARALAARALAARARARALAARARARARARARARARARARARARARARALLLLLLLLLAARARALLAARARALLAARARALLAARARALAARALAARALAARALAARARARARARARARARALLLLLLLLLLLLLLLLLA" }, { "input": "1\n1", "output": "ARALA" }, { "input": "1\n52", "output": "ARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALA" }, { "input": "1\n100", "output": "ARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALA" }, { "input": "2\n0 1", "output": "ARARALA" }, { "input": "2\n1 0", "output": "ARALA" }, { "input": "2\n1 1", "output": "ARARALLA" }, { "input": "2\n0 100", "output": "ARARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALA" }, { "input": "2\n100 0", "output": "ARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALA" }, { "input": "2\n100 100", "output": "ARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALLAARARALL..." }, { "input": "3\n1 0 100", "output": "ARARARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALLLA" }, { "input": "3\n100 0 100", "output": "ARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARARARALAARALAAR..." }, { "input": "3\n0 100 1", "output": "ARARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARARALLA" }, { "input": "3\n1 100 1", "output": "ARARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARARALLLA" }, { "input": "9\n3 0 1 0 0 2 1 3 2", "output": "ARALAARALAARARARARARARALAARARARARALLAARALAARARALLLLLLLLLA" }, { "input": "10\n1 1 1 6 5 9 9 9 5 2", "output": "ARARARARARARARARARARALLLLLLLAARARARARARARALLLLLLAARARARARARARALLLLLLAARARARARARARALLLLLLAARALAARARARARARALLLAARARARALLLAARARARALLLAARARARALLLAARARARARARALLLLLLLLLLA" }, { "input": "58\n3 5 1 5 0 3 2 0 3 1 2 4 2 2 2 1 3 4 3 2 5 1 4 3 2 5 3 3 3 0 0 3 2 3 1 2 1 2 3 2 3 1 5 1 3 5 4 4 4 0 5 1 2 2 4 3 0 4", "output": "ARARALLAARARALLAARARALAARALAARARARALAARALAARALAARALAARARARARALLAARALAARARARARALAARALAARARARARARARARALLLLLAARARALAARALAARARARARARARARARARARALLLLLAARARARALLLAARARALAARARARARALAARALAARALAARARARARARARARARARALLLLLLLAARARALLAARALAARARARARARARARALLLLAARALAARALAARARARARARARARARARALLLAARALAARARARALAARARARALAARARARARARARALLLLAARARALAARARARALAARARARALAARALAARALAARALAARARARARARARARALLLLLAARARARARARALLLLLAARARARARARALLLLAARALAARARARARARARALAARALAARALAARALAARARARARARARALLLLAARARARARALLAARALAARARARARALAARALAARALAARALLLLL..." }, { "input": "198\n0 6 6 9 9 9 1 7 15 3 4 10 15 10 12 0 6 14 15 11 15 3 15 10 11 10 9 2 7 8 2 15 7 15 2 5 8 9 12 2 12 8 11 14 14 13 3 10 8 0 7 4 4 12 9 5 2 3 1 5 11 3 3 0 0 10 11 15 0 15 2 3 6 12 2 6 14 3 15 1 15 14 7 8 1 10 11 9 9 6 14 4 7 12 7 10 5 4 15 13 5 4 12 13 1 9 1 11 8 13 1 1 6 2 13 7 9 0 12 11 2 0 1 5 3 7 0 12 6 13 14 15 10 5 15 6 2 2 0 8 12 8 11 10 7 3 3 11 12 4 3 3 12 9 0 8 8 12 0 2 5 1 9 10 3 1 14 14 3 2 14 15 4 2 11 1 13 14 10 4 4 14 4 12 4 8 15 3 1 4 5 10 12 7 3 11 15 8", "output": "ARARARARARARALLLLLAARARARARARALLLLLAARARARARARALLLLLAARARARARARALLLLLAARARARARARALLLLLAARARARARARALLLAARARARALLLAARARARALLLAARARARARARARARARARARARARALLLLLLLLAARARARARARARARARALLLLLLLLAARARALLAARARALLAARARALLAARARALLAARARALAARALAARALAARALAARALAARALAARALAARALAARARARARARARARALLLLLAARARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARALAARALAARALAARALAARALAARARARALAARALAARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARALLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLA..." }, { "input": "23\n99 100 99 100 100 100 100 99 100 99 99 100 100 100 99 99 100 100 100 99 99 99 99", "output": "ARARARARARARARARARARARARARARARARARARARARARARARALLLLLLLLLLLLLLLLLLLLLLLAARARARARARARARARARARARARARARARARARARARARARARARALLLLLLLLLLLLLLLLLLLLLLLAARARARARARARARARARARARARARARARARARARARARARARARALLLLLLLLLLLLLLLLLLLLLLLAARARARARARARARARARARARARARARARARARARARARARARARALLLLLLLLLLLLLLLLLLLLLLLAARARARARARARARARARARARARARARARARARARARARARARARALLLLLLLLLLLLLLLLLLLLLLLAARARARARARARARARARARARARARARARARARARARARARARARALLLLLLLLLLLLLLLLLLLLLLLAARARARARARARARARARARARARARARARARARARARARARARARALLLLLLLLLLLLLLLLLLLLLLLAARARARARARARAR..." }, { "input": "2\n2 2", "output": "ARARALLAARARALLA" }, { "input": "2\n1 2", "output": "ARARALAARALLA" }, { "input": "2\n2 1", "output": "ARALAARARALLA" }, { "input": "3\n1 2 1", "output": "ARARALAARARALLLA" }, { "input": "7\n1 1 1 0 1 1 1", "output": "ARARARARARARARALLLLLLLA" }, { "input": "8\n1 0 0 0 0 0 0 1", "output": "ARALAARARARARARARARARALA" }, { "input": "10\n1 0 0 0 0 0 0 1 0 1", "output": "ARALAARARARARARARARARARARALLLA" }, { "input": "20\n2 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1", "output": "ARALAARALAARARARARARARARARALAARARARARARARARARARARARARARALLLLLLLA" }, { "input": "20\n2 0 0 0 0 0 0 1 0 0 0 1 0 100 100 100 100 1 0 1", "output": "ARALAARALAARARARARARARARARARARARARARARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLLAARARARARALLLL..." }, { "input": "20\n10 9 8 7 6 5 4 3 0 0 0 1 0 0 0 0 0 0 0 1", "output": "ARARARARARARARARALLLLLLLLAARARARARARARARARALLLLLLLLAARARARARARARARALLLLLLLAARARARARARARALLLLLLAARARARARARALLLLLAARARARARALLLLAARARARALLLAARARALLAARALAARARARARARARARARARARARARARARARARARARARARALLLLLLLLLLLLLLLLLLLLA" } ]
139
20,172,800
0
22,076
949
Curfew
[ "binary search", "brute force", "greedy", "sortings" ]
null
null
Instructors of Some Informatics School make students go to bed. The house contains *n* rooms, in each room exactly *b* students were supposed to sleep. However, at the time of curfew it happened that many students are not located in their assigned rooms. The rooms are arranged in a row and numbered from 1 to *n*. Initially, in *i*-th room there are *a**i* students. All students are currently somewhere in the house, therefore *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<==<=*nb*. Also 2 instructors live in this house. The process of curfew enforcement is the following. One instructor starts near room 1 and moves toward room *n*, while the second instructor starts near room *n* and moves toward room 1. After processing current room, each instructor moves on to the next one. Both instructors enter rooms and move simultaneously, if *n* is odd, then only the first instructor processes the middle room. When all rooms are processed, the process ends. When an instructor processes a room, she counts the number of students in the room, then turns off the light, and locks the room. Also, if the number of students inside the processed room is not equal to *b*, the instructor writes down the number of this room into her notebook (and turns off the light, and locks the room). Instructors are in a hurry (to prepare the study plan for the next day), so they don't care about who is in the room, but only about the number of students. While instructors are inside the rooms, students can run between rooms that are not locked and not being processed. A student can run by at most *d* rooms, that is she can move to a room with number that differs my at most *d*. Also, after (or instead of) running each student can hide under a bed in a room she is in. In this case the instructor will not count her during the processing. In each room any number of students can hide simultaneously. Formally, here is what's happening: - A curfew is announced, at this point in room *i* there are *a**i* students. - Each student can run to another room but not further than *d* rooms away from her initial room, or stay in place. After that each student can optionally hide under a bed. - Instructors enter room 1 and room *n*, they count students there and lock the room (after it no one can enter or leave this room). - Each student from rooms with numbers from 2 to *n*<=-<=1 can run to another room but not further than *d* rooms away from her current room, or stay in place. Each student can optionally hide under a bed. - Instructors move from room 1 to room 2 and from room *n* to room *n*<=-<=1. - This process continues until all rooms are processed. Let *x*1 denote the number of rooms in which the first instructor counted the number of non-hidden students different from *b*, and *x*2 be the same number for the second instructor. Students know that the principal will only listen to one complaint, therefore they want to minimize the maximum of numbers *x**i*. Help them find this value if they use the optimal strategy.
The first line contains three integers *n*, *d* and *b* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*d*<=≤<=*n*<=-<=1, 1<=≤<=*b*<=≤<=10<=000), number of rooms in the house, running distance of a student, official number of students in a room. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109), *i*-th of which stands for the number of students in the *i*-th room before curfew announcement. It is guaranteed that *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<==<=*nb*.
Output one integer, the minimal possible value of the maximum of *x**i*.
[ "5 1 1\n1 0 0 0 4\n", "6 1 2\n3 8 0 1 0 0\n" ]
[ "1\n", "2\n" ]
In the first sample the first three rooms are processed by the first instructor, and the last two are processed by the second instructor. One of the optimal strategies is the following: firstly three students run from room 5 to room 4, on the next stage two of them run to room 3, and one of those two hides under a bed. This way, the first instructor writes down room 2, and the second writes down nothing. In the second sample one of the optimal strategies is the following: firstly all students in room 1 hide, all students from room 2 run to room 3. On the next stage one student runs from room 3 to room 4, and 5 students hide. This way, the first instructor writes down rooms 1 and 2, the second instructor writes down rooms 5 and 6.
[ { "input": "5 1 1\n1 0 0 0 4", "output": "1" }, { "input": "6 1 2\n3 8 0 1 0 0", "output": "2" }, { "input": "5 1 1\n1 1 0 3 0", "output": "0" }, { "input": "5 1 1\n4 0 0 1 0", "output": "1" }, { "input": "2 1 1\n0 2", "output": "0" }, { "input": "100 66 30\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 27 15 53 29 56 30 24 50 39 39 46 4 14 44 16 55 48 15 54 25 4 44 15 29 55 22 49 52 9 2 22 15 14 33 24 38 11 48 27 34 29 8 37 47 36 54 45 24 31 1434", "output": "0" }, { "input": "100 2 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 3 1 2 8 5 1 9 1 2 12 7 5 0 7 2 11 3 17", "output": "27" }, { "input": "100 3 1\n5 8 5 7 1 2 6 4 3 2 3 2 5 4 0 5 6 0 2 0 2 3 2 3 3 2 4 2 1 1 2 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "16" }, { "input": "39 1 1\n0 1 2 0 0 1 1 1 0 1 2 2 2 0 0 2 2 0 0 1 1 2 0 1 0 2 1 0 2 2 1 0 0 3 2 0 1 2 1", "output": "0" }, { "input": "39 3 1\n0 1 1 0 0 2 0 1 3 1 1 1 0 0 1 1 0 0 2 0 1 1 0 1 0 1 2 3 1 0 0 0 0 5 2 0 4 3 0", "output": "0" }, { "input": "50 1 1\n2 0 0 0 2 4 1 0 1 2 2 1 0 0 1 2 0 0 1 2 0 0 0 1 1 0 0 2 1 1 2 0 4 2 0 0 2 2 1 1 1 4 0 0 0 2 0 0 1 1", "output": "0" }, { "input": "50 2 1\n0 1 1 1 1 1 1 0 2 2 0 0 1 1 2 0 1 0 1 2 0 1 1 0 1 2 3 0 0 1 0 3 1 1 1 1 1 1 3 0 0 0 2 0 2 2 0 3 2 0", "output": "0" }, { "input": "100 10 1\n0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 97 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "4" }, { "input": "100 4 1\n0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 90 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "7" }, { "input": "100 66 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 0 1 1 0 0 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 0 0 1 74", "output": "0" }, { "input": "100 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 4 8 1 5 4 4 3 1 2 3 8 18 15 4 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "32" }, { "input": "100 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 6 3 4 2 6 3 4 5 2 5 0 0 0 0 0 0 0 0 0 1 3 5 6 3 1 2 5 1 1 2 0 0 0 0 0 0 0 0 0 3 5 0 0 1 2 2 1 5 7", "output": "25" }, { "input": "30 1 30\n61 4 40 32 23 35 2 87 20 0 57 21 30 7 16 34 38 18 0 51 61 9 41 22 15 43 47 15 23 48", "output": "0" }, { "input": "30 2 25\n21 17 30 1 11 13 5 33 21 36 16 54 4 18 28 41 9 42 14 19 39 55 20 4 15 53 13 78 23 17", "output": "0" }, { "input": "30 3 30\n19 0 64 36 55 24 8 2 6 20 28 58 53 53 56 72 37 7 1 4 96 13 20 51 15 4 13 33 40 12", "output": "0" }, { "input": "100 2 25\n23 47 16 0 81 70 6 4 31 26 56 58 33 34 23 141 24 18 7 7 2 13 15 8 34 115 7 30 6 7 14 62 3 0 7 73 4 7 5 35 17 26 34 33 12 3 23 27 3 40 2 5 10 10 4 56 50 36 4 14 22 17 7 13 22 85 30 7 10 28 60 35 3 27 0 3 7 52 12 10 74 14 56 54 17 1 50 11 23 2 71 31 11 5 9 10 13 7 16 14", "output": "0" }, { "input": "100 3 30\n20 10 8 3 97 20 40 4 58 24 105 56 26 21 66 1 126 4 21 46 8 2 9 21 0 13 24 53 58 23 3 107 1 22 189 3 31 4 31 0 3 0 9 43 19 74 92 7 71 22 46 26 31 49 18 3 10 9 9 110 30 2 40 21 33 4 11 14 47 4 1 37 3 19 18 63 10 53 19 35 11 57 8 3 11 27 23 5 45 15 127 27 23 48 3 8 20 33 5 28", "output": "0" }, { "input": "100 99 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30", "output": "0" }, { "input": "100 1 17\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 56 47 53 49 41 42 52 56 61 42 97 52 55 55 39 54 57 53 67 43 44 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 22 25 23 27 42 24 28 15 19 19 0 0 0 0 0 0 0 0 0 29 28 33 27 22 25 25 30 31 61", "output": "15" }, { "input": "100 1 24\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 151 150 159 159 147 121 143 143 138 138 127 127 128 123 159 159 128 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "33" }, { "input": "100 5 30\n2 5 2 4 5 2 5 6 6 4 3 6 7 1 3 4 1 6 1 3 4 3 5 3 1 5 1 2 0 5 1 0 4 3 2 7 3 3 1 2 3 1 4 1 1 2 1 3 2 4 0 4 2706 4 1 4 3 7 4 4 4 2 1 7 3 1 4 4 2 5 2 2 2 0 1 2 2 6 3 5 2 5 3 0 3 0 6 2 4 1 4 4 4 3 1 2 4 1 1 2", "output": "4" }, { "input": "100 5 30\n1 1 1 1 1 0 1 1 1 2 0 2 1 0 0 1 0 0 0 0 1 0 2 0 0 1 0 0 2 1 0 1 2 1 2 3 1 1 1 1 0 0 2 1 0 1 1 1 1 0 0 1 0 0 1 0 2 0 2911 2 2 1 3 3 1 2 2 1 1 0 0 2 0 3 1 1 2 0 1 0 0 0 0 1 0 1 1 1 3 1 3 1 0 1 0 0 0 1 2 0", "output": "8" } ]
109
13,516,800
3
22,092
0
none
[ "none" ]
null
null
Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has *n* cities connected by *n*<=-<=1 undirected roads, and for any two cities there always exists a path between them. Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26 different ranks, and 'A' is the topmost, so 'Z' is the bottommost. There are enough officers of each rank. But there is a special rule must obey: if *x* and *y* are two distinct cities and their officers have the same rank, then on the simple path between *x* and *y* there must be a city *z* that has an officer with higher rank. The rule guarantee that a communications between same rank officers will be monitored by higher rank officer. Help Ciel to make a valid plan, and if it's impossible, output "Impossible!".
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Tree Land. Each of the following *n*<=-<=1 lines contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*) — they mean that there will be an undirected road between *a* and *b*. Consider all the cities are numbered from 1 to *n*. It guaranteed that the given graph will be a tree.
If there is a valid plane, output *n* space-separated characters in a line — *i*-th character is the rank of officer in the city with number *i*. Otherwise output "Impossible!".
[ "4\n1 2\n1 3\n1 4\n", "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n" ]
[ "A B B B\n", "D C B A D C B D C D\n" ]
In the first example, for any two officers of rank 'B', an officer with rank 'A' will be on the path between them. So it is a valid solution.
[]
1,000
27,136,000
0
22,166
469
Chat Online
[ "implementation" ]
null
null
Little X and Little Z are good friends. They always chat online. But both of them have schedules. Little Z has fixed schedule. He always online at any moment of time between *a*1 and *b*1, between *a*2 and *b*2, ..., between *a**p* and *b**p* (all borders inclusive). But the schedule of Little X is quite strange, it depends on the time when he gets up. If he gets up at time 0, he will be online at any moment of time between *c*1 and *d*1, between *c*2 and *d*2, ..., between *c**q* and *d**q* (all borders inclusive). But if he gets up at time *t*, these segments will be shifted by *t*. They become [*c**i*<=+<=*t*,<=*d**i*<=+<=*t*] (for all *i*). If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of time between *l* and *r* (both borders inclusive). Also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules). How many integer moments of time from the segment [*l*,<=*r*] suit for that?
The first line contains four space-separated integers *p*,<=*q*,<=*l*,<=*r* (1<=≤<=<=*p*,<=*q*<=≤<=50; 0<=≤<=*l*<=≤<=*r*<=≤<=1000). Each of the next *p* lines contains two space-separated integers *a**i*,<=*b**i* (0<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=1000). Each of the next *q* lines contains two space-separated integers *c**j*,<=*d**j* (0<=≤<=*c**j*<=&lt;<=*d**j*<=≤<=1000). It's guaranteed that *b**i*<=&lt;<=*a**i*<=+<=1 and *d**j*<=&lt;<=*c**j*<=+<=1 for all valid *i* and *j*.
Output a single integer — the number of moments of time from the segment [*l*,<=*r*] which suit for online conversation.
[ "1 1 0 4\n2 3\n0 1\n", "2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17\n" ]
[ "3\n", "20\n" ]
none
[ { "input": "1 1 0 4\n2 3\n0 1", "output": "3" }, { "input": "2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17", "output": "20" }, { "input": "5 2 27 452\n148 154\n421 427\n462 470\n777 786\n969 978\n245 247\n313 322", "output": "54" }, { "input": "3 6 25 785\n273 275\n391 397\n775 783\n84 89\n348 354\n480 483\n552 556\n711 716\n838 844", "output": "99" }, { "input": "1 6 364 421\n649 688\n31 39\n438 441\n516 524\n609 615\n708 710\n850 851", "output": "0" }, { "input": "7 10 87 239\n8 23\n325 374\n516 540\n633 658\n728 742\n833 839\n960 995\n99 114\n213 232\n264 269\n321 327\n492 540\n551 559\n587 590\n625 637\n704 723\n750 764", "output": "151" }, { "input": "33 17 295 791\n41 49\n66 73\n95 102\n118 126\n157 158\n189 198\n228 237\n247 251\n301 307\n318 326\n328 333\n356 363\n373 381\n454 460\n463 466\n471 477\n500 501\n505 510\n559 566\n585 588\n597 604\n675 684\n688 695\n699 705\n749 755\n780 788\n869 873\n879 888\n890 892\n909 918\n953 954\n973 978\n993 996\n53 60\n68 74\n102 105\n149 153\n191 206\n230 242\n249 252\n320 325\n483 488\n509 513\n523 524\n544 560\n651 655\n670 672\n691 708\n742 748\n920 939", "output": "497" }, { "input": "5 4 520 527\n257 263\n309 315\n434 439\n540 541\n759 763\n168 176\n313 316\n546 548\n880 881", "output": "0" }, { "input": "11 40 58 976\n14 22\n85 92\n110 112\n173 181\n188 190\n212 218\n494 498\n530 531\n647 656\n943 948\n960 968\n2 16\n20 31\n40 86\n90 91\n93 96\n103 118\n128 155\n170 173\n176 192\n205 207\n210 217\n237 245\n250 280\n302 304\n311 328\n332 376\n387 419\n422 442\n449 454\n462 491\n496 498\n501 516\n525 552\n556 565\n567 573\n577 578\n586 635\n651 677\n688 699\n704 714\n718 719\n733 766\n768 769\n773 811\n822 826\n830 870\n885 917\n937 961\n971 981\n991 1000", "output": "909" }, { "input": "10 28 435 847\n48 57\n86 95\n186 188\n297 304\n500 506\n594 600\n602 609\n802 811\n906 911\n916 921\n20 22\n115 118\n139 141\n170 171\n184 188\n193 197\n227 230\n232 235\n250 252\n256 260\n271 275\n322 324\n326 328\n379 381\n433 434\n528 529\n563 565\n583 584\n614 615\n617 619\n631 632\n726 729\n750 754\n814 817\n853 855\n881 882\n946 947\n981 984", "output": "284" }, { "input": "13 42 292 733\n304 308\n362 365\n396 397\n686 688\n719 722\n815 816\n901 902\n904 905\n921 924\n929 933\n953 954\n977 980\n982 985\n28 30\n36 37\n108 112\n123 127\n134 135\n151 153\n160 162\n203 205\n208 212\n240 243\n261 264\n271 274\n294 297\n356 358\n383 385\n408 412\n415 418\n435 439\n444 447\n500 502\n507 511\n515 519\n525 529\n541 543\n566 569\n577 579\n606 609\n618 622\n655 656\n715 718\n744 745\n767 771\n798 802\n828 830\n839 840\n842 845\n893 894\n897 898\n902 906\n958 960\n981 983\n988 992", "output": "412" }, { "input": "5 46 211 943\n367 371\n405 408\n639 642\n821 825\n974 978\n13 14\n31 34\n36 39\n48 51\n82 86\n173 174\n193 196\n227 230\n249 250\n259 261\n292 294\n325 327\n329 330\n352 353\n380 383\n390 391\n398 399\n411 414\n418 420\n424 427\n478 479\n488 489\n500 502\n511 514\n534 535\n548 552\n581 584\n596 600\n609 611\n618 622\n641 642\n656 657\n674 678\n707 709\n718 720\n746 748\n752 755\n771 773\n775 777\n865 869\n892 896\n910 911\n946 948\n963 964\n977 978\n986 990", "output": "428" }, { "input": "1 8 169 472\n63 553\n32 65\n75 204\n263 277\n289 326\n342 441\n452 911\n945 956\n971 986", "output": "304" }, { "input": "2 1 17 179\n159 202\n579 602\n115 126", "output": "55" }, { "input": "1 1 0 1000\n0 1000\n0 1000", "output": "1001" }, { "input": "10 11 201 515\n2 3\n102 103\n202 203\n302 304\n401 402\n502 503\n600 603\n701 702\n800 803\n900 902\n1 2\n103 104\n201 202\n302 304\n400 404\n501 504\n600 601\n603 604\n701 704\n800 801\n900 902", "output": "26" }, { "input": "1 7 140 478\n400 404\n3 4\n100 105\n301 304\n403 405\n504 506\n600 605\n904 906", "output": "16" }, { "input": "9 8 453 552\n5 18\n23 28\n125 132\n208 209\n215 230\n516 527\n808 819\n906 913\n926 929\n4 18\n221 229\n316 330\n403 424\n506 516\n805 828\n904 914\n916 917", "output": "49" }, { "input": "9 1 24 52\n63 94\n150 164\n244 275\n379 385\n413 420\n441 490\n506 545\n614 661\n752 776\n531 534", "output": "0" }, { "input": "1 1 0 0\n1 3\n2 5", "output": "1" } ]
31
0
0
22,196
443
Kolya and Tandem Repeat
[ "brute force", "implementation", "strings" ]
null
null
Kolya got string *s* for his birthday, the string consists of small English letters. He immediately added *k* more characters to the right of the string. Then Borya came and said that the new string contained a tandem repeat of length *l* as a substring. How large could *l* be? See notes for definition of a tandem repeat.
The first line contains *s* (1<=≤<=|*s*|<=≤<=200). This string contains only small English letters. The second line contains number *k* (1<=≤<=*k*<=≤<=200) — the number of the added characters.
Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.
[ "aaba\n2\n", "aaabbbb\n2\n", "abracadabra\n10\n" ]
[ "6\n", "6\n", "20\n" ]
A tandem repeat of length 2*n* is string *s*, where for any position *i* (1 ≤ *i* ≤ *n*) the following condition fulfills: *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*i* + *n*</sub>. In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.
[ { "input": "aaba\n2", "output": "6" }, { "input": "aaabbbb\n2", "output": "6" }, { "input": "abracadabra\n10", "output": "20" }, { "input": "zwvrx\n3", "output": "6" }, { "input": "ayi\n10", "output": "12" }, { "input": "eexlzphiay\n1", "output": "2" }, { "input": "zumtumtlitf\n2", "output": "6" }, { "input": "xbmrxbmrkzovhb\n3", "output": "8" }, { "input": "ijtvifbuajod\n5", "output": "10" }, { "input": "jhfwjyyzwrjiyrrgveiqkoltivghgkontrqragikttxxuwszjwqhwxindyrdqhucnbwgwrppgqmsasrzohezjlfmkzsqptwpratprcrxyxecnlsaiqrvimihmhjfgzwdtvmfhgbuonpsblphyoxzclkrwbwrkasahiirzqlfjdoomlosltldbpomyyhmdwfchzxnmwlh\n200", "output": "400" }, { "input": "kbxuunznjtxutlauuuipifggjjkequbpvbagmxojhgxtakxioxsmrmoatlyzwsygibhafspqnfbycyztxmtpirqcyhalluhhubne\n100", "output": "200" }, { "input": "lfydqwrwevvvclkkainwxwvqf\n33", "output": "58" }, { "input": "skllmtqzajnzjkuflkazjku\n10", "output": "20" }, { "input": "uqytussdzppiuwxterrfyrwtsrkdpfzhjpeuuulopnnjtltdtlkzwixouxteuheqaxhaicoeveggwkcnkamluxykyktmvafajfnxmeuuulopnnjtltdtlkzwixouxteuheqaxhaicoeveggwkcnkamluxykyktmvafajfnxmefkurbbcbesiwcauwmlhmfslcavsreea\n41", "output": "134" }, { "input": "kitxizqtbzwjqldmhwpmznaoddtgqzithwvyeyuixxhlnmksmsysikftzrskbnriebbwzermgcxalwpmznaoddtgqzithwvyeyuixxhlnmksmsy\n32", "output": "120" }, { "input": "auxrkguktewrcwwklhmuxkgdialidacmjinwcsrtfrtdsvqsbwuqtsrmsyizsvdkbqwrbuphqqvzktqkskylnnqbezibqnaytuuqddrigdkbqwrbuphqqvzktqkskylnnqbezi\n23", "output": "86" }, { "input": "ezlrqvaeekbnkqqjcijtkaoisqpbguqfsqxtzjotdhtrnaoxutybbqzzhrqvaeekbnkqqjcijtkaoisqpbguqfsqxtzjotdhtrnaoxutybbqzzhzoeptxwaunvarfcapxsnamwjyqpxbiegizqotuqen\n15", "output": "108" }, { "input": "ngkdgsdxouojadjqzgxewuuyxdlxulgrblxpkyzhgmkeatmhvbdelmxxrqtsarfvotcxfuiqsxbnczbadelhxtlfwrnbisayeveiejvycllhkictyyriqseznziyurlgiejvycllhkictyyriqseznziyurlgwiubyvqfmabhstqalicamyholkqlvtjfhcfbyr\n133", "output": "266" }, { "input": "nemtbujbscvkgxnbqboeohzfozihjvhcllfseiouggzojhqcoqrvtdsgkubiophnhahgplhtjxblicnavkayzsydmxphgfvhlllontqfpqitrpjiadpmogtqyjhqfpqitrpjiadpmogtqyjhvaopbzglvdmwzsrhtsszyengbihrrzljvofgugmjedgujhzvlebpprue\n140", "output": "280" }, { "input": "wqlvwkiiqfmesejedhyjjfgzqfmiqyaiqefzaywrdundcmbfvhdflrpvkitbltbrzedvozltptkaanbpmjvsdnpthcepfydrdlscexczxwzyatupzlxdhnezdsipeyjqmbvoavsgeuulkqkexpwpttvxeovcjrqnzdeiaatzglvwkiiqfmesejedhyjjfgzqfmiqyaiq\n141", "output": "334" }, { "input": "cxpleheyfwu\n132", "output": "142" }, { "input": "wccknxhbqzjwaseubvizxuisnzneatgjhaatrfydssgzufyztesrxnjlbhckybqlbncvqgjcoupirpqnnmacejicjzhattqolmclqnotctcsliyvjwutvrtrhichssehtlwbrq\n123", "output": "246" }, { "input": "eluswgbaoqmkfymoidkripnpgmbvhydcuupfhecefgosemhverqwzxklzzacdgcrrlzdnocxmzxtiamqpxspfogqhrlsnfzdexamrkowqpqggolnrvxfhenedmfzngnavgnjkzsnkjjjfcgfqjuywmrt\n115", "output": "230" }, { "input": "zonkpassuptcnpeoogztfpaspwdwnmiwsxeskfajlpfswzrdcxhlzxrgddtgmnngevbiybdnwelkzonhrzgldriyymrzduulifphxypcaqurgeqitkxxnsqdpsxattjoncmhihgxdaxixkmockynyjefvhrzgldriyymrzduulifphxypcaqurgeqitkxxnsqdpsxatt\n200", "output": "400" }, { "input": "cznjenwypyeulxzdxfhalfbyefhhgieybtzjmbdirrpybxnftpcqfhrhiifsfkllztwejdvhvtnxecnfgwwxhhcsjsqzhrjddauttbxphfzljgbvcqshateqeulxzdxfhalfbyefhhgieybtzjmbdirrpybxnftpcqfhrhiifsfkllztwejdvhvtnxecnfgwwxhhcsjs\n41", "output": "220" }, { "input": "jtifziirovbklaioslunwvtdavraandnzcwqbealbvqonoxufqrsewwrzvkrecrfqhdduwmcdcdhdtvpyshfhgdwdkmglskidhzayvouwhumzhcphocqyfcdddhzayvouwhumzhcphocqyfcddayfakoxofjgusuonehbxbokjsdlktqrcdurogxltsysyjbiagrvhky\n32", "output": "64" }, { "input": "thdnszfpaznmjlzacpovjcvybdkynhnvkaxvncfpofvnfpkggyfvqbklvrnbwpjswbrvjvqyzheslzxvuuqpbrvjvqyzheslzxvuuqprxasesuweenacripkyevplccdlxocfuqklypxactpajkmhcsgbxwgznizwndthualdbbgxhrtdrodoiddzdmxtatssfsuksqz\n23", "output": "46" }, { "input": "ifglyzxttgfpcgvpfmfmjhuzmgmaiivnbrzjevgxosclwqfewklzstkjmnjmqgpeshndmzrtthpjbhuqoldgvkkmkqinkptatpytrchkvjyeimsfmjhuzmgmaiivnbrzjevgxosclwqfewklzstkjmnjmqgpeshndmzrtthpjbhuqoldgvkkmkqinkptatpytrchkvjy\n15", "output": "186" }, { "input": "ktkkckrzvjhdspjmtljrmwgfoxeuadhajkfjpcmquqldlkutwyqaupnypwqfbxbuaaywcflplmqxnvwmkzpdvvkgxkmsggxmdangeyudqrgrihgbljrmwgfoxeuadhajkfjpcmquqldlkutwyqaupnypwqfbxbuaaywcflplmqxnvwmkzpdvvkgxkmsggxmdangeyudq\n57", "output": "190" }, { "input": "mklxokaoaxzccddmsxzc\n41", "output": "60" }, { "input": "pdgrwrozhkrwwgebwvuilwm\n32", "output": "54" }, { "input": "uzfvkgoaimitrlfjn\n43", "output": "60" }, { "input": "xaxgnvphqavbuxzkcsptsih\n150", "output": "172" }, { "input": "fonwebmlwaxthdwche\n57", "output": "74" } ]
78
3,584,000
0
22,200
0
none
[ "none" ]
null
null
Вася купил стол, у которого *n* ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2*n* частей возможно составить *n* ножек одинаковой длины. При составлении ножки любые две части могут быть соединены друг с другом. Изначально все ножки стола разобраны, а вам заданы длины 2*n* частей в произвольном порядке. Помогите Васе собрать все ножки стола так, чтобы все они были одинаковой длины, разбив заданные 2*n* части на пары правильным образом. Каждая ножка обязательно должна быть составлена ровно из двух частей, не разрешается использовать как ножку только одну часть.
В первой строке задано число *n* (1<=≤<=*n*<=≤<=1000) — количество ножек у стола, купленного Васей. Во второй строке следует последовательность из 2*n* целых положительных чисел *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=100<=000) — длины частей ножек стола в произвольном порядке.
Выведите *n* строк по два целых числа в каждой — длины частей ножек, которые надо соединить друг с другом. Гарантируется, что всегда возможно собрать *n* ножек одинаковой длины. Если ответов несколько, разрешается вывести любой из них.
[ "3\n1 3 2 4 5 3\n", "3\n1 1 1 2 2 2\n" ]
[ "1 5\n2 4\n3 3\n", "1 2\n2 1\n1 2\n" ]
none
[ { "input": "3\n1 3 2 4 5 3", "output": "1 5\n2 4\n3 3" }, { "input": "3\n1 1 1 2 2 2", "output": "1 2\n1 2\n1 2" }, { "input": "1\n3 7", "output": "3 7" }, { "input": "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15", "output": "2 18\n2 18\n2 18\n3 17\n4 16\n5 15\n5 15\n7 13\n7 13\n9 11" }, { "input": "10\n759 82 475 841 46 461 288 525 918 241 789 847 58 954 712 159 942 211 153 539", "output": "46 954\n58 942\n82 918\n153 847\n159 841\n211 789\n241 759\n288 712\n461 539\n475 525" }, { "input": "100\n8 7 7 5 2 7 7 5 1 8 6 3 6 7 2 4 4 2 6 8 5 6 5 2 6 1 3 9 5 8 7 6 5 4 8 6 5 5 3 2 6 5 4 9 7 1 5 7 9 5 7 4 1 6 5 8 2 6 6 1 4 2 3 2 3 9 3 8 7 1 2 4 5 7 3 5 5 6 3 8 3 6 1 5 5 3 3 3 8 8 1 4 3 6 7 1 1 2 4 4 7 3 7 7 8 9 5 8 6 6 4 7 4 9 3 4 7 5 2 8 4 1 9 7 9 7 9 6 7 7 9 6 1 1 1 9 9 4 4 1 5 6 6 3 9 3 3 7 4 2 4 9 6 3 7 5 5 2 9 7 5 4 8 3 1 8 6 3 5 9 9 3 6 8 1 3 7 7 4 4 4 3 8 1 9 3 3 3 3 7 2 4 7 7 1 2 9 3 2 2", "output": "1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1" }, { "input": "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15", "output": "2 18\n2 18\n2 18\n3 17\n4 16\n5 15\n5 15\n7 13\n7 13\n9 11" }, { "input": "10\n759 82 475 841 46 461 288 525 918 241 789 847 58 954 712 159 942 211 153 539", "output": "46 954\n58 942\n82 918\n153 847\n159 841\n211 789\n241 759\n288 712\n461 539\n475 525" }, { "input": "100\n8 7 7 5 2 7 7 5 1 8 6 3 6 7 2 4 4 2 6 8 5 6 5 2 6 1 3 9 5 8 7 6 5 4 8 6 5 5 3 2 6 5 4 9 7 1 5 7 9 5 7 4 1 6 5 8 2 6 6 1 4 2 3 2 3 9 3 8 7 1 2 4 5 7 3 5 5 6 3 8 3 6 1 5 5 3 3 3 8 8 1 4 3 6 7 1 1 2 4 4 7 3 7 7 8 9 5 8 6 6 4 7 4 9 3 4 7 5 2 8 4 1 9 7 9 7 9 6 7 7 9 6 1 1 1 9 9 4 4 1 5 6 6 3 9 3 3 7 4 2 4 9 6 3 7 5 5 2 9 7 5 4 8 3 1 8 6 3 5 9 9 3 6 8 1 3 7 7 4 4 4 3 8 1 9 3 3 3 3 7 2 4 7 7 1 2 9 3 2 2", "output": "1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5" }, { "input": "1\n7 7", "output": "7 7" } ]
62
4,608,000
0
22,207
733
Kostya the Sculptor
[ "data structures", "hashing" ]
null
null
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has *n* stones which are rectangular parallelepipeds. The edges sizes of the *i*-th of them are *a**i*, *b**i* and *c**i*. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=105). *n* lines follow, in the *i*-th of which there are three integers *a**i*,<=*b**i* and *c**i* (1<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=109) — the lengths of edges of the *i*-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.
In the first line print *k* (1<=≤<=*k*<=≤<=2) the number of stones which Zahar has chosen. In the second line print *k* distinct integers from 1 to *n* — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to *n* in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them.
[ "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4\n", "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7\n" ]
[ "1\n1\n", "2\n1 5\n" ]
In the first example we can connect the pairs of stones: - 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. - 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5 - 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5 Or take only one stone: - 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5 - 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 - 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5 - 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5 - 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 - 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone.
[ { "input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4", "output": "1\n1" }, { "input": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7", "output": "2\n1 5" }, { "input": "1\n1 1 1", "output": "1\n1" }, { "input": "2\n2 3 1\n2 2 3", "output": "2\n2 1" }, { "input": "1\n1000000000 1000000000 1000000000", "output": "1\n1" }, { "input": "3\n100 100 100\n25 63 11\n63 15 11", "output": "1\n1" }, { "input": "2\n999999999 1000000000 1000000000\n1000000000 1000000000 1000000000", "output": "2\n2 1" }, { "input": "3\n1 1 2\n1 2 2\n1 1 1", "output": "1\n1" }, { "input": "3\n500 1000 1000\n1000 499 1000\n999 999 999", "output": "2\n1 2" }, { "input": "3\n500 1000 1000\n1000 499 1000\n1000 1001 1001", "output": "1\n3" }, { "input": "9\n1 3 2\n3 3 1\n3 1 2\n3 3 2\n2 2 2\n3 2 1\n3 3 1\n3 3 1\n2 1 2", "output": "2\n4 8" }, { "input": "3\n20 30 5\n20 30 6\n10 10 10", "output": "2\n2 1" }, { "input": "3\n5 20 30\n6 20 30\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 5 30\n20 6 30\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 30 5\n30 20 6\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 30 5\n6 20 30\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 30 5\n6 30 20\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 30 5\n20 6 30\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 30 5\n30 6 20\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 5 30\n20 30 6\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 5 30\n30 20 6\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 5 30\n6 20 30\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 5 30\n6 30 20\n10 10 10", "output": "2\n2 1" }, { "input": "3\n20 5 30\n30 6 20\n10 10 10", "output": "2\n2 1" }, { "input": "3\n5 20 30\n20 30 6\n10 10 10", "output": "2\n2 1" }, { "input": "3\n5 20 30\n30 20 6\n10 10 10", "output": "2\n2 1" }, { "input": "3\n5 20 30\n6 30 20\n10 10 10", "output": "2\n2 1" }, { "input": "3\n5 20 30\n20 6 30\n10 10 10", "output": "2\n2 1" }, { "input": "3\n5 20 30\n30 6 20\n10 10 10", "output": "2\n2 1" } ]
124
0
0
22,229
899
Letters Removing
[ "data structures", "strings" ]
null
null
Petya has a string of length *n* consisting of small and large English letters and digits. He performs *m* operations. Each operation is described with two integers *l* and *r* and a character *c*: Petya removes from the string all characters *c* on positions between *l* and *r*, inclusive. It's obvious that the length of the string remains the same or decreases after each operation. Find how the string will look like after Petya performs all *m* operations.
The first string contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the length of the string and the number of operations. The second line contains the string of length *n*, consisting of small and large English letters and digits. Positions in the string are enumerated from 1. Each of the next *m* lines contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*), followed by a character *c*, which is a small or large English letter or a digit. This line describes one operation. It is guaranteed that *r* doesn't exceed the length of the string *s* before current operation.
Print the string Petya will obtain after performing all *m* operations. If the strings becomes empty after all operations, print an empty line.
[ "4 2\nabac\n1 3 a\n2 2 c\n", "3 2\nA0z\n1 3 0\n1 1 z\n", "10 4\nagtFrgF4aF\n2 5 g\n4 9 F\n1 5 4\n1 7 a\n", "9 5\naAAaBBccD\n1 4 a\n5 6 c\n2 3 B\n4 4 D\n2 3 A\n" ]
[ "b\n", "Az\n", "tFrg4\n", "AB\n" ]
In the first example during the first operation both letters 'a' are removed, so the string becomes "bc". During the second operation the letter 'c' (on the second position) is removed, and the string becomes "b". In the second example during the first operation Petya removes '0' from the second position. After that the string becomes "Az". During the second operations the string doesn't change.
[ { "input": "4 2\nabac\n1 3 a\n2 2 c", "output": "b" }, { "input": "3 2\nA0z\n1 3 0\n1 1 z", "output": "Az" }, { "input": "10 4\nagtFrgF4aF\n2 5 g\n4 9 F\n1 5 4\n1 7 a", "output": "tFrg4" }, { "input": "9 5\naAAaBBccD\n1 4 a\n5 6 c\n2 3 B\n4 4 D\n2 3 A", "output": "AB" }, { "input": "10 10\nhRZQK137KY\n1 10 V\n8 10 g\n2 6 E\n2 2 y\n6 8 J\n1 5 w\n4 6 q\n6 8 K\n2 10 c\n4 6 t", "output": "hRZQK137KY" }, { "input": "20 4\n8QYQY1tp6CA02NGnR04s\n1 9 N\n1 10 y\n5 11 t\n6 7 C", "output": "8QYQY1p6CA02NGnR04s" }, { "input": "30 5\nkR87ctl81OsbekSKwUATCwSPKssjio\n16 25 0\n16 19 W\n6 12 K\n4 23 k\n28 29 z", "output": "kR87ctl81OsbeSKwUATCwSPKssjio" }, { "input": "40 24\nYYUcKDEUVLUCU8EKiUVxnD8TZSSidW8TUDS8Sccb\n3 38 K\n24 33 e\n6 36 d\n5 10 d\n13 14 E\n12 23 S\n4 30 U\n4 11 C\n12 15 Y\n5 27 x\n25 28 W\n25 26 E\n15 26 C\n17 22 d\n6 25 n\n19 22 K\n2 26 T\n1 22 W\n7 19 d\n12 18 K\n4 12 L\n9 18 8\n4 8 i\n6 8 L", "output": "YYUcDEV8iVDZSiDS8Sccb" }, { "input": "50 6\nRQQQQQQRRRRQQQQQRRQQRQRRRRRQRQQQRQQQRRRQQQQQRRQRRR\n18 26 R\n13 33 R\n23 32 R\n7 21 Q\n18 21 R\n14 20 R", "output": "RQQQQQRRRRQQQQQQQQQQQRRR" }, { "input": "1 1\na\n1 1 A", "output": "a" } ]
2,000
7,680,000
0
22,298
438
The Child and Binary Tree
[ "combinatorics", "divide and conquer", "fft", "number theory" ]
null
null
Our child likes computer science very much, especially he likes binary trees. Consider the sequence of *n* distinct positive integers: *c*1,<=*c*2,<=...,<=*c**n*. The child calls a vertex-weighted rooted binary tree good if and only if for every vertex *v*, the weight of *v* is in the set {*c*1,<=*c*2,<=...,<=*c**n*}. Also our child thinks that the weight of a vertex-weighted tree is the sum of all vertices' weights. Given an integer *m*, can you for all *s* (1<=≤<=*s*<=≤<=*m*) calculate the number of good vertex-weighted rooted binary trees with weight *s*? Please, check the samples for better understanding what trees are considered different. We only want to know the answer modulo 998244353 (7<=×<=17<=×<=223<=+<=1, a prime number).
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=105). The second line contains *n* space-separated pairwise distinct integers *c*1,<=*c*2,<=...,<=*c**n*. (1<=≤<=*c**i*<=≤<=105).
Print *m* lines, each line containing a single integer. The *i*-th line must contain the number of good vertex-weighted rooted binary trees whose weight exactly equal to *i*. Print the answers modulo 998244353 (7<=×<=17<=×<=223<=+<=1, a prime number).
[ "2 3\n1 2\n", "3 10\n9 4 3\n", "5 10\n13 10 6 4 15\n" ]
[ "1\n3\n9\n", "0\n0\n1\n1\n0\n2\n4\n2\n6\n15\n", "0\n0\n0\n1\n0\n1\n0\n2\n0\n5\n" ]
In the first example, there are 9 good vertex-weighted rooted binary trees whose weight exactly equal to 3:
[ { "input": "2 3\n1 2", "output": "1\n3\n9" }, { "input": "3 10\n9 4 3", "output": "0\n0\n1\n1\n0\n2\n4\n2\n6\n15" }, { "input": "5 10\n13 10 6 4 15", "output": "0\n0\n0\n1\n0\n1\n0\n2\n0\n5" }, { "input": "1 1\n1", "output": "1" }, { "input": "10 100\n9 95 37 56 39 86 59 5 68 82", "output": "0\n0\n0\n0\n1\n0\n0\n0\n1\n2\n0\n0\n0\n4\n5\n0\n0\n2\n15\n14\n0\n0\n15\n56\n42\n0\n5\n84\n210\n132\n0\n56\n420\n792\n429\n14\n421\n1980\n3004\n1430\n210\n2644\n9009\n11444\n4904\n1984\n15030\n40044\n43773\n17588\n15045\n80136\n175062\n168148\n67810\n100269\n408633\n755988\n649860\n288260\n613456\n2016480\n3234499\n2537036\n1356776\n3531191\n9703953\n13744197\n10069966\n6914982\n19418294\n45783430\n58139494\n40988753\n36899400\n103054154\n212601980\n245473785\n172686018\n200348214\n531589308\n974661171\n395..." }, { "input": "10 100\n7 9 8 6 4 10 1 3 5 2", "output": "1\n3\n10\n36\n137\n543\n2219\n9285\n39587\n171369\n751235\n3328213\n14878431\n67030671\n304035629\n389000654\n373565922\n374004841\n937273532\n481697230\n551368610\n910478728\n958312416\n701222863\n59457828\n15667389\n851972333\n275200719\n441733123\n933122398\n252086378\n548721462\n649821765\n978595366\n919065150\n84631201\n983222527\n188186137\n417226685\n209663310\n938867102\n810054216\n477456389\n669104250\n548955965\n215582746\n955153897\n234809522\n690925876\n485727663\n558641719\n80347309\n9160779\n..." }, { "input": "50 1000\n10 93 11 34 85 17 61 87 58 38 56 83 55 52 70 18 47 82 36 67 53 98 81 41 23 39 13 99 64 16 91 48 22 12 92 78 86 1 65 46 21 57 7 72 31 71 90 68 35 45", "output": "1\n2\n5\n14\n42\n132\n430\n1434\n4877\n16853\n59001\n208824\n745979\n2686167\n9739691\n35529776\n130307310\n480195871\n778911984\n613007631\n657360844\n223557326\n922868393\n993248720\n952499660\n379981268\n129473772\n412174319\n478699077\n796231438\n577702709\n333606742\n326848917\n812203947\n39587572\n861530705\n823608262\n401882936\n656674446\n768073059\n234821436\n876968326\n644872405\n349227486\n996818415\n166227790\n454763626\n251721140\n929096939\n323902204\n128294369\n633739817\n940393486\n91333989..." }, { "input": "100 1000\n302 622 511 670 245 116 998 898 633 422 108 692 159 997 570 634 720 835 769 712 199 632 763 51 578 392 565 559 86 642 800 498 577 875 598 733 480 101 370 120 240 941 500 815 946 522 115 229 196 448 793 954 54 777 639 554 372 236 289 821 465 421 232 765 241 744 18 834 280 203 889 514 350 897 249 230 555 858 250 935 840 467 169 193 680 294 883 265 606 864 487 861 112 354 746 306 947 890 588 207", "output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n2\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n6\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n4\n0\n0\n18\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n15\n0\n0\n57\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n2\n0\n4\n60\n0\n0\n191\n0\n0\n0\n1\n0\n0\n1\n1\n0\n0\n4\n16\n0\n15\n240\n0\n0\n658\n0\n0\n0\n4\n0\n0\n4\n4\n0\n0\n19\n88\n0\n60\n960\n0\n0\n2321\n0\n0\n0\n15\n0\n0\n15\n19\n5\n0\n90\n450\n0\n240\n3863\n0\n..." }, { "input": "1 100\n78", "output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "10 1\n356 750 223 920 213 91 293 166 563 87", "output": "0" }, { "input": "10 65536\n535 44 550 941 479 704 183 616 781 869", "output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n2\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n5\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0..." }, { "input": "1 10\n3589", "output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "1 1\n2", "output": "0" } ]
0
0
-1
22,313
939
Maximize!
[ "binary search", "greedy", "ternary search", "two pointers" ]
null
null
You are given a multiset *S* consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to *S*, the newly added integer is not less than any number in it. 1. Find a subset *s* of the set *S* such that the value is maximum possible. Here *max*(*s*) means maximum value of elements in *s*,  — the average value of numbers in *s*. Output this maximum possible value of .
The first line contains a single integer *Q* (1<=≤<=*Q*<=≤<=5·105) — the number of queries. Each of the next *Q* lines contains a description of query. For queries of type 1 two integers 1 and *x* are given, where *x* (1<=≤<=*x*<=≤<=109) is a number that you should add to *S*. It's guaranteed that *x* is not less than any number in *S*. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. *S* is not empty when a query of type 2 comes.
Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10<=-<=6. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
[ "6\n1 3\n2\n1 4\n2\n1 8\n2\n", "4\n1 1\n1 4\n1 5\n2\n" ]
[ "0.0000000000\n0.5000000000\n3.0000000000\n", "2.0000000000\n" ]
none
[ { "input": "6\n1 3\n2\n1 4\n2\n1 8\n2", "output": "0.0000000000\n0.5000000000\n3.0000000000" }, { "input": "4\n1 1\n1 4\n1 5\n2", "output": "2.0000000000" }, { "input": "8\n1 7\n1 26\n1 40\n1 45\n1 64\n2\n1 88\n1 94", "output": "31.6666666667" }, { "input": "9\n1 35\n2\n2\n1 45\n1 58\n2\n2\n2\n1 100", "output": "0.0000000000\n0.0000000000\n12.0000000000\n12.0000000000\n12.0000000000" }, { "input": "15\n1 300022520\n1 542407315\n2\n2\n2\n1 622764928\n1 706078395\n1 715915848\n1 933742920\n1 942115408\n2\n2\n2\n2\n2", "output": "121192397.5000000000\n121192397.5000000000\n121192397.5000000000\n347266993.6666666900\n347266993.6666666900\n347266993.6666666900\n347266993.6666666900\n347266993.6666666900" }, { "input": "25\n1 134292126\n2\n1 218916741\n1 237556189\n2\n1 259193070\n2\n2\n1 397804479\n1 430795002\n2\n1 483338629\n1 626042215\n2\n1 658608263\n1 715368294\n2\n2\n2\n2\n1 833121838\n2\n1 863192433\n2\n1 966351027", "output": "0.0000000000\n51632031.5000000000\n62450472.0000000000\n62450472.0000000000\n175404987.5000000000\n330842146.8000000100\n402303010.0000000000\n402303010.0000000000\n402303010.0000000000\n402303010.0000000000\n496505845.1999999900\n520562321.1999999900" }, { "input": "88\n1 1411\n2\n1 1783\n1 2132\n2\n2\n1 2799\n2\n2\n1 7856\n1 10551\n2\n2\n1 10868\n1 15159\n1 16497\n2\n1 20266\n2\n2\n2\n1 21665\n2\n2\n2\n2\n1 25670\n2\n2\n2\n1 26767\n1 31392\n2\n2\n2\n1 35319\n1 38575\n1 40111\n2\n1 41305\n1 49444\n1 53013\n2\n2\n1 53117\n2\n2\n1 55113\n2\n2\n2\n2\n2\n2\n1 55270\n1 55395\n1 57534\n2\n1 59699\n2\n2\n2\n2\n2\n1 63483\n1 68129\n2\n2\n2\n2\n2\n1 77893\n2\n2\n2\n2\n2\n1 78505\n1 79944\n1 84716\n1 85845\n2\n2\n1 87122\n1 87614\n1 88419\n1 98018\n2", "output": "0.0000000000\n360.5000000000\n360.5000000000\n801.3333333333\n801.3333333333\n6815.8000000000\n6815.8000000000\n11572.6000000000\n14587.8000000000\n14587.8000000000\n14587.8000000000\n15707.0000000000\n15707.0000000000\n15707.0000000000\n15707.0000000000\n18911.0000000000\n18911.0000000000\n18911.0000000000\n23496.5000000000\n23496.5000000000\n23496.5000000000\n30762.3333333333\n41711.3750000000\n41711.3750000000\n41802.3750000000\n41802.3750000000\n43548.8750000000\n43548.8750000000\n43548.8750000000\n435..." } ]
77
102,400
0
22,323
958
Hyperspace Jump (hard)
[]
null
null
It is now 125 years later, but humanity is still on the run from a humanoid-cyborg race determined to destroy it. Or perhaps we are getting some stories mixed up here... In any case, the fleet is now smaller. However, in a recent upgrade, all the navigation systems have been outfitted with higher-dimensional, linear-algebraic jump processors. Now, in order to make a jump, a ship's captain needs to specify a subspace of the *d*-dimensional space in which the events are taking place. She does so by providing a generating set of vectors for that subspace. Princess Heidi has received such a set from the captain of each of *m* ships. Again, she would like to group up those ships whose hyperspace jump subspaces are equal. To do so, she wants to assign a group number between 1 and *m* to each of the ships, so that two ships have the same group number if and only if their corresponding subspaces are equal (even though they might be given using different sets of vectors). Help Heidi!
The first line of the input contains two space-separated integers *m* and *d* (2<=≤<=*m*<=≤<=30<=000, 1<=≤<=*d*<=≤<=5) – the number of ships and the dimension of the full underlying vector space, respectively. Next, the *m* subspaces are described, one after another. The *i*-th subspace, which corresponds to the *i*-th ship, is described as follows: The first line contains one integer *k**i* (1<=≤<=*k**i*<=≤<=*d*). Then *k**i* lines follow, the *j*-th of them describing the *j*-th vector sent by the *i*-th ship. Each of the *j* lines consists of *d* space-separated integers *a**j*, *j*<==<=1,<=...,<=*d*, that describe the vector ; it holds that |*a**j*|<=≤<=250. The *i*-th subspace is the linear span of these *k**i* vectors.
Output *m* space-separated integers *g*1,<=...,<=*g**m*, where denotes the group number assigned to the *i*-th ship. That is, for any 1<=≤<=*i*<=&lt;<=*j*<=≤<=*m*, the following should hold: *g**i*<==<=*g**j* if and only if the *i*-th and the *j*-th subspaces are equal. In addition, the sequence (*g*1,<=*g*2,<=...,<=*g**m*) should be lexicographically minimal among all sequences with that property.
[ "8 2\n1\n5 0\n1\n0 1\n1\n0 1\n2\n0 6\n0 1\n2\n0 1\n1 0\n2\n-5 -5\n4 3\n2\n1 1\n0 1\n2\n1 0\n1 0\n" ]
[ "1 2 2 2 3 3 3 1 " ]
In the sample testcase, the first and the last subspace are equal, subspaces 2 to 4 are equal, and subspaces 5 to 7 are equal. Recall that two subspaces, one given as the span of vectors <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8dc56705315ce4b334dd46dbc9c8c51fffb0036.png" style="max-width: 100.0%;max-height: 100.0%;"/> and another given as the span of vectors <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99fd3b5233ff3b6f4989df43e2f60edb184bee11.png" style="max-width: 100.0%;max-height: 100.0%;"/>, are equal if each vector *v*<sub class="lower-index">*i*</sub> can be written as a linear combination of vectors *w*<sub class="lower-index">1</sub>, ..., *w*<sub class="lower-index">*k*</sub> (that is, there exist coefficients <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ae69b90a53c26d24b0b4a40a6970f6d5903cd568.png" style="max-width: 100.0%;max-height: 100.0%;"/> such that *v*<sub class="lower-index">*i*</sub> = α<sub class="lower-index">1</sub>*w*<sub class="lower-index">1</sub> + ... + α<sub class="lower-index">*k*</sub>*w*<sub class="lower-index">*k*</sub>) and, similarly, each vector *w*<sub class="lower-index">*i*</sub> can be written as a linear combination of vectors *v*<sub class="lower-index">1</sub>, ..., *v*<sub class="lower-index">*n*</sub>. Recall that a sequence (*g*<sub class="lower-index">1</sub>, *g*<sub class="lower-index">2</sub>, ..., *g*<sub class="lower-index">*m*</sub>) is lexicographically smaller than a sequence (*h*<sub class="lower-index">1</sub>, *h*<sub class="lower-index">2</sub>, ..., *h*<sub class="lower-index">*m*</sub>) if there exists an index *i*, 1 ≤ *i* ≤ *m*, such that *g*<sub class="lower-index">*i*</sub> &lt; *h*<sub class="lower-index">*i*</sub> and *g*<sub class="lower-index">*j*</sub> = *h*<sub class="lower-index">*j*</sub> for all *j* &lt; *i*.
[]
3,000
39,833,600
0
22,350
186
Growing Mushrooms
[ "greedy", "sortings" ]
null
null
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch. Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts *t*1 seconds and the second part lasts *t*2 seconds. The first and the second part are separated by a little break. After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of *v**i* meters per second. After *t*1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by *k* percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of *u**i* meters per second. After a *t*2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary. Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds *a**i* and *b**i*, then there are two strategies: he either uses speed *a**i* before the break and speed *b**i* after it, or vice versa. Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results. The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly. Each of the following *n* lines contains two integers. The *i*-th (1<=≤<=*i*<=≤<=*n*) line contains space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the speeds which the participant number *i* chose.
Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
[ "2 3 3 50\n2 4\n4 2\n", "4 1 1 1\n544 397\n280 101\n280 101\n693 970\n" ]
[ "1 15.00\n2 15.00\n", "4 1656.07\n1 937.03\n2 379.99\n3 379.99\n" ]
- First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 &gt; 4·3·0.5 + 2·3.
[ { "input": "2 3 3 50\n2 4\n4 2", "output": "1 15.00\n2 15.00" }, { "input": "4 1 1 1\n544 397\n280 101\n280 101\n693 970", "output": "4 1656.07\n1 937.03\n2 379.99\n3 379.99" }, { "input": "10 1 1 25\n981 1\n352 276\n164 691\n203 853\n599 97\n901 688\n934 579\n910 959\n317 624\n440 737", "output": "8 1641.50\n6 1417.00\n7 1368.25\n10 1067.00\n4 1005.25\n1 981.75\n9 861.75\n3 814.00\n5 671.75\n2 559.00" }, { "input": "10 6 1 48\n239 632\n976 315\n797 112\n1 835\n938 862\n531 884\n422 607\n152 331\n413 677\n622 978", "output": "5 3788.56\n10 3673.36\n2 3360.12\n6 3289.08\n4 2606.20\n3 2598.64\n9 2525.24\n7 2315.84\n1 2210.84\n8 1184.72" }, { "input": "8 1 4 55\n507 82\n681 492\n602 849\n367 557\n438 320\n798 699\n338 302\n391 814", "output": "3 3666.90\n6 3506.55\n8 3431.95\n2 2945.40\n4 2393.15\n1 2064.90\n5 1896.00\n7 1487.90" }, { "input": "9 6 4 80\n95 269\n95 269\n781 724\n22 269\n173 655\n972 850\n22 269\n95 269\n642 666", "output": "6 4908.00\n3 3992.80\n9 3434.40\n5 2827.60\n1 1190.00\n2 1190.00\n8 1190.00\n4 1102.40\n7 1102.40" }, { "input": "7 1 8 25\n98 713\n876 112\n990 771\n57 395\n171 899\n86 600\n459 320", "output": "3 8498.25\n5 7320.25\n2 7092.00\n1 5777.50\n6 4864.50\n7 3912.00\n4 3202.75" }, { "input": "6 1 5 9\n105 771\n105 771\n105 771\n557 985\n105 771\n105 771", "output": "4 5431.87\n1 3950.55\n2 3950.55\n3 3950.55\n5 3950.55\n6 3950.55" }, { "input": "6 2 2 78\n942 465\n593 600\n480 359\n733 648\n995 55\n526 538", "output": "1 2088.60\n5 2014.20\n4 1751.12\n2 1460.92\n6 1307.44\n3 1117.96" }, { "input": "2 1 1 1\n2 2\n2 2", "output": "1 3.98\n2 3.98" }, { "input": "2 1 1 100\n3 4\n4 3", "output": "1 4.00\n2 4.00" }, { "input": "1 1 1 1\n1 1", "output": "1 1.99" } ]
62
0
0
22,353
0
none
[ "none" ]
null
null
Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams! Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each of them could drink a bottle of... fresh cow milk. Having entered the cafe, the *m* friends found *n* different kinds of milk on the menu, that's why they ordered *n* bottles — one bottle of each kind. We know that the volume of milk in each bottle equals *w*. When the bottles were brought in, they decided to pour all the milk evenly among the *m* cups, so that each got a cup. As a punishment for not passing the test Igor was appointed the person to pour the milk. He protested that he was afraid to mix something up and suggested to distribute the drink so that the milk from each bottle was in no more than two different cups. His friends agreed but they suddenly faced the following problem — and what is actually the way to do it? Help them and write the program that will help to distribute the milk among the cups and drink it as quickly as possible! Note that due to Igor K.'s perfectly accurate eye and unswerving hands, he can pour any fractional amount of milk from any bottle to any cup.
The only input data file contains three integers *n*, *w* and *m* (1<=≤<=*n*<=≤<=50, 100<=≤<=*w*<=≤<=1000, 2<=≤<=*m*<=≤<=50), where *n* stands for the number of ordered bottles, *w* stands for the volume of each of them and *m* stands for the number of friends in the company.
Print on the first line "YES" if it is possible to pour the milk so that the milk from each bottle was in no more than two different cups. If there's no solution, print "NO". If there is a solution, then print *m* more lines, where the *i*-th of them describes the content of the *i*-th student's cup. The line should consist of one or more pairs that would look like "*b* *v*". Each such pair means that *v* (*v*<=&gt;<=0) units of milk were poured into the *i*-th cup from bottle *b* (1<=≤<=*b*<=≤<=*n*). All numbers *b* on each line should be different. If there are several variants to solve the problem, print any of them. Print the real numbers with no less than 6 digits after the decimal point.
[ "2 500 3\n", "4 100 5\n", "4 100 7\n", "5 500 2\n" ]
[ "YES\n1 333.333333\n2 333.333333\n2 166.666667 1 166.666667\n", "YES\n3 20.000000 4 60.000000\n1 80.000000\n4 40.000000 2 40.000000\n3 80.000000\n2 60.000000 1 20.000000\n", "NO\n", "YES\n4 250.000000 5 500.000000 2 500.000000\n3 500.000000 1 500.000000 4 250.000000\n" ]
none
[ { "input": "2 500 3", "output": "YES\n1 333.333333\n2 333.333333\n2 166.666667 1 166.666667" }, { "input": "4 100 5", "output": "YES\n3 20.000000 4 60.000000\n1 80.000000\n4 40.000000 2 40.000000\n3 80.000000\n2 60.000000 1 20.000000" }, { "input": "4 100 7", "output": "NO" }, { "input": "5 500 2", "output": "YES\n4 250.000000 5 500.000000 2 500.000000\n3 500.000000 1 500.000000 4 250.000000" }, { "input": "4 100 8", "output": "YES\n3 50.000000\n1 50.000000\n2 50.000000\n4 50.000000\n1 50.000000\n3 50.000000\n2 50.000000\n4 50.000000" }, { "input": "1 1000 2", "output": "YES\n1 500.000000\n1 500.000000" }, { "input": "2 500 4", "output": "YES\n2 250.000000\n2 250.000000\n1 250.000000\n1 250.000000" }, { "input": "2 500 5", "output": "NO" }, { "input": "9 1000 12", "output": "YES\n3 750.000000\n6 750.000000\n7 250.000000 2 500.000000\n5 750.000000\n9 250.000000 2 500.000000\n4 500.000000 8 250.000000\n6 250.000000 1 500.000000\n4 500.000000 5 250.000000\n7 750.000000\n8 750.000000\n1 500.000000 3 250.000000\n9 750.000000" }, { "input": "20 1000 30", "output": "YES\n5 666.666667\n18 666.666667\n19 666.666667\n9 333.333333 18 333.333333\n14 666.666667\n1 666.666667\n20 333.333333 8 333.333333\n2 666.666667\n1 333.333333 12 333.333333\n12 666.666667\n8 666.666667\n16 666.666667\n16 333.333333 5 333.333333\n10 666.666667\n20 666.666667\n4 666.666667\n9 666.666667\n4 333.333333 7 333.333333\n13 333.333333 2 333.333333\n15 333.333333 14 333.333333\n6 666.666667\n19 333.333333 6 333.333333\n7 666.666667\n3 666.666667\n11 333.333333 17 333.333333\n15 666.666667\n10 333...." }, { "input": "50 1000 50", "output": "YES\n50 1000.000000\n46 1000.000000\n15 1000.000000\n32 1000.000000\n11 1000.000000\n24 1000.000000\n12 1000.000000\n16 1000.000000\n1 1000.000000\n36 1000.000000\n40 1000.000000\n25 1000.000000\n2 1000.000000\n44 1000.000000\n33 1000.000000\n31 1000.000000\n38 1000.000000\n47 1000.000000\n30 1000.000000\n34 1000.000000\n19 1000.000000\n5 1000.000000\n4 1000.000000\n42 1000.000000\n49 1000.000000\n35 1000.000000\n27 1000.000000\n43 1000.000000\n22 1000.000000\n8 1000.000000\n28 1000.000000\n37 1000.000000\n..." }, { "input": "50 1000 49", "output": "YES\n1 81.632653 50 938.775510\n46 816.326531 19 204.081633\n15 142.857143 14 877.551020\n32 857.142857 30 163.265306\n11 306.122449 40 714.285714\n24 714.285714 34 306.122449\n6 571.428571 12 448.979592\n29 938.775510 16 81.632653\n28 102.040816 1 918.367347\n36 326.530612 11 693.877551\n26 734.693878 40 285.714286\n25 102.040816 16 918.367347\n10 40.816327 2 979.591837\n44 224.489796 17 795.918367\n33 755.102041 41 265.306122\n8 510.204082 31 510.204082\n15 857.142857 38 163.265306\n33 244.897959 47 775...." }, { "input": "49 1000 50", "output": "YES\n40 280.000000 11 700.000000\n19 220.000000 47 760.000000\n13 20.000000 2 960.000000\n30 180.000000 46 800.000000\n15 860.000000 14 120.000000\n35 480.000000 31 500.000000\n17 200.000000 44 780.000000\n30 820.000000 32 160.000000\n3 380.000000 5 600.000000\n3 620.000000 22 360.000000\n12 440.000000 7 540.000000\n40 720.000000 26 260.000000\n10 940.000000 2 40.000000\n1 100.000000 28 880.000000\n23 460.000000 35 520.000000\n32 840.000000 37 140.000000\n16 80.000000 25 900.000000\n20 40.000000 29 940.000..." }, { "input": "40 1000 50", "output": "YES\n12 800.000000\n34 800.000000\n35 800.000000\n26 200.000000 4 600.000000\n16 600.000000 30 200.000000\n12 200.000000 7 600.000000\n20 400.000000 23 400.000000\n24 400.000000 39 400.000000\n27 200.000000 38 600.000000\n40 800.000000\n1 200.000000 28 600.000000\n18 200.000000 21 600.000000\n25 800.000000\n31 800.000000\n2 600.000000 13 200.000000\n18 800.000000\n10 400.000000 2 400.000000\n14 600.000000 17 200.000000\n9 200.000000 20 600.000000\n27 800.000000\n15 200.000000 36 600.000000\n36 400.000000 1..." }, { "input": "48 1000 50", "output": "YES\n20 40.000000 29 920.000000\n24 400.000000 41 560.000000\n6 200.000000 5 760.000000\n42 720.000000 21 240.000000\n40 480.000000 26 480.000000\n44 600.000000 17 360.000000\n3 280.000000 22 680.000000\n1 800.000000 45 160.000000\n41 440.000000 33 520.000000\n25 160.000000 14 800.000000\n7 120.000000 12 840.000000\n34 360.000000 24 600.000000\n22 320.000000 43 640.000000\n23 80.000000 48 880.000000\n31 40.000000 8 920.000000\n31 960.000000\n23 920.000000 35 40.000000\n45 840.000000 10 120.000000\n30 640.0..." }, { "input": "45 1000 50", "output": "YES\n15 700.000000 14 200.000000\n14 800.000000 25 100.000000\n12 900.000000\n32 200.000000 37 700.000000\n40 900.000000\n5 700.000000 6 200.000000\n8 200.000000 31 700.000000\n13 100.000000 2 800.000000\n1 500.000000 28 400.000000\n41 500.000000 24 400.000000\n42 900.000000\n2 200.000000 10 700.000000\n5 300.000000 3 600.000000\n34 300.000000 24 600.000000\n42 100.000000 27 800.000000\n44 700.000000 4 200.000000\n9 300.000000 20 600.000000\n23 500.000000 20 400.000000\n12 100.000000 6 800.000000\n16 900.0..." }, { "input": "30 1000 40", "output": "YES\n7 250.000000 8 500.000000\n11 250.000000 23 500.000000\n14 500.000000 15 250.000000\n18 500.000000 9 250.000000\n27 500.000000 17 250.000000\n13 750.000000\n7 750.000000\n3 750.000000\n17 750.000000\n3 250.000000 8 500.000000\n6 500.000000 12 250.000000\n24 750.000000\n21 750.000000\n29 750.000000\n10 750.000000\n1 500.000000 25 250.000000\n28 250.000000 1 500.000000\n27 500.000000 4 250.000000\n19 500.000000 29 250.000000\n19 500.000000 16 250.000000\n4 750.000000\n20 250.000000 23 500.000000\n5 750...." }, { "input": "20 1000 25", "output": "YES\n16 400.000000 19 400.000000\n13 800.000000\n15 800.000000\n9 600.000000 18 200.000000\n7 800.000000\n12 600.000000 1 200.000000\n5 800.000000\n2 400.000000 10 400.000000\n12 400.000000 8 400.000000\n8 600.000000 20 200.000000\n20 800.000000\n6 800.000000\n6 200.000000 19 600.000000\n10 600.000000 3 200.000000\n16 600.000000 5 200.000000\n3 800.000000\n4 600.000000 7 200.000000\n11 600.000000 17 200.000000\n13 200.000000 2 600.000000\n17 800.000000\n14 400.000000 11 400.000000\n15 200.000000 14 600.000..." }, { "input": "21 1000 27", "output": "NO" }, { "input": "21 1000 28", "output": "YES\n2 500.000000 10 250.000000\n16 250.000000 19 500.000000\n4 750.000000\n17 750.000000\n1 500.000000 3 250.000000\n15 750.000000\n7 500.000000 4 250.000000\n5 250.000000 20 500.000000\n21 750.000000\n12 750.000000\n13 750.000000\n5 750.000000\n3 750.000000\n6 750.000000\n16 750.000000\n7 500.000000 17 250.000000\n8 750.000000\n15 250.000000 14 500.000000\n19 500.000000 6 250.000000\n21 250.000000 18 500.000000\n18 500.000000 9 250.000000\n9 750.000000\n1 500.000000 12 250.000000\n10 750.000000\n8 250.00..." }, { "input": "21 1000 29", "output": "NO" }, { "input": "22 1000 30", "output": "NO" }, { "input": "3 356 14", "output": "NO" }, { "input": "9 120 13", "output": "NO" }, { "input": "1 301 20", "output": "NO" }, { "input": "11 489 14", "output": "NO" }, { "input": "6 218 16", "output": "NO" }, { "input": "2 632 19", "output": "NO" }, { "input": "14 157 19", "output": "NO" }, { "input": "12 430 14", "output": "YES\n9 122.857143 7 245.714286\n1 122.857143 3 245.714286\n9 307.142857 6 61.428571\n4 307.142857 8 61.428571\n10 245.714286 2 122.857143\n1 307.142857 12 61.428571\n4 122.857143 5 245.714286\n7 184.285714 5 184.285714\n10 184.285714 3 184.285714\n8 368.571429\n12 368.571429\n11 368.571429\n2 307.142857 11 61.428571\n6 368.571429" }, { "input": "16 980 19", "output": "NO" }, { "input": "1 736 10", "output": "NO" }, { "input": "4 650 19", "output": "NO" }, { "input": "3 953 13", "output": "NO" }, { "input": "10 524 8", "output": "YES\n4 262.000000 5 393.000000\n8 131.000000 6 524.000000\n10 262.000000 3 393.000000\n7 524.000000 5 131.000000\n3 131.000000 1 524.000000\n2 131.000000 9 524.000000\n10 262.000000 2 393.000000\n8 393.000000 4 262.000000" }, { "input": "6 283 11", "output": "NO" }, { "input": "5 825 16", "output": "NO" }, { "input": "13 557 13", "output": "YES\n5 557.000000\n7 557.000000\n6 557.000000\n4 557.000000\n3 557.000000\n1 557.000000\n10 557.000000\n9 557.000000\n8 557.000000\n12 557.000000\n11 557.000000\n13 557.000000\n2 557.000000" }, { "input": "13 503 9", "output": "YES\n6 223.555556 11 503.000000\n5 335.333333 4 391.222222\n2 223.555556 13 503.000000\n9 447.111111 6 279.444444\n12 391.222222 1 335.333333\n4 111.777778 12 111.777778 8 503.000000\n3 503.000000 10 55.888889 1 167.666667\n2 279.444444 10 447.111111\n9 55.888889 7 503.000000 5 167.666667" }, { "input": "12 255 8", "output": "YES\n11 255.000000 2 127.500000\n4 127.500000 8 255.000000\n2 127.500000 10 255.000000\n12 255.000000 1 127.500000\n1 127.500000 3 255.000000\n4 127.500000 5 255.000000\n6 255.000000 9 127.500000\n9 127.500000 7 255.000000" }, { "input": "11 827 13", "output": "NO" }, { "input": "4 381 16", "output": "NO" }, { "input": "18 624 32", "output": "NO" }, { "input": "30 864 48", "output": "NO" }, { "input": "26 637 16", "output": "YES\n26 318.500000 12 637.000000 1 79.625000\n6 238.875000 16 159.250000 19 637.000000\n14 637.000000 24 398.125000\n5 79.625000 26 318.500000 22 637.000000\n4 79.625000 21 637.000000 18 318.500000\n9 637.000000 18 318.500000 20 79.625000\n8 637.000000 3 398.125000\n23 477.750000 20 557.375000\n7 159.250000 17 637.000000 24 238.875000\n2 238.875000 10 637.000000 25 159.250000\n23 159.250000 3 238.875000 11 637.000000\n1 557.375000 25 477.750000\n16 477.750000 5 557.375000\n13 637.000000 2 398.125000\n4 557..." }, { "input": "13 322 43", "output": "NO" }, { "input": "12 792 38", "output": "NO" }, { "input": "30 628 23", "output": "YES\n19 273.043478 16 546.086957\n26 327.652174 28 491.478261\n23 518.782609 11 300.347826\n10 245.739130 25 573.391304\n12 382.260870 6 436.869565\n13 628.000000 2 191.130435\n24 409.565217 17 409.565217\n14 600.695652 24 218.434783\n12 245.739130 7 573.391304\n15 628.000000 29 163.826087 14 27.304348\n23 109.217391 9 81.913043 20 628.000000\n8 628.000000 7 54.608696 3 136.521739\n27 600.695652 17 218.434783\n9 546.086957 18 273.043478\n1 628.000000 28 136.521739 25 54.608696\n22 518.782609 26 300.347826\n..." }, { "input": "2 190 29", "output": "NO" }, { "input": "33 353 40", "output": "NO" }, { "input": "21 608 35", "output": "NO" }, { "input": "46 328 27", "output": "YES\n9 182.222222 20 328.000000 23 48.592593\n4 170.074074 17 60.740741 44 328.000000\n25 97.185185 15 133.629630 14 328.000000\n30 170.074074 32 328.000000 37 60.740741\n8 182.222222 35 48.592593 31 328.000000\n28 291.555556 37 267.259259\n21 242.962963 42 315.851852\n9 145.777778 21 85.037037 18 328.000000\n6 315.851852 12 242.962963\n29 303.703704 19 255.111111\n26 328.000000 40 72.888889 4 157.925926\n3 218.666667 6 12.148148 5 328.000000\n45 194.370370 1 328.000000 28 36.444444\n34 218.666667 27 328.0..." }, { "input": "44 371 47", "output": "NO" }, { "input": "9 615 50", "output": "NO" }, { "input": "4 574 9", "output": "NO" }, { "input": "13 751 24", "output": "NO" }, { "input": "5 556 43", "output": "NO" }, { "input": "2 449 45", "output": "NO" }, { "input": "21 665 45", "output": "NO" }, { "input": "26 905 31", "output": "NO" }, { "input": "26 856 49", "output": "NO" }, { "input": "6 804 32", "output": "NO" }, { "input": "15 737 26", "output": "NO" }, { "input": "35 462 50", "output": "NO" }, { "input": "34 948 42", "output": "NO" }, { "input": "9 929 41", "output": "NO" }, { "input": "11 324 24", "output": "NO" }, { "input": "2 227 11", "output": "NO" }, { "input": "3 606 41", "output": "NO" }, { "input": "21 452 43", "output": "NO" }, { "input": "19 134 48", "output": "NO" }, { "input": "28 595 48", "output": "NO" }, { "input": "36 371 42", "output": "YES\n5 53.000000 6 265.000000\n34 212.000000 27 106.000000\n26 53.000000 32 265.000000\n4 318.000000\n3 318.000000\n31 318.000000\n18 265.000000 21 53.000000\n30 159.000000 16 159.000000\n33 318.000000\n36 212.000000 11 106.000000\n28 318.000000\n35 318.000000\n8 265.000000 31 53.000000\n24 212.000000 14 106.000000\n5 318.000000\n2 265.000000 13 53.000000\n17 53.000000 11 265.000000\n36 159.000000 15 159.000000\n13 318.000000\n19 106.000000 16 212.000000\n17 318.000000\n18 106.000000 9 212.000000\n25 159.0..." }, { "input": "23 511 24", "output": "YES\n7 149.041667 17 340.666667\n16 212.916667 19 276.791667\n3 85.166667 1 404.541667\n21 404.541667 18 85.166667\n2 468.416667 13 21.291667\n22 170.333333 5 319.375000\n22 340.666667 8 149.041667\n4 127.750000 7 361.958333\n12 127.750000 8 361.958333\n23 489.708333\n13 489.708333\n19 234.208333 6 255.500000\n5 191.625000 16 298.083333\n6 255.500000 15 234.208333\n4 383.250000 21 106.458333\n1 106.458333 12 383.250000\n20 42.583333 9 447.125000\n11 191.625000 14 298.083333\n18 425.833333 9 63.875000\n23 2..." }, { "input": "24 836 25", "output": "YES\n13 802.560000\n17 535.040000 7 267.520000\n14 468.160000 24 334.400000\n2 769.120000 13 33.440000\n15 434.720000 14 367.840000\n3 702.240000 10 100.320000\n6 434.720000 19 367.840000\n8 234.080000 22 568.480000\n23 769.120000 11 33.440000\n20 735.680000 23 66.880000\n6 401.280000 15 401.280000\n18 668.800000 9 133.760000\n7 568.480000 4 234.080000\n21 200.640000 4 601.920000\n5 535.040000 22 267.520000\n5 300.960000 16 501.600000\n11 802.560000\n20 100.320000 9 702.240000\n10 735.680000 2 66.880000\n1..." }, { "input": "28 380 29", "output": "YES\n18 262.068966 9 104.827586\n28 78.620690 26 288.275862\n5 117.931034 16 248.965517\n4 235.862069 21 131.034483\n11 65.517241 23 301.379310\n15 209.655172 6 157.241379\n3 327.586207 8 39.310345\n6 222.758621 19 144.137931\n27 157.241379 17 209.655172\n23 78.620690 20 288.275862\n14 196.551724 15 170.344828\n20 91.724138 9 275.172414\n2 353.793103 13 13.103448\n10 340.689655 2 26.206897\n13 366.896552\n25 327.586207 10 39.310345\n24 183.448276 14 183.448276\n24 196.551724 17 170.344828\n4 144.137931 27 ..." }, { "input": "24 704 30", "output": "YES\n13 563.200000\n14 422.400000 15 140.800000\n6 563.200000\n13 140.800000 2 422.400000\n19 422.400000 6 140.800000\n10 422.400000 3 140.800000\n5 140.800000 16 422.400000\n12 281.600000 8 281.600000\n20 281.600000 23 281.600000\n21 281.600000 4 281.600000\n19 281.600000 16 281.600000\n9 140.800000 20 422.400000\n24 281.600000 14 281.600000\n17 140.800000 24 422.400000\n11 563.200000\n9 563.200000\n18 563.200000\n4 422.400000 7 140.800000\n10 281.600000 2 281.600000\n15 563.200000\n17 563.200000\n12 422...." }, { "input": "30 565 40", "output": "YES\n7 141.250000 8 282.500000\n11 141.250000 23 282.500000\n14 282.500000 15 141.250000\n18 282.500000 9 141.250000\n27 282.500000 17 141.250000\n13 423.750000\n7 423.750000\n3 423.750000\n17 423.750000\n3 141.250000 8 282.500000\n6 282.500000 12 141.250000\n24 423.750000\n21 423.750000\n29 423.750000\n10 423.750000\n1 282.500000 25 141.250000\n28 141.250000 1 282.500000\n27 282.500000 4 141.250000\n19 282.500000 29 141.250000\n19 282.500000 16 141.250000\n4 423.750000\n20 141.250000 23 282.500000\n5 423...." }, { "input": "35 948 42", "output": "YES\n7 632.000000 8 158.000000\n33 474.000000 29 316.000000\n21 632.000000 18 158.000000\n28 790.000000\n3 790.000000\n17 632.000000 11 158.000000\n16 158.000000 30 632.000000\n19 158.000000 29 632.000000\n10 474.000000 25 316.000000\n16 790.000000\n11 790.000000\n18 790.000000\n32 474.000000 26 316.000000\n8 790.000000\n1 790.000000\n15 474.000000 22 316.000000\n9 790.000000\n5 158.000000 6 632.000000\n4 474.000000 27 316.000000\n31 158.000000 35 632.000000\n31 790.000000\n20 632.000000 9 158.000000\n20 3..." }, { "input": "6 578 9", "output": "YES\n1 385.333333\n1 192.666667 6 192.666667\n3 385.333333\n5 192.666667 2 192.666667\n4 385.333333\n4 192.666667 3 192.666667\n2 385.333333\n6 385.333333\n5 385.333333" }, { "input": "24 619 28", "output": "YES\n13 530.571429\n14 176.857143 24 353.714286\n15 530.571429\n2 442.142857 13 88.428571\n6 530.571429\n3 265.285714 10 265.285714\n16 353.714286 19 176.857143\n8 530.571429\n11 530.571429\n21 88.428571 18 442.142857\n19 442.142857 6 88.428571\n23 442.142857 11 88.428571\n24 265.285714 17 265.285714\n17 353.714286 7 176.857143\n22 442.142857 8 88.428571\n23 176.857143 20 353.714286\n9 265.285714 20 265.285714\n21 530.571429\n10 353.714286 2 176.857143\n14 442.142857 15 88.428571\n4 88.428571 7 442.142857\n..." }, { "input": "30 986 32", "output": "YES\n22 493.000000 26 431.375000\n6 862.750000 5 61.625000\n27 862.750000 17 61.625000\n8 308.125000 3 616.250000\n9 616.250000 18 308.125000\n13 924.375000\n29 246.500000 19 677.875000\n7 246.500000 8 677.875000\n18 677.875000 21 246.500000\n16 369.750000 30 554.625000\n5 924.375000\n21 739.500000 4 184.875000\n11 431.375000 23 493.000000\n24 924.375000\n10 184.875000 25 739.500000\n28 616.250000 1 308.125000\n28 369.750000 26 554.625000\n20 554.625000 9 369.750000\n24 61.625000 14 862.750000\n14 123.2500..." }, { "input": "26 381 28", "output": "YES\n9 163.285714 18 190.500000\n12 163.285714 26 190.500000\n22 217.714286 5 136.071429\n23 272.142857 11 81.642857\n11 299.357143 3 54.428571\n3 326.571429 8 27.214286\n14 27.214286 24 326.571429\n23 108.857143 20 244.928571\n8 353.785714\n2 326.571429 13 27.214286\n7 108.857143 4 244.928571\n10 299.357143 2 54.428571\n18 190.500000 21 163.285714\n21 217.714286 4 136.071429\n19 81.642857 16 272.142857\n7 272.142857 17 81.642857\n15 353.785714\n22 163.285714 26 190.500000\n14 353.785714\n13 353.785714\n12..." }, { "input": "24 743 32", "output": "YES\n13 557.250000\n15 557.250000\n19 371.500000 6 185.750000\n13 185.750000 2 371.500000\n16 185.750000 19 371.500000\n10 557.250000\n5 557.250000\n12 557.250000\n9 557.250000\n7 371.500000 4 185.750000\n16 557.250000\n18 371.500000 9 185.750000\n14 371.500000 15 185.750000\n24 185.750000 14 371.500000\n20 185.750000 23 371.500000\n18 371.500000 21 185.750000\n21 557.250000\n7 371.500000 17 185.750000\n10 185.750000 2 371.500000\n11 185.750000 23 371.500000\n24 557.250000\n11 557.250000\n5 185.750000 22 3..." }, { "input": "24 459 27", "output": "YES\n13 408.000000\n17 51.000000 24 357.000000\n15 255.000000 14 153.000000\n2 357.000000 13 51.000000\n15 204.000000 6 204.000000\n10 153.000000 3 255.000000\n16 102.000000 19 306.000000\n8 357.000000 22 51.000000\n9 255.000000 20 153.000000\n18 204.000000 9 204.000000\n19 153.000000 6 255.000000\n11 408.000000\n17 408.000000\n7 408.000000\n22 408.000000\n11 51.000000 23 357.000000\n23 102.000000 20 306.000000\n21 153.000000 18 255.000000\n10 306.000000 2 102.000000\n24 102.000000 14 306.000000\n4 357.000..." }, { "input": "25 531 26", "output": "YES\n7 183.807692 17 326.769231\n5 183.807692 16 326.769231\n18 122.538462 21 388.038462\n10 469.730769 2 40.846154\n4 367.615385 21 142.961538\n15 265.500000 14 245.076923\n25 81.692308 1 428.884615\n9 428.884615 20 81.692308\n13 20.423077 2 490.153846\n18 408.461538 9 102.115385\n19 306.346154 16 204.230769\n3 20.423077 11 490.153846\n19 224.653846 6 285.923077\n13 510.576923\n25 449.307692 10 61.269231\n8 388.038462 12 122.538462\n5 347.192308 22 163.384615\n3 510.576923\n23 61.269231 20 449.307692\n12 ..." }, { "input": "40 897 42", "output": "YES\n15 555.285714 36 299.000000\n21 811.571429 18 42.714286\n6 512.571429 12 341.714286\n30 512.571429 32 341.714286\n29 384.428571 19 469.857143\n15 341.714286 22 512.571429\n7 598.000000 8 256.285714\n38 128.142857 27 726.142857\n9 854.285714\n13 854.285714\n28 256.285714 37 598.000000\n23 768.857143 20 85.428571\n1 683.428571 25 170.857143\n6 384.428571 5 469.857143\n2 811.571429 13 42.714286\n23 128.142857 35 726.142857\n2 85.428571 10 768.857143\n24 256.285714 39 598.000000\n8 640.714286 31 213.57142..." }, { "input": "24 371 26", "output": "YES\n13 342.461538\n24 85.615385 17 256.846154\n14 313.923077 15 28.538462\n13 28.538462 2 313.923077\n15 342.461538\n3 256.846154 10 85.615385\n6 28.538462 19 313.923077\n8 199.769231 22 142.692308\n20 285.384615 23 57.076923\n9 256.846154 20 85.615385\n6 342.461538\n21 199.769231 18 142.692308\n17 114.153846 7 228.307692\n7 142.692308 4 199.769231\n5 114.153846 22 228.307692\n11 342.461538\n11 28.538462 23 313.923077\n18 228.307692 9 114.153846\n10 285.384615 2 57.076923\n24 285.384615 14 57.076923\n21 1..." }, { "input": "18 169 20", "output": "YES\n17 118.300000 7 33.800000\n6 50.700000 15 101.400000\n15 67.600000 14 84.500000\n8 50.700000 12 101.400000\n18 135.200000 5 16.900000\n10 50.700000 3 101.400000\n10 118.300000 2 33.800000\n7 135.200000 4 16.900000\n16 16.900000 9 135.200000\n2 135.200000 13 16.900000\n9 33.800000 6 118.300000\n16 152.100000\n4 152.100000\n8 118.300000 18 33.800000\n14 84.500000 11 67.600000\n17 50.700000 11 101.400000\n5 152.100000\n1 84.500000 12 67.600000\n1 84.500000 3 67.600000\n13 152.100000" }, { "input": "24 264 25", "output": "YES\n13 253.440000\n17 168.960000 7 84.480000\n14 147.840000 24 105.600000\n2 242.880000 13 10.560000\n15 137.280000 14 116.160000\n3 221.760000 10 31.680000\n6 137.280000 19 116.160000\n8 73.920000 22 179.520000\n23 242.880000 11 10.560000\n20 232.320000 23 21.120000\n6 126.720000 15 126.720000\n18 211.200000 9 42.240000\n7 179.520000 4 73.920000\n21 63.360000 4 190.080000\n5 168.960000 22 84.480000\n5 95.040000 16 158.400000\n11 253.440000\n20 31.680000 9 221.760000\n10 232.320000 2 21.120000\n17 95.0400..." }, { "input": "27 884 28", "output": "YES\n6 378.857143 15 473.571429\n13 31.571429 2 820.857143\n18 631.428571 9 221.000000\n26 221.000000 22 631.428571\n13 852.428571\n23 726.142857 11 126.285714\n20 694.571429 23 157.857143\n10 789.285714 2 63.142857\n1 726.142857 25 126.285714\n4 568.285714 21 284.142857\n25 757.714286 10 94.714286\n27 347.285714 17 505.142857\n5 599.857143 22 252.571429\n18 252.571429 21 599.857143\n7 852.428571\n8 63.142857 3 789.285714\n14 442.000000 15 410.428571\n19 536.714286 16 315.714286\n3 94.714286 11 757.714286\n..." }, { "input": "18 922 21", "output": "YES\n11 395.142857 17 395.142857\n6 790.285714\n15 790.285714\n12 790.285714\n8 131.714286 18 658.571429\n4 790.285714\n10 526.857143 2 263.428571\n17 526.857143 7 263.428571\n16 526.857143 9 263.428571\n2 658.571429 13 131.714286\n9 658.571429 6 131.714286\n5 395.142857 16 395.142857\n4 131.714286 7 658.571429\n8 790.285714\n15 131.714286 14 658.571429\n14 263.428571 11 526.857143\n18 263.428571 5 526.857143\n12 131.714286 1 658.571429\n3 526.857143 1 263.428571\n13 790.285714\n3 395.142857 10 395.142857\n..." }, { "input": "37 772 38", "output": "YES\n16 203.157895 19 548.526316\n35 284.421053 23 467.263158\n27 426.631579 34 325.052632\n11 60.947368 36 690.736842\n28 121.894737 37 629.789474\n5 609.473684 3 142.210526\n26 751.684211\n9 345.368421 18 406.315789\n10 60.947368 25 690.736842\n19 223.473684 29 528.210526\n4 406.315789 27 345.368421\n7 223.473684 8 528.210526\n23 304.736842 20 446.947368\n24 467.263158 14 284.421053\n26 20.315789 17 731.368421\n6 182.842105 12 568.842105\n3 629.789474 22 121.894737\n18 365.684211 21 386.000000\n5 162.526..." }, { "input": "32 610 40", "output": "YES\n17 122.000000 24 366.000000\n13 488.000000\n9 122.000000 20 366.000000\n29 488.000000\n30 488.000000\n19 244.000000 16 244.000000\n7 366.000000 12 122.000000\n24 244.000000 14 244.000000\n22 488.000000\n31 488.000000\n6 488.000000\n27 488.000000\n3 244.000000 5 244.000000\n1 488.000000\n7 244.000000 8 244.000000\n9 488.000000\n28 244.000000 26 244.000000\n26 366.000000 32 122.000000\n2 366.000000 13 122.000000\n15 488.000000\n15 122.000000 14 366.000000\n21 366.000000 18 122.000000\n25 122.000000 10 3..." }, { "input": "22 771 23", "output": "YES\n13 33.521739 2 703.956522\n7 569.869565 4 167.608696\n14 301.695652 15 435.782609\n6 402.260870 15 335.217391\n8 234.652174 22 502.826087\n5 301.695652 16 435.782609\n6 368.739130 19 368.739130\n9 703.956522 20 33.521739\n17 234.652174 11 502.826087\n11 268.173913 14 469.304348\n3 134.086957 1 603.391304\n4 603.391304 21 134.086957\n13 737.478261\n16 335.217391 19 402.260870\n21 636.913043 18 100.565217\n22 268.173913 5 469.304348\n12 201.130435 8 536.347826\n9 67.043478 18 670.434783\n10 670.434783 2..." }, { "input": "22 792 24", "output": "YES\n13 66.000000 2 660.000000\n7 396.000000 17 330.000000\n6 66.000000 15 660.000000\n6 726.000000\n8 462.000000 22 264.000000\n5 594.000000 16 132.000000\n19 726.000000\n9 132.000000 18 594.000000\n14 198.000000 11 528.000000\n14 594.000000 15 132.000000\n1 462.000000 3 264.000000\n7 396.000000 4 330.000000\n13 726.000000\n16 660.000000 19 66.000000\n4 462.000000 21 264.000000\n22 528.000000 5 198.000000\n12 396.000000 8 330.000000\n21 528.000000 18 198.000000\n10 594.000000 2 132.000000\n20 66.000000 9 ..." }, { "input": "40 100 48", "output": "YES\n5 16.666667 6 66.666667\n27 66.666667 34 16.666667\n31 83.333333\n14 66.666667 17 16.666667\n16 83.333333\n6 33.333333 12 50.000000\n35 33.333333 23 50.000000\n24 83.333333\n38 50.000000 21 33.333333\n4 50.000000 26 33.333333\n28 83.333333\n18 83.333333\n25 66.666667 1 16.666667\n8 83.333333\n13 16.666667 2 66.666667\n9 83.333333\n10 50.000000 2 33.333333\n33 50.000000 29 33.333333\n23 50.000000 20 33.333333\n27 33.333333 38 50.000000\n11 83.333333\n40 83.333333\n9 16.666667 20 66.666667\n7 33.333333 ..." }, { "input": "42 501 48", "output": "YES\n28 375.750000 37 62.625000\n25 250.500000 10 187.875000\n24 438.375000\n34 375.750000 24 62.625000\n26 125.250000 4 313.125000\n16 313.125000 30 125.250000\n19 250.500000 29 187.875000\n37 438.375000\n31 250.500000 8 187.875000\n28 125.250000 1 313.125000\n3 313.125000 5 125.250000\n12 62.625000 7 375.750000\n33 375.750000 41 62.625000\n20 438.375000\n3 187.875000 22 250.500000\n29 313.125000 33 125.250000\n32 438.375000\n15 313.125000 36 125.250000\n17 313.125000 39 125.250000\n1 187.875000 25 250.50..." }, { "input": "36 100 39", "output": "YES\n3 53.846154 22 38.461538\n4 53.846154 27 38.461538\n30 30.769231 32 61.538462\n18 38.461538 21 53.846154\n15 69.230769 36 23.076923\n8 15.384615 7 76.923077\n20 23.076923 9 69.230769\n16 76.923077 19 15.384615\n33 7.692308 14 84.615385\n6 61.538462 12 30.769231\n26 46.153846 28 46.153846\n8 84.615385 31 7.692308\n12 69.230769 7 23.076923\n34 69.230769 24 23.076923\n15 30.769231 22 61.538462\n13 7.692308 2 84.615385\n10 76.923077 2 15.384615\n17 92.307692\n13 92.307692\n29 7.692308 19 84.615385\n30 69...." }, { "input": "42 171 49", "output": "YES\n28 146.571429\n25 73.285714 10 73.285714\n24 97.714286 41 48.857143\n24 73.285714 34 73.285714\n26 146.571429\n16 73.285714 30 73.285714\n19 122.142857 29 24.428571\n37 146.571429\n31 146.571429\n1 122.142857 28 24.428571\n5 146.571429\n7 97.714286 8 48.857143\n33 146.571429\n20 73.285714 9 73.285714\n3 146.571429\n38 146.571429\n32 122.142857 37 24.428571\n22 48.857143 15 97.714286\n14 73.285714 17 73.285714\n25 97.714286 1 48.857143\n2 48.857143 10 97.714286\n3 24.428571 22 122.142857\n4 122.142857 ..." }, { "input": "17 100 10", "output": "YES\n17 30.000000 14 40.000000 11 100.000000\n4 100.000000 8 20.000000 5 50.000000\n17 70.000000 7 100.000000\n9 20.000000 16 100.000000 5 50.000000\n3 40.000000 10 100.000000 2 30.000000\n12 90.000000 8 80.000000\n15 100.000000 6 10.000000 14 60.000000\n3 60.000000 12 10.000000 1 100.000000\n2 70.000000 13 100.000000\n9 80.000000 6 90.000000" }, { "input": "5 100 7", "output": "NO" } ]
93
17,715,200
3
22,366
401
Sereja and Contests
[ "greedy", "implementation", "math" ]
null
null
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds. Codesorfes has rounds of two types: *Div*1 (for advanced coders) and *Div*2 (for beginner coders). Two rounds, *Div*1 and *Div*2, can go simultaneously, (*Div*1 round cannot be held without *Div*2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the *Div*1 round is always greater. Sereja is a beginner coder, so he can take part only in rounds of *Div*2 type. At the moment he is taking part in a *Div*2 round, its identifier equals to *x*. Sereja remembers very well that he has taken part in exactly *k* rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed. Sereja is wondering: what minimum and what maximum number of *Div*2 rounds could he have missed? Help him find these two numbers.
The first line contains two integers: *x* (1<=≤<=*x*<=≤<=4000) — the round Sereja is taking part in today, and *k* (0<=≤<=*k*<=&lt;<=4000) — the number of rounds he took part in. Next *k* lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 *num*2 *num*1" (where *num*2 is the identifier of this *Div*2 round, *num*1 is the identifier of the *Div*1 round). It is guaranteed that *num*1<=-<=*num*2<==<=1. If Sereja took part in a usual *Div*2 round, then the corresponding line looks like: "2 *num*" (where *num* is the identifier of this *Div*2 round). It is guaranteed that the identifiers of all given rounds are less than *x*.
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
[ "3 2\n2 1\n2 2\n", "9 3\n1 2 3\n2 8\n1 4 5\n", "10 0\n" ]
[ "0 0", "2 3", "5 9" ]
In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual *Div*2 round and the round with identifier 6 will be synchronous with the *Div*1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual *Div*2 rounds.
[ { "input": "3 2\n2 1\n2 2", "output": "0 0" }, { "input": "9 3\n1 2 3\n2 8\n1 4 5", "output": "2 3" }, { "input": "10 0", "output": "5 9" }, { "input": "10 2\n1 1 2\n1 8 9", "output": "3 5" }, { "input": "9 3\n1 4 5\n1 1 2\n1 6 7", "output": "2 2" }, { "input": "7 2\n2 3\n1 5 6", "output": "2 3" }, { "input": "81 28\n1 77 78\n1 50 51\n2 9\n1 66 67\n1 12 13\n1 20 21\n1 28 29\n1 34 35\n1 54 55\n2 19\n1 70 71\n1 45 46\n1 36 37\n2 47\n2 7\n2 76\n2 6\n2 31\n1 16 17\n1 4 5\n1 73 74\n1 64 65\n2 62\n2 22\n2 1\n1 48 49\n2 24\n2 40", "output": "22 36" }, { "input": "12 8\n1 4 5\n1 9 10\n2 3\n1 6 7\n2 1\n2 2\n2 8\n2 11", "output": "0 0" }, { "input": "54 25\n1 40 41\n2 46\n2 32\n2 8\n1 51 52\n2 39\n1 30 31\n2 53\n1 33 34\n1 42 43\n1 17 18\n1 21 22\n1 44 45\n2 50\n2 49\n2 15\n1 3 4\n1 27 28\n1 19 20\n1 47 48\n2 13\n1 37 38\n1 6 7\n2 35\n2 26", "output": "10 14" }, { "input": "90 35\n2 83\n2 86\n2 46\n1 61 62\n2 11\n1 76 77\n2 37\n2 9\n1 18 19\n2 79\n1 35 36\n1 3 4\n2 78\n2 72\n1 44 45\n2 31\n2 38\n2 65\n1 32 33\n1 13 14\n2 75\n2 42\n2 51\n2 80\n2 29\n1 22 23\n1 5 6\n2 53\n1 7 8\n1 24 25\n1 54 55\n2 84\n1 27 28\n2 26\n2 12", "output": "25 40" }, { "input": "98 47\n1 48 49\n2 47\n1 25 26\n2 29\n1 38 39\n1 20 21\n2 75\n2 68\n2 95\n2 6\n1 1 2\n1 84 85\n2 66\n1 88 89\n2 19\n2 32\n1 93 94\n1 45 46\n2 50\n1 15 16\n1 63 64\n1 23 24\n1 53 54\n1 43 44\n2 97\n1 12 13\n2 86\n2 74\n2 42\n1 40 41\n1 30 31\n1 34 35\n1 27 28\n2 81\n1 8 9\n2 73\n1 70 71\n2 67\n2 60\n2 72\n1 76 77\n1 90 91\n1 17 18\n2 11\n1 82 83\n1 58 59\n2 55", "output": "18 24" }, { "input": "56 34\n2 22\n2 27\n1 18 19\n1 38 39\n2 49\n1 10 11\n1 14 15\n2 40\n2 34\n1 32 33\n2 17\n1 24 25\n2 23\n2 52\n1 45 46\n2 28\n2 7\n1 4 5\n1 30 31\n2 21\n2 6\n1 47 48\n1 43 44\n1 54 55\n2 13\n1 8 9\n1 2 3\n2 41\n1 35 36\n1 50 51\n2 1\n2 29\n2 16\n2 53", "output": "5 5" }, { "input": "43 27\n1 40 41\n1 2 3\n1 32 33\n1 35 36\n1 27 28\n1 30 31\n1 7 8\n2 11\n1 5 6\n2 1\n1 15 16\n1 38 39\n2 12\n1 20 21\n1 22 23\n1 24 25\n1 9 10\n2 26\n2 14\n1 18 19\n2 17\n2 4\n2 34\n2 37\n2 29\n2 42\n2 13", "output": "0 0" }, { "input": "21 13\n1 6 7\n2 12\n1 8 9\n2 19\n1 4 5\n1 17 18\n2 3\n2 20\n1 10 11\n2 14\n1 15 16\n1 1 2\n2 13", "output": "0 0" }, { "input": "66 1\n1 50 51", "output": "32 63" }, { "input": "62 21\n2 34\n1 39 40\n1 52 53\n1 35 36\n2 27\n1 56 57\n2 43\n1 7 8\n2 28\n1 44 45\n1 41 42\n1 32 33\n2 58\n1 47 48\n2 10\n1 21 22\n2 51\n1 15 16\n1 19 20\n1 3 4\n2 25", "output": "16 27" }, { "input": "83 56\n2 24\n2 30\n1 76 77\n1 26 27\n1 73 74\n1 52 53\n2 82\n1 36 37\n2 13\n2 4\n2 68\n1 31 32\n1 65 66\n1 16 17\n1 56 57\n2 60\n1 44 45\n1 80 81\n1 28 29\n2 23\n1 54 55\n2 9\n2 1\n1 34 35\n2 5\n1 78 79\n2 40\n2 42\n1 61 62\n2 49\n2 22\n2 25\n1 7 8\n1 20 21\n1 38 39\n2 43\n2 12\n1 46 47\n2 70\n1 71 72\n2 3\n1 10 11\n2 75\n2 59\n1 18 19\n2 69\n2 48\n1 63 64\n2 33\n1 14 15\n1 50 51\n2 6\n2 41\n2 2\n2 67\n2 58", "output": "0 0" }, { "input": "229 27\n2 7\n1 64 65\n1 12 13\n2 110\n1 145 146\n2 92\n2 28\n2 39\n1 16 17\n2 164\n2 137\n1 95 96\n2 125\n1 48 49\n1 115 116\n1 198 199\n1 148 149\n1 225 226\n1 1 2\n2 24\n2 103\n1 87 88\n2 124\n2 89\n1 178 179\n1 160 161\n2 184", "output": "98 187" }, { "input": "293 49\n2 286\n2 66\n2 98\n1 237 238\n1 136 137\n1 275 276\n2 152\n1 36 37\n2 26\n2 40\n2 79\n2 274\n1 205 206\n1 141 142\n1 243 244\n2 201\n1 12 13\n1 123 124\n1 165 166\n1 6 7\n2 64\n1 22 23\n2 120\n1 138 139\n1 50 51\n2 15\n2 67\n2 45\n1 288 289\n1 261 262\n1 103 104\n2 249\n2 32\n2 153\n2 248\n1 162 163\n2 89\n1 94 95\n2 21\n1 48 49\n1 56 57\n2 102\n1 271 272\n2 269\n1 232 233\n1 70 71\n1 42 43\n1 267 268\n2 292", "output": "121 217" }, { "input": "181 57\n1 10 11\n1 4 5\n1 170 171\n2 86\n2 97\n1 91 92\n2 162\n2 115\n1 98 99\n2 134\n1 100 101\n2 168\n1 113 114\n1 37 38\n2 81\n2 169\n1 173 174\n1 165 166\n2 108\n2 121\n1 31 32\n2 67\n2 13\n2 50\n2 157\n1 27 28\n1 19 20\n2 109\n1 104 105\n2 46\n1 126 127\n1 102 103\n2 158\n2 133\n2 93\n2 68\n1 70 71\n2 125\n2 36\n1 48 49\n2 117\n1 131 132\n2 79\n2 23\n1 75 76\n2 107\n2 138\n1 94 95\n2 54\n1 87 88\n2 41\n1 153 154\n1 14 15\n2 60\n2 148\n1 159 160\n2 58", "output": "61 98" }, { "input": "432 5\n1 130 131\n2 108\n1 76 77\n1 147 148\n2 137", "output": "214 423" }, { "input": "125 45\n2 70\n2 111\n2 52\n2 3\n2 97\n2 104\n1 47 48\n2 44\n2 88\n1 117 118\n2 82\n1 22 23\n1 53 54\n1 38 39\n1 114 115\n2 93\n2 113\n2 102\n2 30\n2 95\n2 36\n2 73\n2 51\n2 87\n1 15 16\n2 55\n2 80\n2 121\n2 26\n1 31 32\n1 105 106\n1 1 2\n1 10 11\n2 91\n1 78 79\n1 7 8\n2 120\n2 75\n1 45 46\n2 94\n2 72\n2 25\n1 34 35\n1 17 18\n1 20 21", "output": "40 62" }, { "input": "48 35\n1 17 18\n2 20\n1 7 8\n2 13\n1 1 2\n2 23\n1 25 26\n1 14 15\n2 3\n1 45 46\n1 35 36\n2 47\n1 27 28\n2 30\n1 5 6\n2 11\n2 9\n1 32 33\n2 19\n2 24\n2 16\n1 42 43\n1 21 22\n2 37\n2 34\n2 40\n2 31\n2 10\n2 44\n2 39\n2 12\n2 29\n2 38\n2 4\n2 41", "output": "0 0" }, { "input": "203 55\n2 81\n2 65\n1 38 39\n1 121 122\n2 48\n2 83\n1 23 24\n2 165\n1 132 133\n1 143 144\n2 35\n2 85\n2 187\n1 19 20\n2 137\n2 150\n2 202\n2 156\n2 178\n1 93 94\n2 73\n2 167\n1 56 57\n1 100 101\n1 26 27\n1 51 52\n2 74\n2 4\n2 79\n2 113\n1 181 182\n2 75\n2 157\n2 25\n2 124\n1 68 69\n1 135 136\n1 110 111\n1 153 154\n2 123\n2 134\n1 36 37\n1 145 146\n1 141 142\n1 86 87\n2 10\n1 5 6\n2 131\n2 116\n2 70\n1 95 96\n1 174 175\n2 108\n1 91 92\n2 152", "output": "71 123" }, { "input": "51 38\n2 48\n2 42\n2 20\n2 4\n2 37\n2 22\n2 9\n2 13\n1 44 45\n1 33 34\n2 8\n1 18 19\n1 2 3\n2 27\n1 5 6\n1 40 41\n1 24 25\n2 16\n2 39\n2 50\n1 31 32\n1 46 47\n2 15\n1 29 30\n1 10 11\n2 49\n2 14\n1 35 36\n2 23\n2 7\n2 38\n2 26\n2 1\n2 17\n2 43\n2 21\n2 12\n2 28", "output": "0 0" }, { "input": "401 40\n1 104 105\n2 368\n1 350 351\n1 107 108\n1 4 5\n1 143 144\n2 369\n1 337 338\n2 360\n2 384\n2 145\n1 102 103\n1 88 89\n1 179 180\n2 202\n1 234 235\n2 154\n1 9 10\n1 113 114\n2 398\n1 46 47\n1 35 36\n1 174 175\n1 273 274\n1 237 238\n2 209\n1 138 139\n1 33 34\n1 243 244\n1 266 267\n1 294 295\n2 219\n2 75\n2 340\n1 260 261\n1 245 246\n2 210\n1 221 222\n1 328 329\n1 164 165", "output": "177 333" }, { "input": "24 16\n1 16 17\n1 1 2\n1 8 9\n1 18 19\n1 22 23\n1 13 14\n2 15\n2 6\n2 11\n2 20\n2 3\n1 4 5\n2 10\n2 7\n2 21\n2 12", "output": "0 0" }, { "input": "137 37\n2 108\n1 55 56\n2 20\n1 33 34\n2 112\n2 48\n2 120\n2 38\n2 74\n2 119\n2 27\n1 13 14\n2 8\n1 88 89\n1 44 45\n2 124\n2 76\n2 123\n2 104\n1 58 59\n2 52\n2 47\n1 3 4\n1 65 66\n2 28\n1 102 103\n2 81\n2 86\n2 116\n1 69 70\n1 11 12\n2 84\n1 25 26\n2 100\n2 90\n2 83\n1 95 96", "output": "52 86" }, { "input": "1155 50\n1 636 637\n1 448 449\n2 631\n2 247\n1 1049 1050\n1 1103 1104\n1 816 817\n1 1127 1128\n2 441\n2 982\n1 863 864\n2 186\n1 774 775\n2 793\n2 173\n2 800\n1 952 953\n1 492 493\n1 796 797\n2 907\n2 856\n2 786\n2 921\n1 558 559\n2 1090\n1 307 308\n1 1152 1153\n1 578 579\n1 944 945\n1 707 708\n2 968\n1 1005 1006\n1 1100 1101\n2 402\n1 917 918\n1 237 238\n1 191 192\n2 460\n1 1010 1011\n2 960\n1 1018 1019\n2 296\n1 958 959\n2 650\n2 395\n1 1124 1125\n2 539\n2 152\n1 385 386\n2 464", "output": "548 1077" }, { "input": "1122 54\n2 1031\n1 363 364\n1 14 15\n1 902 903\n1 1052 1053\n2 170\n2 36\n2 194\n1 340 341\n1 1018 1019\n1 670 671\n1 558 559\n2 431\n2 351\n2 201\n1 1104 1105\n2 1056\n2 823\n1 274 275\n2 980\n1 542 543\n1 807 808\n2 157\n2 895\n1 505 506\n2 658\n1 484 485\n1 533 534\n1 384 385\n2 779\n2 888\n1 137 138\n1 198 199\n2 762\n1 451 452\n1 248 249\n2 294\n2 123\n2 948\n2 1024\n2 771\n2 922\n1 566 567\n1 707 708\n1 1037 1038\n2 63\n1 208 209\n1 738 739\n2 648\n1 491 492\n1 440 441\n2 651\n1 971 972\n1 93 94", "output": "532 1038" }, { "input": "2938 48\n2 1519\n2 1828\n1 252 253\n1 2275 2276\n1 1479 1480\n2 751\n2 972\n2 175\n2 255\n1 1837 1838\n1 1914 1915\n2 198\n1 1686 1687\n1 950 951\n2 61\n1 840 841\n2 277\n1 52 53\n1 76 77\n2 795\n2 1680\n1 2601 2602\n2 2286\n2 2188\n2 2521\n2 1166\n2 1171\n2 2421\n1 1297 1298\n1 1736 1737\n1 991 992\n1 1048 1049\n2 756\n2 2054\n1 2878 2879\n1 1445 1446\n1 2539 2540\n2 1334\n2 2233\n2 494\n2 506\n1 1942 1943\n2 2617\n1 1991 1992\n2 1501\n1 2488 2489\n1 752 753\n2 2623", "output": "1444 2867" }, { "input": "2698 39\n2 710\n1 260 261\n2 174\n2 1697\n2 915\n1 2029 2030\n2 916\n2 2419\n2 323\n1 2130 2131\n2 1350\n1 64 65\n1 763 764\n1 939 940\n2 1693\n2 659\n2 2281\n2 761\n2 909\n1 1873 1874\n1 1164 1165\n2 2308\n2 504\n1 1035 1036\n1 2271 2272\n1 1085 1086\n1 1757 1758\n2 1818\n1 1604 1605\n1 517 518\n1 2206 2207\n2 636\n1 519 520\n2 1928\n1 1894 1895\n2 573\n2 2313\n1 42 43\n2 1529", "output": "1327 2640" }, { "input": "3999 0", "output": "1999 3998" }, { "input": "1 0", "output": "0 0" }, { "input": "10 5\n1 1 2\n2 3\n2 8\n1 4 5\n1 6 7", "output": "1 1" }, { "input": "4000 0", "output": "2000 3999" } ]
187
3,481,600
3
22,392
56
Corporation Mail
[ "data structures", "expression parsing", "implementation" ]
C. Corporation Mail
2
256
The Beroil corporation structure is hierarchical, that is it can be represented as a tree. Let's examine the presentation of this structure as follows: - *employee* ::= *name*. | *name*:*employee*1,*employee*2, ... ,*employee**k*. - *name* ::= name of an employee That is, the description of each employee consists of his name, a colon (:), the descriptions of all his subordinates separated by commas, and, finally, a dot. If an employee has no subordinates, then the colon is not present in his description. For example, line MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY... is the correct way of recording the structure of a corporation where the director MIKE has subordinates MAX, ARTEM and DMITRY. ARTEM has a subordinate whose name is MIKE, just as the name of his boss and two subordinates of DMITRY are called DMITRY, just like himself. In the Beroil corporation every employee can only correspond with his subordinates, at that the subordinates are not necessarily direct. Let's call an uncomfortable situation the situation when a person whose name is *s* writes a letter to another person whose name is also *s*. In the example given above are two such pairs: a pair involving MIKE, and two pairs for DMITRY (a pair for each of his subordinates). Your task is by the given structure of the corporation to find the number of uncomfortable pairs in it.
The first and single line contains the corporation structure which is a string of length from 1 to 1000 characters. It is guaranteed that the description is correct. Every name is a string consisting of capital Latin letters from 1 to 10 symbols in length.
Print a single number — the number of uncomfortable situations in the company.
[ "MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY...\n", "A:A..\n", "A:C:C:C:C.....\n" ]
[ "3\n", "1\n", "6\n" ]
none
[ { "input": "A:A..", "output": "1" }, { "input": "CK:CK.,CK.,CK..", "output": "3" }, { "input": "RHLGWEVBJ:KAWUINWEI:KAWUINWEI..,ZQATMW.,KAWUINWEI.,RSWN..", "output": "1" }, { "input": "GIRRY.", "output": "0" }, { "input": "XGB:QJNGARRAZV:DWGDCCU:ARDKJV:P:MXBLZKLPYI:FKSBDQVXH:FKSBDQVXH:MXBLZKLPYI..,DWGDCCU..,P...,FKSBDQVXH....,ARDKJV..", "output": "4" }, { "input": "BZSBQVEUZK:GW:IJXBZZR:Q:TTTUZKB:IJXBZZR..,KPMRUKBRJ.,DJJTU..,DJJTU..,SFMVKQPXS.,TTTUZKB:AE..,Q..,VHOCZVQZF:VHOCZVQZF:DJJTU:AE:XVG:GW.,BZSBQVEUZK..,DJJTU..,SFMVKQPXS.,CUUSFRK..,DJJTU..,VHOCZVQZF:AE:TTTUZKB...,TTTUZKB.,PNETLABTTQ.,VHOCZVQZF..,Q:QLQL:IJXBZZR.,Q:KPMRUKBRJ:GW..,Q:BZSBQVEUZK..,Q...,BZSBQVEUZK:DJJTU..,DJJTU:Q:KPMRUKBRJ.,AE..,QLQL:U..,XVG..,XVG:GW:KPMRUKBRJ.,Q:AE...,IJXBZZR.,VHOCZVQZF..,XVG:XVG:SFMVKQPXS:SFMVKQPXS:PNETLABTTQ..,IJXBZZR.....,AE..", "output": "17" }, { "input": "Z:NEY:DL:TTKMDPVN.,TTKMDPVN:AMOX:GKDGHYO:DEZEYWDYEX.,PXUVUT:QEIAXOXHZR.....,WYUQVE:XTJRQMQPJ:NMC..,OZFRSSAZY...,NEY:XTJRQMQPJ:QEIAXOXHZR:DL...,A.,JTI..,GZWGZFYQ:CMRRM:NEY:GZWGZFYQ.,BYJEO..,RRANVKZKLP:ZFWEDY...,TTKMDPVN:A:A.,URISSHYFO:QXWE.....,WTXOTXGTZ.,A:DEZEYWDYEX.,OZFRSSAZY:CWUPIW..,RRANVKZKLP:DEZEYWDYEX:A:WTXOTXGTZ..,CMRRM...,WYUQVE...,TRQDYZVY:VF..,WYUQVE..", "output": "5" }, { "input": "ZTWZXUB:E:E:ZTWZXUB:ZTWZXUB:E..,E.,ZTWZXUB..,E..,ZTWZXUB:E:E...,AUVIDATFD:AUVIDATFD:AUVIDATFD..,ZTWZXUB...,E:ZTWZXUB:E.,E..,ZTWZXUB:E:E..,E..,ZTWZXUB:E.,E...,AUVIDATFD:E:AUVIDATFD..,E:E:AUVIDATFD.,E..,ZTWZXUB:AUVIDATFD...,E.,E..,E:AUVIDATFD.,ZTWZXUB:E...,E:ZTWZXUB.,E..,AUVIDATFD..", "output": "42" }, { "input": "UTQJYDWLRU:AAQESABBIV:ES:S:AAQESABBIV.,ZAJSINN..,MOLZWDPVYT.,MOLZWDPVYT..,KHYPOOUNR:KHYPOOUNR...,ZJXBUI:INOMNMT.,NEQK:USRBDKJXHI.,AWJAV:S:OUHETS...,BRXKYBJD.,S..,NEQK:ES.,ZJXBUI:YNJA...,AWJAV.,OCC:INOMNMT..,OCC.,UTQJYDWLRU..,MOLZWDPVYT:ES:YNJA.,YIWBP.,NAYUL.,USRBDKJXHI..,YNJA.,MOLZWDPVYT.,UTQJYDWLRU..,S:UTQJYDWLRU:NAYUL:USRBDKJXHI...,MOLZWDPVYT:BRXKYBJD..,YIWBP.,ES.,NAYUL:OCC...,OUHETS.,UTQJYDWLRU..", "output": "8" }, { "input": "UWEJCOA:PPFWB:GKWVDKH:UWEJCOA..,QINJL.,ZVLULGYCBJ..,D:D..,EFEHJKNH:QINJL.,GKWVDKH..,NLBPAHEH.,PPFWB.,MWRKW.,UWEJCOA.,QINJL..", "output": "3" }, { "input": "HINLHUMDSC:HINLHUMDSC.,HINLHUMDSC:HINLHUMDSC..,HINLHUMDSC.,HINLHUMDSC.,HINLHUMDSC..", "output": "7" }, { "input": "ZLWSYH:WNMTNAI:FTCKPGZBJ.,UZSCFZVXXK.,LNGCU.,TCT.,LNGCU.,U.,NEHYSET..,FBLI:NEHYSET:IFY..,VN.,VN.,IFY.,FBLI.,YH.,FBLI.,DTXG.,NEHYSET.,WNMTNAI.,VN.,SVXN.,NEHYSET.,TCT.,DTXG..,UZSCFZVXXK:KZQRJFST.,FTCKPGZBJ.,WNMTNAI.,SVXN:DHONBXRZAL..,NEHYSET.,IFY..,MPOEEMVOP:DHONBXRZAL.,DTXG.,FTCKPGZBJ..,KZQRJFST:SVXN.,SVXN..,DTXG:IFY..,ZLWSYH:UZSCFZVXXK.,ZLWSYH..,KZQRJFST:IFY..,IFY.,TCT:FTCKPGZBJ..,LNGCU.,DTXG.,VN.,FBLI.,NSFLRQN.,FTCKPGZBJ.,KZQRJFST.,QLA.,LNGCU.,JKVOAW.,YH.,SVXN.,QLA..", "output": "5" }, { "input": "FWYOOG:NJBFIOD:FWYOOG..,DH.,TSPKXXXE.,YMMMGNYBDC.,YMMMGNYBDC.,YMMMGNYBDC.,YMMMGNYBDC.,NJBFIOD..", "output": "1" }, { "input": "V:V:V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V..,V:V.,V.,V.,V..,V:V.,V.,V.,V.,V..,V:V.,V.,V..,V:V..,V:V.,V..,V.,V:V..,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V.,V..", "output": "134" } ]
498
30,515,200
3.818661
22,412
962
Simple Cycles Edges
[ "dfs and similar", "graphs", "trees" ]
null
null
You are given an undirected graph, consisting of $n$ vertices and $m$ edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges between a pair of vertices) or loops (edges from a vertex to itself). A cycle in a graph is called a simple, if it contains each own vertex exactly once. So simple cycle doesn't allow to visit a vertex more than once in a cycle. Determine the edges, which belong to exactly on one simple cycle.
The first line contain two integers $n$ and $m$ $(1 \le n \le 100\,000$, $0 \le m \le \min(n \cdot (n - 1) / 2, 100\,000))$ — the number of vertices and the number of edges. Each of the following $m$ lines contain two integers $u$ and $v$ ($1 \le u, v \le n$, $u \neq v$) — the description of the edges.
In the first line print the number of edges, which belong to exactly one simple cycle. In the second line print the indices of edges, which belong to exactly one simple cycle, in increasing order. The edges are numbered from one in the same order as they are given in the input.
[ "3 3\n1 2\n2 3\n3 1\n", "6 7\n2 3\n3 4\n4 2\n1 2\n1 5\n5 6\n6 1\n", "5 6\n1 2\n2 3\n2 4\n4 3\n2 5\n5 3\n" ]
[ "3\n1 2 3 \n", "6\n1 2 3 5 6 7 \n", "0\n\n" ]
none
[ { "input": "3 3\n1 2\n2 3\n3 1", "output": "3\n1 2 3 " }, { "input": "6 7\n2 3\n3 4\n4 2\n1 2\n1 5\n5 6\n6 1", "output": "6\n1 2 3 5 6 7 " }, { "input": "5 6\n1 2\n2 3\n2 4\n4 3\n2 5\n5 3", "output": "0" }, { "input": "4 5\n1 2\n2 3\n3 4\n4 1\n1 3", "output": "0" }, { "input": "7 8\n1 2\n2 3\n3 4\n4 1\n3 5\n5 6\n6 7\n7 3", "output": "8\n1 2 3 4 5 6 7 8 " }, { "input": "7 9\n1 2\n2 4\n4 3\n3 1\n2 3\n4 5\n5 6\n6 7\n7 4", "output": "4\n6 7 8 9 " }, { "input": "6 9\n1 2\n2 3\n1 4\n4 2\n5 2\n5 3\n4 5\n6 4\n6 5", "output": "0" }, { "input": "6 7\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n6 4", "output": "6\n1 2 3 5 6 7 " }, { "input": "7 9\n7 3\n7 4\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n6 4", "output": "9\n1 2 3 4 5 6 7 8 9 " }, { "input": "8 9\n1 2\n2 3\n3 4\n4 1\n5 6\n6 7\n7 8\n8 5\n6 8", "output": "4\n1 2 3 4 " }, { "input": "11 9\n5 9\n8 5\n11 3\n11 1\n3 4\n7 11\n3 1\n11 2\n7 2", "output": "6\n3 4 6 7 8 9 " }, { "input": "7 5\n5 4\n7 3\n7 1\n6 7\n3 1", "output": "3\n2 3 5 " }, { "input": "100000 0", "output": "0" }, { "input": "100000 3\n99998 99999\n99999 100000\n100000 99998", "output": "3\n1 2 3 " }, { "input": "1 0", "output": "0" }, { "input": "2 0", "output": "0" }, { "input": "2 1\n1 2", "output": "0" } ]
46
0
0
22,509
425
Sereja and Two Sequences
[ "data structures", "dp" ]
null
null
Sereja has two sequences *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**m*, consisting of integers. One day Sereja got bored and he decided two play with them. The rules of the game was very simple. Sereja makes several moves, in one move he can perform one of the following actions: 1. Choose several (at least one) first elements of sequence *a* (non-empty prefix of *a*), choose several (at least one) first elements of sequence *b* (non-empty prefix of *b*); the element of sequence *a* with the maximum index among the chosen ones must be equal to the element of sequence *b* with the maximum index among the chosen ones; remove the chosen elements from the sequences. 1. Remove all elements of both sequences. The first action is worth *e* energy units and adds one dollar to Sereja's electronic account. The second action is worth the number of energy units equal to the number of elements Sereja removed from the sequences before performing this action. After Sereja performed the second action, he gets all the money that he earned on his electronic account during the game. Initially Sereja has *s* energy units and no money on his account. What maximum number of money can Sereja get? Note, the amount of Seraja's energy mustn't be negative at any time moment.
The first line contains integers *n*, *m*, *s*, *e* (1<=≤<=*n*,<=*m*<=≤<=105; 1<=≤<=*s*<=≤<=3·105; 103<=≤<=*e*<=≤<=104). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The third line contains *m* integers *b*1, *b*2, ..., *b**m* (1<=≤<=*b**i*<=≤<=105).
Print a single integer — maximum number of money in dollars that Sereja can get.
[ "5 5 100000 1000\n1 2 3 4 5\n3 2 4 5 1\n", "3 4 3006 1000\n1 2 3\n1 2 4 3\n" ]
[ "3\n", "2\n" ]
none
[]
46
7,987,200
0
22,527
311
Biologist
[ "flows" ]
null
null
SmallR is a biologist. Her latest research finding is how to change the sex of dogs. In other words, she can change female dogs into male dogs and vice versa. She is going to demonstrate this technique. Now SmallR has *n* dogs, the costs of each dog's change may be different. The dogs are numbered from 1 to *n*. The cost of change for dog *i* is *v**i* RMB. By the way, this technique needs a kind of medicine which can be valid for only one day. So the experiment should be taken in one day and each dog can be changed at most once. This experiment has aroused extensive attention from all sectors of society. There are *m* rich folks which are suspicious of this experiment. They all want to bet with SmallR forcibly. If SmallR succeeds, the *i*-th rich folk will pay SmallR *w**i* RMB. But it's strange that they have a special method to determine whether SmallR succeeds. For *i*-th rich folk, in advance, he will appoint certain *k**i* dogs and certain one gender. He will think SmallR succeeds if and only if on some day the *k**i* appointed dogs are all of the appointed gender. Otherwise, he will think SmallR fails. If SmallR can't satisfy some folk that isn't her friend, she need not pay him, but if someone she can't satisfy is her good friend, she must pay *g* RMB to him as apologies for her fail. Then, SmallR hope to acquire money as much as possible by this experiment. Please figure out the maximum money SmallR can acquire. By the way, it is possible that she can't obtain any money, even will lose money. Then, please give out the minimum money she should lose.
The first line contains three integers *n*, *m*, *g* (1<=≤<=*n*<=≤<=104,<=0<=≤<=*m*<=≤<=2000,<=0<=≤<=*g*<=≤<=104). The second line contains *n* integers, each is 0 or 1, the sex of each dog, 0 represent the female and 1 represent the male. The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤<=104). Each of the next *m* lines describes a rich folk. On the *i*-th line the first number is the appointed sex of *i*-th folk (0 or 1), the next two integers are *w**i* and *k**i* (0<=≤<=*w**i*<=≤<=104,<=1<=≤<=*k**i*<=≤<=10), next *k**i* distinct integers are the indexes of appointed dogs (each index is between 1 and *n*). The last number of this line represents whether *i*-th folk is SmallR's good friend (0 — no or 1 — yes).
Print a single integer, the maximum money SmallR can gain. Note that the integer is negative if SmallR will lose money.
[ "5 5 9\n0 1 1 1 0\n1 8 6 2 3\n0 7 3 3 2 1 1\n1 8 1 5 1\n1 0 3 2 1 4 1\n0 8 3 4 2 1 0\n1 7 2 4 1 1\n", "5 5 8\n1 0 1 1 1\n6 5 4 2 8\n0 6 3 2 3 4 0\n0 8 3 3 2 4 0\n0 0 3 3 4 1 1\n0 10 3 4 3 1 1\n0 4 3 3 4 1 1\n" ]
[ "2\n", "16\n" ]
none
[ { "input": "5 5 9\n0 1 1 1 0\n1 8 6 2 3\n0 7 3 3 2 1 1\n1 8 1 5 1\n1 0 3 2 1 4 1\n0 8 3 4 2 1 0\n1 7 2 4 1 1", "output": "2" }, { "input": "5 5 8\n1 0 1 1 1\n6 5 4 2 8\n0 6 3 2 3 4 0\n0 8 3 3 2 4 0\n0 0 3 3 4 1 1\n0 10 3 4 3 1 1\n0 4 3 3 4 1 1", "output": "16" }, { "input": "5 5 8\n0 1 0 0 0\n1 9 4 3 10\n1 10 3 2 1 4 1\n0 4 3 1 4 3 1\n0 1 3 3 2 5 1\n0 0 3 3 1 4 1\n1 7 3 4 1 3 0", "output": "-12" }, { "input": "5 5 1\n0 0 1 1 0\n7 8 1 10 9\n0 2 3 4 3 5 0\n0 6 3 2 3 5 1\n1 0 3 3 2 5 1\n1 2 3 4 2 5 1\n1 10 3 3 1 2 0", "output": "3" }, { "input": "5 5 1\n0 1 0 0 0\n6 8 2 4 0\n1 9 3 4 5 3 1\n0 2 3 1 5 2 0\n0 2 3 4 5 2 0\n1 8 3 2 1 5 0\n0 5 3 3 2 1 0", "output": "5" }, { "input": "5 5 7\n0 1 0 0 1\n3 1 2 5 1\n0 10 3 1 5 3 1\n0 8 3 5 3 1 1\n1 2 3 1 5 3 0\n0 10 3 3 4 5 1\n1 4 3 3 2 1 0", "output": "27" }, { "input": "5 5 0\n1 0 1 1 0\n1 1 1 8 4\n0 1 3 2 3 1 0\n0 7 3 1 5 2 1\n1 0 3 5 4 3 1\n1 9 3 2 1 4 0\n1 6 3 1 2 5 1", "output": "10" }, { "input": "5 5 4\n0 1 1 0 0\n9 1 2 9 4\n1 0 3 4 3 5 0\n0 10 3 1 2 3 0\n1 6 3 5 4 1 1\n0 7 3 2 5 1 0\n0 9 3 1 4 2 1", "output": "19" }, { "input": "5 5 4\n1 1 0 1 0\n5 10 8 5 4\n0 3 3 5 4 1 1\n0 10 3 1 3 5 0\n1 4 3 2 1 4 1\n0 0 3 5 2 3 0\n0 7 3 2 4 5 0", "output": "0" }, { "input": "5 5 8\n1 0 1 1 1\n3 3 9 6 6\n1 6 3 1 5 2 1\n1 1 3 2 1 3 0\n0 4 3 3 5 4 1\n1 0 3 3 4 1 0\n1 0 3 4 5 2 1", "output": "-4" }, { "input": "5 5 10\n1 1 1 0 1\n7 3 10 1 0\n0 7 3 2 1 3 0\n0 9 3 1 3 2 1\n1 0 3 1 4 5 1\n0 6 3 4 5 2 1\n0 7 3 4 5 2 1", "output": "-1" }, { "input": "5 5 3\n1 0 0 1 0\n8 1 6 8 0\n1 3 3 5 2 3 0\n0 1 3 5 2 1 1\n0 1 3 5 3 1 1\n1 8 3 4 1 2 1\n0 7 3 3 5 4 0", "output": "1" }, { "input": "5 5 3\n1 1 1 0 0\n1 5 7 9 2\n0 6 3 2 3 1 1\n1 2 3 5 2 1 0\n0 1 3 4 3 1 0\n0 2 3 3 1 2 1\n1 3 3 4 2 1 1", "output": "-7" }, { "input": "5 0 9\n0 1 1 1 0\n1 8 6 2 3", "output": "0" } ]
30
0
0
22,544
487
Conveyor Belts
[ "data structures" ]
null
null
Automatic Bakery of Cyberland (ABC) recently bought an *n*<=×<=*m* rectangle table. To serve the diners, ABC placed seats around the table. The size of each seat is equal to a unit square, so there are 2(*n*<=+<=*m*) seats in total. ABC placed conveyor belts on each unit square on the table. There are three types of conveyor belts: "^", "&lt;" and "&gt;". A "^" belt can bring things upwards. "&lt;" can bring leftwards and "&gt;" can bring rightwards. Let's number the rows with 1 to *n* from top to bottom, the columns with 1 to *m* from left to right. We consider the seats above and below the top of the table are rows 0 and *n*<=+<=1 respectively. Also we define seats to the left of the table and to the right of the table to be column 0 and *m*<=+<=1. Due to the conveyor belts direction restriction there are currently no way for a diner sitting in the row *n*<=+<=1 to be served. Given the initial table, there will be *q* events in order. There are two types of events: - "A *x* *y*" means, a piece of bread will appear at row *x* and column *y* (we will denote such position as (*x*,<=*y*)). The bread will follow the conveyor belt, until arriving at a seat of a diner. It is possible that the bread gets stuck in an infinite loop. Your task is to simulate the process, and output the final position of the bread, or determine that there will be an infinite loop. - "C *x* *y* *c*" means that the type of the conveyor belt at (*x*,<=*y*) is changed to *c*. Queries are performed separately meaning that even if the bread got stuck in an infinite loop, it won't affect further queries.
The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=10,<=1<=≤<=*q*<=≤<=105), separated by a space. Next *n* lines, each line contains *m* characters, describing the table. The characters can only be one of "&lt;^&gt;". Next *q* lines, each line describes an event. The format is "C x y c" or "A x y" (Consecutive elements are separated by a space). It's guaranteed that 1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*. *c* is a character from the set "&lt;^&gt;". There are at most 10000 queries of "C" type.
For each event of type "A", output two integers *tx*, *ty* in a line, separated by a space, denoting the destination of (*x*,<=*y*) is (*tx*,<=*ty*). If there is an infinite loop, you should output *tx*<==<=*ty*<==<=<=-<=1.
[ "2 2 3\n&gt;&gt;\n^^\nA 2 1\nC 1 2 &lt;\nA 2 1\n", "4 5 7\n&gt;&lt;&lt;^&lt;\n^&lt;^^&gt;\n&gt;&gt;&gt;^&gt;\n&gt;^&gt;&gt;^\nA 3 1\nA 2 2\nC 1 4 &lt;\nA 3 1\nC 1 2 ^\nA 3 1\nA 2 2" ]
[ "1 3\n-1 -1\n", "0 4\n-1 -1\n-1 -1\n0 2\n0 2\n" ]
For the first sample: If the bread goes from (2, 1), it will go out of the table at (1, 3). After changing the conveyor belt of (1, 2) to "&lt;", when the bread goes from (2, 1) again, it will get stuck at "&gt;&lt;", so output is ( - 1,  - 1).
[]
31
0
0
22,558
436
Cardboard Box
[ "data structures", "greedy" ]
null
null
Everyone who has played Cut the Rope knows full well how the gameplay is organized. All levels in the game are divided into boxes. Initially only one box with some levels is available. Player should complete levels to earn stars, collecting stars opens new box with levels. Imagine that you are playing Cut the Rope for the first time. Currently you have only the levels of the first box (by the way, it is called "Cardboard Box"). Each level is characterized by two integers: *a**i* — how long it takes to complete the level for one star, *b**i* — how long it takes to complete the level for two stars (*a**i*<=&lt;<=*b**i*). You want to open the next box as quickly as possible. So, you need to earn at least *w* stars. How do make it happen? Note that the level can be passed only once: either for one star or for two. You do not necessarily need to pass all the levels.
The first line contains two integers *n* and *w* (1<=≤<=*n*<=≤<=3·105; 1<=≤<=*w*<=≤<=2*n*) — the number of levels in the first box and the number of stars you need to open another box. Each of the following *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=109) — the attributes of the *i*-th level.
In the first line print integer *t* — the minimum time you need to open the next box. In the next line, print *n* digits without spaces — the description of the optimal scenario: - if you need to pass the *i*-th level for one star, the *i*-th digit should equal 1; - if you need to pass the *i*-th level for two stars, the *i*-th digit should equal 2; - if you do not need to pass the *i*-th level at all, the *i*-th digit should equal 0.
[ "2 3\n1 2\n1 2\n", "5 3\n10 20\n5 10\n10 20\n6 9\n25 30\n" ]
[ "3\n12\n", "14\n01020\n" ]
In the first test sample, answer 21 is also assumed correct.
[]
30
0
0
22,569
883
Berland Army
[ "constructive algorithms", "graphs", "greedy" ]
null
null
There are *n* military men in the Berland army. Some of them have given orders to other military men by now. Given *m* pairs (*x**i*, *y**i*), meaning that the military man *x**i* gave the *i*-th order to another military man *y**i*. It is time for reform! The Berland Ministry of Defence plans to introduce ranks in the Berland army. Each military man should be assigned a rank — integer number between 1 and *k*, inclusive. Some of them have been already assigned a rank, but the rest of them should get a rank soon. Help the ministry to assign ranks to the rest of the army so that: - for each of *m* orders it is true that the rank of a person giving the order (military man *x**i*) is strictly greater than the rank of a person receiving the order (military man *y**i*); - for each rank from 1 to *k* there is at least one military man with this rank.
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*m*<=≤<=2·105, 1<=≤<=*k*<=≤<=2·105) — number of military men in the Berland army, number of orders and number of ranks. The second line contains *n* integers *r*1,<=*r*2,<=...,<=*r**n*, where *r**i*<=&gt;<=0 (in this case 1<=≤<=*r**i*<=≤<=*k*) means that the *i*-th military man has been already assigned the rank *r**i*; *r**i*<==<=0 means the *i*-th military man doesn't have a rank yet. The following *m* lines contain orders one per line. Each order is described with a line containing two integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). This line means that the *i*-th order was given by the military man *x**i* to the military man *y**i*. For each pair (*x*,<=*y*) of military men there could be several orders from *x* to *y*.
Print *n* integers, where the *i*-th number is the rank of the *i*-th military man. If there are many solutions, print any of them. If there is no solution, print the only number -1.
[ "5 3 3\n0 3 0 0 2\n2 4\n3 4\n3 5\n", "7 6 5\n0 4 5 4 1 0 0\n6 1\n3 6\n3 1\n7 5\n7 1\n7 4\n", "2 2 2\n2 1\n1 2\n2 1\n" ]
[ "1 3 3 2 2 \n", "2 4 5 4 1 3 5 \n", "-1\n" ]
none
[]
46
0
0
22,581
990
Flow Control
[ "dfs and similar", "dp", "greedy", "trees" ]
null
null
You have to handle a very complex water distribution system. The system consists of $n$ junctions and $m$ pipes, $i$-th pipe connects junctions $x_i$ and $y_i$. The only thing you can do is adjusting the pipes. You have to choose $m$ integer numbers $f_1$, $f_2$, ..., $f_m$ and use them as pipe settings. $i$-th pipe will distribute $f_i$ units of water per second from junction $x_i$ to junction $y_i$ (if $f_i$ is negative, then the pipe will distribute $|f_i|$ units of water per second from junction $y_i$ to junction $x_i$). It is allowed to set $f_i$ to any integer from $-2 \cdot 10^9$ to $2 \cdot 10^9$. In order for the system to work properly, there are some constraints: for every $i \in [1, n]$, $i$-th junction has a number $s_i$ associated with it meaning that the difference between incoming and outcoming flow for $i$-th junction must be exactly $s_i$ (if $s_i$ is not negative, then $i$-th junction must receive $s_i$ units of water per second; if it is negative, then $i$-th junction must transfer $|s_i|$ units of water per second to other junctions). Can you choose the integers $f_1$, $f_2$, ..., $f_m$ in such a way that all requirements on incoming and outcoming flows are satisfied?
The first line contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of junctions. The second line contains $n$ integers $s_1, s_2, \dots, s_n$ ($-10^4 \le s_i \le 10^4$) — constraints for the junctions. The third line contains an integer $m$ ($0 \le m \le 2 \cdot 10^5$) — the number of pipes. $i$-th of the next $m$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$, $x_i \ne y_i$) — the description of $i$-th pipe. It is guaranteed that each unordered pair $(x, y)$ will appear no more than once in the input (it means that there won't be any pairs $(x, y)$ or $(y, x)$ after the first occurrence of $(x, y)$). It is guaranteed that for each pair of junctions there exists a path along the pipes connecting them.
If you can choose such integer numbers $f_1, f_2, \dots, f_m$ in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output $m$ lines, $i$-th line should contain $f_i$ — the chosen setting numbers for the pipes. Pipes are numbered in order they appear in the input. Otherwise output "Impossible" in the only line.
[ "4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1\n", "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1\n" ]
[ "Possible\n4\n-6\n8\n-7\n7\n", "Impossible\n" ]
none
[ { "input": "4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Possible\n-3\n-6\n1\n0\n0" }, { "input": "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Impossible" }, { "input": "1\n0\n0", "output": "Possible" }, { "input": "1\n123\n0", "output": "Impossible" }, { "input": "2\n-1 1\n1\n1 2", "output": "Possible\n1" }, { "input": "2\n-1 1\n1\n2 1", "output": "Possible\n-1" } ]
31
0
0
22,603
154
Double Profiles
[ "graphs", "hashing", "sortings" ]
null
null
You have been offered a job in a company developing a large social network. Your first task is connected with searching profiles that most probably belong to the same user. The social network contains *n* registered profiles, numbered from 1 to *n*. Some pairs there are friends (the "friendship" relationship is mutual, that is, if *i* is friends with *j*, then *j* is also friends with *i*). Let's say that profiles *i* and *j* (*i*<=≠<=*j*) are doubles, if for any profile *k* (*k*<=≠<=*i*, *k*<=≠<=*j*) one of the two statements is true: either *k* is friends with *i* and *j*, or *k* isn't friends with either of them. Also, *i* and *j* can be friends or not be friends. Your task is to count the number of different unordered pairs (*i*,<=*j*), such that the profiles *i* and *j* are doubles. Note that the pairs are unordered, that is, pairs (*a*,<=*b*) and (*b*,<=*a*) are considered identical.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*<=≤<=106, 0<=≤<=*m*<=≤<=106), — the number of profiles and the number of pairs of friends, correspondingly. Next *m* lines contains descriptions of pairs of friends in the format "*v* *u*", where *v* and *u* (1<=≤<=*v*,<=*u*<=≤<=*n*,<=*v*<=≠<=*u*) are numbers of profiles that are friends with each other. It is guaranteed that each unordered pair of friends occurs no more than once and no profile is friends with itself.
Print the single integer — the number of unordered pairs of profiles that are doubles. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the %I64d specificator.
[ "3 3\n1 2\n2 3\n1 3\n", "3 0\n", "4 1\n1 3\n" ]
[ "3\n", "3\n", "2\n" ]
In the first and second sample any two profiles are doubles. In the third sample the doubles are pairs of profiles (1, 3) and (2, 4).
[ { "input": "3 3\n1 2\n2 3\n1 3", "output": "3" }, { "input": "3 0", "output": "3" }, { "input": "4 1\n1 3", "output": "2" }, { "input": "1 0", "output": "0" }, { "input": "2 0", "output": "1" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "10 9\n8 3\n3 1\n3 4\n4 10\n4 7\n7 3\n8 4\n10 3\n4 1", "output": "13" }, { "input": "20 50\n2 15\n20 1\n3 16\n3 4\n15 4\n19 3\n11 6\n1 15\n18 19\n12 9\n12 16\n15 12\n2 12\n4 12\n15 14\n14 18\n7 11\n15 3\n6 7\n15 20\n19 15\n16 2\n12 3\n18 3\n19 2\n20 16\n7 13\n2 3\n18 16\n18 12\n14 3\n6 13\n16 14\n19 12\n14 9\n9 15\n12 14\n1 16\n11 13\n19 14\n9 19\n3 9\n14 4\n19 16\n4 16\n16 9\n2 14\n16 15\n4 19\n15 18", "output": "26" }, { "input": "100 50\n52 14\n73 21\n42 58\n80 37\n92 44\n20 52\n76 35\n14 62\n77 59\n81 33\n85 75\n35 5\n4 30\n82 20\n93 25\n28 84\n35 16\n14 85\n65 84\n5 45\n8 79\n58 51\n57 12\n88 69\n82 71\n43 78\n6 20\n37 10\n98 72\n10 77\n47 63\n39 68\n62 30\n56 70\n61 9\n33 24\n53 25\n34 18\n79 3\n59 73\n52 96\n56 74\n38 31\n9 20\n10 85\n94 10\n27 92\n90 95\n12 72\n56 54", "output": "545" }, { "input": "1000 0", "output": "499500" }, { "input": "6666 0", "output": "22214445" }, { "input": "500000 0", "output": "124999750000" }, { "input": "1000000 10\n812866 512688\n465337 450053\n35648 527231\n937971 160561\n467150 1188\n83248 388747\n608511 71844\n447069 373624\n802473 300350\n63052 903606", "output": "499979500220" }, { "input": "1000000 0", "output": "499999500000" }, { "input": "1000000 0", "output": "499999500000" }, { "input": "1000000 4\n1 100\n1 200\n2 131\n2 199", "output": "499993500023" }, { "input": "1000000 4\n3 1\n3 100\n4 2\n4 59", "output": "499993500023" }, { "input": "1000 2\n1 2\n257 258", "output": "495512" } ]
46
0
0
22,620
132
Turing Tape
[ "implementation" ]
null
null
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using the following method. The integers of the array are processed one by one, starting from the first. Processing *i*-th element of the array is done in three steps: 1. The 8-bit binary notation of the ASCII-code of the previous printed character is reversed. When the first element of the array is processed, the result of this step is considered to be 0. 2. The *i*-th element of the array is subtracted from the result of the previous step modulo 256. 3. The binary notation of the result of the previous step is reversed again to produce ASCII-code of the *i*-th character to be printed. You are given the text printed using this method. Restore the array used to produce this text.
The input will consist of a single line *text* which contains the message printed using the described method. String *text* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *text* will be between 32 (space) and 126 (tilde), inclusive.
Output the initial array, which was used to produce *text*, one integer per line.
[ "Hello, World!\n" ]
[ "238\n108\n112\n0\n64\n194\n48\n26\n244\n168\n24\n16\n162\n" ]
Let's have a closer look at the beginning of the example. The first character is "H" with ASCII-code 72 = 01001000<sub class="lower-index">2</sub>. Its reverse is 00010010<sub class="lower-index">2</sub> = 18, and this number should become the result of the second step of processing. The result of the first step is considered to be 0, so the first element of the array has to be (0 - 18) mod 256 = 238, where *a* mod *b* is the remainder of division of *a* by *b*.
[ { "input": "Hello, World!", "output": "238\n108\n112\n0\n64\n194\n48\n26\n244\n168\n24\n16\n162" }, { "input": "N", "output": "142" }, { "input": "!{|aPUBKs[k\"HE;>O&(Nf}N4,*#g*<3sQXFJ'?Z/H9L[xx Rc5\"8~v}84+wv]w[oO0e':MaNy&6*]jRkYomz[o?=13Y?!fzA3eC\\", "output": "124\n166\n160\n184\n124\n96\n104\n112\n4\n244\n4\n146\n50\n112\n198\n96\n138\n142\n80\n162\n12\n168\n76\n70\n248\n224\n144\n222\n146\n24\n112\n254\n68\n112\n184\n16\n110\n232\n162\n102\n226\n118\n106\n88\n188\n0\n26\n186\n132\n26\n104\n40\n158\n16\n176\n162\n240\n88\n230\n128\n180\n204\n20\n228\n4\n230\n102\n194\n136\n170\n44\n20\n212\n58\n248\n24\n154\n100\n12\n116\n60\n164\n64\n88\n132\n228\n250\n64\n48\n192\n50\n158\n120\n30\n8\n220\n182\n38\n228\n136" }, { "input": "!{|aPUBKs[k\"HE;>O&(Nf}N4,*#g*<3sQXFJ'?Z/H9L[xx Rc5\"8~v}84+wv]w", "output": "124\n166\n160\n184\n124\n96\n104\n112\n4\n244\n4\n146\n50\n112\n198\n96\n138\n142\n80\n162\n12\n168\n76\n70\n248\n224\n144\n222\n146\n24\n112\n254\n68\n112\n184\n16\n110\n232\n162\n102\n226\n118\n106\n88\n188\n0\n26\n186\n132\n26\n104\n40\n158\n16\n176\n162\n240\n88\n230\n128\n180\n204" }, { "input": ":J&UY'O]>@Lc\"4ow&?8#yq{s=gH%'`3Yd[CP#", "output": "164\n10\n238\n186\n16\n182\n242\n56\n62\n122\n208\n108\n130\n24\n54\n8\n138\n104\n224\n88\n38\n16\n176\n16\n18\n214\n212\n110\n192\n222\n58\n50\n116\n76\n24\n184\n70" }, { "input": "Py0L_[Ymh&.", "output": "246\n108\n146\n218\n56\n32\n64\n228\n160\n178\n240" }, { "input": "fH9Bh0f|3gn\"7r|*8p[,<]|4Z%2]&E4$/_@\\wI8v4{]/`4uU']fwMjhV|n:GTWUzy+@Nph|em=]|q<)0BR+)k_", "output": "154\n84\n118\n90\n44\n10\n166\n40\n114\n230\n112\n50\n88\n158\n16\n234\n56\n14\n52\n166\n248\n130\n124\n18\n210\n182\n88\n146\n86\n194\n118\n8\n48\n250\n248\n200\n76\n92\n118\n174\n66\n78\n36\n198\n238\n218\n126\n4\n198\n42\n84\n120\n60\n92\n64\n172\n44\n200\n26\n122\n184\n64\n64\n76\n192\n202\n210\n144\n100\n248\n216\n152\n240\n250\n2\n124\n176\n82\n168\n136\n202\n248\n118\n64\n190\n220" }, { "input": "|wB6qdp/]MLcsaTcq*k`ORMsjdW{\"i5gD_@ap*L0.QbDx:pW3-=-;G~#5EeY", "output": "194\n80\n172\n214\n222\n104\n24\n26\n58\n8\n128\n108\n248\n72\n92\n100\n56\n58\n126\n208\n20\n168\n152\n228\n120\n48\n60\n12\n154\n174\n234\n198\n196\n40\n248\n124\n120\n186\n34\n38\n152\n234\n68\n36\n4\n194\n78\n36\n30\n24\n248\n8\n216\n250\n100\n186\n24\n10\n252\n12" }, { "input": "6FH-y7|>'2.AOQ,=JB{9_FzVwB{7\".5NZb=", "output": "148\n10\n80\n94\n22\n178\n174\n194\n152\n152\n216\n242\n144\n104\n86\n120\n106\n16\n100\n66\n162\n152\n4\n244\n124\n172\n100\n242\n168\n208\n200\n58\n24\n20\n138" }, { "input": "LwQ! k*PQ", "output": "206\n68\n100\n6\n128\n46\n130\n74\n128" }, { "input": "bG[w)@4`{YP`e/8O]t@B&2zu8_fo}v6w\"e;sa1(xy4qz]Tb\\VX!hi;iA}-)*HgP*9%.d9KDE^aqk- T~dhq", "output": "186\n100\n8\n236\n90\n146\n214\n38\n40\n68\n144\n4\n96\n178\n216\n42\n56\n140\n44\n192\n222\n24\n238\n176\n146\n34\n148\n112\n56\n80\n2\n126\n170\n158\n202\n14\n72\n250\n120\n246\n128\n114\n158\n48\n164\n144\n228\n12\n208\n80\n150\n110\n128\n186\n70\n20\n196\n10\n32\n64\n66\n44\n220\n182\n184\n248\n48\n78\n138\n202\n176\n128\n40\n244\n248\n184\n34\n176\n218\n172\n88\n16\n136" }, { "input": "xudk2tAoF>1A>~l)7-Pv5'KUF<(-y;7^7e;y^r</tiv,t]`^_%T}Xu#i8c", "output": "226\n112\n136\n80\n138\n30\n172\n140\n148\n230\n240\n10\n6\n254\n72\n162\n168\n56\n170\n156\n194\n200\n18\n40\n72\n38\n40\n96\n22\n194\n240\n114\n142\n70\n202\n62\n36\n44\n18\n72\n198\n152\n40\n58\n6\n116\n180\n140\n128\n86\n122\n108\n164\n108\n234\n46\n122\n86" }, { "input": "K{9`Ud&YydIs8F3'6!<Q.JT'Zt", "output": "46\n244\n66\n150\n92\n132\n194\n202\n252\n120\n148\n196\n178\n186\n150\n232\n120\n232\n72\n178\n22\n34\n40\n70\n138\n44" }, { "input": "aMCT]:0hDJ*Up5g_l:O&>>%gjQkZkb(mi&;\\7dL\"nWOGz/;,6h*@Q0R53MS2<}F~+Ms\\\"cF-lgF0>C&y7)72\\.T\"8*#VO=|^OtYs", "output": "122\n212\n240\n152\n112\n94\n80\n246\n244\n208\n254\n170\n156\n98\n198\n236\n196\n218\n106\n142\n232\n0\n216\n190\n144\n204\n180\n124\n132\n144\n50\n94\n32\n50\n136\n162\n78\n198\n244\n238\n206\n140\n248\n16\n132\n106\n24\n168\n200\n86\n194\n82\n120\n126\n194\n158\n224\n26\n232\n126\n16\n126\n92\n228\n170\n34\n228\n148\n246\n126\n100\n174\n126\n80\n132\n86\n144\n186\n94\n198\n178\n88\n168\n160\n18\n198\n74\n230\n40\n200\n144\n90\n120\n54\n126\n196\n136\n196\n148\n204" }, { "input": "w|LJfn={m/k3M%?9FR_ZQ6TGz21tk')Q~);b3E`8h-TY385-B6aU?il^M%~C6TC$xK*Jr-NTjp6", "output": "18\n176\n12\n224\n236\n240\n186\n222\n40\n194\n30\n10\n26\n14\n168\n96\n58\n24\n80\n160\n208\n30\n66\n72\n132\n18\n192\n94\n88\n242\n80\n10\n12\n234\n184\n150\n122\n42\n156\n234\n6\n98\n138\n144\n206\n176\n112\n248\n114\n214\n230\n220\n174\n102\n96\n188\n200\n14\n38\n188\n86\n66\n104\n158\n6\n76\n126\n2\n4\n154\n66\n72\n212\n72\n162" }, { "input": "1KU>o@I+8qLs'svr kp0c*\"'(nU3gK)71*8h/*uQ_eYmK>3,O", "output": "116\n186\n40\n46\n134\n244\n112\n190\n184\n142\n92\n100\n234\n22\n96\n32\n74\n46\n200\n2\n70\n114\n16\n96\n208\n158\n204\n222\n230\n20\n62\n168\n96\n56\n56\n6\n34\n160\n166\n36\n144\n84\n12\n228\n228\n86\n176\n152\n66" }, { "input": "Gy[5utS:bV+RbbKKX%$ds~Rf", "output": "30\n68\n196\n46\n254\n128\n100\n110\n22\n220\n150\n138\n4\n0\n116\n0\n184\n118\n128\n254\n88\n80\n52\n228" }, { "input": "]Id)~I`L-;k3<R#%2=49'r#FH,=kc1-a\\05s%L>$Tob0zP+0e`B4m]V 7kEt-1>0GGdqIEii^)]~Y$NhZB}cSu!0aUxsZ(;W&D", "output": "70\n40\n108\n146\n22\n236\n140\n212\n126\n216\n6\n10\n144\n242\n134\n32\n88\n144\n144\n144\n184\n150\n138\n98\n80\n222\n120\n230\n16\n58\n216\n46\n76\n46\n96\n222\n42\n114\n182\n88\n250\n52\n176\n58\n174\n84\n54\n200\n102\n160\n196\n22\n118\n252\n80\n102\n24\n22\n52\n116\n122\n40\n16\n112\n42\n0\n188\n152\n252\n240\n12\n0\n28\n230\n218\n60\n228\n118\n178\n92\n188\n24\n132\n248\n252\n28\n42\n120\n134\n220\n140\n80\n116\n70\n56\n242\n134\n66" }, { "input": "swm (}j[V}LsxAW^kVDm7gS)Ula'cT.Hq02y!0S:NHgA3Y&2q.xI\\:lINCp&*g>37Ew_:ot1", "output": "50\n224\n56\n178\n240\n86\n104\n124\n112\n172\n140\n100\n176\n156\n152\n112\n164\n108\n72\n108\n202\n6\n28\n54\n234\n116\n176\n162\n30\n156\n182\n98\n132\n130\n192\n174\n26\n120\n66\n110\n234\n96\n44\n100\n182\n50\n54\n24\n190\n26\n86\n140\n88\n222\n38\n164\n32\n176\n180\n170\n16\n110\n106\n176\n224\n74\n180\n244\n158\n102\n200\n162" }, { "input": "-Jwv-Owk!b.RQ0/8EoWBJ^$heI'Dbx/,'32 yqdSE}lVJb#", "output": "76\n98\n100\n128\n186\n194\n4\n24\n82\n62\n210\n42\n192\n126\n24\n216\n122\n172\n12\n168\n240\n216\n86\n14\n112\n20\n174\n194\n220\n40\n42\n192\n80\n24\n128\n72\n102\n16\n104\n92\n40\n228\n136\n204\n24\n12\n130" }, { "input": "Cx!j6$!}KHn3. cp}(gy\\", "output": "62\n164\n154\n46\n234\n72\n160\n198\n236\n192\n156\n170\n88\n112\n62\n184\n80\n170\n46\n72\n100" }, { "input": "YG'a?Y.-r*Ppjn;JWAwNlG!)$fp|^a0UO60,n7.#:,yxwqx75X\\)*.Wg:'3T!D9>eAQ(q+0HOLqopgxV|Yd8G]MB)|r4enYQ", "output": "102\n184\n254\n94\n138\n98\n38\n192\n102\n250\n74\n252\n184\n224\n154\n138\n104\n104\n148\n124\n60\n84\n94\n240\n112\n190\n88\n208\n196\n244\n122\n98\n184\n134\n96\n216\n190\n138\n120\n176\n104\n40\n150\n128\n48\n96\n112\n50\n64\n146\n224\n166\n64\n224\n138\n4\n138\n120\n24\n162\n166\n98\n134\n32\n214\n36\n248\n118\n134\n186\n200\n250\n32\n192\n164\n152\n232\n40\n200\n180\n44\n164\n116\n10\n58\n40\n8\n112\n174\n86\n240\n34\n134\n48\n220\n16" }, { "input": "y%0f*q5$^F'P'}k_O1sa\"z45:9d<3?n<W#CR 4QbI'[Nl$?3Ynh{=id$RB9!qGLk9aNbWDb`zKV:H&_(7|2Rr'", "output": "98\n250\n152\n166\n18\n198\n226\n136\n170\n24\n126\n218\n38\n38\n232\n220\n8\n102\n190\n72\n66\n230\n50\n128\n80\n192\n118\n234\n112\n208\n134\n58\n82\n38\n2\n120\n70\n216\n162\n68\n180\n174\n10\n104\n60\n18\n40\n48\n50\n36\n96\n56\n34\n38\n112\n2\n218\n8\n166\n24\n246\n172\n176\n92\n58\n22\n20\n44\n92\n200\n220\n64\n168\n140\n104\n14\n74\n174\n106\n230\n40\n174\n242\n2\n252\n106" }, { "input": "1S9\\3CB3)+h.`lC9&J$65ndtJv'V0cn#i&AX{xexC\\`_$)=5e??1+F~Miyd/", "output": "116\n194\n46\n98\n110\n10\n128\n118\n56\n192\n190\n162\n110\n208\n116\n38\n56\n18\n46\n184\n192\n54\n80\n248\n220\n228\n138\n122\n94\n70\n80\n178\n46\n50\n226\n104\n60\n192\n120\n136\n92\n136\n52\n12\n214\n144\n216\n16\n6\n170\n0\n112\n184\n114\n228\n204\n28\n248\n120\n50" }, { "input": "J#@P;xLBSpIo<\\wr_b5jEc5WWVKt/(of~'A", "output": "174\n142\n194\n248\n46\n190\n236\n240\n120\n188\n124\n156\n186\n2\n76\n160\n84\n180\n154\n86\n180\n220\n26\n194\n0\n128\n152\n164\n58\n224\n30\n144\n232\n154\n98" }, { "input": "`TIGAMYU}", "output": "250\n220\n152\n176\n96\n208\n24\n240\n236" }, { "input": "v$R>J\"bdG7k.R:$%q5XwhO2vxs6M+op0J*>gl @d/@o7kD/;)f!pY:hnV`(`fZDyW[?w~')?lnj,be'uW7x'", "output": "146\n74\n218\n206\n42\n14\n254\n32\n68\n246\n22\n98\n42\n238\n56\n128\n22\n226\n146\n44\n216\n36\n166\n222\n80\n80\n98\n186\n222\n222\n232\n2\n186\n254\n216\n150\n176\n50\n2\n220\n50\n242\n12\n10\n22\n180\n46\n24\n72\n46\n226\n118\n116\n62\n70\n160\n12\n100\n242\n14\n160\n12\n56\n132\n180\n16\n222\n14\n112\n154\n80\n152\n198\n192\n32\n34\n238\n160\n194\n54\n196\n254\n206\n58" }, { "input": "-R[2SSovn|Lo+*[^KMhLzCbV&QZh(1pv_-;le`Tz)wtH$M-=57W&Jv 7m8", "output": "76\n106\n112\n142\n130\n0\n212\n136\n248\n56\n12\n60\n34\n128\n122\n96\n168\n32\n156\n228\n212\n156\n124\n220\n6\n218\n48\n68\n2\n136\n126\n160\n116\n70\n216\n166\n144\n160\n220\n204\n202\n166\n192\n28\n238\n114\n254\n248\n16\n192\n2\n134\n18\n228\n106\n24\n54\n154" }, { "input": "F!d)Y(|&9^.Mgx08%fx!.83661 &(UqZ", "output": "158\n222\n94\n146\n250\n134\n214\n218\n200\n34\n6\n194\n204\n200\n18\n240\n120\n62\n72\n154\n16\n88\n80\n96\n0\n224\n136\n160\n80\n106\n28\n52" }, { "input": "\\Pk|a\\'", "output": "198\n48\n52\n152\n184\n76\n86" }, { "input": "r~tsj14H-)Pl|W?J78<*Q$1YSNi^$>r(=35~Vg3ctX&~he BXa;bxjiVW{yCWm;)sU,.GhO}Z/!z|IQdy", "output": "178\n208\n80\n96\n120\n202\n96\n26\n94\n32\n138\n212\n248\n84\n238\n170\n102\n208\n224\n232\n202\n102\n152\n242\n208\n88\n220\n28\n86\n168\n46\n58\n88\n240\n32\n46\n20\n132\n26\n6\n152\n20\n182\n230\n104\n112\n162\n194\n40\n148\n170\n150\n40\n200\n192\n44\n128\n12\n64\n220\n216\n52\n218\n72\n198\n36\n118\n192\n146\n204\n36\n52\n100\n102\n112\n38\n32\n172\n8\n100\n136" }, { "input": ")Q}fse=WWj.MYCs$pQL^aw`9c,,| arjR35%RKG|o0+1!nyDa/qwgD#\"", "output": "108\n10\n204\n88\n152\n40\n234\n210\n0\n148\n226\n194\n24\n216\n244\n170\n22\n132\n88\n184\n244\n152\n232\n106\n214\n146\n0\n246\n58\n126\n56\n248\n12\n126\n32\n8\n90\n120\n240\n164\n72\n234\n56\n72\n8\n14\n216\n124\n156\n146\n102\n160\n8\n196\n94\n128" }, { "input": "I.$n^{GNA'h*uRE9hDHtvJsEw^ 8T?TQW#IKcIi]\",mfu}A@'E}jy#1;)nKzHGOY8u<S!O*]$:QCWv)_kGU:myj0CM{l@hXcYO", "output": "110\n30\n80\n174\n252\n156\n252\n112\n240\n158\n206\n194\n166\n100\n168\n6\n134\n244\n16\n228\n192\n28\n132\n44\n180\n116\n118\n232\n242\n46\n210\n160\n160\n38\n50\n192\n12\n52\n252\n220\n118\n16\n126\n80\n184\n240\n60\n128\n30\n66\n228\n104\n184\n218\n56\n176\n72\n30\n164\n116\n76\n48\n240\n88\n126\n110\n114\n114\n70\n146\n158\n154\n150\n200\n210\n200\n216\n124\n218\n154\n36\n244\n56\n78\n166\n24\n72\n74\n74\n16\n212\n168\n52\n236\n252\n84\n44\n168" }, { "input": "_]-egPQ]jlIjOA|r?]YI*?D%(;DVTcU5l#FQ]-{sxaqw-'>B3rT g`GgCEv,BzL_(sPArv2&", "output": "6\n64\n6\n14\n192\n220\n128\n208\n100\n32\n164\n60\n100\n112\n68\n240\n82\n66\n32\n8\n62\n88\n218\n126\n144\n56\n186\n184\n64\n100\n28\n254\n118\n114\n98\n216\n208\n6\n214\n16\n176\n152\n248\n160\n58\n208\n104\n58\n118\n126\n36\n38\n30\n224\n36\n252\n36\n32\n52\n58\n242\n228\n44\n56\n230\n70\n196\n136\n52\n224\n34\n232" }, { "input": "x,6Yl%^l5Q+H,1QLwvi}:3td8{ipP(U{\"'FWYn0-r:v)E09", "output": "226\n234\n200\n210\n100\n146\n42\n68\n138\n34\n182\n194\n222\n168\n2\n88\n68\n128\n216\n216\n98\n144\n158\n8\n10\n62\n72\n136\n4\n246\n106\n204\n154\n96\n130\n120\n80\n36\n106\n88\n102\n242\n238\n218\n242\n150\n112" }, { "input": "/Z@PuVh~_3k*d )%Q/|RL", "output": "12\n154\n88\n248\n92\n68\n84\n152\n132\n46\n246\n130\n46\n34\n112\n240\n26\n150\n182\n244\n24" }, { "input": "E-ID~,u/*xLjAn]^+H-'_ q'U9SIOpWFJ*AcN4Y[gD!Nt?1GV=6_6T2&-,9]9WFjVo*hI2Q:r[h2qZTN/`<kaa6Biur*KRv]", "output": "94\n238\n34\n112\n164\n74\n134\n186\n160\n54\n236\n220\n212\n12\n188\n64\n166\n194\n94\n208\n234\n246\n118\n170\n58\n14\n210\n56\n160\n228\n36\n136\n16\n254\n210\n188\n84\n70\n146\n192\n244\n196\n158\n18\n68\n50\n112\n170\n120\n174\n80\n114\n142\n66\n222\n232\n176\n128\n152\n226\n30\n178\n136\n12\n236\n116\n162\n62\n132\n70\n194\n46\n14\n116\n196\n202\n190\n52\n48\n184\n126\n238\n202\n102\n80\n0\n26\n42\n172\n232\n96\n250\n130\n136\n220\n180" }, { "input": "^[O;(`~>S]+Hz^58ca=[osBfevxgL2W,_*AiJumta|)_*H,Ibmls%.KRDcdn6.GmDm=W:X", "output": "134\n160\n232\n22\n200\n14\n136\n2\n178\n16\n230\n194\n180\n228\n206\n144\n86\n64\n202\n226\n228\n40\n140\n220\n192\n56\n80\n56\n180\n230\n98\n182\n58\n166\n210\n236\n68\n164\n248\n136\n168\n72\n170\n154\n166\n66\n222\n162\n76\n144\n128\n104\n42\n48\n162\n136\n40\n92\n160\n176\n10\n248\n146\n44\n148\n108\n250\n210\n142\n66" }, { "input": "t+X/.5,P}@k*VMip=yM1#hrFrV:#KUXot->nCY#.YR.qB", "output": "210\n90\n186\n38\n128\n200\n120\n42\n76\n188\n44\n130\n234\n184\n28\n136\n82\n30\n236\n38\n200\n174\n200\n236\n20\n228\n14\n152\n242\n40\n144\n36\n200\n122\n56\n6\n180\n40\n214\n80\n218\n80\n214\n230\n76" }, { "input": "+Ya%7i6_H%Mg0<AJv3`", "output": "44\n58\n20\n226\n184\n86\n42\n114\n232\n110\n242\n204\n218\n208\n186\n48\n228\n162\n198" }, { "input": "A(k{?;Cqri.Hl,x$PLp=EQsf4p%^G>Y:=0;z8{L]M`77q`\"O&8PSR\"6p.G(@.jAxqiz~qswxc~| ,;~<Rw#=XHbQ4=kJV", "output": "126\n110\n62\n248\n226\n32\n26\n52\n64\n184\n34\n98\n220\n2\n22\n250\n26\n216\n36\n82\n26\n24\n188\n104\n58\n30\n106\n42\n152\n102\n226\n62\n160\n176\n48\n126\n66\n62\n172\n120\n8\n172\n26\n0\n94\n136\n194\n82\n142\n72\n18\n64\n128\n6\n216\n94\n154\n146\n206\n18\n142\n30\n212\n100\n144\n248\n56\n224\n240\n192\n224\n208\n88\n72\n64\n58\n208\n88\n94\n66\n242\n92\n42\n8\n162\n8\n204\n188\n94\n112\n230\n132\n232" }, { "input": "ZWtoEoP\"=Ln'EzM\\)d\"qXHAFAQIxDbY!R4;!4``vG5<H)i{M2e'hD^L9H~SN(A>{bg.i", "output": "166\n112\n188\n56\n84\n172\n236\n198\n136\n138\n188\n146\n66\n68\n172\n120\n166\n110\n226\n182\n116\n8\n144\n32\n224\n248\n248\n116\n252\n220\n172\n22\n58\n30\n80\n88\n88\n38\n0\n152\n140\n54\n112\n42\n126\n254\n184\n44\n102\n166\n194\n206\n244\n168\n72\n150\n138\n148\n180\n88\n94\n146\n6\n158\n152\n96\n114\n222" }, { "input": "w7zw3)Vw&h", "output": "18\n2\n142\n112\n34\n56\n42\n124\n138\n78" }, { "input": "1f$k9Zc(PM'D?xVLWm.Y}o$5g`bRxd9Jl$LMAB5mQi$/6\"@N`IimEvs~zp%)xwRL''>3<\"Z!(09DoyGd{EBA", "output": "116\n38\n66\n78\n58\n66\n148\n178\n10\n88\n206\n194\n38\n222\n180\n56\n72\n52\n66\n218\n220\n200\n210\n120\n198\n224\n192\n252\n44\n248\n138\n74\n28\n18\n242\n128\n48\n64\n150\n246\n44\n244\n114\n48\n136\n40\n66\n144\n108\n116\n252\n224\n20\n52\n160\n80\n32\n80\n106\n16\n118\n48\n164\n24\n78\n0\n104\n176\n144\n248\n234\n214\n112\n8\n112\n122\n44\n88\n188\n188\n72\n60\n96\n192" }, { "input": "G5-bB/m7z/h%zh+%1'>11cTtt>%pt)91\"$IS:#I'K?(AN+;Ply@#3S+K2JP", "output": "30\n54\n248\n110\n4\n78\n62\n202\n142\n106\n222\n114\n70\n72\n66\n48\n24\n168\n104\n240\n0\n198\n156\n252\n0\n178\n216\n150\n224\n154\n248\n16\n72\n32\n146\n200\n110\n152\n50\n174\n18\n214\n232\n146\n16\n158\n248\n210\n212\n152\n156\n62\n248\n2\n246\n2\n134\n250\n72" }, { "input": "]d4VJczIDtIbTWb^j?QeAX%T%}I+tL:t8", "output": "70\n148\n250\n194\n24\n140\n104\n204\n112\n244\n156\n76\n28\n64\n164\n204\n36\n90\n114\n228\n36\n104\n118\n122\n134\n230\n44\n190\n166\n252\n214\n46\n18" }, { "input": "s3=MS8%X", "output": "50\n2\n16\n10\n232\n174\n120\n138" }, { "input": "-dFDYl2g9<k%i6np|qqncD\"sC;3dp2;?b*Ge+*'o7\":w3C.S0A\"baGtiz/uki+IZB!,Hdc!_xPP3*]rS<_", "output": "76\n142\n196\n64\n136\n100\n234\n102\n74\n96\n102\n50\n14\n42\n246\n104\n208\n176\n0\n24\n176\n164\n222\n118\n12\n230\n16\n166\n24\n194\n112\n224\n182\n242\n114\n60\n210\n128\n112\n238\n10\n168\n232\n110\n34\n10\n78\n170\n190\n138\n62\n254\n192\n164\n180\n152\n56\n106\n70\n216\n64\n194\n66\n56\n24\n190\n80\n34\n236\n96\n66\n138\n220\n20\n0\n62\n120\n154\n108\n132\n142\n66" }, { "input": "C4O7b?;zc!LbF%FJV*%Cv8RWSxX\"lV;%t*Dj'k<&1W?)JL+T<qXwP%/36", "output": "62\n150\n58\n6\n166\n74\n32\n126\n152\n66\n82\n236\n228\n190\n66\n16\n232\n22\n176\n226\n84\n82\n210\n96\n32\n172\n4\n214\n14\n204\n142\n56\n118\n218\n50\n204\n114\n14\n154\n216\n216\n162\n238\n104\n66\n32\n94\n170\n238\n174\n116\n44\n228\n102\n176\n40\n96" }, { "input": "YbX.ksH*-e.D~sz$0C6x*-#7cX}@lz<", "output": "102\n84\n44\n166\n158\n8\n188\n190\n160\n14\n50\n82\n164\n176\n112\n58\n24\n74\n86\n78\n202\n160\n240\n216\n38\n172\n92\n188\n204\n216\n34" }, { "input": "o2^\"t", "output": "10\n170\n210\n54\n22" }, { "input": ")`hxy|_K\"-Pb5R'6BtY\"Mu$V!ugxhb=6U1A|ttvq|:N`2f}Z_<<W}wxT~JdK]>Al`}{^*FG<jsg\"D>=A", "output": "108\n142\n240\n248\n128\n96\n68\n40\n142\n144\n170\n196\n154\n98\n102\n120\n42\n20\n148\n86\n146\n4\n138\n186\n230\n214\n200\n200\n8\n208\n138\n80\n194\n30\n10\n68\n16\n0\n192\n224\n80\n226\n234\n108\n186\n230\n168\n100\n96\n190\n0\n82\n44\n208\n208\n244\n172\n44\n44\n84\n24\n62\n250\n76\n48\n72\n224\n100\n38\n242\n128\n166\n230\n136\n232\n162\n34\n166\n192\n58" }, { "input": "JAn}d3f?jI'?QaWI:dR7bH", "output": "174\n208\n12\n184\n152\n90\n102\n106\n166\n196\n174\n232\n114\n4\n156\n88\n54\n54\n220\n94\n166\n52" } ]
154
307,200
-1
22,658
67
Partial Teacher
[ "dp", "graphs", "greedy", "implementation" ]
A. Partial Teacher
1
256
A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees. He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks they get the same number of toffees. The same procedure is followed for each pair of adjacent students starting from the first one to the last one. It is given that each student receives at least one toffee. You have to find the number of toffees given to each student by the teacher such that the total number of toffees is minimum.
The first line of input contains the number of students *n* (2<=≤<=*n*<=≤<=1000). The second line gives (*n*<=-<=1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal marks.
Output consists of *n* integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one.
[ "5\nLRLR\n", "5\n=RRR\n" ]
[ "2 1 2 1 2\n", "1 1 2 3 4\n" ]
none
[ { "input": "5\nLRLR", "output": "2 1 2 1 2" }, { "input": "5\n=RRR", "output": "1 1 2 3 4" }, { "input": "6\nRLRL=", "output": "1 2 1 2 1 1" }, { "input": "3\nR=", "output": "1 2 2" }, { "input": "7\nRR==RR", "output": "1 2 3 3 3 4 5" }, { "input": "166\nR===RL=LRRR=RRRL=LRR=R=RR==L=R=R=RRR=RR=RLLRRL=LLRL==L=R==RLR==RL=RR=LR==R=R=LLRLRLR=RR=RLLRLR=RRLL==L=LR=RR=RRRL=RLLLR==L=RRLRLLLLLLLRL===LRLRLRLRRLL=LRLL===LRLRR==", "output": "1 2 2 2 2 3 2 2 1 2 3 4 4 5 6 7 2 2 1 2 3 3 4 4 5 6 6 6 1 1 2 2 3 3 4 5 6 6 7 8 8 9 2 1 2 4 3 3 2 1 3 2 2 2 1 1 2 2 2 3 1 2 2 2 3 1 1 2 3 3 1 2 2 2 3 3 4 4 2 1 2 1 2 1 2 2 3 4 4 5 2 1 2 1 2 2 3 5 4 3 3 3 2 2 1 2 2 3 4 4 5 6 7 1 1 4 3 2 1 2 2 2 1 1 2 3 1 8 7 6 5 4 3 2 1 3 2 2 2 2 1 2 1 2 1 2 1 2 4 3 2 2 1 4 3 2 2 2 2 1 2 1 2 3 3 3" }, { "input": "333\nLL=LR=R=RRR=L=LRR=RLRLLLR=LRL=RRLRRRLLRRLL====RL=L====LLRL=RR==L==RLL==L=R=RLRR==LRRL=LRL=RLRLRR=R=LR=LLR===LRL=RRL====R==LRLR===LLLLL=LLLRLRLLLLLL==RLL=RL==LR=RRLRLL=R=R=R=RLRLRLLRRL==L==LRR=L=R=R===RLR=R=L=LR=LRLRR=RRL=L=RRLR=RRL=RRRL=RLRRRLLLRR=RRRLRLLLR==RR=RL===R=RL=RLL====RRRR=LR=LL=RL==RRLR====R=L=R==L=R=R=RLR=RR=R=LRRRRLLL", "output": "4 3 2 2 1 2 2 3 3 4 5 6 6 2 2 1 2 3 3 4 1 4 3 2 1 2 2 1 2 1 1 2 3 1 2 3 4 2 1 2 3 2 1 1 1 1 1 5 4 4 3 3 3 3 3 2 1 2 1 1 2 3 3 3 1 1 1 4 3 2 2 2 1 1 2 2 3 1 2 3 3 3 1 2 3 2 2 1 2 1 1 2 1 2 1 2 3 3 4 4 1 3 3 2 1 2 2 2 2 1 2 1 1 2 3 1 1 1 1 1 2 2 2 1 2 1 9 9 9 9 8 7 6 5 4 4 3 2 1 2 1 7 6 5 4 3 2 1 1 1 3 2 1 1 3 2 2 2 1 2 2 3 4 1 3 2 1 1 2 2 3 3 4 4 5 1 2 1 3 2 1 2 4 3 3 3 2 2 2 1 2 3 3 1 1 2 2 3 3 3 3 4 1 2 2 3 3 2 2 1 2 2 1 2 1 2 3 3 4 5 2 2 1 1 2 3 1 2 2 3 4 1 1 2 3 4 1 1 2 1 2 3 4 3 2 1 2 3 3 4 5 6 1 4 3 2..." }, { "input": "24\nR=R==RL=RL=RLL=LLL=LLRL", "output": "1 2 2 3 3 3 4 1 1 2 1 1 8 7 6 6 5 4 3 3 2 1 2 1" }, { "input": "438\nLR=RLLLRL=R==LLR=RRLRRR==RLRLRLLRRRRRLRL=RRRRLRR==RR=RR=LLRR=L=LLRRRLLR==RL=L=LLR=L=R==LLR=L=RR==LRL=LLL=RRR=R=LRLLRLLLR==LRRLLL=L==LLR=RL=LLLLR=RR=LR=RL==LRLRR=RRRRRLRLRR==RR=LLLRLR====LRRLL==LR==LL=LLRR=LRL=RRRRLR=RLLR=R=LLLRRRRR===R==LRLLRLR=LLL=L=L=R=RLLR=R=RR=RL=LLRRLLRR=LRRRR==LR==L==R=L=L=R===LLL=LL==L=L=LLLLL==RRRR==R=RLL=RLR=RRRR=R=L=RRRLLRRLRRRLLRLLRRRL=LR=R=LRLRL=R=RLRRLRRL==R=RRR=RLLR=RR=LL=RLR=R==R===RRLR=LLLR=L===LR=L=R", "output": "2 1 2 2 4 3 2 1 2 1 1 3 3 3 2 1 2 2 3 4 1 2 3 4 4 4 5 1 2 1 3 2 1 2 3 4 5 6 1 2 1 1 2 3 4 5 1 2 3 3 3 4 5 5 6 7 7 2 1 2 4 4 3 3 2 1 2 3 4 2 1 2 2 2 5 4 4 3 3 2 1 2 2 1 1 3 3 3 2 1 2 2 1 1 2 3 3 3 1 5 4 4 3 2 1 1 2 3 4 4 5 5 1 3 2 1 4 3 2 1 2 2 2 1 2 7 6 5 4 4 3 3 3 2 1 2 2 6 5 5 4 3 2 1 2 2 3 4 4 1 2 2 3 2 2 2 1 2 1 2 3 3 4 5 6 7 8 1 2 1 2 3 3 3 4 5 5 3 2 1 2 1 2 2 2 2 2 1 2 4 3 2 2 2 1 5 5 5 4 3 3 2 1 2 3 3 1 2 1 1 2 3 4 5 1 2 2 3 2 1 2 2 4 4 3 2 1 2 3 4 5 6 6 6 6 7 7 7 1 3 2 1 2 1 6 6 5 4 3 3 2 2 1 1 2 2..." }, { "input": "453\nR==LL==RRLLRRLR=L=LRLL=LRRR=R====L=RL======RR==RRRR=LRR=LLLRR=LLLLL===LL=LLL=LR=RLRL===L==R=LRL=L=R==RRLLR=L==LRR=RRLRLLRR=LL==RLRLLRRRL=RRL=R====L=RLRR=RR=RRRL=R=RL=LLR=LR=L=RR=RR====LRRLRRLLR==R==L==RRLLRLR=RLLLLR==L=L=L=RR==L=LRRRL=R==RRL=LRR=RRRRRL===RLRLR=RLRLRLRLRR=RL=LL=RLLRR=LL=RLL=L=LRLLLLLR==RRL=R=L===LRLLL=RRRLR=LR====RR=L===LLLL=R=LLLRRRLL=LL==RLRL=LRLRL=RR=RLR==LLR=LR=RLLRLRRLL==L=LL==L==RLRLRLL=L=RLLR==LLRRLRRL==L=R=RLLRLLLL====L=====", "output": "1 3 3 3 2 1 1 1 2 3 2 1 2 3 1 3 3 2 2 1 4 3 2 2 1 2 3 4 4 5 5 5 5 5 1 1 2 1 1 1 1 1 1 1 2 3 3 3 4 5 6 7 7 1 2 4 4 3 2 1 2 12 12 11 10 9 8 7 7 7 7 6 5 5 4 3 2 2 1 2 2 3 1 3 2 2 2 2 1 1 1 2 2 1 3 2 2 1 1 2 2 2 3 4 2 1 3 3 2 2 2 1 2 3 3 4 5 1 3 2 1 2 3 3 2 1 1 1 2 1 3 2 1 2 3 4 1 1 2 3 1 1 2 2 2 2 2 1 1 2 1 2 3 3 4 5 5 6 7 8 1 1 2 2 4 3 3 2 1 2 2 1 2 2 1 1 2 3 3 4 5 5 5 5 5 1 2 3 1 2 3 2 1 2 2 2 3 3 3 1 1 1 2 3 2 1 2 1 2 2 5 4 3 2 1 4 4 4 3 3 2 2 1 1 2 3 3 3 2 2 1 2 3 4 1 1 2 2 2 3 4 2 2 1 2 3 3 4 5 6 7 8 1 1..." }, { "input": "100\n=L=L=L=R=LR=RRRLRL=LRL=RRLLLLRL=R==R=LLLRR===RR=LR==LRLR===RRLRLLRLLR=LRLRR=L=LRRLLLRR==LLRLLLL==RL", "output": "4 4 3 3 2 2 1 1 2 2 1 2 2 3 4 5 1 3 2 2 1 2 1 1 2 5 4 3 2 1 2 1 1 2 2 2 4 4 3 2 1 2 3 3 3 3 4 5 5 1 2 2 2 1 2 1 2 2 2 2 3 4 1 3 2 1 3 2 1 2 2 1 2 1 2 3 3 2 2 1 2 4 3 2 1 2 3 3 3 2 1 5 4 3 2 1 1 1 2 1" }, { "input": "484\nLLRRRL==RRLRRLR=LRR=RL=LLLRL===RLRRRLRR=RRRL=LLLLRL==RL==R==LLLRL=RLLRLRLLLLLLLRRLL=LLR=LLR==RLL==LLLR=RL==LL=LRRL=LLRRRLR====R=R=LRRRLLL==RLRRLR=LL==LLRLR===RR=LR==RL==L==R====LRL=LR=R=R=R=LL=L=RLR=RL==R==LRLRL==L==LL=LR=L=RRRR=R==RRLRRRLR==R=LL===R===RLRRR===LRRLLRRRRR=L==LLRRRRLRRRLL===L==LR==LR==RRLRRLRLLLL=RRL=L=LLLRLRRLLL=LRRRRLLLR=L=LL=LRLL=R==L=LRR=R=LLLRR=LRRRLR=R=RLLRR=LRL===LL==LR===L=L=L=RLL=LRRL=LL==RL==RRL====RR=L=R==L==RRL=LLRLR=RLLLL==R==RRL=====LR=RRR=LRLRRR=RLR", "output": "3 2 1 2 3 4 1 1 1 2 3 1 2 3 1 2 2 1 2 3 3 5 4 4 3 2 1 2 1 1 1 1 2 1 2 3 4 1 2 3 3 4 5 6 5 5 4 3 2 1 2 1 1 1 2 1 1 1 4 4 4 3 2 1 2 1 1 3 2 1 2 1 8 7 6 5 4 3 2 1 2 5 4 3 3 2 1 3 3 2 1 2 2 2 6 5 4 4 4 3 2 1 2 2 5 4 4 4 3 2 2 1 2 4 3 3 2 1 2 3 4 1 2 2 2 2 2 3 3 4 4 1 2 3 4 3 2 1 1 1 2 1 2 3 1 5 5 4 3 3 3 2 1 2 1 2 2 2 2 3 4 4 1 2 2 2 3 2 2 2 1 1 1 2 2 2 2 2 1 3 2 2 1 2 2 3 3 4 4 5 5 3 2 2 1 1 2 1 2 2 3 1 1 1 2 2 2 1 2 1 6 5 5 5 4 4 4 3 2 2 1 2 2 1 1 2 3 4 5 5 6 6 6 7 8 1 2 3 4 1 2 2 2 3 3 2 1 1 1 1 2 2 2 2 3 1..." }, { "input": "338\n==R===L=RLRLR===RR=RRL==R=R=RLRLLRLRRRLR=LR=RR=RLLRR=RRRLLRLL=RRRRRLRLLLL=RLLRLLLRL===RRR=RRLLR=LLLL===RLL==LRLLLLRLLLLR=====RLRLRLRL=L==RRLL=RLL===LL=R=RRL=LL=L==RRLLR=LLRLL=LL=LL==RRLR=L=RLLL=LRLLLRRLR=RL=RR=R=L==RLRLL=LRRLLLLLL=RRL==RLL==R===LR===LRLRLR==LR=RR==RR=RRRRRLRRRLRLLRRRLL=LR=RRR=RL=R=LRRLR==RRR=LLL===RR=RL==RRLLL=RL=L=RLL", "output": "1 1 1 2 2 2 2 1 1 2 1 2 1 2 2 2 2 3 4 4 5 6 1 1 1 2 2 3 3 4 1 3 2 1 2 1 2 3 4 1 2 2 1 2 2 3 4 4 5 2 1 2 3 3 4 5 6 2 1 3 2 1 1 2 3 4 5 6 1 5 4 3 2 1 1 3 2 1 4 3 2 1 2 1 1 1 1 2 3 4 4 5 6 2 1 5 5 4 3 2 1 1 1 1 4 3 2 2 2 1 5 4 3 2 1 5 4 3 2 1 2 2 2 2 2 2 3 1 2 1 2 1 3 2 2 1 1 1 2 3 2 1 1 5 4 3 3 3 3 2 1 1 2 2 3 5 4 4 3 2 2 1 1 1 2 3 2 1 3 3 2 1 7 6 5 5 4 3 3 2 1 1 1 2 3 1 2 2 1 1 5 4 3 2 2 1 4 3 2 1 2 3 1 2 2 3 1 1 2 3 3 4 4 1 1 1 2 1 4 3 2 2 1 2 7 6 5 4 3 2 1 1 2 3 1 1 1 3 2 1 1 1 2 2 2 2 1 2 2 2 2 1 2 1 2 1..." }, { "input": "198\nLLRRR=RRRRLRRLRR=R===R=RL==R=RLLLR=R=L=LR=R====RRL=RRR=LL=R=RR=RRRLRRLRRR==L=LRLLL====LR=RL==L===LRR=L=L==R==R==L=LLL===R=LLL=R=L=LLLLRLL=RL=LRRLR=RL==RR=R==RLR==R=R==RLRL=LL=RRR=R===LLLRRRRL=RLRLL", "output": "3 2 1 2 3 4 4 5 6 7 8 1 2 3 1 2 3 3 4 4 4 4 5 5 6 1 1 1 2 2 4 3 2 1 2 2 3 3 2 2 1 2 2 3 3 3 3 3 4 5 1 1 2 3 4 4 2 1 1 2 2 3 4 4 5 6 7 1 2 3 1 2 3 4 4 4 2 2 1 5 4 3 2 2 2 2 2 1 2 2 4 3 3 3 2 2 2 2 1 2 3 3 2 2 1 1 1 2 2 2 5 5 5 4 4 3 2 1 1 1 1 4 4 3 2 1 1 6 6 5 5 4 3 2 1 3 2 1 1 3 2 2 1 2 3 1 2 2 3 1 1 1 2 3 3 4 4 4 5 1 2 2 2 3 3 4 4 4 5 1 4 3 3 2 1 1 2 3 4 4 5 5 5 5 3 2 1 2 3 4 5 1 1 2 1 3 2 1" }, { "input": "426\nR==LRRRL=R==LLRRRLRLLLR=====R=RRRLLR==LL=L=RR=L=L==LRRR=LL=RR=LRRRLRLLR=R==RL=RRL===RRRL=RLRRRRRLRLLR=LR==LL=R=RRRLRLLLRL=L=RL=R==L==RRLLRRR=RRR==RL=====R=R==RLR=R==L==RL=RRR=RLL=L=LL=RLLR===R=RL==LR=LRLLLR==L==LR=RLLLRRRRL=RRRL=RL=LR=====R=RR=L=RL==L=LLRL=LL=L==LR=RLLRR=RLRLR=LRLLRR===L===RLL=RR==RR=R====RRLR=L=RLRLRLLRLLL=R=R=LLLRRRLR=L==L=R==LLR=L=L==RRLR=LR=R=LR=RR=R=LLRL=L=R=LLLLLR==L=LR=R=L=LL==LRR=L===RL==LL==R==RL", "output": "1 2 2 2 1 2 3 4 1 1 3 3 3 2 1 2 3 4 1 4 3 2 1 2 2 2 2 2 2 3 3 4 5 6 2 1 4 4 4 3 2 2 1 1 2 4 4 3 3 2 2 2 1 2 3 4 4 2 1 1 2 3 3 1 2 3 4 1 3 2 1 2 2 3 3 3 4 1 1 2 3 1 1 1 1 2 3 4 1 1 2 1 2 3 4 5 6 1 3 2 1 2 2 1 3 3 3 2 1 1 2 2 3 4 5 1 4 3 2 1 3 2 2 1 1 2 1 1 2 2 2 1 1 1 2 3 2 1 2 3 4 4 5 6 7 7 7 8 1 1 1 1 1 1 2 2 3 3 3 4 1 2 2 3 3 3 1 1 1 2 1 1 2 3 4 4 6 5 4 4 3 3 2 1 1 3 2 1 2 2 2 2 3 3 4 2 2 2 1 2 2 1 4 3 2 1 3 3 3 2 2 2 1 2 2 4 3 2 1 2 3 4 5 1 1 2 3 4 1 1 3 2 2 1 2 2 2 2 2 2 3 3 4 5 5 1 1 5 4 4 4 3 3 2 1 6..." }, { "input": "10\nRL=R=RLR=", "output": "1 2 1 1 2 2 3 1 2 2" }, { "input": "2\nL", "output": "2 1" }, { "input": "100\nR=R=RRR=R=RR=RRLL=RLRLLLLLR==L=======L=LLR==RL=R=LRLLLR==LLLL=RRRL=LRL=LR=====L=LLLRRL=LLR===RLR=RR", "output": "1 2 2 3 3 4 5 6 6 7 7 8 9 9 10 11 2 1 1 2 1 6 5 4 3 2 1 5 5 5 4 4 4 4 4 4 4 4 3 3 2 1 2 2 2 3 1 1 2 2 1 4 3 2 1 5 5 5 4 3 2 1 1 2 3 4 2 2 1 3 2 2 1 5 5 5 5 5 5 4 4 3 2 1 2 4 3 3 2 1 2 2 2 2 3 1 2 2 3 4" }, { "input": "23\nL=LLLLRL=RR=RLLLL=RR==", "output": "6 5 5 4 3 2 1 2 1 1 2 3 3 5 4 3 2 1 1 2 3 3 3" }, { "input": "432\n=R=RRL=LLR=LLRLLRL=RL==R===L===LR=RR=LL==RLRLRRL=LRL=RLLRRLLL==RLLR=LLLRL=RLRRLLRRL=RLRRL=LL=RR=RL==LL===R==RR=LLL=RRR===R=RLLLR====R==RL=LRL=LLRLRLLRL=LLR==R==LLLL===R=R=LR=L=LRR=LR==LLL=L=LR=R=RLR=L=R==L=RLLLRR=R===R==L==R===L=RLLRLLLLLLL=LRRL=LLLL=RR==R===RR=LLLLRLRL==R====LR==LRL=L=R=R=L====LRLRL=RRR=RRRL====R=LRLRL===LRLLLR==R==LL=R==L==L=LRRRL==LL=R=L=LL=RRRLLRLRL==LLR===RRR=RRLRRR=R=RL===L=RRRR=R=RL===R==L===LLR=LLRLLLRL", "output": "1 1 2 2 3 4 3 3 2 1 3 3 2 1 3 2 1 2 1 1 2 1 1 1 3 3 3 3 2 2 2 2 1 2 2 3 4 4 2 1 1 1 2 1 2 1 2 3 2 2 1 2 1 1 3 2 1 2 4 3 2 1 1 1 3 2 1 4 4 3 2 1 2 1 1 2 1 2 3 2 1 2 3 1 1 2 1 2 4 3 3 2 1 1 2 3 3 4 3 3 3 2 1 1 1 1 2 2 2 3 4 4 3 2 1 1 2 3 4 4 4 4 5 5 6 3 2 1 2 2 2 2 2 3 3 3 4 2 2 1 4 3 3 2 1 2 1 3 2 1 4 3 3 2 1 2 2 2 5 5 5 4 3 2 1 1 1 1 2 2 3 3 1 3 3 2 2 1 2 3 3 1 6 6 6 5 4 3 3 2 2 1 2 2 3 3 4 1 2 2 1 1 2 2 2 1 1 4 3 2 1 2 3 3 4 4 4 4 5 5 5 1 1 1 2 2 2 2 1 1 3 2 1 9 8 7 6 5 4 3 2 2 1 2 6 5 5 4 3 2 1 1 2 3 3 3..." }, { "input": "4\nRRL", "output": "1 2 3 1" }, { "input": "17\n=RRR=L==LLLLRRRL", "output": "1 1 2 3 6 6 5 5 5 4 3 2 1 2 3 4 1" }, { "input": "20\nRRLLLLLRRRRRRRRLRLR", "output": "1 2 6 5 4 3 2 1 2 3 4 5 6 7 8 9 1 2 1 2" }, { "input": "9\nR===RRLL", "output": "1 2 2 2 2 3 4 2 1" }, { "input": "15\n=RRR=LLLLLRRRL", "output": "1 1 2 3 6 6 5 4 3 2 1 2 3 4 1" } ]
310
1,945,600
3.841376
22,671
954
Water Taps
[ "binary search", "greedy", "sortings" ]
null
null
Consider a system of *n* water taps all pouring water into the same container. The *i*-th water tap can be set to deliver any amount of water from 0 to *a**i* ml per second (this amount may be a real number). The water delivered by *i*-th tap has temperature *t**i*. If for every you set *i*-th tap to deliver exactly *x**i* ml of water per second, then the resulting temperature of water will be (if , then to avoid division by zero we state that the resulting water temperature is 0). You have to set all the water taps in such a way that the resulting temperature is exactly *T*. What is the maximum amount of water you may get per second if its temperature has to be *T*?
The first line contains two integers *n* and *T* (1<=≤<=*n*<=≤<=200000, 1<=≤<=*T*<=≤<=106) — the number of water taps and the desired temperature of water, respectively. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) where *a**i* is the maximum amount of water *i*-th tap can deliver per second. The third line contains *n* integers *t*1, *t*2, ..., *t**n* (1<=≤<=*t**i*<=≤<=106) — the temperature of water each tap delivers.
Print the maximum possible amount of water with temperature exactly *T* you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0). Your answer is considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
[ "2 100\n3 10\n50 150\n", "3 9\n5 5 30\n6 6 10\n", "2 12\n1 3\n10 15\n" ]
[ "6.000000000000000\n", "40.000000000000000\n", "1.666666666666667\n" ]
none
[ { "input": "2 100\n3 10\n50 150", "output": "6.000000000000000" }, { "input": "3 9\n5 5 30\n6 6 10", "output": "40.000000000000000" }, { "input": "2 12\n1 3\n10 15", "output": "1.666666666666667" }, { "input": "20 30\n70 97 14 31 83 22 83 56 19 87 59 7 7 89 24 82 34 40 6 24\n10 4 47 46 11 18 32 55 16 32 53 37 43 32 41 46 57 14 60 44", "output": "916.518518518518519" }, { "input": "1 1\n1000000\n1", "output": "1000000.000000000000000" }, { "input": "1 200\n1000000\n100", "output": "0.000000000000057" }, { "input": "1 1000000\n1000000\n1000000", "output": "999999.999999999944407" } ]
0
0
-1
22,684
482
Game with Strings
[ "bitmasks", "dp", "probabilities" ]
null
null
You play the game with your friend. The description of this game is listed below. Your friend creates *n* distinct strings of the same length *m* and tells you all the strings. Then he randomly chooses one of them. He chooses strings equiprobably, i.e. the probability of choosing each of the *n* strings equals . You want to guess which string was chosen by your friend. In order to guess what string your friend has chosen, you are allowed to ask him questions. Each question has the following form: «What character stands on position *pos* in the string you have chosen?» A string is considered guessed when the answers to the given questions uniquely identify the string. After the string is guessed, you stop asking questions. You do not have a particular strategy, so as each question you equiprobably ask about a position that hasn't been yet mentioned. Your task is to determine the expected number of questions needed to guess the string chosen by your friend.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=50) — the number of strings your friend came up with. The next *n* lines contain the strings that your friend has created. It is guaranteed that all the strings are distinct and only consist of large and small English letters. Besides, the lengths of all strings are the same and are between 1 to 20 inclusive.
Print the single number — the expected value. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
[ "2\naab\naac\n", "3\naaA\naBa\nCaa\n", "3\naca\nvac\nwqq\n" ]
[ "2.000000000000000\n", "1.666666666666667\n", "1.000000000000000\n" ]
In the first sample the strings only differ in the character in the third position. So only the following situations are possible: - you guess the string in one question. The event's probability is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/adaad783a304f9e72218e6e79114c6551a112aad.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - you guess the string in two questions. The event's probability is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/caddcdaf0d707d9e4ffa41e63e462a3c90474546.png" style="max-width: 100.0%;max-height: 100.0%;"/> · <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6bb1686dc4a3e6a10e00b92d434455668cb330a8.png" style="max-width: 100.0%;max-height: 100.0%;"/> = <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/adaad783a304f9e72218e6e79114c6551a112aad.png" style="max-width: 100.0%;max-height: 100.0%;"/> (as in this case the first question should ask about the position that is other than the third one); - you guess the string in three questions. The event's probability is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/caddcdaf0d707d9e4ffa41e63e462a3c90474546.png" style="max-width: 100.0%;max-height: 100.0%;"/> · <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6bb1686dc4a3e6a10e00b92d434455668cb330a8.png" style="max-width: 100.0%;max-height: 100.0%;"/> · <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a53d50910d43b79b6602f97f9fde950c9d1bdf77.png" style="max-width: 100.0%;max-height: 100.0%;"/> = <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/adaad783a304f9e72218e6e79114c6551a112aad.png" style="max-width: 100.0%;max-height: 100.0%;"/>; Thus, the expected value is equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5f789afab0601bacf9123c73584184ef358740fb.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second sample we need at most two questions as any pair of questions uniquely identifies the string. So the expected number of questions is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/208df5d4b6316ba263eede5d4cf4b844075718f1.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the third sample whatever position we ask about in the first question, we immediately identify the string.
[]
1,000
183,398,400
0
22,751
294
Shaass and Bookshelf
[ "dp", "greedy" ]
null
null
Shaass has *n* books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the *i*-th book is *t**i* and its pages' width is equal to *w**i*. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the books on the bookshelf in the following way. First he selects some of the books and put them vertically. Then he puts the rest of the books horizontally above the vertical books. The sum of the widths of the horizontal books must be no more than the total thickness of the vertical books. A sample arrangement of the books is depicted in the figure. Help Shaass to find the minimum total thickness of the vertical books that we can achieve.
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). Each of the next *n* lines contains two integers *t**i* and *w**i* denoting the thickness and width of the *i*-th book correspondingly, (1<=≤<=*t**i*<=≤<=2,<=1<=≤<=*w**i*<=≤<=100).
On the only line of the output print the minimum total thickness of the vertical books that we can achieve.
[ "5\n1 12\n1 3\n2 15\n2 5\n2 1\n", "3\n1 10\n2 1\n2 4\n" ]
[ "5\n", "3\n" ]
none
[ { "input": "5\n1 12\n1 3\n2 15\n2 5\n2 1", "output": "5" }, { "input": "3\n1 10\n2 1\n2 4", "output": "3" }, { "input": "10\n2 10\n2 4\n2 8\n2 3\n2 5\n2 6\n1 2\n1 10\n1 10\n2 5", "output": "12" }, { "input": "1\n2 7", "output": "2" }, { "input": "50\n1 24\n1 16\n1 33\n2 34\n1 26\n2 35\n1 39\n2 44\n2 29\n2 28\n1 44\n2 48\n2 50\n2 41\n2 9\n1 22\n2 11\n2 27\n1 12\n1 50\n2 49\n1 17\n2 43\n2 6\n1 39\n2 28\n1 47\n1 45\n2 32\n1 43\n2 40\n1 10\n1 44\n2 31\n2 26\n2 15\n2 20\n1 49\n1 36\n2 43\n2 8\n1 46\n2 43\n2 26\n1 30\n1 23\n2 26\n1 32\n2 25\n2 42", "output": "67" }, { "input": "20\n2 4\n1 2\n2 2\n1 2\n2 1\n1 3\n2 5\n1 3\n1 1\n2 3\n1 4\n2 3\n1 5\n1 4\n1 4\n1 2\n2 5\n1 5\n2 2\n2 2", "output": "16" }, { "input": "30\n1 48\n1 3\n2 20\n2 41\n1 33\n2 46\n2 22\n2 21\n1 6\n2 44\n1 23\n2 28\n1 39\n1 19\n2 15\n2 49\n1 26\n1 22\n2 42\n2 27\n2 31\n1 49\n1 11\n1 33\n1 1\n2 31\n2 9\n1 18\n2 27\n1 18", "output": "38" }, { "input": "40\n2 14\n1 13\n1 51\n2 18\n2 99\n2 85\n1 37\n2 54\n2 82\n1 93\n1 71\n1 76\n1 40\n2 14\n1 61\n1 74\n2 83\n2 75\n1 12\n1 23\n1 95\n1 84\n2 90\n1 40\n1 96\n2 25\n2 68\n2 87\n2 34\n2 66\n2 60\n2 65\n2 18\n2 48\n1 97\n2 71\n1 94\n1 5\n1 47\n1 29", "output": "53" }, { "input": "1\n1 1", "output": "1" }, { "input": "1\n1 2", "output": "1" }, { "input": "2\n1 2\n2 2", "output": "2" }, { "input": "100\n2 2\n1 2\n1 1\n2 1\n1 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n2 2\n2 1\n1 1\n1 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 2\n1 2\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n1 2\n2 2\n1 2\n1 1\n1 1\n1 1\n2 1\n2 1\n1 2\n1 2\n2 2\n1 2\n1 2\n1 1\n2 1\n2 1\n2 2\n1 2\n2 1\n1 1\n2 1\n1 2\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 1\n1 2\n2 1\n1 1\n1 1\n2 2\n2 2\n1 1\n2 1\n1 2\n2 2\n2 1\n1 2\n1 2\n1 2\n1 1\n2 1", "output": "60" }, { "input": "100\n2 2\n1 2\n1 5\n1 5\n1 2\n1 4\n2 3\n1 2\n1 5\n2 1\n2 2\n2 4\n1 2\n2 3\n1 1\n1 1\n2 5\n2 3\n2 2\n1 2\n2 1\n2 2\n1 5\n2 1\n2 4\n1 4\n1 4\n2 2\n1 1\n2 4\n1 4\n2 4\n1 2\n2 3\n2 3\n1 5\n1 5\n2 3\n1 4\n1 5\n2 2\n1 3\n2 2\n2 2\n1 1\n2 1\n2 5\n1 1\n2 3\n2 5\n1 5\n1 3\n1 5\n2 4\n1 5\n2 3\n2 5\n1 4\n2 3\n2 2\n2 5\n2 4\n1 1\n1 1\n1 3\n2 3\n2 1\n2 1\n1 2\n1 1\n2 5\n2 2\n2 1\n2 3\n2 2\n1 5\n1 2\n1 2\n1 1\n1 2\n1 4\n1 5\n1 4\n1 3\n1 1\n1 2\n2 2\n2 4\n1 2\n1 1\n2 3\n2 3\n2 5\n2 1\n1 5\n1 5\n1 4\n2 2\n1 4\n2 4", "output": "76" }, { "input": "50\n1 69\n2 39\n1 32\n2 35\n1 25\n2 24\n1 59\n2 99\n2 48\n2 54\n1 87\n1 81\n2 42\n2 8\n2 92\n1 78\n2 70\n2 91\n1 86\n1 87\n2 15\n1 93\n1 82\n2 36\n1 12\n1 56\n2 84\n1 98\n1 89\n2 79\n1 22\n1 65\n1 40\n2 13\n2 95\n2 93\n1 9\n2 99\n2 100\n1 76\n2 56\n1 10\n1 2\n2 93\n2 21\n2 33\n1 21\n1 81\n2 10\n2 93", "output": "66" }, { "input": "10\n1 61\n1 92\n2 97\n1 70\n2 37\n2 44\n2 29\n1 94\n2 65\n1 48", "output": "15" }, { "input": "40\n2 14\n1 13\n1 51\n2 18\n2 99\n2 85\n1 37\n2 54\n2 82\n1 93\n1 71\n1 76\n1 40\n2 14\n1 61\n1 74\n2 83\n2 75\n1 12\n1 23\n1 95\n1 84\n2 90\n1 40\n1 96\n2 25\n2 68\n2 87\n2 34\n2 66\n2 60\n2 65\n2 18\n2 48\n1 97\n2 71\n1 94\n1 5\n1 47\n1 29", "output": "53" }, { "input": "2\n1 100\n1 100", "output": "2" }, { "input": "3\n2 5\n2 5\n2 5", "output": "6" } ]
139
0
0
22,755