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

# -*- coding: utf-8 -*-


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

def solve(A, i, m):
    n = len(A)
    if m == 0:
        return True
    if i >= n:
        return False
    res = solve(A, i + 1, m) or solve(A, i + 1, m - A[i])
    return res

for i in M:
    if solve(A, 0, i):
        print ("yes")
    else:
        print ("no")

### FIXED CODE ###

n = int(input())
A = list(sorted(map(int, input().split())))
q = int(input())
M = list(map(int, input().split()))

R = [[None for j in range(2000)] for i in range(n + 1)]

def solve(i, m):
    if R[i][m] != None:
        return R[i][m]
    if m == 0:
        R[i][m] = True
        return True
    elif i > n - 1:
        R[i][m] = False
        return False
    else:
        ans = solve(i + 1, m) or solve(i + 1, m - A[i])
        R[i][m] = ans
        return ans

sum_A = sum(A)
for i in M:
    if sum_A < i:
        print('no')
    elif solve(0, i):
        print('yes')
    else:
        print('no')
### BUGGY CODE ###

s = list(input())
count = 0
while True:
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            del s[i]
            del s[i]
            count += 2
            break
    else:
        break
print(count)

### FIXED CODE ###

s = list(input())
a = s.count("1")
b = s.count("0")
print(len(s) - (max(a,b) - min(a,b)))
### BUGGY CODE ###

def solve(a, b, c):
    sm = 0
    while True:
        for x in range(sm + 1):
            if x * a + (sm - x) * b == c:
                return x, (sm - x)
        sm += 1

n = int(input())
t, a = [int(x) for x in input().split()]
for i in range(1, n):
    t2, a2 = [int(x) for x in input().split()]
    x, y = solve(a2, -t2, a * t2 - t * a2)
    t, a = t + x, a + y

print(t + a)


### FIXED CODE ###

import math
from fractions import Fraction

n = int(input())
t, a = [int(x) for x in input().split()]
for i in range(1, n):
    t2, a2 = [int(x) for x in input().split()]
    x = math.ceil(max(Fraction(t, t2), Fraction(a, a2)))
    t, a = x * t2, x * a2

print(t + a)
### BUGGY CODE ###

def find(n):
    if root[n] < 0:
        return n
    else:
        root[n] = find(root[n])
        return root[n]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if root[x] > root[y]:
        x, y = y, x

    root[x] += root[y]
    root[y] = x

def size(x):
    return -root[find(x)]

def same(x,y):
    return find(x) == find(y)

def member(x):
    rt = find(x)
    return [i for i in range(n) if find(i) == rt]

def roots():
    return [i for i, x in enumerate(root) if x < 0]

def member_count(x):
    return len(roots())

def all_group_members():
    return {r: member(r) for r in roots()}

n , m = map(int,input().split())
root = [-1 for i in range(n)]
for i in range(m):
    a , b = map(lambda x:int(x)-1,input().split())
    unite(a,b)

d = all_group_members()
ans = 0
for v in d.values():
    ans = max(ans,len(v))
print(ans)

### FIXED CODE ###

from collections import deque
n , m = map(int,input().split())
route = [[] for i in range(n)]

for _ in range(m):
    a , b = map(lambda x:int(x)-1,input().split())
    route[a].append(b)
    route[b].append(a)
    
visit = [False for i in range(n)]
ans = 0
for i in range(n):
    if visit[i]:
        continue
    cou = 1
    visit[i] = True
    d = deque()
    d.append(i)
    while d:
        now = d.popleft()
        for j in route[now]:
            if not visit[j]:
                visit[j] = True
                cou += 1
                d.append(j)
    ans = max(cou,ans)
print(ans)
### BUGGY CODE ###

k = int(input())
s = input()

n = len(s)
mod = 10**9+7


def framod(n, mod, a=1):
    for i in range(1, n+1):
        a = a * i % mod
    return a


def power(n, r, mod):
    if r == 0:
        return 1
    if r % 2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r % 2 == 1:
        return n * power(n, r-1, mod) % mod


def comb(n, k, mod):
    a = framod(n, mod)
    b = framod(k, mod)
    c = framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod


a25 = [1]*(k+1)
for i in range(k):
    a25[i+1] = a25[i]*25 % mod
a26 = [1]*(k+1)
for i in range(k):
    a26[i+1] = a26[i]*26 % mod
num = 0
for i in range(0, k+1):
    num = num+comb(i+n-1, n-1, mod)*a25[i] % mod * a26[k-i] % mod
