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:
from operator import mul
from functools import reduce

def nCr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
S = [set(input()) for _ in range(N)]
queue = S.copy()
res = 0
while len(queue)>0:
    s = queue.pop(0)
    poplist = []
    for j in range(len(queue)):
        if s == queue[j]:
            poplist.append(j)
    i = 0
    for j in poplist:
        j -= i
        queue.pop(j)
        i+=1
    if len(poplist)>0:
        res += nCr(len(poplist)+1, 2)
print(res)

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]
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r]

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)):
    co += cmb(b[i][1],2)
print(co)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = {}

cnt = 0
for n in range(N):
    s = ''.join(sorted(input()))

    if s in S.keys():
        cnt += S[s]
        S[s] += 1
        print(s)
    else:
        S[s] = 1

print(cnt)

Submission status: Wrong Answer

Solution code:
# 2019/08/10

import sys
input=sys.stdin.readline
from collections import Counter

n=int(input())
s=[]
for i in range(n):
    a=sorted(list((input().rstrip('\n'))))
    a=''.join(a)
    s.append(a)
c=Counter(s)

cnt=0
for k,v in c.items():
    if v>1:
        cnt+=v

print(cnt-1)

Submission status: Wrong Answer

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

result = 0
for i in range(N - 1):
    for k in range(i + 1, N):
        if S[i] == S[k]:
            result += 1

print(result)

Submission status: Wrong Answer

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

import sys
from operator import mul
from functools import reduce

input = sys.stdin.readline

def cmb(n,r):
    r = min(n-r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def comb(a, b):
    n = a
    for _ in range(b):
        n -= 1
        a *= n

    for i in range(1, b):
        b *= i
    return int(a / b)


def main():
    n = int(input())
    m = {}
    for l in sys.stdin:
        s = ''.join(sorted(l.strip()))
        if s in m:
            m[s] += 1
        else:
            m[s] = 1
    cnt = 0
    for k, v in m.items():
        if v == 1:
            cnt += 1
        else:
            cnt += cmb(v, 2)
    print(cnt)

main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n = int(input())
lst = [input() for i in range(n)]
cnt = 0
for j in range(n - 1):
    for k in range(j + 1, n):
        a = sum(map(lambda x: ord(x), list(lst[j])))
        b = sum(map(lambda x: ord(x), list(lst[k])))
        if a == b:
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
num = []
count = 0
for i in range(N):
    S.append(input())
    num.append(1)
    for j in range(S[i].count('a')):
        num[i] *= 103
    for j in range(S[i].count('b')):
        num[i] *= 107
    for j in range(S[i].count('c')):
        num[i] *= 109
    for j in range(S[i].count('d')):
        num[i] *= 113
    for j in range(S[i].count('e')):
        num[i] *= 127
    for j in range(S[i].count('f')):
        num[i] *= 2
    for j in range(S[i].count('1')):
        num[i] *= 3
    for j in range(S[i].count('h')):
        num[i] *= 5
    for j in range(S[i].count('i')):
        num[i] *= 7
    for j in range(S[i].count('j')):
        num[i] *= 11
    for j in range(S[i].count('k')):
        num[i] *= 13
    for j in range(S[i].count('l')):
        num[i] *= 17
    for j in range(S[i].count('m')):
        num[i] *= 19
    for j in range(S[i].count('n')):
        num[i] *= 23
    for j in range(S[i].count('o')):
        num[i] *= 29
    for j in range(S[i].count('p')):
        num[i] *= 31
    for j in range(S[i].count('q')):
        num[i] *= 37
    for j in range(S[i].count('r')):
        num[i] *= 41
    for j in range(S[i].count('s')):
        num[i] *= 43
    for j in range(S[i].count('t')):
        num[i] *= 47
    for j in range(S[i].count('u')):
        num[i] *= 73
    for j in range(S[i].count('v')):
        num[i] *= 79
    for j in range(S[i].count('w')):
        num[i] *= 83
    for j in range(S[i].count('x')):
        num[i] *= 89
    for j in range(S[i].count('y')):
        num[i] *= 97
    for j in range(S[i].count('z')):
        num[i] *= 101

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
s = list(input() for k in range(N))
result = 0

for ana in s:
    counter = Counter(ana)
    s.remove(ana)
    count = 0
    for an in s:
        temp = Counter(an)
        if counter == temp:
            count += 1
            result += count
            s.remove(an)

print(result)

Submission status: Wrong Answer

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

s.sort()
count = 0

for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1
        for j in range(2,N-i):
            if s[i] == s[i+j]:
                count += 1
            else:
                break

print(count)

Submission status: Wrong Answer

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()
    same_count = len([1 for c in charcount_list if charcount == c])
    if same_count > 0:
        charcount_list.remove(charcount)
        result += sum([i+1 for i, j in enumerate(range(same_count))])

print(result)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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]
        xor = 0
        for k in range(10):
            xor = xor ^ ord(j[k])
            xor = xor ^ ord(i[k])
        if(xor==0):
            pairs+=1

