Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input().strip())
x = [[] for x in range(N)]
for i in range(N-1):
     u, v, w = list(map(int, input().split()))
     x[u-1].append([v-1, w])
     x[v-1].append([u-1,w])



ret = {}
done = []

queue = [0]

for i in range(N):
    curr = queue.pop()
    if curr == 0:
        ret[0] = 0

    for neigh in x[curr]:
        if neigh in done:
            continue
        if neigh[1] % 2 == 0:
            ret[neigh[0]] = ret[curr]
        else:
            ret[neigh[0]] = 0 if ret[curr] == 1 else 1

        queue.append(neigh[0])
    done.append(curr)


for i in range(N):
    print(ret[i])


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

ret = 0

for i in range(N):
    if (i + 1) < K:
        ret += (1.0 / N) * (0.5 ** (math.ceil(math.log2(K / (i+1)))))
    else:
        ret += (1.0 / N)
print(ret)
Buggy python submission (verdict: Runtime Error):
a_,b_ = map(int, (raw_input().strip().split(" ")))

foo = []
for i,a in enumerate(range(a_)):
    foo = raw_input().strip().split(" ")
    for j in range(b_):
        if foo[j] == 'snuke':
            print('A'+ str(i + 1))

Fixed submission:
a_,b_ = map(int, (raw_input().strip().split(" ")))
foo = []
for i,a in enumerate(range(a_)):
    foo = raw_input().strip().split(" ")
    for j in range(b_):
        if foo[j] == 'snuke':
            print(chr(65 + j) + str(i + 1))

Buggy python submission (verdict: Runtime Error):
a_,b_ = map(int, (raw_input().strip().split(" ")))
foo = []
for i,a in enumerate(range(a_)):
    foo = raw_input().strip().split(" ")
    for j in range(b_):
        if foo[j] == 'snuke':
            print(chr(65 + j) + str(i + 1))

Fixed submission:
a_,b_ = map(int, (raw_input().strip().split(" ")))
foo = []
for i,a in enumerate(range(a_)):
    foo = raw_input().strip().split(" ")
    for j in range(b_):
        if foo[j] == 'snuke':
            print(chr(65 + j) + str(i + 1))

Buggy python submission (verdict: Runtime Error):
a_,b_ = map(int, (raw_input().strip().split(" ")))

foo = []
for i,a in enumerate(range(a_)):
    foo = raw_input().strip().split(" ")
    for j in range(b_):
        if foo[j] == 'snuke':
            print(chr(65 + j) + str(i + 1))
    

Fixed submission:
a_,b_ = map(int, (raw_input().strip().split(" ")))
foo = []
for i,a in enumerate(range(a_)):
    foo = raw_input().strip().split(" ")
    for j in range(b_):
        if foo[j] == 'snuke':
            print(chr(65 + j) + str(i + 1))
Buggy python submission (verdict: Runtime Error):
a = int(input().strip())

tmp = []
res = []
ind = 1

def bar(foo,hoge):
    if(foo == 0):
        return
    if foo == 1:
        res.append(1)
        return
    elif foo == 2:
        res.append(2)
        return
    for i in reversed(range(hoge)):
        if (tmp[i] <= foo):
            res.append(i + 1)
            bar(foo - (i + 1) , i)
            return
        
        
    
for i in range(10000000):
    ind = ind + i
    tmp.append(ind)
    if ind >= a :
        bar(a, i + 1 )
        break
for i in res:
    print(i)


Fixed submission:
a = int(input().strip())
import sys
sys.setrecursionlimit(1000000)
tmp = []
res = []
ind = 1

def bar(foo,hoge):
    if(foo == 0):
        return
    if foo == 1:
        res.append(1)
        return
    elif foo == 2:
        res.append(2)
        return
    for i in reversed(range(hoge)):
        if (tmp[i] <= foo):
            res.append(i + 1)
            bar(foo - (i + 1) , i)
            return
        
        
    
for i in range(10000000):
    ind = ind + i
    tmp.append(ind)
    if ind >= a :
        bar(a, i + 1 )
        break
for i in res:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
m = [ int(i) for i in input().strip().split(" ")]

k_tmp = float(sum(m))/len(m)

k1 = int(np.ceil(k_tmp))
k2 = int(np.floor(k_tmp))

res1 = sum([(x-k1) * (x-k1) for x in m])
res2 = sum([(x-k2) * (x-k2) for x in m])
res = 0
if res1 > res2:
    res = res2
else:
    res = res1
print(res)

Fixed submission:
import math

N = int(input())
m = [ int(i) for i in input().strip().split(" ")]

