Problem:


Score : 300 points

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

s_1, s_2, \ldots, s_N are all distinct.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.



Sample input:
3
acornistnt
peanutbomb
constraint


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S = [input() for _ in range(N)]
answer = 0
histgrams = [dict((x, s1.count(x)) for x in s1) for s1 in S]
for i1 in range(N):
  h1 = histgrams[i1]
  for i2 in range(i1+1,N,1):
    h2 = histgrams[i2]
    if h1 == h2:
      answer += 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import collections


def p_c():
    n = int(input())
    ans = 0

    l = []

    for _ in range(n):
        s = collections.Counter(input())
        for le in l:
            if le == s:
                ans += 1

        l.append(s)

    print(ans)


if __name__ == '__main__':
    p_c()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
N = int(input())
 
A = []
for i in range(N):
    a = input()
    a_counter = Counter(a)
    A.append(a_counter)
    
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        if A[i] == A[j]:
            cnt += 1
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0
A = []
lists = []
for i in range(n):
  lists += [input()]
  a = []
  for x in lists[i]:
    a += [x]
  a.sort()  
  lists[i] = a
     
for j in range(n-1):
  for k in range(j+1,n):
    if lists[j] == lists[k]:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: UTF-8 -*-

n = int(input())
l = []

for i in range(n):
    a = list(str(input()))
    a.sort()
    l.append("".join(a))

p = 0

for i in range(n):
    for j in range(n - i - 1):
        if l[i] == l[i+j+1]:
            p += 1

print(p)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0

A = [["".join(sorted(input()))] for _ in range(n)]
A.sort()

for i in range(n-1):
    a = A[i]
    for j in range(n-i-1):
        if a == A[j+i+1]:
            ans += 1
        else:
            break
            
print(ans)

Submission status: Time Limit Exceeded

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

def main():
    N = int(input())
    s = []
    for i in range(N):
        s.append("".join(sorted(list(input().strip()))))
    s = sorted(s)
    
    tmp = []
    check = [False] * N
    ans = 0
    for i in range(N-1):
        count = 1
        for j in range(i+1, N):
            if not check[j]:
                ok = True
                for k in range(10):
                    if s[i][k] != s[j][k]:
                        ok = False
                        break
                if ok:
                    count += 1
                    check[j] = True
        if count > 1:
            tmp.append(count)
    
    ans = 0
    for n in tmp:
        ans += (n * (n-1))//2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

N = _I()
S = []
for i in range(N):
    S.append(input())

"""
a-zの文字数カウントする
[1,1,0,,,]
[1,1,0,,,]
[1,2,1,,,]

などのリストが得られる。
setしてカウント
"""

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ex = [chr(ord('a') + i) for i in range(26)]
s_counts = []
for s in S:
    s_count = []
    for a in ex:
        s_count.append(s.count(a))
    s_counts.append(s_count)

#  print(s_counts)

ans = 0
done_list = []
for s_count in s_counts:
    if s_count in done_list:
        continue
    else:
        done_list.append(s_count)
        cnt = s_counts.count(s_count)
        if cnt == 1:
            continue
        else:
            ans += combinations_count(cnt, 2)
#  chars = []
#  for s in S:
#      char_list = []
#      for char in s:
#          char_list.append(char)
#      char_list.sort()
#      char_list = ''.join(char_list)
#      chars.append(char_list)
#  #  print(chars)
#  ans = 0
#  done_list = []
#  for char in chars:
#      #  print('char' , char)
#      if char in done_list:
#          continue

#      cnt = chars.count(char)
#      if cnt == 1:
#          continue
#      done_list.append(char)
#      ans += combinations_count(cnt, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

my_list = [None] * N

for i in range(N):
    s_i = sorted(input())
    my_list[i] = s_i

sum = 0

for i in range(N):
    for j in range(i + 1, N):
        for k in range(10):
            if not(my_list[i][k] == my_list[j][k]):
                break
            elif k == 9:
                sum += 1


print(sum)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
S = []
ans = [1] * N
for _ in range(N):
    s = input()
    s = Counter(s)
    for i in range(len(S)):
        if s == S[i]:
            ans[i] += 1
            break
    else:
        S.append(s)

