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: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = []
for i in range(N):
    s = list(input())
    s.sort()
    S.append(s)

S.sort()
A = []
cnt = 1

for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    elif cnt > 1:
        A.append(cnt)
        cnt = 1
A.append(cnt)
        
ans = 0
for i in A:
    iL = [j for j in range(i)]
    ans += len(list(itertools.combinations(iL, 2)))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = []
for i in range(N):
    s = list(input())
    s.sort()
    S.append(s)

NL = [i for i in range(N)]
X = itertools.combinations(NL, 2)

ans = 0
for i in X:
    if S[i[0]] == S[i[1]]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())

data = []
for _ in range(n):
    data.append("".join(sorted(input())))
# print(data)
data.sort()
# print(data)

answer = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        if data[i] == data[j]:
            answer+=1
        else:
            break
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

def main():
    s=["".join(sorted(input())) for _ in range(int(input()))]
    c=0
    for i in collections.Counter(s).values():
        c+=len(list(itertools.combinations(range(i),2)))
    print(c)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections
N = (int(input()))
 
ans = 0
counter_list = []
 
for _ in range(N):
    s = input()
    c = collections.Counter(s)
#    print(c)
#    print(counter_list)
    ans += counter_list.count(c)
 
    counter_list.append(c)
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = (int(input()))

ans = 0
counter_list = []

for _ in range(N):
    s = input()
    c = collections.Counter(s)
#    print(c)
#    print(counter_list)
    ans += counter_list.count(c)

    counter_list.append(c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy
n = int(input())

s = []
count = 0
for i in range(n):
    tmp = numpy.array(sorted(list(input())))
    for j in s:
        if all(j == tmp):
            count += 1
    s.append(tmp)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
count = 0
for i in range(N):
    S.append(sorted(input()))
S = sorted(S)
for j in range(1,N):
    for k in range(1,j+1):
        if S[j] != S[j-k]:
            break
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())

Psama = []

for i in range (0, N):
	Psama.append("". join(sorted(input())))

Achamo = list(set(Psama))

Wakashamo = [0]*len(Achamo)

for i in range (0, len(Psama)):
	for j in range (0, len(Achamo)):
		if Psama[i] == Achamo[j]:
			Wakashamo[j]+=1

counter =0

for i in range (0, len(Achamo)):
	if Wakashamo[i]!=1:
		counter+=math.factorial(Wakashamo[i])/(2*math.factorial(Wakashamo[i]-2))

print(int(counter))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
count = 0
for i in range(N):
    S.append(sorted(input()))
for j in range(N-1):
    for k in range(j+1,N):
        f = True
        for l in range(10):
            if S[j][l] != S[k][l]:
                f = False
                break
        if f:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
count = 0
for i in range(N):
    S.append(sorted(input()))
for j in range(N-1):
    for k in range(j+1,N):
        if S[j] == S[k]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for _ in range(n):
    t = sorted(list(input()))
    t = "".join(t)
    s_c = collections.Counter(s)
    c += s_c[t]
    s.append(t)

print(c)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for _ in range(n):
    t = sorted(list(input()))
    t = "".join(t)
    s_c = collections.Counter(s)
    c += s.count(t)
    s.append(t)

print(c)

Submission status: Time Limit Exceeded

Solution code:

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

for _ in range(n):
    t = sorted(list(input()))
    t = "".join(t)
    c += s.count(t)
    s.append(t)

print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = []
l = [i for i in range(n)]
c = 0

for _ in range(n):
    s.append(list(input()))

for j in itertools.combinations(l,2):
    j = list(j)
    if sorted(s[j[0]]) == sorted(s[j[1]]):
        c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
S = [list(input()) for i in range(N)]
ana_list = []
ana_count = []
count = 0

