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())
ls = []
for i in range(n):
    ls.append(input())
for i in range(n):
    ls[i] = sorted(ls[i])
ans = 0
for i in range(n):
    for j in range(i+1,n):
        if ls[i] == ls[j]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=[]
for i in range(n):
  s=list(input())
  s.sort()
  S.append(s)
cont=0
for i in range(n):
  for j in range(i+1,n):
    if S[i]==S[j]:
      cont+=1
print(cont)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main():

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

    for i in range(N-1):
#        pre=Counter(sList[i])
        j=i+1
        while(j!=N):
#            print(pre)
#            print(Counter(sList[j]))
            if cList[i]==cList[j]:
                ans += 1
            j += 1

    print(ans)








    
if __name__== "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

N = int(stdin.readline())
char_counts = list(map(counter, [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:
import collections

N = int(input())
texts = []
for i in range(N):
    texts.append((input()))
    
counters = []
count = 0
for i in range(N):
    for j in range(0,i-1):
        if collections.Counter(texts[j]) == collections.Counter(texts[i]):
            count += 1
    else:
        continue
print(count)

Submission status: Time Limit Exceeded

Solution code:
N   =   int(input())

counter     =   0


A = []

for i in range(26):
    A.append([])




for i in range(N):
    S   =   sorted(input())
    point   =   ord(S[0]) - ord('a')
    for j in range(len(A[point])):
        if(A[point][j] == S):
            counter += 1
            continue
    A[point].append(S)

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_list = []
n_list = []
ana = 0
for i in range(n):
    s = 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:
#coding utf-8

n = int(input())

ans = 0
s = list()
for i in range(n):
    tmp = list(input())
    tmp.sort()
    stirng = ''.join(tmp)
    # print(tmp)
    for j in s:
        if j == stirng:
            ans += 1
            # break;

    s.append(stirng)

print(ans)

Submission status: Time Limit Exceeded

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

nums = []
for w in ws:
    v = [0] * 52
    for c in w:
        if "Z" < c:
            v[ord(c) - ord("a")] += 1
        else:
            v[ord(c) - ord("A") + 26] += 1
    nums.append(v)

ans = 0
found = []
for i in range(n):
    if i in found:
        continue
    r = 0
    for j in range(n):
        if j <= i:
            continue
        if j in found:
            continue
        v = 1
        for k in range(52):
            if nums[i][k] != nums[j][k]:
                v = 0
                break
        if v != 0:
            r += v
            found.append(j)
    ans += (r + 1) * r // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def pair_cal(int):
    tar = int -1
    cnt = tar * (tar+1) / 2

    return round(cnt)

N = int(input())

str_ls = []
for _n in range(0, N):
    c = ''.join(sorted(str(input())))
    str_ls.append(c)

uniq_ls = list(set(str_ls))
# print(uniq_ls)

# str_ls.sort()
# print(str_ls)

total_cnt = 0

for _u in uniq_ls:
    count_num = str_ls.count(_u)
    if count_num != 1:
        total_cnt += pair_cal(count_num)

print(total_cnt)

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
string=[]
ang=0
cou=0
for c in range(n):
    string.append(input())

charcou=[[0]*26 for i in [1]*n]
for c in range(n):
    for d in range(10):
        charcou[c][ord(string[c][d])-97]+=1

for c in range(n):
    for d in range(c+1,n):
        if charcou[c]==charcou[d]:
            ang+=1
print(ang)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N):
    for j in range(N):
        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())

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

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

a.sort()
c = list(map(list, set(map(tuple, a))))
d=[]
for i in c:
    d.append(a.count(i))
count=0
for i in d:
    if i>2:
        count += factorial(i) // (factorial(i - 2) * factorial(2))
    elif i ==2:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[]
an=0
for i in range(N):
    s.append([x for x in input()])
    s[i].sort()
i=0
while i<N:
    y=1
    n=i+1
    while n<N:
        if s[i]==s[n]:
            y+=1
            del s[n]
            N-=1
        else:
            n+=1
    i+=1
    an+=int((y*(y-1)/2))
print(an)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

arr = []

count = 0

def sort_str(s):
    return "".join(sorted(list(s)))


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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools

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

count=0
lis = [1,2,3]
for n in range(len(dic)):
  for l in range(len(dic)):
    if(n < l):
      if(dic[n]==dic[l]):
        count+=1
print(count)

Submission status: Time Limit Exceeded

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

for i in range(n):
  s_elem=''.join(sorted(list(input())))
  s_list.append(s_elem)

unq_list=list(set(s_list))
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())

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

ls = [sorted(list(s)) for s in ls]

