Problem:


Score : 300 points

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

s_1, s_2, \ldots, s_N are all distinct.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.



Sample input:
3
acornistnt
peanutbomb
constraint


Sample output:
1

Submission status: Runtime Error

Solution code:
from collections import Counter as co
from itertools import combinations as com
from operator import mul
from functools import reduce

def combinations_count(n, r):
  r = min(r, n - r)
  numer = reduce(mul, range(n, n - r, -1), 1)
  denom = reduce(mul, range(1, r + 1), 1)
  return numer//denom

n=int(input())
a=0
l=co([set(co(input())) for i in range(n)])
for d,s in l.items():
  if d>=2:a+=combinations_count(d, 2)
print(a)

Submission status: Runtime Error

Solution code:
from collections import Counter as co
from itertools import combinations as com
from operator import mul
from functools import reduce

def combinations_count(n, r):
  r = min(r, n - r)
  numer = reduce(mul, range(n, n - r, -1), 1)
  denom = reduce(mul, range(1, r + 1), 1)
  return numer//denom

n=int(input())
a=0
l=co([set(co(input())) for i in range(n)])
for d,s in l.items():
  if s>=2:a+=combinations_count(s, 2)
print(a)

Submission status: Runtime Error

Solution code:
from collections import Counter as co
from itertools import combinations as com
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

n=int(input())
a=0
l=co([set(co(input())) for i in range(n)])
for d,s in l.items():
  if s>=2:a+=combinations_count(s, 2)
print(a)

Submission status: Runtime Error

Solution code:
import math
input = sys.stdin.readline

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

for i in lis_pat:
    lis_num.append(lis_all.count(i))

ans = 0
for i in lis_num:
    if i != 1:
        ans += comb(i,2)
   
print(ans)

Submission status: Runtime Error

Solution code:
import math
input = sys.stdin.readline

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

ans = 0
for i in lis_pat:
    lis_num.append(lis_all.count(i))
    if lis_all.count(i) != 1:
        ans += math.factorial(lis_all.count(i))/2        
   
print(int(ans))

Submission status: Runtime Error

Solution code:
import math

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

ans = 0
for i in lis_pat:
    lis_num.append(lis_all.count(i))
    if lis_all.count(i) != 1:
        ans += math.factorial(lis_all.count(i))/2        
   
print(int(ans))

Submission status: Runtime Error

Solution code:
import math

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

ans = 0
for i in lis_pat:
    if lis_all.count(i) != 1:
        ans += math.factorial(lis_all.count(i))/2
   
print(int(ans))

Submission status: Runtime Error

Solution code:
import math

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

ans = 0
for i in lis_pat:
    if lis_all.count(i) != 1:
        ans += math.factorial(lis_all.count(i))/2
   
print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

ans = 0
for i in lis_pat:
    if lis_all.count(i) != 1:
        ans += math.factorial(i)/2
   
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
s = []
for _ in range(N):
 s=list(input())
 s.sort()
 s="".join
 A.append(s)
 s=[]
ans = 0
for n in range(N):
    for i in A:
        if A[n] in (i):
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = {}
for _ in range(n):
  s = input()
  k = set(list(s))
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
ans = 0
for k in d:
  n = d[k]
  ans += n * (n - 1) / 2
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
s = []
for _ in range(N):
 s.append(list(input()))
 s.sort()
 s="".join(s)
ans = 0
for n in range(N):
    for i in s:
        if set(s[n]) in (i):
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
s = []
for _ in range(N):
 s.append(int(input()))
for i in range(N):
    for j in range(i+1):
        if s[i] in s[j]:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
s = []
for _ in range(N):
 s.append(int(input()))
for i in range(N):
    for j in range(i+1):
        if s[i] in s[j]:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input)
s = []
for _ in range(N):
 s.append(int(input()))
