QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#182486#4895. Lovely Dogshos_lyric#0 2ms4272kbC++144.4kb2023-09-18 05:00:032024-07-04 02:01:34

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 02:01:34]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:4272kb
  • [2023-09-18 05:00:03]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


int N, D;
vector<int> A, B;
vector<int> C;

vector<int> lpf;
vector<vector<pair<int, int>>> pess;
vector<int> fs;

vector<vector<int>> diviss;

vector<vector<int>> graph;
vector<Int> ans;

pair<vector<int>, map<int, int>> dfs(int u, int pa) {
  pair<vector<int>, map<int, int>> ret;
  {
    const int c = C[u];
    ret.first.push_back(c);
    if (fs[c]) {
      for (const int divi : diviss[c]) {
        ret.second[divi] += fs[c];
      }
    }
    // f(c^2)
    bool ok = true;
    for (const auto &pe : pess[c]) {
      ok = ok && (2 * pe.second <= D);
    }
    if (ok) {
      ans[u] += 1;
    }
  }
  for (const int v : graph[u]) if (pa != v) {
    auto res = dfs(v, u);
    ans[u] += ans[v];
    if (ret.first.size() < res.first.size()) {
      swap(ret, res);
    }
    for (const int c : res.first) {
      const auto &pes = pess[c];
      const int len = pes.size();
      vector<Int> prods(1 << len);
      prods[0] = 1;
      for (int i = 0; i < len; ++i) {
        const int p = pes[i].first;
        const int e = pes[i].second;
        Int q = 1;
        for (int f = 0; f < D + 1 - e; ++f) {
          q *= p;
          if (chmin<Int>(q, N + 1)) break;
        }
        for (int h = 0; h < 1 << i; ++h) {
          prods[h | 1 << i] = min<Int>(prods[h] * q, N + 1);
        }
      }
      int sum = 0;
      for (int h = 0; h < 1 << len; ++h) if (prods[h] <= N) {
        auto it = ret.second.find(prods[h]);
        if (it != ret.second.end()) {
          sum += (__builtin_parity(h)?-1:+1) * it->second;
        }
      }
      ans[u] += sum * fs[c];
    }
    for (const int c : res.first) {
      ret.first.push_back(c);
      for (const int divi : diviss[c]) {
        ret.second[divi] += fs[c];
      }
    }
  }
  return ret;
}

