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

from bisect import bisect_left


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    mask = 1
    target = 1
    ans = 0
    for _ in range(29):
        C = [b & mask for b in B]
        C.sort()
        cnt = 0
        for a in A:
            a = a & mask
            idx1 = bisect_left(C, target*1-a)
            idx2 = bisect_left(C, target*2-a)
            idx3 = bisect_left(C, target*3-a)
            cnt += (N - idx3) + (idx2 - idx1)
        ans += target * (cnt % 2)
        mask <<= 1
        mask |= 1
        target <<= 1
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from bisect import bisect_left


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    mask = 1
    target = 1
    ans = 0
    for _ in range(29):
        AA = sorted([a & mask for a in A], reverse=True)
        BB = sorted([b & mask for b in B])
        cnt = 0
        idx1 = 0  # idx of target*1-a
        idx2 = 0  # idx of target*2-a
        idx3 = 0  # idx of target*3-a
        for a in AA:
            while idx1 < N and a+BB[idx1] < target*1:
                idx1 += 1
            while idx2 < N and a+BB[idx2] < target*2:
                idx2 += 1
            while idx3 < N and a+BB[idx3] < target*3:
                idx3 += 1
            cnt += (N - idx3) + (idx2 - idx1)
        ans += target * (cnt % 2)
        mask <<= 1
        mask |= 1
        target <<= 1
    print(ans)


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

n=input()
a=map(int,raw_input().split())
#print n
#print a

a1_sum=0
a1=[]
for i in a:
	a1_sum+=i
	a1.append(a1_sum)

#print a1


#+,-
b=[]
for i,val in enumerate(a1):
	for j in b:
		val+=j
	if i%2==0:
		if val>0:
			pass
		else:
			t_val=1-val
			b.append(t_val)
	else:
		if val<0:
			pass
		else:
			t_val=-1-val
			b.append(t_val)
ans1=0
if len(b)==0:
	ans1=0
else:
	for i in b:
		ans1+=abs(i)

#-,+
b=[]
for i,val in enumerate(a1):
	for j in b:
		val+=j
	if i%2==0:
		if val<0:
			pass
		else:
			t_val=-1-val
			b.append(t_val)
	else:
		if val>0:
			pass
		else:
			t_val=1-val
			b.append(t_val)

ans2=0
if len(b)==0:
	ans2=0
else:
	for i in b:
		ans2+=abs(i)


print min(ans1,ans2)
			
			



### FIXED CODE ###

n=input()
a=map(int,raw_input().split())
#print n
#print a

a1_sum=0
a1=[]
for i in a:
	a1_sum+=i
	a1.append(a1_sum)

#print a1


#+,-
b=[]
chn_val=0
for i,val in enumerate(a1):
	val+=chn_val
	if i%2==0:
		if val>0:
			pass
		else:
			t_val=1-val
			chn_val+=t_val
			b.append(t_val)
	else:
		if val<0:
			pass
		else:
			t_val=-1-val
			chn_val+=t_val
			b.append(t_val)
ans1=0
if len(b)==0:
	ans1=0
else:
	for i in b:
		ans1+=abs(i)

#-,+
b=[]
chn_val=0
for i,val in enumerate(a1):
	val+=chn_val
	if i%2==0:
		if val<0:
			pass
		else:
			t_val=-1-val
			chn_val+=t_val
			b.append(t_val)
	else:
		if val>0:
			pass
		else:
			t_val=1-val
			chn_val+=t_val
			b.append(t_val)

ans2=0
if len(b)==0:
	ans2=0
else:
	for i in b:
		ans2+=abs(i)


print min(ans1,ans2)
### BUGGY CODE ###

N = int(input())
sX = input()

origin_count = sX.count('1')
one_r_count = origin_count -1
zero_r_count = origin_count +1

one_mod = 0
zero_mod =0
for i in range(N):
    if(one_r_count != 0):
        one_mod = (one_mod * 2) + int(sX[i]) % one_r_count
    zero_mod = (zero_mod * 2 ) + int(sX[i]) % zero_r_count

