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:
def create_anagram_dic(val):
  dic = {}
  for s in val:
    if s not in dic:
      dic[s] = 0
    dic[s] += 1
  
  return dic

def is_anagram(val, dic):
  for k, v in dic.items():
    if val.count(k) != v:
      return False
  return True

N = int(input())

s = list()
for i in range(0, N):
  val = str(input())
  s.append(val)
  
  
result_dic = {}

while len(s) > 0:
  current_val = s[0]
  result_dic[current_val] = 1
  dic = create_anagram_dic(current_val)
  for i in range(len(s) - 1, 0, -1):
    if is_anagram(s[i], dic):
      result_dic[current_val] += 1
      s.pop(i)
  s.pop(0)

result_count = 0
for val in result_dic.values():
  result_count += val * (val - 1) // 2

print(result_count)

Submission status: Time Limit Exceeded

Solution code:
import collections as c
n = int(input())
s = [sorted(input()) for _ in range(n)]

cnt = 0
for i in range(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())
abc = [chr(i) for i in range(97, 97+26)]
ss = []
ct = []
ans = 0

for i in range(N):
    s = input()
    cnt = []
    for j in abc:
        num = s.count(j)
        cnt.append(num)
    if not cnt in ss:
        ss.append(cnt)
        ct.append(1)
    else:
        ct[ss.index(cnt)] += 1

for i in range(len(ct)):
    if ct[i] > 1:
        ans += int((ct[i] * (ct[i] - 1))/2)


print(ans)

Submission status: Time Limit Exceeded

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

count = 0

for i in range(num):
  for j in range(num):
    if i != j:
      if lists[i] == lists[j]:
        count += 1
 
print(int(count/2))

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=[]
cnt=0
for i in range(N):
    s.append(input())
s=list(map(sorted,s))
def get_duplicate_list(seq):
    seen = []
    return [x for x in seq if not seen.append(x) and seen.count(x) == 2]
s2=get_duplicate_list(s)
for j in s2:
    cnt+=combinations_count(s.count(j),2)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [input() for _ in range(n)]
mst = set((list("".join(l))))
l = [[x.count(a) for a in mst] for x in l]
result = 0
for i in range(n-1):
    result += l[i+1:].count(l[i])
print(result)

Submission status: Time Limit Exceeded

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

sorted_S = []    
for i in range(H):
  sorted_S.append("".join(sorted(S[i])))

cnt = 0
for i in range(H):
  for j in range(i+1, H):
   if sorted_S[i] == sorted_S[j]:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
slist = [sorted(input()) for _ in range(N)]
scnt = [slist[:i].count(slist[i]) for i in reversed(range(N))]

print(sum(int(_) for _ in scnt))

Submission status: Time Limit Exceeded

Solution code:
import string

N = int(input())

CountList = []

atoz = string.ascii_lowercase
for i in range(N):
    temp = ''
    s=input()
    CountList.append(''.join(sorted(s)))

lis = set(CountList)

count = 0

for str in lis:
    strcount = CountList.count(str)
    count += sum(range(strcount))

print(count)

Submission status: Time Limit Exceeded

Solution code:
 
n = int(input())
a = {}
for i in range (0, n):
    s = input()
    s = sorted(list(s))
    s = ''.join(s)
    try:
        a[s] += 1
    except:
        a.update({s : 1})
    ans  = 0
    for i in a:
        t = a[i] - 1;
        if(t > 0):
            ans += (1 + t) * t // 2
print(ans)

Submission status: Time Limit Exceeded

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

alp=[chr(_) for _ in range(97,97+26)]
res=[0]*n
ans=0

for j in range(n):
    ll=list(l[j])
    ll.sort()
    aa="".join(ll)
    tmp2=0
    for z in res:
        if aa==z:
            tmp2+=1
    ans+=tmp2
    res[j]=aa
 
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

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
count_list=[]
for item in string_distinct:
	
	
	s_count = string_list.count(item)
	if s_count > 1:
#		idx += (2 * s_count - 1)
		idx += factorial(s_count) // factorial(2) // factorial(s_count - 2)
		count_list.append(item)
print(idx)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

ls = []

for n in range(N):
  i = input()
  ls.append(''.join(sorted(i)))

count = 0

for i in range(N):
  an = ls[i]
  for j in range(i+1, N):
    if an == ls[j] :
      count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input()) 
