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:
from collections import Counter

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
ans = 0
for _ in range(n):
  x = list(input())
  x.sort()
  s.append("".join(x))
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:
#a,b=map(int,input().split())
#p_3,p_4=map(int,input().split())
n=int(input())
#g=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
s=[list(input())for _ in range(n)]
#h=list(map(int,input().split()))
#b=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#s=[list(input().split())for _ in range(n)]
#s=[input()for _ in range(n)]
import copy
ans=[]
for i in range(n):
    s[i].sort()
    tmp="".join(s[i])
    ans.append(tmp)
ans_set=copy.deepcopy(ans)
ans_set=list(set(ans))
cnt=0
for i in range(len(ans_set)):
    ans_cnt=ans.count(ans_set[i])
    cnt+=(ans_cnt*(ans_cnt-1))//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[list(input()) for _ in range(n)]
for i in range(n):
	s[i].sort()
count=0
for i in range(n):
	for j in range(n):
		if s[i]==s[j]:
			count+=1
print(int((count-n)/2))

Submission status: Time Limit Exceeded

Solution code:
#137c
N = int(input())
sList = []
ans = 0

#文字を読み込みつつ、出現回数を辞書化して、配列に追加
for i in range(N): #2<N<10^5
    # https://www.lifewithpython.com/2015/05/python-count-characters-in-string.html
    string = str(input())

    #辞書化
    #counter = {}
    #for c in string:
    #    if not c in counter:
    #        counter[c] = 1
    #    else:
    #        counter[c] += 1
    #sList.append(counter)
    #↓リスト内包表記なら1行で書ける
    dictionarized_string = {letter: string.count(letter) for letter in string}
    ans += sList.count(dictionarized_string)
    sList.append(dictionarized_string)
    
#全通りを比較
#for i in range(N-1):
#    for j in range(i+1,N,1):
#        if sList[i]==sList[j]:
#            ans = ans+1
#↑.countで1行で済んだ  

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
strings = [[]*10 for i in range(n)]
for i in range(n):
    strings[i] = sorted(list(input()))

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import collections
N=int(input())
s=['']*N
for i in range(N):
    s[i]=input()
