Problem:
 Score : 200 points    Problem Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?      Constraints  0≤A<B≤100  0≤C<D≤100  All input values are integers.         Input Input is given from Standard Input in the following format:  A  B  C  D       Output Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.        Sample Input 1 0 75 25 100      Sample Output 1 50  Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up. Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up. Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.       Sample Input 2 0 33 66 99      Sample Output 2 0  Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.       Sample Input 3 10 90 20 80      Sample Output 3 60

Solution (Python):
a, b, c, d = map(int, input().split())
a_b = [i for i in range(a, b+1)]
c_d = [i for i in range(c, d+1)]
counter = -1
flg = "False"

for i in range(len(a_b)):
  for j in range(len(c_d)):
    if a_b[i] == c_d[j]:
      counter += 1
      flg = "True"

if flg == "True":
  print(counter)
else:
  print(0)

Solution (Python):
a,b,c,d=map(int,input().split())
print(max(0,min(b,d)-max(a,c)))

Solution (Python):
a, b, c, d = map( int, input().split())
d = min(b,d) - max(a,c)
print(d if d>0 else 0)

Solution (Python):
A, B, C, D = [int(_) for _ in input().split()]
print(max(0, (min(B, D)-max(A, C))))

Solution (Python):
A_start, A_stop, B_start, B_stop = map(int, input().split())
if A_start <= B_start:
    if A_stop <= B_start:
        time = 0
    elif (A_stop > B_start) & (A_stop <= B_stop):
        time = A_stop - B_start
    else:
        time = B_stop - B_start
else:
    if B_stop <= A_start:
        time = 0
    elif (B_stop > A_start) & (B_stop <= A_stop):
        time = B_stop - A_start
    else:
        time = A_stop - A_start
print(time)

Solution (Python):
a,b,c,d = map(int, input().split())
if c >= b or a >= d:
    print(0)
else:
    if a <= c:
        print(min(b-c,d-c))
    else:
        print(min(d-a,b-a))

Solution (Python):
a, b, c, d = map(int, input().split())

list_alice = []
for i in range(a, b):
  list_alice.append(i)
  
list_bob = []
for i in range(c, d):
  list_bob.append(i)

print(len(list(set(list_alice) & set(list_bob))))

Solution (Python):
a,b,c,d = map(int,input().split())
start = max(a,c)
end   = min(b,d)
ans   = end-start 
if ans < 0:
    print(0)
else:
    print(ans)

Solution (Python):
a,b,c,d = map(int, input().split())
t = min(b,d) - max(a,c)
print(max(0,t))

Solution (Python):
A, B, C, D = [ int(i) for i in input().split() ]
c = 0
for i in range(101):
    if A <= i < B and C <= i < D:
        c += 1
print(c)

Solution (Python):
inputList = list(map(int, input().split(' ')))
A = inputList[0]
B = inputList[1]
C = inputList[2]
D = inputList[3]
answer = 0
if D <= A:
    answer = 0
elif C <= A <= D <= B:
    answer = (D-A)
elif C <= A and B <= D:
    answer = (B-A)
elif A <= C and D <= B:
    answer = (D-C)
elif A <= C <= B <= D:
    answer = (B-C)
print(answer)

Solution (Python):
a,b,c,d = map(int,input().split())
lower,upper = max(a,c),min(b,d)
print(max(upper-lower,0))

Solution (Python):
a, b, c, d = list(map(int, input().split()))

ab = [str(x) for x in range(a, b+1)]

cd = [str(x) for x in range(c, d+1)]

set_abcd = set(ab) & set(cd)

if len(set_abcd) <= 0:
	print(0)
else:
	print(len(set_abcd) - 1)

Solution (Python):
a, b, c, d = map(int, input().split())

lower = max(a, c)
upper = min(b, d)

if upper < lower:
  print('0')
else:
  print(upper - lower)

Solution (Python):
T = [int(i) for i in input().split()]
if T[0] >= T[3] or T[2] >= T[1]:
  print(0)
elif T[0] >= T[2]:
  print(min(T[3] - T[0], T[1] - T[0]))
elif T[2] >= T[0]:
  print(min(T[3] - T[2], T[1] - T[2]))

Solution (Python):
ali1, ali2, bob1, bob2 = map(int, input().split())

if ali1 <= bob1 <= ali2: 
    if ali1 <= bob2 <= ali2:
        print(bob2 -bob1)
    else:
        print(ali2 - bob1)
