Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

h,w = map(int,input().split())
a = []
for i in range(h):
  a.append(input())
 
  used = [True]*(h*w)
  
p = []
for i in range(h):
  for j in range(w):
    if a[i][j] == '#':
      p.append(i*w+j)
      used[i*w+j] = False
 
 
    
res = 0
while p:
    tank = []
    for e in p:
        if e>w-1 and used[e-w]:
            tank.append(e-w)
            used[e-w] = False
        if e%w > 0 and used[e-1]:
            tank.append(e-1)
            used[e-1] = False
        if e<(h-1)*w and used[e+w]:
            tank.append(e+w)
            used[e+w] = False
        if e%w<w-1 and used[e+1]:
            tank.append(e+1)
            used[e+1] =  False
    p = tank
    res += 1
print(res-1)

### FIXED CODE ###

def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

n,m=map(int,input().split())
l=[input().split() for _ in range(m)]
arr=[]
ac,wa=0,0

for r in l:
  p,s=int(r[0]),r[1]
  if s=='AC' and not ([p,'AC'] in arr):
    arr.append([p,s])
  elif s=='WA' and not ([p,'AC'] in arr):
    arr.append([p,s])
for r in arr:
  p,s=r
  if s=='WA' and [p,'AC'] in arr:
    wa+=1
  if s=='AC':
    ac+=1
    
print(ac,wa)

### FIXED CODE ###

n,m=map(int,input().split())
l=[input().split() for _ in range(m)]
arr=[]
ac,wa=0,0
acl=[False for _ in range(n)]
for r in l:
  p,s=int(r[0])-1,r[1]
  if s=='AC' and acl[p]==False:
    arr.append([p,s])
    acl[p]=True
  elif s=='WA' and acl[p]==False:
    arr.append([p,s])
    
for r in arr:
  p,s=r
  if s=='WA' and acl[p]:
    wa+=1
  elif s=='AC':
    ac+=1
    
print(ac,wa)
### BUGGY CODE ###

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from copy import copy

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

    # iである個数
    dp = [[0] * (s + 1) for _ in range(n)]
    dp[0][0] = 2
    if a[0] <= s:
        dp[0][a[0]] = 1

    for i, x in enumerate(a[1:], 1):
        dp[i] = [y * 2 for y in dp[i-1]]
        for j in range(s + 1):
            cur = j + x
            if cur > s:
                continue
            dp[i][cur] += dp[i - 1][j]

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


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

readline = sys.stdin.readline
MOD = 998244353
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from copy import copy

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

    # iである個数
    dp = [[0] * (s + 1) for _ in range(n)]
    dp[0][0] = 2
    if a[0] <= s:
        dp[0][a[0]] = 1

    for i, x in enumerate(a[1:], 1):
        dp[i] = [y * 2 % MOD for y in dp[i - 1]]
        for j in range(s + 1):
            cur = j + x
            if cur > s:
                break
            dp[i][cur] += dp[i - 1][j]

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


if __name__ == '__main__':
    main()
### BUGGY CODE ###

k, s = [int(i) for i in input().split()]

ans = 0
for i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      if i + j + l == s:
        ans += 1
        break
        
print(ans)

### FIXED CODE ###

k, s = [int(i) for i in input().split()]

ans = 0
for i in range(k+1):
  for j in range(k+1):
    if k >= s-i-j and s-i-j>=0:
      ans += 1
        
print(ans)
### BUGGY CODE ###

from collections import deque
n = int(input())
P = list(map(int, input().split()))
INF = 10**18
MAP = ['#']*(n**2)
DIRC = [(-1, 0), (0, 1), (1, 0), (0, -1)]


