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

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline

N, W = map(int, input().split())
dp = np.zeros((N, W+1), dtype='int64')

def solve(N, W):
    for i in range(0, N):
        wi, vi = map(int, input().split())
        dp[i][:wi] = dp[i-1][:wi]
        dp[i][wi:] = np.fmax(dp[i-1][wi:],
                            dp[i-1][:W+1-wi] + vi)
    return dp[N-1][W]

print(solve(N, W))

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

N, W = map(int, input().split())
dp = [0]*(W+1)

def solve(N, W): 
    for i in range(0, N):
        wi, vi = map(int, input().split())
        dp_next = [0] * (W+1)
        for w in range(1, W+1):
            if w >= wi:
                dp_next[w] = max(dp[w - wi] + vi, dp[w])
            else:
                dp_next[w] = dp[w]
        dp = dp_next
    return dp[-1]

print(solve(N, W))
Problem p03164 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N, W = map(int, input().split())
vmax = 1000*100+1
wmax = 100*10**9
dp = [wmax] * vmax
dp[0] = 0
 
for i in range(N):
    wi, vi = map(int, input().split())
    ndp = dp[:]
    for j in range(vi, vmax):
        ndp[j] = min(dp[j], dp[j-vi] + wi)
    dp = ndp

v = 0
for i, w in enumerate(dp):    
    if w == wmax:
        continue
    if w <= W:
        v = i
print(v)

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

N, W = map(int, input().split())
dp = np.zeros((N, W+1), dtype='int64')

def solve(N, W):
    for i in range(0, N):
        wi, vi = map(int, input().split())
        dp[i][:wi] = dp[i-1][:wi]
        dp[i][wi:] = np.fmax(dp[i-1][wi:],
                            dp[i-1][:W+1-wi] + vi)
    return dp[N-1][W]

print(solve(N, W))

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

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

dp = np.zeros((N, W+1), dtype='int64')

for i in range(N):
    wi, vi = map(int, input().split())

    dp[i][:wi] = dp[i-1][:wi]
    dp[i][wi:] = np.fmax(dp[i-1][wi:],
                            dp[i-1][:W+1-wi] + vi)

print(dp[N-1][W])
Problem p03165 (python)

