Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import copy

N = int(input())

x_list = []
for i in range(N):
    x = int(input())
    x_list.append(x)

for i in range(len(x_list)):
    tmp_list = copy.deepcopy(x_list)
    tmp_list.pop(i)
    print(max(tmp_list))

Fixed submission:
import copy

N = int(input())

x_list = []
for i in range(N):
    x = int(input())
    x_list.append(x)

max_value = max(x_list)

get_index = x_list.index(max(x_list))

tmp_list = copy.deepcopy(x_list)
tmp_list.pop(get_index)
without_max_value = max(tmp_list)

for i in range(len(x_list)):
    if i != get_index:
        print(max_value)
    else:
        print(without_max_value)
Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))

s_list = []
a = []
for i in range(M):
    s = list(map(int, input().split()))
    k = s[0]
    for j in range(1, k):
        a[s[j] - 1] |= 1 << i

p = list(map(int, input().split()))

p = 0
for i, x in enumerate(p):
    p |= x << i

ans = 0
for s in range(1 << N):
    t = 0
    for i in range(N):
        if s >> i & 1:
            t ^= a[i]
    if t == p:
        ans += 1

print(ans)

Fixed submission:
t = input().rstrip().split(' ')
switch = int(t[0])
lamp = int(t[1])
s = [list(map(int, input().split())) for _ in range(lamp)]
p = list(map(int, input().split()))
ans = 0

for i in range(2 ** switch):
    ptn = bin(i)[2:].rjust(switch, '0')
    light = True
    for j in range(lamp):
        temp = 0
        for n in range(1, s[j][0] + 1):
            if ptn[s[j][n] - 1] == '1':
                temp += 1
        if temp % 2 != p[j] % 2:
            light = False
    if light:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, K = list(map(int, input().split()))


def cf(x1, x2):
    cf = []
    for i in range(2, min(x1, x2) + 1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)

    cf = sorted(cf)
    return cf

cf_list = cf(A, B)

if len(cf_list) == 0:
    print(1)
else:
    print(cf_list[-K])

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

for i in range(min(A, B), 0, -1):
    if A % i == 0 and B % i == 0:
        count += 1
    if count == K:
        print(i)
        exit()
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())

a_b_c_list = []

for i in range(N):
    a_b_c_list.append(list(map(int, input().split())))