print(num)


### FIXED CODE ###

k = int(input())
s = input()

n = len(s)
mod = 10**9+7


def framod(n, mod, a=1):
    for i in range(1, n+1):
        a = a * i % mod
    return a


def power(n, r, mod):
    if r == 0:
        return 1
    if r % 2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r % 2 == 1:
        return n * power(n, r-1, mod) % mod


def comb(n, k, mod):
    a = framod(n, mod)
    b = framod(k, mod)
    c = framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod


com = [1]*(k+1)
for i in range(k):
    com[i+1] = com[i]*(n+i)*pow(i+1, mod-2, mod) % mod

a25 = [1]*(k+1)
for i in range(k):
    a25[i+1] = a25[i]*25 % mod
a26 = [1]*(k+1)
for i in range(k):
    a26[i+1] = a26[i]*26 % mod
num = 0
for i in range(0, k+1):
    num = (num+com[i]*a25[i] % mod * a26[k-i]) % mod
print(num)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    for i in range(1, 3501):
        for j in range(i, 3501):
            # dN, di, dj = Decimal(N), Decimal(i), Decimal(j)
            z = 4*i*j - N*j - N*i
            if z == 0:
                continue
            h, r = divmod((N*i*j), z)
            if r == 0 and 0 <= h <= 3500:
                print(h, i, j)
                exit()
            

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    for i in range(1, 3501):
        for j in range(i, 3501):
            z = 4*i*j - N*(j+i)
            if z > 0:
                h, r = divmod((N*i*j), z)
                if r == 0:
                    print(h, i, j)
                    exit()
            

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


# #!/usr/bin/env python3
# n = int(input())
# for i in range(1, 3501):
#   for j in range(1, 3501):
#     seed = 4 * i * j - n * (i + j) 
#     if seed > 0:
#       k, mod = divmod(n * i * j, seed) 
#       if mod == 0:
#         print(i, j, k)
#         exit()
### BUGGY CODE ###

import sys

input = sys.stdin.readline


N, W = map(int, input().split())
#x = [tuple(map(int, input().split())) for _ in range(N)]

x = [None] * N
for i in range(N):
    x[i] = tuple(map(int, input().split()))
    
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i, (w, v) in enumerate(x, 1):
    dpi = dp[i]
    dpim = dp[i-1]    
    for j in range(1, W + 1):
        if w <= j:
            a = dpim[j - w] + v
            if a > dpim[j]:
                dpi[j] = a
            else:
                dpi[j] = dpim[j]
        else:
            dpi[j] = dpim[j]

print(dp[-1][W])

### FIXED CODE ###

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, W = map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]

x = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(1, W + 1):
        dp[i][j] = dp[i - 1][j]
        if i != 0 and x[i - 1][0] <= j:
            dp[i][j] = max(dp[i][j], dp[i-1][j-x[i-1][0]] + x[i-1][1])

print(dp[-1][W])
### BUGGY CODE ###

import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
for j in range(N):
    I = copy.deepcopy(A)
    del I[j]
    print(max(I))

### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
maxA = max(A)
secondA = sorted(A)[-2]
for j in range(N):
    if (A[j] != maxA):
        print(maxA)
    else:
        print(secondA)
### BUGGY CODE ###

N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
dp=[[0]*(M+1) for i in range(N+1)]
mod=10**9+7
def Mod(n,mod):
    return n-mod if n>=mod else n
for n in range(1,N+1):
    for m in range(1,M+1):
        x=dp[n-1][m-1]+1 if S[n-1]==T[m-1] else 0
        dp[n][m]=Mod(dp[n-1][m]+dp[n][m-1]-dp[n-1][m-1]+x,mod)
print((dp[-1][-1]+1)%mod)

### FIXED CODE ###

N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
dp=[[0]*(M+1) for i in range(N+1)]
mod=10**9+7
for n in range(1,N+1):
    for m in range(1,M+1):
        x=1 if S[n-1]==T[m-1] else -dp[n-1][m-1]
        y=dp[n-1][m]+dp[n][m-1]+x
        dp[n][m]=y if y<mod else y-mod
print((dp[-1][-1]+1)%mod)
### BUGGY CODE ###

n = int(input())
v = [list(map(int,input().split())) for _ in range(n-1)]
g = {}
for a,b,w in v:
    if a not in g:
        g[a] = []
    if b not in g:
        g[b] = []
    g[a].append([b,w])
    g[b].append([a,w])