for i in range(N):
    for j in range(i+1):
        if s[i] in s[j]:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def main():
  from collections import Counter
  from sys import stdin
  readline = stdin.readline()
  N = int(readline())
  t = Counter([''.join(sorted(readline()[:-1])) for _ in range(N)])
  print(sum(t[k] * (t[k] - 1) // 2 for k in t))
main()

Submission status: Runtime Error

Solution code:
n = int(input())
lst = [input() for _ in range(n)]

counter_lst = []
counter_num = [0] * n
for i in range(n):
    a = Counter(lst[i])
    if a in counter_lst:
        m = counter_lst.index(a)
        counter_num[m] += 1
        counter_lst.append(0)
    else:
        counter_lst.append(a)
        counter_num[i] = 1
    
res = 0
for i in counter_num:
    if i > 0:
        res += i * (i-1) // 2
print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [input for _ in range(n)]
c = [i in range(1, n)]

Submission status: Runtime Error

Solution code:
n = int(input()) 
s = [input() for i in range(n)] 
for i in reversed(range(n)):
    for j in range(i):
        if s[i] == s[j]:
            a+=1
print(a)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
ctr = Counter()
answer = 0
for s in S:
    a = ''.join(sorted(list(s)))
    print(a)
    if a in ctr:
        ans += ctr[a]
    ctr[a] += 1
print(answer)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from math import factorial

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

for i in range(n):
    t = list(input())
    t.sort()
    s += [t]

for i in range(n):
    s[i] = ",".join(s[i])
    s[i] = s[i].replace(",","")
    
d = defaultdict(int)

for key in s:
    d[key] += 1
    
cnt = 0

for key, val in d.items():
    if val >= 2:
        cnt += factorial(val) / factorial(2) / factorial(val - 2)

print(int(cnt))

Submission status: Runtime Error

Solution code:
n=int(input())
string_list=[input() for i in range(n)]
b=[i.sort() for i in strint_list]
g=0
for i  in b:
    g+=(l.count(i)-1)
print(int(g*0.5))

Submission status: Runtime Error

Solution code:

from math import factorial

N = int(input())
D = {}
L = [[]for _ in range(N)]
count = 0
for i in range(N):
    L[i] = list(input())
    L[i].sort()
    L[i] = tuple(L[i])
    if L[i] in D:
        D[L[i]] = D[L[i]] + 1
        if D[L[i]] == 2:
            D[L[i]] = D[L[i]] + 1
    else:
        D[L[i]] = 0
for key in D:
    if D[key] > 2:
        #count += factorial(D[key]) / factorial(2) / factorial(D[key]-2)
    else:
        count += D[key]

print(int(count))

Submission status: Runtime Error

Solution code:

from math import factorial

N = int(input())
D = {}
L = [[]for _ in range(N)]
count = 0
for i in range(N):
    L[i] = list(input())
    L[i].sort()
    L[i] = tuple(L[i])
    if L[i] in D:
        D[L[i]] = D[L[i]] + 1
        if D[L[i]] == 2:
            D[L[i]] = D[L[i]] + 1
    else:
        D[L[i]] = 0
for key in D:
    if D[key] > 2:
        count += factorial(D[key]) / factorial(2) / factorial(D[key]-2)
    else:
        count += D[key]

print(int(count))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
D={}
cnt=0
for i in range(N):
    A.append(sorted(input()))

for sortstr in A:
    if sortstr in D:
        cnt+=D[sortstr]
        D[sortstr]+=1
    else:
        D[sortstr]=1
print(cnt)

Submission status: Runtime Error

Solution code:
import collections
import math

n = int(input())
sl = collections.Counter([str(sorted(input())) for _ in range(n)])

ret = 0
for _, v in sl.most_common():
    if 2 <= v:
        ret += int(math.factorial(v) / math.factorial(2) / math.factorial(v - 2))

print(ret)

Submission status: Runtime Error

Solution code:
import collections
import math

n = int(input())
sl = collections.Counter([str(sorted(input())) for _ in range(n)])

ret = 0
for _, v in sl.most_common():
    if 2 <= v:
        ret += math.factorial(v) / math.factorial(2) / math.factorial(v - 2)

print(int(ret))

Submission status: Runtime Error

Solution code:
N=int(input())
s=[0]*N
S=[0]*N
for i in range(N):
    s[i]=input()
    S[i]=sorted(s[i])
    
flag=0

print(S[0])
print(S[1])
print(S[2])

for i in range(0,N-1):
    for j in range(i+1,N):
        if S[i]==S[j]:
            flag+=1
        
print(flag)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
seen = defaultdict(int)
for _ in range(n):
  s = sorted(input())
  seen[s]+=1

ans = 0
for i in seen:
  ans+= seen[i]*(seen[i]-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
s=[sorted(input()) for _ in range(N)]

S=sorted(S)

count=0
for i in range(N):
    for j in range(N):
        if S[i]==S[j]:
            count+=1
        else:
            break

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
S = []
for i in range(N):
    s = str(input())
    s = ''.join(sorted(a))
    S.append(s)

count = 0
for i in range(N):
    Si = S[i]
    for k in range(N):
        if i==k:
            None
        Sk = S[k]
        if Sk == Si:
            count += 1

print(count / 2)

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


n = int(input())
s = [str(input()) for _ in range(n)]
s_set = set(["".join(sorted(_)) for _ in [i for i in s]])
s = ["".join(sorted(_)) for _ in [i for i in s]]
ans = 0
for word in s_set:
  cnt = 0
  for _ in s:
    if _ == word:
      cnt += 1
  if cnt >= 2:
  	ans += cmb(cnt, 2)
print(ans)

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


n = int(input())
s = [str(input()) for _ in range(n)]
s_set = set(["".join(sorted(_)) for _ in [i for i in s]])
s = ["".join(sorted(_)) for _ in [i for i in s]]
ans = 0
for word in s_set:
  cnt = 0
  for _ in s:
    if _ == word:
      cnt += 1
  ans += cmb(cnt, 2)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ana = {}
answer = 0

for i in range(N):
    s = sorted(input())
    new_str = ''.join(s)
    flag = 0

    try:
        k = ana.keys().index(new_str)y
        ana[k] += 1
        answer += ana[k]

    except:
        ana[new_str] = 0

print(answer)

Submission status: Runtime Error

Solution code:
I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))
#####################################################
from collections import defaultdict
n = I1()
d = defaultdict(int)
for i in range(n):
    d[sorted(input())]+=1
res=0
for i in d.keys():
    if d[i] > 1:
        yy=d[i]-1
        res+=yy*(yy+1)//2
print(res)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N = int(input())
s = []
for _ in range(N):
    s.append(sorted(list(input())))
res = 0
while len(s)>0:
    a = s.pop(0)
    count = 1
    for i,n in enumerate(s):
        if n == a:
            count += 1
            s.pop(i)
    res += comb(count, 2, exact=True)

print(res)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
s = [sorted([*input()]) for i in range(n)] #[*(hogehoge)]で一文字ずつのリストに！
s2 = [''.join(s[i]) for i in range(n)] #sortのために一文字ごとに区切ってリストのにしたものを一単語に連結
s3 = Counter(s2[i] for i in range(n))#同じものを計数
#print(s2)
#print(s3)
#print(s3.values())

print(sum(map(lambda x : x*(x-1)//2, s3.values())))#lambda式は便利

Submission status: Runtime Error

Solution code:
n = int(input())
s = [sorted([*input()]) for k in range(n)] #[*(hogehoge)]で一文字ずつのリストに！
count=0
for i in range(n-1):
    for j in range(i+1,n):
        if s[i] == s[j]:
            count += 1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

n = int(input())
S = [sorted(input()) for _ in range(n)]
S = np.array(S)
uniq, cnt = np.unique(S, return_counts=True, axis=0)
print(1)

Submission status: Runtime Error

Solution code:
import collections
from scipy.special import comb

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

for val in range(n):
    s = input()
    s_L = [i for i in s]
    s_L.sort()
    s = "".join(s_L)
    str_L.append(s)


c = collections.Counter(str_L)

str_L = list(set(str_L))


ans = 0
r = 2

for val in str_L:
    n = c[val]
    ans = ans + comb(n, r, exact=True)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
# import math

n = int(input())
S = [sorted(input()) for _ in range(n)]
S = np.array(S)
uniq, cnt = np.unique(S, axis=0, return_counts=True)
ans = 0
for n in cnt:
#     ans = ans + math.factorial(n) / math.factorial(2) / math.factorial(n - 2)
    ans=1
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

n = int(input())
S = [sorted(input()) for _ in range(n)]
S = np.array(S)
uniq, cnt = np.unique(S, axis=0, return_counts=True)
ans = 0
for n in cnt:
#     ans = ans + math.factorial(n) / math.factorial(2) / math.factorial(n - 2)
    ans=1
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

n = int(input())
S = [sorted(input()) for _ in range(n)]
S = np.array(S)
uniq, cnt = np.unique(S, axis=0, return_counts=True)
ans = 0
for n in cnt:
    ans = ans + math.factorial(n) / math.factorial(2) / math.factorial(n - 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
from math import factorial

n = int(input())
S = [sorted(input()) for _ in range(n)]
S = np.array(S)
uniq, cnt = np.unique(S, axis=0, return_counts=True)
ans = 0
for n in cnt:
    
    ans += factorial(n) / factorial(2) / factorial(n - 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
import collections
from scipy.special import comb

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

for val in range(n):
    s = input()
    s_L = [i for i in s]
    s_L.sort()
    s = "".join(s_L)
    str_L.append(s)

print(str_L)

c = collections.Counter(str_L)
print(c)

str_L = list(set(str_L))


ans = 0
r = 2

for val in str_L:
    n = c[val]
    ans = ans + comb(n, r, exact=True)

print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
s = [0] * n
tmp = 0
num = [0] * n
# 文字列を数値に変換した値を格納
# 文字列を値に対応させた配列numの作成とsort
for i in range(n):
    s[i] = input()
    for j in range(len(s[i])):
        tmp += ord(s[i][j])
    num[i] = tmp
    tmp = 0
num.sort()
count = 1
ans = 0
calc = []
# ansのカウント
# print(num)
for i in range(n-1):
    if (num[i] == num[i+1]):
        count += 1
    else:
        if(count != 1):
            calc.append(count)
            count = 1
if(count != 1):
    calc.append(count)
# print(calc)

# calcからans計算

for i in range(len(calc)):
  temp= math.factorial(calc[i-1])/2
  ans += temp
  #print(calc[i],temp)

    

print(int(ans))


"""
while(i<n-1):
  if(num[i] == num[i+1]):
    count += 1
    i+=1
  else:
    if(count>1):
      ans += ((count) * (count+1)) / 2
      count = 0
    elif(count ==1):
      ans += 1
      count = 0
    else:
      count = 0
    i+=1
    break
      
   """
"""
  if (count > 1):
   
  elif(count ==1):
    ans += 1
    count = 0
  if (count > 1):
    ans += ((count) *(count+1)) /2
  """

Submission status: Runtime Error

Solution code:
import math
n = int(input())
s = [0] * n
tmp = 0
num = [0] * n
# 文字列を数値に変換した値を格納
# 文字列を値に対応させた配列numの作成とsort
for i in range(n):
    s[i] = input()
    for j in range(len(s[i])):
        tmp += ord(s[i][j])
    num[i] = tmp
    tmp = 0
num.sort()
count = 1
ans = 0
calc = []
# ansのカウント
# print(num)
for i in range(n-1):
    if (num[i] == num[i+1]):
        count += 1
    else:
        if(count != 1):
            calc.append(count)
            count = 1
if(count != 1):
    calc.append(count)
# print(calc)

# calcからans計算

for i in range(len(calc)):
    ans += math.factorial(calc[i-1])/2


print(int(ans))


"""
while(i<n-1):
  if(num[i] == num[i+1]):
    count += 1
    i+=1
  else:
    if(count>1):
      ans += ((count) * (count+1)) / 2
      count = 0
    elif(count ==1):
      ans += 1
      count = 0
    else:
      count = 0
    i+=1
    break
      
   """
"""
  if (count > 1):
   
  elif(count ==1):
    ans += 1
    count = 0
  if (count > 1):
    ans += ((count) *(count+1)) /2
  """

Submission status: Runtime Error

Solution code:
N = int(input())
D = {}
for _ in range(N):
    S = "".join(sorted(input()))
    print("S",S)
    print("D",D)
    if S in D:
        D[S] += 1
    else:
        D[S] = 1

ans = 0
for v in D.values():
    ans += v * (v - 1) // 2

print(ans)

Submission status: Runtime Error

Solution code:
d={}
s=0
for _ in range(int(input())):
  l=input()
  l=sorted(l)
  f=d.keys()
  if l not in f:
    d[l]=0
  else:
    d[j]+=1
    s+=d[j]
print(s)

Submission status: Runtime Error

Solution code:
from math import factorial

def comb(n, r):
    if n == 1:
        return 0
    return factorial(n) / factorial(r) / factorial(n - r)

N = int(input())
S = [input() for _ in range(N)]
if N == 1:
    print(0)
    exit()
    
str_dict = {}
for s in S:
    sorted_s = "".join(sorted(s))
    if sorted_s not in str_dict:
        str_dict[sorted_s] = 0
    str_dict[sorted_s] += 1
ans = sum([comb(v, 2) for v in str_dict.values()])
print(int(ans))

Submission status: Runtime Error

Solution code:
from math import factorial

def comb(n, r):
    if n == 1:
        return 0
    return factorial(n) / factorial(r) / factorial(n - r)

N = int(input())
S = [input() for _ in range(N)]
str_dict = {}
for s in S:
    sorted_s = "".join(sorted(s))
    if sorted_s not in str_dict:
        str_dict[sorted_s] = 0
    str_dict[sorted_s] += 1
ans = sum([comb(v, 2) for v in str_dict.values()])
print(int(ans))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
c = Counter(S)
print(sum([k*(k-1)//2 for k in c.values()]))

Submission status: Runtime Error

Solution code:
n = int(input())
s = sorted(list((str(input())) for i in range(n)))
print(s_list.most_common()[0][1])

Submission status: Runtime Error

Solution code:
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
sary = [sorted(stdin.readline().rstrip()) for _ in range(n)]

gr = groupby(sary.sort())

res = 0

for k, g in gr:
    if k >= 2:
        res += k * (k - 1) // 2

print(res)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
s = [input() for i in range(n)]
s = map(list,s)
lst = []
for i in s:
  i.sort()
  lst.append(''.join(i))
ans = collections.Counter(lst)
ctr = 0
for v in ans.items():
  if v != 1:
    ctr += v
print(ctr)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    l = makeSortList(n)
    print(calcAns(l))

def searchList(l, s):
    return [e[0] for e in l].index(s)

def makeSortList(n):
    l = []
    for i in range(n):
        strg = "".join(sorted(input()))
        try: x = searchList(l, strg)
        except: l.append([strg])
        l[x].append(i)
    return l

def calcAns(l):
    ans = 0
    for e_l in l:
        lngth = len(e_l) - 1
        if lngth > 1:
            ans += lngth * (lngth - 1) / 2
    return int(ans)

main()

Submission status: Runtime Error

Solution code:
def main():
    def searchList(l, s):
        length = len(l)
        for i in range(length):
            if l[i][0] == s:
                return i
        else: return -1
    
    def sigma(n):
        m = numpy.array(range(n - 1))
        return m.sum()
    
    sortString = lambda s: "".join(sorted(s))
    
    n = int(input())
    l = []
    ans = 0
    
    for i in range(n):
        strg = sortString(input())
        x = searchList(l, strg)
        if x == -1: l.append([strg])
        l[x].append(i)
    
    for e_l in l:
        lngth = len(e_l)
        ans += sigma(lngth)
    
    print(ans)

main()

Submission status: Runtime Error

Solution code:
# -*- coding:utf8 -*-

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = collections.Counter(s)
t = [list(range(i)) for i in list(c.values()) if i != 1]
a = [sum(i) for i in t]
print(sum(t))

Submission status: Runtime Error

Solution code:
# -*- coding:utf8 -*-
import math

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = [math.factorial(s.count(i)) for i in set(s) if s.count(i) != 1]
ans = 0 if not c else sum(c)/2 
print(ans)

Submission status: Runtime Error

Solution code:
def giaithua1(x):
    if x==1:
        return 1
    else:
        return x*giaithua1(x-1)
n=int(input())
s=[]
t=input()
a=[0]*27
for i in t:
    a[ord(i)-97]+=1
a[26]=1
s.append(a)
for i in range(n-1):
    t=input()
    a=[0]*27
    for j in t:
        a[ord(j)-97]+=1
    t=set(t)
    l=len(s)
    ok=0
    for j in range(l):
        tam=1
        for k in t:
            b=ord(k)-97
            if(a[b]!=s[j][b]):
                tam=0
                break
        if(tam==1):
            s[j][26]+=1
            ok=1
            break
    #print(ok)
    if ok==0:
        a[26]=1
        s.append(a)
kq=0
for i in range(len(s)):
    if s[i][26]==2:
        kq+=1
    elif(s[i][26]>2):
        t=giaithua1(s[i][26])/(giaithua1(2)*giaithua1(s[i][26]-2))
        kq+=t
print(int(kq))

Submission status: Runtime Error

Solution code:
# -*- coding:utf8 -*-
import math

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = [math.factorial(s.count(i)) for i in set(s) if s.count(i) != 1]
print(sum(c)/2)

Submission status: Runtime Error

Solution code:
# -*- coding:utf8 -*-
import math

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = [math.factorial(s.count(i)) for i in set(s)]
print(sum(c)/2)

Submission status: Runtime Error

Solution code:
n = int(input)
ans = {}
for i in range(n):
    s = input()
    t = []
    for i in range(len(s)):
        t.append(s[i])
    t.sort()
    k = "".join(t)
    if k in ans:
        ans[k] = ans[k]+1
    else:
        ans[k] = 0
answer = 0
for i in ans:
    j = ans[i]
    answer += j*(j+1)//2
print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())
S = []

dic = dict()

for _ in range(N):
	s = ''.join(sorted(input()))
	
	if not s in dic:
		dic[s] = 0
	else:
		dic[s] += 1
	
ans = 0

for val in dic.values():
	if val > 1:
		ret += (val * (val - 1)) / 2
		
print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for i in range(N)]
ans = 0
for i in range(N):
  s[i].sort()
for j in range(N):
  for k in range(j+1,N):
    if s[j]==s[k]:
      ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s_list = [sorted(str(input())) for i in range(n)]
print(s_list.most_common()[0][1])

Submission status: Runtime Error

Solution code:
n = int(input())
s_list = [sorted(input()) for i in range(n)]
print(s_list.most_common()[0][1])

Submission status: Runtime Error

Solution code:
n = int(input())
s_list = [input() for i in range(n)]
print(s_list.most_common()[0][1])

Submission status: Runtime Error

Solution code:
n = int(input())
s_list = [input() for i in range range(n)]
print(s_list.most_common()[0][1])

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for _ in range(N)]

for i in range(N):
    s[i] = ''.join(sorted(s[i])) # 文字列をソートすると配列になる

ans = 0
for i in range(N): # iは0からN-2まで
    ans += (s.count(s[i]) - 1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
arr = [input() for _ in range(n)]
ans_dict = {}

for s in arr:
    tmp = sorted(s)
    if tmp in ans_dict:
        ans_dict[tmp] += 1
    else:
        ans_dict[tmp] = 1

ans = 0
for i in ans_dict.values():
    ans += i * ( i - 1) / 2
print( int(ans) )

Submission status: Runtime Error

Solution code:
import math
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
def count_s(s):
  count = []
  while s != []:
    moji = s.pop(0)
    num = s.count(moji)
    if num > 0:
      for i in range(num):
        s.pop(s.index(moji))
      count.append(num+1)
  return count
count = count_s(s)
ans = 0
if len(count) == 0:
  print(ans)
else:
  for i in count:
    ans += math.factorial(i)/2
  print(int(ans))

Submission status: Runtime Error

Solution code:
S_dict = {}
N = int(input())
for _ in range(N):
    s = ''.join(sorted(input()))
    if s not in S_dict.keys():
        S_dict[s] = 0
    else:
        S_dict[s] += S_dict[s] + 1
print(sum(map(long, S_dict.values())))

Submission status: Runtime Error

Solution code:
n = int(input())
ss = []
for i in range(n):
    s = input()
    ss.append(''.join(sorted(s)))

ss = sorted(ss)

res = 0
while True:
    if len(ss) == 0:
        break
    if ss[0] != ss[1]:
        ss.pop(0)
        continue
    i = 1
    while True:
        if i == len(ss):
            res += i * (i-1) / 2
            for num in range(i):
                ss.pop(0)
            break
        if ss[0] == ss[i]:
            i += 1
        else:
            res += i * (i-1) / 2
            for num in range(i):
                ss.pop(0)
            break

print(int(res))

Submission status: Runtime Error

Solution code:
N = int(input())

lst = []
for i in range(N):
    lst.append(''.join(sorted(str(input()))))

lst.sort()
cnt = 0
leng = len(lst)

for i in range(leng):
    if ( leng != i ):
        if ( lst[i] == lst[i+1] ):
            cnt += 1
            break
    else:
        break

print (cnt)

Submission status: Runtime Error

Solution code:
a = int(input())
b = []
for _ in range(a):
  b.append(sorted(list(input())))

for i in range(a):
  for j in range(i+1, a):
    check = True
    for k in range(10):
      if b[i] != b[j]:
        check = False
    if check = True:
      ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import itertools

N = int(input())

lst = []
for i in range(N):
    lst.append(''.join(sorted(str(input()))))

lst.sort()
cnt = 0

for i, item in enumerate(lst):
    if ( lst[i] == lst[i+1] ):
        cnt += 1
        break

print (cnt)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli n;
	cin>>n;

	map<string,lli> ans;
	for(lli i=0;i<n;i++){
		string s;
		cin>>s;

		//ここで受け取った文字列sを辞書順最小にソートする
		sort(s.begin(),s.end());
		//ここで受け取った文字列sを辞書順最小にソートする

		ans[s]++;
	}
	lli sum = 0;

	for(auto e:ans){
		lli tmp = e.second*(e.second-1)/2;
		sum += tmp;
	}
	cout<<sum<<endl;

	return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main (){
  int n;
  cin >> n;
  map<string,int> ans;
  for (int i=0;i<n;i++) {
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    ans[s]++;
  }
  sort(vec.begin(),vec.end());
  long long int count=0;
  //vector<string>::iterator sx = vec.begin();
  long long int count_=0;
  int count__=0;
    /*
  for (int i=0;i<n;i++){
    if (*sx==*(sx+1)){
      if (count_==0){
        count_=1;
      }
      count_++;
    } else {
      count+=count_*(count_-1)/2;
      count_=0;
    }
    sx++;
  }
  */
  cout << count;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main (){
  int n;
  cin >> n;
  map<string,int> ans;
  for (int i=0;i<n;i++) {
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    ans[s]++;
  }
  sort(vec.begin(),vec.end());
  long long int count=0;
  //vector<string>::iterator sx = vec.begin();
  long long int count_=0;
  int count__=0;
  /*
  for (int i=0;i<n;i++){
    if (*sx==*(sx+1)){
      if (count_==0){
        count_=1;
      }
      count_++;
    } else {
      count+=count_*(count_-1)/2;
      count_=0;
    }
    sx++;
  }
  */
  cout << count;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main (){
  int n;
  cin >> n;
  vector<string> vec;
  for (int i=0;i<n;i++) {
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    int j=0;
    vec.push_back(s);
  }
  sort(vec.begin(),vec.end());
  long long int count=0;
  //vector<string>::iterator sx = vec.begin();
  long long int count_=0;
  int count__=0;
  /*
  for (int i=0;i<n;i++){
    if (*sx==*(sx+1)){
      if (count_==0){
        count_=1;
      }
      count_++;
    } else {
      count+=count_*(count_-1)/2;
      count_=0;
    }
    sx++;
  }
  */
  cout << count;
}