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())
A = [0] * N
for i in range(N):
  A_temp = input()
  A[i]= sorted([c for c in A_temp])
count = 0

B = sorted(A)
A_unique_count = 1
for i in range(N-1):
  if B[i] != B[i+1]:
    A_unique_count += 1
#print(A_unique_count)
C = 0    
num = 0

#print(B)

for i in range(A_unique_count):
#  print( 'i' + str(i))
  C = B.count(B[num])
  num += C
#  print(num)
#  print(C)
  count += C * (C -1 ) / 2

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s  = [input() for i in range(N)]
mp = [{} for i in range(N)]

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
  A_temp = input()
  A[i]= sorted([c for c in A_temp])
B = sorted(A)
count = 0

for i in range(N-1):
  for j in range(i+1, N):
    if B[i] != B[j]:
      continue
    else:
      count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
  A_temp = input()
  A[i]= sorted([c for c in A_temp])
B = sorted(A)
#print(B)
count = 0

for i in range(N-1):
  for j in range(i+1, N):
#    print(str(i) + '&'+ str(j))
#    print(B[i])
#    print(B[j])
    if B[i] == B[j]:
      count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for _ in range(n)]
ss = [''.join(sorted(s_tmp)) for s_tmp in s]
count = 0
for i in range(n-1):
    k = 1
    while i+k <= n-1:
        if ss[i] == ss[i+k]:
            count += 1
        k += 1
print(count)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(0,n):
  for j in range(i+1,n):
    flag=True
    for k in range(10):
      if ss[i].count(ss[i][k])!=ss[j].count(ss[i][k]):
        flag=False
    if flag:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(list(input()))
    s[i].sort()
sa = []
for i in range(n):
    s[i].sort()
    tmp = ''
    for j in range(10):
        tmp += s[i][j]
    sa.append(tmp)
count = 0
for i in range(n-1):
    k = 1
    while i+k <= n-1:
        if sa[i] == sa[i+k]:
            count += 1
        k += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

sorted_strings = [''.join(sorted(s)) for s in strings]

num_anagram = 0
for i, j in combinations(sorted_strings, 2):
  if i == j:
    num_anagram += 1

print(num_anagram)

Submission status: Time Limit Exceeded

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

for i in range(n):
  for j in range(n):
    if  i != j and i < j and s[i] == s[j] :
      cnt = cnt + 1
      
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

str_list = []
for i in range(N):
    str_list.append(input())   
memo_list = []

def is_annagram(index1, index2):
    for memo in memo_list:
        if index1 in memo and index2 in memo:
            return True

    s1 = str_list[index1]
    s2 = str_list[index2]
    
    if isinstance(s1, int):
        if isinstance(s2, int):
            return s1 == s2
        else:
            return False
    elif isinstance(s2, int):
        return False

    for s in s1:
        if s not in s2:
            return False
        else:
            s2 = s2.replace(s, "", 1)

    str_list[index2] = index1

    return True

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

str_list = []
for i in range(N):
    str_list.append(input())   
memo_list = []

def is_annagram(index1, index2):
    for memo in memo_list:
        if index1 in memo and index2 in memo:
            return True

    s1 = str_list[index1]
    s2 = str_list[index2]
    for s in s1:
        if s not in s2:
            return False
        else:
            s2 = s2.replace(s, "", 1)

    isMemoUpdate = False
    for memo in memo_list:
        if index1 in memo:
            memo.append(index2)
            isMemoUpdate = True
    if not isMemoUpdate:
        memo_list.append([index1, index2])

    return True

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ss = sorted(ss)

res = 0
for i in range(len(ss)-1):
    for j in range(i+1, len(ss)):
        if ss[i] == ss[j]:
            res += 1
        else:
            break

print(res)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = []
c = {}
strings = ''
ans = 0

for i in range(a):
    check = True
    strings = ''.join(sorted(list(input())))
    if strings not in b:
      check = False
      b.append(strings)
      c[strings] = 1
    if check == True:
      ans += c[strings]
      c[strings] += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = []
c = []
strings = ''
ans = 0

for i in range(a):
    check = True
    strings = sorted(list(input()))
    if strings not in b:
      check = False
      b.append(strings)
      c.append(1)
    if check == True:
      for j in range(len(b)):
          if b[j] == strings:
              ans += c[j]
              c[j] += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