elif bob1 <= ali1 <=bob2:
    if bob1 <= ali2 <= bob2:
        print(ali2 - ali1)
    else:
        print(bob2 - ali1)
else:
    print(0)

Solution (Python):
def abc070_b():
    a, b, c, d = map(int, input().split())

    if c <= a < b <= d:
        return b - a

    if a <= c < d <= b:
        return d - c

    if a <= c < b <= d:
        return b - c

    if c <= a < d <= b:
        return d - a

    if b <= c or d <= a:
        return 0


if __name__ == '__main__':
    print(abc070_b())

Solution (Python):
a,b,c,d = map(int,input().split(" "))
if a >= c:
    e = a
else:
    e = c
if b <= d:
    f = b
else:
    f = d
if f - e <= 0:
    print(0)
else:
    print(f - e)

Solution (Python):
a,b,c,d = list(map(int,input().split()))
e = [a,c]
f = [b,d]

e = max(e)
f = min(f)

if (f-e) >= 0:
  print(f-e)
else:
  print(0)

Solution (Python):
A, B, C, D = list(map(int, input().split()))

if A < C:
    if B - C > 0:
        print(min(B - C, B - A, D - C))
    else:
        print("0")
elif C < A:
    if D - A > 0:
        print(min(D - A, B - A, D - C))
    else:
        print("0")
else:
    print(min(B - A, D - C))

Solution (Python):
a = list(map(int, input().split()))
t_start = max(a[0], a[2])
t_stop = min(a[1], a[3])
t = t_stop-t_start
if t > 0:
    print(t)
else :
    print(0)

Solution (Python):
A, B, C, D = map(int,input().split())
if A > C:
    x = A
else:
    x = C
if B < D:
    y = B
else:
    y = D
if (y-x) > 0:
    print(y-x)
else:
    print(0)

Solution (Python):
a, b, c, d = map(int, input().split())
x, y = sorted([(a, b), (c, d)])
if x[1] <= y[0]:
    print(0)
else:
    print(min(y[1], x[1]) - y[0])

Solution (Python):
A,B,C,D = map(int, input().split())

lower = max(A,C)
upper = min(B,D)

print(max(0,upper-lower))

Solution (Python):
a = list(map(int, input().split()))
alice = 0
bob = 0
ans = 0
for i in range(0, 101):
    if i == a[0]:
        alice = 1
    if i == a[1]:
        alice = 0
    if i == a[2]:
        bob = 1
    if i == a[3]:
        bob = 0

    ans += alice * bob
print(ans)

Solution (Python):
a,b,c,d = map(int,input().split())
s,e = max(a,c),min(b,d)
print(max(e-s,0))

Solution (Python):
a,b,c,d = map(int, input().split())

if b<=c or d<=a:
    print(0)
elif a<=c and b<=d:
    print(b-c)
elif a<=c and d<=b:
    print(d-c)
elif c<=a and b<=d:
    print(b-a)
elif c<=a and d<=b:
    print(d-a)
else:
    print(0)

Solution (Python):
A, B, C, D = list(map(int, input().rstrip().split(' ')))

t = min(B, D) - max(A, C)
print(t if t > 0 else 0)

Solution (Python):
A, B, C, D = map(int, input().split(' '))

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

Solution (Python):
a, b, c, d = map(int, input().split())

def between_time(before, after):
  diff = after - before
  if diff > 0:
    return diff
  else:
    return 0
  
if a > c:
  start = a
else:
  start = c

if b > d:
  fin = d
else:
  fin = b

print(between_time(start, fin))

Solution (Python):
a, b, c, d = map(int, input().split())
s = max(a, c)
e = min(b, d)
print(max(e - s, 0))

Solution (Python):
a,b,c,d = map(int,input().split())
m = [0]*102
m[a] += 1
m[b] -= 1
m[c] += 1
m[d] -= 1
for i in range(1,102):
    m[i] += m[i-1]
print(m.count(2))

Solution (Python):
A,B,C,D=map(int,input().split())
print(max([0,min([B,D]) - max([A,C])]))

Solution (Python):
a, b, c, d = map(int, input().split())
print(len(set(range(a, b)) & set(range(c, d))))

Solution (Python):
a,b,c,d=map(int,input().split());print(len(set(range(a,b))&set(range(c,d))))

