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())
str_list = list()
for _ in range(n):
  tar_str = input()
  tmp_list = list()
  for i in tar_str:
    tmp_list.append(i)
  str_list.append(sorted(tmp_list))

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)

Submission status: Time Limit Exceeded

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


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

print(ans)

Submission status: Time Limit Exceeded

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


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ss = []
cnt = 0

# for _ in range(n):
#     ss.append(input())

# for i, s1 in enumerate(ss[0:n-2+1]):
#     for s2 in ss[i + 1:n-1+1]:
#         # print(s1, s2)
#         if sorted(s1) == sorted(s2):
#             cnt += 1

for _ in range(n):
    ss.append(input())

map = {}
for s in ss:
    sorted_s = ''.join(sorted(s))
    if sorted_s in map.keys():
        map[sorted_s] += 1
    else:
        map[sorted_s] = 1


# map = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
# map = {'a': 10 ** 5}  # maxテスト
# print(map)

# def factorial(n):
#     if n > 0:
#         return n * factorial(n-1)
#     else:
#         return 1


def factorial(x):
    ans = 1
    for i in range(2, x+1):
        ans *= i
    return ans

# あとはxC2の組み合わせの総数を求めれば良い


for n in map.values():
    if n > 1:
        cnt += factorial(n) // (2 * factorial(n-2))
    # print(n)
    # print(cnt)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ss = []
cnt = 0

for _ in range(n):
    ss.append(input())

for i, s1 in enumerate(ss[0:n-2+1]):
    for s2 in ss[i + 1:n-1+1]:
        # print(s1, s2)
        if sorted(s1) == sorted(s2):
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
ans = map(lambda x: s.count(x)-1, set(s))
ans = sum(map(lambda x: int(x*(x+1)/2), ans))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
ans = list(map(lambda x: s.count(x)-1, set(s)))
ans = sum(list(map(lambda x: int(x*(x+1)/2), ans)))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
import math
import sys

sys.setrecursionlimit(10 ** 7)

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


def split(word):
    return [char for char in word]


normalized_s_list = [''.join(sorted(split(s))) for s in s_list]

uniqued_s_list = set(normalized_s_list)

duplicated_s_list = copy.deepcopy(normalized_s_list)
for s in uniqued_s_list:
    duplicated_s_list.remove(s)

duplicated_s_list = list(set(duplicated_s_list))

result = 0
for s in duplicated_s_list:
    count = normalized_s_list.count(s)
    result += (1 / 2) * count * (count - 1)

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

sys.setrecursionlimit(10 ** 7)

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


def split(word):
    return [char for char in word]


normalized_s_list = [''.join(sorted(split(s))) for s in s_list]

uniqued_s_list = set(normalized_s_list)
result = 0
for s in uniqued_s_list:
    count = normalized_s_list.count(s)
    result += (1 / 2) * count * (count - 1)

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
import math

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

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = []
ans = 0
for _ in range(N):
    S = input()
    tmp_arr = []
    for i in range(10):
        tmp_arr.append(S[i])
    tmp_arr.sort()
    arr.append(tmp_arr)
# print(arr)