answer = 0

for a in ans:
    if a > 1:
        answer += a * (a-1) / 2

print(int(answer))

Submission status: Time Limit Exceeded

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

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

cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        if std[i]==std[j]:
            cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
s=[0 for _ in range(N)]
count=0
for i in range(N):
    s[i]=input()
for t in range(N):
    for i in range(N):
        if t>=i:
            continue
        if Counter(s[t])==Counter(s[i]):
            count+=1
        if i==t:
            count-=1
print(int((count)))

Submission status: Time Limit Exceeded

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

for i in range(n):
    s[i] = ''.join(sorted(s[i]))
cnt = 0
for i in range(n):
    for j in range(i):
        if s[i] == s[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


N=int(input())

S=[]
for n in range(N):
    s=input()
    s=''.join(sorted(s))
    S.append(s)

key=sorted(list(set(S)))

total=0
for k in key:
    t=S.count(k)
    if(t>=2):
        total+=cmb(S.count(k),2)

print(total)

Submission status: Time Limit Exceeded

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

sts = []
nums = []
for new_st in s:
    new_st = sorted([x for x in new_st])
    exist_in_sts = False
    for i in range(len(sts)):
        if (new_st == sts[i]):
            nums[i] += 1
            exist_in_sts = True
    if exist_in_sts == False:
        sts.append(new_st)
        nums.append(1)

print(sum([int(x * (x - 1) / 2) for x in nums]))

Submission status: Time Limit Exceeded

Solution code:


import math
import itertools


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))

def is_anagram(s_1, s_2):
    for c in set(s_1):
        char_count_1 = s_1.count(c)
        char_count_2 = s_2.count(c)
        if char_count_1 != char_count_2:
            return False

    return True





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



s_list = list(itertools.combinations(S, 2))



ans = 0
for s_l in s_list:
    s_1 = s_l[0]
    s_2 = s_l[1]

    if is_anagram(s_1, s_2) == True:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N=int(input())
L=[]

for i in range(N):
  L.append(sorted(str(input())))

K=[]
C=[]

for j in range(N):
  if L[j] not in K:
    K.append(L[j])
    C.append(1)
  else:
    C[K.index(L[j])]+=1

A=0
for k in range(len(K)):
  if C[k]>1:
    if C[k]==2:
      A+=1
    else:
      A+=math.factorial(C[k])/(2*math.factorial(C[k]-2))

print(int(A))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [[c for c in input()] for i in range(N)]
for i in range(len(S)):
    S[i].sort()
    S[i] = str(S[i])
wa = 0
for i in range(len(S)):
    for j in range(i+1,len(S)):
        if S[i] == S[j]:
            wa +=1
print(wa)

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8

N = int(input())


s_list = []
for i in range(N):
    input_string = input()
    tmp_list = []
    for s in input_string:
        tmp_list.append(s)
    tmp_list.sort()
    sorted_string = ""
    for s in tmp_list:
        sorted_string = sorted_string + s
    s_list.append(sorted_string)


count = 0
s_list.sort()
while len(s_list) != 0:
    for i in range(1, len(s_list)):
        if s_list[0] == s_list[i]:
            count = count + 1
        else:
            break

    del(s_list[0])
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

arr = []
for i in range(N):
    arr.append(str(input()))

count = 0

def sort_str(s):
    return "".join(sorted(list(s)))

for i, item in enumerate(arr):
    s = sort_str(item)
    for j in range(i+1, N):
        if sort_str(arr[j]) == s:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
Count = int(input())
StringArray = []
for i in range(Count):
  tmp = input()
  tmp = sorted(tmp)
  Str = ""
  for i in tmp:
    Str += i
  StringArray.append(Str)
arraytmp = []
ans = 0
for i, Str in enumerate(StringArray):
    for j in range(i + 1, len(StringArray)):
      if StringArray[i] == StringArray[j]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from collections import deque
import math

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

N = int(input())
que = deque()
for _ in range(N):
    s = input()
    que.append(Counter(s))

