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:
num = int(input())
range_arr = range(num)

strs = [[] for i in range_arr]
for i in range_arr:
    strs[i] = input()

def conv(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: conv(v), strs))
new_strs.sort()
compact_strs = list(set(new_strs))

cnt = 0
for str in compact_strs:
    str_count = new_strs.count(str)
    if str_count >= 2:
        cnt += int(str_count*(str_count-1)/2)

print(cnt)

Submission status: Time Limit Exceeded

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

def main():
    n = int(input())
    sl = [ list(input()) for _ in range(n) ]
    ans = 0

    
    for i in sl:
        i.sort() #sort() methodは元を変える
    
    st = tuple(sl)
    
    for i in range(len(st)-1):
        for j in range(i+1,len(st)):
            if st[i] == st[j]:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
import sys

input=sys.stdin.readline

num=int(input())
stl =[''.join(sorted(input())) for i in range(num)]

duplicate=[x for x in set(stl) if stl.count(x) > 1]

count=0

for dup in duplicate:
    count += factorial(stl.count(dup)) // 2 // factorial(stl.count(dup) - 2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def get_runlength(s): # ex) s = 'RRLLLLRLRLRLRR'
    ret = []
    count = 1
    for i in range(len(s)):
        if i == len(s) - 1:
            ret.append((s[i], count))
            continue
        if s[i] == s[i + 1]:
            count += 1
        else:
            ret.append((s[i], count))
            count = 1
    return ret

n = int(input())
dic = {}
for i in range(n):
    sin = input()
    sin = list(sin)
    sin.sort()
    sin = ''.join(sin)
    try:
        dic[sin] += 1
    except:
        dic[sin] = 1

count = 0
for v in dic.values():
    # count += v * (v - 1) / 2
    count += comb(v, 2)
count = int(count)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = []
count = 0
for i in range(N):
  temp = "".join(sorted(input()))
  count += a.count(temp)
  a.append(temp)

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = []
count = 0
for i in range(N):
  temp = input()
  temp = list(temp)
  temp.sort()
  temp = "".join(temp)
  count += a.count(temp)
  a.append(temp)

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def get_runlength(s): # ex) s = 'RRLLLLRLRLRLRR'
    ret = []
    count = 1
    for i in range(len(s)):
        if i == len(s) - 1:
            ret.append((s[i], count))
            continue
        if s[i] == s[i + 1]:
            count += 1
        else:
            ret.append((s[i], count))
            count = 1
    return ret

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

count = 0
ss = set(s)
for w in ss:
    n = s.count(w)
    count += n * (n - 1) / 2
count = int(count)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
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())
a = []
for i in range(N):
  temp = input()
  temp = list(temp)
  temp.sort()
  a.append("".join(temp))

count = 0
for s in set(a):
  temp = a.count(s)
  if temp >= 2:
    count += cmb(temp,2)

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
S = []
T = []
S = [input() for i in range(N)]
ans = 0

for i,s in enumerate(S):
    s = sorted(list(s))
    s = ''.join(s)
    T.append(s)

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

Submission status: Time Limit Exceeded

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

#ans = []
#for i in range(n):
    #ans.append(sorted(s[i]))

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

print(x)

Submission status: Time Limit Exceeded

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

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

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

print(x)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

cnt_dict = {}

for i in range(N):
    s_list = list(input())
    s_list.sort()
    s_str = "".join(s_list)
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

import itertools
comb = itertools.combinations

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    if cnt < 2:
        continue
    total += len(list(comb(range(cnt), 2)))

print(total)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

cnt_dict = {}

for i in range(N):
    s_str = "".join(sorted(input()))
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

import itertools
comb = itertools.combinations

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    if cnt < 2:
        continue
    total += len(list(comb(range(cnt), 2)))

print(total)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

str_list = [input() for i in range(N)]

cnt_dict = {}

for str in str_list:
    s_str = "".join(sorted(str))
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

import itertools
comb = itertools.combinations

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    if cnt < 2:
        continue
    total += len(list(comb(range(cnt), 2)))

print(total)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

num=int(input())

