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:
#!/usr/bin/env python3
import sys
from collections import defaultdict
from collections import Counter
from collections import OrderedDict

def solve(N: int, s: "List[str]"):
    count_dict = defaultdict(int)
    for i, string in enumerate(s):
        string = list(string)
        info = sorted(OrderedDict(Counter(string)).items(), key=lambda x:x[0])
        info = tuple([tuple([i, j]) for i, j in info])
        count_dict[info] += 1
    result = 0
    for _, v in count_dict.items():
        result += int((v-1) * 0.5 * (1 + v-1))
        #result += sum([i for i in range(v)])
    print(result)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections

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

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

    for num,i in enumerate(s):
        s[num] = collections.Counter(i)

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

    print(count)


if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
li = []
ct = 0
for i in range(n):
    #li.append("".join(sorted(input())))
    li.append(sorted(input()))
for i in range(n):
    for j in range(i+1, n):
        if li[i] == li[j]:
            ct += 1
print(ct)

Submission status: Time Limit Exceeded

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

col_S = [Counter(s) for s in S]
check_S = [0]*len(S)

res = 0
for ind, col_s in enumerate(col_S):
    if check_S[ind] == 1: continue
    cnt = 1
    for ref_ind, ref_col_s in enumerate(col_S[ind+1:]):
        if col_s == ref_col_s:
            check_S[ind+ref_ind+1] = 1
            cnt += 1
    res += cnt * (cnt-1) / 2

print(int(res))

Submission status: Time Limit Exceeded

Solution code:
def is_anagram(string1, string2):
  for a in string1:
    if a not in string2:
      return False
    string2 = string2.replace(a, "", 1)
  if len(string2) == 0:
    return True
  else:
    return False

N = int(input())
strings = [input() for i in range(N)]
ans = 0
for i in range(0, N-1):
  for j in range(i+1, N):
    if is_anagram(strings[i], strings[j]):
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

def get_sum(num):
    return num*(num-1)/2


N = int(input())
S = []
D = defaultdict(int)
ans = 0
for i in range(N):
    s = str(sorted(input()))
    D[s] += 1

for k, v in D.items():
    ans += get_sum(v)


print(int(ans))

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(len(S[i])):
        count[i][ord(S[i][j]) - ord('a')] += 1
#print(count)

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

print(COUNT)

Submission status: Time Limit Exceeded

Solution code:

def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)
#print(verify_anagrams(s,s2))
N = int(input())
ans = 0
words = [input() for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if verify_anagrams(words[i],words[j]):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_list = [sorted(list(input())) for _ in range(n)]
cnt = 0
for i in range(len(s_list) - 1):
    for j in range(i + 1, len(s_list)):
        if s_list[i] == s_list[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce


def cmb(n, r):
        r = min(n - r, r)
        if r == 0:
                return 1
        elif r < 0:
                return 0
        numer = reduce(mul, range(n, n - r, -1))
        denom = reduce(mul, range(1, r + 1))
        return numer // denom


N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
ans = 0
for si in set(s):
        n = s.count(si)
        ans += cmb(n, 2)
print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
"""
https://atcoder.jp/contests/abc137/tasks/abc137_c
"""

import numpy as np


def calc(N: int, strings: np.ndarray) -> np.ndarray:
    strings_preprocessed = [calc_char_counts(s) for s in strings]
    anagram_count = 0
    for i in range(N):
        for j in range(i + 1, N):
            if strings_preprocessed[i] == strings_preprocessed[j]:
                anagram_count += 1
    return anagram_count


def calc_char_counts(string: str):  # Dict[str, int]
    characters = {c for c in string}
    return {c: string.count(c) for c in characters}


def main() -> None:
    N = int(input())
    strings = np.array([input() for _ in range(N)])
    result = calc(N, strings)
    print(result)


main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
s = [input() for i in range(N)]
ans = 0
for i in range(N):
  for j in range(i+1, N, 1):
    if Counter(s[i]) == Counter(s[j]):
      ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:


N = int(input())
A=[]
for i in range(N):
    A.append(input())
    
 
def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)
  
ans=0
for i in range(N):
    for j in range(i+1,N):
#         print(i,j)
#         print(verify_anagrams(A[i],A[j]))
        if verify_anagrams(A[i],A[j]):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [''] * N
for i in range(N):
    tmp = sorted(input())
    s[i] = ''.join(tmp)
s.sort()
cnt = 0
index = 1
for i in range(0,N - 1,index):
    index = 1
    for j in range(i + 1, N):
        if s[i] == s[j]:
            cnt += 1
            index += 1
        else:
            break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
s = np.array([''.join(sorted(input())) for _ in range(n)])
count = 0
for i in range(n):
    count += np.count_nonzero(s[i+1:] == s[i])
print(count)

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)

