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

Fixed submission:
s = input()
j = 0
for i in range(len(s)):
    #print("i=",i)
    if s[i-(2*j)] == "B":
        #print(i-(2*j))
        #print(s)
        if s[0] == "B":
            s = 'x'+s[1:]
            #print(s)
            #print(s[0])
        else:
            #print(i-(2*j))
            s = s[:i-1-(2*j)]+s[i-(2*j)+1:]
            j += 1
            
            #print("s=",s)
            #print(s[:i-1-(2*j)-1])
ans = s.replace('x','')
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
j = 0
for i in range(len(s)):
    #print("i=",i)
    if s[i-(2*j)] == "B":
        #print(i-(2*j))
        #print(s)
        if s[0] == "B":
            s = 'x'+s[1:]
            #print(s)
            #print(s[0])
        else:
            #print(i-(2*j))
            s = s.replace(s[i-1-(2*j)]+s[i-(2*j)],'')
            j += 1
            s += 'xx'
            #print(s)
ans = s.replace('x','')
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
j = 0
for i in range(len(s)):
    if s[i-(2*j)] == "B":
        if s[0] == "B":
            s = s.replace(s[0],'')
            s += 'x'
        else:
            s = s.replace(s[i-1-(2*j)]+s[i-(2*j)],'')
            j += 1
            s += 'xx'
            #print(s, i-(2*j))
ans = s.replace('x','')
print(ans)
Problem p03331 (python)

Fixed submission:
def main():
    N = input()
    if N%10 != 0:
        print(digitSum(N))
    else:
        print(digitSum(N)*10)

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = input()
    if N%10 != 0:
        print(digitSum(N))
    else:
        print(digitSum(N)*10)

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

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

Fixed submission:
a,b,t = [int(i) for i in input().split()]

ans = (t + 0.5) // a * b
print(int(ans))

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

minv = -1
count = 0
s = 0
for i in range(n):
    if a[i] < 0:
        s += -a[i]
        if minv > -a[i] or minv == -1:
            minv = -a[i]
        count += 1
    else:
        s += a[i]
        if minv > a[i] or minv == -1:
            minv = a[i]

print(s)
if count % 2 == 1:
    s += 2*(-minv)

print(s)
Problem p03061 (python)

Fixed submission:
def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        c = a % b
        return gcd(b, c)

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

g_max = -1
l = [0] * n
r = [0] * n
for i in range(n):
    if i == 0:
        l[0] = 0
    else:
        l[i] = gcd(l[i-1], a[i-1])

for i in range(n-1,-1,-1):
    if i == n-1:
        r[i] = 0
    else:
        r[i] = gcd(r[i+1], a[i+1])

g_max = -1
for i in range(n):
    g = gcd(l[i], r[i])
    if g > g_max:
        g_max = g

print(g_max)

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

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

g_max = 0
for i in range(n-1):
    g = gcd(a[i], a[i+1])
    if g > g_max:
        g_max = g
if n == 3:
    g = gcd(a[0], a[2])
    if g > g_max:
        g_max = g

print(g_max)
Problem p02823 (python)

