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:
count = int(input())

str_data = list()
result = 0
for i in range(count):
  judge_str = sorted(input())
  for data in str_data:
    if judge_str == data:
      result += 1
    
  str_data.append(judge_str)
print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
ss = [sorted(s[i]) for i in range(n)]
dic = [''.join(ss[i]) for i in range(n)]
key = [i for i in set(dic) if dic.count(i) > 1]
cnt = 0
for i in key:
    a = dic.count(i)-1
    cnt += (a * (a+1))/2
print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(sorted(input()))
res = 0
for index, j in enumerate(s):
    res += s[index + 1:].count(j)

print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
word = []
ans = 0
temp = 0
tmplist = []
m = 0
for i in range (0,N):
    temp = 0
    linp =  sorted(input())
    inp = ''.join(linp)
    for j in range (0,m):
        if word[j][0] == inp: 
            ans = ans + word[j][1]
            word [j][1] = word[j][1] + 1
            temp = 1
            break
    if temp == 0:
        tmplist = [inp, 1]
        word.append(tmplist) 
        m = m + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce


def factorial(end, start=1):
    return reduce(lambda f, i: f * i, list(range(start, end + 1)), 1)


def combination(n, r):
    return factorial(n) // (factorial(r) * factorial(n - r))


N = int(input())


dp = {}
result = 0

for _ in range(N):
    s = ''.join(sorted(input()))
    if s in dp:
        dp[s] += 1
    else:
        dp[s] = 1

print(reduce(lambda r, key: r + combination(dp[key], 2), dp, 0))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce


def factorial(end, start=1):
    return reduce(lambda f, i: f * i, list(range(start, end + 1)), 1)


def combination(n, r):
    return factorial(n) // (factorial(r) * factorial(n - r))


N = int(input())
ss = [''.join(sorted(input())) for _ in range(N)]

dp = {}
result = 0

for s in ss:
    if s in dp:
        dp[s] += 1
    else:
        dp[s] = 1

print(reduce(lambda r, key: r + combination(dp[key], 2), dp, 0))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
word = []
ans = 0
temp = 0
for i in range (0,N):
    temp = 0
    inp = sorted(input())
    for j in range (0,len(word)):
        for k in range (0,10):
            if word[j][k] != inp[k]:
                temp = 0
                break
            temp = 1
        if temp == 1: 
            ans = ans + word[j][10]
            word [j][10] = word[j][10] + 1
            temp = 1
            break
    if temp == 0:
        inp.append(1)
        word.append(inp)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n = int(input())

#ss = [sorted(list(input())) for _ in range(n)]
ss = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    ss.append(str(tmp))

checked = set()
count = 0

for i, t_ss in enumerate(ss[:-1]):
    if t_ss in checked:
        continue
    checked.add(t_ss)
    add_count = 1
    for t_j_ss in ss[i+1:]:
        if t_ss == t_j_ss:
            count += add_count
            add_count += 1

print(count)

Submission status: Time Limit Exceeded

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

n = int(input())

ss = [sorted(list(input())) for _ in range(n)]
'''
ss = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    ss.append(tmp)
'''

checked = set()
count = 0

for i in range(n-1):
    if i in checked:
        continue
    same_str = set()
    for j in range(i+1, n):
        if ss[i] == ss[j]:
            count += 1

            for s in same_str:
                count += 1

            same_str.add(j)
            checked.add(j)

print(count)

Submission status: Time Limit Exceeded

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

n = int(input())

ss = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    ss.append(tmp)

checked = set()
count = 0

for i in range(n-1):
    if i in checked:
        continue
    same_str = set()
    for j in range(i+1, n):
        if ss[i] == ss[j]:
            count += 1

            for s in same_str:
                count += 1

            same_str.add(j)
            checked.add(j)

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

ss = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    ss.append(tmp)

checked = set()
count = 0

for i in range(n-1):
    if i in checked:
        continue
    same_str = set()
    for j in range(i+1, n):
        if ss[i] == ss[j]:
            count += 1

            for s in same_str:
                count += 1

            same_str.add(j)
            checked.add(j)

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

ss = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    ss.append(tmp)

matrix = [[0 for _ in range(n)] for _ in range(n)]
checked = set()

for i in range(n-1):
    if i in checked:
        continue
    same_str = set()
    for j in range(i+1, n):
        if ss[i] == ss[j]:
            matrix[i][j] = 1

            for s in same_str:
                matrix[s][j] = 1

            same_str.add(j)
            checked.add(j)