dp = [[0 for i in range(3)] for j in range(100)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            if dp[i+1][k] < dp[i][j] + a_b_c_list[i][k]:
                dp[i+1][k] = dp[i][j] + a_b_c_list[i][k]

print(max(dp[N]))

Fixed submission:
N = int(input())

a_b_c_list = []

for i in range(N):
    a_b_c_list.append(list(map(int, input().split())))

dp = [[0 for i in range(3)] for j in range(100010)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            if dp[i+1][k] < dp[i][j] + a_b_c_list[i][k]:
                dp[i+1][k] = dp[i][j] + a_b_c_list[i][k]

print(max(dp[N]))
Buggy python submission (verdict: Runtime Error):
N, a, b = map(int, input.split()) 

sum = 0
for x in N:
  l = [int(y) for y in list(str(x))]
  temp_sum = 0
  for z in l:
    tmep_sum += z
  if a <= temp_sum and b <= temp_sum:
      sum += x
print(sum)

Fixed submission:
# -*- coding: utf-8 -*-
N, a, b = map(int, input().split()) 
 
sum = 0
for x in range(N + 1):
  l = [int(y) for y in list(str(x))]
  temp_sum = 0
  for z in l:
    temp_sum += z
  if a <= temp_sum and b >= temp_sum:
     sum += x
print(sum)
Buggy python submission (verdict: Runtime Error):
a = []
for j in range(3):
    a.append([int(x) for x in input().split()])
n = int(input())
b = [int(input()) for i in range(n)]
def hasbingo(ps):
    for x, y in ps:
        if a[y][x] not in b:
            return False
    return True

def hasany():
    for i in range(3):
        if hasbingo([(i, 0),(i, 1),(i, 2)]):
            return True
        if hasbingo([(0, i), (1, i), (2, i)]):
            return True
    if hasbingo([[0,0],[1,1],[2,2]]):
        return True
    return hasbingo([[0,2],[1,1][2,0]])

if hasany():
    print('Yes')
else:
    print('No')



Fixed submission:
a = []
for j in range(3):
    a.append([int(x) for x in input().split()])
n = int(input())
b = [int(input()) for i in range(n)]
def hasbingo(ps):
    for x, y in ps:
        if a[y][x] not in b:
            return False
    return True

def hasany():
    for i in range(3):
        if hasbingo([(i, 0),(i, 1),(i, 2)]):
            return True
        if hasbingo([(0, i), (1, i), (2, i)]):
            return True
    if hasbingo([(0,0),(1,1),(2,2)]):
        return True
    return hasbingo([(0,2),(1,1), (2,0)])

if hasany():
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
File Edit Options Buffers Tools Python Help                                             
n, m = [int(x) for x in input().split()]
sc = [[int(x) for x in input().split()] for i in range(m)]
r = [-1] * n
def solution():
    for s, c in sc:
        if r[s - 1] >= 0 and r[s - 1] != c or (s == 1 and c == 0 and n != 1):
            return '-1'
        r[s - 1] = c
    for i in range(n):
        if r[i] < 0:
            if i == 0:
                r[i] = 1
            else:
                r[i] = 0
    return ''.join(str(r[i]) for i in range(n))

print(solution())

Fixed submission:
n, m = [int(x) for x in input().split()]
sc = [[int(x) for x in input().split()] for i in range(m)]
r = [-1] * n
def solution():
    for s, c in sc:
        if s == 1 and c == 0 and n != 1:
            return '-1'
        if r[s - 1] >= 0 and r[s - 1] != c:
            return '-1'
        r[s - 1] = c
    for i in range(n):
        if r[i] < 0:
            if i == 0 and n != 1:
                r[i] = 1
            else:
                r[i] = 0
    return ''.join(str(r[i]) for i in range(n))

print(solution())
Buggy python submission (verdict: Runtime Error):
, m, k = [int(x) for x in input().split()]
fr = [i for i in range(n)]
dfr = [[] for i in range(n)]
bl = [[] for i in range(n)]
def deref(a):
    s = []
    while True:
        next = fr[a]
        if next == a:
            break
        s.append(a)
        a = next
    for i in s:
        fr[i] = a
    return a

def merge(a, b):
    #print('merge(',a,b)                                                                
    ra, rb = deref(a), deref(b)
    fr[rb] = ra

for i in range(m):
    a, b = [int(x) - 1 for x in input().split()]
    dfr[a].append(b)
    dfr[b].append(a)
    a, b = min(a, b), max(a, b)
    merge(a, b)
for i in range(n):
    deref(i)
#print(dfr)                                                                             
#print(fr)                                                                              
ss = [[] for i in range(n)]
for i in range(n):
    ss[fr[i]].append(i)
for i in range(k):
    c, d = [int(x) - 1 for x in input().split()]
    bl[c].append(d)
    bl[d].append(c)
    for i in range(n):
    bl[i].sort()
r = []
for i in range(n):
    v = len(ss[fr[i]]) - len(dfr[i]) - 1
    v -= sum(fr[j] == fr[i] for j in bl[i])
    r.append(v)
print(' '.join(str(x) for x in r))



Fixed submission:
n, m, k = [int(x) for x in input().split()]
fr = [i for i in range(n)]
dfr = [[] for i in range(n)]
bl = [[] for i in range(n)]
def deref(a):
    s = []
    while True:
        next = fr[a]
        if next == a:
            break
        s.append(a)
        a = next
    for i in s:
        fr[i] = a
    return a
def merge(a, b):
    ra, rb = deref(a), deref(b)
    fr[rb] = ra
for i in range(m):
    a, b = [int(x) - 1 for x in input().split()]
    dfr[a].append(b)
    dfr[b].append(a)
    a, b = min(a, b), max(a, b)
    merge(a, b)
for i in range(n):
    deref(i)
ss = [[] for i in range(n)]
for i in range(n):
    ss[fr[i]].append(i)
for i in range(k):
    c, d = [int(x) - 1 for x in input().split()]
    bl[c].append(d)
    bl[d].append(c)
for i in range(n):
    bl[i].sort()
r = []
for i in range(n):
    v = len(ss[fr[i]]) - len(dfr[i]) - 1
    v -= sum(fr[j] == fr[i] for j in bl[i])
    r.append(v)
print(' '.join(str(x) for x in r))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
s = 0
for i in range(1, k+1):
  for j in range(1, k+1):
    for k in range(1, k+1):
      s += gcd(i, j, k)
print(s)

Fixed submission:
import itertools
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
l = list(range(1, k+1))                                                
s = 0

for i in itertools.product(l, repeat=3):
  s += gcd(*i)
print(s)
Buggy python submission (verdict: Runtime Error):
n = int(input)

print(round(n/2))

Fixed submission:
n = int(input())
 
if n % 2 == 1:
  print(int((n+1)/2))
else:
  print(int(n/2))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))

