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

Fixed submission:
s = list(input())
s = set(s)
ls = [chr(i) for i in range(97, 97+26)]
ls = set(ls)
b = ls-s
b = list(b)
if  b == []:
    print("None")
else:
    b.sort()
    print(b[0])

Buggy submission (verdict: Runtime Error):
s = list(input())
s = set(s)
ls = [chr(i) for i in range(97, 97+26)]
ls = set(ls)
b = ls-s
b = list(b)
b.sort()
print(b[0])
Problem p03626 (python)

Fixed submission:
def main():
    n = int(input())
    ls1 = list(input())
    ls2 = list(input())

    if ls1[0]==ls2[0]:
        ans = 3
        i =1
        flg = "b"
    else:
        ans = 6
        flg = "a"
        i =2

    while 1:

        if i >= n:
            break

        if ls1[i]==ls2[i]:
            if flg == "a":
                flg = "b"
            else:
                ans = (ans*2)%(10**9+7)

            i += 1

        else:
            if flg == "a":
                ans = (ans*3)%(10**9+7)
            else:
                ans = (ans*2)%(10**9+7)
                flg = "a"

            i += 2
        if i >= n:
            break

    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    ls1 = list(input())
    ls2 = list(input())

    if ls1[0]==ls2[0]:
        ans = 3
        i =1
        flg = "b"
    else:
        ans = 3
        flg = "a"
        i =2

    while 1:


        if ls1[i]==ls2[i]:
            if flg == "a":
                flg = "b"
            else:
                ans = (ans*2)%(10**9+7)

            i += 1

        else:
            if flg == "a":
                ans = (ans*3)%(10**9+7)
            else:
                ans = (ans*2)%(10**9+7)
                flg = "a"

            i += 2
        if i >= n:
            break

    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    ls1 = list(input())
    ls2 = list(input())

    if ls1[0]==ls2[0]:
        ans = 3
        i =1
        flg = "b"
    else:
        ans = 3
        flg = "a"
        i =2
    
    while 1:


        if ls1[i]==ls2[i]:
            if flg == "a":
                flg = "b"
            else:
                ans = (ans*2)%(10**9+7)

            i += 1

        else:
            if flg == "a":
                ans = (ans*3)%(10**9+7)
            else:
                ans = (ans*2)%(10**9+7)
                flg = "a"
            
            i += 2
        if i >= n:
            break
    
    print(ans)

if __name__ == "__main__":
    main()
Problem p03658 (python)

Fixed submission:
n,k = map(int,input().split())
l = [int(x) for x in input().split()]

l.sort(reverse=True)
print(sum(l[:k]))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
l = [input() for _ in range(n)]

l.sort(reverse=True)
print(sum(l[:k]))
Problem p03671 (python)

Fixed submission:
ls = [int(x) for x in input().split()]
print(sum(ls)-max(ls))

Buggy submission (verdict: Runtime Error):
ls = list(input())
l = len(ls)
from collections import Counter

for i in range(l):
    ls.pop(-1)
    ls.pop(-1)
    c = Counter(ls)
    if all(j%2==0 for j in c.values()):
        print(len(ls))
        break
Problem p03673 (python)