while len(arr) != 0:
    tmp = len(arr)
    item = arr[0]
    # print(tmp)
    # print(item)
    while item in arr:
        arr.remove(item)
    tmp_ans = tmp - len(arr)
    # print(tmp_ans)
    if tmp_ans - 2 >= 0:
        ans += C(tmp_ans,2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
# 行数
N = int(input().strip())

# 2次元配列
grid = []
grida = []
p = 0
q = 0
num = 1
for i in range(N):
    array = list(map(str, input().strip().split()))
    grid.append(array)
    aaa = str(array[0])
    new_str_list = sorted(aaa)
    #print(new_str_list)
    grida.append(new_str_list)
#print(grida)
while True:
   if num < len(grida):
    if grida[0] == grida[num]:
     p = p + 1
     q = 1 + 1
     num = num + 1
    else:
     print("k")
    grida.pop(0)
    num = 1

print(q)

Submission status: Time Limit Exceeded

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

import itertools
word_list=[]
num_list=[]
for word in S:
  word=''.join(sorted(word))
  word_list.append(word)
  word_set=set(word_list)
  
for word in word_set:
  num = len(list(itertools.combinations(range(word_list.count(word)),2)))
  num_list.append(num)
print(sum(num_list))

Submission status: Time Limit Exceeded

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

import itertools
word_list=[]
for word in S:
  word=''.join(sorted(word))
  word_list.append(word)
word_set=set(word_list)

num_list=[]
for word in word_set:
  num = len(list(itertools.combinations(range(word_list.count(word)),2)))
  num_list.append(num)
print(sum(num_list))

Submission status: Time Limit Exceeded

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

word_list=list(map(lambda x: ''.join(sorted(x)),S))

import itertools
word_set=set(word_list)
total_counts=[]
for word in word_set:
  num = len(list(itertools.combinations(range(word_list.count(word)),2)))
  total_counts.append(num)
  
print(sum(total_counts))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [input() for i in range(N)]
word_list=[]
for w in S:
  sort_word=''.join(sorted(w))
  word_list.append(sort_word)
word_list.sort()

import itertools
word_set=set(word_list)
total_counts=[]
for word in word_set:
  num = len(list(itertools.combinations(range(word_list.count(word)),2)))
  total_counts.append(num)
  
print(sum(total_counts))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [input() for i in range(N)]
word_list=[]
for w in S:
  sort_word=''.join(sorted(w))
  word_list.append(sort_word)
word_list.sort()

import itertools
word_set=set(word_list)
count_list=[]
for word in word_set:
  count_list.append(word_list.count(word))

total_counts=[]
for num in count_list:
  total_counts.append(len(list(itertools.combinations(range(num),2))))
  
print(sum(total_counts))

Submission status: Time Limit Exceeded

Solution code:
N_number = int(input())
strings = []
count = 0
for i in range(N_number):
  string = "".join(sorted(input()))
  if string in strings:
    count += strings.count(string)
  strings.append(string)
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())

# スペース区切りの整数の入力
ar = []
for i in range(n):
  l = list(input())
  l.sort()
  ar.append("".join(l).__hash__())


count = 0
for i in range(n):
  count = count + ar[i+1:].count(ar[i])

print(count)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

s_li = []
c = 0
for i in range(N) :
    s = ''.join(sorted(list(input())))
    con = s_li.count(s)
    if (con >= 1) :
        c += con
    s_li.append(s)

print(c)

Submission status: Time Limit Exceeded

Solution code:
import statistics as stat
import collections as cl

N = int(input())

s_li = []
c = 0
for i in range(N) :
    s = sorted(list(input()))
    for s_item in s_li :
        if (s == s_item) :
            c += 1
    s_li.append(s)


print(c)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
L=[sorted(list(input()))for i in range(n)]
x=0
while L!=[]:
    a=L.count(L[0])
    if a!=1:
        x+=a*(a-1)//2
    L=[l for l in L if l!=L[0]]
print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
u = ["".join(sorted(list(input()))) for i in range(N)]
ans = 0
for i in range(N):
  ans += u[i:].count(u[i]) - 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=[sorted(list(input())) for i in range(n)]
ans=0

for i in S:
  ans+=S.count(i)-1
print(ans//2)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=[sorted(list(input())) for i 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_list=[sorted(list(input())) for i in range(n)]
S=[]
ans=0

for i in range(n): #リストの文字列変換
  S.append("".join(s_list[i]))
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())
lst = []
for i in range(N):
  s = list(input())
  s.sort()
  lst.append(s)
cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for ss in s:
  ss.sort()

count = 0

for ss in itertools.combinations(s, 2):
  if ss[0] == ss[1]:
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc137/tasks/abc137_c
# C - Green Bin
import collections
import itertools

