Harryxun/sft_time huggingface dataset:
### 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):
            ans1 = math.gcd(a, b)
            ans += math.gcd(ans1, c)

print(ans)


### FIXED CODE ###

from math import gcd

K = int(input())
ans = 0
for i in range(1, K + 1):
    ans += i
for i in range(1, K + 1):
    for j in range(i + 1, K + 1):
        ans += gcd(i, j) * 6

for i in range(1, K - 1):
    for j in range(i + 1, K):
        for k in range(j + 1, K + 1):
            ans += gcd(gcd(i, j), k) * 6

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

S=input()
modn=10**9+7
qnum=S.count('?')
lenS=len(S)

if S[0]=='?':
    dp=[1]*10+[0]*3
else:
    dp=[0]*13
    dp[int(S[0])]=1

for i in range(1,lenS):
    dppre = dp
    dp = [0] * 13
    if S[i] == '?':
        R = range(10)
    else:
        R = [int(S[i])]
    
    for j in range(13):
        for k in R:
            dp[(j * 10 + k) % 13 ] += dppre[j]
    for j in range(13):
        dp[j] %= modn

print(dp[5])

### FIXED CODE ###

M=10**9+7
r=[[(j-k)*9%13 for j in range(10)]for k in range(13)]
d=[1]+[0]*12
for c in input():
    d = [sum(d[j]for j in k)%M for k in r] if c>'9' else [d[(int(c)-k)*9%13]for k in range(13)]
print(d[5])
### BUGGY CODE ###

n, m = map(int, input().split())
card = [i for i in range(1, n+1)]
for _ in range(m):
   l, r = map(int, input().split())
   x = [i for i in range(l, r+1)]
   card = list(set(card) & set(x))

print(len(card))


### FIXED CODE ###

n, m = map(int, input().split())
L = 1
R = n
for _ in range(m):
   l, r = map(int, input().split())
   L = max(L, l)
   R = min(R, r)

if (L <= R):
   print(R - L + 1)
else:
   print(0)
### BUGGY CODE ###

N = int(input())
C=0
for i in range(N):
	C+=i
print(C)


### FIXED CODE ###

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

N, K = list(map(int, input().split()))
links = [list(map(int, input().split())) for _ in range(N-1)]

def perm(a, b):
    s = 1
    for i in range(a-b+1, a+1):
        s *= i
    return s

def main():
    if N == 1:
        return K
    d = {i: set() for i in range(1, N+1)}
    for i, j in links:
        d[i].add(j)
        d[j].add(i)
    history = {1}
    stack = d[1]
    b = len(stack)
    if K - 1 < b:
        return 0
    d.pop(1)
    ans = K * perm(K - 1, b)
    a = K - 2
    lim = max([len(x) for x in d.values()])
    if lim - 1 > a:
        return 0
    lim += 1
    perm_list = [None] * lim
    perm_list[0] = 1
    for i in range(1, lim):
        perm_list[i] = perm_list[i-1] * (a + 1 - i)
    while stack:
        node = stack.pop()
        if node in history:
            continue
        history.add(node)
        ans *= perm_list[len(d[node]) - 1]
        stack |= d[node]
    return ans
    
print(main() % 1000000007)

### FIXED CODE ###

N, K = list(map(int, input().split()))
l = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    l[a].append(b)
    l[b].append(a)

deg1 = [0] * (N + 1)
deg2 = [0] * (N + 1)
history = [True] * (N + 1)
stack = [1]
ans = 1

while stack:
    node = stack.pop()
    ans *= K - deg1[node] - deg2[node]
    ans %= 1000000007
    history[node] = False
    for child in l[node]:
        if history[child]:
            deg1[child] += 1
            deg2[child] += deg1[node]
            deg1[node] += 1
            stack.append(child)
            
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n, m, s, t = map(int,input().split())
C = [list(map(int,input().split())) for i in range(m)]

s -= 1
t -= 1

