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:
N = int(input())
S = []
for _ in range(N):
  s = list(str(input()))
  dic = dict()
  for i in s:
    if dic.get(i) is None:
      dic[i] = 1
    else:
      dic[i] += 1
  S.append(dic)

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())
hantei_list = [1 for _ in range(n)]
moji_list = [str(input()) for _ in range(n)]

sosuu = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]

for i in range(n):
  for j in range(10):
    hantei_list[i] *= sosuu[ord(moji_list[i][j])-ord('a')]

counter = 0
for i in range(n):
  for j in range(i+1, n):
    if hantei_list[i] == hantei_list[j]:
      counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[list(sorted(str(input())))]
r=0
for i in range(1,N):
  s=list(sorted(str(input())))
  r+=S.count(s)
  S.append(s)
print(r)

Submission status: Time Limit Exceeded

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

sorted_s = ["".join(sorted(x)) for x in s]

cnt = 0
for i in range(n):
    cnt += sorted_s[i+1:].count(sorted_s[i])

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sn = []
dic_sn = []
cnt = 0
for i in range(n):
    sn.append(input())
    set_sn = set(sn[i])
    dic_sn.append({})
    for si in set_sn:
        dic_sn[i][si] = sn[i].count(si)

for i in range(n):
    for j in range(i + 1, n):
        if dic_sn[i] == dic_sn[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sn = []
set_sn = []
dic_sn = [{} for i in range(n)]
cnt = 0
sn = [input() for i in range(n)]
set_sn = [set(sn[i]) for i in range(n)]
dic_sn = [{si: sn[i].count(si) for si in set_sn[i]} for i in range(n)]

for i in range(n):
    for j in range(i + 1, n):
        if dic_sn[i] == dic_sn[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sn = []
set_sn = []
dic_sn = []
cnt = 0
for i in range(n):
    sn.append(input())
    set_sn = set(sn[i])
    dic_sn.append({})
    for si in set_sn:
        dic_sn[i][si] = sn[i].count(si)

for i in range(n):
    for j in range(i + 1, n):
        if dic_sn[i] == dic_sn[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for _ in range(n):
    #s.append(list(input())) # !!!
    #s.append(sorted(list(input()))) # !!!
    #s.append(sorted(input())) # !!!
    s += [''.join(sorted(input()))]
    #''.join(sorted((sorted(input()))
#print(s)

x = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            x += 1
 
print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for _ in range(n):
    #s.append(list(input())) # !!!
    #s.append(sorted(list(input()))) # !!!
    #s.append(sorted(input())) # !!!
        s.append(''.join(sorted(input())))
    #''.join(sorted((sorted(input()))
#print(s)

x = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            x += 1
 
print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for _ in range(n):
    #s.append(list(input())) # !!!
    #s.append(sorted(list(input()))) # !!!
    s.append(sorted(input())) # !!!
#print(s)
 
x = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            x += 1
 
print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for _ in range(n):
    #s.append(list(input())) # !!!
    s.append(sorted(list(input()))) # !!!
#print(s)

x = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            x += 1

print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())



s = []
t=0
for i in range(n):
	s.append(input())
	s[i] = sorted(s[i])
	t = t + s.count(s[i]) - 1
          
print(t)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
e_tmp = []
for _ in range(N):
    e_tmp.append(list(input()))
import copy
e = copy.deepcopy(e_tmp)
for i in range(N):
    e[i] = sorted(e_tmp[i])
done_flg = [0]*N
cal = 0
for i in range(N):
    if done_flg[i] == 0:
        tmp_cal = 0
        done_flg[i] = 1
        for j in range(i+1,N):
            #print(j)
            if done_flg[j] == 0:
                if e[i] == e[j]:
                    tmp_cal += 1
                    done_flg[j] = 1
        if tmp_cal != 1:
            tmp_cal = ((tmp_cal+1)*tmp_cal)/2
            #print(tmp_cal)
            #print(((tmp_cal-1)*tmp_cal)/2)
        #print(tmp_cal)
        cal += tmp_cal
print(int(cal))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

anagrams = []
for _ in range(int(input())):
    count = Counter(input())
    found = False
    for v in anagrams:
        if v["count"] == count:
            found = True
            v["total"] += 1
            break
    if not found:
        anagrams.append({"count": count, "total": 1})

total = 0
for v in anagrams:
    n = v["total"]
    total += n * (n - 1) / 2

print(int(total))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

from math import factorial as f
def c(n, k):
  return f(n)//(f(n-k)*f(k)) if n>=k else 0

print(sum(c(l.count(a), 2) for a in s))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from itertools import combinations
dic = defaultdict(lambda : 0)
n = int(input())
for _ in range(n):
    str = ''.join(sorted(input()))
    dic[str] += 1
count = 0
memos = defaultdict(lambda : 0)
for key in dic.keys():
    value = dic[key]
    if not value in memos.keys():
        x = len([i for i in combinations(range(value),2)])
        memos[value] = x
    else:
        x = memos[value]
    count += x
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from itertools import combinations
dic = defaultdict(lambda : 0)
n = int(input())
for _ in range(n):
    str = ''.join(sorted(input()))
    dic[str] += 1
count = 0
for key in dic.keys():
    count += len([i for i in combinations(range(dic[key]),2)])
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
cnt=0  
lst=[[i for i in input()] for j in range(n)]
dic=[[] for i in range(n)]
for i in range(n):
  dic[i]=Counter(lst[i])
for left in range(n-1):
  l=sorted(dic[left].items(),key=lambda x:x[0])
  for right in range(left++1,n):
    r=sorted(dic[right].items(),key=lambda x:x[0])
    flg=True
    for ll,rr in zip(l,r):
      if ll!=rr:
        flg=False
        break
    if flg:
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
nn,*a=open(0).read().split()
n=int(nn)
cnt=0
for left in range(n-1):
  for right in range(left+1,n):
    b=[i for i in a[right][:]]
    for leng in range(10):
      flg=True
      if a[left][leng] in b:
        b.remove(a[left][leng])
      else:  
        flg=False
        break
    if flg:
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
from collections import defaultdict as dd
dic = dd(lambda: 0)

counter = 0
for i in range(n):
  s = input()
  s_s = sorted(s)
  s_s_s = str(s_s)
  counter += dic[s_s_s]
  dic[s_s_s] += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
from collections import Counter as cnt
from itertools import combinations as cm
lis = []
for i in range(n):
  count = cnt(list(input()))
  lis.append(count)
  
counter = 0
for pair in cm(lis, 2):
  if pair[0] == pair[1]:
    counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import math

def convert_bagOfWords(S):
    BOW = [0 for i in range(26)]

    for s in S:
        num = (ord(s) - ord('a')) % 26
        BOW[num] += 1
    
    return(BOW)

N = int(input())
bow_vec = []
N_anagram = [0] * N
new_words = []

for i in range(N):
    bow_vec.append(convert_bagOfWords(input()))

for i in range(N):
    # if (new_words.any(bow_vec[i]) == True):
    if (sum(s == bow_vec[i] for s in new_words) > 0):
        index = new_words.index(bow_vec[i])
        N_anagram[index] += 1
    
    else:
        new_words.append(bow_vec[i])

N_anagram = [i+1 for i in N_anagram if (i > 0)]

answer = 0

for i in N_anagram:
    answer += math.factorial(i) / (2 * math.factorial(i - 2))

print(int(answer))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
# アルファベットがキー、要素をカウント数の辞書にして比較する
s = [Counter(input()) for _ in range(n)]
#print(s)
cnt = 0
for i in range(n-1):
  for j in range(i+1,n):
    #print('{} and {}'.format(s[i], s[j]))
    if s[i] == s[j]: cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
slist = [Counter(input()) for _ in range(N)]
ans = 0
checked = [False] * N
for i in range(N):
    c = 0
    if checked[i]:
        continue
    s = slist[i]
    checked[i] = True
    for j in range(i + 1, N):
        if slist[j] == s:
            c += 1
            checked[j] = True
    ans += sum(range(c + 1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
st = list()
for i in range(n):
    st.append(list(input()))
    st[i].sort()
cnt =0
for i in range(n-1):
    for j in range(i+1,n):
        if st[i] == st[j]:
            cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import string

N = int(input())
groups = {0: 1}
groups_sorted = {0: sorted(input())}

count = 0

for i in range(1,N):
  s = sorted(input())
  
  add_grouped = False
  
  for key,s_check in groups_sorted.items():
    if s == s_check:
      count += groups[key]
      groups[key]+=1
      add_grouped = True
      break
      
  if not add_grouped:
    groups[len(groups.keys())] = 1
    groups_sorted[len(groups_sorted.keys())] = s
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
import string

def bwords(str):
  str = list(str)
  bword = [0]*len(string.ascii_lowercase)
  for s in str:
  	bword[string.ascii_lowercase.index(s)]+=1
  return bword

def check_bword(a_word,b_word):
  for a,b in zip(a_word,b_word):
    if a != b:
      return False
  return True

N = int(input())
groups = {0: 1}
groups_bword = {0: bwords(input())}

for i in range(1,N):
  s = input()
  b_w = bwords(s)
  
  add_grouped = False
  
  for key,bword in groups_bword.items():
    if check_bword(b_w,bword):
      groups[key]+=1
      add_grouped = True
      break
      
  if not add_grouped:
    groups[len(groups.keys())] = 1
    groups_bword[len(groups_bword.keys())] = b_w

count = 0

for key,nums in groups.items():
  count+=nums*(nums-1)//2
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
list = [input() for i in range(n)]

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

memo = {}


def count(s):
    if s in memo:
        return memo[s]
    result = defaultdict(int)
    for c in s:
        result[c] += 1
    memo[s] = result
    return result


def main():
    n = int(input())
    slist = [input() for _ in range(n)]
    cnt = 0
    for i, s in enumerate(slist):
        sset = count(s)
        for s2 in slist[i + 1:]:
            if sset == count(s2):
                cnt += 1
    print(cnt)


main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


def count(s):
    result = defaultdict(int)
    for c in s:
        result[c] += 1
    return result


def main():
    n = int(input())
    slist = [input() for _ in range(n)]
    cnt = 0
    for i, s in enumerate(slist):
        sset = count(s)
        for s2 in slist[i + 1:]:
            if sset == count(s2):
                cnt += 1
    print(cnt)


main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
slist=[]
for i in range(n):
    s10=input()
    si=[]
    for ii in range(10):
        si.append(s10[ii])
    si.sort()
    stmp=""
    for ii in range(10):
        stmp=stmp+si[ii]
    slist.append(stmp)
    
icnt=0    
for i in range(n):
    for j in range(i+1,n):
        if slist[i]==slist[j]:
            icnt=icnt+1
            
print(icnt)

Submission status: Time Limit Exceeded

Solution code:
def is_anagram(s1: str, s2: str) -> bool:
    size1, size2 = len(s1), len(s2)
    if size1 != size2:
        return False

    d1, d2 = dict(), dict()

    for i in range(size1):
        c1, c2 = s1[i], s2[i]
        count1, count2 = d1.get(c1), d2.get(c2)
        if count1 is None:
            d1[c1] = 1
        else:
            d1[c1] = count1 + 1
        if count2 is None:
            d2[c2] = 1
        else:
            d2[c2] = count2 + 1

    return d1 == d2

n = int(input())
ss = [input() for _ in range(n)]

counter = 0

for index1 in range(n):
    for index2 in range(index1 + 1, n):
        if is_anagram(ss[index1], ss[index2]):
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
def is_anagram(s1: str, s2: str) -> bool:
    if len(s1) != len(s2):
        return False

    d1, d2 = dict(), dict()
    for s in list(s1):
        count = d1.get(s)
        if count is None:
            d1[s] = 1
        else:
            d1[s] = count + 1
    for s in list(s2):
        count = d2.get(s)
        if count is None:
            d2[s] = 1
        else:
            d2[s] = count + 1
    return d1 == d2


n = int(input())
ss = [input() for _ in range(n)]

counter = 0

for i in range(n):
    for j in range(i + 1, n):
        if is_anagram(ss[i], ss[j]):
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for i in range(N):
  s += [''.join(sorted(input()))]
set_s = set(s)
cnt = 0
for j in set_s:
  cnt += s.count(j)*(s.count(j) - 1) // 2
print(int(cnt+0.5))

Submission status: Time Limit Exceeded

Solution code:
from scipy.misc import comb
N = int(input())
s = []
for i in range(N):
  s += [''.join(sorted(input()))]
set_s = set(s)
cnt = 0
for j in set_s:
  cnt += comb(s.count(j),2)
print(int(cnt+0.5))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[]
cnt=0
for _ in range(N):
    S.append(sorted(list(input())))
    
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = []
count = 0
for i in range(n):
    L.append(input())

for j in range(n):
    for k in range(j+1, n):
        st1 = sorted(list(L[j]))
        st2 = sorted(list(L[k]))
        if st1 == st2:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
slis=[]
orislis=[]
clis=[]
for i in range(n):
	a=sorted(list(input()))
	slis.append(a)
	if a not in orislis:
		orislis.append(a)
for i in orislis:
	a=0
	for j in slis:
		if i==j:
			a+=1
	clis.append(a)
ans=0
for i in clis:
	b=(i*(i-1))/2
	ans+=b
print(int(ans))

Submission status: Time Limit Exceeded

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

char_count = []
cheack = [0]*N
for i in range(N-1):
    if cheack[i] == 0:
        count = 1
        for k in range(i+1,N):
            if char[i] == char[k]:
                count += 1
                cheack[k] = 1
        if count != 1:
            char_count.append(count)

ans = 0
for hoge in char_count:
    while 0 < hoge:
        hoge -= 1
        ans += hoge 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
char = []
for _ in range(N):
    a = list(input())
    a.sort()
    char.append(a)

char_count = []
cheack = [0]*N
for i in range(N-1):
    if cheack[i] == 0:
        count = 1
        for k in range(i+1,N):
            if char[i] == char[k]:
                count += 1
                cheack[k] = 1
        if count != 1:
            char_count.append(count)

ans = 0
for hoge in char_count:
    while 0 < hoge:
        hoge -= 1
        ans += hoge 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans_list = []
ans = 0
for i in range(n):
    tmp = (sorted(input()))
    tmp_af = ''
    for mozi_i in tmp:
        tmp_af += mozi_i
    ans+=ans_list.count(tmp_af)
    ans_list.append(tmp_af)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
S = inputs[1:]

for i in range(n):
    S[i] = ''.join(sorted(list(S[i])))
S.sort()

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

Submission status: Time Limit Exceeded

Solution code:
import string
import collections

n = int(input())
ans=[]
for i in range(n):
  s=input()
  c = collections.Counter(s)
  ans.append("".join(map(str,[c[i] for i in string.ascii_lowercase])))

c2 = collections.Counter(ans)
cnt=0
for k, v in c2.items():
  cnt+=(v-1)*v//2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    ss = set(s)
    res = 0
    if len(s) == len(ss):
        print(0)
        return
    for i in ss:
        cnt = s.count(i) - 1
        res += (cnt+1)*cnt//2
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    ss = set(s)
    res = 0
    for i in ss:
        cnt = s.count(i) - 1
        res += (cnt+1)*cnt//2
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools

n = int(input())
x = []
for i in range(n):
  x.append(sorted(input()))
  
x_sort = sorted(x)
ans = 0

counter = Counter(map(tuple, x_sort))
for word, cnt in counter.most_common():
  ans += len(list(itertools.combinations(list(range(cnt)), 2)))
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input() for i in range(N)]
cnt = 0

for i in range(N):
  s[i] = sorted(s[i])

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for _ in range(N):
    s.append(''.join(sorted(input().lower())))

l = []
count = 0
for n in range(N):
    if s[n] in l:
        count += l.count(s[n]) 
        l.append(s[n])
    else :
        l.append(s[n])

print(count)

Submission status: Time Limit Exceeded

Solution code:
#python3
import collections as col
n=int(input())
a=[input() for i in range(n)]

b=col.defaultdict(int)
for i in a:
  b[''.join(sorted(i))]+=1


c = [''.join(sorted(a)) for _ in range(n)]
#print(sum2)

sum1=0
for i in b.values():
  sum1+=i*(i-1)//2
print(sum1)

Submission status: Time Limit Exceeded

Solution code:
#python3
import collections as col
n=int(input())
a=[input() for i in range(n)]

b=col.defaultdict(int)
for i in a:
  b[''.join(sorted(i))]+=1


c = [''.join(sorted(a)) for _ in range(n)]
d = {string: a.count(string) for string in a}
#print(sum2)

sum1=0
for i in b.values():
  sum1+=i*(i-1)//2
print(sum1)

Submission status: Time Limit Exceeded

Solution code:
#python3
import collections as col
n=int(input())
a=[input() for i in range(n)]

b=col.defaultdict(int)
for i in a:
  b[''.join(sorted(i))]+=1


c = [''.join(sorted(a)) for _ in range(n)]
d = {string: a.count(string) for string in a}
sum2=0
for i in d.values():
  sum2+=i*(i-1)//2 
#print(sum2)

sum1=0
for i in b.values():
  sum1+=i*(i-1)//2
print(sum1)

Submission status: Time Limit Exceeded

Solution code:
#python3
n = int(input())
a = [''.join(sorted(input())) for _ in range(n)]
d = {string: a.count(string) for string in a}
sum=0
for i in d.values():
  sum+=i*(i-1)//2 
print(sum)

Submission status: Time Limit Exceeded

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

def isAnagram(str1,str2):
    str1 = str1.lower()
    str2 = str2.lower()
    str1 = sorted(str1)
    str2 = sorted(str2)
    return str1 == str2

count = 0

for n in range(N):
    for i in range(n+1, N):
        if isAnagram(s[n], s[i]):
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
a = [input() for _ in range(n)]
sep=''
b = [sep.join(sorted(a[i])) for i in range(n)]
dic = {letters: b.count(letters) for letters in set(b)}

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

Submission status: Time Limit Exceeded

Solution code:
#python3
n = int(input())
a = [input() for _ in range(n)]
sep=''
b = [sep.join(sorted(a[i])) for i in range(n)]
dic = {letters: b.count(letters) for letters in set(b)}

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def is_anagram(s1,s2):
  cnt_s1 = Counter(s1)
  for key in cnt_s1:
    if s2.count(key) != cnt_s1[key]:
      return False
  return True

N = int(input())
S = [input() for _ in range(N)]
used = [False for _ in range(N)]
ans = 0
for i in range(N-1):
  if used[i]==True:
    continue
  tmp_ans = 0
  for j in range(i+1,N):
    if used[j]==True:
      continue
    if is_anagram(S[i],S[j]):
      tmp_ans += 1
      used[i], used[j] = True, True
  
  ans += (tmp_ans+1)*tmp_ans//2 
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [[]]*n
ans = 0

for i in range(n):
    s[i] = list(sorted(input()))

i = 0
j = 1

while i < n-1:
    if i+j < n:
        if s[i] == s[i+j]:
            ans += 1

        if j == n-1-i:
            j = 1
            i += 1
        else:
            j += 1
            
    else:
        break
            

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [[]]*n
ans = 0

for i in range(n):
    s[i] = list(sorted(input()))
                
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:
import sys

def main():
    N = int(input())

    Ss = []
    for x in range(N):
        Ss.append(sorted(input()))

    ans = 0
    for i in range(0, N-1):
        ans += Ss[i+1:N].count(Ss[i])

    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
import sys
 
def main():
    N = int(input())
 
    Ss = []
    for x in range(N):
        Ss.append(sorted(input()))
 
    ans = 0
    for i in range(0, N-1):
        for j in range(i+1, N):
            if Ss[i] == Ss[j]:
                ans += 1
 
    print(ans)
 
main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    N = int(input())

    Ss = []
    for x in range(N):
        Ss.append(sorted(input()))

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

    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    list = []
    N = int(input())
    for i in range(0, N):
        ss = input()
        s = "".join(sorted(ss))
        list.append(s)
    result = 0
    for j in range(0, N):
        for k in range(j + 1, N):
            if list[j] == list[k]:
                result += 1
    print(result)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = ["".join(sorted([c for c in S()])) for _ in range(n)]
    r = 0
    for i in range(n):
        for j in range(i+1,n):
            if a[i] == a[j]:
                r += 1

    return r


print(main())

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
count = [0]*n
l = []
for i in range(n):
    a = ''.join(sorted(input()))
    if a in l:
        count[l.index(a)] += 1
    else:
        l.append(a)
print(sum(int((i+1)*i/2) for i in count if i != 0))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
count = 0
l = []
for i in range(n):
    a = ''.join(sorted(input()))
    count += l.count(a)
    l.append(a)
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
T = int(input())
dct ={}
for z in range(T):
    s = list(input())
    s.sort()
    s = "".join(s)
    if s in dct.keys():
        dct[s] += 1
    else:
        dct[s] = 1
v = 0
for elem in dct.values():
    v += (elem*(elem-1))//2
print(v)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s = [input() for i in range(N)]
cnt=0
def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)

for i in range(N-1):
    for j in range(i+1,N):
        if verify_anagrams(s[i], s[j]):
            cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
l = []
check = []
count = 0
for i in range(n):
    a = list(input())
    a.sort()
    
    if a in l:
        index = l.index(a)
        count += check[index]
        check[index] += 1
    else:
        l.append(a)
        check.append(1)


print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
l = []
check = []
count = 0
for i in range(n):
    a = list(input())
    b = Counter(a)
    b = sorted(b.items())
    if b in l:
        index = l.index(b)
        count += check[index]
        check[index] += 1
    else:
        l.append(b)
        check.append(1)


print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
SET = set()
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in SET:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    SET.add(s)

for i in dict.values():
    ans += i * (i + 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
L = []
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in L:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    L.append(s)
for i in dict.values():
    ans += (math.factorial(i + 1) // (math.factorial(2))) // (math.factorial(i - 1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=sorted(["".join(sorted(input())) for i in range(n)])
ans=0
for p in range(n-1):
  for q in range(p+1,n):
    if s[p]==s[q]:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s_n = [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_n[i] == s_n[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
	for k in range(n):
		if s[i] == s[k] :
			ans += 1

print(int((ans - n) / 2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for _ in range(n)]
ans = 0

for i in range(n):
	for k in range(n):
		if sorted(s[i]) == sorted(s[k]) :
			ans += 1

print(int((ans - n) / 2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
count = 0
for _ in range(n):
    si = input()
    tmp_list = []
    tmp_list_s = []

    for i in range(10):
        tmp_list.append(si[i])

    tmp_list_s = sorted(tmp_list)

    if tmp_list_s in s:
        count += s.count(tmp_list_s)
    s.append(tmp_list_s)

print(count)