for i in range(N):
    tmp = Counter(S[i])
    if tmp in ana_list:
        count += ana_count[ana_list.index(tmp)]
        ana_count[ana_list.index(tmp)] += 1
    else:
        ana_list.append(Counter(S[i]))
        ana_count.append(1)

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
n=int(input())
s=[sorted(input()) for _ in range(n)]
c=[str(collections.Counter(s[i])) for i in range(n)]
k=collections.Counter(c).values()
ans = 0
for i in k:
	if i >= 2:
		ans += math.factorial(i)//2//math.factorial(i-2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
l=[]
p=[]
for _ in range(int(input())):
  s = sorted(input())
  if(l.count(s)==0): p.append(s)
  l.append(s)
  
sum=0
for i in p:
  sum += int((l.count(i)*(l.count(i)-1))/2)               	
print(sum)

Submission status: Time Limit Exceeded

Solution code:
l=[]
p=[]
for _ in range(int(input())):
  s =input()
  if(l.count(sorted(s))==0): p.append(sorted(s))
  l.append(sorted(s))
  
sum=0
for i in p:
  sum += int((l.count(i)*(l.count(i)-1))/2)               	
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())

s = [0 for _ in range(n)]
in_a = [0 for _ in range(n)]
dic_tmp = {}
dic_ar = [0 for _ in range(n)]
for i in range(n):
    in_a[i] = input()

for i in range(n):
    dic_tmp = {}
    for ss in in_a[i]:
        dic_tmp[ss] = dic_tmp.get(ss,0) + 1
    
    dic_ar[i] = dic_tmp

cnt = 0
for i in range(n):
    for j in range(n):
        if(i == j):
            continue
        hantei = len(dic_ar[i].items() ^ dic_ar[j].items())

        if(hantei == 0):
            cnt += 1

