Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;
    cin >> n;

    ll ans = 1;

    ll r = 1e18;

    vector<ll> a(n);

    for (auto &x : a)
    {
        cin >> x;
        if (x == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (1000000000000000000 / ans <= a[i])
        {
            cout << -1 << endl;
            return 0;
        }

        ans *= a[i];
    }

    cout << ans << endl;
}


Fixed submission:
n = int(input())

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

ans = 1

for i in range(n):
   if a[i] == 0:
        print(0)
        exit()

for i in range(n):
    ans *= a[i]
    if ans > 1e18:
        print(-1)
        exit()

print(ans)

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

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

ans = 1

for i in range(n):
    ans *= a[i]
    
if ans > 1e18:
        print(-1)
        exit()

print(ans)

Fixed submission:
n = int(input())

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

ans = 1

for i in range(n):
   if a[i] == 0:
        print(0)
        exit()

for i in range(n):
    ans *= a[i]
    if ans > 1e18:
        print(-1)
        exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll a;
    double b;
    cin >> a >> b;
    ll y = ceil(b * 100.0);

    ll ans = a * y;

    ans /= 100;

    cout << ans << endl;
}


Fixed submission:
import decimal

a, b = input().split()

a = int(a)
b = decimal.Decimal(b)
b *= 100

ans = a * b

ans //= 100

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


k = int(input())
res = []

ans = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        res.append(gcd(i, j))
        
for n in range(1, k + 1):
    for r in list(res):
        ans += gcd(int(r), n)

print(ans)


Fixed submission:
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

k = int(input())
res = [0] * (k + 1)

ans = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        res[gcd(i, j)] += 1

for n in range(1, k + 1):
    for r in range(1, k + 1):
        ans += gcd(r, n) * res[r]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


k = int(input())

ans = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        for n in range(1, k + 1):
            ans += gcd(gcd(i, j), n)

print(ans)


Fixed submission:
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

k = int(input())
res = [0] * (k + 1)

ans = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        res[gcd(i, j)] += 1

for n in range(1, k + 1):
    for r in range(1, k + 1):
        ans += gcd(r, n) * res[r]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


k = int(input())

ans = 0

for i in range(k + 1):
    for j in range(k + 1):
        for n in range(k + 1):
            if i == 0 or j == 0 or n == 0:
                continue
            ans += gcd(gcd(i, j), n)

print(ans)


Fixed submission:
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

k = int(input())
res = [0] * (k + 1)

ans = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        res[gcd(i, j)] += 1

for n in range(1, k + 1):
    for r in range(1, k + 1):
        ans += gcd(r, n) * res[r]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())

x -= 1
y -= 1

ans = [0] * n


for i in range(n):
    for j in range(i + 1, n):
        ans[min(abs(j - i), abs(j - y) + abs(y - i), abs(j - x) + abs(x - i), abs(j - y) + abs(x - i) + 1)] += 1

for i in range(1, n):
    print(ans[i])


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

x -= 1
y -= 1

ans = [0] * n


for i in range(n):
    for j in range(i + 1, n):
        ans[min(abs(j - i), abs(j - x) + abs(y - i) + 1, abs(j - y) + abs(x - i) + 1)] += 1

for i in range(1, n):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
def lcm(X,Y):
    x=X
    y=Y
    if y>x:
        x,y=y,x
    while x%y!=0:
        x,y=y,x%y
    return X*Y//y

cnt=0
ans=0
LCM=1
for i in range(n):
    Q=lcm(LCM,A[i])
    cnt*=Q//LCM
    LCM=Q
    cnt+=Q//A[i]
print(cnt%mod)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
def lcm(X,Y):
    x=X
    y=Y
    if y>x:
        x,y=y,x
    while x%y!=0:
        x,y=y,x%y
    return X*Y//y

cnt=0
ans=0
LCM=1
for i in range(n):
    Q=lcm(LCM,A[i])
    cnt*=Q//LCM
    LCM=Q
    cnt+=Q//A[i]