Solution (Python):


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

if b <= c or a==b or c==d or d <= a:
  print(0)
else:
  print(min(b,d)-max(a,c))

Solution (Python):
l=list(map(int,input().split()))
if l[0]>=l[3] or l[1]<=l[2]:
    print(0)
elif (l[0]<l[2]and l[3]<l[1]) or (l[2]<l[0] and l[1]<l[3]):
    print(min(l[3]-l[2],l[1]-l[0]))
else :
    print(min(l[3]-l[0],l[1]-l[2]))

Solution (Python):
A, B, C, D = map(int, input().split( ))

print(max(0, min(B, D)- max(A,C)))

Solution (Python):
A, B, C, D = map(int, input().split( ))
if B <= C or D <= A:
	print(0)
else:
	print(min(B, D)- max(A,C))

Solution (Python):
a, b, c, d = list(map(int, input().rstrip().split()))
time = []
t_max = max([b, d])
for t in range(t_max + 1):
    if a <= t <= b:
        flag_alice = 1
    else:
        flag_alice = 0
    if c <= t <= d:
        flag_bob = 1
    else:
        flag_bob = 0
    time.append([flag_alice, flag_bob])
switch = 0
for t in time:
    if t == [1, 1]:
        switch += 1
if switch > 0:
    switch -= 1
print(switch)

Solution (Python):
a,b,c,d=map(int,input().split())
if (b<=c)|(d<=a):
    print(0)
elif a<=c<=b<=d:
    print(b-c)
elif c<=a<=d<=b:
    print(d-a)
elif a<=c<=d<=b:
    print(d-c)
else:
    print(b-a)

Solution (Python):
from sys import stdin


def main() -> int:
    a = next_int()
    b = next_int()
    c = next_int()
    d = next_int()

    ans = 0
    for i in range(a, b):
        if c <= i < d:
            ans += 1
    print(ans)
    return 0


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Solution (Python):
A,B,C,D = map(int, input().split())
if B<=C or D<=A:
    print(0)
else:
    print(min(B,D)-max(A,C))

Solution (Python):
a,b,c,d = map(int,input().split())
if d <= a or b <= c:
  print(0)
elif a <= c and d <= b:
  print(d-c)
elif c <= a and b <= d:
  print(b-a)
elif a <= c <= b <= d:
  print(b-c)
elif c <= a <= d <= b:
  print(d-a)

Solution (Python):
A, B, C, D = map(int, input().split())
if A < C:
    a, b, c, d = A, B, C, D
else:
    a, b, c, d = C, D, A, B

if b <= c:
    print(0)
    exit()

print(min(b, d) - c)

Solution (Python):
A, B, C, D = list(map(int, input().split()))
if B <= C or D <= A:
	print(0)
else:
	print(min(B, D) - max(A, C))

Solution (Python):
a,b,c,d = map(int,input().split())
ans = 0
for i in range(101):
  if a <= i < b and c <= i < d:
    ans += 1
print(ans)

Solution (Python):
A, B, C, D = map(int,input().split())






an = [A, B, C, D]
an.sort()

if an == [A, C, B, D]:
    print((B - C))
elif an == [A, C, D, B]:
    print((D - C))
elif an == [C, A, D, B]:
    print((D - A))
elif an == [C, A, B, D]:
    print((B - A))
else:
    print('0')

Solution (Python):
A,B,C,D = map(int, input().split())

ans = 0
for i in range(101):
    if A<=i<B and C<=i<D:
        ans += 1
print(ans)

Solution (Python):
a,b,c,d = map(int, input().split())
print(max(0, (min(b,d)-max(a,c))))

Solution (Python):
A, B, C, D = map(int, input().split())
X, Y = 0, 0
if A <= C:
    X = C
else:
    X = A

if B <= D:
    Y = B
else:
    Y = D

print(max(0, Y - X))

Solution (Python):
a,b,c,d = map(int,input().split())

if a > c:
  start = a
else:
  start = c

if b < d:
  end = b
else:
  end = d

print(0 if end-start < 0 else end-start)

Solution (Python):
a,b,c,d=map(int,input().split())
if a<c:
    if c<=b<=d:
        print(b-c)
    elif b<c:
        print(0)
    elif d<b:
        print(d-c)
if a>=c:
    if a<=d<=b:
        print(d-a)
    elif d<a:
        print(0)
    elif d>b:
        print(b-a)