ans = 0
while len(que):
    c1 = que.pop()
    num = 0
    for c2 in list(que):
       if c1 == c2:
            num += 1
            que.remove(c2)
    if num > 0:
        ans += combination(num+1, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())

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)

sn = []
count = 0

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


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

Submission status: Time Limit Exceeded

Solution code:
import collections
n=int(input())
s=[input() for i in range(n)]
t=[0]*n
for i in range(n):
    t[i]=collections.Counter(s[i])
ans=0
result=0
for i in range(n):
    for j in range(i+1,n):
        if(t[i]==0):
            continue
        if(t[i]==t[j]):
            result+=1
            t[j]=0
    ans+=result*(result+1)/2
    result=0
print(int(ans))

Submission status: Time Limit Exceeded

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

counter     =   0

for i in range(N):
    S   =   sorted(input())
    for j in range(len(A)):
        if(A[j] == S):
            counter += 1
            continue
    A.append(S)

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for _ in range(n)]
S = [0]*(n+1)
count = 0
for i in range(n):
    S[i] = "".join(sorted(s[i]))
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 collections
n = int(input())

s = []
C = []
for i in range(n):                                                                                                                                                                                          
    a = input()                                                                                                                                                                                             
    b = str(a)                                                                                                                                                                                              
    d = sorted(b)                                                                                                                                                                                           
    s.append(d)                                                                                                                                                                                             
    # c = collections.Counter(s[i])                                                                                                                                                                         
    # C.append(c)                                                                                                                                                                                           

count = 0
for j in range(n-1):                                                                                                                                                                                        
    for k in range(j+1, n):                                                                                                                                                                                 
        # if C[j].items() == C[k].items():                                                                                                                                                                  
        if s[j] == s[k]:                                                                                                                                                                                    
            count += 1                                                                                                                                                                                      

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
sl=list([input() for i in range(n)])
def sort_str(s):
    cl = list(s)
    cl.sort()
    return ''.join(cl)
sum=0
al=['']*n
for i in range(n):
    al[i] = sort_str(sl[i])
    for j in range(i+1,n):
        if al[j]=='':
            al[j] = sort_str(sl[j])
        if al[i]==al[j]:
            sum+=1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
cnt = int(input())
lst = []
counter = 0
for i in range(cnt):
    a = list(input())
    lst.append(a)

for j in range(len(lst)):
    for k in range(j+1, len(lst)):
        if sorted(lst[j]) == sorted(lst[k]):
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
while len(s)>0:
    a = s.count(s[0])
    if a==1:
        continue
    else:
        a = (a*(a-1))/2
        t = t+a
    s.remove(s[0])
print(t)

Submission status: Time Limit Exceeded

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

str_dict = [0]*(n)

for i in range(n):
    str_dict[i] = collections.Counter(strs[i])

ans = 0

for i in range(n):
    for j in range(n):
        if str_dict[i] == str_dict[j] and i != j:
            ans += 1

print(int(ans/2))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

def counts(word):
  a=word.count('a')
  b=word.count('b')
  c=word.count('c')
  d=word.count('d')
  e=word.count('e')
  f=word.count('f')
  g=word.count('g')
  h=word.count('h')
  i=word.count('i')
  j=word.count('j')
  k=word.count('k')
  l=word.count('l')
  m=word.count('m')
  n=word.count('n')
  o=word.count('o')
  p=word.count('p')
  q=word.count('q')
  r=word.count('r')
  s=word.count('s')
  t=word.count('t')
  u=word.count('u')
  v=word.count('v')
  w=word.count('w')
  x=word.count('x')
  y=word.count('y')
  z=word.count('z')
  lst=[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]
  
  return lst

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

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

print(match)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

print(cnt)

Submission status: Time Limit Exceeded

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


c=0
for i in range(N):
    for j in range(N-i-1):
        if s[i]==s[j+i+1]:
            c+=1
print(c)

Submission status: Time Limit Exceeded

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

def anagram(sa,sb) :
  flag=True
  sal=list(sa)
  sbl=list(sb)
  for st in sal :
    if st in sbl :
      sbl.remove(st)
    else :
      flag=False
      break
  if flag==False :
    return False
  else:
    return True
   