Fixed submission:
n =int(input())
a = list(map(str,input().split()))
lss = []
lse = []
if n%2==0:
    for i in range(n//2):
        lss.append(a[2*i])
    for i in range(n//2):
        lse.append(a[n-(2*i+1)])

else:
    for i in range(n//2):
        lss.append(a[2*i+1])
    for i in range(n//2+1):
        lse.append(a[n-2*i-1])


ls = lse+lss

print(" ".join(ls))

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

a = [str(x) for x in input().split()]

ls = []

ls.append(a[0)
if n%2==0:
    for i in range(1,n):
        if i%2==0:
            ls.append(a[i])
        else:
            ls.insert(0,a[i])
else:
    for i in range(1,n):
        if i%2==1:
            ls.append(a[i])
        else:
            ls.insert(0,a[i])

print(" ".join(ls))
Problem p03680 (python)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]

i = 1
f = a[0]
while i< 10**6:
    
    if f == 2:
        print(i)
        break
    elif i>n+1:
        print(-1)
        break
    else:
        f = a[f-1]
        i+=1

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]


def solve(a,index,l):
    if l == len(a)+1:
        return print(-1)

    value = a[index-1]
    if value == 2:
        return print(l)
    else:
        solve(a,value,l+1)
    
solve(a,1,1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]
index = a.index(1)+1

def solve(a,index,l):
    if l == len(a)+1:
        return print(-1)

    value = a[index-1]
    if value == 2:
        return print(l)
    else:
        solve(a,value,l+1)
    
solve(a,index,0)
Problem p03693 (python)

Fixed submission:
r,g,b = map(str,input().split())

n = r+g+b
flg = "NO"
if int(n)%4 == 0:
    flg = "YES"
    
print(flg)

Buggy submission (verdict: Runtime Error):
r,g,b = map(str,input().split())

n = r+b+g
flg = "No"
if n%4 == 0:
    flg = "Yes"
    
print(flg)
Problem p03814 (python)

Fixed submission:
s = input()
a=0
z=0

for i in range(len(s)):
    if s[i]=="A":
        a = i
        break

for j in range(len(s)):
    if s[-j-1]=="Z":
        z = len(s)-j-1
        break

print(z-a+1)

Buggy submission (verdict: Runtime Error):
s = input()
a=0
z=0

for i in range(len(s)):
    if s[i]=="A":
        a = i
        break

for j in range(len(s)):
    if s[-j-1]=="Z":
        z = len(s)-j-1
		break
print(z-a+1)
Problem p03827 (python)

Fixed submission:
x=0
x_max = 0

n = int(input())
s = input()

for i in s:
    if i == "I":
        x += 1
    else:
        x -= 1
    x_max = max(x_max,x)

print(x_max)

Buggy submission (verdict: Runtime Error):
x=0
s_max = 0

n = int(input())
s = input()

for i in s:
    if i == "I":
        x += 1
    else:
        x -= 1
    x_max = max(x_max,x)

print(x_max)
Problem p03844 (python)

Fixed submission:
ls = [x for x in input().split()]

if ls[1]=="+":
    print(int(ls[0])+int(ls[2]))
else:
    print(int(ls[0])-int(ls[2]))

Buggy submission (verdict: Runtime Error):
ls = [x for x in input().split()]

if ls[1]=="+":
    print(int(ls[0]+ls[2]))
else:
    print(int(ls[0]-ls[2]))
Problem p03862 (python)

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

cnt = 0

for i in range(n-1):
    if a[i]+a[i+1]<=x:
        pass
    else:
        if (a[i+1]+a[i])-x > a[i+1]:
            cnt += (a[i+1]+a[i])-x
            a[i+1] = 0

        else:
            cnt += (a[i+1]+a[i])-x
            a[i+1] -= (a[i+1]+a[i])-x

print(cnt)

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

cnt = 0

for i in range(1,n):
    if a[i-1]+a[i]<=x:
        pass
    else:
        if (a[i]+a[i-1])-x > a[i]
            a[i] = 0
            cnt += (a[i]+a[i-1])-x
        else:    
            cnt += (a[i]+a[i-1])-x
            a[i]-= (a[i]+a[i-1])-x

print(cnt)
Problem p03957 (python)

Fixed submission:
def main():
    s = list(input())
    for i in range(len(s)):
        for j in range(i+1,len(s)):
            if s[i]=="C" and s[j]=="F":
                print("Yes")
                exit()
    print("No")

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    s = list(input())
    for i in range(len(s)):
        if s[i]=="C":
            idx = i
            break

    for j in range(idx,len(s)):
        if s[j]=="F":
            print("Yes")
            exit()

    print("No")

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    s = input()
    for i in range(len(s)):
        if s[i]=="C":
            idx = i
            break

    for j in range(idx,len(s)):
        if s[j]=="F":
            print("Yes")
            exit()

    print("No")

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    s = input()
    for i in range(len(s)):
        if s[i]=="C":
            idx = i
            break

    for i in range(idx,len(s)):
        if s[i]=="F":
            print("Yes")
            exit()

    print("No")

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    s = input()
    for i in range(len(s)):
        if s[i]=="C":
            idx = i
            break

    for i in range(idx+1,len(s)):
        if s[i]=="F":
            print("Yes")
            exit()

    print("No")

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

Fixed submission:
if __name__ =="__main__":
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]

    now_t,now_a = ls[0]

    for i in range(1,n):
        x = max([~-now_t//ls[i][0] +1 ,~-now_a//ls[i][1] +1])
        now_t,now_a = x*ls[i][0],x*ls[i][1]
    print(now_t+now_a)

Buggy submission (verdict: Runtime Error):
if __name__ =="__main__":
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]

    now_t,now_a = ls[0]

    for i in range(1,n):
        x = max([~-now_t/ls[i][0] +1 ,~-now_a/ls[i][1] +1])
        now_t,now_a = x*ls[i][0],x*ls[i][1]
    print(now_t+now_a)

Buggy submission (verdict: Runtime Error):
if __name__ =="__main__":
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]

    now_t,now_a = ls[0]

    for i in range(1,n):
        x = max([~-now_t/ls[i][0]+1 ,~-now_a/ls[i][1]+1])
        now_t,now_a = x*ls[i][0],x*ls[i][1]
    print(now_t+now_a)
Problem p04029 (python)

Fixed submission:
n = int(input())

c = 0
for i in range(n+1):
    c +=i
print(c)

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

c = 0
for i in range(n+1)
    c +=i
print(c)
Problem p04043 (python)

Fixed submission:
ls = list(map(int,input().split()))
ls.sort()
 
if ls[0]==5 and ls[1]==5 and ls[2]==7:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
    vector<int> a(3);

    rep(i,3){
        cin >> a[i];
    }

    sort(a.begin(),a.end());

    if (a[0]!=5){
        cout << "NO" << endl;
        exit(0);
    }
    if (a[1]!=5){
        cout << "NO" << endl;
        exit(0);
    }
    if (a[2]!=7){
        cout << "NO" << endl;
        exit(0);
    }

    cout << "YES";
    return 0;
}
Problem p02850 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

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

ans = [None]*(n-1)
def rec(cur,color):
    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1
rec(0, 0)
print(max(ans))
print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
N= int(input())

G = [[]*N for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append([b-1, i])

ans = [0]*(N-1)

def func(prt, col):
    cnt = 1
    for cld, org in G[prt]:
        if cnt==org:
            cnt += 1
        ans[org] = cnt
        func(cld, cnt)
        cnt += 1

func(0, 0)

print(max(ans))
for i in range(N-1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append([b,i])

ans = [None]*(n-1)
def rec(cur,color):
    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1
rec(0, 0)
print(max(ans))
print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
N = int(input())
G = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int, input().split())
    G[a-1].append([b-1,i])

ans = [None]*(N-1)

def func(cur,color):
    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        func(to, cnt)
        cnt += 1
        
func(0, 0)
print(max(ans))
print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
N = int(input())

G = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append([b-1,i])

ans = [None]*(N-1)

# 引数：今回の基準頂点、前回の基準頂点と今回の頂点を結ぶ辺の色番号
def func(ver, color):
    # 色番号。まずは最低の番号から始める。もし今回と前回の基準頂点の色番号1の場合は後で色番号変更
    cnt = 1
    # for (基準頂点と繋がっている頂点, 辺の番号) in 基準頂点
    for (to, i) in G[ver]:
        # 既使用（前回の基準頂点と今回の頂点を結ぶ辺の色）と今回使う色番号が同じなら+1で色番号変更
        if cnt==color:
            cnt += 1
        # i番目の辺における色番号
        ans[i] = cnt
        # 今回の頂点と、今回の頂点と基準頂点の辺の色番号を入力し、今回の頂点を次の基準頂点にする
        func(to, cnt)
        # 今回の基準頂点と繋がる次の頂点の処理をするために色番号変更
        cnt += 1

func(0, 0)

print(max(ans))

print(*ans, sep="\n")
Problem p02885 (python)

Fixed submission:
A, B = map(int, input().split())

ans = A-B*2
if ans<0:
    ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):

from scipy.sparse.csgraph import floyd_warshall as fw
N, M, L = map(int, input().split())

# 町間の道の長さのマトリックスを初期値無限で作成
S = [[float("INF") for i in range(N)] for i in range(N)]

# 町間の道の長さ情報をマトリックスに入力
for i in range(M):
    a, b, c = map(int,input().split())
    S[a-1][b-1] = c
    S[b-1][a-1] = c


# ワーシャルフロイド法で最短距離のマップを生成
Sf = fw(S)

T = [[float("INF")for i in range(N)] for i in range(N)]

# 町間を補給なしで通行可能な場合は1、不可能な場合はINFとしてマトリックスを作成
# （町間距離がタンク容量より大きい場合は通行不可）
for i in range(N):
    for j in range(N):
        if Sf[i][j] <= L:
            T[i][j] = 1

# ワーシャルフロイド法で町間移動可否のマップを生成
# すぐ上のfor文で、補給なしで移動できない町間の移動コストはINFにしたが、
# この処理で複数回の補給を行えば移動できる距離を
Tf = fw(T)

for i in range(int(input())):
    a, b = map(int, input().split())
    if Tf[a-1][b-1] != float("INF"):
        print(int(Tf[a-1][b-1])-1)
    else:
        print(-1)
Problem p02889 (python)

Fixed submission:

from scipy.sparse.csgraph import floyd_warshall as fw
N, M, L = map(int, input().split())

# 町間の道の長さのマトリックスを初期値無限で作成
S = [[float("INF") for i in range(N)] for i in range(N)]

# 町間の道の長さ情報をマトリックスに入力
for i in range(M):
    a, b, c = map(int,input().split())
    S[a-1][b-1] = c
    S[b-1][a-1] = c


# ワーシャルフロイド法で最短距離のマップを生成
Sf = fw(S)

T = [[float("INF")for i in range(N)] for i in range(N)]

# 町間を補給なしで通行可能な場合は1、不可能な場合はINFとしてマトリックスを作成
# （町間距離がタンク容量より大きい場合は通行不可）
for i in range(N):
    for j in range(N):
        if Sf[i][j] <= L:
            T[i][j] = 1

# ワーシャルフロイド法で町間移動可否のマップを生成
# すぐ上のfor文で、補給なしで移動できない町間の移動コストはINFにしたが、
# この処理で複数回の補給を行えば移動できる距離を
Tf = fw(T)

for i in range(int(input())):
    a, b = map(int, input().split())
    if Tf[a-1][b-1] != float("INF"):
        print(int(Tf[a-1][b-1])-1)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
N, M, L = map(int, input().split())

# 町間の道の長さのマトリックスを初期値無限で作成
S = [[float("INF") for i in range(N)] for i in range(N)]

# 町間の道の長さ情報をマトリックスに入力
for i in range(M):
    a, b, c = map(int,input().split())
    S[a-1][b-1] = c
    S[b-1][a-1] = c

# ワーシャルフロイド法で最短距離のマップを生成
Sf = fw(S)

T = [[float("INF")for i in range(N)] for i in range(N)]

# 町間を補給なしで通行可能な場合は1、不可能な場合はINFとしてマトリックスを作成
# （町間距離がタンク容量より大きい場合は通行不可）
for i in range(N):
    for j in range(N):
        if Sf[i][j] <= L:
            T[i][j] = 1

# ワーシャルフロイド法で町間移動可否のマップを生成
# すぐ上のfor文で、補給なしで移動できない町間の移動コストはINFにしたが、
# この処理で複数回の補給を行えば移動できる距離を
Tf = fw(T)

for i in range(int(input())):
    a, b = map(int, input().split())
    if Tf[a-1][b-1] != float("INF"):
        print(int(Tf[a-1][b-1])-1)
    else:
        print(-1)
Problem p02936 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,Q = map(int,readline().split())
ABPX = list(map(int,read().split()))
AB = iter(ABPX[:N+N-2])
PX = iter(ABPX[N+N-2:])

graph = [[] for _ in range(N+1)]
for a,b in zip(AB,AB):
    graph[a].append(b)
    graph[b].append(a)

val = [0] * (N+1)
for p,x in zip(PX,PX):
    val[p] += x

stack = [1]
parent = [0] * (N+1)
while stack:
    x = stack.pop()
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
        val[y] += val[x]

print(' '.join(map(str,val[1:])))

Buggy submission (verdict: Runtime Error):


n,q = map(int, input().split())

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

add = [0]*n
for _ in range(q):
    p,x = map(int, input().split())
    add[p-1] += x

ans = [0]*n

def dfs(v,p,value):
    value += add[v]
    ans[v] = value
    for c in g[v]:
        if c == p: continue
        dfs(c,v,value)

dfs(0,-1,0)

print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())

