TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 23:27:57 2019

@author: doppe
"""

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}

ans = 0
for i in range(0, len(S)):
    a = list(S[i])
    a.sort()
    b = ''.join(a)
    if b in groupDict:
        groupDict[b] += 1
    else :
        groupDict[b] = 1

for v in groupDict.values():
    ans += (v * (v - 1)) / 2
        
print(ans)
    

# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 23:27:57 2019

@author: doppe
"""

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}

ans = 0
for i in range(0, len(S)):
    a = list(S[i])
    a.sort()
    b = ''.join(a)
    if b in groupDict:
        groupDict[b] += 1
    else :
        groupDict[b] = 1

for v in groupDict.values():
    ans += (v * (v - 1)) / 2
        
print(int(ans))
    


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collection import Counter
N = int(input())
c = Counter(''.join(sorted(input())) for _ in range(N))
sum_ = lambda n: int(n*(n-1)/2)
print(sum(map(sum_,c.values())))

from collections import Counter
N = int(input())
c = Counter(''.join(sorted(input())) for _ in range(N))
sum_ = lambda n: int(n*(n-1)/2)
print(sum(map(sum_,c.values())))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter
N = int(input())
slist = [Counter(input()) for _ in range(N)]
print(slist)

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

from collections import Counter
N = int(input())
SList = [''.join(sorted(input())) for _ in range(N)]

dic = {}
ans = 0
for word in SList:
    if word not in dic:
        dic[word] = 1
    else:
        ans += dic[word]
        dic[word] += 1

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter
 
n = int(input())
aL = [set(Counter(input()).most_common()) for i in range(n)]
count = 0
 
for i in range(n-1):
    for j in range(i+1, n):
        if aL[i] == aL[j]:
          tmp = aL.count(aL[i])
          count += (tmp-1)*(tmp-2)//2
          aL[j] = 0
 
print(count)

from collections import Counter
N = int(input())
S = [input() for i in range(N)]
counter = Counter()
ans = 0
for s in S:
    a = ''.join(sorted(list(s)))
    if a in counter:
        ans += counter[a]
    counter[a] += 1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from scipy.misc import comb


def resolve():
    n = int(input())
    ss = []
    for i in range(n):
        ss.append(input())

    sorted_ss = list(map("".join, map(sorted, ss)))
    dic = {}

    for s in sorted_ss:
        dic[s] = dic.get(s, 0) + 1

    count = 0
    for key in dic.keys():
        count += comb(dic[key],2)

    print(int(count))

resolve()

def resolve():
    n = int(input())
    dic = {}
    count = 0
    for i in range(n):
        s = input()
        sorted_s = "".join(sorted(s))
        count += dic.get(sorted_s, 0)
        dic[sorted_s] = dic.get(sorted_s, 0) + 1

    print(int(count))
resolve()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
lst = [input() for _ in range(n)]

counter_lst = []
counter_num = [0] * n
for i in range(n):
    a = Counter(lst[i])
    if a in counter_lst:
        m = counter_lst.index(a)
        counter_num[m] += 1
        counter_lst.append(0)
    else:
        counter_lst.append(a)
        counter_num[i] = 1
    
res = 0
for i in counter_num:
    if i > 0:
        res += i * (i-1) // 2
print(res)

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

dic = dict()
res = 0
for i in range(n):
    sorted_string = "".join(sorted(lst[i]))
    if sorted_string in dic:
        dic[sorted_string] += 1
        res += dic[sorted_string]
    else:
        dic[sorted_string] = 0
    
print(res)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import collections
n = int(input())
s = collections.Counter(["".join(sorted(input())) for _ in range(n)]).most_common()
print(s)
cnt = 0
for i in s:
    for j in range(1, i[1]):
        cnt += j
print(cnt)

import collections
n = int(input())
s = collections.Counter(["".join(sorted(input())) for _ in range(n)]).most_common()
#print(s)
cnt = 0
for i in s:
    for j in range(1, i[1]):
        cnt += j
print(cnt)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
dic={}
for _ in range(n):
  s=input()
  s=sorted(s)
  if s not in dic:
    dic[s]=1
  else:
    dic[s]+=1
ans=0
for val in dic.values():
  ans+=val*(val-1)//2
print(ans)

import collections

n=int(input())
arr=[input() for _ in range(n)]
dic={}
for s in arr:
  count=[0]*26
  tmp=collections.Counter(s)
  for char in tmp.keys():
    count[ord(char)-ord('a')]+=tmp[char]
  count=tuple(count)
  if count not in dic:
    dic[count]=1
  else:
    dic[count]+=1