a = int(input())
b = []
for _ in range(a):
  b.append(list(input()))

ans = 0
for i in range(a):
  for j in range(i+1, a):
    check = True
    if collections.Counter(b[i]) != collections.Counter(b[j]):
      check = False
    if check == True:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = []
for _ in range(a):
  b.append(sorted(list(input())))

ans = 0
for i in range(a):
  for j in range(i+1, a):
    check = True
    if b[i] != b[j]:
      check = False
    if check == True:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = []
for _ in range(a):
  b.append(sorted(list(input())))

ans = 0
for i in range(a):
  for j in range(i+1, a):
    check = True
    for k in range(10):
      if b[i] != b[j]:
        check = False
        break
    if check == True:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = []
for _ in range(a):
  b.append(sorted(list(input())))

ans = 0
for i in range(a):
  for j in range(i+1, a):
    check = True
    for k in range(10):
      if b[i] != b[j]:
        check = False
    if check == True:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n=int(input())
l=[]
i=0
for _ in range(0, n):
  s=input()
  c=collections.Counter(s)
  i+=l.count(c)
  l.append(c)
print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
ans = 0
i=0
for n in range(N):
    S=input()
    tmp=list(S)
    tmp.sort()
    s.append("".join(tmp))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
count = 0
set_s = list(set(s))
for i in range(len(set_s)):
    s_count = s.count(set_s[i])
    count += s_count * (s_count - 1) // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
n = int(input())
s = []
count = 0
for _ in range(n):
    s.append(sorted(input()))
    s[_] = ''.join(s[_])
set_s = list(set(s))
for i in range(len(set_s)):
    s_count = s.count(set_s[i])
    count += s_count * (s_count - 1) // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
n = int(input())
s = []
count = 0
for _ in range(n):
    s.append(sorted(input()))
    s[_] = ''.join(s[_]).rstrip('\n')
set_s = set(s)
for i in range(len(set_s)):
    s_count = s.count(list(set_s)[i])
    count += s_count * (s_count - 1) // 2
print(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] = sorted(S[i])
S = sorted(S)
c = 0
for i in range(n - 1):
  j = i + 1
  while S[i] == S[j] and j < n:
    c += 1
    j += 1
    if j == n:
      break
print(c)

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-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())
S = [input() for i in range(n)]
for i in range(n):
  S[i] = sorted(S[i])
c = 0
for i in range(n):
  for j in range(i+1,n):
    if S[i] == S[j]:
      c += 1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

duplicate_ct = 0
count_list = []
for i in range(N):
  sorted_input = ''.join(sorted(input()))
  count_list.append(sorted_input)

for i in range(N):
  slice_position = i + 1
  count = count_list[slice_position:].count(count_list[i])
  duplicate_ct += count

print(duplicate_ct)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
s = [None]*n
ans = 0
for i in range(n):
    c = collections.Counter(s)
    tmp = str(sorted(input()))
    ans += c[tmp]
    s[i] = tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
ans = 0
for _ in range(n):
    tmp = sorted(input())
    ans += s.count(tmp)
    s.append(tmp)
print(ans)

Submission status: Time Limit Exceeded

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

s = sorted(s)
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:
n = int(input())
s = []
count = 0
for i in range(n):
    s.append(sorted(input()))
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 solve(l:list):
    ans = 0
    for i in range(len(l)):
        for j in range(i):
            if l[i] == l[j]:
                ans += 1
    return ans

def main():
    n = int(input())
    l = [sorted(input()) for _ in range(n)]
    print(solve(l))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
x=[]
for i in range(N):
    a={}
    for s in input():
        if s in list(a.keys()):
            a[s]+=1
        else:
            a[s]=1
    x.append(a)
an=0
for i in range(N):
    for s in range(i+1,N):
        if x[i]==x[s]:
            an+=1
print(an)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list_s = [''.join(sorted(input())) for _ in range(n)]
res = 0
for i in range(n):
    for j in range(i + 1, n):
        if list_s[i] == list_s[j]:
            res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
l=[]
for i in range(N):
  l.append(sorted(input()))
ans=0
for a in range(N):
  for b in range(a+1,N):
    if l[a]==l[b]:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for x in range(n)]
length = 10
count = 0

