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

for i in range(N):
  for j in range(N):
    if i >= j:
        pass
    elif s[i] == s[j]:
      ans += 1
    else:
      break

print(int((ans)))

Submission status: Time Limit Exceeded

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

    return (s, n)
(s, n) = read()

for i in range(n):
    s[i].sort()

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

print(count)

Submission status: Time Limit Exceeded

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

    return (s, n)

(s, n) = read()

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

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

print(count)

Submission status: Time Limit Exceeded

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

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

print(int((ans-N)/2))

Submission status: Time Limit Exceeded

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

for i in range(N):
  for j in range(N):
    if i < j:
      if s[i] == s[j]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
  for j in range(N):
    if i < j and s[i] == s[j]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
  for j in range(N):
    if i >= j:
      pass
    else:
      if s[i] == s[j]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as comb
from collections import Counter as counter
 
li = []
match = 0
n = int(input())
 
for i in range(n):
  li.append(dict(counter(list(input()))))

for a, b in comb(li, 2):
  if a==b:
    match += 1
    
print(match)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as comb
from collections import Counter as counter

li = []
match = 0
n = int(input())

for i in range(n):
  li.append(list(input()))
  
for a, b in comb(li, 2):
  if counter(a) == counter(b):
    match += 1
    
print(match)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

result_num = 0
words = [''.join(sorted(str(input())))]
count_dict = {}
count_dict[words[0]] = 1

for i in range(n-1):
  word = ''.join(sorted(str(input())))

  if word in words:
    result_num += count_dict[word]
    count_dict[word] += 1
  else:
    words.append(word)
    count_dict[word] = 1

print(result_num)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
words = []
for i in range(N):
    words.append(input())
w_s = []
for w in words:
    w1 = list(w)
    w1.sort()
    l = " ".join(w1)
    w_s += [l]
n_l = []
for i in list(set(w_s)):
    n = w_s.count(i)
    n_l += [n]
n_c_p = [a for a in n_l if a > 1]
n_c_n = [a for a in n_l if a == 1]
n_c_p1 = [math.factorial(p)/(2*math.factorial(p-2)) for p in n_c_p]
print(int(sum(n_c_p1)))

Submission status: Time Limit Exceeded

Solution code:
def to_dict(text):
    d = {}
    for c in text:
        d[c] = d.get(c, 0) + 1
    return d


n = int(input())
combination_count = 0
s = []
for _ in range(n):
    si = to_dict(input())
    combination_count += sum(1 for old_si in s if old_si == si)
    s.append(si)

print(combination_count)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
words = []
for i in range(N):
    words.append(input())
w_s = []
for w in words:
    w1 = w + "あ"
    w1 = list(w1)
    w1.sort()
    l = [0]
    k = ""
    for i in range(1,len(w1)):
        if w1[i] != w1[i-1]:
            l += [i]
            k += str(l[-1]-l[-2]) + w1[i-1]
    w_s += [k]
n_l = []
for i in list(set(w_s)):
    n = w_s.count(i)
    n_l += [n]
