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())
sl = [input() for _ in [0]*n]
for i in range(len(sl)):
  sl[i] = sorted(sl[i])
  sl[i] = ''.join(sl[i])
count = 0
sl.sort()
while len(sl)>1:
  i = sl.count(sl[-1])
  if i > 1:
    count += i*(i-1)//2
  sl = sl[:-i]
print(count)

Submission status: Time Limit Exceeded

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

for 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 = []
for i in range(N):
    s.append(input().strip())

from collections import Counter

cnt = 0
for i in range(N):
    ms1 = Counter(s[i])
    for j in range(i+1, N):
        ms2 = Counter(s[j])
        if ms1 == ms2:
           cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s= [input() for i in range(N)]
ans=0
for i in range(N):
        for k in range(i+1,N):
                A=list(s[i])
                for j in list(s[k]):
                        if j in A:
                                A.remove(j)
                        else:
                                break
                if len(A) == 0:
                        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis =[]
kotae = 0
for i in range(n):
    lis.append(sorted(list(input())))
for x,i in enumerate(lis):
    for y,k in enumerate(lis):
        if x < y:
            if i == k:
                kotae += 1
print(kotae)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
dicts = {}
for _ in range(K):
    string = str(sorted(input()))
    if string in dicts:
        dicts[string] += 1
    else:
        dicts[string] = 1
# print(dicts)

def calc_pairs(n):
    return n*(n-1)//2
answer = 0
for i,v in dicts.items():
    answer += calc_pairs(v)
    
# answer = 0
# for i in range(K-1):
#     for j in range(i+1,K):
#         if strs[i] == strs[j]:
#             answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
alphas = [chr(i).lower() for i in range(65, 65+26)]

n = int(input())

same_count = 0
sorted_list = []
for index in range(n):
  s = input()
  sorted_s = ''.join(sorted(s))
  same_count += sorted_list.count(sorted_s)

  sorted_list.append(sorted_s)