k_tmp = float(sum(m))/len(m)

k1 = int(math.ceil(k_tmp))
k2 = int(math.floor(k_tmp))

res1 = sum([(x-k1) * (x-k1) for x in m])
res2 = sum([(x-k2) * (x-k2) for x in m])
res = 0
if res1 > res2:
    res = res2
else:
    res = res1
print(res)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math

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

if N > K:
  prob_base = (N-K) / N
  prob = 0
  for i in range(1, N-K+1):
    x = math.ceil(np.log2(K/i))
    prob += (1/N) * (1/2)**x
  
  print(prob_base + prob)

else:
  for i in range(1, N+1):
    x = math.ceil(np.log2(K/i))
    prob += (1/N) * (1/2)**x
  
  print(prob)


  

Fixed submission:
import numpy as np
import math

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

if N > K: 
    prob_base = (N-K) / N
    prob = 0
    
    for i in range(1, K+1):
        x = math.ceil(np.log2(K/i))
        prob += (1/N) * (1/2)**x
        
    print(prob_base + prob)
    
else:
    prob = 0
    for i in range(1, N+1):
        x = math.ceil(np.log2(K/i))
        prob += (1/N) * (1/2)**x
        
    print(prob)
Buggy python submission (verdict: Runtime Error):
N = int(input())

import numpy as np

sum = 0

for n in range(1, int(np.sqrt(N))+1):
    x = (N - n ) // n
    if (N - n) % n == 0 and n**2 < N:
        sum += x

print(sum)

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

print(N-K+1)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

count = 0

for r in range(0, N//R+1):    
    for g in range(0, N//G+1):
        # compute b
        b = (N - r*R - g*G) / B
        
        # judge
        if b.is_integer() and b>=0:
            count += 1

print(count)        

Fixed submission:
R, G, B, N = map(int, input().split())

count = 0

for r in range(N//R+1):

  for g in range((N-r*R)//G+1):
    if (N - r*R - g*G) % B == 0:
      count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

count = 0

for r in range(0, N//R+1):
    #print('-'*10)
    #print(r)
    
    for g in range(0, N//G+1):
        #print(g)
        # compute b
        b = (N - r*R - g*G) / B
        #print(b)
        
        # judge
        if b.is_integer() and b >=0:
            count += 1
            #print('*'*10, count, '*'*10)

print(count)        

Fixed submission:
R, G, B, N = map(int, input().split())

count = 0

for r in range(N//R+1):

  for g in range((N-r*R)//G+1):
    if (N - r*R - g*G) % B == 0:
      count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

sum = 0
for num in range(1,N+1):
    if (N//num) == (N%num):
        sum += num

print(sum)

Fixed submission:
N = int(input())

import numpy as np

sum = 0

for n in range(1, int(np.sqrt(N)+1)):
    x = (N - n ) // n
    if ((N - n) % n == 0) and (x > n):
        sum += x

print(sum)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))

count = 0

for num, hight in enumerate(h):
  if h[num] >= max(h[:num]):
    count += 1

print(count)

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

count = 0

for num, hight in enumerate(h):
  if hight >= max(h[:num+1]):
    count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
a b = map(int, input().split())

if a//b == 0:
  print('Even')
else:
  print('Odd')

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

if (a*b)%2 == 0:
  print('Even')
else:
  print('Odd')
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N, M = map(int, raw_input().split())
_count = [0]*N

for i in range(M):
    L, R = map(int, raw_input().split())
    for j in range(L-1,R):
        _count[j] += 1

print _count.count(M)

Fixed submission:
# -*- coding: utf-8 -*-

N, M = map(int, raw_input().split())
_L = 1
_R = N

for i in range(M):
    L, R = map(int, raw_input().split())
    if _L < L:
        _L = L
    if R < _R:
        _R = R 

print str(max(_R-_L+1,0))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(" "))
acc_gates = set([i for i in range(1, N+1)])
for m in range(M):
    i, j = map(int, input().split(" "))
    tmp = set([n for n in range(i, j+1)])
    acc_gates = acc_gates & tmp

print(len(set(acc_gates)))

Fixed submission:
N, M = map(int, input().split(" "))
min_l = 1
max_r = N

for m in range(M):
    l, r = map(int, input().split(" "))
    if l > min_l:
        min_l = l
    if r < max_r:
        max_r = r

ans = (max_r-min_l)+1
if ans < 0:
    ans = 0

print(ans)
Buggy python submission (verdict: Runtime Error):
D, N = [int(i) for i in input().split()]

list_ = []
for k in range(1, 100):
    str_ = str(k) + "00"*D
    int_ = int(str_)
    list_.append(int_)

print(list_[N-1])

Fixed submission:
D, N = [int(i) for i in input().split()]

list_ = []
for k in range(1, 101):
    str_ = str(k) + "00"*D
    int_ = int(str_)
    list_.append(int_)

if N == 100 and D == 0:
    print(101)
elif N == 100 and D == 1:
    print(10100)
elif N == 100 and D == 2:
    print(1010000)
else:
    print(list_[N-1])
Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
A = [int(a) for a in input().split()]

def soinsuubunkai(N):
    num_ = N
    list_ = []
    for k in range(2, N+1):
        while True:
            if num_ % k == 0:
                list_.append(k)
                num_ = num_ // k
            else:
                break
    return list_

counter = 0
for a in A:
    tmp = soinsuubunkai(a)
    counter += tmp.count(2)

print(counter)

Fixed submission:

N = int(input())
A = [int(a) for a in input().split()]

counter = 0
for a in A:
    tmp = a
    while True:
        if tmp == 0:
            break
        elif tmp % 2 == 0:
            counter += 1
            tmp = tmp // 2
        else:
            break


print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input().split())
listA = list(listA.values())
listA.sort()
times = len(listA) - K
# print(times,len(listA),K)
num = 0

if times <= 0:
    num = 0
else:
    for _ in range(times):
        num += listA.pop(0)

print(num)



Fixed submission:
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input().split())
# print(listA)
listA = list(listA.values())
listA.sort()
times = len(listA) - K

num = 0

if times <= 0:
    num = 0
else:
    for i in range(times):
        num += listA[i]

print(num)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input().split())
# print(listA)
listA = list(listA.values())
listA.sort()
# print(listA)

num = 0
# print(listA)
if len(listA) <= K:
    num = 0
else:
    while len(listA) > K:
        tmp = listA.pop(0)
        listA[len(listA)-1] += tmp
        num += tmp

print(num)



Fixed submission:
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input().split())
# print(listA)
listA = list(listA.values())
listA.sort()
times = len(listA) - K

num = 0

if times <= 0:
    num = 0
else:
    for i in range(times):
        num += listA[i]

print(num)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input().split())
# print(listA)
listA = list(listA.values())
listA.sort()
# print(listA)

num = 0
# print(listA)
if len(listA) <= K:
    num = 0
else:
    while len(listA) > K:
        tmp = listA.pop(0)
        num += tmp
        for _ in range(tmp):
            listA[len(listA)-1] += 1
            listA.sort()
        # print(listA)

print(num)



Fixed submission:
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input().split())
# print(listA)
listA = list(listA.values())
listA.sort()
times = len(listA) - K

