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:
N = int(input())
D = {}
L = [[]for _ in range(N)]
count = 0
for i in range(N):
    L[i] = list(input())
    L[i].sort()
    L[i] = tuple(L[i])
    if L[i] in D:
        D[L[i]] = D[L[i]] + 1
        if D[L[i]] > count:
            count = D[L[i]]
    else:
        D[L[i]] = 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = {}
L = [[]for _ in range(N)]
count = 0
for i in range(N):
    L[i] = list(input())
    L[i].sort()
    L[i] = tuple(L[i])
    D[L[i]] = 0
    if L[i] in D:
        D[L[i]] = D[L[i]] + 1
        if D[L[i]] > count:
            count = D[L[i]]

print(count)

Submission status: Wrong Answer

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

from collections import Counter

c = Counter(S)
l = [d[1] for d in c.items() if d[1] > 1]
print(sum(l)-1)

Submission status: Wrong Answer

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

ans = 0
S = ["".join(sorted(s)) for s in S]

from collections import Counter

c = Counter(S)
print(c.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())

list_s = []
for i in range(n):
    s = input()
    list_s_tmp = []
    for j in s:
        list_s_tmp.append(j)
    
    list_s.append(sorted(list_s_tmp))

result = 0
for i in range(len(list_s)):
    for j in range(len(list_s)- i):
        if list_s[i] == list_s[j]:
            result = result + 1

print((result - n))

Submission status: Wrong Answer

Solution code:
n = int(input())

list_s = []
for i in range(n):
    s = input()
    list_s_tmp = []
    for j in s:
        list_s_tmp.append(j)
    
    list_s_tmp = sorted(list_s_tmp)

    s_tmp = ""
    for j in list_s_tmp:
        s_tmp = s_tmp + j

    list_s.append(s_tmp)

print(len(list_s) - len(set(list_s)))

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 = [input() for i in range(n)]
for k in range(n):
    s[k]=sorted(list(s[k]))
s=sorted(s)


c = 1
count = 0

for x in range (n-1):
        if s[x]==s[x+1]:
            c += 1
        else:
            count += cmb(c,2)
            c = 1
count += cmb(c,2)
print(count)

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 = [input() for i in range(n)]
for k in range(n):
    s[k]=sorted(list(s[k]))
s=sorted(s)
print(s)

c = 1
count = 0

for x in range (n-1):
        if s[x]==s[x+1]:
            c += 1
        else:
            count += cmb(c,2)
            c = 1
count += cmb(c,2)
print(count)

Submission status: Wrong Answer

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

S=sorted(s)

count=0
for i in range(N):
    for j in range(i+1,N):
        if S[i]==S[j]:
            count+=1
        else:
            continue
    if count!=0:
        break         
    
print(count)

Submission status: Wrong Answer

Solution code:
#自分で考えたやつ

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

count = 0
for i in range(N):
    Si = S[i]
    for k in range(N):
        if i==k:
            None
        else:
            Sk = S[k]
            if Sk == Si:
                count += 1

print(count / 2)

"""
N = int(input())
dic = {}
ans = 0

for i in range(N):
    s = ''.join(sorted(input()))
    if s in dic:
        ans += dic[s]
        dic[s] += 1
    else:
        dic[s] = 1
print(ans)
"""

Submission status: Wrong Answer

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

S=sorted(s)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
dic = {}
a = 0
for i in range(n):
  s = ''.join(sorted(input()))
  if s in dic:
    a += dic[s]
    dic[s] += dic[s]
  else:
    dic[s] = 1
print(a)

Submission status: Wrong Answer

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)
from collections import defaultdict
MOD = 10**13
NUM = 10**5

fact = [1] * (NUM + 1)
fact_inv = [1] * (NUM + 1)

for i in range(1, NUM+1):
    fact[i] = (fact[i-1]*i) % MOD
# フェルマーの少定理から(a**MOD-1)が1 => (a**MOD-2)がaの逆元
fact_inv[NUM] = pow(fact[NUM], MOD-2, MOD)

# 階乗の逆元は、逆元の階乗なので、(n-1)!の逆元を求めたいなら(n!の逆元)*nでOK
for i in range(NUM, 2, -1):
    fact_inv[i-1] = (fact_inv[i]*i) % MOD

