Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03640 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    n = int(input())
    A = list(map(int, input().split()))
    B = []
    for i in range(n):
        for _ in range(A[i]):
            B.append(i + 1)

    res = [[0] * W for _ in range(H)]
    for b in B:
        for h in range(H):
            for w in range(W):
                if res[h][w] == 0:
                    res[h][w] = b
                    break
            else:
                continue
            break

    for i in range(H):
        if i % 2 == 0:
            print(*res[i])
        else:
            print(*res[i][::-1])


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    n = int(input())
    A = list(map(int, input().split()))

    grid = [[0 for _ in range(W)] for _ in range(W)]
    h, w = 0, 0
    for i in range(n):
        cnt = A[i]
        while cnt:
            grid[h][w] = i + 1
            cnt -= 1
            if w + 1 < W:
                w += 1
            else:
                h += 1
                w = 0

    for h in range(H):
        print(*grid[h]) if h % 2 == 0 else print(*grid[h][::-1])


if __name__ == '__main__':
    resolve()
Problem p03645 (python)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)
res = []

f_inf = float("inf")
dist = [f_inf for _ in range(n)]
dist[0] = 0
q = deque()
q.append(0)
while q:
    u = q.popleft()
    for nv in tree[u]:
        if dist[nv] == f_inf:
            dist[nv] = dist[u] + 1
            q.append(nv)
if dist[n - 1] <= 2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc068/submissions/12987221
# C - Cat Snuke and a Voyage
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())

    edge = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        edge[a - 1].append(b - 1)
        edge[b - 1].append(a - 1)

    for i in edge[0]:
        if n - 1 in set(edge[i]):
            print("POSSIBLE")
            break
    else:
        print("IMPOSSIBLE")


def resolve2():
    n, m = map(int, input().split())

    edge = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        edge[a - 1].append(b - 1)
        edge[b - 1].append(a - 1)

    depth = [0 for _ in range(n)]

    def dfs(v, p, d):
        depth[v] = d
        for u in edge[v]:
            if u == p:
                continue
            dfs(u, v, d + 1)

    dfs(0, -1, 0)
    if depth[n - 1] <= 2:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


if __name__ == '__main__':
    resolve2()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve2():
    n, m = map(int, input().split())

    edge = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        edge[a - 1].append(b - 1)
        edge[b - 1].append(a - 1)

    depth = [0 for _ in range(n)]

    def dfs(v, p, d):
        depth[v] = d
        for u in edge[v]:
            if u == p:
                continue
            dfs(u, v, d + 1)

    dfs(0, -1, 0)
    if depth[n - 1] <= 2:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


if __name__ == '__main__':
    resolve2()
Problem p03694 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    print(A[-1] - A[0])


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
use proconio::*;
use std::cmp::*;
use std::vec::Vec;