n_c_p = [a for a in n_l if a > 1]
n_c_p1 = [math.factorial(p)/(2*math.factorial(p-2)) for p in n_c_p]
print(int(sum(n_c_p1)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
combination_count = 0
s = []
for _ in range(n):
    si = sorted(input())
    combination_count += sum(1 for old_si in s if old_si == si)
    s.append(si)

print(combination_count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

result_num = 0
words = [sorted(str(input()))]
count_num = [1]

for i in range(n-1):
  word = sorted(str(input()))
  exist = 0
  
  for j, word_ in enumerate(words):
    if word == word_:
      result_num += count_num[j]
      count_num[j] += 1
      exist += 1
      
  if exist == 0:
    words.append(word)
    count_num.append(1)
  
print(result_num)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import Counter
N = int(input().strip())
seq_list = [''.join(sorted(input().strip())) for _ in range(N)]
hash = {}
for seq in seq_list:
  if seq[0] in hash:
    hash[seq[0]] += [seq]
  else:
    hash[seq[0]] = [seq]
result = 0
for s in hash.values():
  if len(s) < 2: continue
  result += len([1 for i,j in itertools.combinations(range(len(s)), 2) if s[i] == s[j]])
print(result)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
combination_count = 0
s = []
for _ in range(n):
    si = collections.Counter(input())
    combination_count += sum(1 for old_si in s if old_si == si)
    s.append(si)

print(combination_count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

result_num = 0
words = []
for i in range(n):
  word = sorted(str(input()))
  for word_ in words:
    if word == word_:
      result_num += 1
  words.append(word)
  
print(result_num)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import Counter
N = int(input().strip())
seq_list = [Counter(input().strip()) for _ in range(N)]
print(len([1 for i,j in itertools.combinations(range(N), 2) if seq_list[i] == seq_list[j]]))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input().strip())
seq_list = [''.join(sorted(input().strip())) for _ in range(N)]
print(len([1 for i,j in itertools.combinations(range(N), 2) if seq_list[i] == seq_list[j]]))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
l=[]
count=0
for i in range(n):
  b=list(input())
  b.sort()
  l.append(b)
for i in range(n):
  for j in range(i+1,n):
    if l[i]==l[j]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
l=[]
count=0
for i in range(n):
  b=input()
  l.append(Counter(b))
for i in range(n):
  for j in range(i+1,n):
    if l[i]==l[j]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
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
# array1 = np.zeros().reshape( n,10)


# list1 = []
list_s = []

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

list_s = list(map(sorted, list_s))



ans = sum(map(lambda y: (sum(map(lambda x: x==list_s[y],list_s)) -1),list(range(n))))
# for i in range(n):
#     ans = ans + sum(map(lambda x: x==list_s[i],list_s)) -1

print(int(ans/2))

Submission status: Time Limit Exceeded

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

mylist2 = list(set(mylist))

ans=0
for i in range(len(mylist2)):
    count = mylist.count(mylist2[i])
    ans+=int(count*(count-1)/2)

print(ans)

Submission status: Time Limit Exceeded

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

myset = set(mylist)
mylist2 = list(myset)

ans=0
for i in range(len(mylist2)):
    count = mylist.count(mylist2[i])
    mylist3 = list(range(count))
    ans += sum(mylist3)
    mylist.remove(mylist2[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n = int(input())
d = [defaultdict(int) for i in range(n)]
for i in range(n):
  for j in input():
    d[i][j] += 1
c = 0
for i in range(n):
  for j in range(i+1,n):
    if all(d[i][key] == d[j][key] for key in d[i]):
      c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import math
from itertools import accumulate
from collections import Counter
import itertools


N = int(input())

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


def is_anagrams(t1, t2):
    c1 = Counter(t1)
    c2 = Counter(t2)
    if sorted(c1.values()) == sorted(c2.values()) and sorted(c1.keys()) == sorted(c2.keys()):
        return 1
    else:
        return 0



count = 0
for t1, t2 in list(itertools.combinations(strings, 2)):
    count += is_anagrams(t1, t2)
print(count)

Submission status: Time Limit Exceeded

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

import os

n = int(input())
#k,x = map(int, input().split())
s = list([list(input()) for i in range(n)])

for i in s:
    i.sort()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as comb
n = int(input())
str_list = []
ans = 0
for i in range(n):
    str_list.append(sorted(input()))

comb_list = list(comb(str_list, 2))

for comb in comb_list:
    if comb[0] == comb[1]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

a = []
for l in sys.stdin:
    if l == '\n':
        break
    else :
        a.append(l)

target = a[int(a[0])]
num = 0
for i in range(1, len(a) - 1):
    for j in range(i + 1, len(a)):
        flag = False
        iStrSorted = ''.join(sorted(a[i]))
        jStrSorted = ''.join(sorted(a[j]))
        if iStrSorted==jStrSorted:
            flag = True
        else:
            flag = False
        if flag:
            num = num + 1
print(num)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n):
    for j in range(1, len(str_list)):
        if sorted(str_list[0]) == sorted((str_list[j])):
            ans += 1
    str_list.pop(0)
print(ans)

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])
l = [s[0]]
count = [1]
result = 0
for i in range(1,n):
    exis = False
    for j in range(len(l)):
        if s[i] == l[j]:
            result += count[j]
            count[j] += 1
            exis = True
    if exis == False:
        l.append(s[i])
        count.append(1)
    
print(result)

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])
count = 0
l = [s[0]]
for i in range(1,n):
    exis = False
    for j in range(len(l)):
        if s[i] == l[j]:
            count += 1
    l.append(s[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
#coding utf-8
N=int(input())

roma = [0 for i in range(N)]

for i in range(N):
  tmp=list(input().strip())
  tmp.sort()
  roma[i]=''.join(tmp)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
s.sort()
count = 0
num = 0
i = 0
while i < N-1:
    num = s.count(s[i])
    count += num * (num - 1) // 2
    i += num
print(count)

Submission status: Time Limit Exceeded

Solution code:
#coding utf-8
N=int(input())

roma = [[0 for i in range(26)] for j in range(N)]

for i in range(N):
  tmp=list(input().strip())
  for j in range(10):
    roma[i][ord(tmp[j])-97] +=1

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

Submission status: Time Limit Exceeded

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

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

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

print(counter)

Submission status: Time Limit Exceeded

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

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

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

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S=[]
for n in range(N):
    S.append(input())
Slist = []
for s in S:
    lists = list(s)
    listss = sorted(lists)
    Slist.append(listss)
def isAna2(Sl,sl):
    boolcount = True
    for i,Sli in enumerate(Sl):
        if Sli != sl[i]:
            boolcount = False
            break
    return boolcount
count = 0
for i,Sl in enumerate(Slist):
    for sl in Slist[i+1:]:
        if isAna2(Sl,sl) == True:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S=[]
for n in range(N):
    S.append(input())
def isAna(a,b):
    boolcount = True
    listb = list(b)
    for ai in list(a):
        if ai in listb:
            listb.remove(ai)
        else:
            boolcount = False
            break
    return boolcount
count = 0
for i,s in enumerate(S):
    for ss in S[i+1:]:
        if isAna(s,ss) == True:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
count = 0
s_set = list(set(s))
for i in range(len(s_set)):
    s_count = s.count(s_set[i])
    if s_count > 1:
        count += (s_count * (s_count - 1)) // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
word=[]
for i in range(N):
  word.append(input())
  
alphalist=[]
alpha=[[] for i in range(N)]
for i in range(N):
  word0=word[i]
  for v in range(10):
    alpha[i].append(word0[v])
  alpha[i].sort()
  alphalist.append(alpha[i])


number=0
for i in range(N):
  freq=alphalist.count(alphalist[i])
  if freq!=1:
    number0=(freq*(freq-1))/2
    number0=number0/freq
    number+=number0
  
print(int(number))

Submission status: Time Limit Exceeded

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

count = 0
s = [''.join(sorted(str(i))) for i in s]
s_set = list(set([x for x in s if s.count(x) > 1]))
for i in range(len(s_set)):
    s_count = s.count(s_set[i])
    count += (s_count * (s_count - 1)) // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
word=[]
for i in range(N):
  word.append(input())
  
alphalist=["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"]
numlist=[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]


numberlist=[]
for i in range(N):
  wordnum0=1
  word0=word[i]
  for v in range(10):
    for k in range(26):
      if word0[v]==alphalist[k] :
        wordnum0*=numlist[k]
        break
  numberlist.append(wordnum0)

number=0
for i in range(N):
  freq=numberlist.count(numberlist[i])
  if freq!=1:
    number0=(freq*(freq-1))/2
    number0=number0/freq
    number+=number0
  
print(int(number))

Submission status: Time Limit Exceeded

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

count = 0
s = [''.join(sorted(str(i))) for i in s]
s_set = list(set(s))
for i in range(len(s_set)):
    s_count = s.count(s_set[i])
    if s_count > 1:
        count += (s_count * (s_count - 1)) // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = ['']*N
 
for i in range(N):
  str = input()
  s[i] = ''.join(sorted(str))
 
s.sort()
ans = 0
for i in range(N):
  ans += s[i+1:].count(s[i])
  
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
s = [''.join(sorted(str(i))) for i in s]
s_set = list(set(s))
for i in range(len(s_set)):
    s_count = s.count(s_set[i])
    count += (s_count * (s_count - 1)) // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

a = []
for l in sys.stdin:
    if l == '\n':
        break
    else :
        a.append(l)

target = a[int(a[0])]
num = 0
for i in range(1, len(a) - 1):
    for j in range(i + 1, len(a)):
        flag = False
        for s in range(0, len(a[i]) - 1):
            if a[i].count(a[i][s]) == a[j].count(a[i][s]):
                flag = True
            else:
                flag = False
                break
        if flag:
            num = num + 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input().split() for i in range(N)]
count = 0

s = [''.join(sorted(str(i))) for i in s]
s_set = list(set(s))
for i in range(len(s_set)):
    count += sum(range(1, s.count(s_set[i])))
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input().split() for i in range(N)]
count = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input().split() for i in range(N)]
count = 0

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

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
s = [collections.Counter(input()) for _ in range(n)]
cnt = 0
for i in range(n):
    a = s[i]
    for b in s[i+1:]:
        if a == b:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
