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: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
N = 10**5+1
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

n = onem()
a =[]

for i in range(n):
    k = list(input())
    k.sort()
    a.append(k)

a.sort()
b = s(a)

co = 0

for i in range(len(b)):
    if b[i][1] != 1:
        co += cmb(b[i][1],2)
print(co)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [''.join(sorted(input())) for _ in range(N)]
#S = [input() for _ in range(N)]
d = {}
for s in S:
  if s not in d:
    d[s] = 0
  d[s] += 1
  
ans = len([v for v in d.values() if v > 1])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
s = [0] * N
for i in range(N):
    s[i] = input()

c = [0] * N
for i in range(N):
    c[i] = collections.Counter(s[i])

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

S = []

for i in range(N):
    s = input()
    slist = list(s)
    slist.sort()
    s = ''.join(slist)
    S.append(s)

count = 0

for s in set(S):
    s_counts  = S.count(s)
    if s_counts > 1:
        fac = math.factorial(s_counts)
        count += fac//2

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

N = int(input())
#k,x = map(int,input().split())

S=[]
for i in range(N):
    s=list(input())
    s.sort()
    S.append(''.join(x for x in s))

ans=0

S.sort()
for key, value in groupby(S):
    l=len(list(value))
    if l==2:
        ans+=1
    elif l>2:
        ans+=l


print(str(ans))

Submission status: Wrong Answer

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])
print(t)
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: Wrong Answer

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):
        print(i, j)
        if s[i] == s[j]:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
n = int(n)
count = 0
word = []

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

for i in range(n):    
    for j in range(n - i - 1):
        master = list(word[i])
        master_arr = len(master)
        target = list(word[j])
        for k in range(len(target)):
            master.append(target[k])
        if len(list(set(master))) == master_arr:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:

N=int(input())

S=[]
for n in range(N):
    s=input()
    s=''.join(sorted(s))
    S.append(s)

total=0
for x in list(set(S)):
    t=S.count(x)
    if t>=2:
        if t%2==0:
            total+=int(t/2)
        else:
            total+=int(t)

print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = {}
for i in range(n):
    s = tuple(sorted(input()))
    if s in d:
        d[s] += d[s] + 1
    else:
        d[s] = 0
    
print(sum(d.values()))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
info=[]
for i in range(n):
  info.append(list(input()))
  
for i in range(n):
  info[i].sort()
  
  
ans=0
for i in range(n):
  for j in range(n-i-1):
    if info[i]==info[i+j+1]:
      ans+=1
      
print(ans)
print(info)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = [''.join(sorted(input())) for j in range(n)]
ls = sorted(ls)

s = ls[0]
i = 1
count = 1
ans = 0
while i < n:
  if ls[i] == s:
    count += 1
    i += 1
    if i == n-1:
      ans += count*(count-1)//2
  else:
    ans += count*(count-1)//2
    count = 1
    s = ls[i]
    i += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

si = []
base_i = ord('a')
for i in range(N):
    inp = input()
    tsum = 0
    for c in inp:
        tsum += 2**(ord(c)- base_i)
    si.append(tsum)

c = collections.Counter(si)

def nc2(n):
    return n*(n-1)//2

ans = 0
for i in c.values():
    if i > 1:
        ans += nc2(i)

print(ans)

Submission status: Wrong Answer

Solution code:
_, *S=open(0).read().split()
a={}
res=0
for s in S:
    x = sum([ord(c) for c in s])
    if x in a:
        res += a[x]
        a[x] += 1
    else:
        a[x] = 1
print(res)

Submission status: Wrong Answer

Solution code:
def comb(a,b):
    x = 1
    for i in range(1,a+1):x*=i
    for i in range(1,b+1):x//=i
    return(x)


n = int(input())

dict_num = {}

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

c=0
for k,v in dict_num.items():
    if(v>=2):c += comb(v,2)
print(c)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    string_type = {}
    for s in inputs:
        count = {}
        s_list = list(s)
        s_list.sort()
        for c in s_list:
            if c in count:
                count[c] += 1
            else:
                count[c] = 1
        key = ""
        for k in count.keys():
            key += "{}{}".format(k, count[k])
        if key in string_type:
            string_type[key] += 1
        else:
            string_type[key] = 1

    comb_count = 0
    for v in string_type.values():
        if v != 1:
            if v == 2:
                comb_count += 1
            else:
                comb_count += v
    return comb_count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = [set(input()) for i in range(n)]
counter = 0
for i in range(n-1):
  for j in range(i+1,n):
    if lis[i] == lis[j]:
      counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = ['']*n
for i in range(n):
    st = list(input())
    st.sort()
    s[i] = st
s.sort()


ans = 0
cnt = 0
for i in range(1,n):
    if s[i-1] == s[i]:
        cnt += 1
    else:
        ans += cnt*(cnt+1)//2
        cnt = 0