# O((V + E)log(V))
# Cは [[スタート頂点, ゴール頂点, 重み], ...] のリスト

for i in range(m):
    for j in range(2):
        C[i][j] -= 1

M = [[] for i in range(n)]
for i in range(len(C)):
    M[C[i][0]].append([C[i][1], C[i][2]])  # 無向グラフなら両方追加
    M[C[i][1]].append([C[i][0], C[i][2]])  # 無向グラフなら両方追加

N = [[] for i in range(n)]
for i in range(len(C)):
    N[C[i][0]].append([C[i][1], C[i][3]])  # 無向グラフなら両方追加
    N[C[i][1]].append([C[i][0], C[i][3]])  # 無向グラフなら両方追加

import heapq

def dijkstra(s, M):
    D = [float("inf")] * n  # 頂点0からの距離
    P = [-1] * n  # 頂点0からの最短距離において、そこの直前の頂点(経路復元に利用)
    D[s] = 0
    V = [0] * n  # その頂点のD[i]が最短距離と確定したら1
    Q = []  # 優先度付きキュー
    for v in range(n):
        heapq.heappush(Q, [D[v], v])

    le = len(Q)
    while le > 0:
        q = heapq.heappop(Q)
        u = q[1]
        du = q[0]
        if V[u] == 0:
            V[u] = 1
            le -= 1
            for i in range(len(M[u])):
                v = M[u][i][0]
                luv = M[u][i][1]
                if V[v] == 0:
                    alt = du + luv
                    if D[v] > alt:
                        D[v] = alt
                        P[v] = u
                        heapq.heappush(Q, [alt, v])
    return D, P

Ds, _ = dijkstra(s, M)
Dt, _ = dijkstra(t, N)

ANS = [0] * n

# print(Ds,Dt)

ans = float("inf")
for i in range(n-1, -1, -1):
    ans = min(ans, Ds[i] + Dt[i])
    ANS[i] = ans

for i in range(n):
    print(10**15 - ANS[i])

### FIXED CODE ###

import sys
input = sys.stdin.readline
n, m, s, t = map(int,input().split())
C = [list(map(int,input().split())) for i in range(m)]

s -= 1
t -= 1

# O((V + E)log(V))
# Cは [[スタート頂点, ゴール頂点, 重み], ...] のリスト

M = [[] for i in range(n)]
for i in range(len(C)):
    M[C[i][0]-1].append([C[i][1]-1, C[i][2]])  # 無向グラフなら両方追加
    M[C[i][1]-1].append([C[i][0]-1, C[i][2]])  # 無向グラフなら両方追加

N = [[] for i in range(n)]
for i in range(len(C)):
    N[C[i][0]-1].append([C[i][1]-1, C[i][3]])  # 無向グラフなら両方追加
    N[C[i][1]-1].append([C[i][0]-1, C[i][3]])  # 無向グラフなら両方追加

import heapq

def dijkstra(s, M):
    D = [10**16] * n  # 頂点0からの距離
    P = [-1] * n  # 頂点0からの最短距離において、そこの直前の頂点(経路復元に利用)
    D[s] = 0
    V = [0] * n  # その頂点のD[i]が最短距離と確定したら1
    Q = []  # 優先度付きキュー
    for v in range(n):
        heapq.heappush(Q, [D[v], v])

    le = len(Q)
    while le > 0:
        q = heapq.heappop(Q)
        u = q[1]
        du = q[0]
        if V[u] == 0:
            V[u] = 1
            le -= 1
            for i in range(len(M[u])):
                v = M[u][i][0]
                luv = M[u][i][1]
                if V[v] == 0:
                    alt = du + luv
                    if D[v] > alt:
                        D[v] = alt
                        P[v] = u
                        heapq.heappush(Q, [alt, v])
    return D, P

Ds, _ = dijkstra(s, M)
Dt, _ = dijkstra(t, N)

ANS = [0] * n

# print(Ds,Dt)