fn main() {
    input! {
        n: usize,
        mut A: [i32; n],
    }
    A.sort();
    let res = A[n - 1] - A[0];
    println!("{}", res);
}
Problem p03695 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    res1 = []
    res2 = []
    for i in range(n):
        a = A[i] // 400
        if a < 8:
            res1.append(a)
        else:
            res2.append(a)

    ma = len(set(res1)) + len(res2)
    mi = len(set(res1)) + 0 if len(set(res1)) != 0 else 1
    print(mi, ma)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    Color = [0] * 9
    for a in A:
        if a >= 3200:
            Color[-1] += 1
        else:
            Color[a // 400] = 1

    mi = sum(Color[:8]) + (1 if sum(Color[:8]) == 0 and Color[9] > 0 else 0)
    ma = sum(Color[:8]) + Color[8]

    print(mi, ma)


if __name__ == '__main__':
    resolve()
Problem p03760 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    o = list(input())
    e = list(input())

    res = [""] * (len(o) + len(e))
    for i in range(len(o) + len(e)):
        if i % 2 != 0:
            s = e.pop(0)
            res[i] = s
        else:
            s = o.pop(0)
            res[i] = s

    print("".join(res))


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    o = input()
    e = input()
    res = []
    for i in range(len(o)):
        res.append(o[i])
        res.append(e[i])
    print("".join(res))


if __name__ == '__main__':
    resolve()
Problem p03912 (python)

Fixed submission:
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    X = list(map(int, input().split()))

    MOD = [defaultdict(int) for _ in range(m + 1)]
    cnt = defaultdict(int)
    for x in X:
        MOD[x % m][x] += 1
        cnt[x % m] += 1

    res = cnt[0] // 2
    if m % 2 == 0:
        res += cnt[m // 2] // 2

    for i in range(1, (m + 1) // 2):
        res += min(cnt[i], cnt[m - i])

        if cnt[i] > cnt[m - i]:
            diff = (cnt[i] - cnt[m - i]) // 2
            for v in MOD[i].values():
                if diff == 0:
                    break
                t = min(diff, v // 2)
                diff -= t
                res += t
        elif cnt[i] < cnt[m - i]:
            diff = (cnt[m - i] - cnt[i]) // 2
            for v in MOD[m - i].values():
                if diff == 0:
                    break
                t = min(diff, v // 2)
                diff -= t
                res += t

    print(res)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict(int)

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    X = list(map(int, input().split()))

    MOD = [defaultdict(int) for _ in range(m + 1)]
    cnt = defaultdict(int)
    for x in X:
        MOD[x % m][x] += 1
        cnt[x % m] += 1

    res = cnt[0] // 2
    if m % 2 == 0:
        res += cnt[m // 2] // 2
        
    for i in range(1, (m + 1) // 2):
        res += min(cnt[i], cnt[m - i])

        if cnt[i] > cnt[m - i]:
            diff = (cnt[i] - cnt[m - i]) // 2
            for v in MOD[i].values():
                if diff == 0:
                    break
                t = min(diff, v // 2)
                diff -= t
                res += t
        elif cnt[i] < cnt[m - i]:
            diff = (cnt[m - i] - cnt[i]) // 2
            for v in MOD[m - i].values():
                if diff == 0:
                    break
                t = min(diff, v // 2)
                diff -= t
                res += t

    print(res)


if __name__ == '__main__':
    resolve()
Problem p04013 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a = map(int, input().split())
    X = list(map(int, input().split()))
    MAX = n * a
    dp = [[[0] * (MAX + 1) for _ in range(n + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(1, n + 1):
        x = X[i - 1]
        for k in range(n):
            for s in range(MAX):
                dp[i][k][s] += dp[i - 1][k][s]
                if s + x <= MAX:
                    dp[i][k + 1][s + x] += dp[i - 1][k][s]
    res = 0
    for k in range(1, n + 1):
        res += dp[-1][k][a * k]
    print(res)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a = map(int, input().split())
    X = list(map(int, input().split()))
    MAX = sum(X) + 1

    dp = [[[0] * MAX for _ in range(n + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(1, n + 1):
        x = X[i - 1]
        for j in range(n):
            for k in range(MAX):
                dp[i][j][k] += dp[i - 1][j][k]
                if k + x < MAX:
                    dp[i][j + 1][k + x] += dp[i - 1][j][k]
    res = 0
    for j in range(1, n + 1):
        res += dp[-1][j][a * j]
    print(res)


if __name__ == '__main__':
    resolve()
Problem p04032 (python)

Fixed submission:
s = input()
n = len(s)

for i in range(n - 1):
    if s[i] == s[i + 1]:
        print(i + 1, i + 2)
        exit()

for i in range(n - 2):
    if s[i] == s[i + 2]:
        print(i + 1, i + 3)
        exit()

print(-1, -1)

Buggy submission (verdict: Runtime Error):
s = str(input())

if len(s) == len(set(s)):
    print(-1, -1)
else:
    for i in range(1, len(s)):
        if s[i - 1] != s[i] and s[i] == s[i + 1]:
            print(i, i + 2)
            break
Problem p02646 (python)

Fixed submission:
from decimal import Decimal
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())

if v==w:
    print("NO")
    exit()
atai = Decimal(abs(b-a))/Decimal(abs(v-w))
if atai<=t and a+v*t>=b+w*t:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
from decimal import Decimal
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
List=list(range(1,t+1))
if a==b:
    print("YES")
    exit()
elif v==w:
    print("NO")
    exit()
def binary_search(x, k, n):
 
  l = 1 #検索範囲の左端
 
  r = n #検索範囲の右端
 
 
 
  while r - l >= 1: #検索範囲がなくなったら処理を終了する
 
    i = (l + r) // 2 #iにデータの真ん中の位置を持たせる
 
    if k[i] == x:
 
      return True
 
    elif k[i] < x:
 
      l = i + 1
 
    else:
 
      r = i
 
 
 
  else:
 
    return False
    
if binary_search(Decimal(b-a)/Decimal(v-w), List, t)==True:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
from decimal import Decimal
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
List=list(range(1,t+1))
if a==b:
    print("YES")
    exit()
elif v==w:
    print("NO")
    exit()
def binary_search(x, k, n):
 
  l = 1 #検索範囲の左端
 
  r = n #検索範囲の右端
 
 
 
  while r - l >= 1: #検索範囲がなくなったら処理を終了する
 
    i = (l + r) // 2 #iにデータの真ん中の位置を持たせる
 
    if k[i] == x:
 
      return True
 
    elif k[i] < x:
 
      l = i + 1
 
    else:
 
      r = i
 
 
 
  else:
 
    return False
    
if binary_search(Decimal(b-a)/Decimal(v-w), List, t)==True:
    print("YES")
else:
    print("NO")
Problem p02687 (python)

Fixed submission:
s=input()
if s=="ABC":
    print("ARC")
else:
    print("ABC")

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (int)(n); i++)
const ld pi=3.14159265358979323846;
 
int main() {
    string s;
    cin>>s;
    if (s=="ABC"){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"ABC"<<endl;
    }
}
Problem p02696 (python)

Fixed submission:
# floor(a/b)=(a-(a%b))/b
# ax%b=a(x%b)%b
a,b,n=map(int,input().split())
if(n>=b-1):
    print(a*(b-1)//b)
else:
    print(a*n//b)

Buggy submission (verdict: Runtime Error):
a,b,n=map(int,input().split())
List=list(range(n+1))
List_ans=[]
for list in List:
    List_ans.append(int(a*list/b)-a*int(list/b))
print(max(List_ans))
Problem p02700 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
counter_1=0
counter_2=0
while c>0:
  c=c-b
  counter_1=counter_1+1 #counter_1は高橋の攻撃回数
while a>0:
  a=a-d
  counter_2=counter_2+1 #counter_2は青木の攻撃回数
if counter_2>=counter_1:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
while a>0 and c>0:
  c=c-b
  a=a-d
if a=0:
  print("No")
else:
  print("Yes")
Problem p02742 (python)

Fixed submission:
H,W=map(int,input().split())
if(H==1 or W==1):
  print(1)
else:
  if((H*W)%2==0):
    print(int(H*W/2))
  else:
    print(int(H*W/2)+1)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
if(H==1 or R==1):
  print(1)
else:
  if((H*W)%2==0):
    print(int(H*W/2))
  else:
    print(int(H*W/2)+1)
Problem p02830 (python)

Fixed submission:
N = int(input())
S, T = map(str, input().split())
 
s = ''
 
for i in range(N):
    s = s + S[i] + T[i]
 
print(s)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
T=input()
x = [S[i:i+1] for i in range(len(S))]
y = [T[i:i+1] for i in range(len(T))]
Problem p02923 (python)

Fixed submission:
n=int(input())
if n==1:
    print(0)
    exit()
h=list(map(int,input().split()))
height=h[0]
l=[]
cnt=0
for i in range(1,n):
    if h[i]<=height:
        cnt+=1
    else:
        cnt=0
    height=h[i]
    l.append(cnt)
print(max(l))

Buggy submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
height=h[0]
l=[]
cnt=0
for i in range(1,n):
    if h[i]<=height:
        cnt+=1
    else:
        cnt=0
    height=h[i]
    l.append(cnt)
print(max(l))
Problem p03386 (python)

Fixed submission:
a,b,k=map(int,input().split())
ans=[]
for i in range(a,min(a+k,b+1),1):
    ans.append(i)
for i in range(b,max(a,b-k),-1):
    ans.append(i)
ans=list(set(ans)) #重複を削除
ans.sort() #ソート
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
num=list(range(a,b+1))
ans=[]
if (2*k>b-a+1):
    for i in num:
        print(i)
    exit()
for i in range(k):
    ans.append(num[i])
    ans.append(num[-(i+1)])
ans=list(set(ans)) #重複を削除
ans.sort() #ソート
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
num=list(range(a,b+1))
ans=[]
if ((b-a+1)%2==0 and 2*k>=b-a) or ((b-a+1)%2==1 and 2*k>=b-a+1):
    for i in num:
        print(i)
    exit()
for i in range(k):
    ans.append(num[i])
    ans.append(num[-(i+1)])
ans=list(set(ans)) #重複を削除
ans.sort() #ソート
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
num=list(range(a,b+1))
ans=[]
if ((b-a+1)%2==0 and k>=b-a) or ((b-a+1)%2==1 and k>=b-a+1):
    for i in num:
        print(i)
    exit()
for i in range(k):
    ans.append(num[i])
    ans.append(num[-(i+1)])
ans=list(set(ans)) #重複を削除
ans.sort() #ソート
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
num=list(range(a,b+1))
ans=[]
if b-a+1<=k:
    for i in num:
        print(i)
    exit()
for i in range(k):
    ans.append(num[i])
    ans.append(num[-(i+1)])
ans=list(set(ans)) #重複を削除
ans.sort() #ソート
for i in ans:
    print(i)
Problem p03633 (python)

Fixed submission:
import math

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

n=int(input())
t=[int(input()) for i in range(n)]

LCM=t[0]
for i in range(1,n):
    LCM=lcm(LCM,t[i])

print(LCM)

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

sys.setrecursionlimit(10**6)

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

n=int(input())
t=[int(input()) for i in range(n)]

LCM=lcm(t[0],t[1])
for i in range(2,n):
    LCM=lcm(LCM,t[i])

print(LCM)

Buggy submission (verdict: Runtime Error):
import math

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

n=int(input())
t=[int(input()) for i in range(n)]

LCM=lcm(t[0],t[1])
for i in range(2,n):
    LCM=lcm(LCM,t[i])

print(LCM)
Problem p02642 (python)

Fixed submission:
import math
n = int(input())
ai = [int(i) for i in input().split()]

ai.sort()

sqr_max_val = int(ai[n-1]**0.5)
max_val = ai[n-1]
#print(ai)
ai_ex = [0]*(2*10**6)
#ai_ex = [0]*(30)

for i in range(n):
    ai_ex[ai[i]-1] += 1

for i in range(n):
    if ai_ex[ai[i]-1] > 1:
        ai_ex[ai[i]-1] = 0
    """
    if ai[i] > sqr_max_val:
        break
    """
    tmp = ai[i]
    baisu = 2
    #print(ai[i])
    while tmp * baisu <=  max_val:
        ai_ex[tmp*baisu-1] = 0
        #print(tmp*baisu)
        baisu += 1
"""
for i in range(100):
    if ai_ex[i] == 1:
        a = 1
        #print(i)
"""
print(sum(ai_ex))
#print(ai_ex)

Buggy submission (verdict: Runtime Error):
import math
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
ai = [int(i) for i in input().split()]

num_li = [0]*(10**6+1)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors



for i in range(n):
    num_li[ai[i]] += 1

ans = 0
    
for i in range(n):
    if num_li[ai[i]] > 1:
        continue
    #print(ai[i])
    flag = True
    div = make_divisors(ai[i])
    #print(div)
    for j in range(len(div)):
        if div[j] == ai[i]:
            continue
        #print(div[j],div)
        if num_li[div[j]] > 0:
            flag = False
            break
    if flag == True:
        ans += 1
    #exit()
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
ai = [int(i) for i in input().split()]

ai.sort()

sqr_max_val = int(ai[n-1]**0.5)
max_val = ai[n-1]
#print(ai)
ai_ex = [0]*(2*10**5+1)
#ai_ex = [0]*(30)

for i in range(n):
    ai_ex[ai[i]-1] += 1

for i in range(n):
    if ai_ex[ai[i]-1] > 1:
        ai_ex[ai[i]-1] = 0
    """
    if ai[i] > sqr_max_val:
        break
    """
    tmp = ai[i]
    baisu = 2
    #print(ai[i])
    while tmp * baisu <=  max_val:
        ai_ex[tmp*baisu-1] = 0
        #print(tmp*baisu)
        baisu += 1

for i in range(100):
    if ai_ex[i] == 1:
        a = 1
        #print(i)

print(sum(ai_ex))
#print(ai_ex)
Problem p02691 (python)

Fixed submission:
n = int(input())
ai = [int(i) for i in input().split()]

li = [0]*(10**6+1)

for i in range(1,n):
    if ai[i] >= 2*10**5:
        continue
    li[ai[i]-i+5*10**5] += 1

ans = 0

for i in range(1,n):
    if ai[i-1] >= 2*10**5:
        continue
    #print(i)
    ans += li[-ai[i-1]-(i-1)+5*10**5]
    if i == n:
        #print(i,i,i)
        break
    if ai[i] < 2*10**5:
        li[ai[i]-i+5*10**5] -= 1
        
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ai = [int(i) for i in input().split()]

li = [0]*(10**6+1)

for i in range(1,n):
    if ai[i] >= 2*10**5:
        continue
    li[ai[i]-i+5*10**5] += 1

ans = 0

for i in range(1,n):
    #print(i)
    ans += li[-ai[i-1]-(i-1)+5*10**5]
    if i == n:
        #print(i,i,i)
        break
    if ai[i] < 2*10**5:
        li[ai[i]-i+5*10**5] -= 1
        
print(ans)
Problem p02692 (python)

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

si = [input() for i in range(n)]

if a == 0 and b == 0 and c== 0:
    print("No")
    exit()

s1 = 0
s2 = 0

abc = [a,b,c]
moji = ['A','B','C']

def checkmoji(s):
    if s == "AB":
        s1 = 0
        s2 = 1
    elif s == 'AC':
        s1 = 0
        s2 = 2
    elif s == 'BC':
        s1 = 1
        s2 = 2
    return s1,s2

ans = []

for i in range(n):
    s1,s2 = checkmoji(si[i])
    if abc[s1] == 0 and abc[s2] == 0:
        print('No')
        exit()
    if abc[s2] == 0:
        abc[s1] -= 1
        abc[s2] += 1
        ans.append(moji[s2])
    elif abc[s1] == 0:
        abc[s1] += 1
        abc[s2] -= 1
        ans.append(moji[s1])
    else:
        
        if i == n-1:
            ans.append(moji[s1])
            break
        
        s1_a,s2_a = checkmoji(si[i+1])
        if s1 == s1_a or s1 == s2_a:
            abc[s1] += 1
            abc[s2] -= 1
            ans.append(moji[s1])
        else:
            abc[s1] -= 1
            abc[s2] += 1
            ans.append(moji[s2])
print('Yes')
for i in range(len(ans)):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n,a,b,c = map(int,input().split())

si = [input() for i in range(n)]

if a == 0 and b == 0 and c== 0:
    print("No")
    exit()

s1 = 0
s2 = 0

abc = [a,b,c]
moji = ['A','B','C']

def checkmoji(s):
    if si[i] == "AB":
        s1 = 0
        s2 = 1
    elif si[i] == 'AC':
        s1 = 0
        s2 = 2
    elif si[i] == 'BC':
        s1 = 1
        s2 = 2
    return s1,s2

ans = []

for i in range(n):
    s1,s2 = checkmoji(si[i])
    if abc[s1] <= 0 and abc[s2] <= 0:
        print('No')
        exit()
    if abc[s2] == 0:
        abc[s1] -= 1
        abc[s2] += 1
        ans.append(moji[s2])
    elif abc[s1] == 0:
        abc[s1] += 1
        abc[s2] -= 1
        ans.append(moji[s1])
    else:
        """
        if i == n-1:
            ans.append(moji[s1])
            break
        """
        s1_a,s2_a = checkmoji(si[i+1])
        if s1 == s1_a or s1 == s2_a:
            abc[s1] += 1
            abc[s2] -= 1
            ans.append(moji[s2])
        else:
            abc[s1] -= 1
            abc[s2] += 1
            ans.append(moji[s1])
print('Yes')
for i in range(len(ans)):
    print(ans[i])
Problem p02722 (python)

Fixed submission:
n = int(input())
n = n-1
ans = 0


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

li = make_divisors(n)
n = n+1
for i in range(2,n+1):
    if i**2 > n:
        break
    tmp = n
    #print(i)
    while tmp % i == 0:
        #print(tmp)
        #exit()
        tmp = tmp / i
    if tmp % i == 1:
        ans += 1
        li.append(i)
#print(li)
print(len(set(li)))

exit()

for i in range(2,n+1):
    """
    if i**2 > n:
        break
    """
    tmp = n
    #print(i)
    if tmp % i == 0:
        #print(tmp)
        #exit()
        #tmp = tmp / i
        ans += 1
        print(i)
    """
    if tmp == 1:
        ans += 1
        print(i)
    """
        
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
n = n-1
ans = 0


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

li = make_divisors(n)

for i in range(2,n+1):
    if i**2 > n:
        break
    tmp = n
    #print(i)
    while tmp % i == 0:
        #print(tmp)
        #exit()
        tmp = tmp / i
    if tmp % i == 1:
        ans += 1
        li.append(i)
        
print(unique(li)-1)

exit()

for i in range(2,n+1):
    """
    if i**2 > n:
        break
    """
    tmp = n
    #print(i)
    if tmp % i == 0:
        #print(tmp)
        #exit()
        #tmp = tmp / i
        ans += 1
        print(i)
    """
    if tmp == 1:
        ans += 1
        print(i)
    """
        
print(ans)