def perm(n,k):
    if n<k or k<0:
        return 0
    else:
        return (fact[n]*fact_inv[n-k])% MOD

def comb(n,k):
    return (perm(n,k)//fact[k])%MOD


def main():
    N = int(input())
    A = [0]*N
    dic = defaultdict(int)
    for i in range(N):
        A[i] = "".join(sorted((input()[:-1])))
        dic[A[i]] +=1
    ans = 0
    for k in dic:
        if dic[k] >= 2:
            ans += comb(dic[k],2)
    print(ans)






if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)
from collections import defaultdict
MOD = 10**9+7
NUM = 10**5

fact = [1] * (NUM + 1)
fact_inv = [1] * (NUM + 1)

for i in range(1, NUM+1):
    fact[i] = (fact[i-1]*i) % MOD
# フェルマーの少定理から(a**MOD-1)が1 => (a**MOD-2)がaの逆元
fact_inv[NUM] = pow(fact[NUM], MOD-2, MOD)

# 階乗の逆元は、逆元の階乗なので、(n-1)!の逆元を求めたいなら(n!の逆元)*nでOK
for i in range(NUM, 2, -1):
    fact_inv[i-1] = (fact_inv[i]*i) % MOD

def perm(n,k):
    if n<k or k<0:
        return 0
    else:
        return (fact[n]*fact_inv[n-k])% MOD

def comb(n,k):
    return (perm(n,k)//fact[k])%MOD


def main():
    N = int(input())
    A = [0]*N
    dic = defaultdict(int)
    for i in range(N):
        A[i] = "".join(sorted((input()[:-1])))
        dic[A[i]] +=1
    ans = 0
    for k in dic:
        if dic[k] >= 2:
            ans += comb(dic[k],2)
    print(ans)






if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
words = []
count = 0

for n in range(N):
    word = list(input())
    word.sort()
    words.append(''.join(word))

uniq = set(words)
for w in uniq:
    num = words.count(w)
    count += math.factorial(num)//2

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s_list = [list(str(input())) for i in range(n)]

dict={}
key_count = 0
count=0
for i in range(n-1):
  if s_list[i].sort() in dict.values():
    count+=1
  else:
    dict[key_count]=s_list[i].sort()
    key_count+=1
    

print(count)

Submission status: Wrong Answer

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

list_new=[]
for i in range(n):
    list_new.append(sorted(list_[i]))

print(list_new)

counter=0
i=0
while i<=n-1:
    j=i+1
    while j<=n-1:
        if list_new[i]==list_new[j]:
            counter+=1
        else:
            counter+=0
        j+=1
    i+=1
    
print(counter)

Submission status: Wrong Answer

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

print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
for _ in range(n):
  s = list(str(input()))
  s.sort()
  lis.append(s)
lis.sort()
ans = 0
num = 0
for i in range(n-1):
  if lis[i+1] == lis[i]:
    num += 1
  else:
    ans += (num * (num+1))//2
    num = 0
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = []
for _ in range(N):
    s.append(sorted(list(input())))
res = 0
while len(s)>0:
    a = s.pop(0)
    count = 1
    for i,n in enumerate(s):
        if n == a:
            count += 1
            s.pop(i)
    res +=  count * (count - 1)//2

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())

li1 = []
for _ in range(n):
    s = list(input())
    li1.append(sorted(s))

cnt = 0
li2 = sorted(li1)
li3 = []
for i in range(1, len(li2)):
    if li2[i] == li2[i-1]:
        cnt += 1
    else:
        li3.append(cnt)
        cnt = 0
    if li2[i] == li2[-1]:
        li3.append(cnt)

cnt1 = 0
for i in li3:
    cnt1 += (i*(i+1))//2
    