ans=0
for val in dic.values():
  ans+=val*(val-1)//2
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

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

print(count)

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)

N = int(input())
dic = {}
for i in range(N):
    spell = ''.join(sorted(input()))
    if spell in dic.keys():
        dic[spell] += 1
    else:
        dic[spell] = 1

count = 0
for num in dic.values():
    count += sum([i for i in range(num)])

print(count)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    n = int(input())
    s = [input() for _ in range(n)]
    d = []
    ans = 0
    for ss in s:
        c = collections.Counter(ss)
        d.append(c)
    for i in range(n):
        for j in range(i + 1, n):
            if d[i] == d[j]:
                ans += 1              
    print(ans)  
        
    
if __name__ == '__main__':
    main()

def main():
    n = int(input())
    d = {}
    ans = 0
    
    for _ in range(n):
        ss = ''.join(sorted(input()))
        d[ss] = d.get(ss, 0) + 1
        
    for v in d.values():
            ans += (v*(v-1)) // 2
         
    print(ans)
       
    
if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
s=[input() for i in range(1,n+1)]
dic={}
l=list()
cnt=0
for i in range(n):
  s[i].sort()
  s=''.join(s[i])
  l.append(s)
  if l[i] in dic:
    cnt+=1
  else:
    dict[l[i]]=1
print(cnt)

n=int(input())
s=[input() for i in range(n)]
dic={}
l=list()
cnt=0
for i in range(n):
  k=sorted(s[i])
  t=''.join(k)
  l.append(t)
  if l[i] in dic:
    dic[l[i]]+=1
  else:
    dic[l[i]]=0
c=list(dic.values())
for i in range(len(c)):
   cnt+=c[i]*(c[i]+1)//2
print(cnt)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# Green Bin
n = int(input())
s = [input() for i in range(n)]
m = 0
list = {}
for i in s:
  i = ' '.join(sorted(i))
  print(i)
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1
for i in list.values():
  l = i -1
  m = m + int(((l * (l + 1)) / 2))
print(m)

n = int(input())
s = [input() for i in range(n)]
m = 0
for i in s:
  i = ' '.join(sorted(i))
for k in range(n):
  m += s[:k].count(s[k])
print(m)

# Green Bin
n = int(input())
s = [input() for i in range(n)]
m = 0
list = {}
for i in s:
  i = ' '.join(sorted(i))
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1
for i in list.values():
  l = i -1
  m = m + int(((l * (l + 1)) / 2))
print(m)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from scipy.special import comb
N=int(input())
dic={}
ans=0
for i in range(N):
    s=list(input())
    s.sort()
    S=''.join(s)
    if S not in dic:
        dic[S]=1
    else:
        dic[S]+=1
for v in dic.values():
    if v>=2:
        ans+=int(comb(v,2))
print(dic)

N=int(input())
dic={}
ans=0
for i in range(N):
    s=list(input())
    s.sort()
    S=''.join(s)
    if S not in dic:
        dic[S]=1
    else:
        dic[S]+=1
for v in dic.values():
    if v>=2:
        ans+=v*(v-1)//2
print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

from collections import Counter
n = int(input())
s = [str(sorted(input()))for _ in range(n)]

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
from collections import Counter, defaultdict

def ncr(n, r):
	f = math.factorial
	return f(n)//f(r)//f(n-r)

n = int(input())

dct = defaultdict(int)

for i in range(n):
	counter = Counter(input().strip())
	tpl = tuple(sorted(counter.items()))
	dct[tpl] += 1
ans = sum(ncr(val, 2) for val in dct.values())

print(ans)

import math
from collections import Counter, defaultdict

def ncr(p):
	return p*(p-1)//2

n = int(input())

dct = defaultdict(int)

for i in range(n):
	counter = Counter(input().strip())
	tpl = tuple(sorted(counter.items()))
	dct[tpl] += 1


ans = sum(ncr(val) for val in dct.values() if val>1)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding:utf8 -*-
import math

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = [math.factorial(s.count(i)) for i in set(s)]
print(sum(c)/2)

# -*- coding:utf8 -*-
import math

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = [math.factorial(s.count(i)) for i in set(s) if s.count(i) != 1]
ans = 0 if not c else sum(c)/2 
print(ans)

# -*- coding:utf8 -*-
import math

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = [math.factorial(s.count(i)) for i in set(s) if s.count(i) != 1]
print(sum(c)/2)

# -*- coding:utf8 -*-

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = collections.Counter(s)
t = [list(range(i)) for i in list(c.values()) if i != 1]
a = [sum(i) for i in t]
print(sum(t))