ans += cnt
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

chars = []
cnt = 0

for _ in range(n):
  new = sorted(list(input()))
  if new in chars:
    cnt += 1
  else:
    chars.append(new)
    
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = dict()
res = 0
for i in range(n):
  ss = input()
  ss = list(ss)
  ss.sort()
  ss = ''.join(ss)
  if d.__contains__(ss):
    res += d[ss]
  else:
    d[ss] = 1
print(res)

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e30)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    N = i_inpl()
    s = []
    for _ in range(N):
        si = "".join(sorted(input()))
        s.append(si)
    s.sort()
    ans = 0
    tmp = 1
    for i in range(N-1):
        if s[i] == s[i+1]:
            tmp += 1
        else:
            ans += comb(tmp, 2)
            tmp = 1
    # print(tmp)
    # if tmp == 1:
    #     ans += 1
    # else:
    ans += comb(tmp, 2)
    print(int(ans))

    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

S = [input() for i in range(N)]
words = []
num = []
for s in S:
    temp = set(list(s))
    if temp in words:
        num[words.index(temp)] += 1
    else:
        words.append(temp)
        num.append(1)

ret = 0
for i in num:
    ret += i*(i-1)//2

print(ret)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
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 II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    s_list = []
    for i in range(N):
        s = SI()
        s = sorted(s)
        s_list.append(''.join(s))

    s_list = sorted(s_list)
    dprint(s_list)

    cnt_list = []
    cnt = 0
    current = ''
    for s in s_list:
        if current != s:
            cnt_list.append(cnt+1)
            current = s
            cnt = 0
        else:
            cnt += 1
    cnt_list.append(cnt+1)
    dprint(cnt_list)
    ans = 0
    for cnt in cnt_list:
        if cnt == 0:
            continue
        else:
            ans += cnt*(cnt-1)//2
            ans %= MOD
    print(ans)
solve()

Submission status: Wrong Answer

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

tmp = []
for s in S:
  tmp.append("".join(sorted(s)))
