File size: 284,513 Bytes
133fe23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
{"problem_id": "p03371", "input": "A, B, C, X, Y = list(map(int, input().split()))\n\n\n\nans = 5000 * 2 * 10 ** 5\n\nfor i in range(10 ** 5 + 1):\n\n    s = i * 2 * C + max(0, X - i) * A + max(0, Y - i) * B\n\n    ans = min(ans, s)\n\n\n\nprint(ans)"}
{"problem_id": "p02612", "input": "import sys\n\n\n\nread = sys.stdin.buffer.read\n\nreadline = sys.stdin.buffer.readline\n\nreadlines = sys.stdin.buffer.readlines\n\n\n\nN = int(read())\n\nx = N + (-N) % 1000\n\nprint((x - N))"}
{"problem_id": "p03078", "input": "# -*- coding: utf-8 -*-\n\nx, y, z, k = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\nb = list(map(int, input().split()))\n\nc = list(map(int, input().split()))\n\n\n\na.sort(reverse=True)\n\nb.sort(reverse=True)\n\nc.sort(reverse=True)\n\n\n\nabc = []\n\n\n\nfor i, _a in enumerate(a):\n\n    for j, _b in enumerate(b):\n\n        if (i+1) * (j+1) > k:\n\n            break\n\n        for l, _c in enumerate(c):\n\n            if (i+1) * (j+1) * (l+1) > k:\n\n                break\n\n            abc.append(_a + _b + _c)\n\n\n\nabc.sort(reverse=True)\n\nfor x in abc[:k]:\n\n    print(x)\n"}
{"problem_id": "p03559", "input": "N = int(input())\n\nA = list(map(int,input().split()))\n\nB = list(map(int,input().split()))\n\nC = list(map(int,input().split()))\n\nA.sort()\n\nC.sort()\n\n\n\nans = 0\n\nfrom bisect import bisect, bisect_left\n\nfor b in B:\n\n    i = bisect_left(A, b)\n\n    j = bisect(C, b)\n\n    ans += i * (N-j)\n\nprint(ans)"}
{"problem_id": "p03674", "input": "n = int(input())\n\na = list(map(int, input().split()))\n\nD = {i: [0] for i in range(1, n+1)}\n\nfor i in range(n+1):\n\n  D[a[i]][0] += 1\n\n  D[a[i]].append(i)\n\npl, pr = 0, 0\n\nfor i in D:\n\n  if D[i][0] == 2:\n\n    pl = D[i][1]\n\n    pr = D[i][2]\n\n    break\n\nL = pl\n\nM = pr - pl - 1\n\nN = n - pr\n\nmod = int(1e9) + 7 # <-- input modulo\n\nmaxf = n+11          # <-- input factional limitation\n\n\n\ndef make_fact(n, k):\n\n    tmp = n\n\n    perm = [i for i in range(k)]\n\n    L = [0 for _ in range(k)]\n\n    for i in range(k):\n\n        L[i] = tmp % (i + 1)\n\n        tmp //= i + 1\n\n    LL = [0 for _ in range(k)]\n\n    for i in range(k):\n\n        LL[i] = perm[L[-i-1]]\n\n        for j in range(L[-i-1]+1, k):\n\n            perm[j-1] = perm[j]\n\n    return LL\n\n\n\ndef doubling(n, m, modulo=mod):\n\n    y = 1\n\n    base = n\n\n    tmp = m\n\n    while tmp != 0:\n\n        if tmp % 2 == 1:\n\n            y *= base\n\n            if modulo > 0:\n\n                y %= modulo\n\n        base *= base\n\n        if modulo > 0:\n\n            base %= modulo\n\n        tmp //= 2\n\n    return y\n\n\n\ndef inved(a, modulo=mod):\n\n    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo\n\n    while l != 0:\n\n        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)\n\n        k, l = l, k % l\n\n    return x % modulo\n\n\n\nfact = [1 for _ in range(maxf+1)]\n\ninvf = [1 for _ in range(maxf+1)]\n\n\n\nfor i in range(maxf):\n\n    fact[i+1] = (fact[i] * (i+1)) % mod\n\ninvf[-1] = inved(fact[-1])\n\nfor i in range(maxf, 0, -1):\n\n    invf[i-1] = (invf[i] * i) % mod\n\n\n\nfor i in range(1, n+2):\n\n  S = fact[n]*invf[i-1]*invf[n-i+1]%mod\n\n  if i <= n-1:\n\n    S += fact[n-1]*invf[i]*invf[n-1-i]%mod\n\n    S %= mod\n\n  if i <= n-M:\n\n    S -= fact[n-1-M]*invf[i-1]*invf[n-M-i]%mod\n\n    S %= mod\n\n  if i <= n:\n\n    S += fact[n-1]*invf[i-1]*invf[n-i]%mod\n\n    S %= mod\n\n  print(S)"}
{"problem_id": "p02952", "input": "n = int(input())\n\n\n\n\n\ndef countKeta(num):\n\n    count = 1\n\n    while num / 10 >= 1:\n\n        count += 1\n\n        num = num // 10\n\n    return count\n\n\n\n\n\ncount = 0\n\n\n\nfor i in range(1, n+1):\n\n    if(countKeta(i) % 2 == 1):\n\n        count += 1\n\n\n\nprint(count)"}
{"problem_id": "p02996", "input": "\n\n\n\nn = int(input())\n\n\n\nabn = [list(map(int,input().split())) for _ in range(n)]\n\n\n\n\n\nabn.sort()\n\nabn.sort(key = lambda x:x[1])\n\n\n\n\n\n#print(abn)\n\n\n\nts = 0 # time_stamp\n\nenable = True\n\nfor abi in abn:\n\n    a, b = abi\n\n\n\n    if not ts + a <= b:\n\n        enable = False\n\n        break\n\n    else:\n\n        ts += a\n\n\n\nprint(('Yes' if enable else 'No'))"}
{"problem_id": "p00053", "input": "def isPrime(x):\n\n    if x == 2:\n\n        return True\n\n    if x < 2 or x % 2 == 0:\n\n        return False\n\n    i, root_x = 3, int(pow(x, 0.5))\n\n    while i <= root_x:\n\n        if x % i == 0:\n\n            return False\n\n        i += 2\n\n    return True\n\n\n\nprimes = [2]\n\nfor i in range(3, 104730):\n\n    if isPrime(i):\n\n        primes.append(primes[-1]+i)\n\nwhile True:\n\n    n = int(input())\n\n    if n == 0:\n\n        break\n\n    print((primes[n-1]))"}
{"problem_id": "p03835", "input": "import sys\n\ninput = sys.stdin.readline\n\nsys.setrecursionlimit(10 ** 7)\n\n\n\nK, S = list(map(int, input().split()))\n\n\n\nans = 0\n\nfor z in range(K+1):\n\n    for y in range(K+1):\n\n        x = S - (z + y)\n\n        if x >= 0 and x <= K:\n\n            ans += 1\n\nprint(ans)"}
{"problem_id": "p02996", "input": "n=int(input())\n\ntask=[] \n\nfor _ in range(n):\n\n    a,b=list(map(int,input().split()))\n\n    task.append((b, -a))\n\n\n\ntask.sort()\n\n\n\ntime=0\n\nflag=True\n\nfor i in task:\n\n    time-=i[1]\n\n    if time>i[0]:\n\n        flag=False\n\n        break\n\n\n\nif flag:\n\n    print(\"Yes\")\n\nelse:\n\n    print(\"No\")\n\n\n"}
{"problem_id": "p03038", "input": "from collections import Counter,defaultdict,deque\n\nfrom heapq import heapify,heappop,heappush\n\nfrom bisect import bisect_left,bisect_right\n\nimport sys,math,itertools,string,queue\n\nsys.setrecursionlimit(10**8)\n\nmod = 10**9+7\n\ndef inp(): return int(sys.stdin.readline())\n\ndef inpl(): return list(map(int, sys.stdin.readline().split()))\n\ndef inpl_str(): return list(sys.stdin.readline().split())\n\ndef inpln(n): return list(int(sys.stdin.readline()) for i in range(n))\n\n\n\nn,m = inpl()\n\na = inpl()\n\nb = [0] * m\n\nfor i in range(m):\n\n    x,y = inpl()\n\n    b[i] = [x,y]\n\na.sort()\n\nb.sort(key=lambda x:x[1], reverse = True)\n\nres = sum(a)\n\ni = 0\n\nj = 0\n\nwhile True:\n\n    # print(i,j)\n\n    if a[i] < b[j][1]:\n\n        res += b[j][1] - a[i]\n\n        i += 1\n\n    else:\n\n        break\n\n    b[j][0] -= 1\n\n    if b[j][0] == 0:\n\n        j += 1\n\n    if i >= n or j >= m:\n\n        break\n\nprint(res)\n"}
{"problem_id": "p02891", "input": "s = input()\n\nk = int(input())\n\n\n\nif len(set(s)) == 1:\n\n    print(((len(s)*k)//2))\n\n    exit()\n\n\n\nss = s + s\n\n\n\nshoko = 0\n\nprev = ''\n\ncnt = 0\n\nfor i in range(len(s)):\n\n    if s[i] == prev:\n\n        cnt += 1\n\n    else:\n\n        shoko += cnt // 2\n\n        cnt = 1\n\n    prev = s[i]\n\nshoko += cnt // 2\n\n\n\nkosa = 0\n\nprev = ''\n\ncnt = 0\n\nfor i in range(len(ss)):\n\n    if ss[i] == prev:\n\n        cnt += 1\n\n    else:\n\n        kosa += cnt // 2\n\n        cnt = 1\n\n    prev = ss[i]\n\nkosa += cnt // 2\n\nkosa -= shoko\n\n\n\nprint((shoko + (k-1)*kosa))"}
{"problem_id": "p03081", "input": "n,q=list(map(int,input().split()));s=\"_\"+input()+\"_\";l,r=0,n+1\n\nfor(m,h)in[input().split()for i in range(q)][::-1]:L=h==\"L\";R=h==\"R\";l,r=[l,l-1,l+1][(m==s[l]and R)-(m==s[l+1]and L)],[r,r-1,r+1][(m==s[r-1]and R)-(m==s[r]and L)]\n\nprint((max(0,r-l-1)))"}
{"problem_id": "p03796", "input": "import math\n\n\n\nn = int(input())\n\nprint((math.factorial(n) % (10 ** 9 + 7)))"}
{"problem_id": "p03035", "input": "a,b=list(map(int,input().split()))\n\nprint((b if 13<=a else b//2 if 6<=a else 0))"}
{"problem_id": "p02688", "input": "N,K=list(map(int,input().split()))\n\n\n\ncon = 0\n\nans = list(int() for _ in range(100000))\n\npre = 0\n\n\n\n\n\nfor _ in range(K):\n\n\n\n    D = int(input())\n\n    arr = list(map(int,input().split()))\n\n\n\n    for j in range(D):\n\n\n\n        ans[pre+j]=arr[j]\n\n\n\n    pre += D\n\n\n\n        \n\nfin = (N+1) - len(set(ans))\n\n\n\nprint(fin)"}
{"problem_id": "p03162", "input": "def main():\n\n  n = int(input())\n\n  a = [0]\n\n  b = [0]\n\n  c = [0]\n\n\n\n  for i in range(n):\n\n      aa,bb,cc = list(map(int,input().split()))\n\n      a.append(max(b[i] + aa, c[i] + aa))\n\n      b.append(max(a[i] + bb, c[i] + bb))\n\n      c.append(max(a[i] + cc, b[i] + cc))\n\n\n\n  print((max(a[-1], b[-1], c[-1])))\n\n\n\nmain()"}
{"problem_id": "p02414", "input": "import sys\n\ne=[list(map(int,e.split()))for e in sys.stdin]\n\nn=e[0][0]+1\n\nfor c in e[1:n]:\n\n t=''\n\n for l in zip(*e[n:]):t+=f'{sum(s*t for s,t in zip(c,l))} '\n\n print((t[:-1]))\n"}
{"problem_id": "p02814", "input": "from functools import reduce\n\nfrom math import gcd\n\n\n\nN, M, *A = list(map(int, open(0).read().split()))\n\n\n\ndef lcm(x, y):\n\n    return x * y // gcd(x, y)\n\n\n\ndef sub_by_2(n):\n\n    cnt = 0\n\n    while n % 2 == 0:\n\n        n //= 2\n\n        cnt += 1\n\n    return cnt\n\n\n\nlcm_2 = [sub_by_2(n // 2) for n in A]\n\nif all(lcm_2[0] == v for v in lcm_2):\n\n    num = reduce(lcm, [v // 2 for v in A])\n\n    res = M // num\n\n    print((res // 2 + res % 2))\n\nelse:\n\n    print((0))\n"}
{"problem_id": "p02552", "input": "x = int(input())\n\nif x == 0:\n\n  print((1))\n\nelse:\n\n  print((0))"}
{"problem_id": "p02959", "input": "from sys import stdin,stdout\n\n\n\nif __name__==\"__main__\":\n\n    n=int(stdin.readline())\n\n\n\n    a=[int(x) for x in stdin.readline().split()]\n\n    b=[int(x) for x in stdin.readline().split()]\n\n\n\n    cnt=0\n\n\n\n    for i in range(n):\n\n        if(a[i]>=b[i]):\n\n            cnt+=b[i]\n\n        else:\n\n            cnt+=a[i]\n\n            d=b[i]-a[i]\n\n            cnt+=min(a[i+1],d)\n\n            if(d>a[i+1]):\n\n                a[i+1]=0\n\n            else: a[i+1]-=d\n\n            \n\n    stdout.write(str(cnt)+\"\\n\")\n"}
{"problem_id": "p03608", "input": "def main():\n\n    from itertools import permutations\n\n\n\n    n, m, r, *x = list(map(int, open(0).read().split()))\n\n    to = x[:r]\n\n\n\n    dis = [[float(\"Inf\")] * (n + 1) for _ in range(n + 1)]\n\n    for i in range(1, n + 1):\n\n        dis[i][i] = 0\n\n\n\n    for a, b, c in zip(*[iter(x[r:])] * 3):\n\n        dis[a][b] = c\n\n        dis[b][a] = c\n\n\n\n    for k in range(1, n + 1):\n\n        for i in range(1, n + 1):\n\n            for j in range(1, n + 1):\n\n                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])\n\n\n\n    ans = float(\"Inf\")\n\n    for p in permutations(to):\n\n        tmp = 0\n\n        nw = p[0]\n\n        for nx in p[1:]:\n\n            tmp += dis[nw][nx]\n\n            nw = nx\n\n\n\n        ans = min(ans, tmp)\n\n\n\n    print(ans)\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03416", "input": "counter = 0\n\nc = list(map(int, input().split(' ')))\n\nfor i in range(c[0], c[1] + 1):\n\n  if str(i)[0] != str(i)[4]:\n\n    continue\n\n  if str(i)[1] != str(i)[3]:\n\n    continue\n\n  counter += 1\n\n\n\nprint(counter)"}
{"problem_id": "p03038", "input": "I=lambda:list(map(int,input().split()))\n\nn,m=I()\n\na=I()\n\na.sort(reverse=True)\n\nqq=[I() for i in range(m)]\n\nqq.sort(key=lambda x:x[1],reverse=True)\n\nans=0\n\nfor x,y in qq:\n\n    for j in range(x):\n\n        if not a:\n\n            break\n\n        aa=a.pop()\n\n        ans+=max(aa,y)\n\nans+=sum(a)\n\nprint(ans)\n\n        "}
{"problem_id": "p03723", "input": "a,b,c=list(map(int,input().split()))\n\ne=(a-b)|(b-c)\n\nprint((bool(e|(a|b|c)%2)*(e^~-e).bit_length()-1))"}
{"problem_id": "p03037", "input": "N, M =list(map(int, input().split()))\n\nL = [0 for i in range(N+1)]\n\nR = [0 for i in range(N+1)]\n\nfor i in range(M):\n\n    l,r = list(map(int, input().split()))\n\n    L[l] += 1\n\n    R[r] += 1\n\ncnt = 0\n\ntmp = 0\n\nfor i in range(N+1):\n\n    tmp += L[i]\n\n    if tmp == M:\n\n        cnt += 1\n\n    tmp -= R[i]\n\nprint(cnt)\n"}
{"problem_id": "p03558", "input": "from collections import deque\n\nK = int(input())\n\nG = [[] for i in range(K)]\n\n\n\nfor n in range(K):\n\n    G[n].append([(n + 1) % K, 1])\n\n    G[n].append([(10 * n) % K, 0])\n\n\n\nque = deque([[1, 1]])\n\ndist = [float('inf')] * K\n\n\n\nwhile que:\n\n    node, cost = que.pop()\n\n    dist[node] = min(cost, dist[node])\n\n    for e, e_cost in G[node]:\n\n        if dist[e] != float('inf'):\n\n            continue\n\n\n\n        if e_cost == 0:\n\n            que.append([e, cost + 0])\n\n\n\n        if e_cost == 1:\n\n            que.appendleft([e, cost + 1])\n\n\n\nprint((dist[0]))\n"}
{"problem_id": "p03307", "input": "import math\n\n\n\n\n\ndef lcm(x, y):\n\n    return (x * y) // math.gcd(x, y)\n\n\n\n\n\nN = int(input())\n\nprint((lcm(N, 2)))"}
{"problem_id": "p02555", "input": "import sys, re\n\nfrom collections import deque, defaultdict, Counter\n\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd\n\nfrom itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement\n\nfrom operator import itemgetter, mul\n\nfrom copy import deepcopy\n\nfrom string import ascii_lowercase, ascii_uppercase, digits\n\nfrom bisect import bisect, bisect_left\n\nfrom heapq import heappush, heappop\n\nfrom functools import reduce, lru_cache\n\ndef input(): return sys.stdin.readline().strip()\n\ndef INT(): return int(input())\n\ndef MAP(): return list(map(int, input().split()))\n\ndef LIST(): return list(map(int, input().split()))\n\ndef ZIP(n): return list(zip(*(MAP() for _ in range(n))))\n\nsys.setrecursionlimit(10 ** 9)\n\nINF = float('inf')\n\nmod = 10 ** 9 + 7\n\n\n\nS = INT()\n\n\n\n@lru_cache(maxsize=None)\n\ndef rec(x):\n\n    if x == 0: return 1\n\n\n\n    ret = 0\n\n    for i in range(x-2):\n\n        ret += rec(i)\n\n        ret %= mod\n\n    return ret\n\n\n\nprint((rec(S)))\n"}
{"problem_id": "p03037", "input": "import sys\n\n\n\nn, m, *lr = list(map(int, sys.stdin.read().split()))\n\nlr = list(zip(*[iter(lr)] * 2))\n\n\n\ndef main():\n\n    cnt = [0] * (n + 1)\n\n    for l, r in lr:\n\n        cnt[l-1] += 1\n\n        cnt[r] -= 1\n\n    \n\n    for i in range(n):\n\n        cnt[i+1] += cnt[i]\n\n    \n\n    res = 0\n\n    for i in range(n):\n\n        res += (cnt[i] == m) & 1\n\n    \n\n    return res\n\n\n\nif __name__ == '__main__':\n\n    ans = main()\n\n    print(ans)"}
{"problem_id": "p01438", "input": "from collections import defaultdict\n\nwhile 1:\n\n    n = int(input())\n\n    if n == 0: break\n\n    L = [0]*n\n\n    D = [0]*n\n\n    for man in range(n):\n\n        m,l = list(map(int,input().split()))\n\n        L[man] = l\n\n        t = 0\n\n        for date in range(m):\n\n            s,e = list(map(int,input().split()))\n\n            for s in range(s-6,e-6):\n\n                t |= 1 << s\n\n        D[man] = t\n\n\n\n    dp = [defaultdict(int) for i in range(n)]\n\n    dp[0][D[0]] = L[0]\n\n    for i in range(1,n):\n\n        for bit in list(dp[i-1].keys()):\n\n            if bit&D[i] == 0:\n\n                dp[i][bit|D[i]] = max(dp[i][bit|D[i]], dp[i-1][bit]+L[i])\n\n            dp[i][bit] = max(dp[i][bit],dp[i-1][bit])\n\n        dp[i][D[i]] = max(dp[i][D[i]], L[i])\n\n        \n\n    ans = max(max(dp[i].values()) for i in range(n))\n\n    print(ans)"}
{"problem_id": "p03208", "input": "N, K = list(map(int, input().split()))\n\n\n\nheight = []\n\nfor _ in range(N) :\n\n    height.append(int(input()))\n\n\n\nheight.sort()\n\nans = float('inf')\n\n\n\nfor i in range(N-K+1) :\n\n    diff = height[i + K - 1] - height[i]\n\n    ans = min(ans, diff)\n\n\n\nprint(ans)"}
{"problem_id": "p03032", "input": "from collections import deque\n\n\n\nn, k = list(map(int, input().split()))\n\nV = list(map(int, input().split()))\n\n\n\nans = 0\n\nfor t in range(k//2 + 1):\n\n    hand = deque(V[:k-t])\n\n    rest = deque(V[k-t:])\n\n    cur_sum = sum(hand)\n\n\n\n    for j in range(k-t+1):\n\n        put_back = 0\n\n        rev_hand = sorted(hand)\n\n\n\n        for i in range(t):\n\n            jewel = rev_hand[i]\n\n            if jewel < 0:\n\n                put_back -= jewel\n\n            else:\n\n                break\n\n\n\n        candidate = cur_sum + put_back\n\n        ans = max(candidate, ans)\n\n\n\n        to_rest = hand.pop()\n\n        rest.appendleft(to_rest)\n\n        to_hand = rest.pop()\n\n        hand.appendleft(to_hand)\n\n\n\n        cur_sum += to_hand - to_rest\n\n\n\nprint(ans)"}
{"problem_id": "p02863", "input": "n,t=list(map(int,input().split()))\n\nab=[list(map(int,input().split()))for _ in range(n)]\n\nab.sort()\n\ndp=[(6007)*[0]for _ in range(n+1)]\n\ndp[0][0]=0\n\nans=0\n\nfor i in range(n):\n\n  for j in range(6007):\n\n    dp[i+1][j]=max(dp[i+1][j],dp[i][j])\n\n    if j<t:dp[i+1][j+ab[i][0]]=max(dp[i][j]+ab[i][1],dp[i][j+ab[i][0]])\n\n    ans=max(ans,dp[i+1][j])\n\nprint(ans)\n"}
{"problem_id": "p00447", "input": "board = [[False]*1000001]*1000001\n\nwhile True:\n\n    m = int(input())\n\n    if m == 0: break\n\n    star = list({tuple(map(int, input().split())) for i in range(m)})\n\n    sx, sy = star[0]\n\n    \n\n    n = int(input())\n\n    starlist = list({tuple(map(int, input().split())) for i in range(n)})\n\n    for i in range(len(starlist)):\n\n        board[starlist[i][0]][starlist[i][1]] = True\n\n    for i in range(n):\n\n        flag = True\n\n        for j in range(len(star)-1):\n\n            dx = starlist[i][0] + star[j+1][0] - sx\n\n            dy = starlist[i][1] + star[j+1][1] - sy\n\n            if dx < 0 or 1000000 < dx or dy < 0 or 1000000 < dy or board[dx][dy] == False:\n\n                flag = False\n\n                break\n\n\n\n        if flag == True:\n\n            print((\"{} {}\".format(starlist[i][0] - sx, starlist[i][1] -sy)))\n\n            break\n\n    "}
{"problem_id": "p03399", "input": "a, b, c, d = int(input()), int(input()), int(input()), int(input()),\n\nprint((min(a, b)+min(c, d)))"}
{"problem_id": "p02837", "input": "def popcount(x):\n\n  r = 0\n\n  while x:\n\n    if x & 1:\n\n      r += 1\n\n    x >>= 1\n\n  return r\n\n\n\nn = int(input())\n\nr = list(range(n))\n\na = [[0, 0] for _ in r]\n\nfor i in r:\n\n  for _ in range(int(input())):\n\n    x, y = list(map(int, input().split()))\n\n    a[i][y] |= 1 << (x - 1)\n\n\n\nm = 0\n\nl = (1 << n) - 1\n\nfor x in range(1, l + 1):\n\n  if all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1):\n\n    m = max(m, popcount(x))\n\nprint(m)\n"}
{"problem_id": "p03039", "input": "n, m, k = list(map(int, input().split()))\n\nmod = 10 ** 9 + 7\n\nMAX = n * m\n\n\n\n\n\nclass ModInt:\n\n    def __init__(self, num):\n\n        self.num = num\n\n\n\n    def __str__(self):\n\n        return str(self.num)\n\n\n\n    def __repr__(self):\n\n        return \"ModInt(num: {}, mod: {}\".format(self.num, mod)\n\n\n\n    def __add__(self, other):\n\n        ret = self.num + other.num\n\n        ret %= mod\n\n        return ModInt(ret)\n\n\n\n    def __sub__(self, other):\n\n        ret = self.num - other.num\n\n        ret %= mod\n\n        return ModInt(ret)\n\n\n\n    def __mul__(self, other):\n\n        ret = self.num * other.num\n\n        ret %= mod\n\n        return ModInt(ret)\n\n\n\n    def pow(self, times):\n\n        pw = pow(self.num, times, mod)\n\n        return ModInt(pw)\n\n\n\n    def inverse(self):\n\n        return ModInt(inv[self.num])\n\n\n\n    def __truediv__(self, other):\n\n        num = self * other.inverse()\n\n        return ModInt(num)\n\n\n\n\n\ndef comb(n, k):\n\n    return fact[n] * inv[n-k] * inv[k]\n\n\n\n\n\nfact = [None] * (MAX + 1)\n\nfact[0] = ModInt(1)\n\nfor i in range(1, MAX + 1):\n\n    fact[i] = fact[i-1] * ModInt(i)\n\n\n\ninv = [None] * (MAX + 1)\n\ninv[MAX] = fact[MAX].pow(mod - 2)\n\nfor i in range(MAX, 0, -1):\n\n    inv[i-1] = inv[i] * ModInt(i)\n\n\n\nans = ModInt(0)\n\nfor i in range(n):\n\n    for j in range(m):\n\n        add = ModInt(n - i) * ModInt(m - j) * ModInt(i + j)\n\n        if i != 0 and j != 0:\n\n            add *= ModInt(2)\n\n\n\n        ans += add\n\n\n\nans *= comb(n * m - 2, k - 2)\n\nprint(ans)\n"}
{"problem_id": "p03241", "input": "N,M = list(map(int,input().split()))\n\nif N==1:\n\n    nmax=M\n\nelse:\n\n    nmax = 1\n\n    for i in range(2,int(M**0.5)+1):\n\n        if M%i==0 and M//i>=N:\n\n            nmax = max(nmax,i)\n\n        if M%i==0 and i>=N:\n\n            nmax = max(nmax,M//i)\n\nprint(nmax)"}
{"problem_id": "p02596", "input": "import sys\n\n\n\nreadline = sys.stdin.readline\n\nreadall = sys.stdin.read\n\nns = lambda: readline().rstrip()\n\nni = lambda: int(readline().rstrip())\n\nnm = lambda: map(int, readline().split())\n\nnl = lambda: list(map(int, readline().split()))\n\nprn = lambda x: print(*x, sep='\\n')\n\n\n\ndef solve():\n\n    d = dict()\n\n    k = ni()\n\n    c = 7 % k\n\n    x = d[c] = 1\n\n    while True:\n\n        c = (c * 10 + 7) % k\n\n        if c in d:\n\n            break\n\n        x += 1\n\n        d[c] = x\n\n    print(d.get(0, -1))\n\n    return\n\n\n\nsolve()\n"}
{"problem_id": "p02959", "input": "import sys\n\ninput = sys.stdin.readline\n\nsys.setrecursionlimit(10 ** 7)\n\n\n\nN = int(input())\n\nA = [int(i) for i in input().split()]\n\nB = [int(i) for i in input().split()]\n\nbefore = sum(A)\n\n\n\nfor i in range(N):\n\n    nokori = B[i]\n\n    for j in range(i,i+2):\n\n        if nokori >= A[j]:\n\n            nokori -= A[j]\n\n            A[j] = 0\n\n        else:\n\n            A[j] -= nokori\n\n            nokori = 0\n\nafter = sum(A)\n\n\n\nprint((before - after))"}
{"problem_id": "p03457", "input": "N = int(input())\n\ntxy = [(0, 0, 0)] + [tuple(map(int, input().split())) for _ in range(N)]\n\nfor i in range(N):\n\n    t1, x1, y1 = txy[i]\n\n    t2, x2, y2 = txy[i+1]\n\n    if abs(x2-x1) + abs(y2-y1) <= t2 - t1 and (x1+y1+x2+y2) % 2 == (t2-t1) % 2:\n\n        continue\n\n    else:\n\n        print('No')\n\n        exit()\n\nprint('Yes')"}
{"problem_id": "p02834", "input": "n,u,v=list(map(int,input().split()))\n\nanss=0\n\nu-=1\n\nv-=1\n\nd=[[]for _ in range(n)]\n\ninf=float('inf')\n\naoki=[inf]*n\n\nfor i in range(n-1):\n\n  a,b=list(map(int,input().split()))\n\n  a-=1\n\n  b-=1\n\n  d[a].append(b)\n\n  d[b].append(a)\n\nQ=d[v]\n\naoki[v]=0\n\ndis=1\n\nvisited={v}\n\nwhile Q:\n\n  P=[]\n\n  for i in Q:\n\n    visited.add(i)\n\n    for j in d[i]:\n\n      if j not in visited:P.append(j)\n\n    aoki[i]=dis\n\n  dis+=1\n\n  Q=P\n\nQ=d[u]\n\nchokudai=[-1]*n\n\nchokudai[u]=0\n\ndis=1\n\nvisited={u}\n\npoint=-1\n\nwhile Q:\n\n  P=[]\n\n  for i in Q:\n\n    visited.add(i)\n\n    for j in d[i]:\n\n      if aoki[j]<=dis+1:\n\n        if aoki[j]==dis+1:anss=1\n\n        if point<0:point=i\n\n        continue\n\n      if j not in visited:P.append(j)\n\n    chokudai[i]=dis\n\n  dis+=1\n\n  Q=P\n\nQ=d[point]\n\ndis=chokudai[point]+1\n\nvisited={point}\n\nwhile Q:\n\n  P=[]\n\n  for i in Q:\n\n    visited.add(i)\n\n    if chokudai[i]==-1:continue\n\n    chokudai[i]=max(dis,chokudai[i])\n\n    for j in d[i]:\n\n      if j not in visited:P.append(j)\n\n  dis+=1\n\n  Q=P\n\nans=0\n\nfor i in range(n):\n\n  if aoki[i]>chokudai[i]:ans=max(ans,chokudai[i])\n\nprint((ans+anss))\n\n#print(aoki)\n\n#print(chokudai)"}
{"problem_id": "p02537", "input": "d=[0]*6**8\n\nn,k,*a=list(map(int,open(0).read().split()+d))\n\nfor i in range(n):d[i]=max(d[j]for j in range(i-99,i+1)if abs(a[i]-a[j])<=k)+1\n\nprint((max(d)))"}
{"problem_id": "p02873", "input": "S = input()\n\n\n\nlst = [1 if S[0]=='<' else -1]\n\nfor i in range(1, len(S)):\n\n    if S[i] == S[i - 1]:\n\n        lst[-1] += 1 if S[i]=='<' else -1\n\n    else:\n\n        lst.append(-1 if S[i]=='>' else 1)\n\n        \n\nans = [0]\n\n\n\nfor i in range(len(lst)):\n\n    if lst[i] > 0:\n\n        ans += list(range(1,lst[i]+1))\n\n    else:\n\n        ans[-1] = max(ans[-1], -lst[i])\n\n        ans += list(range(-lst[i]-1,-1, -1))\n\n\n\nprint((sum(ans)))\n"}
{"problem_id": "p03253", "input": "from math import floor, sqrt\n\nfrom collections import defaultdict\n\ndef factors(n):\n\n    d = defaultdict(int)\n\n    for i in range(2,floor(sqrt(n))+1):\n\n        while n % i == 0:\n\n            n //= i\n\n            d[i] += 1\n\n        if n == 1:\n\n            break\n\n    if n != 1:\n\n        d[n] += 1\n\n    return d\n\ndef inv(x, mod):\n\n    k = mod - 2\n\n    ret = 1\n\n    while k > 0:\n\n        if k&1:\n\n            ret = (ret*x) % mod\n\n        x = (x*x) % mod\n\n        k >>= 1\n\n    return ret\n\nN, M = list(map(int,input().split()))\n\nmod = 10**9+7\n\ndic = factors(M)\n\nK = len(dic)\n\nSIZE = N+max(dic.values()) if list(dic.values()) else N\n\nfact = [None]*(SIZE+1)\n\nfinv = [None]*(SIZE+1)\n\nfact[0] = 1\n\nfor i in range(1,SIZE+1):\n\n    fact[i] = (fact[i-1]*i) % mod\n\nfinv[SIZE] = inv(fact[SIZE], mod=mod)\n\nfor i in range(SIZE, 0, -1):\n\n    finv[i-1] = (finv[i]*i) % mod\n\ndef comb(n,k):\n\n    tmp = (finv[k]*finv[n-k]) % mod\n\n    return (fact[n]*tmp) % mod\n\nans = 1\n\nfor p in dic:\n\n    ans = (ans*comb(dic[p]+N-1, dic[p])) % mod\n\nprint(ans)"}
{"problem_id": "p03416", "input": "a , b = input().split()\n\na = int(a)\n\nb = int(b)\n\ncount=0\n\nfor i in range(a,b+1):\n\n    test = list(str(i))\n\n    if (test[0] == test[4]) and (test[1]==test[3]):\n\n        count=count+1\n\nprint(count)"}
{"problem_id": "p03835", "input": "K,S=list(map(int,input().split()))\n\nO=0\n\nfor X in range(K+1):\n\n  for Y in range(K+1):\n\n    Z=S-X-Y\n\n    if 0<=Z<=K:\n\n      O+=1\n\nprint(O)\n"}
{"problem_id": "p04020", "input": "import sys\n\nstdin = sys.stdin\n\n \n\nsys.setrecursionlimit(10**8) \n\n \n\ndef li(): return list(map(int, stdin.readline().split()))\n\ndef li_(): return [int(x)-1 for x in stdin.readline().split()]\n\ndef lf(): return list(map(float, stdin.readline().split()))\n\ndef ls(): return stdin.readline().split()\n\ndef ns(): return stdin.readline().rstrip()\n\ndef lc(): return list(ns())\n\ndef ni(): return int(stdin.readline())\n\ndef nf(): return float(stdin.readline())\n\n\n\n\n\nn = ni()\n\na = [ni() for _ in range(n)]\n\n\n\ncnt = {i+1: ai for i, ai in enumerate(a)}\n\n\n\nprev = -100\n\ncur = 0\n\nans = 0\n\nfor key in sorted(cnt.keys()):\n\n    if cnt[key] == 0:\n\n        continue\n\n    \n\n    if prev == -100:\n\n        prev = key\n\n    \n\n    if (key-prev) < 2:\n\n        cur += cnt[key]\n\n    else:\n\n        cur = cnt[key]\n\n        \n\n    ans += cur // 2\n\n    cur -= 2 * (cur//2)\n\n    \n\n    prev = key\n\n        \n\nprint(ans)"}
{"problem_id": "p03164", "input": "def main():\n\n    N, W = list(map(int, input().split()))\n\n    w = [0] * N\n\n    v = [0] * N\n\n    for i in range(N):\n\n        w[i], v[i] = list(map(int, input().split()))\n\n\n\n    max_v = max(v)\n\n    dp = [[float('inf')] * (max_v * N + 5) for _ in range(N + 5)]\n\n\n\n    dp[0][0] = 0\n\n\n\n    for i in range(N):\n\n        for j in range(max_v * N):\n\n            if j + v[i] <= max_v * N:\n\n                dp[i+1][j + v[i]] = min(dp[i+1][j + v[i]], dp[i][j] + w[i])\n\n            dp[i+1][j] = min(dp[i+1][j], dp[i][j]) \n\n\n\n    ans = 0\n\n    for j in range(max_v * N + 1):\n\n        if dp[N][j] <= W:\n\n            ans = j\n\n\n\n    print(ans)\n\n\n\nif __name__ == \"__main__\":\n\n    main()"}
{"problem_id": "p03309", "input": "n = int(input())\n\na = list(map(int,input().split()))\n\naa = []\n\nfor i in range(n):\n\n    aa.append(a[i]-(i+1))\n\nb = (sorted(aa)[n//2])\n\n\n\nans = 0\n\nfor i in range(n):\n\n    ans += abs(a[i]-(b+i+1))\n\nprint(ans)"}
{"problem_id": "p02794", "input": "N = int(input())\n\nX = [[] for i in range(N)]\n\nfor i in range(N-1):\n\n    x, y = list(map(int, input().split()))\n\n    X[x-1].append(y-1)\n\n    X[y-1].append(x-1)\n\n\n\nP = [-1] * N\n\nDE = [0] * N\n\nQ = [0]\n\nwhile Q:\n\n    i = Q.pop()\n\n    for a in X[i][::-1]:\n\n        if a != P[i]:\n\n            P[a] = i\n\n            DE[a] = DE[i] + 1\n\n            X[a].remove(i)\n\n            Q.append(a)\n\n\n\ndef lp(u, v):\n\n    t = 0\n\n    while u != v:\n\n        if DE[u] > DE[v]:\n\n            t += 1 << u-1\n\n            u = P[u]\n\n        elif DE[u] < DE[v]:\n\n            t += 1 << v-1\n\n            v = P[v]\n\n        else:\n\n            t += 1 << u-1\n\n            t += 1 << v-1\n\n            u = P[u]\n\n            v = P[v]\n\n    \n\n    return t\n\n\n\nY = []\n\nM = int(input())\n\nfor _ in range(M):\n\n    a, b = list(map(int, input().split()))\n\n    a, b = a-1, b-1\n\n    Y.append(lp(a, b))\n\n\n\nD = {1<<i: i for i in range(50)}\n\nZ = [0] * (1<<M)\n\nans = 0\n\nCC = [0] * N\n\nBC = [0] * (1<<17)\n\nfor m in range(1, 1<<17):\n\n    a = m & (-m)\n\n    BC[m] = BC[m^a] + 1\n\nfor m in range(1<<M):\n\n    a = m & (-m)\n\n    if a == m:\n\n        if a == 0:\n\n            Z[m] = 0\n\n        else:\n\n            Z[m] = Y[D[a]]\n\n    else:\n\n        Z[m] = Z[m^a] | Y[D[a]]\n\n    \n\n    aa = Z[m]\n\n    bc = BC[aa % (1<<17)]\n\n    aa >>= 17\n\n    bc += BC[aa % (1<<17)]\n\n    aa >>= 17\n\n    bc += BC[aa]\n\n    CC[N - 1 - bc] += (1 if BC[m%1024] + BC[m>>10] & 1 == 0 else -1)\n\n\n\nprint((sum([2 ** i * CC[i] for i in range(N)])))"}
{"problem_id": "p03078", "input": "\n\nfrom heapq import heappop, heappush\n\n\n\nX, Y, Z, K = list(map(int, input().split()))\n\nA = list(map(int, input().split()))\n\nB = list(map(int, input().split()))\n\nC = list(map(int, input().split()))\n\n\n\nA.sort(reverse=True)\n\nB.sort(reverse=True)\n\nC.sort(reverse=True)\n\n\n\npq = []\n\nheappush(pq, (-A[0] - B[0] - C[0], 0, 0, 0))\n\nappeared = set((0, 0, 0))\n\n\n\nfor _ in range(K):\n\n    # Pop maximum value\n\n    val, i, j, k = heappop(pq)\n\n    print((-val))\n\n\n\n    # Add next value\n\n    if i + 1 < X and (i + 1, j, k) not in appeared:\n\n        heappush(pq, (-A[i + 1] - B[j] - C[k], i + 1, j, k))\n\n        appeared.add((i + 1, j, k))\n\n\n\n    if j + 1 < Y and (i, j + 1, k) not in appeared:\n\n        heappush(pq, (-A[i] - B[j + 1] - C[k], i, j + 1, k))\n\n        appeared.add((i, j + 1, k))\n\n\n\n    if k + 1 < Z and (i, j, k + 1) not in appeared:\n\n        heappush(pq, (-A[i] - B[j] - C[k + 1], i, j, k + 1))\n\n        appeared.add((i, j, k + 1))\n"}
{"problem_id": "p02773", "input": "import collections\n\nn = int(input())\n\na=[input() for _ in range(n)]\n\nanslist=[]\n\nb=collections.Counter(a)\n\nc=max(list(b.values()))\n\nfor i in b:\n\n    if b[i]==c:\n\n        anslist.append(i)\n\nd=sorted(anslist)\n\nfor i in tuple(d):\n\n    print(i)"}
{"problem_id": "p03371", "input": "a,b,c,x,y = list(map(int,input().split()))\n\nxy = max(x,y)*2+1\n\nprint((min([c*i + max(0,a*(x-i//2)) +max(0,b*(y-i//2)) for i in range(0,xy,2)])))"}
{"problem_id": "p02412", "input": "while True:\n\n    n, x = [int(i) for i in input().split()]\n\n\n\n    if n == x == 0:\n\n        break\n\n\n\n    count = 0\n\n    for s in range(1, n - 1):\n\n        for m in range(s + 1, n):\n\n            for e in range(m + 1, n + 1):\n\n                if x == sum([s, m, e]):\n\n                    count += 1\n\n\n\n    print(count)"}
{"problem_id": "p02837", "input": "n = int(input())\n\nv = [[tuple(map(int, input().split()))for i in range(int(input()))]\n\n     for i in range(n)]\n\n\n\nans = 0\n\nfor i in range(2**n):\n\n    f = [False] * n\n\n    xy = []\n\n    for j in range(n):\n\n        if (i >> j) & 1:\n\n            f[j] = True\n\n            xy.append(v[j])\n\n    flag = True\n\n    for xyi in xy:\n\n        for x, y in xyi:\n\n            if f[x - 1] is not bool(y):\n\n                flag = False\n\n                break\n\n    if flag:\n\n        ans = max(ans, len(xy))\n\nprint(ans)\n"}
{"problem_id": "p03000", "input": "N,X = list(map(int,input().split()))\n\nL = [0] + [int(x) for x in input().split()]\n\n\n\nD = [0] * (N+2)\n\nanswer = 1\n\nfor n in range(2,N+2):\n\n  D[n] = D[n-1] + L[n-1]\n\n  if D[n] <= X:\n\n    answer += 1\n\n    \n\nprint(answer)"}
{"problem_id": "p02983", "input": "mod = 2019\n\nl, r = list(map(int, input().split()))\n\n\n\nif r//mod - l//mod > 0:\n\n  print((0))\n\nelse:\n\n  l %= mod\n\n  r %= mod\n\n  ans = mod\n\n  for i in range(l+1, r+1):\n\n    for j in range(l, i):\n\n      ans = min(i*j%mod, ans)\n\n    if ans == 0:\n\n      break\n\n  print(ans)"}
{"problem_id": "p03425", "input": "#!/usr/bin/env python3\n\n\n\nn = int(input())\n\ns = [input() for _ in range(n)]\n\n\n\nc = [0 for _ in range(5)]\n\nt = 'MARCH'\n\n\n\nfor i in range(n):\n\n    for j in range(5):\n\n        if s[i][0] == t[j]:\n\n            c[j] += 1\n\nans = 0 \n\nfor i in range(5):\n\n    for j in range(i+1, 5): \n\n        for k in range(j+1, 5): \n\n            ans += c[i]*c[k]*c[j]\n\nprint(ans)\n"}
{"problem_id": "p00053", "input": "prim=[True]*1000000\n\nprim[0],prim[1]=False,False\n\nfor i in range(2,1000):\n\n    if prim[i]:\n\n        for j in range(i*2,1000000,i):\n\n            prim[j]=False\n\nprime=[i for i,j in enumerate(prim) if j==True]\n\n\n\nwhile True:\n\n    n=int(input())\n\n    if n==0:\n\n        break\n\n    print((sum(prime[:n])))"}
{"problem_id": "p03037", "input": "n, m = list(map(int, input().split()))\n\ngate = []\n\nl, r = list(map(int, input().split()))\n\nfor i in range(1, m):\n\n    m, s = list(map(int, input().split()))\n\n    if l < m:\n\n        l = m\n\n    if s < r:\n\n        r = s\n\nprint((len([i for i in range(l, r + 1)])))"}
{"problem_id": "p02596", "input": "K=int(input())\n\n\n\nif K%2==0:\n\n    print((-1))\n\n    exit(0)\n\n    \n\nans=[0]*(pow(10,6)+1)\n\nans[0]=0\n\n\n\nfor i in range(1,pow(10,6)):\n\n    ans[i]=(ans[i-1]*10+7)%K\n\n    if ans[i]==0:\n\n        print(i)\n\n        exit(0)\n\n\n\nprint((-1))"}
{"problem_id": "p02537", "input": "def segfunc(x, y): return max(x, y)\n\n\n\nclass SegmentTree:\n\n    def __init__(self, arr):\n\n        size = len(arr)\n\n        n = 2 ** (size - 1).bit_length()\n\n        self.n = n\n\n        self.node = [0] * (2*n)\n\n        for i in range(size):\n\n            self.node[i+n-1] = arr[i]\n\n        for i in reversed(list(range(n-2))):\n\n            self.node[i] = segfunc(self.node[2*i+1], self.node[2*i+2])\n\n\n\n    def update(self, i, x):\n\n        i += self.n - 1\n\n        self.node[i] = x\n\n        while i > 0:\n\n            i = (i - 1) // 2\n\n            self.node[i] = segfunc(self.node[i * 2 + 1], self.node[i * 2 + 2])\n\n\n\n    def update(self, x, val):\n\n        x += (self.n - 1)\n\n        self.node[x] = val\n\n        while x > 0:\n\n            x = (x - 1) // 2\n\n            self.node[x] = segfunc(self.node[2 * x + 1], self.node[2 * x + 2])\n\n\n\n    def query(self, a, b):\n\n        res = 0\n\n        l = self.n - 1 + a\n\n        r = self.n - 1 + (b - 1)\n\n\n\n        while l <= r:\n\n            if l == r:\n\n                res = segfunc(res, self.node[l])\n\n                break\n\n\n\n            if l % 2 == 0:\n\n                res = segfunc(res, self.node[l])\n\n            if r % 2 == 1:\n\n                res = segfunc(res, self.node[r])\n\n            l = l // 2\n\n            r = r // 2 - 1\n\n\n\n        return res\n\n\n\nN, K = list(map(int, input().split()))\n\nINF = 0\n\nseg = SegmentTree([0] * 300000)\n\nfor i in range(N):\n\n    a = int(input())\n\n    tmp = seg.query(max(a - K, 0), min(a + K, 300000) + 1) + 1\n\n    seg.update(a, tmp)\n\nprint((seg.query(0, 300000)))\n"}
{"problem_id": "p03037", "input": "N,M = list(map(int, input().split()))\n\nL = []\n\nR = []\n\nfor _ in range(M):\n\n  l,r = list(map(int, input().split()))\n\n  L.append(l)\n\n  R.append(r)\n\n\n\nans = min(R)-max(L)+1\n\nif ans < 0:\n\n  print((0))\n\nelse:\n\n  print(ans)\n\n  "}
{"problem_id": "p03325", "input": "N = int(input())\n\n\n\nseq = list(map(int, input().split()))\n\n\n\ncnt = 0\n\n\n\nfor num in seq:\n\n    while num % 2 == 0:\n\n        cnt += 1\n\n        num /= 2\n\n\n\nprint(cnt)\n"}
{"problem_id": "p03371", "input": "import sys\n\nsys.setrecursionlimit(10 ** 6)\n\n# input = sys.stdin.readline    ####\n\nint1 = lambda x: int(x) - 1\n\ndef II(): return int(input())\n\n\n\ndef MI(): return list(map(int, input().split()))\n\ndef MI1(): return list(map(int1, input().split()))\n\n\n\ndef LI(): return list(map(int, input().split()))\n\ndef LI1(): return list(map(int1, input().split()))\n\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\n\n\n\ndef printlist(lst, k='\\n'): print((k.join(list(map(str, lst)))))\n\nINF = float('inf')\n\n\n\ndef solve():\n\n    a, b, c, x, y = MI()\n\n\n\n    ans = INF\n\n    for k in range(100001):\n\n        yen = 2 * c * k + max(0, x-k) * a + max(0, y-k) * b\n\n        ans = min(ans, yen)\n\n    print(ans)\n\n\n\n\n\nif __name__ == '__main__':\n\n    solve()\n"}
{"problem_id": "p03796", "input": "import math\n\nn = int(input())\n\nprint((math.factorial(n)%(10**9+7)))"}
{"problem_id": "p03845", "input": "n,t=int(input()),list(map(int,input().split()));T=sum(t)\n\nprint(*[T-t[i-1]+j for i,j in [list(map(int,input().split())) for _ in range(int(input()))]],sep='\\n')\n"}
{"problem_id": "p03363", "input": "n = int(input())\n\nA = [int(i) for i in input().split()]\n\nS = [0]*(n+1)\n\nnum={}\n\nfor i in range(n):\n\n    S[i+1] = S[i] + A[i]\n\nfor i in S:\n\n    if str(i) in list(num.keys()):\n\n        num[str(i)] += 1\n\n    else:\n\n        num[str(i)] = 1\n\nout = [i*(i-1)//2 for i in list(num.values()) if i>1]\n\nprint((sum(out)))"}
{"problem_id": "p02555", "input": "def resolve():\n\n  base = 10**9+7\n\n  S = int(input())\n\n  dp = [0] * (S+1)\n\n  dp[0] = 1\n\n\n\n  for i in range(1, S+1):\n\n    for u in range(i-2):\n\n      dp[i] += dp[u]\n\n      dp[i] %= base\n\n  # print(dp)\n\n  print((dp[S]%base))\n\n\n\nif __name__ == \"__main__\":\n\n  resolve()\n"}
{"problem_id": "p02792", "input": "N = int(input())\n\n\n\ntable = [[0]*10 for i in range(10)]\n\n\n\nfor i in range(1, N+1):\n\n  s = str(i)\n\n  id1 = int(s[0])\n\n  id2 = int(s[-1])\n\n  table[id1][id2] += 1\n\n\n\nans = 0\n\nfor i in range(10):\n\n  for j in range(10):\n\n    ans += table[i][j]*table[j][i]\n\n\n\nprint(ans)"}
{"problem_id": "p03796", "input": "n = int(input())\n\nres = 1\n\nfor num in range(1, n+1):\n\n  res = res * num\n\n  res = res % (pow(10,9) + 7)\n\nprint(res)"}
{"problem_id": "p03371", "input": "#!/usr/bin/env python3\n\nimport sys, math, math, itertools\n\n\n\n\n\ndef solve(A: int, B: int, C: int, X: int, Y: int):\n\n    mn = 1e9\n\n    for i in range(0, 2*(max(X, Y)+1), 2):\n\n        mn = min(mn, C*i+A*max(X-i//2, 0)+B*max(Y-i//2, 0))\n\n    print((int(mn)))\n\n    return\n\n\n\n\n\n# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)\n\ndef main():\n\n    def iterate_tokens():\n\n        for line in sys.stdin:\n\n            for word in line.split():\n\n                yield word\n\n    tokens = iterate_tokens()\n\n    A = int(next(tokens))  # type: int\n\n    B = int(next(tokens))  # type: int\n\n    C = int(next(tokens))  # type: int\n\n    X = int(next(tokens))  # type: int\n\n    Y = int(next(tokens))  # type: int\n\n    solve(A, B, C, X, Y)\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03038", "input": "import sys\n\nfrom operator import itemgetter\n\n\n\nn, m = list(map(int, input().split()))\n\na = list(map(int, sys.stdin.readline().split()))\n\nbc = [ tuple(map(int, x.split())) for x in sys.stdin.readlines()]\n\nbc.sort(key = itemgetter(1), reverse=True)\n\nbc.append((n,0))\n\ndiff = []\n\nfor b, c in bc:\n\n    diff += [c] * b\n\n    if len(diff) > n:\n\n        break\n\n\n\na += diff\n\na.sort()\n\nprint((sum(a[-n:])))\n"}
{"problem_id": "p02917", "input": "N = int(input())\n\nB =list(map(int,input().split()))\n\nA=[0]*N\n\n\n\nA[0]=B[0]\n\nfor i in range(1,N-1):\n\n    A[i]=min(B[i],B[i-1])\n\nA[-1]=B[-1]\n\nprint((sum(A)))"}
{"problem_id": "p02700", "input": "import sys\n\ninput = sys.stdin.readline\n\nfrom collections import *\n\n\n\nA, B, C, D = list(map(int, input().split()))\n\n\n\nwhile True:\n\n    C -= B\n\n    \n\n    if C<=0:\n\n        print('Yes')\n\n        exit()\n\n    \n\n    A -= D\n\n    \n\n    if A<=0:\n\n        print('No')\n\n        exit()"}
{"problem_id": "p03575", "input": "icase=0\n\nif icase==0:\n\n    n,m=list(map(int, input().split()))\n\n    a=[]\n\n    b=[]\n\n    for i in range(m):\n\n        ai,bi=list(map(int, input().split()))\n\n        a.append(ai)\n\n        b.append(bi)\n\nelif icase==1:\n\n    n=6\n\n    m=5\n\n#    a=[[1],[2],[3],[4],[5]]\n\n#    b=[[2],[3],[4],[5],[6]]\n\n    a=[1,2,3,4,5]\n\n    b=[2,3,4,5,6]\n\nelif icase==2:\n\n    n=7\n\n    m=7\n\n    a=[1,2,3,4,4,5,6]\n\n    b=[3,7,4,5,6,6,7]\n\n\n\n    \n\nvtx=[]\n\nfor i in range(n):\n\n    vtx.append([i+1])\n\nicnt=0\n\n\n\nfor j in range(m):    \n\n    vtx1=vtx.copy()\n\n    a1=a.copy()\n\n    b1=b.copy()\n\n    del a1[j]\n\n    del b1[j]\n\n    \n\n    for i in range(m-1):\n\n        for v1 in vtx1:\n\n            if a1[i] in v1:\n\n                if not b1[i] in v1:\n\n                    for v2 in vtx1:\n\n                        if v1!=v2:\n\n                            if b1[i] in v2:\n\n                                break\n\n                    vtx1.remove(v1)\n\n                    vtx1.remove(v2)\n\n                    v3=v1+v2\n\n                    vtx1.append(v3)\n\n#        print(a[i],b[i],len(vtx1),vtx1)\n\n#    print(len(vtx1),vtx1)\n\n    if len(vtx1)!=1:\n\n        icnt=icnt+1\n\nprint(icnt)        "}
{"problem_id": "p02814", "input": "#!/usr/bin/env python3\n\nimport sys\n\nfrom math import gcd\n\nimport math\n\n\n\ndef main():\n\n    N, M = list(map(int, input().split()))\n\n    a = list(map(int, input().split()))\n\n    tmp = 1\n\n    count = None\n\n    for i in range(N):\n\n      tmp = (tmp * a[i]//2) // gcd(tmp,a[i]//2)\n\n      c = 0\n\n      n = a[i]//2\n\n      while n % 2 == 0:\n\n        c += 1\n\n        n //= 2\n\n      if i == 0:\n\n        count = c\n\n      elif count != c:\n\n        print((0))\n\n        exit()\n\n    print(((M//tmp +1)//2))\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p02394", "input": "a=input().split()\n\nb=list(map(int,a))\n\nW=b[0]\n\nH=b[1]\n\nx=b[2]\n\ny=b[3]\n\nr=b[4]\n\nif (r <= x <= (W - r)) and (r <= y <= (H - r)):\n\n  print('Yes')\n\nelse:\n\n  print('No')"}
{"problem_id": "p02394", "input": "ia = [int(i) for i in input().split(\" \")]\n\nW=ia[0]\n\nH=ia[1]\n\nx=ia[2]\n\ny=ia[3]\n\nr=ia[4]\n\nprint((\"Yes\" if 0<=x-r and x+r<=W and 0<=y-r and y+r<=H else \"No\"))"}
{"problem_id": "p03457", "input": "N=input()\n\na=[]\n\nt=True\n\nfor _ in range(int(N)):\n\n    a+=[list(map(int,input().split()))]\n\nfor i in range(int(N)):\n\n    if a[i][0]%2==0:\n\n        if abs(a[i][1]+a[i][2])<=a[i][0] and (a[i][1]+a[i][2])%2==0:\n\n            continue\n\n        else:\n\n            print('No')\n\n            t=False\n\n            break\n\n    else:\n\n        if abs(a[i][1]+a[i][2]<=a[i][0]) and (a[i][1]+a[i][2])%2==1:\n\n            continue\n\n        else:\n\n            print('No')\n\n            t=False\n\n            break\n\nif t:\n\n    print('Yes')"}
{"problem_id": "p03371", "input": "a,b,c,x,y=list(map(int,input().split()))\n\n\n\nyenmin=a*x+b*y\n\nfor zz in range(2*10**5+1):\n\n    xx=max(x-zz//2,0)\n\n    yy=max(y-zz//2,0)\n\n    yen=a*xx+b*yy+c*zz\n\n    if yen<yenmin:\n\n        yenmin=yen\n\nprint(yenmin)\n\n#print(xx,yy,zz)"}
{"problem_id": "p03837", "input": "import queue\n\n\n\nINF = 123456789\n\n\n\ndef main():\n\n    n,m = list(map(int,input().split()))\n\n\n\n    G = [[] for _ in range(n)]\n\n    for _ in range(m):\n\n        a,b,c = list(map(int,input().split()))\n\n        a -= 1\n\n        b -= 1\n\n        G[a].append((b,c))\n\n        G[b].append((a,c))\n\n\n\n    used = set()\n\n    for i in range(n):\n\n        d = [INF for _ in range(n)]\n\n        par = [-1 for _ in range(n)]\n\n\n\n        # dijkstra\n\n        que = queue.PriorityQueue()\n\n        d[i] = 0\n\n        que.put((0,i))\n\n        while not que.empty():\n\n            p = que.get()\n\n            v = p[1]\n\n            if d[v] < p[0]:\n\n                continue\n\n            for (to,cost) in G[v]:\n\n                if d[to] > d[v]+cost:\n\n                    d[to] = d[v]+cost\n\n                    par[to] = v\n\n                    que.put((d[to],to))\n\n\n\n        for j in range(n):\n\n            if i != j:\n\n                a,b = j,par[j]\n\n                if a>b:\n\n                    a,b = b,a\n\n                used.add((a,b))\n\n\n\n    print((m - len(used)))\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03416", "input": "a,b = list(map(int,input().split()))\n\ncount = 0\n\nfor i in range(a,b+1):\n\n    s = str(i)\n\n    l = len(s)\n\n    if all(s[j] == s[l-j-1] for j in range(l)):\n\n            count += 1\n\nprint(count)"}
{"problem_id": "p02921", "input": "import itertools\n\nimport math\n\ndef main():\n\n  s = input()\n\n  t = input()\n\n  cnt = 0\n\n  for i in range(3):\n\n    if s[i] == t[i]:\n\n      cnt += 1\n\n  print(cnt)\n\nif __name__ == '__main__':\n\n  main()"}
{"problem_id": "p03579", "input": "import sys\n\nsys.setrecursionlimit(100000)\n\nN, M = list(map(int, input().split()))\n\nedges = [list(map(int, input().split())) for _ in range(M)]\n\n\n\ngraph = [[] for _ in range(N)]\n\nfor x, y in edges:\n\n    graph[x - 1].append(y - 1)\n\n    graph[y - 1].append(x - 1)\n\n\n\ndef dfs(v, c):\n\n    # c: color = 1 or -1\n\n    node[v] = c\n\n    for i in graph[v]:\n\n        if node[i] == c:\n\n            return False\n\n        \n\n        if node[i] == 0 and not dfs(i, -c):\n\n            return False\n\n        \n\n    return True\n\n\n\nnode = [0] * N\n\nif dfs(0, 1):\n\n    x = sum(v + 1 for v in node) // 2\n\n    print((x * (N - x) - M))\n\nelse:\n\n    print((N * (N - 1) // 2 - M))\n"}
{"problem_id": "p02248", "input": "def kmpTable(w):\n\n    lw = len(w)\n\n    nx = [-1] * (lw + 1)\n\n    j = -1\n\n    for i in range(lw):\n\n        while j >= 0 and w[i] != w[j]:\n\n            j = nx[j]\n\n        j += 1\n\n        nx[i + 1] = j\n\n    return nx\n\ndef kmpSearch(s, w):\n\n    ls = len(s)\n\n    start = 0\n\n    w_idx = 0\n\n    ret = []\n\n    nx = kmpTable(w)\n\n    while start + w_idx < ls:\n\n        if s[start + w_idx] == w[w_idx]:\n\n            w_idx += 1\n\n            if w_idx == len(w):\n\n                ret.append(start)\n\n                start = start + w_idx - nx[w_idx]\n\n                w_idx = nx[w_idx]\n\n        else:\n\n            if w_idx == 0:\n\n                start += 1\n\n            else:\n\n                start = start + w_idx - nx[w_idx]\n\n                w_idx = nx[w_idx]\n\n    return ret\n\nT = input()\n\nP = input()\n\nans = kmpSearch(T, P)\n\nif ans:\n\n    print((\"\\n\".join(map(str, ans))))\t\n\n\n"}
{"problem_id": "p03457", "input": "def main():\n\n    import sys\n\n    input = sys.stdin.buffer.readline\n\n    N = int(input())\n\n    TXY = [[int(i) for i in input().split()] for j in range(N)]\n\n    time, px, py = 0, 0, 0\n\n    for t, x, y in TXY:\n\n        move = abs(x-px) + abs(y-py)\n\n        # print(move, t-time)\n\n        if (t - time) % 2 != move % 2 or t - time < move:\n\n            return print(\"No\")\n\n        time, px, py = t, x, y\n\n    print(\"Yes\")\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03553", "input": "import math,string,itertools,math,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\n\n\nsys.setrecursionlimit(10**7)\n\ninf = 10**20\n\neps = 1.0 / 10**15\n\nmod = 10**9+7\n\n\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\n\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\n\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\n\ndef LS(): return sys.stdin.readline().split()\n\ndef I(): return int(sys.stdin.readline())\n\ndef F(): return float(sys.stdin.readline())\n\ndef S(): return input()\n\ndef pf(s): return print(s, flush=True)\n\ndef divisions(n):\n\n    sq = int(math.sqrt(n)+1)\n\n    d = collections.defaultdict(int)\n\n    while n % 2 == 0:\n\n        n //= 2\n\n        d[2] += 1\n\n    i = 3\n\n    while n > 1 and sq >= i:\n\n        if n % i == 0:\n\n            n //= i\n\n            d[i] += 1\n\n        else:\n\n            i += 2\n\n\n\n    if n > 1:\n\n        d[n] += 1\n\n\n\n    r = [1]\n\n    for k, v in d.items():\n\n        for c in r[:]:\n\n            for i in range(1,v+1):\n\n                r.append(c*(k**i))\n\n\n\n    return sorted(r)\n\n\n\ndef main():\n\n    n = I()\n\n    a = LI()\n\n    s = set()\n\n    for i in range(n,0,-1):\n\n        d = divisions(i)\n\n        ld = len(d)\n\n        for j in range(1,2**ld):\n\n            c = []\n\n            ff = True\n\n            for k in range(ld):\n\n                if j & (1<<k):\n\n                    f = True\n\n                    for e in c:\n\n                        if d[k] % e == 0:\n\n                            f = False\n\n                            ff = False\n\n                            break\n\n                    if f:\n\n                        c.append(d[k])\n\n                if not ff:\n\n                    break\n\n            if ff:\n\n                s.add(tuple(c + [n+1]))\n\n    b = sorted(list(s), reverse=True)\n\n    for c in b:\n\n        t = 0\n\n        for j in range(1,n+1):\n\n            f = False\n\n            for e in c:\n\n                if j%e == 0:\n\n                    f = True\n\n                    break\n\n            if f:\n\n                t += a[j-1]\n\n        if t < 0:\n\n            for j in range(1,n+1):\n\n                f = False\n\n                for e in c:\n\n                    if j%e == 0:\n\n                        f = True\n\n                        break\n\n                if f:\n\n                    a[j-1] = 0\n\n\n\n    return sum(a)\n\n\n\n\n\n\n\nprint(main())\n\n\n\n\n"}
{"problem_id": "p02881", "input": "N = int(input())\n\nans = N - 1\n\np = 1\n\nfor i in range(2, int((N ** 0.5) + 1)):\n\n    if p % 2 == 1 and i > (N ** 0.5):\n\n        break\n\n    if N % i == 0:\n\n        p = i\n\n        j = N // i\n\n        m = i + j - 2\n\n        if m < ans:\n\n            ans = m\n\n        else:\n\n            continue\n\n    else:\n\n        continue\n\nprint(ans)\n"}
{"problem_id": "p03078", "input": "import sys\n\nimport heapq\n\n\n\n\n\n# \\n\n\ndef input():\n\n    return sys.stdin.readline().rstrip()\n\n\n\n\n\ndef main():\n\n    X, Y, Z, K = list(map(int, input().split()))\n\n    A = list(map(int, input().split()))\n\n    B = list(map(int, input().split()))\n\n    C = list(map(int, input().split()))\n\n\n\n    A.sort(reverse=True)\n\n    B.sort(reverse=True)\n\n    C.sort(reverse=True)\n\n\n\n    Q = []\n\n    S = set()\n\n    heapq.heapify(Q)\n\n    heapq.heappush(Q, (-A[0] - B[0] - C[0], 0, 0, 0))\n\n    for i in range(K):\n\n        m, a, b, c = heapq.heappop(Q)\n\n        print((-m))\n\n        if (a + 1, b, c) not in S and a + 1 < X:\n\n            heapq.heappush(Q, (-A[a + 1] - B[b] - C[c], a + 1, b, c))\n\n            S.add((a + 1, b, c))\n\n        if (a, b + 1, c) not in S and b + 1 < Y:\n\n            heapq.heappush(Q, (-A[a] - B[b + 1] - C[c], a, b + 1, c))\n\n            S.add((a, b + 1, c))\n\n        if (a, b, c + 1) not in S and c + 1 < Z:\n\n            heapq.heappush(Q, (-A[a ] - B[b] - C[c+1], a, b, c + 1))\n\n            S.add((a, b, c + 1))\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()\n"}
{"problem_id": "p03494", "input": "def two_count(x):\n\n\tif int(str(x)[-1]) % 2 == 0:\n\n\t\treturn 1 + two_count(x//2)\n\n\telse:\n\n\t\treturn 0\n\n\n\nn = int(input())\n\nn_list = [int(n) for n in input().split(\" \")]\n\n\n\nn_two_count_list = [two_count(n) for n in n_list]\n\n\n\nprint((min(n_two_count_list)))"}
{"problem_id": "p02386", "input": "n=int(input())\n\na=[list(map(int,input().split()))for _ in range(n)]\n\ndef f():\n\n for i in range(n-1):\n\n  d=a[i][:];d[3],d[4]=d[4],d[3]\n\n  for j in range(i+1,n):\n\n   e=a[j][:];e[3],e[4]=e[4],e[3]\n\n   for p in('012345','152043','215304','302541','410352','514320'):\n\n    f=[d[int(k)]for k in p]\n\n    g=f[1:5]*2\n\n    for k in range(4):\n\n     if(g[k:k+4]==e[1:5])*(f[0]==e[0])*(f[5]==e[5]):return 'No'\n\n return 'Yes'\n\nprint((f()))\n"}
{"problem_id": "p02814", "input": "from math import gcd\n\nn, m = list(map(int, input().split()))\n\na = [int(i) // 2 for i in input().split()]\n\nx = 1\n\nfor i in range(n):\n\n    x *= a[i] // gcd(x, a[i])\n\nfor i in a:\n\n    if x // i % 2 == 0:\n\n        print((0))\n\n        exit()\n\nprint(((m // x + 1) // 2))"}
{"problem_id": "p03038", "input": "import sys\n\ninput = lambda: sys.stdin.readline()[:-1]\n\nn,m=list(map(int,input().split()))\n\na0=list(map(int,input().split()))\n\ndata=[list(map(int,input().split())) for i in range(m)]\n\nfor i in a0:\n\n\tdata.append([1,i])\n\ndata.sort(key=lambda tup:-tup[1])\n\nans=0\n\nfor num,val in data:\n\n\tif n>=num:\n\n\t\tn-=num\n\n\t\tans+=val*num\n\n\telse:\n\n\t\tans+=val*n\n\n\t\tbreak\n\nprint(ans)\n"}
{"problem_id": "p03200", "input": "import sys\n\nsys.setrecursionlimit(10**6)\n\nif sys.platform in (['ios','darwin','win32']):\n\n\tsys.stdin=open('Untitled.txt')\n\ninput = sys.stdin.readline\n\ndef INT(): return int(input())\n\ndef MAP(): return [int(s) for s in input().split()]\n\n\n\ndef main():\n\n\tS = input().rstrip()\n\n\tbcnt = 0\n\n\tA = []\n\n\tfor i in range(len(S)):\n\n\t\tif S[i] == 'B': bcnt += 1\n\n\t\tif S[i] == 'W': A.append(bcnt)\n\n\t\n\n\tprint((sum(A)))\n\n\n\nif __name__ == '__main__':\n\n\tmain()"}
{"problem_id": "p03416", "input": "a,b = list(map(int, input().split()))\n\nn = 0\n\nfor i in range(a, b + 1):\n\n    f = True\n\n    s = str(i)\n\n    l = len(s)\n\n    for j in range(l//2 + 1):\n\n        if s[j] != s[- j - 1]:\n\n            f = False\n\n            break\n\n    if f:\n\n        n += 1\n\nprint(n)"}
{"problem_id": "p03752", "input": "import sys\n\n\n\nread = sys.stdin.read\n\nreadline = sys.stdin.readline\n\nreadlines = sys.stdin.readlines\n\nsys.setrecursionlimit(10 ** 9)\n\nINF = 1 << 60\n\n\n\n\n\ndef main():\n\n    N, K, *A = list(map(int, read().split()))\n\n\n\n    ans = INF\n\n    for bit in range(1 << N):\n\n        if (not (bit & 1)) or bin(bit).count('1') != K:\n\n            continue\n\n\n\n        total = 0\n\n        max_height = A[0]\n\n        for i, a in enumerate(A[1:], 1):\n\n            if a <= max_height:\n\n                if bit & (1 << i):\n\n                    total += max_height - a + 1\n\n                    max_height += 1\n\n            else:\n\n                max_height = a\n\n\n\n        if ans > total:\n\n            ans = total\n\n\n\n    print(ans)\n\n\n\n    return\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p02952", "input": "import math\n\nn = int(input())\n\ncnt = 0\n\nfor i in range(1, n + 1):\n\n    if math.floor(math.log10(i) + 1) % 2:\n\n        cnt += 1\n\nprint(cnt)"}
{"problem_id": "p02773", "input": "from collections import defaultdict\n\nn = int(input())\n\n\n\nd = defaultdict(int)\n\nfor _ in range(n):\n\n    key = input()\n\n    d[key] += 1\n\n\n\ndict = sorted(list(d.items()), key=lambda x:x[1], reverse=True)\n\nmax_v = max(d.values())\n\n\n\ndict_li = []\n\nfor a in dict:\n\n    if a[1]==max_v:\n\n        dict_li.append(a[0])\n\n\n\ndict_li.sort()\n\nfor s in dict_li:\n\n    print(s)\n"}
{"problem_id": "p03721", "input": "n,k = list(map(int,input().split()))\n\nl = [0]*(10**5+1)\n\nfor i in range(n):\n\n    ai,bi = list(map(int,input().split()))\n\n    l[ai]+=bi\n\nfor index,i in enumerate(l):\n\n    if i:\n\n        k-=i\n\n        if k<=0:\n\n            break\n\nprint(index)"}
{"problem_id": "p03416", "input": "A, B = list(map(int, input().split()))\n\ncnt = 0\n\nfor i in range(A, B+1):\n\n    l = list(str(i))\n\n\n\n    if l == list(reversed(l)):\n\n        cnt += 1\n\n\n\nprint(cnt)\n"}
{"problem_id": "p03363", "input": "n = int(input())\n\nary = list(map(int, input().split()))\n\n#print(n,ary)\n\n\n\nary_2 = [ary[0]]\n\nfor i in range(1, n):\n\n    ary_2.append(ary[i] + ary_2[i-1])\n\nary_2 = [0] + ary_2\n\n#print(ary_2)\n\n\n\nfrom collections import Counter\n\nc = Counter(ary_2)\n\nv = (list(c.values()))\n\n#print(v)\n\n\n\nfrom math import factorial\n\ndef combinations_count(n, r):\n\n    return factorial(n) // (factorial(n - r) * factorial(r))\n\n\n\nans = 0\n\nfor j in v:\n\n    if j >1:\n\n        ans += combinations_count(j,2)\n\n\n\nprint(ans)"}
{"problem_id": "p02792", "input": "N = int(input())\n\nmem = [[0]*10 for i in range(10)]\n\n\n\nfor i in range(1,N+1):\n\n    a = int(str(i)[0])\n\n    b = int(str(i)[-1])\n\n    mem[a][b] += 1\n\n\n\nans = 0\n\nfor i in range(1,N+1):\n\n    a = int(str(i)[0])\n\n    b = int(str(i)[-1])\n\n    ans += mem[b][a]\n\nprint(ans)"}
{"problem_id": "p03796", "input": "N = int(input())\n\np = 1\n\nfor i in range(N):\n\n    p *= (i + 1)\n\n    p %= (1e9 + 7)\n\nprint((int(p)))"}
{"problem_id": "p02725", "input": "k, n = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\n\n\ndiff = []\n\n\n\nfor i in range(n - 1):\n\n    diff.append(a[i + 1] - a[i])\n\ndiff.append(k - a[-1] + a[0])\n\n\n\nprint((k - max(diff)))\n"}
{"problem_id": "p03253", "input": "class Calc:\n\n    def __init__(self, max_value, mod):\n\n        \"\"\"combination(max_value, all)\"\"\"\n\n        fact = [-1] * (max_value + 1)\n\n        fact[0] = 1\n\n        fact[1] = 1\n\n        for x in range(2, max_value + 1):\n\n            fact[x] = x * fact[x - 1] % mod\n\n\n\n        invs = [1] * (max_value + 1)\n\n        invs[max_value] = pow(fact[max_value], mod - 2, mod)\n\n        for x in range(max_value - 1, 0, -1):\n\n            invs[x] = invs[x + 1] * (x + 1) % mod\n\n\n\n        self.fact = fact\n\n        self.invs = invs\n\n        self.mod = mod\n\n\n\n    def combination(self, n, r):\n\n        if n - r < r:\n\n            return self.combination(n, n - r)\n\n        if r < 0:\n\n            return 0\n\n        if r == 0:\n\n            return 1\n\n        if r == 1:\n\n            return n\n\n        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod\n\n\n\n\n\ndef gen(n):\n\n    x = n\n\n    d = 2\n\n    cnt = 0\n\n    while x % d == 0:\n\n        x //= d\n\n        cnt += 1\n\n    yield cnt\n\n\n\n    d = 3\n\n    ma = d * d\n\n    while ma <= n:\n\n        cnt = 0\n\n        while x % d == 0:\n\n            x //= d\n\n            cnt += 1\n\n        yield cnt\n\n        ma += d * 4 + 4\n\n        d += 2\n\n\n\n    if x > 1:\n\n        yield 1\n\n\n\n\n\ndef main():\n\n    MOD = 10 ** 9 + 7\n\n\n\n    N, M = list(map(int, input().split()))\n\n\n\n    cal = Calc(max_value=N + 30, mod=MOD)\n\n\n\n    ans = 1\n\n    for cnt in gen(M):\n\n        ans = (ans * cal.combination(N + cnt - 1, cnt)) % MOD\n\n    print(ans)\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p02983", "input": "def c_remainder_minimization_2019(L, R):\n\n    ans = float('inf')\n\n    for i in range(L, min(R, L + 2019)):\n\n        for j in range(i + 1, min(R + 1, L + 2020)):\n\n            ans = min(ans, (i * j) % 2019)\n\n    return ans\n\n\n\nL, R = [int(i) for i in input().split()]\n\nprint((c_remainder_minimization_2019(L, R)))"}
{"problem_id": "p03371", "input": "a, b, c, x, y = list(map(int, input().split()))\n\nval = float('inf')\n\nfor k in range(10 ** 5 + 1):\n\n    val = min(val, 2 * c * k + max(x - k, 0) * a + max(y - k, 0) * b)\n\nprint(val)"}
{"problem_id": "p03796", "input": "from math import factorial as f\n\nn = int(input())\n\nprint((f(n) % (10 ** 9 + 7)))"}
{"problem_id": "p03039", "input": "n,m,k=list(map(int,input().split()))\n\nmod=10**9+7\n\nf=[1]\n\nfor i in range(2*10**5+7):f+=[f[-1]*(i+1)%mod]\n\ndef comb(a,b):return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod\n\nans=0\n\nfor i in range(1,n):\n\n  ans+=(i*(n-i)*m**2)*(comb(n*m-2,k-2))\n\n  ans%=mod\n\nfor i in range(1,m):\n\n  ans+=(i*(m-i)*n**2)*(comb(n*m-2,k-2))\n\n  ans%=mod\n\nprint(ans)"}
{"problem_id": "p03796", "input": "import math\n\nprint((math.factorial(int(input()))%(10**9+7)))"}
{"problem_id": "p03371", "input": "A, B, C, X, Y = [int(_) for _ in input().split()]\n\nans = A * X + B * Y\n\nfor i in range(max(X, Y) + 1):\n\n    cost = 2 * C * i\n\n    if X > i:\n\n        cost += A * (X - i)\n\n    if Y > i:\n\n        cost += B * (Y - i)\n\n    ans = min(ans, cost)\n\nprint(ans)"}
{"problem_id": "p03945", "input": "s = input()\n\nlen_s = len(s)\n\ncnt = [0, 0]\n\nfor i in range(1, len(s)):\n\n    memo_0 = s[i - 1]\n\n    memo_1 = s[len_s - i]\n\n    if s[i] != memo_0:\n\n        cnt[0] += 1\n\n    if s[len_s - i - 1] != memo_1:\n\n        cnt[1] += 1\n\nprint((min(cnt)))\n"}
{"problem_id": "p03558", "input": "import heapq\n\nK=int(input())\n\ndist=[10**15 for i in range(K)]\n\ndist[1]=1\n\nq=[]\n\nheapq.heappush(q,(0,1))\n\nwhile (len(q)!=0):\n\n    prc,src=heapq.heappop(q)\n\n    if dist[src]<prc:\n\n        continue\n\n    if dist[(src+1)%K]>dist[src]+1:\n\n        dist[(src+1)%K]=dist[src]+1\n\n        heapq.heappush(q,(dist[(src+1)%K],(src+1)%K))\n\n    if dist[(10*src)%K]>dist[src]:\n\n        dist[(10*src)%K]=dist[src]\n\n        heapq.heappush(q,(dist[(src*10)%K],(src*10)%K))\n\nprint((dist[0]))\n"}
{"problem_id": "p02792", "input": "n = int(input())\n\n\n\ncnt = 0\n\nfor i in range(1, n+1):\n\n    i_str = str(i)\n\n    if len(i_str) == 1:\n\n        cnt += 1\n\n        continue\n\n    if len(i_str) == 2:\n\n        if int(i_str[0]) == int(i_str[1]):\n\n            cnt += 3\n\n        elif int(i_str[1]) != 0 and int(i_str[0]) > int(i_str[1]):\n\n            cnt += 2\n\n        continue\n\n    if len(i_str) == 3:\n\n        if int(i_str[0]) == int(i_str[2]):\n\n            cnt += 4 + (2 * (int(i_str[1])+1) - 1)\n\n        elif int(i_str[2]) != 0 and int(i_str[0]) > int(i_str[2]):\n\n            cnt += 22\n\n        elif int(i_str[0]) < int(i_str[2]):\n\n            cnt += 2\n\n        continue\n\n    if len(i_str) == 4:\n\n        if int(i_str[0]) == int(i_str[3]):\n\n            cnt += 24 + 20 * int(i_str[1]) + 2 * (int(i_str[2])+1) - 1\n\n        elif int(i_str[3]) != 0 and int(i_str[0]) > int(i_str[3]):\n\n            cnt += 222\n\n        elif int(i_str[0]) < int(i_str[3]):\n\n            cnt += 22\n\n        continue\n\n    if len(i_str) == 5:\n\n        if int(i_str[0]) == int(i_str[4]):\n\n            cnt += 224 + 200 * int(i_str[1]) + 20 * int(i_str[2]) + 2 * (int(i_str[3])+1) - 1\n\n        elif int(i_str[4]) != 0 and int(i_str[0]) > int(i_str[4]):\n\n            cnt += 2222\n\n        elif int(i_str[0]) < int(i_str[4]):\n\n            cnt += 222\n\n        continue\n\n    if len(i_str) == 6:\n\n        if int(i_str[0]) == int(i_str[5]):\n\n            cnt += 2224 + 2000 * int(i_str[1]) + 200 * int(i_str[2]) + 20 * int(i_str[3]) + 2 * (int(i_str[4])+1) - 1\n\n        elif int(i_str[5]) != 0 and int(i_str[0]) > int(i_str[5]):\n\n            cnt += 22222\n\n        elif int(i_str[0]) < int(i_str[5]):\n\n            cnt += 2222\n\n        continue\n\n\n\nprint(cnt)"}
{"problem_id": "p03796", "input": "import math\n\n\n\nN = int(input())\n\nans = math.factorial(N) % (10**9 + 7)\n\nprint(ans)"}
{"problem_id": "p03038", "input": "from heapq import heappop, heappush\n\n\n\nn, m = list(map(int, input().split()))\n\na = tuple(map(int, input().split()))\n\n\n\nhq = []\n\nfor aa in a:\n\n    heappush(hq, (-aa, 1))\n\n\n\nfor _ in range(m):\n\n    b, c = list(map(int, input().split()))\n\n    heappush(hq, (-c, b))\n\n\n\nrest = n\n\nans = 0\n\nwhile rest > 0:\n\n    num, cnt = heappop(hq)\n\n\n\n    num *= (-1)\n\n    use = min(rest, cnt)\n\n    ans += use * num\n\n    rest -= use\n\n\n\nprint(ans)\n"}
{"problem_id": "p03371", "input": "A,B,C,X,Y = list(map(int,input().split()))\n\nl = []\n\nfor i in range(max(X,Y)+1):\n\n    T = i * C * 2\n\n    if i < X: \n\n        T += (X-i)*A\n\n    if i < Y:\n\n        T += (Y-i)*B\n\n    l.append(T)\n\nl.sort()\n\nprint((l[0]))"}
{"problem_id": "p04012", "input": "import collections\n\nimport sys\n\na=input()\n\nb=[]\n\n\n\nfor i in a:\n\n  b.append(i)\n\n  \n\nb.sort()\n\nc=collections.Counter(b)\n\nc=list(c.values())\n\n\n\nfor i in range(len(c)):\n\n  if int(c[i])%2==0:\n\n    q=0\n\n  else:\n\n    q=1\n\n    print('No')\n\n    sys.exit()\n\n    \n\nprint('Yes')\n"}
{"problem_id": "p03835", "input": "#ABC951B/Sum_of_Three_Integers\n\n\n\nK, S = list(map(int, input().split()))\n\nans = 0\n\nfor x in range(0, K+1):\n\n    for y in range(0, K+1):\n\n        z = S - x - y\n\n        if 0 <= z and z <= K:\n\n            ans += 1\n\nprint(ans)"}
{"problem_id": "p02276", "input": "n=int(input())-1\n\nA=list(map(int,input().split()))\n\ni=0\n\nfor j in range(n):\n\n if A[j]<=A[-1]:A[i],A[j]=A[j],A[i];i+=1\n\nA[i],A[n]=A[n],A[i]\n\nprint((\" \".join(map(str,A[:i]))+\" [\"+str(A[i])+\"] \"+\" \".join(map(str,A[i+1:]))))\n"}
{"problem_id": "p02792", "input": "N = int(input())\n\nmem = [[0]*10 for _ in range(10)]\n\n\n\nfor i in range(1,N+1):\n\n    a = int(str(i)[0])\n\n    b = int(str(i)[-1])\n\n    mem[a][b] += 1\n\n\n\nans = 0\n\nfor i in range(1,N+1):\n\n    a = int(str(i)[0])\n\n    b = int(str(i)[-1])\n\n    ans += mem[b][a]\n\nprint(ans)\n"}
{"problem_id": "p04012", "input": "w = input()\n\nfor l in w:\n\n\tif w.count(l) % 2 == 1:\n\n\t\tprint(\"No\")\n\n\t\tbreak\n\nelse:\n\n\tprint(\"Yes\")"}
{"problem_id": "p03416", "input": "a, b = list(map(int, input().split()))\n\ntmp=str(a)\n\nc=0\n\nfor i in range(a,b+1):\n\n    tmp=str(i)\n\n    tmp2=\"\"\n\n    for s in range(len(tmp)):\n\n        tmp2=tmp2+tmp[len(tmp)-1-s]\n\n    if tmp==tmp2:\n\n        c=c+1\n\nprint(c)"}
{"problem_id": "p03835", "input": "k,s=list(map(int,input().split()))\n\nans=0\n\nfor i in range(k+1):\n\n    for j in range(k+1):\n\n        z=s-i-j\n\n        if 0<=z<=k:\n\n            ans+=1\n\nprint(ans)\n"}
{"problem_id": "p03078", "input": "import sys, re\n\nfrom collections import deque, defaultdict, Counter\n\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd\n\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\n\nfrom operator import itemgetter, mul\n\nfrom copy import deepcopy\n\nfrom string import ascii_lowercase, ascii_uppercase, digits\n\nfrom bisect import bisect, bisect_left, insort, insort_left\n\nfrom heapq import heappush, heappop\n\nfrom functools import reduce, lru_cache\n\ndef input(): return sys.stdin.readline().strip()\n\ndef INT(): return int(input())\n\ndef MAP(): return map(int, input().split())\n\ndef LIST(): return list(map(int, input().split()))\n\ndef TUPLE(): return tuple(map(int, input().split()))\n\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\n\nsys.setrecursionlimit(10 ** 9)\n\nINF = float('inf')\n\nmod = 10 ** 9 + 7 \n\n#mod = 998244353\n\nfrom decimal import *\n\n#import numpy as np\n\n#decimal.getcontext().prec = 10\n\n\n\nX, Y, Z, K = MAP()\n\nA = sorted(LIST(), reverse = True)\n\nB = sorted(LIST(), reverse = True)\n\nC = sorted(LIST(), reverse = True)\n\n\n\nAB = []\n\nfor i in range(X):\n\n\tfor j in range(Y):\n\n\t\tAB.append(A[i]+B[j])\n\n\n\nAB.sort(reverse = True)\n\nAB = AB[:3000]\n\nABC = sorted([C[0]+AB[i] for i in range(min(3000, X*Y))], reverse = True)\n\n\n\nfor j in range(1, Z):\n\n\tABC_tmp = sorted([C[j]+AB[i] for i in range(min(3000, X*Y))])\n\n\tABC += ABC_tmp\n\n\tABC.sort(reverse = True)\n\n\tABC = ABC[:3000]\n\n\n\nprint(*ABC[:K], sep= \"\\n\")\n\n\n"}
{"problem_id": "p00744", "input": "import collections\n\nimport math\n\n\n\n\n\nclass Dinic:\n\n    \"\"\"Dinic Algorithm: find max-flow\n\n       complexity: O(EV^2)\n\n       used in GRL6A(AOJ)\n\n    \"\"\"\n\n    class edge:\n\n        def __init__(self, to, cap, rev):\n\n            self.to, self.cap, self.rev = to, cap, rev\n\n\n\n    def __init__(self, V, E, source, sink):\n\n        \"\"\" V: the number of vertexes\n\n            E: adjacency list\n\n            source: start point\n\n            sink: goal point\n\n        \"\"\"\n\n        self.V = V\n\n        self.E = [[] for _ in range(V)]\n\n        for fr in range(V):\n\n            for to, cap in E[fr]:\n\n                self.E[fr].append(self.edge(to, cap, len(self.E[to])))\n\n                self.E[to].append(self.edge(fr, 0, len(self.E[fr])-1))\n\n        self.maxflow = self.dinic(source, sink)\n\n\n\n    def dinic(self, source, sink):\n\n        \"\"\"find max-flow\"\"\"\n\n        INF = float('inf')\n\n        maxflow = 0\n\n        while True:\n\n            self.bfs(source)\n\n            if self.level[sink] < 0:\n\n                return maxflow\n\n            self.itr = [0] * self.V\n\n            while True:\n\n                flow = self.dfs(source, sink, INF)\n\n                if flow > 0:\n\n                    maxflow += flow\n\n                else:\n\n                    break\n\n\n\n    def dfs(self, vertex, sink, flow):\n\n        \"\"\"find augmenting path\"\"\"\n\n        if vertex == sink:\n\n            return flow\n\n        for i in range(self.itr[vertex], len(self.E[vertex])):\n\n            self.itr[vertex] = i\n\n            e = self.E[vertex][i]\n\n            if e.cap > 0 and self.level[vertex] < self.level[e.to]:\n\n                d = self.dfs(e.to, sink, min(flow, e.cap))\n\n                if d > 0:\n\n                    e.cap -= d\n\n                    self.E[e.to][e.rev].cap += d\n\n                    return d\n\n        return 0\n\n\n\n    def bfs(self, start):\n\n        \"\"\"find shortest path from start\"\"\"\n\n        que = collections.deque()\n\n        self.level = [-1] * self.V\n\n        que.append(start)\n\n        self.level[start] = 0\n\n\n\n        while que:\n\n            fr = que.popleft()\n\n            for e in self.E[fr]:\n\n                if e.cap > 0 and self.level[e.to] < 0:\n\n                    self.level[e.to] = self.level[fr] + 1\n\n                    que.append(e.to)\n\n\n\nwhile True:\n\n    M, N = list(map(int, input().split()))\n\n    if M == 0 and N == 0:\n\n        break\n\n    blue, red = [], []\n\n    while True:\n\n        for x in input().split():\n\n            blue.append(int(x))\n\n        if len(blue) == M:\n\n            break\n\n    while True:\n\n        for x in input().split():\n\n            red.append(int(x))\n\n        if len(red) == N:\n\n            break\n\n    V = M + N + 2\n\n    edge = [set() for _ in range(V)]\n\n    for i, b in enumerate(blue):\n\n        if b != 1:\n\n            for j, r in enumerate(red):\n\n                if r % b == 0:\n\n                    edge[i].add((M+j, 1))\n\n        for j in range(2, int(math.sqrt(b)) + 1):\n\n            if b % j == 0:\n\n                for k, r in enumerate(red):\n\n                    if r % j == 0 or r % (b // j) == 0:\n\n                        edge[i].add((M+k, 1))\n\n    for i in range(M):\n\n        edge[M+N].add((i, 1))\n\n    for j in range(N):\n\n        edge[M+j].add((M+N+1, 1))\n\n    d = Dinic(V, edge, M+N, M+N+1)\n\n    print((d.maxflow))"}
{"problem_id": "p00174", "input": "while True:\n\n    try:\n\n        for i in range(3):\n\n            line = input().strip()\n\n            if line == '0':\n\n                raise Exception\n\n\n\n            a = b = 0\n\n            for i, s in enumerate(line):\n\n                if i != 0:\n\n                    if s == 'A':\n\n                        a += 1\n\n                    else:\n\n                        b += 1\n\n            if a > b:\n\n                a += 1\n\n            else:\n\n                b += 1\n\n            print(a, b)\n\n\n\n    except:\n\n        break"}
{"problem_id": "p03559", "input": "from bisect import *\n\nn = int(input())\n\na = list(map(int,input().split()))\n\nb = list(map(int,input().split()))\n\nc = list(map(int,input().split()))\n\n\n\na = sorted(a)\n\nc = sorted(c)\n\n\n\nrec = 0\n\nfor i in range(n):\n\n    temp = b[i]\n\n    l = bisect_left(a, temp)\n\n    r = bisect_right(c, temp)\n\n    rec += l * (n - r)\n\nprint(rec)"}
{"problem_id": "p03592", "input": "N,M,K = list(map(int,input().split()))\n\n\n\nfor i in range(N+1):\n\n    for j in range(M+1):\n\n        t = i*M + j*N - i*j*2\n\n        if t==K:\n\n            print('Yes')\n\n            exit()\n\nprint('No')"}
{"problem_id": "p00542", "input": "a,b,c,d,e,f=[int(input()) for _ in range(6)]\n\nprint((sum([a,b,c,d,max(e,f)])-min([a,b,c,d])))"}
{"problem_id": "p03371", "input": "# AtCoder Beginner Contest 095 C - Half and Half\n\nimport sys\n\n\n\nA, B, C, X, Y = list(map(int, sys.stdin.readline().strip().split()))\n\n\n\nans = A * X + B * Y\n\nfor z in range(2, 2 * 10 ** 5 + 1, 2):\n\n    x = max(X - int(z / 2), 0)\n\n    y = max(Y - int(z / 2), 0)\n\n\n\n    price = A * x + B * y + C * z\n\n    ans = min(price, ans)\n\n\n\nprint(ans)\n"}
{"problem_id": "p02773", "input": "from collections import defaultdict\n\nN = int(input())\n\nd = defaultdict(int)\n\n\n\nfor i in range(N):\n\n    S = input()\n\n    d[S] += 1\n\n\n\nm = 0\n\nfor k in list(d.keys()):\n\n    m = max(d[k],m)\n\n\n\nli = []\n\nfor k in list(d.keys()):\n\n    if d[k] == m:\n\n        li.append(k)\n\n\n\nli.sort()\n\nfor l in li:\n\n    print(l)"}
{"problem_id": "p03037", "input": "N,M = list(map(int,input().split()))\n\nL,R = [],[]\n\nfor i in range(M):\n\n    l,r = list(map(int,input().split()))\n\n    L.append(l)\n\n    R.append(r)\n\nans = min(R)-max(L)+1\n\nprint((ans if ans >= 0 else 0))"}
{"problem_id": "p02881", "input": "n = int(input())\n\nl = []\n\nfor i in range(1,1000001):\n\n    a = n / i\n\n    if a.is_integer():\n\n        l.append(i+n/i)\n\nprint((int(min(l)-2)))"}
{"problem_id": "p02881", "input": "n = int(input())\n\nimport math\n\nm = int(math.sqrt(n))+1\n\nanss = []\n\nfor x in range(1, m+1):\n\n  y = n//x\n\n  z = n%x\n\n  if z == 0:\n\n    anss.append(abs(x-1)+abs(y-1))\n\nprint((min(anss)))\n"}
{"problem_id": "p03455", "input": "a, b = list(map(int, input().split()))\n\nif a*b%2 == 1:\n\n    print(\"Odd\")\n\nelse:\n\n    print(\"Even\")"}
{"problem_id": "p02555", "input": "n = int(input())\n\nm = 10**9 + 7\n\n# ans = [0] * (n + 1)\n\nans = [0] * 2200\n\nans[0] = 1\n\n# ans[3] = 1\n\n# ans[4] = 1\n\n# ans[5] = 1\n\nfor i in range(3, n + 1):\n\n    for j in range(i - 2):\n\n        ans[i] += ans[j]\n\n        ans[i] %= m\n\nprint((ans[n]))\n\n# print(ans[:10])\n"}
{"problem_id": "p04021", "input": "import sys\n\ninput = sys.stdin.readline\n\nread = sys.stdin.read\n\n\n\nn = int(input())\n\nA = list(map(int, read().split()))\n\nL = sorted([(j, i) for i, j in enumerate(A)])\n\ncount = 0\n\nfor i in range(n):\n\n  if (L[i][1]-i)%2:\n\n    count += 1\n\nans = (count+1) // 2\n\nprint(ans)"}
{"problem_id": "p02378", "input": "# Acceptance of input\n\n\n\nimport sys\n\n\n\nfile_input = sys.stdin\n\n\n\nX, Y, E = list(map(int, file_input.readline().split()))\n\n\n\nv_num = X + Y + 2\n\n\n\nadj_mat = [[0] * (v_num) for i in range(v_num)]\n\n\n\nfor line in file_input:\n\n    x, y = list(map(int, line.split()))\n\n    adj_mat[x][X + y] = 1\n\n\n\ns = X + Y\n\nt = s + 1\n\n\n\nfor i in range(X):\n\n    adj_mat[s][i] = 1\n\n\n\nfor i in range(X, s):\n\n    adj_mat[i][t] = 1\n\n\n\n# Dinic's algorithm\n\n\n\nimport collections\n\n\n\n# BFS for residual capacity network to construct level graph\n\ndef bfs(start, goal, parent):\n\n    unvisited = [True] * v_num\n\n    queue = collections.deque()\n\n    queue.append(start)\n\n    unvisited[start] = False\n\n    while queue:\n\n        u = queue.popleft()\n\n        for v, r_capacity in enumerate(adj_mat[u]):\n\n            if unvisited[v] and (r_capacity > 0):\n\n                parent[v].append(u)\n\n                queue.append(v)\n\n                unvisited[v] = False\n\n    return unvisited[goal]\n\n\n\n# DFS for level graph and construct blocking flow\n\ndef dfs(goal, path, parent, blocking_flow):\n\n    v = path[-1]\n\n    if v == goal:\n\n        aug_path_flow = 10000\n\n        for x, y in zip(path[1:], path[:-1]):\n\n            aug_path_flow = min(aug_path_flow, adj_mat[x][y])\n\n        for x, y in zip(path[1:], path[:-1]):\n\n            adj_mat[x][y] -= aug_path_flow\n\n            adj_mat[y][x] += aug_path_flow\n\n        blocking_flow[0] += aug_path_flow\n\n    else:\n\n        for u in parent[v]:\n\n            path.append(u)\n\n            dfs(goal, path, parent, blocking_flow)\n\n            path.pop()\n\n\n\ndef dinic(source, sink):\n\n    max_flow = 0\n\n    parent = [[] for i in range(v_num)]\n\n    while not bfs(source, sink, parent):\n\n        blocking_flow = [0]\n\n        path = [sink]\n\n        # search in reverse direction from sink\n\n        dfs(source, path, parent, blocking_flow)\n\n        max_flow += blocking_flow[0]\n\n        parent = [[] for i in range(v_num)]\n\n    return max_flow\n\n\n\n# output\n\nprint((dinic(s, t)))"}
{"problem_id": "p02837", "input": "import sys, re\n\nfrom collections import deque, defaultdict, Counter\n\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log\n\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\n\nfrom operator import itemgetter, mul\n\nfrom copy import deepcopy\n\nfrom string import ascii_lowercase, ascii_uppercase, digits\n\nfrom bisect import bisect, bisect_left, insort, insort_left\n\nfrom math import gcd\n\nfrom heapq import heappush, heappop\n\nfrom functools import reduce\n\nfrom decimal import Decimal\n\ndef input(): return sys.stdin.readline().strip()\n\ndef INT(): return int(input())\n\ndef MAP(): return list(map(int, input().split()))\n\ndef LIST(): return list(map(int, input().split()))\n\ndef ZIP(n): return list(zip(*(MAP() for _ in range(n))))\n\nsys.setrecursionlimit(10 ** 9)\n\nINF = float('inf')\n\nmod = 10**9 + 7\n\nfrom decimal import *\n\n\n\nN = INT()\n\nxy = []\n\n\n\nfor i in range(N):\n\n\tA = INT()\n\n\txy.append([LIST() for _ in range(A)])\n\n\n\nans = 0\n\nfor i in range(1<<N):\n\n\ti = list(\"{:b}\".format(i).zfill(N))\n\n\tfor j in range(N):\n\n\t\tif i[j] == \"1\":\n\n\t\t\tfor x, y in xy[j]:\n\n\t\t\t\tif y != int(i[x-1]):\n\n\t\t\t\t\tbreak\n\n\t\t\telse:\n\n\t\t\t\tcontinue\n\n\t\t\tbreak\n\n\telse:\n\n\t\ttmp = sum([int(x) for x in i])\n\n\t\tans = max(ans, tmp)\n\nprint(ans)\n"}
{"problem_id": "p04012", "input": "w = input()\n\ny = list(set(w))\n\n\n\nfor i in range(len(y)):\n\n    if w.count(y[i]) % 2 != 0:\n\n        print('No')\n\n        exit(0)\n\n\n\nprint('Yes')"}
{"problem_id": "p02851", "input": "from collections import defaultdict\n\n\n\nN, K, *A = list(map(int, open(0).read().split()))\n\n\n\nS = [0] * (N + 1)\n\nfor i in range(N):\n\n    S[i + 1] = S[i] + A[i]\n\n\n\nd = defaultdict(int)\n\nans = 0\n\nfor j in range(N + 1):\n\n    v = (S[j] - j) % K\n\n    ans += d[v]\n\n    d[v] += 1\n\n    if j >= K - 1:\n\n        d[(S[j - K + 1] - (j - K + 1)) % K] -= 1\n\n        \n\nprint(ans)\n"}
{"problem_id": "p02767", "input": "n=int(input())\n\nx=list(map(int,input().split()))\n\n\n\nx.sort()\n\n\n\nfor p in range(x[0],x[len(x)-1]+1):\n\n    psum=0\n\n    for i in range(len(x)):\n\n        psum=psum+(x[0]-x[i])**2\n\n#    print(psum)\n\n    pmin=psum    \n\n    for j in range(x[0]+1,x[len(x)-1]):\n\n        psum=0\n\n        for i in range(len(x)):\n\n            psum=psum+(j-x[i])**2\n\n#        print(psum)\n\n        if pmin>psum:\n\n            pmin=psum\n\nprint(pmin)    "}
{"problem_id": "p03086", "input": "import re\n\n\n\nS = input()\n\nmax = 0\n\n\n\nfor i in range(len(S)) :\n\n    for j in range(i + 1, len(S) + 1) :\n\n        pattern = re.compile(r'[A|T|C|G]{%d}' % int(j - i))\n\n        subStr = S[i:j]\n\n\n\n        if pattern.match(subStr) and j - i > max :\n\n            max = j - i\n\n\n\nprint(max)\n"}
{"problem_id": "p02792", "input": "import itertools\n\nN = int(input())\n\nNketa = len(str(N))\n\n\n\nrange_count = [[0 for j in range(10)]for i in range(10)]\n\n\n\n\n\nfor p in range(1,N+1):\n\n    mae = int(str(p)[0])\n\n    ato = int(str(p)[-1])\n\n    range_count[mae][ato] += 1\n\n\n\n    \n\n\n\ncount = 0\n\nfor j in range(1,N+1):\n\n    a_mae = int(str(j)[0])\n\n    a_ato = int(str(j)[-1])\n\n    \n\n    b_mae = a_ato\n\n    b_ato = a_mae\n\n    \n\n    if b_mae == 0:\n\n        continue\n\n    else:\n\n        count += range_count[b_mae][b_ato]\n\nprint(count)\n\n  "}
{"problem_id": "p02921", "input": "s=input()\n\nt=input()\n\nans=0\n\nif s[0]==t[0]:\n\n    ans+=1\n\nif s[1]==t[1]:\n\n    ans+=1\n\nif s[2]==t[2]:\n\n    ans+=1\n\nprint(ans)\n"}
{"problem_id": "p03835", "input": "k,s=list(map(int,input().split()))\n\ncnt=0\n\nfor i in range(k+1):\n\n    for j in range(k+1):\n\n        if 0 <= s-i-j <= k:\n\n            cnt+=1\n\nprint(cnt)"}
{"problem_id": "p03806", "input": "N,Ma,Mb = list(map(int, input().split()))\n\narr=[list(map(int,input().split())) for _ in range(N)]\n\ndp=[[[5000]*401 for _ in range(401)] for _ in range(41)]\n\ndp[0][0][0] = 0\n\nfor i in range(N):\n\n    a,b,c=arr[i]\n\n    for j in range(10*N+1):\n\n        for k in range(10*N+1):\n\n            if dp[i][j][k] == 5000:\n\n                continue\n\n            dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])\n\n            dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],dp[i][j][k]+c)\n\n\n\nans=5000\n\nfor i in range(1,401):\n\n        if i*Ma>400 or i*Mb>400:\n\n            break\n\n        ans = min(ans, dp[N][i*Ma][i*Mb])\n\nif ans == 5000:\n\n    print((-1))\n\nelse:\n\n    print(ans)"}
{"problem_id": "p02814", "input": "from math import gcd\n\nN, M = list(map(int, input().split()))\n\nA = list([int(x) for x in input().split()])\n\n\n\ncnt = [0 for _ in range(N)]\n\nfor i in range(N):\n\n  a = A[i]\n\n  while a%2 == 0:\n\n    a = a // 2\n\n    cnt[i] += 1\n\n\n\nif max(cnt) > min(cnt):\n\n  print((0))\n\n  exit(0)\n\nC = max(cnt)\n\n\n\nA = list([x // pow(2,C) for x in A])\n\ndef gcd(a,b):\n\n  if a<b:\n\n    a,b = b,a\n\n  while a%b > 0:\n\n    a,b = b,a%b\n\n  return b\n\n\n\ndef lcm(a,b):\n\n  return a*b//gcd(a,b)\n\n\n\nx = A[0]\n\nfor a in A[1:]:\n\n  x = lcm(x,a)\n\nx = x * pow(2,C-1)\n\n\n\nprint(((M // x + 1) // 2))"}
{"problem_id": "p03038", "input": "from heapq import *\n\n\n\n\n\nn, m = list(map(int, input().split()))\n\nPAIRS = [[-a, -1] for a in map(int, input().split())]\n\nheapify(PAIRS)\n\n\n\nfor _ in range(m):\n\n    b, c = list(map(int, input().split()))\n\n    heappush(PAIRS, [-c, -b])\n\n\n\nanswer = 0\n\nfor _ in range(n):\n\n    pair = heappop(PAIRS)\n\n    answer += -pair[0]\n\n    pair[1] += 1\n\n    if pair[1] != 0:\n\n        heappush(PAIRS, pair)\n\n\n\nprint(answer)\n"}
{"problem_id": "p03796", "input": "import math\n\n\n\nn = int(input())\n\nans = math.factorial(n) % (pow(10, 9) + 7)\n\nprint(ans)"}
{"problem_id": "p02596", "input": "k = int(input())\n\nx = 1\n\n\n\nif k%7 != 0:\n\n    mod = 9*k\n\nelse:\n\n    mod = 9*k//7\n\n\n\nfor i in range(10**6):\n\n    x = x*10%mod\n\n    if x == 1:\n\n        print((i + 1))\n\n        exit()\n\n\n\nprint((-1))"}
{"problem_id": "p03200", "input": "s = input()\n\n\n\ncnt = 0\n\nans = 0\n\nfor c in s:\n\n    if c == 'B':\n\n        cnt += 1\n\n    elif c == 'W':\n\n        ans += cnt\n\nprint(ans)\n"}
{"problem_id": "p00053", "input": "import math\n\ndef pri(n):\n\n    if n < 2:\n\n        return False\n\n    elif n == 2:\n\n        return True\n\n    elif n % 2 == 0:\n\n        return False\n\n\n\n    i = 3\n\n    while i <= math.sqrt(n):\n\n        if n % i == 0:\n\n            return False\n\n        i += 2\n\n    return True\n\n\n\nl=[i for i in range(110000)if pri(i) ]\n\n\n\nwhile True:\n\n    n = int(input())\n\n    if n == 0: break\n\n    print((sum(l[:n])))"}
{"problem_id": "p02988", "input": "n = int(input())\n\nl = list(map(int, input().split()))\n\nprint((sum(l[i]<l[i+1]<l[i+2] or l[i]>l[i+1]>l[i+2] for i in range(n-2))))"}
{"problem_id": "p03363", "input": "N = int(input())\n\nA = list(map(int, input().split()))\n\n\n\nans, s = 0, 0\n\nd = {0:1}\n\n\n\nfor i in A:\n\n    s += i\n\n    ans += d.get(s, 0)\n\n    d[s] = d.get(s, 0) + 1\n\n\n\nprint(ans)"}
{"problem_id": "p03162", "input": "N = int(input())\n\nl = [list(map(int, input().split())) for _ in range(N)]\n\n\n\ndp = [[0 for i in range(3)] for j in range(N+1)]\n\n\n\n\n\nfor i in range(1, N+1):\n\n    for j in range(3):\n\n        for k in range(3):\n\n            if j != k:\n\n                dp[i][j] = max(dp[i][j], dp[i-1][k]+l[i-1][k])\n\n\n\nprint((max(dp[N][0], dp[N][1], dp[N][2])))\n\n\n"}
{"problem_id": "p02899", "input": "import sys\n\n\n\ninput = sys.stdin.readline\n\n\n\ndef main():\n\n    ans = 0\n\n    n = int(input())\n\n    o = list(map(int, input().split()))\n\n    l = [0]*n\n\n    for i in range(n):\n\n        l[o[i]-1] = i+1\n\n    for i in range(len(l)):\n\n        if  i != len(l)-1:\n\n            print(\"{} \".format(l[i]), end='')\n\n        else:\n\n            print(l[i])\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p02994", "input": "N,L = list(map(int, input().split()))\n\ntaste = [L+i-1 for i in range(1,N+1)]\n\nif taste[-1] < 0:\n\n  print((sum(taste) + min([abs(x) for x in taste])))\n\nelse:\n\n  print((sum(taste) - min([abs(x) for x in taste])))"}
{"problem_id": "p03416", "input": "# ABC090B - Palindromic Numbers\n\na, b = list(map(int, input().rstrip().split()))\n\ncount = 0\n\nfor i in range(a, b + 1):\n\n    lst = list(map(int, list(str(i))))\n\n    if lst[0] == lst[4] and lst[1] == lst[3]:\n\n        count += 1\n\nprint(count)"}
{"problem_id": "p03720", "input": "n, m = list(map(int, input().split()))\n\ndp = [0] * n\n\nfor i in range(m):\n\n    x, y = list(map(int, input().split()))\n\n    dp[x - 1] += 1\n\n    dp[y - 1] += 1\n\nfor i in range(n):\n\n    print((dp[i]))"}
{"problem_id": "p03558", "input": "import sys\n\nsys.setrecursionlimit(2147483647)\n\nINF=float(\"inf\")\n\nMOD=10**9+7\n\ninput=lambda :sys.stdin.readline().rstrip()\n\n\n\nfrom collections import deque\n\ndef resolve():\n\n    k=int(input())\n\n    E=[[] for _ in range(k)]\n\n    for i in range(k):\n\n        E[i].append(((i+1)%k,1))\n\n        E[i].append(((10*i)%k,0))\n\n\n\n    # 0-1 BFS\n\n    dist=[INF]*k\n\n    dist[1]=0\n\n    Q=deque([1])\n\n    while(Q):\n\n        v=Q.popleft()\n\n        for nv,w in E[v]:\n\n            if(dist[nv]<=dist[v]+w): continue\n\n            dist[nv]=dist[v]+w\n\n            if(w==0): Q.appendleft(nv)\n\n            else: Q.append(nv)\n\n    print((dist[0]+1))\n\nresolve()"}
{"problem_id": "p03796", "input": "import math\n\n\n\nn = int(input())\n\n\n\nprint((math.factorial(n) % (10**9 + 7)))\n"}
{"problem_id": "p03839", "input": "N,K = list(map(int,input().split()))\n\nsrc = list(map(int,input().split()))\n\n\n\ncums = [0]\n\ncump = [0]\n\nfor a in src:\n\n    cums.append(cums[-1] + a)\n\n    cump.append(cump[-1] + max(0,a))\n\n\n\nans = 0\n\nfor i in range(N-K+1):\n\n    tmp = cump[i]\n\n    tmp += max(0, cums[i+K] - cums[i])\n\n    tmp += cump[N] - cump[i+K]\n\n    ans = max(tmp, ans)\n\nprint(ans)\n"}
{"problem_id": "p03796", "input": "def factorial(N):\n\n    power_r = 1\n\n    for n in range(2,N+1):\n\n        power_r *= n\n\n        power_r %= 10**9+7\n\n    return power_r\n\n\n\nif __name__ == '__main__':\n\n    N = int(input())\n\n    print((factorial(N)))"}
{"problem_id": "p02596", "input": "import sys\n\nK = int(input())\n\n\n\npower = 7\n\nSUM = 0\n\n\n\nfor i in range(1, 10 ** 6):\n\n    SUM += power\n\n    if SUM % K == 0:\n\n        print(i)\n\n        sys.exit()\n\n    power *= 10\n\n    power %= K\n\n\n\nprint((-1))"}
{"problem_id": "p02821", "input": "#E\n\nfrom itertools import accumulate\n\nfrom bisect import bisect_left\n\ndef main():\n\n    n,m=list(map(int,input().split()))\n\n    A=list(map(int,input().split()))\n\n    A.sort()\n\n    \n\n    def count(k):\n\n        cnt=0\n\n        for a in A:\n\n            cnt+=bisect_left(A,k-a)\n\n        return cnt\n\n    \n\n    ok=0\n\n    ng=10**10+1\n\n    while ng-ok>1:\n\n        mid=(ok+ng)//2\n\n        if count(mid)<n**2-m:\n\n            ok=mid\n\n        else:\n\n            ng=mid\n\n    border=ok\n\n    \n\n    k=n**2-count(border)\n\n    Acc=[0]+list(accumulate(A))\n\n    s=Acc[-1]\n\n    ans=0\n\n    for a in A:\n\n        idx=bisect_left(A,border-a)\n\n        ans+=a*(n-idx)+(s-Acc[idx])\n\n    ans-=border*(k-m)\n\n    print(ans)\n\n    \n\nif __name__=='__main__':\n\n    main()"}
{"problem_id": "p03634", "input": "import sys\n\ninput = sys.stdin.readline\n\nn = int(input())\n\nv = [[0]+[]*(n+1) for i in range(n+1)]\n\nfor i in range(n-1):\n\n    a,b,c = list(map(int,input().split()))\n\n    v[a].append([b,c])\n\n    v[b].append([a,c])\n\n\n\nq,k = list(map(int,input().split()))\n\nl = [k]\n\nwhile l:\n\n    now = l.pop()\n\n    for i in v[now][1:]:\n\n        if v[i[0]][0] == 0:\n\n            v[i[0]][0] = i[1]+v[now][0]\n\n            l.append(i[0])\n\n\n\nfor i in range(q):\n\n    x,y = list(map(int,input().split()))\n\n    print((v[x][0]+v[y][0]))"}
{"problem_id": "p03568", "input": "from functools import reduce\n\nfrom itertools import product\n\n\n\nN = int(input())\n\n*A, = list(map(int, input().split()))\n\nans = 0\n\nfor t in product([-1, 0, 1], repeat=N):\n\n    prod = reduce(lambda x, y: x*y, [a + t[i] for i, a in enumerate(A)])\n\n    if prod % 2 == 0: ans += 1\n\nprint(ans)"}
{"problem_id": "p02748", "input": "a, b, m = list(map(int,input().split()))\n\ndr = list(map(int,input().split()))\n\nwa = list(map(int,input().split()))\n\nxyc = [list(map(int,input().split())) for i in range(m)]\n\nlow = 200001\n\n\n\nfor i in range(m):\n\n    f = xyc[i][0] - 1\n\n    d = xyc[i][1] - 1\n\n    if low >= dr[f]+wa[d]-xyc[i][2]:\n\n        low = dr[f]+wa[d]-xyc[i][2]\n\n\n\ndr.sort()\n\nwa.sort()\n\n\n\nif low >= (dr[0] + wa[0]):\n\n    print((dr[0] + wa[0]))\n\nelse:\n\n    print(low)"}
{"problem_id": "p02983", "input": "l, r=list(map(int, input().split()))\n\nif r-l>672:\n\n\tp=0\n\nelse:\n\n\tp=2019\n\n\tfor i in range(l, r):\n\n\t\tfor j in range(i+1, r+1):\n\n\t\t\tp=min(p, (((i%2019)*(j%2019))%2019))\n\n\t\t\tif not p:\n\n\t\t\t\tbreak\n\n\t\tif not p:\n\n\t\t\tbreak\n\nprint(p)"}
{"problem_id": "p03371", "input": "a,b,c,x,y = list(map(int,input().split()))\n\nprice = 10**10\n\nfor k in range(10**5+1):\n\n    re = 2*c*k + max(0,x-k)*a + max(0,y-k)*b\n\n    price = min(re,price)\n\nprint(price)"}
{"problem_id": "p03796", "input": "import math\n\nprint((math.factorial(int(input()))%(10**9+7)))"}
{"problem_id": "p02996", "input": "import sys\n\ninput = sys.stdin.readline\n\n\n\nn = int(input())\n\nab = sorted([list(map(int, input().split()))[::-1] for _ in range(n)])\n\n\n\ncnt = 0\n\nfor b, a in ab:\n\n    cnt += a\n\n    if cnt > b:\n\n        print('No')\n\n        break\n\nelse:\n\n    print('Yes')\n"}
{"problem_id": "p03828", "input": "from collections import Counter\n\nN = int(input())\n\ndiv = []\n\nfor i in range(2,N+1):\n\n    while i != 1:\n\n        for d in range(2,i+1):\n\n            while i%d==0:\n\n                i = i//d\n\n                div.append(d)\n\nC = Counter(div).most_common()\n\nAns = 1\n\nfor k,v in C:\n\n    Ans = Ans*(v+1) % (10**9+7)\n\n\n\nprint(Ans)\n"}
{"problem_id": "p02245", "input": "from collections import deque\n\nfrom copy import deepcopy, copy\n\ndy = [-1, 0, 0, 1]\n\ndx = [0, -1, 1, 0]\n\nN = 3\n\ndef g(i, j, a):\n\n    t = a // (10 ** j) % 10\n\n    return a - t * (10 ** j) + t * (10 ** i)\n\ndef MAIN():\n\n    m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}}\n\n    MAP = \"\".join(input().replace(\" \", \"\") for _ in range(N))\n\n    start = 8 - MAP.find(\"0\")\n\n    MAP = int(MAP)\n\n    goal = ('1', '2', '3', '4', '5', '6', '7', '8', '0')\n\n    goal = 123456780\n\n    dp = deque([(0, start, MAP)])\n\n    LOG = {MAP}\n\n    while dp:\n\n        cnt, yx, M = dp.popleft()\n\n        if M == goal:\n\n            print(cnt)\n\n            break\n\n        cnt += 1\n\n        for nyx in m[yx]:\n\n            CM = g(yx, nyx, M)\n\n            if not CM in LOG:\n\n                dp.append((cnt, nyx, CM))\n\n                LOG.add(CM)\n\nMAIN()\n\n\n"}
{"problem_id": "p03416", "input": "# vim: fileencoding=utf-8\n\n\n\n\n\ndef main():\n\n    a, b = list(map(int, input().split()))\n\n    c = 0\n\n    for i in range(a, b + 1):\n\n        s = str(i)\n\n        r = \"\".join(reversed(list(s)))\n\n        if s == r:\n\n            c += 1\n\n    print(c)\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()\n"}
{"problem_id": "p03371", "input": "A, B, C, X, Y = list(map(int, input().split()))\n\n\n\nans = float('inf')\n\n\n\nfor i in range(10 ** 5 + 1):\n\n    ans = min(ans, A * max(X - i, 0) + B * max(Y - i, 0) + 2 * C * i)\n\nprint(ans)"}
{"problem_id": "p03037", "input": "k,m=list(map(int,input().split()))\n\nl=[0 for i in range(k+1)]\n\nfor i in range(m):\n\n  a,s=list(map(int,input().split()))\n\n  l[a-1]+=1;l[s]-=1\n\nans=0\n\nf=0\n\nfor j in range(k):\n\n  l[j]+=f\n\n  f=l[j]\n\nprint((len([1 for i in l if i==m])))"}
{"problem_id": "p02792", "input": "N = int(input())\n\ncount = [[0 for _ in range(9)] for _ in range(9)]\n\nfor i in range(1, N + 1):\n\n    if str(i)[0] != \"0\" and str(i)[-1] != \"0\":\n\n        count[int(str(i)[0]) - 1][int(str(i)[-1]) - 1] += 1\n\nans = 0\n\nfor i in range(0, 9):\n\n    for k in range(0, 9):\n\n        ans += count[i][k] * count[k][i]\n\nprint(ans)"}
{"problem_id": "p03078", "input": "# -*- coding: utf-8 -*-\n\n\n\nimport sys\n\n\n\ndef input(): return sys.stdin.readline().strip()\n\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\n\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\n\ndef ceil(x, y=1): return int(-(-x // y))\n\ndef INT(): return int(input())\n\ndef MAP(): return list(map(int, input().split()))\n\ndef LIST(): return list(map(int, input().split()))\n\ndef Yes(): print('Yes')\n\ndef No(): print('No')\n\ndef YES(): print('YES')\n\ndef NO(): print('NO')\n\nsys.setrecursionlimit(10 ** 9)\n\nINF = float('inf')\n\nMOD = 10 ** 9 + 7\n\n\n\nX,Y,Z,K=MAP()\n\nA=sorted(LIST(), reverse=True)\n\nB=sorted(LIST(), reverse=True)\n\nC=sorted(LIST(), reverse=True)\n\n\n\nABC=[]\n\nfor i in range(X):\n\n    for j in range(Y):\n\n        if (i+1)*(j+1)>K:\n\n            break\n\n        for k in range(Z):\n\n            if (i+1)*(j+1)*(k+1)>K:\n\n                break\n\n            ABC.append(A[i]+B[j]+C[k])\n\nABC.sort(reverse=True)\n\nfor i in range(K):\n\n    print((ABC[i]))\n\n\n"}
{"problem_id": "p02560", "input": "#!/usr/bin/env python3\n\nimport sys\n\nsys.setrecursionlimit(10**6)\n\nINF = 10 ** 9 + 1  # sys.maxsize # float(\"inf\")\n\nMOD = 10 ** 9 + 7\n\n\n\n\n\ndef floor_sum(n, m, a, b):\n\n    ret = 0\n\n    if a >= m:\n\n        ret += (n - 1) * n * (a // m) // 2\n\n        a %= m\n\n    if b >= m:\n\n        ret += n * (b // m)\n\n        b %= m\n\n    y_max = (a * n + b) // m\n\n    x_max = y_max * m - b\n\n    if y_max == 0:\n\n        return ret\n\n    ret += (n - (x_max + a - 1) // a) * y_max\n\n    ret += floor_sum(y_max, a, m, (a - x_max % a) % a)\n\n    return ret\n\n\n\n\n\ndef debug(*x):\n\n    print(*x, file=sys.stderr)\n\n\n\n\n\ndef solve(SOLVE_PARAMS):\n\n    pass\n\n\n\n\n\ndef main():\n\n    # parse input\n\n    T = int(input())\n\n    for _t in range(T):\n\n        N, M, A, B = map(int, input().split())\n\n        print(floor_sum(N, M, A, B))\n\n\n\n\n\n# tests\n\nT1 = \"\"\"\n\n5\n\n4 10 6 3\n\n6 5 4 3\n\n1 1 0 0\n\n31415 92653 58979 32384\n\n1000000000 1000000000 999999999 999999999\n\n\"\"\"\n\nTEST_T1 = \"\"\"\n\n>>> as_input(T1)\n\n>>> main()\n\n3\n\n13\n\n0\n\n314095480\n\n499999999500000000\n\n\"\"\"\n\n\n\n\n\ndef _test():\n\n    import doctest\n\n    doctest.testmod()\n\n    g = globals()\n\n    for k in sorted(g):\n\n        if k.startswith(\"TEST_\"):\n\n            doctest.run_docstring_examples(g[k], g, name=k)\n\n\n\n\n\ndef as_input(s):\n\n    \"use in test, use given string as input file\"\n\n    import io\n\n    f = io.StringIO(s.strip())\n\n    g = globals()\n\n    g[\"input\"] = lambda: bytes(f.readline(), \"ascii\")\n\n    g[\"read\"] = lambda: bytes(f.read(), \"ascii\")\n\n\n\n\n\ninput = sys.stdin.buffer.readline\n\nread = sys.stdin.buffer.read\n\n\n\nif sys.argv[-1] == \"-t\":\n\n    print(\"testing\")\n\n    _test()\n\n    sys.exit()\n\n\n\nmain()\n"}
{"problem_id": "p02881", "input": "import math\n\nN = int(input())\n\nans = 10**12\n\nfor i in range(1,10**6+1):\n\n  j = math.ceil(N/(i+1))\n\n  if (1+i)*j == N:\n\n    ans = min(i+j-1,ans)\n\n  if i == 10**6 and ans == 10**12:\n\n    ans = N-1\n\n    break\n\nprint(ans)"}
{"problem_id": "p02758", "input": "mod = 998244353\n\nN = int(input())\n\nX = []\n\nfor _ in range(N):\n\n    x, d = list(map(int, input().split()))\n\n    X.append((x, x + d))\n\n\n\nX = sorted(X, key = lambda x: x[0])\n\nL = [(0, -(10**9+1), 10**9+1)]\n\nP = [-1] * (N+1)\n\nfor i, (x, y) in enumerate(X):\n\n    while L[-1][2] <= y:\n\n        if L[-1][2] > x and P[i+1] < 0:\n\n            P[i+1] = L[-1][0]\n\n        L.pop()\n\n    if P[i+1] < 0:\n\n        P[i+1] = L[-1][0]\n\n    L.append((i+1, x, y))\n\n\n\nC = [[] for _ in range(N+1)]\n\nfor i, p in enumerate(P):\n\n    if p >= 0:\n\n        C[p].append(i)\n\n\n\nY = [1] * (N+1)\n\nfor i in range(N+1)[::-1]:\n\n    s = 1\n\n    for j in C[i]:\n\n        s = s * (Y[j] + 1) % mod\n\n    Y[i] = s\n\n\n\nprint((Y[0]))"}
{"problem_id": "p02622", "input": "print((sum(si != ti for si, ti in zip(input(), input()))))\n"}
{"problem_id": "p02767", "input": "n = int(input())\n\nx = [int(i) for i in input().split()]\n\np = 10000000\n\nfor i in range(100):\n\n    pi = 0\n\n    for j in range(n):\n\n        pi += (x[j] - (i + 1))**2\n\n    if pi < p:\n\n        p = pi\n\n    # else:\n\n    #     break\n\n        # p[i] += (x[j]-(i+1))**2\n\nprint(p)"}
{"problem_id": "p02792", "input": "def solve():\n\n    N = int(input())\n\n\n\n    numss = [[0]*(10) for _ in range(10)]\n\n    for x in range(1, 10):\n\n        for y in range(1, 10):\n\n            num = 0\n\n            for d in range(1, 5):\n\n                for i in range(10**d):\n\n                    j = x*10**(d+1) + i*10 + y\n\n                    if 1 <= j <= N:\n\n                        num += 1\n\n                    else:\n\n                        break\n\n            j = x*10 + y\n\n            if 1 <= j <= N:\n\n                num += 1\n\n            if x == y:\n\n                j = x\n\n                if 1 <= j <= N:\n\n                    num += 1\n\n            numss[x][y] = num\n\n\n\n    ans = 0\n\n    for A in range(1, N+1):\n\n        ss = str(A)\n\n        ans += numss[int(ss[-1])][int(ss[0])]\n\n\n\n    print(ans)\n\n\n\n\n\nsolve()\n"}
{"problem_id": "p03086", "input": "# -*- coding: utf-8 -*-\n\nfrom collections import deque\n\ndef inpl(): return list(map(int, input().split()))\n\n\n\nS = input()\n\nA = set(\"ATCG\")\n\nans = 0\n\nmode = 0\n\nfor i, s in enumerate(S):\n\n    if s in A:\n\n        if mode == 0:\n\n            mode = 1\n\n            start = i\n\n    else:\n\n        if mode == 1:\n\n            ans = max(i - start, ans)\n\n            mode = 0\n\nif mode == 1:\n\n    ans = max(len(S) - start, ans)\n\nprint(ans)"}
{"problem_id": "p02952", "input": "N = int(input())\n\nans = 0\n\nfor i in range(1, N + 1):\n\n    if len(str(i)) % 2 == 1:\n\n        ans += 1\n\nprint(ans)"}
{"problem_id": "p03353", "input": "S = input()\n\nk = int(input())\n\nA = set()\n\nfor l in range(k+1):\n\n\tfor i in range(len(S)-l):\n\n\t\t\tA.add(S[i:i+l+1])\n\nA = sorted(list(A))\n\nprint((A[k-1]))"}
{"problem_id": "p02693", "input": "import sys\n\ninput = sys.stdin.readline\n\nfrom collections import *\n\n\n\nK = int(input())\n\nA, B = list(map(int, input().split()))\n\n\n\nfor i in range(A, B+1):\n\n    if i%K==0:\n\n        print('OK')\n\n        exit()\n\n    \n\nprint('NG')"}
{"problem_id": "p03806", "input": "n, ma, mb = list(map(int, input().split()))\n\nU = 400\n\ndp = [[[float(\"inf\")]*(U+1) for _ in range(U+1)] for i in range(n+1)]\n\ndp[0][0][0] = 0\n\nfor i in range(n):\n\n  a, b, c = list(map(int, input().split()))\n\n  for j in range(U+1):\n\n    for k in range(U+1):\n\n      if j<a or k<b:\n\n        dp[i+1][j][k] = dp[i][j][k]\n\n      else:\n\n        dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a][k-b]+c)\n\nans = float(\"inf\")\n\nfor i in range(1, 1+U//max(ma, mb)):\n\n  na, nb = i*ma, i*mb\n\n  ans = min(ans, dp[-1][na][nb])\n\nif ans == float(\"inf\"):\n\n  print((-1))\n\nelse:\n\n  print(ans)"}
{"problem_id": "p03558", "input": "from heapq import heappush, heappop\n\nk = int(input())\n\n\n\nheap = [(1,1)]\n\ndist = [float(\"inf\")]*k\n\nwhile heap:\n\n    cost, cur = heappop(heap)\n\n    if dist[cur] <= cost:\n\n        continue\n\n    dist[cur] = cost\n\n    # +1\n\n    nxt = (cur+1)%k\n\n    heappush(heap, (cost+1, nxt))\n\n    # *10\n\n    nxt = cur*10 % k\n\n    heappush(heap, (cost, nxt))\n\n\n\nprint((dist[0]))"}
{"problem_id": "p02921", "input": "S = input()\n\nT = input()\n\n\n\nl = len(S)\n\nres = 0\n\nfor n in range(l):\n\n    if S[n] == T[n]:\n\n        res += 1\n\nprint(res)"}
{"problem_id": "p03371", "input": "A, B, C, X, Y = list(map(int, input().split()))\n\n\n\nmax_iter = max(X, Y) * 2\n\nans = float(\"inf\")\n\nfor i in range(max_iter):\n\n    a = max(X - i, 0)\n\n    b = max(Y - i, 0)\n\n    price = 2*C * i + A * a + B * b\n\n    ans = min(ans, price)\n\n\n\nprint(ans)"}
{"problem_id": "p03309", "input": "import math\n\nimport statistics\n\nn = int(input())\n\na = list(map(int,input().split()))\n\na = [aa-i-1 for i, aa in enumerate(a)]\n\nanswer = n*10**20\n\nmedian_low = statistics.median_low(a)\n\nmedian_high = statistics.median_high(a)\n\n\n\nfor m in (median_low,median_high):\n\n  ans=0\n\n  for aa in a:\n\n    ans += abs(aa-m)\n\n  answer = min(ans,answer)\n\nprint(answer)\n"}
{"problem_id": "p03371", "input": "a,b,c,x,y = list(map(int,input().split()))\n\nans = a*x + b*y\n\nfor i in range(max(x,y) + 1):\n\n\tmoney = max(0,(x-i)*a) + max(0,(y-i)*b) + 2*i*c\n\n\tif money <= ans:\n\n\t\tans = money\n\nprint(ans)"}
{"problem_id": "p02680", "input": "import sys\n\n# from itertools import chain, accumulate\n\n\n\nn, m, *abcdef = list(map(int, sys.stdin.buffer.read().split()))\n\n\n\nver_lines = []\n\nhor_lines = []\n\nx_list = set()\n\ny_list = set()\n\nn3 = n * 3\n\nfor a, b, c in zip(abcdef[0:n3:3], abcdef[1:n3:3], abcdef[2:n3:3]):\n\n    y_list.add(a)\n\n    y_list.add(b)\n\n    x_list.add(c)\n\n    ver_lines.append((a, b, c))\n\n\n\nfor d, e, f in zip(abcdef[n3 + 0::3], abcdef[n3 + 1::3], abcdef[n3 + 2::3]):\n\n    y_list.add(d)\n\n    x_list.add(e)\n\n    x_list.add(f)\n\n    hor_lines.append((d, e, f))\n\nx_list.add(0)\n\ny_list.add(0)\n\n\n\nx_list = sorted(x_list)\n\ny_list = sorted(y_list)\n\nx_dict = {x: i for i, x in enumerate(x_list, start=1)}\n\ny_dict = {y: i for i, y in enumerate(y_list, start=1)}\n\nrow_real = len(x_list)\n\ncol_real = len(y_list)\n\nrow = row_real + 2\n\ncol = col_real + 2\n\nbanned_up_ij = [[0] * row for _ in range(col)]\n\nbanned_down_ij = [[0] * row for _ in range(col)]\n\nbanned_left_ij = [[0] * col for _ in range(row)]\n\nbanned_right_ij = [[0] * col for _ in range(row)]\n\nfor a, b, c in ver_lines:\n\n    if a > b:\n\n        a, b = b, a\n\n    ai = y_dict[a]\n\n    bi = y_dict[b]\n\n    j = x_dict[c]\n\n    banned_left_ij[j][ai] += 1\n\n    banned_left_ij[j][bi] -= 1\n\n    banned_right_ij[j - 1][ai] += 1\n\n    banned_right_ij[j - 1][bi] -= 1\n\nfor d, e, f in hor_lines:\n\n    if e > f:\n\n        e, f = f, e\n\n    i = y_dict[d]\n\n    ej = x_dict[e]\n\n    fj = x_dict[f]\n\n    banned_up_ij[i][ej] += 1\n\n    banned_up_ij[i][fj] -= 1\n\n    banned_down_ij[i - 1][ej] += 1\n\n    banned_down_ij[i - 1][fj] -= 1\n\n\n\nbanned_up = [0] * (row * col)\n\nbanned_down = [0] * (row * col)\n\nbanned_left = [0] * (row * col)\n\nbanned_right = [0] * (row * col)\n\nfor i in range(col):\n\n    ru = banned_up_ij[i]\n\n    rd = banned_down_ij[i]\n\n    ri = row * i\n\n    banned_up[ri] = ru[0]\n\n    banned_down[ri] = rd[0]\n\n    for j in range(1, row):\n\n        banned_up[ri + j] = banned_up[ri + j - 1] + ru[j]\n\n        banned_down[ri + j] = banned_down[ri + j - 1] + rd[j]\n\nfor j in range(row):\n\n    rl = banned_left_ij[j]\n\n    rr = banned_right_ij[j]\n\n    banned_left[j] = rl[0]\n\n    banned_right[j] = rr[0]\n\n    for i in range(1, col):\n\n        ri0 = (i - 1) * row\n\n        ri1 = i * row\n\n        banned_left[ri1 + j] = banned_left[ri0 + j] + rl[i]\n\n        banned_right[ri1 + j] = banned_right[ri0 + j] + rr[i]\n\n\n\n# banned_up = list(chain.from_iterable(map(accumulate, banned_up_ij)))\n\n# banned_down = list(chain.from_iterable(map(accumulate, banned_down_ij)))\n\n# banned_left = list(chain.from_iterable(zip(*map(accumulate, banned_left_ij))))\n\n# banned_right = list(chain.from_iterable(zip(*map(accumulate, banned_right_ij))))\n\n\n\n# for i in range(col):\n\n#     print(walls[i * row:(i + 1) * row])\n\n\n\ns = row * y_dict[0] + x_dict[0]\n\nenable = [-1] * row + ([-1] + [0] * (row - 2) + [-1]) * (col - 2) + [-1] * row\n\n\n\n# for i in range(col):\n\n#     print(enable[i * row:(i + 1) * row])\n\n\n\nq = [s]\n\nmoves = [(-row, banned_up), (-1, banned_left), (1, banned_right), (row, banned_down)]\n\nwhile q:\n\n    c = q.pop()\n\n    if enable[c] == 1:\n\n        continue\n\n    elif enable[c] == -1:\n\n        print('INF')\n\n        exit()\n\n    enable[c] = 1\n\n    for dc, banned in moves:\n\n        if banned[c]:\n\n            continue\n\n        nc = c + dc\n\n        if enable[nc] == 1:\n\n            continue\n\n        q.append(nc)\n\n# for i in range(col):\n\n#     print(enable[i * row:(i + 1) * row])\n\n\n\n\n\nans = 0\n\nfor i in range(col):\n\n    ri = i * row\n\n    for j in range(row):\n\n        if enable[ri + j] != 1:\n\n            continue\n\n        t = y_list[i - 1]\n\n        b = y_list[i]\n\n        l = x_list[j - 1]\n\n        r = x_list[j]\n\n        ans += (b - t) * (r - l)\n\nprint(ans)\n"}
{"problem_id": "p02555", "input": "def main():\n\n    s = int(input())\n\n    mod = 10**9 + 7\n\n\n\n    dp = [0] * (s+1)\n\n    dp[0] = 1\n\n    for i in range(1, s+1):\n\n        for j in range(0, (i-3)+1):\n\n            dp[i] += dp[j]\n\n            dp[i] %= mod\n\n    print((dp[-1]))\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()\n"}
{"problem_id": "p03078", "input": "def slove():\n\n    import sys\n\n    import heapq\n\n    import collections\n\n    input = sys.stdin.readline\n\n    x, y, z, k = list(map(int, input().rstrip('\\n').split()))\n\n    a = list(map(int, input().rstrip('\\n').split()))\n\n    a.sort(reverse=True)\n\n    b = list(map(int, input().rstrip('\\n').split()))\n\n    b.sort(reverse=True)\n\n    c = list(map(int, input().rstrip('\\n').split()))\n\n    c.sort(reverse=True)\n\n    q = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]\n\n    heapq.heapify(q)\n\n    fq = collections.defaultdict(list)\n\n    fq[(-(a[0] + b[0] + c[0]), 0, 0, 0), 1] = 1\n\n    t = 0\n\n    for _ in range(k):\n\n        if len(q) != 0:\n\n            p = heapq.heappop(q)\n\n            t = p[0]\n\n            aq = p[1]\n\n            bq = p[2]\n\n            cq = p[3]\n\n            if aq + 1 < len(a):\n\n                if (-(a[aq+1] + b[bq] + c[cq]), aq+1, bq, cq) not in fq:\n\n                    heapq.heappush(q, [-(a[aq+1] + b[bq] + c[cq]), aq+1, bq, cq])\n\n                    fq[(-(a[aq+1] + b[bq] + c[cq]), aq+1, bq, cq)] = 1\n\n            if bq + 1 < len(b):\n\n                if (-(a[aq] + b[bq+1] + c[cq]), aq, bq+1, cq) not in fq:\n\n                    heapq.heappush(q, [-(a[aq] + b[bq+1] + c[cq]), aq, bq+1, cq])\n\n                    fq[(-(a[aq] + b[bq+1] + c[cq]), aq, bq+1, cq)] = 1\n\n            if cq + 1 < len(c):\n\n                if (-(a[aq] + b[bq] + c[cq+1]), aq, bq, cq+1) not in fq:\n\n                    heapq.heappush(q, [-(a[aq] + b[bq] + c[cq+1]), aq, bq, cq+1])\n\n                    fq[(-(a[aq] + b[bq] + c[cq+1]), aq, bq, cq+1)] = 1\n\n        print((-t))\n\n\n\n\n\nif __name__ == '__main__':\n\n    slove()\n"}
{"problem_id": "p00500", "input": "N = int(input())\n\nscore = [list(map(int, input().split())) for _ in range(N)]\n\nplayers = [0 for _ in range(N)]\n\nfor play in list(zip(*score)):\n\n    for i, p in enumerate(play):\n\n        if play.count(p) == 1:\n\n            players[i] += p\n\nprint(*players, sep='\\n')\n"}
{"problem_id": "p03170", "input": "n,k = list(map(int,input().split()))\n\narr = list(map(int,input().split()))\n\n\n\ndp = [False]*(k+1)\n\n\n\nfor stones in range(k+1):\n\n    for x in arr:\n\n        if stones >= x and dp[stones-x] == False:\n\n            dp[stones] = True\n\n\n\nif dp[k]:\n\n    print(\"First\")\n\nelse:\n\n    print(\"Second\")\n"}
{"problem_id": "p02419", "input": "W = input().lower()\n\ns = []\n\nwhile True:\n\n    T = list(map(str, input().split()))\n\n    if(T[0] == \"END_OF_TEXT\"):\n\n        break\n\n    else:\n\n        for i in range(len(T)):\n\n            s.append(T[i].lower())\n\nans = 0\n\nfor i in range(len(s)):\n\n    if(s[i] == W):\n\n        ans += 1\n\nprint(ans)"}
{"problem_id": "p03796", "input": "import math\n\nprint((math.factorial(int(input()))%(10**9+7)))"}
{"problem_id": "p02773", "input": "import sys\n\nread = sys.stdin.buffer.read\n\nreadline = sys.stdin.buffer.readline\n\nreadlines = sys.stdin.buffer.readlines\n\nN = int(readline())\n\nS = read().split()\n\n\n\nS = sorted(S)\n\nls = [[] for i in range(N + 1)]\n\nmax_num = 0\n\nleft = 0\n\nright = 0\n\nwhile right < N:\n\n    while right < N and S[left] == S[right]:\n\n        right += 1\n\n    if (right  - left) >= max_num:\n\n        ls[right - left].append(S[left].decode())\n\n        max_num = right - left\n\n    left = right\n\n    \n\nprint(('\\n'.join(ls[max_num])))\n"}
{"problem_id": "p03164", "input": "# temp\n\nn,w = list(map(int,input().split()))\n\nwv = [tuple(map(int,input().split())) for i in range(n)]\n\n\n\ndp = [0] + [float(\"inf\")]*(10**5)\n\nfor i in range(n):\n\n    for j in range(10**5,wv[i][1]-1,-1):\n\n        dp[j] = min(dp[j],dp[j-wv[i][1]]+wv[i][0])\n\n\n\nres = 0\n\nfor v,e in enumerate(dp):\n\n    if e <= w:\n\n        res = v\n\nprint(res)"}
{"problem_id": "p02555", "input": "def main():\n\n  n = int(input())\n\n  \n\n  dp = [0]*(n+1)\n\n  dp[0] = 1\n\n  mod = pow(10, 9) + 7\n\n  for i in range(n+1):\n\n    for j in range(i-2):\n\n      dp[i] += dp[j]\n\n      dp[i] %= mod\n\n  \n\n  print((dp[n]))\n\n\n\nif __name__ == \"__main__\":\n\n  main()"}
{"problem_id": "p02264", "input": "class Queue:\n\n    def __init__(self,values):\n\n        self.values = values\n\n\n\n    def empty(self):\n\n        if len(self.values) == 0:\n\n            return True\n\n        else:\n\n            return False\n\n\n\n    def enqueue(self,v):\n\n        self.values.append(v)\n\n\n\n    def dequeue(self):\n\n        if len(self.values) <= 0:\n\n            raise\n\n        else:\n\n            v = self.values[0]\n\n            del self.values[0]\n\n            return v\n\n\n\nn,q = list(map(int,input().split(' ')))\n\nprocesses = []\n\nfor i in range(n):\n\n    n,t = input().split(' ')\n\n    processes.append((n,int(t)))\n\n\n\nqueue = Queue(processes)\n\n\n\nclock = 0\n\ndone = []\n\nwhile not queue.empty():\n\n    p = queue.dequeue()\n\n    n = p[0]\n\n    t = p[1]\n\n    if t <= q:\n\n        clock+=t\n\n        done.append((n,clock))\n\n    else:\n\n        queue.enqueue((n,t-q))\n\n        clock+=q\n\n\n\nfor p in done:\n\n    print(p[0],p[1])"}
{"problem_id": "p02983", "input": "l,r = list(map(int,input().split()))\n\n\n\nif r - l > 2019:\n\n    print((0))\n\nelse:\n\n    tres = 2019\n\n    for i in range(l,r):\n\n        for j in range(i+1,r+1):\n\n            mod = (i % 2019) * (j % 2019) % 2019\n\n            tres = min(tres,mod)\n\n    print(tres)\n"}
{"problem_id": "p03086", "input": "# 2019-11-12 22:21:08(JST)\n\nimport sys\n\n# import collections\n\n# import math\n\n# from string import ascii_lowercase, ascii_uppercase, digits\n\n# from bisect import bisect_left as bi_l, bisect_right as bi_r\n\nimport itertools\n\n# from functools import reduce\n\n# import operator as op\n\n# from scipy.misc import comb # float\n\n# import numpy as np \n\n\n\ndef main():\n\n    s = sys.stdin.readline().rstrip()\n\n    \n\n    all_words = []\n\n    for i in range(1, len(s) + 1):\n\n        for letters in itertools.product('ATCG', repeat=i):\n\n            word = ''.join(letters)\n\n            all_words.append(word)\n\n    \n\n    for i in range(len(all_words)-1, 0-1, -1):\n\n        if all_words[i] in s:\n\n            print((len(all_words[i])))\n\n            sys.exit()\n\n    print((0))\n\n\n\n\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()\n"}
{"problem_id": "p03309", "input": "#                         author:  kagemeka \n\n#                         created: 2019-11-08 14:51:29(JST)\n\n## internal modules\n\nimport sys\n\n# import collections\n\n# import math\n\n# import string\n\n# import bisect\n\n# import re\n\n# import itertools\n\nimport statistics\n\n# import functools\n\n# import operator\n\n## external modules\n\n# import scipy.special   # if use comb function on AtCoder, \n\n# import scipy.misc      # select scipy.misc.comb (old version) \n\n\n\ndef main():\n\n    n, *a = (int(x) for x in sys.stdin.read().split())\n\n    \n\n    for i in range(n):\n\n        a[i] -= (i + 1)\n\n\n\n    if n % 2 != 0:\n\n        b = statistics.median(a)\n\n    else:\n\n        if a.count(statistics.median_high(a)) >= a.count(statistics.median_low(a)):\n\n            b = statistics.median_high(a)\n\n        else:\n\n            b = statistics.median_low(a)\n\n    \n\n    ans = sum([abs(a[i] - b) for i in range(n)])\n\n    print(ans)\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    # execute only if run as a script\n\n    main()\n\n\n\n\n"}
{"problem_id": "p03416", "input": "def findSumDigit(num):\n\n    global total\n\n    total = \"\"\n\n    while num > 0:\n\n        total += str(num % 10)\n\n        num //= 10\n\n    return total\n\n\n\ndef main():\n\n    a,b = list(map(int, input().split()))\n\n    ans = 0\n\n    for i in range(a,b+1):\n\n        tmp = str(findSumDigit(i))\n\n        if tmp == str(i):\n\n            ans += 1\n\n    print(ans)\n\n\n\nif __name__ == '__main__':\n\n    main()"}
{"problem_id": "p03680", "input": "N = int(input())\n\na = [int(input()) for i in range(N)]\n\nnow = a[0]\n\ncount = 1\n\nc = 0\n\nfor i in range(10**6):\n\n    if now != 2:\n\n        count += 1\n\n        now = a[now - 1]\n\n    else:\n\n        print(count)\n\n        c = 1\n\n        break\n\nif c == 0:\n\n    print((-1))\n"}
{"problem_id": "p02386", "input": "n=int(input())\n\na=[list(map(int,input().split()))for _ in range(n)]\n\ndef f():\n\n for i in range(n-1):\n\n  d=a[i][:];d[3],d[4]=d[4],d[3]\n\n  for j in range(i+1,n):\n\n   e=a[j][:];e[3],e[4]=e[4],e[3]\n\n   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):\n\n    f=[d[k]for k in p]\n\n    if f[0]==e[0]and f[5]==e[5]:\n\n     f=f[1:5]*2\n\n     for k in range(4):\n\n      if f[k:k+4]==e[1:5]:return'No'\n\n return'Yes'\n\nprint((f()))\n"}
{"problem_id": "p02952", "input": "N = int(input())\n\n\n\nans = 0\n\n\n\nfor i in range(1, N+1):\n\n    if len(str(i))%2==1:\n\n        ans += 1\n\n\n\nprint(ans)"}
{"problem_id": "p03425", "input": "import itertools\n\nfrom collections import Counter\n\nN = int(input())\n\nsrc = [input() for i in range(N)]\n\nctr = Counter()\n\nfor s in src:\n\n    ctr[s[0]] += 1\n\n\n\nans = 0\n\nfor ptn in itertools.combinations('MARCH',3):\n\n    a,b,c = ptn\n\n    ans += ctr[a]*ctr[b]*ctr[c]\n\nprint(ans)"}
{"problem_id": "p02952", "input": "N = int(input())\n\n\n\ncount = 0\n\nfor i in range(1, N + 1):\n\n    num_dig = 0\n\n    ii = i\n\n    while ii > 0:\n\n        ii = int(ii / 10)\n\n        num_dig += 1\n\n    if num_dig % 2 != 0:\n\n        count += 1\n\n\n\nprint(count)"}
{"problem_id": "p02801", "input": "from string import ascii_lowercase as lower\n\nprint((lower[lower.find(input())+1]))"}
{"problem_id": "p03634", "input": "#!usr/bin/env python3\n\nfrom collections import defaultdict\n\nfrom collections import deque\n\nfrom heapq import heappush, heappop\n\nimport sys\n\nimport math\n\nimport bisect\n\nimport random\n\ndef LI(): return list(map(int, sys.stdin.readline().split()))\n\ndef I(): return int(sys.stdin.readline())\n\ndef LS():return list(map(list, sys.stdin.readline().split()))\n\ndef S(): return list(sys.stdin.readline())[:-1]\n\ndef IR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = I()\n\n    return l\n\ndef LIR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = LI()\n\n    return l\n\ndef SR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = S()\n\n    return l\n\ndef LSR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = SR()\n\n    return l\n\nmod = 1000000007\n\n\n\n#A\n\n\"\"\"\n\ndef gcd(a,b):\n\n    if a == 0:\n\n        return b\n\n    return gcd(b%a,a)\n\nn = I()\n\na = IR(n)\n\nl = a[0]\n\nfor i in range(1,n):\n\n    g = gcd(l,a[i])\n\n    l *= a[i]//g\n\nprint(l)\n\n\"\"\"\n\n\n\n#B\n\nn = I()\n\nv = [[] for i in range(n)]\n\nfor i in range(n-1):\n\n    a,b,c = LI()\n\n    a -= 1\n\n    b -= 1\n\n    v[a].append([b,c])\n\n    v[b].append([a,c])\n\nQ,k = LI()\n\nd = [-1 for i in range(n)]\n\nd[k-1] = 0\n\nq = deque()\n\nq.append(k-1)\n\nwhile q:\n\n    x = q.pop()\n\n    for y,c in v[x]:\n\n        if d[y] == -1:\n\n            d[y] = d[x]+c\n\n            q.append(y)\n\nfor i in range(Q):\n\n    x,y = LI()\n\n    x -= 1\n\n    y -= 1\n\n    print((d[x]+d[y]))\n\n#C\n\n\n\n#D\n\n\n\n#E\n\n\n\n#F\n\n\n\n#G\n\n\n\n#H\n\n\n\n#I\n\n\n\n#J\n\n\n\n#K\n\n\n\n#L\n\n\n\n#M\n\n\n\n#N\n\n\n\n#O\n\n\n\n#P\n\n\n\n#Q\n\n\n\n#R\n\n\n\n#S\n\n\n\n#T\n"}
{"problem_id": "p04012", "input": "import string\n\nw = input()\n\nfor a in string.ascii_lowercase:\n\n    cnt = 0\n\n    for t in w:\n\n        if t == a:\n\n            cnt = cnt + 1\n\n    if cnt % 2 == 1:\n\n        print(\"No\")\n\n        exit()\n\n\n\nprint(\"Yes\")"}
{"problem_id": "p03013", "input": "mod = 10**9+7\n\nn, m = list(map(int, input().split()))\n\nl = [0]*n\n\nfor _ in range(m):\n\n  l[int(input())-1] = 1\n\n\n\ns = 0\n\nt = 1\n\n\n\nfor i in range(n):\n\n  if l[i] > 0:\n\n    t, s = 0, t\n\n  else:\n\n    t, s = (s+t)%mod, t\n\n\n\nprint(t)"}
{"problem_id": "p03774", "input": "N,M = [int(c) for c in input().split()]\n\nab = [list(map(int,input().split())) for c in range(N)]\n\ncd = [list(map(int,input().split())) for c in range(M)]\n\nfor i in range(N):\n\n    mi = 2*10**9\n\n    for j in range(M):\n\n        tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])\n\n        if mi > tmp:\n\n            mi = tmp\n\n            ans = j+1\n\n    print(ans)\n"}
{"problem_id": "p03416", "input": "def test():\n\n    a,b = list(map(int,input().split()))\n\n    count = 0\n\n    for i in range(a,b+1):\n\n        j = list(map(int,list(str(i))))\n\n        if j[0] == j[4] and j[1] == j[3]:\n\n            count += 1\n\n    print(count)\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    test()\n"}
{"problem_id": "p02821", "input": "from bisect import bisect_left\n\nfrom bisect import bisect_right\n\n\n\nn,m = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\na = sorted(a)\n\n\n\na_count = [0]*100010\n\na_sum = [0]*100010\n\n\n\nfor i in range(n):\n\n    a_count[a[i]] += 1\n\n    a_sum[a[i]] += a[i]\n\n\n\nfor i in range(100005,-1,-1):\n\n    a_count[i] += a_count[i+1]\n\n    a_sum[i] += a_sum[i+1]\n\n\n\ndef chk(x):\n\n    case = 0\n\n    for i in range(n):\n\n        if 0<= x-a[i]<= 10**5+5:\n\n            case += a_count[x-a[i]]\n\n        elif x-a[i] < 0:\n\n            case += n\n\n    if case >= m:\n\n        ch = True\n\n    else:\n\n        ch = False\n\n    return ch\n\n\n\nl = 2*a[-1]+1    #NG\n\nr = 1 #OK\n\n\n\nwhile abs(r-l) > 1:\n\n    kk = (r+l)//2\n\n    if chk(kk):\n\n        r = kk\n\n    else:\n\n        l = kk\n\n\n\nans = 0\n\nsm = sum(a)\n\n\n\nl = r\n\n\n\ncase = 0\n\nfor i in range(n):\n\n    num = n-bisect_right(a,l-a[i]-1)\n\n    case += num\n\n    ans += num*a[i]*2\n\n\n\nans -= (case-m)*l\n\n\n\nprint(ans)"}
{"problem_id": "p03548", "input": "X, Y, Z = list(map(int, input().split()))\n\nfor n in range(10 ** 5, 0, -1):\n\n    if X >= n * (Y + Z) + Z:\n\n        break\n\nprint(n)"}
{"problem_id": "p02576", "input": "array = list(map(int, input().split()))\n\nif array[0] % array[1] > 0:\n\n    print(((array[0] // array[1] + 1) * array[2]))\n\nelse:\n\n    print(((array[0] // array[1]) * array[2]))"}
{"problem_id": "p02268", "input": "N = int(input())\n\nS = list(map(int, input().split()))\n\nQ = int(input())\n\nT = list(map(int, input().split()))\n\n\n\ndef binary_search(target_num, head, tail):\n\n    idx = int((head+tail)/2)\n\n    if target_num == S[idx]:\n\n        return True\n\n    elif target_num < S[idx]:\n\n        if head == idx:\n\n            return False\n\n        return binary_search(target_num, head, idx-1)\n\n    else:\n\n        if tail == idx:\n\n            return False\n\n        return binary_search(target_num, idx+1, tail)\n\n\n\n\n\nmatch_count = 0\n\nfor target_num in T:\n\n    if binary_search(target_num, 0, len(S)-1):\n\n        match_count += 1\n\n\n\nprint((str(match_count)))\n"}
{"problem_id": "p03796", "input": "n=input()\n\nn=int(n)\n\na=1\n\nfor i in range(n):\n\n    a=a*(i+1)\n\n    if a>=pow(10,9)+7:\n\n        a=a%(pow(10,9)+7)\n\nprint(a)"}
{"problem_id": "p00003", "input": "import sys\n\nr = []\n\nn = int(input())\n\nl = sys.stdin.readlines()\n\nfor i in l:\n\n  x, y, z = sorted([x*x for x in list(map(int, i.split()))])\n\n  if x + y == z:\n\n      print(\"YES\")\n\n  else:\n\n      print(\"NO\")"}
{"problem_id": "p03086", "input": "import re\n\nptn = re.compile(r\"(A|C|G|T)*\")\n\n\n\nS = input()\n\n\n\nans = 0\n\nfor i in range(len(S)):\n\n  for j in range(len(S)):\n\n    x = ptn.match(S[i:i+j+1]).group(0)\n\n    if(x):\n\n      ans = max(ans, len(x))\n\nprint(ans)"}
{"problem_id": "p03371", "input": "a, b, c, x, y = list(map(int, input().split()))\n\nab = c * 2\n\n\n\nres = float(\"inf\")\n\nif a + b <= ab:\n\n    res = x * a + y * b\n\nelse:\n\n    if x == y:\n\n        res = x * ab\n\n    elif x > y:\n\n        for i in range(y, x + 1):\n\n            cost = i * ab + (x - i) * a\n\n            res = min(res, cost)\n\n    else:\n\n        for i in range(x, y + 1):\n\n            cost = i * ab + (y - i) * b\n\n            res = min(res, cost)\n\nprint(res)\n"}
{"problem_id": "p03371", "input": "a,b,c,x,y=list(map(int,input().split()))\n\n\n\nans=a*x+b*y\n\nfor ci in range(max(x,y)+1):\n\n    sumc = 2*ci*c\n\n    sumc += (x-ci)*a if (x-ci)>0 else 0\n\n    sumc += (y-ci)*b if (y-ci)>0 else 0\n\n    ans=min(ans,sumc)\n\n\n\nprint(ans)"}
{"problem_id": "p01105", "input": "a=65280; b=61680; c=52428; d=43690; e=65535\n\nfrom heapq import heappush, heappop\n\nbase = [a, b, c, d, e, 0]\n\nQ = [(1, el) for el in base]\n\nL = {el: 1 for el in base}\n\nH = []\n\nget = L.get\n\npush = H.append\n\nwhile Q:\n\n    l, p = heappop(Q)\n\n    if L[p] < l: continue\n\n    if l+1 < get(p ^ e, 17):\n\n        L[p ^ e] = l+1\n\n        if l+1 < 16: heappush(Q, (l+1, p ^ e))\n\n    if l+3 < 16:\n\n        for q, r in H:\n\n            if l+r+3 <= 16:\n\n                if l+r+3 < get(p & q, 17):\n\n                    L[p & q] = l+r+3\n\n                    if l+r+3 < 16: heappush(Q, (l+r+3, p & q))\n\n                if l+r+3 < get(p ^ q, 17):\n\n                    L[p ^ q] = l+r+3\n\n                    if l+r+3 < 16: heappush(Q, (l+r+3, p ^ q))\n\n            else: break\n\n    if l < 7: push((p, l))\n\nprint(*map(L.__getitem__, eval(\"e&%s\"%\",e&\".join(open(0).read().replace(*\"-~\").replace(*\"*&\").replace(*\"1e\").split()[:-1]))),sep='\\n')\n"}
{"problem_id": "p04020", "input": "def examB():\n\n    N = I(); A = [I() for _ in range(N)]\n\n    ans = 0; cur= 0\n\n    for i in A:\n\n        if i==0:\n\n            ans += cur//2\n\n            cur = 0\n\n        else:\n\n            cur += i\n\n    ans += cur // 2\n\n    print(ans)\n\n    return\n\n\n\nimport sys,copy,bisect,itertools,heapq,math\n\nfrom heapq import heappop,heappush,heapify\n\nfrom collections import Counter,defaultdict,deque\n\ndef I(): return int(sys.stdin.readline())\n\ndef LI(): return list(map(int,sys.stdin.readline().split()))\n\ndef LSI(): return list(map(str,sys.stdin.readline().split()))\n\ndef LS(): return sys.stdin.readline().split()\n\ndef SI(): return sys.stdin.readline().strip()\n\nmod = 10**9 + 7\n\ninf = float('inf')\n\n\n\nif __name__ == '__main__':\n\n    examB()\n"}
{"problem_id": "p03544", "input": "N = int(input())\n\nL = [ 0 ] * 1000000\n\n\n\nL[0] = 2\n\nL[1] = 1\n\n\n\nfor i in range(2, N+1):\n\n  L[i] = L[i-2] + L[i-1]\n\n\n\nprint((L[N]))\n"}
{"problem_id": "p03013", "input": "import sys\n\nN,M=list(map(int,input().split()))\n\nS=set(map(int,sys.stdin))\n\n\n\na,b=0,1\n\nfor i in range(1,N+1):\n\n    if i in S:\n\n        a,b=b,0\n\n    else:\n\n        a,b=b,a+b\n\n\n\nprint((b%(10**9+7)))\n"}
{"problem_id": "p01138", "input": "import re\n\n\n\nwhile True:\n\n    n = int(input())\n\n    if n == 0:\n\n        break\n\n    l = [0] * (24*60*60+1)\n\n    for _ in range(n):\n\n        h1,m1,s1,h2,m2,s2 = list(map(int, re.split(':| ', input())))\n\n        l[h1*60*60 + m1*60 + s1] += 1\n\n        l[h2*60*60 + m2*60 + s2] -= 1\n\n    r = 0\n\n    for i in range(24*60*60):\n\n        l[i+1] += l[i]\n\n        r = max(r, l[i+1])\n\n    print(r)"}
{"problem_id": "p03074", "input": "N, K = list(map(int, input().split()))\n\nS = input()\n\nnums = []\n\nnow = 1\n\ncnt = 0\n\nfor i in range(N):\n\n    if S[i] == str(now):\n\n        cnt += 1\n\n    else:\n\n        nums.append(cnt)\n\n        now = 1 - now\n\n        cnt = 1\n\nif cnt != 0:\n\n    nums.append(cnt)\n\nif len(nums) % 2 == 0:\n\n    nums.append(0)\n\n\n\nadd = 2 * K + 1\n\nans = 0\n\nleft = 0\n\nright = 0\n\ntmp = 0\n\nfor i in range(0, len(nums), 2):\n\n\n\n    next_left = i\n\n    next_right = min(i + add, len(nums))\n\n\n\n    while next_left > left:\n\n        tmp -= nums[left]\n\n        left += 1\n\n\n\n    while next_right > right:\n\n        tmp += nums[right]\n\n        right += 1\n\n\n\n    ans = max(ans, tmp)\n\nprint(ans)"}
{"problem_id": "p03424", "input": "n=int(input())\n\ns=list(map(str,input().split()))\n\ntotal=[]\n\nfor i in range(n):\n\n    if s[i] not in total:\n\n        total.append(s[i])\n\nprint(('Three' if len(total)==3 else 'Four'))"}
{"problem_id": "p03164", "input": "import sys\n\nfrom collections import Counter, deque, defaultdict\n\nfrom itertools import accumulate, permutations, combinations, takewhile, compress, cycle\n\nfrom functools import reduce\n\nfrom math import ceil, floor, log10, log2, factorial\n\nfrom pprint import pprint\n\n\n\nsys.setrecursionlimit(1000000)\n\n# MOD = 10 ** 9 + 7\n\n# N = int(input())\n\n# A = [int(x) for x in input().split()]\n\n# V = [[0] * 100 for _ in range(100)]\n\n# A = [int(input()) for _ in range(N)]\n\n\n\nN, W = [int(x) for x in input().split()]\n\n\n\ndp = [float('inf')] * 1000 * 100*10\n\nvs = set()\n\nvs.add(0)\n\ndp[0] = 0\n\n\n\nfor i in range(N):\n\n    w, v = [int(x) for x in input().split()]\n\n\n\n    tmpDP = dp.copy()\n\n    for vv in list(vs):\n\n        if dp[vv + v] > dp[vv] + w:\n\n            tmpDP[vv + v] = dp[vv] + w\n\n            vs.add(vv + v)\n\n    dp = tmpDP\n\n\n\n\n\nans = 0\n\nfor v in list(vs):\n\n    if dp[v] <= W:\n\n        ans = max(ans, v)\n\nprint(ans)\n"}
{"problem_id": "p03796", "input": "from math import factorial\n\nN = int(input())\n\nprint((factorial(N) % (10**9 + 7)))"}
{"problem_id": "p00005", "input": "import math\n\nwhile True:\n\n\ttry:\n\n\t\tx,y = list(map(int,input().split()))\n\n\t\tprint('%d %d' % (math.gcd(x,y),x/math.gcd(x,y)*y))\n\n\texcept EOFError:\n\n\t\tbreak"}
{"problem_id": "p02881", "input": "n = int(input())\n\nr = int(n**.5)\n\nfor i in range(r):\n\n  if n % (r-i) == 0:\n\n    print(( (r-i) + n//(r-i) - 2 ))\n\n    break"}
{"problem_id": "p03253", "input": "from collections import Counter\n\ndef factorization(n) -> list:\n\n\tif n==1:\n\n\t\treturn [1]\n\n\tret = []\n\n\ti = 2\n\n\twhile i*i<=n:\n\n\t\twhile n%i==0:\n\n\t\t\tn //= i\n\n\t\t\tret.append(i)\n\n\t\ti += 1\n\n\tif n!=1:\n\n\t\tret.append(n)\n\n\treturn ret\n\n\n\nn,m = list(map(int,input().split()))\n\nmod = 10**9+7\n\nif m==1:\n\n\tprint((1));exit()\n\n\n\nfactors = Counter(factorization(m))\n\nmx = n+max(factors.values())\n\n\n\nfac = [1]*(mx+1)\n\ninv = [1]*(mx+1)\n\nfor i in range(1,mx+1):\n\n\tfac[i] = fac[i-1] * i % mod\n\ninv[-1] = pow(fac[-1], mod - 2, mod)\n\nfor i in range(mx-1, -1, -1):\n\n\tinv[i] = inv[i+1] * (i+1) % mod\n\ndef cmb(n,r):\n\n\tassert n >= r >= 0\n\n\treturn fac[n] * inv[n-r] * inv[r] % mod\n\n\t\n\nans=1\n\nfor v in list(factors.values()):\n\n\tans*=cmb(n+v-1,v)\n\n\tans%=mod\n\n\n\nprint(ans)"}
{"problem_id": "p02725", "input": "K, N = list(map(int, input().split()))\n\nA = list(map(int, input().split()))\n\n\n\ndiff = A[0] + K - A[-1]\n\nans = A[-1] - A[0]\n\nfor i in range(1, N):\n\n    dist = K - A[i] + A[i - 1]\n\n    if dist < ans:\n\n        ans = dist\n\n\n\nprint(ans)\n"}
{"problem_id": "p03371", "input": "import sys\n\ninput = lambda: sys.stdin.readline().rstrip() \n\n\n\ndef resolve():\n\n    A, B, C, X, Y = list(map(int, input().split()))\n\n\n\n    ans = float('inf')\n\n    for i in range(0, max(X, Y)*2+1, 2):\n\n        ans = min(A*max(X-i//2, 0)+B*max(Y-i//2, 0)+C*i, ans)\n\n    print(ans)\n\n\n\nif __name__ == '__main__':\n\n    resolve()\n"}
{"problem_id": "p03416", "input": "A,B = list(map(int,input().split()))\n\nans = 0\n\nfor i in range(A,B+1):\n\n    i = str(i)\n\n    if i[0] == i[4]:\n\n        if i[1] == i[3]:\n\n            ans += 1\n\n        else:\n\n            ans += 0\n\n    else:\n\n        ans += 0\n\nprint(ans)"}
{"problem_id": "p03568", "input": "def main():\n\n    N = int(input())\n\n    A = [int(i) for i in input().split()]\n\n    if N == 1:\n\n        return print(1 if A[0] % 2 == 0 else 2)\n\n    ans = 0\n\n    d = (-1, 0, 1)\n\n    from itertools import product\n\n    for i in product(range(3), repeat=N):\n\n        cur = 1\n\n        for j in range(N):\n\n            cur *= (A[j] + d[i[j]])\n\n        if cur % 2 == 0:\n\n            ans += 1\n\n    print(ans)\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03425", "input": "# -*- coding: utf-8 -*-\n\nfrom collections import defaultdict\n\nfrom itertools import combinations\n\nN = int(input())\n\nC = [0, 0, 0, 0, 0, 0]\n\nD = defaultdict(int)\n\nfor i, m in enumerate(\"MARCH\", start=1):\n\n    D[m] = i\n\n\n\nfor _ in range(N):\n\n    C[D[input()[0]]] += 1\n\n\n\nans = 0\n\nfor a, b, c in combinations(list(range(1, 6)), r=3):\n\n    ans += C[a]*C[b]*C[c]\n\nprint(ans)"}
{"problem_id": "p03796", "input": "import math\n\n\n\nN = int(input())\n\n\n\nprint((math.factorial(N) % (1000000000 + 7)))\n"}
{"problem_id": "p03309", "input": "def main():\n\n    from statistics import median\n\n\n\n    n, *a, = list(map(int, open(0).read().split()))\n\n    a = [x - i for i, x in enumerate(a, 1)]\n\n    a.sort()\n\n    m = int(median(a))\n\n\n\n    ans = sum([abs(x - m) for x in a])\n\n    print(ans)\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03037", "input": "N, M = list(map(int, input().split()))\n\nL, R = [], []\n\nlow = -float('INF')\n\nhigh = float('INF')\n\nfor i in range(M):\n\n    l, r = list(map(int, input().split()))\n\n    L.append(l)\n\n    R.append(r)\n\n    if l > low:\n\n        low = l\n\n    if r < high:\n\n        high = r\n\nprint((max(0, high - low + 1)))\n"}
{"problem_id": "p02555", "input": "a,b,c=1,0,0\n\nexec('a,b,c=b,c,(a+c)%(10**9+7);'*(int(input())-2))\n\nprint(c)"}
{"problem_id": "p03371", "input": "a, b, c, x, y = list(map(int, input().split()))\n\n\n\nz = max(x,y) * 2\n\nmin_sum = c * z\n\n\n\nfor i in range(z):\n\n    r = max(0, y - i) * b\n\n    t = max(0, x - i) * a\n\n    sum = c * i * 2 + r + t\n\n    if sum < min_sum:\n\n        min_sum = sum\n\n\n\nprint(min_sum)"}
{"problem_id": "p03796", "input": "N = int(input())\n\na = 1\n\nfor n in range(2,N+1):\n\n    a = a*n % (10**9+7)\n\nprint(a)"}
{"problem_id": "p03170", "input": "import sys\n\nread = sys.stdin.buffer.read\n\nreadline = sys.stdin.buffer.readline\n\nreadlines = sys.stdin.buffer.readlines\n\n\n\nfrom operator import xor\n\nfrom functools import reduce\n\n\n\nN,K,*A = list(map(int,read().split()))\n\n\n\na = reduce(xor,(1<<a for a in A))\n\n\n\ndp = 0 # bitset\n\nfor n in range(K):\n\n    if not(dp&(1<<n)):\n\n        dp |= (a<<n)\n\n\n\nanswer = 'First' if dp&(1<<K) else 'Second'\n\nprint(answer)"}
{"problem_id": "p02624", "input": "n = int(input())\n\nans = 0\n\nSQRT = int(n ** 0.5)\n\nfor m in range(1,SQRT + 1):\n\n    b = int(n/m)\n\n    ans += m * (m + b) * (b + 1 - m)\n\nans -= SQRT * (SQRT+1) * (2*SQRT+1) // 6\n\nprint(ans)"}
{"problem_id": "p03828", "input": "import math\n\nimport collections\n\n\n\nN = int(input())\n\na = math.factorial(N)\n\ncheck = []\n\nans = 1\n\ni = 2\n\n\n\nwhile a != 1:\n\n    if a % i == 0:\n\n        a //= i\n\n        check.append(i)\n\n    else:\n\n        i += 1\n\n        \n\ncheck = list(collections.Counter(check).values())\n\nfor i in check:\n\n    ans *= (i+1)\n\n    ans %= 10**9+7\n\nprint(ans)"}
{"problem_id": "p03371", "input": "A,B,C,X,Y=list(map(int,input().split()))\n\n\n\nK=10**9\n\nfor i in range(10**5+1):\n\n    S=i*2*C+max(0,X-i)*A+max(0,Y-i)*B\n\n    K=min(K,S)\n\nprint(K)"}
{"problem_id": "p02390", "input": "S = int(input())\n\n\n\nif S >= 3600:\n\n    h=S//3600\n\n    m=S%3600//60\n\n    s=S%60\n\nelif 3600 > S >= 60:\n\n    h=0\n\n    m=S//60\n\n    s=S%60\n\nelse:\n\n    h=m=0\n\n    s=S\n\nprint(h, m, s, sep=\":\")\n"}
{"problem_id": "p03806", "input": "def main():\n\n\tn, ma, mb, *L = list(map(int, open(0).read().split()))\n\n\tM = 1<<30\n\n\tdp = [[M] * 420 for _ in range(420)]\n\n\tdp[0][0] = 0\n\n\tfor a, b, c in zip(*[iter(L)] * 3):\n\n\t\tfor i in range(400, -1, -1):\n\n\t\t\tfor j in range(400, -1, -1):\n\n\t\t\t\tt = dp[i][j] + c\n\n\t\t\t\tif dp[i + a][j + b] > t:\n\n\t\t\t\t\tdp[i + a][j + b] = t\n\n\tans = M\n\n\t_ma, _mb = ma, mb\n\n\twhile _ma < 410 > _mb:\n\n\t\tans = min(ans, dp[_ma][_mb])\n\n\t\t_ma += ma\n\n\t\t_mb += mb\n\n\tprint((ans if ans < M else -1))\n\n\n\nif __name__==\"__main__\":\n\n\tmain()"}
{"problem_id": "p03434", "input": "_,s=open(c:=0)\n\nfor a in sorted(map(int,s.split())):c=a-c\n\nprint(c)"}
{"problem_id": "p03854", "input": "s = input()\n\nt = \"\"\n\nwhile len(t) < len(s):\n\n    target_len = len(s) - len(t)\n\n\n\n    if s[len(t)] == 'd':\n\n        if target_len == 5:\n\n            t += \"dream\"\n\n        elif target_len == 7:\n\n            t += \"dreamer\"\n\n        elif target_len > 7:\n\n            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 7 + 1] != \"era\":\n\n                t += \"dreamer\"\n\n            else:\n\n                t += \"dream\"\n\n        else:\n\n            break\n\n    else:\n\n        if target_len == 5:\n\n            t += \"erase\"\n\n        elif target_len == 6:\n\n            t += \"eraser\"\n\n        elif target_len > 6:\n\n            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 6 + 2] != \"era\":\n\n                t += \"eraser\"\n\n            else:\n\n                t += \"erase\"\n\n        else:\n\n            break\n\n\n\n    if s[0:len(t)] != t:\n\n        break\n\n\n\nprint((\"YES\" if s == t else \"NO\"))\n"}
{"problem_id": "p00134", "input": "from statistics import mean\n\n\n\ninputCount = int(input())\n\nprices = [int(input()) for lp in range(inputCount)]\n\naverage = mean(prices)\n\nprint((int(average)))\n\n\n"}
{"problem_id": "p03559", "input": "from collections import Counter,defaultdict,deque\n\nfrom heapq import heappop,heappush,heapify\n\nimport sys,bisect,math,itertools,math,pprint\n\nsys.setrecursionlimit(10**8)\n\nmod = 10**9+7\n\nINF = float('inf')\n\ndef inp(): return int(sys.stdin.readline())\n\ndef inpl(): return list(map(int, sys.stdin.readline().split()))\n\n\n\nn = inp()\n\nA = sorted(inpl())\n\nB = sorted(inpl())\n\nC = sorted(inpl())\n\ncnt = [0] * n\n\nres = 0\n\nfor i,b in enumerate(B):\n\n    c = bisect.bisect_left(C,b+1)\n\n    cnt[i] = n-c\n\n\n\nacc = [0]\n\nfor x in cnt:\n\n    acc += [acc[-1] + x]\n\nsu = sum(cnt) \n\nfor i,a in enumerate(A):\n\n    c = bisect.bisect_left(B,a+1)\n\n    res += su - acc[c]\n\nprint(res)"}
{"problem_id": "p02552", "input": "x = int(input())\n\nprint((0 if x==1 else 1))"}
{"problem_id": "p02268", "input": "def binarySearch():\n\n    n = int(input())\n\n    S = set(map(int, input().split()))\n\n    q = int(input())\n\n    T = set(map(int, input().split()))\n\n    print((len(S.intersection(T))))\n\n    \n\n\n\nbinarySearch()"}
{"problem_id": "p03416", "input": "a,b=list(map(int,input().split()))\n\n\n\nans=0\n\n\n\nfor i in range(a,b+1):\n\n    buf=str(i)\n\n    #print(buf[0:int(len(buf)/2)],buf[int(len(buf)/2+1):])\n\n    str1=buf[0:int(len(buf)/2)]\n\n    str2=buf[int(len(buf)/2+1):]\n\n    if str1[0]==str2[1] and str1[1]==str2[0]:\n\n        ans+=1\n\n\n\nprint(ans)\n"}
{"problem_id": "p03720", "input": "n, m = list(map(int, input().split()))\n\nRD = list(list(map(int, input().split())) for _ in range(m))\n\nfor i in range(1, n + 1):\n\n    ans = 0\n\n    for j in RD:\n\n        ans += j.count(i)\n\n    print(ans)"}
{"problem_id": "p03325", "input": "N = int(input())\n\nx = list(map(int, input().split()))\n\ncnt = 0\n\nfor i in x:\n\n  while i % 2 == 0:\n\n    cnt += 1\n\n    i /= 2\n\nprint(cnt)"}
{"problem_id": "p02649", "input": "def popcount(x):\n\n    x = x - ((x >> 1) & 0x55555555)\n\n    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)\n\n    x = (x + (x >> 4)) & 0x0f0f0f0f\n\n    x = x + (x >> 8)\n\n    x = x + (x >> 16)\n\n    return x & 0x0000007f\n\n\n\ncmb=[[0 for i in range(51)] for j in range(51)]\n\ncmb[0][0]=1\n\nfor i in range(51):\n\n    for j in range(51):\n\n        if i!=50 and j!=50:\n\n            cmb[i+1][j+1]+=cmb[i][j]\n\n        if i!=50:\n\n            cmb[i+1][j]+=cmb[i][j]\n\n\n\nfor i in range(1,51):\n\n    for j in range(2,51):\n\n        cmb[i][j]+=cmb[i][j-1]\n\n\n\nN,K,T,S=list(map(int,input().split()))\n\na=list(map(int,input().split()))\n\n\n\nmust0=[i for i in range(18) if S>>i &1==0]\n\nmust1=[i for i in range(18) if T>>i &1==1]\n\n\n\nA=[]\n\nfor val in a:\n\n    check=True\n\n    for j in must0:\n\n        check=check&(val>>j &1==0)\n\n    for j in must1:\n\n        check=check&(val>>j &1==1)\n\n    if check:\n\n        A.append(val)\n\n\n\nif not A:\n\n    print((0))\n\n    exit()\n\n\n\nbit=[]\n\nfor i in range(18):\n\n    if i not in must0 and i not in must1:\n\n        bit.append(i)\n\n\n\nfor i in range(len(A)):\n\n    temp=0\n\n    for j in range(len(bit)):\n\n        temp+=(A[i]>>bit[j] &1==1)*2**j\n\n    A[i]=temp\n\n\n\nans=0\n\nn=len(bit)\n\ndata=[0]*(2**n)\n\nfor i in range(2**n):\n\n    t=set([])\n\n    for a in A:\n\n        data[a&i]+=1\n\n        t.add(a&i)\n\n    temp=0\n\n    for val in t:\n\n        temp+=cmb[data[val]][min(K,data[val])]\n\n    ans+=temp*(-1)**popcount(i)\n\n    for val in t:\n\n        data[val]=0\n\n\n\nprint(ans)\n"}
{"problem_id": "p02814", "input": "import sys\n\nfrom math import gcd\n\n\n\nread = sys.stdin.read\n\nreadline = sys.stdin.readline\n\nreadlines = sys.stdin.readlines\n\nsys.setrecursionlimit(10 ** 9)\n\nINF = 1 << 60\n\n\n\n\n\ndef lcm(x, y):\n\n    return x * y // gcd(x, y)\n\n\n\n\n\ndef main():\n\n    N, M = list(map(int, input().split()))\n\n    A = list(set(map(int, input().split(\" \"))))\n\n    A = [a // 2 for a in A]\n\n    semi_lcm = 1\n\n    for a in A:\n\n        semi_lcm = lcm(semi_lcm, a)\n\n        if semi_lcm > M:\n\n            print((0))\n\n            return\n\n\n\n    for a in A:\n\n        if semi_lcm // a % 2 == 0:\n\n            print((0))\n\n            return\n\n\n\n    print(((M // semi_lcm + 1) // 2))\n\n    return\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03634", "input": "import sys\n\nsys.setrecursionlimit(10**6)\n\ndef dfs(v,p,d):\n\n    for i, j in tree[v]:\n\n        if i != p:\n\n            depth[i] = d + j\n\n            dfs(i,v,d+j)\n\n\n\nN = int(input())\n\n\n\ntree = [[] for _ in range(N)]\n\n\n\nfor i in range(N-1):\n\n    a, b, c = list(map(int, input().split()))\n\n    a -= 1\n\n    b -= 1\n\n    tree[a].append((b,c))\n\n    tree[b].append((a,c))\n\n\n\nQ, K = list(map(int, input().split()))\n\n\n\ndepth = [0 for i in range(N)]\n\ndepth[K-1] = 0\n\n\n\ndfs(K-1,-1,0)\n\n\n\nfor _ in range(Q):\n\n    x, y = list(map(int, input().split()))\n\n    print((depth[x-1] + depth[y-1]))"}
{"problem_id": "p03796", "input": "import math\n\nn = int(input())\n\n\n\npower = math.factorial(n)\n\n\n\nprint((power % (10**9 + 7)))\n"}
{"problem_id": "p02883", "input": "#!/usr/bin/env python3\n\nimport sys\n\nINF = float(\"inf\")\n\nfrom bisect import bisect_left\n\n\n\n\n\ndef solve(N: int, K: int, A: \"List[int]\", F: \"List[int]\"):\n\n    A.sort()\n\n    F.sort(reverse=True)\n\n    h = []\n\n    for a, f in zip(A, F):\n\n        h.append((a*f, a, f))\n\n    h.sort()\n\n    maxtime = h[-1][0]\n\n\n\n    def isOK(y):\n\n        i = bisect_left(h, (y+1, -1, -1))\n\n        counter = 0\n\n        # print(h[i:])\n\n        for p, a, f in h[i:]:\n\n            counter += a-y//f\n\n        return counter <= K\n\n\n\n    def binary_search(x):\n\n        ng = -1\n\n        ok = len(x)\n\n        while abs(ok - ng) > 1:\n\n            mid = (ok + ng)//2\n\n            # print(\"mid: {}, in ({}, {})\".format(mid, ng, ok))\n\n            if isOK(mid):\n\n                ok = mid\n\n            else:\n\n                ng = mid\n\n        return ng, ok\n\n\n\n    ng, ok = binary_search(list(range(maxtime)))\n\n    print(ok)\n\n\n\n    # while k > 0:\n\n    #     p1, a1, f1 = heapq.heappop(h)\n\n    #     p2, a2, f2 = heapq.heappop(h)\n\n    #     p1, p2 = -p1, -p2\n\n    #     sub = min(a1 - math.ceil((p2/f1)-1), k)\n\n    #     a1 -= sub\n\n    #     k -= sub\n\n    #     heapq.heappush(h, (-a1*f1, a1, f1))\n\n    #     heapq.heappush(h, (-a2*f2, a2, f2))\n\n    # # print(h)\n\n    # p, a, f = heapq.heappop(h)\n\n    # print(-p)\n\n\n\n    return\n\n\n\n\n\ndef main():\n\n\n\n    def iterate_tokens():\n\n        for line in sys.stdin:\n\n            for word in line.split():\n\n                yield word\n\n    tokens = iterate_tokens()\n\n    N = int(next(tokens))  # type: int\n\n    K = int(next(tokens))  # type: int\n\n    A = [int(next(tokens)) for _ in range(N)]  # type: \"List[int]\"\n\n    F = [int(next(tokens)) for _ in range(N)]  # type: \"List[int]\"\n\n    solve(N, K, A, F)\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03796", "input": "import math\n\nn = int(input())\n\nprint((math.factorial(n)%(10**9+7)))\n"}
{"problem_id": "p03634", "input": "import heapq\n\n\n\nN = int(input())\n\nabc = [list(map(int,input().split())) for _ in range(N-1)]\n\nQ,K = list(map(int,input().split()))\n\nxy = [list(map(int,input().split())) for _ in range(Q)]\n\n\n\nconnect = [[] for _ in range(N)]\n\nINFTY = 10**15\n\nfor a,b,c in abc:\n\n    connect[a-1].append([b-1,c])\n\n    connect[b-1].append([a-1,c])\n\n\n\ncost = [[INFTY,False] for _  in range(N)]\n\ncost[K-1][0] = 0\n\nq = [(0,K-1)]\n\nwhile q:\n\n    _,i = heapq.heappop(q)\n\n    if cost[i][1]:\n\n        continue\n\n    cost[i][1] = True\n\n    ci0 = cost[i][0]\n\n    for j,c in connect[i]:\n\n        if cost[j][1]:\n\n            continue\n\n        tmp_cost = ci0+c\n\n        if tmp_cost < cost[j][0]:\n\n            cost[j][0] = tmp_cost\n\n            heapq.heappush(q,(tmp_cost,j))\n\n\n\nfor x,y in xy:\n\n    print((cost[x-1][0] + cost[y-1][0]))"}
{"problem_id": "p03416", "input": "A,B = list(map(int,input().split()))\n\n\n\n\n\ndef kaibun(n):\n\n\tkey = 0\n\n\tfor i in range(1,n+1):\n\n\t\tif str(i) == str(i)[::-1]:\n\n\t\t\tkey += 1\n\n\treturn key\n\n\n\nprint((kaibun(B)-kaibun(A-1)))"}
{"problem_id": "p02555", "input": "from sys import stdin\n\ndef solve():\n\n    s = int(stdin.readline())\n\n    mod = 10**9+7\n\n    if s < 3: return 0\n\n    dp = [0]*(s+1)\n\n    dp[0] = 1\n\n    for i in range(3,s+1):\n\n        for x in range(3,i+1):\n\n            if x in [i-1,i-2]:\n\n                continue\n\n            dp[i] += dp[i-x]\n\n    return dp[s]%mod\n\nprint((solve()))"}
{"problem_id": "p02773", "input": "N = int(input())\n\ns_list = {}\n\nfor i in range(N):\n\n  S = input()\n\n  if S in list(s_list.keys()):\n\n    s_list[S] += 1\n\n  else:\n\n    s_list[S] = 0\n\nmax = 0\n\nmaxs = []\n\nfor s,c in list(s_list.items()):\n\n  if c > max:\n\n    maxs = [s]\n\n    max = c\n\n  elif c == max:\n\n    maxs.append(s)\n\nmaxs.sort()\n\nfor m in maxs:\n\n  print(m)"}
{"problem_id": "p03796", "input": "import math\n\nx = int(input())\n\nprint((math.factorial(x) % (10**9 + 7)))"}
{"problem_id": "p02730", "input": "S = input()\n\nN = len(S)\n\nleft = S[:int(N/2)]\n\nright = S[int((N+2)/2):]\n\nS_reversed = \"\".join(reversed(list(S)))\n\nleft_reversed = \"\".join(reversed(list(left)))\n\nright_reversed = \"\".join(reversed(list(right)))\n\n\n\nif S == S_reversed and left == left_reversed and right == right_reversed:\n\n    print(\"Yes\")\n\nelse:\n\n    print(\"No\")"}
{"problem_id": "p03416", "input": "a,b=list(map(int,input().split()))\n\nans=0\n\nfor i in range(b+1)[a:]:\n\n  if len(str(i))%2==0:\n\n    p=list(str(i))[:len(str(i))//2]\n\n    q=list(reversed(list(str(i))[len(str(i))//2:]))\n\n    if p==q:\n\n      ans+=1\n\n  else:\n\n    s=list(str(i))[:len(str(i))//2+1]\n\n    d=list(reversed(list(str(i))[len(str(i))//2:]))\n\n    if s==d:\n\n      ans += 1\n\nprint(ans)"}
{"problem_id": "p02814", "input": "import sys\n\nimport itertools\n\n# import numpy as np\n\nimport time\n\nimport math\n\n \n\nsys.setrecursionlimit(10 ** 7)\n\n \n\nfrom collections import defaultdict\n\n \n\nread = sys.stdin.buffer.read\n\nreadline = sys.stdin.buffer.readline\n\nreadlines = sys.stdin.buffer.readlines\n\n \n\n \n\nfrom functools import reduce\n\n# from math import *\n\nfrom math import *\n\nN, M = list(map(int, readline().split()))\n\nA = list(sorted([int(x) // 2 for x in readline().split()]))\n\nmin_cm = reduce(lambda a, b: (a * b) // gcd(a, b), A)\n\n \n\n# print(all(map(lambda x: (min_cm // x) % 2 == 1, A)))\n\nif not all([(min_cm // x) % 2 == 1 for x in A]):\n\n    print((0))\n\n    exit(0)\n\nif min_cm > M:\n\n    print((0))\n\n    exit(0)\n\nans = (M // min_cm + 1) // 2\n\nprint(ans)"}
{"problem_id": "p01093", "input": "while int(input()) > 0:\n\n    s = sorted(map(int, input().split()))\n\n    print((min(abs(a - b) for (a, b) in zip(s, s[1:]))))"}
{"problem_id": "p02814", "input": "# ABC150 D\n\nsi = lambda: input()\n\nni = lambda: int(input())\n\nnm = lambda: list(map(int, input().split()))\n\nnl = lambda: list(map(int, input().split()))\n\nfrom math import gcd\n\nfrom math import ceil\n\ndef lcm(x, y):\n\n    return (x * y) // gcd(x, y)\n\nn,m=nm()\n\na=nl()\n\nans=0\n\na=[x//2 for x in a] \n\n\n\nlcm_v=a[0]\n\nfor i in range(n):\n\n    lcm_v=lcm(lcm_v,a[i])\n\nok_flg=[(lcm_v//i)%2==1 for i in a]\n\nif all(ok_flg):\n\n    ans=((m//lcm_v)+1)//2\n\nprint(ans)\n\n\n"}
{"problem_id": "p02412", "input": "def main():\n\n\n\n    while True:\n\n        n, x = tuple(map(int, input().split()))\n\n        pattern = 0\n\n\n\n        if n == x == 0:\n\n            break\n\n        else:\n\n            for a in range(1, n+1):\n\n                for b in range(1, a):\n\n                    for c in range(1, b):\n\n                        pattern += 1 if a + b + c == x and a > b > c else 0\n\n            print(pattern)\n\n                            \n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03416", "input": "A, B = list(map(int, input().split()))\n\nnumbers = list(range(A, B+1))\n\ncount = 0\n\nfor i in numbers:\n\n    m = str(i)\n\n    rm = ''.join(list(reversed(m)))\n\n    if m == rm:\n\n        count += 1\n\nprint(count)"}
{"problem_id": "p02863", "input": "import sys\n\nfrom operator import itemgetter\n\nfrom heapq import heapify, heappop, heappush\n\nMAX_INT = int(10e15)\n\nMIN_INT = -MAX_INT\n\nmod = 1000000007\n\nsys.setrecursionlimit(1000000)\n\ndef IL(): return list(map(int,input().split()))\n\ndef SL(): return input().split()\n\ndef I(): return int(sys.stdin.readline())\n\ndef S(): return input()\n\n\n\nN, T = IL()\n\nab = [IL() for i in range(N)]\n\nab.sort(key=itemgetter(0))\n\n#print(ab)\n\n\n\ndp = [[0]*(T+1+3000+1) for _ in range(N+1)]\n\nans = 0\n\nfor i in range(N):\n\n  for j in range(T+1+3000+1):\n\n    time, deli = ab[i]\n\n    if 0 <= j-time < T:\n\n      dp[i + 1][j] = max(dp[i][j], dp[i][j - time] + deli)\n\n    else:\n\n      dp[i + 1][j] = dp[i][j]\n\n    ans = max(ans, dp[i + 1][j])\n\nprint(ans)\n\n\n\n#print(dp)\n"}
{"problem_id": "p02599", "input": "import sys\n\n\n\nread = sys.stdin.read\n\nreadline = sys.stdin.readline\n\nreadlines = sys.stdin.readlines\n\nsys.setrecursionlimit(10 ** 9)\n\nINF = 1 << 60\n\nMOD = 1000000007\n\n\n\n# Reference: https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/\n\n# Python3 code to find number of\n\n# distinct numbers in a subarray\n\nMAX = 1000001\n\n\n\n# structure to store queries\n\nclass Query:\n\n    def __init__(self, l, r, idx):\n\n        self.l = l\n\n        self.r = r\n\n        self.idx = idx\n\n\n\n\n\n# updating the bit array\n\ndef update(idx, val, bit, n):\n\n    while idx <= n:\n\n        bit[idx] += val\n\n        idx += idx & -idx\n\n\n\n\n\n# querying the bit array\n\ndef query(idx, bit, n):\n\n    summ = 0\n\n    while idx:\n\n        summ += bit[idx]\n\n        idx -= idx & -idx\n\n    return summ\n\n\n\n\n\ndef answeringQueries(arr, n, queries, q):\n\n\n\n    # initialising bit array\n\n    bit = [0] * (n + 1)\n\n\n\n    # holds the rightmost index of\n\n    # any number as numbers of a[i]\n\n    # are less than or equal to 10^6\n\n    last_visit = [-1] * MAX\n\n\n\n    # answer for each query\n\n    ans = [0] * q\n\n\n\n    query_counter = 0\n\n    for i in range(n):\n\n\n\n        # If last visit is not -1 update -1 at the\n\n        # idx equal to last_visit[arr[i]]\n\n        if last_visit[arr[i]] != -1:\n\n            update(last_visit[arr[i]] + 1, -1, bit, n)\n\n\n\n        # Setting last_visit[arr[i]] as i and\n\n        # updating the bit array accordingly\n\n        last_visit[arr[i]] = i\n\n        update(i + 1, 1, bit, n)\n\n\n\n        # If i is equal to r of any query store answer\n\n        # for that query in ans[]\n\n        while query_counter < q and queries[query_counter].r == i:\n\n            ans[queries[query_counter].idx] = query(queries[query_counter].r + 1, bit, n) - query(\n\n                queries[query_counter].l, bit, n\n\n            )\n\n            query_counter += 1\n\n\n\n    # print answer for each query\n\n    for i in range(q):\n\n        print((ans[i]))\n\n\n\n\n\n# This code is contributed by\n\n# sanjeev2552\n\n\n\n\n\ndef main():\n\n    N, Q = list(map(int, readline().split()))\n\n    C = list(map(int, readline().split()))\n\n    (*LR,) = list(map(int, read().split()))\n\n\n\n    queries = [0] * Q\n\n    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):\n\n        queries[i] = Query(l - 1, r - 1, i)\n\n\n\n    queries.sort(key=lambda x: x.r)\n\n    answeringQueries(C, N, queries, Q)\n\n\n\n    return\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n\n\n"}
{"problem_id": "p02596", "input": "k = int(input())\n\nnum = 0\n\nif not k%2:\n\n    print((-1))\n\nelse:\n\n    for i in range(k):\n\n        num = (num*10+7)%k\n\n        if num == 0:\n\n            print((i+1))\n\n            break\n\n    else:\n\n        print((-1))"}
{"problem_id": "p02596", "input": "k = int(input())\n\ncount = 1\n\nn = 0\n\nif k % 2 == 0 or k % 5 == 0:\n\n    print((-1))\n\nelse:\n\n  while 1:\n\n      n = (n * 10 + 7) % k  \n\n      if n == 0:\n\n        break \n\n      count += 1\n\n  print(count)"}
{"problem_id": "p03250", "input": "a, b, c = sorted(map(int, input().split()))\n\n\n\nprint((c*10 + b + a))"}
{"problem_id": "p03371", "input": "a, b, c, x, y = list(map(int, input().split()))\n\nans = float('inf')\n\n\n\nfor i in range(200005):\n\n    tmp = i * 2 * c\n\n    tmp += max(0, x-i) * a\n\n    tmp += max(0, y-i) * b\n\n    ans = min(ans, tmp)\n\n\n\nprint(ans)"}
{"problem_id": "p03568", "input": "N = int(input())\n\nAs = list(map(int,input().split()))\n\n\n\n\n\ndef dfs(A_s, index,Bss):\n\n    if index == N:\n\n        tmp = 1\n\n        for b in Bss:\n\n            tmp *= b\n\n        return 1 if tmp % 2 == 0 else 0\n\n    b_mi = Bss.copy()\n\n    b_mi.append(A_s[index] - 1)\n\n\n\n    b = Bss.copy()\n\n    b.append(A_s[index])\n\n\n\n    b_pl = Bss.copy()\n\n    b_pl.append(A_s[index] + 1)\n\n    return dfs(A_s,index + 1, b_mi) + dfs(A_s,index + 1,b) + dfs(A_s,index + 1,b_pl)\n\n\n\n\n\nprint((dfs(As,0,[])))\n"}
{"problem_id": "p03796", "input": "import math\n\nn=int(input())\n\nprint((math.factorial(n)%(10**9+7)))"}
{"problem_id": "p02555", "input": "from sys import stdin\n\nfrom math import factorial\n\n\n\n\n\ndef combinations_count(n, r):\n\n    return factorial(n) // (factorial(n - r) * factorial(r))\n\n\n\n\n\ndef combinations_with_replacement_count(n, r):\n\n    return combinations_count(n + r - 1, r)\n\n\n\n\n\ndef main():\n\n    _in = [_.rstrip() for _ in stdin.readlines()]\n\n    S = int(_in[0])  # type:int\n\n    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n\n    min_ = 1\n\n    max_ = S // 3\n\n    ans = 0\n\n    for i in range(min_, max_ + 1):\n\n        mod = S - i * 3\n\n        ans += combinations_with_replacement_count(mod + 1, i - 1) % (10**9 + 7)\n\n    ans %= (10**9 + 7)\n\n    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n    print(ans)\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()\n"}
{"problem_id": "p03801", "input": "n = int(input())\n\na = list(map(int, input().split()))\n\n\n\ntmp = [[e, n - i] for i, e in enumerate(a)]\n\ntmp.sort(reverse=True)\n\n\n\naa = [[e, n - i] for e, i in tmp] + [[0, -1]]\n\n\n\nv_prev, i_prev = aa[0]\n\ni = 0\n\nans = [0] * n\n\nsm = 0\n\nwhile i < n:\n\n    while aa[i][1] >= i_prev:\n\n        sm += aa[i][0]\n\n        i += 1\n\n\n\n    ans[i_prev] += sm - aa[i][0] * i\n\n    sm = aa[i][0] * i\n\n    v_prev, i_prev = aa[i]\n\n\n\nprint(*ans, sep=\"\\n\")\n"}
{"problem_id": "p03013", "input": "N, M = list(map(int, input().split()))\n\nA_ = [int(input()) for _ in range(M)]\n\nA = [0] * (N+3)\n\nfor a in A_:\n\n    A[a] = 1\n\ndp = [0] * (N+3)\n\ndp[0] = 1\n\n\n\nmod = 10**9+7\n\n\n\nfor i in range(1, N+1):\n\n    if A[i-1] == 0:\n\n        dp[i] += dp[i-1]\n\n    if A[i-2] == 0:\n\n        dp[i] += dp[i-2]\n\n    dp[i] %= mod\n\nprint((dp[N]))"}
{"problem_id": "p02792", "input": "n=int(input())\n\nD={}\n\nDD={}\n\nfor i in range(1,n+1):\n\n   s=(str(i)[0],str(i)[-1])\n\n   t=(str(i)[-1],str(i)[0])\n\n   if s not in D:\n\n      D[s]=1\n\n   else:\n\n      D[s]+=1\n\n   if t not in DD:\n\n      DD[t]=1\n\n   else:\n\n      DD[t]+=1\n\nans=0\n\nfor i in D:\n\n   if i in DD:\n\n      ans+=D[i]*DD[i]\n\nprint(ans)\n\n      "}
{"problem_id": "p03796", "input": "import math\n\n\n\nN = int(input())\n\nans = 0\n\n\n\nans =math.factorial(N) % (10**9 +7)\n\n\n\nprint(ans)"}
{"problem_id": "p03078", "input": "X,Y,Z,K = list(map(int,input().split()))\n\nA = list(map(int,input().split()))\n\nB = list(map(int,input().split()))\n\nC = list(map(int,input().split()))\n\nasort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)\n\nprint((asort[0] + bsort[0] + csort[0]))\n\nalready = [[0,0,0]]\n\nx,y,z = 0,0,0\n\nplace_sum = []\n\ncheck = []\n\nfor k in range(K - 1):\n\n    if [x + 1,y,z] not in already and x + 1 < X:\n\n        already.append([x + 1,y,z])\n\n        place_sum.append([x + 1,y,z])\n\n        check.append(asort[x + 1] + bsort[y] + csort[z])\n\n    if [x,y + 1,z] not in already and y + 1 < Y:\n\n        already.append([x,y + 1,z])\n\n        place_sum.append([x,y + 1,z])\n\n        check.append(asort[x] + bsort[y + 1] + csort[z])\n\n    if [x,y,z + 1] not in already and z + 1 < Z:\n\n        already.append([x,y,z + 1])\n\n        place_sum.append([x,y,z + 1])\n\n        check.append(asort[x] + bsort[y] + csort[z + 1])\n\n    print((max(check)))\n\n    x,y,z = place_sum[check.index(max(check))][0],place_sum[check.index(max(check))][1],place_sum[check.index(max(check))][2]\n\n    place_sum.pop(check.index(max(check)))\n\n    check.remove(max(check))"}
{"problem_id": "p03371", "input": "a,b,c,x,y=list(map(int,input().split()))\n\nans=a*x+b*y\n\nn=max(x,y)\n\nfor i in range(1,n+1):\n\n  ans=min(ans,2*i*c+a*max(0,x-i)+b*max(0,y-i))\n\nprint(ans)\n\n\n\n\n"}
{"problem_id": "p03325", "input": "answer = 0\n\nN = int(input())\n\nA = list(map(int,input().split()))\n\nfor i in range(N) :\n\n    while A[i] % 2 == 0 :\n\n        A[i] = A[i] / 2\n\n        answer += 1\n\nprint(answer)\n\n\n"}
{"problem_id": "p03034", "input": "import sys\n\n\n\ndef main():\n\n    input = sys.stdin.readline\n\n    N = int(input())\n\n    S = list(map(int, input().split()))\n\n\n\n    ans = 0\n\n    for C in range(1, N//2):\n\n        n = N // C\n\n        point = 0\n\n        used = set([0])\n\n        for k in range(1, n):\n\n            A = N - 1 - k*C\n\n\n\n            if A in used or k*C in used or A == k*C:\n\n                break\n\n            used.add(A)\n\n            used.add(k*C)\n\n\n\n            point += S[A] + S[k*C]\n\n            ans = max(ans, point)\n\n\n\n    return ans\n\n\n\n\n\nif __name__ == '__main__':\n\n    print((main()))\n"}
{"problem_id": "p03038", "input": "import sys\n\ninput = sys.stdin.readline\n\n\n\ndef I(): return int(input())\n\ndef MI(): return list(map(int, input().split()))\n\ndef LI(): return list(map(int, input().split()))\n\n\n\ndef main():\n\n    mod=10**9+7\n\n    N,M=MI()\n\n    A=LI()\n\n    CB=[[0,0]for _ in range(M)]\n\n    A.sort()\n\n    for i in range(M):\n\n        CB[i][1],CB[i][0]=MI()\n\n        \n\n    CB.sort(reverse=True)\n\n    now=0\n\n    \n\n    for i in range(N):\n\n        if CB[now][1]<=0:\n\n            now+=1\n\n        \n\n        if now>=M:\n\n            break    \n\n        \n\n        ch=CB[now][0]\n\n        if A[i]<ch:\n\n            A[i]=ch\n\n            CB[now][1]-=1\n\n        else:\n\n            break\n\n        \n\n    print((sum(A)))\n\n    \n\n\n\nmain()\n"}
{"problem_id": "p03828", "input": "from math import factorial\n\n\n\nn = int(input())\n\nf = factorial(n)\n\n\n\nmod = 10 ** 9 + 7\n\n\n\ndef primes(n):\n\n    is_prime = [True] * (n + 1)\n\n    is_prime[0] = False\n\n    is_prime[1] = False\n\n    for i in range(2, int(n ** 0.5) + 1):\n\n        if not is_prime[i]:\n\n            continue\n\n        for j in range(i * 2, n + 1, i):\n\n            is_prime[j] = False\n\n    return [i for i in range(n + 1) if is_prime[i]]\n\n\n\nans = 1\n\nfor p in primes(n):\n\n    temp = 1\n\n    while f % p == 0:\n\n        temp += 1\n\n        f //= p\n\n    ans = (ans * temp) % mod\n\nprint(ans)\n"}
{"problem_id": "p02937", "input": "from collections import defaultdict\n\nfrom bisect import bisect_left\n\n\n\ns = input()\n\nn = len(s)\n\ns = s + s\n\nt = input()\n\nif set(t) - set(s):\n\n\tprint((-1))\n\n\texit()\n\nd = defaultdict(list)\n\nfor i in range(2 * n):\n\n\td[s[i]] += [i]\n\ncur = tot = 0\n\nfor c in t:\n\n\tx = d[c][bisect_left(d[c], cur)]\n\n\tif x < n:\n\n\t\tcur = x + 1\n\n\telse:\n\n\t\tcur = x - n + 1\n\n\t\ttot += n\n\ntot += cur\n\nprint(tot)\n"}
{"problem_id": "p02996", "input": "import sys\n\nstdin = sys.stdin\n\n\n\nsys.setrecursionlimit(10 ** 7)\n\n\n\ndef li(): return list(map(int, stdin.readline().split()))\n\ndef li_(): return [int(x) - 1 for x in stdin.readline().split()]\n\ndef lf(): return list(map(float, stdin.readline().split()))\n\ndef ls(): return stdin.readline().split()\n\ndef ns(): return stdin.readline().rstrip()\n\ndef lc(): return list(ns())\n\ndef ni(): return int(stdin.readline())\n\ndef nf(): return float(stdin.readline())\n\n\n\nn = ni()\n\nab = [list(li()) for _ in range(n)]\n\n\n\nab.sort(key=lambda x: x[1])\n\n\n\ncur = 0\n\n\n\nans = True\n\n\n\nfor ai, bi in ab:\n\n    cur += ai\n\n    if cur > bi:\n\n        ans = False\n\n\n\nprint((\"Yes\" if ans else \"No\"))"}
{"problem_id": "p03416", "input": "n, m = list(map(int, input().split()))\n\nans = 0\n\nfor i in range(n, m+1):\n\n    if str(i)[0]+str(i)[1] == str(i)[-1]+str(i)[-2]: ans += 1\n\nprint(ans)"}
{"problem_id": "p00001", "input": "ans=[]\n\nfor i in range (0,10):\n\n    ans.append(int(input()))\n\nans.sort(reverse=True)\n\nfor i in range (0,3):\n\n    print((ans[i]))"}
{"problem_id": "p02555", "input": "# -*- coding: utf-8 -*-\n\nimport sys\n\n\n\n\n\ndef main():\n\n    S = int( sys.stdin.readline() )\n\n\n\n    dp = [0]*(S+1)\n\n    dp[0] = 1\n\n    mod = 10**9 + 7\n\n\n\n    for i in range(3, S+1):\n\n        cnt = 0\n\n\n\n        for j in range(3, i+1):\n\n            cnt += dp[i-j]\n\n            cnt %= mod\n\n        \n\n        dp[i] = cnt\n\n\n\n\n\n    print((dp[-1]))\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()\n"}
{"problem_id": "p02785", "input": "def solve():\n\n  N, K = list(map(int, input().split()))\n\n  H = list(map(int, input().split()))\n\n  if K>=N:\n\n    return 0\n\n  H.sort()\n\n  ans = sum(H[:N-K])\n\n  return ans\n\nprint((solve()))"}
{"problem_id": "p03835", "input": "k, s = list(map(int, input().split()))\n\n\n\nans = 0\n\nfor x in range(k+1):\n\n  for y in range(k+1):\n\n    if 0<=s-x-y<=k:\n\n      ans += 1\n\n      \n\nprint(ans)"}
{"problem_id": "p03680", "input": "import sys\n\n\n\nN = int(input())\n\na = [int(input()) for _ in range(N)]\n\n\n\nl = 1\n\np = a[0] - 1\n\n\n\nif a[0] == 2:\n\n    print(l)\n\n    sys.exit()\n\n\n\nwhile l < int(1e6):\n\n    l += 1\n\n    if a[p] == 2:\n\n        print(l)\n\n        break\n\n    else:\n\n        p = a[p] - 1\n\nelse:\n\n    print((-1))"}
{"problem_id": "p03796", "input": "import math\n\n\n\n\n\ndef main():\n\n    N = int(input())\n\n    power = math.factorial(N)\n\n    print((power % (10 ** 9 + 7)))\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()\n"}
{"problem_id": "p02282", "input": "def post_from_pre_in(preorder_elements, inorder_elements):\n\n    if preorder_elements:\n\n        global cnt\n\n        root = preorder_elements[0]\n\n        root_index = inorder_elements.index(root)\n\n        preorder_left = preorder_elements[1:root_index+1]\n\n        inorder_left = inorder_elements[:root_index]\n\n        preorder_right = preorder_elements[root_index+1:]\n\n        inorder_right = inorder_elements[root_index+1:]\n\n        post_from_pre_in(preorder_left, inorder_left)\n\n        post_from_pre_in(preorder_right, inorder_right)\n\n        if cnt:\n\n            print(root, end = ' ')\n\n            cnt -= 1\n\n        else:\n\n            print(root)\n\n\n\n\n\ncnt = int(input()) - 1\n\n\n\na = list(map(int, input().split()))\n\nb = list(map(int, input().split()))\n\n\n\npost_from_pre_in(a, b)\n"}
{"problem_id": "p03078", "input": "def main():\n\n\tx, y, z, k = list(map(int, input().split()))\n\n\ta = list(map(int, input().split()))\n\n\tb = list(map(int, input().split()))\n\n\tc = list(map(int, input().split()))\n\n\td = [0]*x*y\n\n\tfor i in range(x):\n\n\t\tfor j in range(y):\n\n\t\t\td[i*y+j] = a[i]+b[j]\n\n\td.sort(reverse=True)\n\n\tc.sort(reverse=True)\n\n\n\n\tc_len = min(k, z)\n\n\td_len = min(k, x*y)\n\n\te = [0]*d_len*c_len\n\n\tfor i in range(d_len):\n\n\t\tfor j in range(c_len):\n\n\t\t\te[i*c_len+j] = d[i] + c[j]\n\n\te.sort(reverse=True)\n\n\tfor i in range(k):\n\n\t\tprint((e[i]))\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()"}
{"problem_id": "p00713", "input": "from math import sqrt\n\nfrom bisect import bisect_left\n\ndef circle_center(x1, y1, x2, y2):\n\n    xd = x2 - x1; yd = y2 - y1\n\n    d = xd**2 + yd**2\n\n    k = sqrt((4.0 - d) / d) / 2.0\n\n    xc = (x1 + x2) / 2.0\n\n    yc = (y1 + y2) / 2.0\n\n    return [[xc - k*yd, yc + k*xd], [xc + k*yd, yc - k*xd]]\n\nwhile 1:\n\n    n = int(input())\n\n    if n==0: break\n\n    p = [list(map(float, input().split())) for i in range(n)]\n\n    p.sort()\n\n    prev = 0\n\n    ans = 1\n\n    for i in range(n):\n\n        bx, by = p[i]\n\n        while bx - p[prev][0] >= 2.0: prev += 1\n\n        for j in range(i+1, n):\n\n            cx, cy = p[j]\n\n            if cx - bx >= 2.0: break\n\n            if (bx - cx)**2 + (by - cy)**2 <= 4.0:\n\n                for ex, ey in circle_center(bx, by, cx, cy):\n\n                    count = 2\n\n                    for k in range(prev, n):\n\n                        if k==i or k==j: continue\n\n                        dx, dy = p[k]\n\n                        if dx - bx >= 2.0: break\n\n                        if (ex - dx)**2 + (ey - dy)**2 <= 1.0:\n\n                            count += 1\n\n                    ans = max(ans, count)\n\n    print(ans)"}
{"problem_id": "p03074", "input": "def solve():\n\n  N, K = list(map(int, input().split()))\n\n  _S = input()\n\n  S = []\n\n  b = _S[0]\n\n  s = 0\n\n  if b == '0': S.append(0)\n\n  for _s in _S:\n\n    if b == _s:\n\n      s = s + 1\n\n    else:\n\n      b = _s\n\n      S.append(s)\n\n      s = 1\n\n  S.append(s)\n\n  if b == '0': S.append(0)\n\n\n\n  num = min(len(S), 2 * K + 1)\n\n  # n = sum(S[0:num if _S[0] == '1' else (num - 1)])\n\n  n = sum(S[0:num])\n\n  m = n\n\n  # for i in range(0 if _S[0] == '1' else -1, len(S) - num, 2):\n\n  for i in range(0, len(S) - num, 2):\n\n    n = n - sum(S[i:i+2])\n\n    n = n + sum(S[i + num:i + num + 2])\n\n    m = max(m, n)\n\n\n\n  return m\n\n\n\nprint((solve()))"}
{"problem_id": "p03796", "input": "import math\n\nN = int(input())\n\nans = math.factorial(N) % (10 ** 9 + 7)\n\nprint(ans)"}
{"problem_id": "p03371", "input": "#python3\n\nINF = int(1e9)\n\ndef main():\n\n    a, b, c, x, y = list(map(int, input().split()))\n\n    ans = INF\n\n    for i in range(2*10**5+100):\n\n        t = 2*c*i + max(x-i, 0) * a + max(y-i, 0) * b\n\n        ans = min(ans, t)\n\n    print(ans)\n\nmain()"}
{"problem_id": "p03828", "input": "from functools import reduce\n\nN = int(input())\n\n\n\nprime_table = [1] * (N+1)\n\n\n\nfor x in range(2, N+1):\n\n    for t in range(2, x+1):\n\n        while x % t == 0:\n\n            prime_table[t] += 1\n\n            x //= t\n\nprint((reduce(lambda x, y: x * y % (int(1e9) + 7), prime_table)))"}
{"problem_id": "p03835", "input": "K,S = list(map(int,input().split(\" \")))\n\nans = 0\n\nfor i in range(K+1):\n\n\tfor j in range(K+1):\n\n\t\tif (S - i - j) <= K and (S-i-j) >= 0:\n\n\t\t\tans += 1\n\n\n\nprint(ans)\n"}
{"problem_id": "p02412", "input": "while 1:\n\n    ans=0\n\n    n,x=list(map(int,input().split()))\n\n    if n:\n\n        for i in range(1,n-1):\n\n            for j in range(i+1,n):\n\n                for k in range(j+1,n+1):\n\n                    if i+j+k==x:ans+=1\n\n    else:break\n\n    print(ans)"}
{"problem_id": "p02767", "input": "def main():\n\n  from statistics import mean\n\n  from math import floor,ceil\n\n\n\n  n = int(input())\n\n  x = list(map(int, input().split()))\n\n  x_mean = mean(x) \n\n  if x_mean == 0.5:\n\n      greater_than_x = len([i for i in x if i > x_mean])\n\n      if greater_than_x * 2 >= n:\n\n          x_mean = ceil(x_mean)\n\n      else:\n\n          x_mean = floor(x_mean)\n\n  elif x_mean % 1 > 0.5:\n\n      x_mean = ceil(x_mean)\n\n  else:\n\n      x_mean = floor(x_mean)\n\n  x2 = [(num - x_mean)**2 for num in x]\n\n  print((sum(x2)))\n\n\n\nmain()"}
{"problem_id": "p03854", "input": "import sys\n\nsys.setrecursionlimit(10 ** 6)\n\n\n\n\n\ndef solve():\n\n    S = input()\n\n    # print(S, len(S))\n\n\n\n    words = {0: \"dream\", 1: \"dreamer\", 2: \"erase\", 3: \"eraser\"}\n\n\n\n    TABLE = [[-1 for x in range(len(S) + 1)] for y in range(len(words) + 1)]\n\n\n\n    def recur(i, w):\n\n        if not TABLE[w][i] == -1:\n\n            return TABLE[w][i]\n\n\n\n        if i >= len(S):\n\n            # print(\"jey\", log)\n\n            return True\n\n\n\n        r1, r2, r3, r4 = False, False, False, False\n\n        if S[i:i + 5] == words[0]:\n\n            r1 = recur(i + 5, 0)\n\n        if S[i:i + 7] == words[1]:\n\n            r2 = recur(i + 7, 1)\n\n        if S[i:i + 5] == words[2]:\n\n            r3 = recur(i + 5, 2)\n\n        if S[i:i + 6] == words[3]:\n\n            r4 = recur(i + 6, 3)\n\n\n\n        TABLE[w][i] = r1 or r2 or r3 or r4 or False\n\n\n\n        return TABLE[w][i]\n\n\n\n    ans = recur(0, 0)\n\n\n\n    return ans\n\n\n\n\n\nif __name__ == '__main__':\n\n    res = solve()\n\n    if res:\n\n        print(\"YES\")\n\n    else:\n\n        print(\"NO\")\n"}
{"problem_id": "p02773", "input": "from collections import defaultdict\n\n\n\nN = int(input())\n\nA = [input() for _ in range(N)]\n\nA.sort()\n\nd = defaultdict(int)\n\nfor a in A:\n\n    d[a] += 1\n\n\n\nl = sorted(d.items())\n\nmax_v = 0\n\n\n\nfor _, v in l:\n\n    if v > max_v:\n\n        max_v = v\n\n    \n\nfor k, v in l:\n\n    if v == max_v:\n\n        print(k)\n\n    else:\n\n        continue\n"}
{"problem_id": "p02691", "input": "n = int(input())\n\na = list(map(int, input().split()))\n\na_index = []\n\nfor i in range(n):\n\n    a_index.append((i, a[i]))\n\ndic1 = {}\n\ndic2 = {}\n\nfor i in range(n):\n\n    one = a_index[i][0] + a_index[i][1]\n\n    two = a_index[i][0] - a_index[i][1]\n\n    if one not in dic1:\n\n        dic1[one] = 1\n\n    else:\n\n        dic1[one] += 1\n\n    if two not in dic2:\n\n        dic2[two] = 1\n\n    else:\n\n        dic2[two] += 1\n\nans = 0\n\nfor i in list(dic1.keys()):\n\n    if i in dic2:\n\n        ans += dic2[i] * dic1[i]\n\nfor i in list(dic2.keys()):\n\n    if i in dic1:\n\n        ans += dic1[i] * dic2[i]\n\n        #print(i)\n\nprint((ans // 2))\n"}
{"problem_id": "p03835", "input": "k,s=list(map(int,input().split()))\n\nans=chk=0\n\nfor i in range(k+1):\n\n    for j in range(k+1):\n\n        if (0<=s-i-j<=k): ans+=1\n\nprint(ans)"}
{"problem_id": "p03564", "input": "N,K = int(input()), int(input())\n\nnow = 1\n\nfor i in range(N):\n\n    if now*2 < now + K:\n\n        now *= 2\n\n    else:\n\n        now += K\n\nprint(now)\n"}
{"problem_id": "p02881", "input": "import math\n\nn=int(input())\n\nans=n\n\ni=1\n\nwhile(i<=math.sqrt(n)):\n\n    if n%i==0:\n\n        d=i+n/i-2\n\n        ans=min(ans,d)\n\n    i+=1\n\nprint((int(ans)))"}
{"problem_id": "p03796", "input": "import math\n\n\n\nN = int(input())\n\n\n\npower = math.factorial(N)\n\n\n\nprint((power % 1000000007))\n\n\n"}
{"problem_id": "p03170", "input": "n, k = list(map(int, input().split()))\n\na_s = list(map(int, input().split()))\n\ndp = [\"Second\"] * (k + 1)\n\nfor i in range(k + 1):\n\n    if dp[i] == \"Second\":\n\n        for a in a_s:\n\n            ii = i + a\n\n            if ii <= k:\n\n                dp[ii] = \"First\"\n\nprint((dp[-1]))\n"}
{"problem_id": "p02622", "input": "S, T = [list(input()) for _ in range(2)]\n\ncnt = 0\n\nfor i in range(len(S)):\n\n    if S[i] != T[i]:\n\n        cnt += 1\n\nprint(cnt)\n"}
{"problem_id": "p02886", "input": "N = int(input())\n\nD = list(map(int,input().split()))\n\ncnt = 0\n\nfor i in range(N-1):\n\n    for j in range(i+1,N):\n\n        cnt += D[i]*D[j]\n\nprint(cnt)"}
{"problem_id": "p03370", "input": "N, X = list(map(int, input().split()))\n\n\n\nmn = [0]*N\n\nfor i in range(N):\n\n  mn[i] = int(input())\n\n  \n\nans = N\n\nx = X - sum(mn)\n\n\n\nwhile(x >= min(mn)):\n\n  if x // min(mn) == 0:\n\n    mn[mn.index(min(mn))] = 1000000\n\n  else:\n\n    if x >= min(mn):\n\n      x -= min(mn)\n\n      ans += 1\n\n      \n\nprint(ans)"}
{"problem_id": "p02596", "input": "#! /usr/bin/env python3\n\n\n\nimport sys\n\nint1 = lambda x: int(x) - 1\n\nread = sys.stdin.buffer.read\n\nreadline = sys.stdin.buffer.readline\n\nreadlines = sys.stdin.buffer.readlines\n\nsys.setrecursionlimit(500000)\n\n\n\n\n\ndef isMultiple(s, m):\n\n    tmp = 0\n\n    for i in range(len(s)):\n\n        tmp = (tmp * 10 + int(s[i])) % m\n\n        if tmp == 0:\n\n            return i\n\n    return -1\n\n\n\n\n\nk = int(readline())\n\nacc = \"7\" * 50000000\n\nif k % 2 == 0:\n\n    ans = -1\n\nelse:\n\n\n\n    ans = isMultiple(acc, k)\n\n    if ans != -1:\n\n        ans += 1\n\n\n\nprint(ans)\n"}
{"problem_id": "p02615", "input": "n,*l=list(map(int,open(0).read().split()));print((sum(sorted(l*2)[-2:~n:-1])))"}
{"problem_id": "p02881", "input": "import math\n\nN = int(input())\n\nfor i in range(int(math.sqrt(N))):\n\n    if N % (int(math.sqrt(N))-i) == 0:\n\n        print((int(N/(int(math.sqrt(N))-i)+int(math.sqrt(N))-i-2)))\n\n        break"}
{"problem_id": "p02994", "input": "N, L = [int(i) for i in input().split()]\n\n\n\nmin_ = L\n\nmax_ = L + N -1\n\n\n\ndef eat_apple():\n\n    if max_<0:\n\n        return max_ \n\n    if L < 0:\n\n        return 0\n\n    return L\n\n\n\nprint(((min_+max_)*(max_-min_+1)//2 - eat_apple()))"}
{"problem_id": "p03363", "input": "from collections import Counter\n\n\n\nN = int(input())\n\ninputs = [int(i) for i in input().split()]\n\n\n\nans = 0\n\nruisekiwa = [0] * (N+1)\n\n\n\nfor i in range(N):\n\n    ruisekiwa[i+1] = ruisekiwa[i] + inputs[i]\n\n\n\nruisekiwa = ruisekiwa[1:]\n\nruisekiwa.sort()\n\ncounter_ruiseki = Counter(ruisekiwa)\n\n\n\nfor key, value in list(counter_ruiseki.items()):\n\n    if key == 0 and value == 1:\n\n        ans += value\n\n        continue\n\n    elif key == 0 and value > 1:\n\n        ans += value\n\n    if value > 1:\n\n        ans += sum(list(range(value)))\n\n\n\nprint(ans)\n"}
{"problem_id": "p03457", "input": "import sys\n\n_input = sys.stdin.readline\n\n\n\n\n\ndef resolve():\n\n    N = int(_input())\n\n    T = [list(map(int, _input().split())) for _ in range(N)]\n\n    t, x, y = 0, 0, 0\n\n    for next_t, next_x, next_y in T:\n\n        diff_xy = abs(x - next_x) + abs(y - next_y)\n\n        diff_t = next_t - t\n\n        if diff_xy > diff_t or (diff_xy % 2 != diff_t % 2):\n\n            print('No')\n\n            exit(0)\n\n    print('Yes')\n\n\n\n\n\nif __name__ == '__main__':\n\n    resolve()"}
{"problem_id": "p03107", "input": "S = [int(_) for _ in input()]\n\nlength = len(S)\n\ntemp = [S[0]]\n\nfor x in S[1:]:\n\n    if(len(temp) == 0):\n\n        temp.append(x)\n\n    elif( temp[-1] == x):\n\n        temp.append(x)\n\n    else:\n\n        temp.pop(-1)\n\nprint((length-len(temp)))\n\n        "}
{"problem_id": "p02596", "input": "K = int(input())\n\n\n\nflg = [False]*K\n\n\n\ntmp = 7 % K\n\ncnt = 1\n\nif tmp == 0:\n\n    print(cnt)\n\n    exit()\n\nwhile True:\n\n    tmp = (tmp*10+7)%K\n\n    if flg[tmp]:\n\n        print((-1))\n\n        break\n\n    else:\n\n        cnt += 1\n\n        if tmp == 0:\n\n            print(cnt)\n\n            break\n\n        flg[tmp] = True\n"}
{"problem_id": "p03796", "input": "from math import factorial\n\nprint((factorial(int(input())) % (10**9+7)))"}
{"problem_id": "p03822", "input": "import sys\n\nsys.setrecursionlimit(202020)\n\n\n\nN = int(input())\n\nwon = [[] for i in range(N)]\n\nfor i in range(1,N):\n\n    a = int(input()) - 1\n\n    won[a].append(i)\n\n\n\ndef height(v):\n\n    if not won[v]: return 0\n\n    hs = [height(op) for op in won[v]]\n\n    ret = 0\n\n    for i,h in enumerate(sorted(hs)):\n\n        ret = max(ret, h + len(hs) - i)\n\n    return ret\n\n\n\nprint((height(0)))"}
{"problem_id": "p02595", "input": "N, D = list(map(int, input().split()))\n\ncount = 0\n\nfor i in range(N):\n\n    a, b = list(map(int, input().split()))\n\n    if (a**2 + b**2) <= D**2:\n\n        count += 1\n\nprint(count)\n"}
{"problem_id": "p03309", "input": "# ABC102C - Linear Approximation (ARC100C)\n\nfrom statistics import median\n\n\n\n\n\ndef main():\n\n    n = int(input())\n\n    A = tuple(map(int, input().rstrip().split()))\n\n    A = tuple(j - i for i, j in enumerate(A, start=1))\n\n    b = median(A)\n\n    ans = sum(abs(a - b) for a in A)\n\n    print((int(ans)))\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()"}
{"problem_id": "p01105", "input": "a=65280; b=61680; c=52428; d=43690; e=65535\n\nL = {el: 1 for el in [a, b, c, d, e, 0]}\n\nfor i in range(6):\n\n    R = sorted(L.items(), key=lambda x: x[1])\n\n    for p, l in R:\n\n        if l < 16:\n\n            L[p ^ e] = min(L.get(p ^ e, 16), l+1)\n\n            if l+3 < 16:\n\n                for q, r in R:\n\n                    if l+r+3 <= 16:\n\n                        L[p & q] = min(L.get(p & q, 16), l+r+3)\n\n                        L[p ^ q] = min(L.get(p ^ q, 16), l+r+3)\n\n                    else: break\n\n        else: break\n\nprint(*(L[e & eval(s)] for s in open(0).read().replace(*\"-~\").replace(*\"*&\").replace(*\"1e\").split()[:-1]),sep='\\n')\n"}
{"problem_id": "p02792", "input": "#python3\n\nfrom collections import defaultdict\n\nfrom collections import namedtuple\n\n\n\nP = namedtuple('P', ['front', 'end'])\n\n\n\ndef f(x):\n\n    return P(str(x)[0], str(x)[-1]) \n\n\n\ndef main():\n\n\n\n    n = int(input())\n\n    freq = defaultdict(int)\n\n\n\n    for i in range(1, n+1):\n\n        p = f(i)\n\n        freq[p]+=1\n\n\n\n\n\n    ans = 0\n\n    for i in range(1, n + 1):\n\n        p = f(i)\n\n        q = (p.end, p.front)\n\n        ans += freq[q]\n\n\n\n    print(ans)\n\n\n\nmain()"}
{"problem_id": "p03038", "input": "n, m = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\nbc = [list(map(int, input().split())) for _ in range(m)]\n\n\n\nbc.sort(key=lambda x: x[1], reverse=True)\n\na.sort()\n\n\n\ni = 0\n\nfor b, c in bc:\n\n    for _ in range(b):\n\n        if i < n and a[i] < c:\n\n            a[i] = c\n\n            i += 1\n\n        else:\n\n            break\n\n\n\nans = sum(a)\n\nprint(ans)\n"}
{"problem_id": "p01138", "input": "def f(s):\n\n    s=list(map(int,s.split(':')))\n\n    return (s[0]*60+s[1])*60+s[2]\n\na=86401\n\nwhile 1:\n\n    t=[0]*a\n\n    n=int(input())\n\n    if n==0:break\n\n    for _ in range(n):\n\n        b,c=input().split()\n\n        t[f(b)]+=1;t[f(c)]-=1\n\n    d=0\n\n    for i in range(1,a):\n\n        t[i]+=t[i-1]\n\n        d=max(d,t[i])\n\n    print(d)"}
{"problem_id": "p03796", "input": "import math\n\nn = int(input())\n\nprint((math.factorial(n)%(10**9+7)))\n"}
{"problem_id": "p03107", "input": "S = list(input())\n\nnum_one = S.count(\"1\")\n\nnum_zero = S.count(\"0\")\n\nans = min(num_one, num_zero) *2\n\nprint(ans)\n"}
{"problem_id": "p03457", "input": "import sys\n\ncan = True; input()\n\ne = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]\n\nfor a, b in zip(e[1:], e):\n\n    t = a[0] - b[0] - abs(a[1] - b[1]) - abs(a[2] - b[2])\n\n    if t < 0 or t % 2 == 1: can = False; break\n\nprint((['No', 'Yes'][can]))"}
{"problem_id": "p02901", "input": "import sys\n\nreadline = sys.stdin.readline\n\n\n\nN,M = list(map(int,readline().split()))\n\nINF = 10 ** 10\n\ndp = [INF] * (2 ** N)\n\ndp[0] = 0\n\n\n\nfor i in range(M):\n\n  a,b = list(map(int,readline().split()))\n\n  c = list(map(int,readline().split()))\n\n  key = 0\n\n  for j in range(len(c)):\n\n    key += (1 << (c[j] - 1))\n\n  for j in range(len(dp)):\n\n    if dp[j] == INF:\n\n      continue\n\n    if j | key == j:\n\n      continue\n\n    dp[j | key] = min(dp[j | key], dp[j] + a)\n\n\n\nif dp[-1] == INF:\n\n  print((-1))\n\nelse:\n\n  print((dp[-1]))"}
{"problem_id": "p02721", "input": "N, K, C = list(map(int, input().split()))\n\nS = input()\n\n\n\nlatest = [None]*K\n\ni = len(S)+C\n\nfor j in range(K-1, -1, -1):\n\n  i = S.rindex(\"o\", 0, i-C)\n\n  latest[j] = i\n\n\n\nif i<=C or \"o\" not in S[:i-C]:\n\n  i = -C-1\n\n  for j in latest:\n\n    i = S.index(\"o\", i+C+1)\n\n    if i == j:\n\n      print((i+1))\n"}
{"problem_id": "p02688", "input": "N, K = list(map(int, input().split()))\n\nsunuke = [True]*N\n\nfor i in range(K):\n\n    d = int(input())\n\n    A = list(map(int, input().split()))\n\n    for a in A:\n\n        sunuke[a-1] = False\n\n\n\nans = 0\n\nfor i in range(N):\n\n    if sunuke[i]:\n\n        ans += 1\n\nprint(ans)"}
{"problem_id": "p03796", "input": "import sys\n\ndef input(): return sys.stdin.readline().strip()\n\n\n\ndef resolve():\n\n    import math\n\n    n=int(input())\n\n    print((math.factorial(n)%(10**9+7)))\n\nresolve()"}
{"problem_id": "p03416", "input": "A,B = list(map(int,input().split()))\n\nj = 0\n\nfor i in range(A,B+1):\n\n  l = list(str(i))\n\n  l_reverse = list(reversed(l))\n\n  if l == l_reverse:\n\n    j += 1\n\nprint(j)"}
{"problem_id": "p02390", "input": "s = int(input())\n\nm, s = s // 60, s % 60\n\nh, m = m // 60, m % 60\n\nprint((':'.join(map(str, [h,m,s]))))"}
{"problem_id": "p03796", "input": "import math\n\nN = int(input())\n\nprint((math.factorial(N)%(10**9+7)))"}
{"problem_id": "p03819", "input": "import sys\n\ninput = sys.stdin.readline\n\n\n\ndef main():\n\n  n, m = map(int, input().split())\n\n  LR = [list(map(int, input().split())) for _ in range(n)]\n\n  \n\n  BIT = [0]*(m+2)\n\n  def add(i, a):\n\n    while i <= m+1:\n\n      BIT[i] += a\n\n      i += i&(-i)\n\n  def bit_sum(i):\n\n    res = 0\n\n    while i > 0:\n\n      res += BIT[i]\n\n      i -= i&(-i)\n\n    return res\n\n  \n\n  S = sorted([(r-l+1, l, r) for l, r in LR], reverse=True)\n\n  cnt = n\n\n  L = []\n\n  for i in range(1, m+1):\n\n    while S and S[-1][0] == i:\n\n      c, l, r = S.pop()\n\n      cnt -= 1\n\n      add(l, 1)\n\n      add(r+1, -1)\n\n    res = cnt\n\n    for j in range(0, m+1, i):\n\n      res += bit_sum(j)\n\n    L.append(res)\n\n  print(*L, sep=\"\\n\")\n\n\n\nif __name__ == \"__main__\":\n\n  main()\n"}
{"problem_id": "p03126", "input": "import functools\n\nprint((len(functools.reduce(lambda x, y: x&y,[set(input().split()[1:]) for _ in [0]*int(input().split()[0])]))))"}
{"problem_id": "p03480", "input": "#!/usr/bin/env python3\n\n# coding=utf-8\n\n\n\nimport sys\n\n\n\ns = sys.stdin.readline().strip()\n\nl = [_s is \"1\" for _s in list(s)]\n\nl_r = l[::-1]\n\nindex = 0\n\nfor i, (c, n, c_r, n_r) in enumerate(\n\n        zip(l[:len(s) // 2], l[1:len(s) // 2 + 1], l_r[:len(s) // 2], l_r[1:len(s) // 2 + 1])):\n\n    if c ^ n or c_r ^ n_r:\n\n        index = i + 1\n\nprint((len(s) - index))"}
{"problem_id": "p03325", "input": "N = int(input())\n\nA = list(map(int,input().split()))\n\n\n\nSUM = 0\n\nfor i in A:\n\n    count = 0\n\n    while i%2 == 0:\n\n        i//=2\n\n        count += 1\n\n    SUM+=count\n\nprint(SUM)"}
{"problem_id": "p03796", "input": "n = int(input())\n\n\n\nINF = 10**9 + 7\n\n\n\nans = [0] * (10**5 + 1)\n\nans[0] = 1\n\n\n\nfor i in range(1,10**5 + 1):\n\n    ans[i] = ans[i-1] * i % INF\n\n\n\nprint((ans[n]))\n"}
{"problem_id": "p03371", "input": "a, b, c, x, y = list(map(int, input().split()))\n\nans = a * x + b * y\n\nm = max(x, y)\n\nfor i in range(1, m+1):\n\n  x -= 1\n\n  y -= 1\n\n  if x < 0:\n\n    x = 0\n\n  if y < 0:\n\n    y = 0\n\n  temp = c*(i*2) + x*a + y*b\n\n  if temp < ans:\n\n    ans = temp\n\n\n\nprint(ans)\n"}
{"problem_id": "p03798", "input": "n=int(input())\n\ns=input()\n\nx=[\"SS\",\"SW\",\"WS\",\"WW\"]\n\n\n\ndef check0(i):\n\n    if x[i][0]==\"S\":\n\n        if s[0]==\"o\":\n\n            if x[i][-1]==\"S\":\n\n                return x[i][1]==\"S\"\n\n            else:\n\n                return x[i][1]==\"W\"\n\n        else:\n\n            if x[i][-1]==\"S\":\n\n                return x[i][1]==\"W\"\n\n            else:\n\n                return x[i][1]==\"S\"\n\n    else:\n\n        if s[0]==\"o\":\n\n            if x[i][-1]==\"S\":\n\n                return x[i][1]==\"W\"\n\n            else:\n\n                return x[i][1]==\"S\"\n\n        else:\n\n            if x[i][-1]==\"S\":\n\n                return x[i][1]==\"S\"\n\n            else:\n\n                return x[i][1]==\"W\"\n\ndef check1(i):\n\n    if x[i][n-1]==\"S\":\n\n        if s[n-1]==\"o\":\n\n            if x[i][n-2]==\"S\":\n\n                return x[i][0]==\"S\"\n\n            else:\n\n                return x[i][0]==\"W\"\n\n        else:\n\n            if x[i][n-2]==\"S\":\n\n                return x[i][0]==\"W\"\n\n            else:\n\n                return x[i][0]==\"S\"\n\n    else:\n\n        if s[n-1]==\"o\":\n\n            if x[i][n-2]==\"S\":\n\n                return x[i][0]==\"W\"\n\n            else:\n\n                return x[i][0]==\"S\"\n\n        else:\n\n            if x[i][n-2]==\"S\":\n\n                return x[i][0]==\"S\"\n\n            else:\n\n                return x[i][0]==\"W\"\n\n\n\n\n\nfor i in range(4):\n\n    for j in range(n-2):\n\n        if x[i][j+1]==\"S\":\n\n            if s[j+1]==\"o\":\n\n                if x[i][j]==\"S\":\n\n                    x[i]+=\"S\"\n\n                else:\n\n                    x[i]+=\"W\"\n\n            else:\n\n                if x[i][j]==\"S\":\n\n                    x[i]+=\"W\"\n\n                else:\n\n                    x[i]+=\"S\"\n\n        else:\n\n            if s[j+1]==\"o\":\n\n                if x[i][j]==\"S\":\n\n                    x[i]+=\"W\"\n\n                else:\n\n                    x[i]+=\"S\"\n\n            else:\n\n                if x[i][j]==\"S\":\n\n                    x[i]+=\"S\"\n\n                else:\n\n                    x[i]+=\"W\"\n\n    #print(x[i])\n\n    if check0(i) and check1(i):\n\n        print((x[i]))\n\n        break\n\nelse:\n\n    print((-1))\n"}
{"problem_id": "p03162", "input": "# coding: utf-8\n\n\n\nimport sys\n\ninput = sys.stdin.readline\n\n\n\ndef f(n, abc):\n\n    dp = [[0] * 3 for _ in range(n + 1)]\n\n    for i in range(1, n + 1):\n\n        for j in range(3):\n\n            dp[i][j] = max(dp[i - 1][k] + abc[i - 1][j] \\\n\n                for k in range(3) if k != j)\n\n    return(max(dp[n]))\n\n\n\nn = int(input())    # 1 <= n <= 10^5\n\nabc = [list(map(int, input().rstrip().split())) for _ in range(n)]\n\n\n\nprint((f(n, abc)))\n"}
{"problem_id": "p02595", "input": "N, D = list(map(int, input().split()))\n\npoint = []\n\nfor i in range(N):\n\n    point.append(list(map(int, input().split())))\n\n\n\nct = 0\n\nD2 = D * D\n\nfor i in point:\n\n    if (i[0]**2 + i[1]**2) <= D2:\n\n        ct += 1\n\n\n\nprint(ct)"}
{"problem_id": "p03796", "input": "from math import factorial\n\n\n\nmod = 10**9 + 7\n\nn = int(input())\n\n\n\nans = factorial(n) % mod\n\nprint(ans)"}
{"problem_id": "p03078", "input": "import heapq\n\n\n\nx, y, z, k = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\nb = list(map(int, input().split()))\n\nc = list(map(int, input().split()))\n\n\n\ndef diff(l):\n\n    m = max(l)\n\n    return sorted(m - v for v in l)[1:]\n\n\n\ns = sum(map(max, [a, b, c]))\n\nsa, sb, sc = list(map(diff, [a, b, c]))\n\nda, db, dc = [0], [0], [0]\n\nq = [0]\n\nwhile k > 0:\n\n    while True:\n\n        if len(sa) > 0 and (len(q) == 0 or q[0] > sa[0]):\n\n            for v in [sa[0] + bb + cc for bb in db for cc in dc]:\n\n                heapq.heappush(q, v)\n\n            da.append(sa[0])\n\n            sa = sa[1:]\n\n        elif len(sb) > 0 and (len(q) == 0 or q[0] > sb[0]):\n\n            for v in [sb[0] + aa + cc for aa in da for cc in dc]:\n\n                heapq.heappush(q, v)\n\n            db.append(sb[0])\n\n            sb = sb[1:]\n\n        elif len(sc) > 0 and (len(q) == 0 or q[0] > sc[0]):\n\n            for v in [sc[0] + aa + bb for aa in da for bb in db]:\n\n                heapq.heappush(q, v)\n\n            dc.append(sc[0])\n\n            sc = sc[1:]\n\n        else:\n\n            break\n\n    v = heapq.heappop(q)\n\n    print(s - v)\n\n    k -= 1\n"}
{"problem_id": "p02837", "input": "N = int(input())\n\nA = [0]*N\n\nX = []\n\nY = []\n\nfor i in range(N):\n\n    A[i] = int(input())\n\n    X.append([])\n\n    Y.append([])\n\n    for j in range(A[i]):\n\n        x, y = list(map(int, input().split()))\n\n        X[i].append(x-1)\n\n        Y[i].append(y)\n\nans = 0\n\nfor bit in range(1<<N):\n\n    honest = 0\n\n    ok = True\n\n    for i in range(N):\n\n        if bit&(1<<i):\n\n            honest += 1\n\n            for j in range(A[i]):\n\n                if Y[i][j] == 0:\n\n                    if bit&(1<<X[i][j]):\n\n                        ok = False\n\n                        break\n\n                else:\n\n                    if not bit&(1<<X[i][j]):\n\n                        ok = False\n\n                        break\n\n            if not ok:\n\n                break\n\n    if ok:\n\n        ans = max(ans, honest)\n\nprint(ans)"}
{"problem_id": "p02773", "input": "from collections import Counter\n\nimport sys\n\ninput = sys.stdin.readline\n\n\n\ndef solve():\n\n    N = int(input())\n\n    Sss = [input().rstrip() for _ in range(N)]\n\n\n\n    cnt = Counter(Sss)\n\n    #print('cnt:', cnt)\n\n\n\n    maxNum = max(cnt.values())\n\n    #print('maxNum:', maxNum)\n\n\n\n    anss = []\n\n    for key, value in list(cnt.items()):\n\n        if value == maxNum:\n\n            anss.append(key)\n\n    #print('anss:', anss)\n\n\n\n    anss.sort()\n\n\n\n    print(('\\n'.join(anss)))\n\n\n\n\n\nsolve()\n"}
{"problem_id": "p02278", "input": "\"\"\"Minimum cost Sort.\"\"\"\n\n\n\ndef min_cost_sort(A):\n\n    \"\"\"Sort list A in ascending order.\n\n \n\n    And return the switching cost in sorting.\n\n    \"\"\"\n\n    B = list(A)\n\n    B.sort()\n\n    cost = 0\n\n    min_w = B[0]\n\n    for i, b in enumerate(B):\n\n        tmp_cost = 0\n\n        bi = A.index(b)\n\n        n = 1\n\n        while bi != i:\n\n            n += 1\n\n            st = B[bi]\n\n            si = A.index(st)\n\n            tmp_cost += b + st\n\n            A[bi], A[si] = st, b\n\n            bi = si\n\n        dec = (n - 1) * (b - min_w)\n\n        inc = 2 * (min_w + b)\n\n        if dec < inc:\n\n            cost += tmp_cost\n\n        else:\n\n            cost += tmp_cost - dec + inc\n\n    return cost\n\n\n\n\n\nn = input()\n\n\n\nA = list(map(int, input().split()))\n\n\n\nans = min_cost_sort(A)\n\n\n\nprint(ans)"}
{"problem_id": "p02555", "input": "from functools import lru_cache\n\nimport sys\n\n\n\nsys.setrecursionlimit(2000)\n\n\n\ns = int(input())\n\nmod = 10 ** 9 + 7\n\n\n\n\n\n@lru_cache(maxsize=None)\n\ndef dfs(n):\n\n    if n <= 2:\n\n        return 0\n\n    elif 3<=n<=5:\n\n        return 1\n\n    else:\n\n        count = 1\n\n        for i in range(3, n + 1):\n\n            count += dfs(n - i)\n\n            count %= mod\n\n\n\n        return count % mod\n\n\n\n\n\nans = dfs(s)\n\nprint(ans)\n"}
{"problem_id": "p03721", "input": "n,k = list(map(int,input().split()))\n\nnum = 0\n\nq = []\n\nfor i in range(n):\n\n    a,b = list(map(int,input().split()))\n\n    q.append((a,b))\n\nq.sort()\n\nfor i in range(n):\n\n    a, b = q[i][0], q[i][1]\n\n    num += b\n\n    if num >= k:\n\n        print(a)\n\n        exit()\n\n\n"}
{"problem_id": "p03197", "input": "import sys\n\ninput = sys.stdin.readline\n\nfrom collections import *\n\n\n\ndef dfs(x, y):\n\n    if x==0 and y==0:\n\n        t[x][y] = False\n\n        return False\n\n    \n\n    if x>=1:\n\n        t[x][y] |= not dfs(x-1, y)\n\n        \n\n    if y>=1:\n\n        t[x][y] |= not dfs(x, y-1)\n\n        \n\n    if min(x, y)>=1:\n\n        t[x][y] |= not dfs(x-1, y-1)\n\n   \n\n    return t[x][y]\n\n    \n\nt = [[False]*7 for _ in range(7)]\n\n\n\nfor i in range(7):\n\n    for j in range(7):\n\n        dfs(i, j)\n\n\n\n\"\"\"\n\nfor ti in t:\n\n    print(*ti)\n\n\"\"\"\n\n\n\nN = int(input())\n\nflag = True\n\n\n\nfor _ in range(N):\n\n    a = int(input())\n\n    \n\n    if a%2==1:\n\n        flag = False\n\n        \n\nif flag:\n\n    print('second')\n\nelse:\n\n    print('first')"}
{"problem_id": "p03416", "input": "a,b=list(map(int, input().split()))\n\ncnt=0\n\nfor i in range(a,b+1):\n\n    n=list(str(i))\n\n    if n==list(reversed(n)):\n\n        cnt+=1\n\nprint(cnt)"}
{"problem_id": "p03416", "input": "a, b = list(map(int, input().strip().split(\" \")))\n\ncount = 0\n\nfor i in range(a, b + 1):\n\n    if str(i) == str(i)[::-1]:\n\n        count += 1\n\nprint(count)\n"}
{"problem_id": "p03796", "input": "import math\n\nN = int(input())\n\np = math.factorial(N)\n\nprint((p % 1000000007))"}
{"problem_id": "p02891", "input": "import sys\n\ninput = sys.stdin.readline\n\n \n\ns = input().rstrip()\n\nk = int(input())\n\n    \n\ndef check_count(s):\n\n    cnt_list = [1]\n\n    cnt = 1\n\n    for i in range(1, len(s)):\n\n        if s[i-1] == s[i]:\n\n            cnt_list[-1] += 1\n\n        else:\n\n            cnt_list.append(1)\n\n    return cnt_list\n\n\n\ndef calc_ans(cnt_list, k):\n\n    _ans = 0\n\n    for c in cnt_list:\n\n        _ans += c//2\n\n    return(_ans * k)\n\n\n\nif len(s)==1:\n\n    ans = k//2\n\nelse:\n\n    cnt_list = check_count(s)\n\n    if len(cnt_list)==1:\n\n        ans = (len(s)*k)//2\n\n    else:\n\n        ans = calc_ans(cnt_list, k)\n\n        if s[0]==s[-1]:\n\n            if cnt_list[0]%2==1 and cnt_list[-1]%2==1:\n\n                ans += k - 1\n\n\n\nprint(ans)"}
{"problem_id": "p02881", "input": "N = int(input())\n\n\n\n\n\ndef dist(i, j):\n\n    return i + j - 2\n\n\n\n\n\nmin = 10 ** 24\n\ni = 1\n\nwhile (i ** 2) <= N:\n\n    if 0 == N % i:\n\n        j = N // i\n\n        d = dist(i, j)\n\n        if min > d:\n\n            min = d\n\n    i += 1\n\nprint(d)\n"}
{"problem_id": "p02552", "input": "n = int(input())\n\nprint((1 if n == 0 else 0))\n"}
{"problem_id": "p03039", "input": "import sys\n\nreadline = sys.stdin.readline\n\nsys.setrecursionlimit(10**8)\n\nmod = 10**9+7\n\n#mod = 998244353\n\nINF = 10**18\n\neps = 10**-7\n\n\n\nm,n,k = list(map(int,readline().split()))\n\n\n\ndef comb(n, r, mod):\n\n    r = min(r, n-r)\n\n    mol = 1\n\n    deno = 1\n\n    for i in range(1, r+1):\n\n        mol = mol * (n-r+i) % mod\n\n        deno = deno * i % mod\n\n    ret = mol * pow(deno, mod-2, mod) % mod\n\n    return ret\n\n\n\ndef f1(x,y,a,b):\n\n    return (a+b-x-y)*(a-x+1)*(b-y+1)//2\n\n\n\ndef f2(x,a):\n\n    return (a-x)*(a-x+1)//2\n\n\n\nans = 0\n\n\n\nfor x in range(1,n+1):\n\n    for y in range(1,m+1):\n\n        ans += f1(x,y,n,m)+f1(1,1,x,y)+f1(1,y,x,m)+f1(x,1,n,y)\n\n        ans -= f2(x,n) + f2(1,x) + f2(1,y) + f2(y,m)\n\n        ans %= mod\n\n\n\nans = (ans * comb(m*n-2,k-2,mod))%mod\n\nans = ans*pow(2,mod-2,mod)%mod\n\n\n\nprint(ans)\n"}
{"problem_id": "p03013", "input": "import sys\n\nsys.setrecursionlimit(10**7)\n\ndef lmi(): return list(map(int, input().split()))\n\n\n\nn, m = lmi()\n\n\n\nl = [0] * (n+1)\n\nl[0] = 1\n\n\n\na = 0\n\nif m != 0:\n\n    a = int(input())\n\nk = 1\n\nfor i in range(n+1):\n\n\n\n    if i != a:\n\n        if i == 1:\n\n            l[i] = 1\n\n        elif i >= 2:\n\n            l[i] = l[i-1] + l[i-2]\n\n            l[i] %= 1000000007\n\n    else:\n\n        k += 1\n\n        if k <= m:\n\n            a = int(input())\n\n\n\n\n\n\n\n#print(l)\n\nprint((l[n] % 1000000007))\n"}
{"problem_id": "p03013", "input": "N,M = list(map(int,input().split()))\n\nMOD = 10**9+7\n\ndp = [0]*(N+1)\n\ndp[0]=1\n\nA = [int(input()) for i in range(M)]\n\nban = [1]*(N+1)\n\nfor a in A:\n\n    ban[a]=0\n\nfor i in range(N):\n\n    if i-1>=0:\n\n        dp[i+1]=dp[i]*ban[i]+dp[i-1]*ban[i-1]\n\n    else:\n\n        dp[i+1]=dp[i]*ban[i]\n\n    dp[i+1] %= MOD \n\nprint((dp[N]))"}
{"problem_id": "p03371", "input": "def main():\n\n    A, B, AB, X, Y = list(map(int, input().split()))\n\n    M = max(X, Y)\n\n\n\n    k = 0\n\n    ans = A * X + B * Y\n\n    while True:\n\n        ans = min(\n\n            ans,\n\n            AB * k * 2 + max(0, X - k) * A + max(0, Y - k) * B\n\n        )\n\n\n\n        if k >= M: break\n\n        k += 1\n\n\n\n    print(ans)\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p02245", "input": "import sys\n\n\n\ninit = ''.join(sys.stdin.read().split())\n\n\n\n# Bidirectional search using breadth-first search\n\ndef solve(start, goal):\n\n    if start == goal:\n\n        return 0\n\n    generated_state = {start: 0, goal: 1}   # 0: foreward, 1: backward\n\n    step = {start: 0, goal: 0}\n\n    s = 0\n\n    c_d = [(start, 0), (goal, 1)] # configure and direction\n\n    while True:\n\n        q = iter(c_d)\n\n        c_d = []\n\n        s += 1\n\n        for c, d in q:\n\n            i = c.find('0')\n\n            if 0 <= i <= 5:\n\n                t = str.maketrans('0' + c[i+3], c[i+3] + '0')\n\n                t_c = c.translate(t)\n\n                if t_c in generated_state:\n\n                    if generated_state[t_c] != d:\n\n                        return s + step[t_c]\n\n                else:\n\n                    generated_state[t_c] = d\n\n                    step[t_c] = s\n\n                    c_d.append((t_c, d))\n\n            if i >= 3:\n\n                t = str.maketrans('0' + c[i-3], c[i-3] + '0')\n\n                t_c = c.translate(t)\n\n                if t_c in generated_state:\n\n                    if generated_state[t_c] != d:\n\n                        return s + step[t_c]\n\n                else:\n\n                    generated_state[t_c] = d\n\n                    step[t_c] = s\n\n                    c_d.append((t_c, d))\n\n            if i == 0 or i == 1 or i == 3 or i == 4 or i == 6 or i == 7:\n\n                t = str.maketrans('0' + c[i+1], c[i+1] + '0')\n\n                t_c = c.translate(t)\n\n                if t_c in generated_state:\n\n                    if generated_state[t_c] != d:\n\n                        return s + step[t_c]\n\n                else:\n\n                    generated_state[t_c] = d\n\n                    step[t_c] = s\n\n                    c_d.append((t_c, d))\n\n            if i == 1 or i == 2 or i == 4 or i == 5 or i == 7 or i == 8:\n\n                t = str.maketrans('0' + c[i-1], c[i-1] + '0')\n\n                t_c = c.translate(t)\n\n                if t_c in generated_state:\n\n                    if generated_state[t_c] != d:\n\n                        return s + step[t_c]\n\n                else:\n\n                    generated_state[t_c] = d\n\n                    step[t_c] = s\n\n                    c_d.append((t_c, d))\n\n\n\nprint((solve(init, '123456780')))"}
{"problem_id": "p02837", "input": "def popcount(x):\n\n  r, q = 0, x\n\n  while x:\n\n    r += 1\n\n    x &= x - 1\n\n  return r, q\n\n \n\nn = int(input())\n\nr = list(range(n))\n\na = [[0, 0] for _ in r]\n\nfor i in r:\n\n  for _ in range(int(input())):\n\n    x, y = list(map(int, input().split()))\n\n    a[i][y] |= 1 << (x - 1)\n\nl = (1 << n) - 1 \n\nb = sorted(map(popcount, list(range(1, l + 1))))\n\nans = next((i for i, x in reversed(b)\n\n           if all(a[j][0] & x == a[j][1] & l - x == 0 for j in r if x >> j & 1)), 0)\n\nprint(ans)\n"}
{"problem_id": "p03634", "input": "import queue\n\nn = int(input())\n\n\n\nabc = [[] for i in range(n+1)]\n\n\n\nfor i in range(n-1):\n\n    a,b,c = list(map(int,input().split()))\n\n    abc[a].append([b,c])\n\n    abc[b].append([a,c])\n\n\n\nQ,k = list(map(int,input().split()))\n\nxy = [[int(i) for i in input().split()] for j in range(Q)]\n\n\n\nq = queue.Queue()\n\n\n\nq.put(k)\n\n\n\npath = [-1]*(n+1)\n\npath[k] = 0\n\n\n\nwhile not q.empty():\n\n    tmp = q.get()\n\n    for i in range(len(abc[tmp])):\n\n        #print(abc[tmp])\n\n        #exit()\n\n        num = abc[tmp][i][0]\n\n        if path[num] != -1:\n\n            continue\n\n        else:\n\n            path[num] = path[tmp] + abc[tmp][i][1]\n\n            q.put(num)\n\n            \n\nfor i in range(Q):\n\n    print((path[xy[i][0]]+path[xy[i][1]]))"}
{"problem_id": "p02394", "input": "W,H,x,y,r = [int(i) for i in input().split()]\n\nif x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H:\n\n    print(\"Yes\")\n\nelse:\n\n    print(\"No\")"}
{"problem_id": "p03325", "input": "from math import log2\n\nn = int(input())\n\na = list(map(int, input().split()))\n\nans = 0\n\n\n\nfor _a in a:\n\n    if _a%2 == 0:\n\n        cnt =0\n\n        while _a%2 == 0:\n\n            _a //= 2\n\n            cnt += 1\n\n        ans += cnt\n\n\n\nprint((int(ans)))"}
{"problem_id": "p02685", "input": "# coding: utf-8\n\n\n\n\n\ndef solve(*args: str) -> str:\n\n    n, m, k = list(map(int, args[0].split()))\n\n    mod = 998244353\n\n\n\n    if m == 1 and n-1 == k:\n\n        return str(1)\n\n\n\n    ncr = 1\n\n    p = m*pow(m-1, n-1, mod) % mod\n\n    ret = p\n\n    inv = pow(m-1, mod-2, mod)\n\n    for i in range(1, k+1):\n\n        ncr = (ncr * (n-i)*pow(i, mod-2, mod)) % mod\n\n        p = (p*inv) % mod\n\n        ret += p*ncr % mod\n\n\n\n    return str(ret % mod)\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    print((solve(*(open(0).read().splitlines()))))\n"}
{"problem_id": "p03828", "input": "import collections as col\n\n\n\ndef prime(n):\n\n    ans = []\n\n    num = n\n\n    for i in range(2,n+1):\n\n        if i%2==0 and i!=2: continue\n\n        while num%i == 0: num //= i ; ans.append(i)\n\n    return ans\n\n\n\nn = int(input())\n\nmod = 10**9 + 7\n\n\n\nprimes = []\n\nfor i in range(2,n+1): primes += prime(i)\n\n\n\ncnt = col.Counter(primes)\n\nans = 1\n\nfor key,val in list(cnt.items()): ans *= (val + 1) ; ans %= mod\n\nprint(ans)\n"}
{"problem_id": "p02794", "input": "import sys\n\ndef main():\n\n    input = sys.stdin.readline\n\n    N = int(input())\n\n    E = [[] for _ in range(N)]\n\n    for i in range(N-1):\n\n        a, b = list(map(int, input().split()))\n\n        a, b = a-1, b-1\n\n        E[a].append((b,i))\n\n        E[b].append((a,i))\n\n    \n\n    def dfs(s, g):\n\n        par = [(-1,-1)] * N\n\n        par[s] = (s,-1)\n\n        stack = [s]\n\n        while stack:\n\n            v = stack.pop()\n\n            for to, i in E[v]:\n\n                if par[to][0] >= 0: continue\n\n                par[to] = (v, i)\n\n                if to == g: break\n\n                stack.append(to)\n\n        r = set()\n\n        v = g\n\n        while v != s:\n\n            v, i = par[v]\n\n            r.add(i)\n\n        return r\n\n    \n\n    M = int(input())\n\n    path = [None] * M\n\n    for i in range(M):\n\n        u, v = list(map(int, input().split()))\n\n        u, v = u-1, v-1\n\n        path[i] = dfs(u, v)\n\n\n\n    def calc(s): return 1<<(N-1-len(s))\n\n\n\n    i_ans = 0\n\n    for p in range(1, 1<<M):\n\n        is_odd = bin(p).count('1') & 1\n\n        s = set()\n\n        for i in range(M):\n\n            if p&1: s |= path[i]\n\n            p >>= 1\n\n        if is_odd: i_ans += calc(s)\n\n        else: i_ans -= calc(s)\n\n\n\n    print(((1<<(N-1)) - i_ans))\n\n\n\nif __name__ == '__main__':\n\n    main()"}
{"problem_id": "p02612", "input": "'''\n\n    Auther: ghoshashis545 Ashis Ghosh\n\n    College: jalpaiguri Govt Enggineering College\n\n\n\n'''\n\nfrom os import path\n\nimport sys\n\nfrom functools import cmp_to_key as ctk\n\nfrom collections import deque,defaultdict as dd \n\nfrom bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right\n\nfrom itertools import permutations\n\nfrom datetime import datetime\n\nfrom math import ceil,sqrt,log,gcd\n\ndef ii():return int(input())\n\ndef si():return input()\n\ndef mi():return list(map(int,input().split()))\n\ndef li():return list(mi())\n\nabc='abcdefghijklmnopqrstuvwxyz'\n\nmod=1000000007\n\n#mod=998244353\n\ninf = float(\"inf\")\n\nvow=['a','e','i','o','u']\n\ndx,dy=[-1,1,0,0],[0,0,1,-1]\n\n\n\ndef bo(i):\n\n    return ord(i)-ord('a')\n\n\n\nfile = 0\n\n\n\ndef solve():\n\n    \n\n\n\n\n\n\n\n    # for _ in range(ii()):\n\n\n\n    n=ii()\n\n    n%=1000\n\n    if n!=0:\n\n        n=1000-n\n\n    print(n)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nif __name__ ==\"__main__\":\n\n\n\n    if(file):\n\n\n\n        if path.exists('input1.txt'):\n\n            sys.stdin=open('input1.txt', 'r')\n\n            sys.stdout=open('output1.txt','w')\n\n        else:\n\n            input=sys.stdin.readline\n\n    solve()"}
{"problem_id": "p02685", "input": "M=998244353\n\nn,m,k=list(map(int,input().split()))\n\na=0\n\nc=1\n\nfor i in range(k+1):\n\n  a+=c*m*pow(m-1,n-i-1,M)\n\n  c=c*(n-i-1)*pow(i+1,M-2,M)%M\n\nprint((a%M))"}
{"problem_id": "p03680", "input": "N = int(input())\n\na = [int(input()) for _ in range(N)]\n\n\n\ncnt, i = 0, 0\n\nfor j in range(10 ** 6):\n\n    cnt += 1\n\n    if a[i] == 2:\n\n        print(cnt)\n\n        #break\n\n        quit()\n\n    else:\n\n        i = a[i] - 1\n\nprint((-1))"}
{"problem_id": "p02555", "input": "import math\n\n\n\n\n\ndef combinations_count(n, r):\n\n    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\n\n\n\n\ndef combinations_with_replacement_count(n, r):\n\n    return combinations_count(n + r - 1, r)\n\n\n\n\n\ndef main():\n\n    s = int(input())\n\n    ans = 0\n\n    n = s // 3\n\n\n\n    for i in range(1, n + 1):\n\n        ans += combinations_with_replacement_count(i, 3*(n-i)+s % 3)\n\n\n\n    print((ans % (10**9 + 7)))\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03806", "input": "G_MAX = 40*10\n\nN_MAX = 40\n\nINF = float('inf')\n\n\n\ndp = [[[INF]*(G_MAX+1) for _ in range(G_MAX+1)] \n\n      for _ in range(N_MAX+1)]\n\nN,Ma,Mb = list(map(int, input().split()))\n\na,b,c = [],[],[]\n\nfor _ in range(N):\n\n    ai,bi,ci = list(map(int, input().split()))\n\n    a.append(ai)\n\n    b.append(bi)\n\n    c.append(ci)\n\n\n\ndp[0][0][0] = 0\n\nfrom math import isinf\n\nfor i in range(N):\n\n    for ca in range(G_MAX+1):\n\n        for cb in range(G_MAX+1):\n\n            if isinf(dp[i][ca][cb]): continue\n\n            dp[i+1][ca][cb] = min(dp[i+1][ca][cb],\n\n                                 dp[i][ca][cb])\n\n            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]],\n\n                                           dp[i][ca][cb]+c[i])\n\n            \n\n    \n\nans = INF\n\nfor ca in range(1,G_MAX+1):\n\n    for cb in range(1,G_MAX+1):\n\n        if ca*Mb==cb*Ma:\n\n            ans = min(ans, dp[N][ca][cb])\n\n            \n\nif isinf(ans): ans = -1\n\nprint(ans)"}
{"problem_id": "p03568", "input": "from itertools import product\n\n\n\nn = int(input())\n\nA = list(map(int, input().split()))\n\n\n\ncount = 0\n\nfor C in product((-1, 0, 1), repeat=n):\n\n  total = 1\n\n  for a, c in zip(A, C):\n\n    total *= (a + c)\n\n  if total % 2 == 0:\n\n    count += 1\n\nprint(count)"}
{"problem_id": "p03164", "input": "import sys\n\nsys.setrecursionlimit(2147483647)\n\nINF=float(\"inf\")\n\nMOD=10**9+7\n\ninput=lambda :sys.stdin.readline().rstrip()\n\ndef resolve():\n\n    n,W=list(map(int,input().split()))\n\n    WV=[tuple(map(int,input().split())) for _ in range(n)]\n\n\n\n    V=100000\n\n    dp=[INF]*(V+1)\n\n    dp[0]=0\n\n\n\n    for w,v in WV:\n\n        for x in range(V,-1,-1):\n\n            if(x+v<=V):\n\n                dp[x+v]=min(dp[x+v],dp[x]+w)\n\n\n\n    for x in range(V,-1,-1):\n\n        if(dp[x]<=W):\n\n            print(x)\n\n            return\n\nresolve()"}
{"problem_id": "p02691", "input": "from collections import defaultdict\n\n\n\n\n\ndef main():\n\n    _ = int(input())\n\n    heights = list(map(int, input().split()))\n\n\n\n    \"\"\"\n\n    for j>i, j-i = Ai + Aj\n\n    i + Ai = j -Aj\n\n    \"\"\"\n\n\n\n    L = defaultdict(int)\n\n    R = defaultdict(int)\n\n\n\n    for i, height in enumerate(heights):\n\n        L[i + height] += 1\n\n        R[i - height] += 1\n\n\n\n    total_count = 0\n\n    for x, count_l in list(L.items()):\n\n        if x in R:\n\n            count_r = R[x]\n\n            total_count += count_l * count_r\n\n\n\n    print(total_count)\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()\n"}
{"problem_id": "p03039", "input": "import sys\n\nreadline = sys.stdin.readline\n\nsys.setrecursionlimit(10**8)\n\nmod = 10**9+7\n\n#mod = 998244353\n\nINF = 10**18\n\neps = 10**-7\n\n\n\nm,n,k = list(map(int,readline().split()))\n\n\n\ndef comb(n, r, mod):\n\n    r = min(r, n-r)\n\n    mol = 1\n\n    deno = 1\n\n    for i in range(1, r+1):\n\n        mol = mol * (n-r+i) % mod\n\n        deno = deno * i % mod\n\n    ret = mol * pow(deno, mod-2, mod) % mod\n\n    return ret\n\n\n\ndef f1(x,y,a,b):\n\n    return (a+b-x-y)*(a-x+1)*(b-y+1)//2\n\n\n\ndef f2(x,a):\n\n    return (a-x)*(a-x+1)//2\n\n\n\nans = 0\n\n\n\nfor x in range(1,n+1):\n\n    for y in range(1,m+1):\n\n        a = n-x+1\n\n        b = m-y+1\n\n        c = m*(a*(a-1)+x*(x-1))\n\n        d = n*(b*(b-1)+y*(y-1))\n\n        ans += (c+d)//2\n\n        ans %= mod\n\n\n\nans = (ans * comb(m*n-2,k-2,mod))%mod\n\nans = ans*pow(2,mod-2,mod)%mod\n\n\n\nprint(ans)\n\n\n"}
{"problem_id": "p03253", "input": "N,M = list(map(int,input().split()))\n\ndiv =[]\n\nfor i in range(2,int(M**(1/2))+2):\n\n    cur = 0\n\n    while M%i==0:\n\n        M = M//i\n\n        cur += 1\n\n    if cur >=1:\n\n        div.append(cur)\n\nif M>1: div.append(1)\n\ndiv.sort()\n\nmod = 10**9+7\n\nfrac = [1]*(N+50)\n\nnum = len(frac)\n\nfor i in range(len(frac)-1):\n\n    frac[i+1] = frac[i]*(i+1)%mod\n\nfinv = [1] * (N+50)\n\nfinv[-1] = pow(frac[-1], mod-2, mod)\n\nfor i in range(1, num):\n\n  finv[num-1-i] = finv[num-i] * (num-i) % mod\n\nans = 1\n\nfor i in div:\n\n    ans = ans * frac[N+i-1]*finv[N-1]*finv[i]%mod\n\nprint(ans)"}
{"problem_id": "p03371", "input": "a, b, c, x, y = list(map(int, input().split()))\n\n# print(a, b, c, x, y)\n\n\n\nans = 10000 * (10 **5) + 7\n\nc_max = 0\n\nif x > y:\n\n  c_max = x * 2\n\nelse:\n\n  c_max = y * 2\n\n\n\nfor cc in range(c_max+1):\n\n  ac = x - (cc // 2)\n\n  bc = y - (cc // 2)\n\n  \n\n  if ac < 0:\n\n    ac = 0\n\n  if bc < 0:\n\n    bc = 0\n\n  price = ac * a + bc * b + cc * c\n\n  # print('price: {}, ac: {}, bc: {}, cc: {}'.format(price, ac, bc, cc))\n\n  ans = min(ans, price)\n\n\n\nprint(ans)"}
{"problem_id": "p03425", "input": "N = int(input())\n\nname = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}\n\nmarch = \"MARCH\"\n\nfor _ in range(N):\n\n  S = input()\n\n  if(S[0] in name):\n\n    name[S[0]] += 1\n\nans = 0\n\nfor i in range(3):\n\n  for j in range(i+1,4):\n\n    for k in range(j+1,5):\n\n      ans += name[march[i]] * name[march[j]] * name[march[k]]\n\nprint(ans)"}
{"problem_id": "p02899", "input": "n = int(input())\n\na = list(map(int,input().split()))\n\nans = [i for i in range(n)]\n\na1 = sorted(a)\n\nfor i in range(n):\n\n    num = a[i]\n\n    ans[num - 1] = str(i + 1)\n\n    \n\nprint((' '.join(ans)))"}
{"problem_id": "p02901", "input": "INF = 2*10**7\n\n\n\n\n\ndef main():\n\n    N, M = (int(i) for i in input().split())\n\n    A = []\n\n    B = []\n\n    C = []\n\n    for _ in range(M):\n\n        a, b = (int(i) for i in input().split())\n\n        A.append(a)\n\n        B.append(b)\n\n        bit = 0\n\n        for i in input().split():\n\n            bit |= (1 << (int(i)-1))\n\n        C.append(bit)\n\n    dp = [[INF]*(1 << N) for _ in range(M+1)]\n\n    dp[0][0] = 0\n\n    for i in range(M):\n\n        for j in range(1 << N):\n\n            dp[i+1][j] = min(dp[i+1][j], dp[i][j])\n\n            if dp[i][j] != INF:\n\n                next_bit = j | C[i]\n\n                dp[i+1][next_bit] = min(dp[i+1][next_bit], dp[i][j] + A[i])\n\n    ans = dp[-1][-1]\n\n    if ans == INF:\n\n        print((-1))\n\n    else:\n\n        print(ans)\n\n    # print(*dp, sep=\"\\n\")\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03253", "input": "def prime_factorize(num):\n\n    \"\"\"\n\n    This function performs prime factorization on the input natural number.\n\n    The result is returned in the form of a dictionary with the prime number as the key\n\n    and its number as the value.\n\n    :param num:\n\n    :return prime_factor: Dictionary with the prime number as the key and its number as the value.\n\n    \"\"\"\n\n    prime_factor = {}\n\n    i = 2\n\n    while i ** 2 <= num:\n\n        while num % i == 0:\n\n            num //= i\n\n            if i in list(prime_factor.keys()):\n\n                prime_factor[i] += 1\n\n            else:\n\n                prime_factor[i] = 1\n\n        i += 1\n\n    if num > 1:\n\n        prime_factor[num] = 1\n\n    return prime_factor\n\n\n\n\n\nfrom math import factorial\n\n\n\n\n\ndef comb(n, r, R):\n\n    if n not in R:\n\n        a = factorial(n)\n\n        R[n] = a\n\n    else:\n\n        a = R[n]\n\n\n\n    if n - r not in R:\n\n        b = factorial(n - r)\n\n        R[n - r] = b\n\n    else:\n\n        b = R[n - r]\n\n\n\n    if r not in R:\n\n        c = factorial(r)\n\n        R[r] = c\n\n    else:\n\n        c = R[r]\n\n    return a // (b * c)\n\n\n\n\n\nn, m = list(map(int, input().split()))\n\nr = 1\n\n\n\nR = dict()\n\nprime_fac = prime_factorize(m)\n\nfor v in list(prime_fac.values()):\n\n    r *= comb(v + n - 1, v, R)\n\nmod = 1000000000 + 7\n\nprint((r % mod))\n"}
{"problem_id": "p02951", "input": "a, b, c = list(map(int, input().split()))\n\n\n\nif a < b + c:\n\n    print((b+c-a))\n\nelse:\n\n    print((0))"}
{"problem_id": "p03038", "input": "from collections import Counter\n\nN, M = list(map(int, input().split()))\n\nA = list(map(int, input().split()))\n\n\n\nX = Counter(A)\n\nfor i in range(M):\n\n    B, C = list(map(int, input().split()))\n\n    X[C] += B\n\n\n\nZ = []\n\nfor key, value in list(X.items()):\n\n    Z.append((key, value))\n\n\n\nZ.sort(key=lambda x: x[0], reverse=True)\n\n\n\nans = 0\n\ncnt = 0\n\n\n\nfor value, key in Z:\n\n    if cnt + key <= N:\n\n        ans += key * value\n\n        cnt += key\n\n    else:\n\n        ans += (N - cnt) * value\n\n        break\n\n\n\nprint(ans)\n"}
{"problem_id": "p03723", "input": "a, b, c = list(map(int, input().split()))\n\n\n\nif any(i % 2 != 0 for i in [a, b, c]):\n\n    print((0))\n\n    exit()\n\n\n\nif a == b and b == c:\n\n    print((-1))\n\n    exit()\n\n\n\ncnt = 0\n\na_list = [0]*(1001001)\n\nb_list = [0]*(1001001)\n\nc_list = [0]*(1001001)\n\na_list[0] = a\n\nb_list[0] = b\n\nc_list[0] = c\n\n\n\nfor i in range(1, 1001001):\n\n    a_list[i] = (b_list[i-1] + c_list[i-1]) // 2\n\n    b_list[i] = (c_list[i-1] + a_list[i-1]) // 2\n\n    c_list[i] = (a_list[i-1] + b_list[i-1]) // 2\n\n    cnt += 1\n\n    if a_list[i] % 2 != 0 or b_list[i] % 2 != 0 or c_list[i] % 2 != 0:\n\n        break\n\n\n\nprint(cnt)\n"}
{"problem_id": "p03013", "input": "from functools import lru_cache\n\nimport sys\n\nsys.setrecursionlimit(30000)\n\n\n\nN, M = list(map(int, input().split()))\n\na = list(int(input()) for _ in range(M))\n\n\n\nMOD = pow(10, 9) + 7\n\n\n\nisOk = True\n\nfor i in range(M-1):\n\n    if a[i] + 1 == a[i+1]:\n\n        isOk = False\n\n    \n\nfuncb = [-1] * 100001\n\ndef func(n):\n\n    if n <= 0:\n\n        return 1\n\n    cnt = funcb[n]\n\n    if cnt > 0:\n\n        return cnt\n\n    cnt = 0\n\n    if n >= 2:\n\n        cnt += func(n-2)\n\n    if n >= 1:\n\n        cnt += func(n-1)\n\n    funcb[n] = cnt % MOD\n\n    return funcb[n]\n\n\n\nfunc(30000)\n\nfunc(50000)\n\nfunc(80000)\n\nfunc(100000)\n\n\n\nif not isOk:\n\n    print((0))\n\nelse:\n\n    ans = 1\n\n    s = 0\n\n    for i in range(M+1):\n\n        if i >= M:\n\n            e = N\n\n        else:\n\n            e = a[i] - 1\n\n\n\n        ans = ans * func(e-s) % MOD\n\n\n\n        if i >= M:\n\n            break\n\n\n\n        s = a[i] + 1\n\n\n\n    print(ans)\n"}
{"problem_id": "p02921", "input": "# 2019-11-17 20:44:23(JST)\n\nimport sys\n\n# import collections\n\n# import math\n\n# from string import ascii_lowercase, ascii_uppercase, digits\n\n# from bisect import bisect_left as bi_l, bisect_right as bi_r\n\n# import itertools\n\n# from functools import reduce\n\n# import operator as op\n\n# import re\n\n# import heapq\n\n# import array\n\n# from scipy.misc import comb # (default: exact=False)\n\n# import numpy as np \n\n\n\n\n\ndef main():\n\n    s, t = sys.stdin.read().split()\n\n\n\n    count = 0\n\n    for i in range(3):\n\n        if s[i] == t[i]:\n\n            count += 1\n\n    print(count)\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()\n"}
{"problem_id": "p03416", "input": "#                         author:  kagemeka \n\n#                         created: 2019-11-06 21:30:22(JST)\n\nimport sys\n\n# import collections\n\n# import math\n\n# import string\n\n# import bisect\n\n# import re\n\n# import itertools\n\n# import statistics\n\n# import functools\n\n# import operator\n\n\n\ndef main():\n\n    a, b = (int(x) for x in sys.stdin.read().split())\n\n\n\n    count = 0\n\n    for n in range(a, b+1):\n\n        n = str(n)\n\n        if n == n[::-1]:\n\n            count += 1\n\n\n\n    print(count)       \n\n\n\nif __name__ == \"__main__\":\n\n    # execute only if run as a script\n\n    main()\n"}
{"problem_id": "p02767", "input": "N = int(input())\n\nX = list(map(int, input().split()))\n\nX = list(sorted(X))\n\nif N == 1:\n\n  print((0))\n\n  exit()\n\nans = float('inf')\n\nfor p in range(X[0], X[N - 1] + 1):\n\n  sum = 0\n\n  for x in X:\n\n    sum += (x - p) ** 2\n\n  ans = min(sum, ans)\n\nprint(ans)"}
{"problem_id": "p02725", "input": "k, n = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\nd = [0] * n\n\nd_max = 0\n\n\n\nfor i in range(n - 1):\n\n    d[i] = a[i + 1] - a[i]\n\n    d_max = max(d_max, d[i])\n\n\n\nd[-1] = (k - a[-1]) + a[0]\n\nd_max = max(d_max, d[-1])\n\n\n\nprint((k - d_max))\n"}
{"problem_id": "p02822", "input": "import sys\n\ninput = sys.stdin.readline\n\nfrom collections import deque\n\nN = int(input())\n\nX = [[] for i in range(N)]\n\nfor i in range(N-1):\n\n    x, y = list(map(int, input().split()))\n\n    X[x-1].append(y-1)\n\n    X[y-1].append(x-1)\n\ni0 = min([i for i in range(N) if len(X[i]) == 1])\n\n\n\nP = [-1] * N\n\nQ = deque([i0])\n\nR = []\n\nwhile Q:\n\n    i = deque.popleft(Q)\n\n    R.append(i)\n\n    for a in X[i]:\n\n        if a != P[i]:\n\n            P[a] = i\n\n            X[a].remove(i)\n\n            deque.append(Q, a)\n\n\n\nmod = 10 ** 9 + 7\n\ninv2 = (mod + 1) // 2\n\nA = [1] * N\n\nfor i in R[::-1]:\n\n    s = 0\n\n    for j in X[i]:\n\n        A[i] += A[j]\n\n\n\nans = 0\n\nfor i in range(N):\n\n    s = pow(inv2, N - A[i], mod)\n\n    t = 1 + (1-pow(inv2, N - A[i], mod)) * pow(2, N - A[i], mod)\n\n    for j in X[i]:\n\n        s = (s * pow(inv2, A[j], mod)) % mod\n\n        t = (t + (1-pow(inv2, A[j], mod)) * pow(2, A[j], mod)) % mod\n\n    ans = (ans + 1 - s * t) % mod\n\n\n\nprint((ans * inv2 % mod))"}
{"problem_id": "p03796", "input": "from math import factorial\n\ndef myAnswer(N:int) ->int:\n\n   ans =factorial(N)\n\n   return ans % (10**9 + 7)\n\n\n\ndef modelAnswer():\n\n   tmp=1\n\ndef main():\n\n   N = int(input())\n\n   print((myAnswer(N)))\n\n\n\n\n\nif __name__ == '__main__':\n\n   main()"}
{"problem_id": "p03854", "input": "s = input()[::-1]\n\n\n\nwhile True:\n\n    if len(s) == 0:\n\n        break\n\n    if s[:7] == \"remaerd\":\n\n        s = s[7:]\n\n    elif s[:6] == \"resare\":\n\n        s = s[6:]\n\n    elif s[:5] == \"maerd\" or s[:5] == \"esare\":\n\n        s = s[5:]\n\n    else:\n\n        print(\"NO\")\n\n        exit()\n\n\n\nprint(\"YES\")"}
{"problem_id": "p03074", "input": "import sys\n\nstdin = sys.stdin \n\nni = lambda: int(ns())\n\nna = lambda: list(map(int, stdin.readline().split()))\n\nns = lambda: stdin.readline()\n\n\n\ndef Solve():\n\n    N,K=na()\n\n    S=[int(d) for d in input()]\n\n    l=[]\n\n    N=len(S)\n\n    if(S[0]==0):\n\n        l.append(0)\n\n    b=S[0]\n\n    ct=1\n\n    for i in S[1:]:\n\n        if(b!=i):\n\n            l.append(ct)\n\n            ct=1\n\n            b=i\n\n        else:\n\n            ct+=1\n\n    l.append(ct)\n\n    len_l=len(l)\n\n    if(len_l//2 <= K):\n\n        return sum(l)\n\n    ans = res = sum(l[:2*K+1])\n\n    \n\n    if(len_l%2==0):\n\n        l.append(0)\n\n        len_l+=1\n\n    g = K * 2 + 1\n\n    for i in range(K*2+1,len_l-1,2):\n\n        ans -= l[i-g] + l[i-g+1]\n\n        ans += l[i] + l[1+i]\n\n        if(res<ans):\n\n            res=ans\n\n    #print(S)\n\n    #print(l)\n\n    #print(len_l)\n\n    return res\n\n\n\nprint((Solve()))"}
{"problem_id": "p02837", "input": "def check(x, y):\n\n    for a, b in zip(x, y):\n\n        if a != b and b != -1:\n\n            return False\n\n    else:\n\n        return True\n\n\n\n\n\nn = int(input())\n\nremarks = []\n\ncnt_max = 0\n\nfor _ in range(n):\n\n    a = int(input())\n\n    x = [tuple(map(int, input().split())) for i in range(a)]\n\n    r = [-1] * n\n\n    for i, j in x:\n\n        r[i - 1] = j\n\n    remarks.append(r)\n\nfor r in range(2 ** n):\n\n    r = list(bin(r)[2:].zfill(n))\n\n    r = [int(i) for i in r[:]]\n\n    cnt = 0\n\n    for i in range(n):\n\n        if r[i] == 1:\n\n            flag = check(r, remarks[i])\n\n            cnt += 1\n\n            if not flag:\n\n                cnt = 0\n\n                break\n\n    cnt_max = max(cnt, cnt_max)\n\nprint(cnt_max)"}
{"problem_id": "p03416", "input": "A, B = list(map(int, input().split()))\n\ncount_target = 0\n\n\n\nfor i in range(A, B + 1):\n\n    str_i = str(i)\n\n    reversed_i = ''\n\n    for n_th_i in reversed(list(range(len(str_i)))):\n\n        reversed_i += str_i[n_th_i]\n\n\n\n    if str_i == reversed_i:\n\n        count_target += 1\n\n\n\nprint(count_target)"}
{"problem_id": "p02881", "input": "from collections import Counter,defaultdict,deque\n\nimport sys,bisect,math,itertools,string,queue\n\nfrom heapq import heappop, heappush\n\nsys.setrecursionlimit(10**8)\n\nmod = 10**9+7\n\ndef inp(): return int(sys.stdin.readline())\n\ndef inpl(): return list(map(int, sys.stdin.readline().split()))\n\ndef inpl_str(): return list(sys.stdin.readline().split())\n\ndef inpln(n): return list(int(sys.stdin.readline()) for i in range(n))\n\n\n\nn = inp()\n\nres = float('inf')\n\nfor i in range(1,2*10**6):\n\n    if (n/i).is_integer():\n\n        res = min(res, i + n/i)\n\nprint((int(res-2)))\n"}
{"problem_id": "p02555", "input": "S = int(input())\n\n\n\ndp = [0] * (S + 1)\n\ndp[0] = 1\n\nM = 10 ** 9 + 7\n\n\n\nfor i in range(1, S + 1):\n\n    num = 0\n\n    for j in range(i - 2):\n\n        num += dp[j]\n\n        dp[i] = num % M\n\n\n\nprint((dp[S]))\n\n\n"}
{"problem_id": "p02248", "input": "import random, math\n\nrandom.seed()\n\ndef gen(a, b, num):\n\n    result = set()\n\n    while 1:\n\n        while 1:\n\n            v = random.randint(a, b)//2*2+1\n\n            if v not in result:\n\n                break\n\n        for x in range(3, int(math.sqrt(v))+1, 2):\n\n            if v % x == 0:\n\n                break\n\n        else:\n\n            result.add(v)\n\n            if len(result) == num:\n\n                break\n\n    return result\n\nclass RH():\n\n    def __init__(self, s, base, mod):\n\n        self.base = base\n\n        self.mod = mod\n\n        self.rev = pow(base, mod-2, mod)\n\n\n\n        l = len(s)\n\n        self.h = h = [0]*(l+1)\n\n        tmp = 0\n\n        for i in range(l):\n\n            num = ord(s[i])\n\n            tmp = (tmp*base + num) % mod\n\n            h[i+1] = tmp\n\n    def calc(self, l, r):\n\n        return (self.h[r] - self.h[l] * pow(self.base, r-l, self.mod)) % self.mod\n\n    def fixed(self, length):\n\n        v = pow(self.base, length, self.mod)\n\n        h = self.h; mod = self.mod\n\n        def fixed_calc(l):\n\n            return (h[length+l] - h[l] * v) % mod\n\n        return fixed_calc\n\nclass RRH():\n\n    def __init__(self, s, num=10, primes=None):\n\n        primes = primes or gen(2, 10**3, num)\n\n        MOD = 10**9+7\n\n        self.rhs = [RH(s, p, MOD) for p in primes]\n\n    def calc(self, l, r):\n\n        return [rh.calc(l, r) for rh in self.rhs]\n\n    def fixed(self, length):\n\n        fs = [rh.fixed(length) for rh in self.rhs]\n\n        def multi_fixed_calc(l):\n\n            return list(f(l) for f in fs)\n\n        return multi_fixed_calc\n\n\n\nT = input(); P = input()\n\nprimes = gen(2, 10**3, 2)\n\nHT = RRH(T, primes=primes)\n\nHP = RRH(P, primes=primes)\n\n\n\npv = HP.calc(0, len(P))\n\ncalc = HT.fixed(len(P))\n\nfor i in range(len(T)-len(P)+1):\n\n    if calc(i) == pv:\n\n        print(i)"}
{"problem_id": "p02390", "input": "a = int(input())\n\nh = int(a / 3600)\n\nm = int((a - h * 3600) / 60)\n\ns = int(a - h * 3600 - m * 60)\n\nprint((\":\" .join(map(str, [h, m, s]))))"}
{"problem_id": "p02899", "input": "n = int(input())\n\na = [int(x) for x in input().split()]\n\n\n\nans = list(range(n))\n\n\n\nfor i in range(n):\n\n    ans[a[i]-1] = i+1\n\n    \n\nprint((' '.join(map(str,ans))))"}
{"problem_id": "p03416", "input": "a, b = list(map(int, input().split()))\n\ncnt = 0\n\nfor x in range(a, b + 1):\n\n    s = str(x)\n\n    l = len(s)\n\n    flg = True\n\n    for i in range(l // 2):\n\n        if s[i] != s[l - 1 - i]:\n\n            flg = False\n\n            break\n\n    if flg:\n\n        cnt += 1\n\nprint(cnt)\n"}
{"problem_id": "p02959", "input": "N = int(input())\n\na = list(map(int, input().split()))\n\nb = list(map(int, input().split()))\n\na.reverse()\n\nb.reverse()\n\nans = 0\n\ncapacity = 0\n\nfor i in range(N):\n\n    ans += min(b[i] + capacity, a[i])\n\n    capacity = max(b[i] - max(a[i] - capacity, 0), 0)\n\nans += min(a[-1], capacity)\n\nprint(ans)"}
{"problem_id": "p02863", "input": "#coding:utf-8\n\nimport bisect\n\nimport sys\n\nsys.setrecursionlimit(10**6)\n\nwrite = sys.stdout.write\n\ndbg = lambda *something : print(*something) if DEBUG else 0\n\nDEBUG = True\n\n\n\n\n\n\n\ndef main(given = sys.stdin.readline):\n\n    input = lambda : given().rstrip()\n\n    LMIIS = lambda : list(map(int,input().split()))\n\n    II = lambda : int(input())\n\n    XLMIIS = lambda x : [LMIIS() for _ in range(x)]\n\n\n\n    n, t = LMIIS()\n\n    ab = XLMIIS(n)\n\n\n\n    dp1 = [[0]*t for _ in range(n)]\n\n    for i in range(1, n):\n\n        for j in range(1, t):\n\n            if j < ab[i-1][0]:\n\n                dp1[i][j] = dp1[i-1][j]\n\n            else:\n\n                dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-ab[i-1][0]] + ab[i-1][1])\n\n\n\n\n\n    dp2 = [[0]*t for _ in range(n)]\n\n    for i in range(1, n):\n\n        for j in range(1, t):\n\n            if j < ab[n - i][0]:\n\n                dp2[i][j] = dp2[i-1][j]\n\n            else:\n\n                dp2[i][j] = max(dp2[i-1][j], dp2[i-1][j-ab[n-i][0]] + ab[n-i][1])\n\n\n\n    ans = 0\n\n    for i in range(n):\n\n        for j in range(t - 1):\n\n            ans = max(ans, dp1[i][j] + dp2[n - i - 1][t - j - 1] + ab[i][1])\n\n    print(ans)\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03074", "input": "import sys\n\n\n\nN, K = list(map(int, input().split()))\n\nS = input()\n\n\n\n\n\ndef nexti(n):\n\n    while S[n] == '1':\n\n        n += 1\n\n    while S[n] == '0':\n\n        n += 1\n\n    return n\n\n\n\n\n\ndef nextj(n):\n\n    while S[n] == '0':\n\n        n += 1\n\n        if n == N:\n\n            return N\n\n    while S[n] == '1':\n\n        n += 1\n\n        if n == N:\n\n            return N\n\n    return n\n\n\n\n\n\ni = 0\n\nj = 0\n\nwhile S[j] == '1':\n\n    j += 1\n\n    if j == N:\n\n        print(N)\n\n        sys.exit(0)\n\nfor _ in range(K):\n\n    j = nextj(j)\n\n    if j == N:\n\n        print(N)\n\n        sys.exit(0)\n\n\n\nans = j - i\n\nwhile True:\n\n    i = nexti(i)\n\n    j = nextj(j)\n\n    ans = max(ans, j - i)\n\n    if j == N:\n\n        break\n\n\n\nprint(ans)"}
{"problem_id": "p04044", "input": "N, L = list(map(int, input().split()))\n\nS = list(input() for i in range(N))\n\nstr = \"\"\n\nfor i in range(N-1):\n\n    for j in range(N-1):\n\n        if S[j+1] + S[j] <= S[j] + S[j+1]:\n\n            S[j], S[j+1] = S[j+1], S[j]\n\nfor i in S:\n\n    str += i\n\nprint(str)\n"}
{"problem_id": "p02412", "input": "while True:\n\n\tk=list(map(int,input().split(\" \")))\n\n\tif k[0]==k[1]==0:\n\n\t\tbreak\n\n\tct=0\n\n\ta=0\n\n\tb=0\n\n\tc=0\t\n\n\tmax=k[0]\n\n\tsum=k[1]\n\n\ta=max+1\n\n\t\n\n\twhile True:\n\n\t\ta-=1\n\n\t\tb=a-1\n\n\t\tc=sum-a-b\n\n\t\tif not a>b>c:\n\n\t\t\tprint(ct)\n\n\t\t\tbreak\n\n\t\twhile a>b>c:\n\n\t\t\tif a>b>c>0:\n\n\t\t\t\tct+=1\n\n\t\t\tb-=1\n\n\t\t\tc+=1\n\n\t\t\t"}
{"problem_id": "p04044", "input": "n, l = list(map(int, input().split()))\n\nS = [input() for i in range(n)]\n\nS.sort()\n\nprint((\"\".join(S)))"}
{"problem_id": "p03644", "input": "N = int(input())\n\nif N < 2:\n\n  print(N)\n\nelif 2<=N<4:\n\n  print((2))\n\nelif 4<=N<8:\n\n  print((4))\n\nelif 8<=N<16:\n\n  print((8))\n\nelif 16<=N<32:\n\n  print((16))\n\nelif 32<=N<64:\n\n  print((32))\n\nelif 64<=N:\n\n  print((64))"}
{"problem_id": "p03037", "input": "N, M = list(map(int, input().split()))\n\nLR = [list(map(int, input().split())) for _ in range(M)]\n\n\n\nleft = 1\n\nright = N\n\n\n\nfor l, r in LR:\n\n    if left < l:\n\n        left = l\n\n    if right > r:\n\n        right = r\n\n\n\nans = right - left\n\n\n\nprint((ans + 1 if ans >= 0 else 0))\n"}
{"problem_id": "p03293", "input": "s = input()\n\nt = input()\n\nfor i in range(len(s)):\n\n        if s[i:]+s[:i]==t:\n\n                print('Yes')\n\n                exit()\n\nprint('No')"}
{"problem_id": "p03060", "input": "n = int(input())\n\nv = list(map(int, input().split()))\n\nc = list(map(int, input().split()))\n\nresult = 0\n\nfor i in range(n):\n\n  if v[i] > c[i]:\n\n    result += v[i] - c[i]\n\nprint(result)"}
{"problem_id": "p03416", "input": "a,b = list(map(int,input().split()))\n\nanswer = 0\n\nfor i in range(a,b+1) :\n\n    j = str(i)\n\n    p1 = j[4]\n\n    p2 = j[3]\n\n    p3 = j[2]\n\n    p4 = j[1]\n\n    p5 = j[0]\n\n    k = int(p1+p2+p3+p4+p5)\n\n    if i == k :\n\n        answer += 1\n\nprint(answer)\n\n\n"}
{"problem_id": "p03721", "input": "N,K=list(map(int,input().split()))\n\ndic={}\n\nfor i in range(N):\n\n  a,b=list(map(int,input().split()))\n\n  if a in dic:\n\n    dic[a]+=b\n\n  else:\n\n    dic[a]=b\n\n    \n\ndic=sorted(list(dic.items()),key=lambda x:x[0])\n\nfor d in range(len(dic)):\n\n  amount=dic[d][1]\n\n  if amount>=K:\n\n    print((dic[d][0]))\n\n    exit(0)\n\n  else:\n\n    K-=amount\n\n  "}
{"problem_id": "p03814", "input": "# Problem https://atcoder.jp/contests/abc053/tasks/abc053_b\n\n# Python 1st Try\n\nimport copy\n\n\n\n\n\nclass Problem:\n\n    def __init__(self, stringdata):\n\n        self.stringdata = stringdata\n\n\n\n    def solver(self):\n\n        strcont = copy.copy(self.stringdata)\n\n        result = 0\n\n        rightposition = 0\n\n        leftposition = len(strcont)\n\n        j = 0\n\n        while True:\n\n            if strcont[j] == 'A':\n\n                rightposition = j\n\n                break\n\n            else:\n\n                j = j + 1\n\n        j = leftposition - 1\n\n        while True:\n\n            if strcont[j] == 'Z':\n\n                leftposition = j\n\n                break\n\n            else:\n\n                j = j - 1\n\n\n\n        result = leftposition - rightposition + 1\n\n        return result\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    s = input()\n\n    print((\"{}\".format(Problem(s).solver())))\n"}
{"problem_id": "p03000", "input": "from itertools import accumulate\n\nfrom bisect import *\n\nN, X = list(map(int, input().split()))\n\nL = list(tuple(map(int, input().split())))\n\n\n\nacc = sorted(list(accumulate(L)) + [0])\n\n\n\nn = bisect_right(acc,X)\n\nprint(n)\n\n\n"}
{"problem_id": "p03416", "input": "A, B = list(map(int, input().split()))\n\n\n\ncnt = 0\n\nfor n in range(A, B+1):\n\n    n_s = str(n)\n\n    n_s_rvs = n_s[::-1]\n\n    if n_s == n_s_rvs:\n\n        cnt += 1\n\n\n\nprint(cnt)\n"}
{"problem_id": "p03796", "input": "import math\n\nN=int(input())\n\nprint((math.factorial(N)%(10**9+7)))"}
{"problem_id": "p03371", "input": "# ABC95 C -Half and Half\n\na,b,c,x,y = list(map(float,input().split()))\n\nans = 0\n\nif a+b > 2*c:\n\n    while x != 0.0 and y != 0.0:\n\n        ans += 2*c\n\n        x -= 1.0\n\n        y -= 1.0\n\n        if y == 0.0:\n\n            while x != 0.0:\n\n                if a > 2*c:\n\n                    ans += 2*c\n\n                    x -= 1.0\n\n                else:\n\n                    ans += a\n\n                    x -= 1.0\n\n        if x == 0.0:\n\n            while y != 0.0:\n\n                if b > 2*c:\n\n                    ans += 2*c\n\n                    y -= 1.0\n\n                else:\n\n                    ans += b\n\n                    y -= 1.0\n\nelse:\n\n    ans += a*x + b*y\n\nprint((int(ans)))\n\n\n\n    "}
{"problem_id": "p02595", "input": "N, D = list(map(int, input().split()))\n\ncnt = 0\n\nfor _ in range(N):\n\n    x, y = list(map(int, input().split()))\n\n    if x ** 2 + y ** 2 <= D ** 2:\n\n        cnt += 1\n\n        \n\nprint(cnt)"}
{"problem_id": "p02814", "input": "from math import gcd\n\n\n\nn,m=list(map(int,input().split()))\n\na=list(map(int,input().split()))\n\na=list(set(a))\n\n\n\na=list([x//2 for x in a])\n\n\n\ndef lcm(q):\n\n  x = q[0]\n\n  for i in range(1, len(q)):\n\n    x = (x * q[i]) // gcd(x, q[i])\n\n  return x\n\n\n\nlcma=lcm(a)\n\n\n\nif (lcma//a[0])%2==0:\n\n  print((0))\n\nelse:\n\n  flg=0\n\n  for i in range(1,len(a)):\n\n    if (lcma//a[i])%2==0:\n\n      print((0))\n\n      flg=1\n\n      break\n\n  if flg==0:\n\n    temp=m//lcma\n\n    print((temp//2 if temp%2==0 else temp//2+1))"}
{"problem_id": "p02693", "input": "S = int(input())\n\na = 0\n\ncount = 0\n\nn,m = list(map(int,input().split()))\n\nwhile count == 0:\n\n    a += S\n\n    if n <= a and m >= a:\n\n        count = 1\n\n    if a >= 1000:\n\n        break\n\nif count == 0:\n\n    print(\"NG\")\n\nelse:\n\n    print(\"OK\")"}
{"problem_id": "p03171", "input": "N = int(input())\n\nA = list(map(int, input().split()))\n\nn = N % 2\n\n\n\nDP = [[0] * (N+1) for _ in range(N+1)]\n\n\n\nfor w in range(1, N+1):\n\n    for i in range(N):\n\n        j = i + w\n\n        if j > N:\n\n            continue\n\n        if (w+n) % 2 == 1:\n\n            DP[i][j] = min(DP[i+1][j] - A[i], DP[i][j-1] - A[j-1])\n\n        else:\n\n            DP[i][j] = max(DP[i+1][j] + A[i], DP[i][j-1] + A[j-1])\n\n\n\nprint((DP[0][N]))\n"}
{"problem_id": "p03796", "input": "from math import factorial as fc\n\na = int(input())\n\nprint((fc(a)%(10**9+7)))"}
{"problem_id": "p02574", "input": "from math import gcd\n\n\n\nN = int(input())\n\nnum_lis = list(map(int, input().split()))\n\nc = True\n\n\n\ndef osa_k(max_num):\n\n  lis = [i for i in range(max_num+1)]\n\n  p = 2\n\n  while p**2 <= max_num:\n\n    if lis[p] == p:\n\n      for q in range(2*p, max_num+1, p):\n\n        if lis[q] == q:\n\n          lis[q] = p\n\n    p += 1\n\n  return lis\n\n\n\nhoge = 0\n\nfor i in num_lis:\n\n  hoge = gcd(hoge, i)\n\nif hoge > 1:\n\n  print(\"not coprime\")\n\n  exit()\n\n\n\nd_lis = osa_k(10**6+10)\n\ntmp = set()\n\nfor i in num_lis:\n\n  num = i\n\n  new_tmp = set()\n\n  while num > 1:\n\n    d = d_lis[num]\n\n    new_tmp.add(d)\n\n    num //= d\n\n  for j in new_tmp:\n\n    if j in tmp:\n\n      c = False\n\n      break\n\n    else:\n\n      tmp.add(j)\n\n  else:\n\n    continue\n\n  break\n\n\n\nif c:\n\n  print(\"pairwise coprime\")\n\nelse:\n\n  print(\"setwise coprime\")"}
{"problem_id": "p02850", "input": "n = int(input())\n\nedges = []\n\n\n\nfor id in range(n-1):\n\n    a, b = list(map(int, input().split()))\n\n    edges.append([a-1, b-1, id])\n\n\n\nedges.sort()\n\n\n\nused = [0]*(n)\n\nans = [0]*(n-1)\n\nnum = 1\n\nprev = 0\n\nfor edge in edges:\n\n    _from, to, id = edge\n\n    if _from != prev:\n\n        num = 1\n\n    if used[_from] == num:\n\n        num += 1\n\n    ans[id] = num\n\n    used[to] = num\n\n    num += 1\n\n    prev = _from\n\n\n\nprint((max(ans)))\n\nfor color in ans:\n\n    print(color)\n"}
{"problem_id": "p00003", "input": "for i in range(0, int(input())):\n\n    sidelen = [int(j) for j in input().split(\" \")]\n\n    sidelen.sort(reverse=True)\n\n    if(sidelen[0]**2 == sidelen[1]**2 + sidelen[2]**2):\n\n        print(\"YES\")\n\n    else:\n\n        print(\"NO\")"}
{"problem_id": "p03424", "input": "n = int(input())\n\ns = input().split()\n\ns = set(s)\n\nprint(('Four' if len(s) == 4 else 'Three'))"}
{"problem_id": "p00122", "input": "dX = [2,2,2,1,0,-1,-2,-2,-2,-1,0,1]\n\ndY = [-1,0,1,2,2,2,1,0,-1,-2,-2,-2]\n\ndef solve(x,y,XY):\n\n\txy = XY[:]\n\n\tif len(xy) == 0: return \"OK\"\n\n\tsx,sy = xy.pop(0),xy.pop(0)\n\n\tfor dx,dy in zip(dX,dY):\n\n\t\tif doa(x+dx,y+dy,sx,sy): \n\n\t\t\tr = solve(x+dx,y+dy,xy)\n\n\t\t\tif r: return r\n\n\n\ndef doa(x,y,sx,sy):\n\n\tif not (0 <= x <= 9 and 0 <= y <= 9): return False\n\n\treturn True if abs(x-sx) < 2 and abs(y-sy) < 2 else False\n\n\n\nwhile 1:\n\n\tx,y = list(map(int,input().split()))\n\n\tif x == y == 0: break\n\n\tn = input()\n\n\txy = list(map(int,input().split()))\n\n\tans = solve(x,y,xy)\n\n\tprint(ans if ans else \"NA\")"}
{"problem_id": "p03988", "input": "import sys\n\ninput = sys.stdin.readline\n\nsys.setrecursionlimit(1000000)\n\nfrom collections import deque\n\ndef getN():\n\n    return int(input())\n\ndef getList():\n\n    return list(map(int, input().split()))\n\nimport math\n\n\n\nn = getN()\n\nnums = getList()\n\n\n\n# nums.sort(reverse=True)\n\nmx = max(nums)\n\nmn = (mx+1) // 2\n\nmndx = (mx % 2) + 1\n\n\n\nfrom collections import Counter\n\n\n\ncnt = Counter(nums)\n\n\n\nfor i in range(mn+1, mx+1):\n\n    if cnt[i] < 2:\n\n        print(\"Impossible\")\n\n        sys.exit()\n\n\n\nif cnt[mn] != mndx:\n\n    print(\"Impossible\")\n\nelse:\n\n    print(\"Possible\")"}
{"problem_id": "p02390", "input": "import sys\n\n\n\nif __name__ == '__main__':\n\n    import doctest\n\n    doctest.testmod()\n\n    S = int(sys.stdin.read())\n\n    h = S / 3600\n\n    m = (S % 3600) / 60\n\n    s = S % 60\n\n    print(\"%d:%d:%d\" % (h, m, s))\n"}
{"problem_id": "p02880", "input": "n = int(input())\n\ns = []\n\nfor i in range(1, 10):\n\n  for j in range(1, 10):\n\n    s.append(i*j)\n\nif n in s:\n\n  print(\"Yes\")\n\nelse:\n\n  print(\"No\")"}
{"problem_id": "p03796", "input": "import math\n\nN=int(input())\n\nans=math.factorial(N)\n\nprint((ans%(10**9 +7)))"}
{"problem_id": "p03634", "input": "from collections import deque\n\nn,*t=list(map(int,open(0).read().split()))\n\ncon=[[] for _ in range(n)]\n\ndist_f_k=[0]*n\n\n\n\nfor a,b,c in zip(t[:3*n-3:3],t[1::3],t[2::3]):\n\n\tcon[a-1].append((b-1,c))\n\n\tcon[b-1].append((a-1,c))\n\n\n\nk=t[3*n-2]\n\nque=deque([k-1])\n\nwhile que:\n\n\tcur=que.popleft()\n\n\tfor nxt,dd in con[cur]:\n\n\t\tif dist_f_k[nxt]==0 and nxt!=k-1:\n\n\t\t\tque.append(nxt)\n\n\t\t\tdist_f_k[nxt]=dist_f_k[cur]+dd\n\n\n\nfor x,y in zip(t[3*n-1::2],t[3*n::2]):\n\n\tprint((dist_f_k[x-1]+dist_f_k[y-1]))"}
{"problem_id": "p02622", "input": "S = input()\n\nT = input()\n\nN = len(S)\n\ncnt = 0\n\nfor i in range(N):\n\n    cnt += (S[i] != T[i])\n\n\n\nprint(cnt)\n"}
{"problem_id": "p02264", "input": "n, q = [ int( val ) for val in input( ).split( \" \" ) ]\n\nps = [0]*n\n\nt = [0]*n\n\nfor i in range( n ):\n\n\tps[i], t[i] = input( ).split( \" \" )\n\n\n\n\n\noutput = []\n\nqsum = 0\n\nwhile t:\n\n\tpsi = ps.pop( 0 )\n\n\tti = int( t.pop( 0 ) )\n\n\tif ti <= q:\n\n\t\tqsum += ti\t\n\n\t\toutput.append( psi+\" \"+str( qsum ) )\n\n\telse:\n\n\t\tt.append( ti - q )\n\n\t\tps.append( psi )\n\n\t\tqsum += q\n\n\n\nprint(( \"\\n\".join( output ) ))"}
{"problem_id": "p02688", "input": "N,K = list(map(int, input().split(' ')))\n\na=list(range(1,N+1))\n\nfor i in range(K):\n\n  count=int(input())\n\n  b=input().split(' ')\n\n  for j in range(count):\n\n    if int(b[j]) in a:\n\n      a.remove(int(b[j]))\n\nprint((len(a)))"}
{"problem_id": "p02416", "input": "res = []\n\nwhile True:\n\n    s = input()\n\n    if s == '0':\n\n        break\n\n\n\n    res.append(sum([int(x) for x in s]))\n\n\n\nfor e in res:\n\n    print(e)"}
{"problem_id": "p03086", "input": "import re;print((max(list(map(len,re.split('[^ACGT]',input()))))))"}
{"problem_id": "p03828", "input": "import math\n\nn=int(input())\n\nwaru=10**9+7\n\n\n\nli=[]\n\nli2=[]\n\n\n\nfor i in range(2,n+1):\n\n    tmp=math.factorial(n)\n\n    flag=1\n\n    for j in range(len(li)):\n\n        if i%li[j]==0:\n\n            flag=0\n\n            break\n\n    if flag==1:\n\n        li.append(i)\n\n        li2.append(0)\n\n        while tmp%i==0:\n\n            li2[len(li)-1]+=1\n\n            tmp=tmp//i\n\nans=1\n\n# print(li)\n\n# print(li2)\n\nfor i in range(len(li2)):\n\n    ans*=li2[i]+1\n\nprint((ans%waru))"}
{"problem_id": "p03325", "input": "N = int(input())\n\nA = [int(i) for i in input().split()]\n\nans = 0\n\ncheck = [0]*30\n\nfor i in range(1, 31):\n\n    check[i-1] = 2**i\n\n\n\nfor i in A:\n\n    if i % 2 == 0:\n\n        j = 0\n\n        while check[j] <= i:\n\n            if i % check[j] == 0:\n\n                add = check[j]\n\n            else:\n\n                break\n\n                \n\n            j += 1\n\n        ans += j\n\n        \n\nprint(ans)"}
{"problem_id": "p03845", "input": "N = int(input())\n\nT = list(map(int, input().split()))\n\nM = int(input())\n\np = []\n\nx = []\n\nans = []\n\nfor i in range(M):\n\n    p, x = list(map(int, input().split()))\n\n    ans.append(sum(T[:p-1])+x+sum(T[p:]))\n\n\n\nfor _ in ans:\n\n    print(_)"}
{"problem_id": "p03796", "input": "import math\n\nN = int(input())\n\nprint((math.factorial(N)%(10**9+7)))"}
{"problem_id": "p02901", "input": "def main():\n\n    import math\n\n    N,M=list(map(int,input().split()))\n\n    a=[]\n\n    for i in range(M):\n\n        tmp=list(map(int,input().split()))\n\n        tmpc=list(map(int,input().split()))\n\n        c=0\n\n        for j in range(len(tmpc)):\n\n            c+=2**(tmpc[j]-1)\n\n        tmp[1]=c\n\n        a+=[tmp]\n\n\n\n\n\n    dp=[[10**10 for j in range(2**N)] for i in range(M)]\n\n    dp[0][0]=0\n\n    dp[0][a[0][1]]=a[0][0]\n\n\n\n\n\n    for i in range(1,M):\n\n        dp[i]=dp[i-1]\n\n        for j in range(2**N):\n\n            z,p=a[i][0],a[i][1]\n\n            q=j|p\n\n            x=dp[i-1][j]+z\n\n            if dp[i][q]>x: dp[i][q]=x\n\n\n\n    ans=dp[M-1][2**N-1]\n\n    print((ans if ans<10**10 else -1))\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p02574", "input": "#!/usr/bin/env pypy3\n\n# N,M = map(int,sys.stdin.readline().split())\n\n# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param\n\n# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param\n\n# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param\n\n# s = sys.stdin.readline().rstrip()\n\n# N = int(sys.stdin.readline())\n\n# INF = float(\"inf\")\n\nimport math,sys\n\n\n\nn = int(sys.stdin.readline())\n\na = tuple(map(int,sys.stdin.readline().split()))\n\n#n = int(input())\n\n#a = list(map(int,input().split()))\n\ng = math.gcd(a[0],a[1])\n\nfor i in range(2,n):\n\n    g = math.gcd(g,a[i])\n\nM = max(a)\n\nacc = a[0]\n\nfor i in range(n):\n\n    acc = math.gcd(acc,a[i])\n\nif acc != 1:\n\n    print(\"not coprime\")\n\n    exit()\n\n\n\nLIMIT=max(a)\n\nminPrime = [0]*(LIMIT+1)\n\nminPrime[1] = 1\n\ndef make():\n\n    for i in range(2,LIMIT+1):\n\n        if minPrime[i] == 0:\n\n            minPrime[i] = i\n\n            #print(i)\n\n            for j in range(i+i,LIMIT+1,i):\n\n                #print(i,j)\n\n                if minPrime[j] == 0:\n\n                    minPrime[j] = i\n\nmake()\n\ndef factrial(N):\n\n     ret = []\n\n     while minPrime[N] != N:\n\n         ret.append(minPrime[N])\n\n         N = N//minPrime[N]\n\n     if N != 1:\n\n         ret.append(N)\n\n     return ret\n\n\n\njudge = set([])\n\npc = True\n\n\n\npairwise = True\n\np = set() #all prime\n\n\n\nfor e in a:\n\n    if not pairwise:\n\n        break\n\n    asf = set(factrial(e))\n\n    if judge & asf != set():\n\n        pc = False\n\n    #     #pairwise = False\n\n    #     print(\"setwise coprime\")\n\n    #     exit(0)\n\n    judge |= asf\n\n# for i in a:\n\n#     if not pc:\n\n#         break\n\n#     asf = set(factrial(i))\n\n\n\n#     if judge & asf != set():\n\n#         pc = False\n\n#     judge |= asf\n\nif pc:\n\n    print(\"pairwise coprime\")\n\nelif g == 1:\n\n    print(\"setwise coprime\")\n\nelse:\n\n    print(\"not coprime\")\n"}
{"problem_id": "p02627", "input": "alph = input()\n\nif alph.isupper():\n\n    print(\"A\")\n\nelse:\n\n    print(\"a\")\n"}
{"problem_id": "p03039", "input": "n, m, k = list(map(int, input().split()))\n\n\n\nmod = 1000000007\n\ndef pow(x, n):\n\n    ret = 1\n\n    while n > 0:\n\n        if (n & 1) == 1:\n\n            ret = (ret * x) % mod\n\n        x = (x * x) % mod\n\n        n >>= 1\n\n    return ret\n\n\n\nfac = [1]\n\ninv = [1]\n\nfor i in range(1, n * m + 1):\n\n    fac.append((fac[-1] * i) % mod)\n\n    inv.append(pow(fac[i], mod - 2))\n\n\n\ndef cmb(n, k):\n\n    return (fac[n] * inv[k] * inv[n - k]) % mod\n\n\n\ndef doit(n, m, k):\n\n    ret = 0\n\n    for d in range(m):\n\n        ret = (ret + d * (m - d)) % mod\n\n    return (ret * n * n * cmb(n * m - 2, k - 2)) % mod\n\n\n\nprint(((doit(n, m, k) + doit(m, n, k)) % mod))"}
{"problem_id": "p02555", "input": "s=int(input())\n\np=10**9+7\n\nif s<=2:\n\n    print((0))\n\n    exit()\n\nn=s//3\n\nans=0\n\ndef f(n,k,p):\n\n    if k==0:\n\n        return 1\n\n    elif k%2==0:\n\n        return (f(n,k//2,p)**2)%p\n\n    else:\n\n        return (n*f(n,k-1,p))%p\n\n\n\nfor k in range(1,n+1):\n\n    a=1\n\n    b=1\n\n    for j in range(k-1):\n\n        a=(a*(s-3*k+1+j))%p\n\n        b=(b*(j+1))%p\n\n    ans=(ans+a*f(b,p-2,p))%p\n\n\n\nprint((ans%p))\n\n\n"}
{"problem_id": "p03371", "input": "a,b,c,x,y=list(map(int,input().split()));print((min(k*c*2+a*max(x-k,0)+b*max(y-k,0)for k in range(max(x,y)*3))))"}
{"problem_id": "p03545", "input": "import math\n\nimport string\n\nimport collections\n\nfrom collections import Counter\n\n\n\n\n\ndef readints():\n\n    return list(map(int, input().split()))\n\n\n\n\n\ndef nCr(n, r):\n\n    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))\n\n\n\n\n\ndef has_duplicates2(seq):\n\n    seen = []\n\n    for item in seq:\n\n        if not(item in seen):\n\n            seen.append(item)\n\n    return len(seq) != len(seen)\n\n\n\n\n\ndef divisor(n):\n\n    divisor = []\n\n    for i in range(1, n+1):\n\n        if n % i == 0:\n\n            divisor.append(i)\n\n    return divisor\n\n\n\n\n\n# coordinates\n\ndx = [-1, -1, -1, 0, 0, 1, 1, 1]\n\ndy = [-1, 0, 1, -1, 1, -1, 0, 1]\n\na, b, c, d = list(map(int, input()))\n\n#print(a, b, c, d)\n\nif a+b+c+d == 7:\n\n    print((str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7'))\n\n    exit()\n\nif a+b-c+d == 7:\n\n    print((str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7'))\n\n    exit()\n\nif a+b+c-d == 7:\n\n    print((str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7'))\n\n    exit()\n\nif a+b-c-d == 7:\n\n    print((str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7'))\n\n    exit()\n\nif a-b+c+d == 7:\n\n    print((str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7'))\n\n    exit()\n\nif a-b-c+d == 7:\n\n    print((str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7'))\n\n    exit()\n\nif a-b+c-d == 7:\n\n    print((str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7'))\n\n    exit()\n\nif a-b-c-d == 7:\n\n    print((str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7'))\n\n    exit()\n"}
{"problem_id": "p03723", "input": "a,b,c=list(map(int, input().split()))\n\nd=0\n\nwhile d<10**5:\n\n    if a%2==1 or b%2==1 or c%2==1:break\n\n    a,b,c=b/2+c/2,a/2+c/2,a/2+b/2\n\n    d+=1\n\nelse:d=-1\n\nprint(d)"}
{"problem_id": "p03309", "input": "import statistics\n\nN = int(input())\n\na = [int(i) for i in input().split()]\n\nans = 0\n\n\n\nfor i in range(1,N+1):\n\n  a[i-1] -= i\n\n\n\nb = statistics.median(a)\n\nfor i in range(N):\n\n  ans += abs(a[i]-b)\n\nprint((int(ans)))"}
{"problem_id": "p02665", "input": "n = int(input())\n\nleaves = list(map(int, input().split()))\n\n\n\nans = 0\n\nnodes_min = [0] * (n + 1)\n\nnodes_max = [0] * (n + 1)\n\nnodes_min[n] = leaves[n]\n\nnodes_max[n] = leaves[n]\n\n\n\nfor depth in range(n, 0, -1):\n\n    root_min = nodes_min[depth] // 2 + nodes_min[depth] % 2\n\n    nodes_min[depth - 1] = leaves[depth - 1] + root_min\n\n    root_max = nodes_max[depth]\n\n    nodes_max[depth - 1] = leaves[depth - 1] + root_max\n\nnodes = [0] * (n + 1)\n\nnodes[0] = 1\n\nif nodes[0] < nodes_min[0]:\n\n    print((-1))\n\nelse:\n\n    for depth in range(n):\n\n        roots = nodes[depth]-leaves[depth]\n\n        nodes[depth + 1] = min(roots * 2, nodes_max[depth + 1])\n\n        if nodes[depth+1] < nodes_min[depth+1]:\n\n            print((-1))\n\n            break\n\n    else:\n\n        print((sum(nodes)))\n"}
{"problem_id": "p02691", "input": "N = int(input())\n\nA = [int(i) for i in input().split()]\n\ndp = [0] * 10 ** 7\n\nans = 0\n\nfor i in range(N):\n\n    x = i + 1 - A[i]\n\n    if x >= 0:\n\n        ans += dp[x]\n\n    y = i + 1 + A[i]\n\n    if y < 10 ** 7:\n\n        dp[y] += 1\n\n\n\nprint(ans)\n"}
{"problem_id": "p03544", "input": "a,b=2,1\n\nfor i in[0]*int(input()):a,b=b,a+b\n\nprint(a)"}
{"problem_id": "p02555", "input": "S = int(input())\n\nmod = 10**9+7\n\n\n\ndp = [0]*(S+1)\n\ndp[0] = 1\n\nfor i in range(1,S+1):\n\n    for j in range(0,(i-3)+1):\n\n        dp[i] += dp[j]\n\n        dp[i] %= mod\n\nprint((dp[S]))"}
{"problem_id": "p03107", "input": "# ABC 120 C\n\n\n\nimport re\n\n\n\nS = input()\n\n\n\nl0 = 0\n\nl1 = 0\n\n\n\nfor i in range(len(S)):\n\n    if S[i] == '0':\n\n        l0 += 1\n\n    elif S[i] == '1':\n\n        l1 += 1\n\n\n\nprint((min(l0, l1) * 2))\n"}
{"problem_id": "p02657", "input": "def iput(): return int(input())\n\ndef mput(): return list(map(int, input().split()))\n\ndef lput(): return list(map(int, input().split()))\n\n\n\ndef solve():\n\n    a, b = mput()\n\n    print((a*b))\n\n    return 0\n\n\n\nif __name__ == \"__main__\":\n\n    solve()"}
{"problem_id": "p03759", "input": "a, b, c = list(map(int, input().split()))\n\nif (b - a) == (c - b):\n\n    print(\"YES\")\n\nelse:\n\n    print(\"NO\")"}
{"problem_id": "p03796", "input": "import math\n\nprint((math.factorial(int(input()))%1000000007))"}
{"problem_id": "p03416", "input": "a,b = list(map(int, input().split()))\n\ncount = 0\n\nfor i in range(a,b+1):\n\n    j = str(i)\n\n    if j==''.join(reversed(j)):\n\n        count += 1\n\nprint(count)"}
{"problem_id": "p03796", "input": "#!/usr/bin/env pypy3\n\n\n\nimport math\n\nprint((math.factorial(int(input())) % 1000000007))"}
{"problem_id": "p03721", "input": "(N, K), *AB = [list(map(int, s.split())) for s in open(0)]\n\nfor a, b in sorted(AB):\n\n    K -= b\n\n    if K <= 0:\n\n        print(a)\n\n        break\n"}
{"problem_id": "p03796", "input": "mod = int(1e9+7)\n\nn = int(input())\n\n\n\npower = 1\n\nfor i in range(1, n+1):\n\n    power = power * i % mod\n\nprint(power)"}
{"problem_id": "p03164", "input": "N, W = list(map(int, input().split()))\n\nL = [list(map(int, input().split())) for i in range(N)]\n\nV = 0\n\nfor i in range(N):\n\n  V += L[i][1]\n\n\n\ndp = [[10**9+1] * (V + 1) for i in range(N+1)]\n\ndp[0][0] = 0\n\nfor i in range(N):\n\n    for j in range(V+1):\n\n        if j - L[i][1] >= 0:\n\n          dp[i+1][j] = min(dp[i][j], dp[i][j-L[i][1]] + L[i][0])\n\n        else:\n\n          dp[i+1][j] = dp[i][j]\n\nans = 0\n\nfor j in range(V+1):\n\n    if  W >= dp[-1][j]:\n\n        ans = max(ans, j)\n\nprint(ans)"}
{"problem_id": "p03814", "input": "s = input()\n\n\n\nstart = -1\n\nend = 0\n\nfor i in range(len(s)):\n\n    if s[i] == 'A' and start < 0:\n\n        start = i\n\n    elif s[i] == 'Z':\n\n        end = i\n\nprint((end - start + 1))\n"}
{"problem_id": "p02412", "input": "while 1:\n\n n,x=list(map(int,input().split()))\n\n if n+x==0:break\n\n print((len([1 for i in range(3,n+1)for j in range(2,x-i)if x-i-j<j<i])))"}
{"problem_id": "p03608", "input": "def main():\n\n    from sys import stdin\n\n    input = stdin.readline\n\n\n\n    n, m, r = list(map(int, input().split()))\n\n    l = list(map(int, input().split()))\n\n    for i in range(r):\n\n        l[i] -= 1\n\n    d = [[10**8] * n for _ in range(n)]\n\n    for _ in range(m):\n\n        i, j, k = list(map(int, input().split()))\n\n        d[i-1][j-1] = k\n\n        d[j-1][i-1] = k\n\n\n\n    # Warshall-Floyd algorithm\n\n    for k in range(n):\n\n        for i in range(n):\n\n            for j in range(n):\n\n                if d[i][j] > d[i][k] + d[k][j]:\n\n                    d[i][j] = d[i][k] + d[k][j]\n\n\n\n    # full search\n\n    # 8! = 40320\n\n    from itertools import permutations\n\n\n\n    answer = 10**8\n\n    for i in permutations(l):\n\n        ans = 0\n\n        for j in range(r-1):\n\n            ans += d[i[j]][i[j+1]]\n\n        if ans < answer:\n\n            answer = ans\n\n\n\n    print(answer)\n\n\n\nmain()\n"}
{"problem_id": "p02702", "input": "from collections import Counter\n\nS = input()[::-1]\n\n\n\nmemo = [0]\n\nd = 0\n\nmod = 2019\n\n\n\nfor s in S:\n\n    tmp = int(s) * pow(10, d, mod) % mod\n\n    tmp = memo[-1] + tmp\n\n    memo.append(tmp % mod)\n\n    d += 1\n\n\n\nc = Counter(memo)\n\nans = sum(v * (v - 1) // 2 for v in list(c.values()))\n\nprint(ans)"}
{"problem_id": "p02627", "input": "a = input()\n\nprint(('A' if not a.islower() else 'a'))\n"}
{"problem_id": "p03325", "input": "N=int(input())\n\na=list(map(int,input().split()))\n\nfor i in range(N):\n\n  for j in range(1,31):\n\n    if a[i]%(2**j)!=0:\n\n      a[i]=j-1\n\n      break\n\nprint((sum(a)))"}
{"problem_id": "p03416", "input": "a, b = list(map(int, input().split()))\n\ncnt = 0\n\n\n\nfor i in range(a, b+1):\n\n    i = str(i)\n\n    if i[0] == i[-1] and i[1] == i[-2]:\n\n        cnt += 1\n\n\n\nprint(cnt)\n"}
{"problem_id": "p03835", "input": "k, s = list(map(int, input().split()))\n\ncnt = 0\n\nfor i in range(k + 1):\n\n    for j in range(k + 1):\n\n        if i + j > s:\n\n            break\n\n        elif s - i - j <= k:\n\n            cnt += 1\n\nprint(cnt)\n"}
{"problem_id": "p02702", "input": "from collections import Counter\n\n\n\ns = input()\n\nmod1 = 673\n\nmod2 = 3\n\n\n\nnum1 = 0\n\nnum2 = 0\n\nli1 = []\n\nli2 = []\n\npw1 = 10\n\npw2 = 10\n\nfor i, e in enumerate(s, 1):\n\n    num1 *= 10\n\n    num1 += int(e)\n\n    num1 %= mod1\n\n    inv = pow(pw1, mod1 - 2, mod1)\n\n    li1.append(num1 * inv % mod1)\n\n\n\n    num2 *= 10\n\n    num2 += int(e)\n\n    num2 %= mod2\n\n    inv = pow(pw2, mod2 - 2, mod2)\n\n    li2.append(num2 * inv % mod2)\n\n\n\n    pw1 *= 10\n\n    pw1 %= mod1\n\n    pw2 *= 10\n\n    pw2 %= mod2\n\n\n\nli = [0] + [10 * e1 + e2 for e1, e2 in zip(li1, li2)]\n\nc = Counter(li)\n\n\n\nans = 0\n\nfor v in list(c.values()):\n\n    ans += v * (v - 1) // 2\n\n\n\nprint(ans)\n"}
{"problem_id": "p03371", "input": "a, b, c, x, y = list(map(int, input().split(' ')))\n\n\n\nc = int(c*2)\n\nm = float('inf')\n\nfor i in range(10**5+1):\n\n    m = min(m, a*max(0, x-i)+b*max(0,y-i)+c*i)\n\nprint(m)"}
{"problem_id": "p02983", "input": "l,r=list(map(int,input().split()))\n\ns=list(range(l,r+1))[:2019]\n\nprint((min(i*j%2019for i in s for j in s if i<j)))"}
{"problem_id": "p03945", "input": "s = input()\n\ncnt = 0\n\nfor i in range(len(s) - 1):\n\n    if s[i] == 'W' and s[i + 1] == 'B':\n\n        cnt += 1\n\n    if s[i] == 'B' and s[i + 1] == 'W':\n\n        cnt += 1\n\nprint(cnt)"}
{"problem_id": "p03796", "input": "import math\n\nmod = 10 ** 9 + 7\n\nn = int(input())\n\nprint((math.factorial(n) % mod))"}
{"problem_id": "p03416", "input": "A, B = list(map(int, input().split()))\n\ncount = 0\n\nfor i in range(A, B+1):\n\n    if(str(i) == str(i)[::-1]):\n\n        count += 1\n\nprint(count)\n"}
{"problem_id": "p03568", "input": "import math\n\nimport string\n\n\n\n\n\ndef readints():\n\n    return list(map(int, input().split()))\n\n\n\n\n\ndef nCr(n, r):\n\n    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))\n\n\n\n\n\ndef has_duplicates2(seq):\n\n    seen = []\n\n    for item in seq:\n\n        if not(item in seen):\n\n            seen.append(item)\n\n    return len(seq) != len(seen)\n\n\n\n\n\ndef divisor(n):\n\n    divisor = []\n\n    for i in range(1, n+1):\n\n        if n % i == 0:\n\n            divisor.append(i)\n\n    return divisor\n\n\n\n\n\n# coordinates\n\ndx = [-1, -1, -1, 0, 0, 1, 1, 1]\n\ndy = [-1, 0, 1, -1, 1, -1, 0, 1]\n\n\n\nn = int(input())\n\na = readints()\n\n\n\n\n\ndef func(l):\n\n    if len(l) == n:\n\n        for i in range(len(l)):\n\n            if l[i] % 2 == 0:\n\n                return 1\n\n\n\n        return 0\n\n    return func(l+[(a[len(l)])])+func(l+[(a[len(l)]-1)])+func(l+[(a[len(l)]+1)])\n\n\n\n\n\nprint((func([])))\n"}
{"problem_id": "p03796", "input": "import math\n\n\n\nN = int(input())\n\n\n\nnum = math.factorial(N)\n\n\n\nk, r = divmod(num, 10**9 + 7)\n\nprint(r)"}
{"problem_id": "p03241", "input": "def main():\n\n    N, M = (int(i) for i in input().split())\n\n\n\n    def trial_division(n):\n\n        divs = []\n\n        for i in range(1, int(n**0.5)+1):\n\n            if n % i == 0:\n\n                divs.append(i)\n\n                if i != n//i:\n\n                    divs.append(n//i)\n\n        divs.sort(reverse=True)\n\n        return divs\n\n    divs = trial_division(M)\n\n    for d in divs:\n\n        if d*N <= M:\n\n            return print(d)\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}
{"problem_id": "p03796", "input": "import math\n\n\n\nN = int(input())\n\nC = 10**9 + 7\n\n\n\nprint((math.factorial(N) % C))"}
{"problem_id": "p04017", "input": "import sys\n\ninput = sys.stdin.readline\n\nimport bisect\n\n\n\nn = int(input())\n\nX = list(map(int, input().split()))\n\nl = int(input())\n\nU = 17\n\ndp = [[0]*n for _ in range(U+1)]\n\nfor i, x in enumerate(X):\n\n  t = bisect.bisect_left(X, x+l)\n\n  dp[0][i] = bisect.bisect_right(X, x+l) - 1\n\nfor k in range(U):\n\n  for i in range(n):\n\n    dp[k+1][i] = dp[k][dp[k][i]]\n\ndef test(x, a, b):\n\n  for i in range(U, -1, -1):\n\n    if x >> i & 1:\n\n      a = dp[i][a]\n\n  return a >= b\n\ndef solve(a, b):\n\n  if a > b:\n\n    a, b = b, a\n\n  ng = 0\n\n  ok = n-1\n\n  while ok - ng > 1:\n\n    mid = (ng + ok) // 2\n\n    if test(mid, a, b):\n\n      ok = mid\n\n    else:\n\n      ng = mid\n\n  print(ok)\n\nq = int(input())\n\nfor _ in range(q):\n\n  a, b = list(map(int, input().split()))\n\n  a -= 1\n\n  b -= 1\n\n  solve(a, b)"}
{"problem_id": "p02994", "input": "n, like = list(map(int, input().split()))\n\n\n\narr = [like + i for i in range(n)]\n\n\n\narr.sort(key=lambda x:abs(x))\n\n\n\nprint((sum(arr[1:])))\n"}
{"problem_id": "p03371", "input": "A, B, C, X, Y = list(map(int, input().split()))\n\nans = float('inf')\n\nfor i in range(max(X,Y)+1):\n\n    cost = 2 * C * i + max(0,X-i)*A +max(0,Y-i)*B\n\n    ans = min(ans,cost)\n\nprint(ans)"}
{"problem_id": "p03828", "input": "#coding: UTF-8\n\nimport math\n\nN=int(input())\n\ndef prime_list(k):\n\n    lis=[True for i in range(1,k+1)]\n\n    lis[0]=False\n\n    for i in range(2,k+1):\n\n        j=2\n\n        while j*j<=i:\n\n            if i%j==0:\n\n                lis[i-1]=False\n\n                break\n\n            else:\n\n                j+=1\n\n    return lis\n\n#    print(lis)\n\ndef p_fact(k,N):\n\n    plist=prime_list(k)\n\n    lis=[0]*N\n\n    for i in range(0,k):\n\n        n=0\n\n        if plist[i]:\n\n            while k%(i+1)==0:\n\n                n+=1\n\n                k=k/(i+1)\n\n        lis[i]=n\n\n    return lis\n\nout_lis=[0]*N\n\nfor i in range(1,N+1):\n\n    input_lis=p_fact(i,N)\n\n    out_lis=[out_lis[j]+input_lis[j] for j in range(0,N)]\n\n#print(out_lis)\n\nout=1\n\nfor i in range(0,N):\n\n    out=out*(out_lis[i]+1)\n\nprint((out%1000000007))"}
{"problem_id": "p02245", "input": "import sys\n\nimport queue\n\n\n\nN = 3\n\nf= ''.join(sys.stdin.readline().split())\n\nf+= ''.join(sys.stdin.readline().split())\n\nf+= ''.join(sys.stdin.readline().split())\n\n\n\ndd = [[-1, 0], [0, -1], [1, 0], [0, 1]]\n\n\n\nQ = queue.Queue()\n\nV = dict()\n\n\n\nQ.put([f,f.index('0'),0])\n\nV[f] = True\n\n\n\nwhile not Q.empty():\n\n    u = Q.get()\n\n    if u[0] == '123456780':  break\n\n    sx, sy = u[1]//N, u[1]%N\n\n    for dx, dy in dd:\n\n        tx, ty = sx+dx, sy+dy\n\n        if tx<0 or ty<0 or tx>=N or ty>=N: continue\n\n        v = u[:]\n\n        n1, n2 = u[1], tx*N+ty\n\n        v[1] = n2\n\n        if n1>n2: n1, n2 = n2, n1\n\n        v[0] = v[0][0:n1]+v[0][n2]+v[0][n1+1:n2]+v[0][n1]+v[0][n2+1:]\n\n        if not V.get(v[0], False):\n\n            V[v[0]] = True\n\n            v[2] += 1                                                    \n\n            Q.put(v)\n\n\n\nprint((u[2]))\n"}
{"problem_id": "p03854", "input": "def main():\n\n    S = input()\n\n    w1 = 'dream'[::-1]\n\n    w2 = 'dreamer'[::-1]\n\n    w3 = 'erase'[::-1]\n\n    w4 = 'eraser'[::-1]\n\n    # print(w1,w2,w3,w4)\n\n    S = S[::-1]\n\n    # print(S)\n\n\n\n    # words = ['dream', 'dreamer', 'erase', 'eraser']\n\n    words = [w1, w2, w3, w4]\n\n    T = ''\n\n    while S != T:\n\n        cand = []\n\n        for w in words:\n\n            new_t = T + w\n\n            cand.append(new_t) \n\n        # print('cand', cand)\n\n        ans = False\n\n        for c in cand:\n\n            if c == S[:len(c)]:\n\n                T = c\n\n                ans = True\n\n\n\n        if not ans:\n\n            break\n\n\n\n    if S == T:\n\n        print('YES')\n\n    else:\n\n        print(\"NO\")\n\n\n\nif __name__ == \"__main__\":\n\n    main()"}
{"problem_id": "p03806", "input": "N,MA,MB = list(map(int,input().split()))\n\nsrc = [tuple(map(int,input().split())) for i in range(N)]\n\n\n\nINF = 10**9\n\ndp = [[INF for j in range(401)] for i in range(401)]\n\ndp[0][0] = 0\n\nmaxa = maxb = 0\n\nfor a,b,c in src:\n\n    for ai in range(maxa,-1,-1):\n\n        for bi in range(maxb,-1,-1):\n\n            dp[ai+a][bi+b] = min(dp[ai+a][bi+b], dp[ai][bi] + c)\n\n    maxa += a\n\n    maxb += b\n\n\n\nans = INF\n\nfor i in range(1,401):\n\n    if MA*i > 400 or MB*i > 400: break\n\n    ans = min(ans, dp[MA*i][MB*i])\n\nprint((-1 if ans == INF else ans))"}
{"problem_id": "p03814", "input": "s = input()\n\na = s.find('A')\n\nz = s[::-1].find('Z')\n\nans = len(s)-a-z\n\n\n\nprint(ans)\n\n\n\n#print(*ans, sep='\\n')"}
{"problem_id": "p03494", "input": "_,t=open(0);n=eval(t.replace(' ','|'));print((len(bin(n&-n))-3))"}
{"problem_id": "p03309", "input": "import statistics\n\nN = int(input())\n\nA = [int(a)-i-1 for i,a in enumerate(input().split(),1)]\n\nb = statistics.median_low(A)\n\nc = statistics.median_high(A)\n\nd = sum([abs(x-b) for x in A])\n\ne = sum([abs(x-c) for x in A])\n\nprint((min(d,e)))"}
{"problem_id": "p03416", "input": "a,b = list(map(int,input().split()))\n\nc = 0\n\n\n\nfor i in range(a,b+1):\n\n  new = list(reversed(list(str(i))))\n\n  if new == list(str(i)):\n\n    c += 1\n\n    \n\n    \n\nprint(c)"}
{"problem_id": "p03013", "input": "import sys\n\ninput = sys.stdin.readline\n\nN, M = list(map(int,input().split()))\n\nhole = [0] * (N+1)\n\nfor i in range(M):\n\n    hole[int(input())] = 1\n\nif N == 1:\n\n    print((1))\n\n    exit()\n\nif N == 2:\n\n    if hole[1] == 1:\n\n        print((1))\n\n        exit()\n\n    if hole[1] == 0:\n\n        print((2))\n\n        exit()\n\nflg_one = False\n\nflg_two = False\n\nfirst = 1\n\nsecond = 2\n\nif hole[1] == 1:\n\n    first = 0\n\n    second = 1\n\n    flg_one = True\n\nif hole[2] == 1:\n\n    first = 1\n\n    second = 0\n\n    flg_two = True\n\nif flg_one and flg_two:\n\n    print((0))\n\n    exit()\n\n\n\nfor i in range(3,N):\n\n    if hole[i] == 1:\n\n        first = second\n\n        second = 0\n\n        continue\n\n    tmp = first + second\n\n    tmp %= 1000000007\n\n    first = second\n\n    second = tmp\n\ntmp = first + second\n\ntmp %= 1000000007\n\nprint(tmp)"}
{"problem_id": "p03558", "input": "#!usr/bin/env python3\n\nfrom collections import defaultdict\n\nfrom collections import deque\n\nfrom heapq import heappush, heappop\n\nimport sys\n\nimport math\n\nimport bisect\n\nimport random\n\ndef LI(): return list(map(int, sys.stdin.readline().split()))\n\ndef I(): return int(sys.stdin.readline())\n\ndef LS():return list(map(list, sys.stdin.readline().split()))\n\ndef S(): return list(sys.stdin.readline())[:-1]\n\ndef IR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = I()\n\n    return l\n\ndef LIR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = LI()\n\n    return l\n\ndef SR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = S()\n\n    return l\n\ndef LSR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = SR()\n\n    return l\n\nmod = 1000000007\n\n\n\n#A\n\ndef A():\n\n    s = S()\n\n    t = S()\n\n    if s+t == t[::-1]+s[::-1]:\n\n        print(\"YES\")\n\n    else:\n\n        print(\"NO\")\n\n\n\n#B\n\ndef B():\n\n    n = I()\n\n    for i in range(int(n**0.5)+2)[::-1]:\n\n        if i*i <= n:\n\n            print((i*i))\n\n            quit()\n\n#C\n\ndef C():\n\n    n = I()\n\n    a = LI()\n\n    b = LI()\n\n    c = LI()\n\n    q = [0 for i in range(n)]\n\n    ans = 0\n\n    a.sort()\n\n    b.sort()\n\n    c.sort()\n\n    for i in range(n):\n\n        j = bisect.bisect_left(a,b[i])\n\n        q[i] = j\n\n    for i in range(n-1):\n\n        q[i+1] += q[i]\n\n    q.insert(0,0)\n\n    for i in range(n):\n\n        j = bisect.bisect_left(b,c[i])\n\n        ans += q[j]\n\n    print(ans)\n\n#D\n\ndef D():\n\n    def dijkstra():\n\n        d = [float(\"inf\") for i in range(k)]\n\n        q = [[0,1]]\n\n        d[1] = 0\n\n        while q:\n\n            dx,x = heappop(q)\n\n            for y,dy in v[x]:\n\n                if d[y] > dx+dy:\n\n                    d[y] = dx+dy\n\n                    heappush(q,[d[y],y])\n\n        print((d[0]+1))\n\n    k = I()\n\n    if k == 1:\n\n        print((1))\n\n        quit()\n\n    v = [[] for i in range(k)]\n\n    for i in range(1,k):\n\n        v[i].append([(i+1)%k,1])\n\n        v[i].append([i*10%k,0])\n\n    dijkstra()\n\n#E\n\ndef E():\n\n    return\n\n\n\n#F\n\ndef F():\n\n    return\n\n\n\n#G\n\ndef G():\n\n    return\n\n\n\n#H\n\ndef H():\n\n    return\n\n\n\n#Solve\n\nif __name__ == \"__main__\":\n\n    D()\n"}
{"problem_id": "p03796", "input": "import math\n\nx = int(input())\n\nprint((math.factorial(x) % (10**9 + 7)))"}
{"problem_id": "p02596", "input": "# coding: utf-8\n\n\n\n\n\ndef solve(*args: str) -> str:\n\n    k = int(args[0])\n\n\n\n    l = 9*(k//7 if k % 7 == 0 else k)\n\n    if l % 2 == 0 or l % 5 == 0:\n\n        return '-1'\n\n\n\n    r = phi = l\n\n    for i in range(2, int(-pow(l, 1/2))):\n\n        if r % i == 0:\n\n            phi = phi//i*(i-1)\n\n            while r % i:\n\n                r //= i\n\n\n\n    a = 10 % l\n\n    ret = 1\n\n    while(a != 1):\n\n        a = a*10 % l\n\n        ret += 1\n\n        if phi < ret:\n\n            ret = -1\n\n            break\n\n\n\n    return str(ret)\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    print((solve(*(open(0).read().splitlines()))))\n"}
{"problem_id": "p03013", "input": "import sys\n\nsys.setrecursionlimit(100000)\n\n\n\ndef intinput(): return list(map(int,sys.stdin.readline().split()))\n\n\n\nfib={0:0,1:1,2:1}\n\nfor i in range(3,100003):\n\n    fib[i]=fib[i-1]+fib[i-2]\n\n  #  fib.append(fib[i-1]+fib[i-2])\n\n\n\nn,m=intinput()\n\nmod=10**9+7\n\na=[int(sys.stdin.readline()) for _ in range(m)]\n\nif m!=0:\n\n    l=[a[0]]\n\n    for i in range(len(a)-1):\n\n        l.append(a[i+1]-a[i]-1)\n\n    l.append(n-a[-1])\n\n    k=1\n\n    for i in l:\n\n        k=fib[i]*k%mod\n\n    print((k%mod))\n\nelse:\n\n    print((fib[n+1]%mod))"}
{"problem_id": "p02767", "input": "N = int(input())\n\nA = list(map(int, input().split()))\n\nanswer = 10 ** 9\n\nfor i in range(1,101):\n\n    tmp = 0\n\n    for a in A:\n\n        tmp += abs(a-i) ** 2\n\n    answer = min(answer,tmp)\n\nprint(answer)"}
{"problem_id": "p02850", "input": "\"\"\"\n\nchallenge case\n\n\n\nin:\n\n3\n\n1 3\n\n2 3\n\n\n\nout:\n\n1\n\n1\n\n1\n\n\"\"\"\n\n\n\nfrom collections import deque\n\n\n\ndef main():\n\n\tN, *AB = list(map(int, open(0).read().split()))\n\n\tB = AB[1::2]\n\n\n\n\tE = [[] for _ in range(N + 1)]\n\n\tfor a, b in zip(*[iter(AB)] * 2):\n\n\t\tE[a] += b,\n\n\n\n\tQ = deque([1])\n\n\tC = [0] * (N + 1)\n\n\twhile Q:\n\n\t\tv = Q.popleft()\n\n\t\tc = 0\n\n\t\tfor u in E[v]:\n\n\t\t\tc += 1 + (c + 1 == C[v])\n\n\t\t\tC[u] = c\n\n\t\t\tQ += u,\n\n\n\n\tprint((max(C)))\n\n\tfor b in B:\n\n\t\tprint((C[b]))\n\n\n\nmain()"}
{"problem_id": "p03253", "input": "import sys\n\ninput = sys.stdin.buffer.readline\n\nfrom collections import defaultdict\n\nimport copy\n\n\n\ndef main():\n\n    N,M = list(map(int,input().split()))\n\n    d = defaultdict(int)\n\n    MOD = 10**9+7\n\n    R = 10**5+100\n\n    fac = [0 for _ in range(R+1)]\n\n    fac[0],fac[1] = 1,1\n\n    inv = copy.deepcopy(fac)\n\n    invfac = copy.deepcopy(fac)\n\n    \n\n    for i in range(2,R+1):\n\n        fac[i] = (fac[i-1]*i)%MOD\n\n        inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD\n\n        invfac[i] = (invfac[i-1]*inv[i])%MOD\n\n        \n\n    def coef(x,y):\n\n        num = (((fac[x+y]*invfac[y])%MOD)*invfac[x]%MOD)\n\n        return num\n\n\n\n    while M%2 == 0:\n\n        d[2] += 1\n\n        M //= 2\n\n    f = 3\n\n    while f ** 2 <= M:\n\n        if M % f == 0:\n\n            d[f] += 1\n\n            M //= f\n\n        else:\n\n            f += 2\n\n    if M != 1:\n\n        d[M] += 1\n\n    \n\n    l = list(d.values())\n\n    ans = 1\n\n    for num in l:\n\n        ans *= coef(num,N-1)\n\n        ans %= MOD\n\n        \n\n    print(ans)\n\n    \n\nif __name__ == \"__main__\":\n\n    main()"}
{"problem_id": "p03107", "input": "from collections import Counter\n\nd={chr(i):0 for i in range(2)}\n\ns=Counter(input())\n\nd=d.update(s)\n\nprint((min(s[\"0\"],s[\"1\"])*2))"}
{"problem_id": "p00145", "input": "from functools import reduce\ndef f(a,b): return [Card[a][0], Card[b][1]]\n\nn = int(input())\n\nCard = [[] for _ in [0]*n]\n\nCost = {}\n\nfor i in range(n):\n\n  Card[i] = list(map(int, input().split()))\n\n  Cost[(i, i)] = 0\n\nfor i in range(1, n):\n\n  for j in range(0, n-i):\n\n    a = j+i\n\n    Cost[(j, a)] = min([reduce(lambda a,b: a*b, f(j, k) + f(k+1, a)) + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)])\n\nprint(Cost[0, n-1])"}
{"problem_id": "p03039", "input": "def cmb(n, r, mod):\n\n    if ( r<0 or r>n ):\n\n        return 0\n\n    r = min(r, n-r)\n\n    return g1[n] * g2[r] * g2[n-r] % mod\n\n\n\nA=2*10**5\n\nmod = 10**9+7\n\ng1 = [1, 1]\n\ng2 = [1, 1]\n\ninverse = [0, 1]\n\n\n\nfor i in range( 2, A + 1 ):\n\n    g1.append( ( g1[-1] * i ) % mod )\n\n    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )\n\n    g2.append( (g2[-1] * inverse[-1]) % mod )\n\n\n\nN,M,K=list(map(int,input().split()))\n\nkeisuu=cmb(N*M-2,K-2,mod)\n\n\n\nsum_=0\n\nfor i in range(N):\n\n    a=min(abs(i),abs(N-i-1))\n\n    b=max(abs(i),abs(N-i-1))\n\n    sum_+=(M**2)*((a*(a+1)//2)+(b*(b+1)//2))\n\nfor i in range(M):\n\n    a=min(abs(i),abs(M-i-1))\n\n    b=max(abs(i),abs(M-i-1))\n\n    sum_+=(N**2)*((a*(a+1)//2)+(b*(b+1)//2))\n\nprint(((keisuu * (sum_//2))%mod))"}
{"problem_id": "p02725", "input": "k,n = list(map(int,input().split()))\n\na=list(map(int,input().split()))\n\na.append(a[0]+k)\n\nlongd=0\n\nfor i in range(n):\n\n    tmp=abs(a[i+1]-a[i])\n\n    longd=max(longd,tmp)\n\nprint((k-longd))"}
{"problem_id": "p02886", "input": "def ii():return int(input())\n\ndef iim():return list(map(int,input().split()))\n\ndef iil():return list(map(int,input().split()))\n\ndef ism():return list(map(str,input().split()))\n\ndef isl():return list(map(str,input().split()))\n\n\n\nn = ii()\n\nD = iil()\n\nans = 0\n\nfor i in range(n):\n\n    for j in range(i+1,n):\n\n#        print(i,j)\n\n        ans += D[i]*D[j] \n\nprint(ans)"}
{"problem_id": "p03353", "input": "S = input()\n\nK = int(input())\n\na = list(set(S))\n\na.sort()\n\n\n\nk = []\n\nl = 0\n\nwhile l < len(a):\n\n    for i in range(len(S)):\n\n        if S[i] == a[l]:\n\n            for j in range(1,6):\n\n                if i+j <= len(S):\n\n                    k.append(S[i:i+j])\n\n                else:\n\n                    break\n\n    l += 1\n\n\n\nk = list(set(k))\n\nk.sort()\n\nprint((k[K-1]))"}
{"problem_id": "p02702", "input": "s = input()[::-1]\n\nl = len(s)\n\nc = [0] * 2019\n\nc[0] = 1\n\nten = 1\n\nmod = 0\n\nans = 0\n\n\n\nfor i in range(l):\n\n    mod = (mod + int(s[i]) * ten) % 2019\n\n    ten = ten * 10 % 2019\n\n    c[mod] += 1\n\n\n\nfor i in c:\n\n    ans += i * (i - 1) // 2\n\n\n\nprint(ans)"}
{"problem_id": "p03814", "input": "S=input()\n\nprint((S.rfind('Z')-S.find('A')+1))"}
{"problem_id": "p03371", "input": "#!usr/bin/env python3\n\nfrom collections import defaultdict\n\nfrom collections import deque\n\nfrom heapq import heappush, heappop\n\nimport sys\n\nimport math\n\nimport bisect\n\nimport random\n\ndef LI(): return list(map(int, sys.stdin.readline().split()))\n\ndef I(): return int(sys.stdin.readline())\n\ndef LS():return list(map(list, sys.stdin.readline().split()))\n\ndef S(): return list(sys.stdin.readline())[:-1]\n\ndef IR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = I()\n\n    return l\n\ndef LIR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = LI()\n\n    return l\n\ndef SR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = S()\n\n    return l\n\ndef LSR(n):\n\n    l = [None for i in range(n)]\n\n    for i in range(n):l[i] = LS()\n\n    return l\n\nsys.setrecursionlimit(1000000)\n\nmod = 1000000007\n\n\n\n#A\n\ndef A():\n\n    return\n\n\n\n#B\n\ndef B():\n\n    return\n\n\n\n#C\n\ndef C():\n\n    return\n\n\n\n#D\n\ndef D():\n\n    return\n\n\n\n#E\n\ndef E():\n\n    return\n\n\n\n#F\n\ndef F():\n\n    a,b,c,X,Y = LI()\n\n    ans = float(\"inf\")\n\n    for z in range(300001):\n\n        if z%2 == 0:\n\n            m = c*z\n\n            x = z//2\n\n            y = z//2\n\n            m += a*max(0,X-x)\n\n            m += b*max(0,Y-y)\n\n            if m < ans:\n\n                ans = m\n\n    print(ans)\n\n    return\n\n\n\n#G\n\ndef G():\n\n    n = I()\n\n    x = LI()\n\n    f = [(i,x[i]) for i in range(n)]\n\n    f.sort(key = lambda x:x[1])\n\n    g = [(f[i][0],i) for i in range(n)]\n\n    g.sort(key = lambda x:x[0])\n\n    for i in range(n):\n\n        if g[i][1] < n//2:\n\n            print((f[n//2][1]))\n\n        else:\n\n            print((f[n//2-1][1]))\n\n    return\n\n\n\n#H\n\ndef H():\n\n    return\n\n\n\n#I\n\ndef I_():\n\n    return\n\n\n\n#J\n\ndef J():\n\n    return\n\n\n\n#Solve\n\nif __name__ == \"__main__\":\n\n    F()\n"}
{"problem_id": "p02612", "input": "n = int(input()) % 1000\n\nif n == 0:\n\n    print((0))\n\nelse:\n\n    print((1000 - n))"}
{"problem_id": "p02983", "input": "L ,R = list(map(int,input().split()))\n\n\n\nans =[]\n\nif R - L <= 2019:\n\n    for i in range(L,R+1):\n\n        for j in range(i+1,R+1):\n\n            ans.append(i*j%2019)\n\n\n\nelse:\n\n    for i in range(R-L-1010,R-L+1010):\n\n        for j in range(i,R-L+1010):\n\n            ans.append(i*j%2019)\n\n\n\nprint((min(ans)))\n"}
{"problem_id": "p02773", "input": "from collections import Counter\n\nimport heapq\n\n\n\nn = int(input())\n\nss = []\n\nfor _ in range(n):\n\n    ss.append(input().rstrip())\n\nctr = Counter(ss)\n\nheap = [(-v, k) for k, v in list(ctr.items())]\n\nheapq.heapify(heap)\n\nmaxv = heap[0][0]\n\nwhile heap:\n\n    c = heapq.heappop(heap)\n\n    if c[0] != maxv:\n\n        break\n\n    print((c[1]))\n"}
{"problem_id": "p03037", "input": "# -*- coding: utf-8 -*-\n\n\n\nN, M = list(map(int, input().split()))\n\nL, R = [None] * M, [None] * M\n\nfor i in range(M):\n\n    L[i], R[i] = list(map(int, input().split()))\n\n\n\nl = max(L)\n\nr = min(R)\n\n\n\nans = max(r - l + 1, 0)\n\n\n\nprint(ans)\n"}
{"problem_id": "p02881", "input": "import math\n\ninput_num = int(input())\n\nnum_sqrt = int(math.sqrt(input_num))\n\n\n\nminimam = input_num\n\nfor i in range(num_sqrt+1,0,-1):\n\n    q, mod = divmod(input_num, i)\n\n    distance = q + i -2\n\n    if mod == 0 and minimam > distance:\n\n        minimam = distance\n\nprint(minimam)"}
{"problem_id": "p02881", "input": "# C - Walk on Multiplication Table\n\n# https://atcoder.jp/contests/abc144/tasks/abc144_c\n\n\n\nn = int(input())\n\n\n\nans = 10 ** 12\n\nfor i in range(1, 10 ** 6 + 1):\n\n  if n % i == 0:\n\n    ans = min(ans, n // i + i)\n\n\n\nprint((ans - 2))"}
{"problem_id": "p04020", "input": "# AGC003B - Simplified mahjong\n\nimport sys\n\ninput = sys.stdin.readline\n\n\n\ndef main():\n\n    # split in subsequences when 0 appears -> sum up cur // 2\n\n    N = int(input())\n\n    A = list(map(int, [input() for _ in range(N)])) + [0]\n\n    ans, cur = 0, 0\n\n    for i in A:\n\n        if i:\n\n            cur += i\n\n        else:\n\n            ans += cur // 2\n\n            cur = 0\n\n    print(ans)\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    main()"}
{"problem_id": "p02412", "input": "while True:\n\n    (n, x) = [int(i) for i in input().split()]\n\n    if n == x == 0:\n\n        break\n\n\n\n    count = 0\n\n    for a in range(1, n + 1):\n\n        for b in range(a + 1, n + 1):\n\n            for c in range(b + 1, n + 1):\n\n                if sum([a,b,c]) == x:\n\n                    count += 1\n\n\n\n    print(count)"}
{"problem_id": "p02245", "input": "from collections import deque\n\nN = 3\n\nm = {8: {7, 5}, 7: {8, 6, 4}, 6: {7, 3}, 5: {8, 4, 2}, 4: {7, 5, 3, 1}, 3: {6, 4, 0}, 2: {5, 1}, 1: {4, 2, 0},\n\n     0: {3, 1}}\n\ngoal = 123456780\n\ndef g(i, j, a):\n\n    t = a // (10 ** j) % 10\n\n    return a - t * (10 ** j) + t * (10 ** i)\n\ndef solve():\n\n    MAP = \"\".join(input().replace(\" \", \"\") for _ in range(N))\n\n    start = 8 - MAP.find(\"0\")\n\n    MAP = int(MAP)\n\n    if MAP == goal:\n\n        return 0\n\n    dp = deque([(0, start, MAP)])\n\n    LOG = {MAP}\n\n    while dp:\n\n        cnt, yx, M = dp.popleft()\n\n        if M == goal:\n\n            return cnt\n\n        cnt += 1\n\n        for nyx in m[yx]:\n\n            CM = g(yx, nyx, M)\n\n            if not CM in LOG:\n\n                dp.append((cnt, nyx, CM))\n\n                LOG.add(CM)\n\ndef MAIN():\n\n    print((solve()))\n\nMAIN()\n\n\n"}
{"problem_id": "p03371", "input": "inf = (5000 * 10 ** 5) * 3\n\n\n\na, b, c, x, y = list(map(int, input().split()))\n\n\n\nret = inf\n\nfor cnt_ab in range(max(x, y) * 2 + 1):\n\n    d = cnt_ab // 2\n\n\n\n    cnt_a = max(0, x - d)\n\n    cnt_b = max(0, y - d)\n\n\n\n    t = cnt_ab * c + cnt_a * a + cnt_b * b\n\n    ret = min(ret, t)\n\nprint(ret)\n"}
{"problem_id": "p02555", "input": "S = int(input())\n\nf = [0]*(S+1)\n\nf[0] = 1\n\nif S >= 3: f[3] = 1\n\nif S >= 4: f[4] = 1\n\nif S >= 5: f[5] = 1\n\nfor i in range(6, S+1):\n\n    f[i] = sum(f[i-j] for j in range(3, i+1))%(10**9+7)\n\nprint((f[S]))\n"}
{"problem_id": "p03806", "input": "import sys\n\ninput = sys.stdin.buffer.readline\n\n\n\nN, Ma, Mb = list(map(int, input().split()))\n\nABC = [list(map(int, input().split())) for _ in range(N)]\n\n\n\nINF = 10 ** 15\n\ndp = [[INF for j in range(401)] for i in range(401)]\n\ndp[0][0] = 0\n\n\n\nfor a, b, c in ABC:\n\n  for i in range(400, -1, -1):\n\n    for j in range(400, -1, -1):\n\n      if dp[i][j] != INF:\n\n        dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)\n\n\n\nanswer = INF\n\nfor i in range(1, 401):\n\n  for j in range(1, 401):\n\n    if dp[i][j] != INF and i / j == Ma / Mb:\n\n      answer = min(answer, dp[i][j])\n\n      \n\nprint((answer if answer != INF else -1))"}
{"problem_id": "p02555", "input": "from sys import stdin, stdout, setrecursionlimit\n\nfrom collections import deque, defaultdict, Counter\n\nfrom heapq import heappush, heappop\n\nfrom functools import lru_cache\n\nimport math\n\n\n\nsetrecursionlimit(10**6)\n\nrl = lambda: stdin.readline()\n\nrll = lambda: stdin.readline().split()\n\nrli = lambda: list(map(int, stdin.readline().split()))\n\nrlf = lambda: list(map(float, stdin.readline().split()))\n\n\n\nINF, NINF = float('inf'), float('-inf')\n\nMOD = 10**9 + 7\n\n\n\ndef main():\n\n\ts = int(rl())\n\n\n\n\t@lru_cache(None)\n\n\tdef dp(currsum):\n\n\t\tif currsum == s: return 1\n\n\t\tcnt = 0\n\n\t\tfor d in range(3, 2001):\n\n\t\t\tif currsum + d <= s:\n\n\t\t\t\tcnt += dp(currsum + d)\n\n\t\t\t\tcnt %= MOD \n\n\t\treturn cnt\n\n\tprint((dp(0)))\n\n\tstdout.close()\n\n\n\nif __name__ == \"__main__\":\n\n\tmain()"}
{"problem_id": "p03307", "input": "import math\n\nn=int(input())\n\nprint(((2*n)//math.gcd(2,n)))"}
{"problem_id": "p03854", "input": "import sys\n\ns = input()\n\nts = ['']\n\nwhile True:\n\n  nts= []\n\n  for t in ts:\n\n    for w in ['dreamer', 'eraser', 'dream', 'erase']:\n\n      if s == t + w:\n\n        print('YES')\n\n        sys.exit()\n\n      if s.startswith(t + w):\n\n        nts.append(t + w)\n\n  if len(nts) == 0:\n\n    print('NO')\n\n    sys.exit()\n\n  ts = nts\n"}
{"problem_id": "p02688", "input": "N,K=list(map(int,input().split()))\n\na = [[0]*N]*K\n\na = [[0 for n in range(N)] for k in range(K)]\n\n\n\nfor k in range(K):\n\n    d=int(input())\n\n    have_k=list(map(int,input().split()))\n\n    for h in have_k:\n\n        a[k][h-1]=1\n\n\n\nan=[0]*N\n\nfor k in range(K):\n\n  for n in range(N):\n\n    an[n] = an[n]+a[k][n]\n\n\n\nresult=0\n\nfor i in an:\n\n  if i == 0:\n\n    result+=1\n\n\n\nprint(result)"}
{"problem_id": "p03854", "input": "import sys\n\nsys.setrecursionlimit(1000000)\n\n\n\nS = input()\n\n\n\nT = ['dream', 'dreamer', 'erase', 'eraser']\n\nlenT = [len(i) for i in T]\n\n\n\ndef dayDream(pin):\n\n    global isDream               #;print('dayDream: ', pin, S[pin:])\n\n    for i, d in enumerate(T):\n\n        #print('d:', d)\n\n        if S[pin:pin+lenT[i]] == d:            \n\n            pout = pin + lenT[i] #; print(d, pout)\n\n            if pout == len(S):                \n\n                isDream = True   #; print('YES')\n\n                return \n\n            else:\n\n                dayDream(pout)\n\n    #print('dayDream return', pin)\n\n    return\n\n    \n\nisDream = False\n\ndayDream(0)\n\nif isDream:\n\n    print('YES')\n\nelse:\n\n    print('NO')"}
{"problem_id": "p03037", "input": "n,m=list(map(int,input().split()))\n\nc=[0]*(n+2)\n\nfor i in range(m):\n\n  l,r=list(map(int,input().split()))\n\n  c[l-1]+=1\n\n  c[r]-=1\n\nfor i in range(1,n+2):\n\n  c[i]=c[i]+c[i-1]\n\nans=0\n\nfor i in range(n+2):\n\n  if c[i]==m:\n\n    ans+=1\n\nprint(ans)"}
{"problem_id": "p03287", "input": "n,m=list(map(int,input().split()))\n\na=[int(x) for x in input().split()]\n\nb=[0 for x in range(n+1)]\n\nl=list([0])\n\n\n\nfor i in range(1,n+1):\n\n  b[i]=b[i-1]+a[i-1]\n\n\n\nfor i in range(1,n+1):\n\n  l.append(b[i]%m)\n\n\n\nd=list()\n\nl.sort()\n\nt,c=0,1\n\nfor i in range(1,n+1):\n\n  if l[i]==l[i-1]:\n\n    c+=1\n\n  else:\n\n    if c!=1:\n\n      t += c*(c-1)//2\n\n      c=1\n\n\n\nif c!=1:\n\n  t += c*(c-1)//2  \n\n\n\nprint(t)\n"}
{"problem_id": "p02850", "input": "import copy\n\n\n\nn=int(input())\n\norg_set=set([i for i in range(1,10**5)])\n\nedges=[]\n\nrelations={}\n\nnodes=[]\n\nfor i in range(n-1):\n\n    a,b=list(map(int,input().split(\" \")))\n\n    edges.append([a,b])\n\n    relations.setdefault(a,[]).append(b)\n\n    nodes.append([])\n\nnodes.append([])\n\nnodes.append([])\n\n\n\nmax_color=0\n\nfor start in range(1,n+1):\n\n    targets=relations.get(start,[])\n\n    color=1\n\n    for target in targets:\n\n        if color in nodes[start]:\n\n            color+=1\n\n        else:\n\n            pass\n\n        nodes[target].append(color)\n\n        if color>=max_color:\n\n            max_color=color\n\n        color+=1\n\n\n\nprint(max_color)\n\nfor edge in edges:\n\n    print((nodes[edge[1]][0]))"}
{"problem_id": "p02691", "input": "n=int(input())\n\na=list(map(int,input().split()))\n\nk=[]\n\nans=0\n\nfor i in range(400005):\n\n  k.append(0)\n\nfor i in range(n):\n\n  if i-a[i]>=0:\n\n    ans+=k[i-a[i]]\n\n  if a[i]+i<400005:\n\n    k[a[i]+i]+=1\n\nprint(ans)"}
{"problem_id": "p02881", "input": "import sys\n\nimport os\n\nimport math\n\n\n\nii = lambda: int(sys.stdin.buffer.readline().rstrip())\n\nil = lambda: list(map(int, sys.stdin.buffer.readline().split()))\n\niln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]\n\n\n\niss = lambda: sys.stdin.buffer.readline().decode().rstrip()\n\nisn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]\n\n\n\n\n\ndef main():\n\n    if os.getenv(\"LOCAL\"):\n\n        sys.stdin = open(\"input.txt\", \"r\")\n\n\n\n    N = ii()\n\n    ret = float('inf')\n\n    I = int(math.sqrt(N)) * 10\n\n    for i in range(1, I):\n\n        if N%i == 0:\n\n            j = N//i\n\n            ret = min(ret, j + i - 2)\n\n\n\n    print(ret)\n\n\n\n\n\nif __name__ == '__main__':\n\n    main()\n"}