c=list(map(collections.Counter,s))
count=0
for i in range(N):
    count += c[i+1:].count(c[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
l=[]
val=[]
for i in range(N):
  s=list(str(input()))
  s.sort()
  if s not in l:
    l.append(s)
    val.append(1)
  else:
    num=l.index(s)
    val[num]+=1
ans=0
for i in range(len(val)):
  ans+=val[i]*(val[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#AtCoder

import sys
import math
import itertools

def checkAnagram(S1, S2):
	s1 = sorted(S1)
	s2 = sorted(S2)
	for n in range(len(s1)):
		if s1[n] != s2[n]:
			return False
	return True

N = int(input())
S = []

for n in range(N):
	S.append(input())

count = 0
for n in range(N):
	for m in range(n+1,N):
		if checkAnagram(S[n],S[m]):
			count += 1

print(count)

"""

"""

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N = int(input())
words = list()
count = 0
for _ in range(N):
    words.append(sorted(input()))

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
words = list()
count = 0
for _ in range(N):
    words.append(sorted(input()))

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_s = []
for i in range(N):
    list_s.append(list(input()))

def judge(sent1,sent2):
    sent1.sort()
    sent2.sort()
    return sent1 == sent2

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

sList = []
ans = 0

#文字を読み込みつつ、出現回数を辞書化して、配列に追加
for i in range(N):
    # https://www.lifewithpython.com/2015/05/python-count-characters-in-string.html
    string = str(input())
    counter = {}
    
    #辞書化
    for c in string:
        if not c in counter:
            counter[c] = 1
        else:
            counter[c] += 1
            
    sList.append(counter)
    
#全通りを比較
for i in range(N-1):
    for j in range(i+1,N,1):
        if sList[i]==sList[j]:
            ans = ans+1
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as  np
n=int(input())
b=[sorted(list(input())) for i in range(n)]
print(int(np.sum(list(map(lambda x:b.count(x)-1, b)))*0.5))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [[] for _ in range(N)]
count = 0
for i in range(N):
    S[i] = list(input())
    S[i].sort()
for i in range(N-1):
    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())

list_s = []
for i in range(n):
    s = input()
    list_s_tmp = []
    for j in s:
        list_s_tmp.append(j)
    
    list_s.append(sorted(list_s_tmp))

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

print((result - n))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = [input() for _ in range(n)]
V = sorted(v)

cnt = 0

for i in range(n):
    V[i] = sorted(V[i])

for i in range(n):
    for j in range(n):
        if V[i] == V[j] and i!=j:
            cnt += 1
            
print(int(cnt/2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
for k in range(n):
    s[k]=sorted(list(s[k]))
count = 0

for x in range (n-1):
    for y in range (x+1,n):
        if s[x]==s[y]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
for k in range(n):
    s[k]=''.join(sorted(list(s[k])))
count = 0

for x in range (n-1):
    for y in range (x+1,n):
        if s[x]==s[y]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[sorted(input()) for _ in range(N)]
 
S=sorted(s)
 
count=0
for i in range(N):
    for j in range(i+1,N):
        if S[i]==S[j]:
            count+=1
        else:
            break
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
  s_val = list(input())
  s_val.sort()
  s.append(s_val)
ans = 0
while s != []:
  for k in range(1,len(s)):
    if s[0] == s[k]:
      ans += 1
  s.remove(s[0])
print(ans)

Submission status: Time Limit Exceeded

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

S=sorted(s)

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

print(count)

Submission status: Time Limit Exceeded

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

S=sorted(s)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
def countAnagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    if f(w1) == f(w2):
        return 1
    else:
        return 0

n = int(input())
nlist = [input() for i in range(n)]
r = 0
for i, j in enumerate(nlist):
    for k, l in enumerate(nlist):
        if i < k:
            r += countAnagrams(j, l)
print(r)

Submission status: Time Limit Exceeded

Solution code:
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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[]
count=0
for i in range(N):
    s=sorted(input())
    S.append(s)
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:
import sys

N = int(input())
ana = {}
answer = 0

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

    for k in (ana.keys()):
        if new_str == k:
            ana[k] += 1
            answer += ana[k]
            flag = 1

    if flag == 0:
        ana[new_str] = 0

print(answer)

Submission status: Time Limit Exceeded

Solution code:
x = 0
n = int(input())
values = [""]*n
for i in range(0, n, 1):
    values[i] = "".join(sorted(list(input())))
for i in range(0, n, 1):
    x+=values[i+1:].count(values[i])
print(x)

Submission status: Time Limit Exceeded

Solution code:
x = 0
n = int(input())
values = [""]*n
for i in range(0, n, 1):
    values[i] = input()
    values[i] = "".join(sorted(list(values[i])))
for i in range(0, n, 1):
    for j in range(i+1, n, 1):
        #print(values[i],values[j])
        if values[i]==values[j]:
            x+=1
        else:
            pass
print(x)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

comb = itertools.combinations(s,2)

cnt = 0
for x,y in comb:
  x = list(x)
  x.sort()
  y = list(y)
  y.sort()
  if x == y:
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

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

comb = itertools.combinations(s,2)

cnt = 0
for x,y in comb:
  if collections.Counter(x) == collections.Counter(y):
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(n):
    si = input()
    s[i] = sorted(list(si))
    for j in range(i - 1, -1, -1):
        if s[i] == s[j]:
            num_of_anaglam[i] = 1 + num_of_anaglam[j]
            break

print(sum(num_of_anaglam))

Submission status: Time Limit Exceeded

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

list_new=[]
i=0
counter=0
while i <=n-1:
    list_new.append(sorted(list_[i]))
    counter+=list_new.count(sorted(list_[i]))-1
    i+=1

print(counter)

Submission status: Time Limit Exceeded

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

for _ in range(n):
    si = input()
    slist = sorted(list(si))
    for i in range(len(s)):
        if slist == s[i]:
            ctr += 1
    s.append(slist)

print(ctr)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for i in range(N):
    S = input()
    S = sorted(S)
    s.append(S)
ans = 0

for j in range(N):
    for k in range(j, N, 1):
        if s[j] == s[k] and j != k:
            ans += 1
        else:
            continue
print(ans)

Submission status: Time Limit Exceeded

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

for _ in range(n):
    si = input()
    slist = sorted(list(si))
    for i in range(len(s)):
        if slist == sorted(list(s[i])):
            ctr += 1
    s.append(si)

print(ctr)

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    n = int(input())
    s_array = [''.join(sorted(input()[:-1])) for _ in range(n)]

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

    print(count)

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    n = int(input())
    s_array = [sorted(input()[:-1]) for _ in range(n)]

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

    print(count)

Submission status: Time Limit Exceeded

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


def main(n, s_array):
    count = 0
    for i in range(n):
        for j in range(i+1, n):
            if(s_array[i] == s_array[j]):
                count += 1
    return count


if __name__ == "__main__":
    n = int(input())
    s_array = [sorted(input()[:-1]) for _ in range(n)]

    print(main(n, s_array))

Submission status: Time Limit Exceeded

Solution code:
import time
N = int(input())
s = [str(input()) for i in range(N)]

e = []
f = [0] * N
j = 0
ans = 0
for i in range(N):
  s[i] = "".join(sorted(s[i]))
#print(s)

for i in range(N):
  if s[i] not in e:
    e.append(s[i])
    f[j] = 1
    j += 1
  else:
    a = e.index(s[i])
    ans += f[a]
    f[a] += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [[]]*N
for i in range(N):
  k = input()
  s[i] = [c for c in k]
  s[i].sort()

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
letters = []
for i in range(n):
	l = input()
	s = sorted(l)
	letters.append(s)
ans = 0
for j in range(n):
	ans += (letters.count(letters[0]) - 1)
	letters.remove(letters[0])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [str(input()) for i in range(N)]
#print(s)

e = []
f = [0] * N
j = 0
ans = 0
for i in range(N):
  s[i] = sorted(s[i])
  if s[i] not in e:
    e.append(s[i])
    f[j] = 1
    j += 1
  else:
    a = e.index(s[i])
    ans += f[a]
    f[a] += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [str(input()) for i in range(N)]
#print(s)

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

e = []
f = [0] * N
j = 0
ans = 0
for i in range(N):
  if s[i] not in e:
    e.append(s[i])
    f[j] = 1
    j += 1
  else:
    a = e.index(s[i])
    ans += f[a]
    f[a] += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

li1 = []
for _ in range(n):
    s = list(input())
    li1.append(sorted(s))


li2 = []
for i in li1:
    s = ''.join(i)
    li2.append(s)

cnt = 0
for i in set(li2):
    cnt1 = li2.count(i)
    cnt += (cnt1*(cnt1-1))//2
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i<j:
            ana1 = sorted(list(S[i]))
            ana2 = sorted(list(S[j]))
            if ana1 == ana2:
                count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i<j:
            ana1 = list(S[i])
            ana2 = list(S[j])
            ana1.sort()
            ana2.sort()
            if ana1 == ana2:
                count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i == j or i > j: #2つの文字列を選択
            continue
        else:
            ana1 = list(S[i])
            ana2 = list(S[j])
            ana1.sort()
            ana2.sort()
            if ana1 == ana2:
                count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i == j or i > j: #2つの文字列を選択
            continue
        else:
            ana1 = []
            ana2 = []
            for k in range(10):
                ana1.append(S[i][k])
                ana2.append(S[j][k])
                ana1.sort()
                ana2.sort()
           
            if ana1 == ana2:
                count += 1
            else:
                continue
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
#import collections
#import sys
 
#input=sys.stdin.readline
 
N=int(input())
l=[]
clist=[]
 
for i in range(N):
    l.append(list(input()))
    l[i].sort()
    l[i]="".join(l[i])
    #clist.append(collections.Counter(list(input().replace("\n",""))))#ここは普通に入れてfor文でcounterする
 
count=0
 
for i in range(N):
    for j in range(i+1,N):
        if l[i]==l[j]:
            count+=1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
#import collections
#import sys
 
#input=sys.stdin.readline
 
N=int(input())
l=[]
 
for i in range(N):
    l.append(list(input()))
    l[i].sort()
    #clist.append(collections.Counter(list(input().replace("\n",""))))#ここは普通に入れてfor文でcounterする
 
count=0
 
for i in range(N):
    for j in range(i+1,N):
        if l[i]==l[j]:
            count+=1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import collections
import sys
 
input=sys.stdin.readline
 
N=int(input())
l=[]
clist=[]
 
for i in range(N):
    l.append(list(input().replace("\n","")))
    l[i]=collections.Counter(l[-1])
    #clist.append(collections.Counter(list(input().replace("\n",""))))#ここは普通に入れてfor文でcounterする
 
count=0
 
for i in range(N):
    for j in range(i+1,N):
        if l[i]==l[j]:
            count+=1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import collections
import sys
 
input=sys.stdin.readline
 
N=int(input())
l=[]
clist=[]
 
for i in range(N):
    l.append(list(input().replace("\n","")))
    clist.append(collections.Counter(l[-1]))
    #clist.append(collections.Counter(list(input().replace("\n",""))))#ここは普通に入れてfor文でcounterする
 
count=0
 
for i in range(N):
    for j in range(i+1,N):
        if clist[i]==clist[j]:
            count+=1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
check_arr = np.zeros([N, 26])

for i in range(N):
    word = input()
    for j in range(len(word)):
        check_arr[i, ord(word[j])-ord('a')] += 1
count = 0
for l in range(N):
    for m in range(l+1, N):
        if (check_arr[l] - check_arr[m] == np.zeros(26)).all():
            count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
S = []

ans = 0

for i in range(N):
    S.append(sorted(list(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:
n=int(input())
s=[]
for i in range(n):
    s.append(''.join(sorted(input())))
ans=0
while(s!=[]):
    ans+=s.count(s[0])*(s.count(s[0])-1)//2
    s=[i for i in s if i!=s[0]]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append(''.join(sorted(input())))
ans=0
while(s!=[]):
    if s.count(s[0])>1:
        ans+=s.count(s[0])*(s.count(s[0])-1)//2
    s=[i for i in s if i!=s[0]]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
econ = []
for i in range(n):
    econ.append(input())
for i in range(n): 
    a = []
    for j in econ[i]:
        a += j
    econ[i] = sorted(a)
        
tei = 0      
for i in range(n):
    for j in range(i+1,n):
        if econ[i] == econ[j]:
            tei += 1
print(tei)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[sorted(input()) for _ in range(N)]
m=0
for i in range(N):
  c=s.count(s[i])
  if c>1:
    m+=c-1
    s[i]=[]
print(m)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[sorted(input()) for _ in range(N)]
m=0
for i in range(N):
  c=s.count(s[i])
  if c>1:
    m+=c-1
  s[i]=[]
print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
c = 0
c_dict = {}
l = []
for i in range(n):
    s_listed = sorted(list(input()))
    s = ''.join(s_listed)
    if s in l:
        if s in c_dict.keys():
            c_dict[s] += 1
        else:
            c_dict[s] = 1
    l.append(s)
for i in c_dict.values():
    if i == 1:
        c += 1
    else:
        c += i * (i + 1) / 2
print(int(c))

Submission status: Time Limit Exceeded

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

N = int(input())
s = []
for _ in range(N):
    s_array = sorted(input())
    x = ""
    for i in s_array:
        x += i
    s.append(x)


count = 0
for x in range(N):
    for y in range(x + 1, N):
        if s[x] == s[y]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

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

count = 0
for x in range(N):
    for y in range(x + 1, N):
        if s[x] == s[y]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def verify_anagrams(s1, s2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(s1) == f(s2)

N = int(input())
S = [input() for _ in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if verify_anagrams(S[i], S[j]):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

count = 0
for x in range(N):
    for y in range(x + 1, N):
        if s[x] == s[y]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

def to_dict(s):
    res = defaultdict(int)
    for i in range(0, len(s)):
        c = s[i]
        res[c] = res[c] + 1

    return res

def same_dict(d1, d2):
    for k, v in d1.items():
        if k not in d2:
            return False
        if d1[k] != d2[k]:
            return False

    return True

N = int(input())
s_dicts = []

for i in range(0, N):
    s_dicts.append(to_dict(input()))

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
def anagram(s):
    count = 0
    for i in range(n):
        for j in range(i+1,n):
            if s[i] == s[j]:
                count += 1
    return count

n = int(input())
s = []
for i in range(n):
    li = sorted(input())
    li = ''.join(li)
    s.append(li)
print(anagram(s))

Submission status: Time Limit Exceeded

Solution code:
def anagram(s):
    count = 0
    for i in range(n):
        for j in range(i+1,n):
            if s[i] == s[j]:
                count += 1
    return count
  
n = int(input())
s = []
for i in range(n):
    li = sorted(input())
    s.append(li)
print(anagram(s))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [''.join(sorted(input())) for _ 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:
input_size = int(input())
a = []
s = 0
b = []
for i in range(input_size):
  a.append(input())
  b.append([])
  for l in a[i]:
    b[i].append(l)
  b[i].sort()

for num in range(input_size):
  for num_2 in range(num + 1, input_size):
    if b[num] == b[num_2]:
      s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  l = []
  for i in range(n):
    l.append(input())
  for i in range(n):
    l[i] = ''.join(sorted(l[i]))
  l.sort()
  
  fact = [1 for i in range(n+1)]
  for i in range(1, n+1):
    fact[i] = fact[i-1]*i
  
  res = 0
  count = 1
  for i in range(1,n):
    if l[i-1] == l[i]:
      count += 1
      if i == n-1:
        res += int(fact[count]/(fact[count - 2]*fact[2]))
    elif count > 1:
      res += int(fact[count]/(fact[count - 2]*fact[2]))
      count = 1
    elif count == 1:
      pass
    else:
      print('error!')
      quit()
  
  print(res)
  
if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lists = []
result = 0
for i in range(N):
    lists.append(input())

sortedlist = []
for i in range(0, N):
    sortedlist.append(sorted(lists[i]))

sortedlist.sort()
for i in range(0, N):
    for j in range(i + 1, N):
        if sortedlist[i] == sortedlist[j]:
            result += 1
        else:
            break

print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lists = []
result = 0
for i in range(N):
    lists.append(input())

sortedlist = []
for i in range(0, N):
    sortedlist.append(sorted(lists[i]))

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
# abc137 C: Green bin

import sys

def cup(n):
    return int((n+1) * (n/2))

N = int(input())
array = [''.join(sorted(list(input()))) for i in range(N)]
item = set(array)

result = 0
for i in item:
    c = array.count(i)
    if c > 1:
        result += cup(c-1)

print(result)

Submission status: Time Limit Exceeded

Solution code:
# abc137 C: Green bin

import sys

def cup(n):
    return int((n+1) * (n/2))

N = int(input())
array = [''.join(sorted(list(input()))) for i in range(N)]
item = set(array)

result = 0
for i in item:
    c = array.count(i)
    result += cup(c-1)

print(result)

Submission status: Time Limit Exceeded

Solution code:
# abc137 C: Green bin

import sys

N = int(input())
array = [''.join(sorted(list(input()))) for i in range(N)]
item = set(array)

result = 0
for i in item:
    c = array.count(i)
    for j in range(c):
        result += j

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [list(input()) for i in range(n)]
l = ["".join(sorted(i)) for i in l]
l = [i for i in l if i != 1]
l.sort()
s = 0
for i in range(len(l)-1):
  for j in range(i+1,len(l)):
    if l[i] == l[j]:
      s += 1
    else:
      break
print(s)

Submission status: Time Limit Exceeded

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