Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, W = map(int, input().split())
dp = [[0 for j in range(W+1)] for i in range(N+1)]

for i in range(N):
    w, v = map(int, input().split())
    for sum_w in range(W+1):
        # i番目の品を取る
        if w <= sum_w:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w] + v)
        # i番目の品を取らない
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[-1][-1])

Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, W = map(int, input().split())
dp = [[0 for j in range(W+1)] for i in range(N+1)]

for i in range(N):
    w, v = map(int, input().split())
    for sum_w in range(W+1):
        # i番目の品を取る
        if w <= sum_w:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w] + v)
        # i番目の品を取らない
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N, W = map(int, input().split())
dp = np.zeros((N+1, W+1), dtype=np.int64)

for i in range(N):
    w, v = map(int, input().split())
    for sum_w in range(W+1):
        # i番目の品を取る
        if w <= sum_w:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w] + v)
        # i番目の品を取らない
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[-1][-1])

Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, W = map(int, input().split())
dp = [[0 for j in range(W+1)] for i in range(N+1)]

for i in range(N):
    w, v = map(int, input().split())
    for sum_w in range(W+1):
        # i番目の品を取る
        if w <= sum_w:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w] + v)
        # i番目の品を取らない
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
cnt = 1
for i in range(N):
    cnt *= a[i]
an = 0
while cnt%2 == 0:
    cnt //= 2
    an += 1
print(an)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
    while a[i]%2 == 0:
        a[i] //= 2
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
A = []
B = []

while len(a) > 0:
	A.append(max(a))
	a.remove(max(a))
	B.append(max(a))
	a.remove(max(a))

print(sum(A) - sum(B))

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
A = []
B = []

if len(a) % 2 == 1:
	A.append(min(a))
	a.remove(min(a))

while len(a) > 0:
	A.append(max(a))
	a.remove(max(a))
	B.append(max(a))
	a.remove(max(a))

print(sum(A) - sum(B))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

a, b = map(int, input().split())

if a*b % 2 == 0:
	print("Even")
eles:
	print("Odd")

Fixed submission:
# coding: utf-8
 
a, b = map(int, input().split())
 
if a*b % 2 == 0:
	print("Even")
else:
	print("Odd")
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, Y = map(int, input().split())
Y /= 1000
cnt = 0

for x in reversed(range(N+1)):
    for y in reversed(range(N+1-x)):
        for z in reversed(range(N+1-x-y)):
            if 10*x + 5*y + z == Y and x + y + z == N:
                print(str(x)+" "+str(y)+" "+str(z))
                sys.exit()
print("-1 -1 -1")

Fixed submission:
N, Y = map(int, input().split())
Y /= 1000
res10 = res5 = res1 = -1

for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if 10*x + 5*y + z == Y:
            res10 = x
            res5 = y
            res1 = z
print(str(res10)+" "+str(res5)+" "+str(res1))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
divide = ["dream", "dreamer", "erase", "eraser"]
S = S[::-1]
divide = [divide[i][::-1] for i in range(4)]

while len(S) > 0:
    for i in range(4):
        if S[:len(divide[i])] == divide[i]:
            flag = "YES"
            S = S[len(divide[i]):]
            break
        else:
            flag = "NO"

print(flag)

Fixed submission:
S = input()
divide = ["dream", "dreamer", "erase", "eraser"]
S = S[::-1]
divide = [divide[i][::-1] for i in range(4)]
 
while len(S) > 0:
    for i in range(4):
        if S[:len(divide[i])] == divide[i]:
            flag = "YES"
            S = S[len(divide[i]):]
            break
        else:
            flag = "NO"
    if flag == "NO":
        break

print(flag)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    n = int(stdin.readline().rstrip())
    #A, B = map(float, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    import functools
    import operator
    result = functools.reduce(operator.mul, A)
    if result > 10**18:
        print(-1)
    else:
        print(result)


main()


Fixed submission:
import sys

stdin = sys.stdin

def main():
    n = int(stdin.readline().rstrip())
    A = list(map(int, stdin.readline().rstrip().split()))
    A.sort()
    ans = 1
    for i in range(n):
        if ans > 10**18:
            if A[0] == 0:
                print(0)
                exit()
            print(-1)
            exit()
        ans *= A[-i]
    print(ans if ans <= 10**18 else -1)