hoge = 0
for i in range(N):
    hoge += sum([1 if x==ls[i] else 0 for x in ls[i:len(ls)]]) - 1

print(hoge)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


n = int(input())
s = [input() for _ in range(n)]
S = [0]*n
goukei = 0
for i in range(n):
    S[i] = "".join(sorted(s[i]))
C = set(S)
for i in C:
    if S.count(i) >= 2:
        goukei += combinations_count(S.count(i),2)
print(goukei)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

letter = []

n = int(input())
for i in range(n):
    word = []
    s = input()
    for j in 'abcdefghijklmnopqrstuvwxyz':
        word.append(s.count(j))
    letter.append(word)
ans = 0
moya = []
for i in range(n):
    moya.append(letter.count(letter[i]))
for i in range(2, n+1):
    aaaaa = moya.count(i) // i
    ans += ((i * (i-1)) // 2) * aaaaa
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
    S.append(''.join(sorted(list(input()))))

for i in range(N):
    if iscalc[i]:
        for j in range(i+1,N):
            if S[i]==S[j]:
                temp_ans += 1
                iscalc[j]=False
        ans_list.append(temp_ans)
        temp_ans=1


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

print(round(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools
def count(string):
    sets = list(set(string))
    return {s: string.count(s) for s in sets}

def infer(match):
    match_num = 0
    for x, y in itertools.combinations(match, 2):
        if x == y:
            match_num += 1
    
    return match_num

N = int(input())
sents = [count(input()) for i in range(N)]
ans = infer(sents)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = []
for i in range(n):
    s = input()
    key = []
    val = []
    for j in range(10):
        cnt = 1
        if s[j] not in key and j < 9:
            for k in range(j+1,10):
                if s[j] == s[k]:
                    cnt += 1
            key.append(s[j])
            val.append(cnt)
        elif j == 9:
            if s[j] not in key:
                key.append(s[j])
                val.append(cnt)
    d = dict(zip(key, val))
    lis.append(d)
#print(lis)
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        if lis[i] == lis[j]:
            ans += 1
#print(lis[1] == lis[3])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

for _ in range(N):
    S.append(input())

def create_hash(_str):
    hash = ""
    for i, a in enumerate(["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"]):
        count = 0
        for s in _str:
            if s == a:
                count += 1
        hash += str(count)
    return hash

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

hist = {}
for s in S:
    hash = create_hash(s)
    hist[hash] = hist.get(hash, 0) + 1

pairs = 0
for k, v in hist.items():
    if v > 1:
        pairs += combinations(v, 2)
print(pairs)

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]

ans = 0
done_list = []
for s in S:
    if s in done_list: continue
    count = S.count(s)
    ans += combinations_count(count, 2)
    done_list.append(s)




print(ans)

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)]
cnt = 0
for i in range(0, n-1):
    stype1 = {}
    for j in range(10):
        if s[i][j] in stype1:
            stype1[s[i][j]] += 1
        else:
            stype1[s[i][j]] = 1
    for k in range(i+1, n):
        stype2 = {}
        for l in range(10):
            if s[k][l] in stype2:
                stype2[s[k][l]] += 1
            else:
                stype2[s[k][l]] = 1
        if stype1 == stype2:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word) == get_counter(second_word)
flag=0
n=int(input())
list1=[]
check_list=[]
for i in range(n):
    list1.append(input())
for i in range(n):
    for j in range(n):
        if verify_anagrams(list1[i], list1[j]):
            if (i!=j)and(list1[j] not in check_list):
                check_list.append(list1[i])
                flag=flag+1
print(flag)

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:
import numpy as np
N = int(input())

List=[input() for i in range(N)]
count = 0

ct = np.zeros((N, ord('z') - ord('a')+1))
for i, s1 in enumerate(List):
  for x in s1:
  	ct[i, ord(x)-ord('a')]+=1
  k = ct[i]
  for p in range(i) :
    if (k == ct[p]).all():
      count+=1

print(count)

Submission status: Time Limit Exceeded

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

from collections import Counter

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

cnt = 0
d = dict([(k,v) for k, v in zip(range(N), [range(i+1, N) for i in range(N)])])
for i in range(N):
    jrange= d[i]
    l_eq = []
    l_neq = []
    for j in jrange:
        if s_multisets[i] == s_multisets[j]:
            l_eq.append(j)
            cnt += 1
        else:
            l_neq.append(j)
    for k in l_eq:
        for l in l_neq:
            try:
                d[k].remove(l)
            except:
                pass

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [input() for i in range(n)]
    num = 0
    for i in range(len(a)):
        a[i] = "".join(sorted(a[i]))
    a.sort()
    for i in range(len(a)):
        e = a[i]
        j = 1
        while i+j < len(a) and e == a[i+j]:
            num = num + 1
            j = j + 1
    print(num)