print(pairs)

Submission status: Wrong Answer

Solution code:
n = int(input())
s_list = [input().split() for i in range(n)]
s_list = sorted(["".join(sorted(s[0])) for s in s_list])
s_list.sort()

cnt = 0
p = 1
while p<n:
  tmp = 0
  while p<n and s_list[p-1]==s_list[p]:
    cnt += 1
    tmp += 1
    p += 1
  if tmp>1:
    cnt += 1
  p += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
#C
N = int(input())
pairdic = {}
s = ''.join(sorted(input()))
pairdic[s] = 1
for i in range(1, N):
    s = ''.join(sorted(input()))
    if s in pairdic:
        pairdic[s] += 1        
    else:
        pairdic[s] = 1
result = 0
for i in pairdic:
    result += (pairdic[i] * pairdic[i]-1)//2
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [str(input()) for i in range(N)] 
for i in range(N):
    t[i] = list(t[i])
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        if set(t[i])==set(t[j]):
            cnt += 1
print(cnt)

Submission status: Wrong Answer

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

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

for i in range(math.ceil(len(l_s)/2)):
    c += l_s[i:].count(l_s[i])-1

print(c)

Submission status: Wrong Answer

Solution code:
from sys import stdin
data = []
N = int(stdin.readline().rstrip())
for _ in range(N):
    data.append(tuple(sorted(set(input()))))


ans = dict()

for i in data:
    if i in ans:
        ans[i] += 1
    else:
        ans[i] = 1

from scipy.misc import comb
res = 0
for j in ans.values():
    res += comb(j, 2, exact=True)
print(res)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
ab=[list(input()) for l in range(n)]

c=[0]*n
for i in range(n):
    c[i]=sorted(ab[i])
moji=[0]*n
for i in range(n):
    moji[i] = ','.join(c[i])

c = collections.Counter(moji)
print(c.most_common()[0][1]-1)

Submission status: Wrong Answer

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

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

for i in range(n):
    x = input().rstrip('\n')
    text = ''.join(sorted(list(x)))
    if text not in dic:
        dic[text] = 0
    else:
        dic[text] += dic[text]+1

ans = sum(list(dic.values()))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
dics = [0] * N
for i in range(N):
    s = input()
    count = 0
    dic = set()
    for k in list(s):
        dic.add(k)
    dics[i] = dic

result = 0
for i in range(N - 1):
    for k in range(i + 1, N):
        if dics[i] == dics[k]:
            result += 1

print(result)

Submission status: Wrong Answer

Solution code:
# 2019 8/10
# ABC137 C Green Bin

N = int(input())

words = []

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

words.sort()
print(words)

cnt = 0

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

print(cnt)

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)):
    co += cmb(b[i][1],2)