from collections import deque
queue = deque([[1,0]])
b = deque()
done = set([])
while queue:
    q,d = queue.popleft()
    if d%2==1:
        b.appendleft(q)
    done |= set([q])
    for new_q in g[q]:
        v_,d_ = new_q
        if v_ not in done:
            queue.appendleft([v_,d+d_])
for i in range(1,n+1):
    if i in b:
        print(1)
    else:
        print(0)

### FIXED CODE ###

n = int(input())
v = [list(map(int,input().split())) for _ in range(n-1)]
g = {}
for a,b,w in v:
    if a not in g:
        g[a] = []
    if b not in g:
        g[b] = []
    g[a].append([b,w])
    g[b].append([a,w])
from collections import deque
queue = deque([[1,0]])
b = [-1]*n
b[0] = 0
while queue:
    q,d = queue.popleft()
    if d%2==1:
        b[q-1] = 0
    else:
        b[q-1] = 1
    for new_q in g[q]:
        v_,d_ = new_q
        if b[v_-1]==-1:
            queue.appendleft([v_,d+d_])
for i in b:
    print(i)
### BUGGY CODE ###

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict, deque
    n, m = map(int, readline().split())
    edge = defaultdict(list)
    for _ in range(m):
        a, b = map(int, readline().split())
        edge[a].append(b)
        edge[b].append(a)

    q = int(readline())
    mat = [[] for _ in range(q)]

    for i in range(q):
        mat[i] = list(map(int, readline().split()))

    paint = [[0, -1] for _ in range(n + 1)]
    for v, d, c in mat[::-1]:
        if d == 0 and paint[v] == -1:
            paint[v][0] = c
            paint[v][1] = 0
        else:
            if paint[v][1] >= d:
                continue
            que = deque()
            que.append((v, d, c))
            while que:
                cur, rem, color = que.popleft()
                if paint[cur][0] == 0:
                    paint[cur][0] = color
                    paint[cur][1] = rem
                if rem > 0:
                    n_rem = rem - 1
                    for nx in edge[cur]:
                        if paint[nx][1] >= n_rem:
                            pass
                        else:
                            que.append((nx, n_rem, color))

    for i in range(1, n + 1):
        print(paint[i][0])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict, deque
    n, m = map(int, readline().split())
    edge = defaultdict(list)
    for _ in range(m):
        a, b = map(int, readline().split())
        edge[a].append(b)
        edge[b].append(a)

    q = int(readline())
    mat = [[] for _ in range(q)]

    for i in range(q):
        mat[i] = list(map(int, readline().split()))

    dp = [[0] * 11 for _ in range(n + 1)]

    for v, d, c in mat[::-1]:
        if dp[v][d] != 0:
            continue
        que = deque()
        que.append((v, d, c))
        while que:
            cur, dist, color = que.popleft()
            for i in range(dist, -1, -1):
                if dp[cur][i] == 0:
                    dp[cur][i] = color
                else:
                    break
            if dist > 0:
                for nx in edge[cur]:
                    if dp[nx][dist - 1] != 0:
                        continue
                    else:
                        que.append((nx, dist - 1, color))

    for i in range(1, n + 1):
        print(dp[i][0])


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

N = int(input())
A = list(map(int, input().split(' ')))
A_num = list(set(A.copy()))
for i in range(N):
    out = 0
    for j in A_num:
        if j == A[i]:
            out += int((A.count(j) * (A.count(j) - 1) / 2 - (A.count(j) - 1)))
        else:
            out += int((A.count(j) * (A.count(j) - 1) / 2))
    print(out)

### FIXED CODE ###

'''
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split(' '))))
num_sum = 0
remove_array = np.array([], int)
for i in range(N):
    c1 = np.count_nonzero(A == i + 1)
    c2 = np.count_nonzero(A == A[i])
    if c2 <= 1:
        remove_array = np.append(remove_array, 0)
    else:
        remove_array = np.append(remove_array, c2 - 1)
    num_sum += int(c1 * (c1 - 1) / 2)
print(*(num_sum - remove_array), sep='\n')
'''
import collections
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A)
total = 0
for key in cnt.keys():
    total += cnt[key] * (cnt[key] - 1) // 2
for i in range(N):
    tmp = total
    tmp -= cnt[A[i]] * (cnt[A[i]] - 1) // 2
    tmp += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) // 2
    print(tmp)
### BUGGY CODE ###