g = [[] for _ in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

add = [0]*N

for _ in range(Q):
    p, x = map(int, input().split())
    add[p-1] += x

ans = [0]*N

def func(v, p, val):
    val += add[v]
    ans[v] = val
    for c in g[v]:
        if c==p: continue
        func(c, v, val)

func(0, -1, 0)

print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())

g = [[] for _ in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

add = [0]*N

for _ in range(Q):
    p, x = map(int, input().split())
    add[p-1] += x

ans = [0]*N

def func(v, p, val):
    val += add[v]
    ans[v] = val
    for c in g[v]:
        if c==p:
            continue
        func(c, v, val)

func(0, -1, 0)

print(*ans)
Problem p02972 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

A = [0] + A
for i in range(N//2, 0, -1):
    A[i] = sum(A[i::i])%2
ans = [i for i in range(N+1) if A[i]]
print(len(ans))
print(*ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    
    
B = []
B.append(A[0])
pre = A[0]
cnt = 0
for i in range(1, N):
    if A[i] > B[cnt] and A[i] > pre:
        pre = A[i]
    elif A[i] <= pre:
        if A[i] <= B[cnt]:
            pre = A[i]
            B.append(A[i])
            cnt += 1
        else:
            del B[-1]
            if A[i] > max(B):
                pre = A[i]
            else:
                cnt += 1
                pre = A[i]
print(cnt+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    
    
B = []
B.append(A[0])
pre = A[0]
cnt = 0
for i in range(1, len(A)):
    if A[i] > B[cnt] and A[i] > pre:
        pre = A[i]
    elif A[i] <= pre:
        if A[i] <= B[cnt]:
            pre = A[i]
            B.append(A[i])
            cnt += 1
        else:
            del B[-1]
            if A[i] > max(B):
                pre = A[i]
            else:
                cnt += 1
                pre = A[i]
print(cnt+1)
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())
C = []
flag = False
for i in range(L, R+1):
    if i%2019==0:
        flag = True
        break
    else:
        C.append(i)
        
if flag:
    print(0)
else:
    import itertools
    ans = 4080400
    for x, y in list(itertools.combinations(C, 2)):
        if (x*y)%2019<ans:
            ans = (x*y)%2019
    print(ans)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
C = []
flag = False
for i in range(L, R+1):
    if i%2019==0:
        flag = True
        break
    else:
        C.append(i)
        
if flag:
    print(0)
else:
    ans = 4080400
    for x, y in list(itertools.combinations(C, 2)):
        if (x*y)%2019<ans:
            ans = (x*y)%2019
    print(ans)
Problem p02995 (python)

Fixed submission:
A, B, C, D = map(int, input().split())

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - D_s
if A%D==0:
    D_cnt += 1

import fractions
lcm = (C * D) // fractions.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - D_s
if A%D==0:
    D_cnt += 1

import math
lcm = (C * D) // math.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - C_s
if A%C==0:
    D_cnt += 1

import math
lcm = (C * D) // math.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)
Problem p03087 (python)

Fixed submission:

N, Q = map(int, input().split())
S = list(input())
lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l-1, r-1])
AC = []
pre = None
cnt = 0
for c in S:
    if c == "A":
        pre = "A"
    elif pre == "A" and c == "C":
        cnt += 1
        pre = None
    elif pre == "A":
        pre = None
    AC.append(cnt)
for l, r in lr:
    print(AC[r] - AC[l])

Buggy submission (verdict: Runtime Error):

N, Q = map(int, input().split())
S = input()


t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    print(t[R[i]] - t[L[i]])

Buggy submission (verdict: Runtime Error):



N, Q = map(int, input().split())

S = input()

for i in range(Q):
    cnt = 0
    l, r = map(int, input().split())
    T = S[l-1:r]
    for t in list(T):
        if t=="A":
            flag = True
        elif t=="T" and flag:
            cnt += 1
            flag = False
        else:
            flag = False
    print(cnt)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()

L = []
R = []

for i in range(Q):
    l, r = map(int, input().split())
    L.append(l-1)
    R.append(r-1)

a = [0]*N
pre = ''

for i, s in enumerate(S):
    if pre=='A' and s=='C':
        a[i] = 1
    pre = s

cnt = 0
for i in range(Q):
    cnt = sum(a[:R[i]]) - sum(a[:L[i]])
	print(cnt)
Problem p03353 (python)

Fixed submission:
s = input()
K = int(input())

s_list = list(set(s))
s_list.sort()

ans = []

def pack_in_dict_order(s_in):
    ans.append(s_in)
    if len(ans)<K:
        for s_l in s_list:
            temp = s_in + s_l
            if temp in s:
                pack_in_dict_order(temp)

for s_in in s_list:
    pack_in_dict_order(s_in)

print(ans[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())

s_list = list(set(s))
s_list.sort()

ans = []

def pack_in_dict_order(s_in):
    ans.append(s_in)
    if len(ans)==K:
        pass
    else:
        for s_l in s_list:
            temp = s_in + s_l
            if temp in s:
                pack_in_dict_order(temp)

for s_in in s_list:
    pack_in_dict_order(s_in)

print(ans[K-1])
Problem p03471 (python)

Fixed submission:
N, Y = map(int, input().split())

aMax = Y//10000

flag = False

for i in range(aMax+1):
    for j in range(N-i+1):
        if i*10000 + j*5000 + (N-i-j)*1000 == Y:
            a = i
            b = j
            c = N-i-j
            flag = True
            break
    if flag:
        break
            
if flag:
    print(a, b, c)
else:
    print(-1, -1, -1)

Buggy submission (verdict: Runtime Error):
N, Y = map(int, input().split())

Y //= 1000
xmax = Y//10
flag = True

for x in range(xmax, -1, -1):
    if flag==False:
        break
    for y in range(N-x, -1, -1):
        if 9*x + 6*y == Y - N:
            xans = x
            yans = y
            zans = N - x - y
            flag = False
            break

print(xans, yans, zans)