for i in range(n):
    s1 = list(s[i])
    s1.sort()
    for j in range(i+1,n):
        flag = True
        s2 = list(s[j])
        s2.sort()
        for k in range(length):
            if (s1[k] == s2[k]):
                continue
            else:
                flag = False
                break
        if (flag):
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
string = [input() for i in range(n)]
string2 = [''.join(sorted(x)) for x in string]
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        if string2[i] == string2[j]:
            count += 1

print(count)
#print(string2)

Submission status: Time Limit Exceeded

Solution code:
# B - One Clue
def main():
    count = int(input())
    data = []
    for i in range(count):
        data.append(''.join(sorted(str(input()))))

    my_dict = {i: data.count(i) for i in data}
    print(sum([sum(range(l)) for l in list(my_dict.values())]))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s = [ str(input()) for _ in range(n)]
s = [sorted(x) for x in s]
pairs =[]
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            pairs.append(tuple([i,j]))
print(len(pairs))

Submission status: Time Limit Exceeded

Solution code:
def count_the_character(string,character):
    count = 0
    for e in list(string):
        if e == character:
            count += 1
        else:pass
    return count
    
def return_if_the_lists_same(lst1,lst2):
    for a in range(26):
        if lst1[a] == lst2[a]:
            pass
        else:return False
        
    return True
    
n = int(input())
lst = [0 for i in range(n)]
lst_of_count = [[0 for i in range(26)] for i in range(n)]
alphabets = list("abcdefghijklmnopqrstuvwxyz")
for i in range(n):
    lst[i] = input()
    
    for a in range(26):
        lst_of_count[i][a] = count_the_character(lst[i],alphabets[a])
        
        

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

Submission status: Time Limit Exceeded

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

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

counter=0
for i in range(len(S)):
    S[i]=list(S[i])
    S[i].sort()
    
for i in range(N):
    for j in range(i + 1, N):
        if S[i]==S[j]:
            counter=counter+1
   
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
count = 0
S = []
for i in range(N):
    S.append([s for s in input()])
for v in itertools.combinations(S, 2):
    v[0].sort()
    v[1].sort()
    if v[0] == v[1]:
        count += 1
if count == 1:
    print(1)
else:
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

print(sum(s1 == s2 for s1, s2 in itertools.combinations(S, 2)))

Submission status: Time Limit Exceeded

Solution code:
def cmp(A,B):
    ans = True
    n = len(A)
    i = 0
    while i < n:
        if A[i] == B[i]:
            i += 1
        else:
            ans = False
            break
    return ans

N = int(input())
L = []
i = 0
while i < N:
    tmp = input()
    L.append(sorted(tmp))
    i += 1

cnt = 0
i = 0

while i < N-1:
    j = i+1
    while j < N:
        if cmp(L[i],L[j]):
            cnt += 1
        j += 1
    i += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = []
i = 0
while i < N:
    tmp = input()
    L.append(sorted(tmp))
    i += 1

cnt = 0
i = 0

while i < N-1:
    j = i+1
    while j < N:
        if L[i] == L[j]:
            cnt += 1
        j += 1
    i += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations

N = int(input())
c = Counter(["".join(sorted(list(input()))) for i in range(N)])
res = 0
for k,i in c.most_common():
  if i == 1:
    break
  res += len(list(combinations([0 for n in range(i)],2)))

print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations

N = int(input())
c = Counter(["".join(sorted(list(input()))) for i in range(N)])
res = 0
for i in c.values():
  if i > 1:
    res += len(list(combinations([0 for n in range(i)],2)))

print(res)

Submission status: Time Limit Exceeded

Solution code:
import collections
import string

def s_to_hist(s):
    hist = collections.Counter()
    for c in s:
        hist[c] += 1
    hist_list = []
    for al in string.ascii_letters:
        hist_list.append(str(hist[al]))
    return " ".join(hist_list)

s_hist = collections.Counter()

N = int(input())
for n in range(N):
    s = input().strip()
    s_hist[s_to_hist(s)] += 1

ans = 0
for key in s_hist:
    ans += s_hist[key]*(s_hist[key]-1)/2
print(int(ans))

Submission status: Time Limit Exceeded

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