print(co)

Submission status: Wrong Answer

Solution code:
n = int(input())

t = [str(input()) for i in range(n)]

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) / 2 for k in t))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

print(res)

Submission status: Wrong Answer

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

import sys

input = sys.stdin.readline

def comb(a, b):
    if a == 2:
        return 1

    n = a
    for _ in range(b):
        n -= 1
        a *= n

    for i in range(1, b):
        b *= i
    return int(a / b)


def main():
    n = int(input())
    m = {}
    for l in sys.stdin:
        s = ''.join(sorted(l.strip()))
        if s in m:
            m[s] += 1
        else:
            m[s] = 1
    cnt = 0
    for k, v in m.items():
        cnt += comb(v, 2)
    print(cnt)

main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
ls=[]
ans=0
for i in range(n):
    s=input()
    n=0
    for j in range(10):
        n+=ord(s[j])
    ls.append(n)
c=Counter(ls)
for i in c.values():
    if i>1:
        ans+=i*(i-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
s_count = list()
for i in range(n):
    s = input()
    s_list = ""
    for j in range(26):
        s_list += str(s.count(chr(j + 97)))
    s_count.append(s_list)
s = collections.Counter(s_count)
print(sum(s.values()) - len(s))

Submission status: Wrong Answer

Solution code:
from collections import Counter as C
from scipy.misc import comb
n=int(input());s=[input() for _ in range(n)]
print(int(sum(map(lambda x:comb(x,2),C(tuple(sorted(C(i).most_common(),key=lambda x:x[0]))for i in s).values()))))

Submission status: Wrong Answer

Solution code:
N = int(input())
dics = [0] * N
for i in range(N):
    s = input()
    count = 0
    dic = {}
    for k in list(s):
        v = dic.get(k, None)
        if v is not None:
            dic[k] = v + 1
        else:
            dic[k] = 1
    dics[i] = dic
    print(dic)

result = 0
for i in range(N - 1):
    for k in range(i + 1, N):
        if dics[i] == dics[k]:
            result += 1

print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[]
a="abcdefghijklmnopqrstuvwxyz"
mojin=[0 for j in range(n)]
ans=0
cnt=0
for i in range(n):
  l=input()
  for j in l:
    for p,q in enumerate(a):
      if j==q:
        mojin[i]+=2**p

mojin.sort()
for i in range(1,n):
  if mojin[i]==mojin[i-1]:
    cnt+=1
    ans+=1
  else:
    if cnt>1:
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for i in range(n):
    ss = ''.join(sorted(input()))
    s.append(ss)
print(len([x for x in set(s) if s.count(x) > 1]))

Submission status: Wrong Answer

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

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

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

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

#print(sorted(ans))

ans.sort()

temp = ans[0]

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

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

#print(ans)
print(int(count))

Submission status: Wrong Answer

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

j = 0
flag = 0
res = []
ans = 0

res.append(s_list[0])
for j in range(N-1):
    if s_list[j] == s_list[j+1]:
        res.append(s_list[j+1])
    else:
        if len(res) >=2:
            ans += (len(res) * (len(res)-1)) //2
        res = []

if len(res) >=2:
    ans += (len(res) * (len(res)-1)) //2

elif len(res) == 1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:

from itertools import groupby

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

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

S.sort()

for key, value in groupby(S):
    l = len(list(value))
    ans += (l*(l-1) / 2)


print(str(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s=[]
m={}
sum=0
for i in range(0,n):
    tmp = (list(input()).sort())
    if tmp in m:
        m[tmp]+=1
    else:
        m[tmp] = 0
for k in m:
    if m[k]>1:
        sum+=m[k]
print(sum)

Submission status: Wrong Answer

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

c=0
for j in range(N):
    for i in range(N):
        if i<j:
            if s[i]==s[j]:
                c+=1
        else:
            break

print(c)

Submission status: Wrong Answer

Solution code:
def npr(n,r):
    if n == r:return 1
    ans1 = 1
    ans2 = 1
    for i in range(1,r+1):
        print((n-r+i),i)
        ans1 *= i
        ans2 *= (n-r+i)
    return ans2//ans1

N = int(input())
dics = {}
sl = []
for _ in range(N):
    s = input()
    sl.append(''.join(sorted(s)))
for c in sl:dics[c] = dics.get(c,0)+1
g = 0
for k in dics.keys():
    if dics[k] >=2:
        g += npr(dics[k],2)
print(g)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

count = 0

def check(m, s):
    for k in list(s):
        if k not in m:
            return False

    return True

for i, item in enumerate(arr):
    m = {}
    for k in list(item):
        m[k] = 1
    
    for j in range(i+1, N):
        if check(m, arr[j]):
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from math import factorial
N = int(input())
S = [[0 for j in range(10)] for i in range(N)]
for i in range(N):
    s = str(input())
    for j in range(10):
        S[i][j] = s[j]
    S[i].sort()
S.sort()
ans = 0
i = 0
j = 1
while i < N:
    tmp = 0
    while i + j < N and S[i] == S[i + j]:
        tmp += 1
        j += 1
    if tmp != 0:
        ans += factorial(tmp)
    i += 1
    j = 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
array = [''.join(sorted(list(input()))) for i in range(N)]
print(N - len(set(array)))

Submission status: Wrong Answer

Solution code:
n=int(input())
sl=list([input() for i in range(n)])
sum=0
m=[0]*n
for i in range(n):
    if m[i]==1:
        continue
    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
            m[j]=1
print(sum)

Submission status: Wrong Answer

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

def verify_anagrams(w1, w2):
  f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
  return f(w1) == f(w2)

for i in range(n):
  for j in range(i+1, n):
    if verify_anagrams(S[i], S[j]):
      print("{} {}".format(S[i], S[j]))
      ans += 1

print(ans)

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
            if i == len(x)-2:
                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)):
    co += cmb(b[i][1],2)
print(co)

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 t in range(N):
    for i in range(N):
        if Counter(s[i])==Counter(s[t]):
            count+=1
            print(s[i],s[t])
print(int((count-N)/2))

Submission status: Wrong Answer

Solution code:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
print(n-len(set(anagrams)))

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input())
a=[]
b=[]
c=0
for i in range(n):
    a.append("".join(sorted(list(input()))))
