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:
from itertools import permutations, combinations
n = int(input())
s = []
for _ in range(n):
  s.append(input())

ilist = []
for a in range(len(s)):
  ilist.append(list(s[a]))
  a += 1
#print(ilist)
for ss in range(len(ilist)):
  ilist[ss].sort()
#print(ilist)
li = list(combinations(ilist, 2))
trial = len(li)#何回比較するか求める
ans = 0 #answer
  
for b in range(len(li)):
  if(li[b][0] == li[b][1]):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
my_list = [None] * N
for i in range(N):
    s_i = input()
    my_dict = {}
    for j in range(10):
        if s_i[j] in my_dict:
            my_dict[s_i[j]] += 1
        else:
            my_dict[s_i[j]] = 1
    my_list[i] = my_dict
sum = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if my_list[i] == my_list[j]:
            sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ls = [sorted(list(input())) for i in range(N)]
print(sum([ls[i:N].count(ls[i])-1 for i in range(N)]))

Submission status: Time Limit Exceeded

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

ss = []
counts = []
answer = 0

chars = [x for x in "abcdefghijklmnopqrstuvwxyz"]
num = len(chars)

for i in range(N):
  ss.append(input().strip())
  _count = [0 for _ in range(num)]
  for _s in ss[i]:
    _count[chars.index(_s)] += 1
    
  counts += [_count]
  
  for j in range(i):
    if counts[j] == _count:
      answer += 1
    
print(answer)

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    l.append(sorted(str(input())))

p = 0

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

print(p)

Submission status: Time Limit Exceeded

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

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:
import numpy as np
from sys import stdin
def fun(x):
    ret = 1
    while x:
        ret *= x
        x -= 1
    return ret

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




n = int(input())

ss = [sorted(stdin.readline()) for i in range(n)]
ss.sort()

tmp = ss[0]
cnt = 0
ans = 0
for i in range(n):
    if tmp == ss[i]: cnt+=1
    else:
        tmp = ss[i]
        ans += cmb(cnt, 2)
        cnt=1
print(ans+cmb(cnt,2))

Submission status: Time Limit Exceeded

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

ans = 0
memo = [x for x in range(N)]
for x in range(N-1):
    for y in range(1,N):
        if S[x] == S[y] and memo[x] != memo[y]:
            memo[y] = memo[x]

for x in range(N):
    con = memo.count(x)
    if con != 0:
        ans += con*(con-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def change_dict(string):
	dic = {}
	for ch in set(string):
		dic[ch] = string.count(ch)
	return dic

n = int(input())
st = []
for i in range(n):
	st.append(change_dict(input()))
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
a = list(map(str, [input() for i in range(n)]))

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

def comb(n, r):
    if n < 2:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())

string = []
count = 0

for i in range(n):
    string.append("".join(sorted(input())))

base = len(string)
string_set = list(set(string))

if base == len(string_set):
    print(0)
else:
    total = 0
    for ref in string_set:
        total += (comb(string.count(ref), 2))
    print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
lst = []
lstn = [0] *10**5
cnt = 0
j = 0

def nCr(n,r):
    r = min(r,n-r)
    numerator = 1
    for i in range(n,n-r,-1):
        numerator *= i
    denomination = 1
    for i in range(r,1,-1):
        denomination *= i
    return numerator // denomination


for i in range(n):
    s = input()
    c = Counter(s)
    if c not in lst:
        lst.append(c)
        lstn[j] = 1
        j += 1
    else:
        k = lst.index(c)
        lstn[k] += 1

for x in lstn:
    if x >= 2:
        cnt += nCr(x,2)
print(cnt)

Submission status: Time Limit Exceeded

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

def c(s, x):
    n = 0
    for i in s:
        if i == x:
            n = n + 1
    return n


def f(si, sj):
    for i in range(10):
        if c(si, sj[i]) != c(sj, sj[i]):
            return 0
    return 1

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

for i in range(n - 1):
    for j in range(i + 1, n):
        x = x + f(s[i], s[j])
print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
strlist = []
for i in range(n):
    strlist.append(sorted(list((str(input())))))
    
count = 0
for i in range(n):
    for j in range(i+1, n):
        if(strlist[i] == strlist[j]):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def P(n,r):
  s = 1
  for i in range(r+1, n+1):
    s = s*i
  return s

def cmb(n,r):
  if n == r:
    return 1
  else:
    return P(n,r) // P(n-r,0)

N = int(input())
S = []
ans = 0
n = 1

for i in range(N):
  s = list(input())
  s.sort()
  S.append(s)

S.sort()

