Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def submit():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    d = [float('inf') for _ in range(n)]
    d[0] = 0
    for i in range(1, n):
        for j in range(1, k + 1):
            if i - j >= 0:
                d[i] = min(d[i],
                           d[i - j] + abs(h[i] - h[i - j]))
            else:
                break
    print(d[n - 1])

submit()

Fixed submission:
def submit():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    d = [float('inf') for _ in range(n)]
    d[0] = 0
    for i in range(1, n):
        for j in range(1, k + 1):
            if i - j >= 0:
                d[i] = min(d[i],
                           d[i - j] + abs(h[i] - h[i - j]))
            else:
                break
    print(d[n - 1])

submit()
Buggy python submission (verdict: Time Limit Exceeded):
def submit():
    n, w = map(int, input().split())
    item_max = 100
    val_max = 1000
    col_max = item_max * val_max
 
    # dp[i][j] = item iまでで価値jになるようにした時の最小重み
    dp = [[float('inf') for _ in range(col_max + 1)] for _ in range(n + 1)]
    for i in range(n + 1):
        dp[i][0] = 0

    for i in range(1, n + 1):
        wi, vi = map(int, input().split())
        for j in range(col_max + 1):
            if 0 <= j - vi <= col_max:
                dp[i][j] = min(dp[i - 1][j],
                               dp[i - 1][j - vi] + wi)
            else:
                dp[i][j] = dp[i - 1][j]

    ans = 0
    for i in range(col_max + 1):
        if dp[n][i] <= w:
            ans = i
    print(ans)

submit()
        

Fixed submission:
n, w = map(int, input().split())
item_max = 100
val_max = 1000
col_max = item_max * val_max

# dp[i][j] = item iまでで価値jになるようにした時の最小重み
dp = [[float('inf') for _ in range(col_max + 1)] for _ in range(n + 1)]
for i in range(n + 1):
    dp[i][0] = 0

for i in range(1, n + 1):
    wi, vi = map(int, input().split())
    for j in range(1, col_max + 1):
        if j >= vi:
            dp[i][j] = min(dp[i - 1][j],
                            dp[i - 1][j - vi] + wi)
        else:
            dp[i][j] = dp[i - 1][j]

ans = 0
for i in range(col_max + 1):
    if dp[n][i] <= w:
        ans = i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):


def submit():
    s = input()
    t = input()

    # dp[i][j] : sをi、tをjまで見た時のlcs長
    # dp[i + 1][j + 1] = {
    #   dp[i][j] + 1, 
    #   dp[i + 1][j] or dp[i][j + 1]のいずれか
    # }

    dp = [[0 for _ in range(len(t) + 1)] for _ in range(len(s) + 1)]

    for i in range(len(s)):
        for j in range(len(t)):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
    
    # 再構成する
    i = len(s)
    j = len(t)
    ans = ""
    while dp[i][j]:
        if s[i - 1] == t[j - 1]:
            ans = s[i - 1] + ans
            i -= 1
            j -= 1
        else:
            if dp[i][j] == dp[i - 1][j]:
                i -= 1
            else:
                j -= 1
    print(ans)


submit()

Fixed submission:


def submit():
    s = input()
    t = input()

    # dp[i][j] : sをi、tをjまで見た時のlcs長
    # dp[i + 1][j + 1] = {
    #   dp[i][j] + 1, 
    #   dp[i + 1][j] or dp[i][j + 1]のいずれか
    # }

    dp = [[0 for _ in range(len(t) + 1)] for _ in range(len(s) + 1)]

    for i in range(len(s)):
        for j in range(len(t)):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
    
    # 再構成する
    i = len(s)
    j = len(t)
    ans = ""
    while dp[i][j]:
        if s[i - 1] == t[j - 1]:
            ans = s[i - 1] + ans
            i -= 1
            j -= 1
        else:
            if dp[i][j] == dp[i - 1][j]:
                i -= 1
            else:
                j -= 1
    print(ans)