Solution (Python):
a, b, c, d = map(int, input().split())
print(max(0, min(b, d) - max(a, c)))

Solution (Python):
A,B,C,D = map(int, input().split())
print(len(set(range(A,B)) & set(range(C,D))))

Solution (Python):
A,B,C,D = map(int, input().split())

risuto1 = []
risuto2 = []
for i in range(A,B+1):
    risuto1.append(i)
for i in range(C,D+1):
    risuto2.append(i)
kotae = len(set(risuto1) & set(risuto2)) 

if kotae == 0:
    print("0")
else:
    print(list(set(risuto1) & set(risuto2))[-1] - list(set(risuto1) & set(risuto2))[0])

Solution (Python):
a, b, c, d = map(int, input().split(" "))

print(max(0, min(b, d) - max(a, c)))

Solution (Python):
A, B, C, D = map(int, input().split())
if B <= C or D <= A:
    print(0)
else:
    if C < B:
        print(min(B, D)-max(C, A))
    elif A < D:
        print(min(B, D)-max(A, C))

Solution (Python):
a,b,c,d = map(int,input().split())
if a<c:
    if d < b:
        print(d-c)
    elif c < b:
        print(b-c)
    else:
        print(0)
else:
    if b < d:
        print(b-a)
    elif a < d:
        print(d-a)
    else:
        print(0)

Solution (Python):
input_list = list(map(int, input().split()))
a = input_list[0]
b = input_list[1]
c = input_list[2]
d = input_list[3]

Alice_range = set(range(a,b))
Bob_range = set(range(c,d))
same_time = len(Alice_range & Bob_range)

print(same_time)

Solution (Python):
a, b, c, d = map(int, input().split())
print(max(0,min(b,d)-max(a,c)))

Solution (Python):
listA = list(map(int, input().split()))
if min(listA[3], listA[1])-max(listA[0], listA[2])<0:
    print(0)
else:
    print(min(listA[3], listA[1])-max(listA[0], listA[2]))

Solution (Python):
a, b, c, d = map(int, input().split())

if b <= c or d <= a:
    print("0")
    exit(0)

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

Solution (Python):
a,b,c,d=map(int,input().split())
if ((c>a and c>b) or (a>c and a>d)):
    print(0)
else:
    print(min(b,d) - max(a,c))

Solution (Python):
a, b, c, d = list(map(int, input().split()))
ans = min(b,d) - max(a,c)
if ans < 0:
  ans = 0
print(ans)

Solution (Python):
a, b, c, d = map(int, input().split())

l = max(a, c)
r = min(b, d)

if l <= r:
    print(r - l)
else:
    print(0)

Solution (Python):
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a,b,c,d = li()

on = [0]*101

for i in range(101):
    if a <= i <= b and c <= i <= d:
        on[i] += 1
        
print(max(sum(on)-1, 0))

Solution (Python):
A,B,C,D = map(int,input().split())
ans = 0
for i in range(A,B):
    if C <= i < D:
        ans += 1
print(ans)

Solution (Python):
A,B,C,D = map(int,input().split())
ans = min(B,D)-max(A,C)
print(ans if ans>=0 else '0')

Solution (Python):
A, B, C, D = map(int, input().split(' '))

s = sorted([A,B,C,D])

if (s[1]==B and s[2] == C) or (s[1]==D and s[2] == A) :
    print('0')
else:
    print(str(s[2]-s[1]))

Solution (Python):
A,B,C,D = map(int, input().split())

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

Solution (Python):
a,b,c,d = map(int, input().split())
print(max(0, min(b,d) - max(a,c)))

Solution (Python):
A,B,C,D = map(int,input().split())
if B <= C :
    print(0)
elif D <= A :
    print(0)
elif A <= D and C <= B :
    if A <= C  and D <= B :
        print(D-C)
    elif C <= A and B <= D :
        print(B-A)
    elif (D-A) > (B-C) :
        print(B-C)
    else :
        print(D-A)

Solution (Python):
n = list(map(int, input().split()))

def func1(k,l):
    if k>l:
        return l
    else:
        return k

def func(x):
    if (x[2]>x[1]) or (x[0]>x[3]):
        return 0
    else:
        if x[0]>x[2]:
            return (func1(x[1],x[3])-x[0])
        else:
            return (func1(x[1],x[3])-x[2])

print(func(n))

