Input:
import sys

def main():

    in1 = input()

    nums, length = in1.split(' ')

    nums= int(nums)

    length = int(length)

    bombs = []

    for i in range(nums):

        bombs.append(input())

    checked = [['']*length for i in range(nums)]

    for i in range(nums):

        for j in range(length):

            if bombs[i][j] == '#':

                checked[i][j] = '#'

            else:

                bombnum = 0

                if i != 0:

                    if j != 0:

                        if bombs[i-1][j-1] == '#':

                            bombnum += 1

                    if j != length -1:

                        if bombs[i-1][j+1] == '#':

                            bombnum += 1

                    if bombs[i-1][j] == '#':

                        bombnum += 1

                if j != 0:

                    if bombs[i][j-1] == '#':

                        bombnum += 1

                if j != length-1:

                    if bombs[i][j+1] == '#':

                        bombnum += 1

                if i != nums-1:

                    if j != 0:

                        if bombs[i+1][j-1] == '#':

                            bombnum += 1

                    if j != length -1:

                        if bombs[i+1][j+1] == '#':

                            bombnum += 1

                    if bombs[i+1][j] == '#':

                        bombnum += 1

                checked[i][j] = bombnum

    for i in checked:

        for j in i:

            print(j, end = '')

        print('')

if __name__ == '__main__':

    main()

def check(b, i, j, x, y):

 if i < 0 or j < 0 or i == x or j == y:

  return 0

 if b[i][j] == "#":

  return 1

 return 0

bounds = input().split(" ")

x = int(bounds[0])

y = int(bounds[1])

board = [None] * x

for i in range(0, x):

 k = input()

 board[i] = [None] * y

 for j in range(0, y):

  board[i][j] = k[j]

for i in range(0, x):

 for j in range(0, y):

  if board[i][j] == ".":

   p = 0

   p += check(board, i-1, j-1, x, y)

   p += check(board, i-1, j  , x, y)

   p += check(board, i-1, j+1, x, y)

   p += check(board, i  , j-1, x, y)

   p += check(board, i  , j+1, x, y)

   p += check(board, i+1, j-1, x, y)

   p += check(board, i+1, j  , x, y)

   p += check(board, i+1, j+1, x, y)

   board[i][j] = p

 z = ""

 for j in range(0, y):

  z += str(board[i][j])

 print(z)

import sys

def main():
    in1 = input()
    nums, length = in1.split(" ")
    nums = int(nums)
    length = int(length)
    bombs = []
    for i in range(nums):
        bombs.append(input())
    checked = [[""] * length for i in range(nums)]
    for i in range(nums):
        for j in range(length):
            if bombs[i][j] == "#":
                checked[i][j] = "#"
            else:
                bombnum = 0
                if i != 0:
                    if j != 0:
                        if bombs[i - 1][j - 1] == "#":
                            bombnum += 1
                    if j != length - 1:
                        if bombs[i - 1][j + 1] == "#":
                            bombnum += 1
                    if bombs[i - 1][j] == "#":
                        bombnum += 1
                if j != 0:
                    if bombs[i][j - 1] == "#":
                        bombnum += 1
                if j != length - 1:
                    if bombs[i][j + 1] == "#":
                        bombnum += 1
                if i != nums - 1:
                    if j != 0:
                        if bombs[i + 1][j - 1] == "#":
                            bombnum += 1
                    if j != length - 1:
                        if bombs[i + 1][j + 1] == "#":
                            bombnum += 1
                    if bombs[i + 1][j] == "#":
                        bombnum += 1
                checked[i][j] = bombnum
    for i in checked:
        for j in i:
            print(j, end="")
        print("")

if __name__ == "__main__":
    main()

def check(b, i, j, x, y):
    if i < 0 or j < 0 or i == x or j == y:
        return 0
    if b[i][j] == "#":
        return 1
    return 0

bounds = input().split(" ")
x = int(bounds[0])
y = int(bounds[1])
board = [None] * x
for i in range(0, x):
    k = input()
    board[i] = [None] * y
    for j in range(0, y):
        board[i][j] = k[j]
for i in range(0, x):
    for j in range(0, y):
        if board[i][j] == ".":
            p = 0
            p += check(board, i - 1, j - 1, x, y)
            p += check(board, i - 1, j, x, y)
            p += check(board, i - 1, j + 1, x, y)
            p += check(board, i, j - 1, x, y)
            p += check(board, i, j + 1, x, y)
            p += check(board, i + 1, j - 1, x, y)
            p += check(board, i + 1, j, x, y)
            p += check(board, i + 1, j + 1, x, y)
            board[i][j] = p
    z = ""
    for j in range(0, y):
        z += str(board[i][j])
    print(z)

+    if i < 0 or j < 0 or i == x or j == y:

-    checked = [[""] * length for i in range(nums)]

-                            bombnum += 1

-                    if j != length - 1:

-                            bombnum += 1

-                            bombnum += 1

-                    if j != length - 1:

-                            bombnum += 1

-                checked[i][j] = bombnum

+            p += check(board, i - 1, j - 1, x, y)

+            p += check(board, i - 1, j, x, y)

+            p += check(board, i - 1, j + 1, x, y)

+            p += check(board, i, j - 1, x, y)

+            p += check(board, i, j + 1, x, y)

+            p += check(board, i + 1, j - 1, x, y)

+            p += check(board, i + 1, j, x, y)

+            p += check(board, i + 1, j + 1, x, y)


Input:
#python3

import collections as cl

n=int(eval(input()))

a=[''.join(sorted(eval(input()))) for _ in range(n)]

sum=0

for i in list(cl.Counter(a).values()):

  sum+=i*(i-1)//2

print(sum)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from collections import Counter

def main():

    n = int(readline())

    S = []

    for i in range(n):

        S.append(''.join(sorted(readline().rstrip().decode())))

    ans = 0

    for v in list(Counter(S).values()):

        ans += v*(v-1)//2

    print(ans)

if __name__ == '__main__':

    main()

# python3
import collections as cl

n = int(eval(input()))
a = ["".join(sorted(eval(input()))) for _ in range(n)]
sum = 0
for i in list(cl.Counter(a).values()):
    sum += i * (i - 1) // 2
print(sum)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter

def main():
    n = int(readline())
    S = []
    for i in range(n):
        S.append("".join(sorted(readline().rstrip().decode())))
    ans = 0
    for v in list(Counter(S).values()):
        ans += v * (v - 1) // 2
    print(ans)

if __name__ == "__main__":
    main()

-a = ["".join(sorted(eval(input()))) for _ in range(n)]

+        S.append("".join(sorted(readline().rstrip().decode())))

+    for v in list(Counter(S).values()):


Input:
n, a, b = list(map(int, input().split()))

f = 0

for i in range(1, n+1):

  s = sum(map(int, list(str(i))))

  if s >= a and s <= b:

    f += i

print(f)

def sumofdigits(n):

  s = 0

  while n > 0:

    s += n % 10

    n = n // 10

  return s

n, a, b = list(map(int, input().split()))

f = 0

for i in range(1, n+1):

  s = sumofdigits(i)

  if s >= a and s <= b:

    f += i

print(f)

n, a, b = list(map(int, input().split()))
f = 0
for i in range(1, n + 1):
    s = sum(map(int, list(str(i))))
    if s >= a and s <= b:
        f += i
print(f)

def sumofdigits(n):
    s = 0
    while n > 0:
        s += n % 10
        n = n // 10
    return s

n, a, b = list(map(int, input().split()))
f = 0
for i in range(1, n + 1):
    s = sumofdigits(i)
    if s >= a and s <= b:
        f += i
print(f)

+def sumofdigits(n):
+    s = 0
+    while n > 0:
+        s += n % 10
+        n = n // 10
+    return s
+
+
-    s = sum(map(int, list(str(i))))
+    s = sumofdigits(i)


Input:
n, k = list(map(int, input().split()))

if n%k > 0:

    print((1))

else:

    print((0))

n, k = list(map(int, input().split()))

if n%k == 0:

  print((0))

else:

  print((1))

n, k = list(map(int, input().split()))
if n % k > 0:
    print((1))
else:
    print((0))

n, k = list(map(int, input().split()))
if n % k == 0:
    print((0))
else:
    print((1))


Input:
N = int(eval(input()))

S = list(eval(input()))

s = set(S)

count = 0

maxx = 0

for i in range(N): #切断場所

    for k in range(i):

        if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:

            count += 1

    maxx = max(maxx, count)

    count = 0

print(maxx)

N = int(eval(input()))

S = eval(input())

s = set(S)

count = 0

maxx = 0

for i in range(N): #切断場所

    for k in range(i):

        if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:

            count += 1

    maxx = max(maxx, count)

    count = 0

print(maxx)

N = int(eval(input()))
S = list(eval(input()))
s = set(S)
count = 0
maxx = 0
for i in range(N):  # 切断場所
    for k in range(i):
        if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:
            count += 1
    maxx = max(maxx, count)
    count = 0
print(maxx)

N = int(eval(input()))
S = eval(input())
s = set(S)
count = 0
maxx = 0
for i in range(N):  # 切断場所
    for k in range(i):
        if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:
            count += 1
    maxx = max(maxx, count)
    count = 0
print(maxx)

-S = list(eval(input()))
+S = eval(input())


Input:
k = int(eval(input()))

sum = 0

def gcd(a, b):

    if b == 0:

        return a

    return gcd(b, a % b)

for a in range(1, k + 1):

    for b in range(1, k + 1):

        ab_gcd = gcd(a, b)

        for c in range(1, k + 1):

            abc_gcd = gcd(c, ab_gcd)

            sum += abc_gcd

print(sum)

import math

K = int(eval(input()))

ans = 0

for a in range(1, K+1):

    for b in range(1, K + 1):

        ab_gcd = math.gcd(a, b)

        for c in range(1, K + 1):

            ans += math.gcd(ab_gcd, c)

print(ans)

import math

K = int(eval(input()))
ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        ab_gcd = math.gcd(a, b)
        for c in range(1, K + 1):
            ans += math.gcd(ab_gcd, c)
print(ans)

-k = int(eval(input()))
-sum = 0
+import math
-def gcd(a, b):
-    if b == 0:
-        return a
-    return gcd(b, a % b)
-for a in range(1, k + 1):
-    for b in range(1, k + 1):
-        ab_gcd = gcd(a, b)
-        for c in range(1, k + 1):
-            abc_gcd = gcd(c, ab_gcd)
-            sum += abc_gcd
-print(sum)
+K = int(eval(input()))
+ans = 0
+for a in range(1, K + 1):
+    for b in range(1, K + 1):
+        ab_gcd = math.gcd(a, b)
+        for c in range(1, K + 1):
+            ans += math.gcd(ab_gcd, c)
+print(ans)


Input:
import sys

n, a, *x = list(map(int, sys.stdin.read().split()))

def main():

    ma = a * n

    res = [[[0] * (ma + 1) for _ in range(n + 1)] for _ in range(n + 1)]

    res[0][0][0] = 1

    for i in range(n):

        cur = x[i]

        for j in range(i+2):

            for k in range(ma + 1):

                res[i+1][j][k] += res[i][j][k]

                if k >= cur:

                    res[i+1][j][k] += res[i][j-1][k-cur]

    ans = 0

    for j in range(1, n+1):

        ans += res[n][j][j*a]

    return ans

if __name__ == '__main__':

    ans = main()

    print(ans)

import sys

n, a, *x = list(map(int, sys.stdin.read().split()))

def main():

    for i in range(n):

        x[i] -= a

    x.sort()

    res = [[0] * 99*n for _ in range(n+1)]

    # res[i][49*n]を中心とする。

    res[0][49*n] = 1

    for i in range(n):

        for j in range(99*n):

            res[i+1][j] += res[i][j]

            cur = x[i]

            if cur >= 0:

                if j >= cur:

                    res[i+1][j] += res[i][j-cur]

            else:

                if j - cur <= 99 * n - 1:

                    res[i+1][j] += res[i][j-cur]

    ans = res[n][49*n] - 1

    return ans

if __name__ == '__main__':

    ans = main()

    print(ans)

import sys

n, a, *x = list(map(int, sys.stdin.read().split()))

def main():
    ma = a * n
    res = [[[0] * (ma + 1) for _ in range(n + 1)] for _ in range(n + 1)]
    res[0][0][0] = 1
    for i in range(n):
        cur = x[i]
        for j in range(i + 2):
            for k in range(ma + 1):
                res[i + 1][j][k] += res[i][j][k]
                if k >= cur:
                    res[i + 1][j][k] += res[i][j - 1][k - cur]
    ans = 0
    for j in range(1, n + 1):
        ans += res[n][j][j * a]
    return ans

if __name__ == "__main__":
    ans = main()
    print(ans)

import sys

n, a, *x = list(map(int, sys.stdin.read().split()))

def main():
    for i in range(n):
        x[i] -= a
    x.sort()
    res = [[0] * 99 * n for _ in range(n + 1)]
    # res[i][49*n]を中心とする。
    res[0][49 * n] = 1
    for i in range(n):
        for j in range(99 * n):
            res[i + 1][j] += res[i][j]
            cur = x[i]
            if cur >= 0:
                if j >= cur:
                    res[i + 1][j] += res[i][j - cur]
            else:
                if j - cur <= 99 * n - 1:
                    res[i + 1][j] += res[i][j - cur]
    ans = res[n][49 * n] - 1
    return ans

if __name__ == "__main__":
    ans = main()
    print(ans)