#!/usr/bin/env python3
# O(NlogN) 

n = int(input())
ans = 0 
for i in range(1, n+1):
    for j in range(i, n+1, i): 
        ans += j
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
# O(NlogN)

n = int(input())

div = [0 for _ in range(n+1)]
for i in range(1, n+1):
    ti = i 
    while True:
        if ti > n:
            break
        div[ti] += 1 
        ti += i
ans = 0 
for i in range(1, n+1):
    ans += i*div[i]
print(ans)
### BUGGY CODE ###

from fractions import gcd  # in math module python >= 3.5
from functools import reduce


def gcdall(numlist):
    return reduce(gcd, numlist)


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    if len(a) < 3:
        print(max(a))
        return

    gcds = []
    for i in range(len(a)):
        excepted = list(set([a[j] for j in range(len(a)) if j != i]))
        b = 0
        while all([k % 2 == 0 for k in excepted]):
            b += 1
            excepted = [k // 2 for k in excepted]

        if b > 0:
            gcds.append(gcdall(excepted) * 2 * b)
        else:
            gcds.append(gcdall(excepted))
    print(max(gcds))


main()

### FIXED CODE ###

from fractions import gcd  # in math module python >= 3.5


def main():
    n = int(input())
    a = list(map(int, input().split()))
    if len(a) < 3:
        print(max(a))
        return

    ls = []
    for i in range(n+1):
        if i == 0:
            ls.append(0)
        else:
            ls.append(gcd(ls[i-1], a[i-1]))

    rs = []
    for i in range(n+1):
        if i == 0:
            rs.append(0)
        else:
            rs.append(gcd(rs[i-1], a[-i]))
    rs = list(reversed(rs)) + [0]

    m = [gcd(ls[i], rs[i+1]) for i in range(n+1)]

    print(max(m))


main()
### BUGGY CODE ###

n=int(input())
s=input()

ans=float("inf")
for i in range(n+1):
    left=s[0:i]
    right=s[i:n]
    tmp=(left.count("#")+right.count("."))
    # print(left,right,tmp)
    ans=min(ans,tmp)
    
print(ans)

### FIXED CODE ###

n=int(input())
s=input()
w_cnt=s.count(".")

ans=[w_cnt]
b=0
w=w_cnt

for i in range(n):
    if s[i]=="#":
        b+=1
    else:
        w-=1
    ans.append(b+w)

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

n=int(input())
# s=input()
# a,b=map(int,input().split())
# h=list(map(int,input().split()))
l=sorted(list(map(int,input().split())))

# mod=10**9+7
# n=20
# fact=[1]
# for i in range(n):
#     fact+=fact[-1]*(i+1)%mod,
# print(fact)
# print(l)
# ほんと？
from bisect import bisect_left,bisect_right
ans=0
for i in range(n):
    for j in range(i+1,n):
        a=l[i]
        b=l[j]
        ll=l[j+1:]
        # print(ll)
        # abs(a-b)<c<a+bをみたすcは何個？
        ans+=bisect_left(ll,a+b)-bisect_right(ll,b-a)
print(ans)

### FIXED CODE ###

import bisect
 
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
 
for i in range(n):
  for j in range(i+1,n):
    temp=l[i]+l[j]
    ans+=(bisect.bisect_left(l,temp)-j-1)
print(ans)
### BUGGY CODE ###

import collections
import sys
input = sys.stdin.readline
from array import array
def solve():
  n = int(input())
  query = []
  query2 = []
  ans = array('I', [])
  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    query.append((a,b))
    query2.append(a)
    query2.append(b)
  c = list(int(i) for i in input().split())
  c = sorted(c,reverse =True)
  
  d = collections.Counter(query2)
  for i in range(len(d)):
    tmp = d.most_common()[i][0]
    #print(tmp)
    ans.insert(tmp-1,c[i])
  print(sum(c) +(-1)*max(c))
  #dの処理
  print(*ans)
  
solve()

### FIXED CODE ###

import collections
import sys
input = sys.stdin.readline
import heapq
from array import array
def solve():
  n = int(input())

  query2 = collections.deque([])
  edge = [[] for _ in range(n)]
  ans = array('I', [ 0 for i in range(n)])
  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    query2.append(a)
    query2.append(b)
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
  c = list(int(i) for i in input().split())
  if n == 1:
    print(1)
    print(c[0])
    exit()
  c = collections.deque(sorted(c,reverse =True))
  d = collections.Counter(query2)
  d2 = d.most_common()
  bfs = []
  heapq.heappush(bfs,(-1*d2[0][1],d2[0][0]-1,-1))#回数,場所、親
  ct = 0
  visit = [False]*n
  while bfs:
    times,place,parent = heapq.heappop(bfs)
    if visit[place]:
      continue
    else:
      visit[place] = True

      for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp,place))
      #print(place,parent,times)
      ans[place] = c.popleft()

      #print(c,place)

  print(sum(ans)-max(ans))
  print(*ans)
  