num = 0

if times <= 0:
    num = 0
else:
    for i in range(times):
        num += listA[i]

print(num)
Buggy python submission (verdict: Time Limit Exceeded):
H,W = input().split()
H,W = int(H),int(W)
MP = []
for i in range(10):
    MP.append(list(map(int,input().split())))

board = []
for h in range(H):
    board.append(list(map(int,input().split())))

def mincost(start,goal):
    queue = []
    queue.append((start,[],0))
    queue[0][1].append(start)
    mincost = 99999999999999999999999999999
    while len(queue) != 0:
        q = queue.pop(0)
        if q[0] == goal:
            if q[2] < mincost:
                mincost = q[2]
        else:
            for i in range(10):
                if i not in q[1]:
                    tq = q[1].copy()
                    tq.append(i)
                    if q[2]+MP[q[0]][i] < mincost:
                        queue.append((i,tq,q[2]+MP[q[0]][i]))
    return mincost

need_magical_power = 0
for h in range(H):
    for w in range(W):
        if board[h][w] == -1 or board[h][w] == 1:
            pass
        else:
            need_magical_power += mincost(board[h][w],1)

print(need_magical_power)


Fixed submission:
H,W = input().split()
H,W = int(H),int(W)
MP = []
for i in range(10):
    MP.append(list(map(int,input().split())))

board = []
for h in range(H):
    board.append(list(map(int,input().split())))

def mincost(start,goal):
    queue = []
    queue.append((start,[],0))
    queue[0][1].append(start)
    mincost = 99999999999999999999999999999
    while len(queue) != 0:
        q = queue.pop(0)
        if q[0] == goal:
            if q[2] < mincost:
                mincost = q[2]
        else:
            for i in range(10):
                if i not in q[1]:
                    tq = q[1].copy()
                    tq.append(i)
                    if q[2]+MP[q[0]][i] < mincost:
                        queue.append((i,tq,q[2]+MP[q[0]][i]))
    return mincost

