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:
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]
print('a')
S.sort()

ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)

Submission status: Wrong Answer

Solution code:
# -*- config: utg-8 -*-

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

sort_list = []

for i in s:
	str_sort_list = sorted(i)
	new_str = ''.join(str_sort_list)
	sort_list.append(new_str)

count = 0
for i in sort_list:
  hoge = sort_list.pop(0)
  chohuku_count = sort_list.count(hoge)
  count += chohuku_count
  

print(count)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
d = collections.defaultdict(int)
for _ in range(n):
    a = sorted(input())
    s = ''.join(a)
    d[s] += 1
print(d)
count = 0
for v in d.values():
    count += v * (v-1) // 2
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter


n=int(input())
string_list=[Counter(input()) for i in range(n)]
count=0
i2=0
for string1 in string_list:
    string_list.remove(string_list[i2])
    i2=i2+1
    if string1 in string_list:
        count=count+string_list.count(string1)

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
import itertools

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())

nums = ["".join(str(list(collections.Counter(input()).values()))) for _ in range(N)]
c = collections.Counter(nums).values()
ans = 0
for i in c:
    ans += cmb(i, 2)
print(ans)

Submission status: Wrong Answer

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

S = []
for i in range(len(s)):
    foo = list(reversed(s[i]))
    foo.sort()
    S.append(''.join(foo))
counter = []
for i in range(len(s)):
    counter.append(S.count(S[i]))
ans = max(counter) - 1
if ans < 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

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

ans = 0

for i in range(len(str)-1):
    list1 = list(str[i])
    for j in range(i+1,len(str)):
        count = 0
        list2 = list(str[j])
        for k in range(10):
            num = list2.count(list1[k])
            if num == 0:
                break
            else:
                count = count + 1
        if count == 10:
            ans = ans + 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力


def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))


def process(n, s):
    count = 0
    for i in range(0, n):
        for k in range(i, n):
            if i == k:
                continue
            if anagram(s[i], s[k]) == True:
                count += 1
    return count


def anagram(a, b):
    for i in a:
        if i in b:
            b.replace(i, '')
            continue
        else:
            return False
    return True

# def anagram(a, b):
#     a = ''.join(sorted(a))
#     b = ''.join(sorted(b))
#     return a == b


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
ans = 0
for i in range(n):
    s = input()
    s_lis = [ s[i] for i in range(10)]
    key = []
    val = []
    for j in range(10):
        if s_lis[j] not in key:
            key.append(s_lis[j])
            val.append(s_lis.count(s_lis[j]))
    d = dict(zip(key, val))
    lis.append(d)
    if n > 0:
        for l in range(i-1):
            if lis[-1] == lis[l]:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [0]*N
p = [0]*N
for i in range(N):
    s[i] = "".join(sorted(input()))
    print(s)
    for j in range(i-1,-1,-1):
        if s[i] == s[j]:
            p[i] = p[j] + 1
            break

print(sum(p))

Submission status: Wrong Answer

Solution code:

n=int(input())
lis=[]
ans=0
for i in range(n):
  lis.append(list(input()))
while(len(lis)>0) :
  aim=lis[0]
  sum=[]
  for k in range(len(lis)):
    if(set(aim)==set(lis[k])):
      sum.append(k)
  amount=len(sum)
  for m in range(amount):
    ans+=m
    if(len(lis)>0):
      lis.pop(sum[m]-m)
print(ans)

Submission status: Wrong Answer

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

def uniGram(sentences_String):
    return([sentences_String[0+i:1+i] for i in range(len(sentences_String)-1+1)])

sUniGramed = list(map(uniGram, s))
sSetted = list(map(set, sUniGramed))
sLength = len(sSetted)

ans = 0
for i in range(sLength-1):
    current = sSetted[i]
    for j in range(sLength-i-1):
        if current & sSetted[i+j+1] == current:
            ans += 1
        else:
            pass
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[list(input()) for i in range(n)]
count=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        p=[col for col  in a[i] if col not in a[j]]
        if len(p)==0:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [sorted(input()) for _ in range(n)]
s.sort()
count = 0
array = [0] * (n - 1)

for i in range(1, n):
    count = 0
    for k in range(len(s[0])):
        if s[i - 1][k] == s[i][k]:
            count += 1
            if count == len(s):
                array[i - 1] += 1
                if s[i - 2][k] == s[i][k]:
                    array[i - 2] += 1
        else:
            break

print(sum(array))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n=int(input())
s=[]
li=[]
ans=0
cnt=1