count = 0
for row in matrix:
    count += sum(row)

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
res = 0
for index, j in enumerate(s):
    for k in s[index + 1:]:
        for l in j:
            k = k.replace(l, "", 1)
        if not k:
            res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
import re

n = int(input())
s = []
for i in range(n):
    s.append(input())
res = 0
for index, j in enumerate(s):
    for k in s[index + 1:]:
        for l in j:
            k = re.sub(l, "", k)
        if not k:
            res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

ss = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    ss.append(tmp)
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        if ss[i] == ss[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
a = []
ans = 0

for i in range(N):
    tmp = input()
    tmp2 = Counter(tmp)
    a.append(tmp2)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:

def green_bin(s, N):
    anagram_num = 0
    sorted_s_sub = []
    sorted_s = []
        
    for i in range(N):
        sorted_si = sorted(s[i])
        sorted_s_sub.append(''.join(sorted_si))

    sorted_s = sorted(sorted_s_sub)

    i = 0
    item_count = []
    while i < N:
        item = sorted_s[i]
        count = sorted_s.count(item)
        item_count.append(count)
        i += count  # count だけ進める
    
    for count in item_count:
        
        anagram_num += int(count * (count - 1) / 2)

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin(s, N))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

print(a)

str_list = []
str_all_list = []
for num in range(N):
  for element in itertools.permutations(a[num], len(a[num])):
    str_ = ''
    for list in element:
      str_ += list
    str_list.append(str_)
  str_all_list.append(str_list)

count = 1
result = 0

for i in range(N):
  for j in range(i+1,N-count):
    judge = 0
    for z in str_all_list[i]:
      if z in str_all_list[j]:
        result += 1
        judge = 1
        break;
  count += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:

def green_bin(s, N):
    anagram_num = 0
    sorted_s = []
        
    for i in range(N):

        if i == 0:
            sorted_s.append(sorted(s[i]))

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

                if i == 0:
                    sorted_s.append(sorted(s[j]))

                if sorted_s[i] == sorted_s[j]:
                    anagram_num += 1

    return anagram_num



def green_bin2(s, N):
    anagram_num = 0
    sorted_s_sub = []
    sorted_s = []
        
    for i in range(N):
        sorted_si = sorted(s[i])
        sorted_s_sub.append(''.join(sorted_si))

    sorted_s = sorted(sorted_s_sub)

    i = 0
    item_count = []
    while i < N:
        item = sorted_s[i]
        count = sorted_s.count(item)
        item_count.append(count)
        i += count  # count だけ進める
    
    for count in item_count:
        
        anagram_num += int(count * (count - 1) / 2)

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin2(s, N))

Submission status: Time Limit Exceeded

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

while len(words) >=2:
  a = words[0]
  del words[0]
  for i in range(len(words)):
    if a == words[i]:
      counter += 1
    else: continue  

print(counter)

Submission status: Time Limit Exceeded

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

while len(words) >=2:
  a = words[0]
  del words[0]
  for i in range(len(words)):
    if a == words[i]:
      counter += 1
    else: continue  

print(counter)

Submission status: Time Limit Exceeded

Solution code:

def green_bin(s, N):
    anagram_num = 0
    sorted_s = []
        
    for i in range(N):

        if i == 0:
            sorted_s.append(sorted(s[i]))

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

                if i == 0:
                    sorted_s.append(sorted(s[j]))

                if sorted_s[i] == sorted_s[j]:
                    anagram_num += 1

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin(s, N))

Submission status: Time Limit Exceeded

Solution code:

def green_bin(s, N):
    anagram_num = 0
    sorted_s = []

    for i in range(N):
        sorted_s.append(sorted(s[i]))
        
    for i in range(N):
        # sorted_si = sorted(s[i])

        for j in range(i + 1, len(s)):
            # sorted_sj = sorted(s[j])

            if sorted_s[i] == sorted_s[j]:
            # if sorted_si == sorted_sj:
                anagram_num += 1

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin(s, N))

Submission status: Time Limit Exceeded

Solution code:

def green_bin(s, N):
    anagram_num = 0
    sorted_s = []

    # for i in range(N):
         
    for i in range(N):
        sorted_si = sorted(s[i])

        for j in range(i + 1, len(s)):
            sorted_sj = sorted(s[j])

            if sorted_si == sorted_sj:
                anagram_num += 1

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin(s, N))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list = []
ans = 0
for i in range(n):
  list.append(input())
  list[i] = ''.join(sorted(list[i]))
for i in range(n):
  ans += list.count(list[i]) -1