-    res = [[[0] * (ma + 1) for _ in range(n + 1)] for _ in range(n + 1)]


Input:
N=int(eval(input()))

A=[]

for i in range(N):

   A.append(eval(input()))

A=list(set(A))

print((len(A)))

n=int(eval(input()))

a=set(int(eval(input())) for i in range(n))

print((len(a)))

N = int(eval(input()))
A = []
for i in range(N):
    A.append(eval(input()))
A = list(set(A))
print((len(A)))

n = int(eval(input()))
a = set(int(eval(input())) for i in range(n))
print((len(a)))

+a = set(int(eval(input())) for i in range(n))


Input:
#coding: utf-8

group={'a':[1,3,5,7,8,10,12],'b':[4,6,9,11],'c':[2]}

input_lines=input()

input_numbers=input_lines.split()

n=list(map(int,input_numbers))#n[0]とn[1]に数字

first_group = False

second_group = False

for i in group:

    for j in range(0,len(group[i])):

        if group[i][j] == n[0]:

            first_group = True

        if group[i][j] == n[1]:

            second_group = True

    if first_group == True and second_group==False or first_group == False and second_group == True:

        print("No")

        break

if first_group and second_group:

    print("Yes")

group =[0,1,3,1,2,1,2,1,1,2,1,2,1]

input_lines=input()

input_numbers=input_lines.split()

n=list(map(int,input_numbers))

if group[n[0]] == group[n[1]]:

    print("Yes")

else:

    print("No")

# coding: utf-8
group = {"a": [1, 3, 5, 7, 8, 10, 12], "b": [4, 6, 9, 11], "c": [2]}
input_lines = input()
input_numbers = input_lines.split()
n = list(map(int, input_numbers))  # n[0]とn[1]に数字
first_group = False
second_group = False
for i in group:
    for j in range(0, len(group[i])):
        if group[i][j] == n[0]:
            first_group = True
        if group[i][j] == n[1]:
            second_group = True
    if (
        first_group == True
        and second_group == False
        or first_group == False
        and second_group == True
    ):
        print("No")
        break
if first_group and second_group:
    print("Yes")

group = [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1]
input_lines = input()
input_numbers = input_lines.split()
n = list(map(int, input_numbers))
if group[n[0]] == group[n[1]]:
    print("Yes")
else:
    print("No")

-n = list(map(int, input_numbers))  # n[0]とn[1]に数字


Input:
import sys

import numpy as np

n = int(sys.stdin.readline().rstrip())

a = np.array(sys.stdin.readline().split(), dtype=np.int64)

