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:
Ncount = int(input())
strings = []
count_flag = 0
letters_count = []
for i in range(Ncount):
  strings.append(input())
  
def letter_count(string):
  letters = {}
  for i in range(10):
    if string[i] not in letters:
      letters[string[i]] = 1
    else :
      letters[string[i]] += 1
  return letters

for i in strings:
  letters_count.append(letter_count(i))


for i in range(len(letters_count)):
  for j in range(i+1, len(letters_count)):
    if letters_count[i] == letters_count[j]:
      count_flag += 1

print(count_flag)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for i in range(N):
  s.append(sorted(input()))
#lis = list(set(s))
lis = list(map(list, set(map(tuple, s))))
#print(lis)
c = 0
for i in lis:
    indexes = [k for k, x in enumerate(s) if x == i]
    #print(i,indexes)
    k = len(indexes)-1
    #print(k)
    c += sum([i for i in range(k,0,-1)])
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for i in range(N):
  s.append(sorted(input()))
c = 0
for i in range(1,N-1):
    indexes = [k for k, x in enumerate(s[i:]) if x == s[i-1]]
    c += len(indexes)
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for i in range(N):
  s.append(sorted(input()))
#print(s)
judge = [False]*N
judge[0] = [True]
#print(s[0]==s[2])
#print(s[1:].index(s[0]))
t = s[0]
c = 0
for i in range(1,N):
  
    indexes = [k for k, x in enumerate(s[i:]) if x == s[i-1]]
    c += len(indexes)
print(c)

Submission status: Time Limit Exceeded

Solution code:
Ncount = int(input())
strings = []
count_flag = 0
letters_count = []
for i in range(Ncount):
  strings.append(input())
  
def letter_count(string):
  letters = {}
  for i in range(10):
    if string[i] not in letters:
      letters[string[i]] = 1
    else :
      letters[string[i]] += 1
  return letters

for i in strings:
  letters_count.append(letter_count(i))
  
for i in range(len(letters_count)):
  for j in range(i+1, len(letters_count)):
    if letters_count[i] == letters_count[j]:
      count_flag += 1

print(count_flag)

Submission status: Time Limit Exceeded

Solution code:
number=int(input())
counter=0
answer=0
y=0
words=[]
 
for i in range(number):
    List = (input())
    words.append(list(List))
 
for j in range(number):
    z=0
    for k in range(number):
        
        centence=[]
        centence1=[]
 
        for g in range(number): 
            centence=words[y]
            centence1=words[z]
 
        x=-1
        word=[]
        word1=[]
 
        for f in range(10):
            x=x+1
            word.append(centence[x])
            word1.append(centence1[x])
        
        num=0
        a=[]
        ans=0
 
        for h in range(10):
            a=word[num]
            b=word.count(a)
            c=word1.count(a)
            if b == c:
                num=num+1
            else:
                ans=1
        if ans == 0:
            counter=counter+1
        else:
            counter=counter+0
 
        z=z+1
    y=y+1
answer=counter/2
print(int(answer-number/2))

Submission status: Time Limit Exceeded

Solution code:
number=int(input())
counter=0
answer=0
y=0
words=[]

for i in range(number):
    List = (input())
    words.append(list(List))

for j in range(number):
    z=0
    for k in range(number):
        
        centence=[]
        centence1=[]

        for g in range(number): 
            centence=words[y]
            centence1=words[z]

        x=-1
        word=[]
        word1=[]

        for f in range(10):
            x=x+1
            word.append(centence[x])
            word1.append(centence1[x])
        
        num=0
        a=[]
        ans=0

        for h in range(10):
            a=word[num]
            b=word.count(a)
            c=word1.count(a)
            if b == c:
                num=num+1
            else:
                ans=1
        if ans == 0:
            counter=counter+1
        else:
            counter=counter+0

        z=z+1
    y=y+1
answer=counter/2
print(int(answer-number/2))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())

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

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

    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip() for _ in range(n)]
new = []
for i in range(n):
    sort = sorted(data[i])
    sorting = "".join(sort)
    new.append(sorting)
new.sort()
score = 0
s = 0
count  = 0
while s<n-1:
    daburi = 1
    stop = 0
    for p in range(s,n-1):
        if new[p] == new[p+1] and stop == 0:
            daburi += 1
        else:
            stop += 1
    score += daburi*(daburi-1)//2
    count += daburi
    s = count
