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-----
0 75 25 100

-----Sample Output-----
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.

Difficulty: introductory

Starter code:

Solutions:
a, b, c, d = list(map(int, input().split()))
s = max(a, c)
e = min(b, d)
print((e - s if e-s > 0 else 0))


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

a,b,c,d = map(int, input().split())
alice = set(i for i in range(a,b+1))
bob = set(j for j in range(c,d+1))
s = alice & bob
print(max(len(alice & bob) - 1, 0))

a = [int(x) for x in input().split()]
print(max(0,min(a[1],a[3]) -max(a[0],a[2])))

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

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

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

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

t = [0] * 101

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

for i in range(a, b):
    t[i] += 1
for j in range(c, d):
    t[j] += 1
print((t.count(2)))


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


LI = lambda: list(map(int, input().split()))

A, B, C, D = LI()


def main():
    x = max(A, C)
    y = min(B, D)
    ans = max(0, y - x)
    print(ans)


def __starting_point():
    main()

__starting_point()

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

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

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

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

def answer(a: int, b: int, c: int, d: int) -> int:
    return len(set(range(a, b)) & set(range(c, d)))


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


def __starting_point():
    main()
__starting_point()

A, B, C, D = [int(i) for i in input().split()]

t1 = max(A, C)
t2 = min(B, D)

print((max(0, t2 - t1)))


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


with open(0) as f:
    a, b, c, d = map(int, f.read().split())
f = lambda x: 0 if x < 0 else x
print(f(min(b, d) - max(a, c)))

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

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

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

import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    a,b,c,d = MII()
    print(max(min(b,d)-max(a,c), 0))

def __starting_point():
    main()
__starting_point()

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

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

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

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

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

import re
import copy

def accept_input():
    ast,aen,bst,ben = list(map(int, input().split()))
    return ast,aen,bst,ben

def process(s):
    if s == "#":
        return 1
    else:
        return 0
ast,aen,bst,ben = accept_input()

if ast >= bst and ast <= ben:
    print((min(ben,aen)-ast))
elif ast < bst:
    if aen < bst:
        print((0))
    else:
        print((min(aen,ben)-bst))
else:
    print((0))


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

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

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

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

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

a, b, c, d = tuple(map(lambda x: int(x), input().split(" ")))

start = max(a, c)
end = min(b, d)

print(max(end - start, 0))

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

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

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

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

mint = max(A, C)
maxt = min(B, D)

dt = max(0, maxt - mint)
print(dt)


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

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

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

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)

a, b, c, d = map(int, input().split())
if a < c:
        if b < c:
                print(0)
        if c <= b <= d:
                print(abs(b-c))
        if d < b:
                print(abs(d-c))
if c <= a:
        if d < a:
                print(0)
        if a <= d <= b:
                print(abs(d-a))
        if b < d:
                print(abs(b-a))

# -*- coding: utf-8 -*-

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

start = max(A,C)
end = min(B,D)
ans = max(end - start, 0)
print(ans)

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

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

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

def main():
    a, b, c, d = list(map(int, input().split()))
    print((max(0, min(b, d) - max(a, c))))


def __starting_point():
    main()

__starting_point()

a,b,c,d=map(int,input().split());r=min(b,d)-max(a,c);print([0,r][r>0])

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

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

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

a,b,c,d = map(int,input().split())
ans = min(b,d) - max(a,c)
print((ans,0)[ans<0])

def main():
    A, B, C, D = list(map(int, input().split()))

    if D <= A or B <= C:
        ans = 0
    if C <= A and A <= D:
        ans = D - A
    if C <= B and B <= D:
        ans = B - C
    if A <= C and D <= B:
        ans = D - C
    if C <= A and B <= D:
        ans = B - A
    print(ans)


def __starting_point():
    main()

__starting_point()

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

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

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


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


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

alice = [1 if A <= t < B else 0 for t in range(0, 110)]
bob = [1 if C <= t < D else 0 for t in range(0, 110)]

