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

def solve():
    H,W=list(map(int,input().split(' ')))
    darker =[]
    cnt = 0
    for i in range(H):
        darker.append(list(input()))
    for i in range(H):
        darker[i].insert(0,'.')
        darker[i].append('.')
    darker.insert(0,['.' for i in range(W+2)])
    darker.append(['.' for i in range(W+2)])
    while True:
        c = 0
        tmp=[]
        for i in range(1,H+1):
            for j in range(1,W+1):
                if darker[i][j] =='#':
                    c +=1
                    if darker[i-1][j] =='.':
                        tmp.append([i-1,j])
                    if darker[i][j-1] =='.':
                        tmp.append([i,j-1])
                    if darker[i+1][j] == '.':
                        tmp.append([i+1,j])
                    if darker[i][j+1] =='.':
                        tmp.append([i,j+1])
        if c ==H*W:
            break
        for i in range(0,H+2):
            for j in range(0,W+2):
                if [i,j] in tmp:
                    darker[i][j]='#'

        cnt +=1
    return cnt

print(solve())

### FIXED CODE ###

import numpy as np

def solve():
    H,W=map(int,input().split(' '))
    max_value = H+W
    values =[]
    for i in range(H):
      values.append([0 if i == '#' else max_value for i in list(input())])
    values = np.array(values)

    for x in range(W-1):
        values[:,x+1] = np.minimum(values[:,x]+1,values[:,x+1])
    for x in range(W-1,0,-1):
        values[:,x-1] = np.minimum(values[:,x-1],values[:,x]+1)
    for x in range(H-1):
        values[x+1,:] = np.minimum(values[x,:]+1,values[x+1,:])
    print('')
    for x in range(H-1,0,-1):
        values[x-1,:] = np.minimum(values[x,:]+1,values[x-1,:])
    print(np.max(values))