def bfs(init_v):
    next_v = deque([init_v])
    dist = [INF]*(n**2)
    dist[to_v(*init_v)] = 0
    MAP[to_v(*init_v)] = '.'
    mincost = INF
    quit = 0
    while next_v:
        if quit:
            break
        i, j = next_v.popleft()
        for di, dj in DIRC:
            x, y = i+di, j+dj
            if x < 0 or y < 0 or n <= x or n <= y:
                if dist[to_v(i, j)] < mincost:
                    mincost = dist[to_v(i, j)]
                    if mincost == 0:
                        quit = 1
                        break
                continue
            cost = 0 if MAP[to_v(x, y)] == '.'else 1
            if dist[to_v(x, y)] <= dist[to_v(i, j)]+cost:
                continue
            dist[to_v(x, y)] = dist[to_v(i, j)]+cost
            next_v.append((x, y))
    return dist, mincost


def to_idx(p):
    i, j = divmod(p-1, n)
    return i, j


def to_v(i, j):
    return i*n+j


ans = 0
# よく考えたら、これO(N**4)だった
for p in P:
    dist, mincost = bfs(to_idx(p))
    ans += mincost
print(ans)


### FIXED CODE ###

from collections import deque
n = int(input())
Ps = list(map(lambda x: int(x)-1, input().split()))
cost = [min(i, n-1-i, j, n-1-j) for i in range(n) for j in range(n)]
exist = [1]*(n**2)


def to_idx(p):
    return divmod(p, n)


def to_v(i, j):
    return i*n+j


def bfs(init_v):
    next_v = deque([init_v])
    exist[init_v] = 0
    while next_v:
        v = next_v.popleft()
        i, j = to_idx(v)
        if 0 < i:
            v2 = v-n
            if cost[v2] > cost[v]+exist[v]:
                cost[v2] = cost[v]+exist[v]
                next_v.append(v2)

        if i < n-1:
            v2 = v+n
            if cost[v2] > cost[v]+exist[v]:
                cost[v2] = cost[v]+exist[v]
                next_v.append(v2)

        if 0 < j:
            v2 = v-1
            if cost[v2] > cost[v]+exist[v]:
                cost[v2] = cost[v]+exist[v]
                next_v.append(v2)

        if j < n-1:
            v2 = v+1
            if cost[v2] > cost[v]+exist[v]:
                cost[v2] = cost[v]+exist[v]
                next_v.append(v2)

ans = 0
for p in Ps:
    ans += cost[p]
    bfs(p)
print(ans)
### BUGGY CODE ###

S = input()
N = len(S)

p = 2019
X = [0 for _ in range(p)]
X[0] = 1

dp = X[:]
ans = 0
for i in range(N):
    v = int(S[i])
    np = X[:]
    for k in range(p):
        x = (k * 10 + v) % p
        np[x] += dp[k]
    dp = np[:]
    ans += dp[0] - 1
print(ans)


### FIXED CODE ###

S = input()
N = len(S)

p = 2019
X = [0 for _ in range(p)]
X[0] = 1

dp = X[:]
ans = 0
for i in range(N):
    v = int(S[i])
    np = X[:]
    for k in range(p):
        x = (k * 10 + v) % p
        np[x] += dp[k]
    dp = np[:]
    ans += dp[0] - 1
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    S = input().rstrip()
    Q = int(input())
    reverse_flag = False
    for _ in range(Q):
        q = input().rstrip()
        if q == '1':
            reverse_flag = not reverse_flag
        else:
            _, F, C = q.split()
            if (F == '1' and reverse_flag is False) or (F == '2' and reverse_flag is True):
                S = C + S
            else:
                S = S + C
    if reverse_flag is True:
        print(S[::-1])
    else:
        print(S)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    S = input().rstrip()
    Q = int(input())
    reverse_flag = False
    head = ''
    tail = ''
    for _ in range(Q):
        q = input().rstrip()
        if q == '1':
            reverse_flag = not reverse_flag
        else:
            _, F, C = q.split()
            if (F == '1' and reverse_flag is False) or (F == '2' and reverse_flag is True):
                head += C
            else:
                tail += C
    if reverse_flag is True:
        print(tail[::-1] + S[::-1] + head)
    else:
        print(head[::-1] + S + tail)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

from operator import itemgetter

N = int(input())
xy = sorted([list(map(int, input().split())) + [i] for i in range(N)])
E = []
for i in range(N-1):
  E.append((xy[i+1][0]-xy[i][0],xy[i][2],xy[i+1][2]))