print(score)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())

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

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

    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())

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

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

    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

    h=list(input())

    h.sort(reverse=False)
    
    a.append(h)


while True:

    if len(a)==0:
        break
    
    x+=sum(range(a.count(a[0])))
    y=a[0]

    for j in range(a.count(y)):
        a.remove(y)
    

print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]
cnt = 0
for i in range(len(s)-1):
  for j in range(i+1, len(s)):
    if s[i] == s[j]:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip() for _ in range(n)]
new = []
for i in range(n):
    sort = sorted(data[i])
    sorting = "".join(sort)
    new.append(sorting)
new.sort()
score = 0
news = list(set(new))
for s in range(len(news)):
    k = new.count(news[s])
    score += int((k-1)*k/2)
print(score)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input() for k in range(N)]
s = [''.join(sorted(list(s_element))) for s_element in s]
memory = {}
result = 0
for s_element in s:
    if s_element not in list(memory.keys()):
        memory[s_element] = 1
    else:
        result += memory[s_element]
        memory[s_element] += 1
print(result)

Submission status: Time Limit Exceeded

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

    h=list(input())

    h.sort(reverse=False)
    
    a.append(h)


for j in range(N):

    if len(a)==0:
        break
    
    x+=sum(range(a.count(a[0])))
    y=a[0]

    if a.count(y)>=1:

        for k in range(a.count(y)):

            a.remove(y)
            
    

print(x)

Submission status: Time Limit Exceeded

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

    h=list(input())

    h.sort(reverse=False)
    
    a.append(h)


for j in range(N):
    if len(a)==0:
        break
    
    x+=sum(list(range(a.count(a[0]))))
    y=a[0]

    if a.count(y)>=1:

        for k in range(a.count(y)):

            a.remove(y)
            
    

print(x)

Submission status: Time Limit Exceeded

Solution code:
#input N
N = int(input())

#define a list s:
s = list()

#input N words
for i in range(N):
    s.append(''.join(sorted(input())))

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input()) 
s = [input() for i in range(N)]
LIS=[]
for i in range(N):
  LIS.append(''.join(sorted(s[i])))
n=0
set1=set(LIS)
for str in set1:
  m=LIS.count(str)
  n+=m*(m-1)/2
print(int(n))

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = []
count = 0
for i in range(a):
    l = list(input())
    l.sort()
    r = "".join(l)
    if r in ar:
        count += ar.count(r)
    ar.append(r)
print(count)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = []
count = 0
for i in range(a):
    l = list(input())
    l.sort()
    ar.append("".join(l))
for r in set(ar):
    if ar.count(r) >= 2:
        for i in range(1,ar.count(r)):
            count += i
print(count)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = []
count = 0
for i in range(a):
    l = list(input())
    ar.append(l)