main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(r)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import collections

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

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

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

Submission status: Time Limit Exceeded

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

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

print(int(a))

Submission status: Time Limit Exceeded

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

def sort_list(st):
    arr = []
    freq = []
    for moji in st:
        exist_in_st = False
        for i in range(len(arr)):
            if moji == arr[i]:
                freq[i] += 1
                exist_in_st = True
        if exist_in_st == False:
            arr.append(moji)
            freq.append(1)
    ans = []
    for st, num in zip(arr, freq):
        ans.append([st,num])
    ans.sort(key=lambda x:x[0])
    return  ans

def compare_lists(li1, li2):
    if len(li1) != len(li2):
        return False
    if len(li1) == len(li2):        
        for a1, a2 in zip(li1, li2):
            if  a1 != a2:
                return False
    return True

sts = []
nums = []
for new_st in s:
    new_st = sort_list(new_st)
    exist_in_sts = False
    for i in range(len(sts)):
        if (new_st == sts[i]):
            nums[i] += 1
            exist_in_sts = True
    if exist_in_sts == False:
        sts.append(new_st)
        nums.append(1)

ans = sum([int(x * (x - 1) / 2) for x in nums])
print(ans)

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)
    if l.count(s_str)>1:
        cnt=cnt+l.count(s_str)-1

print(cnt)
#print(l)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

S = []
for i in range(n):
    s = input()
    s = sorted(list(s))
    s = str(s)
    S.append(s)

T = set(S)

ans = 0
cnt = [S.count(T.pop()) - 1 for i in range(len(T))]
for c in cnt:
    ans += c * (c+1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper())
 
    return get_counter(first_word) == get_counter(second_word)

N = int(input())

S = [0 for i in range(N)]

for i in range(N):
  S[i] = input()
  
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

k = 0
while len(S) > 1:
    ss = S[0]
    n = S.count(ss)
    k += n*(n-1)//2
    S = S[n:]

print(k)

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
list = []
counter = 0
for i in range(n):
    list.append([c for c in raw_input()])

from collections import Counter

for j in range(n):
    for k in range(j+1,n):
        if sorted(list[j]) == sorted(list[k]):
            counter +=1
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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


count=0
while len(su)>0:
  j=su[0]
  del su[0]
  count+=su.count(j)
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [str(input()) for i in range(N)]
ans=0
def anagram(si,sj):
    for si_i in si:
        sj = sj.replace(si_i,"",1)
    if sj=="":
        return 1
    else:
        return 0
for i in range(int(N)-1):
    for j in range(i+1,int(N)):
        if anagram(s[i],s[j]):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_li = []
for i in range(n):
    s = input()
    s_i = {}
    for j in range(10):
        s_i[s[j]] = 0
    for j in range(10):
        s_i[s[j]] += 1
    buf = ""
    for k, v in sorted(s_i.items()):
        buf += str(k) + str(v)
    s_li.append(buf)

ans = 0

for i in range(n):
    for j in range(n):
        if i >= j :
            continue
        if s_li[i] == s_li[j]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def fun(x):
    ret = 1
    while x:
        ret *= x
        x -= 1
    return ret

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


n = int(input())

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

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

Submission status: Time Limit Exceeded

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

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