need_magical_power = 0
mincost_list = []
for i in range(10):
    mincost_list.append(mincost(i,1))


for h in range(H):
    for w in range(W):
        if board[h][w] == -1 or board[h][w] == 1:
            pass
        else:
            need_magical_power += mincost_list[board[h][w]]

print(need_magical_power)
Buggy python submission (verdict: Runtime Error):
S_ = input()
T = input()
loop = len(S_) - len(T) + 1
stringlist = []

# check S_ in T
for n in range(loop):
    chance = True
    for i in range(len(T)):
        if S_[n+i] == T[i] or S_[n+i] == "?":
            pass
        else:
            chance = False
            break

    if chance:
        tmp = S_[:n] + T + S_[n+len(T):]
        stringlist.append(tmp)

if len(stringlist) == 0:
    print("UNRESTORABLE")
else:
    stringlist.sort()
    String = stringlist[0]
    S = ""
    for i in range(len(S_)):
        if String[i] == "?":
            S += "a"
        else:
            S += String[i]

print(S)





Fixed submission:
S_ = input()
T = input()
loop = len(S_) - len(T) + 1
stringlist = []

# check S_ in T
for n in range(loop):
    chance = True
    for i in range(len(T)):
        if S_[n+i] == T[i] or S_[n+i] == "?":
            pass
        else:
            chance = False
            break

    if chance:
        tmp = S_[:n] + T + S_[n+len(T):]
        stringlist.append(tmp)

if len(stringlist) == 0:
    print("UNRESTORABLE")
else:
    stringlist.sort()
    String = stringlist[0]
    S = ""
    for i in range(len(S_)):
        if String[i] == "?":
            S += "a"
        else:
            S += String[i]
    print(S)

Buggy python submission (verdict: Runtime Error):
S_ = input()
T = input()
loop = len(S_) - len(T) + 1
stringlist = []

# check S_ in T
for n in range(loop):
    chance = True
    for i in range(len(T)):
        if S_[n+i] == T[i] or S_[n+i] == "?":
            pass
        else:
            chance = False
            break

    if chance:
        tmp = S_[:n] + T + S_[n+len(T):]
        stringlist.append(tmp)

if len(stringlist) == 0:
    print(UNRESTORABLE)
else:
    stringlist.sort()
    String = stringlist[0]
    S = ""
    for i in range(len(S_)):
        if String[i] == "?":
            S += "a"
        else:
            S += String[i]

print(S)





Fixed submission:
S_ = input()
T = input()
loop = len(S_) - len(T) + 1
stringlist = []

# check S_ in T
for n in range(loop):
    chance = True
    for i in range(len(T)):
        if S_[n+i] == T[i] or S_[n+i] == "?":
            pass
        else:
            chance = False
            break

    if chance:
        tmp = S_[:n] + T + S_[n+len(T):]
        stringlist.append(tmp)

if len(stringlist) == 0:
    print("UNRESTORABLE")
else:
    stringlist.sort()
    String = stringlist[0]
    S = ""
    for i in range(len(S_)):
        if String[i] == "?":
            S += "a"
        else:
            S += String[i]
    print(S)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = []
for i in range(N): 
    a = int(input())
    if a not in ans:
        ans.append(a)
    else:
        ans.remove(a)


print(len(ans))

Fixed submission:
from collections import Counter
N = int(input())

ans = []
for i in range(N): 
    a = int(input())
    ans.append(a)

count = Counter(ans)

anser = 0
for _ in count.values():
    if _ % 2 == 1:
        anser += 1

print(anser)
Buggy python submission (verdict: Runtime Error):
Q, H, S, D = input().split()
Q, H, S, D = int(Q), int(H), int(S), int(D) # price 0.25 0.5 1.0 2.0
N = int(input())

per_2l_price = [Q*8, H*4, S*2, D]
per_1l_price = [Q*4, H*2, S]
per_05_price = [Q*2, H]
per_025_price = [Q]
needtobuy_l = N
needtobuy_m = 0


def st_min(lt):
    min_num = 0
    min_ = 1000000000000000000000000
    for i in range(len(lt)):
        if lt[i] < min_:
            min_num = i
            min_ = lt[i]
    return min_num
st_min


