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


def main():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

    @functools.lru_cache(maxsize=None)
    def solve(stock: int, money: int, day: int, end_day: int) -> int:
        if end_day == day:
            return money

        current_price = A[day]

        money_buy = money - (money // current_price) * current_price
        stock_buy = (money // current_price) + stock

        money_sell = money + stock * current_price
        stock_sell = 0

        return max(
            solve(stock, money, day + 1, end_day),
            solve(stock_buy, money_buy, day + 1, end_day),
            solve(stock_sell, money_sell, day + 1, end_day),
        )

    print(solve(0, 1000, 0, N))


if __name__ == "__main__":

    sys.setrecursionlimit(1024 * 1024 * 2)
    threading.stack_size(128 * 1024 * 1024 * 2)
    threading.Thread(target=main).start()


Fixed submission:
from typing import List


def solve(A: List[int], N: int) -> int:
    current_money = 1000
    for i in range(N - 1):
        stocks = 0

        if A[i] < A[i + 1]:
            stocks = current_money // A[i]
        current_money += (A[i + 1] - A[i]) * stocks
    return current_money


def main():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

    print(solve(A, N))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(input())
A = [int(x) for x in input().split(" ")]
product = 1
for a in A:
    product = product * a
if product > 10 ** 18:
    print(-1)
    sys.exit(0)

print(product)

Fixed submission:
import sys

N = int(input())
A = [int(x) for x in input().split(" ")]
if 0 in set(A):
    print(0)
    sys.exit(0)

product = 1
for a in A:
    product = product * a
    if product > 10 ** 18:
        print(-1)
        sys.exit(0)


print(product)

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

N = int(input())
A = [int(x) for x in input().split(" ")]
product = 1
for a in A:
    product = product * a
if product > 10 ** 18:
    print(-1)
    sys.exit(0)

print(product)


Fixed submission:
import sys

N = int(input())
A = [int(x) for x in input().split(" ")]
if 0 in set(A):
    print(0)
    sys.exit(0)

product = 1
for a in A:
    product = product * a
    if product > 10 ** 18:
        print(-1)
        sys.exit(0)


print(product)

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

N = int(input())
A = [int(x) for x in input().split(" ")]
product = 1
for a in A:
    product = product * a
if product > 10 ** 18:
    print(-1)
    sys.exit(1)

print(product)


Fixed submission:
import sys

N = int(input())
A = [int(x) for x in input().split(" ")]
if 0 in set(A):
    print(0)
    sys.exit(0)

product = 1
for a in A:
    product = product * a
    if product > 10 ** 18:
        print(-1)
        sys.exit(0)


print(product)
Buggy python submission (verdict: Time Limit Exceeded):
MAX = 5100000

MOD = 1000000007


def read_input():
    x, y = map(int, input().split(" "))
    return x, y


class BinomialCoefficients(object):
    def __init__(self, MAX=MAX, MOD=MOD):
        self.MOD = MOD
        self.fac = [1 for _ in range(MAX)]
        self.finv = [1 for _ in range(MAX)]
        self.inv = [1 for _ in range(MAX)]
        for i in range(2, MAX):
            self.fac[i] = self.fac[i - 1] * i % MOD
            self.inv[i] = MOD - self.inv[MOD % i] * (MOD // i) % MOD
            self.finv[i] = self.finv[i - 1] * self.inv[i] % MOD

    def calc(self, n, k):
        if n < k:
            return 0
        if n == 0 or k < 0:
            return 0
        return self.fac[n] * (self.finv[k] * self.finv[n - k] % self.MOD) % self.MOD


def ans(X, Y):
    a_3 = 2 * X - Y
    b_3 = 2 * Y - X
    if a_3 % 3 != 0 and b_3 % 3 != 0:
        return 0
    if a_3 < 0 or b_3 < 0:
        return 0
    a = a_3 // 3
    b = b_3 // 3

    c = BinomialCoefficients()
    return c.calc(a + b, a)


if __name__ == "__main__":
    X, Y = read_input()
    print(ans(X, Y))


Fixed submission:
MAX = 5100000

MOD = 1000000007


def read_input():
    x, y = map(int, input().split(" "))
    return x, y


class BinomialCoefficients(object):
    def __init__(self, MAX=MAX, MOD=MOD):
        self.MOD = MOD
        self.fac = [1 for _ in range(MAX)]
        self.finv = [1 for _ in range(MAX)]
        self.inv = [1 for _ in range(MAX)]
        for i in range(2, MAX):
            self.fac[i] = self.fac[i - 1] * i % MOD
            self.inv[i] = MOD - self.inv[MOD % i] * (MOD // i) % MOD
            self.finv[i] = self.finv[i - 1] * self.inv[i] % MOD

    def calc(self, n, k):
        if n < k:
            return 0
        if n == 0 or k < 0:
            return 0
        return self.fac[n] * (self.finv[k] * self.finv[n - k] % self.MOD) % self.MOD


def ans(X, Y):
    a_3 = 2 * X - Y
    b_3 = 2 * Y - X
    if a_3 % 3 != 0 and b_3 % 3 != 0:
        return 0
    if a_3 < 0 or b_3 < 0:
        return 0
    a = a_3 // 3
    b = b_3 // 3

    c = BinomialCoefficients()
    return c.calc(a + b, a)


if __name__ == "__main__":
    X, Y = read_input()
    print(ans(X, Y))
Buggy python submission (verdict: Runtime Error):
N = int(input())

p = [int(x) for x in input().split(' ')]
sorted_p = sorted(p)
count = 0
for i in range(N):
    if p[i] != sorted_p[i]:
        count += 1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")


Fixed submission:
A, B = map(int, input().split(' '))
ans = (A + B) / 2
print(int(ans)) if ans == int(ans) else print('IMPOSSIBLE ')
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split(' '))
red = N-K
p = 10**9+7


def comb(n, k, p):
    """power_funcを用いて(nCk) mod p を求める"""
    from math import factorial
    if n < 0 or k < 0 or n < k:
        return 0
    if n == 0 or k == 0:
        return 1
    a = factorial(n) % p
    b = factorial(k) % p
    c = factorial(n-k) % p
    return (a*power_func(b, p-2, p)*power_func(c, p-2, p)) % p


def power_func(a, b, p):
    """a^b mod p を求める"""
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power_func(a, b//2, p)
        return d*d % p
    if b % 2 == 1:
        return (a*power_func(a, b-1, p)) % p


def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)


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


Fixed submission:
import collections
s = input()
c = collections.Counter(s)
if list(c.values())[0] == 2 and list(c.values())[1] == 2:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N, L = map(int,input().split(' '))
l=list(range(L,N+L,1))
minabs = min([abs(x) for x in l])
if N+L+1<=0:
    print(sum(l)+minabs)
else:
    print(sum(l)-minabs) 

Fixed submission:
inp = str(input())
def a(inp):
    for x in range(3):
    
        if inp[x]==inp[x+1]:
            return 'Bad'
    return 'Good'
print(a(inp))
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D = map(int,input().split(' '))
lis = range(A,B+1)
count = 0
for x in lis:
    if x % C !=0 and x%D !=0:
        count +=1
print(count)

Fixed submission:
import math

A, B, C, D = [int(x) for x in input().split(" ")]
lcm_c_d = (C * D) // math.gcd(C, D)
num_c = (B // C) - (A - 1) // C
num_d = (B // D) - (A - 1) // D
num_cd = (B // lcm_c_d) - (A - 1) // lcm_c_d
print(B - A - num_c - num_d + num_cd + 1)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = [0 for x in range(N)]
    B = [0 for x  in  range(N)]
    for i in range(N):
        l = list(map(int,input().split(" ")))
        A[i] = l
    sortedA=sorted(A, key= lambda x: x[1])
    ans='No'
    for i,x in enumerate(sortedA):
        s=0
        for ind in range(i+1):
            s+=sortedA[ind][0]
        if  s>x[1]:
            return 'No'
    return 'Yes'
    
if __name__ == "__main__":
    print(main())


Fixed submission:
def main():
    N = int(input())
    A = [0 for x in range(N)]
    for i in range(N):
        A[i] = list(map(int, input().split(" ")))
    sortedA = sorted(A, key=lambda x: x[1])
    s = [0 for _ in range(N)]
    for i, x in enumerate(sortedA):
        if i == 0:
            s[i] = x[0]
        else:
            s[i] = s[i-1]+x[0]

        if s[i] > x[1]:
            return 'No'
    return 'Yes'


if __name__ == "__main__":
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    s = input()
    subsrings = []
    K = int(input())
    for i in range(len(s)):
        subsrings.append(s[i:])
    subsrings.sort()

    first = set()

    for s in subsrings:
        for i in range(1, len(s) + 1):
            if s[:i] not in first:
                first.add(s[:i])
                if len(first) == K:
                    print(s[:i])
                    break


Fixed submission:
if __name__ == "__main__":
    s = input()

    K = int(input())

    subsrings = [s[i : i + K + 1] for i in range(len(s))]
    subsrings.sort()

    first = set()

    for s in subsrings:

        for i in range(1, len(s) + 1):
            if s[:i] not in first:
                first.add(s[:i])
                if len(first) == K:
                    print(s[:i])
                    break
Buggy python submission (verdict: Runtime Error):
def solve(n):
    if n == 1:
        return 0
    else:
        if S[n - 2] == S[n - 1]:
            return solve(n - 1)
        else:
            return solve(n - 1) + 1


if __name__ == "__main__":
    S = input()
    first_s = S[0]
    S = [1 if first_s == s else 0 for s in S]

    print(solve(len(S)))


Fixed submission:
import threading
import sys


def main():
    def solve(n):
        if n == 1:
            return 0
        else:
            if S[n - 2] == S[n - 1]:
                return solve(n - 1)
            else:
                return solve(n - 1) + 1

    S = input()
    first_s = S[0]
    S = [1 if first_s == s else 0 for s in S]

    print(solve(len(S)))


if __name__ == "__main__":

    sys.setrecursionlimit(1024 * 1024 * 2)
    threading.stack_size(128 * 1024 * 1024 * 2)
    threading.Thread(target=main).start()
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
l = [int(i) for i in input().split()]
for i in range(k):
    l.remove(max(l))
print(sum(l))

Fixed submission:
n,k = map(int,input().split())
l = [int(i) for i in input().split()]
ls = sorted(l)
if k == 0:
  print(sum(l))
else:
  print(sum(ls[:-k]))
Buggy python submission (verdict: Runtime Error):
r = input()
print(r**2)

Fixed submission:
r = float(input())
print(int(r**2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
L=set()
for i in range(2,9):
  for j in range(2,9):
    L.add(i*j)
if N in L:
  print(Yes)
else:
  print(No)

Fixed submission:
N = int(input())
L=set()
for i in range(1,10):
  for j in range(1,10):
    L.add(i*j)
if N in L:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
S = input()
if S == "Sunny":
  print("Cloudy")
elif S == "Cloudy":
  print("Rainy")
else print("Sunny")

Fixed submission:
S = str(input())
if S == "Sunny":
  print("Cloudy")
elif S == "Cloudy":
  print("Rainy")
else:
  print("Sunny")
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = [int(x) for x in input().split()]
C = 0
for i in range(N-1):
  if H[i] <= H[i+1]+1:
    C += 1
if (C == N-1 OR C == N):
  print("Yes")
else:
  print("No")


Fixed submission:
N = int(input())
H = [int(x) for x in input().split()]
C = 0
for i in range(N-1):
  if H[i] > H[i+1]:
    H[i+1]=H[i+1]+1
  if H[i] <= H[i+1]:
    C += 1
if C == N-1:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = [int(x) for x in input().split()]
C = 0
for i in range(N-1):
  if H[i] <= H[i+1]+1:
    C += 1
if C == N-1 OR C == N:
  print("Yes")
else:
  print("No")


Fixed submission:
N = int(input())
H = [int(x) for x in input().split()]
C = 0
for i in range(N-1):
  if H[i] > H[i+1]:
    H[i+1]=H[i+1]+1
  if H[i] <= H[i+1]:
    C += 1
if C == N-1:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
N = input()
H = [int(x) for x in input().split()]
C = 0
for i in H:
  if H[i] <= H[i+1]+1:
    C += 1
if C = N:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
H = [int(x) for x in input().split()]
C = 0
for i in range(N-1):
  if H[i] > H[i+1]:
    H[i+1]=H[i+1]+1
  if H[i] <= H[i+1]:
    C += 1
if C == N-1:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if a<=b:
  s=b
  b=-1+b
else:
  s=a
  a=-1+a
if a<=b:
  t=b
else:
  t=a
print(s+t)

Fixed submission:
a,b=map(int,input().split())
if a<=b:
  s=b
  b=-1+b
else:
  s=a
  a=-1+a
if a<=b:
  t=b
else:
  t=a
print(s+t)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a==b and b==c:
  print("Yes")
  else:
    print("No")

Fixed submission:
a,b,c=map(int,input().split())
if a==b and b==c:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
x=input
if x==A:
  print("T")
elif x==T:
  print("A")
elif x==G:
  print("C")
else:
  print("G")

Fixed submission:
x=input()
if x=="A":
  print("T")
elif x=="T":
  print("A")
elif x=="G":
  print("C")
else:
  print("G")
Buggy python submission (verdict: Runtime Error):
S=str(input())
slice6=S[6]
slice5=S[5]
if int(slice6) < 5 and slice5 ==0:
  print("Heisei")
  else:
    print("TBD")


Fixed submission:
S=str(input())
slice6=S[6]
slice5=S[5]
if int(slice6) < 5 and int(slice5) ==0:
  print("Heisei")
else:
  print("TBD")

Buggy python submission (verdict: Runtime Error):
S=str(input())
slice6=S[6]
slice5=S[5]
if int(slice) < 5 and slice5 ==0:
  print("Heisei")
  else:
    print("TBD")


Fixed submission:
S=str(input())
slice6=S[6]
slice5=S[5]
if int(slice6) < 5 and int(slice5) ==0:
  print("Heisei")
else:
  print("TBD")

Buggy python submission (verdict: Runtime Error):
S=str(input())
slice=S[6]
if int(slice) < 5 and S[5] ==0:
  print("Heisei")
  else:
    print("TBD")

Fixed submission:
S=str(input())
slice6=S[6]
slice5=S[5]
if int(slice6) < 5 and int(slice5) ==0:
  print("Heisei")
else:
  print("TBD")
Buggy python submission (verdict: Runtime Error):
N=int(input())
K=int(input())
if N%K == 0:
  print(0)
else:
  print(1)


Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
K=int(input())
if N%K =0:
  print(0)
else:
  print(1)


Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N = input()
K = input()
mod = N%K
if mod=0:
  print('0')
else:
  print('1')


Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N = input()
K = input()
mod = N%K
if mod=0:
  print"0"
else:
  print"1"


Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N = input()
K = input()
mod = N%K
if mod=0:
  print("0")
else:
  print("1")


Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())
mod=N%K
if mod=0:
  print("0")
else:
  print("1")


Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())
if N%K == 0:
  print("0")
else:
  print("1")


Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
K=int(input())
if N%K == 0:
  print("0")
else:
  print("1")


Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
K=int(input())
if N%K =0:
  print("0")
else:
  print("1")


Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
K=int(input())
if N%K =0:
  print("0")
  else:
    print("1")


Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N=int(imput())
K=int(imput())
if N%K =0:
  print("0")
  else:
    print("1")

Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
R=int(input())
if R <1200
 print("ABC")
if R<2800
 print("ARC")
else
 print("AGC")

Fixed submission:
R=int(input())
if R <1200:
 print("ABC")
elif R<2800:
 print("ARC")
else:
 print("AGC")
Buggy python submission (verdict: Runtime Error):
c=input()
if(c.isupper()==True):
  	print('A')
else
	print('a')
  

Fixed submission:
c=input()
if(c.isupper()==True):
  print('A')
else:
  print('a')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = map(int, input().split());

a.sort()
ans = 1
above = False
for x in a:
	ans *= x
	if ans > 10**18:
		above = True
		break

if not above:
	print(ans)
else:
	print(-1)

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

a.sort()
ans = 1
above = False
for x in a:
	ans *= x
	if ans > 10**18:
		above = True
		break

if not above:
	print(ans)
else:
	print(-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
lengths = list(map(int, input().split()))

truth = True
for i in range(len(lengths)):
	curr = lengths[:i]+lengths[i+1:]
	if curr < lengths[i]:
		truth = False
		break
	
print(["No","Yes"][truth])

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

truth = True
for i in range(len(lengths)):
	curr = lengths[:i]+lengths[i+1:]
	if sum(curr) <= lengths[i]:
		truth = False
		break
	
print(["No","Yes"][truth])
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())

burger = [1]*(n+1)
patty = [1]*(n+1)

stopped = 0
for i in range(1,n):
	burger[i] = 2*burger[i-1]+3
	patty[i] = 2*patty[i-1]+1
	
def solve(n, x):
	if n = 0:
		if x = 0:
			return 0
		else:
			return 1
	elif x == 0:
		return 0
	elif x == burger[n]:
		return patty[n]
	elif x == burger[n-1]+1:
		return patty[n-1]
	elif x == burger[n-1]+2:
		return patty[n-1]+1
	elif x < burger[n-1]+2:
		return solve(n-1, x-1)
	elif x > burger[n-1]+2:
		return solve(n-1, x-burger[n-1]-2)+patty[n-1]+1

print(solve(n, x))

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

burger = [1]*(n+1)
patty = [1]*(n+1)

stopped = 0
for i in range(1,n):
	burger[i] = 2*burger[i-1]+3
	patty[i] = 2*patty[i-1]+1
	
def solve(n, x):
	if n == 0:
		if x == 0:
			return 0
		else:
			return 1
	elif n == 1:
		if x == 0:
			return 0
		elif x == 1:
			return 0
		elif x == 2:
			return 1
		elif x == 3:
			return 2
		elif x == 4:
			return 3
		else:
			return 3
	elif x == 0:
		return 0
	elif x == burger[n]:
		return patty[n]
	elif x == burger[n-1]+1:
		return patty[n-1]
	elif x == burger[n-1]+2:
		return patty[n-1]+1
	elif x < burger[n-1]+2:
		return solve(n-1, x-1)
	elif x > burger[n-1]+2:
		return solve(n-1, x-burger[n-1]-2)+patty[n-1]+1

print(solve(n, x))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
q = int(input())

for _ in range(q):
	a, b, c, d = map(int, input().split())
	
	x = s[a-1:b].count('A')
	y = t[c-1:d].count('A')
	
	print(['NO', 'YES'][((x+b-a+1)-(y+d-c+1))%3==0]) 

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

len_s = len(s)
len_t = len(t)

s_counter= [0]*(len_s+1)
s_temp = 0
for i in range(len_s):
	if s[i] == "A":
		s_temp += 1
	s_counter[i+1] = s_temp
	
t_counter= [0]*(len_t+1)
t_temp = 0
for i in range(len_t):
	if t[i] == "A":
		t_temp += 1
	t_counter[i+1] = t_temp

for _ in range(q):
	a, b, c, d = map(int, input().split())
	
	x = s_counter[b]-s_counter[a-1]
	y = t_counter[d]-t_counter[c-1]
	print(['NO', 'YES'][((x+b-a+1)-(y+d-c+1))%3==0])

Buggy python submission (verdict: Time Limit Exceeded):
def checker(x,y):
	count_x_a = x.count('A')
	count_y_a = y.count('A')
	
	len_x = count_x_a*2 + (len(x)-count_x_a)
	len_y = count_y_a*2 + (len(y)-count_y_a)
	return (len_x-len_y)%3 == 0
	
s = input()
t = input()
q = int(input())

for _ in range(q):
	a, b, c, d = map(int, input().split())
	
	x = s[a-1:b]
	y = t[c-1:d]
	
	print(['NO', 'YES'][checker(x,y)]) 

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

len_s = len(s)
len_t = len(t)

s_counter= [0]*(len_s+1)
s_temp = 0
for i in range(len_s):
	if s[i] == "A":
		s_temp += 1
	s_counter[i+1] = s_temp
	
t_counter= [0]*(len_t+1)
t_temp = 0
for i in range(len_t):
	if t[i] == "A":
		t_temp += 1
	t_counter[i+1] = t_temp

for _ in range(q):
	a, b, c, d = map(int, input().split())
	
	x = s_counter[b]-s_counter[a-1]
	y = t_counter[d]-t_counter[c-1]
	print(['NO', 'YES'][((x+b-a+1)-(y+d-c+1))%3==0])

Buggy python submission (verdict: Time Limit Exceeded):
def checker(x,y):
	new_x = ''
	for ch in list(x):
		if ch == 'A':
			new_x += 'BB'
		else:
			new_x += 'B'
	
	new_y = ''
	for ch in list(y):
		if ch == 'A':
			new_y += 'BB'
		else:
			new_y += 'B'
	
	len_x = len(new_x)
	len_y = len(new_y)
	
	return (len_x-len_y)%3 == 0
s = input()
t = input()
q = int(input())

for _ in range(q):
	a, b, c, d = map(int, input().split())
	
	x = s[a-1:b]
	y = t[c-1:d]
	
	print(['NO', 'YES'][checker(x,y)]) 

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

len_s = len(s)
len_t = len(t)

s_counter= [0]*(len_s+1)
s_temp = 0
for i in range(len_s):
	if s[i] == "A":
		s_temp += 1
	s_counter[i+1] = s_temp
	
t_counter= [0]*(len_t+1)
t_temp = 0
for i in range(len_t):
	if t[i] == "A":
		t_temp += 1
	t_counter[i+1] = t_temp

for _ in range(q):
	a, b, c, d = map(int, input().split())
	
	x = s_counter[b]-s_counter[a-1]
	y = t_counter[d]-t_counter[c-1]
	print(['NO', 'YES'][((x+b-a+1)-(y+d-c+1))%3==0])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split(' ')))
Q = int(input())
Bs = []
for i in range(Q):
    Bs.append(list(map(int, input().split(' '))))
    
    
A_list = [0]*(10**5+1)
for i in A:
    A_list[i] += 1
    
for B in Bs:
    b, c = B
    A_list[c] += A_list[b]
    A_list[b] = 0
    print(sum([i*num for num, i in enumerate(A_list)]))

Fixed submission:
N = int(input())
A = list(map(int, input().split(' ')))
Q = int(input())
Bs = []
for i in range(Q):
    Bs.append(list(map(int, input().split(' '))))
    
    
A_list = [0]*(10**5+1)
for i in A:
    A_list[i] += 1
    
sum_value = sum(A)
for B in Bs:
    b, c = B
    sum_value += A_list[b]*c
    sum_value -= A_list[b]*b
    
    A_list[c] += A_list[b]
    A_list[b] = 0
    print(sum_value)
Buggy python submission (verdict: Runtime Error):
import warnings
warnings.simplefilter('ignore')

from numba import jit

N = int(input())
As = list(map(int, input().split(' ')))


@jit
def test(As):
    not_divisible = 0
    for num_i, Ai in enumerate(As):
        for num_j, Aj in enumerate(As):
            if num_i==num_j:
                continue
            if Ai%Aj==0:
                break
        else:
            not_divisible += 1
    print(not_divisible)
    
test(As)

Fixed submission:
import itertools
import numpy as np

X, N = list(map(int, input().split(' ')))
ps = input()
if len(ps)!=0:
    ps = list(map(int, ps.split(' ')))

ps_sort = list(sorted(ps))
not_in_ps = np.array([[abs(i-X), i] for i in range(-1, 102) if i not in ps_sort])
print(not_in_ps[np.argmin(not_in_ps[:,0], 0), 1])

Buggy python submission (verdict: Runtime Error):
import itertools
import numpy as np

X, N = list(map(int, input().split(' ')))
ps = list(map(int, input().split(' ')))

ps_sort = list(sorted(ps))
not_in_ps = np.array([[abs(i-X), i] for i in range(101) if i not in ps_sort])
print(not_in_ps[np.argmin(not_in_ps[:,0], 0), 1])

Fixed submission:
import itertools
import numpy as np

X, N = list(map(int, input().split(' ')))
ps = input()
if len(ps)!=0:
    ps = list(map(int, ps.split(' ')))

ps_sort = list(sorted(ps))
not_in_ps = np.array([[abs(i-X), i] for i in range(-1, 102) if i not in ps_sort])
print(not_in_ps[np.argmin(not_in_ps[:,0], 0), 1])