ans = 10**16
for i in range(n-1, -1, -1):
    ans = min(ans, Ds[i] + Dt[i])
    ANS[i] = ans

for i in range(n):
    print(10**15 - ANS[i])
### BUGGY CODE ###

S = input()

count = 0
for num_length in range(4, len(S) + 1):
    for i in range(len(S) - num_length + 1):
        j = i + num_length - 1
        sub_S = int(S[i:j + 1])
        if sub_S % 2019 == 0:
            count += 1
# for times in range(1, 101):
#     num = 2019 * times
#     if num > int(S): break
#     num_length = len(str(num))
#     for i in range(len(S) - num_length + 1):
#         j = i + num_length - 1
#         sub_S = int(S[i:j + 1])
#         if num == sub_S:
#             count += 1

print(count)

### FIXED CODE ###

S = list(input())
N = len(S)
# N 文字の文字列 S から、長さ N+1 の ---累積和--- s[0], s[1], ..., s[N] を作る
# これを 2019 で割ったあまりで分類する (具体的には counter[ r ] := あまりが r のやつが何個あるか)
# 各 r ごとに、counter[r] 個から 2 個選ぶ方法の数を、足し上げる

counter = [0] * 2019
k = 10
for i in range(N + 1):
    if i == 0:
        sub = 0
    elif i == 1:
        sub = int(S[N - 1])
    else:
        sub += int(S[N - i]) * k
        k *= 10
        k %= 2019
    rest = sub % 2019
    counter[rest] += 1

ans = 0
for r in counter:
    ans += r * (r - 1) // 2
print(ans)
### BUGGY CODE ###

import numpy as np

N = int(input()) #1行目のNを取得する
s = [input() for i in range(N)] #複数行の数値の入力を取得


for i in range(N):
    buf = s.copy()
    buf.pop(i)
    ans = max(buf)
    print(ans)


### FIXED CODE ###

N = int(input()) #1行目のNを取得する
s = []
s = [int(input()) for i in range(N)] #複数行の数値の入力を取得

max_num = max(s)
max_ind = s.index(max_num)
s.remove(max_num)
max2_num = max(s)
 
for i in range(N):
    if i == max_ind:
        print(max2_num)
    else:
        print(max_num)
### BUGGY CODE ###

import collections

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

c=collections.Counter(A)
kazu=list(c.values())
kazu1=[i*(i-1)/2 for i in kazu]

for k in range(N):
    sub=c[A[k]]-1
    print(int(sum(kazu1)-sub))

### FIXED CODE ###

import collections
import numpy as np

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

c=collections.Counter(A)
kazu=list(c.values())
a=np.array(kazu)
sn=a*(a-1)/2
s=sum(sn)
for k in range(N):
    sub=c[A[k]]-1
    print(int(s-sub))
### BUGGY CODE ###

#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = set(A)
L = []
for i in B:
    L.append(A.count(i))
L.sort()
if len(B) <= K:
    print('0')
else:
    print(str(sum(L[0:len(B)-K])))


### FIXED CODE ###

#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = set(A)
    L = [0 for i in range(N+1)]
    for i in A:
        L[i] += 1
    L.sort()
    if len(B) <= K:
        print('0')
    else:
        print(str(sum(L[0:N+1-K])))


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

N = int(input())
A = [int(input()) for i in range(N)]
B = list(A)
max_A = max(A)
for i in range(N):
    if max_A == A[i]:
        B.remove(A[i])
        print(max(B))
        B = list(A)
    else:
        print(max_A)

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
max_A = max(A)
B = set(A)
if len(B) == 1 or A.count(max_A) >= 2:
    for i in range(N):
        print(max_A)
else:
    C = list(A)
    for i in range(N):
        if A[i] == max_A:
            C.remove(max_A)
            print(max(C))
        else:
            print(max_A)
### BUGGY CODE ###

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

def check(x, y):
	if x & y == 0:
		return True
	else:
		return False

ans = n