print(cnt1)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i == j or i > j: #2つの文字列を選択
            continue
        else:
            ana1 = list(S[i])
            ana2 = list(S[j])
            ana1.sort()
            ana2.sort()
            print(ana1,ana2)
            if ana1 == ana2:
                count += 1
            else:
                continue
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i == j or i > j: #2つの文字列を選択
            continue
        else:
            ana1 = [S[i]]
            ana2 = [S[j]]
            ana1.sort()
            ana2.sort()
            if ana1 == ana2:
                count += 1
            else:
                continue
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i == j or i > j: #2つの文字列を選択
            continue
        else:
            ana1 = []
            ana2 = []
            for k in range(10):
                ana1.append(S[i][k])
                ana2.append(S[j][k])
                ana1.sort()
                ana2.sort()
            print(ana1,ana2)
            if ana1 == ana2:
                count += 1
            else:
                continue
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

n = int(input())
S = [sorted(input()) for _ in range(n)]
S = np.array(S)
print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [0] * n
tmp = 0
num = [0] * n
 #文字列を数値に変換した値を格納
 #文字列を値に対応させた配列numの作成とsort
for i in range(n):
  s[i] = input()
  for j in range(len(s[i])):
    tmp += ord(s[i][j])
  num[i] = tmp
  tmp = 0
num.sort()
count = 1
ans = 0
calc = []
#ansのカウント
#print(num)
for i in range(n-1):
  if (num[i] == num[i+1]):
    count += 1
  else:
    if(count != 1):
      calc.append(count)
      count = 1
if(count!= 1):
  calc.append(count)
#print(calc)

#calcからans計算

for i in range(len(calc)):
  ans += calc[i] * (calc[i]-1) /2


print(int(ans))
  



"""
while(i<n-1):
  if(num[i] == num[i+1]):
    count += 1
    i+=1
  else:
    if(count>1):
      ans += ((count) * (count+1)) / 2
      count = 0
    elif(count ==1):
      ans += 1
      count = 0
    else:
      count = 0
    i+=1
    break
      
   """     
"""
  if (count > 1):
   
  elif(count ==1):
    ans += 1
    count = 0
  if (count > 1):
    ans += ((count) *(count+1)) /2
  """

Submission status: Wrong Answer

Solution code:
def comb(n):
    return n * (n - 1) // 2
  
N=int(input())
S=[]
for i in range(N):
    S.append(input())
    
ord_list = []
prime_list = [11,13,17,19,23,29,31,37,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127]

for s in S:
    ret = 0
    for c in s:
        ret += prime_list[ord(c) - 97]
    ord_list.append(ret)

    
ord_list.sort()

ans = 0
anagram = 1
temp = ord_list[0]

for i in range(1, N):
    if temp == ord_list[i]:
        anagram += 1
    else:
        ans += comb(anagram)
        anagram = 1
        temp = ord_list[i]

ans += comb(anagram)
    
print(ans)

Submission status: Wrong Answer

Solution code:
def comb(n):
    return n * (n - 1) // 2
  
N=int(input())
S=[]
for i in range(N):
    S.append(input())
    
ord_list = []
prime_list = [11,13,17,19,23,29,31,37,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127]

for s in S:
    ret = 0
    for c in s:
        ret += prime_list[ord(c) - 97]
    ord_list.append(ret)

    
ord_list.sort()

ans = 0
anagram = 1
temp = ord_list[0]

for i in range(1, N):
    if temp == ord_list[i]:
        anagram += 1
    else:
        ans += comb(anagram)
        anagram = 1
        temp = ord_list[i]

if anagram != 1:
    ans += comb(anagram)
    
print(ans)

Submission status: Wrong Answer

Solution code:
def comb(n):
    return n * (n - 1) // 2
  
N=int(input())
S=[]
for i in range(N):
    S.append(input())
    
ord_list = []
prime_list = [11,13,17,19,23,29,31,37,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127]

for s in S:
    ret = 0
    for c in s:
        ret += prime_list[ord(c) - 97]
    ord_list.append(ret)

    
ord_list.sort()

ans = 0
anagram = 1
temp = ord_list[0]

for i in range(1, N):
    print(ans)
    if temp == ord_list[i]:
        anagram += 1
    else:
        ans += comb(anagram)
        anagram = 1
        temp = ord_list[i]

if anagram != 1:
    ans += comb(anagram)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def comb(n):
    if n == 1:
        return 0
    
    if n not in dic:
        f_n = math.factorial(n)
        dic[n] = f_n
    else:
        f_n = dic[n]
        
    if n - 2 not in dic:
        f_n2 = math.factorial(n-2)
        dic[n - 2] = f_n2
    else:
        f_n2 = dic[n - 2]   
    
    return f_n // (f_n2 * 2)
  
