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

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

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

HSorted = sorted(H)

HIndexToHeight = []
HHeightToIndex = {}

for i in range(N):
    if i != 0 and HSorted[i] == HSorted[i-1]:
        continue
    HIndexToHeight.append(HSorted[i])
    HHeightToIndex[HSorted[i]] = len(HIndexToHeight) - 1

INF = 10 ** 12

heightCount = len(HIndexToHeight)

DP = []
for i in range(N):
    DP.append([])
    for j in range(K + 1):
        DP[i].append([])
        for k in range(heightCount):
            DP[i][j].append(INF)

for k in range(heightCount):
    if k == HHeightToIndex[H[0]]:
        DP[0][0][k] = H[0]
    elif K != 0:
        DP[0][1][k] = HIndexToHeight[k]

for i in range(1,N):
    currentHeight = HHeightToIndex[H[i]]
    for j in range(K + 1):
        for k in range(heightCount):
            if currentHeight > k:
                if j > 0:
                    DP[i][j][k] = min(DP[i-1][j-1][k], DP[i][j][k])
                DP[i][j][currentHeight] = min(DP[i-1][j][k] + HIndexToHeight[currentHeight] - HIndexToHeight[k], DP[i][j][currentHeight])
            elif currentHeight == k:
                DP[i][j][currentHeight] = min(DP[i-1][j][k], DP[i][j][currentHeight])
            else:
                if j > 0:
                    DP[i][j][k] = min(DP[i-1][j-1][k], DP[i][j][k])
                DP[i][j][currentHeight] = min(DP[i-1][j][k], DP[i][j][currentHeight])
ans = INF

for j in range(K + 1):
    for k in range(heightCount):
        if ans > DP[N-1][j][k]:
            ans = DP[N-1][j][k]
if K == N:
    print(0)
else:
    print(ans)

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

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

HSorted = sorted(H)

HIndexToHeight = []
HHeightToIndex = {}

for i in range(N):
    if i != 0 and HSorted[i] == HSorted[i-1]:
        continue
    HIndexToHeight.append(HSorted[i])
    HHeightToIndex[HSorted[i]] = len(HIndexToHeight) - 1

INF = 10 ** 12

heightCount = len(HIndexToHeight)

DP = []
for i in range(N):
    DP.append([])
    for j in range(K + 1):
        DP[i].append([])
        for k in range(heightCount):
            DP[i][j].append(INF)

for k in range(heightCount):
    if k == HHeightToIndex[H[0]]:
        DP[0][0][k] = H[0]
    else:
        DP[0][1][k] = HIndexToHeight[k]

for i in range(1,N):
    currentHeight = HHeightToIndex[H[i]]
    for j in range(K + 1):
        for k in range(heightCount):
            if currentHeight > k:
                if j > 0:
                    DP[i][j][k] = min(DP[i-1][j-1][k], DP[i][j][k])
                DP[i][j][currentHeight] = min(DP[i-1][j][k] + HIndexToHeight[currentHeight] - HIndexToHeight[k], DP[i][j][currentHeight])
            elif currentHeight == k:
                DP[i][j][currentHeight] = min(DP[i-1][j][k], DP[i][j][currentHeight])
            else:
                if j > 0:
                    DP[i][j][k] = min(DP[i-1][j-1][k], DP[i][j][k])
                DP[i][j][currentHeight] = min(DP[i-1][j][k], DP[i][j][currentHeight])
ans = INF

for j in range(K + 1):
    for k in range(heightCount):
        if ans > DP[N-1][j][k]:
            ans = DP[N-1][j][k]

print(ans)
Problem p02659 (python)