for i in range(n):
  s.append(sorted(input()))
s.sort(key=itemgetter(1,0))
s=s+['0']

for i in range(n):
  if s[i]==s[i+1]:
    cnt+=1
  elif cnt>0:
    li.append(cnt*(cnt-1)/2)
    cnt=1
print(int(sum(li)))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for i in range(n)]
s_sorted = []
c=0
for w in s:
    w_list = [c for c in w]
    w_list.sort()
    s_sorted.append(w_list)
for w2 in s_sorted:
    if s_sorted.count(w2) > 1:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = []
for _ in range(N):
    lst.append(input().split())
    
counter = []

for i in range(N):
    a = []
    for j in range(10):
        a.append(lst[i][0][j])
    counter.append(a)

for j in range(N):
    counter[j].sort()

cnt = 0

for k in range(N-1):
    for l in range(1, N-1):
        if counter[k] == counter[l]:
            cnt += 1
        else:
            continue
            
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    td = {}
    strs = []
    for _ in range(N):
        strs.append(sum([ord(ci) for ci in input()]))
    strs.reverse()

    for t in strs:
        if t not in td.keys():
            td[t] = 0
        elif td[t] == 0:
            td[t] = 1
        else:
            td[t] *= 2
    count = 0
    for v in td.values():
        if v > 0:
            count += v

    print(count)


main()

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
S = []
for i in range(N):
    S.append(','.join(sorted(str(input()))))
ctr = 0
T = []
ans = 0
while S:
    cur = S.pop(0)
    flg = 1
    for i in range(len(T)):
        
        if cur == T[i]:
            ans += 1
            flg = 0
            break
    if flg:
        T.append(cur)
print(ans)

Submission status: Wrong Answer

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

def main():
    n = int(input())
    s = sorted([sorted(input()) for i in range(n)])
    ans = 0
    for i in s:
        cnt = 1
        for k in range(0, len(s)-1):
            if s[k] == s[k + 1]:
                cnt += 1
            else:
                break
        del s[0:cnt]
        if cnt > 1:
            ans += (cnt * (cnt - 1)) // 2
    print(int(ans))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

arr = []

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

for s in arr:
    s.sort()

anag = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    # 省略できるかどうか判定
    flg = 0
    for x in range(i):
        if(anag[x][i] == 1):
            flg = 1
            prev = x
            break
    if(flg == 1):
        anag[i][i+1:] = anag[prev][i+1:]
        break

    s1 = arr[i]
    for j in range(i+1, n):
        s2 = arr[j]
        if(s1 == s2):
            anag[i][j] = 1

# print(anag)

count = 0

for a in anag:
    count += sum(a)

print(count)

Submission status: Wrong Answer

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

N = int(input())

S = []

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

S.sort()
print('a')
ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)

Submission status: Wrong Answer

Solution code:
num = int(input())
dic = [input() for i in range(num)]

sdic = []
ans = 0
for i in range(num):
    dic[i] = "".join(sorted(dic[i]))
while len(dic) > 0:
    now = dic[0]
    cnt = dic.count(now)
    ans += int((cnt * (cnt - 1)) / 2)
    for now in dic:
        dic.remove(now)
print(ans)

Submission status: Wrong Answer

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

S = []
for i in range(len(s)):
    foo = list(reversed(s[i]))
    foo.sort()
    S.append(''.join(foo))
counter = []
for i in range(len(s)):
    counter.append(S.count(S[i]))

print(max(counter) - 1)

Submission status: Wrong Answer

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

for i in range(n):
  s[i] = ''.join(map(str, sorted(s[i])))

s = sorted(s)

print(s)

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

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


count=0
while len(su)>0:
  j=su[0]
  del su[0]
  c=su.count(j)+1
  count+=c*(c-1)/2
  su=[i for i in su if i!=j]
  
print(int(count))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

len_org = len(temp)
len_unique = len(set(temp))

if len_org == len_unique:
  print(0)
else:
  print(len_org - len_unique)

Submission status: Wrong Answer

Solution code:
N=int(input())
strings=[list(str(input())) for a in range(N)]
sorteds=[]
for thing in strings:
    thing.sort()
    sorteds.append("".join(thing))