# -*- coding:utf8 -*-
import collections

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = collections.Counter(s)
t = [range(i) for i in list(c.values()) if i != 1]
a = [sum(i) for i in t]
print(sum(a))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())

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

print(n - len(set(s)))

import collections  

n = int(input())

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

def f(a):
  if a == 0:
    return 1
  else:
    return a * f(a - 1)
  
cnt = 0
for (c, m) in collections.Counter(s):
	combi = f(m - 1)
    if combi != 1:
      cnt += combi
    
print(cnt)

import collections  

n = int(input())

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

def f(a):
    if a == 0:
        return 1
    else:
        return a * f(a - 1)
  
cnt = 0
for (c, m) in collections.Counter(s):
	combi = f(m - 1)
    if combi != 1:
        cnt += combi
    
print(cnt)

import collections  

n = int(input())

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

cnt = 0
for (c, m) in collections.Counter(s).items():
    ccnt += m * (m - 1) / 2
    
print(cnt)

import collections  

n = int(input())

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

cnt = 0
for (c, m) in collections.Counter(s).items():
    cnt += m * (m - 1) / 2
    
print(cnt)

n = int(input())

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

print(n - len(set(s)))

import collections  

n = int(input())

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

cnt = 0
for (c, m) in collections.Counter(s).items():
    cnt += m * (m - 1) // 2
    
print(cnt)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter
n = int(input())
S = [str(sorted(input())) for _ in range(N)]