t=[[0]*10]*N
y=[[0]*10]*N

for i in range(N):
  s=input()
  for j in range(10):
    t[i][j]=s[j]
  y[i]=sorted(t[i])

y.sort()

count=0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
for i in range(n):
  s.append("".join(sorted(input())))
ss=set(s)
ans=0
for _ in ss:
  l=s.count(_)
  ans+=l*(l-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N=int(input())

str_array = [input() for i in range(N)]
  
alpha2num = lambda c: ord(c) - ord('a')

array=np.zeros((N,26))

for i in range(N):
    for char in str_array[i]:
        array[i,alpha2num(char)]+=1

count=0
for j in range(N-1):
        count+=np.sum(np.all(array[j:]==array[j],axis=1))-1
    
print()
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

def main():
    n = int(input())
    c = [[] for i in range(n)]
    count = 0
    lists =[]

    for num in range(n):
        c[num] = input()
        c[num] = ''.join(sorted(c[num]))

    for i in c:
        if i in lists:
            count = count + lists.count(i)
            lists.append(i)
        else:
            lists.append(i)

    print(count)


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

n=int(input())
ls=[]
for _ in range(n):
    ip=list(input())
    ip.sort()
    a="".join(ip)
    ls.append(a)
ls.sort()
cnt=0
b=0
i=0
al=[]
while 1:
    b=ls[i] 
    cnt=ls.count(b)
    if cnt>=2:
        i+=cnt
        x=cmb(cnt,2)
        al.append(x)
    else:
        i+=1
    if i==n:
        break
ans=sum(al)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections as c
n = int(input())
s = [input() for _ in range(n)]

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

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
from itertools import combinations

ans = 0
N = int(input())

S = list()
for n in range(N):
  S.append(sorted(Counter(input()).items(), key=lambda x:x[0])) 
  
for (i, j) in combinations(range(N), 2):
  if S[i] == S[j]:
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:

N=int(input())
li=[]
for i in range(N):
  li.append(input())
count=0
from collections import Counter
 
def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)
for i in range(N):
  for j in range(i+1):
    if i != j:
      if verify_anagrams(li[i],li[j]):
        count+=1
print(count)

Submission status: Time Limit Exceeded

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


cnt = 0
for i in range(len(s)):
    tmp = s[i+1:].count(s[i])
    cnt += tmp

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
s = list(map(sorted,s))
score = 0
for j in range(len(s)-1):
    score += s[j+1:].count(s[j])
print(score)

Submission status: Time Limit Exceeded

Solution code:
import copy


def main():
    n = int(input())
    s = [["" for j in range(10)] for i in range(n)]
    for i in range(n):
        s[i] = list(input())

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

    print(cnt)


def anagram(list1, list2):
    if not list1:
        return True

    if list1[0] in list2:
        list2.remove(list1[0])
        list1.pop(0)
        return anagram(list1, list2)
    else:
        return False


def count_anagram(s, str_list):
    cnt = 0
    for t in str_list:
        u, v = copy.copy(s), copy.copy(t)
        if anagram(u, v):
            cnt += 1
    return cnt


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
count = sum([sum([s[i] == si for si in s[i+1:]]) for i in range(n)])
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = []
count = 0
for i in range(N):
    a += [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:
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]:
            try:
                lst.remove(element)
            except ValueError:
                pass
        if len(lst)==0:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]

S.sort()

ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)

Submission status: Time Limit Exceeded

Solution code:

def anagram(str1, str2):
    str1List = list(str1)
    str2List = list(str2)

    str1List.sort()
    str2List.sort()

    anagramFlg = 1

    for i in range(len(str1List)):
        if str1List[i] != str2List[i]:
            anagramFlg = 0
            break

    return anagramFlg


n = int(input())

inputList=[]
for i in range(n):
    line = input()
    inputList.append(line)

# print(inputList)

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[]
A=0

for i in range(N):
  d=sorted(str(input()))
  if d in L:
    A+=L.count(d)
  L.append(d)

print(A)

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:
from collections import Counter

# def create_count_dic(text):
#     count_dic = {}
#     for t in text:
#         if t in count_dic:
#             count_dic[t] += 1
#         else:
#             count_dic[t] = 1
#     return count_dic

def is_anagram(text1, text2):
    # text1_dic = create_count_dic(text1)
    # text2_dic = create_count_dic(text2)
    if Counter(text1) == Counter(text2):
        return True
    else:
        return False