if needtobuy_l >= 2.0:
    mn = st_min(per_2l_price)
    needtobuy_m += per_2l_price[mn] * (needtobuy_l // 2.0)
    needtobuy_l -= 2.0 * (needtobuy_l // 2.0)
print(needtobuy_l, needtobuy_m)
input()
if needtobuy_l >= 1.0:
    mn = st_min(per_1l_price)
    needtobuy_m += per_1l_price[mn] * (needtobuy_l // 1.0)
    needtobuy_l -= 1.0 * (needtobuy_l // 1.0)
print(needtobuy_l, needtobuy_m)
input()
if needtobuy_l >= 0.5:
    mn = st_min(per_05_price)
    needtobuy_m += per_05_price[mn] * (needtobuy_l // 0.5)
    needtobuy_l -= 0.5 * (needtobuy_l // 0.5)
print(needtobuy_l, needtobuy_m)
input()
if needtobuy_l >= 0.25:
    needtobuy_m += Q * (needtobuy_l // 0.25)
    needtobuy_l -= 0.25 * (needtobuy_l // 0.25)

print(int(needtobuy_m))


Fixed submission:
Q, H, S, D = input().split()
Q, H, S, D = int(Q), int(H), int(S), int(D)
N = int(input())

needtobuy_l = N
needtobuy_m = 0
per_2l_price = [D,
                S*2, S+H*2, S+H+Q*2,
                H*4, H*3+Q*2, H*2+Q*4, H+Q*6,
                Q*8]
per_1l_price = [S,
                H*2, H+Q*2,
                Q*4]

if needtobuy_l % 2 == 0:
    mincost = min(per_2l_price)
    needtobuy_m = mincost * (needtobuy_l // 2)
else:
    mincost = min(per_2l_price)
    needtobuy_m = mincost * (needtobuy_l // 2)
    mincost = min(per_1l_price)
    needtobuy_m += mincost * 1

print(needtobuy_m)
Buggy python submission (verdict: Time Limit Exceeded):
A = list(input())
N = len(A)
uq_list = []

count = 1
for i in range(0, N):
    tempstr = A[i]
    for j in range(i+1, N):
        if A[j] != tempstr:
            count += 1

print(count)


Fixed submission:
from collections import Counter
A = input()
N = len(A)
counter = Counter(A)
count = 1


for i in range(0, len(A)):
    counter[A[i]] -= 1
    count += (len(A[(i+1):N]) - counter[A[i]])

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
A = list(input())
N = len(A)
uq_list = []


def concatStr(liststr):
    temp = ""
    for _ in liststr:
        temp += _
    return temp

for i in range(0, N):
    for j in range(i, N):
        temp = A.copy()
        temp[i], temp[j] = temp[j], temp[i]
        strings = concatStr(temp)
        if strings not in uq_list:
            uq_list.append(strings)

print(len(uq_list))


Fixed submission:
from collections import Counter
A = input()
N = len(A)
counter = Counter(A)
count = 1


for i in range(0, len(A)):
    counter[A[i]] -= 1
    count += (len(A[(i+1):N]) - counter[A[i]])

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


def solve(A, B, C, D):
    if A < C:
        if B < C:
            print("0")
        elif A <= C and D <= B:
            print(str(D-C))
        else:
            ptint(str(B-C))
    else:
        if D < A:
            print("0")
        elif C <= A and B <= D:
            print(str(B-A))
        else:
            print(str(D-A))

solve(A, B, C, D)


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


def solve(A, B, C, D):
    if A < C:
        if B < C:
            return 0
        elif A <= C and D <= B:
            return (D - C)
        else:
            return (B - C)
    else:
        if D < A:
            return 0
        elif C <= A and B <= D:
            return (B - A)
        else:
            return (D - A)

print(solve(A, B, C, D))

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

if A < C:
    if B < C:
        print(0)
    elif A <= C and D <= B:
        print(D-C)
    else:
        ptint(B-C)
else:
    if D < A:
        print(0)
    elif C <= A and B <= D:
        print(B-A)
    else:
        print(D-A)


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


def solve(A, B, C, D):
    if A < C:
        if B < C:
            return 0
        elif A <= C and D <= B:
            return (D - C)
        else:
            return (B - C)
    else:
        if D < A:
            return 0
        elif C <= A and B <= D:
            return (B - A)
        else:
            return (D - A)

print(solve(A, B, C, D))

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

if A < C:
    if B < C:
        print(0)
    elif A <= C and D <= B:
        print(D-C)
    else:
        ptint(B-C)
else:
    if D < A:
        print(0)
    elif C <= A and N <= D:
        print(B-A)
    else:
        print(D-A)


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


def solve(A, B, C, D):
    if A < C:
        if B < C:
            return 0
        elif A <= C and D <= B:
            return (D - C)
        else:
            return (B - C)
    else:
        if D < A:
            return 0
        elif C <= A and B <= D:
            return (B - A)
        else:
            return (D - A)

print(solve(A, B, C, D))