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

n = int(input())
pref = []
suff = []

for i in range(n):
	s = input()
	pos = neg = 0
	for ch in s:
		if ch == '(':
			pos += 1
		elif pos == 0:
			neg += 1
		else:
			pos -= 1
	if pos >= neg:
		pref.append([pos, neg])
	else:
		suff.append([pos, neg])


pref.sort(key=lambda x: x[1])
suff.sort(key=lambda x: -x[0])

totPos = 0

for pos, neg in pref:
	if neg > totPos:
		print("No")
		exit(0)
	totPos -= neg
	totPos += pos

for pos, neg in suff:
	if neg > totPos:
		print("No")
		exit(0)
	totPos -= neg
	totPos += pos

if totPos != 0:
	print("No")
else:
	print("Yes")


### FIXED CODE ###

n = int(input())
ara = [input() for _ in range(n)]
pref = []
suff = []

for s in ara:
	pos = neg = 0
	for ch in s:
		if ch == '(':
			pos += 1
		elif pos == 0:
			neg += 1
		else:
			pos -= 1
	if pos >= neg:
		pref.append([pos, neg])
	else:
		suff.append([pos, neg])


pref.sort(key=lambda x: x[1])
suff.sort(key=lambda x: x[0], reverse=True)

totPos = 0

ara = pref + suff

for pos, neg in ara:
	if neg > totPos:
		print("No")
		exit(0)
	totPos -= neg
	totPos += pos


if totPos != 0:
	print("No")
else:
	print("Yes")
### BUGGY CODE ###

s=list(input())

N=len(s)

f=True
cnt=0
while f:
    f=False
    for i in range(2,N):
        if "".join(s[i-2:i+1])=="ABC":
            s[i-2]="B"
            s[i-1]="C"
            s[i]="A"
            cnt+=1
            f=True
print(cnt)


### FIXED CODE ###

so=input()

s=""

N=len(so)
i=0
while i<N:
    if so[i]=="A":
        s=s+"A"
        i+=1
    elif so[i:i+2]=="BC":
        s=s+"B"
        i+=2
    elif so[i]=="C" or so[i]=="B":
        s=s+"D"
        i+=1

L=len(s)
f=False
cnt=0
a=0
for i in range(L):
    if s[i]=="A":
        f=True
        a+=1
    elif f and s[i]=="B":
        cnt+=a
    elif s[i]=="D":
        f=False
        a=0
print(cnt)
### BUGGY CODE ###

n = int(input())
 
s = input()
 
x = []
 
for i in range(n):
    x.append(s[i])
 
m = len(set(x))
 
import itertools
 
cnt = 0
for i in range(1, m+1):
    p = list(itertools.combinations(s,i))
    cnt += sum(len(pp) == len(set(pp)) for pp in p)
 
print(cnt)

### FIXED CODE ###


n = int(input())

s = input()

x = []

for i in range(n):
    x.append(s[i])

import collections

clist = collections.Counter(x)

y = list(clist.values())

cnt = 1

for item in y:
    cnt = cnt * (item + 1)

cnt = cnt - 1
cnt = cnt % (10 ** 9 + 7)
print(cnt)
### BUGGY CODE ###

import collections
a = input().split()
M = int(a[2])
hidari = []
migi = []
c = []
 
for i in range(M):
  b = input().split()
  hidari.append(b[0])
  migi.append(b[1])
  c.append(b)
  
countleft = collections.Counter(hidari)
countright = collections.Counter(migi)
leftmax = countleft.most_common()[0][1]
rightmax = countright.most_common()[0][1]
tempmax = int(leftmax + rightmax)
 
leftkeys = [k for k, v in countleft.items() if v == leftmax]
rightkeys = [k for k, v in countright.items() if v == rightmax]
 
leftkeyN = int(len(leftkeys))
rightkeyN = int(len(rightkeys))
flag = int(0)
cnt = int(0)
#これで左右の最頻回数はOK
#左右の最頻奴も探した
#ここから最頻同志になってるやつを探す
 
for T in range(M):
  if c[T][0] in leftkeys:
    if c[T][1] in rightkeys:
      cnt = cnt + 1
    else:
      pass
  else:
    pass
 
 