submit()
Buggy python submission (verdict: Time Limit Exceeded):


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

    # dp[i][j] : i ~ j - 1までの数列におけるX - Yのスコア
    # taroのターンの場合、
    #   max(dp[i + 1][j] + iスコア, dp[i][j - 1] + jスコア)
    # jiroのターンの場合
    #   min(dp[i + 1][j] - iスコア, dp[i][j - 1] - jスコア)

    dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
    for i in range(n + 1):
        dp[i][i] = 0

    # len = 1, 2, 3, ...と求めてゆく
    # len = xのとき、dp[i + 1][j]かdp[i][j - 1]はlen = x - 1のときのスコアなので
    # 計算済み
    for l in range(1, n + 1):
        for i in range(n):
            j = i + l
            if j > n:
                break
            
            # taroのターン, nとlの偶奇が一致する時
            if (n - l) % 2 == 0:
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
            else:
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])

    print(dp[0][n])
            

submit()

Fixed submission:


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

    # dp[i][j] : i ~ j - 1までの数列におけるX - Yのスコア
    # taroのターンの場合、
    #   max(dp[i + 1][j] + iスコア, dp[i][j - 1] + jスコア)
    # jiroのターンの場合
    #   min(dp[i + 1][j] - iスコア, dp[i][j - 1] - jスコア)

    dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
    for i in range(n + 1):
        dp[i][i] = 0

    # len = 1, 2, 3, ...と求めてゆく
    # len = xのとき、dp[i + 1][j]かdp[i][j - 1]はlen = x - 1のときのスコアなので
    # 計算済み
    for l in range(1, n + 1):
        for i in range(n):
            j = i + l
            if j > n:
                break
            
            # taroのターン, nとlの偶奇が一致する時
            if (n - l) % 2 == 0:
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
            else:
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])

    print(dp[0][n])
            

submit()
Buggy python submission (verdict: Time Limit Exceeded):


def rec(a, s, e, dp, ss):
    if dp[s][e] > 0:
        return dp[s][e]

    if e - s == 1:
        dp[s][e] = 0
        return 0
    
    cur_min = float('inf')
    for i in range(s + 1, e):
        lc = rec(a, s, i, dp, ss)
        rc = rec(a, i, e, dp, ss)
        test = lc + rc + ss[s][e]
        if test < cur_min:
            cur_min = test
    dp[s][e] = cur_min
    return cur_min


def submit():
    n = int(input())
    a = list(map(int, input().split()))
    dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
    ss = [[0 for _ in range(n + 1)] for _ in range(n + 1)]

    for i in range(n + 1):
        for j in range(i, n + 1):
            ss[i][j] = sum(a[i:j])
    
    print(rec(a, 0, n, dp, ss))


submit()

Fixed submission:


def rec(a, s, e, dp, ss):
    if dp[s][e] > 0:
        return dp[s][e]

    if e - s == 1:
        dp[s][e] = 0
        return 0
    
    cur_min = float('inf')
    for i in range(s + 1, e):
        lc = rec(a, s, i, dp, ss)
        rc = rec(a, i, e, dp, ss)
        test = lc + rc + ss[s][e]
        if test < cur_min:
            cur_min = test
    dp[s][e] = cur_min
    return cur_min


def submit():
    n = int(input())
    a = list(map(int, input().split()))
    dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
    ss = [[0 for _ in range(n + 1)] for _ in range(n + 1)]

    for i in range(n + 1):
        for j in range(i, n + 1):
            ss[i][j] = sum(a[i:j])
    
    print(rec(a, 0, n, dp, ss))


submit()
Buggy python submission (verdict: Time Limit Exceeded):

import numpy as np

def submit():
    n, k = map(int, input().split())
    hlist = np.array([int(input()) for _ in range(n)])

    hlist.sort()
    min_diff = float('inf')
    for i in range(0, n - k + 1):
        choices = hlist[i : i + k]
        maxh = np.max(choices)
        minh = np.min(choices)

        if maxh - minh < min_diff:
            min_diff = maxh - minh

    print(min_diff)
        

if __name__ == "__main__":
    submit()

