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())
list = ["".join(sorted(input())) for i in range(N)]
count = 0
res = [[e, list.count(e)] for e in set(list) if list.count(e) > 1]
for r in res:
    count += (r[1] * (r[1] - 1)) / 2

print(int(count))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


N = int(input())
s_list = [Counter(list(input())) for _ in range(N)]
count = 0
skip_n = []
for i in range(N):
  if i in skip_n:
    continue

  tmp_count = 0
  for j in range(i + 1, N):
    if s_list[i] == s_list[j]:
      tmp_count += 1
      skip_n.append(j)
  count += int((tmp_count+1)*tmp_count/2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)

    return len(result)


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)):
        if list_difference(a[i],a[j])==0:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n   = int(input())
dic = {chr(j):i for i,j in enumerate(range(97, 97+26))}
input_list = np.ones((int(n),26)) * 1000
count = 0
for i in range(n):
    input_vec   = np.zeros(26)
    for j in input():
        input_vec[dic[j]] += 1
    count += (1 - ((input_list - input_vec)**2).sum(1).astype(np.bool)).sum()
    input_list[i] = input_vec
print(count)

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):
  first = Counter(str_list[i])
  for j in range(n-i-1):
    second = Counter(str_list[j+i+1])
    if first == second:
      ans +=1
print(ans)

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0

l = []

for _ in range(n):
    s = sorted(input())
    for le in l:
        if le == s:
            ans += 1

    l.append(s)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def green_bin(n,s):
    count = 0
 
    x = [sorted(i) for i in s]
    _x = sorted(x)
 
    for i in range(n-1):
        for j in range(i+1,n):
            if _x[i] == _x[j]:
                count += 1
            else:
                break
 
    return count
if __name__ == '__main__':
    n = int(input())
    s = [ input() for i in range(n)]
 
    print(green_bin(n,s))

Submission status: Time Limit Exceeded

Solution code:
#coding utf-8

n = int(input())

ans = 0
s = list()

class node:
    def __init__(self,s):
        self.s = s
        self.n = 1
    def add(self):
        self.n += 1

for i in range(n):
    tmp = list(input())
    tmp.sort()
    st = ''.join(tmp)
    n = node(st)
    # print(tmp)

    shuoldApped = True
    for j in s:
        if j.s == st:
            ans += 1 * j.n
            j.add()
            shuoldApped = False
            break;
    
    if shuoldApped:
        s.append(n)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [''.join(sorted(input())) for i in range(N)]
a_unique = set(a)
b = 0
for i in a_unique:
    c = a.count(i)
    b = b + c * (c - 1) / 2
print(int(b))

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
s = ["".join(sorted(input())) for i in range(n)] 
count = 0
for i in range(n-1):
  if s[i] in s[i+1:n]:
    count += s[i+1:n].count(s[i])
print(int(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-1):
    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:
import math
def is_anagram(string1, string2):
  for a in string1:
    if a not in string2:
      return False
    string2 = string2.replace(a, "", 1)
  if len(string2) == 0:
    return True
  else:
    return False

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())
strings = []
anagrams_num = []
for i in range(N):
  string = ''.join(sorted(input()))
  try:
    anagram_index = strings.index(string)
    anagrams_num[anagram_index] += 1
  except:
    strings.append(string)
    anagrams_num.append(0)

ans = 0
for anagram_num in anagrams_num:
  if anagram_num > 0:
    ans += int(cmb(anagram_num+1,2)) 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
count = -N
List = [[c for c in input()] for i in range(N)]
for j in List:
  for k in List:
    if sorted(j) == sorted(k):
      count += 1
print(int(count/2))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
strl=[list(input()) for i in range(n)]
"""
def anagram(sa,sb) :
  flag=True
  sal=list(sa)
  sbl=list(sb)
  sal.sort()
  sbl.sort()
  if sal==sbl:
    return True
  else :
    return False
  
  for i in range(10) :
    if sal[i] in sbl :
      sbl.remove(sal[i])
    else :
      flag=False
      break

  """
  #return flag
   
#print(anagram("peanutbomb","constraint"))    
count=0
for i in range(n) :
  jl=list(range(i+1,n))
  for j in jl :
    flag=True
    sal=strl[i]
    sbl=strl[j]
    sal.sort()
    sbl.sort()
    if sal==sbl:
      count+=1
    """
    flag=True
    sal=list(strl[i])
    sbl=list(strl[j])
    for k in range(10):
      tmp=sal[k]
      if tmp in sbl :
        sbl.remove(tmp)
      else :
        flag=False
        break
     
    if flag :
      count+=1
    """