main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    n = int(stdin.readline().rstrip())
    #A, B = map(int, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans =1
    for i in range(n):
        ans *= A[i]
    if ans > 10**18:
        print(-1)
    else:
        print(ans)

main()


Fixed submission:
import sys

stdin = sys.stdin

def main():
    n = int(stdin.readline().rstrip())
    A = list(map(int, stdin.readline().rstrip().split()))
    A.sort()
    ans = 1
    for i in range(n):
        if ans > 10**18:
            if A[0] == 0:
                print(0)
                exit()
            print(-1)
            exit()
        ans *= A[-i]
    print(ans if ans <= 10**18 else -1)


main()
Buggy python submission (verdict: Runtime Error):
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def main():
    n = int(stdin.readline().rstrip())
    l = factorization(n)
    z = []
    for i in range(len(l)):
        #[i][0]がpの候補
        if is_prime(l[i][0]):
            for j in range(l[i][1]):
                z.append(l[i][0] ** (j+1))
    z = list(set(z))
    z.sort()
    ans = 0
    for i in range(len(z)):
        if n % z[i] == 0:
            n = n / z[i]
            ans += 1
        if n < z[i+1]:
            print(ans)
            exit()
    print(ans)

main()


Fixed submission:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

def solve():
    x = int(stdin.readline().rstrip())
    p = factorization(x)
    num = []
    if x == 1:
        print(0)
        exit()
    for i in p:
        for j in range(i[1]):
            if x%(i[0] ** (j+1)) == 0:
                num.append(i[0] ** (j+1))
                x = x/(i[0] ** (j+1))
            else:
                break
    print(len(num))
    exit()



if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,m = map(int, stdin.readline().rstrip().split())
h = list(map(int, stdin.readline().rstrip().split()))

michi = [[0] * n for i in range(n)]

for i in range(m):
    a,b = map(int, stdin.readline().rstrip().split())
    michi[a-1][b-1] = michi[b-1][a-1] = 1

count = 0
for i in range(n):
    b=0
    for j in range(n):
        if michi[i][j]==1:
            if h[i] > h[j]:
                pass
            else:
                b=1
        else:
            pass
    if b==1:
        pass
    else:
        count += 1

print(count)


Fixed submission:
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,m = map(int, stdin.readline().rstrip().split())
h = list(map(int, stdin.readline().rstrip().split()))

#michi = [[0] * n for i in range(n)]

good = [1]*n

for i in range(m):
    a,b = map(int, stdin.readline().rstrip().split())
    if h[a-1] < h[b-1]:
        good[a-1] = 0
    elif h[a-1] > h[b-1]:
        good[b-1] = 0
    else:
        good[a-1] = good[b-1] = 0

print(good.count(1))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
x = int(stdin.readline().rstrip())

if x == 1:
    print(0,-1)


for i in range(1,x):
    if x%i==0:
        for a in range(i):
            b = a-i
            if int(a**4 + a**3*b + a**2*b**2 + a*b**3 + b**4) == int(x/i):
                print(a,b)
                exit()
    else:
        pass


Fixed submission:
from sys import stdin
x = int(stdin.readline().rstrip())

for i in range(-120,120):
    for j in range(-120,120):
        if i**5 - j**5 == x:
            print(i, j)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