N = int(input())
S = [input() for x in range(N)]
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def factorial(i):
    ans = 1
    for j in range(1,i+1):
        ans *= j
    return ans
N = int(input())
A = [input() for i in range(N)]
a = []
for i in A:
    b = list(i)
    b.sort()
    a.append(b)

a.sort()
c = list(map(list, set(map(tuple, a))))
d=[]
for i in c:
    if a.count(i)==1:
        continue
    d.append(a.count(i))
count=0
for i in d:

    if i>2:
        count += factorial(i) // (factorial(i - 2) * factorial(2))
    elif i ==2:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

tmp = []
counter = 0
for i in range(N):
    new_str = ''.join(sorted(str(input()))) 
    tmp.append(new_str)
    counter += tmp.count(new_str)

#new_str_list = [i for i in new_str = ''.join(list(sorted(str(input()))))]
#print(new_str_list)

    #for j in range(i):
    #    if str(new_str) == str(tmp[j]):
    #        counter += 1

print(counter-len(tmp))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
word_list = []
ans = []
condition = True

for i in range(0, n):
  word_list.append(sorted(list(input()))) #すべての単語をソートし、リスト化
  
while condition:
  c = word_list.count(word_list[0]) #リストの先頭と一致する要素の個数
  ans.append(int(c * (c-1)/2)) #c個から2つ選ぶ組み合わせ。
  word_list = [i for i in word_list if word_list[0] != i]
  if len(word_list) <= 1:
    condition = False

print(sum(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 += sum([1 if x==ls[i] else 0 for x in ls[i:N]]) - 1
print(hoge)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
b = [''.join(sorted(input())) for i in range(n)]
c = list(set(b))
ans = 0
for i in c:
  d = b.count(i)
  if d >1:
    ans += d*(d-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
f=["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"]
g=[]
for p in range (0,a):
    b=input()
    h=[0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,0,0,0,0,0,0,0,0,0,0,0,0]
    for q in range (0,10):
        c=b[q]
        for r in range (0,26):
            if c==f[r]:
                h[r]+=1
    g.append(h)

i=tuple(g)


x=0
for s in range (0,a):
    for t in range (s,a-1):
        g=list(i)
        k=g.pop(s)
        l=g[t]
        if k==l:
            x+=1
    g=list(i)
print(x)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S = []
A = []
from collections import Counter

for _ in range(N):
    S.append(input())
L=[]
for s in S:
  L.append(Counter(s))

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

chars = []
cnt = 0

for _ in range(n):
  chars.append(''.join(sorted(list(input()))))
  
for i in range(n):
  cnt += chars[i+1:].count(chars[i])
  
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# K,X = list(map(int, input().split()))

import numpy as np

N = int(input())

mat = np.zeros(N)
alphabet = "abcdefghijklmnopqrstuvwxyz"

for i in range(N):
    word = input()
    for s in word:
        mat[i] += 2**alphabet.index(s)
# print(mat)
ans = 0
for i in range(N):
    for j in range(i+1, N):
        # print(mat[i])
        # print(mat[j])
        # print("{}, {}".format(i,j))
        # print(mat[i] - mat[j])
        if mat[i] - mat[j] == 0:
            # print(i)
            # print(j)
            # print()
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int( input() )

judge_nums = []
for i in range( n ):
	judge_num = 10**27 # 一桁目はフェイク
	str = input()
	for s in str :
		judge_num += 10**(ord( s )-97)
	judge_nums.append( judge_num )
judge_nums = sorted( judge_nums )


count = 0
for i in range( n ) :
	bFound = False
	for j in range( i+1, n ) :
		if judge_nums[i] != judge_nums[j] :
			break
		if judge_nums[i] == judge_nums[j] :
			count += 1
			bFound = True

print( count )

Submission status: Time Limit Exceeded

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


def cmb(n,r):
    if n == 1: return 0
    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())
    s = [''.join(sorted(input())) for i in range(n)]
    s_set = set(s)

    ans = 0
    if len(s_set) == len(s):
        print(ans)
        sys.exit()

    for i in s_set:
        ans += cmb(s.count(i), 2)

    print(ans)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math


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


def main():
    N = int(stdin.readline())
    s = [stdin.readline().rstrip().split() for _ in range(N)]

    s_flat = [flatten for inner in s for flatten in inner]

    a = []
    b = set()
    sum = 0

    for S in s_flat:
        new_S = ''.join(sorted(S))
        a.append(new_S)
        b.add(new_S)

    for X in b:
        if a.count(X) == 1:
            pass
        else:
            sum += combinations_count(a.count(X), 2)

    print(sum)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = []
count = 0
for i in range(N):
    a += [sorted(input())]
for i in range(N):
    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:
N = int(input())
my_list = [None] * N
for i in range(N):
    s_i = sorted(list(input()))
    my_list[i] = s_i
sum = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        for k in range(10):
            if not(my_list[i][k] == my_list[j][k]):
                break
            elif k == 9:
                sum += 1
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = [input() for i in range(n)]
count = 0
for i in range(len(s)):
    che = Counter(s[i]) 
    for t in s[i+1:]:
        if che == Counter(t):
            count+=1
print(count)

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)):
    for j in range(i+1, len(mylist)):
        if mylist[i] == mylist[j]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def f(si, sj):
    for i in range(10):
        if si.count(sj[i]) != sj.count(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())