print(int(ans/2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
uw = []
S = []
c = 0
for i in range(N):
    s = sorted(input())
    if s not in uw:
        uw.append(s)
        
    S.append(s)

for w in uw:
    n = S.count(w)
    if n == 1:
        c += 0
    elif n == 2:
        c += 1
        
    else:
        c += (n - 1)*(2 + (n - 2))//2
    
print(int(c))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [sorted(input()) for i in range(N)]
c = 0
for i in range(N):
    for j in range(N - i - 1):
        if S[i] == S[i + 1 + j]:
            c += 1           
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [str(input()) for _ in range(n)]
# l = set(l)

m = [-1]*n
ans = 0

for i in range(n-1):
  if m[i] >= 0:
    continue
  else:
    si = l[i]
    m[i] = i
    temp  = 0
    for j in range(i+1, n):
      if m[j] >= 0:
        continue
      else:
        sj = l[j]
        if sorted(si) == sorted(sj): 
          temp += 1
          m[j] = i
          #print(i, temp)
  ans += (temp+1)*temp/2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [str(input()) for _ in range(n)]
# l = set(l)

m = [-1]*n
ans = 0

for i in range(n-1):
  if m[i] >= 0:
    continue
  else:
    si = l[i]
    m[i] = i
    temp  = 0
    for j in range(i+1, n):
      if m[j] >= 0:
        continue
      else:
        sj = l[j]
        for k in range(10):
          sj = sj.replace(si[k], '', 1)
        if sj == '':
          temp += 1
          m[j] = i
          #print(i, temp)
  ans += (temp+1)*temp/2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
l = [str(input()) for _ in range(n)]
l = set(l)

ans = 0

for si, sj in itertools.combinations(l, 2):
  for k in range(10):
    sj = sj.replace(si[k], '', 1)
  if sj == '':
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(n-1):
  si = l[i]
  for j in range(i+1, n):
    sj = l[j]
    for k in range(10):
      sj = sj.replace(si[k], '', 1)
    if sj == '':
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

words = list(map(lambda word: input(), range(N)))

letter_lists = []
for word in words:
  letters = list(map(lambda word: word, word))
  letters.sort()
  letter_lists.append(letters)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000)
def intinput():return map(int,input().split())

factmemo={0:1} #階乗
def fact(n):
    if n in factmemo:
        return factmemo[n]
    k = n*fact(n-1)
    factmemo[n]=k
    return k

def comb(a,b): return fact(a)//(fact(a-b)*fact(b)) #組み合わせ

for i in range(10):
    fact(i+10000)
n=int(input())
s={}
for i in range(n):
    t=list(input())
    t.sort()
    t="".join(t)
    try:
        s[t]+=1
    except:
        s[t]=1
ans=0
for i in s.values():
    if i!=1:
        ans+=comb(i,2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s_list=[]
for i in range(N):
    s_list.append(sorted(list(input())))
set_list=list(map(list, set(map(tuple, s_list))))

import math

count=0
for element in set_list:
    many = s_list.count(element)
    if many>1:
        count+=math.factorial(many) // (math.factorial(many - 2) * math.factorial(2))

print(count)

Submission status: Time Limit Exceeded

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

sList = []

for n in range(0, N):
    string = list(input())
    sList.append(string)
    sList[n].sort()

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

Submission status: Time Limit Exceeded

Solution code:
# 実行時間超過

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

for i in range(N):
    s_list.append(sorted(list(input())))

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

Submission status: Time Limit Exceeded

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

for _ in range(N):
    s_list.append(input())
    
count=0
for i in range(N):
    for j in range(i+1,N):
        s1=list(s_list[i])
        s2=list(s_list[j])
        if sorted(s1)==sorted(s2):
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

for _ in range(N):
    s_list.append(input())
    
count=0
for i in range(N):
    for j in range(i+1,N):
        s1=[]
        s2=[]
        for k in range(10):
            s1.append(s_list[i][k])
            s2.append(s_list[j][k])
        if sorted(s1)==sorted(s2):
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def is_anagram( a, b ):
    for chr in a:
        if a.count( chr ) != b.count( chr ):
            return False
    return True

count = 0
listcnt = len(sntlist)
for i in range( listcnt-1 ):
    for j in range( i+1, listcnt ):
        if is_anagram( sntlist[i], sntlist[j] ):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

def is_anagram( a, b ):
    for chr in a:
        if a.count( chr ) != b.count( chr ):
            return False
    return True

count = 0
for i in range( len( sntlist )-1 ):
    for j in range( i+1, len(sntlist) ):
        if is_anagram( sntlist[i], sntlist[j] ):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [str(input()) for _ in range(N)]
dic_list = [dict() for _ in range(N)]
for letter in ['a','b','c','d','e','f','g','h','i','j','k','l','m','n',
               'o','p','q','r','s','t','u','v','w','x','y','z']:
  for i in range(N):
    dic_list[i][letter] = s[i].count(letter)
ans = 0
for i in range(N):
  for j in range(i+1, N):
    if dic_list[i] == dic_list[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

def green_bin(s):
    anagram_num = 0

    for i in range(len(s)):
        sorted_si = sorted(s[i])

        for j in range(i + 1, len(s)):
            sorted_sj = sorted(s[j])

            if sorted_si == sorted_sj:
                anagram_num += 1

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin(s))

Submission status: Time Limit Exceeded

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

for l in range(N):
  S[l].sort()
  S[l] = ''.join(S[l]) 

S.sort()
for k in range(N):
  S[k] = list(S[k])
ans = 0

for j in range(N-1):
  for m in range(j+1,N):
    p = 0
    q = 1
    while p < 10:
      if S[j][p] == S[m][p]:
        p += 1
      else:
        q = 0
        break
    ans += q

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter
N = int(input())
S = [list(input()) for i in range(N)]

for l in range(N):
  S[l].sort()
  S[l] = ''.join(S[l]) 

S.sort()

ans = 0


for j in range(N-1):
  for m in range(j+1,N):
    if S[j] == S[m]:
      ans += 1
    else:
      break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
strs = [sorted(str(input())) for _ in range(n)]

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

Submission status: Time Limit Exceeded

Solution code:
def equalCheck(aList, bList):
  checkList = [0] * 10
  for i in range(10):
    for j in range(10):
      if checkList[j] == 0 and aList[i] == bList[j]:
        checkList[j] = 1
  if 0 in checkList:
    return False
  return True

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

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

Submission status: Time Limit Exceeded

Solution code:
def equalCheck(aList, bList):
  checkList = [0] * 10
  for i in range(10):
    for j in range(10):
      if aList[i] == bList[j] and checkList[j] == 0:
        checkList[j] = 1
  if 0 in checkList:
    return False
  return True

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

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

Submission status: Time Limit Exceeded

Solution code:
n  = int(input())
def s(i):
    s = input()
    a = []
    for m in range(0,10):
        a.append(s[m])
    a.sort()
    return a
b = [s(i) for i in range (0, n)]
l = 0
for k in range(0, n - 1):
    for j in range (k + 1, n):
        if b[k] == b[j]:
            l = l + 1

print (l)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
B=[]
ans=0
for i in range(N):
    x="".join(sorted(input()))
    if x in A:
      ii=A.index(x)
      B[ii]+=1
    else:
      A.append(x)
      B.append(1)
ans=0
for b in B:
  ans+=(b-1)*(b)/2
print(int(ans))

Submission status: Time Limit Exceeded

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

for l in range(N):
  S[l].sort()

ans = 0
for j in range(N-1):
  for k in range(j+1,N):
    p = 0
    x = 1
    while x == 1 and p < 10:
      if S[j][p] != S[k][p]:
        x = 0
        break
      else:
        p += 1
    ans += x

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n  = int(input())
def s(i):
    s = input()
    a = []
    for m in range(0,10):
        a.append(s[m])
    a.sort()
    return a
b = []
l = 0
for i in range (0, n):
    b.append(s(i))
for k in range(0, n - 1):
    for j in range (k + 1, n):
        if b[k] == b[j]:
            l = l + 1

print (l)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = []
B=[]
ans=0
for i in range(N):
    x=collections.Counter(list(input()))
    if x in A:
      ii=A.index(x)
      B[ii]+=1
    else:
      A.append(x)
      B.append(1)
ans=0
for b in B:
  ans+=(b-1)*(b)/2
print(int(ans))

Submission status: Time Limit Exceeded

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

for l in range(N):
  S[l].sort()
  T[l] = ''.join(S[l])

ans = 0
for j in range(N-1):
  for k in range(j+1,N):
    p = 0
    x = 1
    while x == 1 and p < 10:
      if S[j][p] != S[k][p]:
        x = 0
        break
      else:
        p += 1
    ans += x

print(ans)

Submission status: Time Limit Exceeded

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

for l in range(N):
  S[l].sort()
  T[l] = ''.join(S[l])

ans = 0
for j in range(N):
  for k in range(j+1,N):
    if j != k:
      if S[j][0] == S[k][0]:
        if S[j][9] == S[k][9]:
          if T[j] == T[k]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

cnt = 0
while len(strs) > 1:
  s = strs.pop()
  cnt += strs.count(s)
print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0
for j in range(N):
  for k in range(j+1,N):
    if len(set(S[j])^set(S[k])) == 0:
      S[j].sort()
      S[k].sort()
      if (''.join(S[j]) == ''.join(S[k])):
        ans += 1
           
           
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
strs = [sorted(str(input())) for _ in range(n)]

cnt = 0
while len(strs) > 1:
  s = strs.pop()
  cnt += strs.count(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#計算間に合わなかった泣

n = int(input())
l = list(str(input()) for _ in range(n))
d = [{} for _ in range(n)]

for m, a in enumerate(l):
    for p in range(10):
        d[m][a[p]] = a.count(a[p])
cnt = 0
dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]

for i in d:
    pp=[i==k for k in d]
    kk = [x for x, _ in enumerate(pp) if _]
    d = dellist(d, kk)
    cnt += (len(kk)-1)*len(kk)/2

print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

for j in range(N):
  S[j].sort()
  S[j] = ''.join(S[j])

ans = 0  

for k in range(N):
  for l in range(k+1,N):
    if k < l:
      if S[k] == S[l]:
        ans += 1
  
print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
L = [input().strip() for _ in range(N)]

m = [{} for _ in range(N)]
for i in range(N):
    for v in L[i]:
        if m[i].get(v) == None:
            m[i][v] = 0
        m[i][v] += 1
        
ans = 0
# very slow
for i in range(N):
    for j in range(i + 1, N):
        if m[i] == m[j]:
            ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
strs = [str(input()) for _ in range(n)]

cnt = 0
while len(strs) != 0:
  s = strs.pop()
  anagrams = set(["".join(a) for a in itertools.permutations(s)])
  for anag in anagrams:
    if anag in strs:
      cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
strs = [str(input()) for _ in range(n)]

cnt = 0
while len(strs) != 0:
  s = strs.pop()
  for anagram in set(itertools.permutations(s)):
    if "".join(anagram) in strs:
      cnt += 1
      
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = [""] * n
    ans = 0
    for i in range(n):
        s[i] = SortString(input())
    s.sort()
    for i in range(n - 1):
        for j in range(i + 1, n):
            if s[i] == s[j]:
                ans += 1
            else:
                break
    print(ans)
  
  
def SortString(text):
    return "".join(sorted(list(text)))
  
  
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = [""] * n
    ans = 0
    for i in range(n):
        s[i] = SortString(input())
    s.sort()
    for i in range(n - 1):
        for j in range(i + 1, n):
            if s[i] == s[j]:
                ans += 1
            else:
                break
    print(ans)


def SortString(text):
    return "".join(sorted(list(text)))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ls=[]
n=0
for i in range(N):
    ln=sorted(input())
    n+=ls.count(ln)
    ls.append(ln)
print(n)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ls=[]
n=0
for i in range(N):
    str1=''.join(sorted(input()))
    n+=ls.count(str1)
    ls.append(str1)
print(n)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ls=[]
n=0
for i in range(N):
    str1=''.join(sorted(input()))
    if str1 in ls:
        n+=ls.count(str1)
        ls.append(str1)
    else:
        ls.append(str1)
print(n)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


def check(s1, s2, i, j, memo):
    if memo[i] == -1:
        if memo[j] == -1:
            if s1 == s2:
                memo[i] = i
                memo[j] = i
                return 1
            else:
                return 0
        else:
            return 0
    else:
        if memo[j] == -1:
            if s1 == s2:
                memo[j] = i
                return 1
        elif memo[i] == memo[j]:
            return 1

    return 0


def main():
    N = int(input())

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

    ans = 0
    memo = [-1 for i in range(N)]
    for i in range(N):
        for j in range(i+1, N):
            if len(S[i]) == len(S[j]):
                ans += check(S[i], S[j], i, j, memo)

    print(ans)


main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


def check(s1, s2, i, j, memo):
    if memo[i] == memo[j] and memo[i] != -1:
        return 1
    elif memo[i] != memo[j] and memo[j] != -1:
        return 0

    if s1 == s2:
        if memo[i] == -1:
            memo[i] = i
            memo[j] = i
        elif memo[j] == -1:
            memo[j] = memo[i]
        return 1

    else:
        return 0


def main():
    N = int(input())

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

    ans = 0
    memo = [-1 for i in range(N)]
    for i in range(N):
        for j in range(i+1, N):
            if len(S[i]) == len(S[j]):
                ans += check(S[i], S[j], i, j, memo)

    print(ans)


main()