for i in range(a):
    for j in range(i+1,a):
        ar[i].sort()
        ar[j].sort()
        if ar[i] == ar[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

s = []

for i in range(N) :
  s.append(input())
#  print(s[i])

list_s = []

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

count = 0  

joint_s = []

for i in range(N) :
  joint = ''
  for j in list_s[i] :
    joint += j
  joint_s.append(joint)
    

for i in range(N) :
  for j in range(N - i - 1) :
    if joint_s[i] == joint_s[i + j + 1] :
      count = count + 1

print(count)  
#print(list_s)
#print(joint_s)

Submission status: Time Limit Exceeded

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

result = 0
for i in range(N):
    for j in range(i + 1, N):
        if ss[i] == ss[j]:
            result += 1
print(int(result))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
s = [list(input()) for _ in range(N)]
S = []
cnt = 0

for i in range(N):
    mycounter = Counter(S)
    temp = "".join(sorted(s[i]))
    S.append(temp)
    cnt += mycounter[temp]

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

result = 0
for u in set(ss):
    cnt = len([s for s in ss if s == u])
    result += (cnt * (cnt -1)) / 2
print(int(result))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
s = [input() for i in range(n)]
b = sorted(["".join(sorted(s[i])) for i in range(n)])
c = np.unique(b)
cnt = 0
for t in c:
    i = b.count(t)
    if i > 1:
        cnt += i * (i - 1) // 2
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(N):
    cnt += S.count(S[i]) - 1
print(cnt // 2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(range(n))
for i in range(n):
  s[i] = list(str(input()))
  s[i].sort()

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())
mojiretu = [input() for _ in range(N)]
mojiretu2 = []
answer = 0

for n in mojiretu:
  mojiretu2.append(sorted(list(n)))
 
for index, moji in enumerate(mojiretu2):
  i = index+1
  while i < N:
    if moji == mojiretu2[i]:
      answer+=1
    i+=1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
mojiretu = [input() for _ in range(N)]
mojiretu2 = []
answer = 0

for n in mojiretu:
  mojiretu2.append(''.join(sorted(list(n))))
 
for index, moji in enumerate(mojiretu2):
  i = index+1
  while i < N:
    if moji == mojiretu2[i]:
      answer+=1
    i+=1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
count=0
for i in range(N):
    S=''.join(sorted(input()))
    A.append(S)

for i in range(N):
    for j in range(i,N):
        if A[i]==A[j] and i!=j:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

hantei = True
cnt = 0
for i in range(N):
    temp = s.pop(0)
    for S in s:
        for k in range(len(temp)):
            if S.count(temp[k]) != temp.count(temp[k]):
                hantei = False
                break
        if hantei:
            cnt += 1
        else:
            hantei = True

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
word=[]
word_lst=[]
for i in range(N):
  s=input()
  word.append(s)
  word_lst.append(list(word[i]))
  word_lst[i].sort()
  word_lst[i]=''.join(word_lst[i])

count=0
for i in range(N):
  flag = 0
  for j in range(N):
    if flag == 1:
      pass
    if word_lst[i]==word_lst[j]:
      count=count+1
      flag =flag+1

total=int((count-N)/2)
  
  
print(total)

Submission status: Time Limit Exceeded

Solution code:

#アルゴリズムはあってるがLTE
N = int(input())
wordl = []

for i in range(N):
    w = input()
    wl = []
    for j in range(10):
        wl.append(w[j])
    wl.sort()
    w2 = ' '
    for p in range(10):
        w2 += wl[p]
    wordl.append(w2)
wordl.sort()
#print(wordl)

ans = 0
for k in range(N):
    for q in range(k+1,N):
        if wordl[k] == wordl[q]:
            ans += 1
        else:
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC137C
import copy
import sys
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))
#k=hoge[0]
#x=hoge[1]

list = [[0 for i in range(26)] for j in range(n)]
#list[0][1]=1
#print(list)

hash=[]
for i in range(0,300):
	hash.append([])

for i in range(0,n):
	tmp=input()
	hoge=0
	for j in range(0,10):
		list[i][ord(tmp[j])-ord("a")]+=1
		hoge+=ord(tmp[j])-ord("a")
	hoge=hoge%300
	hash[hoge].append(i)
#print(hash)

sum=0

for i in range(0,300):
	for j in range(0,len(hash[i])-1):
		for k in range(j+1,len(hash[i])):
			#print(i)
			#print(hash[i][j])
			#print(hash[i][k])
			for m in range(0,26):
				if(list[hash[i][j]][m]!=list[hash[i][k]][m]):
					break
				elif(m==25):
					sum+=1


#for i in range(0,n-1):
#	for j in range(i+1,n):
#		for k in range(0,26):
#			if(list[i][k]!=list[j][k]):
#				break
#			elif(k==25):
#				sum+=1

print(sum)

#print(list)
#print(list[0][:])

Submission status: Time Limit Exceeded

Solution code:
#Coding:Utf-8

N=int(input())
s=[list(input()) for i in range(N)]
total=num=0
for l in range(N):
    s[l].sort()
s.sort()
while len(s)!=0:
    num=s[1:N].count(s[0])
    for m in range(1,num+1):
        total+=m
        s.remove(s[0])
    s.remove(s[0])

print(total)

Submission status: Time Limit Exceeded

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

for i in range(N):
    w = input()
    wl = []
    for j in range(10):
        wl.append(w[j])
    wl.sort()
    w2 = ' '
    for p in range(10):
        w2 += wl[p]
    wordl.append(w2)
wordl.sort()
#print(wordl)

ans = 0
for k in range(N):
    for q in range(k+1,N):
        if wordl[k] == wordl[q]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#Coding:Utf-8