if cnt == int(leftkeyN * rightkeyN):
    print(int(tempmax - 1))
else:
    print(int(tempmax))
    
    
    

### FIXED CODE ###

import collections
a = input().split()
M = int(a[2])
hidari = []
migi = []
c = []
 
for i in range(M):
  b = input().split()
  hidari.append(b[0])
  migi.append(b[1])
  c.append(b)
  
countleft = collections.Counter(hidari)
countright = collections.Counter(migi)
leftmax = countleft.most_common()[0][1]
rightmax = countright.most_common()[0][1]
tempmax = int(leftmax + rightmax)
 
leftkeys = [k for k, v in countleft.items() if v == leftmax]
rightkeys = [k for k, v in countright.items() if v == rightmax]
 
leftkeyN = int(len(leftkeys))
rightkeyN = int(len(rightkeys))
flag = int(0)
cnt = int(0)
#これで左右の最頻回数はOK
#左右の最頻奴も探した
#ここから最頻同志になってるやつを探す
 
for i in range(M):
    goukei = int(countleft.get(c[i][0])) + int(countright.get(c[i][1]))
    if goukei == tempmax:
        cnt += 1
    else:
        pass

if cnt == int(leftkeyN * rightkeyN):
    print(int(tempmax - 1))
else:
    print(int(tempmax))
### BUGGY CODE ###

#Z[i]:length of the longest list starting from S[i] which is also a prefix of S
#O(|S|)
def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg

N=int(input())
S=input()
S=[S[i] for i in range(0,N)]

def condition(num):
    if num==0:
        return True
    for i in range(0,N-2*num+1):
        s=S[i:i+num]
        t=S[i+num:]
        data=Z_algorithm(s+['?']+t)
        for j in range(num+1,len(data)):
            if data[j]==num:
                return True

    return False

start=0
end=N
while end-start>1:
    test=(end+start)//2
    if condition(test):
        start=test
    else:
        end=test

if condition(end):
    print(end)
else:
    print(start)

### FIXED CODE ###

from itertools import groupby

N=int(input())
S=input()
def condition(num):
    if num==0:
        return True
    else:
        flag=0
        data=[]
        for i in range(0,N-num+1):
            data.append([S[i:i+num],i])
        data.sort()
        partdata=[data[i][0] for i in range(0,len(data))]
        partdata=groupby(partdata)
        subdata=[]
        for key,group in partdata:
            g=len(list(group))
            subdata.append(g)
        s=0
        t=subdata[0]-1
        if len(subdata)==1:
            if data[t][1]-data[s][1]>=num:
                flag=1
        for i in range(0,len(subdata)-1):
            if data[t][1]-data[s][1]>=num:
                flag=1
            s=t+1
            t=t+subdata[i+1]
        if data[t][1]-data[s][1]>=num:
            flag=1
        return flag==1

start=0
end=N
while end-start>1:
    test=(end+start)//2
    if condition(test):
        start=test
    else:
        end=test
if condition(end):
    print(end)
else:
    print(start)
### BUGGY CODE ###

N,Q = list(map(int, input().split()))
S = list(input())
L = []
for _ in range(Q):
    temp = list(map(int, input().split()))
    L.append(temp)
I = []
for i in range(len(S)-1):
    if S[i] == "A" and S[i+1] == "C":
        I.append(i)
for j in range(Q):
    cnt = 0
    l,r = L[j]
    R = []
    for k in range(l-1,r-1):
        R.append(k)
    for i in I:
        if i in R:
            cnt += 1
    print(cnt)

### FIXED CODE ###

def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
H_dict = []
cnt = 0
for h in range(N):
    tmp_h = H[h]
    cnt2 = 0
    for ab in AB:
        if h+1 in ab:
            left = [i for i in ab if i != h + 1]
            z = left[0]
            if H[z-1] >= tmp_h:
                cnt2 += 1
    if cnt2 == 0:
        cnt += 1
print(cnt)

### FIXED CODE ###

