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())
strings = []
answer = 0
for i in range(n):
  string = input()
  string = sorted(string)
  strchar=[string['char'] for string in strings]
  if string not in strchar:
    strings.append(dict(char=string, num=0))
  else:
    strchar=[strn for strn in strings if string == strn['char']]
    strchar[0]['num'] = strchar[0]['num'] + 1
    answer = answer + strchar[0]['num']
print(answer)

Submission status: Time Limit Exceeded

Solution code:


if __name__ == "__main__":
    n = int(input())
    lst = []
    count = 0
    for i in range(n):
        lst.append(''.join(sorted(input())))
    for i in range(n):
        for j in range(i + 1, n):
            count += int(lst[i] == lst[j])
    print(count)

Submission status: Time Limit Exceeded

Solution code:


if __name__ == "__main__":
    n = int(input())
    lst = []
    count = 0
    for i in range(n):
        lst.append(sorted(list(input())))
    for i in range(n):
        for j in range(i + 1, n):
            count += int(len([a for a, b in zip(lst[i], lst[j]) if a == b]) == 10)
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
ans=0
#dict={}
s_list = []
# for i in s:
#   if i in dict:
#     ans+=dict[i]
#     dict[i]+=1
#   else:
#     dict[i]=1

# print(dict)
for i in range(n):
  check = 0
  for j in s_list:
    if s[i] == j:
      check = 1
      ans += 1
  s_list.append(s[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
ans=0
#dict={}

# for i in s:
#   if i in dict:
#     ans+=dict[i]
#     dict[i]+=1
#   else:
#     dict[i]=1

# print(dict)
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 = []
for n in range(N):
    S.append(input())

Y=[]
for s in S:
    X = []
    for w in s:
        X.append(w)
        X.sort()
    Y.append(X)

ans_d = 0

for n in range(N):
    for i in range(N):
        if i == n:
            pass
        else:
            if Y[n] == Y[i]:
                ans_d += 1
            else:
                pass

ans = ans_d / 2
print(round(ans))

Submission status: Time Limit Exceeded

Solution code:
import math
def combinations_count(n, r):
    if n >= r:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
n = int(input())
s = [list(map(str, input())) for i in range(n)]
count = 0
for i in range(n):
    s[i].sort()
for i in s:
    k = s.count(i)
    l = i
    count += combinations_count(k, 2)
    for j in range(k):
        s.remove(s[s.index(l)])
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
s = [list(map(str, input())) for i in range(n)]
count = 0
for i in range(n):
    s[i].sort()
for i in s:
    k = s.count(i)
    l = i
    if k == 1:
        s.remove(l)
    else:
        count += combinations_count(k, 2)
        for j in range(k):
            s.remove(s[s.index(l)])
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
cnt=[]
for i in range(n):
  s.append(str(input()))
  cnt.append([])
  for c in [chr(j+ord('a')) for j in range(26)]:
    cnt[i].append([c,s[i].count(c)])

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

print(v)
print("\n")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

import sys
input = sys.stdin.readline

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

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

s.sort()

out=0

for i in range(N):
    for j in range(i+1,N,1):
        if s[i]==s[j]:
            out+=1
        else:
            continue

print(out)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools

def verify_anagrams(first_word, second_word):
    return Counter(first_word) == Counter(second_word)

N = int(input())
S = [str(Counter(sorted(input()))) for _ in range(N)]
print(sum((x * (x - 1)) // 2 for x in Counter(S).values()))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools

def verify_anagrams(first_word, second_word):
    return Counter(first_word) == Counter(second_word)

N = int(input())
S = [Counter(input()) for _ in range(N)]
sum = 0

x = itertools.combinations(S, 2)
for combi in x:
    if combi[0] == combi[1]:
        sum += 1
# print(Counter(S))
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools

def verify_anagrams(first_word, second_word):
    return Counter(first_word) == Counter(second_word)

N = int(input())
S = []
for _ in range(N):
    S.append(Counter(input()))
sum = 0

x = itertools.combinations(S, 2)
for combi in x:
    if combi[0] == combi[1]:
        sum += 1
# print(Counter(S))
print(sum)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
cnt=0
s=[sorted(input()) for _ in range(n)]
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:
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))

s_srt = []
for i in range(n):
    s_srt.append(sorted(s[i]))
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if s_srt[i] == s_srt[j]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 組み合わせの数を出力
import sys
input = sys.stdin.readline

n = int(input())
s = [sorted(input()) for _ in range(n)]
t = 0
dup = []
# sが空っぽになるまで重複するものを消して差分を控える
while s:
    t = len(s)
    pop = s.pop()
    try:
        while True:
            s.remove(pop)
    except ValueError:
        pass
    dup.append(t-len(s))

ans = sum(c*(c-1)//2 for c in dup)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 組み合わせの数を出力
n = int(input())
s = [sorted(input()) for _ in range(n)]
t = 0
dup = []
# sが空っぽになるまで重複するものを消して差分を控える
while s:
    t = len(s)
    pop = s.pop()
    try:
        while True:
            s.remove(pop)
    except ValueError:
        pass
    dup.append(t-len(s))

ans = sum(c*(c-1)//2 for c in dup)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 組み合わせの数を出力
n = int(input())
s = [sorted(input()) for _ in range(n)]
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        if s[i] == s[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

b = [False] * n
ans = 0
count = 1

for i in range(n):
    if b[i]:
        continue
    for j in range(i + 1, n):
        if s[i] == s[j]:
            count += 1
            b[j] = True
    ans += int(count * (count - 1) / 2)
    count = 1
    b[i] = True

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import collections
import math

n = int(input())

a = [str(sorted(input())) for _ in range(n)]
a.sort()
s = set(a)

l = []
for i in s:
    l.append(a.count(i))

ans = 0
for i in l:
    if i == 1:
        pass
    else:
        ans += (i-1) * i // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

c = []
for i in s:
    c.append(collections.Counter(i))

ans = 0
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:
#K,X = map(int,input().split())
N = int(input())
S = [''.join(sorted(input())) for i in range(N)]
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:
N=int(input())
LST=[]
count=0
for i in range(N):
    a=input()
    lst=[]
    for j in range(len(a)):
        lst.append(a[j])
    LST.append(sorted(lst))
for i in range(N-1):
    for j in range(i+1,N):
        if LST[i]==LST[j]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
LST=[]
for i in range(N):
    a=input()
    lst=[]
    for j in range(len(a)):
        lst.append(a[j])

    LST.append(sorted(lst))

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

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    sj = sorted(input())
    s.append(sj)

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        for k in range(len(s[0])):
            if s[i][k] != s[j][k]:
                break
            if len(s[0])-1 == k:
                count += 1

print(count // 2)

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()
    s = ''.join(sorted(s))
    ans += list_s.count(s)

    list_s.append(s)

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    D = [defaultdict(int) for _ in range(N)]
    for d in D:
        S = list(input()[:-1])
        for s in S:
            d[s] += 1
    # print(D)

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
count = 0

def get_counter(s):
    return Counter(s.upper().replace(' ', ''))

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = int(input())

S = list()

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

S.sort()
ans = 0
for j in range(N):
    k = 1
    while j+k < N and S[j][0] == S[j+k][0]:
        if "".join(S[j]) == "".join(S[j+k]):
            ans += 1
        k += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = int(input())

S = list()

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

ans = 0
for j in range(N):
    k = 1
    while j+k < N:
        if "".join(S[j]) == "".join(S[j+k]):
            ans += 1
        k += 1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
count = 0
for _ in range(n):
    l.append(sorted(input()))
while len(l) > 0:
    count += l.count(l[0]) - 1
    l = l[1:]
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
count = 0
for _ in range(n):
    l.append(list(map(lambda x: sorted(x), input().split())))
    for j in range(len(l) - 1):
        if l[-1] == l[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [list(map(lambda x:sorted(x), input().split())) for _ in range(n)]
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())

dic = []

ans = 0

for i in range(n):
    ip = ''.join(sorted(input()))

    for k in range(len(dic)):
        if ip == dic[k]:
            ans += 1

    dic.append(ip)


print(ans)

Submission status: Time Limit Exceeded

Solution code:
#137c
N = int(input())
sList = []
ans = 0

#文字を読み込みつつ、出現回数を辞書化して、配列に追加
for i in range(N): #2<N<10^5
  # https://www.lifewithpython.com/2015/05/python-count-characters-in-string.html
  string = str(input())

  #辞書化
  #counter = {}
  #for c in string:
  #    if not c in counter:
  #        counter[c] = 1
  #    else:
  #        counter[c] += 1
  #sList.append(counter)
  #↓リスト内包表記なら1行で書ける
  dictionarized_string = {letter: string.count(letter) for letter in string}
  ans += sList.count(dictionarized_string)
  sList.append(dictionarized_string)

  #全通りを比較
  #for i in range(N-1):
  #    for j in range(i+1,N,1):
  #        if sList[i]==sList[j]:
  #            ans = ans+1
  #↑.countで1行で済んだ  

print(ans)

Submission status: Time Limit Exceeded

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

s_dict = []


for i in range(n):
    count = {}
    for c in s[i]:
        count.setdefault(c,0)
        count[c] += 1
    s_dict.append(count)
    
ans = 0
for i in range(n):
    for j in range(i+1,n):
        if s_dict[i] == s_dict[j]: ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

ans = 0
D = {}
for i in range(n):
      s = "".join(sorted(input()))
      if s in D.keys():
            ans += D[s]
            D[s] += 1
      else:
            D[s] = 1
print(ans)

Submission status: Time Limit Exceeded

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

n = int(input())

ans = 0
D = {}
for i in range(n):
      s = "".join(sorted(input()))
      if s in D.keys():
            ans += D[s]
            D[s] += 1
      else:
            D[s] = 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
      L[i] = sorted(L[i])
      L[i] = ''.join(L[i])
L = sorted(L)

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    s = list(input())
    s = sorted(s)
    s_list.append(s)

for i in range(n):
    for j in range(i+1,n):
        if s_list[i] == s_list[j]:
            ans = ans + 1
        elif s_list[i] != s_list[j]:
            continue

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    s = list(input())
    s = sorted(s)
    s_list.append(s)

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

print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
s_list = ["".join(sorted(list(input()))) for _ in range(n)]

cnt = 0
combs = combinations(s_list, 2)
for comb in combs:
    if comb[0] == comb[1]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

print(sum(1 if s1 == s2 else 0 for s1, s2 in combinations(S, 2)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
 
def comb(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
 
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
 
 
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())
strs = list()
for _ in range(n):
    strs.append(sorted(list(input())))

total = 0
for i in range(n):
    for j in range(i + 1, n):
        if strs[i] == strs[j]:
            total += 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0
sListSum = 0
sList = [None] * n

for i in range(n):
    s = sorted(input())
    sListSum += sList.count(s)
    sList[i] = s

print(sListSum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0
sListSum = 0

sList = ["".join(sorted(list(input()))) for _ in range(n)]
sListSet = list(set(sList))
for i in sListSet:
    cnt = sList.count(i)
    sListSum += int(cnt * (cnt - 1) / 2)
print(sListSum)

Submission status: Time Limit Exceeded

Solution code:
import itertools


def main():
    n = int(input())
    s = [sorted(input()) for _ in range(n)]
    seq = list(itertools.combinations(s, 2))
    ans = 0
    for i in seq:
        if i[0] == i[1]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
#S = [input() for _ in range(N)]
S = ["".join(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:
from collections import Counter as co
from itertools import combinations as com
n=int(input())
a=0
l=[set(co(input()).items()) for i in range(n)]
for d,s in com(range(n),2):
  if l[d]==l[s]:a+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as co
from itertools import combinations as com
n=int(input())
a=0
l=[co(input()).items() for i in range(n)]
for d,s in com(range(n),2):
  if l[d]==l[s]:a+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as co
from itertools import combinations as com
n=int(input())
a=0
l=[list(sorted(co(input()).items())) for i in range(n)]
for d,s in com(range(n),2):
  if l[d]==l[s]:a+=1
print(a)

Submission status: Time Limit Exceeded

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

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

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

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

for i in lis_pat:
    lis_num.append(lis_all.count(i))

ans = 0
for i in lis_num:
    if i != 1:
        ans += comb(i,2)
   
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

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

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

for i in lis_pat:
    lis_num.append(lis_all.count(i))

ans = 0
for i in lis_num:
    if i != 1:
        ans += comb(i,2)
   
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

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

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

for i in lis_pat:
    lis_num.append(lis_all.count(i))

ans = 0
for i in lis_num:
    if i != 1:
        ans += comb(i,2)
   
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]"):

    count = 0
    str_list = []
    for s_i in s:

        s_i = list(s_i)
        s_i.sort()

        if s_i in str_list:
            # print(s_i)
            # print("True")
            count += str_list.count(s_i)
            str_list.append(s_i)

        else:
            # print(s_i)
            # print("False")
            str_list.append(s_i)

    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]"):

    count = 0
    for i in range(len(s) - 1):

        s_from = list(s[i])
        s_from.sort()
        # print(s_from)

        for j in range(i + 1, len(s)):

            s_target = list(s[j])
            s_target.sort()
            # print(s_target)

            if s_target == s_from:
                count += 1
            else:
                pass
    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

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

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

ans = 0
for i in lis_pat:
    if lis_all.count(i) != 1:
        ans += comb(lis_all.count(i),2)
   
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
lis_all = []
lis_pat = []
lis_num = []

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

count = 0
for i in range(N):
    lis_S = list(str(input()))
    lis_S.sort()
    if lis_S not in lis_all:
        lis_pat.append(lis_S)
    lis_all.append(lis_S)

for i in lis_pat:
    lis_num.append(lis_all.count(i))

ans = 0
for i in lis_num:
    if i != 1:
        ans += comb(i,2)
   
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  N = int(input())
  A = []
  s = []
  ans = 0
  for _ in range(N):
    s=list(input())
    s.sort()
    s="".join(s)
    A.append(s)
    ans += A.count(s)
  print(ans-N)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
s = []
ans = 0
for _ in range(N):
 s=list(input())
 s.sort()
 s="".join(s)
 A.append(s)
 ans += A.count(s)
print(ans-N)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
s = []
for _ in range(N):
 s=list(input())
 s.sort()
 s="".join(s)
 A.append(s)
ans = 0
for n in range(N):
    for i in A[n+1::]:
        if A[n] in (i):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for _ in range(n):
  s.append(collections.Counter(input()))

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
lists=[]
setlists=[]
uselists=[]
allsums=0

n=int(input())
for s in range(n):
    something=sorted(str(input()))
    lists.append(something)
    if something not in setlists:
        setlists.append(something)


for i in setlists:
    whatis=lists.count(i)
    uselists.append(whatis)

for x in uselists:
    allsums+=int(x*(x-1)/2)
print(allsums)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as ct
emptylists=[]
allsums=0

n=int(input())
for s in range(n):
    something=dict(ct(str(input())))
    emptylists.append(something)

for x in range(n):
    for y in range(n):
        if emptylists[x]==emptylists[y]:
            allsums+=1
        else:
            continue
print(int((allsums-n)/2))

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
s = []
for i in range(0,N):
  K = (''.join(sorted(raw_input())))
  s.append(K)
ans = 0
s = sorted(s)
i = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sorted = []
for l in s:
	tmp = []
	for m in l:
		tmp.append(m)
	tmp.sort()

	tmp2 = ''
	for i in tmp:
		tmp2+=i

	sorted.append(tmp2)

count=0
for i,n in enumerate(sorted):
	for j in range(i + 1,N):
		if sorted[i]==sorted[j]:
			count+=1

print(count)

Submission status: Time Limit Exceeded

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

N = int(input())
S_list =[]
for _ in range(N):
  s = input()
  s = sorted(list(s))
  S_list.append(s)
counter = 0
for i in range(len(S_list)):
  for j in range(len(S_list)-1-i):
    if S_list[i] == S_list[i+j+1]:
      counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S_list =[]
for _ in range(N):
  s = input()
  s = sorted(list(s))
  S_list.append(s)
counter = 0
for i in range(len(S_list)):
  for j in range(len(S_list)-1-i):
    if S_list[i] == S_list[i+j+1]:
      counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
slist = []
for i in range(N):
    slist.append(sorted(list(input())))
count = [0 for i in range(N)]
c = []
answer = 0
for i in range(N):
    d = 0
    for j in range(len(c)):
        if slist[i] == c[j]:
            count[j] += 1
            answer += count[j]
            d = 1
    if d == 0:
        c.append(slist[i])
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
slist = []
for i in range(N):
    slist.append(sorted(list(input())))
count = [0 for i in range(N)]
c = []
c.append(slist[0])
for i in range(N):
    d = 0
    for j in range(len(c)):
        if slist[i] == c[j]:
            count[j] += 1
            d = 1
    if d == 0:
        c.append(slist[i])
count[0] -= 1
def counting(n):
    if n == 0:
        return 0
    else:
        return n*(n+1)//2
sum = 0
for i in range(N):
    sum += counting(count[i])
print(sum)

Submission status: Time Limit Exceeded

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

sdic = {}
for i in range(n):
    s = str(sorted(list(input())))
    if s in sdic.keys():
        ans += sdic[s]
        sdic[s] += 1
    else:
        sdic[s] = 1

print(ans)

Submission status: Time Limit Exceeded

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

ss = ['']*n
for i in range(n):
    ss[i] = sorted(s[i])

for i in range(n-1):
    for v in range(i+1,n):
        if ss[i] == ss[v]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [input() for _ in range(N)]
S = list(map(lambda x: sorted(x), S))
cnt = 0 
for i, str1 in enumerate(S):
    for str2 in S[i + 1:]:
        if str1 == str2:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(sorted(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())
l = []
for _ in range(n):
    l.append(''.join(sorted(input())))

cnt = 0
for e in l:
    ll = l[1:]
    for ee in ll:
        if e == ee:
            cnt += 1
    l = ll

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
l = []
for _ in range(n):
    l.append(''.join(sorted(input())))

cnt = 0
for idx, e in enumerate(l):
    ll = l[idx+1:]
    for ee in ll:
        if e == ee:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

L = []

for i in range(0,len(S)):
	L.append(sorted(S[i]))

for i in range(0,len(L)):
	L[i] = ",".join(L[i])

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

print(counter)

Submission status: Time Limit Exceeded

Solution code:


H = int(input())
S = []
for _ in range(H):
	S.append(input()) 

L = []

for i in range(0,len(S)):
	L.append(sorted(S[i]))

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

print(counter)

Submission status: Time Limit Exceeded

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

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