Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m = mi()
alis = li()
for i in range(n):
    alis[i] //= 2

ima = alis[0] & -alis[0]
alis[0] //= (1<<(ima-1))
for i in range(1,n):
    tmp = alis[i] & -alis[i]
    if ima != tmp:
        print(0)
        exit()
    else:
        alis[i] //= (1<<(ima-1))

tmp = (1<<(ima-1))
#a>b
def gcd(a,b):
    if a < b:
        a,b = b,a
    while b!=0:
        a,b=b,a%b
    return a
#a>b
def lcm(a,b):
    return a*b // gcd(a,b)
ima = 1
for i in range(n):
    ima = lcm(alis[i],ima)
    if ima*tmp > m:
        print(0)
        exit()
ans = 0

tmm = m//ima
if tmm % 2 ==0:
    print(tmm//2)
else:
    print(tmm//2 +1)
    

Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m = mi() 
alis = li()
for i in range(n):
    alis[i] //= 2

ima = alis[0] & -alis[0]
alis[0] //= ima
for i in range(1,n):
    tmp = alis[i] & -alis[i]
    if ima != tmp:
        print(0)
        exit()
    else:
        alis[i] //=ima

tmp = ima
#a>b
def gcd(a,b):
    if a < b:
        a,b = b,a
    while b!=0:
        a,b=b,a%b
    return a
#a>b
def lcm(a,b):
    return a*b // gcd(a,b)
ima = 1
for i in range(n):
    ima = lcm(alis[i],ima)
    if ima*tmp > m:
        print(0)
        exit()
ans = 0

tmm = m//(ima*tmp)
if tmm % 2 ==0:
    print(tmm//2)
else:
    print(tmm//2 +1)
Buggy python submission (verdict: Time Limit Exceeded):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
alis = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
while True:
    if np.all(alis== 0):
        break
    c = (alis % 2 == 0)
    b[count] = sum(c)
    count += 1
    alis //= 2
mod = 10 ** 9 + 7
ans = 0
for i in range(61):
    tmp = (1<<i) % mod
    k = (b[i] * (n-b[i]))  % mod
    k = k*tmp % mod
    ans += k
    ans %= mod
print(ans)



Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
A = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
ans = 0
MOD = 10**9 + 7
while A.any():
    one = np.count_nonzero(A & 1)
    k = (1<<count) % MOD
    #ans += (one * (n - one) * pow(2, count, MOD)) % MOD
    ans += (one * (n - one)) * k % MOD
    ans %= MOD
    A >>= 1
    count += 1
 
print(ans)

Buggy python submission (verdict: Runtime Error):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
alis = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
while True:
    if np.all(alis== 0):
        break
    c = (alis % 2 == 0)
    b[count] = sum(c)
    count += 1
    alis //= 2
mod = 10 ** 9 + 7
ans = 0
for i in range(61):
    tmp = (1<<i) % mod
    k = (b[i] * (n-b[i]))  % mod
    k = k*tmp % mod
    ans += k
    ans %= mod
print(ans)


Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
A = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
ans = 0
MOD = 10**9 + 7
while A.any():
    one = np.count_nonzero(A & 1)
    k = (1<<count) % MOD
    #ans += (one * (n - one) * pow(2, count, MOD)) % MOD
    ans += (one * (n - one)) * k % MOD
    ans %= MOD
    A >>= 1
    count += 1
 
print(ans)

Buggy python submission (verdict: Runtime Error):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
alis = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
while True:
    if np.all(alis== 0):
        break
    c = (alis % 2 == 0)
    b[count] = sum(c)
    count += 1
    alis //= 2
mod = 10 ** 9 + 7
ans = 0
for i in range(61):
    tmp = (1<<i) % mod
    k = (b[i] * (n-b[i]))  % mod
    k = k*tmp % mod
    ans += k
    ans %= mod
print(ans)


Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
A = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
ans = 0
MOD = 10**9 + 7
while A.any():
    one = np.count_nonzero(A & 1)
    k = (1<<count) % MOD
    #ans += (one * (n - one) * pow(2, count, MOD)) % MOD
    ans += (one * (n - one)) * k % MOD
    ans %= MOD
    A >>= 1
    count += 1
 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

import bisect
n = int(input())
L = list(map(int,input().split()))
L.sort()
goukei = []
for i in range(n-1):
    for j in range(i+1,n):
        tmp = L[i] + L[j]
        tm = [tmp,j]
        goukei.append(tm)
ans = 0
for i in range(len(goukei)):
    ans+=  bisect.bisect_left(L[goukei[i][1]+1:],goukei[i][0])

print(ans)


Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n = ii()
l = li()

l.sort()
from bisect import bisect_left as bl

ans = 0
for i in reversed(range(2,n)):
    for k in range(1 ,i):
        ng = l[i] - l[k] + 1
        tmp = bl(l[:k],ng)
        ans += max(0,k-tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
print((n-1)*n//2)

Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()

print(n*(n-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
if N == 1:
    print(ans)
else:
    for i in range(N-1):
        ans += i+1
    print(ans)


Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()

print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
#E
from collections import deque
n = int(input())
matches = [list(a -1 for a in map(int,input().split()))
     for _ in range(N)]
q = deque(range(n))
depth = [0] * n
waiting = [-1] * n

while q:
    a = q.popleft()
    ma = matches[a]
    if not ma:
        continue
    # gyaku kara kanngaeteru
    b = ma.pop()
    if waiting[b] == a:
        depth[a] = depth[b] = max(depth[a],depth[b]) +1
        q.append(a)
        q.append(b)
    else:
        waiting[a] = b
if any(matches):
    print(-1)
else:
    print(max(depth))

Fixed submission:
#E
from collections import deque
n = int(input())
matches = [list(a -1 for a in map(int,input().split()))
     for _ in range(n)]
q = deque(range(n))
depth = [0] * n
waiting = [-1] * n

while q:
    a = q.popleft()
    ma = matches[a]
    if not ma:
        continue
    # gyaku kara kanngaeteru
    b = ma.pop()
    if waiting[b] == a:
        depth[a] = depth[b] = max(depth[a],depth[b]) +1
        q.append(a)
        q.append(b)
    else:
        waiting[a] = b
if any(matches):
    print(-1)
else:
    print(max(depth))
Buggy python submission (verdict: Runtime Error):
from heapq import heappop,heappush
from collections import defaultdict
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab_sort = sorted(ab,key=lambda x:x[0])
h_queue = []
j = 0
ans = 0
for i in range(1,m+1):
    while (j < n) and (ab_sort[j] <= i):
        heappush(h_queue,ab_sort[j])
        j += 1
    if len(h_queue):
        ans -= heappop(h_queue)
print(ans)



Fixed submission:
from heapq import heappop,heappush
from collections import defaultdict

n,m = map(int,input().split())
data = defaultdict(list)
for _ in range(n):
    a,b = map(int,input().split())
    data[a].append(b)

ans = 0
h_queue =[]
for i in range(1,m+1):
    for j in data[i]:
        heappush(h_queue,-j)
    if len(h_queue) > 0:
        ans -= heappop(h_queue)

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

count = 0
for i in range(N):
    if V[i] > C[i]:
        count += V[i] - C[i]

print (count)

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

N = T // A
print(N*B)
Buggy python submission (verdict: Runtime Error):
N = int(input().split())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

count = 0
for i in range(N):
    if V[i] > C[i]:
        count += V[i] - C[i]

print (count)

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

count = 0
for i in range(N):
    if V[i] > C[i]:
        count += V[i] - C[i]

print (count)
Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(5)]
k = int(input())

if (a[-1] - a[0] =< k ):
    print("Yay!")
else:
    print(":(")

Fixed submission:
#A
a = [int(input()) for i in range(5)]
k = int(input())

if (a[-1] - a[0] <= k ):
    print("Yay!")
else:
    print(":(")

Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(5)]
k = int(input())

if a[-1] - a[0] =< k:
    print("Yay!")
else:
    print(":(")

Fixed submission:
#A
a = [int(input()) for i in range(5)]
k = int(input())

if (a[-1] - a[0] <= k ):
    print("Yay!")
else:
    print(":(")
Buggy python submission (verdict: Runtime Error):
N,Q = list(map(int,input().split()))
S = input()
L = []
R = []
for i in range(Q):
    a = list(map(int,input().split()))
    L.append(a[0])
    R.append(a[1])

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
        A_flag = False
    else:
        if S[i] == "A" :
            A_flag = True
        else:
            A_flag = False
    S_count.append(count)

for i in range(Q):
    print(S_count[R[i] - 1] - S_count[L[i] - 1])

Fixed submission:
b = input()
if b == "A":
    print("T")
elif b == "T":
    print("A")
elif b == "C":
    print("G")
else:
    print("C")
Buggy python submission (verdict: Runtime Error):
N,Q = list(map(int,input().split()))
S = input()
L = []
R = []
for i in range(Q):
    a = list(map(int,input().split()))
    L.append(a[0])
    R.append(a[1])

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
    else:
        if S[i] == "A" :
            A_flag = True
        else:
            A_flag = False
    S_count.append(count)

for i in range(Q):
    print(S_count[R[i]] - S_count[L[i]])

Fixed submission:
#c
N,Q = list(map(int,input().split()))
S = input()
L = []
R = []
for i in range(Q):
    a = list(map(int,input().split()))
    L.append(a[0])
    R.append(a[1])

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
   
    if S[i] == "A" :
        A_flag = True
    else:
        A_flag = False
    S_count.append(count)

for i in range(Q):
    print(S_count[R[i] - 1] - S_count[L[i] - 1])

Buggy python submission (verdict: Runtime Error):
#c
N,Q = list(map(int,input().split()))
S = input()
L = []
R = []
for i in range(Q):
    a = list(map(int,input().split()))
    L.append(a[0])
    R.append(a[1])

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
    else:
        if S[i] == "A" :
            A_flag = True
        else:
            A_flag = False
    S_count = count

for i in range(Q):
    print(S_count[R[i]] - S_count[L[i]])

Fixed submission:
#c
N,Q = list(map(int,input().split()))
S = input()
L = []
R = []
for i in range(Q):
    a = list(map(int,input().split()))
    L.append(a[0])
    R.append(a[1])

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
   
    if S[i] == "A" :
        A_flag = True
    else:
        A_flag = False
    S_count.append(count)

for i in range(Q):
    print(S_count[R[i] - 1] - S_count[L[i] - 1])

Buggy python submission (verdict: Runtime Error):
N,Q = list(map(int,input().split()))
S = input()
L = []
R = []
for i in range(Q):
    a = list(map(int,input().split()))
    L.append(a[0])
    R.append(a[1])

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
    else:
        if S[i] == "A" :
            A_flag = True
        else:
            A_flag = False
    S_count = count

for i in range(Q):
    print(S[R[i]] - S[L[i]])

Fixed submission:
#c
N,Q = list(map(int,input().split()))
S = input()
L = []
R = []
for i in range(Q):
    a = list(map(int,input().split()))
    L.append(a[0])
    R.append(a[1])

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
   
    if S[i] == "A" :
        A_flag = True
    else:
        A_flag = False
    S_count.append(count)

for i in range(Q):
    print(S_count[R[i] - 1] - S_count[L[i] - 1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print("Hello World")
else :
    A , B = int(input())
    print(A+B)

Fixed submission:
N = int(input())
if N == 1:
    print("Hello World")
else :
    A  = int(input())
    B = int(input())
    print(A+B)

Buggy python submission (verdict: Runtime Error):
N = int(input)
if N == 1:
    print("Hello World")
else :
    A , B = int(input)
    print(A+B)

Fixed submission:
N = int(input())
if N == 1:
    print("Hello World")
else :
    A  = int(input())
    B = int(input())
    print(A+B)
Buggy python submission (verdict: Runtime Error):
a = int(input()))
b = int(a /100)
if a > (100b + 10b +b -1):
    print(100(b+1) + 10(b+1) +b +1)
else:
    print(100b + 10b + b)

Fixed submission:
a = int(input())
b = int(a /100)
if a > (100*b + 10*b +b ):
    print(100*(b+1) + 10*(b+1) +b +1)
else:
    print(100*b + 10*b + b)
Buggy python submission (verdict: Runtime Error):
n, m, X,Y = map(int,input().split())
x = list(int(i) for i in input().split())
y = list(int(i) for i in input().split())

x.sort()
y.sort()

if x[-1] < Y and y[0] >X and x[-1] < y[0]:
    print("No War")
else:
    print("War")

Fixed submission:
a = list(int(i) for i in input().split())
a.sort()
print(10*a[2]+a[1] + a[0])
Buggy python submission (verdict: Runtime Error):
N = int(input().split())
a = []
flag = 1
for i in range(N):
    a.append(str(input().split()))
    if i != 0:
        for j in range(i):
            if a[i] == a[j]:
                flag =0


back = a[0][-1]
for i in range(1,N):
    front = a[i][0]
    if front != back:
        flag = 0
        break
    back = a[i][-1]

if flag == 0:
    print("No") 
else:
    print("Yes")

Fixed submission:
N = int(input())
a = []
flag = 1
for i in range(N):
    a.append(str(input()))
    if i != 0:
        for j in range(i):
            if a[i] == a[j]:
                flag =0


back = a[0][-1]
for i in range(1,N):
    front = a[i][0]
    if front != back:
        flag = 0
        break
    back = a[i][-1]

if flag == 0:
    print("No") 
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
#3_1_1
import bisect
n = int(input())
a = list(map(int,input().split))
b = list(map(int,input().split))
c = list(map(int,input().split))

a.sort()
c.sort()
ans = 0
for i in range(n):
    ue = bisect.bisect_left(a,b[i])
    sita = bisect.bisect_right(c,b[i])
    ans += ue * sita
print(ans)

Fixed submission:
#3_1_1
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
c.sort()
ans = 0
for i in range(n):
    ue = bisect.bisect_left(a,b[i])
    sita = n - bisect.bisect_right(c,b[i])
    ans += ue * sita
print(ans)
Buggy python submission (verdict: Runtime Error):
def dfs(v,N,visit_list):

    all_visit = True

    for i in range(N):
        if visit_list[i] == False:
            all_visit = False
    
    if all_visit:
        return 1

    ret = 0

    for k in range(N):
        if Graph[v][k] == False:
            continue
        if visit_list[k] :
            continue
        
        visit_list[k] = True
        ret += dfs(k,N,visit_list)
        visit_list[k] = False
    return ret

visit_list = [False for i in range(N)]
visit_list[0] = True
print(dfs(0,N,visit_list))
    



Fixed submission:
N,M = map(int,input().split())
pat = [[int(i) for i in input().split()] for _ in range(M)]
Graph = [[0 for i in range(N)] for _ in range(N)]
for i,j in pat:
    Graph[i-1][j-1] = 1
    Graph[j-1][i-1] = 1

def dfs(v,N,visit_list):

    all_visit = True

    for i in range(N):
        if visit_list[i] == False:
            all_visit = False
    
    if all_visit:
        return 1

    ret = 0

    for k in range(N):
        if Graph[v][k] == False:
            continue
        if visit_list[k] :
            continue
        
        visit_list[k] = True
        ret += dfs(k,N,visit_list)
        visit_list[k] = False
    return ret

visit_list = [False for i in range(N)]
visit_list[0] = True
print(dfs(0,N,visit_list))

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
pat = [[int(i) for i in input().split()] for _ in range(M)]
Graph = [[0 for i in range(N)] for _ in range(N)]
for i,j in pat:
    Graph[i-1][j-1] = 1
    Graph[j-1][i-1] = 1

def dfs(v,N=N,visit_list):

    all_visit = True

    for i in range(N):
        if visit_list[i] == False:
            all_visit = False
    
    if all_visit:
        return 1

    ret = 0

    for k in range(N):
        if Graph[v][k] == False:
            continue
        if visit_list[k] :
            continue
        
        visit_list[k] = True
        ret += dfs(k,N,visit_list)
        visit_list[k] = False
    return ret

visit_list = [False for i in range(N)]
visit_list[0] = True
print(dfs(0,N,visit_list))
    



Fixed submission:
N,M = map(int,input().split())
pat = [[int(i) for i in input().split()] for _ in range(M)]
Graph = [[0 for i in range(N)] for _ in range(N)]
for i,j in pat:
    Graph[i-1][j-1] = 1
    Graph[j-1][i-1] = 1

def dfs(v,N,visit_list):

    all_visit = True

    for i in range(N):
        if visit_list[i] == False:
            all_visit = False
    
    if all_visit:
        return 1

    ret = 0

    for k in range(N):
        if Graph[v][k] == False:
            continue
        if visit_list[k] :
            continue
        
        visit_list[k] = True
        ret += dfs(k,N,visit_list)
        visit_list[k] = False
    return ret

visit_list = [False for i in range(N)]
visit_list[0] = True
print(dfs(0,N,visit_list))
Buggy python submission (verdict: Runtime Error):
from itertools import product
S = input()
ans = 0

for string in product(["","+"],repeat=len(S) - 1):
    string = list(string)
    string.append("")
    sum_ = [a + b for a,b in zip(S,string)]
    ans += sum_

print(ans)

Fixed submission:
from itertools import product
S = input()
ans = 0

for string in product(["","+"],repeat=len(S) - 1):
    string = list(string)
    string.append("")
    sum_ = [a + b for a,b in zip(S,string)]
    ans += eval("".join(sum_))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = tuple([int(e) for e in input().split()])
    arr = [0] + [int(e) for e in input().split()]

    seen = set()
    actual = 1
    seen.add(1)
    while k > 0:
        actual = arr[actual]
        k -= 1
        if actual in seen:
            break
        seen.add(actual)

    c = 1
    ac = arr[actual]
    while actual != ac:
        ac = arr[ac]
        c += 1

    k = k % c
    while k > 0:
        actual = arr[actual]
        k -= 1
    print(actual)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n, k = tuple([int(e) for e in input().split()])
    arr = [0] + [int(e) for e in input().split()]

    seen = set()
    actual = 1
    seen.add(1)
    pos = [1]
    mp = {1:1}
    while k > 0:
        actual = arr[actual]
        k -= 1
        if actual in seen:
            break
        seen.add(actual)
        pos.append(actual)
        mp[actual] = len(pos)

    c = 1 + len(pos) - mp[actual]
    k = k % c
    print(pos[mp[actual] + k - 1])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())

st = set()
for i in range(n):
  set.add(input())
  
print(len(st))

Fixed submission:
n = int(input())

st = set()
for i in range(n):
  st.add(input())
  
print(len(st))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 6)

def find(idx, c, arr, tb):

    if c == 0:
        return 0

    if idx <= 0:
        return -100000

    if (idx, c) in tb:
        return tb[(idx, c)]

    rs = find(idx - 2, c - 1, arr, tb) + arr[idx - 1]
    rs = max(rs, find(idx - 1, c, arr, tb))

    tb[(idx, c)] = rs
    return rs


def main():

    n = int(input())
    arr = [int(e) for e in input().split(' ')]
    print(find(n, n // 2, arr, {}))
    return 0


main()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)

def find(idx, c, arr, tb):

    if c == 0:
        return 0

    if idx <= 0 or idx < 2 * c - 1:
        return float('-inf')

    if (idx, c) in tb:
        return tb[(idx, c)]

    rs = find(idx - 2, c - 1, arr, tb) + arr[idx - 1]
    rs = max(rs, find(idx - 1, c, arr, tb))

    tb[(idx, c)] = rs
    return rs

def main():

    n = int(input())
    arr = [int(e) for e in input().split(' ')]
    print(find(n, n // 2, arr, {}))
    return 0


main()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- Coding: utf-8 -*-

S = input()
length = len(S)
ans = 0

l=0
while l+2 < length:
  s = S[l:l+3]
  if s == "ABC":
    ans += 1
    S = S[:l] + "BCA" + S[l+3:]
    l -= 1
  else:
    if s[2] == "A":
      l += 2
    elif s[2] == "B":
      l += 1
    else:
      l += 3

  l = max(0, l)

print(ans)


Fixed submission:
S = input()
S = S.replace('BC', 'D')
length = len(S)

ans = 0
count_a = 0
for i in range(length):
  c = S[i]

  if c == 'A':
    count_a += 1
  elif c == 'D':
    ans += count_a
  else:
    count_a = 0

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

S = input()
length = len(S)
ans = 0
l=0
while l+2 < length:
  s = S[l:l+3]
  if s == "ABC":
    ans += 1
    S = S[:l] + "BCA" + S[l+3:]
    l -= 2
  else:
    l += 1

  l = max(0, l)

print(ans)

Fixed submission:
S = input()
S = S.replace('BC', 'D')
length = len(S)

ans = 0
count_a = 0
for i in range(length):
  c = S[i]

  if c == 'A':
    count_a += 1
  elif c == 'D':
    ans += count_a
  else:
    count_a = 0

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

def MAP():
    return map(int, input().split())

a,b=MAP()

t=1
cnt=0
while True:
    if b <= t:
        break
    t -= 1
    t += a
    cnt += 1
print(cnt)

Fixed submission:
s=input()
t=input()

cnt=0
for i in range(3):
    if s[i] == t[i]:
        cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
seki = 0
for m in range(1, M + 1):
    for d in range(1, D + 1):
        d10, d1 = divmod(d, 10)
        if d10 >= 2 and d1 >= 2 and d10 * d1 == m:
            seki += 1
print(seki)

Fixed submission:
M,D=map(int, input().split())

seki=0
for m in range(1,M+1):
    for d in range(1,D+1):
        str_d = str(d)
        if len(str_d)==2:
            d10 = int(str_d[0])
            d1  = int(str_d[1])
            if d10 >= 2 and d1 >= 2 and d10*d1 == m:
                seki+=1
print(seki)