Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def trial_division(n):
    a = []  
    while n % 2 == 0:
        a.append(2)
        n /= 2
    f = 3
    while f*f <= n:
        if n % f == 0:
            a.append(f)
            n /= f
        else:
            f += 2   
    if n != 1: a.append(n)
    return a
A,B = (lambda x: (min(x),max(x)))(list(map(int,input().split())))
print(len(set(trial_division(A),trial_division(B)))+1)

Fixed submission:
def trial_division(n,b):
    a = []
    if n%2==0 and b%2==0:
        a.append(2)
    while n % 2 == 0:
        n /= 2
    f = 3
    while f*f <= n:
        if n % f == 0: 
            if b%f == 0:
                a.append(f)
            n /= f
        else:
            f += 2   
    if n != 1 and b%n==0: 
        a.append(n)
    return a
A,B = (lambda x: (min(x),max(x)))(list(map(int,input().split())))
print(len(set(trial_division(A,B)))+1)
Buggy python submission (verdict: Time Limit Exceeded):
print(sum(range(1,int(input()))))

Fixed submission:
print((lambda x:int(x)*(int(x)-1)//2)(int(input())))
Buggy python submission (verdict: Runtime Error):
N = int(input())
W = map(int,input().split())
t = []
for i in range(1,N):
  t.append(abs(sum(W[:i])-sum(W[i:])))
print(min(t))

Fixed submission:
N = int(input())
W = list(map(int,input().split()))
t = []
for i in range(1,N):
  t.append(abs(sum(W[:i])-sum(W[i:])))
print(min(t))
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
a = [] 
for i in range(M):
    a.append(int(input()))
a.sort()
diff = [a[i+1]-a[i] for i in range(M-1)] if M!=1 else []
if diff and min(diff)==1 :
    print(0)
else:
    if not(diff):
        stairs = [a[0]-1,N-a[0]-1]
    else :
        stairs = [a[0]-1]+[diff[i]-2 for i in range(M-1)]+[N-a[-1]-1]
    
    t = [1,1]
    for i in range(max(stairs)-1):
        t.append(t[-1]+t[-2])
    ans = 1
    for i in stairs:
        ans *= t[i]
    print(ans%1000000007)

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

for i in range(M):
    a.append(int(input()))
a.sort()
diff = [a[i+1]-a[i] for i in range(M-1)] if M!=1 else []
if diff and min(diff)==1 :
    print(0)
else:
    if M==0:
        stairs = [N]
    elif not(diff):
        stairs = [a[0]-1,N-a[0]-1]
    else :
        stairs = [a[0]-1]+[diff[i]-2 for i in range(M-1)]+[N-a[-1]-1]
    
    t = [1,1]
    for i in range(max(stairs)-1):
        t.append(t[-1]+t[-2])
    ans = 1
    for i in stairs:
        ans *= t[i]
    print(ans%1000000007)
Buggy python submission (verdict: Runtime Error):
import math
N, K = [int(i) for i in input().split()]
n = []
k = K
res = 0
while k!=1:
    n.append(k)
    k = math.ceil(k/2)

for i in range(len(n)):
    if N >= n[i]:
        res += (N-n[i]+1)/2**i
        o = i
        break

while o < len(n) - 1:
    res += (n[o] - n [o + 1]) / 2 ** (o + 1)
    o += 1
 
res = res / N
print(res)

Fixed submission:
import math
N,K = map(int, input().split())
if K == 1:
    print(1)
else:
    P = max(0,(N-(K-1))/N)
    t = 0
    for i in range(1,min(N+1,K)):
        foo = math.log2(K/i)
        x=math.ceil(foo)
        t+=(1/2)**x
    P+=t*(1/N)
    print(P)

Buggy python submission (verdict: Runtime Error):
import math
N, K = [int(i) for i in input().split()]
n = [K]
k = K
while True:
    k /= 2
    n.append(math.ceil(k))
    if math.ceil(k)==1:break

n.reverse()
ma=[(1/2)**i for i in range(len(n))]
t=[]
m=len(n)
for i,(j,k) in enumerate(zip(n[1:],n)):
    t+=[ma[m-i-1]]*(j-k)
if N>K:t+=[1]*(N-K+1)
else: t=t[:N]
print("{:9f}".format(math.fsum(t)/len(t)))

Fixed submission:
import math
N,K = map(int, input().split())
if K == 1:
    print(1)
else:
    P = max(0,(N-(K-1))/N)
    t = 0
    for i in range(1,min(N+1,K)):
        foo = math.log2(K/i)
        x=math.ceil(foo)
        t+=(1/2)**x
    P+=t*(1/N)
    print(P)
Buggy python submission (verdict: Runtime Error):
from math import gcd
N = int(input())
A = list(map(int,input().split()))
gcda = [A[0]]
gcdb = [A[-1]]
for i in range(N-2):
    gcda.append(gcd(gcda[-1],A[i+1]))
    gcdb.append(gcd(gcdb[-1],A[-(i+2)]))
gcdb.reverse()
GC = [gcdb[0]]
for i in range(N-2):
    GC.append(gcd(gcda[i],gcdb[i+1]))
else:
    GC.append(gcda[-1])
print(max(GC))

Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
gcda = [A[0]]
gcdb = [A[-1]]
for i in range(N-2):
    gcda.append(gcd(gcda[-1],A[i+1]))
    gcdb.append(gcd(gcdb[-1],A[-(i+2)]))
gcdb.reverse()
GC = [gcdb[0]]
for i in range(N-2):
    GC.append(gcd(gcda[i],gcdb[i+1]))
else:
    GC.append(gcda[-1])
print(max(GC))

Buggy python submission (verdict: Runtime Error):
import math
def gcd(a,b):
    if a == 0 or b == 0:
        return max(a,b)
    else:
        return math.gcd(a,b)


N = int(input())
A = [int(i) for i in input().split()]

L = [0]
R = [0]
for i in range(N):
    L.append(gcd(L[-1],A[i]))
    R = [gcd(R[0],A[N-1-i])] + R
M = [gcd(i,j) for i,j in zip(L[:-1],R[1:])]
print(max(M))

Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
gcda = [A[0]]
gcdb = [A[-1]]
for i in range(N-2):
    gcda.append(gcd(gcda[-1],A[i+1]))
    gcdb.append(gcd(gcdb[-1],A[-(i+2)]))
gcdb.reverse()
GC = [gcdb[0]]
for i in range(N-2):
    GC.append(gcd(gcda[i],gcdb[i+1]))
else:
    GC.append(gcda[-1])
print(max(GC))

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
N = int(input())
A = [int(i) for i in input().split()]
if N>2:
    GCD = [gcd(*[e for s,e in enumerate(A) if s!=i]) for i in range(N)]
    print(max(GCD))
else:print(math.gcd(*A))

Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
gcda = [A[0]]
gcdb = [A[-1]]
for i in range(N-2):
    gcda.append(gcd(gcda[-1],A[i+1]))
    gcdb.append(gcd(gcdb[-1],A[-(i+2)]))
gcdb.reverse()
GC = [gcdb[0]]
for i in range(N-2):
    GC.append(gcd(gcda[i],gcdb[i+1]))
else:
    GC.append(gcda[-1])
print(max(GC))

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
N = int(input())
A = [int(i) for i in input().split()]
GCD = [gcd(*[e for s,e in enumerate(A) if s!=i]) for i in range(N)]
print(max(GCD))

Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
gcda = [A[0]]
gcdb = [A[-1]]
for i in range(N-2):
    gcda.append(gcd(gcda[-1],A[i+1]))
    gcdb.append(gcd(gcdb[-1],A[-(i+2)]))
gcdb.reverse()
GC = [gcdb[0]]
for i in range(N-2):
    GC.append(gcd(gcda[i],gcdb[i+1]))
else:
    GC.append(gcda[-1])
print(max(GC))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
cap = [int(input()) for i in range(5)]
state = [N, 0, 0, 0, 0, 0]
time = 0
while state[-1] != N:
    for i in range(4,-1,-1):
        if state[i]==0:
            continue
        move = cap[i] if state[i]>=cap[i] else state[i]
        state[i] -= move
        state[i+1] += move
    time += 1
print(time)

Fixed submission:
import math
N = int(input())
cap = [int(input()) for i in range(5)]
print( math.ceil(N/min(cap))+4)

Buggy python submission (verdict: Runtime Error):
N = int(input())
cap = [int(input()) for i in range(5)]
state = [N, 0, 0, 0, 0, 0]
time = 0
while state[-1] != N:
    for i in range(4,-1,-1):
        if state[i]==0:
            continue
        move = cap if state[i]>=cap[i] else state[i]
        state[i] -= move
        state[i+1] += move
    time += 1
print(time)

Fixed submission:
import math
N = int(input())
cap = [int(input()) for i in range(5)]
print( math.ceil(N/min(cap))+4)
Buggy python submission (verdict: Runtime Error):
S = "".join([i if i in 'ACGT' else ' ' for i in input()])
print(max([len(i) for i in S.split()]))

Fixed submission:
S = "".join([i if i in 'ACGT' else ' ' for i in input()])
print(max([len(i) for i in S.split()]+[0]))
Buggy python submission (verdict: Runtime Error):
a,b=list(map(int,input().split()))
if a <= 9 and b <=9:
    return a*b
return -1

Fixed submission:
a,b=list(map(int,input().split()))
if a <= 9 and b <= 9 and a >=1 and b >=1:
    print(a*b)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
import sys

class Solution(object):
	def __init__(self):
		self.n = 0
		self.p = []
		self.result = 0
	def readInput(self):
		self.n = int(sys.stdin.readline())
		a = sys.stdin.readline().split()
		for i in xrange(self.n):
			self.p.append(float(a[i]))
		#print self.p

	def coinTossRec(self, idx, tail_count, prob):
		if idx == self.n - 1:
			#last index
			self.result += (prob * self.p[idx])
			if tail_count != 0:
				#Check for head
				self.result += (prob * (1-self.p[idx]))
		else:
			self.coinTossRec(idx+1, tail_count, prob * self.p[idx])
			if tail_count != 0:
				self.coinTossRec(idx+1, tail_count-1, prob * (1-self.p[idx]))


	def coinToss(self):
		tail_count = self.n // 2 if self.n %2 == 1 else self.n //2 - 1
		self.coinTossRec(0, tail_count, 1)
		print self. result		


if __name__ == '__main__':
	s = Solution()
	s.readInput()
	s.coinToss()

Fixed submission:
import sys

#TODO: Find a better DP solution
#Current is just a recursive solution
#Time complexity of recursive solutions?

class Solution(object):
	def __init__(self):
		self.n = 0
		self.p = []
		self.result = 0

	def readInput(self):
		self.n = int(sys.stdin.readline())
		a = sys.stdin.readline().split()
		for i in xrange(self.n):
			self.p.append(float(a[i]))
		#print self.p

	def coinTossRec(self, idx, tail_count, prob):
		if idx == self.n - 1:
			#last index
			self.result += (prob * self.p[idx])
			if tail_count != 0:
				#Check for head
				self.result += (prob * (1-self.p[idx]))
		else:
			self.coinTossRec(idx+1, tail_count, prob * self.p[idx])
			if tail_count != 0:
				self.coinTossRec(idx+1, tail_count-1, prob * (1-self.p[idx]))

	def coinTossIter(self):
		dp = [0] * (self.n + 1) #i is the probability of i heads so far
		dp[0] = 1
		for i in xrange(self.n):
			p_heads = self.p[i]
			for j in xrange(i+1, -1, -1):
				if j == 0:
					dp[j] = dp[j] * (1 - p_heads)
				else:
					dp[j] = dp[j-1] * p_heads + dp[j] * (1- p_heads)
		ans = 0
		for i in xrange((self.n//2) + 1, self.n+1):
			ans += dp[i]

		print ans

	def coinToss(self):
		tail_count = self.n // 2 if self.n %2 == 1 else self.n //2 - 1
		self.coinTossRec(0, tail_count, 1)
		print self. result		


if __name__ == '__main__':
	s = Solution()
	s.readInput()
	s.coinTossIter()
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
s = [k for i in range(n)]
for i in range(q):
    z = int(input())
    for j in range(n):
        if j != z - 1:
            s[j] -= 1
        
for i in range(n):
    if s[i] <= 0:
        print('No')
    else:
        print('Yes')

Fixed submission:
n, k, q = map(int, input().split())
s = [k for i in range(n)]
d = {}
for i in range(q):
    z = int(input())
    if z-1 not in d:
        d[z-1] = 1
    else:
        d[z-1] += 1 

for i in range(n):
    if i in d:
        s[i] = s[i] - q + d[i]
        if s[i] > 0:
            print('Yes')
        else:
            print('No')
    else:
        s[i] -= q
        if s[i] > 0:
            print('Yes')
        else:
            print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
inp = list(map(int, input().split()))
length = len(inp)
ans = 0
curr_max = 0
for i in range(-1,-length,-1):
    if inp[i] <= inp[i-1]:
        ans += 1
        if ans > curr_max:
            curr_max = ans
    else:
        ans = 0
print(curr_max)

Fixed submission:
s = input()
t = input()
ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
d = {}
v = {}
for _ in range(n - 1):
    a, b = input().split()
    if a not in d:
        d[a] = [b]
    else:
        d[a].append(b)
    if b not in d:
        d[b] = []

for key in d.keys():
    v[key] = 0

for _ in range(q):
    node, increment = input().split()
    queue = [node]
    all_childs = [node]
    while len(queue) > 0:
        el = queue.pop()
        if el not in all_childs:
            all_childs.append(el)
        childs = d[el]
        if len(childs) > 0:
            queue.extend(d[el])
    for child in all_childs:
        v[child] += int(increment)

for value in v.values():
    print(value, end=' ')
print('')

Fixed submission:
a = int(input())
s = input()
if a < 3200:
    print('red')
else:
    print(s)
Buggy python submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    if a>=10 or b >= 10:
      print(-1)
    else:
      print(a*b)
      

Fixed submission:
a,b=map(int,input().split())
if a >= 10 or b >= 10:
  print(-1)
else:
  print(a*b)

Buggy python submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    if a>9 or b>9:
      print(-1)
    else:
      print(a*b)

Fixed submission:
a,b=map(int,input().split())
if a >= 10 or b >= 10:
  print(-1)
else:
  print(a*b)

Buggy python submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    if a<9 and b<9:
      print(a*b)
    else:
      print(-1)

Fixed submission:
a,b=map(int,input().split())
if a >= 10 or b >= 10:
  print(-1)
else:
  print(a*b)

Buggy python submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    if a<9 and b<9:
      print(a*b)
    else:
		print(-1)
      

Fixed submission:
a,b=map(int,input().split())
if a >= 10 or b >= 10:
  print(-1)
else:
  print(a*b)

Buggy python submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    if a>9 or b>9:
      print(-1)
    else:
      print(a*b)
      

Fixed submission:
a,b=map(int,input().split())
if a >= 10 or b >= 10:
  print(-1)
else:
  print(a*b)

Buggy python submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    if a>9  | b>9:
      print(-1)
    else:
      print(a*b)
      

Fixed submission:
a,b=map(int,input().split())
if a >= 10 or b >= 10:
  print(-1)
else:
  print(a*b)

Buggy python submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    if a>9  || b>9:
      print(-1)
    else:
      print(a*b)
      

Fixed submission:
a,b=map(int,input().split())
if a >= 10 or b >= 10:
  print(-1)
else:
  print(a*b)

Buggy python submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    if a>9 or b >9:
      print(-1)
    else:
      print(a*b)
      

Fixed submission:
a,b=map(int,input().split())
if a >= 10 or b >= 10:
  print(-1)
else:
  print(a*b)

Buggy python submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    if a>=10 or b >= 10:
      print(-1)
    else:
      print(a*b)
      

Fixed submission:
a,b=map(int,input().split())
if a >= 10 or b >= 10:
  print(-1)
else:
  print(a*b)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))
c = 1

bean = True
for i in range(1, n):
  bean = True
  for j in range(i, 0, i-1):
    if l[j-1] > l[i]:
      bean = False
  if bean:
    c += 1

print(c)


Fixed submission:
n = int(input())
l = list(map(int, input().split()))
c = 1

bean = True
for i in range(1, n):
  bean = True
  for j in range(i, 0, -1):
    if l[j-1] > l[i]:
      bean = False
  if bean:
    c += 1

print(c)
Buggy python submission (verdict: Time Limit Exceeded):
storeNum, canNum = input().split()
storeNum = int(storeNum)
canNum = int(canNum)
costs = [0] * storeNum
maxCanNumbers = [0] * storeNum

for i in range(storeNum):
    costs[i], maxCanNumbers[i] = input().split()
    costs[i] = int(costs[i])
    maxCanNumbers[i] = int(maxCanNumbers[i])

currentStoreHasMoreCans = False
totalPrice = 0

while canNum > 0 and not currentStoreHasMoreCans:
    currentStoreHasMoreCans = True
    minCostIndex = costs.index(min(costs))
    if canNum >= maxCanNumbers[minCostIndex]:
        totalPrice = totalPrice + costs[minCostIndex] * maxCanNumbers[minCostIndex]
        canNum = canNum - maxCanNumbers[minCostIndex]
    else:
        totalPrice = totalPrice + costs[minCostIndex] * canNum
        canNum = 0
    currentStoreHasMoreCans = False
    costs[minCostIndex] = 1000000001

print(totalPrice)

Fixed submission:
storeNum, canNum = input().split()
storeNum = int(storeNum)
canNum = int(canNum)
costs = [0] * storeNum
maxCanNumbers = [0] * storeNum

for i in range(storeNum):
    costs[i], maxCanNumbers[i] = input().split()
    costs[i] = int(costs[i])
    maxCanNumbers[i] = int(maxCanNumbers[i])

currentStoreHasMoreCans = False
totalPrice = 0

costs, maxCanNumbers = (list(x) for x in zip(*sorted(zip(costs, maxCanNumbers))))

for i in range(storeNum):
    if canNum >= maxCanNumbers[i]:
        totalPrice = totalPrice + costs[i] * maxCanNumbers[i]
        canNum = canNum - maxCanNumbers[i]
        if canNum is 0:
            break
    else:
        totalPrice = totalPrice + costs[i] * canNum
        canNum = 0    
        break

print(totalPrice)
Buggy python submission (verdict: Runtime Error):
# ==================================================== #
# -*- coding: utf-8 -*
n, m = map(int, input().split())

arr = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    arr[a] += 1
    arr[b] += 1
for i in range(n):
    print(arr[i])

Fixed submission:
# ==================================================== #
# -*- coding: utf-8 -*
n, m = map(int, input().split())
arr = [0] * 114514

for i in range(m):
    a, b = map(int, input().split())
    arr[a-1] += 1
    arr[b-1] += 1

for i in range(n):
    print(arr[i])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = []
for _ in range(N):
    index = A.index(min(A))
    ans.append(index + 1)
    A[index] = N + 1
print(' '.join(map(str, ans)))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

A_dict = {}
for i in range(N):
    A_dict[i+1] = A[i]

sorted_dict = sorted(A_dict.items(), key=lambda x: x[1])

ans = []
for t in sorted_dict:
    ans.append(t[0])
print(' '.join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())
A = list(int(input()) for i in range(Q))

for i in range(N):
    cnt = A.count(i + 1)
    if K - (Q - cnt) > 0:
        print('Yes')
    else:
        print('No')

Fixed submission:
N, K, Q = map(int, input().split())
A = list(int(input()) for i in range(Q))

P = [-(Q - K)] * N

for a in A:
    P[a - 1] += 1

for p in P:
    if p > 0:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())
A = list(int(input()) for i in range(Q))

P = [K] * N
for i in range(N):
    cnt = A.count(i + 1)
    P[i] = P[i] - (Q - cnt)

for p in P:
    if p > 0:
        print('Yes')
    else:
        print('No')


Fixed submission:
N, K, Q = map(int, input().split())
A = list(int(input()) for i in range(Q))

P = [-(Q - K)] * N

for a in A:
    P[a - 1] += 1

for p in P:
    if p > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))