for i in range(n - 1):
	x = a[i]
	for j in range(i + 1, n):
		y = a[j]
		if not check(x, y):
			break
		ans += 1
		x += y

print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
bits = [[0 for _ in range(20)] for _ in range(n)]

for i in range(n):
	for j in range(20):
		bits[i][j] = (a[i] >> j) & 1

ans = 0
bits_sum = [0] * 20

r = 0
for l in range(n):
	r = max(r, l)
	while r < n:
		bits_sum = [bits_sum[j] + bits[r][j] for j in range(20)]
		if max(bits_sum) > 1:
			bits_sum = [bits_sum[j] - bits[r][j] for j in range(20)]
			break
		r += 1
	#print(bits_sum, r)
	ans += r-l
	bits_sum = [bits_sum[j] - bits[l][j] for j in range(20)]
	#print(bits_sum, r)

#ans += 1
print(ans)
### BUGGY CODE ###

def main():
    s, t = input(), input()
    v = [('', False) for _ in range(len(t) + 1)]
    w = [('', False) for _ in range(len(t) + 1)]
    for i in range(1, len(s) + 1):
        for j in range(1, len(t) + 1):
            u, uu = v[j]
            l, ll = w[j - 1]
            d, dd = v[j - 1]
            if s[i - 1] == t[j - 1]:
                if len(u) > len(l) and not uu:
                    l, ll = u, uu 
                if len(l) > len(d) and not ll:
                    d, dd = l, ll
                w[j] = (d + s[i - 1], True)
            else:
                if len(u) > len(l):
                    l, ll = u, uu
                dd = False
                if len(l) > len(d):
                    d, dd = l, ll
                w[j] = (d, dd)
        v, w = w, v
    print(v[-1][0])


main()


### FIXED CODE ###

def main():
    s = input()
    t = input()
    v = [0] * (len(t) + 1)
    dp = [v]
    for i, si in enumerate(s, 1):
        u, v = v, v.copy()
        dp.append(v)
        ll, ul = 0, 0
        for j, ti in enumerate(t, 1):
            uu = u[j]
            if si == ti:
                v[j] = ll = ul + 1
            else:
                if ll > uu:
                    v[j] = ll
                else:
                    ll = uu
            ul = uu
    k = dp[i][j]
    r = ''
    while k:
        if dp[i - 1][j] == k:
            i -= 1
        elif dp[i][j - 1] == k:
            j -= 1
        else:
            k -= 1
            i -= 1
            j -= 1
            r += s[i]
    print(r[::-1])

main()
### BUGGY CODE ###

import sys
import bisect
A,B,Q = [int(n) for n in input().split()]
# N = int(input())
INF = 10 **18
s = [0]*A
t = [0]*B
s = [-INF] + [int(input()) for n in range(A)] + [INF]
t = [-INF] + [int(input()) for n in range(B)] + [INF]
def binary_search(arry, target):
    result = None
    left = 0
    right = len(arry) - 1

    while left <= right:
        mid = (left + right) // 2
        if arry[mid] == target:
            result = mid
            break
        elif arry[mid] > target:
            right = mid - 1
        else:
            left = mid + 1

    if result == None:
        result = mid
        if(mid+1 < len(arry)):
            result = mid+1 if (abs(arry[mid+1] - target) < abs(arry[mid] - target)) else result
        if(mid-1 >= 0):
            result = mid-1 if (abs(arry[result] - target) > abs(arry[mid-1] - target)) else result
        return result
    else:
        return result+1

for i in range(Q):
    x = int(input())
    mostntera = binary_search(s,x)
    # print(mostntera)
    tera0 = s[mostntera]
    tera1 = s[mostntera-1] if x-tera0<0 else s[mostntera+1]
    # print(tera0,tera1)
    mostnzin = binary_search(t,x)
    zin0 = t[mostnzin]
    zin1 = t[mostnzin-1] if x-zin0<0 else t[mostnzin+1]
    # print(zin0,zin1)
    ans = INF
    for a in [tera0, tera1]:
        for b in [zin0,zin1]:
            d1,d2 = abs(x-a) +abs(a-b), abs(x-b) + abs(a-b)
            ans = min(ans,d1,d2)
    print(ans)


