Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def cost(i,j):
        x1,y1,r1=xyr[i]
        x2, y2, r2 = xyr[j]
        res=((x1-x2)**2+(y1-y2)**2)**0.5-r1-r2
        return max(res,0)

    sx,sy,gx,gy=MI()
    n=II()
    xyr=LLI(n)
    xyr=[[sx,sy,0]]+xyr+[[gx,gy,0]]
    n+=2
    to=[[] for _ in range(n)]
    for i in range(n):
        x1,y1,r1=xyr[i]
        for j in range(i):
            x2, y2, r2 = xyr[j]
            c=cost(i,j)
            to[i].append((j,c))
            to[j].append((i,c))
    hp=[]
    fin=[False]*n
    heappush(hp,(0,0))
    while hp:
        d,u=heappop(hp)
        if fin[u]:continue
        fin[u]=True
        if u==n-1:
            print(d)
            exit()
        for v,c in to[u]:
            if fin[v]:continue
            heappush(hp,(d+c,v))

main()

Fixed submission:
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def cost(i,j):
        x1,y1,r1=xyr[i]
        x2, y2, r2 = xyr[j]
        res=((x1-x2)**2+(y1-y2)**2)**0.5-r1-r2
        return max(res,0)

    sx,sy,gx,gy=MI()
    n=II()
    xyr=LLI(n)
    xyr=[[sx,sy,0]]+xyr+[[gx,gy,0]]
    n+=2
    to=[[] for _ in range(n)]
    for i in range(n):
        x1,y1,r1=xyr[i]
        for j in range(i):
            x2, y2, r2 = xyr[j]
            c=cost(i,j)
            to[i].append((j,c))
            to[j].append((i,c))
    hp=[]
    fin=[False]*n
    heappush(hp,(0,0))
    while hp:
        d,u=heappop(hp)
        if fin[u]:continue
        fin[u]=True
        if u==n-1:
            print(d)
            exit()
        for v,c in to[u]:
            if fin[v]:continue
            heappush(hp,(d+c,v))

main()
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *
from math import gcd

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    n,k=MI()
    ans=k*pow(k-1,n-1)
    print(ans)

main()


Fixed submission:
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    n,k=MI()
    ans=k*pow(k-1,n-1)
    print(ans)

main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 1:
    print(1)
elif A[0] == 1 and A[1] == 1:
    print(0)
elif A[0] == 1:
    print(1)
else:
    Eratos = [False]*1000001
    ans = 0
    for i in range(N):
        if Eratos[A[i]]:
            ans += 1
        else:
            for j in range(A[i], 1000001, A[i]):
                Eratos[j] = True
print(N-ans)

Fixed submission:
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 1:
    print(1)
elif A[0] == 1 and A[1] == 1:
    print(0)
elif A[0] == 1:
    print(1)