print(sum(map(lambda x: x * (x - 1) // 2, Counter(S).values())))

from collections import Counter
n = int(input())
S = [str(sorted(input())) for _ in range(n)]

print(sum(map(lambda x: x * (x - 1) // 2, Counter(S).values())))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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/2
            for i in range(1,count+1):
                Z = Z * i
            ans = ans + Z
            count = 1

if count != 1:
    Z = 1/2
    for i in range(1,count+1):
        Z = Z * i
    ans = ans + Z
        

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
            Z = Z * count * (count-1)
            Z = Z // 2
            ans = ans + Z
            count = 1

if count != 1:
    Z = 1
    Z = Z * count * (count-1)
    Z = Z // 2
    ans = ans + Z
        
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
S = [sorted(input()) for _ in range(N)]
strDict = {}
count = 0

for s in S:
    s = s[0]
    if s not in strDict:
        strDict[s] = 1
    else:
        strDict[s] += 1
    
for i in strDict.keys():
    n = strDict[i]
    count += n*(n-1)//2
print(count)

N = int(input())
str_unions = sorted([tuple(sorted(input())) for _ in range(N)])
count_dict = {}
ret = 0

for s in str_unions:
    if s not in count_dict:
        count_dict[s] = 1
    else: count_dict[s] += 1

sum_n = lambda n: n*(n+1)//2
print(sum(map(lambda x:sum_n(x-1), count_dict.values())))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter
n = int(input())
s = [tuple(sorted(list(input()))) for _ in range(n)]
ans = 0
st = []
count = {}

for i in range(n):
    if not s[i] in st:
        st += [s[i]]
        count[s[i]] = 0

for i in range(n):
    if s[i] in st:
        ans += count[s[i]]
        count[s[i]] += 1


from collections import Counter
n = int(input())
s = [tuple(sorted(input())) for _ in range(n)]

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections
n = int(input())
s = [0]*n
c = {}
T = [0]*n
ans = 0
for i in range(n):
	s[i] = input()
	c[i] = collections.Counter(list(s[i]))
	T[i] = str(c[i])
D = collections.Counter(T)
for i in D.values():
	ans += i*(i-1)/2
print(int(ans))

import collections
n = int(input())
s = [0]*n
c = {}
T = [0]*n
for i in range(n):
	s[i] = input()
	c[i] = collections.Counter(list(s[i]))
	T[i] = str(c[i])
D = collections.Counter(T)
ans = 0
for i in D.values():
	ans += i*(i-1)//2
print(ans)

import collections
n = int(input())
s = [0]*n
c = {}
T = [0]*n
ans = 0
for i in range(n):
	s[i] = input()
	c[i] = collections.Counter(list(s[i]))
	T[i] = str(c[i])
D = collections.Counter(T)
for i in D.values():
	ans += i*(i-1)/2
print(ans)

import collections
n = int(input())
s = [0]*n
L = [0]*n
ans = 0
for i in range(n):
	s[i] = input()
	L[i] = ''.join(sorted(list(s[i])))
D = collections.Counter(L)
for i in D.values():
	ans += i*(i-1)//2
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
s = []
cnt = 0

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

for i in range(N):
    for j in range(i+1, N):
        for k in range(len(s[i])):
            tmp = s[i]
            tmp = tmp.replace(s[j][k], "")
        if tmp == "":
            cnt += 1
        else:
            continue
            
print(cnt)


N = int(input())
s = []
cnt = 0

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

for i in range(N):
    for j in range(i+1, N):
        for k in range(len(s[i])):
          	tmp = s[i]
            tmp = s[i].replace(s[j][k], "")
        if tmp == "":
            cnt += 1
        else:
            continue
            
print(cnt)



N = int(input())
dic = {}
count = 0


for i in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    count += dic.get(s_sorted, 0)
    dic[s_sorted] = dic.get(s_sorted, 0) + 1

print(count)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):


using namespace std;

int main(void) {
    int N;
    cin >> N;
    
    vector<string> v;
    string s;
    for(int i=0; i<N; i++) {
        cin >> s;
        v.push_back(s);
    }

    for(int i=0; i<v.size(); i++) {
        sort(v[i].begin(), v[i].end());
    }

    int result = 0;
    for(int i=0; i<v.size(); i++) {
        result += count(v.begin()+i, v.end(), v[i]);
    }
    
    cout << result << endl;
    
    return 0;
}




using namespace std;

int main(void) {
    int N;
    cin >> N;
    
    vector<string> v;
    string s;
    for(int i=0; i<N; i++) {
        cin >> s;
        v.push_back(s);
    }

    for(int i=0; i<v.size(); i++) {
        sort(v[i].begin(), v[i].end());
    }

    int result = 0;
    for(int i=0; i<v.size(); i++) {
        result += count(v.begin()+i, v.end(), v[i]) - 1;
    }
    
    cout << result << endl;
    
    return 0;
}


N = int(input())

s = ["".join(sorted(input())) for i in range(N)]

count = 0
d = {}
for elm in s:
    if elm in d:
        count += d[elm]
        d[elm] += 1
    else:
        d[elm] = 1

print(count)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math

n = int(input())
s = [0]*n
ans = {}
ans_v = 0

for i in range(n):
    s[i] = "".join(sorted(list(input())))
    
s_set = set(s)

for i in s_set:
    ans[i] = 0
    
for i in s:
    ans[i] += 1

for j in ans.values():
    if j >= 2:
        ans_v += math.factorial(j) /( (math.factorial(j - 2)* math.factorial(2)))
    
print(ans_v)

import math

n = int(input())
s = [0]*n
ans = {}
ans_v = 0

for i in range(n):
    s[i] = "".join(sorted(list(input())))
    
s_set = set(s)

for i in s_set:
    ans[i] = 0
    
for i in s:
    ans[i] += 1

for j in ans.values():
    if j >= 2:
        ans_v += math.factorial(j) /( (math.factorial(j - 2)* math.factorial(2)))
    
print(int(ans_v))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
input=sys.stdin.readline
#import math
import collections
#from collections import deque

N = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
l = {}
for i in range(N):
    if i == N-1:
      S = list(input())
    else:
      S = list(input()[:-1])
    S.sort()
    S = tuple(S)
    if S in l.keys():
      l[S] += 1
    else:
      l[S] = 1
ans = 0
for j in l.values():
  ans += j*(j-1)/2
print(int(ans))

import sys
input=sys.stdin.readline
#import math
import collections
#from collections import deque

N = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
l = {}
for i in range(N):
    S = list(input())
    S.remove("\n")
    S.sort()
    S = tuple(S)
    if S in l.keys():
      l[S] += 1
    else:
      l[S] = 1
ans = 0
for j in l.values():
  ans += j*(j-1)/2
print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: 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.

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


for i in range(n):
    l[i] = ''.join(sorted(l[i]))
     


l.sort()


flag = 0
for i in range(n-1):
    if l[i] == l[i+1]:
        flag == flag + 1

print(flag)

N = int(input())
S = sorted(''.join(sorted(list(input()))) for i in range(N))
# N(10+log_2(10)+10)
ans = 0
sep = []
for i in range(N-1): # N*4
    if  S[i] != S[i+1]:
        sep.append(i+1)
sep.append(N)
# print(sep)
count = []
prev = 0
for i in sep: # len(set(N))*2 <= N*2
    count.append(i-prev)
    prev = i
# print(count)
for i in count: # N*2 (similarly)
    ans += i*(i-1)//2
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

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

n = int(input())
note = dict()
for i in range(n):
    s = "".join(sorted(input()))
    if s in note.keys():
        note[s] += 1
    else:
        note[s] = 1
        
import collections
c = collections.deque(note.values())
ans = 0
for i in range(c):
    q = c.popleft()
    ans += q*(q-1)//2

print(ans)

import sys
#input = sys.stdin.readline

n = int(input())
note = dict()
ans = 0
for i in range(n):
    s = "".join(sorted(sys.stdin.readline()))
    if s in note.keys():
        ans += note[s]
        note[s] += 1
    else:
        note[s] = 1

print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter

n = int(input())
s = []
for i in range(n):
    s.append(''.join(sorted(input())))
    
v = list(Counter(s).values())
ans = []
for i in range(len(v)):
    if v[i] >= 2:
        ans.append((v[i] * (v[i]-1))/2)

print(sum(ans))

from collections import Counter

n = int(input())
s = []
for i in range(n):
    s.append(''.join(sorted(input())))
    
v = list(Counter(s).values())
ans = []
for i in range(len(v)):
    if v[i] >= 2:
        ans.append((v[i] * (v[i]-1))/2)

print(int(sum(ans)))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
s=[]
for i in range(n):
    x=input()
    y=[]
    for j in x:
        y.append(j)
    y.sort()
    s.append(y)
cnt=0
for i in range(n):
    for j in range(n):
        if s[i]==s[j]:
            cnt+=1
print(cnt)

n=int(input())
s=[]
for i in range(n):
    x=input()
    y=[]
    for i in x:
        y.append(i)
    y.sort()
    s.append(''.join(y))

d=dict()

for i in range(n):
    if s[i] not in d.keys():
        d[s[i]]=1
    else:
        d[s[i]]+=1
ans=0
for v in d.values():
    ans+=v*(v-1)/2
print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

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


strings = [''.join(sorted(s)) for s in strings]
strings.sort()

for s in strings:
    print(s)


hashMap = {}
for string in strings:
    if string not in hashMap:
        hashMap[str(string)] = 1
    else:
        hashMap[str(string)] += 1


sum = 0

for key in hashMap:
    v = hashMap[key]
    sum += v * (v - 1) / 2
print(int(sum))


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


strings = [''.join(sorted(s)) for s in strings]
strings.sort()


hashMap = {}
for string in strings:
    if string not in hashMap:
        hashMap[str(string)] = 1
    else:
        hashMap[str(string)] += 1


sum = 0

for key in hashMap:
    v = hashMap[key]
    sum += v * (v - 1) / 2
print(int(sum))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict
from itertools import combinations
import sys
input = sys.stdin.readline

n = int(input())
s = [input().split()[0] for _ in range(n)]
cnt = defaultdict(int)
for i in range(n):
    s[i].sort()
    cnt["".join(s[i])] += 1
result = 0
for c in cnt:
    result += len(list(combinations([""] * cnt[c], 2)))
print(result)

from collections import defaultdict
import sys
def input() -> str:
    return sys.stdin.readline()
n = int(input())
s = [input() for _ in range(n)]
cnt = defaultdict(int)
ans = 0
for si in s:
    ana = "".join(sorted(si))
    ans += cnt[ana]
    cnt[ana] += 1
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

import collections

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
ans = sum(x*(x-1)//2 for x in c.values())
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import bisect
n = int(input())
words = []
count = 1
total = 0
for i in range(n):
    s = sorted(input())
    bisect.insort_right(words, s, lo=0, hi=len(words))
print(words)
for i in range(1,n):
    if words[i-1] == words[i]:
        count += 1
    elif count != 1:
        total += int(count * (count-1)/2)
        count = 1
    else:
        count = 1
    if i == n - 1 and count != 1:
        total += int(count * (count-1)/2)
    
print(total)

letters = {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4, 'g': 7, 'f': 6, 'i': 9, 'h': 8, 'k': 11, 'j': 10, 'm': 13, 'l': 12, 'o': 15, 'n': 14, 'q': 17, 'p': 16, 's': 19, 'r': 18, 'u': 21, 't': 20, 'w': 23, 'v': 22, 'y': 25, 'x': 24, 'z': 26}
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
n = int(input())
words = {}
total = 0
hashv = 1
for i in range(n):
    s = input()
    for l in s:
        hashv = hashv*primes[letters[l] - 1]
    if hashv not in words.keys():
        words[hashv] = 1
    else:
        words[hashv] += 1
    hashv = 1

for key in words:
    if words[key] != 1:
        total += int(words[key] * (words[key]-1)/2)
    
print(total)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
ans=0
dict={}
for i in s:
    if i in dict:
        ans+=dict[s]
        dict[s]+=1
    else:
        dict[s]=1
print(ans)

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
li=[]
for i in range(n):
    s=list(input())
    s.sorted()
    li.append(s)
li.sorted()

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

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

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


Verdicts: Runtime Error

Accepted