xy.sort(key = itemgetter(1))
for i in range(N-1):
  E.append((xy[i+1][1]-xy[i][1],xy[i][2],xy[i+1][2]))
*p, = range(N)
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y

def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    if px < py:
        p[py] = px
    else:
        p[px] = py
    return 1

E.sort()
ans = 0
for c, v, w in E:
    if unite(v, w):
        ans += c
print(ans)

### FIXED CODE ###

from operator import itemgetter
from heapq import heappush, heappop, heapify

N = int(input())
xy = sorted([list(map(int, input().split())) + [i] for i in range(N)])
G = [[] for i in range(N)]
for i in range(N-1):
  a,b = xy[i][2], xy[i+1][2]
  c = xy[i+1][0]-xy[i][0]
  G[a].append((b,c))
  G[b].append((a,c))
xy.sort(key = itemgetter(1))
for i in range(N-1):
  a,b = xy[i][2], xy[i+1][2]
  c = xy[i+1][1]-xy[i][1]
  G[a].append((b,c))
  G[b].append((a,c))

used = [0]*N
que = [(c, w) for w, c in G[0]]
used[0] = 1
heapify(que)

ans = 0
while que:
    cv, v = heappop(que)
    if used[v]:
        continue
    used[v] = 1
    ans += cv
    for w, c in G[v]:
        if used[w]:
            continue
        heappush(que, (c, w))
print(ans)
### BUGGY CODE ###

a = input().split()
n = int(a[0])
m = int(a[1])
qq = int(a[2])
ll = list()
r = list()

for _ in range(m):
    a = input().split()
    ll.append(int(a[0]))
    r.append(int(a[1]))

p = list()
q = list()

for _ in range(qq):
    a = input().split()
    p.append(int(a[0]))
    q.append(int(a[1]))

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

for i in range(m):
    x[ll[i] - 1][r[i] - 1] += 1

c = list()

for i in range(n):
    c.append(list())
    for j in range(n):
        a = x[i][j]

        if 0 < j:
            a += c[i][j - 1]

        c[i].append(a)

for i in range(qq):
    r = 0

    for j in range(p[i] - 1, q[i]):
        r += c[j][q[i] - 1]
        if 1 < p[i]:
            r -= c[j][p[i] - 2]

    print(r)


### FIXED CODE ###

a = input().split()
n = int(a[0])
m = int(a[1])
qq = int(a[2])

x = [[0] * n for _ in range(n)]

for _ in range(m):
    a = input().split()
    x[int(a[0]) - 1][int(a[1]) - 1] += 1

c = list()

for i in range(n):
    c.append(list())
    for j in range(n):
        a = x[i][j]

        if 0 < j:
            a += c[i][j - 1]

        c[i].append(a)

z = list()

for i in range(n):
    z.append(list())
    for j in range(n):
        a = c[i][j]

        if 0 < i:
            a += z[i - 1][j]

        z[i].append(a)

for _ in range(qq):
    r = 0
    a = input().split()
    p = int(a[0])
    q = int(a[1])

    if 0 < q:
        r += z[q - 1][q - 1]

    if 0 < q and 1 < p:
        r -= z[q - 1][p - 2] + z[p - 2][q - 1]

    if 1 < p:
        r += z[p - 2][p - 2]

    print(r)
### BUGGY CODE ###

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

for i in range(1, N+1):
    print(A.count(i))

### FIXED CODE ###

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

max_A = max(A)

from collections import Counter

dic = Counter(A)

for i in range(1, max_A + 1):
    print(dic[i])

for i in range(max_A + 1, N+1):
    print(0)
### BUGGY CODE ###

import collections

N=int(input())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
c=collections.Counter(A)
x=2*c[A[0]]-1
if x>N-1:
    print(sum(A)-A[0])
    exit()
ans=A[0]*(2*c[A[0]]-1)
A=A[c[A[0]]:]
while x<N-1:
    x+=2*c[A[0]]
    ans+=A[0]*2*c[A[0]]
    if x<N-1:
        A=A[c[A[0]]:]
    else:
        y=x-N+1
        ans-=y*A[0]