### FIXED CODE ###

import sys
import bisect
A,B,Q = [int(n) for n in input().split()]
# N = int(input())
INF = 10 **18
s = [0]*A
t = [0]*B
s = [-INF] + [int(input()) for n in range(A)] + [INF]
t = [-INF] + [int(input()) for n in range(B)] + [INF]

for i in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
### BUGGY CODE ###

import heapq
import sys

H, W = map(int, input().split())
a = [[] for i in range(10)]
for i in range(10):
	c = [int(j) for j in input().split()]
	for j in range(10):
		a[i].append([c[j], j])
ans = 0
for i in range(H):
	A = [int(j) for j in input().split()]
	for j in A:
		if j == -1:
			continue
		b = [[0, j]]
		c = [False] * 10
		d = [sys.maxsize] * 10
		d[j] = 0
		while len(b):
			e = heapq.heappop(b)
			c[e[1]] = True
			for k in a[e[1]]:
				if c[k[1]]:
					continue
				if d[e[1]] + k[0] < d[k[1]]:
					d[k[1]] = d[e[1]] + k[0]
					heapq.heappush(b, [d[k[1]], k[1]])
		ans += d[1]
print(ans)

### FIXED CODE ###

import heapq
import sys

H, W = map(int, input().split())
c = [[int(j) for j in input().split()] for i in range(10)]
A = [[int(j) for j in input().split()] for i in range(H)]
ans = 0
for i in A:
	for j in i:
		if j == -1:
			continue
		a = [(0, j)]
		b = [False] * 10
		d = [sys.maxsize] * 10
		d[j] = 0
		while len(a):
			e = heapq.heappop(a)
			b[e[1]] = True
			for k in range(len(c[e[1]])):
				if b[k]:
					continue
				if d[e[1]] + c[e[1]][k] < d[k]:
					d[k] = d[e[1]] + c[e[1]][k]
					heapq.heappush(a, (d[k], k))
		ans += d[1]
print(ans)
### BUGGY CODE ###

n, m = (int(_) for _ in input().split())  
a = list(map(int, input().split()))
x = [list(int(_) for _ in input().split()) for i in range(m)]
[a.extend(list(i[1] for ii in range(i[0]))) for i in x]

a = sorted(a,key = lambda x:-x)

print(sum(a[:n]))

### FIXED CODE ###

n, m = (int(_) for _ in input().split())  
a = list(map(int, input().split()))
x = [list(int(_) for _ in input().split()) for i in range(m)]
x = sorted(x,key = lambda x:-x[1])

[a.extend(list(i[1] for ii in range(i[0]))) for i in x if len(a) <= n * 2]
a = sorted(a,key = lambda x:-x)

print(sum(a[:n]))
### BUGGY CODE ###

def f(s,x):
    global ans
    if 1 <= s <= n and x == k:
        ans += 1
    elif s > n:
        return s
    if x < k:
        for i in range(1,10):
            nexts = s*10 + i
            f(nexts,x+1)
    if s != 0:
        nexts = s*10
        f(nexts,x)
    return s
ans = 0
n = int(input())
k = int(input())
f(0,0)
print(ans)

### FIXED CODE ###

