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

import numpy as np
import math

# input

N = int(input())
s = [str(input()) for _ in range(N)]

# sort
for i in range(0,N):
    s[i] = sorted(s[i])
    
count = 0 
for i in range(N):
    for j in range(N):
        if (s[i] == s[j]) & (i < j):
            count += 1

print(count)

### FIXED CODE ###

import numpy as np

def Speed_Anag_Count(String):
    count = {}
    for i in String:
        i = sorted(i)
        i = str(''.join(i))
        if count.get(i) is None:
            count[i] = 0
        count[i] += 1
    
    return count

N = int(input())

S = [str(input()) for _ in range(N)]

count = Speed_Anag_Count(S)

ans=0
for i in count.values():
    ans += (i*(i-1)/2)
    
print(int(ans))
### BUGGY CODE ###

#abc 063 c
n=int(input())
s=[]
for i in range(n):
    num=int(input())
    s.append(num)
score_max=100*101
select_i=101
memo=[False]*score_max

def dfs(i,score):
    if i==n:
        memo[score]=True
        return 0
    dfs(i+1,score),
    dfs(i+1,score+s[i])


dfs(0,0)
ans=0
for i in range(score_max):
    if i%10!=0 and memo[i]==True:
        ans=i
print(ans)

### FIXED CODE ###

#abc 063 c
n=int(input())
s=[]
for i in range(n):
    num=int(input())
    s.append(num)

dp=[[False]*11000 for _ in range(110)]
dp[0][0]=True
for i in range(n):
    for j in range(11000):
        if dp[i][j]==True:
            dp[i+1][j]=True
            dp[i+1][j+s[i]]=True

ans=0
for i in range(11000):
    if dp[n][i]==True and i%10!=0:
        ans=i
print(ans)
### BUGGY CODE ###

#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop
import sys
sys.setrecursionlimit(1000000000)

def solve(positions, s, t):
    # print('{}, s = {}, t = {}'.format(positions, s, t))
    ans = 0
    while len(t) > 0:
        if len(positions[t[0]]) == 0:
            return -1

        i = 0
        j = 0
        while i < len(s) and j < len(t):
            candidates = positions[t[j]]
            pos = bisect.bisect_left(candidates, i)
            if pos == len(candidates):
                break

            i = candidates[pos] + 1
            j += 1

        if j == len(t):
            ans += i
            break
        else:
            ans += len(s)
            t = t[j:]

    return ans

def main():
    s = input()
    t = input()

    positions = defaultdict(list)
    for i in range(len(s)):
        positions[s[i]].append(i)

    print(solve(positions, s, t))


if __name__ == '__main__':
    main()


### FIXED CODE ###

#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def solve(positions, s, t):

    if not set(t) <= set(s):
        return -1

    loop = 0
    prev = -1

    for tchar in t:
        candidates = positions[tchar]
        pos = bisect.bisect_right(candidates, prev)

        if pos == len(candidates):
            loop += 1
            pos = 0
        prev = candidates[pos]

    return loop * len(s) + prev + 1


def main():
    s = input()
    t = input()

    positions = defaultdict(list)
    for i in range(len(s)):
        positions[s[i]].append(i)

    print(solve(positions, s, t))


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

from collections import deque
from math import ceil
H,W,K=map(int,input().split())
grid=[input() for i in range(H)]
G={}
                               
for i in range(H):
  for j in range(W):
    if grid[i][j]=="S":
      S=(i,j)
    if grid[i][j]!="#":
      G[(i,j)]=set()
      if i>0:
        if grid[i-1][j]!="#":
          G[(i,j)].add((i-1,j))
      if i<H-1:
        if grid[i+1][j]!="#":
          G[(i,j)].add((i+1,j))
      if j>0:
        if grid[i][j-1]!="#":
          G[(i,j)].add((i,j-1))
      if j<W-1:
        if grid[i][j+1]!="#":
          G[(i,j)].add((i,j+1))
stack=deque([(S[0],S[1],0)])
visited=[[False]*(W) for i in range(H)]
visited[S[0]][S[1]]=True
a=float("inf")
while stack:
  y,x,m=stack.popleft()
  if m>K:
    break
  a=min(a,min(x,W-1-x,y,H-1-y))
  for k in G[(y,x)]:
    if not visited[k[0]][k[1]]:
      stack.append((k[0],k[1],m+1))
      visited[k[0]][k[1]]=True