print(ans)






        




    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
ans=0
for i in range(1,N):
    ans+=A[i//2]
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
A = []
cnt = 0

for i in range(n-1):
    A.append(a[i])
    x = sum(A) + a[i+1]
    if sum(A) > 0 and x > 0:
        y = abs(x)+1
        cnt += y
        a[i+1] -= y

    elif sum(A) < 0 and x < 0:
        y = abs(sum(A) - a[i+1])-1
        cnt += y
        a[i+1] += y

if sum(a) == 0:
    cnt += 1

print(cnt)

### FIXED CODE ###

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))
### BUGGY CODE ###

import math
goal = 0
n = int(input())
n+=1
for i in range(1,n):
    for j in range(1,n):
        for k in range(1,n):
            list1 = [i,j,k]
            ans = list1[0]
            for m in range(1, 3):
                ans = math.gcd(ans, list1[m])
            goal +=ans

print(goal)

### FIXED CODE ###

import math
goal = 0
n = int(input())
n+=1
for i in range(1,n):
    for j in range(1,n):
        for k in range(1,n):
            list1 = [i,j,k]
            ans = list1[0]
            for m in range(1, 3):
                ans = math.gcd(ans, list1[m])
            goal +=ans

print(goal)
### BUGGY CODE ###

def main():
  N, K = map(int,input().split())
  sett = set()
  ans = float('inf')
  if N%K==0:
    print(0)
    return
  while N not in sett:
    sett.add(N)
    N = abs(N-K)
    ans = min(ans,N)
  print(ans)
  return 
main()

### FIXED CODE ###

def main():
  N, K = map(int,input().split())
  print(min(N%K, K-N%K))
  return 
main()
### BUGGY CODE ###

from collections import deque
N, M = map(int, input().split())
P = list(map(int, input().split()))
K = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    K[x].append(y)
    K[y].append(x)
used = [0]*N
OK = []
for i in range(N):
    P[i] -= 1
    if i == P[i]:
        OK.append(i)
ans = 0
for i in range(N):
    if used[i] == 0:
        used[i] = 1
        S = deque([i])
        Enable = [i]
        Origin = [P[i]]
        while S:
            t = S.popleft()
            for j in K[t]:
                if used[j] == 0:
                    used[j] = 1
                    Enable.append(j)
                    Origin.append(P[j])
                    S.append(j)
    T_1 = list(set(OK + Enable))
    T_2 = list(set(OK + Origin))
    ans = max(ans, len(T_1) + len(T_2) - len(set(T_1 + T_2)))

print(ans)

### FIXED CODE ###

from collections import deque
N, M = map(int, input().split())
P = list(map(int, input().split()))
K = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    K[x].append(y)
    K[y].append(x)
used = [0]*N
OK = []
for i in range(N):
    P[i] -= 1
    if i == P[i]:
        OK.append(i)
ans = 0
for i in range(N):
    if used[i] == 0:
        used[i] = 1
        S = deque([i])
        Enable = [i]
        Origin = [P[i]]
        while S:
            t = S.popleft()
            for j in K[t]:
                if used[j] == 0:
                    used[j] = 1
                    Enable.append(j)
                    Origin.append(P[j])
                    S.append(j)
        T_1 = list(set(OK + Enable))
        T_2 = list(set(OK + Origin))
        ans = max(ans, len(T_1) + len(T_2) - len(set(T_1 + T_2)))

print(ans)
### BUGGY CODE ###

from operator import mul
from functools import reduce
N = int(input())
Aj = list(map(int, input().split()))

ans = reduce(mul, Aj)

if ans > 10**18:
	ans = -1
print(ans)


### FIXED CODE ###

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

ans = 1
ng = False
max = 10**18
for A in Aj:
	if A == 0:
		ans = 0
		break
	if ng or ans*A > max:
		ans = -1
		ng = True
	else:
		ans *= A
print(ans)
### BUGGY CODE ###