Solution (Python):
A, B, C, D = map(int, input().split())
ans = min(B, D) - max(A, C)
if ans <= 0:
    print(0)
else:
    print(ans)

Solution (Python):
a,b,c,d=map(int,input().split())
if b<=c or d<=a:print(0)
elif a<c<b<d:print(b-c)
elif c<a<d<b:print(d-a)
else:print(min(b-a,d-c))

Solution (Python):
A,B,C,D = map(int, input().split())
if A > C:
    A,C = C,A
    B,D = D,B

if B > C:
    ans = min(B,D) - max(A,C)
else:
    ans = 0
print(ans)

Solution (Python):
A,B,C,D = map(int,input().split())
p = min(B,D)-max(A,C)
if (p <= 0):
  print('0')
else:
  print(p)

Solution (Python):
A, B, C, D = map(int, input().split())
imos = [0 for i in range(102)]
imos[A] += 1
imos[B] -= 1
imos[C] += 1
imos[D] -= 1
for i in range(1, 101):
    imos[i] += imos[i - 1]
cnt = 0
for i in range(101):
    if imos[i] == 2:
        cnt += 1
print(cnt)

Solution (Python):
A,B,C,D=map(int,input().split())
if A>C:
    A,B,C,D=C,D,A,B
if C<=B and B<=D:
    print(B-C)
elif A<=C and D<=B:
    print(D-C)
else:
    print(0)

Solution (Python):
a,b,c,d = map(int, input().split())

print(max(min(b, d) - max(a, c), 0))

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    A, B, C, D = map(int, input().split())
    print(max(0, min(B, D) - max(A, C)))


if __name__ == '__main__':
    main()

Solution (Python):
A, B, C, D=map(int, input().split())
if max(A,C)<=min(B,D):
    print(min(B,D)-max(A,C))
else:
    print(0)

Solution (Python):
a,b,c,d = map(int, input().split())
left = max(a,c)
right = min(b,d)
print(max(0,right-left))

Solution (Python):
a, b, c, d = list(map(int, input().split()))

ans = max(0, min(b, d)-max(a, c))
print(ans)

Solution (Python):
A, B, C, D = map(int, input().split())

print(max(min(B, D) - max(A, C),0))

Solution (Python):
a,b,c,d = map(int,input().split())
if c>b or a>d:
    print(0)
else:
    print(min(b,d) - max(a,c))

Solution (Python):
a, b, c, d = [int(v) for v in input().split()]
ans = min(b, d) - max(a, c)
if ans < 0:
    ans = 0
print(ans)

Solution (Python):
a,b,c,d=map(int,input().split());print(max(0,min(b,d)-max(a,c)))

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]




dp = None


def main():
    A, B, C, D = li_input()
    L = [0] * 101

    for i in range(101):
        if A <= i < B:
            L[i] += 1

        if C <= i < D:
            L[i] += 1

    ans = 0

    for l in L:
        if l == 2:
            ans += 1

    print(ans)


main()

Solution (Python):
A,B,C,D = list(map(int, input().split()))
ans = sum([(A <= i and i < B) and (C <= i and i < D) for i in range(101)])
print (ans)

Solution (Python):
import numpy
a, b, c, d = map(int, input().split())
l = [0]*110
l[a] += 1
l[b] -= 1
l[c] += 1
l[d] -= 1
l = numpy.cumsum(l)
print(list(l).count(2))

Solution (Python):
a, b, c, d = map( int, input().split())
print( max(0, min(b,d) - max(a,c)))

Solution (Python):
A, B, C, D = map(int, input().split())

if B <= C:
    print(0)

elif D <= A:
    print(0)

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

elif C > A:
    if  B >= D:
        print(D-C)
    else:
        print(B-C)

Solution (Python):

a,b,c,d=map(int,input().split())
if a<=c<=b:
    if b<=d:
        print(b-c)
    else:
        print(d-c)
elif b<c or d<=a:
    print(0)
elif c<a and b<d:
    print(b-a)
else:
    print(d-a)

Solution (Python):
a,b,c,d=map(int,input().split())

higher=min(b,d)
lower=max(a,c)

if higher<lower:
  print(0)
else:
  print(higher-lower)

Solution (Python):
A, B, C, D = [int(t) for t in input().split()]
t = min(B, D) - max(A, C)
print(max(0, t))