N=int(input())
s=[list(input()) for i in range(N)]
total=num=0
for l in range(N):
    s[l].sort()
s.sort()
for m in range(N):
    if m==0:
        dupl=s[m+1:N+1].count(s[m])
        for o in range(1,dupl+1):
            total+=o
        num+=dupl+1
    elif num!=N:
        dupl=s[num+1:N+1].count(s[num])
        for o in range(1,dupl+1):
            total+=o
        num+=dupl+1
    else:
        break

print(total)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = input()
N = int(N)
S = {}
n_anagram = 0
D = {"a":2, "b":3, "c":5, "d":7, "e":11, "f":13,"g":17, "h":19, "i":23, "j":29, "k":31, "l":37, "m":41, "n":43,
"o":47, "p":53, "q":57, "r":59, "s":61, "t":67, "u":71, "v":73, "w":79, "x":83, "y":87, "z":1}

for i in range(N):
    s = input()
    s1 = [D[x] for x in s]
    s2 = np.prod(s1)
    if s2 in S:
        n_anagram= n_anagram + S[s2]
        S[s2] += 1
    else:
        S[s2] = 1
    
print(n_anagram)

Submission status: Time Limit Exceeded

Solution code:
#Coding:Utf-8

N=int(input())
s=[list(input()) for i in range(N)]
total=0
for l in range(N):
    s[l].sort()
for m in range(N):
    total+=s[m+1:N+1].count(s[m])

print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
word = [input() for i in range(N)]
sorted_word = tuple(tuple(sorted(list(word[i]))) for i in range(N))
dict_word = {sorted_word[i]:0 for i in range(N)}
ans = 0


for i in range(N):
  if sorted_word[i] in sorted_word[i+1:]:
    dict_word[sorted_word[i]] += 1
    
for value in dict_word.values():
  ans += int((1+value) * value / 2)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
words = []
answer = 0

for i in range(num):
  words.append(sorted(list(input())))
words.sort(key=lambda x:(x[9],x[8],x[7],x[6],x[5],x[4],x[3],x[2],x[1],x[0]))
for i in range(num - 1):
  q = 0
  for j in range(num -i - 1):
    if q >0 and words[i][9] != words[j + 1 + i][9]:
      break
    if words[i] == words[j + 1 + i]:
      answer += 1
      q += 1
    
    
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
word = [input() for i in range(N)]
sorted_word = [tuple(sorted(list(word[i]))) for i in range(N)]
dict_word = {sorted_word[i]:0 for i in range(N)}
ans = 0



for i in range(N):
  if sorted_word[i] in sorted_word[i+1:]:
    dict_word[sorted_word[i]] += 1
    
for value in dict_word.values():
  ans += (1+value) * value / 2
  
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
words = []
answer = 0

for i in range(num):
  words.append(sorted(list(input())))
words.sort(key=lambda x:x[0])
for i in range(num):
  q = 0
  for j in range(num -i - 1):
    p = 0
    out = 0
    if q >0 and words[i][0] != words[j + 1 + i][0]:
      break
    if words[i] == words[j + 1 + i]:
      answer += 1
      q += 1
    
    
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
data=["".join(sorted(input())) for i in range(n)]
hash=[]
r=[26**i for i in range(10)]
for s in data:
  h=0
  for c, i in zip(s,range(10)):
    h+=(ord(c)-97)*r[i]
  hash.append(h)
count=0
for i in range(n):
  for j in range(i+1,n):
    if hash[i]==hash[j]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
words = []
answer = 0

for i in range(num):
  words.append(sorted(list(input())))
words.sort(key=lambda x:x[0])
for i in range(num):
  q = 0
  for j in range(num -i - 1):
    p = 0
    out = 0
    if q >0 and words[i][0] != words[j + 1 + i][0]:
      break
    for k in range(10):
      if words[i][k] == words[j + 1 + i][k]:
        p += 1
      else:
        break
    if p == 10:
      answer += 1
      q += 1
    
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
strings.sort()
sums=0
sorteds=strings
for st in list(set(sorteds)):
    n=sorteds.count(st)
    if n!=1:
       sums=sums+combinations_count(n,2)