n = int(input().split()[0])
s_list = []
c_list = []

for _ in range(n):
    s = input().split()[0]
    s_list.append(s)
    c_list.append(collections.Counter(s))

p = itertools.combinations(c_list, 2)
ans = sum([1 if a == b else 0 for a, b in list(p)])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
ans = 0
n = int(input())
ls = [input() for i in range(n)]
for i in range(len(ls)):
    tmp = sorted(list(ls[i]))
    ls[i] =  ''.join(tmp)

for i, j in itertools.combinations(ls,2):
    if i == j:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list()
count = 0
for i in range(N):
    s = sorted(input())
    if s in l:
        count+=l.count(s)
    l.append(s)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
s_list = []
out = 0

for i in range(N):
  s_list.append(''.join(sorted(list(input()))))
  
for s1, s2 in itertools.combinations(s_list, r=2): 
	out = out+1 if s1==s2 else out
    
print(out)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
s_list = []
out = 0

for i in range(N):
  s_list.append(input())
  
for s1, s2 in itertools.combinations(s_list, r=2): 
	s1 = sorted(list(s1))
	s2 = sorted(list(s2))
    
	out = out+1 if s1==s2 else out
    
print(out)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

count = 0

s=[''.join(sorted(input())) for i in range(n)]

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
string_list=["".join(sorted(list(input()))) for i in range(n)]
string_set=set(string_list)
cnt=0
for s in string_set:
  n=string_list.count(s)
  cnt+=int(n*(n-1)/2)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
qt = int(input())
sl = [input() for i in range(qt)]
ls = []
count = 0

for s in sl:
    s = "".join(sorted(s))
    ls.append(s)

i = 0
j = 0
key = ""

while len(ls) > i:
    while len(ls) > (j + 1):
        j += 1
        if ls[i] == ls[j]:
            count += 1
    i += 1
    j = i

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from collections import defaultdict
N = int(input())
D = defaultdict(int)
for i in range(N):
    S = tuple(sorted(Counter(input()).most_common()))
    D[S] += 1

ans = 0
for key in D:
    M = D[key]
    if M >= 2:
        ans += M*(M-1)//2
    
print(ans)

Submission status: Time Limit Exceeded

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

for i, s in enumerate(S):
    S[i] = "".join(sorted(list(s)))

skiptbl = [False for j in range(N)]
count = 0
for i in range(N):
    if skiptbl[i]:
        continue
    d = 0
    for j in range(i+1, N):
        if skiptbl[j]:
            continue
        if S[i] == S[j]:
            d += 1
            skiptbl[j] = True
    count += d if d <= 1 else d + math.factorial(d) / (2 * math.factorial(d - 2))
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
S = [input() for i in range(N)]
count = 0
l = [False for i in range(N)]
for i, s in enumerate(S):
    if l[i]:
        continue
    sset = set(s)
    d = 0
    for j in range(i+1, N):
        if l[j]:
            continue
        for c in sset:
            if s.count(c) != S[j].count(c):
                break
        else:
            d += 1
            l[j] = True
    count += d if d <= 1 else d + math.factorial(d) / (2 * math.factorial(d - 2))
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
s = [input() for i in range(n)]
arr = []
ans = 0
for i in s:
    arr.append(collections.Counter(i))

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    S = []
    for i in range(N):
        s = input()
        s = sorted(s)
        s = ''.join(s)
        S.append(s)
    S.sort()
    SS = sorted(list(set(S)))
    SN = []
    M = len(SS)
    for i in range(M - 1):
        sn = S.index(SS[i + 1])
        SN.append(sn)
        S = S[sn:]
    SN.append(len(S))

    res = 0
    for sn in SN:
        res += sn * (sn - 1) // 2

    print(res)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as dd
N = int(input())
S = []
for i in range(N):
    s = input()
    s = sorted(s)
    s = ''.join(s)
    S.append(s)