l = []
ans = 0
for s in S:
    st = "".join(sorted(list(s)))
    if st in l:
        ans += l.count(st)
    l.append(st)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def is_anagram(string1, string2):
  string1 = list(string1)
  string2 = list(string2)
  string1.sort()
  string2.sort()
  for i in range(len(string1)):
    if not string1[i] == string2[i]:
      return False
  return True

count = 0
N = int(input())
strings = [input() for _ in range(N)]

for string1_index in range(N):
  string1 = strings[string1_index]
  for delta_index in range(N - string1_index - 1):
    delta_index = delta_index + 1
    string2 = strings[string1_index + delta_index]
    if is_anagram(string1, string2):
      count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

anum = 0

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

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

for i in range(N):
    temp = [s for s in strings[i]]
    temp.sort()
    strings[i] = ''.join(temp)

for i in range(N-1):
    for j in range(i+1,N):
        if strings[i] == strings[j]:
            anum += 1

print(anum)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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


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:
import numpy as np

abcs = ["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"]
anum = 0

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

for i in range(N-1):
    for j in range(i+1,N):
        c1 = np.zeros(26)
        c2 = np.zeros(26)
        for k in range(26):
            for l in range(10):
                if abcs[k] == strings[i][l]:
                    c1[k] += 1
                if abcs[k] == strings[j][l]:
                    c2[k] += 1
        if sum(c1 == c2) == 26:
            anum +=1

