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

from collections import deque
import numpy as np

H, W = map(int, input().split())
H += 2; W += 2
grid = []
grid.append("#" * W)
for h in range(H-2):
  grid.append("#" + input() + "#")
grid.append("#" * W)

INF = 10**9
ans = 0
for h in range(1, H-1):
  for w in range(1, W-1):
    
    if grid[h][w]=="#": continue

    dist = np.array([[INF]*W for i in range(H)])
    dist[h][w] = 0 
    q = deque([(h,w)])

    while(q):
      v_h, v_w = q.popleft()
      d_v = dist[v_h][v_w]
      for n_h, n_w in ((v_h, v_w-1),(v_h, v_w+1),(v_h-1, v_w),(v_h+1, v_w)):
        if grid[n_h][n_w]=="#": continue
        d_n = d_v + 1
        if d_n > dist[n_h][n_w]:
          continue
        dist[n_h][n_w] = d_n
        q.append((n_h,n_w))


    
      dist_m = max(x for x in dist.flatten() if x < INF)
      ans = max(ans, dist_m)

print(ans)

      


    

### FIXED CODE ###

from collections import deque
import numpy as np

H,W = map(int,input().split())
maze = [input() for _ in range(H)]

ans = 0
for x in range(H):
    for y in range(W):
        #壁からはスタートできない
        if maze[x][y] == "#":
            continue

        #初期化
        distance = [[0]*W for _ in range(H)]
        #start位置
        stack = deque([[x,y]])

        while stack:
            h,w = stack.popleft()
            for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
                new_h, new_w = h+i, w+j
                if new_h < 0 or new_w < 0 or new_h >= H or new_w >= W:
                    continue
                elif maze[new_h][new_w] != "#" and distance[new_h][new_w] == 0:
                    distance[new_h][new_w] = distance[h][w]+1
                    stack.append([new_h, new_w])

        #start位置は0で初期化
        distance[x][y] = 0
        ans = max(ans, np.max(distance))

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

n=int(input())
cnt=0
A,B=[],[]
for i in range(n):
  a,b=list(map(int,input().split()))
  A.append(a)
  B.append(b)