print(cnt//2)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
num = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", 9:"i", 10:"j"}

D = []
for i in range(N):
    s = input()
    d = ""
    for j in alpha:
        c = s.count(j)
        if c:
            d += j + num[c]
    
    D.append(d)

D.sort()
#print(D)

count = 0
idx = 0
while idx < len(D):
    #print(D[idx])
    n = D.count(D[idx])
    count += n * (n-1) // 2
    idx += n

print(count)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
        

D = []
for i in range(N):
    s = input()
    d = {"a": 0, "b": 0, "c": 0, "d": 0, "e": 0, "f": 0, "g": 0, "h": 0, "i": 0, "j": 0, "k": 0, "l": 0, "m": 0, "n": 0, "o": 0, "p": 0, "q": 0, "r": 0, "s": 0, "t": 0, "u": 0, "v": 0, "w": 0, "x": 0, "y": 0, "z": 0}
    for j in s:
        d[j] += 1
    
    D.append(d)

#print(D)
count = 0
while len(D):
    s = D[0]
    #print(D.count(s))
    n = D.count(s)
    count += n * (n-1) // 2
    while n:
        D.remove(s)
        n -= 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

tp=[]
ii=0
for sss in st:
  c=s.count(sss)
  if c>1:
    tp.append(c)
    r+=(c*(c-1))//2
    
print(r)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

tp=[[""]*2 for ii in range(len(st))]
ii=0
for sss in st:
  tp[ii][0]=s.count(sss)
  tp[ii][1]=sss
  ii+=1
#tp.sort(reverse=True)

for jj in range(len(tp)):
  """
  if tp[jj][0]==1:
    print(r)
    exit()

  """
  r2=tp[jj][0]
  if r2>1:
    r+=(r2*(r2-1))//2      
    
print(r)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

tp=[[""]*2 for ii in range(len(st))]
ii=0
for sss in st:
  tp[ii][0]=s.count(sss)
  tp[ii][1]=sss
  ii+=1
tp.sort(reverse=True)
"""
for ii in range(len(tp)):
  print(tp[ii])
"""
for jj in range(len(tp)):
  if tp[jj][0]==1:
    print(r)
    exit()
  """sss=tp[jj][1]
  ls=[]
  r2=0
  for ii in range(len(s)):
    if s[ii]==sss:
      ls.append(ii)
      r2+=1
  m=len(ls)
  for ii in range(m):
    del s[ls[m-1-ii]]
  """
  r2=tp[jj][0]
  if r2>1:
    r+=(r2*(r2-1))//2      
    
print(r)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

tp=[[""]*2 for ii in range(len(st))]
ii=0
for sss in st:
  tp[ii][0]=s.count(sss)
  tp[ii][1]=sss
  ii+=1
tp.sort(reverse=True)
"""
for ii in range(len(tp)):
  print(tp[ii])
"""
for jj in range(len(tp)):
  if tp[jj][0]==1:
    print(r)
    exit()
  sss=tp[jj][1]
  ls=[]
  r2=0
  for ii in range(len(s)):
    if s[ii]==sss:
      ls.append(ii)
      r2+=1
  m=len(ls)
  for ii in range(m):
    del s[ls[m-1-ii]]
  if r2>1:
    r+=(r2*(r2-1))//2      
    
print(r)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

for sss in st:
  ls=[]
  r2=0
  for ii in range(len(s)):
    if s[ii]==sss:
      ls.append(ii)
      r2+=1
  m=len(ls)
  for ii in range(m):
    del s[ls[m-1-ii]]
  if r2>1:
    r+=(r2*(r2-1))//2      
    
print(r)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

for sss in st:
  ls=[]
  r2=0
  for ii in range(len(s)):
    if s[ii]==sss:
      ls.append(ii)
      r2+=1
  """print(st)
  print(ls)
  print(r2)"""
  m=len(ls)
  for ii in range(m):
    del s[ls[m-1-ii]]
  if r2>1:
    r+=(r2*(r2-1))//2      
  #print(ii)
"""  
import numpy as np
for ii in range(n-1):
  for jj in np.arange(ii+1,n):
    #print(ii,jj)
    if s[ii]==s[jj]:
      #print(s[ii],s[jj])
      r+=1
"""
print(r)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[""]*n
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  s[ii]="".join(ss)
"""
for ii in range(n):
  print(s[ii])
"""
import numpy as np
for ii in range(n-1):
  for jj in np.arange(ii+1,n):
    #print(ii,jj)
    if s[ii]==s[jj]:
      #print(s[ii],s[jj])
      r+=1
print(r)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

n = int(input())
a = []
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    S = ''.join(s)
    a.append(S)

c = collections.Counter(a)
for i in c.values():
    ans += len(list(itertools.combinations(range(i), 2)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 文字のリストを作成し、組み合わせを求めてアナグラムになっているかチェックする
import itertools

n = int(input())
s = list(input() for i in range(n))
s_comb = list(itertools.combinations(s, 2))

count = 0

for i in range(len(s_comb)):
    s_i = s_comb[i][0]
    # 文字列はsort()メッソドが使用できないので、sorted()で新しいリスト作成
    # 文字列を昇順にすることでアナグラムチェックしやすいようにする
    s_i_str_list = sorted(s_i)
    s_j = s_comb[i][1]
    s_j_str_list = sorted(s_j)
    
    # アナグラムかチェック
    if s_i_str_list == s_j_str_list:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
list=[input() for i in range(n)]
lists=[]
for i in list:
  lists.append(''.join(sorted(i)))
  
#ここまででソートしたリストを得た。ここまではオーケー
cnt=0
for i in range(n):
  for k in range(i+1,n):
    if lists[i]==lists[k]:
        cnt+=1
  
  
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
dictionary={}
count=0
for i in range(N):
    s=str(sorted(input()))
    if s in dictionary:
        dictionary[s]+=1
        count+=dictionary[s]
    else:
        dictionary[s]=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
di={}
count=0
for i in range(n):
  s=str(sorted(input()))
  if s in di:
    di[s]+=1
    count+=di[s]
  else:
    di[s]=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S =[Counter(input()) for i in range(N)]
ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    if S[i] == S[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

label = []
num = {}

for i in range(n):
    seq = input()
    seq = ''.join(sorted(seq))
    if seq in label:
        num[seq] += 1
    else:
        label.append(seq)
        num[seq] = 1

ans = 0
for s in num:
    k = num[s]
    if k > 1:
        ans += k * (k-1) // 2

print(ans)

Submission status: Time Limit Exceeded

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

B = []
for i in range(N):
    s = ''.join(S[i])
    B.append(s)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
s = ["".join(sorted(list(input()))) for _ in range(n)]
ans = 0
for v in combinations(s, 2):
    if v[0] == v[1]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
s = [sorted(list(input())) for _ in range(n)]
ans = 0
for v in combinations(s, 2):
    if v[0] == v[1]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
lst = []
num = [1]*n
ans = 0
lst_append = lst.append
s_all = [sorted(input()) for _ in range(n)]
for s in s_all:
    if s not in lst:
        lst_append(s)
    else:
        pos = lst.index(s)
        ans += num[pos]
        num[pos] += 1

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
lst = []
num = [1]*n
ans = 0
lst_append = lst.append
s_all = [sorted(input()) for _ in range(n)]
for s in s_all:
    if s not in lst:
        lst_append(s)
    else:
        pos = lst.index(s)
        num[pos] += 1
for j in num:
    ans += (j * (j-1)) / 2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
lst = []
num = [1]*n
ans = 0
lst_append = lst.append
for i in range(n):
    s = sorted(input())
    s = "".join(s)
    if s not in lst:
        lst_append(s)
    else:
        pos = lst.index(s)
        num[pos] += 1
for j in num:
    ans += (j * (j-1)) / 2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = []
num = [1]*n
ans = 0
for i in range(n):
    s = sorted(input())
    s = "".join(s)
    if s not in lst:
        lst.append(s)
    else:
        pos = lst.index(s)
        num[pos] += 1
for j in num:
    ans += (j * (j-1)) / 2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = []
num = [1]*n
ans = 0
for i in range(n):
    s = sorted(input())
    if s not in lst:
        lst.append(s)
    else:
        pos = lst.index(s)
        num[pos] += 1
for j in num:
    ans += (j * (j-1)) / 2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
def convertListToStr(lst):
	s = "".join(lst)
	return s

N=int(input())
dict={}
ans=0
for i in range(N):
	s = convertListToStr(sorted(input()))
	for check in dict:
		if check==s:
			ans+=dict[check]
			dict[check]+=1
			break
	else:
		dict[s]=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
unique_string = []
ans = 0

for _ in range(N):
    s = "".join(sorted(input()))
    ans += unique_string.count(s)
    unique_string.append(s)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
check_lst=[]
ans=0
for i in range(N):
	check_lst.append([0]*26)
for i in range(N):
	s = input()
	for c in s:#a=97, z=122
		check_lst[i][ord(c)-97]+=1
for i in range(N-1):
	for j in range(i+1,N):
		if check_lst[i]==check_lst[j]:
			ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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())
s = ["".join(sorted(input())) for _ in range(N)]
number_of_anagrams = []

for string in set(s):
    cnt = s.count(string)
    if cnt > 1:
        number_of_anagrams.append(cnt)

ans = sum(combinations_count(num, 2) for num in number_of_anagrams)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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())
s = ["".join(sorted(input())) for _ in range(N)]
number_of_anagrams = []
ans = 0

for string in set(s):
    cnt = s.count(string)
    if cnt > 1:
        number_of_anagrams.append(cnt)

for num in number_of_anagrams:
    ans += combinations_count(num, 2)

print(ans)

Submission status: Time Limit Exceeded

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

S=set(s)
"""
import math

def cmb(n,r):
    return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))
"""
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

ans=0
for x in S:
    a=s.count(x)
    if a<2:
        continue
    else:
        ans+=cmb(a,2)
print(ans)

Submission status: Time Limit Exceeded

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

S=set(s)

import math

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


ans=0
for x in S:
    a=s.count(x)
    if a<2:
        continue
    else:
        ans+=cmb(a,2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
s = []
ans = 0
for i in range(N):
    s.append(''.join(sorted(S())))

for i in range(N-1):
    for q in range(i+1,N):
        if s[i] == s[q]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
S = [[]for _ in range(10)]
for _ in range(N):
    s = input()
    S[len(s)-1].append(Counter(s))

ans = 0
for _ in range(10):
    for i in range(len(S[_])):
        for j in range(i+1, len(S[_])):
            if S[_][i] == S[_][j]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

lst = []
cnt = 0
n = int(input())
for i in range(n):
  s = input()
  c = collections.Counter(s)
  if c in lst:
    cnt += lst.count(c)
  lst.append(c)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections

lst = []
n = int(input())
for i in range(n):
  s = input()
  c = collections.Counter(s)
  lst.append(c)

cnt = 0
for i, elem1 in enumerate(lst):
  for elem2 in lst[i+1:]:
    if elem1 == elem2:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]

ans = 0
d = []
for i in s:
  if i not in d:
    t = s.count(i)
    ans += t*(t-1)//2
    d.append(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]

ans = 0
for i in list(set(s)):
  t = s.count(i)
  ans += t*(t-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools
N = int(input())
s = list(Counter(input()) for i in range(N))
A = list(itertools.combinations(range(0, N), r=2))
ans = 0
for i in A:
    if s[i[0]] == s[i[1]]:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

n = int(input())
note = dict()
ans = 0
for i in range(n):
    s = "".join(sorted(sys.stdin.readline()))
    if s in note.keys():
        ans += note[s]
        note[s] += 1
    else:
        note[s] = 1

print(ans)

Submission status: Time Limit Exceeded

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

n = int(input())
note = dict()
ans = 0
for i in range(n):
    s = "".join(sorted(input()))
    if s in note.keys():
        ans += note[s]
        note[s] += 1
    else:
        note[s] = 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
note = dict()
ans = 0
for i in range(n):
    s = "".join(sorted(input()))
    if s in note.keys():
        ans += note[s]
        note[s] += 1
    else:
        note[s] = 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
note = dict()
for i in range(n):
    s = "".join(sorted(input()))
    if s in note.keys():
        note[s] += 1
    else:
        note[s] = 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
note = dict()
for i in range(n):
    s = "".join(sorted(input()))
    if s in note.keys():
        note[s] += 1
    else:
        note[s] = 1
        
ans = 0
for i in note.values():
    ans += i*(i-1)//2

print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
l = [''.join(sorted(list(input())))]
cnt = 0
for i in range(N-1):
    s = ''.join(sorted(list(input())))
    cnt += l.count(s)
    l.append(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
l = [''.join(sorted(list(input())))]
cnt = 0
for i in range(N-1):
    s = ''.join(sorted(list(input())))
    cnt += l.count(s)
    l.append(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
from itertools import combinations
import sys
input = sys.stdin.readline

N = int(input())
s = [''.join(sorted(list(input()))) for _ in range(N)]
#for i in range(N):
#    s.append(''.join(sorted(list(input()))))
c = collections.Counter(s)

cnt = 0
for i in c.values():
    if i > 1:
        cnt += len(tuple(combinations(range(i), 2)))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
from itertools import combinations

N = int(input())
s = [''.join(sorted(list(input()))) for _ in range(N)]
#for i in range(N):
#    s.append(''.join(sorted(list(input()))))
c = collections.Counter(s)

cnt = 0
for i in c.values():
    if i > 1:
        cnt += len(tuple(combinations(range(i), 2)))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
from itertools import combinations

N = int(input())
s = []
for i in range(N):
    s.append(''.join(sorted(list(input()))))
c = collections.Counter(s)

cnt = 0
for i in c.values():
    if i > 1:
        cnt += len(list(combinations(range(i), 2)))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x = []
a = []
s = 0

for i in range(N):
  y = sorted(input())
  if y in x:
    b = x.index(y)
    a[b] += 1
    s = s + a[b]
  else:
    x.append(y)
    a.append(0)
  

print(s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x = []
for i in range(N):
  y = sorted(input())
  x.append(y)
  
s = 0
while len(x)>1:
  for j in range(1,len(x)):
    if x[0] == x[j]:
      s += 1
  x.pop(0)
      
print(s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x = []
for i in range(N):
  y = sorted(input())
  x.append(y)
  
s = 0
for i in range(N):
  for j in range(i+1,N):
    if x[i] == x[j]:
      s += 1
      
print(s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s = [input() for i in range(n)]
c=0
a=["" for i in range(n)]
for i in range(n):
   b=(sorted([s[i][j] for j in range(10)]))
   a[i]=''.join(b)

for i in range(n-1):
    for j in range(i+1,n):
        if a[i]==a[j]:
            c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = (int)(input())
s = [sorted(list(input())) for i in range(n)]
 
ans = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    if s[i] == s[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = (int)(input())
s = [input() for i in range(n)]
count = [[0 for i in range(26)] for j in range(n)]
for i in range(n):
  for j in range(10):
    count[i][ord(s[i][j]) - 97] += 1
#print(*count)

ans = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    if count[i] == count[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
for i in range(n):
  s.append(sorted(input()))
ans=0
for i in range(n):
  for j in range(n):
    if i>j:
      if s[i]==s[j]:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [''.join(sorted(list(input()))) for _ in range(N)]

ans = 0
for n in range(1,N):
  if a[n] in a[:n]:
    ans += a[:n].count(a[n])
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for n in range(1,N):
  if a[n] in a[:n]:
    ans += a[:n].count(a[n])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
x={}
ans=0
for j in range(n):
    s=list(input())
    s.sort()
    p=''.join(s)
    if s not in l:
        l.append(s)
        x[p]=1
    else:
        ans+=x[p]
        x[p]+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
count=0

for i in range(N):
  s.append("".join(sorted(input())))
  
duplicate_list =sorted(set(s), key=s.index)

for i in range (len(duplicate_list)):
  for j in range (s.count(duplicate_list[i])):
    count += j

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
count=0

for i in range(N):
  a = list(input())
  a.sort()
  s.append(''.join(a))
  
duplicate_list =sorted(set(s), key=s.index)

for i in range (len(duplicate_list)):
  for j in range (s.count(duplicate_list[i])):
    count += j

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
count=0

def duplicates(list):
  seen=[]
  return [x for x in s if x not in seen and not seen.append(x)]

for i in range(N):
  a = list(input())
  a.sort()
  s.append(''.join(a))

duplicate_list = duplicates(s)

for i in range (len(duplicate_list)):
  for j in range (s.count(duplicate_list[i])):
    count += j

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
count=0

def duplicates(list):
  seen=[]
  return [x for x in s if x not in seen and not seen.append(x)]

for i in range(N):
  a = list(input())
  a.sort()
  s.append(a)

duplicate_list = duplicates(s)

for i in range (len(duplicate_list)):
  for j in range (s.count(duplicate_list[i])):
    count += j

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
count=0
for i in range(N):
  a = list(input())
  a.sort()
  s.append(a)

while True:
  if len(s) == 0:
    break
  count += s.count(s[0]) - 1
  del s[0]
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
s = []
for i in range(N):
    s.append(input())
count = 0
for i in range(N):
    for j in range(N - i - 1):
        if Counter(s[i]) == Counter(s[i + j + 1]):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys, collections
n = int(input())
uq = []
chk = {}
for x in sys.stdin.readlines():
    x = x.rstrip()
    tmp = collections.Counter(sorted(x))
    h = ''
    for i in tmp:
        h += i + str(tmp[i])
    if h not in uq:
        uq.append(h)
    else:
        if h not in chk:
            chk.setdefault(h, 1)
        chk[h] += 1
ans = 0
for x in chk:
    ans += chk[x]*(chk[x]-1)//2
print(ans)