S.sort()
SS = sorted(list(set(S)))
SN = []
M = len(SS)
for i in range(M - 1):
    sn = S.index(SS[i + 1])
    SN.append(sn)
    S = S[sn:]
SN.append(len(S))

res = 0
for sn in SN:
    res += sn * (sn - 1) // 2

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as dd
N = int(input())
S = []
for i in range(N):
    s = input()
    s = sorted(s)
    s = ''.join(s)
    S.append(s)
S.sort()
SS = sorted(list(set(S)))
SN = []
for i in range(len(SS)):
    sn = 0
    for j in range(len(S)):
        if SS[i] == S[j]:
            sn += 1
        else:
            break
    S = S[sn:]
    SN.append(sn)

res = 0
for sn in SN:
    res += sn * (sn - 1) // 2

print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as dd
N = int(input())
S = []
for i in range(N):
    s = input()
    s = sorted(s)
    s = ''.join(s)
    S.append(s)
S.sort()
SS = sorted(list(set(S)))
SN = []
for i in range(len(SS)):
    SN.append(S.count(SS[i]))
    if i < len(SS) - 1:
        j = S.index(SS[i+1])
        S = S[j:]


res = 0
for sn in SN:
    res += sn * (sn - 1) // 2

print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as dd
N = int(input())
S = []
for i in range(N):
    s = input()
    s = sorted(s)
    s = ''.join(s)
    S.append(s)

SS = set(S)
SN = []
for ss in SS:
    SN.append(S.count(ss))

res = 0
for sn in SN:
    res += sn * (sn - 1) // 2

print(res)

Submission status: Time Limit Exceeded

Solution code:
import collections

def make_hist(s):
  hist = collections.Counter()
  for c in s:
    hist[c] += 1
  return hist

ans = 0
s_hist = []
N = int(input())
for n in range(N):
  new_hist = make_hist(input().strip())
  for s in s_hist:
    if(s == new_hist):
      ans += 1
  s_hist.append(new_hist)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

S = np.array(S)

s = list('abcdefghijklmnopqrstuvwxyz')

T = np.zeros([N, 26])

for i, a in enumerate(s):
  T[:, i] = np.sum(S == a, axis=1)


c = 0
for i in range(N):
  c += np.sum(np.prod(T[i] == T[i+1:], axis=1))
  
print(c)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

S = np.array(S)

s = list('abcdefghijklmnopqrstuvwxyz')

T = np.zeros([N, 26])

for i, a in enumerate(s):
  T[:, i] = np.sum(S == a, axis=1)


c = 0
for i in range(N):
  for j in range(i+1, N):
    if (T[i] == T[j]).all():
      c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
s = []
for _ in range(N):
    b = list(input())
    b.sort()
    c = ''.join(b)
    s.append(c)

count = 0
for v in itertools.combinations(s, 2):
    if v[0] == v[1]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
s = []
for i in range (N):
    word = input()
    word_lst = []
    for j in range (len(word)):
        word_lst.append(word[j])
    word_lst = np.sort(word_lst)
    words = ""
    for j in range (len(word_lst)):
        words += word_lst[j]
    s.append(words)
#print (s)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input()) #get 1st row
inlist = [input() for i in range(N)] #read row (add int using brackets if needed)
result = []

#make dic from input parameters
for component in inlist :
    dic = []
    for n in component:
        dic.append(n)
    dic.sort()
    result.append(dic)

counter = 0
for k1, v1 in enumerate(result):
    for k2, v2 in enumerate (result):
        if v1 == v2 and k1 > k2:
            counter += 1

print (counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input()) #get 1st row
inlist = [input() for i in range(N)] #read row (add int using brackets if needed)
result = []

#make dictionary from input parameters
for component in inlist :
    dic = {}
    #read each
    for n in component:
        if n in dic.keys():
            dic[n] += 1
        else :
            dic[n] = 1
    result.append(dic)