print(cnt%mod)

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


def lcm(X, Y):
    x = X
    y = Y
    if y > x:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return X*Y//y


l = 1

mod = pow(10, 9) + 7


for i in list(a):
    l = lcm(l, i)

ans = 0

for i in list(a):
    ans += l // i
    ans %= mod

print(ans)


Fixed submission:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
def lcm(X,Y):
    x=X
    y=Y
    if y>x:
        x,y=y,x
    while x%y!=0:
        x,y=y,x%y
    return X*Y//y

cnt=0
ans=0
LCM=1
for i in range(n):
    Q=lcm(LCM,A[i])
    cnt*=Q//LCM
    LCM=Q
    cnt+=Q//A[i]
print(cnt%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions as f

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

l = 1

mod = pow(10, 9) + 7

for i in list(a):
    l = l * i // f.gcd(l, i)

ans = 0

for i in list(a):
    ans += l // i
    ans %= mod
    
print(ans)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
def lcm(X,Y):
    x=X
    y=Y
    if y>x:
        x,y=y,x
    while x%y!=0:
        x,y=y,x%y
    return X*Y//y

cnt=0
ans=0
LCM=1
for i in range(n):
    Q=lcm(LCM,A[i])
    cnt*=Q//LCM
    LCM=Q
    cnt+=Q//A[i]
print(cnt%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions as f

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

l = 1

mod = pow(10, 9) + 7

for i in list(a):
    l = l * i // f.gcd(l, i)

ans = 0

for i in list(a):
    ans += l // i
    ans %= mod
    
print(ans)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
def lcm(X,Y):
    x=X
    y=Y
    if y>x:
        x,y=y,x
    while x%y!=0:
        x,y=y,x%y
    return X*Y//y

cnt=0
ans=0
LCM=1
for i in range(n):
    Q=lcm(LCM,A[i])
    cnt*=Q//LCM
    LCM=Q
    cnt+=Q//A[i]
print(cnt%mod)
Buggy python submission (verdict: Runtime Error):
print((int)input()**3/27)

Fixed submission:
print((int(input())**3)/27)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
import math
n = int(input())
a = list(map(int, input().split()))
MOD=10**9+7
lcm=1
for i in range(n):
    lcm*=a[i]//math.gcd(lcm,a[i])
res=0
for i in range(n):
    res+=lcm//a[i]
print(res%MOD)

Fixed submission:
from fractions import gcd
import math
n = int(input())
a = list(map(int, input().split()))
MOD=10**9+7
lcm=1
for i in range(n):
    lcm*=a[i]//gcd(lcm,a[i])
res=0
for i in range(n):
    res+=lcm//a[i]
print(res%MOD)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a = list(map(int, input().split()))

def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)
b=[0]*n
for i in range(n):
    b[i]=a[i]//2
flag=False
f=False
for i in range(n):
    if(b[i]%2!=b[0]%2):
        flag=True
x=1
if(b[0]%2==0):
    f=True
for i in range(n):
    x=lcm(x,b[i])

if(f):
    l=0
else:
    res=m//x+1
    res//=2
#print(x)
if(flag):
    print(0)
else:
    print(res)


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

def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b):
    return a*b//gcd(a,b)
b=[0]*n
for i in range(n):
    b[i]=a[i]//2
flag=False
f=0
keta=0
buf=b[0]
while(buf%2==0):
    buf/=2
    keta+=1
for i in range(n):
    buf=b[i]
    tmp=0
    while(buf%2==0):
        buf/=2
        tmp+=1
    if(keta!=tmp):
        flag=True
x=1
if(b[0]%2==0):
    f=1
for i in range(n):
    x=lcm(x,b[i])
res=m//x+1
res//=2
#print(x)
if(flag):
    print(0)
else:
    print(res)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a = list(map(int, input().split()))