M=len(list(set(sorteds)))
print(N-M)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = []
for i in range(N):
    s.append(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:
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

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

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

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

# ans = n-len(set(s))
# print(s)
print(n-len(get_unique_list(s)))
# print(set(s))
# print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = []
for i in range(n):
    tmp = []
    tmp = list(input())
    tmp.sort()
    s.append("".join(tmp))

s.sort()

cnt = 0
key = s[0]
flag = 0
t_cnt = 0
for i in range(n-1):
    if key == s[i] and s[i] == s[i+1]:
        cnt += 1
        flag = 1
        t_cnt += 1
    elif s[i] != s[i+1] and t_cnt > 1:
        if flag == 1:
            cnt += 1
        key = s[i+1]
        flag = 0
        t_cnt = 0
    elif s[i] != s[i+1]:
        key = s[i+1]
        flag = 0
        t_cnt = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[input() for _ in range(n)]
for i in range(n):
    s[i] = sum(map(ord,list(s[i])))
print(len(s)-len(set(s)))

Submission status: Wrong Answer

Solution code:

n = int(input())
s = list([input() for i in range(n)])
q = [''.join(sorted(x)) for x in s]

c = 0
"""
for i in range(n):
	q.append(sorted(s[i]))

for i in range(n):
	for j in range(i+1,n):
		if q[i] == q[j]:
			c += 1
"""
p = sorted(q)
for i in range(n-1):
	if p[i] != p[i+1]:
		if i!=0:
			if p[i] == p[i-1]:
				c+=1

c1 = len(s)
c2 = len(set(q))

print(c1-c2+c)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
list = []
counter = 0
for i in range(n):
    list.append([c for c in raw_input()])
for j in range(n):
    counter += sorted(list[j+1:]).count(sorted(list[j]))
print(counter)

Submission status: Wrong Answer

Solution code:
num = int(input())
count = 0
list_a2z = [chr(i) for i in range(97, 97+26)]
dic_ana = {}
for _ in range(num):
    s = input()
    dic_a2z = {}
    for i in s:
        for j in list_a2z:
            if i == j:
                if j in dic_a2z:
                    dic_a2z[j] += 1
                    break
                else:
                    dic_a2z[j] = 1
                    break
    dic_a2z = str(sorted(dic_a2z))
    if dic_a2z in dic_ana:
        dic_ana[dic_a2z] += 1
    else:
        dic_ana[dic_a2z] = 1
for k in dic_ana.values():
    count += k * (k - 1) // 2
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
#l=[]
cnt=0
#for i in range(n):
#    s=input()
#    s_list=list(s)
#    s_list.sort()
#    s_str=str(s_list)
#    l.append(s_str)
#    if l.count(s_str)>1:
#        cnt=cnt+l.count(s_str)-1

S=[list(input()) for _ in range(n)]
for i in range(n):
    s=S[i]
    s.sort()
    S[i]=s
    if S.count(s)>1:
        cnt=cnt+S.count(s)-1
#print(S)

print(cnt)
#print(l)

Submission status: Wrong Answer

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


alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t," "u", "v", "w", "x", "y", "z"]

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

"""
ans = 0

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

Submission status: Wrong Answer

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

n = int(input())

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

    #解析
    str_list = [0] * 26
    for i in range(len(s)):
        h = list(s)
        str_list[ord(h[i])-ord('a')] += 1

    dict_str = ''
    for j in range(10):
        dict_str += str(str_list[j]) + ','
    list_list.append(dict_str)

#print(list(set(list_list)))

c = collections.Counter(list_list)

count = 0
for p in c.values():
    if p >= 2:
        for k in range(p):
        	count += k
        #print(list(range(p)))

#print(c)
print(count)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
countr = []
liss = []
for i in range(N):
  s = input()
  a = collections.Counter(s)
  if a in liss:
    ind = liss.index(a)
    countr[ind] += 1
  else:
    liss.append(a)
    countr.append(1)

ans = 0
for cc in countr:
  if cc > 1:
    ans = ans + cc * (cc - 1) / 2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())

ss = [0 for _ in range(N)]
counts = []

chars = [x for x in "abcdefghijklmnopqrstuvwxyz"]
num = len(chars)

for i in range(N):
  ss[0] = input().strip()
  _count = [0 for _ in range(num)]
  for _s in ss[0]:
    _count[chars.index(_s)] += 1
    
  counts += [_count]
  
answer = 0
  
for i in range(N):
  for j in range(i + 1, N):
    if ss[i] == ss[j]:
      answer += 1
    
print(answer)

Submission status: Wrong Answer

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

ss = sorted(ss)

total = 0
count = 0
for n in range(N):
    if n==0:
        continue
    # print("ss["+str(n-1)+"]="+str(ss[n-1]))
    # print("ss["+str(n)+"]="+str(ss[n]))
    if ss[n-1]==ss[n]:
        count += 1
    else:
        total += int(count*(count+1)/2)
        count = 0
    # print("===")
total += count
count = 0

print(int(total))

Submission status: Wrong Answer

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

S = []
for i in range(len(s)):
    foo = list(reversed(s[i]))
    foo.sort()
    S.append(''.join(foo))
counter = []
for i in range(len(s)):
    counter.append(S.count(S[i]))

print(max(counter))

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding: utf-8
amount = int(input())
strings = list(map(str, [input() for i in range(amount)]))
sum = 0

for i in range(len(strings)):
	# print(strings[i])
	abc = list(strings[i])
	abc.sort()
	strings[i] = ''.join(abc)
	# print(strings[i])

strings.sort()

for j in range(len(strings)-1):
	# print(j)
	if strings[j] == strings[j+1]:
		sum = sum+1

print(sum)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
l = ["".join(sorted([c for c in input()])) for i in range(N)]
l.sort()

print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
strings=[list(str(input())) for a in range(N)]
sorteds=[]
for thing in strings:
    thing.sort()
    sorteds.append("".join(thing))
print(sorteds)
M=len(list(set(sorteds)))
print(N-M)

Submission status: Wrong Answer

Solution code:
A = []
B = []
N = int(input())

for i in range(N):
	t = input()
	t = sorted(t)
	
	flag = True
	for i in range(len(A)):
		if A[i] == t:
			B[i] += 1
			flag = False
			break
	
	if flag:
		A.append(t)
		B.append(1)
		
ans = 0
for b in B:
	if b==2:
		ans += 1
	elif b!=1:
		t = 1
		for i in range(2,b+1):
			t*=i
		ans += t//2
		
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import itertools

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())

nums = ["".join(str(list(collections.Counter(list(input())).values()))) for _ in range(N)]
ans = 0
for i in collections.Counter(nums).values():
    ans += cmb(i, 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for i in range(n):
    si = set(input())
    s.append(si)
ans = 0
for j in range(n-1):
    for k in range(j+1, n):
        if s[j] == s[k]:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
i = int(input())
d = []
z = 0
x = 0

for s in range(i):
    f = sorted(input())
    t = ''.join(f)
    d.append(t)

for t in d:
    z = d.count(t)
    if z == 2:
        x = x + 1
        d.remove(t)
    elif z >= 3:
        x = x + z
        d.remove(t)
    else:
        continue

print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())

arr = []

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

for s in arr:
    s.sort()

anag = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    # 省略できるかどうか判定
    flg = 0
    for x in range(i):
        if(anag[x][i] == 1):
            flg = 1
            prev = x
            break
    if(flg == 1):
        anag[i][i+1:] = anag[prev][i+1:]
        break

    s1 = arr[i]
    for j in range(i+1, n):
        s2 = arr[j]
        result = True
        for k in range(10):
            if(s1[k] != s2[k]):
                result = False
                break
        if(result):
            anag[i][j] = 1

count = 0

for a in anag:
    count += sum(a)

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s_list = [''.join(sorted(input())) for _ in range(n)]
cnt = 0
for si in s_list:
    s_list.remove(si)
    add_cnt = 1
    for sj in s_list:
        if si == sj:
            cnt += add_cnt
            add_cnt += 1
            s_list.remove(sj)
    if len(s_list) <= 1:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
s_list = [input() for _ in range(int(N))]

new_s = []
for i, s in enumerate(s_list):
    s = list(set(s))
    new_s.append([{char, s_list[i].count(char)} for char in s])
    
match = []
M=[i for i in range(N)]
center = int(N/2)
count = 0
if N%2==0: # 偶数の時
    for i in range(N-1):
        for i in range(center):
            match.append((M[0+i],M[-1-i]))
        M = M[:1] + M[2:] + M[1:2]
else: # 奇数の時
    for i in range(N):
        for i in range(1,center+1):
            match.append((M[i],M[-i+1]))
        M = M[1:] + M[:1] # １つずつずらす
for m in match:
    if new_s[m[0]] == new_s[m[1]]:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    td = {}
    for _ in range(N):
        t = sum([ord(ci) for ci in input()])
        if t not in td.keys():
            td[t] = 0
        elif td[t] == 0:
            td[t] = 1
        else:
            td[t] *= 2
    count = 0
    for v in td.values():
        if v > 0:
            count += v

    print(count)


main()

Submission status: Wrong Answer

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

sdict = [{c:s.count(c) for c in s} for s in S]
c = [ "".join( [str(sd[c]) for c in 'abcdefghijklmnopqrstuvwxyz' if c in sd] ) for sd in sdict ]

sdictc = {}
maxSdictc = 0
for cc in c:
    #print(cc)
    if cc in sdictc:
        sdictc[cc] += 1
        maxSdictc += 1
    else:
        sdictc[cc] = 0

print(maxSdictc)

Submission status: Wrong Answer

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

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

count1 = 0

for i in range(len(str)-1):
    list1 = list(str[i])
    for j in range(i+1,len(str)):
        count2 = 0
        list2 = list(str[j])
        for k in range(10):
            num = list2.count(list1[k])
            if num == 0:
                continue
            else:
                count2 = count2 +1
        if count2 == 10:
            count1 = count1 + 1
        
print(count1)

Submission status: Wrong Answer

Solution code:
N = int(input())

def nume(x):
    return x*(x-1)/2-(x-1)

save = []

for i in range(N):
    s = ''.join(sorted(input()))
    save.append(s)

save.sort()

cnt = 0
serial = 1
for i in range(N-1):
    if save[i] == save[i+1]:
        cnt += 1
        serial += 1
    else:
        cnt += int(nume(serial))
        serial = 1

print(cnt)

Submission status: Wrong Answer

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

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

#print(s)

s_list = [[] for _ in range(n)]
for i in range(n):
    #listに格納
    for j in range(10):
        s_list[i].append(s[i][j])
    #ソートをかける
    s_list[i].sort()

check = []

#s_listの要素（リスト）について、
#他の要素と同一のものがあるかチェック
for i in range(n):
    for j in range(i+1, n):
        c = (s_list[i] == s_list[j])
        if (c == True) and (i not in check) and (j not in check):
            check.append(i)
            check.append(j)

#print(check)
print(len(check))

#重複を削除して要素数カウント

Submission status: Wrong Answer

Solution code:
#from Collections import Counter

N = int(input())
count = 0
word = []
def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)

def str_sort(str):
    #f = lambda str: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return lambda str: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
for _ in range(N):
    word.append(str_sort(input()))


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

Submission status: Wrong Answer

Solution code:
N = int(input())
X =[]
for i in range(N):
    Y =list(input())
    Y.sort()
    X.append(Y)
X.sort()
    
ans = 0
count = 1 
for i in range(N-1):
    if X[i] == X[i+1]:
        count += 1
    else:
        if count != 1:
            Z = 1
            for i in range(1,count+1):
                Z = Z * i
            Z = Z // 2
            ans = ans + Z
            count = 1
            
if count != 1:
    Z = 1
    for i in range(1,count+1):
        Z = Z * i
    Z = Z // 2
    ans = ans + Z
        
print(ans)

Submission status: Wrong Answer

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

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 = []
for i in range(n):
  s.append(input())
h = []
b = 'abcdedfhijklmnopqrstuvwyz'
for i in s:
  a = [0] * 27
  for c,d in enumerate(b):
    a[c] = i.count(d)
  ss = ''
  for j in a:
    ss += str(j)
  h.append(ss)
 
ans = 0
c = {}
for i in h:
  if c.get(i, -1) == -1:
    c[i] = 1
  else:
    c[i] += 1
sum = 0
for i in c:
  if c[i] < 2:
    continue
  ans += cmb(c[i],2)
print(ans)

Submission status: Wrong Answer

Solution code:
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 = []
ans = 0
n = 1

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

for i in range(N-1):
  if S[i] == S[i+1]:
    n += 1
  elif n >= 2:
    ans += cmb(n,2)
    n = 0
  else:
    n = 0

if S[N-1] == S[N-2]:
  ans += cmb(n,2)
  
print(ans)

Submission status: Wrong Answer

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

from operator import mul
from functools import reduce
def aaa(n,r):
    if n == 1:
        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

print(sum(map(lambda x:aaa(x, 2), a.values())))

Submission status: Wrong Answer

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

n = int(input())

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

    #解析
    str_list = [0] * 26
    for i in range(len(s)):
        h = list(s)
        str_list[ord(h[i])-ord('a')] += 1

    dict_str = ''
    for j in range(10):
        dict_str += str(str_list[j]) + ','
    list_list.append(dict_str)

#print(list(set(list_list)))

c = collections.Counter(list_list)

count = 0
for p in c.values():
    if p >= 2:
        count += sum(list(range(p)))
        #print(list(range(p)))

#print(c)
print(count)