c = 1
for i in range(n):
  if(i != 0 and sum(map(lambda x: p[i] <= x, p[:i])) == i):
    c += 1  
print(c)

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

MIN = 10e5
c = 0
for i in range(n):
  if p[i] <= MIN:
    MIN = p[i]
    c += 1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))

ok = 0
ng = 0
ng_tmp = [0] * n
ok_l = []

for i in range(m):
  tmp = input().split()
  p = int(tmp[0])
  s = tmp[1]
  if ok_l.count(p) == 0:
    if s == 'AC':
      ok_l.append(p)
      ok += 1
      ng += ng_tmp[p-1]
    if s == 'WA':
      ng_tmp[p-1] += 1

  
print(ok, ng)

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

ok = 0
ng = 0
ng_tmp = [0] * n
flag = [True] * n

for i in range(m):
  tmp = input().split()
  p = int(tmp[0])
  s = tmp[1]
  if flag[p-1]:
    if s == 'AC':
      flag[p-1] = False
      ok += 1
      ng += ng_tmp[p-1]
    if s == 'WA':
      ng_tmp[p-1] += 1

  
print(ok, ng)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))

ok = 0
ng = 0
ng_tmp = [0] * n
ok_l = []

for i in range(m):
  tmp = input().split()
  p = int(tmp[0])
  s = tmp[1]
  if ok_l.count(p) == 0:
    if s == 'AC':
      ok_l.append(p)
      ok += 1
      ng += ng_tmp[p-1]
    if s == 'WA':
      ng_tmp[p-1] += 1

  
print(ok, ng)

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

ok = 0
ng = 0
ng_tmp = [0] * n
flag = [True] * n

for i in range(m):
  tmp = input().split()
  p = int(tmp[0])
  s = tmp[1]
  if flag[p-1]:
    if s == 'AC':
      flag[p-1] = False
      ok += 1
      ng += ng_tmp[p-1]
    if s == 'WA':
      ng_tmp[p-1] += 1

  
print(ok, ng)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

if(1 in a == False):
  print(-1)
  exit()
if(a == list(map(lambda x: x+1, range(len(a))))):
  print(0)
  exit()

count = 0
for i in range(n):
  if(i+1 in a == False):
    break
  if(i < len(a)):
    while(len(a) > i and a[i] != i+1):
      a.pop(i)
      count += 1
 
if count == 0 or len(a) == 0:
  print(-1)
else:
  print(count)

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

c = 0
for i in range(n):
  if a[i] == c + 1:
    c += 1
if c == 0:
  print(-1)