for i in range(n):
    if a[i] not in b:
        heapq.heappush(b,a[i])
print(n-len(b))

Submission status: Wrong Answer

Solution code:
def green_bin(n,s):
    count = 0
    for i in range(n-1):
        for j in range(1,n):
            if i == j:
                continue
            else:
                si = sorted(s[i])
                sj = sorted(s[j])

            if si == sj:
                count += 1

    return count
if __name__ == '__main__':
    n = int(input())
    s = [ input() for i in range(n)]

    print(green_bin(n,s))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
strs = [sorted(Counter(input()),key=lambda x:x[0]) for i in range(N)]
ans=0
for i in range(len(strs)):
    if strs[i] in strs[i+1:]:
        ans+=strs[i+1:].count(strs[i])
print(ans)

Submission status: Wrong Answer

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

num = 0
for i in range(n):
    for j in range(i + 1, n):
        if i == j:
            continue
        is_anagram = True
        for k in range(10):
            found = False
            for l in range(10):
                if s[i][k] == s[j][l]:
                    found = True
                    break
            if not found:
                is_anagram = False
                break
        if is_anagram:
            num += 1
print(num)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
s = [collections.Counter(input()) for i in range(n)]
print(s)

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

Solution code:
n = int(input())
a = [input() for i in range(n)]
b = []
for i in range(n):
  b.append(''.join(sorted(a[i])))

print(n - len(list(set(b))))

Submission status: Wrong Answer