f = [0] * 220000
pop = [0]* 220000

for i in range(1,220000):
    pop[i] = pop[i//2] + i%2
    f[i] = f[i % pop[i]] + 1

onepow = [1] * 220000
zeropow = [1]* 220000

for i in range(1,220000):
    if(one_r_count != 0):
        onepow[i] = onepow[i-1] * 2 % one_r_count
    zeropow[i] = zeropow[i-1] * 2 % zero_r_count

for i in range(1,N+1):
    if(sX[i-1] == '1'):
        if(one_r_count != 0):
            Xi_n = one_mod - onepow[N-i]
            Xi_n %= one_r_count
            print(f[Xi_n]+1)
        else:
            print(0)
    else:
        Xi_n = zero_mod + zeropow[N-i]
        Xi_n %= zero_r_count
        print(f[Xi_n]+1)



### FIXED CODE ###

N = int(input())
sX = input()

origin_count = sX.count('1')
one_r_count = origin_count -1
zero_r_count = origin_count +1

one_mod = 0
zero_mod =0
for b in sX:
    if one_r_count != 0:
        one_mod = (one_mod * 2 + int(b) )% one_r_count
    zero_mod = (zero_mod * 2  + int(b) )% zero_r_count

f = [0] * 220000
pop = [0]* 220000

for i in range(1,220000):
    pop[i] = pop[i//2] + i % 2
    f[i] = f[i % pop[i]] + 1

onepow = [1] * 220000
zeropow = [1]* 220000

for i in range(1,220000):
    if one_r_count != 0:
        onepow[i] = onepow[i-1] * 2 % one_r_count
    zeropow[i] = zeropow[i-1] * 2 % zero_r_count

for i in range(1,N+1):
    if sX[i-1] == '1':
        if one_r_count != 0:
            Xi_n = one_mod - onepow[N-i]
            Xi_n %= one_r_count
            print(f[Xi_n]+1)
        else:
            print(0)
    if sX[i-1] == '0':
        Xi_n = zero_mod + zeropow[N-i]
        Xi_n %= zero_r_count
        print(f[Xi_n]+1)
### BUGGY CODE ###

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

i = 0
while i < n:
  j = i+1
  while j < n:
    if a_list[i] == a_list[j]:
      print("NO")
      exit()
    j += 1
  i += 1

print("YES")

### FIXED CODE ###

import collections

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

a_counter = collections.Counter(a_list)

ans = "YES"
for value in a_counter.values():
  if value > 1:
    ans = "NO"
    break

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

import math
A,B,N = list(map(int,input().split()))
ans = 0
c = int()
for i in range(N+1):
    c = math.floor(A*i/B)-(A*math.floor(i/B))
    if ans <= c:
        ans  =c
    if ans > c:
        break

print(ans)

### FIXED CODE ###

import math
A,B,N = list(map(int,input().split()))
c = int()
if B-1 > N:
    i = N
else:
    i = B-1
c = math.floor(A*i/B)-(A*math.floor(i/B))

print(c)
### BUGGY CODE ###

from collections import Counter
import math

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

c2 = math.factorial(2)

memory = {}

for k in range(1, N+1):
    a = A[:k-1] + A[k:]
    count = Counter(a)

    sum = 0
    for k, v in count.items():
        if v < 2:
            continue
        kvs = '%d,%d' % (k,v)
        if kvs in memory:
            sum += memory[kvs]
        else:
            memory[kvs] = math.factorial(v) // (math.factorial(v - 2) * c2)
            sum += memory[kvs]
    print(sum)

### FIXED CODE ###

from collections import Counter
import math

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

c = Counter(A)

all_ans = 0
for n in c.values():
    if n <= 1:
        continue
    all_ans += math.factorial(n)//(math.factorial(n-2)*math.factorial(2))

for n in A:
    print(all_ans - (c[n]-1))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000)

N, Y = map(int, input().split())
Y = Y // 1000

def find(num, yen):
    if num == 0:
        if yen == 0:
            return [0, 0, 0]
        return None
    #残り全部1万円でも足りない or 残り全部1000円でもオーバーするなら打ち切り
    if num * 10 < yen or num > yen:
        return None

    if yen >= 10:
        r = find(num - 1, yen - 10)
        if r != None:
            r[0] += 1
            return r
    if yen >= 5:
        r = find(num - 1, yen - 5)
        if r != None:
            r[1] += 1
            return r
    if yen >= 1:
        r = find(num - 1, yen - 1)
        if r != None:
            r[2] += 1
            return r
    return None

r = find(N, Y)
if r is None:
    print(-1, -1, -1)
else:
    print(r[0], r[1], r[2])

### FIXED CODE ###

N, Y = map(int, input().split())
Y = Y // 1000

for y10 in range(0, N + 1):
    remain = N - y10
    if y10 * 10 > Y:
        break
    for y5 in range(0, remain + 1):
        y1 = N - y10 - y5
        t = y1 + y5 * 5 + y10 * 10
        if t == Y:
            print(y10, y5, y1)
            exit()
print(-1, -1, -1)
### BUGGY CODE ###

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

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10**9 + 7

memo = [[0] * M for _ in range(N)]
def dfs(i, j):
    if i < 0 or j < 0:
        return 1
    if memo[i][j] != 0:
        return memo[i][j]
    if S[i] == T[j]:
        memo[i][j] = (dfs(i-1, j) + dfs(i, j-1)) % mod
    else:
        memo[i][j] = (dfs(i-1, j) + dfs(i, j-1) - dfs(i-1, j-1)) % mod
    return memo[i][j]

print(dfs(N-1, M-1))

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10**9 + 7

dp = [[0] * (M+1) for _ in range(N+1)]
for i in range(N+1):
    for j in range(M+1):
        if i == 0 or j == 0:
            dp[i][j] = 1
        elif S[i-1] == T[j-1]:
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod
        else:
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod
print(dp[-1][-1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from math import factorial
from bisect import bisect
from functools import reduce

def func(x, arr):
    p = bisect(arr, x)
    num = 1
    for i in range(p + 1, len(arr) + 1):
        num = (num * i) % MOD
    arr = arr[:p]
    if len(arr) == 0:
        return x * num
    ret = 0
    num2 = 1
    for i in range(len(arr) - 1, -1, -1):
        tmp = func(x % arr[i], arr[:i]) * num2 % MOD
        ret = (ret + tmp) % MOD
        num2 = num2 * i % MOD
    return ret * num % MOD

def main():
    N, X = LI()
    S = LI()
    S.sort()
    ans = func(X, S)

    return ans

print(main())

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from math import factorial
from collections import Counter

def main():
    N, X = LI()
    S = LI()
    S.sort(reverse=True)
    dp = Counter()
    dp[X] = factorial(N)
    for i, s in enumerate(S):
        pre = dp
        dp = Counter()
        for n, cnt in pre.items():
            if s <= n:
                dp[n] += cnt * (N - 1 - i) // (N - i)
                dp[n % s] += cnt // (N - i)
            else:
                dp[n] += cnt
    ans = 0
    for n, cnt in dp.items():
        ans = (ans + (n * cnt) % MOD) % MOD

    return ans

print(main())
### BUGGY CODE ###

import copy

h,w = map(int,input().split())
#a = [input() for _ in range(h)]
a = [list(input()) for _ in range(h)]
b = [[False]*w for _ in range(h)]
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    if cnt > 0:
        c = copy.deepcopy(tmp)
        ans += 1
    else:
        break

print(ans)


### FIXED CODE ###

import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

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

#!/usr/bin/env python3

import itertools

N = int(input())
S = str(input())

l_pw = []
if N-3 == 1:
    for i in range(N):
        l_S = list(S)
        l_S.pop(i)
        l_pw.append(','.join(l_S))
else:
    combs = list(itertools.combinations(range(N), N-3))
    for comb in combs:
        l_S = list(S)
        for i in sorted(comb, reverse=True):
            l_S.pop(i)
        l_pw.append(','.join(l_S))

print(len(set(l_pw)))


### FIXED CODE ###

#!/usr/bin/env python3

import itertools

N = int(input())
S = str(input())

# 暗証番号Vを000から999まで決め打ちすると、次の問題を1000回解けば良いことになる。
# SからN-3桁を消して、Vを作ることができるか。
# この問題は貪欲法で解くことができる。
# - 1. S_i = V_1であるようなiのうち、最小のiをp_1とする。そのようなiが存在しなければ、Vを作ることはできない。
# - 2. S_i = V_2であるようなiのうち、p_1より大きい、かつ最も小さいiをp_2とする。そのようなiが存在しなければ、Vを作ることはできない。
# - 3. S_i = V_3であるようなiのうち、p_2より大きい、かつ最も小さいiをp_3とする。そのようなiが存在しなければ、Vを作ることはできない。
# e.g., S = 869120, V = 812
# - V_1 = 8より、p_1 = 0
# - V_2 = 1, p_1 = 0より、p_2 = 3
# - V_3 = 2, p_2 = 3より、p_3 = 4

def can_make_pw(S, password):
    # step1
    v1 = password[0]
    p1 = S.find(v1)
    if p1 == -1:
        return False
    # step2
    v2 = password[1]
    p2 = S.find(v2, p1+1)
    if p2 == -1:
        return False
    # step3
    v3 = password[2]
    p3 = S.find(v3, p2+1)
    if p3 == -1:
        return False
    return True

passwords = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            password = str(i) + str(j) + str(k)
            passwords.append(password)
# print(passwords)

count = 0
for password in passwords:
    if can_make_pw(S, password):
        # print(f"You can make {password} from {S}")
        count += 1

print(count)

# 全探索はTLE
# l_pw = []
# if N-3 == 1:
#     for i in range(N):
#         l_S = list(S)
#         l_S.pop(i)
#         l_pw.append(','.join(l_S))
# else:
#     combs = list(itertools.combinations(range(N), N-3))
#     for comb in combs:
#         l_S = list(S)
#         for i in sorted(comb, reverse=True):
#             l_S.pop(i)
#         l_pw.append(','.join(l_S))
# print(len(set(l_pw)))
### BUGGY CODE ###

N,K=map(int,input().split())
D=[]
X=[]
Y=[]

for i in range(N):
    x,y=map(int,input().split())
    D.append([x,y])
    X.append(x)
    Y.append(y)
    
X.sort()
Y.sort()
D.sort()
ans=10**20
for a in range(len(X)):
    for b in range(len(X)-a):
        if len(X)-b-a<K:
            break
        for c in range(len(Y)):
            for d in range(len(Y)-c):
                cnt=0
                for e in range(a,len(X)-b):
                    if X[a]<=D[e][0]<=X[len(X)-1-b] and Y[c]<=D[e][1]<=Y[len(Y)-1-d]:
                        cnt+=1
                if cnt>=K and ans>abs(X[a]-X[len(X)-1-b])*abs(Y[c]-Y[len(Y)-1-d]):
                    ans=abs(X[a]-X[len(X)-1-b])*abs(Y[c]-Y[len(Y)-1-d])
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
D=[]
X=[]
Y=[]

for i in range(N):
    x,y=map(int,input().split())
    D.append([x,y])
    X.append(x)
    Y.append(y)
    
X.sort()
Y.sort()
D.sort()
ans=10**20
for a in range(len(X)):
    for b in range(len(X)-a):
        if len(X)-b-a<K:
            break
        for c in range(len(Y)):
            for d in range(len(Y)-c):
                cnt=0
                for e in range(a,len(X)-b):
                    if X[a]<=D[e][0]<=X[len(X)-1-b] and Y[c]<=D[e][1]<=Y[len(Y)-1-d]:
                        cnt+=1
                if cnt>=K and ans>abs(X[a]-X[len(X)-1-b])*abs(Y[c]-Y[len(Y)-1-d]):
                    ans=abs(X[a]-X[len(X)-1-b])*abs(Y[c]-Y[len(Y)-1-d])
print(ans)
### BUGGY CODE ###

n=int(input())
a=[int(i) for i in input().split()]
b=[]
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0,a[i])
    
if n%2==0:
    print(*b)
else:
    print(*b[::-1])

### FIXED CODE ###

from collections import deque
n=int(input())
a=deque([int(i) for i in input().split()])
b=deque()

if n%2==0:
    for i in range(n):
        if i % 2 == 0:
            b.append(a.popleft())
        else:
            b.appendleft(a.popleft())
else:
    for i in range(n):
        if i % 2 == 0:
            b.appendleft(a.popleft())
        else:
            b.append(a.popleft())
print(*b)
### BUGGY CODE ###

S = [input()]
Q = int(input())
querys = [input() for _ in range(Q)]
is_reverse = False

for q in querys:
    query = q.split()
    if len(query) == 1:
        is_reverse = not is_reverse
        continue
    _, f, c = query
    if is_reverse:
        
        if f == "1":
            S = S + [c]
        elif f == "2":
            S = [c] + S
    else:
        if f == "1":
            S = [c] + S
        elif f == "2":
            S = S + [c]
if is_reverse:
    print("".join(S)[::-1])
else:
    print("".join(S))


### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())
querys = [input() for _ in range(Q)]
is_reverse = False
d = deque([S])

for q in querys:
    query = q.split()
    if len(query) == 1:
        is_reverse = not is_reverse
        continue
    _, f, c = query
    if is_reverse:
        
        if f == "1":
            d.append(c)
        elif f == "2":
            d.appendleft(c)
    else:
        if f == "1":
            d.appendleft(c)
        elif f == "2":
            d.append(c)
if is_reverse:
    print("".join(d)[::-1])
else:
    print("".join(d))
### BUGGY CODE ###

n,k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ans = []
for a,b in ab:
    ans += [a] * b
ans.sort()
print(ans[k-1])

### FIXED CODE ###

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

n = 0
for i in range(N):
  if n + ab[i][1] < K:
    n += ab[i][1]
  else:
    print(ab[i][0])
    break
### BUGGY CODE ###

num,product = map(int,input().split())
order = len(str(product)) / num
cnt = round(10 ** order)
gcd = 1
while(cnt > 1):
    calc = cnt ** num
    if calc > product:
        cnt = cnt - 1
        continue
    if product % calc == 0:
        gcd = cnt
        break
    else:
        cnt = cnt - 1
print(gcd)

### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import defaultdict
from math import sqrt,floor
num,product = map(int,input().split())
cnt = int(sqrt(product) + 2)
dd = defaultdict(int)

for i in range(2,cnt):
    if product % i == 0:
        a = 0
        while product % i == 0:
            a += 1
            product = product // i
        dd[i] = a
if product != 1:
    dd[product] =  1
ans = 1
for p,n in dd.items():
    ans *= pow(p,floor(n/num))
print(ans)
### BUGGY CODE ###

def two(x):
    lis=[]
    for i in range(50):
        lis.append(x%2)
        x=x//2
    return lis

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

tl=[]
for i in range(50):
    tl.append(2**i)

lis=[0 for i in range(50)]

for ai in a:
    for j in range(50):
        lis[j]=(lis[j]+two(ai)[j])%2

ans=[]
for ai in a:
    ansi=0
    for j in range(50):
        if two(ai)[j]!=lis[j]:
            ansi+=tl[j]
    ans.append(ansi)

print(*ans)

### FIXED CODE ###

def two(x):
    lis=[]
    for i in range(50):
        lis.append(x%2)
        x=x//2
    return lis

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

tl=[]
for i in range(50):
    tl.append(2**i)

lis=[0 for i in range(50)]

for ai in a:
    twoi=two(ai)
    for j in range(50):
        lis[j]=(lis[j]+twoi[j])%2

ans=[]
for ai in a:
    ansi=0
    twoi=two(ai)
    for j in range(50):
        if twoi[j]!=lis[j]:
            ansi+=tl[j]
    ans.append(ansi)

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

import sys
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = []
for q in range(Q):
    bc = list(map(int, input().split()))
    BC.append(bc)


for bc in BC:
    ind = [i for i, x in enumerate(A) if x==bc[0]]
    for i in ind:
        A[i] = bc[1]
    print(sum(A))

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A)
Q = int(input())
ans = []
s = sum(A)
for _ in range(Q):
    b, c = map(int, input().split())
    n = cnt[b]
    if b in cnt:
        cnt[c] += cnt[b]
        del cnt[b]
    s += (c-b)*n
    print(s)
### BUGGY CODE ###

N=int(input())

import sys
input = sys.stdin.readline

s=[list(input()) for i in range(N)]

for i in range(N):
    s[i].sort()

s.sort()

out=0

for i in range(N):
    for j in range(i+1,N,1):
        if s[i]==s[j]:
            out+=1
        else:
            continue

print(out)


### FIXED CODE ###

N=int(input())

import sys
input = sys.stdin.readline

s=[list(input()) for i in range(N)]

for i in range(N):
    s[i].sort()

out=0

d={}

for i in range(N):
    if str(s[i]) in d:
        out+=d[str(s[i])]
        d[str(s[i])]+=1
    else:
        d[str(s[i])]=1

print(out)
### BUGGY CODE ###

import numpy as np
S = list(input())
n = len(S)
right = np.ones(n, dtype=np.int64)
left = np.ones(n, dtype=np.int64)
for i, s in enumerate(S):
  if s == 'R':
    left[i] = 0
  else:
    right[i] = 0
zeros = np.zeros(n, dtype=np.int64)
cnt = 1
first = np.ones(n, dtype=np.int64)
second = np.copy(zeros)
second[1:] += (first * right)[:-1]
second[:-1] += (first * left)[1:]

if np.all(first == second):
  print(*second)
else:
  while True:
    cnt += 1
    third = np.copy(zeros)
    third[1:] += (second * right)[:-1]
    third[:-1] += (second * left)[1:]
    if np.all(first == third):
      break
    else:
      first = second
      second = third
  if cnt % 2 == 0:
    print(*third)
  else:
    print(*second)

### FIXED CODE ###

import numpy as np
S = list(input())
n = len(S)
ans = [0] * n
right_flag = False
for i, s in enumerate(S):
  if s == 'R' and right_flag is False:
    right_index = i
    right_flag = True
  elif s == 'L' and right_flag:
    right_flag = False
    cnt = i - right_index
    odd = cnt // 2
    even = cnt - odd
    ans[i-1] += even
    ans[i] += odd
left_flag = False
for i, s in enumerate(S[::-1], 1):
  if s == 'L' and left_flag is False:
    left_index = i
    left_flag = True
  elif s == 'R' and left_flag:
    left_flag = False
    cnt = i - left_index
    odd = cnt // 2
    even = cnt - odd
    ans[-i+1] += even
    ans[-i] += odd
print(*ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100000000)
n,q= map(int,input().split())
nodes = [[]for _ in range(n+1)]
value = [0 for _ in range(n+1)]
for i in range(n-1):
    a,b = map(int,sys.stdin.readline().split())
    nodes[a].append(b)
    nodes[b].append(a)
query = []
for i in range(q):
    a, b = map(int, sys.stdin.readline().split())
    value[a]+=b
def dfs(node,p,score):
    for v in nodes[node]:
        if v !=p:
            value[v]+=score
            dfs(v,node,value[v])

dfs(1,-1,value[1])
for i in range(1,n+1):
    sys.stdout.write('{} '.format(int(value[i])))



### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)
n,q= map(int,input().split())
nodes = [[]for _ in range(n+1)]
value = [0 for _ in range(n+1)]
for i in range(n-1):
    a,b = map(int,sys.stdin.readline().split())
    nodes[a].append(b)
    nodes[b].append(a)
query = []
for i in range(q):
    a, b = map(int, sys.stdin.readline().split())
    value[a]+=b
def dfs(node,p,score):
    for v in nodes[node]:
        if v !=p:
            value[v]+=score
            dfs(v,node,value[v])

dfs(1,-1,value[1])
for i in range(1,n+1):
    sys.stdout.write('{} '.format(int(value[i])))