for i in range(N-1):
  if S[i] == S[i+1]:
    n += 1
  elif n >= 2:
    ans += cmb(n,2)
    n = 1
  else:
    n = 1
  
if S[N-1] == S[N-2]:
  ans += cmb(n,2)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
num = []
num_list = []
count_list = []
num_list_counter = 0
count = 0

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

for i in range(N):
    S.append(input())
    num = 1
    num *= pow_k(2, S[i].count('a'))
    num *= pow_k(3 , S[i].count('b'))
    num *= pow_k(5 , S[i].count('c'))
    num *= pow_k(7 , S[i].count('d'))
    num *= pow_k(11 , S[i].count('e'))
    num *= pow_k(13 , S[i].count('f'))
    num *= pow_k(17 , S[i].count('g'))
    num *= pow_k(19 , S[i].count('h'))
    num *= pow_k(23 , S[i].count('i'))
    num *= pow_k(29 , S[i].count('j'))
    num *= pow_k(31 , S[i].count('k'))
    num *= pow_k(37 , S[i].count('l'))
    num *= pow_k(41 , S[i].count('m'))
    num *= pow_k(43 , S[i].count('n'))
    num *= pow_k(47 , S[i].count('o'))
    num *= pow_k(73 , S[i].count('p'))
    num *= pow_k(79 , S[i].count('q'))
    num *= pow_k(83 , S[i].count('r'))
    num *= pow_k(89 , S[i].count('s'))
    num *= pow_k(97 , S[i].count('t'))
    num *= pow_k(101 , S[i].count('u'))
    num *= pow_k(103 , S[i].count('v'))
    num *= pow_k(107 , S[i].count('w'))
    num *= pow_k(109 , S[i].count('x'))
    num *= pow_k(113 , S[i].count('y'))
    num *= pow_k(127 , S[i].count('z'))

    if num_list_counter == 0:
        num_list.append(num)
        count_list.append(1)
        num_list_counter += 1
    else:
        judge = 0
        for j in range(num_list_counter):
            if num_list[j] == num:
                judge = 1
                count += count_list[j]
                count_list[j] += 1
        if judge == 0:
            num_list_counter += 1
            num_list.append(num)
            count_list.append(1)

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 = [""] * N
ans = 0

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

s = sorted(s)
dup = [x for x in set(s) if s.count(x) > 1]