ans=1+ceil(a/K)
print(ans)


    
        
        
          
  


### FIXED CODE ###

from collections import deque
from math import ceil
H,W,K=map(int,input().split())
grid=[input() for i in range(H)]

for i in range(H):
  for j in range(W):
    if grid[i][j]=="S":
      S=(i,j)

stack=deque([(S[0],S[1],0)])
visited=[[False]*(W) for i in range(H)]
visited[S[0]][S[1]]=True
a=float("inf")
t=[-1,1]
while stack:
  i,j,m=stack.popleft()
  if m>K:
    break
  a=min(a,min(i,H-1-i,j,W-1-j))
  if a==0:
    break
  for s in t:
    if not visited[i+s][j] and grid[i+s][j]!="#":
      stack.append((i+s,j,m+1))
    if not visited[i][j+s] and grid[i][j+s]!="#":
      stack.append((i,j+s,m+1))
    visited[i+s][j]=True
    visited[i][j+s]=True
ans=1+ceil(a/K)
print(ans)
### BUGGY CODE ###

def warshall_floyd(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

import sys
f = sys.stdin

while True:
    n, m = map(int, f.readline().split())
    if n == 0:
        break
    abct = [list(map(int, f.readline().split())) for _ in range(n)]
    
    d = [[[float('inf')] * m for i in range(m)], [[float('inf')] * m for i in range(m)]]
    
    for ai, bi, ci, ti in abct:
        d[0][ai - 1][bi - 1] = ci
        d[1][ai - 1][bi - 1] = ti

    warshall_floyd(d[0])
    warshall_floyd(d[1])
        
    for i in range(int(f.readline())):
        p, q, r = map(int, f.readline().split())
        print(d[r][p - 1][q - 1])

### FIXED CODE ###

import heapq
import sys
from collections import defaultdict

def dijkstra(graph, size, start):
    d = [float('inf')] * size
    d[start] = 0
    q = [(0, start)]
    while len(q):
        du, u = heapq.heappop(q)
        for length, v in graph[u]:
            if d[v] > du + length:
                d[v] = du + length
                heapq.heappush(q, (d[v], v))
    return d

f = sys.stdin

while True:
    n, m = map(int, f.readline().split())
    if n == 0:
        break
    abct = [map(int, f.readline().split()) for _ in range(n)]
    d = [defaultdict(list), defaultdict(list)]
    
    for ai, bi, ci, ti in abct:
        ai -= 1
        bi -= 1
        d[0][ai].append((ci, bi))
        d[0][bi].append((ci, ai))
        d[1][ai].append((ti, bi))
        d[1][bi].append((ti, ai))
    
    dist = {}
    for i in range(int(f.readline())):
        p, q, r = map(int, f.readline().split())
        p -= 1
        q -= 1
        try:
            print(dist[(q,r)][p])
        except KeyError:
            try:
                print(dist[(p,r)][q])
            except:
                dist[(p,r)] = dijkstra(d[r], m, p)
                print(dist[(p,r)][q])
### BUGGY CODE ###

def main(n,a,b,c):
  import bisect
  ab=[] #ab[i]:上部にi個目を選んだ時、中部に選べるもののうち最小のインデックス。選べないならnになる
  ab.append(bisect.bisect_right(b,a[0]))
  bc=[]
  bc.append(bisect.bisect_right(c,b[0]))
  for i in range(1,n):
    if ab[i-1]==n:
      ab.append(n)  
    elif a[i]<b[ab[i-1]]:
      ab.append(ab[i-1])
    else:
      ab.append(bisect.bisect_right(b[ab[i-1]:],a[i])+ab[i-1])
    if bc[i-1]==n:
      bc.append(n)
    elif b[i]<c[bc[i-1]]:
      bc.append(bc[i-1])
    else:
      bc.append(bisect.bisect_right(c[bc[i-1]:],b[i])+bc[i-1])
  ans=0
  for i in range(n):
    for j in range(ab[i],n):
      ans+=n-bc[j]
  print(ans)
if __name__=='__main__':
  n=int(input())
  a=sorted(list(map(int,input().split())))
  b=sorted(list(map(int,input().split())))
  c=sorted(list(map(int,input().split())))
  main(n,a,b,c)


### FIXED CODE ###

def main(n,a,b,c):
  import bisect
  ans=0
  for i in range(n):
    na=bisect.bisect_left(a,b[i])
    nc=n-bisect.bisect_right(c,b[i])
    ans+=na*nc
  print(ans)
if __name__=='__main__':
  n=int(input())
  a=sorted(list(map(int,input().split())))
  b=sorted(list(map(int,input().split())))
  c=sorted(list(map(int,input().split())))
  main(n,a,b,c)
### BUGGY CODE ###

N = int(input())

a = [int(N) for N in input().split()]
b = len(a)

count = 0

for i in range(1,N+1):
    for k in range(0,b):
        if(i == a[k]):
            count += 1
    print(count)
    count = 0


### FIXED CODE ###

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

# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 095 c問題
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
"""

import numpy as np

N = int(input())
X = np.array(list(map(int, input().split(" "))))

for i in range(N):
    print(int(np.median(np.append(X[:i], X[i+1:]))))

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 095 c問題
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
"""
import random
import copy

N = int(input())
X = list(map(int, input().split(" ")))
sorted_X = sorted(X)
med1 = sorted_X[N//2-1]
med2 = sorted_X[N//2]
for i in range(N):
    if X[i] <= med1:
        print(med2)
    else:
        print(med1)
### BUGGY CODE ###

num = int(input())

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

a = 1

for i in list:
  a *= i

if a > 10**18:
  print(-1)
else:
  print(a)


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
l.sort()
x=10**18
a=1
for i in l:
  a=a*i
  if a>x:
    a=-1
    break
print(a)
### BUGGY CODE ###

N = int(input())
print(sum([i for i in range(N)]))

### FIXED CODE ###

N = int(input())
print((N-1)*N//2)
### BUGGY CODE ###

#import time

nk = [int(x) for x in raw_input().strip().split()]
d = []
for i in range(nk[0]):
    d_tmp = raw_input().strip().split()
    d.append([int(d_tmp[0]), int(d_tmp[1]), int(d_tmp[2] == 'B')])

n1 = nk[0]
k1 = nk[1]
k2 = k1 * 2

#d = tuple(d)
n = 0
#t = time.clock()
for i in range(k1):
    for j in range(k1):
        n_tmp = [0, 0]
        for k in range(n1):
            x = (d[k][0] - i) // k1 % 2
            y = (d[k][1] - j) // k1 % 2
            if x == y:
                n_tmp[1 - d[k][2]] += 1
            else:
                n_tmp[d[k][2]] += 1
        if n_tmp[0] > n:
            n = n_tmp[0]
        if n_tmp[1] > n:
            n = n_tmp[1]
#print time.clock() - t
print n


### FIXED CODE ###

import numpy as np

def getBoundary(p, k, k2):
    if p - k + 1 >= 0:
        return [(p - k + 1, p + 1)]
    else:
        return [(0, p + 1), ((p - k + 1) % k2, k2)]

n, k = map(int, input().strip().split())
k2 = k * 2
b = [[0 for i in range(k2 + 1)] for j in range(k2 + 1)]

for i in range(n):
    x_str, y_str, c_str = input().strip().split()
    x = int(x_str) % k2
    y = (int(y_str) + (c_str == 'B') * k) % k2
    for xb, xe in getBoundary(x % k2, k, k2):
        for yb, ye in getBoundary(y % k2, k, k2):
            b[xb][yb] += 1
            b[xb][ye] -= 1
            b[xe][yb] -= 1
            b[xe][ye] += 1
    for xb, xe in getBoundary((x + k) % k2, k, k2):
        for yb, ye in getBoundary((y + k) % k2, k, k2):
            b[xb][yb] += 1
            b[xb][ye] -= 1
            b[xe][yb] -= 1
            b[xe][ye] += 1

arr_b = np.array(b)
for i in range(k2):
    arr_b[i + 1] += arr_b[i]
for j in range(k2):
    arr_b[:, j + 1] += arr_b[:, j]
print(arr_b.max())
### BUGGY CODE ###

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

count = 0
ret = 0
while(count < n):
    if count + a >= n:
        ret += n - count
        break
    if count + a + b >= n:
        ret += a
        break
    count += a + b
    ret += a
print(ret)

### FIXED CODE ###

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

ret = n // (a + b) * a
ret += a if (n % (a + b) >= a) else n % (a + b)
print(ret)
### BUGGY CODE ###

S = list(input())
x = len(S)
c = 0
for i in range(x):
  if S[i] == 'W':
    c += S[:i].count('B')
print(c)
    

### FIXED CODE ###

S = input()
x = len(S)
c = 0
ans = 0
for i in range(x):
  
  if S[i] == 'W':
    
    c += 1
    
    ans += i + 1 - c
    
    
print(ans)
### BUGGY CODE ###

import decimal

n, k = map(int, input().split())
p_list = list(map(int, input().split()))
sum = 0
max = 0
index = 0
value = 0

for i in range(n - k + 1):
    sum = 0
    for j in range(k):
        sum += p_list[i + j]
    if sum > max:
        max = sum
        index = i

for i in range(k):
    for j in range(p_list[index + i]):
        value += (decimal.Decimal(j + 1) / decimal.Decimal(p_list[index + i]))

print(value)


### FIXED CODE ###

n, k = map(int, input().split())
p_list = list(map(int, input().split()))
num = sum(p_list[0:k])
max = 0
index = 0
value = 0

for i in range(n - k):
    num = num + p_list[i + k] - p_list[i]
    if num > max:
        max = num
        index = i + 1

for i in range(k):
    value += (1 + p_list[index + i])/ 2

print(value)
### BUGGY CODE ###

S = list(input())
ls = len(S)
odd_list = []
result = ""

while ls > 0:
    ls -= 1
    if ls % 2 == 0:
        odd_list.append(ls)
        odd_list = sorted(odd_list)

for i in odd_list:
    result = result + S[i]
print(result)

### FIXED CODE ###

S = str(input())
ls = len(S)
odd_list = []
result = ""

while ls > 0:
    ls -= 1
    if ls % 2 == 0:
        odd_list.append(ls)
odd_list = sorted(odd_list)
# print(odd_list)

for i in odd_list:
    result = result + S[i]
print(result)
### BUGGY CODE ###

import sys

input = sys.stdin.readline

h, w = map(int, input().split())
# 蛮兵
painted = [['#'] * (w + 2)]
painted += [['#'] + list(input().rstrip()) + ['#'] for _ in range(h)]
painted.append(['#'] * (w + 2))
que = []

for y in range(1, h + 1):
    for x in range(1, w + 1):
        if painted[y][x] == '#':
            painted[y][x] = 0
            que.append((y, x))
cnt = 0
while que:
    qq = []
    for y, x in que:
        if painted[y - 1][x] == '.':
            painted[y - 1][x] = painted[y][x] + 1
            qq.append((y - 1, x))
        if painted[y + 1][x] == '.':
            painted[y + 1][x] = painted[y][x] + 1
            qq.append((y + 1, x))
        if painted[y][x + 1] == '.':
            painted[y][x + 1] = painted[y][x] + 1
            qq.append((y, x + 1))
        if painted[y][x - 1] == '.':
            painted[y][x - 1] = painted[y][x] + 1
            qq.append((y, x - 1))
    que = qq

print(painted[y][x])

### FIXED CODE ###

import sys

input = sys.stdin.readline


def main():
    h, w = map(int, input().split())
    # 蛮兵
    painted = [['#'] * (w + 2)]
    painted += [['#'] + list(input().rstrip()) + ['#'] for _ in range(h)]
    painted.append(['#'] * (w + 2))
    que = []

    for y in range(1, h + 1):
        for x in range(1, w + 1):
            if painted[y][x] == '#':
                painted[y][x] = 0
                que.append((y, x))
    while que:
        qq = []
        for y, x in que:
            if painted[y - 1][x] == '.':
                painted[y - 1][x] = painted[y][x] + 1
                qq.append((y - 1, x))
            if painted[y + 1][x] == '.':
                painted[y + 1][x] = painted[y][x] + 1
                qq.append((y + 1, x))
            if painted[y][x + 1] == '.':
                painted[y][x + 1] = painted[y][x] + 1
                qq.append((y, x + 1))
            if painted[y][x - 1] == '.':
                painted[y][x - 1] = painted[y][x] + 1
                qq.append((y, x - 1))
        que = qq

    print(painted[y][x])


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

# https://atcoder.jp/contests/abc110/tasks/abc110_d

def get_prime_dic(n):
    dic = {}

    while n % 2 == 0:
        if 2 in dic:
            dic[2] += 1
        else:
            dic[2] = 1
        n = n // 2

    i = 3
    while i <= n:
        while n % i == 0:
            n //= i
            if i in dic:
                dic[i] += 1
            else:
                dic[i] = 1
        i += 2
    return dic


# Calculate count of combination
def combination(n, r):
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
    return a // b


def main():
    N, M = map(int, input().split())
    d = get_prime_dic(M)
    # print(d)

    ans = 1
    for k, v in d.items():
        ans *= combination(v + N - 1, v)
        ans %= 1000000007

    print(ans)


main()


### FIXED CODE ###

N, M = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
def func(M):
  res = []
  i = 2
  while i * i <= M:
    c=0
    while M % i == 0:
      M /= i
      c += 1
    if c > 0:
      res.append(c)
    i += 1
  if M > 1:
    res.append(1)
  return res

def conb(n, r):
  N, R = n, r
  for i in range(1, r):
    N *= n-i
    R *= r-i
  return N // R

res = func(M)
ans = 1
for i in res:
  ans = (ans * conb(i+N-1, i)) % mod
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
p = [0 for _ in range(10**6)]
for x in a:
  d = int(x)
  for y in range(2,10**3):
    if d % y == 0:
      p[y] += 1
      while d % y == 0:
        d //= y
  if d != 1:
    p[d] += 1
  #print(p)
if max(p) == 1:
  print('pairwise coprime')
  exit()
now = int(a[0])
for x in a:
  big,sml = x,now
  while big % sml != 0:
    #print(big,sml)
    big,sml = sml,big%sml
  now = sml
  #print(now)
if now == 1:
  print('setwise coprime')
else:
  print('not coprime')
  #print(now)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
p = [0 for _ in range(10**6)]
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
#print(pr)
at = 0
for x in a:
  d = int(x)
  for y in pr:
    if d % y == 0:
      if p[y] == 1:
        at = 1
      else:
        p[y] = 1
      while d % y == 0:
        d //= y
  if d != 1:
    if p[d] == 1:
      at = 1
    else:
      p[d] = 1
  if at == 1:
    break
  #print(p)
if at == 0:
  print('pairwise coprime')
  exit()
now = int(a[0])
for x in a:
  big,sml = x,now
  while sml:
    #print(big,sml)
    big,sml = sml,big%sml
  now = big
  if now == 1:
    print('setwise coprime')
    exit()
  #print(now)
print('not coprime')
### BUGGY CODE ###

N = int(input())

max_num = 10 ** 9 + 7

power = 1
for i in range(1, N+1):
  power *= i
  
print(power % max_num)



### FIXED CODE ###

N = int(input())

max_num = 10 ** 9 + 7

power = 1
for i in range(1, N+1):
  power = (power * i) % max_num
  
print(power)
### BUGGY CODE ###

MOD = 10**9 + 7

x, y = map(int, input().split())
a = 2 * y - x
b = 2 * x - y

if a < 0 or b < 0:
    ans = 0
elif a % 3 != 0 or b % 3 != 0:
    ans = 0
else:
    a //= 3
    b //= 3
    # print(a, b)

    MOD = 10**9 + 7
    MAX = a + b + 1
    fact = [1 for _ in range(MAX)]
    finv = [1 for _ in range(MAX)]
    for i in range(2, MAX):
        fact[i] = fact[i - 1] * i % MOD
        finv[i] = pow(fact[i], MOD - 2, MOD)

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

    ans = comb(a + b, a)

print(ans)


### FIXED CODE ###

MOD = 10**9 + 7


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


x, y = map(int, input().split())
a = 2 * y - x
b = 2 * x - y

if a < 0 or b < 0:
    ans = 0
elif a % 3 != 0 or b % 3 != 0:
    ans = 0
else:
    a //= 3
    b //= 3
    # print(a, b)
    ans = comb(a + b, a)

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

def main():
    x, y = map(int, input().split())
    if x == y:
        return print('-1')
    if y == 1:
        return print('-1')
    for i in range(1000000000):
        if (i * x) % y != 0:
            return print(i*x)
main()


### FIXED CODE ###

def main():
    x, y = map(int, input().split())
    if x % y == 0:
        return print('-1')
    for i in range(1000000000):
        if (i * x) % y != 0:
            return print(i*x)
main()
### BUGGY CODE ###

from heapq import heappop,heappush

n = int(input())

p = []

for i in range(n):
    x,y = map(int,input().split())
    p.append((i,x,y))

e = [[] for _ in range(n)]

p = sorted(p,key=lambda x:x[1])
for i in range(n-1):
    e[p[i][0]].append([abs(p[i+1][1]-p[i][1]),p[i+1][0]])
    e[p[i+1][0]].append([abs(p[i+1][1]-p[i][1]),p[i][0]])

p = sorted(p,key=lambda x:x[2])
for i in range(n-1):
    e[p[i][0]].append([abs(p[i+1][2]-p[i][2]),p[i+1][0]])
    e[p[i+1][0]].append([abs(p[i+1][2]-p[i][2]),p[i][0]])

def Prim(n,edge):
    used = [False] * n
    q = []
    #e = [cost,target]
    for e in edge[0]:
        heappush(q,e)
    used[0] = True
    res = 0
    while q:
        c,v = heappop(q)
        if used[v]:
            continue
        used[v] = True
        for e in edge[v]:
            if not used[e[1]]:
                heappush(q,e)
        res += c
    return res

print(Prim(n,e))

### FIXED CODE ###

import sys
input = sys.stdin.readline

from heapq import heappop,heappush

n = int(input())
p = []
for i in range(n):
    x,y = map(int,input().split())
    p.append((i,x,y))

e = [[] for _ in range(n)]

p = sorted(p,key=lambda x:x[1])
n0,x0,y0 = p[0]
for i in range(n-1):
    n1,x1,y1 = p[i+1]
    e[n0].append([min(abs(x1-x0),abs(y1-y0)),n1])
    e[n1].append([min(abs(x1-x0),abs(y1-y0)),n0])
    n0,x0,y0 = n1,x1,y1

p = sorted(p,key=lambda x:x[2])
n0,x0,y0 = p[0]
for i in range(n-1):
    n1,x1,y1 = p[i+1]
    e[n0].append([min(abs(x1-x0),abs(y1-y0)),n1])
    e[n1].append([min(abs(x1-x0),abs(y1-y0)),n0])
    n0,x0,y0 = n1,x1,y1

def Prim(n,edge):
    #edge[source] = [[cost_1,target_1],[cost_2,target_2],...]
    used = [False] * n
    q = []
    #e = [cost,target]
    for e in edge[0]:
        heappush(q,e)
    used[0] = True
    res = 0
    while q:
        c,v = heappop(q)
        if used[v]:
            continue
        used[v] = True
        for e in edge[v]:
            if not used[e[1]]:
                heappush(q,e)
        res += c
    return res

print(Prim(n,e))
### BUGGY CODE ###

N,M = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
l = [list(map(int,input().split())) for i in range(M)]

def change(ll,b,c):
    ll.sort()
    if b>N:
        b=N
    for n,i in enumerate(ll[:b]):
        if c>i:
            ll[n] = c
        else:
            break
    return ll

for i in range(M):
    A = change(A,l[i][0],l[i][1])
print(sum(A))

### FIXED CODE ###

N,M = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
l = [list(map(int,input().split())) for i in range(M)]

A.sort()
l = sorted(l,key = lambda x:x[1])

ind =0
for b,c in l[::-1]:
    mx = min(N,ind+b)
    for i in range(ind,mx):
        if c>A[i]:
            A[i] = c
    if mx==N:
        break
    ind += b
print(sum(A))
### BUGGY CODE ###

import math
k = int(input())


ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += math.gcd(a, math.gcd(b, c))
print(ans)

### FIXED CODE ###

from math import gcd
k = int(input())
 
 
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(a, gcd(b, c))
print(ans)
### BUGGY CODE ###

n=int(input())
a=[]

a.append(str(input()))

for i in range(n-1):
  flag = 1
  tmp = str(input())
  for j in range(len(a)):
    if a[j] == tmp:
      flag = 0
  if flag == 1:
    a.append(tmp)

print(len(a))

### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
  a.append(str(input()))

ans=1
a=sorted(a)
tmp=a[0]
for i in range(n-1):
  if a[i+1] != tmp:
    ans += 1
    tmp=a[i+1]

print(ans)