#print(anagram("peanutbomb","constraint"))    
count=0
for i in range(n) :
  for j in range(n) :
    if i>= j :
      continue
    if anagram(strl[i],strl[j]) ==True :
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = [input() for i in range(N)]
a = []*N
for i in A:
    b = list(i)
    b.sort()
    a.append(b)

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

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
sorted_lists = []
count_list = []

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

for i in range(N):
    inserted_flag = True
    input_sorted = sorted(input()) 
    for i in range(len(sorted_lists)): 
        if input_sorted == sorted_lists[i]:
            count_list[i] = count_list[i] + 1
            inserted_flag = False
    if inserted_flag:
        sorted_lists.append(input_sorted)
        count_list.append(1)

count = 0
for count_num in count_list:
    if count_num == 1:
        continue
    count = count + combinations_count(count_num, 2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
def fun(x):
    ret = 1
    while x:
        ret *= x
        x -= 1
    return ret

def cmb(n,r):
    if n==r: return 1
    else: return fun(n) // (fun(r)*fun(n-r))

n = int(input())
ss = [sorted(input()) for i in range(n)]
ss.sort()

tmp = ss[0]
sss = [0]*n
j = 0
for i in range(n):
    if tmp == ss[i]: sss[j]+=1
    else:
        tmp = ss[i]
        j += 1
        sss[j]+=1

ans = 0
for i in sss:
    if i>1: ans += cmb(i,2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
A = [input() for i in range(N)]
def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)
 
ans=0
for i in range(N):
    for j in range(i+1,N):
        if verify_anagrams(A[i],A[j]):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())

s = []
for i in range(N):
    c = Counter(input())
    s.append(sorted(list(c.items()))) 

result = 0
for elm in s:
    result += s.count(elm) - 1

print(int(result/2))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_list = []
a = 0
str1 = ""
str2 = ""

for i in range(N):
    a_list.append(input())

for k in range(N):
    str1 = "".join(sorted(a_list[k]))
    for l in range(k + 1, N):
        str2 = "".join(sorted(a_list[l]))
        if str1 == str2:
            a += 1

print(a)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

cnt = 0
words = []
for word_cnt in Counter(s).values():
    cnt += word_cnt*(word_cnt-1)//2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())

s = [[] for _ in range(N)]
check = []
ans = []
for x in range(N):
    for c in input():
        s[x].append(c)

for x in s:
    check.append(Counter(x))

for x in range(N):
    for y in range(x+1,N):
        ans.append(dict(check[x])==dict(check[y]))


print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

S=[list(input()) for _ in range(N)]

dic=[]

for i,s in enumerate(S):
    dic.append({})
    for x in s:
        try:
            dic[i][x]=+dic[i][x]+1
        except:
            dic[i][x]=1
    #dic[i].sort()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as counter

N = int(input())
char_counts = [counter(input()) for i in range(N)]
match_count = 0
for i, c in enumerate(char_counts):
  for j in range(i+1, N, 1):
    if char_counts[j] == c:
      match_count += 1
print(match_count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import json
N = int(input())
c = []

for _ in range(N):
    s = input()
    d = dict(Counter(s))
    ds = sorted(d.items(), key=lambda x:x[0])
    c.append(json.dumps(ds))

res = [c.count(e) for e in set(c) if c.count(e) > 1]

sum = 0
for i in res:
    sum += (i*(i-1)//2)


print(sum)

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])))
while len(sdic) > 0:
    now = sdic[0]
    cnt = sdic.count(now)
    ans += int((cnt * (cnt - 1)) / 2)
    for i in range(cnt):
        sdic.remove(now)
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

for i in range(n):
	for j in range(n):
		if i != j:
			if q[i] == q[j]:
				c += 1

print(int(c/2))

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    for j in range(i + 1, n):
        dic1 = {}
        dic2 = {}
        for k in range(10):
            
            if s[i][k] in dic1:
                dic1[s[i][k]] += 1
            else:
                dic1[s[i][k]] = 1
            if s[j][k] in dic2:
                dic2[s[j][k]] += 1
            else:
                dic2[s[j][k]] = 1
        
        if dic1 == dic2:
            #print(dic1, dic2)
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [''.join(sorted(input())) for _ in range(0, N)]
result = 0
for i, s in enumerate(S):
    for j in range(i + 1, len(S)):
        if s == S[j]:
            result += 1
