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 collections import defaultdict
N = int(input())

anagrams = defaultdict(int)
for _ in range(N):
    chars = input()
    d = defaultdict(int)
    tuple_d = tuple(sorted(chars))
    if tuple_d in anagrams:
        anagrams[tuple_d] += anagrams[tuple_d]
    else:
        anagrams[tuple_d] += 1

print(sum([i-1 for i in anagrams.values()]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
cnt = 0
d = {}
for i in range(n):
  sortsi = ''.join(sorted(s[i]))
  #print(sortsi)
  if sortsi in d: cnt+=1
  else: d[sortsi]=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())

s=[]

d={}

ans=0

for i in range(n):
    tmp="".join(sorted(input()))
    if tmp not in d:
        d[tmp]=1
    else:
        ans+=d[tmp]
        d[tmp]+=d[tmp]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

s=[]

d={}

pre_number=0

ans=0

for i in range(n):
    tmp=input()
    tmp="".join(sorted(tmp))
    s.append(tmp)
    buf=set(s)
    if len(buf) != pre_number:
        pre_number=len(buf)
        d[tmp]=1
    else:
        ans+=d[tmp]
        d[tmp]+=d[tmp]
        
print(ans)

Submission status: Wrong Answer

Solution code:
import string

def bwords(str):
  str = list(str)
  bword = [0]*len(string.ascii_lowercase)
  for s in str:
  	bword[string.ascii_lowercase.index(s)]+=1
  return bword

def check_bword(a_word,b_word):
  for a,b in zip(a_word,b_word):
    if a != b:
      return False
  return True

N = int(input())
groups = {0: 1}
groups_bword = {0: bwords(input())}

for i in range(1,N):
  s = input()
  b_w = bwords(s)
  
  add_grouped = False
  
  for key,bword in groups_bword.items():
    if check_bword(b_w,bword):
      groups[key]+=1
      add_grouped = True
      break
      
  if not add_grouped:
    groups[len(groups.keys())] = 1
    groups_bword[len(groups_bword.keys())] = b_w

count = 0

for key,nums in groups.items():
  print(key,nums)
  count+=nums*(nums-1)//2
  
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = []
S = set()
count = 0
for i in range(n):
    line = "".join(sorted(list(input())))
    L.append(line)
    S.add(line)


for s in S:
    count += L.count(s) - 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input()for i in range(n)]
d = {}
ans = 0
for j in s:
    ss = "".join(sorted(s))
    if ss in d:
        d[ss] += 1
        ans += d[ss]
    else:
        d[ss] = 0
print(ans)

Submission status: Wrong Answer

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

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i])))
    d[s] += 1
 