#for i in range(num):
#    str=input()
#    str=''.join(sorted(str))
#    str = ''.join(sorted(input()))
#    stl.append(str)
stl =[(''.join(sorted(input()))) for i in range(num)]

duplicate=[x for x in set(stl) if stl.count(x) > 1]
count=0

for dup in duplicate:
    count += factorial(stl.count(dup)) // 2 // factorial(stl.count(dup) - 2)
    
print(count)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

str_list = [input() for i in range(N)]

cnt_dict = {}

for str in str_list:
    s_str = "".join(sorted(str))
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

import itertools

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    if cnt < 2:
        continue
    total += len(list(itertools.combinations(range(cnt), 2)))

print(total)

Submission status: Time Limit Exceeded

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

count = 0
for j in range(N):
    # print(j, s.count(s[j])-1)
    count += (s.count(s[j])-1)
print(count//2)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
slist=[]
ans=0
for s in range(N):
	line=list(input())
	line.sort()
	slist+=[line]
	ans+=slist.count(line)-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

str_list = [input() for i in range(N)]

cnt_dict = {}

for str in str_list:
    s_str = "".join(sorted(str))
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

import itertools

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    if cnt < 2:
        continue
    total += len(list(itertools.combinations(range(cnt), 2)))

print(total)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

S=[]
S_count=dict()

total=0

for n in range(N):
    s=input()
    s=''.join(sorted(s))
    if s in S:
        total+=S_count[s]
        S_count[s]+=1

    else:
        S_count[s]=1
    S.append(s)

print(total)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

num=int(input())
count=0

#for i in range(num):
#    str=input()
#    str=''.join(sorted(str))
#    str = ''.join(sorted(input()))
#    stl.append(str)
stl =[(''.join(sorted(input()))) for i in range(num)]

duplicate=[x for x in set(stl) if stl.count(x) > 1]
if duplicate:
    for dup in duplicate:
        n=stl.count(dup)
        count += factorial(n) // 2 // factorial(n - 2)
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())

check = []
ans = {}
answer = 0
for _ in range(N):
    s = Counter(input())
    if s not in check:
        check.append(s)
        ans[str(sorted(s.items(), key=lambda x:x[0]))] = 0

    else:
        ans[str(sorted(s.items(), key=lambda x:x[0]))] += 1
        answer += ans[str(sorted(s.items(), key=lambda x:x[0]))]

print(answer)

Submission status: Time Limit Exceeded

Solution code:
# C
from collections import Counter
 
def ana(a,b):
    if sorted(a) == sorted(b): return 1
    return 0
    
n = int(input())
s = []
for i in range(n): s.append(input()) 

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sl = []
for _ in range(n):
    sl.append(input())
rl=[]
ll=[]
rslt=0
for i in range(n):
    r=sorted(sl[i])
    if r in rl: tmp=rl.index(r); ll[tmp]+=1; rslt+=ll[tmp]
    else: rl.append(r); ll.append(0)
print(rslt)

Submission status: Time Limit Exceeded

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

allChars = 'abcdefghijklmnopqrstuvwxyz'
mapList =[]
charMap={}


for string in strings:
    for allChar in allChars:
        for char in list(allChar):
            charMap[char] = 0
    for char in list(string):
        charMap[char] += 1
    #pprint.pprint(charMap)
    charMapCopy = copy.deepcopy(charMap)
    mapList.append(charMapCopy)
#pprint.pprint(mapList)

count = 0
for i in range(len(mapList)):
    #pprint.pprint(mapList[i])
    for j in range(i):
        if mapList[i] == mapList[j]:
            #pprint.pprint(mapList[i])
            #pprint.pprint(mapList[j])
            #print(str(i)+ ' ' +str(j))
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sl = []
for _ in range(n):
    sl.append(input())
rl=[]
ll=[]
rslt=0
for i in range(n):
    r=sorted(sl[i])
    if r in rl: ll[rl.index(r)]+=1; rslt+=ll[rl.index(r)]
    else: rl.append(r); ll.append(0)
print(rslt)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline().strip())
list = []
ans = 0
for x in range(n):
  list.append(sorted(''.join(sys.stdin.readline().strip())))