overlap = [1 for a, b in zip(alice, bob) if a > 0 and b > 0]

print((len(overlap)))


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

s1 = set(range(a,b+1))
s2 = set(range(c,d+1))


print(max(len(s1 & s2)-1,0))

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

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

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

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

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

import numpy as np

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

a = [0 for _ in range(100)]
b = [0 for _ in range(100)]

a[A:B] = [1 for _ in range(B - A)]
b[C:D] = [1 for _ in range(D - C)]

c = np.array(a) * np.array(b)

print(c.sum())


url = "https://atcoder.jp//contests/abc070/tasks/abc070_b"

def main():
    t = list(map(int, input().split()))
    start = max(t[0], t[2])
    end = min(t[1], t[3])
    if end >= start:
        print((end - start))
    else:
        print((0))

def __starting_point():
    main()

__starting_point()

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

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


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


ans = 0

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

print(ans)

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

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

if l[1] < l[2]:
    print(0)
elif l[0] > l[3]:
    print(0)
else:
    l.sort()
    print(l[2]-l[1])

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

a,b,c,d = list(map(int, input().split()))
x=[0]*101
cnt=0
for i in range(a,b+1):
    x[i]=1
for i in range(c,d+1):
    if x[i]==1:
        cnt+=1
if cnt==0:
    print(cnt)
else:
    print((cnt-1))


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


import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

# N = I()
# a = LI()

A, B, C, D = LI()

if B <= C or D <=A:
    ans = 0
elif C <= A and B <= D:
    ans = B - A
elif A<=C and D<=B:
    ans = D - C
elif A<=C and B<=D:
    ans = B-C
elif C<=A and D<=B:
    ans = D-A
else:
    ans = 'error'

print(ans)

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

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

if A<=C and D<=B: 
    print(D-C)
    return

if C<=A and B<=D: 
    print(B-A)
    return


if (A<=C and C<= B and B<=D): 
    print(B-C)
    return

if C<=A and A<=D and D<=B: 
    print(D-A)
    return

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

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

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

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

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

if (b<=c)|(d<=a):
    print(0)
else:
    if (a<=c)&(b<=d):
        print(b-c)
    elif (c<=a)&(d<=b):
        print(d-a)
    else:
        print(min(d-c,b-a))

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

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

def answer(a: int, b: int, c: int, d: int) -> int:
    return max(0, min(b, d) - max(a, c))


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


def __starting_point():
    main()
__starting_point()

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

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

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

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

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

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

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

bottom = max(A, C)
top = min(B, D)

if top - bottom > 0:
    print((top - bottom))
else:
    print((0))


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

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


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


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


lst = input().split()

A = int(lst[0])
B = int(lst[1])
C = int(lst[2])
D = int(lst[3])

if (B <= C) or (D <= A):
   print(0)
elif (A <= C <= B) and (C <= B <= D):
   print(B - C)
elif (C <= A <= D) and (A <= D <= B):
   print(D - A)
else:
   print(min([B - A, D - C]))

A,B,C,D = map(int,input().split())
if A>D or B<C:
  print(0)
  return
if C>A:
  A = C
if D<B:
  B = D
print(B-A)

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

a = list(range(A, B))
b = list(range(C, D))

a_b_and = set(a) & set(b)
print(len(a_b_and))

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

if C >= B or A >= D:
    print("0")

else:
    mi = max(A,C)
    ma = min(B,D)
    print(ma - mi)

A, B, C, D=map(int, input().split())
X=set([i for i in range(A, B)])
print(sum([1 for i in range(C, D) if i in X]))

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

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

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

A,B,C,D=list(map(int,input().split()))
ali='0'*101
bob='0'*101
ali=ali[:A]+'1'*(B-A)+ali[B+1:]
bob=bob[:C]+'1'*(D-C)+bob[D+1:]
ans=int(ali,2)&int(bob,2)
print((bin(ans).count('1')))


def main():
    A, B, C, D = list(map(int, input().split()))

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


def __starting_point():
    main()

__starting_point()

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

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

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

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

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