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

#!/usr/bin/env python3
#ABC65 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heapify
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(sys.stdin.readline())
par = [i for i in range(n)]
rank = [0]*n
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def union(x,y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

x,y = [],[]
for i in range(n):
    a,b = map(int,sys.stdin.readline().split())
    x.append((a,i))
    y.append((b,i))
x.sort()
y.sort()
h = []
heapify(h)
for i in range(n-1):
    x1, j1 = x[i]
    x2, j2 = x[i+1]
    y1, k1 = y[i]
    y2, k2 = y[i+1]
    heappush(h,(x2-x1, j1, j2))
    heappush(h,(y2-y1, k1, k2))
ans = 0
x = 0
while h:
    w,s,t = heappop(h)
    if find(s) != find(t):
        x += 1
        union(s,t)
        ans += w
    if x == n-1:
        break
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC65 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heapify
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(sys.stdin.readline())
par = [i for i in range(n)]
rank = [0]*n
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def union(x,y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

x,y = [],[]
for i in range(n):
    a,b = map(int,sys.stdin.readline().split())
    x.append((a,i))
    y.append((b,i))
x.sort()
y.sort()
h = []
heapify(h)
for i in range(n-1):
    x1, j1 = x[i]
    x2, j2 = x[i+1]
    y1, k1 = y[i]
    y2, k2 = y[i+1]
    heappush(h,(x2-x1, j1, j2))
    heappush(h,(y2-y1, k1, k2))
ans = 0
x = 0
while h:
    w,s,t = heappop(h)
    if find(s) != find(t):
        x += 1
        union(s,t)
        ans += w
    if x == n-1:
        break
print(ans)
### BUGGY CODE ###

def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    prev= [0] * n
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
            break
        used[v] = True

        for j in range(n):
            if d[j] > d[v]+cost[v][j]:
                prev[j] = v
            d[j] = min(d[j],d[v]+cost[v][j])
    return prev

def main():
    n,w = map(int,input().split()) #n:頂点数　w:辺の数
    checker = [0]
    cost = [[float("inf") for i in range(n)] for i in range(n)] 
    #cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
    for i in range(w):
        x,y= map(int,input().split()) 
        checker.append(x)
        checker.append(y)
        x -= 1
        y -= 1
        cost[x][y] = 1
        cost[y][x] = 1
    checker = list(set(checker))
    if checker == list(range(n+1)):
        print("Yes")
        for i in dijkstra(0,n,w,cost)[1:]:
            print(i + 1)
    else:
        print("No")
 
 
if __name__ == '__main__':
  main()

### FIXED CODE ###

from collections import deque

def bfs(start, line):
    quene = deque([start])
    d = [None] * len(line) # reset distance from start
    d[start] = 0
    ans = [None] * len(line)
    while quene:
        v = quene.popleft()
        for i in line[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                ans[i] = v
                quene.append(i)
    return ans


def main():
    n,w = map(int,input().split()) #n:頂点数　w:辺の数
    checker = [0]
    line = [[] for _ in range(n)]
    for i in range(w):
        x,y= map(int,input().split()) 
        x -= 1
        y -= 1
        line[x].append(y)
        line[y].append(x)
    print("Yes")
    ans = bfs(0,line)
    for i in ans[1:]:
        print(i+1)

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

n = int(input())
a = list(map(int,input().split()))
b = list(a)
c = int(n/2)
for j in range(1,c):
    M = max(b)
    m= min(b)
    b.remove(M)
    b.remove(m)
ML = min(b)
MR = max(b)
for i in range(0,n):
    if a[i] >= MR:
        print(ML)
    else:
        print(MR)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = list(a)
b.sort()
c = int(n/2)
ML=b[c-1]
MR=b[c]
for i in range(0,n):
    if a[i] >= MR:
        print(ML)
    else:
        print(MR)
### BUGGY CODE ###

#142_E
n, m = map(int, input().split())
inf = 10 ** 10
keys = [0 for _ in range(m)]
A = [] 

for i in range(m):
    a, _ = map(int, input().split())
    keys[i] = sum([2 ** (int(c) - 1) for c in input().split()])
    A.append(a)
    
dp = [[inf for _ in range(2 ** n)] for _ in range(m+1)]
dp[0][0] = 0
for i in range(0, m):
    for key in range(2 ** n):
        dp[i+1][key] = dp[i][key]
        
    for key in range(2 ** n):
        dp[i+1][key | keys[i]] = min(dp[i+1][key | keys[i]],
                                     dp[i][key] + A[i])

if dp[m][2 ** n - 1] == inf:
    print(-1)
else:
    print(dp[m][2 ** n - 1])

### FIXED CODE ###

#142_E
n, m = map(int, input().split())
inf = 10 ** 10
keys = [0 for _ in range(m)]
A = [] 

for i in range(m):
    a, _ = map(int, input().split())
    keys[i] = sum([2 ** (int(c) - 1) for c in input().split()])
    A.append(a)
    
dp = [[inf for _ in range(2 ** n)] for _ in range(m+1)]
dp[0][0] = 0
for i in range(0, m):
    for key in range(2 ** n):
        dp[i+1][key] = dp[i][key]
        
    for key in range(2 ** n):
        dp[i+1][key | keys[i]] = min(dp[i+1][key | keys[i]],
                                     dp[i][key] + A[i])

if dp[m][2 ** n - 1] == inf:
    print(-1)
else:
    print(dp[m][2 ** n - 1])
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

h, w = map(int, input().split())
field = []
todo = deque([])

for y in range(h):
    text = input()
    field.append(text)
    for x in range(w):
        if text[x] == '#':
            todo.append([y, x])

dy = [1, -1, 0, 0]
dx = [0, 0, 1, -1]

seen = [[None] * w for _ in range(h)]

for y, x in todo:
    seen[y][x] = 0

while todo:
    y, x = todo.popleft()

    for i in range(4):
        ny, nx = y + dy[i], x + dx[i]

        if ny < 0 or h <= ny or nx < 0 or w <= nx:
            continue
        elif seen[ny][nx] is not None:
            continue
        else:
            seen[ny][nx] = seen[y][x] + 1
            todo.append([ny, nx])

    if not todo:
        print(seen[y][x])


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline

h, w = map(int, input().split())
field = []
todo = deque([])

for y in range(h):
    text = input()
    field.append(text)
    for x in range(w):
        if text[x] == '#':
            todo.append([y, x])

dy = [1, -1, 0, 0]
dx = [0, 0, 1, -1]

seen = [[None] * w for _ in range(h)]

for y, x in todo:
    seen[y][x] = 0

while todo:
    y, x = todo.popleft()

    for i in range(4):
        ny, nx = y + dy[i], x + dx[i]

        if ny < 0 or h <= ny or nx < 0 or w <= nx:
            continue
        elif seen[ny][nx] is not None:
            continue
        else:
            seen[ny][nx] = seen[y][x] + 1
            todo.append([ny, nx])

    if not todo:
        print(seen[y][x])
### BUGGY CODE ###

import heapq
def main():
    N, M, S = map(int, input().split())
    maxS = 50 * (N-1)
    cost = [[] for _ in range(N)]
    for _ in range(M):
        U, V, A, B = map(int, input().split())
        U = U - 1
        V = V - 1
        cost[U].append((A,B,V))
        cost[V].append((A,B,U))
    for i in range(N):
        cost[i].sort()
    r = []
    for _ in range(N):
        C, D = map(int, input().split())
        r.append((C,D))
    time = [-1] * N
    money = [-1] * N
    used = set()
    cities = N
    q = [(0, S, 0)] # time, silver, city
    count = 0
    while cities:
        count += 1
        t, s, ci = heapq.heappop(q)
        if (s, ci) in used or money[ci] >= s:
            continue
        used.add((s, ci))
        if time[ci] == -1:
            time[ci] = t
            money[ci] = s
            cities -= 1
        for a, b, v in cost[ci]:
            if s < a:
                break
            if (s-a, v) not in used and money[v] < s-a:
                heapq.heappush(q, (t+b, s-a, v))
        if s != maxS:
            c, d = r[ci]
            if (s+c, ci) not in used:
                heapq.heappush(q, (t+d, s+c, ci))
    for i in time[1:]:
        print(i)
main()


### FIXED CODE ###

import heapq
def main():
    N, M, S = map(int, input().split())
    maxS = 50 * (N-1)
    cost = [[] for _ in range(N)]
    for _ in range(M):
        U, V, A, B = map(int, input().split())
        U = U - 1
        V = V - 1
        cost[U].append((A,B,V))
        cost[V].append((A,B,U))
    for i in range(N):
        cost[i].sort()
    r = []
    for _ in range(N):
        C, D = map(int, input().split())
        r.append((C,D))
    time = [-1] * N
    money = [-1] * N
    used = set()
    cities = N
    q = [(0, S, 0)] # time, silver, city
    count = 0
    while cities:
        count += 1
        t, s, ci = heapq.heappop(q)
        if (s, ci) in used or money[ci] >= s:
            continue
        used.add((s, ci))
        if time[ci] == -1:
            time[ci] = t
            money[ci] = s
            cities -= 1
        for a, b, v in cost[ci]:
            if s < a:
                break
            if (s-a, v) not in used and money[v] < s-a:
                heapq.heappush(q, (t+b, s-a, v))
        if s != maxS:
            c, d = r[ci]
            m = cost[ci][0][0]
            k = max(1, (m-s+c-1)//c)
            if (s+c, ci) not in used:
                heapq.heappush(q, (t+d*k, min(s+c*k, maxS), ci))
    for i in time[1:]:
        print(i)
main()
### BUGGY CODE ###

n,t=map(int,input().split())
a=input().split()
for i in range(n):
    a[i]=int(a[i])
    
big=max(a)

def calc(a,i,saidai):
    if a[i]+saidai>big:return 0
    x=a[i]
    if i==len(a)-1:return 0
    else:return max(a[i+1:])-x

saidai=0
count=0
for i in range(n):
    ans=calc(a,i,saidai)
    if saidai<ans:
        saidai=ans
        count=1
    elif saidai==ans:count+=1
    
print(count)

### FIXED CODE ###

n,t=map(int,input().split())
a=list(map(int,input().split()))
saisyo=a[0]
saidai=0
count=0
for i in range(n):
    if a[i]<saisyo:saisyo=a[i]
    else:
        if a[i]-saisyo>saidai:
            saidai=a[i]-saisyo
            count=1
        elif a[i]-saisyo==saidai:
            count+=1
print(count)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
l=[]; r=[]
for _ in range(Q):
    l1, r1 = map(int, input().split())
    l.append(l1); r.append(r1)
for i in range(Q):
    s = S[l[i]-1:r[i]]
    print(int((r[i]-l[i]+1-len(s.replace("AC","")))/2))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
L = [0]*(N+1)
for i in range(N):
    if S[i:i+2] == "AC":
        L[i+1] = L[i] +1
    else:
        L[i+1] = L[i]
for i in range(Q):
    l,r = map(int, input().split())
    print(L[r-1]-L[l-1])
### BUGGY CODE ###

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

MOD = 10 ** 9 + 7

pos = []
neg = []
for a in A:
    if a >= 0:
        pos.append(a)
    else:
        neg.append(a)

flag = False  # 積を正にできるか

if N == K:
    ans = 1
    for a in A:
        ans *= a % MOD
    print(ans % MOD)
    exit()


if len(pos) > 0:
    flag = True
else:
    if K % 2 == 0:
        flag = True

ans = 1
if not flag:
    # 積を正にできないとき
    # 絶対値の小さい方からK個とる
    A = sorted([abs(x) for x in A])
    for a in A[:K]:
        ans *= a % MOD
    ans *= -1
else:
    pos.sort()
    neg.sort(reverse=True)
    if K % 2 == 1:
        # Kが奇数の時
        # 一番大きい偶数を1つとる。
        ans *= pos.pop() % MOD

    # pos, neg sort -> 2個ずつペア -> 降順sort -> 上から K//2 個とる
    pairs = []
    while len(pos) >= 2:
        x = pos.pop()
        x *= pos.pop()
        pairs.append(x)
    while len(neg) >= 2:
        x = neg.pop()
        x *= neg.pop()
        pairs.append(x)
    pairs = sorted(pairs, reverse=True)
    for p in pairs[: K // 2]:
        ans *= p % MOD

print(ans % MOD)



### FIXED CODE ###

import sys
import heapq

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    MOD = 10 ** 9 + 7

    pos = []
    neg = []
    for a in A:
        if a >= 0:
            pos.append(a)
        else:
            neg.append(a)

    flag = False  # 積を正にできるか

    if N == K:
        ans = 1
        for a in A:
            ans *= a
            ans %= MOD
        print(ans % MOD)
        exit()

    if len(pos) > 0:
        flag = True
    else:
        if K % 2 == 0:
            flag = True

    ans = 1
    if not flag:
        # 積を正にできないとき
        # 絶対値の小さい方からK個とる
        h = [abs(x) for x in A]
        heapq.heapify(h)

        for i in range(K):
            ans *= heapq.heappop(h)
            ans %= MOD
        ans *= -1
    else:
        hpos = [-x for x in pos]
        heapq.heapify(hpos)
        hneg = neg[:]
        heapq.heapify(hneg)
        if K % 2 == 1:
            # Kが奇数の時
            # 一番大きい偶数を1つとる。
            ans *= -heapq.heappop(hpos)
            ans %= MOD

        # pos, neg sort -> 2個ずつペア -> 降順sort -> 上から K//2 個とる
        pairs = []
        while len(hpos) >= 2:
            x = -heapq.heappop(hpos)
            x *= -heapq.heappop(hpos)
            heapq.heappush(pairs, -x)
        while len(hneg) >= 2:
            x = heapq.heappop(hneg)
            x *= heapq.heappop(hneg)
            heapq.heappush(pairs, -x)
        if len(pairs):
            for i in range(K // 2):
                ans *= -heapq.heappop(pairs)
                ans %= MOD

    print(ans % MOD)


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

from collections import Counter
H,W,M = list(map(int,input().split()))

counterH = Counter()
counterW = Counter()
targets = set()
for i in range(M):
    h,w = list(map(int,input().split()))
    counterH[h] += 1
    counterW[w] += 1
    targets.add((h,w))

max_w = 0
max_h = 0
if M == 1:
    print(1)
else:
    ans = 2
    flg = False
    for count_H in counterH.most_common():
        max_h = max(max_h,count_H[1])
        if max_h != count_H[1]:
            break
        for count_W in counterW.most_common():
            max_w = max(max_w,count_W[1])
            if max_w != count_W[1]:
                break
            # print(count_H,count_W)
            if (count_H[0],count_W[0]) in targets:
                ans = max(ans,count_H[1]+count_W[1]-1)
            else:
                ans = max(ans,count_H[1]+count_W[1])
                flg = True
            if flg:
                break
        if flg:
            break
    print(ans)

### FIXED CODE ###

def main():
    from collections import Counter
    H,W,M = list(map(int,input().split()))

    counterH = Counter()
    counterW = Counter()
    targets = set()
    for i in range(M):
        h,w = list(map(int,input().split()))
        counterH[h] += 1
        counterW[w] += 1
        targets.add((h,w))

    most_commonH = counterH.most_common()
    most_commonW = counterW.most_common()
    max_w = most_commonW[0][1]
    max_h = most_commonH[0][1]
    if M == 1:
        print(1)
    else:
        ans = 2
        flg = False
        for count_H in most_commonH:
            if max_h != count_H[1]:
                break
            for count_W in most_commonW:
                if max_w != count_W[1]:
                    break
                # print(count_H,count_W)
                if (count_H[0],count_W[0]) in targets:
                    ans = max(ans,count_H[1]+count_W[1]-1)
                else:
                    ans = max(ans,count_H[1]+count_W[1])
                    flg = True
                if flg:
                    break
            if flg:
                break
        print(ans)

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

N, W = map(int, input().split())
goods = [list(map(int, input().split())) for i in range(N)]
v_sum = sum([i[1] for i in goods])
dp = [float("inf") for i in range(v_sum + 1)]
dp[0] = 0
for i in range(N):
    for j in range(v_sum, -1, -1):
        dp[j] = min(dp[j - goods[i][1]] + goods[i][0], dp[j])
 
for i in range(v_sum, -1, -1):
    if dp[i] <= W:
        print(i)
        break

### FIXED CODE ###

n, w = map(int, input().split())
items = []
 
for i in range(n):
    items.append(list(map(int, input().split())))
 
 
def knapsack(n, w, items):
    c = [[0 for _ in range(w + 1)] for _ in range(n + 1)]
    g = [[0 for _ in range(w + 1)] for _ in range(n + 1)]
 
    for i in range(w + 1):
        c[0][i] = 0
        g[0][i] = 1
 
    for i in range(n + 1):
        c[i][0] = 0
 
    for i in range(1, n + 1):
        for j in range(1, w + 1):
            c[i][j] = c[i - 1][j]
            g[i][j] = 0
            item = items[i - 1]
            if item[0] > j:
                continue
            if item[1] + c[i - 1][j - item[0]] > c[i - 1][j]:
                c[i][j] = item[1] + c[i - 1][j - item[0]]
                g[i][j] = 1
 
    max_value = c[n][w]
    routes = []
    for i in range(n, 0, -1):
        if g[i][w] == 1:
            routes.append(i)
            w -= items[i - 1][0]
    return max_value, routes
 
 
result, _ = knapsack(n, w, items)
print(result)
### BUGGY CODE ###

def gcd(n,m):
    while n:
        m,n = [n,m%n]
    return m

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

S = gcd(A,B)

s = {1}
i = 2
while S != 1:
    while S % i == 0:
        S //= i
        s |= {i}
    i += 1

print(len(s))

### FIXED CODE ###

def gcd(n,m):
    while n:
        m,n = [n,m%n]
    return m

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

S = gcd(A,B)

s = 1
i = 2
while True:
    if S == 1:
        break
    if i ** 2 >= S:
        break
    hoge = 0
    while S % i == 0:
        hoge += 1
        S //= i
    if hoge:
        s += 1
    i += 1

print(s + (S != 1))
### BUGGY CODE ###

s=input()
q=int(input())
check=True
for i in range(q):
    a=input().split()
    if(a[0]=="1"):
        check= not check
    else:
        if(a[1]=="1"):
            if(check):
                s=a[2]+s
            else:
                s+=a[2]
        else:
            if(check):
                s+=a[2]
            else:
                s=a[2]+s
print(s if check else s[::-1])



### FIXED CODE ###

import sys
from collections import deque
s = input()
q = int(input())
dq = deque(s)
rev = False
for i in range(q):
    t = input().split()
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            if rev:
                dq.append(t[2])
            else:
                dq.appendleft(t[2])
        else:
            if rev:
                dq.appendleft(t[2])
            else:
                dq.append(t[2])
s = "".join(list(dq))
if rev:
    print(s[::-1])
else:
    print(s)
### BUGGY CODE ###

n,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
memory = [1]
cur = 1
count = 0
while True:
    if count == k:
        print(cur)
        exit()
    if a[cur] in memory:
        for i in range(len(memory)):
            if memory[i] == a[cur]:
                loop_begin = i
                break
        loop_end = count
        break
    else:
        memory.append(a[cur])
        cur = a[cur]
        count += 1
loop = memory[loop_begin:]
loop_length = loop_end-loop_begin+1
k -= loop_begin
print(loop[k%loop_length])

### FIXED CODE ###

n,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
memory = [1]
dic = {}
cur = 1
count = 0
while True:
    if count == k:
        print(cur)
        exit()
    if a[cur] in dic.keys():
        loop_begin = dic[a[cur]]
        loop_end = count
        break
    else:
        count += 1
        memory.append(a[cur])
        dic[a[cur]] = count
        cur = a[cur]
loop = memory[loop_begin:]
loop_length = loop_end-loop_begin+1
k -= loop_begin
print(loop[k%loop_length])
### BUGGY CODE ###

import collections
n = int(input())
s = [input() for _ in range(n)]
c = collections.Counter(s)
l = [i for i,v in c.items() if v == max(c.values())]
l.sort()
for j in l:
    print(j)

### FIXED CODE ###

import collections
n = int(input())
s = [input() for _ in range(n)]
c = collections.Counter(s)
mv = c.most_common()[0][1]
l = [i for i,v in c.items() if v == mv]
l.sort()
for j in l:
    print(j)
### BUGGY CODE ###

r,g,b,n=map(int,input().split())

ans=0
for i in range(n//r+1):
    for j in range(n//g+1):
        if (n-(i*r+j*g))%b==0 and (n-(i*r+j*g))>=0:
            #print(n-(i*r+j*g))
            ans+=1
print(ans)

### FIXED CODE ###

r,g,b,n=map(int,input().split())

ans=0
for i in range(n//r+1):
    for j in range(n//g+1):
        if (n-(i*r+j*g))%b==0 and (n-(i*r+j*g))>=0:
            #print(n-(i*r+j*g))
            ans+=1
print(ans)
### BUGGY CODE ###

MOD = 1000000007

s = [-1 if x == '?' else int(x) for x in input()]
n = len(s) + 1

dp = [0] * 13
dp[0] = 1

for i, x in enumerate(s):
    next_dp = [0] * 13
    if x == -1:
        for j in range(10):
            for ki in range(13):
                next_dp[(ki * 10 + j) % 13] += dp[ki]
    else:
        for ki in range(13):
                next_dp[(ki * 10 + x) % 13] += dp[ki]
    dp = [k % MOD for k in next_dp]

print(dp[5])

### FIXED CODE ###

MOD = 1000000007

s = [-1 if x == '?' else int(x) for x in input()]
n = len(s) + 1

dp = [0] * 13
dp[0] = 1

r = [[(j-i)*4%13 for i in range(10)]for j in range(13)]

for i, x in enumerate(s):
    next_dp = [0] * 13
    if x == -1:
        next_dp = [sum(dp[i] for i in j) for j in r]
    else:
        next_dp = [dp[j[x]] for j in r]
    dp = [k % MOD for k in next_dp]

print(dp[5])
### BUGGY CODE ###

num=int(input())
list=[[] for i in range(10)]
count=0
for i in range(num):
  a=input()
  la=len(a)
  if a not in list[la-1]:
    list[la-1].append(a)
    count+=1
print(count)

### FIXED CODE ###

num=int(input())
list=[]
for i in range(num):
  a=input()
  list.append(a)
b=set(list)
print(len(b))