print(sums)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
word = [input() for i in range(N)]
sorted_word = [sorted(list(word[i])) for i in range(N)]
count = 0
for i in range(N-1):
  for j in range(1,N-i):
    if sorted_word[i] == sorted_word[i+j]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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


while sortlist:
    a=sortlist.pop()
    times=sortlist.count(a)+1
    for i in range(times-1):
        sortlist.pop()
    b=int(times*(times-1)/2)
    count+=b
    
print(int(count) )

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
src = [''.join(sorted(input())) for _ in range(n)]
dic = {}
for s in src:
    # 辞書にキーが存在しなければキー追加
    if s not in dic:
        dic[s] = 0
    else:
        dic[s] += 1
count = 0
# 辞書から値だけ取り出す
for d in dic.values():
    count += len(list(itertools.combinations(range(d+1), 2)))
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
wordlist=[input() for i in range(n)]
sortlist=[]
for i in range(n):
    a=list(wordlist[i])
    a.sort()
    a="".join(a)
    sortlist.append(a)
    
count=0
sortlist.sort()


while sortlist:
    a=sortlist.pop()
    times=sortlist.count(a)+1
    for i in range(times-1):
        sortlist.pop()
    b=int(times*(times-1)/2)
    count+=b
    
print(int(count) )

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
s = [input() for i in range(n)]

ans = 0
dic =[]
for i in s:
    a = [c for c in i]
    a.sort()
    if len(dic) == 0:
        dic.append(a)
    else:
        for d in dic:
            if a==d:
                ans+=1
            
        dic.append(a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
check = [False] * N
cnt = 0
for i in range(N - 1):
    part = 0
    if check[i]:
        continue
    for j in range(i + 1, N):
        if check[j]:
            continue
        if s[i] == s[j]:
            part += 1
            check[j] = True
    cnt += (part + 1) * part // 2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = ['']*N

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

s.sort()
ans = 0
for i in range(N):
  ans += s[i+1:].count(s[i])
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [sorted(input()) for i in range(n)]
ans = 0
for i in range(n):
    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())
d = {}
for i in range(N):
  s = "".join(sorted(input()))
  if s in d.keys():
    d[s] += 1
  else:
    d.setdefault(s, 1)
count = 0
for v in d.values():
  count += (v-1)*v//2
print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n = int(input())
s = []
for i in range(n):
    s.append(input())
count = 0
#---ここまでok
for i in range(n):
    s[i] = ''.join(sorted(s[i]))