def main():

    res = np.bincount(np.minimum(a // 400, 8), minlength=9)

    ans_min = np.count_nonzero(res[:8])

    ans_max = ans_min + res[8]

    if ans_min == 0:

        ans_min = 1

    return ans_min, ans_max

if __name__ == '__main__':

    ans = main()

    print(*ans, sep=' ')

import sys

n, *a = list(map(int, sys.stdin.read().split()))

def main():

  cnt = [0] * 9

  for x in a:

    cnt[min(x, 3200) // 400] += 1

  mi = 0

  for x in cnt[:8]:

    if x: mi += 1

  ma = mi + cnt[8]

  mi = max(1, mi)

  print((mi, ma))

if __name__ == '__main__':

  main()

import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
a = np.array(sys.stdin.readline().split(), dtype=np.int64)

def main():
    res = np.bincount(np.minimum(a // 400, 8), minlength=9)
    ans_min = np.count_nonzero(res[:8])
    ans_max = ans_min + res[8]
    if ans_min == 0:
        ans_min = 1
    return ans_min, ans_max

if __name__ == "__main__":
    ans = main()
    print(*ans, sep=" ")

import sys

n, *a = list(map(int, sys.stdin.read().split()))

def main():
    cnt = [0] * 9
    for x in a:
        cnt[min(x, 3200) // 400] += 1
    mi = 0
    for x in cnt[:8]:
        if x:
            mi += 1
    ma = mi + cnt[8]
    mi = max(1, mi)
    print((mi, ma))

if __name__ == "__main__":
    main()

-a = np.array(sys.stdin.readline().split(), dtype=np.int64)

+n, *a = list(map(int, sys.stdin.read().split()))

-    res = np.bincount(np.minimum(a // 400, 8), minlength=9)

-    ans_min = np.count_nonzero(res[:8])


Input:
import math

h,n = list(map(int,input().split()))

a = [0 for _ in range(n)]

b = [0 for _ in range(n)]

for i in range(n):

    a[i], b[i] = list(map(int,input().split()))

dp = []

for i in range(h + max(a)):

    dp.append(pow(2, 31) - 1)

dp[0] = 0

for i in range(1, len(dp)):

    '''

    tmp = dp[i]

    for j in range(n):

        tmp = min(tmp, dp[max(0, i-a[j])] + b[j])

    dp[i] = tmp

    '''

    dp[i] = min(dp[i - A] + B for A, B in zip(a, b))

print((min(dp[h:])))

import sys

inf = sys.maxsize

h,n = list(map(int,input().split()))

a = [0 for _ in range(n)]

b = [0 for _ in range(n)]

for i in range(n):

    a[i], b[i] = list(map(int,input().split()))

dp = [inf for _ in range(h + max([a[i] for i in range(n)]) + 10)] #dp[体力i削るのに必要な魔力]

dp[0] = 0

for i in range(1, len(dp)):

    for j in range(n):

        dp[i] = min(dp[i], dp[max(0, i-a[j])] + b[j])

#print(dp)

print((min(dp[h:])))

import math

h, n = list(map(int, input().split()))
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))
dp = []
for i in range(h + max(a)):
    dp.append(pow(2, 31) - 1)
dp[0] = 0
for i in range(1, len(dp)):
    """
    tmp = dp[i]
    for j in range(n):
        tmp = min(tmp, dp[max(0, i-a[j])] + b[j])
    dp[i] = tmp
    """
    dp[i] = min(dp[i - A] + B for A, B in zip(a, b))
print((min(dp[h:])))

import sys

inf = sys.maxsize
h, n = list(map(int, input().split()))
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))
dp = [inf for _ in range(h + max([a[i] for i in range(n)]) + 10)]  # dp[体力i削るのに必要な魔力]
dp[0] = 0
for i in range(1, len(dp)):
    for j in range(n):
        dp[i] = min(dp[i], dp[max(0, i - a[j])] + b[j])
# print(dp)
print((min(dp[h:])))

+dp = [inf for _ in range(h + max([a[i] for i in range(n)]) + 10)]  # dp[体力i削るのに必要な魔力]

-        tmp = min(tmp, dp[max(0, i-a[j])] + b[j])

-    dp[i] = min(dp[i - A] + B for A, B in zip(a, b))


Input:
#!/usr/bin/env python3

from copy import deepcopy

def main():

    n = eval(input())

    l = len(n)

    k = int(eval(input()))

    dp0 = [0 for j in range(4)]

    dp1 = [0 for j in range(4)]

    dp1[0] = 1

    for i in range(l):

        dppre0 = deepcopy(dp0)

        dppre1 = deepcopy(dp1)

        d = int(n[i])

        if d == 0:

            for j in [1, 2, 3]:

                dp0[j] += dppre0[j - 1] * 9

        else:

            for j in [1, 2, 3]:

                dp0[j] += dppre0[j - 1] * 9

                dp0[j] += dppre1[j - 1] * max(0, d - 1)

            for j in [0, 1, 2, 3]:

                dp0[j] += dppre1[j]

            dp1 = [0 for j in range(4)]

            for j in [1, 2, 3]:

                dp1[j] = dppre1[j - 1]

    print((dp0[k] + dp1[k]))

if __name__ == "__main__":

    main()

#!/usr/bin/env python3

def main():

    n = eval(input())

    l = len(n)

    k = int(eval(input()))

    dp0 = [0 for j in range(4)]

    dp1 = [0 for j in range(4)]

    dp1[0] = 1

    for i in range(l):

        d = int(n[i])

        if d == 0:

            for j in [3, 2, 1]:

                dp0[j] += dp0[j - 1] * 9

        else:

            for j in [3, 2, 1]:

                dp0[j] += dp0[j - 1] * 9

                dp0[j] += dp1[j - 1] * max(0, d - 1)

                dp0[j] += dp1[j]

            dp0[0] += dp1[0]

            dp1 = [0] + dp1[0:3]

    print((dp0[k] + dp1[k]))

if __name__ == "__main__":

    main()

-            dp1 = [0 for j in range(4)]


Input:
# coding: utf-8

w, h, N = list(map(int, input().split()))

rect = [0, w, 0, h]

for i in range(N):

    x, y, a = list(map(int, input().split()))

    rect[a - 1] = (lambda c, r, p: [r, c][p * (c - r) < 0])([x, y][a > 2], rect[a - 1], int(not a % 2) - int(a % 2))

length = lambda x: [x, 0][x < 0]

print((length(rect[1] - rect[0]) * length(rect[3] - rect[2])))

# coding: utf-8

w, h, N = list(map(int, input().split()))

rect = [0, w, 0, h]

for i in range(N):

    x, y, a = list(map(int, input().split()))

    rect[a - 1] = (lambda c, r, p: [r, c][p * (c - r) < 0])([x, y][a > 2], rect[a - 1], [1, -1][a % 2])

length = lambda x: [x, 0][x < 0]

print((length(rect[1] - rect[0]) * length(rect[3] - rect[2])))

# coding: utf-8
w, h, N = list(map(int, input().split()))
rect = [0, w, 0, h]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    rect[a - 1] = (lambda c, r, p: [r, c][p * (c - r) < 0])(
        [x, y][a > 2], rect[a - 1], int(not a % 2) - int(a % 2)
    )
length = lambda x: [x, 0][x < 0]
print((length(rect[1] - rect[0]) * length(rect[3] - rect[2])))

# coding: utf-8
w, h, N = list(map(int, input().split()))
rect = [0, w, 0, h]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    rect[a - 1] = (lambda c, r, p: [r, c][p * (c - r) < 0])(
        [x, y][a > 2], rect[a - 1], [1, -1][a % 2]
    )
length = lambda x: [x, 0][x < 0]
print((length(rect[1] - rect[0]) * length(rect[3] - rect[2])))


Input:
import sys

input=sys.stdin.readline

def main():

    N,Q = list(map(int,input().split()))

    X = [list(map(int,input().split())) for _ in range(N-1)]

    Y = [list(map(int,input().split())) for _ in range(Q)]

    con = [[] for _ in range(N)]

    for i in range(N-1):

        con[X[i][0]-1]+=[X[i][1]-1]

        con[X[i][1]-1]+=[X[i][0]-1]

    dif = [0]*N

    for i in range(Q):

        dif[Y[i][0]-1] += Y[i][1]

    root = [0]

    while root:

        cur = root.pop()

        for i in con[cur]:

            dif[i] += dif[cur]

            con[i].remove(cur)

            root.append(i)

    print((*dif))

if __name__ == "__main__":

    main()

import sys

input=sys.stdin.readline

from collections import deque

def main():

    N,Q = list(map(int,input().split()))

    X = [list(map(int,input().split())) for _ in range(N-1)]

    Y = [list(map(int,input().split())) for _ in range(Q)]

    con = [[] for _ in range(N)]

    for i in range(N-1):

        con[X[i][0]-1]+=[X[i][1]-1]

        con[X[i][1]-1]+=[X[i][0]-1]

    dif = [0]*N

    for i in range(Q):

        dif[Y[i][0]-1] += Y[i][1]

    root = deque([0])

    go = [True for _ in range(N)]

    go[0] = False

    while root:

        cur = root.pop()

        for fol in con[cur]:

            if go[fol]:

                dif[fol] += dif[cur]

                go[fol] = False

                root.append(fol)

    print((*dif))

if __name__ == "__main__":

    main()

import sys

input = sys.stdin.readline

def main():
    N, Q = list(map(int, input().split()))
    X = [list(map(int, input().split())) for _ in range(N - 1)]
    Y = [list(map(int, input().split())) for _ in range(Q)]
    con = [[] for _ in range(N)]
    for i in range(N - 1):
        con[X[i][0] - 1] += [X[i][1] - 1]
        con[X[i][1] - 1] += [X[i][0] - 1]
    dif = [0] * N
    for i in range(Q):
        dif[Y[i][0] - 1] += Y[i][1]
    root = [0]
    while root:
        cur = root.pop()
        for i in con[cur]:
            dif[i] += dif[cur]
            con[i].remove(cur)
            root.append(i)
    print((*dif))

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
from collections import deque

def main():
    N, Q = list(map(int, input().split()))
    X = [list(map(int, input().split())) for _ in range(N - 1)]
    Y = [list(map(int, input().split())) for _ in range(Q)]
    con = [[] for _ in range(N)]
    for i in range(N - 1):
        con[X[i][0] - 1] += [X[i][1] - 1]
        con[X[i][1] - 1] += [X[i][0] - 1]
    dif = [0] * N
    for i in range(Q):
        dif[Y[i][0] - 1] += Y[i][1]
    root = deque([0])
    go = [True for _ in range(N)]
    go[0] = False
    while root:
        cur = root.pop()
        for fol in con[cur]:
            if go[fol]:
                dif[fol] += dif[cur]
                go[fol] = False
                root.append(fol)
    print((*dif))

if __name__ == "__main__":
    main()

+from collections import deque
-    root = [0]
+    root = deque([0])
+    go = [True for _ in range(N)]
+    go[0] = False
-        for i in con[cur]:
-            dif[i] += dif[cur]
-            con[i].remove(cur)
-            root.append(i)
+        for fol in con[cur]:
+            if go[fol]:
+                dif[fol] += dif[cur]
+                go[fol] = False
+                root.append(fol)


Input:
#@YottyPG　Qiita

from collections import deque

N,M,K = list(map(int,input().split()))

friend = [list(map(int,input().split())) for _ in range(M)]

block = [list(map(int,input().split())) for _ in range(K)]

f = [set() for _ in range(N+1)]

b = [set() for _ in range(N+1)]

for i,j in friend:

    f[i].add(j)

    f[j].add(i)

for i,j in block:

    b[i].add(j)

    b[j].add(i)

stack=deque()

ans = [0]*(N+1)

visited = [0]*(N+1)

for i in range(1,N+1):

    if visited[i]:

        continue

    link = {i}

    visited[i] = 1

    stack.append(i)

    while stack:

        n = stack.pop()

        for j in f[n]:

            if visited[j]==0:

                stack.append(j)

                visited[j] = 1

                link.add(j)

    for i in link:

        ans[i] = len(link) - len(link & f[i]) - len(link & b[i]) - 1

print((*ans[1:]))

#id:KabukiMining

import sys

from math import *

from collections import deque, Counter, defaultdict

from fractions import gcd

input = lambda: sys.stdin.readline().rstrip()

def eprint(s):

    sys.stderr.write('DEBUG: {}'.format(s))

    return

def main():

    n, m, k = list(map(int, input().split()))

    fgraph = [list() for i in range(n)]

    bgraph = [list() for i in range(n)]

    cgraph = [list() for i in range(n)]

    rks = [None] *n

    sys.setrecursionlimit(10**9)

    # r: どの連結成分に存在するかをメモするid

    def dfs(graph,s,r):

        if rks[s] is None:

            rks[s] = r

        for i in range(len(graph[s])):

            if rks[graph[s][i]-1] is not None:

                continue

            dfs(graph, graph[s][i]-1,r)

    for i in range(m):

        a,b = list(map(int, input().split()))

        fgraph[a-1].append(b)

        fgraph[b-1].append(a)

    # print(fgraph)

    #print(bgraph)

    # 連結成分に対してid的なindexをつける

    c = -1

    for i in range(n):

        if rks[i] is None:

            c += 1

            dfs(fgraph, i, c)

    for i in range(k):

        c,d = list(map(int, input().split()))

        if rks[c-1] == rks[d-1]:

            bgraph[d-1].append(c)

            bgraph[c-1].append(d)

    counter = Counter(rks)

    for i in range(n):

        # counter[rks[i]] 連結成分のサイズ

        # len(fgraph[i]) 友達の数

        # len(bgraph[i]) 連結成分内のブロックの数

        # 1 自分

        print((counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1))

if __name__ == '__main__':

    main()

# @YottyPG　Qiita
from collections import deque

N, M, K = list(map(int, input().split()))
friend = [list(map(int, input().split())) for _ in range(M)]
block = [list(map(int, input().split())) for _ in range(K)]
f = [set() for _ in range(N + 1)]
b = [set() for _ in range(N + 1)]
for i, j in friend:
    f[i].add(j)
    f[j].add(i)
for i, j in block:
    b[i].add(j)
    b[j].add(i)
stack = deque()
ans = [0] * (N + 1)
visited = [0] * (N + 1)
for i in range(1, N + 1):
    if visited[i]:
        continue
    link = {i}
    visited[i] = 1
    stack.append(i)
    while stack:
        n = stack.pop()
        for j in f[n]:
            if visited[j] == 0:
                stack.append(j)
                visited[j] = 1
                link.add(j)
    for i in link:
        ans[i] = len(link) - len(link & f[i]) - len(link & b[i]) - 1
print((*ans[1:]))

# id:KabukiMining
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd

input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write("DEBUG: {}".format(s))
    return

def main():
    n, m, k = list(map(int, input().split()))
    fgraph = [list() for i in range(n)]
    bgraph = [list() for i in range(n)]
    cgraph = [list() for i in range(n)]
    rks = [None] * n
    sys.setrecursionlimit(10**9)
    # r: どの連結成分に存在するかをメモするid
    def dfs(graph, s, r):
        if rks[s] is None:
            rks[s] = r
        for i in range(len(graph[s])):
            if rks[graph[s][i] - 1] is not None:
                continue
            dfs(graph, graph[s][i] - 1, r)

    for i in range(m):
        a, b = list(map(int, input().split()))
        fgraph[a - 1].append(b)
        fgraph[b - 1].append(a)
    # print(fgraph)
    # print(bgraph)
    # 連結成分に対してid的なindexをつける
    c = -1
    for i in range(n):
        if rks[i] is None:
            c += 1
            dfs(fgraph, i, c)
    for i in range(k):
        c, d = list(map(int, input().split()))
        if rks[c - 1] == rks[d - 1]:
            bgraph[d - 1].append(c)
            bgraph[c - 1].append(d)
    counter = Counter(rks)
    for i in range(n):
        # counter[rks[i]] 連結成分のサイズ
        # len(fgraph[i]) 友達の数
        # len(bgraph[i]) 連結成分内のブロックの数
        # 1 自分
        print((counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1))

if __name__ == "__main__":
    main()

+from collections import deque, Counter, defaultdict

-N, M, K = list(map(int, input().split()))

-friend = [list(map(int, input().split())) for _ in range(M)]

-block = [list(map(int, input().split())) for _ in range(K)]

-        ans[i] = len(link) - len(link & f[i]) - len(link & b[i]) - 1

+input = lambda: sys.stdin.readline().rstrip()

+    sys.stderr.write("DEBUG: {}".format(s))

+    n, m, k = list(map(int, input().split()))

+    fgraph = [list() for i in range(n)]

+    bgraph = [list() for i in range(n)]

+    cgraph = [list() for i in range(n)]

+    # r: どの連結成分に存在するかをメモするid

+            if rks[graph[s][i] - 1] is not None:

+            dfs(graph, graph[s][i] - 1, r)

+        a, b = list(map(int, input().split()))

+    # 連結成分に対してid的なindexをつける

+        c, d = list(map(int, input().split()))

+        print((counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1))


Input:
# import bisect

# import copy

# import fractions

# import math

# import numpy as np

# from collections import Counter, deque

# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():

    s=list(eval(input()))

    # アルファベット小文字→(97, 123)

    # アルファベット大文字→(65, 91)

    # 半角数字→(48, 58)

    # ひらがな→(12353, 12436)

    # カタカナ→(12449, 12532+1)

    # 全角数字→(65296, 65306)

    def moji_list(*args):

        moji = []

        for i in range(len(args)):

            moji.extend([chr(j) for j in range(args[i][0], args[i][1])])

        return moji

    lowercase = moji_list((97,123))

    for i in s:

        if i in lowercase:

            lowercase.remove(i)

    print((lowercase[0] if len(lowercase)!=0 else 'None'))

resolve()

# import bisect

# import copy

# import fractions

# import math

# import numpy as np

# from collections import Counter, deque

# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():

    s=list(eval(input()))

# アルファベット小文字→(97, 123)を入力に入れる

# アルファベット大文字→(65, 91)

# 半角数字→(48, 58)

# ひらがな→(12353, 12436)

# カタカナ→(12449, 12532+1)

# 全角数字→(65296, 65306)

    def moji_list(*args):

        moji = []

        for i in range(len(args)):

            moji.extend([chr(j) for j in range(args[i][0], args[i][1])])

        return moji

    lowercase = moji_list((97,123))

    print((min(set(lowercase)-set(s) or ['None'])))

resolve()

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product
def resolve():
    s = list(eval(input()))
    # アルファベット小文字→(97, 123)
    # アルファベット大文字→(65, 91)
    # 半角数字→(48, 58)
    # ひらがな→(12353, 12436)
    # カタカナ→(12449, 12532+1)
    # 全角数字→(65296, 65306)
    def moji_list(*args):
        moji = []
        for i in range(len(args)):
            moji.extend([chr(j) for j in range(args[i][0], args[i][1])])
        return moji

    lowercase = moji_list((97, 123))
    for i in s:
        if i in lowercase:
            lowercase.remove(i)
    print((lowercase[0] if len(lowercase) != 0 else "None"))

resolve()

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product
def resolve():
    s = list(eval(input()))
    # アルファベット小文字→(97, 123)を入力に入れる
    # アルファベット大文字→(65, 91)
    # 半角数字→(48, 58)
    # ひらがな→(12353, 12436)
    # カタカナ→(12449, 12532+1)
    # 全角数字→(65296, 65306)
    def moji_list(*args):
        moji = []
        for i in range(len(args)):
            moji.extend([chr(j) for j in range(args[i][0], args[i][1])])
        return moji

    lowercase = moji_list((97, 123))
    print((min(set(lowercase) - set(s) or ["None"])))

resolve()

-    # アルファベット小文字→(97, 123)

+    # アルファベット小文字→(97, 123)を入力に入れる

-    print((lowercase[0] if len(lowercase) != 0 else "None"))

+    print((min(set(lowercase) - set(s) or ["None"])))


Input:
k,s = list(map(int,input().split()))

n = 0

for x in range(k+1):

    for y in range(k+1):

        z = s-x-y

        if 0<=z<=k:

            n+=1

print(n)

K,S = list(map(int,input().split()))

a = 0

for X in range(K+1):

  for Y in range(K+1):

    Z = S-X-Y

    if 0<=Z<=K:

      a+=1

print(a)

k, s = list(map(int, input().split()))
n = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            n += 1
print(n)

K, S = list(map(int, input().split()))
a = 0
for X in range(K + 1):
    for Y in range(K + 1):
        Z = S - X - Y
        if 0 <= Z <= K:
            a += 1
print(a)

-k, s = list(map(int, input().split()))
-n = 0
-for x in range(k + 1):
-    for y in range(k + 1):
-        z = s - x - y
-        if 0 <= z <= k:
-            n += 1
-print(n)
+K, S = list(map(int, input().split()))
+a = 0
+for X in range(K + 1):
+    for Y in range(K + 1):
+        Z = S - X - Y
+        if 0 <= Z <= K:
+            a += 1
+print(a)


Input:
import math

import sys

def sieve(n):

    if n < 2:

        is_prime = [False for _ in range(n+1)]

        return is_prime

    is_prime = [True for _ in range(n+1)]

    is_prime[0] = False

    is_prime[1] = False

    for i in range(2, int(n**0.5)+1):

        if is_prime[i]:

            for j in range(i*2, n+1, i):

                is_prime[j] = False

    return is_prime

def main():

	N=10**5

	prime=sieve(N)

	a=[0 for i in range(N+1)]

	for i in range(3,N+1):

		if prime[i] and prime[(i+1)//2]: a[i]=a[i-1]+1

		else: a[i]=a[i-1]

	Q=int(eval(input()))

	for i in range(Q):

		l,r=list(map(int,input().split()))

		print((a[r]-a[l-1]))

if __name__ == '__main__':

    main()

import math

import sys

def sieve(n):

    if n < 2:

        is_prime = [False for _ in range(n+1)]

        return is_prime

    is_prime = [True for _ in range(n+1)]

    is_prime[0] = False

    is_prime[1] = False

    for i in range(2, int(n**0.5)+1):

        if is_prime[i]:

            for j in range(i*2, n+1, i):

                is_prime[j] = False

    return is_prime

input = sys.stdin.readline

N=10**5

prime=sieve(N)

a=[0 for i in range(N+1)]

for i in range(3,N+1):

	if prime[i] and prime[(i+1)//2]: a[i]=a[i-1]+1

	else: a[i]=a[i-1]

for i in range(int(eval(input()))):

	l,r=list(map(int,input().split()))

	print((a[r]-a[l-1]))

import math
import sys

def sieve(n):
    if n < 2:
        is_prime = [False for _ in range(n + 1)]
        return is_prime
    is_prime = [True for _ in range(n + 1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if is_prime[i]:
            for j in range(i * 2, n + 1, i):
                is_prime[j] = False
    return is_prime

def main():
    N = 10**5
    prime = sieve(N)
    a = [0 for i in range(N + 1)]
    for i in range(3, N + 1):
        if prime[i] and prime[(i + 1) // 2]:
            a[i] = a[i - 1] + 1
        else:
            a[i] = a[i - 1]
    Q = int(eval(input()))
    for i in range(Q):
        l, r = list(map(int, input().split()))
        print((a[r] - a[l - 1]))

if __name__ == "__main__":
    main()

import math
import sys

def sieve(n):
    if n < 2:
        is_prime = [False for _ in range(n + 1)]
        return is_prime
    is_prime = [True for _ in range(n + 1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if is_prime[i]:
            for j in range(i * 2, n + 1, i):
                is_prime[j] = False
    return is_prime

input = sys.stdin.readline
N = 10**5
prime = sieve(N)
a = [0 for i in range(N + 1)]
for i in range(3, N + 1):
    if prime[i] and prime[(i + 1) // 2]:
        a[i] = a[i - 1] + 1
    else:
        a[i] = a[i - 1]
for i in range(int(eval(input()))):
    l, r = list(map(int, input().split()))
    print((a[r] - a[l - 1]))

-        if prime[i] and prime[(i + 1) // 2]:

-        l, r = list(map(int, input().split()))

+    if prime[i] and prime[(i + 1) // 2]:

+    l, r = list(map(int, input().split()))


Input:
import collections,itertools,sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

N,W = LI()

wv = [LI() for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N+1)] #1_indexed

for i,j in itertools.product(list(range(1,N+1)),list(range(W+1))):

    w,v = wv[i-1]

    if j-w>=0:

        dp[i][j] = max(dp[i][j],dp[i-1][j-w]+v)

    dp[i][j] = max(dp[i][j],dp[i-1][j])

print((dp[-1][-1]))

import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

N,W = LI()

wv = [LI() for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N+1)] #1_indexed

for i in range(1,N+1):

    w,v = wv[i-1]

    for j in range(W+1):

        if j-w>=0:

            dp[i][j] = max(dp[i][j],dp[i-1][j-w]+v)

        dp[i][j] = max(dp[i][j],dp[i-1][j])

print((dp[-1][-1]))

import collections, itertools, sys

def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))

N, W = LI()
wv = [LI() for _ in range(N)]
dp = [[0] * (W + 1) for _ in range(N + 1)]  # 1_indexed
for i, j in itertools.product(list(range(1, N + 1)), list(range(W + 1))):
    w, v = wv[i - 1]
    if j - w >= 0:
        dp[i][j] = max(dp[i][j], dp[i - 1][j - w] + v)
    dp[i][j] = max(dp[i][j], dp[i - 1][j])
print((dp[-1][-1]))

import sys

def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))

N, W = LI()
wv = [LI() for _ in range(N)]
dp = [[0] * (W + 1) for _ in range(N + 1)]  # 1_indexed
for i in range(1, N + 1):
    w, v = wv[i - 1]
    for j in range(W + 1):
        if j - w >= 0:
            dp[i][j] = max(dp[i][j], dp[i - 1][j - w] + v)
        dp[i][j] = max(dp[i][j], dp[i - 1][j])
print((dp[-1][-1]))

-for i, j in itertools.product(list(range(1, N + 1)), list(range(W + 1))):


Input:
N = int(eval(input()))

A = list(map(int,input().split()))

B = list(map(int,input().split()))

ans = 0

for i in range(N):

    p = min(A[i], B[i])

    ans += p

    B[i] -= p

    p = min(A[i+1],B[i])

    ans += p

    A[i+1] -= p

print(ans)

N = int(eval(input()))

A = list(map(int,input().split()))

B = list(map(int,input().split()))

ans = 0

for i,b in enumerate(B):

    x = min(A[i], b)

    ans += x

    b -= x

    y = min(A[i+1], b)

    ans += y

    A[i+1] -= y

print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    p = min(A[i], B[i])
    ans += p
    B[i] -= p
    p = min(A[i + 1], B[i])
    ans += p
    A[i + 1] -= p
print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i, b in enumerate(B):
    x = min(A[i], b)
    ans += x
    b -= x
    y = min(A[i + 1], b)
    ans += y
    A[i + 1] -= y
print(ans)

-for i in range(N):
-    p = min(A[i], B[i])
-    ans += p
-    B[i] -= p
-    p = min(A[i + 1], B[i])
-    ans += p
-    A[i + 1] -= p
+for i, b in enumerate(B):
+    x = min(A[i], b)
+    ans += x
+    b -= x
+    y = min(A[i + 1], b)
+    ans += y
+    A[i + 1] -= y


Input:
a, b, c, k = list(map(int, input().split()))

if a >= k:

    print(k)

elif a + b >= k:

    print(a)

else:

    print((a - (k -(a+b))))

a, b, c, k = list(map(int, input().split()))

if k <= a:

    print(k)

elif k <= a+b:

    print(a)

elif k > a+b:

    print((a- (k-(a+b))))

a, b, c, k = list(map(int, input().split()))
if a >= k:
    print(k)
elif a + b >= k:
    print(a)
else:
    print((a - (k - (a + b))))

a, b, c, k = list(map(int, input().split()))
if k <= a:
    print(k)
elif k <= a + b:
    print(a)
elif k > a + b:
    print((a - (k - (a + b))))

-if a >= k:
+if k <= a:
-elif a + b >= k:
+elif k <= a + b:
-else:
+elif k > a + b:


Input:
N,M,K=map(int,input().split())

par=[-1]*N

num=[0]*N

def find(x):

    if par[x-1]<0:

        return x

    else:

        par[x-1]=find(par[x-1])

        return par[x-1]

def union(x,y):

    p,q=find(x),find(y)

    if p==q:

        return

    if p>q:

        p,q=q,p

    par[p-1]+=par[q-1]

    par[q-1]=p

def size(x):

    return -par[find(x)-1]

def same(x,y):

    return find(x)==find(y)

for _ in range(M):

    a,b=map(int,input().split())

    union(a,b)

    num[a-1]+=1

    num[b-1]+=1

for _ in range(K):

    c,d=map(int,input().split())

    if same(c,d):

        num[c-1]+=1

        num[d-1]+=1

for i in range(N):

    print(size(i+1)-1-num[i],end=" ")

N,M,K=map(int,input().split())

par=[-1]*N

num=[0]*N

def find(x):

    if par[x]<0:

        return x

    else:

        par[x]=find(par[x])

        return par[x]

def union(x,y):

    p,q=find(x),find(y)

    if p==q:

        return

    if p>q:

        p,q=q,p

    par[p]+=par[q]

    par[q]=p

def size(x):

    return -par[find(x)]

def same(x,y):

    return find(x)==find(y)

for _ in range(M):

    a,b=map(int,input().split())

    a-=1

    b-=1

    union(a,b)

    num[a]+=1

    num[b]+=1

for _ in range(K):

    c,d=map(int,input().split())

    c-=1

    d-=1

    if same(c,d):

        num[c]+=1

        num[d]+=1

for i in range(N):

    print(size(i)-1-num[i],end=" ")

N, M, K = map(int, input().split())
par = [-1] * N
num = [0] * N

def find(x):
    if par[x - 1] < 0:
        return x
    else:
        par[x - 1] = find(par[x - 1])
        return par[x - 1]

def union(x, y):
    p, q = find(x), find(y)
    if p == q:
        return
    if p > q:
        p, q = q, p
    par[p - 1] += par[q - 1]
    par[q - 1] = p

def size(x):
    return -par[find(x) - 1]

def same(x, y):
    return find(x) == find(y)

for _ in range(M):
    a, b = map(int, input().split())
    union(a, b)
    num[a - 1] += 1
    num[b - 1] += 1
for _ in range(K):
    c, d = map(int, input().split())
    if same(c, d):
        num[c - 1] += 1
        num[d - 1] += 1
for i in range(N):
    print(size(i + 1) - 1 - num[i], end=" ")

N, M, K = map(int, input().split())
par = [-1] * N
num = [0] * N

def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def union(x, y):
    p, q = find(x), find(y)
    if p == q:
        return
    if p > q:
        p, q = q, p
    par[p] += par[q]
    par[q] = p

def size(x):
    return -par[find(x)]

def same(x, y):
    return find(x) == find(y)

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    union(a, b)
    num[a] += 1
    num[b] += 1
for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if same(c, d):
        num[c] += 1
        num[d] += 1
for i in range(N):
    print(size(i) - 1 - num[i], end=" ")

-    print(size(i + 1) - 1 - num[i], end=" ")

+    print(size(i) - 1 - num[i], end=" ")


Input:
import numpy as np

s=eval(input())

n=len(s)

MOD=1000000007

wayA=np.array([0,0,0,0],dtype=np.int64)

wayB=np.array([0,0,0,0],dtype=np.int64)

wayC=np.array([0,0,0,0],dtype=np.int64)

MOD2=np.array([MOD,MOD,MOD,MOD],dtype=np.int32)

hatena=0

for c in s:

	if c=="A":

		wayA[0]+=1

	if c=="B":

		wayB+=wayA

	if c=='C':

		wayC+=wayB

	if c=='?':

		wayC[1]=wayC[1]+wayB[0]

		wayC[2]=wayC[2]+wayB[1]

		wayC[3]=wayC[3]+wayB[2]

		wayB[1]=wayB[1]+wayA[0]

		wayB[2]=wayB[2]+wayA[1]

		wayA[1]=wayA[1]+1

		hatena+=1

	wayA%=MOD2

	wayB%=MOD2

	wayC%=MOD2

ans=0

for i in range(0,4):

	p3=1

	for k in range(0,hatena-i):

		p3=p3*3

		p3=p3%MOD

	ans=ans+p3*wayC[i]

	ans=ans%MOD

print((int(ans)))

import numpy as np

s=eval(input())

n=len(s)

MOD=1000000007

wayA=np.array([0,0,0,0],dtype=np.int64)

wayB=np.array([0,0,0,0],dtype=np.int64)

wayC=np.array([0,0,0,0],dtype=np.int64)

MOD2=np.array([MOD,MOD,MOD,MOD],dtype=np.int32)

hatena=0

for c in s:

	if c=="A":

		wayA[0]+=1

	if c=="B":

		wayB+=wayA

	if c=='C':

		wayC+=wayB

	if c=='?':

		wayC[1]=wayC[1]+wayB[0]

		wayC[2]=wayC[2]+wayB[1]

		wayC[3]=wayC[3]+wayB[2]

		wayB[1]=wayB[1]+wayA[0]

		wayB[2]=wayB[2]+wayA[1]

		wayA[1]=wayA[1]+1

		hatena+=1

	wayA%=MOD2

	wayB%=MOD2

	wayC%=MOD2

ans=0

for i in range(0,4):

	ans=ans+pow(3,hatena-i)*wayC[i]

	ans=ans%MOD

print((int(ans)))

import numpy as np

s = eval(input())
n = len(s)
MOD = 1000000007
wayA = np.array([0, 0, 0, 0], dtype=np.int64)
wayB = np.array([0, 0, 0, 0], dtype=np.int64)
wayC = np.array([0, 0, 0, 0], dtype=np.int64)
MOD2 = np.array([MOD, MOD, MOD, MOD], dtype=np.int32)
hatena = 0
for c in s:
    if c == "A":
        wayA[0] += 1
    if c == "B":
        wayB += wayA
    if c == "C":
        wayC += wayB
    if c == "?":
        wayC[1] = wayC[1] + wayB[0]
        wayC[2] = wayC[2] + wayB[1]
        wayC[3] = wayC[3] + wayB[2]
        wayB[1] = wayB[1] + wayA[0]
        wayB[2] = wayB[2] + wayA[1]
        wayA[1] = wayA[1] + 1
        hatena += 1
    wayA %= MOD2
    wayB %= MOD2
    wayC %= MOD2
ans = 0
for i in range(0, 4):
    p3 = 1
    for k in range(0, hatena - i):
        p3 = p3 * 3
        p3 = p3 % MOD
    ans = ans + p3 * wayC[i]
    ans = ans % MOD
print((int(ans)))

import numpy as np

s = eval(input())
n = len(s)
MOD = 1000000007
wayA = np.array([0, 0, 0, 0], dtype=np.int64)
wayB = np.array([0, 0, 0, 0], dtype=np.int64)
wayC = np.array([0, 0, 0, 0], dtype=np.int64)
MOD2 = np.array([MOD, MOD, MOD, MOD], dtype=np.int32)
hatena = 0
for c in s:
    if c == "A":
        wayA[0] += 1
    if c == "B":
        wayB += wayA
    if c == "C":
        wayC += wayB
    if c == "?":
        wayC[1] = wayC[1] + wayB[0]
        wayC[2] = wayC[2] + wayB[1]
        wayC[3] = wayC[3] + wayB[2]
        wayB[1] = wayB[1] + wayA[0]
        wayB[2] = wayB[2] + wayA[1]
        wayA[1] = wayA[1] + 1
        hatena += 1
    wayA %= MOD2
    wayB %= MOD2
    wayC %= MOD2
ans = 0
for i in range(0, 4):
    ans = ans + pow(3, hatena - i) * wayC[i]
    ans = ans % MOD
print((int(ans)))

+    ans = ans + pow(3, hatena - i) * wayC[i]


Input:
from collections import deque

from itertools import chain

H, W = list(map(int, input().split()))

M = [list(eval(input())) for _ in range(H)]

inf = float('inf')

def flatten(list_of_lists):

    return chain.from_iterable(list_of_lists)

def bfs(start, end):

    distance = [[inf for i in range(W)] for j in range(H)]

    queue = deque([(end, start)])

    distance[end][start] = 0

    while queue:

        y, x = queue.pop()

        for i in range(0, 4):

            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

            if 0 <= nx < W and 0 <= ny < H and M[ny][nx] != '#' and distance[ny][nx] == inf:

                queue.appendleft((ny, nx))

                distance[ny][nx] = distance[y][x] + 1

    return distance

m = 0

for i in range(W):

    for j in range(H):

        if M[j][i] != "#":

            for length in list(flatten(bfs(i, j))):

                if length != inf and m < length:

                    m = length

print(m)

from collections import deque

from itertools import chain

H, W = list(map(int, input().split()))

M = [list(eval(input())) for _ in range(H)]

inf = float('inf')

def flatten(list_of_lists):

    return chain.from_iterable(list_of_lists)

def bfs(start, end):

    distance = [[inf for _ in range(W)] for _ in range(H)]

    queue = deque([(end, start)])

    distance[end][start] = 0

    while queue:

        y, x = queue.pop()

        for i in range(0, 4):

            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

            if 0 <= nx < W and 0 <= ny < H and M[ny][nx] != '#' and distance[ny][nx] == inf:

                queue.appendleft((ny, nx))

                distance[ny][nx] = distance[y][x] + 1

    return distance

m = 0

for i in range(W):

    for j in range(H):

        if M[j][i] != "#":

            for length in list(flatten(bfs(i, j))):

                if length != inf and m < length:

                    m = length

print(m)

from collections import deque
from itertools import chain

H, W = list(map(int, input().split()))
M = [list(eval(input())) for _ in range(H)]
inf = float("inf")

def flatten(list_of_lists):
    return chain.from_iterable(list_of_lists)

def bfs(start, end):
    distance = [[inf for i in range(W)] for j in range(H)]
    queue = deque([(end, start)])
    distance[end][start] = 0
    while queue:
        y, x = queue.pop()
        for i in range(0, 4):
            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
            if (
                0 <= nx < W
                and 0 <= ny < H
                and M[ny][nx] != "#"
                and distance[ny][nx] == inf
            ):
                queue.appendleft((ny, nx))
                distance[ny][nx] = distance[y][x] + 1
    return distance

m = 0
for i in range(W):
    for j in range(H):
        if M[j][i] != "#":
            for length in list(flatten(bfs(i, j))):
                if length != inf and m < length:
                    m = length
print(m)

from collections import deque
from itertools import chain

H, W = list(map(int, input().split()))
M = [list(eval(input())) for _ in range(H)]
inf = float("inf")

def flatten(list_of_lists):
    return chain.from_iterable(list_of_lists)

def bfs(start, end):
    distance = [[inf for _ in range(W)] for _ in range(H)]
    queue = deque([(end, start)])
    distance[end][start] = 0
    while queue:
        y, x = queue.pop()
        for i in range(0, 4):
            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
            if (
                0 <= nx < W
                and 0 <= ny < H
                and M[ny][nx] != "#"
                and distance[ny][nx] == inf
            ):
                queue.appendleft((ny, nx))
                distance[ny][nx] = distance[y][x] + 1
    return distance

m = 0
for i in range(W):
    for j in range(H):
        if M[j][i] != "#":
            for length in list(flatten(bfs(i, j))):
                if length != inf and m < length:
                    m = length
print(m)

-    distance = [[inf for i in range(W)] for j in range(H)]

+    distance = [[inf for _ in range(W)] for _ in range(H)]


Input:
import sys

from collections import deque

input = sys.stdin.readline

def main():

    n = int( input() )

    input_a = list ( map( int, input().split() ) )

    a = deque( input_a )

    while( len(a) != 1 ):

        x = a.popleft()

        y = a.popleft()

        z = x ^ y

        a.append(z)

    sum = a.popleft()

    ans = []

    for i in input_a:

        x = i ^ sum

        ans.append(x)

    for i in ans:

        print( i , end = ' ' )

main()

n = int( eval(input()) )

a = list( map(int, input().split()) )

x = 0

for i in a:

    x ^= i

print(( * list( [x^y for y in a] ) ))

import sys
from collections import deque

input = sys.stdin.readline

def main():
    n = int(input())
    input_a = list(map(int, input().split()))
    a = deque(input_a)
    while len(a) != 1:
        x = a.popleft()
        y = a.popleft()
        z = x ^ y
        a.append(z)
    sum = a.popleft()
    ans = []
    for i in input_a:
        x = i ^ sum
        ans.append(x)
    for i in ans:
        print(i, end=" ")

main()

n = int(eval(input()))
a = list(map(int, input().split()))
x = 0
for i in a:
    x ^= i
print((*list([x ^ y for y in a])))

-    input_a = list(map(int, input().split()))


Input:
import itertools

n = int(eval(input()))

xy = [list(map(int, input().split())) for _ in range(n)]

ans = []

X = 0

for v in itertools.permutations(list(range(n))):

  cnt = 0

  X += 1

  for i in range(n-1):

    x1,y1 = xy[v[0]][0], xy[v[0]][1]

    x2,y2 = xy[v[1]][0], xy[v[1]][1]

    cnt += ((x1-x2)**2 + (y1-y2)**2)**0.5

  ans.append(cnt)

print((sum(ans)/X))

import itertools

n = int(eval(input()))

xy = [list(map(int, input().split())) for _ in range(n)]

ans = []

for v in itertools.permutations(list(range(n)), n):

    a = 0

    for i in range(len(v)-1):

        x1,y1 = xy[v[i]][0], xy[v[i]][1]

        x2,y2 = xy[v[i+1]][0], xy[v[i+1]][1]

        a += ((x1-x2)**2+(y1-y2)**2)**0.5

    ans.append(a)

print((sum(ans)/len(ans)))

import itertools

n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
ans = []
X = 0
for v in itertools.permutations(list(range(n))):
    cnt = 0
    X += 1
    for i in range(n - 1):
        x1, y1 = xy[v[0]][0], xy[v[0]][1]
        x2, y2 = xy[v[1]][0], xy[v[1]][1]
        cnt += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
    ans.append(cnt)
print((sum(ans) / X))

import itertools

n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
ans = []
for v in itertools.permutations(list(range(n)), n):
    a = 0
    for i in range(len(v) - 1):
        x1, y1 = xy[v[i]][0], xy[v[i]][1]
        x2, y2 = xy[v[i + 1]][0], xy[v[i + 1]][1]
        a += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
    ans.append(a)
print((sum(ans) / len(ans)))

-for v in itertools.permutations(list(range(n))):

+for v in itertools.permutations(list(range(n)), n):


Input:
def main():

    from collections import Counter

    import sys

    n = int(eval(input()))

    a = list(map(int, sys.stdin.readline().split()))

    d = Counter(a)

    base = sum(v * (v - 1) // 2 for v in list(d.values()))

    e = {k: base - (v >= 2) * (v - 1) for k, v in list(d.items())}

    for i in a:

        print((e[i]))

if __name__ == '__main__':

    main()

def main():

    from collections import Counter

    import sys

    eval(input())

    a = list(map(int, sys.stdin.readline().split()))

    d = Counter(a)

    base = sum(v * (v - 1) // 2 for v in list(d.values()))

    e = [str(base - (d[v] - 1)) for v in a]

    print(('\n'.join(e)))

if __name__ == '__main__':

    main()

def main():
    from collections import Counter
    import sys

    n = int(eval(input()))
    a = list(map(int, sys.stdin.readline().split()))
    d = Counter(a)
    base = sum(v * (v - 1) // 2 for v in list(d.values()))
    e = {k: base - (v >= 2) * (v - 1) for k, v in list(d.items())}
    for i in a:
        print((e[i]))

if __name__ == "__main__":
    main()

def main():
    from collections import Counter
    import sys

    eval(input())
    a = list(map(int, sys.stdin.readline().split()))
    d = Counter(a)
    base = sum(v * (v - 1) // 2 for v in list(d.values()))
    e = [str(base - (d[v] - 1)) for v in a]
    print(("\n".join(e)))

if __name__ == "__main__":
    main()

-    e = {k: base - (v >= 2) * (v - 1) for k, v in list(d.items())}

+    e = [str(base - (d[v] - 1)) for v in a]


Input:
from collections import defaultdict

N, M = list(map(int, input().split()))

MOD = 10 ** 9 + 7

prime = defaultdict(int)

for i in range(2, M + 1):

    if i * i > M:

        break

    while M % i == 0:

        prime[i] += 1

        M //= i

if M != 1:

    prime[M] = 1

def comb(n, k):

    ret = 1

    for i in range(1, k + 1):

        ret = ret * (n - i + 1) % MOD

        ret = ret * pow(i, MOD - 2, MOD) % MOD

    return ret

ans = 1

for v in list(prime.values()):

    ans = ans * comb(N + v - 1, N - 1) % MOD

print(ans)

from collections import defaultdict

def prime_factor(n):

    # O(sqrt(N))

    d = defaultdict(int)

    for i in range(2, n + 1):

        if i * i > n:

            break

        while n % i == 0:

            d[i] += 1

            n //= i

    if n != 1:

        d[n] += 1

    return d

MAX = 2 * 10 ** 5 + 10

MOD = 10 ** 9 + 7

# Factorial

fac = [0] * (MAX + 1)

fac[0] = 1

fac[1] = 1

# Inverse

inv = [0] * (MAX + 1)

inv[1] = 1

# Inverse factorial

finv = [0] * (MAX + 1)

finv[0] = 1

finv[1] = 1

for i in range(2, MAX + 1):

    fac[i] = fac[i - 1] * i % MOD

    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD

    finv[i] = finv[i - 1] * inv[i] % MOD

def comb(n, k):

    if n < k or k < 0:

        return 0

    return (fac[n] * finv[k] * finv[n - k]) % MOD

def comb_rep(n, k):

    return comb(n + k - 1, n - 1)

N, M = list(map(int, input().split()))

primes = prime_factor(M)

res = 1

for k in list(primes.values()):

    res *= comb_rep(N, k)

    res %= MOD

print(res)

from collections import defaultdict

N, M = list(map(int, input().split()))
MOD = 10**9 + 7
prime = defaultdict(int)
for i in range(2, M + 1):
    if i * i > M:
        break
    while M % i == 0:
        prime[i] += 1
        M //= i
if M != 1:
    prime[M] = 1

def comb(n, k):
    ret = 1
    for i in range(1, k + 1):
        ret = ret * (n - i + 1) % MOD
        ret = ret * pow(i, MOD - 2, MOD) % MOD
    return ret

ans = 1
for v in list(prime.values()):
    ans = ans * comb(N + v - 1, N - 1) % MOD
print(ans)

from collections import defaultdict

def prime_factor(n):
    # O(sqrt(N))
    d = defaultdict(int)
    for i in range(2, n + 1):
        if i * i > n:
            break
        while n % i == 0:
            d[i] += 1
            n //= i
    if n != 1:
        d[n] += 1
    return d

MAX = 2 * 10**5 + 10
MOD = 10**9 + 7
# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
# Inverse
inv = [0] * (MAX + 1)
inv[1] = 1
# Inverse factorial
finv = [0] * (MAX + 1)
finv[0] = 1
finv[1] = 1
for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def comb(n, k):
    if n < k or k < 0:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % MOD

def comb_rep(n, k):
    return comb(n + k - 1, n - 1)

N, M = list(map(int, input().split()))
primes = prime_factor(M)
res = 1
for k in list(primes.values()):
    res *= comb_rep(N, k)
    res %= MOD
print(res)

+    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD

+    finv[i] = finv[i - 1] * inv[i] % MOD

-        ret = ret * pow(i, MOD - 2, MOD) % MOD

+    return (fac[n] * finv[k] * finv[n - k]) % MOD

-    ans = ans * comb(N + v - 1, N - 1) % MOD


Input:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()

def list2d(a, b, c): return [[c] * b for i in range(a)]

def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1): return int(-(-x // y))

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes(): print('Yes')

def No(): print('No')

def YES(): print('YES')

def NO(): print('NO')

sys.setrecursionlimit(10 ** 9)

INF = 10 ** 18

MOD = 10 ** 9 + 7

N, K = MAP()

S = eval(input())

# ランレングス圧縮

A = []

# 番兵

if S[0] == '0':

    A.append(0)

cur = S[0]

cnt = 1

for i, s in enumerate(S[1:], 1):

    if s != cur:

        A.append(cnt)

        cnt = 1

        cur = s

    else:

        cnt += 1

A.append(cnt)

# 例外処理

if len(A) == 1:

    print(N)

    exit()

# 番兵

if S[-1] == '0':

    A.append(0)

M = len(A)

ans = sm = sum(A[:K*2+1])

for i in range(K*2+1, M):

    sm += A[i]

    # 今回増やすのが0の区間なら、後ろ2つ減る

    if i % 2 == 1:

        if i-K*2 >= 0:

            sm -= A[i-K*2]

        if i-K*2-1 >= 0:

            sm -= A[i-K*2-1]

    ans = max(ans, sm)

print(ans)

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()

def list2d(a, b, c): return [[c] * b for i in range(a)]

def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1): return int(-(-x // y))

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes(): print('Yes')

def No(): print('No')

def YES(): print('YES')

def NO(): print('NO')

sys.setrecursionlimit(10 ** 9)

INF = 10 ** 18

MOD = 10 ** 9 + 7

N, K = MAP()

S = eval(input())

# ランレングス圧縮

# (後の処理がしやすいように、常に1の区間から始まって1の区間で終わる形にする)

A = []

# 番兵

if S[0] == '0':

    A.append(0)

cnt = 1

cur = S[0]

for i, s in enumerate(S[1:], 1):

    if s != cur:

        A.append(cnt)

        cnt = 1

        cur = s

    else:

        cnt += 1

A.append(cnt)

# 例外処理

if len(A) == 1:

    print(N)

    exit()

# 番兵

if S[-1] == '0':

    A.append(0)

M = len(A)

ans = sm = sum(A[:K*2+1])

# 常に1の区間まで取った方が得なので、indexを2ずつ進める

for i in range(K*2+2, M, 2):

    # 前の0の区間と1の区間を増やす

    sm += A[i-1] + A[i]

    # 後ろの0の区間と1の区間を減らす

    if i-K*2-2 >= 0:

        sm -= A[i-K*2-2]

    if i-K*2-1 >= 0:

        sm -= A[i-K*2-1]

    ans = max(ans, sm)

print(ans)

# -*- coding: utf-8 -*-
import sys

def input():
    return sys.stdin.readline().strip()

def list2d(a, b, c):
    return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
    return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
    return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
    return int(-(-x // y))

def INT():
    return int(eval(input()))

def MAP():
    return list(map(int, input().split()))

def LIST(N=None):
    return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
    print("Yes")

def No():
    print("No")

def YES():
    print("YES")

def NO():
    print("NO")

sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, K = MAP()
S = eval(input())
# ランレングス圧縮
A = []
# 番兵
if S[0] == "0":
    A.append(0)
cur = S[0]
cnt = 1
for i, s in enumerate(S[1:], 1):
    if s != cur:
        A.append(cnt)
        cnt = 1
        cur = s
    else:
        cnt += 1
A.append(cnt)
# 例外処理
if len(A) == 1:
    print(N)
    exit()
# 番兵
if S[-1] == "0":
    A.append(0)
M = len(A)
ans = sm = sum(A[: K * 2 + 1])
for i in range(K * 2 + 1, M):
    sm += A[i]
    # 今回増やすのが0の区間なら、後ろ2つ減る
    if i % 2 == 1:
        if i - K * 2 >= 0:
            sm -= A[i - K * 2]
        if i - K * 2 - 1 >= 0:
            sm -= A[i - K * 2 - 1]
    ans = max(ans, sm)
print(ans)

# -*- coding: utf-8 -*-
import sys

def input():
    return sys.stdin.readline().strip()

def list2d(a, b, c):
    return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
    return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
    return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
    return int(-(-x // y))

def INT():
    return int(eval(input()))

def MAP():
    return list(map(int, input().split()))

def LIST(N=None):
    return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
    print("Yes")

def No():
    print("No")

def YES():
    print("YES")

def NO():
    print("NO")

sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, K = MAP()
S = eval(input())
# ランレングス圧縮
# (後の処理がしやすいように、常に1の区間から始まって1の区間で終わる形にする)
A = []
# 番兵
if S[0] == "0":
    A.append(0)
cnt = 1
cur = S[0]
for i, s in enumerate(S[1:], 1):
    if s != cur:
        A.append(cnt)
        cnt = 1
        cur = s
    else:
        cnt += 1
A.append(cnt)
# 例外処理
if len(A) == 1:
    print(N)
    exit()
# 番兵
if S[-1] == "0":
    A.append(0)
M = len(A)
ans = sm = sum(A[: K * 2 + 1])
# 常に1の区間まで取った方が得なので、indexを2ずつ進める
for i in range(K * 2 + 2, M, 2):
    # 前の0の区間と1の区間を増やす
    sm += A[i - 1] + A[i]
    # 後ろの0の区間と1の区間を減らす
    if i - K * 2 - 2 >= 0:
        sm -= A[i - K * 2 - 2]
    if i - K * 2 - 1 >= 0:
        sm -= A[i - K * 2 - 1]
    ans = max(ans, sm)
print(ans)

+# (後の処理がしやすいように、常に1の区間から始まって1の区間で終わる形にする)

-    # 今回増やすのが0の区間なら、後ろ2つ減る

+# 常に1の区間まで取った方が得なので、indexを2ずつ進める

+    # 前の0の区間と1の区間を増やす

+    # 後ろの0の区間と1の区間を減らす


Input:
import sys

readline = sys.stdin.buffer.readline

n = int(readline())

a = list(map(int, readline().split()))

a.sort()

v = 1

for i in a:

  v *= i

  if v > 1000000000000000000:

    print((-1))

    break

  elif v == 0:

    print((0))

    break

else:

  print(v)

import sys

readline = sys.stdin.buffer.readline

n = int(readline())

a = list(map(int, readline().split()))

v = 1

if min(a) == 0:

  print((0))

else:

  for i in a:

    v *= i

    if v > 1000000000000000000:

      print((-1))

      break

  else:

    print(v)


Input:
S = eval(input())

if S.endswith('s'):

  S = S + 'es'

else:

  S = S + 's'

print(S)

S = eval(input())

if S[-1] == "s":

  print((S + "es"))

else:

  print((S + "s"))

S = eval(input())
if S.endswith("s"):
    S = S + "es"
else:
    S = S + "s"
print(S)


Input:
n, x = list(map(int,input().split()))

li = list(input().split())

li = [abs(int(a)-x) for a in li]

def gcd(a,b):

    while a%b!=0:

        a,b = b,a%b

    return b

if n == 1:

    print((abs(li[0])))

elif n == 2:

    print((gcd(li[0],li[1])))

elif n >= 3:

    c = gcd(li[0],li[1])

    #print(c)

    for i in range(2,len(li)-1):

        c = gcd(c,li[i])

    print(c)

n, x = list(map(int,input().split()))

li = list(input().split())

li = [abs(int(a)-x) for a in li]

def gcd(a,b):

    while a%b!=0:

        a,b = b,a%b

    return b

from functools import reduce

a = reduce(gcd,li)

print(a)

n, x = list(map(int, input().split()))
li = list(input().split())
li = [abs(int(a) - x) for a in li]

def gcd(a, b):
    while a % b != 0:
        a, b = b, a % b
    return b

if n == 1:
    print((abs(li[0])))
elif n == 2:
    print((gcd(li[0], li[1])))
elif n >= 3:
    c = gcd(li[0], li[1])
    # print(c)
    for i in range(2, len(li) - 1):
        c = gcd(c, li[i])
    print(c)

n, x = list(map(int, input().split()))
li = list(input().split())
li = [abs(int(a) - x) for a in li]

def gcd(a, b):
    while a % b != 0:
        a, b = b, a % b
    return b

from functools import reduce

a = reduce(gcd, li)
print(a)

-if n == 1:
-    print((abs(li[0])))
-elif n == 2:
-    print((gcd(li[0], li[1])))
-elif n >= 3:
-    c = gcd(li[0], li[1])
-    # print(c)
-    for i in range(2, len(li) - 1):
-        c = gcd(c, li[i])
-    print(c)
+from functools import reduce
+
+a = reduce(gcd, li)
+print(a)


Input:
import sys

sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 10 ** 9 + 7

def resolve():

    n = int(eval(input()))

    S = list(eval(input()) for _ in range(n))

    cnt_AB = 0

    cnt_A = 0

    cnt_B = 0

    res = 0

    for s in S:

        res += s.count("AB")

        if s[0] == "B" and s[-1] == "A":

            cnt_AB += 1

        elif s[0] == "B":

            cnt_B += 1

        elif s[-1] == "A":

            cnt_A += 1

    if cnt_A + cnt_B > 0:

        print((res + cnt_AB + min(cnt_A, cnt_B)))

    else:

        print((res + max(0, cnt_AB - 1)))

if __name__ == '__main__':

    resolve()

import sys

sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

f_inf = float('inf')

mod = 10 ** 9 + 7

def resolve():

    n = int(eval(input()))

    cnt_BA = cnt_A = cnt_B = cnt_AB = 0

    for _ in range(n):

        s = input().rstrip()

        cnt_AB += s.count("AB")

        if s[0] == "B" and s[-1] == "A":

            cnt_BA += 1

        elif s[0] == "B":

            cnt_B += 1

        elif s[-1] == "A":

            cnt_A += 1

    res = cnt_AB + max(0, (cnt_BA - 1)) + min(cnt_A, cnt_B)

    cnt_BA = 1 if cnt_BA >= 1 else 0

    cnt_A = cnt_A - min(cnt_A, cnt_B)

    cnt_B = cnt_B - min(cnt_A, cnt_B)

    if cnt_A != 0 and cnt_BA != 0:

        res += min(cnt_A, cnt_BA)

    elif cnt_B != 0 and cnt_BA != 0:

        res += min(cnt_B, cnt_BA)

    print(res)

if __name__ == '__main__':

    resolve()

import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7

def resolve():
    n = int(eval(input()))
    S = list(eval(input()) for _ in range(n))
    cnt_AB = 0
    cnt_A = 0
    cnt_B = 0
    res = 0
    for s in S:
        res += s.count("AB")
        if s[0] == "B" and s[-1] == "A":
            cnt_AB += 1
        elif s[0] == "B":
            cnt_B += 1
        elif s[-1] == "A":
            cnt_A += 1
    if cnt_A + cnt_B > 0:
        print((res + cnt_AB + min(cnt_A, cnt_B)))
    else:
        print((res + max(0, cnt_AB - 1)))

if __name__ == "__main__":
    resolve()

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7

def resolve():
    n = int(eval(input()))
    cnt_BA = cnt_A = cnt_B = cnt_AB = 0
    for _ in range(n):
        s = input().rstrip()
        cnt_AB += s.count("AB")
        if s[0] == "B" and s[-1] == "A":
            cnt_BA += 1
        elif s[0] == "B":
            cnt_B += 1
        elif s[-1] == "A":
            cnt_A += 1
    res = cnt_AB + max(0, (cnt_BA - 1)) + min(cnt_A, cnt_B)
    cnt_BA = 1 if cnt_BA >= 1 else 0
    cnt_A = cnt_A - min(cnt_A, cnt_B)
    cnt_B = cnt_B - min(cnt_A, cnt_B)
    if cnt_A != 0 and cnt_BA != 0:
        res += min(cnt_A, cnt_BA)
    elif cnt_B != 0 and cnt_BA != 0:
        res += min(cnt_B, cnt_BA)
    print(res)

if __name__ == "__main__":
    resolve()

-    S = list(eval(input()) for _ in range(n))

+    cnt_BA = cnt_A = cnt_B = cnt_AB = 0

-        print((res + cnt_AB + min(cnt_A, cnt_B)))

-        print((res + max(0, cnt_AB - 1)))

+    res = cnt_AB + max(0, (cnt_BA - 1)) + min(cnt_A, cnt_B)


Input:
import sys

input = sys.stdin.readline

N, M = list(map(int, input().split()))

A = [0]*M

B = [0]*M

C = [0]*M

for i in range(M):

    A[i], B[i] = list(map(int, input().split()))

    for c in [int(i) for i in input().split()]:

        C[i] |= 1 << (c - 1)

dp = [[float("inf")] * 2 ** N for _ in range(2)]

dp[0][0] = 0

for i, c in enumerate(C):

    for bit in range(2 ** N):

        if c & bit == bit:

            dp[1][bit] = min(dp[1][bit], dp[0][bit], A[i])

        else:

            dp[1][bit] = min(dp[1][bit], dp[0][bit])

        dp[1][c | bit] = min(dp[0][c | bit], dp[0][bit] + A[i], dp[1][c | bit])

    dp[0], dp[1] = dp[1], dp[0]

print((dp[0][-1] if dp[0][-1] < float("inf") else - 1))

import sys

input = sys.stdin.readline

N, M = list(map(int, input().split()))

A = [0]*M

B = [0]*M

C = [0]*M

for i in range(M):

    A[i], B[i] = list(map(int, input().split()))

    for c in [int(i) for i in input().split()]:

        C[i] |= 1 << (c - 1)

dp = [[float("inf")] * 2 ** N for _ in range(2)]

dp[0][0] = 0

for i, c in enumerate(C):

    for bit in range(2 ** N):

        dp[1][bit] = min(dp[1][bit], dp[0][bit])

        dp[1][c | bit] = min(dp[0][bit] + A[i], dp[1][c | bit])

    dp[0], dp[1] = dp[1], dp[0]

print((dp[0][-1] if dp[0][-1] < float("inf") else - 1))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
    A[i], B[i] = list(map(int, input().split()))
    for c in [int(i) for i in input().split()]:
        C[i] |= 1 << (c - 1)
dp = [[float("inf")] * 2**N for _ in range(2)]
dp[0][0] = 0
for i, c in enumerate(C):
    for bit in range(2**N):
        if c & bit == bit:
            dp[1][bit] = min(dp[1][bit], dp[0][bit], A[i])
        else:
            dp[1][bit] = min(dp[1][bit], dp[0][bit])
        dp[1][c | bit] = min(dp[0][c | bit], dp[0][bit] + A[i], dp[1][c | bit])
    dp[0], dp[1] = dp[1], dp[0]
print((dp[0][-1] if dp[0][-1] < float("inf") else -1))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
    A[i], B[i] = list(map(int, input().split()))
    for c in [int(i) for i in input().split()]:
        C[i] |= 1 << (c - 1)
dp = [[float("inf")] * 2**N for _ in range(2)]
dp[0][0] = 0
for i, c in enumerate(C):
    for bit in range(2**N):
        dp[1][bit] = min(dp[1][bit], dp[0][bit])
        dp[1][c | bit] = min(dp[0][bit] + A[i], dp[1][c | bit])
    dp[0], dp[1] = dp[1], dp[0]
print((dp[0][-1] if dp[0][-1] < float("inf") else -1))


Input:
n = int(eval(input()))

a = int(eval(input()))

q = n % 500

if a >= q:

  print('Yes')

else:

  print('No')

n =int(eval(input()))

a =int(eval(input()))

print(('Yes' if n %500<=a else 'No'))

n = int(eval(input()))
a = int(eval(input()))
q = n % 500
if a >= q:
    print("Yes")
else:
    print("No")

n = int(eval(input()))
a = int(eval(input()))
print(("Yes" if n % 500 <= a else "No"))

+print(("Yes" if n % 500 <= a else "No"))


Input:
N,Q=list(map(int,input().split()))

ans=[0]*N

ki=[[] for _ in range(N)]

for i in range(N-1):

 a,b=list(map(int,input().split()))

 ki[a-1].append(b-1)

 ki[b-1].append(a-1)

for i in range(Q):

 p,q=list(map(int,input().split()))

 ans[p-1]+=q

# dfs

stack = [0]

visited = ["False"] * N

while stack:

 ne = stack.pop()

 if visited[ne] == "False":

  visited[ne] = "True"

  for j in ki[ne]:

   if visited[j] == "False":

    ans[j]+=ans[ne]

    stack.append(j)

L=[str(a) for a in ans]

L=' '.join(L)

print(L)

import sys

input = sys.stdin.readline

N,Q=list(map(int,input().split()))

ans=[0]*N

ki=[[] for _ in range(N)]

for i in range(N-1):

 a,b=list(map(int,input().split()))

 ki[a-1].append(b-1)

 ki[b-1].append(a-1)

for i in range(Q):

 p,q=list(map(int,input().split()))

 ans[p-1]+=q

# dfs

stack = [0]

visited = ["False"] * N

while stack:

 ne = stack.pop()

 if visited[ne] == "False":

  visited[ne] = "True"

  for j in ki[ne]:

   if visited[j] == "False":

    ans[j]+=ans[ne]

    stack.append(j)

L=[str(a) for a in ans]

L=' '.join(L)

print(L)

import sys

input = sys.stdin.readline
N, Q = list(map(int, input().split()))
ans = [0] * N
ki = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    ki[a - 1].append(b - 1)
    ki[b - 1].append(a - 1)
for i in range(Q):
    p, q = list(map(int, input().split()))
    ans[p - 1] += q
# dfs
stack = [0]
visited = ["False"] * N
while stack:
    ne = stack.pop()
    if visited[ne] == "False":
        visited[ne] = "True"
        for j in ki[ne]:
            if visited[j] == "False":
                ans[j] += ans[ne]
                stack.append(j)
L = [str(a) for a in ans]
L = " ".join(L)
print(L)

+import sys
+
+input = sys.stdin.readline


Input:
import numpy as np

n,m=list(map(int,input().split()))

x=list(map(int,input().split()))

arr=np.array(sorted(x))

dif=np.diff(arr)

lis=dif.tolist()

lis=sorted(lis)

for i in range(n-1):

    if len(lis)>0:

        lis.pop()

print((sum(lis)))

import numpy as np

n,m=list(map(int,input().split()))

x=list(map(int,input().split()))

arr=np.sort(np.array(x))

dif=np.diff(arr)

lis=dif.tolist()

lis=sorted(lis)

for i in range(n-1):

    if len(lis)>0:

        lis.pop()

print((sum(lis)))

import numpy as np

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
arr = np.array(sorted(x))
dif = np.diff(arr)
lis = dif.tolist()
lis = sorted(lis)
for i in range(n - 1):
    if len(lis) > 0:
        lis.pop()
print((sum(lis)))

import numpy as np

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
arr = np.sort(np.array(x))
dif = np.diff(arr)
lis = dif.tolist()
lis = sorted(lis)
for i in range(n - 1):
    if len(lis) > 0:
        lis.pop()
print((sum(lis)))

-arr = np.array(sorted(x))
+arr = np.sort(np.array(x))


Input:
n,m,*t=list(map(int,open(0).read().split()))

a=sorted(t[:n])[::-1]

m=0

for c,b in sorted(zip(t[n+1::2],t[n::2]))[::-1]:

 while a and b and c>a[-1]:m+=c;b-=1;a.pop()

print((m+sum(a)))

n,m,*t=list(map(int,open(0).read().split()))

a=sorted(t[:n])[::-1]

m=0

for c,b in sorted(zip(t[n+1::2],t[n::2]))[::-1]:

 while a and c>a[-1]and b:m+=c;b-=1;a.pop()

print((m+sum(a)))

n, m, *t = list(map(int, open(0).read().split()))
a = sorted(t[:n])[::-1]
m = 0
for c, b in sorted(zip(t[n + 1 :: 2], t[n::2]))[::-1]:
    while a and b and c > a[-1]:
        m += c
        b -= 1
        a.pop()
print((m + sum(a)))

n, m, *t = list(map(int, open(0).read().split()))
a = sorted(t[:n])[::-1]
m = 0
for c, b in sorted(zip(t[n + 1 :: 2], t[n::2]))[::-1]:
    while a and c > a[-1] and b:
        m += c
        b -= 1
        a.pop()
print((m + sum(a)))

-    while a and b and c > a[-1]:
+    while a and c > a[-1] and b:


Input:
N = int(eval(input()))

A = list(map(int,input().split()))

cnt = 0

for a in A:

  while a%2 == 0:

    a //= 2

    cnt += 1

print(cnt)

N = int(eval(input()))

A = list(map(int,input().split()))

cnt = 0

for a in A:

  #print(format(a,'b')[::-1])

  #print(format(a,'b')[::-1].index('1'))

  cnt += format(a,'b')[::-1].index('1')

print(cnt)

N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for a in A:
    while a % 2 == 0:
        a //= 2
        cnt += 1
print(cnt)

N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for a in A:
    # print(format(a,'b')[::-1])
    # print(format(a,'b')[::-1].index('1'))
    cnt += format(a, "b")[::-1].index("1")
print(cnt)


Input:
import sys

read = sys.stdin.buffer.read

input = sys.stdin.buffer.readline

inputs = sys.stdin.buffer.readlines

# mod=10**9+7

# rstrip().decode('utf-8')

# map(int,input().split())

# import numpy as np

def main():

	n=int(eval(input()))

	ans=0

	if n>=105:

		ans+=1

	if n>=135:

		ans+=1

	if n>=165:

		ans+=1

	if n>=189:

		ans+=1

	if n>=195:

		ans+=1

	print(ans)

if __name__ == "__main__":

	main()

import sys

input = sys.stdin.buffer.readline

#input = sys.stdin.readline

def II(): return int(eval(input()))

def MI(): return list(map(int,input().split()))

def LI(): return list(map(int,input().split()))

# mod=10**9+7

# rstrip().decode('utf-8')

# map(int,input().split())

def main():

	n=II()

	li=[105,135,165,189,195]

	ans=0

	for i in range(n+1):

		if i in li:

			ans+=1

	print(ans)

if __name__ == "__main__":

	main()

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np
def main():
    n = int(eval(input()))
    ans = 0
    if n >= 105:
        ans += 1
    if n >= 135:
        ans += 1
    if n >= 165:
        ans += 1
    if n >= 189:
        ans += 1
    if n >= 195:
        ans += 1
    print(ans)

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.buffer.readline
# input = sys.stdin.readline
def II():
    return int(eval(input()))

def MI():
    return list(map(int, input().split()))

def LI():
    return list(map(int, input().split()))

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
def main():
    n = II()
    li = [105, 135, 165, 189, 195]
    ans = 0
    for i in range(n + 1):
        if i in li:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

+    return list(map(int, input().split()))


Input:
from collections import defaultdict, Counter

from itertools import product, groupby, count, permutations, combinations

from math import pi, sqrt

from collections import deque

from bisect import bisect, bisect_left, bisect_right

INF = float("inf")

def main():

    N = int(eval(input()))

    ans = 0

    for i in range(10**9):

        if i * i <= N:

            ans = max(ans, i * i)

        else:

            break

    print(ans)

if __name__ == '__main__':

    main()

from collections import defaultdict, Counter

from itertools import product, groupby, count, permutations, combinations

from math import pi, sqrt

from collections import deque

from bisect import bisect, bisect_left, bisect_right

from string import ascii_lowercase

from functools import lru_cache

import sys

sys.setrecursionlimit(10000)

INF = float("inf")

YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"

dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]

def inside(y, x, H, W):

    return 0 <= y < H and 0 <= x < W

def ceil(a, b):

    return (a + b - 1) // b

def main():

    N = int(eval(input()))

    i = 1

    while i * i <= N:

        i += 1

    print(((i - 1) * (i - 1)))

if __name__ == '__main__':

    main()

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right

INF = float("inf")

def main():
    N = int(eval(input()))
    ans = 0
    for i in range(10**9):
        if i * i <= N:
            ans = max(ans, i * i)
        else:
            break
    print(ans)

if __name__ == "__main__":
    main()

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys

sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

def ceil(a, b):
    return (a + b - 1) // b

def main():
    N = int(eval(input()))
    i = 1
    while i * i <= N:
        i += 1
    print(((i - 1) * (i - 1)))

if __name__ == "__main__":
    main()

+YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"


Input:
N = int(eval(input()))

a = list(map(int, input().split()))

a.sort()

n = a[-1]

diff = 10**18

r = -1

for ai in a:

    if abs(n-2*ai)<diff:

        diff = abs(n-2*ai)

        r = ai

print((n, r))

import sys

input = sys.stdin.readline

n = int(eval(input()))

a = list(map(int, input().split()))

a.sort()

l = [ai for ai in a[:-1]]

l.sort(key=lambda x: abs(a[-1]/2-x))

print((a[-1], l[0]))

N = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
n = a[-1]
diff = 10**18
r = -1
for ai in a:
    if abs(n - 2 * ai) < diff:
        diff = abs(n - 2 * ai)
        r = ai
print((n, r))

import sys

input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
l = [ai for ai in a[:-1]]
l.sort(key=lambda x: abs(a[-1] / 2 - x))
print((a[-1], l[0]))

+l.sort(key=lambda x: abs(a[-1] / 2 - x))


Input:
# https://atcoder.jp/contests/abc129/submissions/5841482 を参考

N,M = list(map(int, input().split()))

A = [int(eval(input())) for _ in range(M)]

MOD = 10**9 + 7

F = [1]*(N+1)

for j in A:

    F[j-1] = 0

a = 1; b = 0

for i in range(N):

    if not F[i]:    #F[i] == 0

        a, b = 0, a

    else:

        a, b = ((a+b) % MOD), a

print(a)

N, M, *A = list(map(int, open(0).read().split()))

MOD = 10**9 + 7

F = [1]*(N+1)

for j in A:

    F[j-1] = 0

a = 1; b = 0

for i in range(N):

    if not F[i]:    #F[i] == 0

        a, b = 0, a

    else:

        a, b = ((a+b) % MOD), a

print(a)

# https://atcoder.jp/contests/abc129/submissions/5841482 を参考
N, M = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(M)]
MOD = 10**9 + 7
F = [1] * (N + 1)
for j in A:
    F[j - 1] = 0
a = 1
b = 0
for i in range(N):
    if not F[i]:  # F[i] == 0
        a, b = 0, a
    else:
        a, b = ((a + b) % MOD), a
print(a)

N, M, *A = list(map(int, open(0).read().split()))
MOD = 10**9 + 7
F = [1] * (N + 1)
for j in A:
    F[j - 1] = 0
a = 1
b = 0
for i in range(N):
    if not F[i]:  # F[i] == 0
        a, b = 0, a
    else:
        a, b = ((a + b) % MOD), a
print(a)

-A = [int(eval(input())) for _ in range(M)]

+N, M, *A = list(map(int, open(0).read().split()))


Input:
def main():

    n = int(eval(input()))

    a_list = list(map(int, input().split()))

    mean_a = sum(a_list) / n

    diff_list = [abs(a - mean_a) for a in a_list]

    min_a = min(diff_list)

    print((diff_list.index(min_a)))

if __name__ == "__main__":

    main()

def main():

    n = int(eval(input()))

    a_list = list(map(int, input().split()))

    sum_a = sum(a_list)

    min_val = 100

    min_index = 0

    for i, a in enumerate(a_list):

        d = abs(n * a - sum_a)

        if d < min_val:

            min_val = d

            min_index = i

    print(min_index)

if __name__ == "__main__":

    main()

-    diff_list = [abs(a - mean_a) for a in a_list]


Input:
a,b,x = list(map(int,input().split()))

print((b//x-(a-1)//x))

a,b,x = list(map(int,input().split()))

cnt2 = b//x

cnt1 = (a-1)//x

print((cnt2-cnt1))

a, b, x = list(map(int, input().split()))
print((b // x - (a - 1) // x))

a, b, x = list(map(int, input().split()))
cnt2 = b // x
cnt1 = (a - 1) // x
print((cnt2 - cnt1))


Input:
n, k, q = list(map(int, input().split()))

out = [k-q for _ in range(n)]

for _ in range(q):

    a = int(eval(input()))-1

    out[a] += 1

for i in range(n):

    msg = "Yes" if out[i] > 0 else "No"

    print(msg)

n, k, q, *a = list(map(int, open(0).read().split()))

out = [k-q for _ in range(n)]

for i in range(q):

    out[a[i]-1] += 1

for i in out:

    msg = "Yes" if i > 0 else "No"

    print(msg)

n, k, q = list(map(int, input().split()))
out = [k - q for _ in range(n)]
for _ in range(q):
    a = int(eval(input())) - 1
    out[a] += 1
for i in range(n):
    msg = "Yes" if out[i] > 0 else "No"
    print(msg)

n, k, q, *a = list(map(int, open(0).read().split()))
out = [k - q for _ in range(n)]
for i in range(q):
    out[a[i] - 1] += 1
for i in out:
    msg = "Yes" if i > 0 else "No"
    print(msg)

-n, k, q = list(map(int, input().split()))

+n, k, q, *a = list(map(int, open(0).read().split()))

-    msg = "Yes" if out[i] > 0 else "No"


Input:
H, W = list(map(int, input().split()))

S = []

for _ in range(H):

    S.append(list(eval(input())))

d = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]

for i in range(H):

    for j in range(W):

        if S[i][j] == '.':

            cnt = 0

            for r in range(8):

                y = i + d[r][0]

                x = j + d[r][1]

                if 0 <= x < W and 0 <= y < H and S[y][x] == '#':

                        cnt = cnt + 1

            S[i][j] = str(cnt)

for i in range(H):

    print((''.join(S[i])))

H,W=list(map(int,input().split()))

S=[[0 for i in range(W)] for j in range(H)]

for i in range(H):

  a=list(map(str,eval(input())))

  for j in range(W):

    S[i][j]=a[j]

  a=[]

#print(S)

V=[[0 for i in range(W)] for j in range(H)]

for m in range(H):

  for n in range(W):

    if S[m][n]=="#":

      V[m][n]="#"

      continue

    if m > 0 and n > 0 and S[m-1][n-1]=="#":

      V[m][n] += 1

    if m > 0 and S[m-1][n]=="#":

      V[m][n] += 1

    if m > 0 and n < W - 1 and S[m-1][n+1]=="#":

      V[m][n] += 1

    if n > 0 and S[m][n-1]=="#":

      V[m][n] += 1

    if n < W - 1 and S[m][n+1]=="#":

      V[m][n] += 1

    if m < H - 1 and n > 0 and S[m+1][n-1]=="#":

      V[m][n] += 1

    if m < H - 1 and S[m+1][n]=="#":

      V[m][n] += 1

    if m < H - 1 and n < W - 1 and S[m+1][n+1]=="#":

      V[m][n] += 1

a=[]

#print(V)

for k in range(H):

  for l in range(W):

    a.append(V[k][l])

  print(("".join(map(str,a))))

  a=[]

H, W = list(map(int, input().split()))
S = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    a = list(map(str, eval(input())))
    for j in range(W):
        S[i][j] = a[j]
    a = []
# print(S)
V = [[0 for i in range(W)] for j in range(H)]
for m in range(H):
    for n in range(W):
        if S[m][n] == "#":
            V[m][n] = "#"
            continue
        if m > 0 and n > 0 and S[m - 1][n - 1] == "#":
            V[m][n] += 1
        if m > 0 and S[m - 1][n] == "#":
            V[m][n] += 1
        if m > 0 and n < W - 1 and S[m - 1][n + 1] == "#":
            V[m][n] += 1
        if n > 0 and S[m][n - 1] == "#":
            V[m][n] += 1
        if n < W - 1 and S[m][n + 1] == "#":
            V[m][n] += 1
        if m < H - 1 and n > 0 and S[m + 1][n - 1] == "#":
            V[m][n] += 1
        if m < H - 1 and S[m + 1][n] == "#":
            V[m][n] += 1
        if m < H - 1 and n < W - 1 and S[m + 1][n + 1] == "#":
            V[m][n] += 1
a = []
# print(V)
for k in range(H):
    for l in range(W):
        a.append(V[k][l])
    print(("".join(map(str, a))))
    a = []

+S = [[0 for i in range(W)] for j in range(H)]

+V = [[0 for i in range(W)] for j in range(H)]


Input:
import sys

from collections import Counter

def make_prime_checker(n):

    # nまでの自然数が素数かどうかを表すリストを返す  O(nloglogn)

    is_prime = [False, True, False, False, False, True] * (n//6+1)

    del is_prime[n+1:]

    is_prime[1:4] = False, True, True

    for i in range(5, int(n**0.5)+1):

        if is_prime[i]:

            is_prime[i*i::i] = [False] * (n//i-i+1)

    return is_prime

def main():

    Primes = [p for p, is_p in enumerate(make_prime_checker(2200)) if is_p]

    def decomp(n):

        res1 = res2 = 1

        for p in Primes:

            cnt = 0

            while n % p == 0:

                n //= p

                cnt += 1

            cnt %= 3

            if cnt == 1:

                res1 *= p

            elif cnt == 2:

                res2 *= p

        if int(n**0.5)**2 == n:

            res2 *= int(n**0.5)

        else:

            res1 *= n

        return res1 * res2 * res2, res1 * res1 * res2

    N, *S = list(map(int, sys.stdin.buffer.read().split()))

    T = []

    inv_dict = {}

    for s in S:

        t, t_inv = decomp(s)

        T.append(t)

        inv_dict[t] = t_inv

    counter_T = Counter(T)

    ans = 0

    for t, t_cnt in list(counter_T.items()):

        if t == 1:

            ans += 1

            continue

        t_inv = inv_dict[t]

        t_inv_cnt = counter_T[t_inv]

        if t_cnt > t_inv_cnt or (t_cnt == t_inv_cnt and t > t_inv):

            ans += t_cnt

    print(ans)

main()

import sys

from subprocess import Popen, PIPE

from itertools import groupby

from collections import Counter

def main():

    sys.stdin.readline()

    S = sys.stdin.read().split()

    T = []

    inv_dict = {}

    Factors = Popen(["factor"] + S, stdout=PIPE).communicate()[0].split(b"\n")

    for factors in Factors[:-1]:

        factors = list(map(int, factors.split()[1:]))

        t = 1

        t_inv = 1

        for f, group in groupby(factors):

            n = len(list(group)) % 3

            if n == 1:

                t *= f

            elif n == 2:

                t_inv *= f

        t, t_inv = t * t_inv * t_inv, t * t * t_inv

        T.append(t)

        inv_dict[t] = t_inv

    counter_T = Counter(T)

    ans = 0

    for t, t_cnt in list(counter_T.items()):

        if t == 1:

            ans += 1

            continue

        t_inv = inv_dict[t]

        t_inv_cnt = counter_T[t_inv]

        if t_cnt > t_inv_cnt or (t_cnt == t_inv_cnt and t > t_inv):

            ans += t_cnt

    print(ans)

main()

import sys
from collections import Counter

def make_prime_checker(n):
    # nまでの自然数が素数かどうかを表すリストを返す  O(nloglogn)
    is_prime = [False, True, False, False, False, True] * (n // 6 + 1)
    del is_prime[n + 1 :]
    is_prime[1:4] = False, True, True
    for i in range(5, int(n**0.5) + 1):
        if is_prime[i]:
            is_prime[i * i :: i] = [False] * (n // i - i + 1)
    return is_prime

def main():
    Primes = [p for p, is_p in enumerate(make_prime_checker(2200)) if is_p]

    def decomp(n):
        res1 = res2 = 1
        for p in Primes:
            cnt = 0
            while n % p == 0:
                n //= p
                cnt += 1
            cnt %= 3
            if cnt == 1:
                res1 *= p
            elif cnt == 2:
                res2 *= p
        if int(n**0.5) ** 2 == n:
            res2 *= int(n**0.5)
        else:
            res1 *= n
        return res1 * res2 * res2, res1 * res1 * res2

    N, *S = list(map(int, sys.stdin.buffer.read().split()))
    T = []
    inv_dict = {}
    for s in S:
        t, t_inv = decomp(s)
        T.append(t)
        inv_dict[t] = t_inv
    counter_T = Counter(T)
    ans = 0
    for t, t_cnt in list(counter_T.items()):
        if t == 1:
            ans += 1
            continue
        t_inv = inv_dict[t]
        t_inv_cnt = counter_T[t_inv]
        if t_cnt > t_inv_cnt or (t_cnt == t_inv_cnt and t > t_inv):
            ans += t_cnt
    print(ans)

main()

-    # nまでの自然数が素数かどうかを表すリストを返す  O(nloglogn)

-    is_prime = [False, True, False, False, False, True] * (n // 6 + 1)

-    for i in range(5, int(n**0.5) + 1):

-            is_prime[i * i :: i] = [False] * (n // i - i + 1)

-    Primes = [p for p, is_p in enumerate(make_prime_checker(2200)) if is_p]

-        return res1 * res2 * res2, res1 * res1 * res2

-    N, *S = list(map(int, sys.stdin.buffer.read().split()))

+    Factors = Popen(["factor"] + S, stdout=PIPE).communicate()[0].split(b"\n")

+        factors = list(map(int, factors.split()[1:]))

+        for f, group in groupby(factors):

+        t, t_inv = t * t_inv * t_inv, t * t * t_inv


Input:
#!/usr/bin/env python3

from pprint import pprint

from collections import deque, defaultdict

import itertools

import math

import sys

sys.setrecursionlimit(10 ** 6)

input = sys.stdin.buffer.readline

INF = float('inf')

n_nodes, m_edges = list(map(int, input().split()))

edges = []

for _ in range(m_edges):

    u, v = list(map(int, input().split()))

    edges.append([u - 1, v - 1])

# pprint(edges)

def find_root(v):

    if v != parents[v]:

        parents[v] = find_root(parents[v])

    return parents[v]

def has_same_root(u, v):

    return find_root(u) == find_root(v)

def unite(u, v):

    root_u, root_v = find_root(u), find_root(v)

    if root_u == root_v:

        return

    if rank[root_u] < rank[root_v]:

        root_u, root_v = root_v, root_u

    parents[root_v] = root_u

    rank[root_u] += rank[root_v]

res = 0

for i in range(m_edges):

    parents = [i for i in range(n_nodes)]

    rank = [1] * n_nodes

    for j in range(m_edges):

        if i == j:

            continue

        u, v = edges[j]

        if not has_same_root(u, v):

            unite(u, v)

    # pprint(parents)

    count = 0

    for v in range(n_nodes):

        if parents[v] == v:

            count += 1

    if count > 1:

        res += 1

print(res)

#!/usr/bin/env python3

from pprint import pprint

import sys

sys.setrecursionlimit(10 ** 6)

INF = float('inf')

N, M = list(map(int, input().split()))

edges = []

for _ in range(M):

    u, v = list(map(int, input().split()))

    edges.append([u-1, v-1])

# pprint(edges)

# ある辺iを除いた残りの辺にそれぞれに対してuniteの操作を行ったのち、異なるparentsの数を数える

# 連結グラフであれば、異なるparentsの数は1になる

# 非連結グラフであれば、異なるparentsの数は2以上になる

def root(v):

    if parents[v] == v:

        return v

    parents[v] = root(parents[v])

    return parents[v]

def unite(u, v):

    u_root = root(u)

    v_root = root(v)

    if u_root == v_root:

        return

    parents[u_root] = v_root

def same(u, v):

    return root(u) == root(v)

ans = 0

for e_i in edges:

    parents = [i for i in range(N)]

    for e_j in edges:

        if e_i == e_j:

            continue

        u, v = e_j

        if not same(u, v):

            unite(u, v)

    count = 0

    for v in range(N):

        if parents[v] == v:

            count += 1

    if count > 1:

        ans += 1

print(ans)

#!/usr/bin/env python3
from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = float("inf")
n_nodes, m_edges = list(map(int, input().split()))
edges = []
for _ in range(m_edges):
    u, v = list(map(int, input().split()))
    edges.append([u - 1, v - 1])
# pprint(edges)
def find_root(v):
    if v != parents[v]:
        parents[v] = find_root(parents[v])
    return parents[v]

def has_same_root(u, v):
    return find_root(u) == find_root(v)

def unite(u, v):
    root_u, root_v = find_root(u), find_root(v)
    if root_u == root_v:
        return
    if rank[root_u] < rank[root_v]:
        root_u, root_v = root_v, root_u
    parents[root_v] = root_u
    rank[root_u] += rank[root_v]

res = 0
for i in range(m_edges):
    parents = [i for i in range(n_nodes)]
    rank = [1] * n_nodes
    for j in range(m_edges):
        if i == j:
            continue
        u, v = edges[j]
        if not has_same_root(u, v):
            unite(u, v)
    # pprint(parents)
    count = 0
    for v in range(n_nodes):
        if parents[v] == v:
            count += 1
    if count > 1:
        res += 1
print(res)

#!/usr/bin/env python3
from pprint import pprint
import sys

sys.setrecursionlimit(10**6)
INF = float("inf")
N, M = list(map(int, input().split()))
edges = []
for _ in range(M):
    u, v = list(map(int, input().split()))
    edges.append([u - 1, v - 1])
# pprint(edges)
# ある辺iを除いた残りの辺にそれぞれに対してuniteの操作を行ったのち、異なるparentsの数を数える
# 連結グラフであれば、異なるparentsの数は1になる
# 非連結グラフであれば、異なるparentsの数は2以上になる
def root(v):
    if parents[v] == v:
        return v
    parents[v] = root(parents[v])
    return parents[v]

def unite(u, v):
    u_root = root(u)
    v_root = root(v)
    if u_root == v_root:
        return
    parents[u_root] = v_root

def same(u, v):
    return root(u) == root(v)

ans = 0
for e_i in edges:
    parents = [i for i in range(N)]
    for e_j in edges:
        if e_i == e_j:
            continue
        u, v = e_j
        if not same(u, v):
            unite(u, v)
    count = 0
    for v in range(N):
        if parents[v] == v:
            count += 1
    if count > 1:
        ans += 1
print(ans)

-from collections import deque, defaultdict

-n_nodes, m_edges = list(map(int, input().split()))

-        parents[v] = find_root(parents[v])

+# ある辺iを除いた残りの辺にそれぞれに対してuniteの操作を行ったのち、異なるparentsの数を数える

+# 連結グラフであれば、異なるparentsの数は1になる

+# 非連結グラフであれば、異なるparentsの数は2以上になる

-    return find_root(u) == find_root(v)

-    root_u, root_v = find_root(u), find_root(v)

-        root_u, root_v = root_v, root_u

-    parents = [i for i in range(n_nodes)]