def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)
b=[0]*n
for i in range(n):
    b[i]=a[i]//2
flag=False
f=False
for i in range(n):
    if(b[i]%2!=b[0]%2):
        flag=True
x=1
if(b[0]%2==0):
    f=True
for i in range(n):
    x=lcm(x,b[i])

if(f):
    l=0
else:
    res=m//x+1
    res//=2
print(x)
if(flag):
    print(0)
else:
    print(res)


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

def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b):
    return a*b//gcd(a,b)
b=[0]*n
for i in range(n):
    b[i]=a[i]//2
flag=False
f=0
keta=0
buf=b[0]
while(buf%2==0):
    buf/=2
    keta+=1
for i in range(n):
    buf=b[i]
    tmp=0
    while(buf%2==0):
        buf/=2
        tmp+=1
    if(keta!=tmp):
        flag=True
x=1
if(b[0]%2==0):
    f=1
for i in range(n):
    x=lcm(x,b[i])
res=m//x+1
res//=2
#print(x)
if(flag):
    print(0)
else:
    print(res)
Buggy python submission (verdict: Runtime Error):
k,n=map(int,input().split())
for i in range(n):
  print(-n+1+i)
print(0)
for i in range(n):
  printf(i)

Fixed submission:
k,n=map(int,input().split())
for i in range(k-1):
  print(n-k+i+1,end=" ")
print(n,end=" ")
for i in range(k-1):
  print(n+i+1,end=" ")