set_s = list(set(s))
if len(set_s) != len(s):
    for i in set_s:
        if s.count(i) >= 2:
            count += int(s.count(i) * (s.count(i) - 1) / 2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
b=[]
x=0
t=1
for i in range(N):

    a=list(input())

    a.sort(reverse=False)

    b.append(a)


while True:

    if len(b)==1:

        break

    q=b[0]

    if q==b[t]:

        x+=1

    

    if t==len(b)-1:

        del b[0]

        t=0

    t+=1





print(x)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = []
for i in range(N):
  a = list(input())
  A.append(sorted(a))

count=0
for i in range(N):
  for j in range(i+1, N):
    if A[i]==A[j]:
      count+=1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
x=int(input())
z=0
l=[]
while(z<x):
    n=input()
    n=sorted(n)
    l.append(n)
    z+=1
s=0
f=0
h=1
while(s<(x-1)):
    while(h<x):
        if(l[s]==l[h]):
            f+=1
        h+=1
    s+=1
    h=s+1
print(f)

Submission status: Time Limit Exceeded

Solution code:
import math

def calc_comb(n):
    k = 2
    if n <= 1 :
        return 0
    elif n ==2 :
        return 1
    return math.factorial(n)/(math.factorial(n-k) * math.factorial(k))

n = int(raw_input(""))

smap = {}
tmp = ""
for i in range(0, n):
    tmp = ''.join(sorted(raw_input("")))
    if smap.get(tmp, None) == None:
        smap[tmp] = 1
    else:
        smap[tmp] += 1
count = 0
for s, num in smap.items():
    #print num
    count += calc_comb(num)
print count

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
data=["".join(sorted(input())) for i in range(n)]
hash=[sum(ord(c) for c in s) for s in data]
count=0
for i in range(n):
  for j in range(i+1,n):
    if hash[i]==hash[j] and data[i]==data[j]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

def calc_comb(n):
    k = 2
    if n <= 1 :
        return 0
    elif n ==2 :
        return 1
    return math.factorial(n)/(math.factorial(n-k) * math.factorial(k))

n = int(raw_input(""))

smap = {}
tmp = ""
for i in range(0, n):
    tmp = raw_input("")
    tmp_s = ''.join(sorted(tmp))
    if smap.get(tmp_s, None) != None:
        smap[tmp_s] += 1
    else:
        smap[tmp_s] = 1
count = 0
for s, num in smap.items():
    #print num
    count += calc_comb(num)
print count

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
data=["".join(sorted(input())) for i in range(n)]
hash=[max(ord(c) for c in s) for s in data]
count=0
for i in range(n):
  for j in range(i+1,n):
    if hash[i]==hash[j] and data[i]==data[j]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def sort_str(str):
  return ''.join(sorted(list(str)))

n = int(input().rstrip())
s = [sort_str(input().rstrip()) for _ in range(n)]

ans = 0
pool = {}
for i in range(n):
  if not s[i] in pool.keys():
    pool[s[i]] = 0
  else:
    pool[s[i]] += 1
    ans += pool[s[i]]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
data=["".join(sorted(input())) for i in range(n)]
count=0
for i in range(n):
  for j in range(i+1,n):
    if data[i]==data[j]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
stl =[''.join(sorted(input())) for i in range(num)]

duplicate=[x for x in set(stl) if stl.count(x) > 1]

count=0

for dup in duplicate:
    n=stl.count(dup)
    count += n*(n-1) // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
data=[sorted(input()) for i in range(n)]
count=0
for i in range(n):
  for j in range(i+1,n):
    if data[i]==data[j]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import string


def str2dic(str):
  dic = {c:0 for c in string.ascii_lowercase}
  for c in str:
    dic[c] += 1
  return dic

def is_anaglam(a, b):
  if a == b:
    return True
  return False


n = int(input().rstrip())
s = [str2dic(input().rstrip()) for _ in range(n)]

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

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
import sys

input=sys.stdin.readline

num=int(input())
#stl =[''.join(sorted(input())) for i in range(num)]
stl =[input() for i in range(num)]
stl =[''.join(sorted(i)) for i in stl]

duplicate=[x for x in set(stl) if stl.count(x) > 1]

count=0

for dup in duplicate:
    n=stl.count(dup)
    count += factorial(n) // 2 // factorial(n - 2)
print(count)

Submission status: Time Limit Exceeded

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


def is_anaglam(a, b):
  if sorted(list(a)) == sorted(list(b)):
    return True
  return False


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

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
import sys

input=sys.stdin.readline

num=int(input())
stl =[''.join(sorted(input())) for i in range(num)]

duplicate=[x for x in set(stl) if stl.count(x) > 1]

count=0

for dup in duplicate:
    n=stl.count(dup)
    count += factorial(n) // 2 // factorial(n - 2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

num=int(input())
stl =[''.join(sorted(input())) for i in range(num)]

duplicate=[x for x in set(stl) if stl.count(x) > 1]

count=0

for dup in duplicate:
    n=stl.count(dup)
    count += factorial(n) // 2 // factorial(n - 2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
range_arr = range(num)

strs = [[] for i in range_arr]
for i in range_arr:
    strs[i] = input()

def sort(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: sort(v), strs))
strs_length = len(new_strs)

cnt = 0
for i, str in enumerate(new_strs):
    if i >= strs_length-1:
        continue
    
    cnt += new_strs[(i+1):].count(str)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
dicts = {}
for i in range(N):
    s = "".join(sorted(input()))
    dicts[s] = dicts[s] + 1 if s in list(dicts.keys()) else 1

num = 0
for k, v in dicts.items():
  num += v * (v-1) // 2
print(num)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
range_arr = range(num)

strs = [[] for i in range_arr]
for i in range_arr:
    strs[i] = input()

def conv(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: conv(v), strs))
compact_strs = list(set(new_strs))

cnt = 0
for str in compact_strs:
    i = 0
    for tmp_str in new_strs:
        if str == tmp_str:
            cnt += i
            i += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
s = list(map(sorted,s))
ss = list("".join(i) for i in s)
score = 0
for j in range(len(ss)-1):
    score += ss[j+1:].count(ss[j])
print(score)