N=int(input())
S=[]
for i in range(N):
    S.append(input())
    
ord_list = []
prime_list = [11,13,17,19,23,29,31,37,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127]
dic={}

for s in S:
    ret = 0
    for c in s:
        ret += prime_list[ord(c) - 97]
    ord_list.append(ret)
    
ord_list.sort()

ans = 0
ans_temp = 1
temp = ord_list[0]

for i in range(1, N):
    if temp == ord_list[i]:
        ans_temp += 1
    else:
        ans += comb(ans_temp)
        ans_temp = 1
        temp = ord_list[i]

if ans_temp != 1:
    ans += comb(ans_temp)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def comb(n):
    if n == 1:
        return 1
    
    if n not in dic:
        f_n = math.factorial(n)
        dic[n] = f_n
    else:
        f_n = dic[n]
        
    if n - 2 not in dic:
        f_n2 = math.factorial(n-2)
        dic[n - 2] = f_n2
    else:
        f_n2 = dic[n - 2]   
    
    return f_n // (f_n2 * 2)
  
N=int(input())
S=[]
for i in range(N):
    S.append(input())
    
ord_list = []
prime_list = [11,13,17,19,23,29,31,37,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127]
dic={}

for s in S:
    ret = 0
    for c in s:
        ret += prime_list[ord(c) - 97]
    ord_list.append(ret)
    
ord_list.sort()

ans = 0
ans_temp = 1
temp = ord_list[0]

for i in range(1, N):
    if temp == ord_list[i]:
        ans_temp += 1
    else:
        ans += comb(ans_temp)
        ans_temp = 1
        temp = ord_list[i]
        
ans += comb(ans_temp)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=[]
for i in range(N):
    S.append(input())
    
ord_list = []
prime_list = [11,13,17,19,23,29,31,37,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127]

for s in S:
    ret = 0
    for c in s:
        ret += prime_list[ord(c) - 97]
    ord_list.append(ret)
    
ord_list.sort()

ans = 0
temp = ord_list[0]