for i in range(len(list)-1):
  for j in range(i+1, n):
    if list[i] == list[j]:
      ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys 
inpurt = sys.stdin.readline
N = int(input())
cnt = 0
texts = [sorted(list(input().rstrip())) for _ in range(N)]
for i in range(N):
  for j in range(i+1, N):
    if texts[i] == texts[j]:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys

input = sys.stdin.readline
n = int(input())
str_list = [''.join(sorted(input().rstrip())) for i in range(n)]
ans = 0
for i in range(n-1):
  ans += str_list[i+1:].count(str_list[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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())
        s[i].sort()

    print(int(count_anagram(s[0], s[1:], 0)))


def count_anagram(s, str_list, total):
    cnt = 0
    tmp = []
    for i, t in enumerate(str_list):
        if s == t:
            cnt += 1
            tmp.append(i)
    if cnt > 0:
        total += (cnt+1) * cnt / 2
        for i in reversed(tmp):
            str_list.pop(i)

    if str_list:
        return count_anagram(str_list[0], str_list[1:], total)
    else:
        return total


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sl = []
for _ in range(n):
    sl.append(input())
rl=[]
ll=[]
for i in range(n):
    r=sorted(sl[i])
    if r in rl: ll[rl.index(r)]+=1
    else: rl.append(r); ll.append(0)
rslt=0
for i in ll:
    if not i==0: rslt+=((1+i)*i >> 1)
print(rslt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = [None] * n
    for i in range(n):
        s[i] = str(input()).replace("\n", "")

    ans = list()
    pairs = 0
    for i in s:
        count_word = dict()
        for j in i:
            count_word[j] = i.count(j)

        if count_word in ans:
            pairs += ans.count(count_word)

        ans.append(count_word)

    print(pairs)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
ans = 0
for i in range(N-1):
    s1 = S[i]
    for s2 in S[i+1:]:
        if s1 == s2:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys

input = sys.stdin.readline
n = int(input())
counter_list = [Counter(input().rstrip()) for i in range(n)]
ans = 0
for i in range(n-1):
  if counter_list[i] in counter_list[i+1:]:
    ans +=counter_list[i+1:].count(counter_list[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
#S = [input() for i in range(N)]
S=[]
alpha_dic={"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_list = []
temp_ans = 1
ans = 0

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

for key,value in alpha_dic.items():
    set_S = set(value)
    for s in set_S:
        a = value.count(s)
        ans += a*(a-1)/2

print(round(ans))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

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

ans = 0

for i in range(len(str)-1):
    list1 = str[i]
    
    for j in range(i+1,len(str)):
        list2 = str[j]
            
        if list1 == list2:
            ans = ans + 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
count = 0
lists =[]
count_dict = Counter()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
sn=[''.join(sorted(list(input()))) for _ in range(N)]
sm=set(sn)
res=0
for s in sm:
  cnt=sn.count(s)
  res+=(1+(cnt-1))*(cnt-1)//2
print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main():
    n = int(input())
    count = 0
    lists =[]
    count_dict = Counter()

    for i in range(n):
        input_data = ''.join(sorted(input()))
        if input_data in lists:
            count += 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:
from collections import Counter
 
N = int(input())
S = []
ans = [1] * N
for _ in range(N):
    s = Counter(input())
    for i in range(len(S)):
        if s == S[i]:
            ans[i] += 1
            break
    else:
        S.append(s)
        
print(sum(a * (a-1) // 2 for a in ans if a > 1))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = [[e for e in input()] for _ in range(N)]

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

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

print('{}'.format(ans))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

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

ans = 0

for i in range(len(str)-1):
    list1 = str[i]
    
    for j in range(i+1,len(str)):
        list2 = str[j]
            
        count = 0
        for k in range(len(list1)):

            if list1[k] == list2[k]:
                count = count + 1
            else:
                break
            
        if count == len(list1):
            ans = ans + 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
dic = {}

for _ in range(N):
    s = sorted(input())
    s = str(s)
    if s in dic.keys():
        dic[s] += 1
    else:
        dic[s] = 1

print(sum(d * (d-1) // 2 for d in dic.values() if d > 1))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ss = []
ht = []
ans = 0

for i in range(N):
    s = sorted(input())
    if not s in ss:
        ss.append(s)
        ht.append(1)
    else:
        ans += ht[ss.index(s)]
        ht[ss.index(s)] += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = ['']* N
ans = 0
for i in range(N):
    S[i]= sorted(input())
    ans += S.count(S[i]) - 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

for i in range(0, len(s)):
  sorted_val = ''.join(sorted(s[i]))
  is_contain = False
  for k in result_dic.keys():
    if sorted_val == k:
      result_dic[k] += 1
      is_contain = True
      break
  if not is_contain:
    result_dic[sorted_val] = 1

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

def main():
    n = int(stdin.readline().rstrip())
    count = 0
    counter = [0]*n

    for i in range(n):
        counter[i] = Counter(stdin.readline().rstrip())
    for i in range(n):
        for j in range(i+1,n):
            if all(counter[i][key] == counter[j][key] for key in counter[i]) :
                count += 1

    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def anagram(list1, list2):

    anagramFlg = 1

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

    return anagramFlg


n = int(input())

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

# print(inputList)

sortedList = []
for i in range(n):
    tmpList = list(inputList[i])
    tmpList.sort()
    sortedList.append(tmpList)

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())

strs = [[] for i in range(num)]
for i in range(num):
    strs[i] = input()

def conv(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: conv(v), strs))
new_strs.sort()
shorten_strs = list(set(new_strs))

cnt = 0

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

for str in shorten_strs:
    nums = new_strs.count(str)
    if nums >= 2:
        cnt += comb_count(nums, 2)

print(cnt)

Submission status: Time Limit Exceeded

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

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

#print(s)

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

#print(S)

num=0

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

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

ans = 0

for i in range(len(str)-1):
    list1 = sorted(list(str[i]))
    
    for j in range(i+1,len(str)):
        list2 = sorted(list(str[j]))
            
        count = 0
        for k in range(len(list1)):

            if list1[k] == list2[k]:
                count = count + 1
            else:
                break
            
        if count == len(list1):
            ans = ans + 1
        
print(ans)

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:
        ans += ct[ss.index(cnt)]
        ct[ss.index(cnt)] += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

N = int(stdin.readline().rstrip())
strings = ''
lists = []
for _ in range(N):
  s = ''.join(sorted(stdin.readline().rstrip()))
  strings += s
  lists.append(s)
counts = [strings[(i+1)*len(s):].count(c) for i, c in enumerate(lists)]
match_count = sum(counts)
print(match_count)

Submission status: Time Limit Exceeded

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

S_sorted = []

for i in range(N):
    str_sorted = list(S[i])
    str_sorted.sort()
    S_sorted.append(str_sorted)

c = 0
for i in range(0,N):
    for j in range(i+1,N):
        if S_sorted[i] == S_sorted[j]:
            c = c + 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_list = []
n_list = []
ana = 0
for i in range(n):
    s = "".join(sorted(input()))
    #print(s)
    if len(s_list) > 0:
        for num, s_i in enumerate(s_list):
            is_exist = False
            if s_i == s:
                n_list[num] += 1
                ana += n_list[num]
                is_exist = True
                break
        if not is_exist:
            s_list.append(s)
            n_list.append(0)
    else:
        s_list.append(s)
        n_list.append(0)

print(int(ana))

Submission status: Time Limit Exceeded

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

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

t=[]
flag=0
for i in range(N):
	for j in range(len(t)):
		flag=0
		if s[i]==t[j][0]: #tは二次元リストで定義していたことに気を付けよう
			t[j][1] += 1
			flag=1
			break
	if flag==0:
		t.append([s[i],1])

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A=[]
S=[]
for i in range(N):
    a = list(input())
    a.sort()
    A.append(a)
    if a not in S:
        S.append(a)

count=0
for i in S:
    if A.count(i)==1:
        continue
    count += A.count(i)*(A.count(i)-1)//2
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

l = [''.join(sorted(input())) for i in range(int(input()))]
s = [int(i) for i in collections.Counter(l).values()]
a=0
b=0
for i in range(max(s)):
    b+=i
    a+=s.count(i+1)*b
print(a)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
s=[input() for i in range(N)]
a=0
b=N-1
for i in range(b):
    c=N-i-1
    t=s[i]
    u=list(s[i])
    u.sort()
    for j in range(c):
        v=s[i+j+1]
        w=list(v)
        w.sort()
        for k in range(10):
            if u[k]!=w[k]:
                break
            else:
                if k<9:
                    continue
                else:
                    a=a+1
print(a)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    sl = [ list(input()) for _ in range(n) ]
    ans = 0

    
    for i in sl:
        i.sort() #sort() methodは元を変える
    
    st = tuple(sl)
    
    for i in range(len(st)-1):
        for j in range(i+1,len(st)):
            if sl[i] == sl[j]:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
        

obj = defaultdict(lambda: 1)

N=int(input())
ANA=[]
L=[]
for i in range(N):
    k="".join(sorted([x for x in input()]))
    if k in L:
        obj[k]+=1
    else:
        L.append(k)

result=0
for i in obj.values():
    if i and i-1:
        result+=i*(i-1)/2
    
print(int(result))

Submission status: Time Limit Exceeded

Solution code:
import collections

l = sorted([''.join(sorted(input())) for i in range(int(input()))])
s = [int(i) for i in collections.Counter(l).values()]
a=0
b=0
for i in range(max(s)):
    b+=i
    a+=s.count(i+1)*b
print(a)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from operator import mul
from functools import reduce

def combination(n, r):
    if n < r:
        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

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
ans = 0
for anagram in set(s):
    ans += combination(s.count(anagram), 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
lst=[]
for i in range(N):
  text=input()
  lst=lst+[sorted(text)]
lst=sorted(lst)      
count=0
i=0
while(i<N-1):
  j=1
  while(lst[i]==lst[i+j]):
    count=count+j
    j=j+1
    if (i+j >= N):
      break
  i=i+j
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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


alphabet = set('abcdefghijklmnopqrstuvwxyz')
s_list = [int('1' + ''.join([str(s_i[a]) for a in alphabet])) for s_i in s]

count = 0
i = 0

for x in s_list:
  i += 1
  temp = s_list[i:]
  hoge = s[i:]
  for y in temp:
    if y == x:
      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
  ls = [j for j in range(i+1, N) if j not in skip_n]
  for j in ls:
    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:
n=int(input())
wordlist=[input() for i in range(n)]
sortlist=[]
for i in range(n):
    a=list(wordlist[i])
    a.sort()
    a="".join(a)
    sortlist.append(a)
    
def kaijyo(n):
    ans=1
    for i in range(1,n+1):
        ans*=i
    return ans

count=0
sortlist.sort()


while sortlist:
    a=sortlist.pop()
    times=sortlist.count(a)+1
    for i in range(times-1):
        sortlist.pop()
    b=1
    for i in range(2):
        b*=(times-i)
    b=int(b/2)
    count+=b
    
print(int(count) )

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    temp = []
    for j in range(len(s[i])):
        temp.append(s[i][j])

    ans.append(''.join(sorted(temp)))

#ans.sort()
temp = ans[0]

# if ans.count(temp) == 1:
#     count = 0
# else:
#     count = ans.count(temp)
count = 0
setV = set()

for i in range(n):
    if ans.count(ans[i]) > 1:
        if ans[i] in setV:
            continue
        else:
            num = ans.count(ans[i])
            count += (num * (num-1))/2
            setV.add(ans[i])

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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


alphabet = set('abcdefghijklmnopqrstuvwxyz')
s_list = [int(''.join([str(s_i[a]) for a in alphabet])) for s_i in s]

count = 0
i = 0

for x in s_list:
  i += 1
  temp = s_list[i:]
  hoge = s[i:]
  for y in temp:
    if y == x:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations
import sys
input = sys.stdin.readline
n = int(input())
cnt = Counter(["".join(sorted(input().split()[0])) for _ in range(n)])
print(sum([len(list(combinations([""] * cnt[c], 2))) for c in cnt]))