n=int(input())
string_list=[input() for i in range(n)]

count=0
for string1 in string_list:
    for string2 in string_list:
        if(string1!=string2):
            if(verify_anagrams(string1, string2)):
                count=count+1
count = int(count/2)

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

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

"""
a-zの文字数カウントする
[1,1,0,,,]
[1,1,0,,,]
[1,2,1,,,]

などのリストが得られる。
setしてカウント
"""

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
#  counts = []
#  ex = [chr(ord('a') + i) for i in range(26)]
#  for s in S:
#      cnt = [0 for _ in range(26)]
#      for char in set(s):
#          cnt[ex.index(char)] = s.count(char)
#      counts.append(cnt)
#  #  print(counts)
#  done_list = []
#  ans = 0
#  for cnt in counts:
#      if cnt in done_list:
#          continue
    
#      # nC2 を計算
#      c = counts.count(cnt)
#      if c == 1:
#          continue
#      a = combinations_count(c, 2)
#      ans += a
#      done_list.append(cnt)


new_chars = []
for s in S:
    tmp = sorted(list(set(s)))
    chars = ''
    for t in tmp:
        chars = chars + s.count(t) * t
    new_chars.append(chars)

tmp = list(set(new_chars))
ans = 0
for t in tmp:
    cnt = new_chars.count(t)
    if cnt == 1:
        continue
    ans += combinations_count(cnt, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lists = [input() for i in range(n)]
cnt = 0
for i in range(n-1):
  for j in range(i+1,n):
    a = lists[i]
    b = lists[j]
    c = []
    d = []
    for x in a:
      c += [x]
    for y in b:
      d += [y]
    c.sort()
    d.sort()
    if c == d:
      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)

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

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

print(count)

Submission status: Time Limit Exceeded

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

dicts = [defaultdict(int) for _ in range(N)]

for i in range(N):
    for j in range(10):
        dicts[i][s[i][j]] += 1
#print(dicts)
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        #print(dicts[i], dicts[j])
        if dicts[i] == dicts[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

count = 0
strs = sorted( strs )
for i in range( n ) :
	bFound = False
	for j in range( i+1, n ) :
		if strs[i] == strs[j] :
			count += 1
			bFound = True
		elif bFound == True :
			break
		else:
			pass

print( count )

Submission status: Time Limit Exceeded

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

for i in range(n):
    s=input()
    tmp_set=list(set(s))
    s_dict={}
    
    for i in tmp_set:
        s_dict[i]=s.count(i)    
    li.append(s_dict)

ans=0

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())

F    = [None] * (N+1)
F[0] = 1

for i in range(1, N+1):
    F[i] = F[i-1] * i

S = [None] * N

for i in range(N):
    S[i] = ''.join(sorted(list(input())))