for x in dup:
    ans += combinations_count(s.count(x), 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [sorted(input()) for _ in range(N)]
cnt = 0
for i in range(N):
    for j in range(N):
        if i != j and s[i] == s[j]:
            cnt+=1
    s[i] = "COUNTED{}".format(i)
print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import collections

alpha2num = lambda c:ord(c) - ord('a')

N = int(input())
D = np.zeros([26,N])
SUM = 0

for n in range(N):
  s = input()
  c = collections.Counter(s)
  for _c in c.keys():
    i = alpha2num(_c)
    D[i, n] = c[_c]
    
  d = D[:,n]
  d = d.reshape(len(d),1)
  diff = D - d
  count = sum(np.square(diff))
  k = np.count_nonzero(count == 0)
  SUM = SUM + k
  
print('%d' % (SUM-N))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n =int(input())
A=[]
for I in range(n):
  moji=list(input())
  moji.sort()
  moji=''.join(moji)
  A.append(moji)
N=0
for i in range(n):
  a=A[i]
  for s in range(i+1,n):
    b=A[s]
    if a==b:
      N+=1
print(N)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
S = [input() for _ in range(n)]
ans = 0

for i in range(n):
  S[i] = Counter(S[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())
a=[list(input()) for i in range(n)]
count=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        lst=a[i].copy()
        for element in a[j]:
            if element in lst:
                lst.remove(element)
        if len(lst)==0:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
alrdy = []
 
def is_anagrams(word1, word2):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(word1) == get_counter(word2)

dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
cnt = 0
while len(s) > 1:
  remove_list = []
  for i in range(len(s)-1):
    remove_list.append(i)
    for j in range(i+1, len(s)):
      if is_anagrams(s[i], s[j]):
        cnt += 1
        remove_list.append(j)
  s = dellist(s, remove_list)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations
N= int(input())
s = [''.join(sorted(list(input()))) for i in range(N)]
tmp = list(combinations(s,2))
result = [i for i in tmp if i[0] == i[1]]
print(len(result))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
c=[''.join(sorted(input())) for _ in range(n)]
x=[x for x in set(c) if c.count(x) > 1]
an=0

for i in x:
    t=c.count(i)
    for j in range(t):
        an+=j

print(an)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [list(input()) for _ in range(N)]
ans = 0
for i in range(N):
    S[i].sort()
print
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:
chars = ["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"]


def eratosthenes_sieve(n):
    primes = [2]
    for odd in range(3, n + 1, 2):
        for p in primes:
            if odd % p == 0:
                break
            if p ** 2 > odd:
                primes.append(odd)
                break
    return primes


n = int(input())
array = [None] * n
for i in range(n):
    new = input()
    var = 1

    for j in range(10):
        h = chars.index(new[j])
        var *= eratosthenes_sieve(150)[h]

    array[i] = var

ans = 0
pool = set(array)
for ele in pool:
    m = array.count(ele)
    ans += m * (m - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

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

hoge = 0
for i in range(N):
    hoge+=ls[i:N].count(ls[i])-1
print(hoge)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())

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

count = 0
for num, l in enumerate(list):
  for i in range(len(list)):
    if i == num:
      continue
    l_counter = Counter(l)
    n_counter = Counter(list[i])
    
    if l_counter == n_counter:
      count += 1

print(int(count/2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = []
for i in range(n):
  w = str(input())
  kusa = list(w)
  kusa.sort()
  lis.append(tuple(kusa))
syu = set(lis)
counter = 0
for d in syu:
  m = lis.count(d)
  counter += (m*(m-1))//2
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import collections

result=0
H = int(input())
S = []
for _ in range(H):
    S.append(collections.Counter(tuple(input())))  

for j in range(H):
    for i in range(j+1,H):
            if S[j] == S[i]:
                result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
dicts = [collections.Counter(input()) for _ in range(n)]
kotae = 0
for k, word in enumerate(dicts):
    for com_word in dicts[:k]:
        if word == com_word:
            kotae += 1
print(kotae)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_list = [''.join(sorted(input())) for _ in range(n)]
s_set = set(s_list)
cnt = 0
for s in s_set:
    cnt += sum(range(s_list.count(s)))
    s_list.remove(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
a = sys.stdin.readlines()

n = int(a[0])
ans = 0
now = 1

for i in a[1:n+1]:
    for j in a[now+1:n+1]:
        if sorted(i) == sorted(j):
            ans += 1
    now += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans=[]
for i in range(n):
    qw=input()
    ans.append([0,0,0,0,0,0,0,0,0,0])
    for j in range(10):
        ans[i][j]=qw[j]
    ans[i].sort()

ans.sort()
a=0
for i in range(n-1):
    for j in range(n-1-i):
        if ans[i]==ans[n-1-j]:
            a+=n-i-j-1
            break

print(int(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mylist = []
for s in l:
    s_list = [ c for c in s]
    mylist.append("".join(sorted(s_list)))

ans=0
for i in range(len(mylist)):
    ans += mylist.count(mylist[0]) - 1
    del mylist[0]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
sn=[input() for _ in range(N)]
def check(s1,s2):
  for c in s1:
    if s1.count(c)!=s2.count(c):
      return False
  else:
    return True
  
cnt=0
for i in range(len(sn)-1):
  for ii in range(i+1,len(sn)):
    if sn[i]==sn[ii]:
      cnt+=1
      continue
    if check(sn[i],sn[ii]):
      sn[ii]=sn[i]
      cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

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

ss = []
counts = []

chars = [x for x in "abcdefghijklmnopqrstuvwxyz"]
num = len(chars)

for i in range(N):
  ss.append(input().strip())
  _count = [0 for _ in range(num)]
  for _s in ss[i]:
    _count[chars.index(_s)] += 1
    
  counts += [_count]
  
answer = 0
  
for i in range(N):
  for j in range(i + 1, N):
    if counts[i] == counts[j]:
      answer += 1
    
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import json


from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n = int(input())
S = list()

A = list()
for _ in range(n):
  S.append(input())

for i in range(len(S)):
  hash = dict()
  for a in range(len(S)):
    for b in range(len(S[i])):
      hash[S[a][b]] = 0
  for j in range(len(S[i])):
    
    hash[S[i][j]] += 1
    
  A.append(hash)
  
count = 0
ddd = dict()
unique_list = list(map(json.loads, set(map(json.dumps, A))))
ans = 0

for dd in unique_list:
  if A.count(dd) > 1:
    ans += cmb(A.count(dd),2)

print(ans)

Submission status: Time Limit Exceeded

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

num = 0
for i in range(N):
    for j in range(i+1,N):
        if X[i] == X[j]:
            num += 1
        else:
            num += 0
print(num)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n=int(input())
s=deque([])
cnt=0
for _ in range(n):
    s.append(sorted(input()))
for i in range(n):
    for j in range(n):
        if i<j:
            if s[i]==s[j]:
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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


hits = 0
for i in range(n - 1):
  target = strings.pop()
  hits += sum(target == x for x in strings)

print(hits)

Submission status: Time Limit Exceeded

Solution code:
def C_GreenBin():
    N = int(input())
    s = []
    for x in range(N):
        s.append(sorted(input()))
    result = 0
    for x in range(N):
        s.sort()
    for i in range(0, N - 1):
        for j in range(i + 1, N):
            if s[i] == s[j]:
                result += 1
            else:
                break
    print(result)
    
if __name__ == "__main__":
    C_GreenBin()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

Submission status: Time Limit Exceeded

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

def group(idxs):
  idxs_r=[idxs[0],]
  for i in range(1,len(idxs)):
    if words[idxs[0]]==words[idxs[i]]:
      idxs_r.append(idxs[i])
  m=len(idxs_r)
  pairs=m*(m-1)/2
  
  for idx in idxs_r:
    idxs.remove(idx)
  
  return idxs,pairs

match=0
idxs=[int(i) for i in range(n)]

while len(idxs)>0:
  idxs,pairs=group(idxs)
  match+=int(pairs)

print(match)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
words = []
answer = 0

for i in range(num):
  words.append(sorted(list(input())))
words.sort(key=lambda x:x[0])
for i in range(num):
  q = 0
  for j in range(num -i - 1):
    p = 0
    out = 0
    if q >0 and words[i][0] != words[j + 1 + i][0]:
      break
    for k in range(10):
      if words[i][k] == words[j + 1 + i][k]:
        p += 1
      else:
        break
    if p == 10:
      answer += 1
      q += 1
    
print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = []
count = 0
for i in range(N):
    a += [''.join(sorted(input()))]
for i in range(N-1):
    for j in range(1, N):
        if i+j >= N:
            break
        if a[i] == a[i+j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# import numpy as np
# import copy

def main():

    n = int(input())
    s = []
    for i in range(n):
        s.append(input())
    count = 0
    for index,i in enumerate(s):
        i2 = [h for h in i]
        i2.sort()
        iss = ''.join(i2)
        for jindex,j in enumerate(s):
            if index == jindex:
                continue
            j2 = [h for h in j]
            j2.sort()
            js = ''.join(j2)
            if iss == js:
                count = count + 1


    print(int(count/2))
            
            
    

    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
	r = min(n-r,r)
	if r == 0: return 1
	over = reduce(mul, range(n, n - r, -1))
	under = reduce(mul, range(1,r + 1))
	return over // under

#from math import factorial

if __name__ == "__main__":
	n=int(input())
	string_list=[]

	for _ in range(n):
		rel = sorted(list(input()))
		string_list.append(''.join(rel))
	    
	string_distinct = set(string_list)
	idx = 0
	for item in string_distinct:
		s_count = string_list.count(item)
		if s_count > 1:
			idx += cmb(s_count,2)
	print(idx)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
ans = 0
s = []
N = int(input())
for i in range(N):
	tmp = []
	string = input()
	for st in string:
		tmp.append(st)
	s.append(tmp)

for m in s:
	for n in s:
		if Counter(n)==Counter(m) and m != n:
			ans+=1
print(int(ans/2))

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
    
cnt = 0
s = []
tmp = []
n = int(input())
for i in range(n):
    string = input()
    string = ''.join(sorted(string))
    s.append(string)

for i, e in enumerate(s):
    """
    要素が何個あるか検査　AND　tmpにないやつ
    ・１：なにもしない
    ・2以上：個数調べてCNT更新。その要素をtmpに記録する
    """
    count = s.count(e)
    if count > 1 and not e in tmp:
        cnt += cmb(count, 2)
        tmp.append(e)
print(cnt)

Submission status: Time Limit Exceeded

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

from collections import Counter
#from collections import defaultdict

s_multisets = []
for i in range(N):
    s_multisets.append(Counter(s[i]))

cnt = 0
d = dict([(k,v) for k, v in zip(range(N), [set(range(i+1, N)) for i in range(N)])])
for i in range(N):
    #d[i] = Counter(s[i])
    jrange= d[i]
    s_eq = set()
    s_neq = set()
    for j in jrange:
        if s_multisets[i] == s_multisets[j]:
            s_eq.add(j)
            cnt += 1
        else:
            s_neq.add(j)
    for k in s_eq:
        d[k] = d[k] - s_neq

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections

result=0
H = int(input())
S = []
for _ in range(H):
    S.append(collections.Counter(tuple(input())))  

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力


def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))


def process(n, s):
    count = 0
    for i in range(0, n):
        for k in range(i, n):
            if i == k:
                continue
            if anagram(s[i], s[k]) == True:
                count += 1
    return count


# def anagram(a, b):
#     for i in a:
#         if i in b:
#             b = b.replace(i, '')
#             continue
#         else:
#             return False
#     return True

def anagram(a, b):
    return sorted(a) == sorted(b)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
T = []
for i in range(N):
  S.append(str(input()))
for j in range(N):
  T.append(''.join(sorted(S[j])))
count = 0
for k in range(N):
  for m in range(k+1,N):
    if T[k]==T[m]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
from functools import reduce
from operator import mul

input = sys.stdin.readline


# def c(num):
#     return reduce(mul, range(1, num + 1))
def cmb(n, r):
    r = min(n - r, r)
    if r <= 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def main():
    n = int(input())
    lines = ["".join(sorted(input().strip())) for _ in range(n)]
    count = 0
    for text in set(lines):
        txt_cnt = lines.count(text)
        if txt_cnt == 1:
            continue
        count += cmb(txt_cnt, 2)
    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [0]*N
p = [0]*N
for i in range(N):
    s[i] = "".join(sorted(input()))
    for j in range(i-1,-1,-1):
        if s[i] == s[j]:
            p[i] = p[j] + 1
            break

print(sum(p))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 21:22:42 2019

@author: doppe
"""
import copy
import math


def isAnagram(dict, str2):
    dictCopy = copy.copy(dict)
    for c2 in str2:
        if (c2 in dictCopy):
            dictCopy[c2] -= 1
            if (dictCopy[c2] < 0):
                return False
        else:
            return False
    return True
 
def makeDict(str1):
    dict = {}
    for c in str1:
        if (c in dict):
            dict[c] += 1
        else:
            dict[c] = 1
    return dict

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}
for i in range(0, len(S)):
    if (i in groupList):
        continue
    dict = makeDict(S[i])
    for j in range(i + 1, len(S)):
        if (j in groupList):
            continue
        if (isAnagram(dict, S[j])):
            groupList.append(j)
            if (i in groupDict):
                groupDict[i] += 1
            else:
                groupDict[i] = 2

for v in groupDict.values():
    ans += (v * (v - 1)) / 2

print(int(ans))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ch = []
for i in range(N):
    ch.append(''.join(sorted(list(input()))))
cnt = 0
ch = sorted(ch)
tmp = 0
for i in range(N):
    for j in range(i+1,N):
        if ch[i]==ch[j]:
            cnt += 1
        else:
            tmp = j
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    count = 0
    lists =[]

    for i in range(n):
        input_data = ''.join(sorted(input()))
        if input_data in lists:
            count = count + lists.count(input_data)
            lists.append(input_data)
        else:
            lists.append(input_data)

    print(count)


if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main():

    N = int(input())
    sList = [Counter(list(input())) for _ in range(N)]
    ans = 0

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

    print(ans)


    
if __name__== "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

slist = []
for h in range(n):
  slist.append(input())

newlist = []
word=[]
wordy = ""
for i in range(n):
  word = list(slist[i])
  word.sort()
  for jk in range(len(word)):
	  wordy = wordy+word.pop()
  newlist.append(wordy)
  wordy=""
new2list = sorted(newlist)

count= 0
for j in range(n-1):
  k = j+1
  while (new2list[j] == new2list[k]):
    count += 1
    k += 1
    if k == n:
      break

print(count)

Submission status: Time Limit Exceeded

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


cnt = 0
set_list = set(s)
for i in set_list:
    num = s.count(i)
    tmp = num * (num - 1) / 2
    cnt += tmp

print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
def fac(n):
  s = 1
  for i in range(1, n+1):
    s = s*i
  return s

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

N = int(input())
S = []
ans = 0
n = 1

for i in range(N):
  s = list(input())
  s.sort()
  
  S.append(s)
  
S.sort()

for i in range(N-1):
  if S[i] == S[i+1]:
    n += 1
  elif n >= 2:
    ans += cmb(n,2)
    n = 1
  else:
    n = 1
  
if S[N-1] == S[N-2]:
  ans += cmb(n,2)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
words = [Counter(input()) for _ in range(N)]
ans = 0
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

counters_counts = [words.count(x) for x in get_unique_list(words) if words.count(x) > 1]

for count in counters_counts:
    ans += int((count * (count-1)) / 2)
print(ans)