def f(a,b):
  if a%b==0:
    return 0
  else:
    return (b*(a//b+1)-a)

for i in range(n)[::-1]:
  add=f(A[i],B[i])
  A[:i+1]=map(lambda x:x+add,A[:i+1])
  cnt+=add
print(cnt)

### FIXED CODE ###

n=int(input())
cnt=0
A,B=[],[]
for i in range(n):
  a,b=list(map(int,input().split()))
  A.append(a)
  B.append(b)

for i in range(n)[::-1]:
  if (A[i]+cnt)%B[i]==0:
    continue
  else:
    cnt+=(B[i]*((A[i]+cnt)//B[i]+1)-(A[i]+cnt))
print(cnt)
### BUGGY CODE ###

MAX = 1000000


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

dp = [[-1 for j in range(MAX + 1)] for i in range(n)]
dp[0][0] = 1000
for k in range(1, MAX + 1):
    if 1000 - a[0] * k < 0:
        break
    dp[0][k] = 1000 - a[0] * k
print(dp[0])
for i in range(1, n):
    for j in range(MAX + 1):
        dp[i][j] = max(dp[i][j], dp[i - 1][j])
        # 買うとき
        for k in range(1, MAX + 1):
            if j - k < 0:
                break
            # if dp[i - 1][j - k] - a[i] * k < 0:
            #     break
            dp[i][j] = max(dp[i][j], dp[i - 1][j - k] - a[i] * k)
        # 売る時
        for k in range(1, MAX + 1):
            if j + k >= MAX + 1:
                break
            if dp[i - 1][j + k] < 0:
                break
            dp[i][j] = max(dp[i][j], dp[i - 1][j + k] + a[i] * k)
    print(dp[i])
ans = max(dp[-1])
print(max(ans, 1000))
    # return max(ans, 1000)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
x = []
flag = True
for i in reversed(range(n)):
    if i == 0:
        if not flag:
            x.append(a[i])
        break
    flag2 = flag
    if flag:
        if a[i - 1] < a[i]:
            x.append(a[i])
            flag2 = not flag2
    else:
        if a[i - 1] > a[i]:
            x.append(a[i])
            flag2 = not flag2
    flag = flag2
x = x[::-1]
m = len(x)
if m % 2 == 1:
    x = x[1:]
# print("x =", x)
cur_money = 1000
cur_stock = 0
for i in range(m):
    if i % 2 == 0:
        cur_stock += cur_money // x[i]
        cur_money %= x[i]
    else:
        cur_money += x[i] * cur_stock
        cur_stock = 0
print(cur_money)
### BUGGY CODE ###

k = int(input())

i = 0
n = 0
while True:
  i += 1
  s = str(i)
  for j in range(len(s)-1):
    if (int(s[j]) - int(s[j+1])) not in [-1, 0, 1]:
      break
  else:
    n += 1
    if n == k:
      print(i)
      break

### FIXED CODE ###

from collections import deque
 
k = int(input())
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
 
for i in range(k):
  a = q.popleft()
  if a % 10 == 0:
    q.append(10*a)
    q.append(10*a + 1)
  elif a % 10 == 9:
    q.append(10*a + 8)
    q.append(10*a + 9)
  else:
    q.append(10*a + a%10 - 1)
    q.append(10*a + a%10)
    q.append(10*a + a%10 + 1)
else:
  print(a)
### BUGGY CODE ###

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

for i in range(1, n + 1):
    print(a.count(i))


### FIXED CODE ###

import collections

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

c = collections.Counter(a)

for i in range(1, n + 1):
    if i in c:
        print(c[i])
    else:
        print(0)
### BUGGY CODE ###

# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


A, B, K = invr()
r1 = []
r2 = []
k = K
for i in range(A, B+1):
    if k > 0:
        r1.append(i)
        print(i)
        k -= 1
k = K
for i in range(B, A-1, -1):
    if k > 0:
        if i not in r1:
            r2.append(i)
        k -= 1
r2 = sorted(r2)
for i in r2:
    print(i)


### FIXED CODE ###

# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


A, B, K = invr()
r1 = []
r2 = []
k = K
for i in range(A, B+1):
    if k > 0:
        r1.append(i)
        print(i)
    else:
        break
    k -= 1
k = K
for i in range(B, A-1, -1):
    if k > 0:
        if i not in r1:
            r2.append(i)
    else:
        break
    k -= 1
r2 = sorted(r2)
for i in r2:
    print(i)
### BUGGY CODE ###

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

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

for i in range(m):
    a, b = map(int, input().split())
    for _ in range(a):
        A.append(b)

A = sorted(A)

print(sum(A[-n:]))

### FIXED CODE ###

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

B = []
C = []
for i in range(m):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

D = zip(C, B)
D = sorted(D)
C, B = zip(*D)
C = reversed(C)
B = reversed(B)
total = 0

for i, j in zip(C, B):
    if total >= n:
        break
    else:
        total += j
        A.extend([i] * j)

A = sorted(A)
print(sum(A[-n:]))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush


def solve():
    n = II()
    A = LI()
    # th = pow(10, 18)
    ans = 1
    for a in A:
        ans *= a
        # print(a, ans)
        # if ans > th:
        #     print(-1)
        #     return
    if ans > 1_000_000_000_000_000_000:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush


def solve():
    n = II()
    A = LI()
    th = 1_000_000_000_000_000_000
    ans = 1
    if 0 in A:
        print(0)
        return

    for a in A:
        ans *= a
        # print(a, ans)
        if ans > th:
            print(-1)
            return
    print(ans)


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

def main():
    n = int(input())
    s = [input() for i in range(n)]
    a = [[0] * 26 for _ in range(n)] 
    al = 'abcdefghijklmnopqrstuvwxyz'
    cnt = 0

    for i in range(n):
        for j in s[i]:
            a[i][al.index(j)] += 1 


    for i in range(n-1):
        for j in range(i+1,n):
            if a[i] == a[j]:
                cnt += 1

    print(cnt)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    dic = {}
    cnt = 0

    for i in s:
        if i in dic:
            cnt+=dic[i]
            dic[i]+=1
        else:
            dic[i]=1

    print(cnt)

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

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    for j in range(1, K+1):
        if j <= i:
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
        else:
            break
print(dp[-1])

### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]* N
dp[0] = 0
for j in range(1, N):
    for i in range(max(0, j-K), j):
        dp[j] = min(dp[i]+abs(h[j]-h[i]), dp[j])
print(dp[-1])
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 7)


def func(l, r, taro_turn):
    # [l,r]
    # return taro - jiro
    if l > r:
        return 0

    if taro_turn is None:
        # jiro_turn
        return min(func(l, r - 1, True) - a[r], func(l + 1, r, True) - a[l])
    else:
        # taro_turn
        return max(func(l, r - 1, None) + a[r], func(l + 1, r, None) + a[l])


n = int(input())
a = tuple(int(x) for x in input().split())

print(func(0, n - 1, True))


### FIXED CODE ###

n = int(input())
a = tuple(int(x) for x in input().split())

memo = tuple([None] * n for _ in range(n))
for i, aa in enumerate(a):
    memo[i][i] = aa

for l in range(n - 1, -1, -1):
    for r in range(l, n):
        if memo[l][r] is None:
            memo[l][r] = max(a[r] - memo[l][r - 1], a[l] - memo[l + 1][r])

print(memo[0][n - 1])
### BUGGY CODE ###

N,M = map(int,input().split())
P = []
Y = []
arr = [[]for j in range(10**5+1)]
for i in range(M):
  listA = list(map(int,input().split()))
  P.append(listA[0])
  Y.append(listA[1])
  arr[listA[0]].append(listA[1])
  arr[listA[0]].sort()
for i in range(M):
  for k in range(M):
    if arr[P[i]][k] == Y[i]:
      break
  print(str(P[i]).rjust(6,'0')+str(k+1).rjust(6,'0'))

### FIXED CODE ###

N,M = map(int,input().split())
P = []
Y = []
arr = [[]for j in range(10**5+1)]
for i in range(M):
  listA = list(map(int,input().split()))
  P.append(listA[0])
  Y.append(listA[1])
  arr[listA[0]].append(listA[1])
for i in range(N+1):
  arr[i].sort()
for i in range(M):
  #二部探索
  left = 0
  right = len(arr[P[i]])-1
  while left <= right:
    mid = (left+right)//2
    if arr[P[i]][mid] == Y[i]:
      k = mid
      break
    elif arr[P[i]][mid] > Y[i]:
      right = mid-1
    else:
      left = mid+1
  print(str(P[i]).rjust(6,'0')+str(k+1).rjust(6,'0'))
### BUGGY CODE ###

N = int(input())

sitigosan = ['7', '5', '3']
non_sitigosan = ['0', '1', '2', '4', '6', '8', '9']

cnt = 0
for i in range(1, N+1):
    str_i = str(i)
    flag = True
    for n in sitigosan:
        if n not in str_i:
            flag = False
            break
    if flag :
        for m in non_sitigosan:
            if m in str_i:
                flag = False
                break
    if flag :
        cnt += 1        
        
print(cnt)

### FIXED CODE ###

N = int(input())

def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))
### BUGGY CODE ###

h,w = map(int,input().split())
lis = [list(map(str,input().split("#"))) for i in range(h)]
li = []
for i in range(h):
  s = []
  for j in lis[i]:
    for n in range(len(j)):
      s.append(len(j))
    s.append(0)
  li.append(s)
l = []
for i in range(w):
  s = []
  cou = 0
  for j in range(h):
    if li[j][i] != 0:
      cou += 1
    else:
      cou = 0
    s.append(cou)
  for g in range(h-1):
    if s[-(2+g)] != 0 and s[-(2+g)] < s[-(1+g)]:
      s[-(2+g)] = s[-(1+g)]
  l.append(s)
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans,li[i][j] + l[j][i]-1)
print(ans)