print(count)

Submission status: Time Limit Exceeded

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

for l in range(N):
    S[l] = list(str(S[l]))
    S[l] = sorted(S[l])
S = sorted(S)
count = 0
for i in range(N-1):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            count = count + 1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

# alp = ["a","b","c","d","e",
# "f","g","h","i","j",
# "k","l","m","n","o",
# "p","q","r","s","t",
# "u","v","w","x","y","z"]
# 
ans = 0
# array1 = np.zeros().reshape( n,10)


# list1 = []
list_s = []

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

list_s = list(map(sorted, list_s))

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

print(int(ans/2))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as counter
from sys import stdin 

N = int(stdin.readline().rstrip())
char_counts = [sorted(stdin.readline().rstrip()) for _ in range(N)]
counts = [list(map(lambda x: x == c, char_counts[i+1:]))  for i, c in enumerate(char_counts)]
match_count = sum(list(map(sum, counts)))
print(match_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

literals = [[0]*26 for _ in range(N)]

for i in range(N):
    word = input()
    for char in word:
        literals[i][ord(char) - 97] += 1

answer = 0
for i in range(N):
    target = literals.pop()
    answer += literals.count(target)

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = ['']*N
ans = 0
for i in range(N):
    s[i] = sorted(input())
    if i != 0:
        for j in range(i):
#            print(i, j)
            if s[i] == s[j]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
    a = []
    for j in range(10):
        a.append(lst[i][0][j])
    counter.append(a)

for j in range(N):
    counter[j].sort()

cnt = 0

for k in range(N-1):
    for l in range(k+1, N):
        if counter[k] == counter[l]:
            cnt += 1
        else:
            continue
            
print(cnt)

Submission status: Time Limit Exceeded

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

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
    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 as ct

N = int(input())
s = []
k = []
a = 0

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

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

print(a)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []

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

counter = 0
for n in range(N):
    for m in range(n + 1, N):
        if len(S[n]) == len(S[m]):
            S[n].sort()
            S[m].sort()
            if S[n]== S[m]:
                counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
ns = []
ans = 0
for i in range(len(s)):
    if ns.count(s[i]) == 0:
        aas = s.count(s[i])
        if aas > 0:
            ns.append(s[i])
        for j in range(1, aas):
            ans += j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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:
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


era = eratosthenes_sieve(150)

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 *= era[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:
import itertools

def comb(n, r):
    return len(list(itertools.combinations(range(n), r)))

n = int(input())
s = []
for i in range(n):
    sin = input()
    sin = list(sin)
    sin.sort()
    sin = ''.join(sin)
    s.append(sin)

ss = set(s)
count = 0
for u in ss:
    al = s.count(u)
    count += comb(al, 2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

L = []
for i in range(N):
    L.append(sorted(input().strip()))

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

print(Sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for _ in range(n)]
# 文字列そのものをアルファベット順に並び替え
s = ["".join(sorted(a)) for a in s]
count = 0
for i in range(n):
    for j in range(i, n + 1):
        if j == n - 1:
            break
        if s[i] == s[j + 1]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

for i in range(0, n):
  word = sorted(list(input()))
  word_list.append(word)
  
while len(word_list) > 1:
  c_word = word_list[0]
  c = word_list.count(c_word)
  ans += int(c * (c-1)/2)
  while c_word in word_list:
    word_list.remove(c_word)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
#S = [input() for i in range(N)]
S=[]
firstalpha=[]
ans_list = []
temp_ans = 1
ans = 0

for i in range(N):
    temp = sorted(list(input()))
    S.append(''.join(temp))
    #firstalpha.append(temp[0])
    
set_S = set(S)

for s in set_S:
    a = S.count(s)
    ans += a*(a-1)/2

print(round(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):
    cnt += s.count(s[i]) - 1
    s[i] = "COUNTED{}".format(i)
print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
ans = 0

l = []

for _ in range(n):
    s = collections.Counter(input())
    for le in l:
        if le == s:
            ans += 1

    l.append(s)

print(ans)

Submission status: Time Limit Exceeded

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

n=int(input())
s=deque([])
cnt=0
for _ in range(n):
    s.append(sorted(deque(list(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:
def green_bin(n,s):
    count = 0

    x = [sorted(i) for i in s]
    _x = sorted(x)

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

    return count
if __name__ == '__main__':
    n = int(input())
    s = [ input() for i in range(n)]

    print(green_bin(n,s))

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(''.join(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:
def main():
    n = int(input())
    count = 0
    lists =[]
    count_dict = {}

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

    print(count)


if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:

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

N = int(input())
S = [create_count_dic(input()) for x 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:
# -*- coding: utf-8 -*-
N = int(input())
a = []
count = 0
for i in range(N):
    a += [''.join(sorted(input()))]
sorted_a = sorted(a)
for i in range(N-1):
    for j in range(1, N):
        if i+j >= N:
            break
        if sorted_a[i] == sorted_a[i+j]:
            count += 1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int( input() )

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


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

print( count )

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [''.join(sorted(list(input()))) for i in range(N)]
a_unique = set(a)
b = 0
for i in a_unique:
    c = a.count(i)
    b = b + c * (c - 1) / 2
print(int(b))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
lst = []
lstn = [] 
cnt = 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.append(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:
N = int(input())
s = ['']*N
ans = 0
for i in range(N):
    s[i] = ''.join(sorted(input()))
    if i != 0:
        for j in range(i):
#            print(i, j)
            if s[i] == s[j]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for _ in range(N):
  a = str(input())
  alist = list(a)
  s.append(sorted(alist))
  
cnt = 0
while len(s) > 1:
  same = 0
  s1 = s.pop()
  same = s.count(s1)
  if same != 0:
    cnt += (same+1) * same / 2
    while s1 in s:
      s.remove(s1)

print(int(cnt))

Submission status: Time Limit Exceeded

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

su=[]
for i in s:
    shu=sorted(list(i))
    su.append("".join(shu))


count=0
while len(su)>1:
  j=su[0]
  del su[0]
  c=su.count(j)+1
  count+=c*(c-1)/2
  su=[i for i in su if i!=j]
  
print(int(count))

Submission status: Time Limit Exceeded

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

s=[[]]
result=0
for anag in S:
    flag=0
    for nows in range(len(s)):
        hikaku1 = list(anag)
        if nows==0:
            continue
        for a in s[nows][0]:
            if a in hikaku1:
                hikaku1.remove(a)
            else:
                break
            if not hikaku1:
                flag=1
                result+=s[nows][1]
                s[nows][1]+=1
        if flag==1:
            break
    if flag==0:
        s.append([anag,1])
print(result)

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(x)-1 for i, x in enumerate(ls)]))

Submission status: Time Limit Exceeded

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

ab = "abcdefghijklmnopqrstuvwxyz"
ab_dict = {}
for i,c in enumerate(ab):
    ab_dict[c] = i

def count_c(s):
    count_list = [0]*26
    sum_11 = 0
    for c in s:
        count_list[ab_dict[c]] += 1
    for i in range(26):
        sum_11 += count_list[i] * (11**i)
    return sum_11

sc_list = []
for s in s_list:
    sc = count_c(s)
    sc_list.append(sc)

ans = 0
for i,sc in enumerate(sc_list):
    for sc2 in sc_list[i+1:]:
        if sc == sc2:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

num = 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)
        num += 1
    r[l.index(an)] += 1

z = 0
for i in range(1,max(r)+1):
    #print(j)
    z += i-1
    if i in r:
        res += z*r.count(i)
else:
    print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
def main():
    n = int(input())
    s_list = [str(input()) for i in range(n)]
    s_list = [list(s) for s in s_list]
    cnt = 0 
    for i in range(len(s_list)):
        s1 = s_list[i]
        for s2 in s_list[i+1:]:
            if Counter(s1) == Counter(s2):
                cnt += 1
    print(cnt)

if __name__=='__main__':
    main()

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.sort()


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

print( count )

Submission status: Time Limit Exceeded

Solution code:
def main():
    loop_count = int(input())

    str_pattern_list = []
    str_pattern_count = []
    matched_count = 0
    for i in range(loop_count):
        string = ''.join(sorted(input()))

        if string in str_pattern_list:
            str_pattern_count[str_pattern_list.index(string)] += 1
            matched_count += str_pattern_count[str_pattern_list.index(string)]
        else:
            str_pattern_list.append(string)
            str_pattern_count.append(0)

    print(matched_count)
    

if __name__ == '__main__':
    main()

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:
N = int(input())
sl = []
tmp = []
cnt = 0

for i in range(N):
	new = sorted(list(input()))
	
	for j in sl:
		if new == j:
			cnt+=1
			
	sl.append(new)
	
print(cnt)

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
    for j in range(i):
        if l[i]==l[j]:
            cnt = cnt+1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s_list=[]
unq_list=[]
for i in range(n):
  s_elem=''.join(sorted(list(input())))
  s_list.append(s_elem)
  if s_list.count(s_elem) == 2:
    unq_list.append(s_elem)

count=0

for j in range(len(unq_list)):
  match_n=s_list.count(unq_list[j])
  count+=sum(range(1, match_n))

print(count)

Submission status: Time Limit Exceeded

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

ans = 0
for i in temp:
    for j in temp:
        if not i == j:
            if (s[i] == s[j]):
                ans += 1
print(int(ans/2))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
#S = [input() for i in range(N)]
S=[]
firstalpha=[]
ans_list = []
temp_ans = 1
ans = 0

for i in range(N):
    temp = sorted(list(input()))
    S.append(''.join(temp))
    #firstalpha.append(temp[0])
    
set_S = set(S)

for s in set_S:
    ans_list.append(S.count(s))

for a in ans_list:
    ans += a*(a-1)/2

print(round(ans))

Submission status: Time Limit Exceeded

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

N = int(input())
dic = [None] * N
for i in range(N):
    s = input()
    char_set = {x for x in s}
    char_freq = {x: s.count(x) for x in char_set}
    dic[i] = char_freq

# alphabet = dict.fromkeys("abcdefghijklmnopqrstuvwxyz", 0)
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if dic[i] == dic[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

c = 0
out = 0
while c < N-1:
    for i in range(c, N-1):
        s_l = set(s[c])
        s_r = set(s[i+1])
        if(s_l != s_r):
            continue
        s_l_li = list(s_l)
        s_r_li = list(s_r)
        for j in range(len(s_l_li)):
            if(s[c].count(s_l_li[j]) != s[i+1].count(s_l_li[j])):
                break
            if j == (len(s_l_li)-1):
                out += 1
    c += 1
print(out)

Submission status: Time Limit Exceeded

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

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

    print(count)


if __name__ == '__main__' :
    main()

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())
strings=[list(str(input())) for a in range(N)]
sorteds=[]
for thing in strings:
    thing.sort()
    sorteds.append("".join(thing))
sorteds.sort()
sums=0
for st in list(set(sorteds)):
    n=sorteds.count(st)
    if n!=1:
       sums=sums+combinations_count(n,2)

print(sums)

Submission status: Time Limit Exceeded

Solution code:


import math


def str_sort(s):
    return ''.join(sorted(s))
    
def combinations_count(n, r):
    if n == 1: return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def is_anagram(s_1, s_2):
    for c in set(s_1):
        char_count_1 = s_1.count(c)
        char_count_2 = s_2.count(c)
        if char_count_1 != char_count_2:
            return False

    return True





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



S = [str_sort(s) for s in S]

set_S = set(S)

ans = 0
if len(set_S) == len(S):
    ans = 0
else:
    for set_s in set_S:
        set_count = S.count(set_s)
        ans += combinations_count(set_count, 2)







print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []

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

counter = 0
for n in range(N):
    for m in range(n + 1, N):
        S[n].sort()
        S[m].sort()
        if S[n]== S[m]:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
count=0
s=[sorted(input()) for i in range(N)]
n=['a' for t in range(N) for i in range(t+1,N) if s[t]==s[i]]
print(len(n))

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 = ["".join(sorted(input())) for i in range(N)]

S_ = S[:]
S_ = set(S_)

a = [int(combinations_count(S.count(i), 2)) for i in S_ if not S.count(i) == 1]

print(sum(a))

Submission status: Time Limit Exceeded

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

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())
l_d = []
count = 0
for _ in list(range(N)):
  x = {}
  a = str(input())
  for i in list(range(len(a))):
    if a[i] not in x:
      x[a[i]] = 1
    else:
      x[a[i]] += 1
  if l_d:
    num = 0
    for l in list(range(len(l_d))):
      if l_d[l] == x:
        num +=1
    count += num
  l_d.append(x)
print(count)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(0, N):
    for j in range(i+1, N):
        if Counter(Si[i]) == Counter(Si[j]):
            count += 1
        else:
            pass
print(int(count))