s = {}

for i in range(n):
  c = "{}".format(sorted(Counter(input()).most_common()))
  v = s.get(c, 0)
  s[c] = v + 1

result = 0

for v in s.values():
  result += v * (v-1) / 2

print(int(result))

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

result = 0

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import math

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

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

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

unique_s = set(s)

output = 0
for k in unique_s:
     if s.count(k) != 1:
        output += int(comb(s.count(k), 2))

print(output)

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    for j in range(i+1, N):
        a = sorted(s[i])
        b = sorted(s[j])
        for x in range(len(a)):
            if a[x] != b[x]:
                break
            elif x == len(a)-1:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s_list=[''.join(sorted(input())) for _ in range(n)]
c = 0
s_list_exist = []
for s in s_list:
  c_contain = s_list.count(s)
  if not s in s_list_exist and c_contain != 1:
    c += c_contain * (c_contain-1) // 2
    s_list_exist.append(s)
print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
s = [input() for i in range(N)]

c = []
ans = 0
for i in range(N):
    c.append(Counter(s[i]))

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
s = [input() for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        a = Counter(s[i])
        b = Counter(s[j])
        if a == b:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

#word = [list(input()) for i in range(N)] 
#print(word)
word2 = [''.join(sorted(list(input())))  for i in range(N)]
  

#print(word2)  
ans = Counter(word2)
ans_v = ans.values()
#print(ans_v)
#import numpy as np
#ans_np = np.array(list(ans_v))
#x = 0
from itertools import combinations
x =[ (len(list(combinations(list('a'*i),2)))) for i in ans_v]
  
  
print(sum(x))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = sorted(list(sorted([i for i in input()]) for j in range(n)))
count = 0
loop = 0
for k in range(n-1):
    for l in range(k+1, n):
        if lis[k] == lis[l]:
            count += 1
        else:
            pass
print(count)

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())