def main():
    mod = 2**61-1
    pow3 = [1]*200001
    p = 1
    i3 = pow(3, mod-2, mod)
    for i in range(1, 200001):
        p = p*3 % mod
        pow3[i] = p

    def rolling_hash(seq):
        h = rolling_hash2(seq)
        seq_size = len(seq)
        H0s = [0]*seq_size
        for i, j in enumerate(seq):
            H0s[i] = h
            h = (h-j-1+(j+1)*pow3[n])*i3 % mod
        return H0s

    def rolling_hash2(seq):
        p = 0
        for i, j in enumerate(seq):
            p += (j+1)*pow3[i] % mod
        return p % mod

    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    m = max(a+b)
    a1 = [0]*n
    a2 = [0]*n
    b1 = [0]*n
    memo = [0]*n
    cnt = n

    for k in range(len(bin(m))-2):
        k2 = 2**k
        for i, j in enumerate(a):
            p = j & k2
            a1[i] = p
            a2[i] = p ^ k2
        for i, j in enumerate(b):
            b1[i] = j & k2
        b_hash = rolling_hash2(b1)
        A1 = rolling_hash(a1)
        A2 = rolling_hash(a2)
        for i, j in enumerate(memo):
            if j is None:
                continue
            elif A1[i] == b_hash:
                pass
            elif A2[i] == b_hash:
                memo[i] += k2
            else:
                memo[i] = None
                cnt -= 1
        if cnt == 0:
            return

    for i, j in enumerate(memo):
        if j is not None:
            print(i, j)


main()


### FIXED CODE ###

def main():
    mod = 2**31-1
    pow3 = [1]*200001
    p = 1
    i3 = pow(3, mod-2, mod)
    for i in range(1, 200001):
        p = p*3 % mod
        pow3[i] = p

    def rolling_hash(seq):
        h = 0
        for i, j in enumerate(seq):
            h += (j+1)*pow3[i]
        h %= mod
        H0s = [0]*n
        for i, j in enumerate(seq):
            H0s[i] = h
            h = (h-j-1+(j+1)*pn)*i3 % mod
        return H0s

    def rolling_hash2(seq):
        p = 0
        p2 = 0
        for i, j in enumerate(seq):
            p += (j+1)*pow3[i]
            p2 += (2-j)*pow3[i]
        return p % mod, p2 % mod

    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    m = max(a+b)
    a1 = [0]*n
    b1 = [0]*n
    memo = [0]*n
    cnt = n
    pn = pow3[n]

    for k in range(len(bin(m))-2):
        k2 = 2**k
        for i, j in enumerate(a):
            a1[i] = (j & k2) >> k
        for i, j in enumerate(b):
            b1[i] = (j & k2) >> k
        b_hash, b_hash2 = rolling_hash2(b1)
        A1 = rolling_hash(a1)
        for i, (j, k) in enumerate(zip(memo, A1)):
            if j is None:
                continue
            elif k == b_hash:
                pass
            elif k == b_hash2:
                memo[i] += k2
            else:
                memo[i] = None
                cnt -= 1
        if cnt == 0:
            return

    for i, j in enumerate(memo):
        if j is not None:
            print(i, j)