### FIXED CODE ###

h,w = map(int,input().split())
tate = [[0]*w for i in range(h)]
yoko = [[0]*w for i in range(h)]
s = [str(input()) for i in range(h)]

for i in range(h):
    cnt = 0
    now = 0
    for j in range(w):
        if s[i][j] == ".":
            cnt += 1
        else:
            for k in range(now,j+1):
                yoko[i][k] = cnt
            cnt = 0
            now = j+1
    for k in range(now,j+1):
        yoko[i][k] = cnt
for i in range(w):
    cnt = 0
    now = 0
    for j in range(h):
        if s[j][i] == ".":
            cnt += 1
        else:
            for k in range(now,j):
                tate[k][i] = cnt
            cnt = 0
            now = j+1
    for k in range(now,j+1):
        tate[k][i] = cnt
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,tate[i][j]+yoko[i][j]-1)
print(ans)
### BUGGY CODE ###

import bisect

A, B, Q = map(int, input().split())
s = []
sd = {}
for i in range(A):
    x = int(input())
    s.append(x)
    sd[i] = x
t = []
td = {}
for i in range(B):
    x = int(input())
    t.append(x)
    td[i] = x
for i in range(Q):
    x = int(input())
    j = bisect.bisect(s, x)
    ans = 2 * 10 ** 10
    if j > 0:
        k = bisect.bisect(t, sd[j - 1])
        if k > 0:
            ans = min(ans,abs(x-sd[j-1])+abs(sd[j-1]-td[k-1]))
        if k < B:
            ans = min(ans, abs(x-sd[j-1])+abs(sd[j-1]-td[k]))
    if j < A:
        k = bisect.bisect(t, sd[j])
        if k > 0:
            ans = min(ans, abs(x-sd[j])+abs(sd[j]-td[k-1]))
        if k < B:
            ans = min(ans, abs(x-sd[j])+abs(sd[j]-td[k]))
    j = bisect.bisect(t, x)
    if j > 0:
        k = bisect.bisect(s, td[j - 1])
        if k > 0:
            ans = min(ans,abs(x-td[j-1])+abs(td[j-1]-sd[k-1]))
        if k < A:
            ans = min(ans, abs(x-td[j-1])+abs(td[j-1]-sd[k]))
    if j < B:
        k = bisect.bisect(s, td[j])
        if k > 0:
            ans = min(ans, abs(x-td[j])+abs(td[j]-sd[k-1]))
        if k < A:
            ans = min(ans, abs(x-td[j])+abs(td[j]-sd[k]))
    print(ans)

### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline

A, B, Q = map(int, input().split())
s = []
for i in range(A):
    s.append(int(input()))
t = []
for i in range(B):
    t.append(int(input()))
for i in range(Q):
    x = int(input())
    j = bisect.bisect(s, x)
    ans = 2 * 10 ** 10
    if j > 0:
        k = bisect.bisect(t, s[j - 1])
        if k > 0:
            ans = min(ans,abs(x-s[j-1])+abs(s[j-1]-t[k-1]))
        if k < B:
            ans = min(ans, abs(x-s[j-1])+abs(s[j-1]-t[k]))
    if j < A:
        k = bisect.bisect(t, s[j])
        if k > 0:
            ans = min(ans, abs(x-s[j])+abs(s[j]-t[k-1]))
        if k < B:
            ans = min(ans, abs(x-s[j])+abs(s[j]-t[k]))
    j = bisect.bisect(t, x)
    if j > 0:
        k = bisect.bisect(s, t[j - 1])
        if k > 0:
            ans = min(ans,abs(x-t[j-1])+abs(t[j-1]-s[k-1]))
        if k < A:
            ans = min(ans, abs(x-t[j-1])+abs(t[j-1]-s[k]))
    if j < B:
        k = bisect.bisect(s, t[j])
        if k > 0:
            ans = min(ans, abs(x-t[j])+abs(t[j]-s[k-1]))
        if k < A:
            ans = min(ans, abs(x-t[j])+abs(t[j]-s[k]))
    print(ans)
