Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,x = (int(x) for x in input().split())
l=list(map(int,input().split()))
k=0
d=0

while d<=x:
  d=d+l[k]
  k=k+1

if n+1<k:
  print(n+1)
else:print(k)

Fixed submission:
n,x = (int(x) for x in input().split())
l=list(map(int,input().split()))
k=0
d=0

while d<=x:
   if len(l)<=k:
    break
   else:
    d=d+l[k]
    k=k+1
if d<=x:
  print(k+1)
else:print(k)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    max_ans = 10 ** 18
    ans = 0
    for i in A:
        if ans == 0:
            ans = i
        else:
            ans *= i

    if max_ans < ans:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    max_ans = 10 ** 18
    ans = 0
    if 0 in A:
        print(0)
        exit()

    for i, a in enumerate(A):
        if i == 0:
            ans = a
            continue

        ans = ans * a
        if ans > max_ans:
            print(-1)
            exit()

    if max_ans < ans:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    max_ans = 10 ** 18
    ans = 0
    for i in A:
        if ans == 0:
            ans = i
        else:
            ans *= i
    if max_ans < ans:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    max_ans = 10 ** 18
    ans = 0
    if 0 in A:
        print(0)
        exit()

    for i, a in enumerate(A):
        if i == 0:
            ans = a
            continue

        ans = ans * a
        if ans > max_ans:
            print(-1)
            exit()

    if max_ans < ans:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a, b = input().split()