n = int(stdin.readline().rstrip())
s = str(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                if j-i!=k-j:
                    ans += 1

print(ans)


Fixed submission:
from sys import stdin
n = int(stdin.readline().rstrip())
s = str(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

rnum = s.count("R")
gnum = s.count("G")
bnum = s.count("B")

ans = rnum * gnum * bnum

for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j - i
        if k<n:
            if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
                ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
n = int(stdin.readline().rstrip())
As = list(map(int, stdin.readline().rstrip().split()))

nums = []
ans = 0

s = set(As)
s = list(s)


for i in range(len(s)):
    num = As.count(s[i])
    nums.append(num)
    p = num * (num-1) / 2
    ans += p

for k in range(n):
    num = nums[s.index(As[k])] - 1
    p = num*(num-1)/2
    bigp = (num+1)*num/2
    print(int(ans - bigp + p))


Fixed submission:
import collections
from sys import stdin
n = int(stdin.readline().rstrip())
ass = list(map(int, stdin.readline().rstrip().split()))

c = collections.Counter(ass)

cnum =[0]*len(c)
keys = c.keys()

cs = {}
for i in keys:
    key = c[i]
    combi = key *(key-1) / 2
    cs[i] = combi

sum = sum(cs.values())

for i in range(n):
    add = c[ass[i]]-1
    adds = add *(add-1) / 2
    ans = sum - cs[ass[i]] + adds
    print(int(ans))
Buggy python submission (verdict: Runtime Error):
from sys import stdin
A,B = map(int, stdin.readline().rstrip().split())

def search(x):
    p = (x*0.08)//1
    q = (x*0.10)//1
    if p==A and q==B:
        print(x)
        exit()
    elif p > A or q > B:
        print(-1)
    else:
        search(x+1)

search(1)


Fixed submission:
from sys import stdin
import sys
A,B = map(int, stdin.readline().rstrip().split())
sys.setrecursionlimit(2000)
def search(x):
    p = (x*0.08)//1
    q = (x*0.10)//1
    if p==A and q==B:
        print(x)
        exit()
    elif p > A and q > B:
        print(-1)
    else:
        search(x+1)

search(1)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
n,m = map(int, stdin.readline().rstrip().split())

count = 0
penalty = 0
qb = [0]*n
was = [0]*n

for i in range(m):
    p,s = map(str,stdin.readline().rstrip().split())
    p = int(p)
    if s == "AC" and qb[p-1] != "AC":
        qb[p-1] = "AC"
        pentalty += was[p-1]
        count += 1
    elif s == "WA":
        was[p-1] += 1
    else:
        pass

print(count, penalty)

Fixed submission:
from sys import stdin
n,m = map(int, stdin.readline().rstrip().split())

count = 0
penalty = 0
qb = [0]*n
was = [0]*n

for i in range(m):
    p,s = map(str,stdin.readline().rstrip().split())
    p = int(p)
    if s == "AC" and qb[p-1] != "AC":
        qb[p-1] = "AC"
        penalty += was[p-1]
        count += 1
    elif s == "WA":
        was[p-1] += 1
    else:
        pass

print(count, penalty)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
n = int(stdin.readline().rstrip())
a = l = list(map(int, stdin.readline().rstrip().split()))

lf = 0
lb = 0
while len(a) > 0:
    if lf <= lb:
        lf += a.pop(0)
    else:
        lb += a.pop(len(a)-1)
h = 0
if lf <= lb:
    h = lb-lf
else:
    h = lf-lb
print(h)


Fixed submission:
from sys import stdin
n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))

lf = 0
lb = 0
front = 0
back = n-1
for i in range(n):
    if lf <= lb:
        lf += a[front]
        front += 1
    else:
        lb += a[back]
        back += -1
if lf <= lb:
    h = lb-lf
else:
    h = lf-lb
print(h)
Buggy python submission (verdict: Runtime Error):

from sys import stdin

n = int(stdin.readline().rstrip())
l = [1,2,3,4,5,6,7,8,9,2,4,6,8,10,12,14,16,18,3,6,9,12,15,18,21,24,27,4,8,12,16,20,24,28,32,36,5,10,15,20,25,30,35,40,45,6,12,18,24,30,36,42,48,54,7,14,21,28,35,42,49,56,63,64,72,81]
ans = n in l
if ans == True:
    ans = "Yes"
else:
    ans = "No"
print(ans)


Fixed submission:

from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]
if A<1 or A>9 or B<1 or B>9:
    ans = -1
else:
    ans = A*B

print(ans)

Buggy python submission (verdict: Runtime Error):

from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]
if A<1 or A>9 B<1 or B>9:
    ans = -1
else:
    ans = A*B

print(ans)


Fixed submission:

from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]
if A<1 or A>9 or B<1 or B>9:
    ans = -1
else:
    ans = A*B

print(ans)
Buggy python submission (verdict: Runtime Error):

from sys import stdin

S = str(stdin.readline().rstrip())
K = int(stdin.readline().rstrip())

lenS = len(S)
ans = 0