Solution (Python):
a, b, c, d = map(int, input().split())
time_list = [a, b, c, d]

if c - b > 0 or a - d > 0:
    print('0')
else:
    time_list.sort()
    print(time_list[2] - time_list[1])

Solution (Python):
A,B,C,D = [int(x) for x in input().split()]

left  = max(A,C)
right = min(B,D)

width = right - left
print(width if width>0 else 0)

Solution (Python):
a, b, c, d = map(int, input().split())
t = min(b, d) - max(a, c)
if t < 0:
  print(0)
else:
  print(t)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

a,b,c,d = inpl()
print(max(0,(min(b,d)-max(a,c))))

Solution (Python):
A, B, C, D = map(int, input().split())
if min(B, D) - max(A, C) >= 0:
    print(min(B, D) - max(A,C))
else:
    print(0)

Solution (Python):

a1, a2, b1, b2 = map(int, raw_input().split())


if a1 <= b1 <= a2:
    
    if b2 <= a2:
        print(b2 - b1)
    else:
        print(a2 - b1)
elif b1 <= a1 <= b2:
    
    if a2 <= b2:
        print(a2 - a1)
    else:
        print(b2 - a1)
else:
    print(0)

Solution (Python):
import sys
a, b, c, d = map(int, input().split())

def ans(a):
    if a < 0:
        print(0) 
    else:
        print(a)

if a < c:
    if c < b:
        if b < d:
            ans(b-c)
        else:
            ans(d-c)
    else:
        ans(0)
else:
    if a < d:
        if d < b:
            ans(d-a)
        else:
            ans(b-a)
    else:
        ans(0)

sys.exit(0)

Solution (Python):


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

    if min(b, d) - max(a, c) >= 0:
        print(min(b, d) - max(a, c))
    else:
        print(0)

if __name__ == '__main__':
    main()

Solution (Python):
a,b,c,d = list(map(int,input().split()))
if (min(b,d)-max(a,c)) < 0:
    print(0)
else:
    print(min(b,d)-max(a,c))

Solution (Python):
a,b,c,d=map(int,input().split())
l={i for i in range(a,b+1)}&{i for i in range(c,d+1)}
if not l:
  print(0)
else:
  print(len(l)-1)

Solution (Python):
a,b,c,d=map(int,input().split())
ans=[0 for _ in range(100)]
for i in range(a,b):
    ans[i] += 1
for i in range(c,d):
    ans[i] += 1
print(ans.count(2))

Solution (Python):
A,B,C,D=map(int,input().split())
print(max(0,min(B,D)-max(A,C)))

Solution (Python):
a, b, c, d = map(int, input().split(" "))

print(max(0, min(b, d) - max(a, c)))

Solution (Python):
A,B,C,D = map(int,input().split())

a = []
for i in range(A,B+1):
    a.append(i)
b = []
for i in range(C,D+1):
    b.append(i)
c = set(a)&set(b)
if c ==set():
    print(0)
else:
	print(len(c)-1)

Solution (Python):
A,B,C,D=list(map(int,input().split()))
time=0
if A<=D and C<=B:
    time=min(B,D)-max(A,C)
else:
    pass
print(time)

Solution (Python):
A, B, C, D = map(int, input().split())

s = max(A, C)
e = min(B, D)
print(max(0, e - s))

Solution (Python):
a,b,c,d=map(int,input().split())
x=min(b,d)-max(a,c)
print(x if x>0 else 0)

Solution (Python):
A, B, C, D = map(int, input().split())
print(max(0, min(B, D) - max(A, C)))

Solution (Python):
a,b,c,d=map(int,input().split())
start=max(a,c)
end=min(b,d)
print(end-start if end-start > 0 else 0)

Solution (Python):
A, B, C, D = map(int, input().split())
print(max(0, min(B, D) - max(A, C)))

Solution (Python):
A,B,C,D = map(int, input().split())
s = A if A > C else C
e = B if B < D else D
if e < s:
    print(0)
else:
    print(e-s)

Solution (Python):
a, b, c, d = list(map(int, input().split()))
if b<c or d<a:
  print(0)
else:
  print(min(b, d)-max(a, c))

Solution (Python):
A, B, C, D = map(int, input().split())
if max(A, C) < min(B, D):
	print(min(B, D) - max(A, C))
else:
	print(0)

Solution (Python):
A, B, C, D = map(int, input().split())
if C < A:
    A, B, C, D = C, D, A, B