Fixed submission:

def submit():
    n, k = map(int, input().split())
    hlist = [int(input()) for _ in range(n)]

    hlist.sort()
    min_diff = float('inf')
    for i in range(0, n - k + 1):
        minh = hlist[i]
        maxh = hlist[i + k - 1]
        if maxh - minh < min_diff:
            min_diff = maxh - minh

    print(min_diff)
        

if __name__ == "__main__":
    submit()

Buggy python submission (verdict: Time Limit Exceeded):

def submit():
    n, k = map(int, input().split())
    hlist = [int(input()) for _ in range(n)]

    hlist.sort()
    min_diff = float('inf')
    for i in range(0, n - k + 1):
        choices = hlist[i : i + k]
        maxh = max(choices)
        minh = min(choices)

        if maxh - minh < min_diff:
            min_diff = maxh - minh

    print(min_diff)
        

if __name__ == "__main__":
    submit()

Fixed submission:

def submit():
    n, k = map(int, input().split())
    hlist = [int(input()) for _ in range(n)]

    hlist.sort()
    min_diff = float('inf')
    for i in range(0, n - k + 1):
        minh = hlist[i]
        maxh = hlist[i + k - 1]
        if maxh - minh < min_diff:
            min_diff = maxh - minh

    print(min_diff)
        

if __name__ == "__main__":
    submit()
Buggy python submission (verdict: Time Limit Exceeded):