Fixed submission:
A, B = input().split()
A = int(A)
B = round(float(B) * 100)
print(A*B//100)

Buggy submission (verdict: Runtime Error):
A, B = input().split()
A = int(A)
B = int(B * 100)
print(A*B//100)
Problem p02597 (python)

Fixed submission:
N = int(input())
c = input()
rlist = []
wlist = []
for i in range(N):
    if c[i] == 'R':
        rlist.append(i)
    else:
        wlist.append(i)

cnt = 0
if len(rlist) == 0:
    print(0)
    exit()
for i in range(len(wlist)):
    if wlist[i] < rlist[-cnt - 1]:
        cnt += 1
    else:
        break
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
c = input()
rlist = []
wlist = []
for i in range(N):
    if c[i] == 'R':
        rlist.append(i)
    else:
        wlist.append(i)

cnt = 0
for i in range(len(wlist)):
    if wlist[i] < rlist[-cnt - 1]:
        cnt += 1
    else:
        break
print(cnt)
Problem p02629 (python)

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

for i in range(1, 15):
    if n >= 26**i:
        n -= 26**i
        continue
    ans = ""
    for j in range(i):
        ans += chr(n%26 + ord("a"))
        n //= 26
    print(ans[::-1])
    break

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

al = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

for i in reversed(range(10)):
    if n//(26**i):
        print(al[n//26**i-1], end="")
        n = n%(26**i)
Problem p02659 (python)

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

a = int(a)
b = int(b.replace(".", ""))

if a * b >= 100:
    print(str(a*b)[:-2])
else:
    print(0)

Buggy submission (verdict: Runtime Error):
l = input().split()
a = int(l[0])
b = int(float(l[1])*100.)
ans = a * b
aans = str(ans)[:-2]

print(int(aans))
Problem p02753 (python)

Fixed submission:
s = input()

if "A" in s and "B" in s:
    print("Yes")
else:
    print("No")

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

rev = 0
head = []
tail = []

for i in range(q):
    t = input().split()
    if t[0] == "1":
        rev ^= 1
    else:
        if (int(t[1])-1)^rev == 0:
            head.append(t[2])
        else:
            tail.append(t[2])

h = "".join(head)
t = "".join(tail)

if rev == 0:
    s = s[::-1]
    print(h[::-1] + s + t)
else:
    print(t[::-1] + s + h)
Problem p02773 (python)

Fixed submission:
n = int(input())

words = {}

for i in range(n):
    key = input()
    if key not in words:
        words[key] = 0
    words[key] += 1

l = []
th = max(words.values())

for i,j in words.items():
    if th == j:
        l.append(i)

l.sort()

print(*l, sep="\n", end="")

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

l = [0] * n
for i in range(n):
    l[i] = input()

k = set(l)
m = 0
ans = []

for i in k:
    cnt = l.count(i)
    if cnt > m:
        m = cnt
        ans.clear()
        ans.append(i)
    elif cnt == m:
        ans.append(i)

ans.sort()

for i in ans:
    print(i)

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

l = [0] * n
for i in range(n):
    l[i] = input()

k = set(l)
m = 0
ans = []

for i in k:
    cnt = l.count(i)
    if cnt > m:
        m = cnt
        ans.clear()
        ans.append(i)
    elif cnt == m:
        ans.append(i)

ans.sort()

print(*ans, sep="\n", end="")

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

l = [0] * n
for i in range(n):
    l[i] = input()

k = set(l)
m = 0
ans = []

for i in k:
    cnt = l.count(i)
    if cnt > m:
        m = cnt
        ans.clear()
        ans.append(i)
    elif cnt == m:
        ans.append(i)

ans.sort()

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

Fixed submission:
x = int(input())

def get_prime(n):
    p = [2]
    for i in range(3, n, 2):
        if all(i%j!=0 for j in p):
            p.append(i)
    return p

p = get_prime(x)

if x == 2:
    print(2)
else:
    if x%2 == 0:
        x += 1
    while True:
        for prime in p:
            if x%prime == 0:
                break
        else:
            print(x)
            break
        x += 2

Buggy submission (verdict: Runtime Error):
x = int(input())
if x == 2:
    print(2)
    sys.exit()
elif x%2 == 0:
    x += 1

def get_prime(n):
    p = [2]
    for i in range(3, n, 2):
        if all(i%j!=0 for j in p):
            p.append(i)
    return p

p = get_prime(x)

while True:
    for prime in p:
        if x%prime == 0:
            break
    else:
        print(x)
        break
    x += 2
Problem p03127 (python)

Fixed submission:
from fractions import gcd

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

g = a[0]

for i in range(1,n):
    g = gcd(g,a[i])

print(g)

Buggy submission (verdict: Runtime Error):
import math

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

g = a[0]

for i in range(1,n):
    g = math.gcd(g,a[i])

print(g)

Buggy submission (verdict: Runtime Error):
import math

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

g = a[0]

for i in range(1,n):
    g = math.gcd(g,a[i])

print(g)
Problem p03073 (python)

Fixed submission:
#!/usr/bin/env python3
S = input()
bf = '01' * (len(S) // 2) + '0' * (len(S) & 1)
wf = '10' * (len(S) // 2) + '1' * (len(S) & 1)
ans = 10**5
ans = min(ans, [x != y for x, y in zip(S, bf)].count(True))
ans = min(ans, [x != y for x, y in zip(S, wf)].count(True))
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
bf='01'*(len(s)//2)
wf='10'*(len(s)//2)
if len(s)%2==1:
  bf+='0'
  wf+='1'
ans=min(len([x!=y if x,y in zip(list(s),list(bf))]),len([x!=y if x,y in zip(list(s),list(wf))]))
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
bf='01'*(len(s)//2)
wf='10'*(len(s)//2)
if len(s)%2==1:
  bf+='0'
  wf+='1'
ans=min(len([x!=y if x,y in zip(s,bf)]),len([x!=y if x,y in zip(s,wf)]))
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
bf='01'*(len(s)//2)+('0'*(len(s)&1))
wf='10'*(len(s)//2)+('1'*(len(s)&1))
ans=min(len([x!=y if x,y in zip(s,bf)]),len([x!=y if x,y in zip(s,wf)]))
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
bf='01'*(len(s)//2)+'0'*(len(s)&1)
wf='10'*(len(s)//2)+'1'*(len(s)&1)
ans=min(len([x!=y if x,y in zip(s,bf)]),len([x!=y if x,y in zip(s,wf)]))
print(ans)
Problem p03104 (python)

Fixed submission:
#!/usr/bin/env python3


def f(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0


A, B = map(int, input().split())
print(f(A) ^ f(B) ^ A)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
N, M = map(int, input().split())
L = sorted(list(map(int, input().split())) for _ in range(N))

ans = 0
cnt = 0
for A, B in L:
    if cnt + B > M:
        ans += A * (M - cnt) if cnt + B > M else B
        break
    ans += A * B
    cnt += B

print(ans)
Problem p03822 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

N = int(input())

children = [[] * N for i in range(N)]
for i in range(N)[1:]:
    a = int(input()) - 1
    children[a].append(i)

def dfs(n):
    if children[n] == []:
        return 0
    dp = [dfs(child) for child in children[n]]
    dp.sort(reverse=True)
    return max(dp[i] + (i + 1) for i in range(len(dp)))

print(dfs(0))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(int(10**5))

N = int(input())
a = [int(input()) - 1 for _ in range(N)[1:]]

children = [[] * N for i in range(N)]
for i in range(N)[:-1]:
    children[a[i]].append(i + 1)

def dfs(n):
    if children[n] == []:
        return 0
    dp = [dfs(child) for child in children[n]]
    dp.sort(reverse=True)
    return max(dp[i] + (i + 1) for i in range(len(dp)))

print(dfs(0))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
N = int(input())
a = [int(input()) - 1 for _ in range(N)[1:]]

children = [[] * N for i in range(N)]
for i in range(N)[:-1]:
    children[a[i]].append(i + 1)

def dfs(n):
    if children[n] == []:
        return 0
    dp = [dfs(child) for child in children[n]]
    dp.sort(reverse=True)
    return max(dp[i] + (i + 1) for i in range(len(dp)))

print(dfs(0))
Problem p03055 (python)

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

def bfs(i):
    global depth
    depth = [0] * N
    s = [i]
    depth[i] = 1
    while s:
        v = s.pop()
        for u in adj[v]:
            if not depth[u]:
                depth[u] = depth[v] + 1
                s.append(u)

bfs(0)
i = depth.index(max(depth))
bfs(i)

print('Second' if max(depth) % 3 == 2 else 'First')

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

def dfs(v, p):
    for u in adj[v]:
        if u != p:
            depth[u] = depth[v] + 1
            dfs(u, v)

depth = [0] * N
dfs(0, -1)

i = depth.index(max(depth))

depth = [0] * N

dfs(i, -1)

print('Second' if max(depth) % 3 == 1 else 'First')
Problem p02695 (python)

Fixed submission:
from itertools import combinations_with_replacement

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


def calc(l):
    score = 0
    for a, b, c, d in cond:
        if l[b] - l[a] == c:
            score += d
    return score


ans = 0
for l in combinations_with_replacement(range(1, m + 1), n):
    cand = calc(l)
    ans = max(ans, cand)

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import combinations_with_replacement

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


def calc(l):
    score = 0
    for a, b, c, d in cond:
        if l[b] - l[a] == c:
            score += d
    return score


ans = 0
l = [0] * n
l[0] = 1


def dfs(l_len):
    if l_len == n:
        ans = max(ans, calc(l))
        return

    for i in range(l[l_len - 1], m + 1):
        l[l_len] = i
        dfs(l_len + 1)


dfs(0)
print(ans)
Problem p02726 (python)

Fixed submission:
from heapq import heappush, heappop


def dijkstra(graph: list, n: int, v_s: int, INF: int = float('inf')) -> list:
    # graph[v_from] = [v_to, ...]
    dist = [INF] * n

    dist[v_s] = 0
    heap = [(0, v_s)]  # heap = [(dist[v], v), ...]
    while heap:
        _, v_from = heappop(heap)
        for v_to in graph[v_from]:
            dist_cand = dist[v_from] + 1
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist


n, x, y = map(int, input().split())
x -= 1
y -= 1
g = [[] for _ in range(n)]
for i in range(n):
    if i - 1 >= 0:
        g[i].append(i - 1)
    if i + 1 < n:
        g[i].append(i + 1)
g[x].append(y)
g[y].append(x)

d = [dijkstra(g, n, i) for i in range(n)]
# print(*d, sep='\n')

ans = [0] * n
for i in range(n):
    for j in range(i + 1, n):
        ans[d[i][j]] += 1

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

Buggy submission (verdict: Runtime Error):
n, x, y = map(int, input().split())
x -= 1
y -= 1

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

for k in range(1, n):
    print(ans[k])
Problem p02793 (python)

Fixed submission:
def GCD(a: int, b: int) -> int:
    return a if b == 0 else GCD(b, a % b)


def LCM(a: int, b: int) -> int:
    return a * b // GCD(a, b)


MOD = 10**9 + 7
n = int(input())
a = tuple(map(int, input().split()))

MAX_a = max(a)
iinv = [1] * (MAX_a + 1)
for i in range(2, MAX_a + 1):
    iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD

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

lcm %= MOD

ans = 0
for i in range(n):
    ans += lcm * iinv[a[i]]
    ans %= MOD

print(ans)

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


def factorize(n: int) -> dict:
    f = defaultdict(int)
    while n % 2 == 0:
        f[2] += 1
        n //= 2
    p = 3
    while p * p <= n:
        while n % p == 0:
            f[p] += 1
            n //= p
        p += 2
    if n != 1:
        f[n] += 1
    return f


def _pow(b, p, mod):
    ret = 1
    while p:
        if p % 2 == 1:
            ret *= b
            ret %= mod
        b **= 2
        p //= 2
    return ret


MOD = 10**9 + 7
n = int(input())
a = tuple(map(int, input().split()))

a_fac = []
lcm_fac = defaultdict(int)
for a_i in a:
    a_fac_i = factorize(a[i])
    a_fac.append(a_fac_i)
    for k, v in a_fac_i.items():
        lcm_fac[k] = max(lcm_fac[k], v)

# print(lcm_fac)
ans = 0
for a_fac_i in a_fac:
    b_i = 1
    for k, v in lcm_fac.items():
        b_i *= _pow(k, v - a_fac_i[k], MOD)
        b_i %= MOD
    # print(i, a[i], b_i)
    ans += b_i
    ans %= MOD

print(ans)
Problem p02863 (python)

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

n, t = map(int, input().split())
dish = [tuple(map(int, input().split())) for _ in range(n)]
dish.sort()
# print(*dish, sep='\n')

dp = [[0] * (t + 1) for _ in range(n + 1)]
for i in range(n):
    for t0 in range(t):
        dp[i + 1][t0] = dp[i][t0]
    for t0 in range(t):
        t1 = min(t0 + dish[i][0], t)
        dp[i + 1][t1] = max(dp[i + 1][t1], dp[i][t1], dp[i][t0] + dish[i][1])

ans = max(dp[n])
# print(*dp, sep='\n')
# print([dp[i][-1] for i in range(n + 1)])
print(ans)

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

n, t = map(int, input().split())
dish = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0] * (t + 1) for _ in range(n + 1)]
for i in range(n):
    for t0 in range(dish[i][0]):
        dp[i + 1][t0] = dp[i][t0]
    for t0 in range(t):
        t1 = min(t0 + dish[i][0], t)
        dp[i + 1][t1] = max(dp[i + 1][t1], dp[i][t1], dp[i][t0] + dish[i][1])

ans = max(dp[n])
# print(*dp, sep='\n')
# print([dp[i][-1] for i in range(n + 1)])
print(ans)
Problem p02990 (python)

Fixed submission:
MOD = 10**9 + 7
MAX = 2000 + 5
fac = [1 for _ in range(MAX)]
for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD

def comb(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    return (fac[n] * pow(fac[k], MOD-2, MOD) % MOD) * pow(fac[n-k], MOD-2, MOD) % MOD

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

for i in range(1, k+1):
    ans = comb(k-1, i-1) * comb(n-k+1, i) % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
MAX = 2000 + 5
fact = [1 for _ in range(MAX)]
finv = [1 for _ in range(MAX)]
for i in range(2, MAX):
    fact[i] = fact[i - 1] * i % MOD
    finv[i] = pow(fact[i], MOD-2, MOD)

def comb(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    return (fac[n] * finv[k] % MOD) * finv[n-k] % MOD

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

for i in range(1, k+1):
    ans = comb(k-1, i-1) * comb(n-k+1, i) % MOD
    print(ans)
Problem p03016 (python)

Fixed submission:
import numpy as np
l, a, b, m = map(int, input().split())
# l = 107
# a = 10000000000007  # 10**13 + 7
# b = 1000000000000007  # 10**15 + 7
# m = 998244353

s_max = a + b * (l - 1)

# ten_pow[i] = 10**i
ten_pow = [1]
while ten_pow[-1] <= s_max:
    ten_pow.append(ten_pow[-1] * 10)

# d[i] = (s_j <= 10**i - 1 なるjの数)
D_MAX = len(ten_pow)
d = [0] * D_MAX
for i in range(D_MAX):
    if ten_pow[i] >= a:
        d[i] = max((ten_pow[i] - 1 - a) // b, 0)
d[-1] = l - 1

# cd[i] = ((i+1)桁のsの要素数(s_0を除く))
cd = [d[i + 1] - d[i] for i in range(len(d) - 1)]
# print(ten_pow)
# print(d)
# print(cd)

y = np.array([a, a + b, 1]).T % m
for i in range(len(cd)):
    x = np.array([[ten_pow[i + 1] % m, 1, 0], [0, 1, b], [0, 0, 1]])
    x %= m
    # print(x)
    # print('y', y)
    k = cd[i]
    while k > 0:
        if k & 1:
            y = np.dot(x, y) % m
            # print('y', y)
        x = np.dot(x, x) % m
        k = k >> 1

ans = y[0] % m
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
l, a, b, m = map(int, input().split())
# l = 107
# a = 10000000000007  # 10**13 + 7
# b = 1000000000000007  # 10**15 + 7
# m = 998244353

s_max = a + b * (l - 1)
ten_pow = [1]
while ten_pow[-1] <= s_max:
    ten_pow.append(ten_pow[-1] * 10)
D_MAX = len(ten_pow)
d = [0] * D_MAX
for i in range(D_MAX):
    if ten_pow[i] >= a:
        d[i] = (ten_pow[i] - a) // b
        if (ten_pow[i] - a) % b == 0:
            d[i] -= 1
d[-1] = l - 1
cd = [d[i + 1] - d[i] for i in range(len(d) - 1)]
# print(ten_pow)
# print(d)
# print(cd)

y = np.array([a, a + b, 1]).T % m
for i in range(len(cd)):
    x = np.array([[ten_pow[i + 1], 1, 0], [0, 1, b], [0, 0, 1]])
    x %= m
    # print(x)
    # print('y', y)
    k = cd[i]
    while k > 0:
        if k & 1:
            y = (x @ y) % m
            # print('y', y)
        x = (x @ x) % m
        k = k >> 1

ans = y[0]
print(ans)
Problem p03272 (python)

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

print(n-i+1)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
if 0 in x:
    x.remove(0)
    k -= 1
    n -= 1

if n == 0:
    print(0)
else:
    si = bisect_left(x, 0)

    ans = x[-1] - x[0]
    if si + k - 1 < len(x):
        ans = min(ans, x[si + k - 1])
    if si - k >= 0:
        ans = min(ans, abs(x[si - k]))

    for i in range(n):
        tmp_ans = 0
        if i < si and i + k -1 < len(x):
            tmp_ans = abs(x[i]) * 2 + x[i + k - 1]
            ans = min(ans, tmp_ans)
        elif i - k + 1 >= 0:
            tmp_ans = x[i] * 2 + abs(x[i - k + 1])
            ans = min(ans, tmp_ans)

    print(ans)
Problem p03315 (python)

Fixed submission:
s = input()

ans = 0
for i in range(len(s)):
    if s[i] == "+":
        ans += 1
    else:
        ans -= 1

print(ans)

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

ans = 0
for i in range(len(s)):
    if s[i] == "+":
        ans += 1ac
    else:
        ans -= 1

print(ans)
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(200000)
n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c))
    edges[b].append((a, c))

q, k = map(int, input().split())
k -= 1

visited = [0] * n
d = [0] * n
def dfs(v, c):
    for u, c2 in edges[v]:
        if visited[u] == 0:
            d[u] = c + c2
            visited[u] = 1
            dfs(u, c + c2)

visited[k] = 1
dfs(k, 0)

for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(d[x] + d[y])

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

q, k = map(int, input().split())
k -= 1

visited = [0] * n
d = [0] * n
def dfs(v, c):
    for u, c2 in edges[v]:
        if visited[u] == 0:
            d[u] = c + c2
            visited[u] = 1
            dfs(u, c + c2)

visited[k] = 1
dfs(k, 0)

for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(d[x] + d[y])
Problem p03242 (python)

Fixed submission:
print(1110-int(input()))

Buggy submission (verdict: Runtime Error):
print 1110 - input
Problem p02757 (python)

Fixed submission:
n, p = map(int, input().split())
s = list(map(int, input()))
ans = 0

if p == 2 or p == 5:
    for i, x in enumerate(s):
        if (p == 2 and not x % 2) or (p == 5 and (x == 0 or x == 5)):
            ans += i+1
    print(ans)
    exit()

s.reverse()
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = (cum[i] + s[i] * pow(10, i, p)) % p
t = [0] * p
for x in cum: t[x] += 1

for x in t:
    ans += x * (x-1) // 2
print(ans)

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())
s = list(map(int, input()))
ans = 0

if p == 2 or p == 5:
    for i, x in enumerate(s):
        if (p == 2 and not x % 2) or (p == 5 and (x == 0 or x == 5)):
            ans += i+1
    print(ans)
    exit()

s.reverse()
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = (cum[i] + s[i] * pow(10, i, p)) % p
t = [0] * 10
for x in cum: t[x] += 1

for x in t:
    ans += x * (x-1) // 2
print(ans)