print(anum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = []
count = {}
total = 0

for i in range(n):
    x.append(sorted(list(input())))
    count[str(x[i])] = x.count(x[i])
for x in count.values():
    total += (x * (x - 1)) / 2
print(int(total))

Submission status: Time Limit Exceeded

Solution code:
import json

n = int(input())
x = []
count = {}
total = 0

for i in range(n):
    x.append(sorted(list(input())))
    count[str(x[i])] = x.count(x[i])
for x in count.values():
    total += (x * (x - 1)) / 2
print(int(total))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
dic = [Counter(input()) for i in range(n)]
cnt=0
for i in range(n):
  for j in range(i+1, n):
    if dic[i]==dic[j]:
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools
N, *s = open(0).read().split()
s_sorted = [''.join(sorted(c)) for c in s]
c = collections.Counter(s_sorted)
res = list(set(s_sorted))
count = 0
for s in res:
  if c[s] > 2:
    count += len(list(itertools.combinations(range(c[s]), 2)))
  elif c[s] == 2:
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
data=[collections.Counter(list(input())) for i in range(int(input()))]
count=0
for i in range(len(data)):
    for m in range(i+1,len(data)):
        count+=data[i]==data[m]
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
used_s = {}
for _ in range(n):
    s = tuple(sorted(input()))
    if not s in used_s.keys():
        used_s[s] = 0
    else:
        used_s[s] += 1
        ans += 1 * used_s[s]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
used_s = {}
for _ in range(n):
    s = "".join(sorted(input()))
    if not s in used_s.keys():
        used_s[s] = 0
    else:
        used_s[s] += 1
        ans += 1 * used_s[s]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
set_s = set(s)
seq_s = "".join(s)
ans = 0
start_i = 0
used_s = {}
for i in range(n):
    cnt = used_s.get(s[i],seq_s.count(s[i],start_i) if s[i] in set_s else 0)
    ans += cnt - 1
    used_s[s[i]] = cnt - 1
    start_i += len(s[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
set_s = set(s)
seq_s = "".join(s)
ans = 0
start_i = 0
used_s = {}
for i in range(n):
    cnt = used_s.get(s[i],seq_s.count(s[i],start_i) if s[i] in set(s) else 0)
    ans += cnt - 1
    used_s[s[i]] = cnt - 1
    start_i += len(s[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
seq_s = "".join(s)
ans = 0
start_i = 0
used_s = {}
for i in range(n):
    cnt = used_s.get(s[i],seq_s.count(s[i],start_i))
    ans += cnt - 1
    used_s[s[i]] = cnt - 1
    start_i += len(s[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
seq_s = "".join(s)
ans = 0
start_i = 0
for i in range(n):
    cnt = seq_s.count(s[i],start_i)
    ans += cnt - 1
    start_i += len(s[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 整数の入力
N = int(input())
# 改行区切りの整数の入力
S = []
for k in range(N):
  S.append(sorted(tuple(input())))
# 初期値
count = 0
St = list(map(tuple,S))
SS = list(set(St))
SS = list(map(list,SS))
# 繰り返し
for i in range(len(SS)):
  j = int(S.count(SS[i]))
  n = j*(j-1)/2
  count += n
# 出力
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
P = []
ans = 0
for _ in range(N):
    s = input()
    c = Counter(s)
    for p in P:
        if p == c:
            ans += 1
    P.append(c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [sorted(input()) for _ in range(n)]
ans = 0
for i in range(n):
    for 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 k in range(N):
  S.append(input())
#初期値
n = 0
#繰り返し
for i in range(len(S)):
    for j in range(1,len(S)-i):
        if sorted(list(S[i])) == sorted(list(S[j+i])):
          n += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
# 整数の入力
N = int(input())
# 改行区切りの整数の入力
S = []
for k in range(N):
  S.append(input())
#初期値
n = 0
#繰り返し
for i in range(len(S)):
  for j in range(len(S)):
    if i < j:
      if sorted(list(S[i])) == sorted(list(S[j])):
        n += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import copy

N = int(input())


ss = list()

base = dict([[chr(ord('a') + i),  0] for i in range(26)])
for k in range(N):
    a = copy.copy(base)
    s = input()
    for c in s:
        a[c] += 1

    ss.append(a)

res = 0
for i in range(N-1):
    for j in range(i+1, N):
        flag = True
        for k in range(26):
            c = chr(ord('a')+k)
            if ss[i][c] != ss[j][c]:
                flag = False
                break
        if flag:
            res += 1


print(res)

Submission status: Time Limit Exceeded

Solution code:
count = 0
lo = int(input())
N = [input() for i in range(lo)]
for i in range(lo):
    for j in range(i + 1, lo):
        tmp = N[j]
        for k in range(10):
            tmp = tmp.replace(N[i][k], "", 1)
        if tmp == "":
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(0,n):
    c = c + s.count(s[i]) - 1
print(c//2)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[''.join(sorted(input())) for i in range(N)]
B=list(map(A.count,set(A)))

ans=0
for b in B:
    if b==2:ans+=1
    else:ans+=b*(b-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations
n = int(input())
s = []
for _ in range(n):
  s.append(input())
 
ilist = []
for a in range(len(s)):
  ilist.append(list(s[a]))
 
for ss in range(len(ilist)):
  ilist[ss].sort()
 
li = list(combinations(ilist, 2))
ans = 0
 
for b in range(len(li)):
  if(li[b][0] == li[b][1]):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
slist = [Counter(list(input())) for _ in range(N)]
counter = 0
for j in range(N):
    js = slist[j]
    for i in range(j):
        if js==slist[i]:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
slist = [Counter(list(input())) for _ in range(N)]
counter = 0
for j in range(N):
    for i in range(j):
        if slist[j]==slist[i]:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
lists=[]
count=0

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

for i in range(N-1):
    j=lists.pop(0)
    
    count +=lists.count(j)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N =int(input())
s = sorted(sorted(input()) for i in range(N))
cnt = 0
i = 0
while i <= N-1:
    grnm=(s[i+1:]).count(s[i])
    if grnm == 0:
        i+=1
    else:
        cnt += int(grnm*(grnm+1)/2)
        i+=(grnm+1)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N =int(input())
s = sorted((sorted(input()) for i in range(N)))
cnt = 0
for i in range(N):
    cnt+=(s[i+1:]).count(s[i])
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for _ in range(N):
    s.append(input())
s

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

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

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N =int(input())
s = list(sorted(input()) for i in range(N))
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())
s = list(sorted(input()) for i in range(N))
cnt = 0
for i in range(N):
    for j in range(N):
        if s[i]==s[j]:
            cnt+=1
print(int((cnt-N)/2))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
lst = []
cnt = 0
for i in range(N):
    s = str(input())
    lst.append(sorted(s))
ans = itertools.combinations(lst, 2)
for j in ans:
    if j[0] == j[1]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
str_list = list()
for _ in range(n):
  tar_str = input()
  str_list.append(sorted(list(tar_str)))

count = 0
for j in range(len(str_list)):
  t_list = str_list.pop()
  for k in str_list:
    if t_list == k:
      count += 1
print(count)