solve()
### BUGGY CODE ###

N = int(input())
A_list = list(map(int, input().split()))
for i in range(1, N + 1):
    print(A_list.count(i))

### FIXED CODE ###

import collections
N = int(input())
A_list = list(map(int, input().split()))
c = collections.Counter(A_list)
for i in range(1, N + 1):
    print(c[i])
### BUGGY CODE ###

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

INF = 10**9 + 7

res = 0

for i in range(N-1):
    for j in range(i+1,N):
        res += A[i] ^ A[j]
        res %= INF

print(res)


### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.readline

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

A = np.array(A,np.int64)

mod = 10**9 + 7

res = 0

for i in range(60):
    count = np.count_nonzero(A & 1)
    res += (N - count) * count * 2 ** i
    res %= mod
    A >>= 1

print(res)
### BUGGY CODE ###

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

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

Group=[i for i in range(N+1)]

Swap=[None]*M
for i in range(M):
    Swap[i]=tuple(map(int,input().split()))

for i in range(M):
    if (Group[Swap[i][1]],Group[Swap[i][0]])!=(min(Group[Swap[i][0]], Group[Swap[i][1]]),min(Group[Swap[i][0]], Group[Swap[i][1]])):
        Group=[min(Group[Swap[i][0]], Group[Swap[i][1]])  if (j==Group[Swap[i][0]] or j==Group[Swap[i][1]]) else j for j in Group]

count=0

for i in range(N):
    if Group[P[i]]==Group[i+1]:
        count+=1


print(count)


### FIXED CODE ###

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

Group=[i for i in range(N+1)]


Swap=[None]*M
for i in range(M):
    Swap[i]=sorted(map(int,input().split()))

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

for i in range(M):
    if find(Swap[i][1]) != find(Swap[i][0]):
        Group[find(Swap[i][1])]=min(find(Swap[i][1]),find(Swap[i][0]))
        Group[find(Swap[i][0])]=min(find(Swap[i][1]),find(Swap[i][0]))
        Group[Swap[i][1]]=min(find(Swap[i][1]),find(Swap[i][0]))
        Group[Swap[i][1]]=min(find(Swap[i][1]),find(Swap[i][0]))

count=0

for i in range(N):
    if find(P[i])==find(i+1):
        count+=1


print(count)
### BUGGY CODE ###

N = int(input())
S = input()
ans = 0

Klist = [N-1]
IJ = list()
for i in range(N-2):
    for j in range(i+1, N-1):
        if not S[i] == S[j]:
            IJ.append((i, j))
            Klist.append(j)
K = sorted(list(set(Klist)), reverse=True)
for ij in IJ:
    i, j = ij
    for k in K:
        if not j < k:
            break
        if S[j] == S[k]:
            continue
        if S[i] == S[k]:
            continue
        if j-i == k-j:
            continue
        ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N):
    for j in range(i, N):
        k = 2*j - i
        if N > k and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans -= 1
print(ans)
### BUGGY CODE ###

import collections
N = int(input())
all = []
count = []
nsame = 0
for i in range(N):
  tmp = collections.Counter(list(input()))
  if i >= 1:
    for j in range(i):
      if count[j] == tmp:
        nsame = nsame + 1
  count.append(tmp)
print(nsame)

### FIXED CODE ###

N = int(input())
alldict = {}
nsame = 0
for i in range(N):
  tmp = list(input())
  tmp.sort()
  if ''.join(tmp) in alldict:
    alldict[''.join(tmp)] = alldict[''.join(tmp)] + 1
  else:
    alldict[''.join(tmp)] = 1

from operator import mul
from functools import reduce
def cmb(n,r):
    if n == 1:
        return 0
    r = min(n-r,r)
    if r == 0:
        return 1
    ov = reduce(mul, range(n, n-r, -1))
    un = reduce(mul, range(1, r+1))
    return ov // un

print(sum([cmb(i, 2) for i in alldict.values()]))