### BUGGY CODE ###

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

dictA = {}

for z in A:
    dictA.setdefault(z, 0)
    dictA[z] += 1


BC = [list(map(int, input().split())) for i in range(Q)]
for x in BC:
    if x[0] in dictA.keys():
        dictA.setdefault(x[1], 0)
        dictA[x[1]] += dictA[x[0]]
        dictA.pop(x[0])
        # print(dictA)

    sumA = 0
    for k, v in dictA.items():
        sumA += k * v
    print(sumA)


### FIXED CODE ###

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

dictA = {}

for z in A:
    dictA.setdefault(z, 0)
    dictA[z] += 1

sumA = sum(A)

BC = [list(map(int, input().split())) for i in range(Q)]
for x in BC:
    if x[0] in dictA.keys():
        sumA += (x[1] - x[0]) * dictA[x[0]]
        dictA.setdefault(x[1], 0)
        dictA[x[1]] += dictA[x[0]]
        dictA.pop(x[0])
    print(sumA)
### BUGGY CODE ###

n = int(input())

S = []
for _ in range(n):
    s = list(input())
    s.sort()
    S.append("".join(s))
S.sort()

C = []
i = 0
while i < n:
    c = S.count(S[i])
    if c > 1:
        C.append(c)
    i += c

ans = 0
for c in C:
    ans += c * (c - 1) // 2

print(ans)


### FIXED CODE ###

n = int(input())

S = []
for _ in range(n):
    s = list(input())
    s.sort()
    S.append("".join(s))
S.sort()

C = []
c = 1
for i in range(n - 1):
    if S[i] == S[i + 1]:
        c += 1
    else:
        C.append(c)
        c = 1
C.append(c)

ans = 0
for c in C:
    ans += c * (c - 1) // 2

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

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

B_i = []

for i in range(1, N + 1):
    B_i.append(str(A_i.index(i) + 1))

print(" ".join(B_i))


### FIXED CODE ###

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

B_i = [0 for s in range(N)]

for i in range(1, N + 1):
    B_i[A_i[i - 1] - 1] = str(i)


print(" ".join(B_i))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = [[] for _ in range(N)]
        self.revE = [[] for _ in range(N)]

    def add_edge(self, s, t, w=1):
        self.E[s].append((t, w))
        self.revE[t].append((s, w))


def solve(N: int, M: int, s: "List[int]", t: "List[int]"):
    c = Counter(s)
    g = Graph(N)
    for ss, tt in zip(s, t):
        g.add_edge(ss, tt, 1/c[ss])

    DP = [0]*N
    for i in range(N-2, -1, -1):
        DP[i] = sum(DP[t] for t, w in g.E[i])/c[i] + 1
    # print(DP)

    gm = DP[0]
    for i in range(N-1):
        if len(g.E[i]) == 1:
            continue
        m = 0
        mj = -1
        for j, _ in g.E[i]:
            if m < DP[j]:
                m = DP[j]
                mj = j
        # print(i, mj)

        dp = [0]*N
        for j in range(N-2, -1, -1):
            if i == j:
                dp[j] = (sum(dp[t] for t, w in g.E[j])-m)/(c[j]-1) + 1
            else:
                dp[j] = sum(dp[t] for t, w in g.E[j])/c[j] + 1
        gm = min(dp[0], gm)
        # print(dp)
    print(gm)


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    t = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))-1
        t[i] = int(next(tokens))-1
    solve(N, M, s, t)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = [[] for _ in range(N)]

    def add_edge(self, s, t, w=1):
        self.E[s].append(t)