def submit():
    n, k = map(int, input().split())

    k_cand = [i * k for i in range(1, (2 * n) // k + 1)]

    ans = []
    for i in range(1, n + 1):
        a = i
        for k1 in k_cand:
            b = k1 - a
            if b <= 0 or b > n:
                continue

            for k2 in k_cand:
                c = k2 - b
                if c <= 0 or c > n:
                    continue

                if (a + c) % k == 0:
                    ans.append((a, b, c))

    print(len(ans))
        

if __name__ == "__main__":
    submit()

Fixed submission:
def submit():
    n, k = map(int, input().split())

    if k % 2:
        count = sum([1 for c in range(1, n + 1) if c % k == 0])
        print(count ** 3)
    else:
        count_1 = sum([1 for c in range(1, n + 1) if c % k == 0])
        count_2 = sum([1 for c in range(1, n + 1) if c % k == k // 2])
        print(count_1 ** 3 + count_2 ** 3)


if __name__ == "__main__":
    submit()
Buggy python submission (verdict: Runtime Error):
"""
102 C
"""

import math

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def sum_abs(alist, b):
    return sum([abs(a - b) for a in alist])


def submit():
    n, alist = read_input()

    alist = [a - (i + 1) for i, a in enumerate(alist)]
    alist.sort()

    if n % 2:
        b_min, b_max = alist[n // 2], alist[n // 2 + 1]
        print(min(sum_abs(alist, b_min), sum_abs(alist, b_max)))
    else:
        print(sum_abs(alist, alist[n // 2]))


if __name__ == "__main__":
    submit()

Fixed submission:
"""
102 C
"""

import math

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def sum_abs(alist, b):
    return sum([abs(a - b) for a in alist])


def submit():
    n, alist = read_input()

    alist = [a - (i + 1) for i, a in enumerate(alist)]
    alist.sort()

    if n % 2 == 0:
        b_min, b_max = alist[n // 2], alist[n // 2 + 1]
        print(min(sum_abs(alist, b_min), sum_abs(alist, b_max)))
    else:
        print(sum_abs(alist, alist[n // 2]))


if __name__ == "__main__":
    submit()
Buggy python submission (verdict: Time Limit Exceeded):


def read_input():
    s = input()
    k = int(input())
    return s, k

def submit():
    s, k = read_input()

    subs = set()
    for i in range(len(s)):
        for j in range(i+1,len(s)+1):
            subs.add(s[i:j])

    subs = [[c for c in s] for s in subs]
    subs.sort()

    print(''.join(subs[k - 1]))

if __name__ == '__main__':
    submit()


Fixed submission:


def read_input():
    s = input()
    k = int(input())
    return s, k


# sから、candsの間に挟まる文字列(長さl)を探す
def search_insertion(s, cands, l):
    result = []

    for i in range(len(s)):
        for c in cands:
            if s[i:i+l].startswith(c):
                result.append(s[i:i+l])

    cands.extend(result)
    cands = list(set(cands))
    return cands


def sort_s(cands):
    t = [[c for c in s] for s in cands]
    t.sort()
    return [''.join(s) for s in t]


def submit():
    s, k = read_input()

    cands = list(set([c for c in s]))
    precands = None
    for i in range(2, len(s) + 1):
        cands = search_insertion(s, cands, i)
        cands = sort_s(cands)
        cands = cands[:k]

        if precands == cands:
            break
        precands = cands[:]

    print(cands[-1])

if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Time Limit Exceeded):


class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.size = [1 for i in range(n + 1)]

    def find(self, x):
        if x == self.par[x]:
            return self.par[x]
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        if self.same(x, y):
            return
        xr = self.find(x)
        yr = self.find(y)
        if self.size[xr] > self.size[yr]:
            xr, yr = yr, xr
        self.size[yr] = self.size[xr] + self.size[yr]
        self.par[xr] = yr


def submit():
    n, m = map(int, input().split())
    plist = list(map(int, input().split()))
    
    uf = UnionFind(n)
    for _ in range(m):
        x, y = map(int, input().split())
        uf.unite(x, y)

    groups = {}
    for i in range(1, n + 1):
        r = uf.find(i)
        if r not in groups.keys():
            groups[r] = {i}
        else:
            groups[r].add(i)

    ans = 0
    for group in groups.values():
        for g in group:
            if plist[g - 1] in group:
                ans += 1
    print(ans)


submit()

Fixed submission:


class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.size = [1 for i in range(n + 1)]

    def find(self, x):
        if x == self.par[x]:
            return self.par[x]
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        if self.same(x, y):
            return
        xr = self.find(x)
        yr = self.find(y)
        if self.size[xr] > self.size[yr]:
            xr, yr = yr, xr
        self.size[yr] = self.size[xr] + self.size[yr]
        self.par[xr] = yr


def submit():
    n, m = map(int, input().split())
    plist = list(map(int, input().split()))
    
    uf = UnionFind(n)
    for _ in range(m):
        x, y = map(int, input().split())
        uf.unite(x, y)

    groups = {}
    for i in range(1, n + 1):
        r = uf.find(i)
        if r not in groups.keys():
            groups[r] = {i}
        else:
            groups[r].add(i)

    ans = 0
    for group in groups.values():
        for g in group:
            if plist[g - 1] in group:
                ans += 1
    print(ans)


submit()
Buggy python submission (verdict: Time Limit Exceeded):


def read_input():
    n = int(input())
    xlist = list(map(int, input().split()))
    return n, xlist


def get_median(s):
    l = len(s)
    return s[int((l-1)/2)]


def submit():
    n, xlist = read_input()

    xlist = [(x, i) for i, x in enumerate(xlist)]
    xlist.sort(key=lambda x: x[0])

    pos_dic = {}
    for i, x in enumerate(xlist):
        pos_dic[x[1]] = i

    for i in range(n):
        target = pos_dic[i]
        p = xlist.pop(target)
        print(get_median(xlist)[0])
        xlist.insert(target, p)




if __name__ == '__main__':
    submit()


Fixed submission:


def read_input():
    n = int(input())
    xlist = list(map(int, input().split()))
    return n, xlist


def get_median(s, ignore):
    l = len(s)
    if ignore < l/2:
        return s[int((l+1)/2)]
    else:
        return s[int((l-1)/2)]

def submit():
    n, xlist = read_input()

    xlist = [(x, i) for i, x in enumerate(xlist)]
    xlist.sort(key=lambda x: x[0])

    pos_dic = {}
    for i, x in enumerate(xlist):
        pos_dic[x[1]] = i

    for i in range(n):
        target = pos_dic[i]
        print(get_median(xlist, target)[0])




if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Runtime Error):
a,b = map(int, input())

if (a*b)%2:
  print('Odd')
else:
  print('Even')

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

if (a*b)%2:
    print('Odd')
else:
    print('Even')
Buggy python submission (verdict: Time Limit Exceeded):

import math


def query(ql, qr, buckets, is_prime):
    ans = 0
    lb, rb = -1, -1
    for st, ed, count in buckets:
        # 完全に含まれていればそのままカウント
        if ql < st and ed < qr:
            ans += count
            continue
        
        # 左にはみ出している
        if st < ql <= ed and ed <= qr:
            for x in range(ql, ed + 1):
                ans += x % 2 and is_prime[x] and is_prime[(x + 1) // 2]
            continue

        # 右にはみ出している
        if ql < st and st <= qr < ed:
            for x in range(st, qr + 1):
                ans += x % 2 and is_prime[x] and is_prime[(x + 1) // 2]
            continue

        # 収まっている
        if st <= ql and qr <= ed:
            for x in range(ql, qr + 1):
                ans += x % 2 and is_prime[x] and is_prime[(x + 1) // 2]
            break
    return ans
        

def submit():
    n_max = 10**5

    # n_maxまでの素数を数える
    is_prime = {x: True for x in range(1, n_max + 1)}
    is_prime[1] = False
    for x in range(2, math.ceil(math.sqrt(n_max)) + 1):
        if is_prime[x]:
            y = 2 * x
            while y <= n_max:
                is_prime[y] = False
                y += x
    
    # バケット法で数えておく
    bucket_size = math.floor(math.sqrt(n_max))
    buckets = []
    for st in range(1, n_max + 1, bucket_size):
        ed = st + bucket_size - 1
        like2017s = [is_prime[x] and is_prime[(x + 1) // 2] for x in range(st, ed + 1) if x % 2 and x <= n_max]
        bucket_count = sum(like2017s)
        buckets.append([st, ed, bucket_count])
    
    # クエリを処理する
    q = int(input())
    queries = []
    for _ in range(q):
        queries.append(list(map(int, input().split())))
        
    for q in queries:
        res = query(q[0], q[1], buckets, is_prime)
        print(res)


submit()
                


Fixed submission:

import math

def submit():
    n_max = 10**5

    # n_maxまでの素数を数える
    is_prime = {x: True for x in range(1, n_max + 1)}
    is_prime[1] = False
    for x in range(2, math.ceil(math.sqrt(n_max)) + 1):
        if is_prime[x]:
            y = 2 * x
            while y <= n_max:
                is_prime[y] = False
                y += x

    like2017 = {}
    for x in range(1, n_max + 1):
        like2017[x] = x % 2 and is_prime[x] and is_prime[(x + 1) // 2]

    # xまでの2017に似た数の個数を覚えておく
    accumulation = {0: 0}
    for x in range(1, n_max + 1):
        accumulation[x] = accumulation[x - 1] + like2017[x]
    
    # クエリを処理する
    q = int(input())
    queries = []
    for _ in range(q):
        queries.append(list(map(int, input().split())))
        
    for l, r in queries:
        print(accumulation[r] - accumulation[l - 1])
    
submit()
Buggy python submission (verdict: Runtime Error):

import math

def read_input():
    a, b, c, d, e, f = map(int, input().split())
    return a, b, c, d, e, f


# 100aと100bの線形結合でf以下でとりうる値を見つける
def search_water_valiation(a, b, f):
    result = []
    for i in range(30):
        for j in range(30):
            water = 100*a*i + 100*b*j
            if water <= f:
                result.append(water)

    result = list(set(result))
    result.sort()

    return result


# c, dの線形結合でmax_sugar以下の最大値を探す
# cx + dy <= max_sugarより
# y <= - c/d x + max_sugar/d
# xの範囲は(0, max_sugar/c)
def search_most_sweet(c, d, max_sugar):
    sugars = []
    for x in range(math.floor(max_sugar/c) + 1):
        y = math.floor((-c * x + max_sugar)/d)
        sugars.append(c*x + d*y)

    sugars = list(set(sugars))
    return max(sugars)

def submit():
    a, b, c, d, e, f = read_input()

    waters = search_water_valiation(a, b, f)
    max_sugars = [w * e // 100 for w in waters]

    result = []
    for water, max_sugar in zip(waters, max_sugars):
        sugar = search_most_sweet(c, d, max_sugar)
        result.append((water, sugar))

    result = [r for r in result if r[0] + r[1] <= f]
    result = [(w+s, s, 100 * s / (w + s)) for (w, s) in result if (w, s) != (0, 0)]

    r = max(result, key=lambda x:x[2])
    print('{} {}'.format(r[0], r[1]))

if __name__ == '__main__':
    submit()

Fixed submission:

import math

def read_input():
    a, b, c, d, e, f = map(int, input().split())
    return a, b, c, d, e, f


# 100aと100bの線形結合でf以下でとりうる値を見つける
def search_water_valiation(a, b, f):
    result = []
    for i in range(30):
        for j in range(30):
            water = 100*a*i + 100*b*j
            if water <= f:
                result.append(water)

    result = list(set(result))
    result.sort()

    return result


# c, dの線形結合でmax_sugar以下の最大値を探す
# cx + dy <= max_sugarより
# y <= - c/d x + max_sugar/d
# xの範囲は(0, max_sugar/c)
def search_most_sweet(c, d, max_sugar):
    sugars = []
    for x in range(math.floor(max_sugar/c) + 1):
        y = math.floor((-c * x + max_sugar)/d)
        sugars.append(c*x + d*y)

    sugars = list(set(sugars))
    return max(sugars)

def submit():
    a, b, c, d, e, f = read_input()

    waters = search_water_valiation(a, b, f)
    max_sugars = [min(w * e // 100, f - w) for w in waters]

    result = []
    for water, max_sugar in zip(waters, max_sugars):
        sugar = search_most_sweet(c, d, max_sugar)
        result.append((water, sugar))

    result = [r for r in result if r[0] + r[1] <= f]
    result = [(w+s, s, 100 * s / (w + s)) for (w, s) in result if (w, s) != (0, 0)]

    r = max(result, key=lambda x:x[2])
    print('{} {}'.format(r[0], r[1]))

if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Time Limit Exceeded):

def read_input():
    n = int(input())
    alist = []

    for i in range(n):
        alist.append(int(input()))

    return n, alist


def submit():
    n, alist = read_input()

    paper = {}
    for a in alist:
        if a not in paper.keys():
            paper[a] = 1
        else:
            paper[a] *= -1

    paper_write = [t for t in paper.items() if t[1] == 1]
    print(len(paper_write))

if __name__ == '__main__':
    submit()

Fixed submission:

def read_input():
    n = int(input())
    alist = []

    for i in range(n):
        alist.append(int(input()))

    return n, alist


def submit():
    n, alist = read_input()

    paper = {a: -1 for a in alist}

    for a in alist:
        paper[a] *= -1

    paper_write = [t for t in paper.items() if t[1] == 1]
    print(len(paper_write))

if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Runtime Error):


def read_input():
    a, b, c, d = map(int, input().split())

    return a, b, c, d

def submit():
    a, b, c, d = read_input()

    if b < c or d < a:
        print(0)
        return

    if a < c:
        if d <= b:
            print(d - c)
        else:
            print(b - c)
    else:
        if b <= d:
            print(b - a)
        else:
            print(d - a)



if __name__ == '__main__':
    sub

Fixed submission:

def read_input():
    a, b, c, d = map(int, input().split())

    return a, b, c, d

def submit():
    a, b, c, d = read_input()

    if b < c or d < a:
        print(0)
        return

    if a < c:
        if d <= b:
            print(d - c)
        else:
            print(b - c)
    else:
        if b <= d:
            print(b - a)
        else:
            print(d - a)
    return

if __name__ == '__main__':
    submit()