int main() {
  for (; ~scanf("%d%d", &N, &D); ) {
    A.resize(N - 1);
    B.resize(N - 1);
    for (int i = 0; i < N - 1; ++i) {
      scanf("%d%d", &A[i], &B[i]);
      --A[i];
      --B[i];
    }
    C.resize(N);
    for (int u = 0; u < N; ++u) {
      scanf("%d", &C[u]);
    }
    
    lpf.assign(N + 1, 0);
    for (int n = 2; n <= N; ++n) lpf[n] = n;
    for (int p = 2; p <= N; ++p) if (lpf[p] == p) {
      for (int n = 2 * p; n <= N; n += p) chmin(lpf[n], p);
    }
    pess.assign(N + 1, {});
    fs.assign(N + 1, 0);
    for (int n = 1; n <= N; ++n) {
      fs[n] = 1;
      for (int nn = n; nn > 1; ) {
        const int p = lpf[nn];
        int e = 0;
        do {
          ++e;
          nn /= p;
        } while (nn % p == 0);
        pess[n].emplace_back(p, e);
        fs[n] *= ((e <= D) ? ((e&1)?-1:+1) : 0);
      }
    }
// cerr<<"fs = "<<fs<<endl;
    
    diviss.assign(N + 1, {});
    for (int d = 1; d <= N; ++d) {
      for (int n = d; n <= N; n += d) {
        diviss[n].push_back(d);
      }
    }
    
    graph.assign(N, {});
    for (int i = 0; i < N - 1; ++i) {
      graph[A[i]].push_back(B[i]);
      graph[B[i]].push_back(A[i]);
    }
    ans.assign(N, 0);
    dfs(0, -1);
    for (int u = 0; u < N; ++u) {
      printf("%lld\n", ans[u]);
    }
cerr<<"========"<<endl;
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Judgement Failed

Test #1:

score: 10
Accepted
time: 0ms
memory: 4104kb

input:

20 2
18 8
18 11
13 19
10 8
9 11
4 8
9 15
9 17
2 1
13 18
20 18
1 8
12 17
7 16
5 11
16 15
6 19
14 16
1 3
2 15 5 13 20 6 16 18 9 19 17 7 14 10 11 3 1 12 4 8

output:

16
1
1
1
0
1
0
12
3
1
6
1
3
1
2
1
1
7
1
0

result:

ok 20 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 3948kb

input:

500 1
287 459
335 297
303 82
427 202
500 158
257 45
410 274
208 19
172 113
274 379
380 65
234 46
161 441
73 488
473 327
474 481
152 67
78 414
260 20
142 385
494 343
446 72
498 296
111 9
349 372
448 217
282 442
412 144
342 44
282 92
337 128
426 201
104 493
278 298
278 145
363 121
92 305
278 379
166 1...

output:

158
-3
0
0
-1
0
0
0
-1
-1
-2
0
0
1
0
0
0
0
-1
-3
0
0
1
0
1
0
0
0
0
0
1
6
5
0
0
0
0
0
1
0
0
0
-1
2
0
0
0
98
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
-11
0
0
1
0
0
0
-5
0
0
11
0
0
0
0
-1
0
0
1
0
7
-2
0
31
0
2
14
-3
0
1
0
0
0
0
1
0
0
-2
-3
0
0
-3
0
0
0
0
0
0
0
0
0
-1
0
0
-1
0
1
0
0
0
2
1
0
-3
0
0
0
-1
0
0
0
-...

result:

ok 500 tokens

Test #3:

score: 0
Accepted
time: 1ms
memory: 3988kb

input:

500 1
420 282
9 357
176 82
390 58
280 145
303 106
342 485
300 241
149 18
233 286
499 473
288 22
472 103
271 244
490 273
419 93
26 5
408 243
132 423
75 53
112 390
26 227
413 312
401 320
96 71
479 129
459 373
322 425
465 85
244 117
155 7
44 407
225 351
67 480
370 24
408 60
463 245
270 264
271 82
109 3...

output:

158
0
-1
0
6
0
0
0
0
1
0
0
-1
18
0
0
0
0
0
0
0
1
0
0
0
4
0
0
0
1
1
2
0
0
0
0
0
-3
0
0
0
0
0
0
-1
0
3
-1
0
-3
0
0
0
0
0
-1
-1
0
1
0
0
0
1
0
0
0
0
1
0
0
-1
0
7
0
1
230
2
0
0
-6
0
6
0
-2
-2
0
0
-8
0
0
-1
3
1
0
1
0
0
1
0
-3
1
0
0
0
0
-1
0
0
0
0
0
-2
0
-1
0
1
0
7
0
0
-1
0
0
0
0
0
1
0
0
-3
0
-1
0
0
0
0
0
...

result:

ok 500 tokens

Test #4:

score: 0
Accepted
time: 1ms
memory: 4272kb

input:

500 1
407 7
167 9
444 291
345 93
446 169
305 310
231 378
93 158
93 128
233 75
499 106
93 430
403 132
26 186
305 452
15 238
82 93
146 93
272 11
62 319
301 91
136 28
93 60
478 324
101 248
180 445
253 155
61 456
348 130
137 308
93 63
376 93
202 446
93 401
458 9
226 93
164 93
432 484
265 93
396 218
473 ...

output:

158
-207
0
-12
20
0
0
0
49
0
-34
0
56
-59
-38
-119
0
0
0
103
-48
-46
-64
-11
0
-54
0
65
0
0
0
0
0
0
-41
-7
0
0
0
-54
0
39
0
-155
0
0
-49
0
0
-67
0
0
0
-54
-120
0
0
-55
0
0
-21
115
0
0
0
-206
0
0
-21
0
-48
-27
0
0
-71
0
151
0
2
-41
-58
0
0
0
0
0
-11
0
0
-49
-54
-38
49
-32
0
37
0
0
0
0
-42
0
0
-56
54
...

result:

ok 500 tokens

Test #5:

score: 0
Accepted
time: 2ms
memory: 3948kb

input:

500 1
27 412
370 80
199 200
189 311
29 174
242 428
302 491
64 278
390 342
334 86
145 468
329 308
466 462
85 371
198 182
18 435
338 85
473 105
50 131
312 62
58 417
233 53
38 278
377 365
162 397
293 228
12 211
432 499
218 134
390 130
272 381
336 133
137 356
95 449
290 327
151 232
179 272
201 269
304 3...

output:

158
1
2
0
0
0
0
0
1
0
0
0
0
1
1
0
0
3
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
2
0
-8
0
0
0
0
0
0
0
-1
0
0
0
0
0
1
0
0
0
-1
0
0
0
0
-2
0
-2
-1
-3
0
0
0
2
0
-1
0
0
1
1
0
-1
-4
0
1
0
0
0
0
0
1
0
-3
0
0
0
0
0
0
-2
0
0
0
0
0
0
1
1
1
-1
0
0
0
0
0
-1
0
9
0
-67
0
0
0
0
0
0
-4
-2
0
0
0
0
-2
-1
-1
0
-2
0
0
-...

result:

ok 500 tokens

Test #6:

score: 0
Accepted
time: 1ms
memory: 4248kb

input:

500 2
428 7
101 379
176 90
188 28
455 459
196 332
481 438
294 234
222 285
2 448
58 491
132 449
111 413
254 163
9 201
269 393
79 11
182 331
277 265
88 370
233 188
329 294
446 445
136 131
317 453
311 219
437 486
496 310
85 349
421 326
316 490
499 367
404 361
446 411
249 494
462 58
433 60
57 278
45 456...

output:

629
8
20
1
0
1
1
1
2
0
2
0
1
0
3
0
4
0
0
0
1
0
0
1
0
1
1
169
1
0
2
1
1
0
2
1
1
1
1
568
2
2
0
0
0
1
1
0
0
48
1
0
1
1
0
2
0
8
0
0
1
0
0
2
2
2
2
1
1
0
1
0
1
1
0
7
0
0
1
1
1
0
0
2
7
0
0
0
0
1
13
1
0
6
-1
1
0
1
2
0
4
1
1
4
1
1
1
1
0
0
1
-1
3
2
1
1
0
0
0
1
1
2
3
1
9
1
1
1
3
0
5
8
-1
1
2
0
5
1
1
0
0
2
0
1
...

result:

ok 500 tokens

Test #7:

score: 0
Accepted
time: 1ms
memory: 4216kb

input:

500 3
102 64
271 215
377 453
237 410
39 280
210 109
7 139
446 304
9 484
189 335
60 398
269 65
429 487
186 279
451 44
245 144
288 396
498 433
225 335
254 482
392 335
477 139
275 193
58 274
312 334
427 201
141 4
389 330
184 133
436 18
239 302
188 38
45 348
173 433
285 54
33 296
150 189
320 278
182 316...

output:

104
0
4
75
1
21
1
1
7
0
2
2
4
4
4
-3
0
1
0
1
2
1
0
2
1
2
0
6
0
1
0
8
3
5
2
1
1
1
2
2
6
1
0
0
0
3
-2
1
3
1
0
5
0
0
0
1
1
1
1
33
1
1
0
1
6
1
2
3
0
-1
1
1
1
1
1
1
7
1
1
0
1
0
1
1
120
3
1
2
10
0
3
0
0
1
3
1
3
1
0
0
1
0
2
1
0
1
0
26
2
6
1
0
0
1
4
1
0
0
1
1
2
1
0
3
1
1
0
0
1
0
14
1
0
3
0
1
1
0
11
0
8
0
1
...

result:

ok 500 tokens

Test #8:

score: 0
Accepted
time: 1ms
memory: 4256kb

input:

500 4
89 102
92 484
360 314
414 280
439 165
331 311
349 110
484 252
422 473
401 137
183 34
175 91
306 42
285 186
296 22
62 441
389 238
240 268
165 44
117 34
110 255
465 58
53 82
478 350
195 306
362 422
239 35
36 33
484 284
153 181
285 478
201 148
5 196
331 350
235 291
497 270
140 292
317 439
222 252...

output:

525
6
6
1
4
0
1
1
1
1
3
1
1
1
1
3
1
1
1
3
12
3
1
5
1
1
2
3
1
11
1
3
6
1
2
1
1
1
1
1
1
0
0
1
1
0
1
1
1
1
2
0
1
3
1
4
0
1
1
1
1
1
2
1
1
0
547
1
6
5
62
0
1
1
6
0
1
0
4
6
1
0
1
3
3
1
3
0
4
6
3
7
0
2
1
1
1
0
1
1
1
6
1
1
1
1
1
0
307
5
2
1
1
0
0
1
5
1
1
1
5
1
2
1
1
1
1
0
2
0
1
1
3
2
7
2
405
1
1
3
1
1
0
4
2...

result:

ok 500 tokens

Test #9:

score: 0
Accepted
time: 1ms
memory: 3944kb

input:

500 5
487 484
346 261
290 56
40 334
16 3
171 224
311 151
425 371
460 469
248 256
117 217
309 79
165 482
259 374
131 408
117 24
18 234
448 197
253 205
421 211
437 408
218 298
159 35
463 169
247 310
289 365
389 275
64 411
117 431
472 279
259 236
351 106
447 39
75 54
18 336
82 89
259 41
331 356
385 77
...

output:

308
1
24
1
0
0
1
1
0
1
1
6
12
1
3
2
1
11
1
1
0
1
6
4
1
1
1
1
1
1
1
1
1
1
10
1
6
2
38
1
3
5
0
1
1
0
0
1
5
0
61
3
1
2
5
1
5
32
4
8
1
0
0
4
1
1
1
9
1
2
4
1
4
1
1
1
8
0
1
0
4
1
0
1
4
1
38
2
2
1
1
1
3
6
0
119
10
1
1
13
1
3
1
1
1
7
1
3
1
1
1
1
1
1
3
1
6
3
1
1
3
1
5
1
3
1
1
1
3
0
10
3
8
2
1
2
4
2
1
1
0
1
0...

result:

ok 500 tokens

Test #10:

score: 0
Accepted
time: 1ms
memory: 4240kb

input:

500 6
387 133
199 269
328 469
142 241
334 323
266 453
479 411
141 56
287 158
493 267
306 387
257 483
310 381
398 14
110 457
462 170
11 262
321 316
413 299
364 488
132 166
304 131
208 245
423 21
360 427
369 188
72 10
219 93
181 279
118 129
20 499
462 122
261 254
180 495
199 300
241 90
491 274
382 127...

output:

506
1
4
1
1
1
1
1
1
1
15
1
2
1
0
1
1
5
1
2
2
3
1
12
1
6
7
1
3
5
1
1
4
1
2
1
70
1
1
12
32
4
3
1
1
3
11
1
3
3
1
9
4
10
1
0
4
1
63
1
1
1
26
4
1
1
3
1
3
3
1
1
1
1
1
1
7
1
1
2
1
1
8
1
1
1
5
7
5
3
2
1
4
3
1
1
6
1
1
2
0
2
1
3
1
1
6
1
4
1
3
3
1
1
2
1
2
0
5
3
1
1
2
3
1
7
1
1
343
1
1
2
4
2
1
1
2
1
1
1
12
1
1
...

result:

ok 500 tokens

Test #11:

score: 0
Accepted
time: 1ms
memory: 3996kb

input:

500 7
366 320
150 327
384 317
144 293
399 290
438 76
27 305
210 43
472 144
310 490
347 234
457 268
319 142
268 407
295 371
82 111
282 244
324 203
438 60
493 170
162 157
96 104
489 323
274 236
170 307
252 84
144 404
483 264
370 272
124 282
353 250
499 406
492 306
361 54
233 361
366 155
72 17
114 103
...

output:

412
1
1
1
2
1
1
0
1
3
4
1
3
6
1
1
343
6
3
1
11
1
1
3
1
1
6
9
9
5
2
1
3
1
1
1
6
1
1
1
1
2
1
8
1
1
11
4
0
8
1
1
19
1
5
6
1
2
11
1
6
1
0
34
8
1
1
1
1
2
1
203
2
2
4
12
1
1
1
1
1
9
1
2
1
1
1
1
1
2
1
3
1
0
1
37
1
1
3
1
3
1
7
11
0
1
1
2
1
2
6
1
1
1
1
1
1
2
3
1
1
1
0
2
10
3
1
75
0
1
1
1
0
1
2
1
1
1
3
19
2
1...

result:

ok 500 tokens

Test #12:

score: 0
Accepted
time: 1ms
memory: 4052kb

input:

500 8
14 22
499 298
38 476
195 58
38 306
98 258
313 252
220 303
68 28
87 303
27 172
322 264
430 419
354 351
29 324
160 207
475 237
492 303
335 243
61 386
444 491
263 382
264 133
382 85
259 128
416 48
308 115
83 392
426 321
354 28
325 466
152 433
363 349
325 353
423 142
443 362
190 166
462 362
183 24...

output:

450
3
2
1
1
1
3
9
1
3
1
79
1
3
4
1
1
14
1
7
1
2
3
3
7
3
1
162
1
1
1
1
10
1
1
1
1
9
2
1
1
7
1
0
1
1
2
3
1
1
4
1
2
22
1
1
1
2
1
1
1
11
1
1
1
2
5
119
1
1
5
3
7
12
1
1
3
1
1
4
1
1
37
3
54
5
2
1
2
1
2
1
1
1
1
17
1
1
1
1
1
3
1
1
1
1
0
1
3
1
1
1
3
1
448
3
1
3
4
1
2
1
1
1
1
6
3
10
1
1
2
1
2
1
1
1
1
1
2
3
1
...

result:

ok 500 tokens

Test #13:

score: 0
Accepted
time: 2ms
memory: 3964kb

input:

500 8
440 350
94 352
197 47
495 208
490 353
489 432
266 407
176 397
201 352
331 428
450 444
168 23
464 398
428 229
123 481
218 122
193 117
39 255
190 84
483 140
345 111
334 358
200 30
5 59
466 331
128 125
217 285
370 17
90 20
43 429
368 294
380 278
40 486
176 13
471 468
53 69
2 163
58 153
355 374
38...

output:

450
4
1
5
2
4
1
1
1
6
1
3
469
14
19
1
1
3
1
18
10
28
3
1
1
0
1
1
3
3
5
1
3
4
3
8
3
1
1
15
3
1
1
3
10
1
6
1
1
1
1
1
2
1
1
1
1
21
1
3
1
10
1
2
1
1
1
4
1
1
4
1
1
0
3
1
1
1
1
5
2
7
4
14
2
1
1
1
1
7
2
1
4
1
4
1
433
10
2
13
1
1
1
1
5
1
4
6
1
1
3
1
1
1
1
1
1
1
1
2
3
1
1
7
1
1
5
9
1
1
3
4
1
2
3
1
19
1
11
1
...

result:

ok 500 tokens

Test #14:

score: 0
Accepted
time: 1ms
memory: 4056kb

input:

500 8
88 395
88 162
192 401
232 209
136 168
308 94
198 88
298 285
17 43
227 112
361 33
181 31
88 200
88 372
128 493
415 347
256 203
88 447
88 436
315 222
88 294
366 483
280 486
215 163
133 343
226 283
183 88
272 23
88 379
88 45
49 341
344 426
237 64
278 197
271 217
178 405
88 111
88 74
165 50
131 49...

output:

450
1
1
1
1
1
1
161
1
1
0
175
241
1
1
219
132
199
1
1
1
1
134
1
1
1
1
176
135
1
193
125
145
1
1
1
1
1
400
1
0
1
134
1
1
1
238
1
178
227
208
231
1
0
1
1
186
1
1
219
1
1
138
144
209
1
183
183
1
213
1
182
218
1
1
190
1
1
1
131
161
149
198
1
1
209
1
118
1
193
1
137
1
138
1
1
178
1
227
139
422
1
130
382
...

result:

ok 500 tokens

Test #15:

score: 0
Accepted
time: 2ms
memory: 4256kb

input:

500 8
396 247
170 343
238 295
438 423
408 442
98 180
207 350
72 425
437 147
82 85
5 178
168 141
87 372
250 218
396 130
303 328
470 237
127 297
178 327
90 130
97 50
326 299
293 280
413 401
286 32
478 353
282 38
159 84
383 158
14 276
469 261
394 179
367 388
484 497
494 232
162 314
292 344
26 483
211 3...

output:

450
1
2
1
1
1
1
1
1
1
1
1
1
1
2
16
1
1
4
1
1
7
1
8
2
15
1
2
1
6
1
16
1
8
1
2
4
1
1
1
1
4
1
2
8
1
2
1
1
1
1
1
16
2
1
1
6
2
1
40
1
16
0
1
33
1
124
1
32
7
8
1
153
1
1
1
1
1
2
1
2
2
2
19
4
1
20
8
1
8
4
1
0
1
1
3
2
1
1
1
8
2
6
1
6
6
1
2
38
6
1
1
1
2
1
1
56
1
2
2
2
6
11
1
2
1
4
6
12
16
1
6
1
1
4
1
2
1
1
1...

result:

ok 500 tokens

Test #16:

score: 0
Accepted
time: 1ms
memory: 3928kb

input:

500 9
500 139
126 130
264 199
277 262
21 410
108 314
347 142
497 397
416 417
438 321
101 438
292 345
277 299
22 146
127 21
119 316
339 198
236 380
485 347
31 156
276 156
270 493
362 39
210 13
499 477
497 391
173 45
423 451
239 311
219 390
282 303
4 475
88 234
34 472
271 470
66 143
391 223
54 386
404...

output:

439
1
1
3
1
6
164
2
1
1
1
1
132
2
3
1
1
1
1
4
4
1
4
1
55
202
3
8
1
0
4
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
3
1
1
1
0
3
1
7
1
1
7
1
17
1
1
1
3
2
3
2
2
1
1
11
7
2
1
18
1
1
1
1
1
0
6
3
3
1
1
5
1
3
1
1
26
1
8
1
1
1
4
3
1
1
1
2
3
1
1
1
1
3
6
1
1
1
3
1
1
1
34
1
26
1
1
1
1
1
1
1
2
1
1
3
1
4
4
1
1
2
10
1
3
1
6
1
...

result:

ok 500 tokens

Test #17:

score: 0
Accepted
time: 1ms
memory: 3960kb

input:

500 9
281 499
420 114
385 279
336 190
296 247
274 483
148 269
132 25
319 66
482 444
445 81
7 136
272 330
108 417
204 92
48 25
414 175
277 155
295 213
140 183
16 420
348 28
179 415
157 357
359 299
469 335
439 17
173 67
330 221
297 132
257 333
205 232
147 333
111 273
270 340
19 329
205 118
387 218
20 ...

output:

439
1
3
1
3
4
1
3
2
53
1
1
0
2
1
8
1
3
249
1
1
1
1
6
282
10
1
2
5
1
1
14
1
1
2
6
6
20
1
1
1
1
1
1
1
2
1
399
12
1
9
1
2
5
1
1
2
1
1
1
1
1
1
3
1
6
1
3
1
1
1
1
1
3
1
1
8
1
2
1
2
1
11
3
3
4
1
1
3
1
3
2
7
1
1
1
243
1
27
7
6
3
1
1
1
1
1
8
6
28
6
1
1
1
3
3
2
15
10
6
1
0
1
6
1
3
2
1
1
1
1
1
3
1
1
3
1
3
3
11...

result:

ok 500 tokens

Test #18:

score: -10
Judgement Failed

input:

500 9
26 71
446 145
445 145
485 149
373 485
145 110
145 142
145 123
249 145
418 21
308 392
334 145
145 46
145 429
417 246
425 218
488 145
166 236
460 47
354 145
141 477
277 32
447 69
278 145
53 204
93 106
145 221
145 424
305 371
145 213
145 292
144 349
476 374
358 277
169 145
189 422
76 247
472 42
1...

output:


result:


Subtask #2:

score: 0
Judgement Failed

Test #24:

score: 0
Judgement Failed

input:

2000 1
134 1468
867 1750
351 1220
1690 1888
1685 134
585 282
1142 643
206 271
260 1833
1987 770
1029 1667
322 1371
341 518
601 915
119 893
1933 1502
951 1785
1056 1630
1957 1208
96 55
1508 1212
331 427
505 151
1378 1486
1545 697
1459 629
202 997
180 1917
1638 1177
1244 1896
302 658
1433 1605
1318 19...

output:


result:


Subtask #3:

score: 0
Judgement Failed

Test #45:

score: 0
Judgement Failed

input:

200000 20
117994 12616
53490 106425
103660 50033
132640 78252
58384 19939
69183 10015
39098 165030
179856 130356
65245 57831
18234 83378
4240 154896
177149 102260
4634 180087
132390 19627
98506 60775
1890 120740
87908 21917
41323 192721
181885 96684
69412 139951
9800 38301
59025 29879
186185 81402
1...

output:


result:


Subtask #4:

score: 0
Judgement Failed

Test #50:

score: 0
Judgement Failed

input:

200000 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61...

output:


result:


Subtask #5:

score: 0
Judgement Failed

Test #55:

score: 0
Judgement Failed

input:

200000 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61...

output:


result:


Subtask #6:

score: 0
Judgement Failed

Test #78:

score: 0
Judgement Failed

input:

50000 1
8097 41839
17674 41774
40520 8024
5786 38261
20664 43471
1217 49276
11185 40807
14186 25584
31704 14814
42333 41475
13053 39565
45938 30104
5826 39463
5031 10814
43784 6042
58 33849
42978 18978
36307 33276
34769 4351
27884 37532
27528 29431
29451 39345
10946 9667
19016 47269
7911 30103
10308...

output:


result:


Subtask #7:

score: 0
Judgement Failed

Test #103:

score: 0
Judgement Failed

input:


output:


result: