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

Fixed submission:
import sys
input = sys.stdin.readline
from heapq import *

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
pq = []
ans = 0

for i in range(X):
    heappush(pq, p[i])
    ans += p[i]

for i in range(Y):
    heappush(pq, q[i])
    ans += q[i]

r.sort(reverse=True)
now = ans

for i in range(C):
    now -= heappop(pq)
    heappush(pq, r[i])
    now += r[i]
    ans = max(ans, now)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
l = p[:X]+q[:Y]
l.sort()
s = sum(l)
ans = s

for i in range(C):
    ans = max(ans, s-l[i]+r[i])

print(ans)
Problem p02782 (python)

Fixed submission:
def C(n, r):
    return fact[n]*inv_table[r]*inv_table[n-r]
    
def g(r, c):
    res = 0
    
    for i in range(1, r+2):
        res += C(i+c, c)
        res %= MOD
    
    return res

r1, c1, r2, c2 = map(int, input().split())
MOD = 10**9+7
fact = [1]

for i in range(1, 2*10**6+100):
    fact.append(fact[-1]*i%MOD)
    
inv_table = [pow(fact[-1], MOD-2, MOD)]

for i in range(1, 2*10**6+100)[::-1]:
    inv_table.append(inv_table[-1]*i%MOD)

inv_table.reverse()

print((g(r2, c2)-g(r2, c1-1)-g(r1-1, c2)+g(r1-1, c1-1))%MOD)

Buggy submission (verdict: Runtime Error):
def inv(x):
    return pow(x, MOD-2, MOD)

def C(n, r):
    return fact[n]*inv(fact[r])*inv(fact[n-r])
    
def g(r, c):
    res = 0
    
    for i in range(1, r+2):
        res += C(i+c, c)
        res %= MOD
    
    return res

r1, c1, r2, c2 = map(int, input().split())
MOD = 10**9+7
fact = [1]

for i in range(1, 10**6+100):
    fact.append(fact[-1]*i%MOD)

print((g(r2, c2)-g(r2, c1-1)-g(r1-1, c2)+g(r1-1, c1-1))%MOD)
Problem p02814 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

N, M = map(int, input().split())
a = list(map(int, input().split()))
b = [ai//2 for ai in a]
    
L = 1

for bi in b:
    L = lcm(L, bi)

flag = True

for i in range(N):
    if (L-b[i])%a[i]!=0:
        flag = False
    
if not flag:
    print(0)
    exit()
    
L2 = 1

for ai in a:
    L2 = lcm(L2, ai)

if L>M:
    print(0)
else:
    print((M-L)//L2+1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

N, M = map(int, input().split())
a = list(map(int, input().split()))
b = [ai//2 for ai in a]
    
L = 1

for bi in b:
    L = lcm(L, bi)

flag = True

for i in range(N):
    if (L-b[i])%a[i]!=0:
        flag = False
    
if not flag:
    print(0)
    exit()
    
L2 = 1

for ai in a:
    L2 = lcm(L2, ai)

if L>M:
    1/0
    
if L>M:
    print(0)
else:
    print((M-L)//L2+1)
Problem p02909 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]

if S=='Sunny':
    print('Cloudy')
elif S=='Cloudy':
    print('Rainy')
else:
    print('Sunny')

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long

string S;
 
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> S;
    if (S=="Sunny") cout << "Cloudy" << endl;
    else if (S=="Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}
Problem p02929 (python)

Fixed submission:
N = int(input())
S = list(input())

for i in range(2*N):
    if (2*N-i)%2==1:
        S[i] = 'B' if S[i]=='W' else 'W'
        
if S.count('B')!=N:
    print(0)
    exit()

ans = 1
MOD = 10**9+7
B = 0

for Si in S:
    if Si=='B':
        B += 1
    else:
        ans *= B
        ans %= MOD
        B -= 1

fact = [1]

for i in range(1, N+1):
    fact.append(fact[-1]*i%MOD)

ans *= fact[N]
ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
S = input()[:-1]

if S[0]=='W':
    print(0)
    exit()
    
l = [0]
ans = 1
MOD = 10**9+7

for i in range(1, 2*N):
    if S[i]==S[i-1]:
        l.append(1^l[-1])
    else:
        l.append(l[-1])

if l.count(0)!=n:
    print(0)
    exit()
    
zero = 0

for li in l:
    if li==0:
        zero += 1
    else:
        ans *= zero
        ans %= MOD
        zero -= 1
        
for i in range(1, N+1):
    ans *= i
    ans %= MOD

print(ans)
Problem p02941 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
q = deque([])

for i in range(N):
    if B[i]>A[i] and B[i]>B[(i-1)%N]+B[(i+1)%N]:
        q.append(i)

ans = 0

while q:
    i = q.popleft()
    sub = B[(i-1)%N]+B[(i+1)%N]
    
    if B[i]%sub>=A[i]:
        ans += (B[i]-B[i]%sub)//sub
        B[i] %= sub
    else:
        if (B[i]-A[i])%sub==0:
            ans += (B[i]-A[i])//sub
            B[i] = A[i]
        else:
            print(-1)
            exit()
            
    for j in [(i-1)%N, (i+1)%N]:
        if B[j]>A[j] and B[j]>B[(j-1)%N]+B[(j+1)%N]:
            q.append(j)

if A==B:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
q = deque([])

for i in range(N):
    if B[i]>A[i] and B[i]>B[(i-1)%N]+B[(i+1)%N]:
        q.append(i)

ans = 0

while q:
    i = q.popleft()
    sub = B[(i-1)%N]+B[(i+1)%N]
    
    if B[i]%sub>=A[i]:
        ans += (B[i]-B[i]%sub)//sub
        B[i] %= sub
    else:
        if (B[i]-A[i])%sub==0:
            ans += B[i]-A[i]//sub
            B[i] = A[i]
        else:
            print(-1)
            exit()
            
    for j in [i-1, i+1]:
        if B[j]>A[j] and B[j]>B[(j-1)%N]+B[(j+1)%N]:
            q.append(j)

if A==B:
    print(ans)
else:
    print(-1)
Problem p03071 (python)

Fixed submission:
A,B=map(int,input().split())
print(max(2*A-1,2*B-1,A+B))

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
ans = max(2*A-1, 2*B-1, A*B0
print(ans)0)
Problem p03096 (python)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
C = [int(input()) for _ in range(N)]+[-1]
l = []

for i in range(N):
    if C[i]!=C[i+1]:
        l.append(C[i])

if len(l)==1:
    print(1)
    exit()
    
dp = [0]*(len(l))
acc = [0]*(2*10**5+100)
dp[0] = 1
acc[l[0]] = 1
acc[l[1]] = 1
MOD = 10**9+7

for i in range(1, len(l)):
    dp[i] = acc[l[i]]
    
    if i<len(l)-1:
        acc[l[i+1]] += dp[i]
        acc[l[i+1]] %= MOD

print(dp[-1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())
C = [int(input()) for _ in range(N)]+[-1]
l = []

for i in range(N):
    if C[i]!=C[i+1]:
        l.append(C[i])

dp = [0]*(len(l))
acc = [0]*(2*10**5+100)
dp[0] = 1
acc[l[0]] = 1
acc[l[1]] = 1
MOD = 10**9+7

for i in range(1, len(l)):
    dp[i] = acc[l[i]]
    
    if i<len(l)-1:
        acc[l[i+1]] += dp[i]
        acc[l[i+1]] %= MOD

print(dp[-1])
Problem p03128 (python)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-10**18]*(N+1)
dp[0] = 0

for i in range(N):
    for Ai in A:
        if i+nums[Ai]<=N:
            dp[i+nums[Ai]] = max(dp[i+nums[Ai]], dp[i]+1)

ans = []
now = N

for i in range(dp[N]):
    for Ai in A:
        if now-nums[Ai]>=0 and dp[now-nums[Ai]]==dp[N]-i-1:
            now -= nums[Ai]
            ans.append(str(Ai))
            break

print(''.join(ans))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-10**18]*(N+1)
dp[0] = 0

for i in range(N):
    for Ai in A:
        if i+nums[Ai]<=N:
            dp[i+nums[Ai]] = max(dp[i+nums[Ai]], dp[i]+1)

ans = []
now = N

for i in range(dp[N]):
    for Ai in A:
        if dp[now-nums[Ai]]==dp[N]-i-1:
            now -= nums[Ai]
            ans.append(str(Ai))
            break

print(''.join(ans))
Problem p03138 (python)

Fixed submission:
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
L = 100
dp = [[-float('inf')]*2 for _ in range(L+1)]
dp[0][0] = 0

for i in range(L):
    Ki = (K>>(L-1-i))&1
    
    for j in range(2):
        for k in range(2 if j else Ki+1):
            add = 0
            
            for Ai in A:
                add += k^((Ai>>(L-1-i))&1)
            
            dp[i+1][j|(k<Ki)] = max(dp[i+1][j|(k<Ki)], dp[i][j]+add*2**(L-1-i))
            
print(max(dp[L]))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
L = 50
dp = [[-10**18]*2 for _ in range(L+1)]
dp[0][0] = 0

for i in range(L):
    Ki = (K>>(L-1-i))&1
    
    for j in range(2):
        for k in range(2 if j else Ki+1):
            add = 0
            
            for Ai in A:
                add += k^((Ai>>(L-1-i))&1)
            
            dp[i+1][j|(k<Ki)] = max(dp[i+1][j|(k<Ki)], dp[i][j]+add*2**(L-1-i))

ans = max(dp[L])

if N*K>10**6:
    exit()
    
ans2 = 0

for i in range(K+1):
    ans2 = max(ans2, sum(i^Ai for Ai in A))
    
if ans!=ans2:
    1/0
Problem p03241 (python)

Fixed submission:
def make_divs(n):
    divs = []
    
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            divs.append(i)
            
            if i!=n//i:
                divs.append(n//i)
                
    divs.sort(reverse=True)
    
    return divs

N, M = map(int, input().split())
divs = make_divs(M)

for d in divs:
    if M//d>=N:
        print(d)
        exit()

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long

int N, M;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M;
    int ans = 0;
    for (int i=1; i*i<=M; i++) {
        if (M%i==0) {
            if (i*N<=M) ans = max(ans, i);
            if (i!=M/i) {
                int j = M/i;
                if (j*N<=M) ans = max(ans, j);
            }
        }
    }
    cout << ans << endl;
}
Problem p03440 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        p = x
        
        while not self.par[p]<0:
            p = self.par[p]
        
        while x!=p:
            tmp = x
            x = self.par[x]
            self.par[tmp] = p
        
        return p
    
    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        
        if rx==ry: return False
        
        if self.rank[rx]<self.rank[ry]:
            rx, ry = ry, rx
        
        self.par[rx] += self.par[ry]
        self.par[ry] = rx
    
        if self.rank[rx]==self.rank[ry]:
            self.rank[rx] += 1
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N, M = map(int, input().split())
a = list(map(int, input().split()))
uf = Unionfind(N)

for _ in range(M):
    x, y = map(int, input().split())
    uf.unite(x, y)

d = defaultdict(list)
rs = set()

for i in range(N):
    r = uf.root(i)
    rs.add(r)
    d[r].append(a[i])

if len(rs)==1:
    print(0)
    exit()

if 2*(len(rs)-1)>N:
    print('Impossible')
    exit()
    
ans = 0

for k in d.keys():
    d[k].sort()
    ans += d[k][0]

l = []

for v in d.values():
    l += v[1:]

l.sort()
ans += sum(l[:len(rs)-2])

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import defaultdict

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        p = x
        
        while not self.par[p]<0:
            p = self.par[p]
        
        while x!=p:
            tmp = x
            x = self.par[x]
            self.par[tmp] = p
        
        return p
    
    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        
        if rx==ry: return False
        
        if self.rank[rx]<self.rank[ry]:
            rx, ry = ry, rx
        
        self.par[rx] += self.par[ry]
        self.par[ry] = rx
    
        if self.rank[rx]==self.rank[ry]:
            self.rank[rx] += 1
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N, M = map(int, input().split())
a = list(map(int, input().split()))
uf = Unionfind(N)

for _ in range(M):
    x, y = map(int, input().split())
    uf.unite(x, y)

d = defaultdict(list)
rs = set()

for i in range(N):
    r = uf.root(i)
    rs.add(r)
    d[r].append(a[i])

if len(rs)==1:
    print(0)
    exit()

if 2*(len(rs)-1)>N:
    print('Impossible')
    exit()
    
ans = 0

for k in d.keys():
    d[k].sort()
    ans += d[0]

l = []

for v in d.values():
    l += v[1:]

l.sort()
ans += sum(l[:len(rs)-2])

print(ans)
Problem p02584 (python)

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    x,k,d = LI()
    if x == 0:
        if k % 2 == 1:
            print(d)
        else:
            print(0)
        return
    else:
        s = abs(x) // x
    c = abs(x) // d

    ans = 0
    if c >= k:
        ans = x - d * k * s
    else:
        ans = x - d * c * s
        if (k-c) % 2 == 1:
            ans = ans - d * s
    print(abs(ans))
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    x,k,d = LI()
    s = abs(x) // x
    c = abs(x) // d

    ans = 0
    if c >= k:
        ans = x - d * k * s
    else:
        ans = x - d * c * s
        if (k-c) % 2 == 1:
            ans = ans - d * s
    print(abs(ans))
if __name__ == '__main__':
    main()
Problem p02588 (python)

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():

    N = int(input())
    d = [[0] * 19 for _ in range(19)]
    c = []
    for _ in range(N):
        x = round(float(input()) * 10**9)
        d2 = 0
        d5 = 0
        while x % 2 == 0 and d2 < 18:
            x //= 2
            d2 += 1
        while x % 5 == 0 and d5 < 18:
            x //= 5
            d5 += 1
        d[d2][d5] += 1

    a = [[0] * 19 for _ in range(19)]
    for i in range(18,-1,-1):
        s = 0
        for j in range(18,-1,-1):
            s += d[i][j]
            a[i][j] = s
            if i < 18:
                a[i][j] += a[i+1][j]

    ans = 0
    for i in range(19):
        for j in range(19):
            ans += d[i][j] * a[18-i][18-j]
            if i >= 9 and j >=9:
                ans -= d[i][j]


    print(ans//2)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 2 ** 31 - 1
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    cnt = collections.Counter()
    ans = 0
    C = []
    for _ in range(N):
        s = SI()
        a = []
        bit = 0
        for x in s:
            x = ord(x) - ord('a')
            bit |= 1 << x
            a.append(bit)
        for i in range(len(s),-1,-1):
            if i == len(s):
                c = 0
            else:
                c = (c * 27 + ord(s[i]) - ord('a') + 1) % MOD
            if i > 0:
                d = c * 27
                for j in range(26):
                    if a[i-1] & (1<<j) and i < 0:
                        cnt[(d+j+1)%MOD] += 1
        C.append(c)
    for c in C:
        ans += cnt[c] - 1

    print(ans)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 2 ** 31 - 1
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    cnt = collections.Counter()
    ans = 0
    C = []
    for _ in range(N):
        s = SI()
        a = []
        bit = 0
        for x in s:
            x = ord(x) - ord('a')
            bit |= 1 << x
            a.append(bit)
        for i in range(len(s),-1,-1):
            if i == len(s):
                c = 0
            else:
                c = (c * 27 + ord(s[i]) - ord('a') + 1) % MOD
            if i > 0:
                d = c * 27
                for j in range(26):
                    if a[i-1] & (1<<j) & i < 0:
                        cnt[(d+j+1)%MOD] += 1
        C.append(c)
    for c in C:
        ans += cnt[c] - 1

    print(ans)
if __name__ == '__main__':
    main()
Problem p02609 (python)

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [-int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    N = NI()
    X = SI()

    cnt = [0] * (N+1)
    for i in range(1,N+1):
        x = i % bin(i).count('1')
        if x == 0:
            cnt[i] = 1
        else:
            cnt[i] = cnt[x] + 1

    xc = X.count('1')
    xp = 0
    xm = 0
    xpb = 1
    xmb = 1
    for i in range(N-1,-1,-1):
        xp = (xp + int(X[i]) * xpb) % (xc+1)
        if xc > 1:
            xm = (xm + int(X[i]) * xmb) % (xc-1)
            xmb = (xmb * 2) % (xc - 1)
        else:
            xm = 0
            xmb = 0
        xpb = (xpb * 2) % (xc+1)

    for i in range(N):
        if X[i] == '0':
            x = (xp + pow(2,N-i-1,xc+1)) % (xc+1)
        else:
            if xc > 1:
                x = (xm - pow(2,N-i-1,xc-1)) % (xc-1)
            else:
                x = -1
        if x < 0:
            print(0)
        else:
            print(cnt[x]+1)



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [-int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    N = NI()
    X = SI()

    cnt = [0] * (N+1)
    for i in range(1,N+1):
        x = i % bin(i).count('1')
        if x == 0:
            cnt[i] = 1
        else:
            cnt[i] = cnt[x] + 1

    xc = X.count('1')
    xp = 0
    xm = 0
    xpb = 1
    xmb = 1
    for i in range(N-1,-1,-1):
        xp = (xp + int(X[i]) * xpb) % (xc+1)
        xm = (xm + int(X[i]) * xmb) % (xc-1)
        xpb = (xpb * 2) % (xc+1)
        xmb = (xmb * 2) % (xc-1)

    for i in range(N):
        if X[i] == '0':
            x = (xp + pow(2,N-i-1,xc+1)) % (xc+1)
        else:
            x = (xm - pow(2,N-i-1,xc-1)) % (xc-1)
        print(cnt[x]+1)



if __name__ == '__main__':
    main()
Problem p02642 (python)

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()

    y = [0] * (10**6 + 1)
    z = [0] * (10**6 + 1)
    A = []
    for x in sys.stdin.readline().split():
        x = int(x)
        A.append(x)
        y[x] += 1
        if y[x] == 1:
            c = x * 2
            while c <= 10**6:
                z[c] = 1
                c += x

    ans = 0
    for i in range(N):
        x = A[i]
        if y[x] > 1: continue

        if z[x] == 0:
            ans += 1

    print(ans)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()

    y = [0] * (10**6 + 1)
    A = []
    for x in sys.stdin.readline().split():
        x = int(x)
        A.append(x)
        y[x] += 1

    ans = 0
    for i in range(N):
        x = A[i]
        if x > 1:
            if y[1] : continue
        if y[x] > 1: continue

        f = 1
        for j in range(2,int(math.sqrt(x))+1):
            if y[j] or y[x//j]:
                if i % j == 0
                    f = 0
                    break
        ans += f

    print(ans)
if __name__ == '__main__':
    main()
Problem p02692 (python)

Fixed submission:
import sys,math,copy,queue,itertools,bisect,collections
from heapq import *
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(-1,0),(0,1),(0,-1))

n,a,b,c = LI()
z = [a,b,c]
s = [sys.stdin.readline().rstrip() for _ in range(n)]
ans = []
for i in range(n):
    x = s[i]
    p = -1
    if x == 'AB': j=0;k=1;l=2
    elif x == 'AC': j=0;k=2;l=1
    elif x == 'BC': j=1;k=2;l=0
    if z[j] > z[k]:
        z[j] -= 1; z[k] += 1
        p = k
    else:
        z[j] += 1; z[k] -= 1
        p = j
    if (z[j] == 0 or z[k] == 0) and z[l] == 0:
        if i < n-1:
            y = s[i+1]
            if y == 'AB': j1=0;k1=1;l1=2
            elif y == 'AC': j1=0;k1=2;l1=1
            elif y == 'BC': j1=1;k1=2;l1=0
            if z[j1] == 0 and z[k1] == 0:
                if z[j] == 0:
                    z[j] += 2; z[k] -= 2
                    p = j
                else:
                    z[j] -= 2; z[k] += 2
                    p = k
    if min(z) < 0:
        print('No')
        exit(0)
    if p==0:ans.append('A')
    elif p==1:ans.append('B')
    else: ans.append('C')
print('Yes')
print(*ans,sep='\n')

Buggy submission (verdict: Runtime Error):
import sys,math,copy,queue,itertools,bisect,collections
from heapq import *
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(-1,0),(0,1),(0,-1))

n,a,b,c = LI()
z = [a,b,c]
s = [sys.stdin.readline().rstrip() for _ in range(n)]
ans = []
for i in range(n):
    x = s[i]
    p = -1
    if x == 'AB': j=0;k=1;l=2
    elif x == 'AC': j=0;k=2;l=1
    elif x == 'BC': j=1;k=2;l=0
    if z[j] > z[k]:
        z[j] -= 1; z[k] += 1
        p = k
    else:
        z[j] += 1; z[k] -= 1
        p = j
    if (z[j] == 0 or z[k] == 0) and z[l] == 0:
        if i < n+1:
            y = s[i+1]
            if x == 'AB': j1=0;k1=1;l1=3
            elif x == 'AC': j1=0;k1=2;l1=1
            elif x == 'BC': j1=1;k1=2;l1=0
            if z[j1] == 0 and z[k1] == 0:
                if z[j] == 0:
                    z[j] += 2; z[k] -= 2
                    p = j
                else:
                    z[j] -= 2; z[k] += 2
                    p = k
    if min(z) < 0:
        print('No')
        exit(0)
    if p==0:ans.append('A')
    elif p==1:ans.append('B')
    else: ans.append('C')
print('Yes')
print(*ans,sep='\n')