solve()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    _ = int(input())
    hoge = tuple(map(int, input().split()))
    sumn = 0
    mod = 10 ** 9 + 7

    for h in range(len(hoge)):
        if h+1 <= len(hoge):
            for hh in range(h+1, len(hoge)):
                sumn += hoge[h] * hoge[hh]
                sumn %= mod
    print(sumn)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    _ = int(input())
    nums = tuple(map(int, input().split()))
    mod = 10 ** 9 + 7

    num_sum = sum(nums)
    part_sum = sum(map(lambda x: x**2, nums)) # naname

    print((num_sum**2 - part_sum) // 2 % mod)


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

N = int(input())
list = input().split()
H = [int(x) for x in list]

FLAG = True
for i in range(N):
  current = H[i]
  for j in range(i, N):
    if ( (current-H[j])>1):
      FLAG = False

      break;
      
if(FLAG == True):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N = int(input())
list = input().split()
H = [int(x) for x in list]
 
FLAG = True
current = H[N-1]
for i in reversed(range(N-1)):
  if(H[i]-1 > current):
    FLAG = False
    break
  elif(H[i]-1 == current):
    H[i] = H[i] -1
  else:
    H[i] = H[i]
  current = H[i]
  
if(FLAG == True):
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

n=(int)(input())
a = list(input() for i in range(n))
maxi = 0
big = []
#print(a)
for i in range(n):
  temp = a.count(a[i])
  if temp > maxi:
    big = [a[i]]
    maxi = temp
  elif temp == maxi:
    big.append(a[i])
ans = sorted(list(set(big)))
for i in range(len(ans)):
  print(ans[i])

### FIXED CODE ###

n=(int)(input())
a = sorted(list(input() for i in range(n)))
lis = sorted(list(set(a)))
big = [0 for i in range(len(lis))]
maxi = 0
counter = 1
check = 0
#print(a)
for i in range(len(a) - 1):
  #print(a[i])
  if a[i] == a[i + 1]:
    counter += 1
  else:
    big[check] = counter
    counter = 1
    check += 1
else:
  big[-1] = counter
maxi = max(big)
#print(lis, big)
for i in range(len(lis)):
  if big[i] == maxi:
    print(lis[i])
### BUGGY CODE ###

#ABC129D-Lamp.py

#import list
from sys import stdin, setrecursionlimit
from functools import lru_cache

input = stdin.readline
setrecursionlimit(10000)

#constant
H, W = list(map(int,input().split()))
S = [input() for _ in range(H)]

#variable

#function
@lru_cache(maxsize=None)
def L(i,j):
    if S[i-1][j-1] == "#":
        return 0
    elif S[i-1][j-1] == ".":
        if j == 1:
            return 1
        else:
            return L(i,j-1) + 1

@lru_cache(maxsize=None)
def R(i,j):
    if S[i-1][j-1] == "#":
        return 0
    elif S[i-1][j-1] == ".":
        if j == W:
            return 1
        else:
            return R(i,j+1) + 1

@lru_cache(maxsize=None)
def U(i,j):
    if S[i-1][j-1] == "#":
        return 0
    elif S[i-1][j-1] == ".":
        if i == 1:
            return 1
        else:
            return U(i-1,j) + 1

@lru_cache(maxsize=None)
def D(i,j):
    if S[i-1][j-1] == "#":
        return 0
    elif S[i-1][j-1] == ".":
        if i == H:
            return 1
        else:
            return D(i+1,j) + 1

#class

#main function
def main():
    maxScore = 0
    for i in range(1,H+1):
        for j in range(1,W+1):
            score = L(i,j)+R(i,j)+U(i,j)+D(i,j)-3
            if score > maxScore:
                maxScore = score
    print(maxScore)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#ABC129D-Lamp.py

#import list
import sys
import numpy as np

#main function
def main():
    buffer = sys.stdin.buffer
    H, W = list(map(int,buffer.readline().split()))
    S = np.frombuffer(buffer.read(H*(W+1)), dtype="B") == ord(".")
    S = S.reshape((H,W+1))[:,:-1]
    L = np.empty((H,W), dtype="i4")
    R = np.empty((H,W), dtype="i4")
    U = np.empty((H,W), dtype="i4")
    D = np.empty((H,W), dtype="i4")

    L[:,0] = S[:,0]
    for i in range(1,W):
        L[:,i] = (L[:,i-1] + 1) * S[:,i]

    R[:,-1] = S[:,-1]
    for i in range(1,W):
        R[:,-1-i] = (R[:,-i] + 1) * S[:,-1-i]

    U[0] = S[0]
    for i in range(1,H):
        U[i] = (U[i-1] + 1) * S[i]

    D[-1] = S[-1]
    for i in range(1,H):
        D[-1-i] = (D[-i] + 1) * S[-1-i]

    score = L + R + U + D - 3
    print(int(score.max()))


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

import sys

def main():
    S = list(input())
    N = len(S) + 1
    a = []
    for i in range(N):
        a.append(calc(i, S))
    
    print(sum(a))

def calc(i, S):
    if i == 0:
        if S[i] == '<':
            return 0
        else:
            j = 0
            while j < len(S) and S[j] == '>':
                j += 1
            return j
    elif i == len(S):
        if S[i - 1] == '>':
            return 0
        else:
            j = 0
            while j < len(S) and S[i - 1 - j] == '<':
                j += 1
            return j
    else:
        j = 0
        while j < i and S[i - 1 - j] == '<':
            j += 1
        k = 0
        while (i + k) < len(S) and S[i + k] == '>':
            k += 1
        return max(j, k)

main()


### FIXED CODE ###

def main():
    S = list(input())
    N = len(S) + 1
    a = [-1] * N
    for i in range(N):
        if a[i] == -1:
            calc(i, S, a)

    print(sum(a))

def calc(i, S, a):
    if i == 0:
        if S[i] == '<':
            a[i] = 0
        else:
            j = 0
            while j < len(S) and S[j] == '>':
                j += 1
            for k in range(j):
                a[k] = j - k
    elif i == len(S):
        if S[i - 1] == '>':
            a[i] = 0
        else:
            a[i] = a[i - 1] + 1
    else:
        if S[i - 1] == '<' and S[i] == '<':
            a[i] = a[i - 1] + 1
        elif S[i - 1] == '<' and S[i] == '>':
            j = 0
            while (i + j) < len(S) and S[i + j] == '>':
                j += 1
            for l in range(j):
                a[i + l] = j - l
            a[i] = max(a[i - 1] + 1, j)
        elif S[i - 1] == '>' and S[i] == '<':
            a[i] = 0
        elif S[i - 1] == '>' and S[i] == '>':
            a[i] = a[i - 1] - 1

main()
### BUGGY CODE ###

n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
import numpy as np
def func(j):
  dp=np.zeros(3001,np.int64)
  # dp[i]:時間合計i以内に食べれる料理のおいしさ総和
  for i in range(n):
    if j==i:
      continue
    a,b=ab[i]
    dp[a:]=np.maximum(dp[a:],dp[:-a]+b)
  return dp[t-1]
ans=0
for i in range(n):
  ans=max(ans,func(i)+ab[i][1])
print(ans)


### FIXED CODE ###

n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
import numpy as np
ans=0
dp=np.zeros(t,np.int64)
# dp[i]:時間合計i以内に食べれる料理のおいしさ総和の最大
for i in range(n):
  a,b=ab[i]
  ans=max(ans,dp[-1]+b)
  dp[a:]=np.maximum(dp[a:],dp[:-a]+b)
print(ans)
### BUGGY CODE ###

n, a, b = map(int, input().split())
a_count = 0
n_count = 0

while n_count < n:
    for i in range(a):
        if n_count >= n:
            break
        a_count += 1
        n_count += 1
    n_count += b

print(a_count)


### FIXED CODE ###

n, a, b = map(int, input().split())
ans = n // (a+b)*a
rem = n % (a+b)
ans += min(rem, a)
print(ans)
### BUGGY CODE ###

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

a.sort()

result = 0
mod = 10**9+7

def solve(x, y):
    if x == 0:
        return 1
    else:
        x = min(x, y-x)
        r = 1
        for i in range(y-x+1, y+1):
            r *= i
            r %= mod
        for i in range(1, x+1):
            r *= pow(i, mod-2, mod)
            r %= mod
        return r

s, l = 0, 0

for i in range(n-k+1):
    for j in range(i+k-1, n):
        x = solve(k-2, j-i-1)%mod
        s = s+(a[i]*x)%mod
        l = l+(a[j]*x)%mod
print((l-s)%mod)

### FIXED CODE ###

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

a.sort()

result = 0
mod = 10**9+7

 
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
n = 10**5+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
 
for i in range( 2, n+1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


if k==1:
    print(0)
else:
    result = 0
    for i in range(N-k+1):
        result += (a[N-i-1]-a[i])*cmb(N-1-i, k-1)
        result %= mod

    print(result%mod)
### BUGGY CODE ###

hoge = input().split()

N = int(hoge[0])
K = int(hoge[1])
p_list = []

hoge = input().split()

for i in range(N):
  p_list.append(int(hoge[i]))
  
big = 0
for i in range(N-K+1):
  _sum = sum(p_list[i:i+K])
  if _sum > big:
    big = _sum
    
ans = (float(big) / 2) + 0.5 * float(K) 
print(ans)

### FIXED CODE ###

hoge = input().split()

N = int(hoge[0])
K = int(hoge[1])

p_list = list(map(int,input().split()))
  
big = 0
s = [0] * (N+1)
for i in range(N):
  s[i+1] = s[i] + p_list[i]

res = 0
for i in range(N-K+1):
  val = s[K+i] - s[i]
  if res < val:
    res = val

ans = (float(res) / 2) + 0.5 * float(K) 
print(ans)
### BUGGY CODE ###

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=[]
ka=0
sb=[]
kb=0
for i in range(n):
  if ka+a[i]<=k:
    ka+=a[i]
    sa.append(a[i])
  else:
    break
for i in range(m):
  if kb+b[i]<=k:
    kb+=b[i]
    sb.append(b[i])
  else:
    break
ans=max(len(sa),len(sb))
tb=[]
for i in range(len(sa)):
  if sa[i]>k:
    break
  while kb+sa[i]>k:
    kb-=sb[-1]
    sb.pop(-1)
  sb=[sa[i]]+sb
  tb.append(sa[i])
  kb+=sa[i]
  if ans<(len(sb)+len(tb)):
    ans=len(sb)
print(ans)


### FIXED CODE ###

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

sa=[]
ka=0
sb=[]
kb=0
for i in range(n):
  if ka+a[i]<=k:
    ka+=a[i]
    sa.append(a[i])
  else:
    break
for i in range(m):
  if kb+b[i]<=k:
    kb+=b[i]
    sb.append(b[i])
  else:
    break
ans=max(len(sa),len(sb))
tb=[]
for i in range(len(sa)):
  if sa[i]>k:
    break
  while kb+sa[i]>k:
    kb-=sb[-1]
    sb.pop(-1)
  tb.append(sa[i])
  kb+=sa[i]
  if ans<(len(sb)+len(tb)):
    ans=(len(sb)+len(tb))
print(ans)
### BUGGY CODE ###

import numpy as np

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

a.sort(reverse=True)
a = np.array(a)

def isok(i):

    if i <= (p-1):
        return True

    points = a.copy()

    points[i] += m
    points[:(p-1)] += m

    adding_point = m*v-m*p

    if points[i] < points[p-1]:
        return False

    j = n-1
    # okflag = True
    while adding_point > 0:

        if j <= p-2:
            return False

        if i == j:
            j -= 1
            continue
        adding_point -= min(m, points[i]- points[j])

        j -= 1

    return True

if isok(n-1):
    print(n)
    exit()

ok = p-1
ng = n-1

while ng - ok > 1:
    mid = (ok+ng)//2

    if isok(mid):
        ok = mid
    else:
        ng = mid
print(ok+1)


### FIXED CODE ###

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

a.sort(reverse=True)

def isok(i):

    if i <= (p-1):
        return True

    points = a.copy()

    points[i] += m

    adding_point = m*v-m*p

    if points[i] < points[p-1]:
        return False

    j = n-1
    while adding_point > 0:

        if j <= p-2:
            return False

        if i == j:
            j -= 1
            continue
        adding_point -= min(m, points[i]- points[j])

        j -= 1

    return True

if isok(n-1):
    print(n)
    exit()

ok = p-1
ng = n-1

while ng - ok > 1:
    mid = (ok+ng)//2

    if isok(mid):
        ok = mid
    else:
        ng = mid
print(ok+1)
### BUGGY CODE ###

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

li = [0]*n

for i in lr:
    for j in range(i[0]-1,i[1]):
        li[j] += 1
    

print(li.count(m))


### FIXED CODE ###

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

llist = []
rlist = []
for i in range(m):
    l,r = map(int,input().split())
    llist += [l]
    rlist += [r]

print(max(0,min(rlist)-max(llist)+1))
### BUGGY CODE ###

tmp = raw_input()
s = list(set(map(int, raw_input().split())))
tmp = raw_input()
t = sorted(map(int, raw_input().split()))

max_n = s[-1]
ans = 0

for i in t:
	for j in range(len(s)):
		if i == s[j]:
			ans += 1
			break
		elif i <= s[j]:
			break
print ans

### FIXED CODE ###

input()
l = raw_input().split()
input()
print len(set(l) & set(raw_input().split()))
### BUGGY CODE ###

n,m = map(int, input().split())
a_list = [int(a) for a in input().split()]
a_list.sort()
for i in range(m):
    b,c = map(int, input().split())
    for j in range(b):
        if a_list[j]<c:
            a_list[j] = c
        else:
            break
    a_list.sort()
print(sum(a_list))

### FIXED CODE ###

n,m = map(int, input().split())
a_list = [int(a) for a in input().split()]
a_list.sort()
bc_list = [0 for _ in range(m)]
for i in range(m):
    b,c = map(int, input().split())
    bc_list[i] = [b,c]
bc_list.sort(key= lambda x:x[1],reverse=True)
cur = 0
for i in range(m):
    b,c = bc_list[i][0],bc_list[i][1]
    for j in range(b):
        if cur >= n:
            break
        if a_list[cur]>=c:
            break
        else:
            a_list[cur] = c
            cur += 1
    else:
        continue
    break
print(sum(a_list))
### BUGGY CODE ###

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

# 遅延評価で加えてあげるだけ

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
 
g = [[] for _ in range(N+1)]
for a,b in AB:
    g[a].append(b)
    g[b].append(a)
 
cnt = [0] * (N+1)
for p,x in PX:
    cnt[p] += x

def dfs(v, p, add):
    cnt[v] += add
    for nv in g[v]:
        if nv == p:
            continue
        dfs(nv, v, cnt[v])

dfs(1, 0, 0)

print(' '.join(map(str, cnt[1:])))
### BUGGY CODE ###

n,ma,mb=map(int,input().split())
A=[]
for i in range(n):
  a,b,c=map(int,input().split())
  A.append([a,b,c])
DP=[[[float("inf")]*(10*n+1) for _ in range(10*n+1)] for _ in range(n+1)]
DP[0][0][0]=0
for i in range(n):
  a,b,c=A[i][0],A[i][1],A[i][2]
  for j in range(10*(i+1)+1):
    for k in range(10*(i+1)+1):
      if j>=a and k>=b:
        DP[i+1][j][k]=min(DP[i][j-a][k-b]+c,DP[i][j][k])
      else:
        DP[i+1][j][k]=DP[i][j][k]
ans=float("inf")
for i in range(10*n+1):
  for j in range(10*n+1):
    if i*mb==j*ma and i*j!=0:
      ans=min(ans,DP[n][i][j])
print(ans if ans!=float("inf") else -1)

### FIXED CODE ###

n,ma,mb=map(int,input().split())
A=[]
for i in range(n):
  a,b,c=map(int,input().split())
  A.append([a,b,c])
DP=[[[float("inf")]*(10*n+1) for _ in range(10*n+1)] for _ in range(n+1)]
DP[0][0][0]=0
for i in range(n):
  a,b,c=A[i][0],A[i][1],A[i][2]
  for j in range(10*(i+1)+1):
    for k in range(10*(i+1)+1):
      if j>=a and k>=b:
        DP[i+1][j][k]=min(DP[i][j-a][k-b]+c,DP[i][j][k])
      else:
        DP[i+1][j][k]=DP[i][j][k]
ans=float("inf")
for i in range(10*n+1):
  for j in range(10*n+1):
    if i*mb==j*ma and i*j!=0:
      ans=min(ans,DP[n][i][j])
print(ans if ans!=float("inf") else -1)
### BUGGY CODE ###

def main():
    H, W, D = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(H)]

    dic = {i: (-1, -1) for i in range(1, H*W + 1)}
    for h in range(H):
        for w in range(W):
            dic[A[h][w]] = (h+1, w+1)

    Q = int(input())
    for query in range(Q):
        le, ri = (int(i) for i in input().split())
        cur = 0
        while le != ri:
            i, j = dic[le]
            x, y = dic[le + D]
            cur += abs(x - i) + abs(y - j)
            le = le + D
        print(cur)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    H, W, D = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(H)]
    num_to_xy = {}
    d_sum = [[] for _ in range(D)]
    for h in range(H):
        for w in range(W):
            num_to_xy[A[h][w]] = (h+1, w+1)
            d_sum[A[h][w] % D].append((A[h][w]))
    for d in range(D):
        d_sum[d].sort()
        cur = []
        y, x = -1, -1
        j, i = -1, -1
        for i, a in enumerate(d_sum[d]):
            if i == 0:
                y, x = num_to_xy[a]
                continue
            j, i = num_to_xy[a]
            cur.append(abs(x - i) + abs(y - j))
            y, x = j, i
        s = [0] * (len(cur) + 1)
        for i in range(0, len(cur)):
            s[i+1] = s[i] + cur[i]
        d_sum[d] = s
    Q = int(input())
    for q in range(Q):
        le, ri = (int(i) for i in input().split())
        if le % D != 0:
            print(d_sum[le % D][(ri - le % D)//D] -
                  d_sum[le % D][(le - le % D)//D])
        else:
            print(d_sum[le % D][(ri - le % D)//D-1] -
                  d_sum[le % D][(le - le % D)//D-1])


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

s=input()[::-1]
alist=[0]*2019
num=0
lens=len(s)
for i in range(lens):
  num=(num+int(s[i])*(10**i))%2019
  alist[num]+=1
alist[0]+=1
ans=0
for i in range(2019):
  ans+=alist[i]*(alist[i]-1)//2
print(ans)

### FIXED CODE ###

s=input()[::-1]
alist=[0]*2019
num1=0
num2=1/10
lens=len(s)
for i in range(lens):
  num2=int(((num2)*10)%2019)
  num1=(num1+int(s[i])*(num2))%2019
  alist[num1]+=1
alist[0]+=1
ans=0
for i in range(2019):
  ans+=alist[i]*(alist[i]-1)//2
print(ans)
### BUGGY CODE ###

k = int(input())
num = input().split()

ass = 0

for i in range(k):
    for j in range(i+1,k):
        n1 = int(num[i])
        n2 = int(num[j])
        n3 = n1 * n2
        ass += n3

ans = ass % (10**9 + 7)
print(ans)

### FIXED CODE ###

k = int(input())
num = input().split()

l = 0
ass = 0
ans = 0

for i in range(k):
    l += int(num[i])

for i in range(k):
    l -= int(num[i])
    ass += int(num[i]) * l
    

ans = ass % (10**9 + 7 )
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100010)

def main():
    def input():
        return sys.stdin.readline()[:-1]

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

    p = list(map(int,input().split()))
    p = [p[k]-1 for k in range(N)]
    parent = [k for k in range(N)]

    def find(x):
        if parent[x] == x:
            return x
        else:
            return find(parent[x])

    def unite(x,y):
        parent[find(x)] = find(y)

    for k in range(M):
        x, y = map(int,input().split())
        unite(x-1,y-1)

    ans = 0
    for k in range(N):
        if find(k) == find(p[k]):
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(100010)

def main():
    def input():
        return sys.stdin.readline()[:-1]

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

    p = list(map(lambda x: int(x)-1, input().split()))
    parent = [k for k in range(N)]

    def find(x):
        if parent[x] == x:
            return x
        else:
            parent[x] = find(parent[x])
            return find(parent[x])

    def unite(x,y):
        parent[find(x)] = find(y)

    for k in range(M):
        x, y = map(int,input().split())
        unite(x-1,y-1)

    ans = 0
    for k in range(N):
        if find(k) == find(p[k]):
            ans += 1
    print(ans)

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

def cmd(l,command):
    if command == 'deleteFirst':
        l.pop(0)
    elif command == 'deleteLast':
        l.pop(-1)
    else:
        ope, num = command.split()
        num = int(num)
        if ope == 'insert':
            l.insert(0,num)
        else:
            if num in l:
                l.remove(num)


if __name__ == '__main__' :
    l = list()
    n = input()
    for i in range(n):
        cmd(l,raw_input())

    for i in range(len(l)-1):
        print l[i],
    print l[-1]

### FIXED CODE ###

from collections import deque

class MyList(deque):
    def __init__(self):
        self.__init__ = deque
        self.d = {'deleteFirst':self.delF, 'deleteLast':self.delL, 'insert':self.insX, 'delete':self.delX}
    def cmd(self,command):
        if ' ' in command:
            ope, num = command.split()
            num = int(num)
            self.d[ope](num)
        else:
            self.d[command]()
            
    def delF(self):
        self.popleft()

    def delL(self):
        self.pop()

    def insX(self,num):
        self.appendleft(num)

    def delX(self,num):
        if num in self:
            self.remove(num)

if __name__ == '__main__' :
    l = MyList()
    n = input()
    
    for i in range(n):
        l.cmd(raw_input())

    q = deque(l)
    for i in range(len(l)-1):
        print q.popleft(),
    print l[-1]
### BUGGY CODE ###

n=int(input())
s= []
for _ in range(n):
    s.append(input())
count=1
for i in range(1,n):
    for j in range(i):
        if s[i]==s[j]:
            break
    else:
      count=count+1
print(count)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
print(len(set(s)))