N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
cnt = 0
new = [0 for i in range(N)]
for ab in AB:
    if H[ab[0]-1] <= H[ab[1]-1]:
        new[ab[0]-1] += 1
    if H[ab[0] - 1] >= H[ab[1] - 1]:
        new[ab[1]-1] += 1
print(new.count(0))
### BUGGY CODE ###

n,m = map(int,input().split())
k = n
while True:
    if m % k == 0:
        print(m//k)
        break
    k += 1

### FIXED CODE ###

n,m = map(int,input().split())
divisors = []
for i in range(1,int(m**0.5)+1):
    if m % i == 0:
        divisors.append(i)
        divisors.append(m//i)
divisors.sort()
k = 0
for i in range(len(divisors)):
    if divisors[i] > m/n:
        k = i - 1
        break
    if i == len(divisors) - 1:
        k = len(divisors) - 1
print(divisors[k])
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

dp = [[0] * 13 for i in range(len(S)+1)]

dp[0][0] = 1

for i in range(len(S)):
    if S[i] == "?":
        c = -1
    else:
        c = int(S[i])
    for j in range(0, 10):
        if c != -1 and c != j:
            continue
        for k in range(0, 13):
            # dp[i+1][(10*k + j) % 13] = (dp[i+1][(10*k+j) % 13] + dp[i][k]) % mod
            dp[i+1][(10*k+j) % 13] = (dp[i+1][(10*k+j) % 13] + dp[i][k]) % mod
print(dp[len(S)][5])


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

dp = [[0] * 13 for i in range(len(S)+1)]

dp[0][0] = 1

for i in range(len(S)):
    if S[i] == "?":
        c = -1
    else:
        c = int(S[i])
    for j in range(0, 10):
        if c != -1 and c != j:
            continue
        for k in range(0, 13):
            # dp[i+1][(10*k + j) % 13] = (dp[i+1][(10*k+j) % 13] + dp[i][k]) % mod
            dp[i+1][(10*k+j) % 13] = (dp[i+1][(10*k+j) % 13] + dp[i][k]) % mod
print(dp[len(S)][5])
### BUGGY CODE ###

from collections import deque
N, K = map(int, input().split())
      
A =  list(map(int, input().split()))
B = [0] * (N + 1)

for i in range(N):
  B[i+1] = A[i]

start = 1
d = deque([])
first = 0
while True:
  a = B[start]
  start = a
  first += 1
  if d.count(a) == 1:
    break
  d.append(a)

second = 0
start_ = start
while True:
  start_ = B[start_]
  second += 1
  if start_ == start:
    break

if K <= first:
  S = 1
else:
  K -= first
  K %= second
  S = start

for i in range(K):
  S = B[S]
print(S)

### FIXED CODE ###

def main():

  N, K = map(int, input().split())   
  A = [0] + list(map(int, input().split()))
  cur = 1
  visited = [-1] * (N + 1)
  visited[cur] = 0
  for i in range(1, K + 1):
    next_cur = A[cur]
    if next_cur == cur:
      print(next_cur)
      return
    elif visited[next_cur] != -1:
      mod = i - visited[next_cur]
      start = visited[next_cur]
      break
    else:
      visited[next_cur] = visited[cur] + 1
      cur = next_cur
  else:
    print(next_cur)
    return
  K = (K - start) % mod
  print(visited.index(K+start))
  
  
if __name__ == "__main__":
  main()
### BUGGY CODE ###

l, n = [], int(input().strip())

for _ in range(n):
    opr, word = input().strip().split()
    word = int(word.translate(str.maketrans('ACGT', '1234')), base=5)
    if opr.startswith('i'):
        l.append(word)
    else:
        print('yes' if word in l else 'no')

### FIXED CODE ###

l, n, r = set(), int(input()), str.maketrans('ACGT', '1234')

for _ in range(n):
    opr, word = input().split()
    word = int(word.translate(r), base=5)
    if opr.startswith('i'):
        l.add(word)
    else:
        print('yes' if word in l else 'no')
### BUGGY CODE ###

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

sum = 0

for i in range(N - 1):
  for j in range(i + 1, N):
    sum += A[i] * A[j]
    
ans = sum % (10**9 + 7)

print(ans)


### FIXED CODE ###

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

for i in range(N):
  sum_a += A[i] 

for i in range(N):
  sum_a -= A[i]
  sum += A[i] * sum_a
  ans = sum % (10**9 + 7)

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

x = int(input())
prime = []
for i in range(2,2*x):
    prime_check = 0
    for j in prime:
        if i % j == 0:
            prime_check = 1
            break
    if prime_check == 0:
        if i >= x:
            ans = i
            break
        else:
            prime.append(i)
print(ans)

### FIXED CODE ###

x = int(input())
prime = []
for i in range(2,2*x):
    prime_check = 0
    for j in prime:
        if i % j == 0:
            prime_check = 1
            break
    if prime_check == 0:
        if i >= x:
            ans = i
            break
        else:
            prime.append(i)
print(ans)
### BUGGY CODE ###

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


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(N)]
for i in A:
    B[i - 1] += 1
for i in B:
    print(i)
### BUGGY CODE ###

n = list(map(int, input().split()))
re = True
num = n[0]
if n[1] == 1:
  print(0)
elif n[1] == 2:
  if n[0]%2 == 0:
    print(0)
  else:
    print(1)
else:
  while re:
    k = num - n[1]
    if num > abs(k):
      num = abs(k)
    else:
      re = False
  print(num)

### FIXED CODE ###

n = list(map(int, input().split()))
k = n[0] % n[1]

if abs(k - n[1]) > k:
  print(k)
else:
  print(abs(k - n[1]))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	#S = list(input())
	#L,R = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	A = input().split()
	A = [int(s) for s in A]

	ans = [0 for _ in range(N)]
	
	ed = min(A[0]*2, A[-1]*2)
	for i in range(ed, -1, -2):
		fin = True
		for j in range(N):
			if j == 0:
				ans[j] = i
				continue
			tmp = (A[j-1] - (ans[j-1] / 2))*2

			if tmp < 0 or tmp % 2 == 1:
				fin = False
				break
			else :
				ans[j] = int(tmp)
		
		if fin == False:
			pass
		else:
			if (ans[-1] / 2) + (ans[0] / 2) == A[-1]:
				#print("sss")
				break

	ans = [str(a) for a in ans]
	print(' '.join(ans))


if __name__ == "__main__":
	main()

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	tmp = 0
	for i, val in enumerate(A):
		if i == 0:
			tmp += 2*val
			continue
		if i % 2 == 1:
			tmp -= 2*val
		else:
			tmp += 2*val
	
	x = tmp / 2
	
	ans = []
	ans.append(int(x))
	for i, val in enumerate(A):
		tmp = (val - (ans[i]/2)) * 2
		ans.append(int(tmp))
	
	ans = ans[:-1]
	ans = [str(s) for s in ans]
	print(" ".join(ans))
	
if __name__ == "__main__":
	main()
### BUGGY CODE ###

import os

def main():
	n = int(input())
	syo_list = []
	count = 0
	for i in range(n):
		syo = input()
		if not syo in syo_list:
			syo_list.append(syo)
			count += 1
	print(count)

if __name__  == "__main__":
	main()


### FIXED CODE ###

import os

def main():
	n = int(input())
	syo_list = []
	for i in range(n):
		syo = input()
		syo_list.append(syo)
	print(len(set(syo_list)))

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

import math

n, m = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for i in range(n):
  if a[i] in d:
    l = d[a[i]]
    l.append(i)
    d[a[i]] = l    
  else:
    d[a[i]] = [i]

for i in range(m):
  b = max(a)
  li = d[b]
  li0 = li.pop(0)
  d[b] = li
  a[li0] = b/2
  if b/2 in d:
    l = d[b/2]
    l.append(li0)
    d[b/2] = l
  else:
    d[b/2] = [li0]

ans = 0
for i in a:
  ans += math.floor(i)
print(ans)

### FIXED CODE ###

import math
import heapq

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

hq = []
for i in range(n):
  heapq.heappush(hq, a[i]*(-1))

for i in range(m):
  b = heapq.heappop(hq)
  b = ((-1)*b)//2
  heapq.heappush(hq, b*(-1))

ans = 0
for i in hq:
  ans += i *(-1)
print(ans)
### BUGGY CODE ###

n, m = [int(i) for i in input().split()]

a = list(map(int, input().split()))
b = []
c = []

for i in range(m):
    b.append(0)
    c.append(0)
    b[i], c[i] = [int(j) for j in input().split()]
a.sort()
cnt = 0
for i in range(m):
    for j in range(n):
        if(cnt >= b[i]):
            break
        if(c[i] > a[j]):
            a[j] = c[i]
            cnt += 1
    cnt = 0
    a.sort()
print(sum(a))

### FIXED CODE ###

import copy

n, m = [int(i) for i in input().split()]
ans = []
a = list(map(int, input().split()))
for i in range(len(a)):
    ans.append([1, a[i]])
for i in range(m):
    d, e = [int(i) for i in input().split()]
    ans.append([d, e])

ans1 = sorted(ans, key=lambda x: x[1], reverse = True)
cnt = 0
ans2 = 0
k = 0
while cnt < n:
    ans2 += ans1[k][0] * ans1[k][1]
    cnt += ans1[k][0]
    k += 1
ans2 -= (cnt - n) * ans1[k-1][1]
print(ans2)
### BUGGY CODE ###

#import sys
#input = sys.stdin.readline
 
n = int(input())
a =[int(i) for i in input().split()]
b =[int(i) for i in input().split()]
 
cnt, prev_cnt = 0, -1
while cnt != prev_cnt:
    prev_cnt = cnt
    for i in range(n):
        
        adj_sum = b[i - 1] + b[(i + 1) % n]
        k = (b[i] - a[i]) // adj_sum
        if k > 0:
            b[i] -= k * adj_sum
            cnt += k
 
print(cnt if a == b else -1)

### FIXED CODE ###

#import sys
#input = sys.stdin.readline

n = int(input())
a = [0]*n
b = [0]*n
a =[int(xi) for xi in input().split()]
b =[int(yi) for yi in input().split()]

cnt, prev_cnt = 0, -1
while cnt != prev_cnt:
    prev_cnt = cnt
    for i in range(n):
        
        adj_sum = b[i - 1] + b[(i + 1) % n]
        k = (b[i] - a[i]) // adj_sum
        if k > 0:
            b[i] -= k * adj_sum
            cnt += k

print(cnt if a == b else -1)
### BUGGY CODE ###

if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split(" ")))

    count = 0
    for i in range(n):
        flag = 0
        for j in range(n):
            if i > j:
                if p[i] > p[j]:
                    flag = 1
                    break
                    # print(i, j)
        if flag == 0:
            count = count + 1

    print(count)