else:
    Eratos = [False]*1000001
    ans = 0
    for i in range(N):
        if Eratos[A[i]]:
            ans += 1
        else:
            if i < N-1 and A[i] == A[i+1]:
                ans += 1
            for j in range(A[i], 1000001, A[i]):
                Eratos[j] = True
    print(N-ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = sorted(list(map(int, input().split())))
ans, s, i = 0, set(), 0

while i < N:
    j = 1
    while i+j <= N-1 and A[i] == A[i+j]:
        j += 1
    if j > 1:
        ans += j 
        s.add(i)
        i += j
    else:
        border, sadd = A[i] // 2, True
        for j in s:
            if A[i] % A[j] == 0:
                ans += 1
                sadd = False
                break
            elif A[j] > border:
                break
        if sadd:
            s.add(i)
        i += 1

print(N - ans)


Fixed submission:
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 1:
    print(1)
elif A[0] == 1 and A[1] == 1:
    print(0)
elif A[0] == 1:
    print(1)
else:
    Eratos = [False]*1000001
    ans = 0
    for i in range(N):
        if Eratos[A[i]]:
            ans += 1
        else:
            if i < N-1 and A[i] == A[i+1]:
                ans += 1
            for j in range(A[i], 1000001, A[i]):
                Eratos[j] = True
    print(N-ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0

for i in range(N):
    if (i < N-1 and A[i] == A[i+1]) or (0 < i and A[i-1] == A[i]):
        ans += 1
        continue
    border = A[i] // 2
    for j in range(i):
        if A[i] % A[j] == 0:
            ans += 1
            break
        elif A[j] > border:
            break

print(N - ans)

Fixed submission:
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 1:
    print(1)
elif A[0] == 1 and A[1] == 1:
    print(0)
elif A[0] == 1:
    print(1)
else:
    Eratos = [False]*1000001
    ans = 0
    for i in range(N):
        if Eratos[A[i]]:
            ans += 1
        else:
            if i < N-1 and A[i] == A[i+1]:
                ans += 1
            for j in range(A[i], 1000001, A[i]):
                Eratos[j] = True
    print(N-ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
if N == 0:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
elif A[0] != 0:
    print(-1)
else:
    rest = [1]
    for i in range(1, N+1):
        rest.append(min(rest[i-1]*2 - A[i], 10**13))
    ans, cnodes = A[N], A[N]
    for i in range(N-1, -1, -1):
        if cnodes//2 + cnodes%2 > rest[i]:
            print(-1)
            exit()
        else:
            cnodes = min(cnodes, rest[i]) + A[i]
            ans += cnodes
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
if N == 0:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
elif A[0] != 0:
    print(-1)
else:
    rest = [1]
    for i in range(1, N+1):
        rest.append(min(rest[i-1]*2 - A[i], 10**13))
    ans, cnodes = A[N], A[N]
    for i in range(N-1, -1, -1):
        if cnodes//2 + cnodes%2 > rest[i]:
            print(-1)
            exit()
        else:
            cnodes = min(cnodes, rest[i]) + A[i]
            ans += cnodes
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int, input().split()))
ans, d = 0, dict()

for i in range(N):
    diff = A[i] + A[0] - i 
    if d.get(diff) == None:
        d[diff] = [i]
    else:
        d[diff].append(i)

diff = 0
if d.get(0) != None:
    ans += len(d[0])

for i in range(1, N):
    diff -= A[i] - A[i-1] + 1
    dl = d.get(diff) 
    if dl != None:
        index = bisect.bisect_right(dl, i)        
        d[diff] = d[diff][index:]
        ans += len(d[diff])

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans, d = 0, dict()

for i in range(N):
    key = A[i] + i
    if d.get(key) == None:
        d[key] = 1
    else:
        d[key] += 1
    
    key = i - A[i]
    if d.get(key) != None:
        ans += d[key]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans, d = 0, dict()

for i in range(N):
    diff = A[i] + A[0] - i 
    if d.get(diff) == None:
        d[diff] = [i]
    else:
        d[diff].append(i)

diff = 0
if d.get(0) != None:
    ans += len(d[0])

for i in range(1, N):
    diff -= A[i] - A[i-1] + 1
    if d.get(diff) != None:
        j = 0
        while j < len(d[diff]) and d[diff][j] <= i:
            j += 1
        d[diff] = d[diff][j:]
        ans += len(d[diff])

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans, d = 0, dict()

for i in range(N):
    key = A[i] + i
    if d.get(key) == None:
        d[key] = 1
    else:
        d[key] += 1
    
    key = i - A[i]
    if d.get(key) != None:
        ans += d[key]

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
ans = set()

def point(x):
    temp = 0
    for i in range(Q):
        a, b, c, d = abcd[i]
        if x[b-1] - x[a-1] == c:
            temp += d
    return temp

def maker(x):
    dig = len(x)
    if  dig == N:
        ans.add(point(x))
    else:
        for i in range(x[-1], M+1):
            maker(x + [i])

for i in range(1, M):
    maker([i])
print(max(ans))

Fixed submission:
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
ans = set()

def point(x):
    temp = 0
    for i in range(Q):
        a, b, c, d = abcd[i]
        if x[b-1] - x[a-1] == c:
            temp += d
    return temp

def maker(x):
    dig = len(x)
    if  dig == N:
        ans.add(point(x))
    else:
        for i in range(x[-1], M+1):
            maker(x + [i])

for i in range(1, M+1):
    maker([i])
print(max(ans))
Buggy python submission (verdict: Runtime Error):
import collections

N = int(input())
S = input()

c = collections.Counter(S)
if 'R' in c.keys() and 'G' in c.keys() and 'B' in c.keys():
    ans = c['R'] * c['G'] * c['B']

    for x in range(N//2 - 1):
        for i in range(N - 2*(x+1)):
            if S[i] != S[i+x+1] and S[i] != S[i+2*(x+1)] and S[i+x+1] != S[i+2*(x+1)]:
                ans -= 1
print(ans)

Fixed submission:
import collections

N = int(input())
S = input()

c = collections.Counter(S)
if 'R' in c.keys() and 'G' in c.keys() and 'B' in c.keys():
    ans = c['R'] * c['G'] * c['B']

    for i in range(N-2):
        for x in range(((N-i)-1)//2):
            if S[i] != S[i+x+1] and S[i] != S[i+2*(x+1)] and S[i+x+1] != S[i+2*(x+1)]:
                ans -= 1
else:
    ans = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())

if N % 2 != 0:
    print(0)
else:
    n = N // 10
    ans = n
    for i in range(1,int(math.log(n, 5) + 1)):
        ans += n // (5 ** i)
    print(ans)

Fixed submission:
import math
N = int(input())

if N % 2 != 0 or N <= 8:
    print(0)
else:
    n = N // 10
    ans = n
    for i in range(1,int(math.log(n, 5) + 1)):
        ans += n // (5 ** i)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

Cn, ans = N * (N-1) // 2, 0

for i in range(60):
    count = 0
    for j in range(N):
        count += A[j] % 2
        A[j] //= 2
    if count == 0:
        continue
    ans += (Cn - (count*(count-1)//2 + (N-count)*(N-count-1)//2)) * (2**i)
print(ans % (10**9 + 7)) 

Fixed submission:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

Cn, ans = N * (N-1) // 2, 0

for i in range(60):
    count = int(np.sum(A % 2))
    A //= 2
    if count == 0:
        continue
    ans += (Cn - (count*(count-1)//2 + (N-count)*(N-count-1)//2)) * (2**i)
print(ans % (10**9 + 7))

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

def C(a,b):
    if a - b < 0:
        return 0
    else:
        return math.factorial(a) // (math.factorial(b)*math.factorial(a-b))

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

Cn, ans = N * (N-1) // 2, 0

for i in range(60):
    count = 0
    for j in range(N):
        count += A[j] % 2
        A[j] //= 2
    if count == 0:
        continue
    ans += (Cn - (C(count, 2) + C(N-count, 2))) * (2**i)
print(ans % (10**9 + 7)) 

Fixed submission:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

Cn, ans = N * (N-1) // 2, 0

for i in range(60):
    count = int(np.sum(A % 2))
    A //= 2
    if count == 0:
        continue
    ans += (Cn - (count*(count-1)//2 + (N-count)*(N-count-1)//2)) * (2**i)
print(ans % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A > B:
    A, B = B, A

s = [1] * (A+1)
ans, t = 1, set()
i, lim = 2, A ** 0.5
while i < lim:
    if s[i] == 1:
        for j in range(i*2, A+1, i):
            s[j] = 0
        if A % i == 0 and B % i == 0:
            ans += 1
    i += 1

print(ans)

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

length = int(A ** 0.5) + 2
Ax = A
s = [1] * length
ans, i, lim, t = 1, 2, A ** 0.5, set()
while i < lim:
    if s[i] == 1:
        for j in range(i*2, length, i):
            s[j] = 0
        if A % i == 0:
            if B % i == 0:
                ans += 1
            while Ax % i == 0:
                Ax //= i
    i += 1

if Ax >= length and B % Ax == 0:
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
 
N,M = map(int, input().split())
Ap = input().split()
A = [0]*N
for i in range(N):
    A[i] = int(Ap[i])
A.sort()

for i in range(M):
    x = A[-1]
    x //= 2
    A = A[:-1]
    A.insert(bisect_left(A, x), x)
 
print(sum(A))

Fixed submission:
from bisect import bisect_left
 
N,M = map(int, input().split())
A = sorted([int(x) for x in input().split()])
 
while M > 0:
    x = A.pop(-1)
    x //= 2
    ind = bisect_left(A, x)
    M -= 1
    if ind < N-1:
        temp = [x] + [A[-i-1]//2 for i in range(min(M, N-1 - ind))]
        A = sorted(A[:N-len(temp)] + temp)
    else:
        A.insert(bisect_left(A, x), x)
    M -= N-1 - ind
 
print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

N,M = map(int, input().split())
A = sorted([int(x) for x in input().split()])

for i in range(M):
    x = A.pop(-1)
    x //= 2
    A.insert(bisect_left(A, x), x)

print(sum(A))

Fixed submission:
from bisect import bisect_left
 
N,M = map(int, input().split())
A = sorted([int(x) for x in input().split()])
 
while M > 0:
    x = A.pop(-1)
    x //= 2
    ind = bisect_left(A, x)
    M -= 1
    if ind < N-1:
        temp = [x] + [A[-i-1]//2 for i in range(min(M, N-1 - ind))]
        A = sorted(A[:N-len(temp)] + temp)
    else:
        A.insert(bisect_left(A, x), x)
    M -= N-1 - ind
 
print(sum(A))
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(sum(list(range(N))))

Fixed submission:
N = int(input())
ans = N*(N-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())

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

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

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

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

for i in range(1,K+1):
    if N-K+1 < i:   print(0)
    else:   print( (C(N-K+1,i)*C(K-1,i-1)) % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = sorted([int(x) for x in input().split()])
ans = []

for i in range(N-1):
    if (N-i) % 2 == 0:
        ans += [A[-1],A[0]]
        n = A[-1] - A[0]
        j = 0
        while n > A[j]:
            j += 1
            if j == (N-i)-1:    break
        A = A[1:j] + [n] + A[j:(N-i)-1]

    else:
        ans += [A[0],A[-1]]
        n = A[0] - A[-1]
        j = (N-i)-1
        while n < A[j]:
            j -= 1
            if j == 0:    break
        A = A[1:j] + [n] + A[j:(N-i)-1]

print(A[0])          
for i in range(N-1):
    print(ans[2*i],ans[2*i+1])



Fixed submission:
N = int(input())
A = sorted([int(x) for x in input().split()])
ans = []

if A[-1] <= 0:
    print(A[-1] - sum(A[:-1]))
    a = A[-1]
    for i in range(N-1):
        print(a,A[i])
        a -= A[i]

elif A[0] >= 0:
    print(sum(A[1:])-A[0])
    a = A[0]
    for i in range(1,N-1):
        print(a,A[i])
        a -= A[i]
    print(A[N-1],a)

else:
    i = 0
    while A[i] < 0:
        i += 1
    print(sum(A[i:]) - sum(A[:i]))
    a,b = A[i-1],A[i]

    if i != N-1:
        for j in range(N-i-1):
            print(a,A[i+j+1])
            a -= A[i+j+1]
    if i != 1:
        for j in range(i-1):
            print(b,A[j])
            b -= A[j]

    print(b,a)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
a = []
for i in range(M):
    a += [int(input())]

if N == 1:  print(1)
elif N == 2:
    if 1 in a:  print(1)
    else:   print(2)
else:
    temp1, temp2 = 0,0
    if 1 not in a:  temp1 = 1
    if 2 not in a:  temp2 = 1 + temp1
    
    for i in range(2,N):
        temp = 0
        if i+1 not in a:    temp = temp1 + temp2
        temp1 = temp2
        temp2 = temp

print( int(temp % 1000000007) )

Fixed submission:
N,M = map(int, input().split())
a = set()
for i in range(M):
    a.add(int(input()))

if N == 1:  print(1)
elif N == 2:
    if 1 == M:  print(1)
    else:   print(2)
else:
    temp, temp1, temp2 = 0,0,0
    if 1 not in a:  temp1 = 1
    if 2 not in a:  temp2 = 1 + temp1
    
    for i in range(2,N-1):
        temp = 0
        if i+1 not in a:    temp = temp1 + temp2
        temp1 = temp2
        temp2 = temp

    print( int((temp1+temp2) % 1000000007) )
Buggy python submission (verdict: Runtime Error):
sys.setrecursionlimit(100002)

L = input()
MOD = 10**9+7

num_ab = [1]
for i in range(1, len(L)+1):
    num_ab.append((num_ab[-1] * 3) % MOD)

def calc(L, m):
    m %= MOD
    if len(L) == 1:
        return (m * num_ab[int(L)]) % MOD
    elif '0' not in L:
        return (m * num_ab[len(L)]) % MOD
    elif '1' not in L[1:]:
        return ((m * num_ab[len(L) - 1]) % MOD + (2 * m) % MOD) % MOD
    else:
        return ((m * num_ab[len(L) - 1]) % MOD + calc(L[L[1:].index('1') + 1:], 2*m)) % MOD

print(calc(L,1))

Fixed submission:
L = input()
MOD = 10**9+7

num_ab = [1]
for i in range(1, len(L)+1):
    num_ab.append((num_ab[-1] * 3) % MOD)

ans, m = 0, 1
while True:
    if '0' not in L:
        ans = (ans + (m * num_ab[len(L)]) % MOD) % MOD
        print(ans)
        exit()
    elif '1' not in L[1:]:
        ans = (ans + ((m * num_ab[len(L) - 1]) % MOD + (2 * m) % MOD) % MOD) % MOD
        print(ans)
        exit()
    else:
        ans = (ans + (m * num_ab[len(L) - 1]) % MOD) % MOD
        L = L[L[1:].index('1') + 1:]
        m = (2 * m) % MOD

Buggy python submission (verdict: Runtime Error):
L = input()
MOD = 10**9+7

num_ab = [1]
for i in range(1, len(L)+1):
    num_ab.append((num_ab[-1] * 3) % MOD)

def calc(L, m):
    m %= MOD
    if len(L) == 1:
        return (m * num_ab[int(L)]) % MOD
    elif '0' not in L:
        return (m * num_ab[len(L)]) % MOD
    elif '1' not in L[1:]:
        return ((m * num_ab[len(L) - 1]) % MOD + (2 * m) % MOD) % MOD
    else:
        return ((m * num_ab[len(L) - 1]) % MOD + calc(L[L[1:].index('1') + 1:], 2*m)) % MOD

print(calc(L,1))

Fixed submission:
L = input()
MOD = 10**9+7

num_ab = [1]
for i in range(1, len(L)+1):
    num_ab.append((num_ab[-1] * 3) % MOD)

ans, m = 0, 1
while True:
    if '0' not in L:
        ans = (ans + (m * num_ab[len(L)]) % MOD) % MOD
        print(ans)
        exit()
    elif '1' not in L[1:]:
        ans = (ans + ((m * num_ab[len(L) - 1]) % MOD + (2 * m) % MOD) % MOD) % MOD
        print(ans)
        exit()
    else:
        ans = (ans + (m * num_ab[len(L) - 1]) % MOD) % MOD
        L = L[L[1:].index('1') + 1:]
        m = (2 * m) % MOD
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())[::-1] + [0,0]
N,i = len(s),0
ansl = []
while i < N:
    if s[i] == 'C' and s[i+1] == 'B':
        temp = [0]
        i += 2
        while i < N:
            if s[i] == 'A':
                temp += [1]
                i += 1
            elif s[i] == 'C' and s[i+1] == 'B':
                temp += [0]
                i += 2
            else:
                break
        ansl += [temp]
    else:   i += 1

ans = 0
for c in ansl:
    for i in range(len(c)-1):
        if c[i]==0:    ans += c[i+1:].count(1)

print(ans)




Fixed submission:
s = list(input())[::-1] + [0,0]
N,i,ans = len(s),0,0

while i < N:
    if s[i] == 'C' and s[i+1] == 'B':
            temp = 1
            i += 2
            while i < N:
                if s[i] == 'A':
                    ans += temp
                    i += 1
                elif s[i] == 'C' and s[i+1] == 'B':
                    temp += 1
                    i += 2
                else:
                    break
    else:   i += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())[::-1] + [0,0]
N,i = len(s),0
ansl = []
while i < N:
    if s[i] == 'C' and s[i+1] == 'B':
        temp = [0]
        i += 2
        while i < N:
            if s[i] == 'A':
                temp += [1]
                i += 1
            elif s[i] == 'C' and s[i+1] == 'B':
                temp += [0]
                i += 2
            else:
                break
        ansl += [temp]
    else:   i += 1

ans = 0
for c in ansl:
    for i in range(len(c)-1):
        if c[i]==0:    ans += c[i+1:].count(1)

print(ans)




Fixed submission:
s = list(input())[::-1] + [0,0]
N,i,ans = len(s),0,0

while i < N:
    if s[i] == 'C' and s[i+1] == 'B':
            temp = 1
            i += 2
            while i < N:
                if s[i] == 'A':
                    ans += temp
                    i += 1
                elif s[i] == 'C' and s[i+1] == 'B':
                    temp += 1
                    i += 2
                else:
                    break
    else:   i += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
V = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
P = [V[x]-C[x] for x in range(N)]

P = sorted(P)[::-1]
i,ans = 0,0

while P[i] > 0:
    ans += P[i]
    i += 1
print(ans)

Fixed submission:
N = int(input())
V = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
P = [V[x]-C[x] for x in range(N)]

P = sorted(P)[::-1]
i,ans = 0,0

while P[i] > 0:
    ans += P[i]
    i += 1
    if i == N:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = (int(x) for x in input().split())
S = list(input())
size = [1]
memo = [S[0],0]
for i in range(1,N):
    if S[i] == memo[0]:
        size[memo[1]] += 1
    else:
        memo = [S[i],memo[1]+1]
        size += [1]

if S[0] == '0':
    size = [0] + size
if S[-1] == '0':
    size += [0]

if int((len(size)-1)/2) <= K:
    print(N)
else:
    ans = 0
    for i in range(len(size)-(K*2))[::2]:
        a = sum(size[i:i+K*2+1])
        if ans < a:
            ans = a
    print(ans)


Fixed submission:
N,K = (int(x) for x in input().split())
S = list(input())
size = [1]
memo = S[0]
for i in range(1,N):
    if S[i] == memo:
        size[-1] += 1
    else:
        memo = S[i]
        size += [1]

if S[0] == '0':
    size = [0] + size
if S[-1] == '0':
    size += [0]

if int((len(size)-1)/2) <= K:
    print(N)
else:
    ans = sum(size[0:K*2+1])
    a = ans
    for i in range(2,len(size)-(K*2))[::2]:
        a = a - (size[i-2] + size[i-1]) + (size[i+K*2-1] + size[i+K*2])
        if ans < a:
            ans = a
    print(ans)