s = []
for i in range(n):
  s.append(sorted(list(input())))
cnt = 0
while s != []:
  ss = s.pop(0)
  k = s.count(ss)
  cnt += k * (k+1) // 2
  while ss in s:
    s.remove(ss)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [['n' for i in range(10)] for j in range(n)]
for i in range(n):
    s[i]=list(input())
    s[i].sort()
j=0
ans=0
for i in range(n):
    j=n-1
    while j>i:
        if s[i]==s[j]:
            ans = ans + 1
        j=j-1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [sorted(input()) for i in range(N)]
count = 0
for n in range(N):
    ss = s[n]
    for nn in range(n + 1, N):
        if ss == s[nn]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
l = ["".join(sorted([c for c in input()])) for i in range(N)]
l.sort()


def fac(n):
    """階乗"""
    res = 0
    for i in range(1, n+1):
        res += i
    return res

hash_t = {}
for i in range(N-1):
    if l[i] == l[i+1]:
        if l[i] in hash_t.keys():
            hash_t[l[i]] += 1
        else:
            hash_t[l[i]] = 1

cnt = 0
for x in hash_t.values():
    cnt += fac(x)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N=int(input())

str_array = [input() for i in range(N)]
  
alpha2num = lambda c: ord(c) - ord('a')

array=np.zeros((N,26))

for i,sent in enumerate(str_array):
    for char in sent:
        array[i,alpha2num(char)]+=1

count=0
for j in range(N-1):
        count+=np.sum(np.all(array[j:]==array[j],axis=1))-1
    
print()
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [list(map(str, input().split())) for i in range(N)]

for i in range(N):
    S[i] = list(str(S[i]))
    S[i] = sorted(S[i])

count = 0
for k in range(N-1):
    for j in range (k+1,N):
        if S[k] == S[j]:
            count = count + 1
        else:
            pass
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = 0
list1 = [list(input()) for i in range(N)]
for j in range(N):
    list1[j].sort()
else:
    list1.sort()
    for k in range(0,N-1):
        for l in range(k+1,N):
            if list1[k] == list1[l]:
                a += 1
            else:
                break
print(a)

Submission status: Time Limit Exceeded

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

for i in range(n):
  s[i] = ''.join(map(str, sorted(s[i])))

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 = input()
n = int(n)
count = 0
word = []

for i in range(n):
    word.append(input())

for i in range(n - 1):    
    master = list(word[i])
    for j in range(i + 1, n):
        target = list(word[j])
        for k in range(len(master)):
            l = 0
            while l < len(target):
                if master[k] == target[l]:
                    target.pop(l)
                    break
                l += 1
        if len(target) == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s=[]
for i in range(n):
    s.append(input())