print(same_count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
m = {}

for i in range(n):
  s = "".join(sorted(list(input())))
  if s in m.keys():
    m[s] = m[s] + 1
  else:
    m[s] = 1

ans = 0
for s in m.keys():
  ans += m[s] * (m[s] - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
"""
https://atcoder.jp/contests/abc137/tasks/abc137_c
"""

import numpy as np


def calc(N: int, sorted_strings: np.ndarray) -> np.ndarray:
    anagram_count = 0
    for i in range(N):
        for j in range(i + 1, N):
            if np.all(sorted_strings[i] == sorted_strings[j]):
                anagram_count += 1
    return anagram_count


def main() -> None:
    N = int(input())
    sorted_strings = np.array([sorted(input()) for _ in range(N)])
    result = calc(N, sorted_strings)
    print(result)


main()

Submission status: Time Limit Exceeded

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

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

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:
from collections import Counter
n = int(input())

sn = []
count = 0

for i in range(n):
  sn.append(Counter(list(input())))

for i in range(n - 1):
  for j in range(i+1,n):
    if sorted(sn[i].items()) == sorted(sn[j].items()):
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
string = np.zeros(N)
ans = 0
for i in range(N):
    mozi = input()
    for k in range(10):
        string[i] += (ord(mozi[k])-96)**10

string_new = sorted(string)
for j in range(N-1):
    index = j + 1
    while string_new[j] == string_new[index]:
        ans += 1
        index += 1
        if index >= N:
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

conbi = 0

strings = []
for i in range(n):
  
  notinstr = 1
  s = input()
  l = [0] * 27 #27こめがかぶった回数
  for j in s:
    l[ord(j)-ord('a')] += 1
  
  for string in strings:
    f = 0
    for j in range(26):
      if l[j] != string[j]:
        f = 1
        break
    
    if(f == 0):
      string[26] += 1
      #print(string[26])
      conbi += string[26]
      notinstrs = 0
      break
  
  if notinstr == 1:
    strings.append(l)
  
print(conbi)

Submission status: Time Limit Exceeded

Solution code:
import  numpy   as  np
N   =   int(input())
A   =   []

Alphabet    =   np.zeros((N,26)).astype(np.uint8)

counter     =   0

for i in range(N):
    A.append(input())
    
    for j in range(10):
        Alphabet[i , ord(A[i][j] ) - ord('a')] += 1

for i in range(0 , N):
    for j in range(i + 1 , N,1):
        ans     =   np.sum(np.uint8(Alphabet[i] == Alphabet[j]))
        if(ans == 26):
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [input() for _ in range(n)]
ans = 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):
  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:
n=int(input())
slist=[]
for i in range(n):
    slist.append(''.join(sorted(input())))
dup = [s for s in set(slist) if slist.count(s) > 1]
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
res=0
for s in dup:
    res += combinations_count(slist.count(s),2)
print(res)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import collections
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 = []
count = []
for i in range(n):
    s = list(str(input()))
    s = collections.Counter(s)
    s = sorted(s.items(), key=lambda x:x[0])
    #print(s)
    if i == 0:
        S.append(s)
        count.append(0)
        continue
    if s in S:
        #print(S,s)
        #print(S.index(s))
        count[S.index(s)] += 1
        #count += 1
        #S.append(s)
    else:
        S.append(s)
        count.append(0)
#print(count)
ans = 0
for cnt in count:
    if cnt==0:
        continue
    ans += cmb(cnt+1, 2)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s_list = ["".join(sorted(input())) for _ in range(N)]
s_set = set(s_list)
ans = 0

for D in s_set:
  num = s_list.count(D) 
  ans += (num * (num-1)) // 2
  
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#######################################
import numpy as np
import math
import copy
import re
import sys
#sys.exit(0)

inf = float("inf")
prime = 1

def check_print(check_flag, text, end="\n"):
  if check_flag:
    print(text, end=end)

def c2i(x):
    if str.isdecimal(x):
        return int(x)
    else:
        return x

def cout(*args):
  arglist = []
  for arg in args:
    if hasattr(arg, "__iter__"):
      arglist.extend(arg)
    else:
      arglist.append(arg)
      
  arglist = list(map(str, arglist))
  print(" ".join(arglist))
  
def count2(num):
  count=0
  while num%2==0:
    num/=2
    count+=1
  return count

def ketasum(num):
  nums = [int(s) for s in str(num)]
  return sum(nums)

#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return a

def lcm(a, b): #最小公倍数
  return a * b // gcd (a, b)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)

def lcm3(lis): #最小公倍数(3over)
  ans = lis[0]
  for li in lis:
    ans = lcm(ans,li)

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1

#input stock
"""
n = int(input())

#list
a = map(int, input().split())
a,b = map(int, input().split())

d=[]
for i in range(n):
  d[i]=int(input())

#2dim-list
a = [list(map(int, input().split())) for i in range(n)]

s = input()
ss =  [int(si) for si in s]
"""

#processing stock
"""
a = sorted(a)
a = sorted(a, reverse=True)

"""

#regex
"""
pattern = ""
result = re.search(pattern, s)

result = re.fullmatch(pattern, s)

result = re.finditer(pattern, s)
for res in result:
    print res.group()   # 1回目: ca      2回目: ca   
    print res.start()   # 1回目: 0       2回目: 6      
    print res.end()     # 1回目: 2       2回目: 8      
    print res.span()    # 1回目: (0, 2)  2回目: (6, 8)
"""

def strnum(st):
  st = list(st)
  for i in range(len(st)):
    tmp = st[i] + str(st[i:].count(st[i]))
    st[i] = str(tmp)
  return st
#######################################
n = int(input())
s = [""]*n
for i in range(n):
  s[i] = set(strnum(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 = []

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

cnt = 0
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())
ch = []
for i in range(N):
    ch.append(sorted(list(input())))
#print(ch[0])
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if ch[i]==ch[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

pairs = 0

for pos,i in enumerate(s):
    for posj in range(pos+1,len(s)):
        j = s[posj]
        if(sorted(j)==sorted(i)):
            pairs+=1


print(pairs)

Submission status: Time Limit Exceeded

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

count = 0
strs = sorted( strs )
for i in range( n ) :
	bFound = False
	for j in range( i+1, n ) :
		if strs[i] == strs[j] :
			count += 1
			bFound = True
		elif bFound == True :
			break
		else:
			pass

print( count )

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
s,a=[],[]
flag=0
for i in range(n):
 l.append(input())
for i in range(n-1):
 for j in range(i+1,(i)+(n-i)):
  s=list(l[i])
  a=list(l[j])
  flag+=1
  for u in range(10):
   if s[u] in a:
    a.remove(s[u])
   else:
    flag-=1
    break
print(flag)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for _ in range(n)]
ans = 0
for i in range(n-1):
  l = list(set(s[i]))
  for j in range(n):
    if i < j:
      for k in range(len(l)):
        if s[i].count(l[k]) != s[j].count(l[k]):
          break
        if k == len(l)-1:
          ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
s = [collections.Counter(list(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:
def factorial(n):
    a = 1
    for i in range(1, n + 1):
        a *= i
    return a

def nCr(n,r):
    if r > n:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

####
N = int(input())
sorted_dic = {}
for i in range(N):
    s = "".join(sorted(input()))
    v = 0
    if s in sorted_dic:
        v = sorted_dic[s]
    sorted_dic[s] = v + 1

ans = 0
for k in sorted_dic:
    v = sorted_dic[k]
    #print(k,v,factorial(v),factorial(2), factorial(v - 2), nCr(v, 2))
    ans = ans + nCr(v, 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python

l_s = []
c = 0
n = int(input())
for i in range(n):
    s = input()
    l_s.append(sorted(s))

for i in range(len(l_s)):
    c += l_s[i:].count(l_s[i])-1

print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import collections

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

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

N=input()

fact= [1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact.append(fact_tmp) 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n]/fact[r]/fact[n-r])

C=defaultdict(lambda: 0) 
for i in range(N):
	s=raw_input()
	s=list(s)
	s.sort()
	s="".join(s)
	C[s]+=1
ans=0

for i in C.values():
	ans+=ncr(i,2)

print ans

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections 
N=int(input())
S=[collections.Counter(list(input())) for i in range(N)]

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    ans = 0
    while len(s) != 0:
        cnt = s.count(s[0])
        tmp = s[0]
        for i in range(cnt):
            s.remove(tmp)
        if cnt == 1:
            continue
        ans += (cnt * (cnt - 1)) / 2
    print(int(ans))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0

for g in range(N):
    for k in range(N):
        if g == k:
            continue
        if S[g] == S[k]:
            # print("g {} k {}".format(g,k))
            count+=1


print(int(count/2))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
strs = [Counter(input()) for i in range(N)]
ans=0
for i in range(len(strs)):
    if strs[i] in strs[i+1:]:
        ans+=strs[i+1:].count(strs[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
s = [input() for i in range(N)]
ans = 0
S =[]
for i in range(N):
  S.append(Counter(s[i]))
for i in range(N):
  for j in range(i+1, N, 1):
    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)]
for i in range(N):
  si=list(str(input()))
  s[i].extend(si)
ans=0

for i in range(N-1):
  for j in range(i+1,N):
    if sorted(s[i])==sorted(s[j]):
      ans+=1
    else:
      pass
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C
N = int(input())
pair = [1]
s = ''.join(sorted(input()))
s_set = {s}
s_list = [s]
for i in range(1, N):
    s = ''.join(sorted(input()))
    if s in s_set:
        pair[s_list.index(s)] += 1        
    else:
        s_list.append(s)
        s_set.add(s)
        pair.append(1)
result = 0
for i in pair:
    result += (i * (i-1))//2
print(result)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

i=0
sortedSet=[]

while i<N:
  temp=input()
  tempSet=[]
  j=0
  while j<len(temp):
    tempSet.append(temp[j])
    j=j+1
  tempSet.sort()
  #print(tempSet)
  sortedSet.append(tempSet)
  i=i+1

result=0
i=0
while i<N:
  j=i+1
  while j<N:
    if sortedSet[i]==sortedSet[j]:
      result=result+1
      #print(i,j)
    j=j+1
  i=i+1

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
texts = []
for i in range(N):
    texts.append((input()))
    

counters = []
count = 0
for text in texts:
    c = collections.Counter(text)
    for t in counters:
        if t == c:
            count += 1
    counters.append(c)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = []
for i in range(n):
    s.append(input())

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        if i == j:
            pass
        else:
            #print(i,j)
            a1 = list(s[i])
            b1 = list(s[j])

            a1.sort()
            b1.sort()

            a2 = "".join(a1)
            b2 = "".join(b1)

            if a2 == b2:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
s = [""]*N
S = []
for i in range(N):
    # s[i] = input()
    S.append(collections.Counter(input()))
# print(s)
# print(S)
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        if S[i] == S[j]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:


import math


def str_sort(s):
    return ''.join(sorted(s))
    
def combinations_count(n, r):
    if n == 1: return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))



N = int(input()) 
S = [str(input()) for i in range(N)] 

S = [str_sort(s) for s in S]

set_S = list(set(S))

ans = 0
if len(set_S) == len(S):
    ans = 0
else:
    for set_s in set_S:
        set_count = S.count(set_s)
        ans += combinations_count(set_count, 2)


print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(N):
  for j in range(i + 1, N):
#    print (i, j, end=" ")
    a = sorted(list(S[i]))
    b = sorted(list(S[j]))
#    print (a, b)
    
    for k in range(10):
      if a[k] != b[k]:
        break
    else:
      cnt += 1
    
print (cnt)

Submission status: Time Limit Exceeded

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

for i in range(N):
    ss.append(sorted(input()))
    
ans = []

for i in ss:
    k = ss.count(i)
    ans.append(k-1)

print(int(sum(ans)/2))

Submission status: Time Limit Exceeded

Solution code:
#n = (int(i) for i in input().split())  
n=int(input())
prime = [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]
num=[1] * n
count = 0
for i in range(0,n):
    S = input()
    for s in S:
        num[i] = num[i] * prime[ord(s)-ord('a')]
    for j in range(0,i):
        if num[i] == num[j]:
            count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [list(input()) for _ in range(N)]
l = []
cnt = 0
for st in s:
    st.sort()
    l.append("".join(st))
l.sort()
a = list(set(l))
for uni in a:
    c = l.count(uni)
    if c>1:
        while c>1:
            cnt += c-1
            c -=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append(''.join(sorted(str(input()))))
ans=0
s.sort()
for i in range(n-1):
    for j in range(i+1,n):
        if s[i]==s[j]:
            ans+=1
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
s=[]
dp=[False]*n
ans=0
for _ in range(n):
    s.append(input())
for i in range(n):
    for j in range(i):
        if not dp[i]:
            dp[i]=Counter(s[i])
        if not dp[j]:
            dp[j]=Counter(s[j])
        if dp[i]==dp[j]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [list(sorted(input())) for i in range(N)]
# s.sort()

ans = 0
for c in s:
        tmp = s.count(c)
        if tmp > 1:
                ans += tmp - 1

print(ans // 2)

Submission status: Time Limit Exceeded

Solution code:
count = 0
scounts = []
N = int(input())
for n in range(N):
    s = sorted(input())
    found = False
    for scount in scounts:
        # print("s="+str(s))
        # print("scount[0]="+str(scount[0]))
        if scount[0] == s:
            found = True
            count += scount[1]
            scount[1] += 1
            break
    if not found:
        scounts.append([s, 1])
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as cl
N = int(input())
List=[input() for i in range(N)]
count = 0
cl_list = [cl(x) for x in List]

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
count = 0
for _ in range(N):
  s.append(sorted(input()))
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:
from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word) == get_counter(second_word)

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

ans = 0
roop = True

while s != []:
    string = s.pop()
    s_new = []
    temp = 1
    for mojiretu in s:
        if verify_anagrams(string, mojiretu):
            temp += 1
        else:
            s_new.append(mojiretu)
    ans += temp * (temp-1) // 2
    s = s_new.copy()

print(ans)

Submission status: Time Limit Exceeded

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

c=0
for j in range(N):
    for i in range(N):
        if i<j:
            if s[i]==s[j]:
                c+=1
        else:
            break

print(c)

Submission status: Time Limit Exceeded

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

pairs = 0

for pos,i in enumerate(s):
    for posj in range(pos+1,len(s)):
        j = s[posj]
        anagram = True
        for k in range(10):
            if i.count(j[k])!=j.count(j[k]) :
                anagram = False
                break
        if(anagram):
            pairs+=1


print(pairs)

Submission status: Time Limit Exceeded

Solution code:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------

N = int(input())						# 5

A=[]
for i in range(N):
	s = input()
	l = sorted(s)
	s = "".join(l)
	A.append(s)

A.sort()
S=set(A)

p("A ",A)
p("S ",S)


ans=0
for s in S:
	i = A.count(s)
	
	ans += i*(i-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
N = int(input())
s = []
for i in range(N):
    ss = input()
    s.append(ss)
t= []
for i in range(N):
    tt= sorted(s[i])
    t.append(tt)
#s.sort()
#print(t)

count = 0
for i in range(N):
    start = t[i]
    for j in range(i+1,N):
#        print("i,j1=",i,j)
        if start == t[j]:
#            print("i,j=",i,j)
            count = count +1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections as col
N = int(input())
l = [input() for _ in range(N)]
count = 0
for i in range(N):
    c = col.Counter(str(l[i]))
    for j in range(i+1, N):
        d = col.Counter(str(l[j]))
        if c == d:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
for n in range(N):
  s = [ss for ss in input()]
  s.sort()
  s_join = "".join(s)
  S.append(s_join)

S_set = list(set(S))
ans = 0
for ss in S_set:
  howmany_ss = S.count(ss)
  if howmany_ss == 1:
    continue
  else:
    ans += sum(range(1, howmany_ss))
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []

char = []
for i in range(26):
    char.append(chr(97+i))

r = 0

for i in range(n):
    l.append(input())

def getCount(s):
    return [s.count(c) for c in char]
    
for i in range(n):
    base = getCount(l[i])
    
    for j in range(i+1, n):
        target = getCount(l[j])
        anagram = True
        for a, b in zip(base, target):
            if not (a == b):
              anagram = False
              break
        if anagram:
            r += 1

print(r)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

alp = ["a","b","c","d","e",
"f","g","h","i","j",
"k","l","m","n","o",
"p","q","r","s","t",
"u","v","w","x","y","z"]

ans = 0
list1 = []
for i in range(n):
    s = input()
    list2=[]
    for alp1 in alp:
        list2.append(s.count(alp1))

    if i >0:
        ans = ans + sum(map(lambda x: x==list2,list1))
            
    list1.append(list2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

char_list = []

for s in S:
	char_list.append(Counter(s))

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

Submission status: Time Limit Exceeded

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

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product, permutations,combinations

n = int(input())

# c_hash = {}
c_list = []
# n = 3
for i in range(n):
    s = input()
    c_list.append(''.join(sorted(s)))

# print(sorted(c_list))

c_hash = {}
for c in c_list:
    if c not in c_hash:
        c_hash[c] = 0
    c_hash[c] += 1
count = 0    
for k, v in c_hash.items():
    if v >= 2:
        temp = len(list(combinations(range(v),2)))
        count += temp

print(count)

Submission status: Time Limit Exceeded

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

ans = 0
for c in s:
        tmp = s.count(c)
        if tmp > 1:
                ans += tmp - 1

print(ans // 2)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
dic = [input() for i in range(num)]

sdic = []
ans = 0
for i in range(num):
    sdic.append("".join(sorted(dic[i])))
for i in range(num):
    ans += (sdic.count(sdic[0]) - 1)
    sdic.pop(0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
def combinations(n, r):
  if n == r:
    return 1
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
s = [[sorted(input()),1]]
ans = 0
for i in range(N-1):
  s_i = sorted(input())
  flag = 0
  for j in range(len(s)):
    if s[j][0] == s_i:
      flag = 1
      s[j][1] += 1
      break
  if flag != 1:
    s.append([s_i,1])
for j in range(len(s)):
    tmp = s[j][1]
    if tmp != 1:
      ans += combinations(tmp,2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    n = int(input())
    s = [sorted(list(input())) for _ in range(n)]
    ans = 0

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))

    return get_counter(first_word) == get_counter(second_word)

n = int(input())
s = []
for i in range(n):
    l = input()
    s.append(l)
cnt = 0 
for i in range(n-1):
    for j in range(i+1, n):
        if verify_anagrams(s[i], s[j]) == True:
            cnt += 1
print(cnt)