print(Counter(tmp).most_common()[0][1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(sorted(str(input())))
ctr = 0
status = [0] * N
for i in range(N - 1):
    for j in range(i + 1, N):
        if S[i] == S[j] and status[j] == 0:
            ctr += 1
            status[j] = 1
print(ctr)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=[[0 for i in range(26)]for j in range(n)]
a=ord("a")
for i in range(n): #10**5
    s=input()
    for j in range(10):  #10
        m[i][ord(s[j])-a]+=1

s=[[0]]
for i in range(1,n):  #10**5
    b=1
    for j in range(len(s)):
        a=1
        for k in range(10):
            if m[s[j][0]][k]!=m[i][k]:
                a=0
                break
        if a:
            s[j]+=[i]
            b=0
            break
    if b:
        s+=[[i]]

ans=0
for i in range(len(s)):
    x=len(s[i])
    ans+=x*(x-1)//2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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]
    for x,y in zip(a,b):
      c = []
      d = []
      c += [x]
      d += [y]
    c.sort()
    d.sort()
    if c==d:
      cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import mul
from functools import reduce


def inpl():
    return list(map(int, input().split()))


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


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

d = {}
for s in S:
    tmp = list(s)
    tmp.sort()
    d[tuple(tmp)] = d.get(tuple(tmp), 0) + 1

print(d)
for k, v in d.items():
    ans += cmb(v, 2)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  counts = {}
  for i in range(N):
    s = input()
    ss = "".join(sorted(s))
    if not ss in counts:
      counts[ss] = 0
    counts[ss] += 1

  ans = 0
  for count in counts.values():
    if count > 1:
      combi = 1
      for n in range(3, count+1):
        combi *= n
      ans += combi
  print(ans)

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for i in range(n)]
d = {}
for i in s:
    num = 0
    for j in i:
        num += ord(j)
    if num in d:
        d[num] += 1
    else:
        d[num] = 1

ans = 0
for i in d:
    temp = d[i]
    ans += temp * (temp-1) /2

print(int(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
sN=[input() for _ in range(N)]
ret=0

def ana(s1,s2):
    tmp1=set(s1)
    tmp2=set(s2)
    if tmp1==tmp2:
        return True
    return False

for i in range(N-1):
    for j in range(i+1,N):
        if ana(sN[i],sN[j]):
            ret+=1

print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
candidates = []
for i in range(N):
    candidates.append("".join(sorted(input())))
new = set(candidates)
print(len(candidates) - len(new))

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [""]*N
for i in range(N) :
    L[i] = "".join(sorted(list(input())))
L = sorted(L)
L.append("#")
ans = 0
cnt = 0
for i in range(N) :
    if L[i] == L[i+1] :
        cnt += (cnt+1 if cnt != 0 else 1)
    else :
        ans += cnt
        cnt = 0
print(ans)

Submission status: Wrong Answer

Solution code:


N = int(input())
S = [list(input()) for _ in range(N)]
for i in range(N):
    S[i].sort()
S.sort()
ans = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def A():
    a, b = map(int, input().split())
    lt = [
        a + b,
        a - b,
        a * b
    ]
    print(max(lt))


def B():
    k, x = map(int, input().split())

    answer = ''
    for i in range(2*k-1):
        answer += str(x-k+1+i) + ' '

    answer = answer[:-1]
    print(answer)


def C():
    N = int(input())
    literals = [set(input()) for _ in range(N)]
    
    answer = 0
    for i in range(N):
        for j in range(N):
            if i is j:
                continue
            if literals[i] == literals[j]:
                answer += 1
    
    answer = int(answer/2)
    print(answer)
    

if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[set(input()) for _ in range(n)]
ans=0
for i in range(n):
    for j in range(n):
        if s[i]==s[j]:
            ans+=1
print((ans-n)//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
import math
s = [input() for _ in range(N)]
res = 0
count = [[0]*26 for _ in range(N)]
for i in range(N):
    for ss in s[i]:
        index = ord(ss)-ord('a')
        count[i][index] += 1
count.sort()
ans = [0]*(N+1)
for i in range(1, N):
    if all(count[i][j] == count[i-1][j] for j in range(26)):
        ans[i]=ans[i-1]+1
for i in range(N):
    if ans[i]>0 and ans[i+1]==0:
        res+=math.factorial(ans[i]+1)//2
print(res)

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = sorted([''.join(sorted(input())) for _ in range(N)])
print(S)
prev = ''
ans = 0
n = 0
for i in range(N):
    if S[i]!=prev:
        ans += n*(n-1)//2
        prev=S[i]
        n=1
    else:
        n+=1
ans += n*(n-1)//2

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    s = list(input() for _ in range(n))
    c = 0
    for i in range(n):
        for j in range(i + 1, n):
            si = set(s[i])
            sj = set(s[j])
            if si == sj:
                c += 1
    return c


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

print(s)
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: Wrong Answer

Solution code:
import collections
import math
n = int(input())
s_dict = {}
for _ in range(n):
    s = input()
    s = "".join(sorted(s))
    if s not in s_dict.keys():
        s_dict[s] = 1
    else:
        s_dict[s] += 1
ans = 0
for i in s_dict.values():
    ans += (math.factorial(i) // 2)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect


from math import factorial
# 組み合わせ
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

def main():
    num = int(input())
    data = [input() for i in range(num)]
    for i in range(num):
        data[i] = list(Counter(data[i]))
        data[i].sort()

    visit = [0 for i in range(num)]
    ans = 0
    for i in range(num):
        if visit[i]:
            continue
        visit[i] = 1
        kari = 1
        for j in range(i + 1, num):
            if data[i] == data[j]:
                visit[j] = 1
                kari += 1
        if kari >= 2:
            ans += combinations_count(kari, 2)
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
G = {}
p = 17923
M = 10 ** 9 + 7
for _ in range(n):
    s = input()
    s = sorted(list(s))
    yt = 0
    for i in range(len(s)):
        yt += p ** (i + 1) * (ord(s[i]) - 95)
        yt %= M
    if yt not in G:
        G[yt] = 0
    G[yt] += 1
ans = 0
for i in G:
    ans += G[i] * (G[i] - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
G = {}
p = 179
M = 10 ** 9 + 33
for _ in range(n):
    s = input()
    s = sorted(list(s))
    yt = 0
    for i in range(len(s)):
        yt += p ** (i + 1) * (ord(s[i]) - 95)
        yt %= M
    if yt not in G:
        G[yt] = 0
    G[yt] += 1
ans = 0
for i in G:
    ans += G[i] * (G[i] - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools
n = int(input())
l = []
for i in range(n):
    s = input()
    l.append(Counter(s))
    
q = list(itertools.combinations(range(n), 2))
ans = 0

for i in range(len(q)):
    if l[q[i][0]] == l[q[i][1]]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    S = [sorted(input()) for _ in range(N)]

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for i in range(N):
    s = sorted(input())
    for j in range(i):
        if S[j]==s:
            ans += 1
    S.append(s)

# print(len(S)-len(set(S)))
# print(S)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
a = input()
N = int(a)
s = [input() for i in range(N)]
count = 0

c = [collections.Counter(s[i]) for i in range(N)]

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
word = [input() for _ in range(n)]
count = 0

for i in range(n):
    word[i] = sorted(word[i])

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
word = [input() for _ in range(n)]
count = 0

for i in range(n-1):
    for j in range(i+1,n):
        a = sorted(word[i])
        b = sorted(word[j])
        if a == b:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
data=[]
d={}
for i in range(n):
  s=sorted(input())
  if s not in data:
    data.append(s)
    d[len(data)-1]=1
  else:
    d[data.index(s)]+=1
ans=0
for i in d:
  ans+=d[i]*(d[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
data=[]
d={}
for i in range(n):
  s=sorted(input())
  if s not in data:
    data.append(s)
    d[data.index(s)]=1
  else:
    d[data.index(s)]+=1
ans=0
for i in d:
  ans+=d[i]*(d[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
aa = []

for i in range(n):
  s = sorted(input())
  s = [''.join(s)]
  aa.append(*s)

cc = collections.Counter(aa)
c = [c[1] for c in cc.items() if c[1] >1]

def fact(n):
  x = 1
  for i in range(1, n+1):
    x *= i
  return x

def comb(n):
  return fact(n) / ( 2 * fact((n-2)))


ans = 0
for i in range(len(c)):
  ans += comb(c[i])
  

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
aa = []

for i in range(n):
  s = sorted(input())
  s = [''.join(s)]
  aa.append(*s)

cc = collections.Counter(aa)
c = [c[1] for c in cc.items() if c[1] >1]

def fact(n):
  x = 1
  for i in range(1, n+1):
    x *= i
  return x

def comb(n):
  return fact(n) / ( 2 * fact((n-2)))


ans = 0
for i in range(len(c)):
  ans += comb(c[i])
  

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [None] * n
ans = 0
for i in range(n):
    l[i] = sorted(input())
for i in range(n-1):
    for j in range(i+1, n):
        if l[i] == l[j]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
lis = []
N = int(input().rstrip())
for i in range(N):
  str = input().rstrip()
  counter = {}
  for c in str:
    if not c in counter:
        counter[c] = 1
    else:
        counter[c] += 1
  lis.append(counter)
count = 0
for i in range(N):
  for j in range(i+1, N):
    if lis[i] == lis[j]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
input = sys.stdin.readline
lis = []
N = int(input().rstrip())
for i in range(N):
  str = input().rstrip()
  counter = {}
  for c in str:
    if not c in counter:
        counter[c] = 1
    else:
        counter[c] += 1
  lis.append(counter)
count = 0
for i in range(N):
  for j in range(i+1, N):
    if lis[i] == lis[j]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = []
cnt = 0

for i in range(n):
  s = sorted(list(input()))
  arr.append(s)

for i in range(n):
  for j in range(n):
    if i != j and arr[i] == arr[j]:      
      cnt += 1

print(cnt//2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ss = [input() for n in range(N)]

def check_diff(s1, s2):
    if sorted(s1) == sorted(s2):
        return True
    else:
        return False

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
count_dict = {}
s = [''.join(sorted(input())) for i in range(N)]
for word in s:
    if word in list(count_dict.keys()):
        count_dict[word] +=1
    else:
        count_dict[word] = 1
result = sum([i *(i-1)/2 for i in count_dict.values()])
print(int(result))

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
log = []
arr = []
ans = 0
for _ in range(n):
  S = sorted(list(input()))
  s = ''.join(S)
  if s not in log:
    log.append(s)
    arr.append(1)
  else:
    i = log.index(s)
    ans += arr[i]
    arr[i] += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
log = []
arr = []
ans = 0
for _ in range(n):
  S = sorted(list(input()))
  if S not in log:
    log.append(S)
    arr.append(1)
  else:
    i = log.index(S)
    ans += arr[i]
    arr[i] += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

def sum_stair(n):
    num = 0
    for i in range(1, n + 1):
        num += i
    return num

def main():
    N = int(input())
    s = [sorted(input()) for _ in range(N)]

    t = []
    for i in s:
        if i not in t:
            t.append(i)

    ans = 0
    for i in t:
        ans += max(0, sum_stair(s.count(i) - 1))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

def sort_str(t):
    l = sorted(t)
    text = ''
    for i in range(len(t)):
        text += l[i]
    return text

def sum_stair(n):
    num = 0
    for i in range(1, n + 1):
        num += i
    return num

def main():
    N = int(input())
    s = [sort_str(input()) for _ in range(N)]

    t = set(s)
    ans = 0
    for i in t:
        ans += max(0, sum_stair(s.count(i) - 1))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [sorted(input()) for i in range(N)]
s.sort()
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        for k in range(10):
            c = 1
            if s[i][k] != s[j][k]:
                c = 0
                break
        if c == 0:
            break
        if c == 1:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [sorted(input()) for i in range(N)]
s.sort()
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if s[i] == s[j]:
            ans += 1
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n=int(input())
s=[input() for _ in range(n)]
dicti=[]
for i in range(n):
  tmp = collections.Counter(s[i])
  dicti.append(tmp)
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    if dicti[i]==dicti[j]: ans+=1
print(ans)

Submission status: Time Limit Exceeded

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