def solve(N: int, M: int, s: "List[int]", t: "List[int]"):
    c = Counter(s)
    g = Graph(N)
    for ss, tt in zip(s, t):
        g.add_edge(ss, tt)

    DP = [0]*N
    for i in range(N-2, -1, -1):
        DP[i] = sum(DP[t] for t in g.E[i])/c[i] + 1

    gm = DP[0]
    for i in range(N-2):
        if len(g.E[i]) == 1:
            continue
        dp = DP[:]
        for j in range(i, -1, -1):
            tot, m = 0, 0
            for t in g.E[j]:
                tot += dp[t]
                m = max(dp[t], m)
            if i == j:
                dp[j] = (tot-m)/(c[j]-1)
            else:
                dp[j] = tot/c[j]
            dp[j] += 1
        gm = min(dp[0], gm)
        # print(dp)
    print(gm)


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    t = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))-1
        t[i] = int(next(tokens))-1
    solve(N, M, s, t)


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

import sys
input=sys.stdin.readline
N,K,L=map(int,input().split())
road=[tuple(map(int,input().split())) for _ in range(K)]
metro=[tuple(map(int,input().split())) for _ in range(L)]
inf=float('inf')
def Find(root,x):
    if root[x]<0:
        return x
    if root[x]>=0:
        root[x]=Find(root,root[x])
    return root[x]

def UnionFind(N,branch):
    root=[-1*inf]*(N+1)
    tree=dict()
    for a,b in branch:
        aroot=Find(root,a)
        broot=Find(root,b)
        if root[aroot]<-1*N and root[broot]<-1*N:
            tree[-1*a]={a,b}
            root[a]=-1*a
            root[b]=a
        elif root[broot]<-1*N and root[aroot]>=-1*N:
            tree[root[aroot]]|={b,}
            root[broot]=aroot
        elif root[aroot]<-1*N and root[broot]>=-1*N:
            tree[root[broot]]|={a,}
            root[aroot]=broot
        elif root[aroot]==root[broot]:
            continue
        elif root[aroot]!=root[broot]:
            tree[root[aroot]]|=tree[root[broot]]
            tree.pop(root[broot])
            root[broot]=aroot
    return root,tree

r_root,r_tree=UnionFind(N,road)
m_root,m_tree=UnionFind(N,metro)
ans=''
for i in range(1,N+1):
    ri=Find(r_root,i)
    mi=Find(m_root,i)
    if r_root[ri]<-1*N or m_root[mi]<-1*N:
        ans+='1 '
    else:
        ans+=str(len(r_tree[r_root[ri]]&m_tree[m_root[mi]]))+' '
print(ans[:-1])

### FIXED CODE ###

import sys
input=sys.stdin.readline
N,K,L=map(int,input().split())
road=[tuple(map(int,input().split())) for _ in range(K)]
metro=[tuple(map(int,input().split())) for _ in range(L)]
inf=float('inf')
def Find(root,x):
    if root[x]<0:
        return x
    if root[x]>=0:
        root[x]=Find(root,root[x])
        return root[x]

def UnionFind(N,branch):
    root=[-1]*(N+1)
    for a,b in branch:
        aroot=Find(root,a)
        broot=Find(root,b)
        if aroot==broot:continue
        elif root[aroot]<=root[broot]:
            root[aroot]+=root[broot]
            root[broot]=aroot
        elif root[aroot]>root[broot]:
            root[broot]+=root[aroot]
            root[aroot]=broot
    return root
r_root=UnionFind(N,road)
m_root=UnionFind(N,metro)
from collections import defaultdict
data=[]
cnt=defaultdict(int)
for i in range(1,N+1):
    ri=Find(r_root,i)
    mi=Find(m_root,i)
    data.append((ri,mi))
    cnt[(ri,mi)]+=1
ans=''
for d in data:
    ans+=str(cnt[d])+' '
print(ans[:-1])