else:
  print(n - c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

if(1 in a == False):
  print(-1)
  exit()
if(a == list(map(lambda x: x+1, range(len(a))))):
  print(0)
  exit()

count = 0
for i in range(n):
  if(i < len(a)):
    while(len(a) > i and a[i] != i+1):
      a.pop(i)
      count += 1
 
if count == 0 or len(a) == 0:
  print(-1)
else:
  print(count)

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

c = 0
for i in range(n):
  if a[i] == c + 1:
    c += 1
if c == 0:
  print(-1)
else:
  print(n - c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

if(1 in a == False):
  print(-1)
  exit()
if(a == list(map(lambda x: x+1, range(len(a))))):
  print(0)
  exit()

count = 0
for i in range(n):
  if(i < len(a)):
    while(len(a) > i and a[i] != i+1):
      a.pop(i)
      count += 1
 
if count == 0 or len(a) == 0:
  print(-1)
else:
  print(count)

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

c = 0
for i in range(n):
  if a[i] == c + 1:
    c += 1
if c == 0:
  print(-1)
else:
  print(n - c)
Buggy python submission (verdict: Time Limit Exceeded):
x=input().split()
h=int(x[0])
w=int(x[1])
d=int(x[2])
grid=[[]*w for i in range(h)]
for i in range(h):
    y=input().split()
    x=0
    while x<w:
        y[x]=int(y[x])
        x=x+1
    grid[i]=y
coor=[[]*2 for i in range(h*w)]
for i in range(h):
    for j in range(w):
        coor[grid[i][j]-1]=[i,j]
q=int(input())
for ii in range(q):
    x=input().split()
    l=int(x[0])
    r=int(x[1])
    cost=0
    while l!=r:
        cost+=abs(coor[l+d-1][0]-coor[l-1][0])+abs(coor[l+d-1][1]-coor[l-1][1])
        l+=d
    print(cost)

Fixed submission:
x=input().split()
h=int(x[0])
w=int(x[1])
d=int(x[2])
grid=[[]*w for i in range(h)]
for i in range(h):
    y=input().split()
    x=0
    while x<w:
        y[x]=int(y[x])
        x=x+1
    grid[i]=y
coor=[[]*2 for i in range(h*w)]
for i in range(h):
    for j in range(w):
        coor[grid[i][j]-1]=[i,j]
cost=[0*i for i in range(h*w-d)]
for i in range(h*w-d):
    cost[i]=abs(coor[i+d][0]-coor[i][0])+abs(coor[i+d][1]-coor[i][1])
ans=[0*i for i in range(h*w)]
for i in range(d,h*w):
    ans[i]=ans[i-d]+cost[i-d]
q=int(input())
for ii in range(q):
    x=input().split()
    l=int(x[0])
    r=int(x[1])
    print(ans[r-1]-ans[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
x=input().split()
h=int(x[0])
w=int(x[1])
d=int(x[2])
grid=[[]*w for i in range(h)]
for i in range(h):
    y=input().split()
    x=0
    while x<w:
        y[x]=int(y[x])
        x=x+1
    grid[i].extend(y)
coor=[[]*2 for i in range(h*w)]
for i in range(h):
    for j in range(w):
        coor[grid[i][j]-1].append(i)
        coor[grid[i][j]-1].append(j)
q=int(input())
for ii in range(q):
    x=input().split()
    l=int(x[0])
    r=int(x[1])
    cost=0
    while l!=r:
        cost+=abs(coor[l+d-1][0]-coor[l-1][0])+abs(coor[l+d-1][1]-coor[l-1][1])
        l+=d
    print(cost)

Fixed submission:
x=input().split()
h=int(x[0])
w=int(x[1])
d=int(x[2])
grid=[[]*w for i in range(h)]
for i in range(h):
    y=input().split()
    x=0
    while x<w:
        y[x]=int(y[x])
        x=x+1
    grid[i]=y
coor=[[]*2 for i in range(h*w)]
for i in range(h):
    for j in range(w):
        coor[grid[i][j]-1]=[i,j]
cost=[0*i for i in range(h*w-d)]
for i in range(h*w-d):
    cost[i]=abs(coor[i+d][0]-coor[i][0])+abs(coor[i+d][1]-coor[i][1])
ans=[0*i for i in range(h*w)]
for i in range(d,h*w):
    ans[i]=ans[i-d]+cost[i-d]
q=int(input())
for ii in range(q):
    x=input().split()
    l=int(x[0])
    r=int(x[1])
    print(ans[r-1]-ans[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
count=0
li=[0 for i in range(n)]
for i in range(n):
    a=int(input())
    li[i]=a
li.sort()
i=0
while i<n:
    x=li.count(li[i])
    if x%2==1:
        count+=1
    i+=x
print(count)

Fixed submission:
n=int(input())
count=0
li=[0 for i in range(n)]
for i in range(n):
    a=int(input())
    li[i]=a
li.sort()
i=0
x=1
while i<n-1:
    if li[i]==li[i+1]:
        x+=1
        if i+2==n-1:
            count+=1
    else:
        x=1
        if i+1==n-1:
            count+=1
    if x%2==1:
        count+=1
    i+=x
    x=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
count=0
li=[0 for i in range(n)]
for i in range(n):
    a=int(input())
    li[i]=a
li.sort()
while len(li)!=0:
    x=li.count(li[0])
    if x%2==1:
        count+=1
    li=li[x:]
print(count)

Fixed submission:
n=int(input())
count=0
li=[0 for i in range(n)]
for i in range(n):
    a=int(input())
    li[i]=a
li.sort()
i=0
x=1
while i<n-1:
    if li[i]==li[i+1]:
        x+=1
        if i+2==n-1:
            count+=1
    else:
        x=1
        if i+1==n-1:
            count+=1
    if x%2==1:
        count+=1
    i+=x
    x=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
count=0
li=[]
for i in range(n):
    a=int(input())
    if a in li:
        li.remove(a)
        count-=1
    else:
        li.append(a)
        count+=1
print(count)

Fixed submission:
n=int(input())
count=0
li=[0 for i in range(n)]
for i in range(n):
    a=int(input())
    li[i]=a
li.sort()
i=0
x=1
while i<n-1:
    if li[i]==li[i+1]:
        x+=1
        if i+2==n-1:
            count+=1
    else:
        x=1
        if i+1==n-1:
            count+=1
    if x%2==1:
        count+=1
    i+=x
    x=1
print(count)
Buggy python submission (verdict: Runtime Error):
def ncr(x,y):
	ans=1
	q=x-y
	while x>y:
		ans*=x
		x=x-1
	
	while q>1:
		ans=ans/q
		q=q-1
	
	return ans

x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=[0]*n
x = input().split()
ind=0
M={1:0}
M2={1:0}
for i in x:
	v[ind]=int(i)
	if int(i) in M:
		M[v[ind]]+=1
	else:
		M[v[ind]]=1
	ind+=1
v.sort(reverse=True)

cnt=0
ind=0
m=0
while cnt<a:
	cnt+=1
	m=((cnt-1)*m+v[ind])/cnt
	if v[ind] in M2:
		M2[v[ind]]+=1
	else:
		M2[v[ind]]=1
	ind+=1
while cnt<b:
	if (cnt*m+v[ind])/(cnt+1)<m-0.5:
		break
	else:
		cnt+=1;
		if v[ind] in M2:
			M2[v[ind]]+=1
		else:
			M2[v[ind]]=1
		ind+=1
print(m)
maxw=cnt;
ways=0;
for i in range(cnt,a-1,-1):
	if v[ind-1] not in M2:
			M2[v[ind]]=0
	if v[ind-1] not in M:
			M[v[ind-1]]=0
	ways+=ncr(M[v[ind-1]],M2[v[ind-1]])
	
	M2[v[ind-1]]-=1

print(int(ways))
	

Fixed submission:
x=input().split()
ans=int(x[0])+int(x[1])
print(int(ans%24))
Buggy python submission (verdict: Runtime Error):
n=int(input())
f=[]
for i in range(1,int(n**0.5)):
    if n%i==0:
        f.append(i)
        f.append(int(n/i))
print(len(str(f[-1])))

Fixed submission:
n=int(input())
f=[]
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        f.append(i)
        f.append(int(n/i))
if n==1:
    print('1')
else:
    print(len(str(f[-1])))
Buggy python submission (verdict: Runtime Error):
#include <iostream>
using namespace std;

int main() {
    int a, b, c, q;
    cin >> a >> b >> c;
    q = b/a;
    if(q < c){
        cout << q << endl;
    }else{
        cout << c << endl;
    };
    return 0;
}

Fixed submission:
a = list(map(int, input().split()))
b = a[1]//a[0]
print(b if b < a[2] else a[2])

Buggy python submission (verdict: Runtime Error):
import fractions


def main():
    a = list(map(int, input().split()))
    b = fractions.gcd(a[0], a[1])
    c = b
    for i in range(a[2]-1):
        while True:
            c -= 1
            if b % c == 0:
                break
    print(c)


main()

Fixed submission:
a = list(map(int, input().split()))
b = a[1]//a[0]
print(b if b < a[2] else a[2])
Buggy python submission (verdict: Runtime Error):
import math


def main():
    a = list(map(int, input().split()))
    b = math.gcd(a[0], a[1])
    c = b
    for i in range(a[2]-1):
        while True:
            c -= 1
            if b % c == 0:
                break
    print(c)


main()

Fixed submission:
import fractions


def main():
    a = list(map(int, input().split()))
    b = fractions.gcd(a[0], a[1])
    c = b
    for i in range(a[2]-1):
        while True:
            c -= 1
            if b % c == 0:
                break
    print(c)


main()

Buggy python submission (verdict: Runtime Error):
import fraction


def main():
    a = list(map(int, input().split()))
    b = fraction.gcd(a[0], a[1])
    c = b
    for i in range(a[2]-1):
        while True:
            c -= 1
            if b % c == 0:
                break
    print(c)


main()

Fixed submission:
import fractions


def main():
    a = list(map(int, input().split()))
    b = fractions.gcd(a[0], a[1])
    c = b
    for i in range(a[2]-1):
        while True:
            c -= 1
            if b % c == 0:
                break
    print(c)


main()
Buggy python submission (verdict: Time Limit Exceeded):
a = input()
b = len(a)
while ('01' in a) or ('10' in a):
    a = a.replace('01', '').replace('10', '')
print(b - len(a))

Fixed submission:
a = input()
b = len(a)
print(b - abs(a.count('1')-a.count('0')))
Buggy python submission (verdict: Runtime Error):
import numpy as np


S = input()
dp = np.zeros((int(1e5+1), 4), dtype=np.int64)
i = 0
mod = 1e9+7
dp[0][0] = 1
for s in S:
    if s == '?':
        dp[i+1] = dp[i]*3 % mod
        dp[i+1][1:] += dp[i][:3]
        dp[i+1] = np.remainder(dp[i+1], mod)
    else:
        dp[i+1] = dp[i]
        if s == 'A':
            dp[i+1][1] += dp[i][0]
            dp[i+1][1] = np.remainder(dp[i+1][1], mod)
        elif s == 'B':
            dp[i+1][2] += dp[i][1]
            dp[i+1][2] = np.remainder(dp[i+1][2], mod)
        elif s == 'C':
            dp[i+1][3] += dp[i][2]
            dp[i+1][3] = np.remainder(dp[i+1][3], mod)
    i += 1
print(dp[len(S)][3])

Fixed submission:
import numpy as np


dp = np.zeros((2, 4), dtype=np.int64)
mod = 1e9+7
dp[0][0] = 1
for s in input():
    if s == '?':
        dp[1] = dp[0]*3
        dp[1][1:] += dp[0][:3]
        dp[1] = np.remainder(dp[1], mod)
    else:
        dp[1] = dp[0]
        if s == 'A':
            dp[1][1] += dp[0][0]
            dp[1][1] = np.remainder(dp[1][1], mod)
        elif s == 'B':
            dp[1][2] += dp[0][1]
            dp[1][2] = np.remainder(dp[1][2], mod)
        elif s == 'C':
            dp[1][3] += dp[0][2]
            dp[1][3] = np.remainder(dp[1][3], mod)
    dp[0] = dp[1]
print(dp[0][3])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


S = input()
dp = np.zeros((int(1e5+1), 4), dtype=np.int64)
i = 0
mod = 1e9+7
dp[0][0] = 1
for s in S:
    if s == '?':
        dp[i+1] = dp[i]*3 % mod
        dp[i+1][1:] += dp[i][:3]
        dp[i+1] = np.remainder(dp[i+1], mod)
    else:
        dp[i+1] = dp[i]
        if s == 'A':
            dp[i+1][1] += dp[i][0]
            dp[i+1][1] = np.remainder(dp[i+1][1], mod)
        elif s == 'B':
            dp[i+1][2] += dp[i][1]
            dp[i+1][2] = np.remainder(dp[i+1][2], mod)
        elif s == 'C':
            dp[i+1][3] += dp[i][2]
            dp[i+1][3] = np.remainder(dp[i+1][3], mod)
    i += 1
print(dp[len(S)][3])

Fixed submission:
import numpy as np


dp = np.zeros((2, 4), dtype=np.int64)
mod = 1e9+7
dp[0][0] = 1
for s in input():
    if s == '?':
        dp[1] = dp[0]*3
        dp[1][1:] += dp[0][:3]
        dp[1] = np.remainder(dp[1], mod)
    else:
        dp[1] = dp[0]
        if s == 'A':
            dp[1][1] += dp[0][0]
            dp[1][1] = np.remainder(dp[1][1], mod)
        elif s == 'B':
            dp[1][2] += dp[0][1]
            dp[1][2] = np.remainder(dp[1][2], mod)
        elif s == 'C':
            dp[1][3] += dp[0][2]
            dp[1][3] = np.remainder(dp[1][3], mod)
    dp[0] = dp[1]
print(dp[0][3])
Buggy python submission (verdict: Runtime Error):
from sympy import isprime
import math
n=int(input())
if (isprime(n))==True:
    print(int(n-1))
else:
    N=int(math.sqrt(n))
    for i in reversed(range(N)):
        if n%(i+1)==0:
            print(int((n/(i+1))+i-1))
            break

Fixed submission:
import math
n=int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
if is_prime(n)==True:
    print(int(n-1))
else:
    N=int(math.sqrt(n))
    for i in reversed(range(N)):
        if n%(i+1)==0:
            print(int((n/(i+1))+i-1))
            break
Buggy python submission (verdict: Runtime Error):
a,b= map(int, input().split())

if(c=a-b*2 >=0):
    print(c)
else:
    print(0)


Fixed submission:
a,b= map(int, input().split())
c=a-b*2
if(c>=0):
    print(c)
else:
    print(0)