### FIXED CODE ###

if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split(" ")))

    count = 0
    min_num = 10000000
    for i in p:
        if i < min_num:
            count = count + 1
            min_num = i

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

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

for i in a:
    if i in ball.keys():
        ball[i] += 1
    else:
        ball[i] = 1

ball = sorted(ball.items(), key=lambda x: -x[1])

ans = 0
if len(ball) > k:
    for i in range(k):
        ans += ball[i][1]
    ans = n - ans
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
ball = [0]*n

for i in a:
    ball[i - 1] += 1
ball.sort(reverse=True)

ans = 0
if len(ball) > k:
    for i in range(k):
        ans += ball[i]
    ans = n - ans
print(ans)
### BUGGY CODE ###

n = int(input())
s = []
for _ in range(n):
    tmp=sorted(input(), key=str.lower)
    s.append(tmp)
cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        if s[i]==s[j]:
            cnt+=1
print(cnt)


### FIXED CODE ###

N = int(input())
S = [''.join(sorted(input().rstrip())) for _ in range(N)]
 
from collections import Counter
counter = Counter(S)
 
answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)
### BUGGY CODE ###

n = int(input())
sum = 0
l = []
for _ in range(0,n):
    s = input()
    if s in l:
        continue
    else:
        l.append(s)
        sum += 1

print(sum)

### FIXED CODE ###

n = int(input())
sum = 0
l = set()
for _ in range(0,n):
    s = input()
    if s in l:
        continue
    else:
        l.add(s)
        sum += 1

print(sum)