ans = 0
for v in d.values():
    print(v)
    ans += v*(v+1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    
    from collections import Counter
    c = Counter(s)
    res = 0
    for i in c.most_common(2):
        cnt = i[1]
        res += cnt * (cnt-1) // 2
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    ss = set(s)
    res = 0
    if len(s) == len(ss):
        print(0)
        return
    if len(s) - len(ss) <= len(ss):
        print(len(s)-len(ss))
        return
    for i in ss:
        cnt = s.count(i) - 1
        res += (cnt+1)*cnt//2
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    dict = {}
    for i in range(N):
        s = "".join(sorted(input()))
        if s in dict:
            dict[s] = dict[s] * 2
        else:
            dict[s] = 1
    result = 0
    l = list(dict.keys())
    for j in l:
        result += int(dict[j])
    print(result - len(l))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    list = []
    result = 0
    N = int(input())
    for i in range(0, N):
        ss = input()
        s = "".join(sorted(ss))
        if i == 0:
            list.append(s)
        else:
            for j in list:
                if j == s:
                    result += 1
                    break
                list.append(s)
    print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

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

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

ha=[0]*N
for i in range(N):
    for j in range(len(s[i])):
        ha[i]+=pow(2,(ord(s[i][j])-ord("a")))

c=collections.Counter(ha)

ans=0
for n in c.values():
    ans+=(n*(n-1))//2
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range (n-1):
    if ss[i] == ss[i+1]:
        count = 2
        i+=1
        while i != n-1 and ss[i] == ss[i+1]:
            count+=1
            i+=1
        ans+=(count*(count-1)//2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
count = [0]*n
l = []
for i in range(n):
    a = ''.join(sorted(input()))
    if a in l:
        count[l.index(a)] += 1
    else:
        l.append(a)
print(max(count))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [input() for i in range(N)]
num = 0
for i in range(N):
    for j in range(i+1, N):
        count = 0
        for k in range(10):
            if s[i][k] in s[j]:
                count += 1
        if count == 10:
            num += 1

print(num)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    dic = {}
    s = "".join(sorted(input()))
    dic[s] = 0
    for _ in range(N-1):
        s = "".join(sorted(input()))
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 0
    return sum(dic.values())

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
d = {}
ans = 0

for i in range(n):
    s = ''.join(sorted(input()))
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
#print(d)
for k, v in d.items():
    if v != 1:
      print(v)
      ans += v * (v - 1) / 2

print(int(ans))

Submission status: Wrong Answer

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions


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 = []
n = 0
for i in range(N):
    s.append(list(input()))
ans = 0


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

s.sort()
for i in range(N):
    s[i] = set(s[i])


for i in range(1,N):

    if s[i]==s[i-1]:
        n += 1
        if i == N-1:
            ans += cmb(n+1, 2)
    else:
        if n > 0:
            ans += cmb(n+1,2)
            n = 0
print(ans)

Submission status: Wrong Answer

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions


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 = []
n = 0
for i in range(N):
    s.append(list(input()))
ans = 0
s.sort()
for i in range(N):
    s[i]=set(s[i])
for i in range(1,N):
    if s[i]==s[i-1]:
        n += 1
        if i == N-1:
            ans += cmb(n+1, 2)
    else:
        if n > 0:
            ans += cmb(n+1,2)
            n = 0
print(ans)

Submission status: Wrong Answer

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions


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 = []
n = 0
for i in range(N):
    s.append(list(input()))
ans = 0
s.sort()
for i in range(N):
    s[i]=set(s[i])
for i in range(N-1):
    if s[i]==s[i+1]:
        n += 1
        if i == N-2:
            ans += cmb(n+1, 2)
    else:
        if n > 0:
            ans += cmb(n+1,2)
            n = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
N = int(input())
S = []
for i in range(N):
    S.append("".join(sorted(input())))
S.sort()
C = []
cnt = 1
for i in range(N - 1):
    if S[i] == S[i + 1]:
        cnt += 1
    else:
        C.append(cnt)
        cnt = 1
C.append(cnt)
ans = 0
for cnt in C:
    ans += int(comb(cnt,2))
print(ans)

Submission status: Wrong Answer

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

d = {}
ret = 0
for s in S:
    new_s = "".join((sorted(s)))
    if new_s in d:
        if d[new_s] > 0:
            d[new_s] += d[new_s]
        else:
            d[new_s] = 1
    else:
        d[new_s] = 0
    ret += d[new_s]
print(ret)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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
  
def kaijo(n):
    if n == 1:
        return n
    return n * kaijo(n-1)
    
n  = int(input())
box = []
for i in range(n):
  a = str(input())
  aa = Counter(a)
  aaa = aa.most_common()
  box.append(aaa)
box.sort()
ans = 0
bago = 0
for i in range(len(box)-1):
  if i < bago: continue
  count = 1
  flag = True
  while flag:
    if i != len(box)-1:
      if box[i]==box[i+1]:
        count += 1
        i += 1
        bago = i
      else:
        flag = False
    else:
      count = 0
      flag = False
  ans += cmb(count, 2)
  
print(ans-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())
d = {}
ret = 0
for s in S:
    new_s = "".join((sorted(s)))
    if new_s in d:
        if d[new_s] > 0:
            d[new_s] += d[new_s]
        else:
            d[new_s] = 1
    else:
        d[new_s] = 0
    ret += d[new_s]
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())
d = {}
for s in S:
    new_s = "".join((sorted(s)))
    if new_s in d:
        d[new_s] += d[new_s]
    else:
        d[new_s] = 1
print(max(d.values()))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = []; count = 0
for i in range(N):
    spell = ''.join(sorted(input()))
    '''
    if spell in s:
        
        count += int(s.count(spell))
        '''
    s.append(spell)

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = []; count = 0
for i in range(N):
    spell = ''.join(sorted(input()))
    if spell in s:
        '''
        count += int(s.count(spell))
        '''
    s.append(spell)

print(count)

Submission status: Wrong Answer

Solution code:
# TODO: WAなので修正する
from math import factorial
from operator import mul
from functools import reduce

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

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

li.sort()
index = 0
anagram_cnt_sum = 0
while(index < n):
    anagram_cnt = li.count(li[index])
    if anagram_cnt > 1:
        anagram_cnt_sum += cmb(factorial(anagram_cnt), 2)
    index += anagram_cnt
print(anagram_cnt_sum)

Submission status: Wrong Answer

Solution code:
# TODO: WAなので修正する
from math import factorial

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

li.sort()
index = 0
anagram_cnt_sum = 0
while(index < n):
    anagram_cnt = li.count(li[index])
    if anagram_cnt > 1:
        anagram_cnt_sum += factorial(anagram_cnt) // 2
    index += anagram_cnt
print(anagram_cnt_sum)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
li = [input() for x in range(N)]
ans = 0
wli = list()
for k in li:
    word = ''.join(sorted(list(k)))
    if word in wli:
        ans += 1
    else:
        wli.append(word)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

s_set = []

for _ in range(N):
    inp = input()
    s_set.append(''.join(sorted(inp)))


sss = list(set(s_set))
print(N-len(sss))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s=[list(input()).sort() for i in range(n)]
c=Counter(s)
ans=0
for i in c.values():
  ans+=i*(i-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s=[list(input()).sort() for i in range(n)]
c=Counter(s)
ans=0
for i in c.values():
  ans+=i*(i-1)//2

Submission status: Wrong Answer

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

for i in range(N):
    #各文字列に番号A[i]を与える
    string = input()
    flag = True
    for j in range(10):
        A[i]+=10**(ord(string[j])-ord('a'))
        if(j<9):
            if(string[j]!=string[j+1]):
                flag = False
    if flag:
        A[i] = (ord(string[0])-ord('a')+1)*(-1)
    
A.sort()
ans=0

i=0
while(i<N-1):
    j=0
    if A[i] == A[i+1]:
        count=1
        while A[i+j] == A[i+j+1]:
            count+=1
            j+=1
            if i+j+1>=N-1:
                break
        ans += (count*(count-1))//2
    i += 1+j
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]*N
dic_list=[]

for i in range(N):
    #各文字列に番号A[i]を与える
    string = input()
    flag = True
    for j in range(10):
        A[i]+=10**(ord(string[j])-ord('a'))
        if(j<9):
            if(string[j]!=string[j+1]):
                flag = False
    if flag:
        A[i] = (ord(string[0])-ord('a')+1)*(-1)

A.sort()

ans=0

B = [0]*N
i=0
while(i<N-1):
    j=0
    if A[i] == A[i+1]:
        count=1
        while A[i+j] == A[i+j+1]:
            count+=1
            j+=1
            if i+j+1>=N-1:
                break
        ans += count*(count-1)//2
    i += 1+j
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]*N
dic_list=[]