n = list(input())
k = int(input())
t = len(n)
ketaDP = [[[0 for i in range(2)] for j in range(k+1)] for u in range(t)]
#ketaDP = [上から何桁目][0以外が何回出てる][nより小さいの確定？]
ketaDP[0][0][0] = 1
ketaDP[0][1][0] = int(n[0])-1
ketaDP[0][1][1] = 1
for i in range(1,t):
    now = int(n[i])
    for j in range(k+1):
        ketaDP[i][j][0] += ketaDP[i-1][j][0]
    for j in range(k):
        ketaDP[i][j+1][0] += ketaDP[i-1][j][0] * 9
    if now == 0:
        for j in range(k+1):
            ketaDP[i][j][1] += ketaDP[i-1][j][1]
    elif now != 0:
        for j in range(k+1):
            ketaDP[i][j][0] += ketaDP[i-1][j][1]
        for j in range(k):
            ketaDP[i][j+1][1] += ketaDP[i-1][j][1]
            ketaDP[i][j+1][0] += ketaDP[i-1][j][1]*(now-1)
print(sum(ketaDP[t-1][k]))
### BUGGY CODE ###

def ryuka(n):
    a = 2
    b = 1
    if n == 0:
        return a
    elif n == 1:
        return b
    else:
        return ryuka(n-1)+ryuka(n-2)
n = int(input())
print(ryuka(n))

### FIXED CODE ###

n = int(input())
l = [2, 1]
if n == 1:
    print(1)
else:
    for i in range(n):
        l.append(l[i+1]+l[i])
    print(l[n])
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
B = [0] * len(A)
C = [0] * len(A)
for i in range(len(A)):
  B[i] = A[i] + 1
  C[i] = A[i] - 1

t= 0
m = 0
for X in range(1 ,10 ** 5 + 1):
  t = A.count(X) + B.count(X) + C.count(X)
  m = max(m,t)
print(m)

### FIXED CODE ###

N = int(input())
As = list(map(int,input().split()))
c = 0
nums = [0]*(10**5+1)
for a in As:
    nums[a]+=1

for i in range(1,len(nums)):
    if i == len(nums)-1:
        t = nums[i - 1] + nums[i]
    else:
        t = nums[i-1]+nums[i]+nums[i+1]
    c = max(c,t)
print(c)
### BUGGY CODE ###

n = int(input())