Fixed submission:
def main():
    n = 10**18
    a = 10**18
    b = 10**18
    n, a, b = map(int, input().split())

    if (b - a) % 2 == 1:
        print((b-a)//2 + (b-a) % 2 + min(a-1, n-b))
    else:
        print((b - a) // 2)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = 10**18
    a = 10**18
    b = 10**18
    n, a, b = map(int, input().split())

    if (b-a) % 2 == 1:
        t = min(a-1, n-b)
        if a-1 == t:
            a = 1
            b = b-t
            print(t + 1 + ((b-1)-a)//2)
        else:
            a = a + t
            b = n
            print(t + 1 ((b-1)-a)//2)

    else:
        print((b-a)//2)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = 10**18
    a = 10**18
    b = 10**18
    print(n, a, b)
    n, a, b = map(int, input().split())

    if (b-a) % 2 == 1:
        t = min(a-1, n-b)
        if a-1 == t:
            a = 1
            b = b-t
            print(t + 1 + ((b-1)-a)//2)
        else:
            a = a + t
            b = n
            print(t + 1 ((b-1)-a)//2)

    else:
        print((b-a)//2)


if __name__ == '__main__':
    main()

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

    if (b-a) % 2 == 1:
        t = min(a-1, n-b)
        if a-1 == t:
            a = 1
            b = b-t
            print(t + 1 + ((b-1)-a)//2)
        else:
            a = a + t
            b = n
            print(t + 1 ((b-1)-a)//2)

    else:
        print((b-a)//2)


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

Fixed submission:
from fractions import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)

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

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)
Problem p02850 (python)

Fixed submission:
from sys import stdin

input = stdin.buffer.readline

n = int(input())
v = [[] for _ in range(n+1)]
edge = [0] * -~n

ans = 0


def dfs(c,fa,x):
    global ans
    color = 1
    for to, eg in v[x]:
        if to == fa:
            continue
        if color == c:
            color += 1
        edge[eg] = color
        ans = max(ans, color)
        dfs(color, x, to)
        color += 1


def bfs(x):
    q = [[0,0,x]]
    ans = 0
    while len(q):
        c, fa, now = q.pop()
        color = 1
        for to, eg in v[now]:
            if to == fa:
                continue
            if color == c:
                color += 1
            edge[eg] = color
            q.append([color, now, to])
            ans = max(ans, color)
            color += 1
    return ans


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

print(bfs(1))
for i in range(n-1):
    print(edge[i])

Buggy submission (verdict: Runtime Error):
from sys import stdin

input = stdin.buffer.readline

n = int(input())
v = [[] for _ in range(n+1)]
edge = [0] * -~n

ans = 0


def dfs(c,fa,x):
    global ans
    color = 1
    for to, eg in v[x]:
        if to == fa:
            continue
        if color == c:
            color += 1
        edge[eg] = color
        ans = max(ans, color)
        dfs(color, x, to)
        color += 1


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

dfs(0,0,1)
print(ans)
for i in range(n-1):
    print(edge[i])
Problem p02882 (python)

Fixed submission:
import math
a, b, x = map(int, input().split())
h = x / (a * a)
if x < a*a*b / 2:
    print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
    print(math.degrees(math.atan((2*(b-x/(a*a)))/a)))

Buggy submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())
h = x / (a * a)
if x < a*a*b / 2:
    print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
    if x == a*a*b:
        print(0)
    print(90-math.degrees(math.atan(a/(2*(b-x/(a*a))))))

Buggy submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())
h = x / (a * a)
if x < a*a*b / 2:
    print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
    print(90-math.degrees(math.atan(a/(2*(b-x/(a*a))))))

Buggy submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())
h = x / (a * a)
if x < b / 2:
    print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
    print(90-math.degrees(math.atan(a/(2*(b-x/(a*a))))))

Buggy submission (verdict: Runtime Error):
from math import atan,degrees
a, b, x = map(int, input().split())
h = x / (a * a)
if x < b / 2:
    print(90-degrees(atan(2*x/(a*b*b))))
else:
    print(90-degrees(atan(a/(2*(b-x/(a*a))))))
Problem p02900 (python)

Fixed submission:
a, b = map(int, input().split())
import math


def _gcd(x, y):
    if y == 0:
        return x
    return _gcd(y, x % y)


gcd = _gcd(a, b)
i, cnt = 2, 1
while i * i <= gcd:
    flag = 0
    while gcd % i == 0:
        flag = 1
        gcd //= i
    if flag:
        cnt += 1
    i += 1
if gcd != 1:
    cnt += 1
print(cnt)

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

gcd = math.gcd(a, b)
i, cnt = 2, 1
while i * i <= gcd:
    flag = 0
    while gcd % i == 0:
        flag = 1
        gcd //= i
    if flag:
        cnt += 1
    i += 1
if gcd != 1:
    cnt += 1
print(cnt)

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

gcd = math.gcd(a, b)
i, cnt = 2, 1
while i * i <= gcd:
    flag = 0
    while gcd % i == 0:
        flag = 1
        gcd //= i
    if flag:
        cnt += 1
    i += 1
if gcd != 1:
    cnt += 1
print(cnt)
Problem p02901 (python)

Fixed submission:
from sys import setrecursionlimit as SRL, stdin

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())
n, m = rrd()

e = [[] for _i in range(1 << 13)]

p = []
for i in range(m):
    a, b = rrd()
    lst = list(rrd())
    g = 0
    for j in lst:
        g |= 1 << (j - 1)
    p.append((a, g))

for i in range(1 << n):
    for j in p:
        e[i].append((i | j[1], j[0]))
inf = 10**10

dis = [inf] * (1 << 13)
vis = [0] * (1 << 13)
dis[0] = 0

from heapq import *

q = [(0, 0)]
while len(q):
    ds, now = heappop(q)
    if vis[now]:
        continue
    vis[now] = 1
    for next, cost in e[now]:
        if dis[next] > dis[now] + cost:
            dis[next] = dis[now] + cost
            heappush(q, (dis[next], next))

if dis[(1 << n) - 1] == inf:
    print(-1)
else:
    print(dis[(1 << n) - 1])

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit as SRL, stdin

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())
n, m = rrd()

e = [[] for _i in range(1 << 13)]

p = []
for i in range(m):
    a, b = rrd()
    lst = list(rrd())
    g = 0
    for j in lst:
        g |= 1 << (j - 1)
    p.append((a, g))

for i in range(1 << n):
    for j in p:
        e[i].append((i | j[1], j[0]))
from math import inf

dis = [inf] * (1 << 13)
vis = [0] * (1 << 13)
dis[0] = 0

from heapq import *

q = [(0, 0)]
while len(q):
    ds, now = heappop(q)
    if vis[now]:
        continue
    vis[now] = 1
    for next, cost in e[now]:
        if dis[next] > dis[now] + cost:
            dis[next] = dis[now] + cost
            heappush(q, (dis[next], next))

if dis[(1 << n) - 1] == inf:
    print(-1)
else:
    print(dis[(1 << n) - 1])
Problem p02936 (python)

Fixed submission:
from sys import setrecursionlimit as SRL, stdin, stdout

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

n, q = rrd()

v = [[] for _i in range(n + 10)]

for i in range(n - 1):
    x, y = rrd()
    v[x].append(y)
    v[y].append(x)

add = [0] * (n + 10)

for i in range(q):
    p, x = rrd()
    add[p] += x

p = [(1, 0)]
vis = [0] * (n + 2)
while len(p):
    now, fa = p.pop()
    add[now] += add[fa]
    vis[now] = 1
    for i in v[now]:
        if not vis[i]:
            p.append((i,now))

stdout.write(" ".join(map(str, add[1:n + 1])))

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

v = [[] for _i in range(n + 10)]

for i in range(n - 1):
    x, y = map(int, input().split())
    v[x].append(y)
    v[y].append(x)

add = [0] * (n + 10)

for i in range(q):
    p, x = map(int, input().split())
    add[p] += x


def dfs(now, fa):
    add[now] += add[fa]
    for i in v[now]:
        if i == fa:
            continue
        dfs(i, now)


dfs(1, 0)

for i in range(1, n + 1):
    print(add[i], end=' ')
Problem p02936 (python)

Fixed submission:
from sys import exit, stderr, stdin, setrecursionlimit
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N, Q = list(map(int,input().split()))
    adjl = [[] for _ in range(N+1)]
    for _ in  range(N-1):
        a, b = list(map(lambda x: int(x),input().split()))
        adjl[a].append(b)
        adjl[b].append(a)
    res = [0]*(N+1)
    # print(adjl)
    for _ in  range(Q):
        p, x = list(map(lambda x: int(x),input().split()))
        res[p] += x
    # def dfs(n, parent = None):
    #     if parent != None:
    #         res[n] += res[parent]
    #     for neigh in adjl[n]:
    #         if neigh == parent:
    #             continue
    #         else:
    #             dfs(neigh,n)
    # dfs(0)
    q = [(1,0)]
    while q:
        x, parent = q.pop()
        res[x] += res[parent]
        for neigh in adjl[x]:
            if neigh != parent:
                q.append((neigh,x))

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





if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return






def main():
    N,Q = list(map(int,input().split()))
    adjl = [[] for _ in range(N)]
    for _ in  range(N-1):
        a, b = list(map(lambda x: int(x)-1,input().split()))
        adjl[a].append(b)
        adjl[b].append(a)
    res = [0]*N
    for _ in  range(Q):
        p, x = list(map(lambda x: int(x),input().split()))
        res[p-1] += x
    def dfs(n, parent = None):
        if parent != None:
            res[n] += res[parent]
        for neigh in adjl[n]:
            if neigh == parent:
                continue
            else:
                dfs(neigh,n)
    dfs(0)
    for _ in range(N):
        print(res[_],end=" ")
    print()





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

Fixed submission:
from sys import exit, stderr, stdin, setrecursionlimit
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return



def main():
    # まず可能かどうか
    S = str(input().rstrip())*2
    T = str(input().rstrip())
    LS = len(S)//2
    LT = len(T)
    S *= 3
    # はじめて出る位置
    char_p = dict()
    for i in range(LS):
        if not S[i] in char_p:
            char_p[S[i]] = i

    # char_pの文字が２つめのはじめて出る位置までに
    char_d = dict(zip(char_p.keys(),[[0 for __ in range(LS+char_p[c])] for c in char_p]))
    for c in char_p:
        dis = 1
        for i in range(LS+char_p[c]-1,-1,-1):
            if S[i] == c:
                char_d[c][i] = dis
                dis = 1
            else:
                char_d[c][i] = dis
                dis += 1
    # 答えの計算
    debug(char_d)
    init = True
    for t in T:
        if t not in char_p:
            print(-1)
            exit()
        else:
            debug(t,'string')
            if init:
                cur = char_p[t]
                init = False
            #それ以外なら区切りで相対的な位置を出して足す
            else:
                rel_cur = cur%LS
                debug(rel_cur,"relative_cursol")
                cur += char_d[t][rel_cur]
        debug(cur,"cur")
        # print()
    print(cur+1)






if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from sys import exit, stderr, stdin, setrecursionlimit
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return



def main():
    # まず可能かどうか
    S = str(input().rstrip())*2
    T = str(input().rstrip())
    LS = len(S)//2
    LT = len(T)
    S *= 3
    # はじめて出る位置
    char_p = dict()
    for i in range(LS):
        if not S[i] in char_p:
            char_p[S[i]] = i
    print(char_p)

    # char_pの文字が２つめのはじめて出る位置までに
    char_d = dict(zip(char_p.keys(),[[0 for __ in range(LS+char_p[c])] for c in char_p]))
    for c in char_p:
        dis = 1
        for i in range(LS+char_p[c]-1,-1,-1):
            if S[i] == c:
                char_d[c][i] = dis
                dis = 1
            else:
                char_d[c][i] = dis
                dis += 1
    # 答えの計算
    debug(char_d)
    cur = char_p[T[0]]
    for t in T[1:]:
        if t not in char_p:
            print(-1)
            exit()
        else:
            debug(t,'string')
            #それ以外なら区切りで相対的な位置を出して足す
            rel_cur = cur%LS
            debug(rel_cur,"relative_cursol")
            cur += char_d[t][rel_cur]
        debug(cur,"cur")
        # print()
    print(cur+1)






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

Fixed submission:
inp = lambda cast=int: list(map(cast, input().split()))
# printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
n, = inp()
A = [0.0] + inp(float)
dp = [[0.0 for _ in range(n + 1)] for _ in range(n + 1)]
res = 0.0
for i in range(n + 1):
    for j in range(n + 1):
        if i == 0:
            dp[i][j] = 1 if j == 0 else 0
        elif j == 0:
            dp[i][j] = dp[i-1][j] * (1 - A[i])
        else:
            dp[i][j] = dp[i-1][j] * (1 - A[i]) \
                       + dp[i-1][j-1] * A[i]
        if i == n and j > n/2:
            res += dp[i][j]
print(res)

Buggy submission (verdict: Runtime Error):
inp = lambda cast=int: list(map(cast, input().split()))
printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
n, = inp()
A = [0.0] + inp(float)
dp = [[0.0 for _ in range(n + 1)] for _ in range(n + 1)]
res = 0.0
for i in range(n + 1):
    for j in range(n + 1):
        if i == 0:
            dp[i][j] = 1 if j == 0 else 0
        elif j == 0:
            dp[i][j] = dp[i-1][j] * (1 - A[i])
        else:
            dp[i][j] = dp[i-1][j] * (1 - A[i]) \
                       + dp[i-1][j-1] * A[i]
        if i == n and j > n/2:
            res += dp[i][j]
printf(res)
Problem p02823 (python)

Fixed submission:
i = raw_input()
N, A, B = i.split()

N = int(N)
A = int(A)
B = int(B)

if abs(A-B)%2 == 0:
  print int(abs(A-B)/2)
else:
  e = int(min(A-1, N-B))
  d = (B-A+1) // 2
  print e + d

Buggy submission (verdict: Runtime Error):
i = input()
N, A, B = i.split(' ')

N = int(N)
A = int(A)
B = int(B)

if abs(A-B)%2==0:
  print(abs(A-B)/2)
else:
  print(min(max(A, B), max(N-A, N-B))
Problem p02823 (python)

Fixed submission:
# Function for calc
def match(n, a, b):
    if (b - a)% 2 == 0:
        print((b-a)/2)
    else:
        if (n - b) >= a:
            print((a)+((b-(a+1))/2))
        else:
            x=(n-b+1)
            print(x+((n-(a+x))/2))
# Run match
in_string = raw_input()
[N, A, B] = [int(v) for v in in_string.split()]
match(N, A, B)

Buggy submission (verdict: Runtime Error):
# Function for calc
def match(n, a, b):
    if (b - a)% 2 == 0:
        print((b-a)/2)
    else:
        if (n - b) > a:
            print((a)+((b-(a+1))/2))
        else:
            x=(n-b+1)
            print(x+((n-(a+x))/2))
# Run match
in_string = input()
N = int(in_string[0])
A = int(in_string[1])
B = int(in_string[2])

match(N, A, B)

Buggy submission (verdict: Runtime Error):
from sys import argv

# Function for calc
def match(n, a, b):
    if (b - a)% 2 == 0:
        print((b-a)/2)
    else:
        if (n - b) > a:
            print((a)+((b-(a+1))/2))
        else:
            x=(n-b+1)
            print(x+((n-(a+x))/2))
# Run match
match(int(argv[1]), int(argv[2]), int(argv[3]))

Buggy submission (verdict: Runtime Error):
from sys import argv

# Function for calc
def match(n, a, b):
    if (b - a)% 2 == 0:
        print((b-a)/2)
    else:
        if (n - b) > a:
            print((a)+((b-(a+1))/2))
        else:
            x=(n-b+1)
            print(x+((n-(a+x))/2))
# Run match
match(int(argv[1]), int(argv[2]), int(argv[3]))

Buggy submission (verdict: Runtime Error):
from sys import argv

# Function for calc
def match(n, a, b):
    if (b - a)% 2 == 0:
        print((b-a)/2)
    else:
        mid = (n / 2)
        if (n - a) > b:
            print(b)
        else:
            print(n-a-1)

# Run match
match(int(argv[1]), int(argv[2]), int(argv[3]))
Problem p02823 (python)

Fixed submission:
import numpy as np

def min_steps_v2(n, a, b):
    n = np.int64(n)
    a = np.int64(a)
    b = np.int64(b)

    if (b - a) % 2 == 0:
        return np.int64(int(b - a) // 2)
 
    # odd case
    a_diff = a - 1
    b_diff = n - b
 
    if a_diff > b_diff:
      steps_to_even = n - b + 1
      remain_steps = min_steps_v2(n, a + (n - b) + 1, n)
    else:
      steps_to_even = a
      remain_steps = min_steps_v2(n, 1, b - a)
 
    return steps_to_even + remain_steps

numbers = input().split(' ')
 
n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
 
print(min_steps_v2(n, a, b))

Buggy submission (verdict: Runtime Error):
def min_steps_v2(n, a, b):
    n = np.int64(n)
    a = np.int64(a)
    b = np.int64(b)

    if (b - a) % 2 == 0:
        return np.int64(int(b - a) // 2)
 
    # odd case
    a_diff = a - 1
    b_diff = n - b
 
    if a_diff > b_diff:
      steps_to_even = n - b + 1
      remain_steps = min_steps_v2(n, a + (n - b) + 1, n)
    else:
      steps_to_even = a
      remain_steps = min_steps_v2(n, 1, b - a)
 
    return steps_to_even + remain_steps

numbers = input().split(' ')
 
n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
 
print(min_steps_v2(n, a, b))

Buggy submission (verdict: Runtime Error):
def min_steps_v2(n, a, b):
    if (b - a) % 2 == 0:
        return int((b - a) / 2)
 
    # odd case
    a_diff = a - 1
    b_diff = n - b
 
    if a_diff > b_diff:
      steps_to_even = n - b + 1
      remain_steps = min_steps_v2(n, A + (N - B) + 1, N)
    else:
      steps_to_even = a
      remain_steps = min_steps_v2(n, 1, b - a)
 
    return int(steps_to_even + remain_steps)
 
numbers = input().split(' ')
 
n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
 
print(min_steps_v2(n, a, b))

Buggy submission (verdict: Runtime Error):
numbers = raw_input().split(' ')

n = numbers[0]
a = numbers[1]
b = numbers[2]

def even_diff(A, B):
  return (B - A) / 2


def odd_diff(N, A, B):
  a_diff = A - 1
  b_diff = N - B
  
  if a_diff > b_diff:
    return N - A
  else:
    return B - 1

if (a - b) % 2 == 0:
  result = even_diff(a, b)
else:
  result = odd_diff(n, a, b)    
  
print(result)
Problem p02823 (python)

Fixed submission:
strargs = input()

n, a, b = map(lambda x: int(x), strargs.split())

if (b - a) % 2 == 0:
  print((b - a)//2)
  
elif a - 1 < n - b:
  newB = b - a
  mid = (newB - 1)//2 + 1
  print(a + mid - 1)

else:
  newA = (a + (n - b + 1))
  mid = newA + (n - newA)//2
  print((n - b + 1) + (n - newA)//2)

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

n, a, b = map(lambda x: int(x), strargs)

if (b - a) % 2 == 0:
  print(int((b - a)/2))
  
elif n - a < b - 1:
  print(n - a)

else:
  print(b - 1)

Buggy submission (verdict: Runtime Error):
strargs = [10, 3, ]

n, a, b = map(lambda x: int(x), strargs)

if (b - a) % 2 == 0:
  print(int((b - a)/2))
  
elif n - a < b - 1:
  print(n - a)

else:
  print(b - 1)