for i in range(N):
    #各文字列に番号A[i]を与える
    string = input()
    flag = True
    for j in range(10):
        A[i]+=10**(ord(string[j])-ord('a'))
        if(j<9):
            if(string[j]!=string[j+1]):
                flag = False
    if flag:
        A[i] = (ord(string[0])-ord('a')+1)*(-1)

A.sort()
print(A)
ans=0

B = [0]*N
i=0
while(i<N-1):
    j=0
    if A[i] == A[i+1]:
        count=1
        while A[i+j] == A[i+j+1]:
            count+=1
            j+=1
            if i+j+1>=N-1:
                break
        ans += count*(count-1)//2
    i += 1+j
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]*N
dic_list=[]

for i in range(N):
    #各文字列に番号A[i]を与える
    string = input()
    flag = True
    for j in range(10):
        A[i]+=10**(ord(string[j])-ord('a'))
        if(j<9):
            if(string[j]!=string[j+1]):
                flag = False
    if flag:
        A[i] = (ord(string[0])-ord('a')+1)*(-1)

A.sort()

ans=0

B = [0]*N
for i in range(N-1):
    if A[i] == A[i+1]:
        j=0
        count=0
        count2=1
        while A[i+j] == A[i+j+1]:
            count+=1
            j+=1
            if i+j+1>=N-1:
                break
        for k in range(1,count+1):
            count2 *= k 
        ans += count2

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = 0
input_list = []
while a < n:
    ant = input()
    input_list.append(set(list(ant)))
    a += 1
seen = []
print(len(input_list) - len([x for x in input_list if x not in seen and not seen.append(x)]))

Submission status: Wrong Answer

Solution code:
N = int(input())

S = []

a = ord("a")
for i in range(N):
    s = list(input())
    s.sort()
    s_= "".join(s)
    S.append(s_)
S.sort()

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
d=Counter()
for i in range(n):
    t=str("".join(sorted(input())))
    d[t]+=1
print(max(d.values())-1)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
n=int(input())
l=[]
for _ in range(n):
  s=input()
  s=''.join(sorted(s))
  l.append(s)