Fixed submission:
s = input()
t = input()
dp = [[0] * (len(s)+1) for _ in range(len(t)+1)]
for i in range(1, len(t)+1):
    ti = t[i-1]
    dp[i] = dp[i-1][:]
    for j in range(1, len(s)+1):
        if ti == s[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

ans = ''
sl = len(s)
tl = len(t)
while sl > 0 and tl > 0:
    if s[sl-1] == t[tl-1]:
        sl -= 1
        tl -= 1
        ans = s[sl] + ans
        continue
    if dp[tl][sl] == dp[tl][sl-1]:
        sl -= 1
    elif dp[tl][sl] == dp[tl-1][sl]:
        tl -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
s = input()
t = input()

dp = [[0] * (len(s)+1) for _ in range(len(t)+1)]
for i in range(1, len(t)+1):
    ti = t[i-1]
    dp[i] = dp[i-1]
    for j in range(1, len(s)+1):
        if ti == s[j-1]:
            dp[i][j] = dp[i][j-1] + 1
        else:
            if dp[i][j-1] >= dp[i][j]:
                dp[i][j] = dp[i][j-1]
ans = ''
sl = len(s)
tl = len(t)
while sl > 0 and tl > 0:
    if s[sl-1] == t[tl-1]:
        sl -= 1
        tl -= 1
        ans = s[sl] + ans
        continue

    if dp[tl][sl] == dp[tl][sl-1]:
        sl -= 1
    elif dp[tl][sl] == dp[tl-1][sl]:
        tl -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
s = input()
t = input()

dp = np.zeros((len(t)+1, len(s)+1))
for i in range(1, len(t)+1):
    ti = t[i-1]
    dp[i] = dp[i-1]
    for j in range(1, len(s)+1):
        if ti == s[j-1]:
            dp[i][j] = dp[i][j-1] + 1
        else:
            if dp[i][j-1] >= dp[i][j]:
                dp[i][j] = dp[i][j-1]
ans = ''
sl = len(s)
tl = len(t)
while sl > 0 and tl > 0:
    if s[sl-1] == t[tl-1]:
        sl -= 1
        tl -= 1
        ans = s[sl] + ans
        continue

    if dp[tl][sl] == dp[tl][sl-1]:
        sl -= 1
    elif dp[tl][sl] == dp[tl-1][sl]:
        tl -= 1
print(ans)

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

dp = [0] * (len(s)+1)
dps = [[] for _ in range(len(s)+1)]
for i in range(1, len(t)+1):
    ti = t[i-1]
    for j in range(1, len(s)+1):
        sj = s[j-1]
        if ti == sj:
            dp[j] = dp[j-1] + 1
            dps[j] = (dps[j-1] + [ti]).copy()
        else:
            if dp[j-1] >= dp[j]:
                dp[j] = dp[j-1]
                dps[j] = dps[j-1][:]
print(''.join(dps[-1]))
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(lambda x: int(x)-1, input().split())
    G[x].append(y)

# iを始点としたときの有効パスの最大長さ
dp = [-1] * n
 
def rec(s):
    if dp[s] != -1:
        return dp[s]

    ret = 0
    for ns in G[s]:
        ret = max(ret, rec(ns)+1)
    dp[s] = ret
    return ret

ml = 0    
for i in range(n):
    ml = max(ml, rec(i))
print(ml)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(25000)
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(lambda x: int(x)-1, input().split())
    G[x].append(y)

# iを始点としたときの有効パスの最大長さ
dp = [-1] * n
 
def rec(s):
    if dp[s] != -1:
        return dp[s]

    ret = 0
    for ns in G[s]:
        ret = max(ret, rec(ns)+1)
    dp[s] = ret
    return ret

ml = 0    
for i in range(n):
    ml = max(ml, rec(i))
print(ml)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(lambda x: int(x)-1, input().split())
    G[x].append(y)

# iを始点としたときの有効パスの最大長さ
dp = [-1] * n

def rec(s):
    if dp[s] != -1:
        return dp[s]
    
    ret = 0
    for ns in G[s]:
        ret = max(ret, rec(ns)+1)
    dp[s] = ret
    return ret

ml = 0    
for i in range(n):
    ml = max(ml, rec(i))

print(ml)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(5000)
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(lambda x: int(x)-1, input().split())
    G[x].append(y)

# iを始点としたときの有効パスの最大長さ
dp = [-1] * n

def rec(s):
    if dp[s] != -1:
        return dp[s]
    
    ret = 0
    for ns in G[s]:
        ret = max(ret, rec(ns)+1)
    dp[s] = ret
    return ret

ml = 0    
for i in range(n):
    ml = max(ml, rec(i))

print(ml)
Problem p03294 (python)

Fixed submission:
from fractions import gcd
N = int(input())
A = tuple(map(int, input().split()))

l = A[0]
for i in range(1, N):
    l = l * A[i] // gcd(l, A[i])
l = l - 1

f = 0 
for a in A:
    f += l % a
print(f)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = tuple(map(int, input().split()))
l = np.lcm.reduce(A) - 1

f = 0 
for a in A:
    f += l % a
print(f)
Problem p03308 (python)

Fixed submission:
N = int(input())
A = tuple(map(int, input().split()))
print(max(A) - min(A))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = tuple(map(int, input().split()))
print(max(A) - min(A)
Problem p03361 (python)

Fixed submission:
h, w = map(int, input().split())
M = [input() for _ in range(h)]

ng = False
for i in range(h):
    for j in range(w):
        if M[i][j]  == '.':
            continue

        for mi, mj in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            ni = i + mi; nj = j + mj
            if ni < 0 or h <= ni or nj < 0 or w <= nj:
                continue

            if M[ni][nj] == '#':
                break
        else:
            ng=True
    if ng:
        break

if ng:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
M = [input() for _ in range(h)]

ng = False
for i in range(h):
    for j in range(w):
        if M[i][j]  == '.':
            continue

        for mi, mj in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            ni = i + mi; nj = j + mj
            if ni < 0 or h <= ni or nj < 0 or w <= nj:
                continue

            if M[ni][nj] == '#':
                break
        else:
            ng=True
    if ng:
        break
if ng:
    break

if ng:
    print('No')
else:
    print('Yes')
Problem p03488 (python)

Fixed submission:
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    dp = [{} for _ in range(len(D)+1)]
    dp[0][s] = 1
    for i in range(len(D)):
        d = D[i]
        for j in dp[i]:
            dp[i+1][j+d] = 1
            dp[i+1][j-d] = 1
    return g in dp[-1]

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    OFS = 5
    dp = [0] * (2*OFS+1)
    dp[OFS+s] = 1
    for i in range(len(D)):
        d = D[i]
        ndp = [0] * (2*OFS+1)
        for j in range(2*OFS+1):
            try:
                ndp[j] += dp[j-d]
            except:
                pass
            try:
                ndp[j] += dp[j+d]
            except:
                pass
        dp = ndp
    return dp[OFS+g] > 0

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')
Problem p03501 (python)

Fixed submission:
n, a, b = map(int, input().split())
a = n*a
print(min(a, b))

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, intput().split())
a = n*a
print(min(a, b))
Problem p03504 (python)

Fixed submission:
n, C = map(int, input().split())
cq = [[] for _ in range(C)]
stc = [tuple(map(int, input().split())) for _ in range(n)]
stc = sorted(stc, key=lambda x: x[0])

for s, t, c in stc:
    c -= 1
    if cq[c]:
        fs, ft = cq[c][-1]
        if ft != s:
            cq[c].append([s, t])
        else:
            cq[c][-1] = [fs, t]
    else:
        cq[c].append([s, t])

R = [0] * (2*10**5+2)
for qq in cq:
    for s, t in qq:
        R[2*s-1] += 1
        R[2*t+1] -= 1

from itertools import accumulate
CR = list(accumulate(R))
print(max(CR))

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

for _ in range(n):
    s, t, c = tuple(map(int, input().split()))
    if cq[c-1]:
        fs, ft = cq[c-1][-1]
        if ft != s:
            cq[c-1].append([s, t])
        else:
            cq[c-1][-1] = [fs, t]
    else:
        cq[c-1].append([s, t])

R = [0] * (2*10**5+1)
for qq in cq:
    for s, t in qq:
        R[2*s-1] += 1
        R[2*t+1] -= 1

from itertools import accumulate
CR = list(accumulate(R))

print(max(CR))
Problem p03547 (python)

Fixed submission:
a, b = input().split()
if a==b:
  print("=")
else:
  print("<" if a < b else ">")

Buggy submission (verdict: Runtime Error):
a, b input().split()
if a==b:
  print("=")
else:
  print("<" if a < b else ">")
Problem p03549 (python)

Fixed submission:
n, m = map(int, input().split())
s100 = 100*(n - m) * 2**m
s1900 = m * 1900 * 2**m
print(s100 + s1900)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
s100 = 100*(n - m) * 2**m
s1900 = m * 1900 * 2**m
print(s100 + s1900)
\
Problem p03557 (python)

Fixed submission:
n = int(input())
A = sorted(tuple(map(int, input().split())))
B = tuple(map(int, input().split()))
C = sorted(tuple(map(int, input().split())))

import bisect

count = 0
for b in B:
    # Aの候補
    la = bisect.bisect_left(A, b)
    # Cの候補
    rc = bisect.bisect_right(C, b)
    
    count += la*(n-rc)

print(count)

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

count = 0
for b in B:
    # Aの候補
    la = -1
    ra = n
    while (ra - la) > 1:
        mid = (la+ra)//2
        if A[mid] > b:
            ra = mid
        else:
            la = mid
    if A[la] != b:
        la += 1

    # Cの候補
    lc = -1
    rc = n
    while (rc - lc) > 1:
        mid = (lc+rc)//2
        if C[mid] < b:
            lc = mid
        else:
            rc = mid
    if C[rc] == b:
        rc += 1
    
    count += la*(n-rc)

print(count)

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

count = 0
for b in B:
    # Aの候補
    la = -1
    ra = n
    while (ra - la) > 1:
        mid = (la+ra)//2
        if A[mid] > b:
            ra = mid
        else:
            la = mid
    if A[la] != b:
        la += 1

    # Cの候補
    lc = -1
    rc = n
    while (rc - lc) > 1:
        mid = (lc+rc)//2
        if C[mid] < b:
            lc = mid
        else:
            rc = mid
    if C[rc] == b:
        rc += 1
        
        count += la*(n-rc)
    
    print(count)
Problem p03569 (python)

Fixed submission:
S = input()
snx = S.replace('x', '')
ls = len(S)
if ls == 1 or len(snx) == 0:
    print(0)
    exit(0)
l = 0
r = ls-1

ans = 0
while l < r:
    lxc = 0
    while S[l] == 'x':
        l += 1
        lxc += 1
    rxc = 0
    while S[r] == 'x':
        r -= 1
        rxc += 1
    ans += abs(lxc-rxc)

    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        print(-1)
        break
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
snx = S.replace('x', '')
ls = len(S)
if ls == 1:
    print(0)
    exit(0)
l = 0
r = ls-1

ans = 0
while l < r:

    lxc = 0
    while S[l] == 'x':
        l += 1
        lxc += 1
    
    rxc = 0
    while S[r] == 'x':
        r -= 1
        rxc += 1

    ans += abs(lxc-rxc)

    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        print(-1)
        break
else:
    print(ans)
Problem p03599 (python)

Fixed submission:
a,b,c,d,e,f = map(int, input().split())
ws = []
for i in range(f//100//a+1):
    for j in range(f//100//b+1):
        w = 100*(a*i+b*j)
        if 0 < w <= f:
            ws.append(w)
        if w >= f:
            break
ss = []
for i in range(f*e//(100+e)//c+1):
    for j in range(f*e//(100+e)//d+1):
        s = c*i+d*j
        if 0 <= s <= f*e//(100+e):
            ss.append(s)
n = []
for w in ws:
    for s in ss:
        if w+s > f:
            continue
        if s > e*w//100:
            continue
        n.append((s/(w+s), w+s, s))

nmax = max(n, key=lambda x:x[0])
print(nmax[1], nmax[2])

Buggy submission (verdict: Runtime Error):
a,b,c,d,e,f = map(int, input().split())
ws = []
for i in range(f//100//a+1):
    for j in range(f//100//b+1):
        w = 100*(a*i+b*j)
        if 0 < w < f:
            ws.append(w)
        if w >= f:
            break

ss = []
for i in range((f-100*a)//c+1):
    for j in range((f-100*a)//d+1):
        s = c*i+d*j
        if 0 < s < f-100*a:
            ss.append(s)

n = []
for w in ws:
    for s in ss:
        if w+s > f:
            continue
        if s > e*w//100:
            continue
        n.append((s/(w+s), w+s, s))

nmax = max(n, key=lambda x:x[0])
print(nmax[1], nmax[2])

Buggy submission (verdict: Runtime Error):
a,b,c,d,e,f = map(int, input().split())
wvs = []
va = 0
while va <= f:
    va += 100*a
    vab = va
    while vab <= f:
        wvs.append(vab)
        vab += 100*b

svs = []
vc = 0
while vc+100*a <= f:
    vc += c
    vcd = vc
    while vcd+100*a <= f:
        svs.append(vcd)
        vcd += d

n = []
for w in wvs:
    for s in svs:
        if w+s > f:
            break
        if s/w > e/100:
            break
        n.append((s/(w+s), w+s, s))

nmax = max(n, key=lambda x:x[0])
print(nmax[1], nmax[2])
Problem p03836 (python)

Fixed submission:
sx, sy, tx, ty = map(int, input().split())
dy = ty - sy
dx = tx - sx
ans = dy*'U' + dx*'R' + dy*'D' + dx*'L'
ans += 'L' + (dy+1)*'U' + (dx+1)*'R' + 'D'
ans += 'R' + (dy+1)*'D' + (dx+1)*'L' + 'U'
print(ans)

Buggy submission (verdict: Runtime Error):
sx, sy, tx, ty = map(int, input().split())
ofs = 1001
visited = [[0] * 2003 for _ in range(2003)]
stoij = {'U':[0, 1], 'D':[0,-1], 'L':[-1, 0], 'R':[1, 0]}

from collections import deque
def bfs(si, sj, gi, gj):
    q = deque([[si, sj, '']])
    visitedinbfs = [[0] * 2003 for _ in range(2003)]
    visitedinbfs[sj][si] = 1

    while q:
        i, j, s = q.popleft()
        if i == gi and j == gj:
            break

        for ns in ['U', 'D', 'L', 'R']:
            mi, mj = stoij[ns]
            ni, nj = i + mi, j + mj
            if ni < 0 or 2003 <= ni or nj < 0 or 2003 <= ni:
                continue
            if visitedinbfs[nj][ni] == 1 or visited[nj][ni] == 1:
                continue
            visitedinbfs[nj][ni] = 1
            q.append([ni, nj, s+ns])

    for ss in s:
        mi, mj = stoij[ss]
        si += mi
        sj += mj
        if si == gi and sj == gj:
            break
        visited[sj][si] = 1
    return s

ans =  bfs(sx+ofs, sy+ofs, tx+ofs, ty+ofs)
ans += bfs(tx+ofs, ty+ofs, sx+ofs, sy+ofs)
ans += bfs(sx+ofs, sy+ofs, tx+ofs, ty+ofs)
ans += bfs(tx+ofs, ty+ofs, sx+ofs, sy+ofs)
print(ans)
Problem p03994 (python)

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

ns = []
for c in s[:-1]:
    if c == 'a':
        ns.append(c)
        continue

    ofstoa = ord('z')+1-ord(c)
    if k >= ofstoa:
        ns.append(chr(ord(c) + ofstoa - 26))
        k -= ofstoa
    else:
        ns.append(c)

last = ord(s[-1])
k = k%26
if last + k > ord('z'):
    ns.append(chr(last + k - 26))
else:
    ns.append(chr(last + k))
print(''.join(ns))

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

ns = []
for c in s[:-1]:
    ofstoa = ord('z')+1-ord(c)
    if k >= ofstoa:
        ns.append('a')
        k -= ofstoa
    else:
        ns.append(c)

last = ord(s[-1])
if last + k > ord('z'):
    ns.append(chr(last + k - 26))
else:
    ns.append(chr(last + k))

print(''.join(ns))
Problem p04013 (python)

Fixed submission:
n, a = map(int, input().split())
X = tuple(map(int, input().split()))
dp = [[[0] * (2550) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1
for i in range(n):
    # i枚目までで
    for j in range(n):
        # j枚のカードを選んで
        for s in range(n*a+1):
            # 合計がsになるパターン
            if dp[i][j][s] == 0:
                continue
            # i枚目のカードが選ばれない場合
            dp[i+1][j][s] += dp[i][j][s]
            # i枚目のカードが選ばれる場合
            dp[i+1][j+1][s+X[i]] += dp[i][j][s]
ans = 0
for k in range(1, n+1):
    ans += dp[n][k][k*a]
print(ans)

Buggy submission (verdict: Runtime Error):
n, a = map(int, input().split())
X = tuple(map(int, input().split()))
dp = [[[0] * (n*max(X)+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1
for i in range(n):
    # i枚目までで
    for j in range(n):
        # j枚のカードを選んで
        for s in range(n*max(X)+1):
            # 合計がsになるパターン
            if dp[i][j][s] == 0:
                continue
            # i枚目のカードが選ばれない場合
            dp[i+1][j][s] += dp[i][j][s]
            # i枚目のカードが選ばれる場合
            dp[i+1][j+1][s+X[i]] += dp[i][j][s]
ans = 0
for k in range(1, n+1):
    ans += dp[n][k][k*a]
print(ans)
Problem p02574 (python)

Fixed submission:
from fractions import gcd

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

A = max(As)
lst = [0]*(A+1)
rlt = [0]*(A+1)

for i in range(2, A+1):
  if lst[i] > 0:
    continue
  j = 1
  while i*j <= A:
    if lst[i*j] == 0:
      lst[i*j] = i
    j += 1
  if j == 1:
    break
    
for a in As:
  tmp = -1
  while a > 1:
    if tmp != lst[a]:
      rlt[lst[a]] += 1
      tmp = lst[a]
    a //= lst[a]

r = max(rlt) 

if r < 2:
  print('pairwise coprime')
elif r < N:
  print('setwise coprime')
else:
  print('not coprime')

Buggy submission (verdict: Runtime Error):
from fractions import gcd

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

A = max(As)
lst = [0]*(A+1)
rlt = [0]*(A+1)

for i in range(2, len(lst)//2):
  if lst[i] > 0:
    continue
  j = 1
  while i*j <= A:
    if lst[i*j] == 0:
      lst[i*j] = i
    j += 1
    
for a in As:
  tmp = -1
  while a > 1:
    if tmp != lst[a]:
      rlt[lst[a]] += 1
      tmp = lst[a]
    a //= lst[a]

r = max(rlt) 

if r < 2:
  print('pairwise coprime')
elif r < N:
  print('setwise coprime')
else:
  print('not coprime')
Problem p02599 (python)

Fixed submission:
from sys import stdin
input = stdin.readline
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
n, q = map(int, input().split())
tmp = list(map(int, input().split()))
color = [-1]
for v in tmp:
    color.append(v)
qry = [None]*q
ans = [0]*q
p = 0
for _ in ans:
    l, r = map(int, input().split())
    qry[p] = [l-1, r, p]
    p += 1
qry.sort(key=lambda x: x[1])
dic = {}
last_update_idx = 1
bit = Bit(n)
for l, r, i in qry:
    if last_update_idx < r+1:
        st = set()
        for j in range(last_update_idx, r+1):
            if not color[j] in st and color[j] in dic:
                bit.add(dic[color[j]], -1)
            dic[color[j]] = j
            st.add(color[j])
        for v in st:
            bit.add(dic[v], 1)
        last_update_idx = r+1
    ans[i] = bit.sum(r) - bit.sum(l)
for v in ans:
    print(v)

Buggy submission (verdict: Runtime Error):
#####segfunc######
def segfunc(x,y):
    return x + y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

n, Q = map(int, input().split())
Cs = [0] + list(map(int, input().split()))
Qs = []
for i in range(Q):
  l,r = map(int, input().split())
  Qs.append((i,l,r))
Qs.sort(key=lambda x:x[2])  

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

ans = [-1]*Q
dic = {}
b = 1
 
for i,l,r in Qs:
  if b < r + 1:
    st = set()
    for j in range(b,r+1):
      if not Cs[j] in st and Cs[j] in dic:
        update(dic[Cs[j]], 0)
      st.add(Cs[j])
      dic[Cs[j]] = j
    for s in st:
      update(dic[s], 1)
    b = r + 1
  ans[i] = query(l,r+1)
    
for a in ans:
  print(a)
Problem p02843 (python)

Fixed submission:
X = int(input())

a = X // 100
b = X % 100

m = 5*a

if b > m:
  print(0)
else:
  print(1)

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

a = X // 100
b = X % 100

m = 5*a

if b > m:
  print(0)
else:
  print(1)