if S[0] == S[lenS-1]:
    S2 = S*2
    a = 0#位置
    while a < lenS*2-1:
        ans2 = 0
        if S2[a] == S2[a+1]:
            b = 2
            x = S2[a]
            for i in range(1,lenS*2-a):
                try:
                    if x == S2[a+1+i]:
                        b += 1
                    else:
                        break
                except:
                    b = 2
            ans2 += b//2
            a += 1+b
        else:
            a += 1
    a = 0#位置
    while a < lenS-1:
        ans1 = 0
        if S[a] == S[a+1]:
            b = 2
            x = S[a]
            for i in range(1,lenS-a):
                try:
                    if x == S[a+1+i]:
                        b += 1
                    else:
                        break
                except:
                    b = 2
            ans1 += b//2
            a += 1+b
        else:
            a += 1
    differ = ans2-ans1
    ans = differ*(K-1) + ans1*K
else:
    a = 0#位置
    while a < lenS-1:
        if S[a] == S[a+1]:
            b = 2
            x = S[a]
            for i in range(1,lenS-a):
                try:
                    if x == S[a+1+i]:
                        b += 1
                    else:
                        break
                except:
                    b = 2
            ans += b//2
            a += 1+b
        else:
            a += 1
    ans = ans*K


print(ans)


Fixed submission:

from sys import stdin

S = str(stdin.readline().rstrip())
K = int(stdin.readline().rstrip())

l = len(S)
ans = 0

for i in range(l):
    mo = S[0]*l
    if mo == S:
        ans = l*K//2
        print(ans)
        exit()
    else:
        pass


if S[0] == S[l-1]:
    S2 = S*2
    l2 = len(S2)
    a = 0#位置
    ans2 = 0
    while a < l2-1:
        if S2[a] == S2[a+1]:
            t = S2[a]
            c = 1
            for i in range(1,l2-a):
                if t == S2[a+i]:
                    c += 1
                else:
                    break
            j = c//2
            ans2 += j
            a += c
        else:
            a += 1
    a = 0#位置
    ans1 = 0
    while a < l-1:
        if S[a] == S[a+1]:
            t = S[a]
            c = 1
            for i in range(1,l-a):
                if t == S[a+i]:
                    c += 1
                else:
                    break
            j = c//2
            ans1 += j
            a += c
        else:
            a += 1
    differ = ans2-ans1*2
    ans = differ*(K-1) + ans1*K
else:
    a = 0#位置
    while a < l-1:
        if S[a] == S[a+1]:
            t = S[a]
            c = 1
            for i in range(1,l-a):
                if t == S[a+i]:
                    c += 1
                else:
                    break
            j = c//2
            ans += j
            a += c
        else:
            a += 1

    ans = ans*K

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

from sys import stdin
import heapq

N = int(input())
As = [int(x) for x in stdin.readline().rstrip().split()]
ans = ""

for i in range(N):
    small = heapq.nsmallest(i + 1, As)
    index = As.index(small[i])
    ans += str(index + 1) + " "

print(ans)


Fixed submission:

from sys import stdin
import heapq

N = int(input())
As = [int(x) for x in stdin.readline().rstrip().split()]
ans = [0] * N

for i in range(N):
    x = As[i]
    ans[x-1] = i + 1

ans = ' '.join(map(str, ans))
print(ans)
Buggy python submission (verdict: Runtime Error):

N = input()
steps = [i for i in N]
N = len(N)
ans = "Yes"
#024 L があるとダメ
for i in range(0,N+1,2):
    if steps[i] == "L":
        ans = "No"
for i in range(1,N,2):
    if steps[i] == "R":
        ans = "No"
print(ans)


Fixed submission:

N = input()
steps = [i for i in N]
N = len(N)
ans = "Yes"
for i in range(0,N,2):
    if steps[i] == "L":
        ans = "No"
for i in range(1,N,2):
    if steps[i] == "R":
        ans = "No"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from collections import defaultdict, deque, Counter
import sys
from bisect import bisect_left
import heapq
import math
import numpy as np

sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

c =[]
same = []

for i in range(n):
    ci = Counter(str(stdin.readline().rstrip()))
    if ci in c:
        same[c.index(ci)] += 1
    else:
        c.append(ci)
        same.append(1)

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

print(int(ans))


Fixed submission:
from sys import stdin
from collections import defaultdict, deque, Counter
import sys
from bisect import bisect_left
import heapq
import math
#import numpy as np

sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

s = {}
ans = 0

for i in range(n):
    l = list(str(stdin.readline().rstrip()))
    l.sort()
    l = str(l)
    if l in s:
        s[l] += 1
        ans += s[l] -1
    else:
        s[l] = 1

print(ans)