counter = 0
for k1, v1 in enumerate(result):
    for k2, v2 in enumerate (result):
        if v1 == v2 and k1 > k2:
            counter += 1

print (counter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

string=list()
for i in range(N):
  c=list(input())
  c.sort()
 # print(''.join(c))
  string.append(''.join(c))
  
#print(string)

count=0
M=N
for j in range(N):
  s=string[0]
  c=string.count(s)
  M=M-c
  count=count +int(c*(c-1)/2)
  for k in range(c):
   string.remove(s)
  if j+1>M-1:
    break
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

def main():
    num = int(input())
    s = []
    count = 0
    for i in range(0,num): 
        s_c = []
        for c in input():
            s_c.append(c)
        s_c.sort()
        s.append(s_c)

    for i in range(num):
        for j in range(i+1, num):
            if (s[i] == s[j]):
                count = count + 1 
                #print("equal: {}, {}".format(i,j))
    print(count)
    
if __name__ == "__main__" :
    main()

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

def main():
    num = int(input())
    s = []
    count = 0
    for i in range(0,num): 
        s_c = []
        for c in input():
            s_c.append(c)
        s_c.sort()
        s.append(s_c)

    for i in range(num):
        for j in range(num):
            if (j > i)&(s[i] == s[j]):
                count = count + 1 
                #print("equal: {}, {}".format(i,j))
    print(count)
    
if __name__ == "__main__" :
    main()

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

def main():
    num = int(input())
    s = []
    count = 0
    for i in range(0,num): 
        s_c = []
        for c in input():
            s_c.append(c)
        s_c.sort()
        s.append(s_c)

    for i in range(num):
        for j in range(num):
            if j > i:
                if s[i] == s[j]:
                    count = count + 1 
                    #print("equal: {}, {}".format(i,j))
    print(count)
    
if __name__ == "__main__" :
    main()

Submission status: Time Limit Exceeded

Solution code:
num = input()
lst = []
for i in range(0, int(num)):
  s = input()
  lst.append(s)

srt = [sorted(i) for i in lst]
cnt = 0
for n, i in enumerate(srt):
  cnt += srt[n+1:].count(i)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
num = input()
lst = []
for i in range(0, int(num)):
  s = input()
  lst.append(s)
  
srt = [sorted(i) for i in lst]
cnt = 0
for n, i in enumerate(srt):
  cnt += srt[n+1:].count(i)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
num = input()
lst = []
for i in range(0, int(num)):
  s = input()
  lst.append(s)

spr = []
for i in lst:
  spr.append([l for l in i])

srt = [sorted(i) for i in spr]
cnt = 0
for n, i in enumerate(srt):
  cnt += srt[n+1:].count(i)

print(cnt)

Submission status: Time Limit Exceeded

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

spr = []
for i in lst:
  spr.append([l for l in i])

srt = [sorted(i) for i in spr]
cnt = 0
for n, i in enumerate(srt):
  cnt += srt[n+1:].count(i)

print(cnt)

Submission status: Time Limit Exceeded

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

res = 0

while(True):
  m = len(s)
  count1 = 0
  ind = []
  for j in range(m-1):
    if(s[0]==s[j+1]):
      ind.append(j+1)
      #del s[j+1]
      count1 = count1+1
  ind.sort(reverse=True)
  for i in range(len(ind)):
    del s[ind[i]]
  del s[0]
  res = res+(1+count1)/2*count1
  if(len(s)==0):
    break
print(int(res))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

for i in range(n) : 
    for j in range(i) : 
        if Counter(S[i]) == Counter(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(str(input())))
  s[i].sort()
count = 0

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

def verify_anagrams(first_word, second_word):
    first = first_word.lower()
    second = second_word.lower()
    FIRST = []
    SECOND = []
    for i in first:
        if i != " ":
            FIRST.append(i)
    for i in second:
        if i != " ":
            SECOND.append(i)
    if len(FIRST) != len(SECOND):
        return 0
    for i in FIRST:
        if i in SECOND:
            SECOND.remove(i)
    if SECOND == []:
        return 1
    return 0
for i in range(n):
  for j in range(n):
    if verify_anagrams(list[i], list[j]):
      count += 1
    
print(int((count-n)/2))

Submission status: Time Limit Exceeded

Solution code:
n = int( input() )
da = []
ans = 0
for i in range(n):
    s = input()
    d = {}
    for item in s:
        if item in d:
            d[item] += 1
        else:
            d[item] = 1

    for d1 in da:
        if d1 == d:
            ans += 1
    
    da.append(d)


print(ans)

Submission status: Time Limit Exceeded

Solution code:
len = 10

def anagram(s1, s2) :
    index = [-1]*len
    for i in range(len) :
        for j in range(len) : 
            if index[j] < 0 and s1[i] == s2[j] : 
                #print("i:{}, j{}".format(i,j))
                index[j] = i
                break
    for x in index : 
        if x < 0 : return False
    return True

n=int(input())
L=[]
for i in range(n) :
    L.append([i, input()])
count=0
for i in range(n) :
    for j in range(i+1,n) :
        if  anagram(L[i][1],L[j][1]) : 
            #print("i:{}, j{}".format(i,j))
            count += 1
#print(L)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# define
def isAnagram(str1, str2) : 
    true_flag = 1
    
    for i in str1 : 
        if (str1.count(i) != str2.count(i)) : 
            true_flag = 0
            
    if (true_flag == 1) : 
        return True
    else : 
        return False

# initial setting
cnt = 0
        
# number input
n = int(input())
s = [0] * n

# letter input
for i in range(n) : 
    s[i] = input()
    
# charcter count
for i in range(n) : 
    for j in range(i) : 
        if isAnagram(s[i], s[j]) == True : 
            cnt += 1

# output
print(cnt)
        
# all selection patterns(test)
# for i in range(4) : 
#     for j in range(i) : 
#         if i != j : 
#             print(i, j)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

if __name__ == "__main__":
    N = int(input())
    s = []
    for i in range(N):
        s.append("".join(sorted(input())))
    s.sort()
    ans = 0
    for i in range(len(s)):
        for j in range(i+1, len(s)):
            if s[i] == s[j]:
                ans += 1
            else:
                break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

if __name__ == "__main__":
    N = int(input())
    s = []
    for i in range(N):
        s.append("".join(sorted(input())))
    s = sorted(s)
    ans = 0
    for i in range(len(s)):
        for j in range(i+1, len(s)):
            if s[i] == s[j]:
                ans += 1
            else:
                break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

if __name__ == "__main__":
    N = int(input())
    s = []
    for i in range(N):
        s.append("".join(sorted(input())))
    ans = 0
    for i in range(len(s)):
        for j in range(i+1, len(s)):
            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())

Ssort=[sorted(s) for s in S]

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

print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = [input() for i in range(N)]
for i in range(N):
    l[i] = ''.join(sorted(l[i]))
count = 0
for i in range(N):
    for j in range(i+1,N):
        if(l[i]==l[j]):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = [input() for i in range(N)]
for i in range(N):
    l[i] = ''.join(sorted(l[i]))
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        if(l[i]==l[j]):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
N = int(N)

list_modified = []

for n in range(1, N + 1):
    s = input()
    list_s = sorted(s)
    new_s = ''.join(list_s)
    list_modified.append(new_s)
    
m = 0
    
for k in range(0, N):
    for l in range (k + 1, N):
        if list_modified[k] == list_modified[l]:
            m += 1
        else:
            continue

print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = []
ans = 0
a = ["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"]
for i in range(n):
    s = list(input())
    for j in range(10):
        s[j] = a.index(s[j])
    s = sorted(s)
    li.append(s)
li2  = li.copy()
for s in li2:
    ans -= 1
    ans += li.count(s)
    li.remove(s)
    if ans < 0:
        ans = 0
print(ans)