l.sort()
c=0
for i,j in groupby(l):
  z=len(list(j))
  c=c+(z*(z-1)/2)
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    d=input()
    print(d)
    a.append("".join(sorted(d)))
#print(a)

count=0
for i in range(n):
    temp=a.pop()
    count+=a.count(temp)
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=dict()
for i in range(n):
  l = "".join(sorted(input())) 
  if l not in d:
    d[l]=1
  else:
    d[l]+=1
ans=0
for x in d.values():
  ans+=(x*x-1)/2
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=dict()
for i in range(n):
  l = "".join(sorted(input())) 
  if l not in d:
    d[l]=1
  else:
    d[l]+=1
ans=0
for x in d.values():
  ans+=(x*x+1)/2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

dic = collections.defaultdict(int)
for i in range(N):
    dic[''.join(sorted(input()))] += 1

ans = 0
for k, v in dic.items():
    if v > 1:
        ans += v
print(max(ans-1, 0))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = []
for i in range(N):
    a += [''.join(sorted(input()))]

count = 0
for c in collections.Counter(a).items():
    if c[1] > 1:
        count += c[1]
    else:
        break
print(max(count-1, 0))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = []
count = 0
for i in range(N):
    a += [''.join(sorted(input()))]

for c in collections.Counter(a).items():
    print(c[1])
    exit()

Submission status: Wrong Answer

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

for j in range(n):
    arr2.append("".join(arr[j]))


print(n - len(set(arr2)))

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = []
arr2 = []
arr3 = []
for i in range(n):
    arr.append(list(input()))

for j in range(n):
    arr2.append(arr[j].sort())


print(arr[0])

Submission status: Wrong Answer

Solution code:
N =int(input())
#S = list(map(str, input().split()))
S = list(map(str, input().split()))

#受け取った文字列をアルファベットに並び替え
S=[''.join(sorted(a)) for a in S]

#バケットを作って、出現回数をカウント
count=[0]*(len(set(S)))
unique_S=list(set(S))
ans=0
for ele in S:
    count[unique_S.index(ele)]+=1
count=sorted(count,reverse=True)

#階乗のコード
def cor(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact
#組み合わせのコード
def combination(n,c):
    a=(cor(n))/(cor(n-c)*cor(c))
    return a

for i in count:
    if i==1:
        break
    else:
        ans+=combination(i,2)
print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = ["".join(sorted(list(input()))) for _ in range(n)]
s.sort()

count = 0
prev = s[0]
for s_i in s[1::]:
    if prev == s_i:
        count += 1
    else:
        prev = s_i
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
s = list(list(input())for i in range(N))
count = 1
ans = 0
s.sort()
for i in range(N):
    s[i].sort()
for i in range(0,N-1):
    if s[i] == s[i+1]:
        ans += count
        count += 1
    else:
        count = 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(str(input())) for i in range(n)]
cnt=0
nums=[x for x in range(n)]
for m in l:
  m.sort()
print(l)
for i in nums[:n-1]:
  for j in l[i+1:]:
    if(l[i]==j):
      cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(str(input())) for i in range(n)]
cnt=0
nums=[x for x in range(n)]
for m in l:
  m.sort()
print(l)
for i in nums[:n-2]:
  for j in l[i+1:]:
    if(l[i]==j):
      cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N =int(input())
S = list(map(str, input().split())) 
#受け取った文字列をアルファベットに並び替え
S=[''.join(sorted(a)) for a in S]

#バケットを作って、出現回数をカウント
count=[0]*(len(set(S)))
unique_S=list(set(S))
ans=0
for ele in S:
    count[unique_S.index(ele)]+=1
count=sorted(count,reverse=True)