Solution code:
from collections import Counter, defaultdict

N = int(input())
S = []
j = [0]*N

ans = 0
for i in range(N):
    p = Counter(input())
    if p in S:
        ans += 1
        j[S.index(p)] += 1
    else:
        S.append(p)

for i in j:
    if i > 1:
        ans += 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())
anaglams = {}
count = 0
for s in S:
    chrs = [0]*26
    for c in s:
        if c not in chrs:
            index = ord(c) - ord('a')
            chrs[index] = 1
            continue
        chrs[c] += 1
    if str(chrs) not in anaglams:
        anaglams[str(chrs)] = 0
    else:
        anaglams[str(chrs)] += 1
    count += anaglams[str(chrs)]
print(count)

Submission status: Wrong Answer

Solution code:
import itertools

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

ans = 0
c = list(itertools.combinations(s, 2))
for i in c:
    if i[0] == i[1]:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def nCr(n, r):
    r = min(r, n-r)
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i
    return numerator // denominator

N = int(input())
S = [set(input()) for _ in range(N)]
queue = S.copy()
res = 0
while len(queue)>0:
    s = queue.pop(0)
    poplist = []
    for j in range(len(queue)):
        if s == queue[j]:
            poplist.append(j)
    i = 0
    for j in poplist:
        j -= i
        queue.pop(j)
        i+=1
    if len(poplist)>0:
        res += nCr(len(poplist)+1, 2)
print(res)

Submission status: Wrong Answer

Solution code:
n =int(input())
X = [list(map(str, sorted(input()))) for i in range(n)]

result = 0
for i in range(n):
    for j in range(n-i-1):
        result += 1 if X[i]==X[j] else 0

print(result)

Submission status: Wrong Answer

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    sl = [''.join(sorted(input())) for i in range(n)]

    dic = {}
    for i in range(n-1, -1, -1):
        if sl[i] in dic.keys():
            dic[sl[i]] += dic[sl[i]] + 1
        else:
            dic[sl[i]] = 0

    print(sum([v for v in dic.values()]))

Submission status: Wrong Answer

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

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

l_s = []
for i in range(n):
    l_s.append(sorted(l[i]))

c = 0

for i in range(len(l_s)):
    c += l_s[i:].count(l_s[i])-1
    print(l_s[i:].count(l_s[i])-1)

print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
sums = [0] * N
for i in range(N):
    s = input()
    count = 0
    for k in list(s):
        t = ord(k)
        count += t
    sums[i] = count

result = 0
for i in range(N - 1):
    for k in range(i + 1, N):
        if sums[i] == sums[k]:
            result += 1

print(result)

Submission status: Wrong Answer

Solution code:
#import sys
N = int(input())
#A, B = list(map(int,input().split()))
S = [''.join(sorted(input())) for _ in range(N)]
D = {}
for s in S :
    if s in D :
        D[s] += 1
    else :
        D[s] = 1
V = list(D.values())
count = 0
for v in V :
    if v == 1 :
        count += 0
    elif v == 2 :
        count += 1
    elif v >= 3 :
        count += v
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [sorted(list(input())) for i in range(N)]
b = 0
for i in a:
 b = b + a.count(i)
print(b / 2)

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

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

count = 1
ans = 0
pre = ""
for s in sorted(S):
    if s == pre:
        count += 1
    else:
        ans += (count*(count-1))//2
        count = 1
    pre = s
ans += (count*count-1)//2
print (ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

Submission status: Wrong Answer

Solution code:

x = []
n = int(input())
for i in range(n):
    x.append(sorted(list(input())))
x = sorted(x)
s = 0
su = 0

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

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 = defaultdict(int)
    for _ in range(N):
        si = tuple(sorted(input()))
        s[si] += 1

    ans = 0
    for i in s.values():
        ans += comb(i, 2)
    
    print(int(ans))
if __name__ == "__main__":
    main()