a = int(a)
b = math.floor(float(b) * 100)
print(a * b // 100)

Fixed submission:
import math


def main():
    a, b = input().split()
    A = int(a)
    # B = int(math.floor(float(b) * 100))
    B = int(b.replace('.', ''))
    print(int(A * B // 100))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
a, b = input().split()
a = int(a)
b = math.floor(float(b) * 100)
print(a * b // 100)

Fixed submission:
import math


def main():
    a, b = input().split()
    A = int(a)
    # B = int(math.floor(float(b) * 100))
    B = int(b.replace('.', ''))
    print(int(A * B // 100))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math


def main():
    a, b, h, m = map(int, input().split())
    if h == 0 and m == 0:
        print(abs(b - a))
        exit()

    h_basho = h * 60 + m
    m_basho = m * 12
    h_m_basho = h_basho - m_basho

    if h_m_basho == 360:
        print(a + b)
        exit()
    elif h_m_basho < 360:
        kakudo = 90 * h_m_basho / 180
    else:
        kakudo = 90 * (720 - h_m_basho) / 180

    ab2 = a ** 2 + b ** 2
    cos = 2 * a * b * (round(math.cos(round(math.radians(kakudo)), 20), 20))

    if kakudo <= 90:
        ac = ab2 - cos
        print("%.20f" % math.sqrt(ac))
    else:
        ac = ab2 + cos
        print("%.20f" % math.sqrt(ac))


if __name__ == '__main__':
    main()


Fixed submission:
import math


def main():
    a, b, h, m = map(int, input().split())
    th = (h * 60 + m) / 720 * 2 * math.pi
    tm = m / 60 * 2 * math.pi
    xh = a * math.cos(th)
    yh = a * math.sin(th)
    xm = b * math.cos(tm)
    ym = b * math.sin(tm)
    dx = xh - xm
    dy = yh - ym
    ans = math.sqrt(dx ** 2 + dy ** 2)
    print("%.10f" % ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    a = [v[i] for i in range(n) if i % 2 == 0]
    b = [v[i] for i in range(n) if i % 2 == 1]
    half_n = n // 2
    a_count = Counter.most_common(Counter(a))
    b_count = Counter.most_common(Counter(b))
    ans = 0
    if a_count[0][1] > b_count[0][1]:
        ans += half_n - a_count[0][1]
        if a_count[0][0] == b_count[0][0]:
            ans += half_n - b_count[1][1]
        else:
            ans += half_n - b_count[0][1]
    elif a_count[0][1] < b_count[0][1]:
        ans += half_n - b_count[0][1]
        if a_count[0][0] == b_count[0][0]:
            ans += half_n - a_count[1][1]
        else:
            ans += half_n - a_count[0][1]
    else:
        if a_count[0][0] == b_count[0][0]:
            ans += half_n - a_count[0][1]
            ans += half_n - b_count[1][1]
        else:
            ans += half_n - a_count[0][1]
            ans += half_n - b_count[0][1]
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    # a = [v[i] for i in range(n) if i % 2 == 0]
    # b = [v[i] for i in range(n) if i % 2 == 1]

    # a_count = Counter.most_common(Counter(a))
    # b_count = Counter.most_common(Counter(b))

    # half_n = n // 2
    ac = Counter(v[::2]).most_common(2)
    bc = Counter(v[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        print(n - ac[0][1] - bc[0][1])
    else:
        if len(bc) == 1 or len(ac) == 1:
            print(n // 2)
        else:
            print(n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1]))

    # ans = 0

    # half_n = n // 2
    # eq = a_count[0][0] == b_count[0][0]
    # h_ac0 = half_n - a_count[0][1]
    # h_bc0 = half_n - b_count[0][1]

    # if len(a_count) == 1 and len(b_count) == 1:
    #     if eq:
    #         print(half_n)
    #         exit()
    #     else:
    #         print(ans)
    #         exit()

    # if a_count[0][1] > b_count[0][1]:
    #     ans += h_ac0
    #     if eq:
    #         ans += half_n - b_count[1][1]
    #     else:
    #         ans += h_bc0
    # elif a_count[0][1] < b_count[0][1]:
    #     ans += h_bc0
    #     if eq:
    #         ans += half_n - a_count[1][1]
    #     else:
    #         ans += h_ac0
    # else:
    #     if eq:
    #         ans += h_ac0
    #         ans += half_n - b_count[1][1]
    #     else:
    #         ans += h_ac0
    #         ans += h_bc0
    # print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
buf = 1
for i in range(N) :
    buf = buf * A[i]
if buf > 10**(18) :
    print("-1")
else :
    print(buf)

Fixed submission:
import numpy as np
N = int(input())
buf = list(map(int,input().split()))
cnt = 1
flag = True
for i in range(N) :
    if buf[i] == 0 :
        print(0)
        exit()
for i in range(N) :
    cnt = cnt * buf[i]
    if cnt > 10 ** 18 :
        flag = False
        break

if flag == True :
    print(cnt)
else :
    print("-1")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
buf = 1
for i in A :
    buf = buf * i

if buf <= 10 ** (18) :
    print(buf)
else :
    print("-1")


Fixed submission:
import numpy as np
N = int(input())
buf = list(map(int,input().split()))
cnt = 1
flag = True
for i in range(N) :
    if buf[i] == 0 :
        print(0)
        exit()
for i in range(N) :
    cnt = cnt * buf[i]
    if cnt > 10 ** 18 :
        flag = False
        break

if flag == True :
    print(cnt)
else :
    print("-1")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

for i in range(N) :
    print(A.count(i+1))

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
cnt = [0 for y in range(N)]

for i in range(N-1) :
    cnt[A[i]-1] += 1

for i in range(N) :
    print(cnt[i])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

def main():
    cnt = 0
    cnt_1 = 0
    for i in range(N) :
        for j in range(i+1,N) :
            for k in range(j+1,N) :
                cnt_1 += 1
                if ((S[i] == S[j]) or (S[i] == S[k]) or (S[j] == S[k])) or (k == 2*j-i) :
                    cnt += 1
    print(cnt_1 - cnt)

if __name__ == '__main__':
    main()

Fixed submission:
N = int(input())
S = list(input())
r,g,b = 0,0,0
k = 0
buf = 0

for i in range(N) :
    if S[i] == 'R' :
        r += 1
    elif S[i] == 'G' :
        g += 1
    else :
        b += 1

for j in range(N) :
    for i in range(j) :
        k = 2 * j - i
        if k <= N-1 :
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k] :
                buf += 1

print(r*g*b - buf)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
cnt = 0
cnt_1 = 0
for i in range(N) :
    for j in range(i+1,N) :
        for k in range(j+1,N) :
            cnt_1 += 1
            if ((S[i] == S[j]) or (S[i] == S[k]) or (S[j] == S[k])) or (k == 2*j-i) :
                cnt += 1
print(cnt_1 - cnt)

Fixed submission:
N = int(input())
S = list(input())
r,g,b = 0,0,0
k = 0
buf = 0

for i in range(N) :
    if S[i] == 'R' :
        r += 1
    elif S[i] == 'G' :
        g += 1
    else :
        b += 1

for j in range(N) :
    for i in range(j) :
        k = 2 * j - i
        if k <= N-1 :
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k] :
                buf += 1

print(r*g*b - buf)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
cnt = 0
cnt_1 = 0
for i in range(N) :
    for j in range(i,N) :
        for k in range(j,N) :
            cnt_1 += 1
            if ((S[i] == S[j]) or (S[i] == S[k]) or (S[j] == S[k])) or (j-i == k-j) :
                cnt += 1
print(cnt_1 - cnt)

Fixed submission:
N = int(input())
S = list(input())
r,g,b = 0,0,0
k = 0
buf = 0

for i in range(N) :
    if S[i] == 'R' :
        r += 1
    elif S[i] == 'G' :
        g += 1
    else :
        b += 1

for j in range(N) :
    for i in range(j) :
        k = 2 * j - i
        if k <= N-1 :
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k] :
                buf += 1

print(r*g*b - buf)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K = map(int,input().split())
for i in range(K) :
    if A >= 1 :
        A = A - 1
    elif B >= 1 :
        B = B - 1
    else :
        pass

print(A,B)  

Fixed submission:
A,B,K = map(int,input().split())

if A >= K :
    A = A - K 
    print(A,B)
else :
    if (B-(K-A)) >= 0 :
        print(0,B-(K-A)) 
    else :
        print(0,0)
Buggy python submission (verdict: Time Limit Exceeded):
N = list(input()) #e.g. 1432
buf_1 = 0 #入力の3桁目以上 - 2桁目以下 ,1400
buf_2 = 0 #X_1+...+X_6はこれ以下 , 入力の3桁目以上,14
counter = 0 #カウンタ

if len(N) <= 2 : #2桁以下なら終了
    print(0)
    exit()

#3桁以上なら続行
M = 10*int(N[-2]) + int(N[-1]) #入力の2桁目以下,32
for i in range(len(N) - 2) :
    buf_1 += (100*(10**i)) * int(N[-(i+3)]) 
buf_2 = int(buf_1/100) #入力の3桁目以上

##test##
#print('M is')
#print(M)
#print('buf_2 is')
#print(buf_2)
##test##

for j in range(int(M)+1) :
    for k in range(int(M/2)+1) :
        for l in range(int(M/3)+1) :
            for m in range(int(M/4)+1) :
                for n in range(int(M/5)+1) :
                    if M == (1*j+2*k+3*l+4*m+5*n) and (buf_2 -(j+k+l+m+n)) >= 0 :
                        ##test##
                        #print('set is')
                        #print(buf_2 -(j+k+l+m+n),j,k,l,m,n)
                        ##test##
                        print(1)
                        exit()
print(0)

Fixed submission:
X = int(input())
for i in range(1,X+1) :
    for j in range(100*i,105*i+1) :
        if X % j == 0 :
            print(1)
            exit()
print(0)

Buggy python submission (verdict: Time Limit Exceeded):
N = list(input()) #e.g. 1432
buf_1 = 0 #入力の3桁目以上 - 2桁目以下 ,1400
buf_2 = 0 #X_1+...+X_6はこれ以下 , 入力の3桁目以上,14

if len(N) <= 2 : #2桁以下なら終了
    print(0)
    exit()

#3桁以上なら続行
M = 10*int(N[-2]) + int(N[-1]) #入力の2桁目以下,32
for i in range(len(N) - 2) :
    buf_1 += (100*(10**i)) * int(N[-(i+3)]) 
buf_2 = int(buf_1/100) #入力の3桁目以上

Flag_1 = False

for j in range(int(M)+1) :
    for k in range(int(M/2)+1) :
        for l in range(int(M/3)+1) :
            for m in range(int(M/4)+1) :
                for n in range(int(M/5)+1) :
                    if M == (1*j+2*k+3*l+4*m+5*n) and (buf_2 -(j+k+l+m+n)) >= 0 :
                        #print('set is')
                        #print(buf_2 -(j+k+l+m+n),j,k,l,m,n)
                        print(1)
                        Flag_1 = True
                        exit()
if Flag_1 == False :
    print(0)

Fixed submission:
X = int(input())
for i in range(1,X+1) :
    for j in range(100*i,105*i+1) :
        if X % j == 0 :
            print(1)
            exit()
print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n, *a = map(int, open(0).read().split())

ans = 1
for ai in a:
    ans *= ai

if ans > 10 ** 18:
    print(-1)
else:
    print(ans)

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

if 0 in a:
    print(0)
    exit()

ans = 1
for ai in a:
    ans *= ai
    if ans > 10 ** 18:
        print(-1)
        exit()

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, *a = map(int, open(0).read().split())

ans = 1
for ai in a:
    ans *= ai

if ans > 10 ** 18:
    print(-1)
else:
    print(ans)


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

if 0 in a:
    print(0)
    exit()

ans = 1
for ai in a:
    ans *= ai
    if ans > 10 ** 18:
        print(-1)
        exit()

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

i = 1
a = 1
b = 0
while a**5 - b**5 <= x:
    if a**5 - b**5 == x:
        print(a, b)
        exit()
    a += 1
    b -= 1

while True:
    i += 1
    if x % i:
        continue

    b = 1
    a = i - b
    while b < a and a**5 - b**5 <= x:
        if a**5 - b**5 == x:
            print(a, b)
            exit()
        a += 1
        b -= 1

    a = i
    b = 0
    while a**5 - b**5 <= x:
        if a**5 - b**5 == x:
            print(a, b)
            exit()
        a += 1
        b -= 1

Fixed submission:
x = int(input())
OP = [+1, -1]
for a in range(1000):
    for b in range(a + 1):
        for op1 in OP:
            for op2 in OP:
                if (op1 * a)**5 - (op2 * b)**5 == x:
                    print(op1 * a, op2 * b)
                    exit()

Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

i = 1
a = 1
b = 0
while a**5 - b**5 <= x:
    if a**5 - b**5 == x:
        print(a, b)
        exit
    a += 1
    b -= 1

while True:
    i += 1
    if x % i:
        continue

    b = 1
    a = i - b
    while b < a and a**5 - b**5 <= x:
        if a**5 - b**5 == x:
            print(a, b)
            exit
        a += 1
        b -= 1

    a = i
    b = 0
    while a**5 - b**5 <= x:
        if a**5 - b**5 == x:
            print(a, b)
            exit
        a += 1
        b -= 1

Fixed submission:
x = int(input())
OP = [+1, -1]
for a in range(1000):
    for b in range(a + 1):
        for op1 in OP:
            for op2 in OP:
                if (op1 * a)**5 - (op2 * b)**5 == x:
                    print(op1 * a, op2 * b)
                    exit()
Buggy python submission (verdict: Time Limit Exceeded):
n, *a = map(int, open(0).read().split())
for i in range(1, n + 1):
    print(a.count(i))
    a = list(filter(lambda x: x != i, a))

Fixed submission:
n, *a = map(int, open(0).read().split())
bt = [None] + [0] * n

for ai in a:
    bt[ai] += 1

for a in bt[1:]:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n, *a = map(int, open(0).read().split())
[print(a.count(i)) for i in range(1, n + 1)]


Fixed submission:
n, *a = map(int, open(0).read().split())
bt = [None] + [0] * n

for ai in a:
    bt[ai] += 1

for a in bt[1:]:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def dfs(rel, s):
    dist = [-1] * len(rel)

    q = deque()
    q.append(s)
    dist[s] = 0

    while len(q):
        e = q.popleft()
        for ei in Rel[e]:
            if dist[ei] >= 0:
                continue
            q.append(ei)
            dist[ei] = dist[e] + 1

    ans = [0] * (len(rel) - 1)
    for d in dist:
        ans[d] += 1
    return ans


N, X, Y = map(int, input().split())
Rel = [None] + [[] for _ in range(N)]
for i in range(1, N + 1):
    if i > 1:
        Rel[i].append(i - 1)
    if i < N:
        Rel[i].append(i + 1)
Rel[X].append(Y)
Rel[Y].append(X)

K = [0] * (N - 1)

for i in range(1, N + 1):
    dist = dfs(Rel, i)
    for k, v in enumerate(dist[1:]):
        K[k] += v

for k in K[:-1]:
    print(k // 2)
print(0)

Fixed submission:
N, X, Y = map(int, input().split())
D = [None] + [0] * (N - 1)
for i in range(1, N):
    for j in range(i + 1, N + 1):
        d = min(abs(j - i),
                abs(X - i) + 1 + abs(j - Y),
                abs(Y - i) + 1 + abs(j - X))
        D[d] += 1

for d in D[1:]:
    print(d)
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split())) + [-1]
q = list(map(int, input().split())) + [-1]
r = list(map(int, input().split())) + [-1]
p.sort()
q.sort()
r.sort()

summ = 0
Z = 0
while X + Y - Z:
    if r[-1] * (C - Z > 0) < p[-1] * (X > 0) > q[-1] * (Y > 0):
        summ += p.pop()
        X -= 1
    elif p[-1] * (X > 0) < q[-1] * (Y > 0) > r[-1] * (C - Z > 0):
        summ += q.pop()
        Y -= 1
    else:
        summ += r.pop()
        Z += 1

print(summ)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
p = p[-X:]
q = q[-Y:]
r.extend(p)
r.extend(q)
r.sort()
print(sum(r[-(X + Y):]))
Buggy python submission (verdict: Time Limit Exceeded):
import collections
import math


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


input()
a = list(map(int, input().split()))
c = collections.Counter(a)

summ = sum([comb(v, 2) for v in c.values()])
for ai in a:
    print(summ - comb(c[ai], 2) + comb(c[ai] - 1, 2))

Fixed submission:
import collections
import math


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


input()
a = list(map(int, input().split()))
c = collections.Counter(a)

summ = sum([comb(v, 2) for v in c.values()])
for ai in a:
    print(summ - c[ai] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import math


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


n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)

summ = 0
for v in c.values():
    summ += comb(v, 2)

for i in range(n):
    print(summ - comb(c[a[i]], 2) + comb(c[a[i]] - 1, 2))

Fixed submission:
import collections
import math


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


input()
a = list(map(int, input().split()))
c = collections.Counter(a)

summ = sum([comb(v, 2) for v in c.values()])
for ai in a:
    print(summ - c[ai] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import math
import copy


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


n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)

for ai in a:
    cc = copy.deepcopy(c)
    cc[ai] -= 1
    print(sum(comb(v, 2) for v in cc.values()))

Fixed submission:
import collections
import math


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


input()
a = list(map(int, input().split()))
c = collections.Counter(a)

summ = sum([comb(v, 2) for v in c.values()])
for ai in a:
    print(summ - c[ai] + 1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
s = sorted([*range(N)], key=lambda i: A[i])
s = [i + 1 for i in s]
print(*s)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
s = sorted([i for i in range(N)], key=lambda i: A[i])
s = [i + 1 for i in s]
print(*s)
Buggy python submission (verdict: Runtime Error):
s,t=map(int,open(0).read().split());print(sum([j==i for i in s for j in t]))

Fixed submission:
s,t=open(0).read().split();print(sum([j==i for i,j in zip(s,t)]))
Buggy python submission (verdict: Time Limit Exceeded):
import math


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


n = int(input())
c = [''.join(sorted(list(input()))) for _ in range(n)]
s = set(c)

anagram = [0] * len(s)
for i, si in enumerate(s):
    anagram[i] = c.count(si)

print(sum(comb(a, 2) for a in anagram if a > 1))

Fixed submission:
import math
import collections


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


n = int(input())
s = [''.join(sorted(list(input()))) for _ in range(n)]
c = collections.Counter(s)
print(sum(comb(a, 2) for a in c.values() if a > 1))

Buggy python submission (verdict: Time Limit Exceeded):
import math


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


n = int(input())
c = [''.join(sorted(list(input()))) for _ in range(n)]
s = set(c)

anagram = [0] * len(s)
for i, si in enumerate(s):
    anagram[i] = c.count(si)

print(sum(comb(a, 2) for a in anagram if a > 1))

Fixed submission:
import math
import collections


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


n = int(input())
s = [''.join(sorted(list(input()))) for _ in range(n)]
c = collections.Counter(s)
print(sum(comb(a, 2) for a in c.values() if a > 1))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import collections


n = int(input())
c = list([collections.Counter(input()) for _ in range(n)])

summ = 0
for c1, c2 in itertools.combinations(c, 2):
    summ += c1 == c2
print(summ)

Fixed submission:
import math
import collections


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


n = int(input())
s = [''.join(sorted(list(input()))) for _ in range(n)]
c = collections.Counter(s)
print(sum(comb(a, 2) for a in c.values() if a > 1))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import collections


def is_anagram(s1, s2):
    c1 = collections.Counter(s1)
    c2 = collections.Counter(s2)
    return c1 == c2


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

summ = 0
for s1, s2 in itertools.combinations(s, 2):
    summ += is_anagram(s1, s2)

print(summ)

Fixed submission:
import math
import collections


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


n = int(input())
s = [''.join(sorted(list(input()))) for _ in range(n)]
c = collections.Counter(s)
print(sum(comb(a, 2) for a in c.values() if a > 1))
Buggy python submission (verdict: Runtime Error):
_,*l=open(0).read().split()
[print(i + 1)for i in sorted([*range(len(l)//2)],key=lambda i:(l[i*2],-int(l[i*2+1])))]

Fixed submission:
_,*l=open(0).read().split()
[print(i + 1)for i in sorted(range(len(l)//2),key=lambda i:(l[i*2],-int(l[i*2+1])))]
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

for _ in range(q):
    li, ri = map(int, input().split())
    print(s[li - 1:ri].count('AC'))

Fixed submission:
n, q = map(int, input().split())
s = input()

a = [0, 0]
for i in range(2, n + 1):
    a.append(a[i - 1] + (s[i - 2:i] == 'AC'))


for _ in range(q):
    li, ri = map(int, input().split())
    print(a[ri] - a[li])