print(result)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
  base = s[i]
  num = sum([base==j for j in s[i+1:]])
  count += num
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
p = [r for r in sys.stdin.read().split('\n') if r != '']
n = int(p[0])
s = p[1:]
for i, r in enumerate(s):
    s[i] = ''.join(sorted((c for c in r)))
total = 0
while len(s):
    a = s.pop(-1)
    count = 0
    for i in reversed(range(0, len(s))):
        if s[i] == a:
            count += 1
            s.pop(i)
    total += int((count + 1) * count / 2)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
a = ["".join(sorted(list(reversed(input())))) for i in range(n)]
uni_a = list(set(a))
eles = []
for i in range(len(uni_a)):
	eles.append(a.count(uni_a[i]))
cnt = 0
for i in range(len(eles)):
	if eles[i] != 1:
		cnt += eles[i]*(eles[i]-1) / 2
print(int(cnt))

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
para = [input() for i in range(N)]
def check(a,b):
    p = []
    q = []
    for i in range(10):
        if a[i] == b[i] :
            continue
        else :
            p.append(a[i])
            q.append(b[i])
    p.sort()
    q.sort()
    if p == q :
        return True 
            
a = 0 
for i in range(N):
    for j in range(i+1,N):
        if check(para[i],para[j]):
            a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
ll = [Counter(input()) for _ in range(n)]
c = 0
for i, s in enumerate(ll):
    c += len([j for j in range(i + 1, n) if s == ll[j]])
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = ["".join(sorted([c for c in input()])) for i in range(N)]
l.sort()


def fac(n):
    """階乗"""
    res = 0
    for i in range(1, n+1):
        res += i
    return res

hash_t = {}
for i in range(N-1):
    if l[i] == l[i+1]:
        if l[i] in hash_t.keys():
            hash_t[l[i]] += 1
        else:
            hash_t[l[i]] = 1

cnt = 0
for x in hash_t.values():
    cnt += fac(x)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools

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)
lst =[]
N = int(input())
for i in range(N):
    s = input() 
    lst.append(s)
c=0
word_lst = list(itertools.combinations(lst, 2))
for w1, w2 in word_lst:
    flg = verify_anagrams(w1, w2)
    if flg == True:
            c += 1
print(c)

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)
 
    return get_counter(first_word) == get_counter(second_word)

N = int(input())
words = [input() for _ in range(N)]
ans = 0
while True:
    if not words:
        break
    target = words.pop(0)
    same_word_index = []
    loop_sum = 0
    for i, word in enumerate(words):
        if verify_anagrams(target, word):
            same_word_index.append(i)
            loop_sum += 1
    # 同じやつをリストから消す
    if same_word_index:
        for index in reversed(same_word_index):
            words.pop(index)
    # 合計に加算
    ans += int((loop_sum * (loop_sum+1)) / 2)
    
    # 後ろからも
    if not words:
        break
    target = words.pop()
    same_word_index = []
    loop_sum = 0
    for i, word in enumerate(words):
        if verify_anagrams(target, word):
            same_word_index.append(i)
            loop_sum += 1
    # 同じやつをリストから消す
    if same_word_index:
        for index in reversed(same_word_index):
            words.pop(index)
    # 合計に加算
    ans += int((loop_sum * (loop_sum+1)) / 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
al='abcdefghijklmnopqrstuvwxyz'
nums=[]
N=int(input())
s=[]
an=0
for i in range(N):
    s.append([x for x in input()])
    s[i].sort()
for i in range(N):
    for n in range(i+1,N):
        if s[i]==s[n]:
            an+=1
print(an)

Submission status: Time Limit Exceeded

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

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

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

print(int(ans/2))

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):
    a = list((S[i]))
    b = list((S[j]))
    
    for k in range(10):
      if a[k] in b:
        b.remove(a[k])
      else:
        break
    else:
      cnt += 1
print (cnt)

Submission status: Time Limit Exceeded

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