print(min(D - C, B - A, max(0, B - C)))

Solution (Python):
A, B, C, D = map(int, input().split())
if max(A, C) <= min(B, D):
	print(min(B, D) - max(A, C))
else:
	print(0)

Solution (Python):
a,b,c,d=map(int,input().split())
print(max(0,min(b,d)-max(a,c)))

Solution (Python):
a, b, c, d = map(int, input().split())

print(max(0, min(d, b) - max(a, c)))

Solution (Python):
a,b,c,d=map(int, input().split())

e=max([a,c])
f=min([b,d])

if f-e<0:
    print(0)
else:
    print(f-e)

Solution (Python):
import sys

a, b, c, d = list(map(int, input().split()))

if b < c or d < a:
  print(0)
  sys.exit()

if a < c:
  if b < d:
    print(b - c)
    sys.exit()
  else:
    print(d - c)
else:
  if b < d:
    print(b - a)
  else:
    print(d - a)

Solution (Python):
a,b,c,d = map(int, input().split())
ans = min(b,d) - max(a,c)
if ans > 0 :
    print(ans)
else:
    print("0")

Solution (Python):
"""
https://abc070.contest.atcoder.jp/tasks/abc070_b
"""
[a,b,c,d]=[int(i) for i in input().split()]

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

elif a<=c and c<=b and b<=d:
    print(b-c)

elif c<=a and b<=d:
    print(b-a)

elif c<=a and d<=b:
    print(d-a)

elif a<=c and d<=b:
    print(d-c)

Solution (Python):
A, B, C, D = map(int, input().split())

max_AC = max(A, C)
min_BD = min(B, D)

if min_BD >= max_AC:
    print(min_BD - max_AC)
else:
    print(0)

Solution (Python):
A, B, C, D = map(int, input().split())

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

Solution (Python):
A,B,C,D = map(int,raw_input().split())
print sum([1 if A<=x and x+1<=B and C<=x and x+1<=D else 0 for x in range(100)])

Solution (Python):
A, B, C, D = input().split(' ')
A, B, C, D = int(A), int(B), int(C), int(D)

if B < C or D < A:
    print(0)
else:
    print(min(D, B) - max(C, A))

Solution (Python):
[A, B, C, D] = [int(x) for x in input().split()]
E = min(B, D) - max(A, C)
E = E if E > 0 else 0
print(E)

Solution (Python):
a,b,c,d = map(int, input().split())
ret = min(b,d) - max(a,c)
if ret > 0 :
    print(ret)
else:
    print("0")

Solution (Python):
A, B, C, D = map(int, input().split())

t = min(B, D) - max(A, C)
if t < 0:
    print(0)
else:
    print(t)

Solution (Python):
a,b,c,d=map(int,input().split())
print(max(0,min(b,d)-max(a,c)))

Solution (Python):
A,B,C,D = map(int,input().split())
ans = 0
for i in range(0,100):
    if A<=i<B and C<=i<D:
        ans += 1
print(ans)

Solution (Python):


A, B, C, D = map(int, input().split())

ans = min(B, D) - max(A, C)

if ans > 0:
    print(ans)
else:
    print(0)

Solution (Python):


A, B, C, D = map(int, input().split())

ans = 0
for i in range(0, 100):
    if A <= i < B and C <= i < D:
        ans += 1
print(ans)

Solution (Python):

A, B, C, D = map(int, input().split())

ans = 0

if A <= D:
    if A >= C:
        if B >= D:
            ans = D - A
        else:
            ans = B - A
if C <= B:
    if A < C:
        if B >= D:
            ans = D - C
        else:
            ans = B - C

print(ans)

Solution (Python):
A, B, C, D=map(int,input().split())
maximum=max(A,C)
minimum=min(B,D)
if minimum-maximum<0:
    print (0)
else:
    print(minimum-maximum)

Solution (Python):
A, B, C, D = map(int, input().split())
print(max(min(B, D) - max(A, C), 0))

Solution (Python):


a, b, c, d = map(int, input().split())
if b < c or d < a:
    print(0)
else:
    print(min(b, d) - max(a, c))

Solution (Python):
A_s, A_e, B_s, B_e = map(int, input().split())


lower = max(A_s, B_s)
upper = min(A_e, B_e)

print(max(0, upper - lower))