main()
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
a1 = [a[x*2] for x in range(n//2+n%2)]
a2 = [a[x*2+1] for x in range(n//2)]
sa1 = set(a1)
sa2 = set(a2)
a1set = []
a2set = []

for k in sa1:
    a1set.append([k,a1.count(k)])
for k in sa2:
    a2set.append([k,a2.count(k)])

a1set.sort(key=lambda x:x[1],reverse=True)
a2set.sort(key=lambda x:x[1],reverse=True)
while True:
    if a1set[0][0] != a2set[0][0]:
        print(n-a1set[0][1]-a2set[0][1])
        exit(0)
    elif len(a1set) > 1 and len(a2set) > 1:
        if a1set[0][1] + a2set[1][1] > a2set[0][1] + a1set[1][1]:
            a2set.pop(0)
        else:
            a1set.pop(0)
    elif len(a1set) > 1:
        a1set.pop(0)
    elif len(a2set) > 1:
        a2set.pop(0)
    else:
        print(n - a1set[0][1])
        exit(0)




print(a1, a2)

### FIXED CODE ###

from collections import Counter
n = int(input())
el = [int(i) for i in input().split()]
odd_l = Counter(el[::2])
even_l = Counter(el[1::2])
a1, b1 = odd_l.most_common(1)[0]
a2, b2 = even_l.most_common(1)[0]
if a1 != a2:
    ans = n - b1 - b2
else:
    if len(odd_l) > 1:
        b3 = odd_l.most_common(2)[1][1]
    else:
        b3 = 0
    if len(even_l) > 1:
        b4 = even_l.most_common(2)[1][1]
    else:
        b4 = 0
    ans = min(n - b1 - b4, n - b3 - b2)
print(ans)
### BUGGY CODE ###

n = int(input())
s = input()
d = n - s[::-1].find('.') - 1
c = s[:d].count('#')
d2 = s.find('#')
c2 = s[d2:].count('.')
ans = 10**9
for i in range(n + 1):
    ans = min(ans, s[:i].count('#') + s[i:].count('.'))
print(ans)

### FIXED CODE ###

n = int(input())
s = [1 if c == '#' else 0 for c in input()]
l = [0] * (n + 1)
l2 = [0] * (n + 1)
for i in range(n):
    l[i + 1] = s[i] + l[i]
s = s[::-1]
for i in range(n):
    l2[i + 1] = 1-s[i] + l2[i]
l2 = l2[::-1]
ans = float('inf')
for i in range(n + 1):
    ans = min(ans, l[i] + l2[i])
print(ans)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**9)
    from collections import deque
    mod = 10**9+7
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        x, y = map(int, input().split())
        G[x-1].append(y-1)
        G[y-1].append(x-1)
    que = deque([0])
    children = [[] for _ in range(N)]
    while que:
        v = que.pop()
        for nv in G[v]:
            if children[nv]:
                continue
            children[v].append(nv)
            que.append(nv)   
    memo = [[-1]*2 for _ in range(N)]
    def dp(i, c):
        if memo[i][c] >=0:
            return memo[i][c]
        if c == 1:
            res = 1
            for j in children[i]:
                res*=dp(j, 0)
                res%=mod
            memo[i][c] = res
        else:
            res = 1
            for j in children[i]:
                res*=(dp(j, 0)+dp(j, 1))
                res%=mod
            memo[i][c]= res
        return memo[i][c]
    print((dp(0, 0)+dp(0, 1))%mod)
main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**9)
    from collections import deque
    mod = 10**9+7
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        x, y = map(int, input().split())
        G[x-1].append(y-1)
        G[y-1].append(x-1)
    que = deque([0])
    children = [[] for _ in range(N)]
    while que:
        v = que.pop()
        for nv in G[v]:
            if children[nv]:
                continue
            children[v].append(nv)
            que.append(nv)   
    memo = [[-1]*2 for _ in range(N)]
    def dp(i, c):
        if memo[i][c] >=0:
            return memo[i][c]
        if c == 1:
            res = 1
            for j in children[i]:
                res*=dp(j, 0)
                res%=mod
            memo[i][c] = res
        else:
            res = 1
            for j in children[i]:
                res*=(dp(j, 0)+dp(j, 1))
                res%=mod
            memo[i][c]= res
        return memo[i][c]
    print((dp(0, 0)+dp(0, 1))%mod)
main()
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    for i, j in enumerate(a):
        if j == b:
            a[i] = c
    print(sum(a))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
sm = sum(a)
hm = [0] * (10 ** 5 + 1)
for i in a:
    hm[i] += 1
for _ in range(q):
    b, c = map(int, input().split())
    sm += (c - b) * hm[b]
    hm[c] += hm[b]
    hm[b] = 0
    print(sm)
### BUGGY CODE ###

n = int(input())
a = list(input().split())

for i in range(1,n+1):
    print(a.index(str(i)) + 1, end=' ')
print()

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    ans[a[i]-1] = i + 1
for i in range(n):
    print(ans[i], end=' ')
print()