for i in range(1, N):
    if temp == ord_list[i]:
        ans += 1
    else:
        temp = ord_list[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
counter = 0
tmp = {}
for _ in range(n):
    s = str(sorted(input()))
    if s in tmp:
        tmp[s] += tmp[s] + 1
    else:
        tmp[s] = 0
print(sum(tmp.values()))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
t = []
count = 0
for _ in range(n):
    s = input()
    c = Counter(s)
    if c in t:
        count += 1
    else:
        t.append(c)

print(count)

Submission status: Wrong Answer

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

S = []
ans = 0
for i in range(n):
    if s[i] in S:
        ans += 1
    else:
        S.append(s[i])

ans = ans + (len(S) - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
def areAnagram(str1, str2):  
    # Get lengths of both strings  
    n1 = len(str1)  
    n2 = len(str2)  
    
      
    if n1 != n2:  
        return 0
  
     
    str1 = sorted(str1) 
    str2 = sorted(str2) 
  
      
    for i in range(0, n1):  
        if str1[i] != str2[i]:  
            return 0
  
    return 1
n=int(input())
l=[]
for i in range(n):
  l.append(input())
s=0
for i in range(n):
  for j in range(i,n):
    if areAnagram(l[i],l[j]):
      s+=1
print(s)

Submission status: Wrong Answer

Solution code:
def is_anagram(s1, s2):
    if s1 == s2:
        return True
    if set(s1) != set(s2):
        return False
    s2_list = list(s2)
    for c in s1:
        if c in s2_list:
            s2_list.remove(c)
        else:
            return False
    return True

N = int(input())

strings = list(input() for _ in range(N))
anagrams = 0

while strings != []:
    count = 1
    string = strings[0]
    strings = strings[1:]
    for s in strings:
        if is_anagram(string, s):
            count += 1
            strings.remove(s)
    anagrams += (count * (count - 1)) // 2

print(anagrams)

Submission status: Wrong Answer

Solution code:
def is_anagram(s1, s2):
    s2_list = list(s2)
    for c in s1:
        if c in s2_list:
            s2_list.remove(c)
        else:
            return False
    return True

N = int(input())

strings = list(input() for _ in range(N))
anagrams = 0

while strings != []:
    count = 1
    string = strings[0]
    strings.remove(string)
    for s in strings:
        if is_anagram(string, s):
            count += 1
            strings.remove(s)
    anagrams += (count * (count - 1)) // 2

print(anagrams)

Submission status: Wrong Answer

Solution code:
def is_anagram(s1, s2):
    s1_list = [s1[i] for i in range(10)]
    s2_list = [s2[i] for i in range(10)]
    for i in range(10):
        try:
            s2_list.remove(s1_list[i])
        except ValueError:
            return False
    return True

N = int(input())

strings = list(input() for _ in range(N))
anagrams = 0

while strings != []:
    count = 1
    string = strings[0]
    strings.remove(string)
    for s in strings:
        if is_anagram(string, s):
            count += 1
            strings.remove(s)
    anagrams += (count * (count - 1)) // 2

print(anagrams)

Submission status: Wrong Answer

Solution code:
n = int(input())
econ = []
for i in range(n):
    econ.append(input())
print(econ)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
st = []
ans = 0
for i in range(n):
    sti = str(sorted(s[i]))
    st.append(sti)
count = Counter(st)
for i in count.values():
    if i != 1:
        for j in range(1, i):
            ans += j * (j - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
def anagram(n,s):
    count = 0
    dic = {}
    for s in S:
        if s in dic:
            count += dic[s]
            dic[s] += 1
        else:
            dic[s] = 1
    return count

N = int(input())
S = []
for i in range(N):
    li = sorted(input())
    li = ''.join(li)
    S.append(li)
anagram(N,S)

Submission status: Wrong Answer

Solution code:
input_size = int(input())
a = []
s = 0
b = []
for i in range(input_size):
  a.append(input())
  b.append([])
  for l in a[i]:
    b[i].append(l)

for num in range(input_size):
  for num_2 in range(num + 1, input_size):
    if set(b[num]) == set(b[num_2]):
      s += 1
print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=0
l=[]
for i in range(n):
	s_listed=sorted(list(input()))
	s=''.join(s_listed)
	if s in l:
		c+=1
	l.append(s)
print(c)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
lists = []
result = 0
tempres = 0
for i in range(N):
    lists.append(input())

sortedlist = []
for i in range(0, N):
    sortedlist.append(sorted(lists[i]))

sortedlist.sort()
for i in range(0, N):
    if tempres != 0:
        tempres -= 1
        continue

    for j in range(i + 1, N):
        if sortedlist[i] == sortedlist[j]:
            tempres += 1
        else:
            break

    result += math.factorial(tempres)

print(result)

Submission status: Wrong Answer

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

for i in range(n):
  lists = [j for j in input().split()]
  lists.sort()
  s = "".join(lists)
  buf.append(s)
  
buf.sort()
same= 0
sent= buf[0]

for i in range(1,n):
  if buf[i]==sent:
    same += 1
  else:
    sent = buf[i]
    ans += (same*(same+1))//2
    same = 0
  
ans += (same*(same+1))//2

print(ans)

Submission status: Wrong Answer

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

for i in range(n):
  lists = [i for i in input().split()]
  lists.sort()
  s = "".join(lists)
  buf.append(s)
  
buf.sort()
same= 0
sent= buf[0]

for i in range(1,n):
  if buf[i]==sent:
    same += 1
  else:
    sent = buf[i]
    ans += (same*(same+1))//2
    same = 0
  
ans += (same*(same+1))//2

print(ans)

Submission status: Wrong Answer

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

for i in range(n):
  lists = input().split()
  lists.sort()
  s = "".join(lists)
  buf.append(s)
  
buf.sort()
same= 0
sent= buf[0]

for i in range(1,n):
  if buf[i]==sent:
    same += 1
  else:
    sent = buf[i]
    ans += (same*(same+1))//2
    same = 0
  
ans += (same*(same+1))//2

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n = II()
string = [IS() for _ in range(n)]
counter_list = []
for s in string:
    counter_list.append(str(C(s)))
a = sorted(counter_list)
cnt = 0
ans = 0
tmp = a[0]
for i in range(n):
    if tmp != a[i]:
        ans += (cnt*(cnt-1))//2
        cnt = 1
        tmp = a[i]
        continue
    cnt += 1
ans += (cnt*(cnt-1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [0] * n
tmp = 0
num = [0] * n
 #文字列を数値に変換した値を格納
for i in range(n):
  s[i] = input()
  for j in range(len(s[i])):
    tmp += ord(s[i][j])
  num[i] = tmp
  tmp = 0
num.sort()

count = 0
ans = 0

for i in range(n-1):
  if(num[i] == num[i+1]):
    count += 1
  else:
    if (count != 0):
      ans += (count+1) //2
    count = 0
  if (count != 0):
    ans += (count+1) //2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [0] * n
tmp = 0
num = [0] * n
print(len(s)) #文字列を数値に変換した値を格納
for i in range(n):
  s[i] = input()
  for j in range(len(s[i])):
    tmp += ord(s[i][j])
  num[i] = tmp
  tmp = 0
num.sort()

count = 0
ans = 0
print(num)
for i in range(n-1):
  if(num[i] == num[i+1]):
    count += 1
  else:
    if (count != 0):
      ans += (count+1) //2
    count = 0
  if (count != 0):
    ans += (count+1) //2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n = II()
string = [IS() for _ in range(n)]
counter_list = []
for s in string:
    counter_list.append(str(C(s)))
a = sorted(counter_list)
cnt = 0
ans = 0
tmp = a[0]
for i in range(n):
    if tmp != a[i]:
        ans += COMBINATION(cnt, 2)
        cnt = 1
        tmp = a[i]
        continue
    cnt += 1
ans += COMBINATION(cnt, 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [list(input()) for i in range(n)]
l = ["".join(sorted(i)) for i in l]
l.sort()
m = [l.count(l[i]) - 1 for i in range(n)]
o = [i*(i-1)/2 for i in m]
print(sum(o))

Submission status: Wrong Answer

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

cnt = 0

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

print(cnt)

Submission status: Wrong Answer

Solution code:
#import scipy
#import sys
#from collections import defaultdict
from collections import Counter
#from itertools import accumulate
from itertools import product, permutations,combinations
#from operator import itemgetter
#from bisect import bisect_left,bisect
#from heapq import heappop,heappush
#from fractions import gcd
#from math import ceil,floor,sqrt,cos,sin,pi
#from copy import deepcopy
#import numpy as np

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

count = []
for i in range(N):
	count.append(Counter(S[i]))

conb = list(combinations(count, 2))

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

#print(conb)

'''
ans = 0
for i in range(N):
	for j in range(i, N):
		if (count[i] == count[j]) and (i != j):
			ans += 1
'''

print(count)
print(ans)

Submission status: Wrong Answer

Solution code:
#import scipy
#import sys
#from collections import defaultdict
from collections import Counter
#from itertools import accumulate
from itertools import product, permutations,combinations
#from operator import itemgetter
#from bisect import bisect_left,bisect
#from heapq import heappop,heappush
#from fractions import gcd
#from math import ceil,floor,sqrt,cos,sin,pi
#from copy import deepcopy
#import numpy as np

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

count = []
for i in range(N):
	count.append(Counter(S[i]))

ans = 1
for i in range(N):
	for j in range(i, N):
		if (count[i] == count[j]) and (i != j):
			ans += 1


#print(count)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
print(s)
ans = 0
for si in set(s):
    n = c[si]
    ans += n * (n - 1) // 2
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
	s.append(input())
	c.clear()
	for j in s[i]:
		c.append(j)

	c.sort()
	c_str = ''
	for j in range(10):
		c_str += c[j]

	s_dash.append(c_str)

for i in range(n):
	for j in range(i+1,n):
		if s_dash[i][0] != s_dash[j][0]:
			break
		elif s_dash[i] == s_dash[j]:
			ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
S = ["".join(sorted(input()[:-1])) for _ in range(N)]
c = Counter(S)
print(sum([k*(k-1)//2 for k in c.values()]))