Solution (Python):
a,b,c,d = map( int, input().split() )
def main(b,c,d):
    r1 = max(0, b - c)
    r2 = max(0, b - d)
    print(max(0,r1 - r2))
if a <= c:
    main(b, c, d)
else:
    main(d, a, b)

Solution (Python):
a,b,c,d=map(int,input().split());print(len(set(range(a,b))&set(range(c,d))))

Solution (Python):
A, B, C, D = map(int, input().split())
print(max(0, min(B, D) - max(A, C)))

Solution (Python):
A, B, C ,D = map(int, input().split())

def cal(n):
    global B, D
    if B <= D:
        print(B-n)
    else:
        print(D-n)

if A >= D or B <= C:
    print(0)
elif A >= C:
    cal(A)
else:
    cal(C)

Solution (Python):
A, B, C ,D = map(int, input().split())

if A >= D or B <= C:
    print(0)
elif A >= C:
    if B <= D:
        print(B-A)
    else:
        print(D-A)
else:
    if B <= D:
        print(B-C)
    else:
        print(D-C)

Solution (Python):
a,b,c,d=map(int,input().split())
print(max(min(b,d)-max(a,c),0))

Solution (Python):
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	a, b, c, d = map(int, input().split())
	print(max(0, min(b, d) - max(a, c)))

if __name__ == '__main__':
	main()

Solution (Python):
A,B,C,D = map(int,input().split())

if A < C:
    if B < D:
        if B - C >= 0:
            print(B-C)
        else:
            print(0)
    else:
        if D - C >= 0:
            print(D-C)
        else:
            print(0)
else:
    if B < D:
        if B - A >= 0:
            print(B-A)
        else:
            print(0)
    else:
        if D - A >= 0:
            print(D-A)
        else:
            print(0)

Solution (Python):
a, b, c, d = map(int,input().split())
if (min(b, d) - max(a, c)) <= 0:
    print('0')
else :
    print('{}'.format(min(b, d) - max(a, c)))

Solution (Python):
a,b,c,d = map(int,input().split())
ans = min(b,d) - max(a,c)
if ans <= 0:
    print(0)
else:
    print(ans)

Solution (Python):
a,b,c,d=[int(i) for i in input().split()];print(max(0, min(b,d)-max(a,c)))

Solution (Python):
a, b, c, d = [int(i) for i in input().split()]

alice = [0] * 101
bob = [0] * 101

for i in range(a,b):
    alice[i] = 1
    
for i in range(c, d):
    bob[i] = 1

cnt = 0
for i in range(max(b,d)):
    if alice[i] == 1 and bob[i] == 1:
        cnt += 1

print(cnt)

Solution (Python):
A,B,C,D = (int(i) for i in input().split())

if B<=C:
    print(0)
elif D<=A:
    print(0)
else:
    big = min(D,B)
    small = max(A,C)
    print(big-small)

Solution (Python):
A, B, C, D = map(int, input().split())

if B < C or D < A:
    print(0)

elif A < C:
    print(min(B - C, D - C))

else:
    print(min(D - A, B - A))

Solution (Python):
A,B,C,D=map(int,input().split())
ans=0
if min(B,D)-max(A,C) >0:
    ans=min(B,D)-max(A,C)
print(ans)

Solution (Python):
def dup(A, B):
    r = 0
    for x in A:
        if x in B:
          r = r + 1
    return r-1 if r != 0 else 0


a, b, c, d = (int(i) for i in input().split())

A = range(a, b+1)
B = range(c, d+1)

result = dup(A, B) if len(A) <= len(B) else dup(B, A)

print(result)

Solution (Python):
a, b, c, d = map(int, input().split())
print(max(0, min(b, d) - max(c, a)))

Solution (Python):
a, b, c, d = map(int, input().split())
print(max(min(b, d) - max(a, c), 0))

Solution (Python):
a, b, c, d = map(int, input().split())

if (a<=c and b<=c) or (c<=a and d<=a):
    print(0)
else:
    print(min(b,d)-max(a,c))

Solution (Python):
def smaller(x, y):
	if x < y: return x
	else: return y

def calc(a, b, c, d):
	if b < c: return 0
	else: return smaller(b, d) - c

A, B, C, D = map(int, raw_input().split())

if A > C:
	tmp1 = A
	tmp2 = B
	A = C
	B = D
	C = tmp1
	D = tmp2

print calc(A, B, C, D)