def func(x):
  divisors = []
  for i in range(1, int(x**0.5)+1):
    if x % i == 0:
      divisors.append(i)
      if i != x // i:
        divisors.append(x//i)
  return len(divisors)

res = 0
for i in range(n):
  res += (i+1) * func(i+1)
print(res)

### FIXED CODE ###

def solve(n):
    ans = 0
    for i in range(1,n+1):
        y = n//i
        ans += (y*(y+1)*i)/2
    return ans

def main():
    n = int(input())
    print(int(solve(n)))

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

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


def main():
  H, W = list(map(int, input().split()))

  M = [input()[:-1] for _ in range(H)]

  def bfs(start):
    dist = [[float('inf')]*W for _ in range(H)]
    dist[start[0]][start[1]] = 0

    is_visited = [[0]*W for _ in range(H)]
    is_visited[start[0]][start[1]] = float('inf')
    q = deque([start])
    max_ = 0

    while len(q):
      now_h, now_w = q.popleft()
      if M[now_h][now_w] == '#':
        return
      # is_visited[now_h][now_w] = 1
      is_visited[now_h][now_w] = float('inf')
      for next_h, next_w in ((now_h+1, now_w),
                             (now_h-1, now_w),
                             (now_h, now_w-1),
                             (now_h, now_w+1)):

        if not(0 <= next_h < H) or not(0 <= next_w < W) or \
           (is_visited[next_h][next_w] == float('inf')) or \
           M[next_h][next_w] == '#':
           # (dist[next_h][next_w] != float('inf')) or \
          continue

        dist[next_h][next_w] = dist[now_h][now_w] + 1
        max_ = max(max_, dist[next_h][next_w])
        q.append((next_h, next_w))
    return max_

  max_ = 0
  for h in range(H):
    for w in range(W):
      if M[h][w] == '.':
        max_ = max(bfs((h, w)), max_)

  print(max_)


if(__name__ == '__main__'):
  main()


### FIXED CODE ###

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


def main():
  H, W = list(map(int, input().split()))

  M = [input()[:-1] for _ in range(H)]

  def bfs(start):
    dist = [[float('inf')]*W for _ in range(H)]
    dist[start[0]][start[1]] = 0

    q = deque([start])
    max_ = 0

    while len(q):
      now_h, now_w = q.popleft()
      for next_h, next_w in ((now_h+1, now_w),
                             (now_h-1, now_w),
                             (now_h, now_w-1),
                             (now_h, now_w+1)):

        if not(0 <= next_h < H) or not(0 <= next_w < W) or \
           (dist[next_h][next_w] != float('inf')) or \
           M[next_h][next_w] == '#':
          continue

        temp = dist[now_h][now_w] + 1
        dist[next_h][next_w] = temp
        if max_ < temp:
          max_ = temp
        q.append((next_h, next_w))
    return max_

  max_ = 0
  for h in range(H):
    for w in range(W):
      if M[h][w] == '.':
        max_ = max(bfs((h, w)), max_)

  print(max_)


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

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import bisect

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    al.sort()
    while len(al) > 1:
        p = al[-1] % sum(al[:-1])
        q = al[-1]
        al = al[:-1]
        if p == 0:
            continue
        if p == q:
            q -= al[-1]
            if q <= 0:
                continue
            p = q
        bisect.insort(al, p)
    print(al[0])

if __name__=="__main__":
    solve()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

def gcd(a, b):
    if a < b:
        a,b = b,a
    while b > 0:
        r = a % b
        a,b = b,r
    return a

def arrgcd(a):
    alen = len(a)
    if alen == 3:
        return gcd(a[0], gcd(a[1], a[2]))
    elif alen == 2:
        return gcd(a[0], a[1])
    elif alen == 1:
        return a[0] # 最初から1つ
    elif alen == 0:
        return 0
    else:
        return gcd(arrgcd(a[:alen//2]), arrgcd(a[alen//2:]))

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    print(arrgcd(al))

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

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

bits = [[0] * 60 for _ in range(N)]

for i, a in enumerate(A):
    if i != 0:
        for j in range(60):
            bits[i][j] += bits[i - 1][j]
    cnt = 0
    while a != 0:
        if a & 1:
            bits[i][cnt] += 1

        cnt += 1
        a >>= 1


all_sum = 0
two_exp = [pow(2, i, MOD) for i in range(60)]

for i, a in enumerate(A):
    temp_sum = 0
    cnt = 0
    while cnt < 60:
        ones = bits[-1][cnt] - bits[i][cnt]
        zeros = N - (i + 1) - ones

        if a & 1:
            temp_sum += (two_exp[cnt] * zeros) % MOD
        else:
            temp_sum += (two_exp[cnt] * ones) % MOD

        temp_sum %= MOD

        a >>= 1
        cnt += 1

    all_sum += temp_sum
    all_sum %= MOD


print(all_sum)



### FIXED CODE ###

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

sum_all = 0
p = 1
for i in range(60):
    ones = 0
    zeros = 0

    x = 1 << i
    for a in A:
        if a & x:
            ones += 1
        else:
            zeros += 1

    sum_all += p * ones * zeros % MOD
    p *= 2 % MOD


print(sum_all % MOD)
### BUGGY CODE ###

def C_GreenBin():
    N = int(input())
    s = []
    for x in range(N):
        s.append(sorted(input()))
    result = 0
    for i in range(0, N - 1):
        for j in range(i + 1, N):
            if s[i] == s[j]:
                result += 1
    print(result)
    
if __name__ == "__main__":
    C_GreenBin()

### FIXED CODE ###

def C_GreenBin():
    from collections import Counter
    N = int(input())
    s = []
    for x in range(N):
        list_tmp = sorted(input())
        s.append("".join(list_tmp))
    result = 0
    s_tmp = Counter(s)
    for x in s_tmp.values():
        if x > 1:
            result += ((x - 1) * x) // 2
    print(result)
    
if __name__ == "__main__":
    C_GreenBin()