print(sum([F[i] // F[i-2] // 2 for i in Counter(S).values()]))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n):
    first = s[i]
    for j in range(n):
        if i >= j:
            continue
        second = s[j]
        for k in range(10):
            if first[k] == second[k]:
                if k==9:
                    ans += 1
                continue
            else:
                break


print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import collections

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
    
n = int(input())
S = []
count = []
for i in range(n):
    s = list(str(input()))
    s = collections.Counter(s)
    s = sorted(s.items(), key=lambda x:x[0])
    #print(s)
    if i == 0:
        S.append(s)
        count.append(0)
        continue
    if s in S:
        #print(S,s)
        #print(S.index(s))
        count[S.index(s)] += 1
        #count += 1
        #S.append(s)
    else:
        S.append(s)
        count.append(0)
#print(count)
ans = 0
for cnt in count:
    if cnt==0:
        continue
    ans += cmb(cnt+1, 2)
    
print(ans)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as cl
N = int(input())
List=[input() for i in range(N)]
count = 0
for x in range(N):
	for y in range(x+1,N):
		if (cl(List[x]) == cl(List[y])):
			count+=1
print(count)

Submission status: Time Limit Exceeded

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

pairs = 0

for pos,i in enumerate(s):
    for posj in range(pos+1,len(s)):
        j = s[posj]
        anagram = True
        for k in range(10):
            if i.count(j[k])!=j.count(j[k]) :
                anagram = False
                break
            if i.count(i[k])!=j.count(i[k]) :
                anagram = False
                break
        if(anagram):
            pairs+=1


print(pairs)

Submission status: Time Limit Exceeded

Solution code:

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

ans = 0

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

for i in range(N):
    s_i = S[i]

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

        if s_i == s_j:
            ans += 1


print(ans)

Submission status: Time Limit Exceeded

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

def make_charcount(word):
    charcount = {}
    for c in word:
        if c not in charcount:
            charcount[c] = 1
        else:
            charcount[c] += 1
    return charcount

charcount_list = [make_charcount(word) for word in word_list]

result = 0
while(len(charcount_list)):
    charcount = charcount_list.pop()
    result += len([1 for c in charcount_list if charcount == c])

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
anagrams = [sorted(input()) for i in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1, n):
        if anagrams[i] == anagrams[j]:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

cnt = 0
for i in range(n):
    for j in range(n):
        if i == j:
            pass
        else:
            a1 = list(s[i])
            b1 = list(s[j])

            a1.sort()
            b1.sort()

            a2 = "".join(a1)
            b2 = "".join(b1)

            if a2 == b2:
                cnt += 1

print(cnt//2)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import string

N = int(input())

CountList = []

atoz = string.ascii_lowercase
for i in range(N):
    temp = ''
    s=input()
    for c in atoz:
        temp+=str(s.count(c))
    CountList.append(temp)

count = 0
for i,str1 in enumerate(CountList[:-1]):
    for str2 in CountList[i+1:]:
        if str1==str2:
            count+=1

print(count)

Submission status: Time Limit Exceeded

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

N = int(input())

S = []

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

ct = 0
for n in range(N):
  for m in range(n+1,N):
    if S[n]==S[m]:
      ct+=1
      
print(ct)

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()
    for i in s:
        count_word = dict()
        for j in i:
            count_word[j] = i.count(j)

        ans.append(count_word)

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

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


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


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
sk = ""
count = 0
for i in range(n):
    si = input()
    sj = sorted(si)
    for j in range(len(si)):
        sk +=sj[j]
    s.append(sk)
    sk = ""

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if s[i] == s[j]:
            count += 1

print(count // 2)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
lst = [Counter(input()) for i in range(n)]
#lst2 = 1#Counter(lst)
#for i in len(lst):
#  print(i.values)
cnt = 0
for i in range(len(lst)-1):
  for j in range(i+1,len(lst)):
    #print(0)
    if lst[i]==lst[j]:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

List = []
for i in range(N):
    temp = {}
    for j in range(10):
        if A[i][j] in temp:
            temp[A[i][j]] += 1
        else:
            temp[A[i][j]] = 1
    List.append(temp)
    
ans = 0
for i in range(N-1):
    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())
s = []
for i in range(N):
    s.append(sorted(input()))

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:

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

count = 0
for i in range(len(str)):
    for j in range(i+1, len(str)):
        if str[i] == str[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations

n = int(input())

counters = []
for _ in range(n):
    counters.append(Counter(input().rstrip()))

ans = 0
for c1, c2 in combinations(counters, 2):
    ck1 = sorted(c1.keys())
    ck2 = sorted(c2.keys())
    if len(ck1) != len(ck2):
        continue
    for k1, k2 in zip(ck1, ck2):
        if k1 != k2:
            break
        elif c1[k1] != c2[k2]:
            break
    else:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

S = []
for i in range(N):
    S.append("".join(sorted(list(input()))))

cnt = 0
for i in range(N):
    cnt += S[i+1:].count(S[i])
    
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)
N = int(input())
s = [input() for i in range(N)]
num = 0
for i in range(N):
    for j in range(i+1,N):
        if verify_anagrams(s[i],s[j]):
            num+=1
print(num)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
sl=list([input() for i in range(n)])
sum=0
for i in range(n):
    sl1 = list(sl[i])
    sl1.sort()
    s1 = ''.join(sl1)
    for j in range(i+1,n):
        sl2 = list(sl[j])
        sl2.sort()
        s2 = ''.join(sl2)
        if s1==s2:
            sum+=1
print(sum)

Submission status: Time Limit Exceeded

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

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])
    #print("{}".format(s[i]))

ans = 0
uniqs = set(s)
for orig in uniqs:
    occurence = s.count(orig)
    ans = ans + (occurence * (occurence -1)) // 2
print("{}".format(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

my_list = []

for i in range(N):
    s_i = input()
    my_dict = {}
    for j in range(10):
        if s_i[j] in my_dict:
            my_dict[s_i[j]] += 1
        else:
            my_dict[s_i[j]] = 1
    my_dict = sorted(my_dict.items())
    my_list.append(my_dict)

sum = 0

for i in range(N):
    num = 0
    for j in range(i + 1, N):
        if my_list[i] == my_list[j]:
            num += 1
    sum += num

print(sum)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
def is_anagram(s1,s2):
    if Counter(s1)==Counter(s2):
        return True
    else:
        return False

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

Submission status: Time Limit Exceeded

Solution code:
import collections
import sys

input = sys.stdin.readline
N=int(input().strip())
S = [input().strip() for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if collections.Counter(S[i]) == collections.Counter(S[j]):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    dict_list =[]
    for i in range(n):
        dict={}
        s = input()
        for i in s:
            if i in dict:
                dict[i] = dict[i]+1
            else:
                dict[i]=1
        dict_list.append(dict)

    count = 0
    for i in range(n):
        for j in range(n):
            if j > i:
                if dict_list[i] == dict_list[j]:
                    count = count +1
    print(count)

Submission status: Time Limit Exceeded

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

result = 0

s_set = set(s)

for elem in s_set:
    cnt = s.count(elem)
    if cnt == 1:
        continue
    else:
        result += int(cnt * (cnt - 1) / 2)

print(result)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

ans = 0

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8


def main():
    # n = map(int, input().split(" "))
    n = int(input())
    m = []
    count = 0
    for _ in range(n):
        m.append(input())
    for i in range(n):
        for j in range(i+1, n):
            if is_anagram(m[i], m[j]):
                count += 1
    print(count)


def is_anagram(s1, s2):
    s1_length = len(s1)
    s2_length = len(s2)
    if s1_length != s2_length:
        return False
    else:
        for index in range(s1_length):
            search_char = s1[index: index+1]
            search_result = s2.find(search_char)
            if search_result == -1:
                return False
            else:
                s2 = s2.replace(search_char, "", 1)
    return True

main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ls=[]
for i in range(N):
    s=input()
    dc={}
    for ss in s:
        if ss in dc.keys():
            dc[ss]+=1
        else:
            dc[ss]=1
    ls.append(dc)
ans=0
#print(ls)
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):
    ss = ''.join(sorted(input()))
    s.append(ss)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
ss=[]
n=int(input())
i=0
while i!=n:

    s=list(input())
    s.sort()
    ss.append(s)
    i+=1
ans=0
i=0
while i!=n:
    s=ss[i]
    ans+=ss.count(s)-1
    i+=1
print(int(ans/2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
  SS = str(input())
  m = list(SS)
  m.sort()
  s.append(m)
s.sort()
ans = 0
for i in range(len(s)-1):
  for j in range(i+1,len(s)):
    if(s[i][0]==s[j][0]):
      if(s[i]==s[j]):
        ans += 1
    else:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


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

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

Submission status: Time Limit Exceeded

Solution code:
import collections
n=int(input())
s=[input() for i in range(n)]
t=[0]*n
for i in range(n):
    t[i]=collections.Counter(s[i])
ans=0
for i in range(n):
    for j in range(i+1,n):
        if(t[i]==t[j]):
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
ans = 0
for n in range(N):
  chars = sorted(list(input()))

  if chars in s:
    ans += s.count(chars)
  s.append(chars)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s= [input() for i in range(N)]
ans=0
for i in range(N):
        for k in range(i+1,N):
                A=list(s[i])
                for j in list(s[k]):
                        if j in A:
                                A.remove(j)
                if len(A) == 0:
                        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

res = 0
for i in range(N):
    for j in range(i + 1, N):
        res += int(S[i] == S[j])
print(res)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
sl=[]
count=0
for i in range(N):
  sl.append(input())
def hikaku(x,y):
  ans="gram"
  lx=list(x)
  ly=list(y)
  dicx={}
  dicy={}
  for i in range(len(lx)):
    countix=lx.count(lx[i])
    countiy=ly.count(ly[i])
    dicx[lx[i]]=countix
    dicy[ly[i]]=countiy
  if dicx!=dicy:
    ans="tigau"
  return ans

for i in range(N-1):
  for j in range(i+1,N):
    if hikaku(sl[i],sl[j])=="gram":
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = []
ans = 0
for i in range(n):
    si = input()
    si = sorted(si)
    ss = ""
    for a in si:
        ss += a
    s.append(ss)

sset = list(set(s))

if(len(sset) == len(s)):
    print(0)
else:
    for e in sset:
        if(s.count(e) == 1):
            continue
        ans += s.count(e) * (s.count(e) - 1) // 2

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

def anagrams(word1,word2):
    def get_counter(s):
        return Counter(s)
    return get_counter(word1)==get_counter(word2)

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

print(num)