#word = [list(input()) for i in range(N)] 
#print(word)
word2 = []
for i in range(N):
  i = list(input())
  i.sort()
  i = ''.join(i)
  word2.append(i)

from collections import Counter
ans = Counter(word2)
ans_v = ans.values()
#print(ans)
#import numpy as np
#ans_np = np.array(list(ans_v))
x = 0
from itertools import combinations
for i in ans_v:
  x+=(len(list(combinations(list('a'*i),2))))
  
print(x)

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())

word = [input() for i in range(N)] 
#print(word)
word2 = []
for i in word:
  i = list(i)
  i.sort()
  i = ''.join(i)
  word2.append(i)

from collections import Counter
ans = Counter(word2)
ans_v = ans.values()
#print(ans)
#import numpy as np
#ans_np = np.array(list(ans_v))
x = 0
from itertools import combinations
for i in ans_v:
  x+=(len(list(combinations(list('a'*i),2))))
  
print(x)

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())

word = [input() for i in range(N)] 
#print(word)
word2 = []
for i in word:
  i = list(i)
  i.sort()
  i = ''.join(i)
  word2.append(i)

from collections import Counter
ans = Counter(word2)
ans_v = ans.values()
#print(ans)
import numpy as np
ans_np = np.array(list(ans_v))
x = []

from itertools import combinations
for i in ans_np:
  x.append(len(list(combinations(list('a'*i),2))))
  
print(sum(x))

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())

word = [input() for i in range(N)] 
#print(word)
word2 = []
for i in word:
  i = list(i)
  i.sort()
  word2.append(i)