while M > 0:
    max_index = A.index(max(A))
    A[max_index] = A[max_index] // 2
    M -= 1
print(sum(A))


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))

while M > 0:
    A.sort(reverse=True)
    if A[0] == 0:
        break
    ham = A[0] // 2
    for i, a in enumerate(A):
        if ham < a and M > 0:
            A[i] = A[i] // 2
            M -= 1
        else:
            break
print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = input()


def flip_direction(target, start, end):
    for i in range(start, end + 1):
        if target[i] == 'R':
            target = target[:i] + 'L' + target[i + 1:]
            # S[i] = 'L'
        else:
            target = target[:i] + 'R' + target[i + 1:]
            # S[i] = 'R'
    return target


def count_happy_person():
    count = 0
    dir = S[0]
    for i in range(1, len(S)):
        if dir == S[i]:
            count += 1
        else:
            dir = S[i]
    return count


for _ in range(K):
    start = 0
    end = 0
    for i in range(1, len(S)):
        if S[0] != S[i]:
            if start == 0:
                start = i
            end = i
        else:
            if start != 0:
                break
    S = flip_direction(S, start, end)
print(count_happy_person())

Fixed submission:
N, K = map(int, input().split())
S = input()

happy_face = N - 1 - S.count('LR') - S.count('RL')
ans = min(N - 1, happy_face + 2 * K)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial

N = int(input())
S = list(''.join(sorted(str(input()))) for _ in range(N))
unique_S = list(set(S))

ans = 0
for s in unique_S:
    n = S.count(s)
    if n > 1:
        ans += factorial(n) // (factorial(n - 2) * factorial(2))
print(ans)


Fixed submission:
N = int(input())
S = list(''.join(sorted(str(input()))) for _ in range(N))

dic = {}
ans = 0

for s in S:
    if not s in dic:
        dic[s] = 1
    else:
        ans += dic[s]
        dic[s] += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb

N = int(input())
S = list(''.join(sorted(str(input()))) for _ in range(N))
unique_S = list(set(S))

ans = 0
for s in unique_S:
    n = S.count(s)
    if n > 1:
        ans += comb(n, 2, exact=True)
print(ans)


Fixed submission:
N = int(input())
S = list(''.join(sorted(str(input()))) for _ in range(N))

dic = {}
ans = 0

for s in S:
    if not s in dic:
        dic[s] = 1
    else:
        ans += dic[s]
        dic[s] += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial

N = int(input())
S = list(''.join(sorted(str(input()))) for _ in range(N))
unique_S = list(set(S))

ans = 0
for s in unique_S:
    n = S.count(s)
    if n > 1:
        ans += factorial(n) / factorial(2) / factorial(n - 2)
print(int(ans))


Fixed submission:
N = int(input())
S = list(''.join(sorted(str(input()))) for _ in range(N))

dic = {}
ans = 0

for s in S:
    if not s in dic:
        dic[s] = 1
    else:
        ans += dic[s]
        dic[s] += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

NUM = 10 ** 9 + 7

N, K = map(int, input().split())


def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


for i in range(1, K + 1):
    print((comb(N - K + 1, i) * comb(K - 1, i - 1)) % NUM)


Fixed submission:
import math

NUM = 10 ** 9 + 7

N, K = map(int, input().split())


def comb(a, b):
    return math.factorial(a) // (math.factorial(a - b) * math.factorial(b))


c = N - K + 1
d = K - 1
for i in range(1, K + 1):
    if c < i:
        print(0)
    else:
        print((comb(c, i) * comb(d, i - 1)) % NUM)