list_s = []
for j in range(n):
    list_s.append(sorted(list(s[j])))
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
unique_list = get_unique_list(list_s)
ans = []
for k in range(len(unique_list)):
    count = 0
    for l in range(n):
        if unique_list[k] == list_s[l]:
            count += 1
    ans.append(count * (count-1) // 2)

print(sum(ans))

Submission status: Time Limit Exceeded

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

for i in range(len(S)):
    a = sorted(S[i])
    S[i] = ''.join(a)

S_unq = set(S)
num_list = []

for i in S_unq:
    num = S.count(i)
    num_list.append(num)

dup_list = [i for i in num_list if i > 1]
dup_num = 0
for i in dup_list:
    b = (i * (i - 1)) / 2
    dup_num += b

print(int(dup_num))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools
N=int(input())
S=[]
for i in range(N):
    s="".join(sorted(list(input())))
    S.append(s)
c=Counter(S).most_common()
ans=0
for i in range(len(c)):
    if c[i][1]>1:
        ans+=len(list(itertools.combinations(range(c[i][1]), 2)))
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import math

n = int(input())
s = [input() for _ in range(n)]
ans = 0
while len(s) > 0:
    count = 1
    si = Counter([x for x in s[0]])
    j = 1
    while j < len(s):
        if si == Counter([x for x in s[j]]):
            count += 1
            s.pop(j)
        else:
            j += 1
    if count > 1:
        ans += math.factorial(count) // (2 * math.factorial(count-2))
    s.pop(0)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import copy


def main():
    n = int(input())
    s = [["" for j in range(10)] for i in range(n)]
    for i in range(n):
        s[i] = list(input())

    cnt = 0
    for i in range(n):
        cnt += count_anagram(s[i], copy.copy(s[i+1: n]))

    print(cnt)


def anagram(list1, list2):
    if not list1:
        return True

    if list1[0] in list2:
        list2.remove(list1[0])
        list1.pop(0)
        return anagram(list1, list2)
    else:
        return False


def count_anagram(s, str_list):
    cnt = 0
    for t in str_list:
        u, v = copy.copy(s), copy.copy(t)
        if anagram(u, v):
            cnt += 1
    return cnt


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

i=0
sortedSet=[]
result=0
while i<N:
  temp=''.join(sorted(input()))
  sortedSet.append(temp)
  j=0
  while j<i:
    if sortedSet[j]==temp:
      result=result+1
    j=j+1
  i=i+1

print(result)

Submission status: Time Limit Exceeded

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

for i in range(N):
    os[i] = "".join(sorted(s[i]))
#print(os)
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        #print(dicts[i], dicts[j])
        if os[i] == os[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

## a-zの文字が各文字列でそれぞれ何度出てくるか数える
## 26要素を持つリストが複数できて、リストの中身の完全一致回数を求める

AtoZlist = [chr(i) for i in range(97,97+26)]
countlist = []
for l in range(N):
    countlist.append([])

for i in AtoZlist:
    for k in S:
        ci = k.count(i)
        countk = S.index(k)
        countlist[countk].append(ci)

answer = 0
for x in range(N):
    for y in range(N):
        if x >= y:
            continue
        elif countlist[x] == countlist[y]:
            answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
r = [0]*10**5
res = 0

for i in range(n):
    an = list(input())
    an.sort()
    an = "".join(map(str, an))
    #print(an)
    if an not in l:
        l.append(an)
    r[l.index(an)] += 1

for i in r:
    for j in range(i-1,0,-1):
        #print(j)
        res += j
else:
    print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [input() for i in range(n)]
char = [chr(97+i) for i in range(26)]
char_list = [[m.count(c) for c in char] for m in l]

t = [[a, b] for a in range(n) for b in range(a+1, n) if (char_list[a] == char_list[b])]
print(len(t))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
for i in range(n):
  t=list(input())
  t.sort()
  l.append(t)
l.sort()
length=len(l)
count=0
a=0
while True:
  if a>=length:break
  c=l.count(l[a])
  if c == 0:
    a+=1
    continue
  else:
    t=0
    for i in range(1,c):
      count+=i
    a+=c
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
str_list = [input() for i in range(n)]
ans = 0
from collections import Counter
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
    if get_counter(first_word) == get_counter(second_word):
      return 1
    else:
      return 0
for i in range(n):
  for j in range(n-i-1):
    ans += verify_anagrams(str_list[i], str_list[j+i+1])
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

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

for _ in range(n):
	rel = sorted(list(input()))
	string_list.append(''.join(rel))
    
#string_distinct = set(string_list)
#print(len(string_list) - len(string_distinct))
idx = 0
count_list=[]
for item in string_list:
	
	if item in count_list:
		continue
	
	s_count = string_list.count(item)
	if s_count > 1:
#		idx += (2 * s_count - 1)
		idx += factorial(s_count) // factorial(2) // factorial(s_count - 2)
		count_list.append(item)
print(idx)