#階乗のコード
def cor(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact
#組み合わせのコード
def combination(n,c):
    a=(cor(n))/(cor(n-c)*cor(c))
    return a

print(count)
for i in count:
    if i==1:
        break
    else:
        ans+=combination(i,2)
print(int(ans))

Submission status: Wrong Answer

Solution code:
N =int(input())
S = list(map(str, input().split())) 
#受け取った文字列をアルファベットに並び替え
S=[''.join(sorted(a)) for a in S]

#バケットを作って、出現回数をカウント
count=[0]*(len(set(S)))
unique_S=list(set(S))
ans=0
for ele in S:
    count[unique_S.index(ele)]+=1
count=sorted(count,reverse=True)

#階乗のコード
def cor(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact
#組み合わせのコード
def combination(n,c):
    a=(cor(n))/(cor(n-c)*cor(c))
    return a

print(count)
for i in count:
    if i==1:
        break
    else:
        ans+=combination(i,2)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(list)
ans_list = c.most_common()
ans = [ans[1] for ans in ans_list if not ans[1]==1]
ans_len = len(ans)
if ans_len==0:
    print(0)
else:
    print(sum(ans)-ans_len)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(list)
ans_list = c.most_common()
ans = [ans[1] for ans in ans_list if not ans[1]==1]
print(sum(ans))

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(list)
ans_list = c.most_common()
print([ans[1] for ans in ans_list if not ans[1]==1])

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
array = []
for i in range(N):
    s = input()
    dict = {}
    for j in range(len(s)):
        if s[j] not in dict:
            dict[s[j]] = 1
        else:
            dict[s[j]] += 1
    dict = sorted(dict)
    array.append(str(dict))
sum = 0
c = collections.Counter(array)
for v in c.values():
    sum += int(v*(v-1)/2)
print(sum)

Submission status: Wrong Answer

Solution code:
from collections import Counter
class Combination:
    _maxNum = 0
    _divider = 0
    _fact = []
    _inv = []
    _finv = []

    def __init__(self, maxNum, divider):
        self._maxNum = maxNum
        self._divider = divider
 
        _fact = [0] * (maxNum + 1)
        _fact[0] = _fact[1] = 1


        if divider != 0:
            _inv = [0] * (maxNum + 1)
            _finv = [0] * (maxNum + 1)
            _inv[0] = _inv[1] = _finv[0] = _finv[1] = 1
        else:
            _inv = []
            _finv = []

        for i in range(2, maxNum + 1):
            _fact[i] = _fact[i - 1] * i;
            if divider != 0:
                _fact[i] %= _divider
                _inv[i] = _divider - _inv[_divider % i] * (_divider // i) % _divider
                _finv[i] = _finv[i - 1] * _inv[i] % _divider

        self._fact = _fact
        self._inv = _inv
        self._finv = _finv

    def nPk(self, n, k):
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            return 0
        return(self._fact[n] // self._fact[n - k])

    def nCk(self, n, k):
        ans = 0
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            ans = 0
        elif self._divider == 0:
            ans = self.nPk(n, k)
            ans //= self._fact[k]
        else:
            ans = self._fact[n] * (self._finv[k] * self._finv[n - k] % self._divider) % self._divider

        return ans

def ABC137C_GreenBin():
    N = int(input().strip())
    S = [input().strip() for i in range(N)]

    di = Counter()
    for s in S:
        s = ''.join(sorted(list(s)))
        di[s] += 1
    
#    cmb = Combination(max(di.values()), 0)

    ans = 0
    for num in di.values():
        ans += 1#cmb.nCk(num, 2)

    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
class Combination:
    _maxNum = 0
    _divider = 0
    _fact = []
    _inv = []
    _finv = []

    def __init__(self, maxNum, divider):
        self._maxNum = maxNum
        self._divider = divider
 
        _fact = [0] * (maxNum + 1)
        _fact[0] = _fact[1] = 1


        if divider != 0:
            _inv = [0] * (maxNum + 1)
            _finv = [0] * (maxNum + 1)
            _inv[0] = _inv[1] = _finv[0] = _finv[1] = 1
        else:
            _inv = []
            _finv = []

        for i in range(2, maxNum + 1):
            _fact[i] = _fact[i - 1] * i;
            if divider != 0:
                _fact[i] %= _divider
                _inv[i] = _divider - _inv[_divider % i] * (_divider // i) % _divider
                _finv[i] = _finv[i - 1] * _inv[i] % _divider

        self._fact = _fact
        self._inv = _inv
        self._finv = _finv

    def nPk(self, n, k):
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            return 0
        return(self._fact[n] // self._fact[n - k])

    def nCk(self, n, k):
        ans = 0
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            ans = 0
        elif self._divider == 0:
            ans = self.nPk(n, k)
            ans //= self._fact[k]
        else:
            ans = self._fact[n] * (self._finv[k] * self._finv[n - k] % self._divider) % self._divider

        return ans

def ABC137C_GreenBin():
    N = int(input().strip())
    S = [input().strip() for i in range(N)]

    di = Counter()
    for s in S:
        s = ''.join(sorted(list(s)))
        di[s] += 1
    
    cmb = Combination(max(di.values()), 0)

    ans = 0
    for num in di.values():
        ans += 1#cmb.nCk(num, 2)

    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()