counter = 0  
for i in word2:
  for j in word2:
     if i == j:
        counter += 1
      
print((counter-N)//2)

Submission status: Time Limit Exceeded

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

def solve():
    N = int(input())
    dicts = []
    for i in range(N):
        s = input()
        d = {}
        for moji in s:
            if not moji in d:
                d[moji] = 0
            d[moji] += 1
        dicts.append(d)

    ans = 0    
    done = set()
    for i in range(N):
        if i in done: continue
        d1 = dicts[i]
        ret = 0
        for j in range(i+1, N):
            d2 = dicts[j]
            if d1 == d2:
                done.add(j)
                ret += 1
        # ret + (ret-1) + ... + 1 を計算する
        ans += (ret+1)*ret/2 # 和の公式

    print(int(ans))



if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())

word = [input() for i in range(N)] 
#print(word)
word2 = []
for i in word:
  i = list(i)
  i.sort()
  word2.append(i)

  
counter = 0  
for i in word2:
  for j in range(word2.index(i)+1,N):
#    print('j:',j,i)
    try:
      if i == word2[j]:
#        print('yes')
        counter += 1
    except IndexError:
      continue
      #print(word2[j])
      
print(counter//2)

Submission status: Time Limit Exceeded

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

def solve():
    N = int(input())
    dicts = []
    for i in range(N):
        s = input()
        d = {}
        for moji in s:
            if not moji in d:
                d[moji] = 0
            d[moji] += 1
        dicts.append(d)

    ans = 0    
    for i in range(N):
        d1 = dicts[i]
        for j in range(i+1, N):
            d2 = dicts[j]
            ans += 1 if d1 == d2 else 0

    print(ans)



if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
number=int(input())
List = [input() for i in range(number)]
x=0
y=0
word=[]
answer=0
for f in range(number):
    a=(List[x])
    word.append(sorted(a))    
    x=x+1
for j in range(number):
    ans=0
    ams=()
    ams=word.pop(y)
    ans=word.count(ams)
    answer=answer+ans
    word.insert(y,ams)
    y=y+1
print(int(answer/2))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

if __name__ == "__main__":
    N = int(input())
    S = [0] * N
    analist = 0
    for i in range(N):
        S[i] = Counter(input())
    for i in range(N):
        keys = list(S[i].keys())

        for j in range(i+1,N):
            target = S[j]
            tgtkeys = list(target.keys())
            anaflg = 0
            if len(keys) == len(tgtkeys):
                for k in range(len(keys)): 
                    if target[tgtkeys[k]] != S[i][tgtkeys[k]]:
                        anaflg = 1
                        break
                if anaflg == 0:
                    analist += 1
            else:
                anaflg = 1
        anaflg = 0
    print(analist)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as ct
n = int(input())
ans = 0
words = [input() for _ in range(n)]
while words:
  mas = words.pop()
  count = 0
  for word in words:
    if ct(mas) == ct(word):
      count += 1
      words.remove(word)
  if count == 1:
    ans += count
  else:
    ans += count * (count + 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
number=int(input())
List = [input() for i in range(number)]
x=0
n=0
m=0
word=[]
b=[]
answer=0
for f in range(number):
    a=(List[x])
    word.append(sorted(a))    
    x=x+1
for j in range(number):
    for h in range(number):
        if word[n] == word[m]:
            answer=answer+1
        else:
            answer=answer+0
        m=m+1
    n=n+1 
    m=0
print(int((answer-number)/2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N):
  for j in range(N):
    if i >= j:
      pass
    else:
      count = 0
      for k in range(10):
        if sorted(list(s[i]))[k] == sorted(list(s[j]))[k]:
          count += 1
      if count == 10:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
  for j in range(N):
    if i == j:
      pass
    else:
      count = 0
      for k in range(10):
        if sorted(list(s[i]))[k] == sorted(list(s[j]))[k]:
          count += 1
      if count == 10:
        ans += 1

print(int(ans/2))

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

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

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

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

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

        #for f in range(10):
           # x=x+1
           # word.append(centence[x])
           # word1.append(centence1[x])
            
        ab=sorted(centence)
        ac=sorted(centence1)
        
        if ab == ac:
            counter=counter+1
        else:
            counter=counter+0

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