Buggy python submission (verdict: Runtime Error):
x,y=mao(int,input().split())
print(x+y//2)

Fixed submission:
x,y=map(int,input().split())
print(x+y//2)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if(n>=1000):
  print("ABD")
 else:
  print("ABC")

Fixed submission:
n=int(input())
if(n>=1000):
  print("ABD")
else:
  print("ABC")
Buggy python submission (verdict: Runtime Error):
n=input()
print(n//3)

Fixed submission:
print(int(input())//3)
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
print((x-a)%b)


Fixed submission:
x=int(input())
a=int(input())
b=int(input())
print((x-a)%b)

Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
print((x+a)%b)

Fixed submission:
x=int(input())
a=int(input())
b=int(input())
print((x-a)%b)
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
if abs(a-x)>abc(b-x):
  print('A')
else:
  print('B')

Fixed submission:
x,a,b=map(int,input().split())
if abs(a-x)<abs(b-x):
  print('A')
else:
  print('B')
Buggy python submission (verdict: Runtime Error):
a,b,h=map(int,input().split())
print((a+b)*h//2)


Fixed submission:
a=int(input())
b=int(input())
h=int(input())
print((a+b)*h//2)

Buggy python submission (verdict: Runtime Error):
a,b,h=map(int,input().split())
print((a+b)*h/2)


Fixed submission:
a=int(input())
b=int(input())
h=int(input())
print((a+b)*h//2)

Buggy python submission (verdict: Runtime Error):
a,b,h=map(int,input().split())
print((a+b)/h)

Fixed submission:
a=int(input())
b=int(input())
h=int(input())
print((a+b)*h//2)
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
s = list(map(int, input().split()))
a = 1
flag0 = False
flag = True
for i in s:
  a*=i
  if a > 1000000000000000000:
    flag = False
  if i == 0:
    flag0 = True
if flag0:
  print(0)
elif flag:
  print(a)
else:
  print(-1)

Fixed submission:
n = input()
s = list(map(int, input().split()))
a = 1
flag0 = False
flag = True
for i in s:
  a*=i
  if a > 1000000000000000000:
    flag = False
    break
for i in s:
  if i == 0:
    flag0 = True
if flag0:
  print(0)
elif flag:
  print(a)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())

g = [[] * 1 for i in range(n)]

for i in range(n-1):
    a = int(input())
    g[a-1].append(i+1)

def dfs(v):
    max = 0
    max_i = 0
    for u in g[v]:
        next = dfs(u)
        if next == max:
            max_i += 1
        elif next > max:
            max = next
            max_i = 1
    return max + max_i

print(dfs(0))



Fixed submission:
import sys
sys.setrecursionlimit(3000000)

n = int(input())

g = [[] * 1 for i in range(n)]

for i in range(n-1):
    a = int(input())
    g[a-1].append(i+1)

def dfs(v):
    childs = []
    for u in g[v]:
        child = dfs(u)
        childs.append(child)
    childs.sort()
    ans = 1
    for child in childs:
        if ans < child:
            ans = child
        ans += 1
    return ans

print(dfs(0)-1)

Buggy python submission (verdict: Runtime Error):
n = int(input())

g = [[] * 1 for i in range(n)]

for i in range(n-1):
    a = int(input())
    g[a-1].append(i+1)

def dfs(v):
    max = 0
    max_i = 0
    for u in g[v]:
        next = dfs(u)
        if next == max:
            max_i += 1
        elif next > max:
            max = next
            max_i = 1
    return max + max_i

print(dfs(0))



Fixed submission:
import sys
sys.setrecursionlimit(3000000)

n = int(input())

g = [[] * 1 for i in range(n)]

for i in range(n-1):
    a = int(input())
    g[a-1].append(i+1)

def dfs(v):
    childs = []
    for u in g[v]:
        child = dfs(u)
        childs.append(child)
    childs.sort()
    ans = 1
    for child in childs:
        if ans < child:
            ans = child
        ans += 1
    return ans

print(dfs(0)-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
a = list(map(int, input().split()))

now = 1
for i in range(k):
    now *= a[i]

for i in range(k,n):
    prv = now
    now *= a[i]
    now /= a[i-k]
    if prv < now:
        print("Yes")
    else:
        print("No")

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

for i in range(k,n):
    if a[i] > a[i-k]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]
last = [[-1] for i in range(26)]
# before query
ans = 0
for i in range(D):
    op = t[i]-1
    ans += s[i][op]
    last[op].append(i)
    for j in range(26):
        ans -= c[j]*(i-last[j][-1])
    # print(ans)
from bisect import *

m = int(input())
def suminc(a,b):
    return b*(b-1)//2-a*(a-1)//2
while m:
    m-=1
    update = 0
    d,q = map(int, input().split())
    d-=1
    q-=1
    oq = t[d]-1
    update += s[d][q]-s[d][oq]
    idx = bisect_left(last[oq],d)
    if idx == len(last[oq])-1:
        cnt = D - last[oq][idx]
    else:
        cnt = last[oq][idx+1] - last[oq][idx]
    update += c[oq]*suminc(0,cnt)
    cntprv = last[oq][idx] - last[oq][idx-1]
    update -= c[oq]*suminc(cntprv,cntprv+cnt)

    idx2 = bisect_left(last[q],d)-1
    if idx2 == len(last[q])-1:
        cnt = D - d
    else:
        cnt = last[oq][idx2+1] - d
    if idx2 == len(last[q])-1:
        cntprv = D - last[oq][idx2] - cnt
    else:
        cntprv = last[oq][idx2+1] - last[oq][idx2] - cnt
    update += c[q]*suminc(cntprv,cntprv+cnt)
    update -= c[q]*suminc(0,cnt)

    ans += update
    del last[oq][idx]
    last[q].insert(idx2+1,d)
    print(ans)
    t[d] = q+1







    

Fixed submission:
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]
last = [[-1] for i in range(26)]
# before query
ans = 0
for i in range(D):
    op = t[i]-1
    ans += s[i][op]
    last[op].append(i)
    for j in range(26):
        ans -= c[j]*(i-last[j][-1])
    # print(ans)
from bisect import *
import random
m = int(input())
def suminc(a,b):
    return b*(b-1)//2-a*(a-1)//2
while m:
    m-=1
    update = 0
    d,q = map(int, input().split())
    # d = random.randint(1,365)
    # q = random.randint(1,26)
    d-=1
    q-=1
    oq = t[d]-1
    update += s[d][q]-s[d][oq]
    idx = bisect_left(last[oq],d)
    if idx == len(last[oq])-1:
        cnt = D - last[oq][idx]
    else:
        cnt = last[oq][idx+1] - last[oq][idx]
    update += c[oq]*suminc(0,cnt)
    cntprv = last[oq][idx] - last[oq][idx-1]
    update -= c[oq]*suminc(cntprv,cntprv+cnt)

    idx2 = bisect_left(last[q],d)-1
    if idx2 == len(last[q])-1:
        cnt = D - d
    else:
        cnt = last[q][idx2+1] - d
    if idx2 == len(last[q])-1:
        cntprv = D - last[q][idx2] - cnt
    else:
        cntprv = last[q][idx2+1] - last[q][idx2] - cnt
    update += c[q]*suminc(cntprv,cntprv+cnt)
    update -= c[q]*suminc(0,cnt)

    ans += update
    del last[oq][idx]
    last[q].insert(idx2+1,d)
    print(ans)
    t[d] = q+1
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import bisect
n,m,k = map(int, input().split())
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))
ans = 0
a.appendleft(0)
b.appendleft(0)

for i in range(1,n+1):
    a[i]+=a[i-1]
for i in range(1,m+1):
    b[i]+=b[i-1]

for i in range(n+1):
    now = k-a[i]
    if now<0:
        continue
    idx = bisect.bisect_right(b,now)
    ans = max(ans,idx-1+i)

print(ans)

Fixed submission:
from collections import deque
import bisect
n,m,k = map(int, input().split())
a = [0]
b = [0]
a1 = list(map(int, input().split()))
b1 = list(map(int, input().split()))
# a1 = [1000000]*200000
# b1 = [1000000]*200000
ans = 0
a = a + a1
b = b + b1

for i in range(1,n+1):
    a[i]+=a[i-1]
for i in range(1,m+1):
    b[i]+=b[i-1]

for i in range(n+1):
    now = k-a[i]
    if now<0:
        break
    idx = bisect.bisect_right(b,now)
    ans = max(ans,idx-1+i)

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

ok = [True]*100005

a.sort()
ans=0
for i in range(n):
    if i<n-1 and a[i]!=a[i+1] and ok[a[i]]:
        ans+=1
    elif i==n-1 and ok[a[i]]:
        ans+=1
    if ok[a[i]]:
        for j in range(a[i],100004,a[i]):
            ok[j]=False

print(ans)

    


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

ok = [True]*1000005

a.sort()
ans=0
for i in range(n):
    if i<n-1 and a[i]!=a[i+1] and ok[a[i]]:
        ans+=1
    elif i==n-1 and ok[a[i]]:
        ans+=1
    if ok[a[i]]:
        for j in range(a[i],1000004,a[i]):
            ok[j]=False

print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = int(input())

print(a*b)

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

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

flag= True
ans=1
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        flag=False

if flag:
    print(ans)
else:
    if 0 in a:
        print(0)
    else:
        print(-1)

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

flag= True
ans=1
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        flag=False
        break

if flag:
    print(ans)
else:
    if 0 in a:
        print(0)
    else:
        print(-1)
Buggy python submission (verdict: Runtime Error):
n,a,b,c = map(int, input().split())
op = [input() for i in range(n)]

val=[a,b,c]
flag=True
ansls=list()

for i in range(n):
    s1=ord(op[i][0])-ord('A')
    s2=ord(op[i][1])-ord('A')
    if val[s1]>val[s2]:
        ansls.append(s2)
        val[s2]+=1
        val[s1]-=1
    elif val[s1]<val[s2]:
        ansls.append(s1)
        val[s1]+=1
        val[s2]-=1
    else:
        s1n = ord(op[i+1][0])-ord('A')
        s2n = ord(op[i+1][1])-ord('A')
        nxt = set([s1,s2]) & set([s1n,s2n])
        nxt = list(nxt)[0]
        ansls.append(nxt)
        val[nxt]+=1
        if nxt==s1:
            val[s2]-=1
        else:
            val[s1]-=1
    if min(val)<0:
        flag=False
        break

if flag:
    print('Yes')
    for i in range(n):
        print(chr(ansls[i]+ord('A')))
else:
    print('No')

    

Fixed submission:
n,a,b,c = map(int, input().split())
op = [input() for i in range(n)]

val=[a,b,c]
flag=True
ansls=list()

for i in range(n):
    s1=ord(op[i][0])-ord('A')
    s2=ord(op[i][1])-ord('A')
    if val[s1]>val[s2]:
        ansls.append(s2)
        val[s2]+=1
        val[s1]-=1
    elif val[s1]<val[s2] or i+1==n:
        ansls.append(s1)
        val[s1]+=1
        val[s2]-=1
    else:
        s1n = ord(op[i+1][0])-ord('A')
        s2n = ord(op[i+1][1])-ord('A')
        nxt = set([s1,s2]) & set([s1n,s2n])
        nxt = list(nxt)[0]
        ansls.append(nxt)
        val[nxt]+=1
        if nxt==s1:
            val[s2]-=1
        else:
            val[s1]-=1
    if min(val)<0:
        flag=False
        break

if flag:
    print('Yes')
    for i in range(n):
        print(chr(ansls[i]+ord('A')))
else:
    print('No')
Buggy python submission (verdict: Runtime Error):

h, w = map(int, input().split())
mp = [list(input()) for i in range(h)]
dp = [[0]*105 for _ in range(105)]
if mp[0][0]=='#':
    dp[0][0]+=1
for i in range(w-1):
    plus=0
    if mp[0][i+1]=='#':
        plus=1
    dp[0][i+1] = dp[0][i]+plus
for i in range(h-1):
    plus=0
    if mp[i+1][0]=='#':
        plus=1
    dp[i+1][0] = dp[i][0]+plus

for i in range(1,w):
    for j in range(1,h):
        plus=0
        if mp[i][j]=='#':
            plus=1
        dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + plus

print(dp[h-1][w-1])
    




Fixed submission:

h, w = map(int, input().split())
mp = [list(input()) for i in range(h)]
dp = [[0]*105 for _ in range(105)]
if mp[0][0]=='#':
    dp[0][0]+=1
for i in range(w-1):
    plus=0
    if mp[0][i+1]!=mp[0][i] and mp[0][i+1] == '#':
        plus=1
    dp[0][i+1] = dp[0][i]+plus
for i in range(h-1):
    plus=0
    if mp[i+1][0]!=mp[i][0] and mp[i+1][0] == '#':
        plus=1
    dp[i+1][0] = dp[i][0]+plus

for i in range(1,h):
    for j in range(1,w):
        plus=0
        plus2=0
        if mp[i][j]!=mp[i-1][j] and mp[i][j]=='#':
            plus=1
        if mp[i][j]!=mp[i][j-1] and mp[i][j]=='#':
            plus2=1
        dp[i][j] = min(dp[i-1][j]+plus, dp[i][j-1]+plus2)

print(dp[h-1][w-1])
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
def lcm(x,y):
    return (x * y) // gcd(x, y)
MOD = 10**9+7


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

l = reduce(lcm,a)
ans=0
for i in range(n):
    ans+=l//a[i]%MOD
    ans%=MOD

print(int(ans))

Fixed submission:
from fractions import gcd
from functools import reduce
def lcm(x,y):
    return (x * y) // gcd(x, y)
MOD = 10**9+7


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

l = reduce(lcm,a)%MOD
ans=0
for i in range(n):
    ans+=l*pow(a[i],MOD-2, MOD)
    ans%=MOD

print(int(ans))