c=0
for i in sn:
    n=s.count(i)
    c += (n*(n-1)//2)

print(c)

Submission status: Time Limit Exceeded

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

counter = 0
check = 0

for i in range(N-1):
    for j in range(i+1, N):
        n1 = [0] * 26
        n2 = [0] * 26
        check = 0
        for c in str[i]:
            for l in range(26):
                if ord(c) == ord('a') + l: n1[l] += 1
        for c in str[j]:
            for l in range(26):
                if ord(c) == ord('a') + l: n2[l] += 1
        for k in range(26):
            if n1[k] != n2[k]: check=1
        if check==0: counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

def isAnagram(one, two):
    lapped_list = [0 for i in range(10)]
    is_anagram = True
    for i in range(10):
        target = one[i]
        index = two.find(target)
        if index == -1:
            is_anagram = False
            break
        elif one.count(target) != two.count(target):
            is_anagram = False
            break
    return is_anagram

counter = 0

while len(string_list) > 0:
    same_counter = 0
    same_list = []
    for i in range(1, len(string_list)):
        one = string_list[0]
        two = string_list[i]
        if isAnagram(one, two):
            same_counter += 1
            same_list.append(i)
    if same_counter != 0:
        counter += (same_counter * (same_counter+1))/2
        for j in reversed(range(same_counter)):
            string_list.pop(same_list[j])
    string_list.pop(0)

print(int(counter))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding : utf-8

import os
import sys

N = int(input())

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

S = list(map(lambda x: "".join(sorted(x)), S))

#for s in S:
#	print(s)

S.sort()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
cnt = 0
N = int(input())
s = [0] * N
for i in range(N):
    s[i] = str(sorted(input()))

cnt = 0
for i in set(s):
    n = s.count(i)
    cnt += n * (n - 1) // 2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n) :
	s.append(sorted(input()))
c = 0
 
for i in range(len(s)) :
	c += s[i+1:].count(s[i]) 
print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations

ans = 0
N = int(input())

S = list()
for n in range(N):
  S.append(input())
  
def count(s1, s2):
  global ans
  s1, s2 = list(s1), list(s2)
  c1, c2 = Counter(s1), Counter(s2)
  c1, c2 = sorted(c1.items(), key=lambda x:x[0]), sorted(c2.items(), key=lambda x:x[0]) 
  if c1 == c2:
    ans += 1
  
for STR in list(combinations(S, 2)):
  count(*STR)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

ans = 0
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    for j, compe_word in enumerate(words[ix+1:]):
        compe_word_list = list(compe_word)
        compe_word_list.sort()
        if ''.join(map(str, compe_word_list)) == ''.join(map(str, word_list)):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# ABC137 C

import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
    
def C(n, r):
    return P(n, r)//math.factorial(r)

def is_anagram(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)
    
n = int(input())
s = []
for _ in range(n):
    s.append(input())

count = 0
while len(s) > 0:
    anagram = 0
    w1 = s.pop()
    for w2 in s:
        if len(w1) == len(w2):
            if is_anagram(w1, w2):
                anagram += 1
                s.remove(w2)
    if anagram > 0:
        count += C(anagram + 1, 2)
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
def Stair(x):
  y=1
  for z in range(1,x+1):
    y*=z
  return y
N=int(input())
L=[]

for i in range(N):
  L.append(sorted(str(input())))

K=[]
C=[]

for j in range(N):
  if L[j] not in K:
    K.append(L[j])
    C.append(1)
  else:
    C[K.index(L[j])]+=1

A=0
for k in range(len(K)):
  if C[k]>1:
    if C[k]==2:
      A+=1
    else:
      A+=Stair(C[k])/(2*Stair(C[k]-2))

print(int(A))

Submission status: Time Limit Exceeded

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

ans = 0
i = 0
while i < len(l):
    ans += sum([sorted(l[i]) == sorted(l[n]) for n in range(i+1,n)])
    i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [''.join(sorted(input())) for _ in range(0, N)]
d = {}

for s in S:
    if s[0] in d.keys():
        d[s[0]].append(s)
    else:
        d[s[0]] = [s]

result = 0

for k in d.values():
    if len(k) > 1:
        for i, s in enumerate(k):
            for j in range(i + 1, len(k)):
                if s == k[j]:
                    result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys,math
N = int(input())
s = []
ans = 0
for i in range(N):
    tmp = input()
    li_tmp = list(tmp)
    s_tmp = sorted(li_tmp)
    st = "".join(s_tmp)
    s.append(st)

a = []
a.append(s[N-1])
for i in range(N-2,-1,-1):
    ans += a.count(s[i])
    a.append(s[i])
print(ans)

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:
import numpy as np
n   = input()
dic = {chr(j):i for i,j in enumerate(range(97, 97+26))}
input_list = []
for i in range(int(n)):
    input_vec   = np.zeros(26)
    for i in input():
        input_vec[dic[i]] += 1
    input_list +=[input_vec]
count = 0
print(int(np.array([ 1 if ((text_1 - text_2)**2).sum() == 0 else 0 for text_1 in input_list[:-1] for text_2 in input_list[:-1]]).sum()/2))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import math

l_s = []
c = 0
n = int(input())
for i in range(n):
    s = input()
    c += l_s.count(sorted(s))
    l_s.append(sorted(s))

print(c)

Submission status: Time Limit Exceeded

Solution code:
def check(line):
    moji = 0
    for c in line:
        moji += pow(10, (ord(c)-97))
    return moji


N = int(input())
s = [input() for i in range(N)]
res = []
count = 0

for x in s:
    res.append(check(x))

for k, x in enumerate(res):
    for j in range(k+1, N):
        if x == res[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
from itertools import combinations
import string

N = int(input())
s = [str(input()) for x in range(N)]


cs = [Counter(x) for x in s]

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