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())

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

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

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 a > c:
  if a > d:
    print('0')
    exit()
  elif b < d:
    print(str(b-a))
    exit()
  else:
    print(str(d-a))
    exit()
else:
  if c > b:
    print('0')
    exit()
  elif d < b:
    print(str(d-c))
    exit()
  else:
    print(str(b-c))
    exit()

Solution (Python):
A,B,C,D = (int(i) for i in input().split())
Alice_time = set(range(A,B+1))
Bob_time = set(range(C,D+1))
common_time = Alice_time & Bob_time
common_time_list = list(common_time)
common_time_list_sorted = sorted(common_time_list)
if len(common_time_list_sorted) > 1:
    print(common_time_list_sorted[-1]-common_time_list_sorted[0])
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())
ans=min(b,d)-max(a,c)
print(ans if ans>0 else 0)

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

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

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

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

if k>=l:
    print(0)
else:
    print(l-k)

Solution (Python):
import sys

a, b, c, d = map(int, sys.stdin.readline().split())

def main():
    return max(0, min(b, d) - max(a, c))

if __name__ == '__main__':
    ans = main()
    print(ans)

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

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

alice = set(range(a, b+1))
bob = set(range(c, d+1))

ans = len(alice & bob)

print(max(ans - 1, 0))

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

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

print(max(0, end - start))

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

Solution (Python):
a,b,c,d=map(int,input().split())
l=[a,b,c,d]
if b>c and d>a:
    l.sort()
    print(l[2]-l[1])
else:
    print(0)

Solution (Python):
import sys
input = sys.stdin.readline
A,B,C,D=map(int,input().rstrip().split())
start=max(A,C)
end=min(B,D)
if end-start>0:
    print(end-start)
else:
    print(0)

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

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

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

Solution (Python):
A, B, C, D = map(int, input().split())
if C - B < 0 and A - D < 0:
        print(min(D, B) - max(C, A)) 
else:
        print(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,b,c,d=map(int,input().split())
s,g=max(a,c),min(b,d)
ans=g-s
print(ans if ans>0 else 0)

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

ans = 0
for i in range(101):
    if i >= a and i < b and i >= c and i < d:
        ans += 1
print(ans)

Solution (Python):
a, b, c, d = map(int, input().split())
 
cnt = [0]*101
for i in range(a, b+1):
    cnt[i] += 1
for j in range(c, d+1):
    cnt[j] += 1
 
ans = cnt.count(2) - 1
if ans == -1:
    print(0)
else:
    print(ans)

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

if(C-B>0 or A-D>0):
    print(0)
    exit()
start=max(A,C)
end=min(B,D)
print(end-start)

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

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

Solution (Python):
a, b, c, d = 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(0,min(b,d)-max(a,c)))

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    ls = [0] * 101
    a, b, c, d = list(map(int, readline().split()))
    for i in range(a, b):
        ls[i] += 1
    for i in range(c, d):
        ls[i] += 1
    print(ls.count(2))


if __name__ == '__main__':
    solve()

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())

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

Solution (Python):
a,b,c,d=[int(i) for i in input().split()]
if(c-b>0 or a-d>0):
    print(0)
    exit()
start=max(a,c)
end=min(b,d)
print(end-start)

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

Solution (Python):
a,b,c,d=map(int,input().split())
s=max(a,c)
e=min(b,d)
ans=max(0,e-s)
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())
if b<c:
    print(0)
elif d<a:
    print(0)
else:
    print(min(b,d)-max(a,c))

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







ans = 0
al = range(a,b + 1)
bo = range(c,d + 1)
for l in al:
  if l in bo:
    ans += 1
if ans > 0:
  print(ans - 1)
else:
  print(0)

Solution (Python):

c=input().split()
for i in range(len(c)):
    c[i]=int(c[i])
if c[1]<c[2] or c[3]<c[0]:
    print(0)
else:
    c.sort()
    print(c[2]-c[1])

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    a,b,c,d=MI()
    print(max(min(b,d)-max(a,c),0))

main()

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)
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)
else:
    print(d - a)

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

if C <= B and A <= C:
    if D <= B:
        time = D - C
    else:
        time = B - C

if D >= A and A >= C:
    if D <= B:
        time = D - A
    else:
        time = B - A

print(time)

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

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

Solution (Python):
ABCD=list(map(int,input().split()))
A=ABCD[0]
B=ABCD[1]
C=ABCD[2]
D=ABCD[3]

E=list(range(A,B+1))
F=list(range(C,D+1))

if len(list(set(E)&set(F)))==0:
    print(0)
else:
    print(len(list(set(E)&set(F)))-1)

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

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 = map(int, input().split())

alice = []
bob = []
for i in range(a, b+1):
    alice.append(i)

for j in range(c, d+1):
    bob.append(j)


count=0
for i in range(len(alice)):
    if alice[i] in bob:
        count += 1

if count>0:
    print(count-1)
else:
    print(count)

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

print(max(time, 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 = (int(i) for i in input().split())

X = max(A,C)
Y = min(B,D)

ans = max(Y - X,0)
print(ans)

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

    if not (0 <= a and a < b and b <= 100 and 0 <= c and c < d and d <= 100):
        return
    if not (isinstance(a, int) and isinstance(b, int) and isinstance(c, int) and isinstance(d, int)):
        return
    
    if(b <= c or d <= a):
        print(0)
    elif(a <= c and c < b and b <= d):
        print(b - c)
    elif(c <= a and a < d and d <= b):
        print(d - a)
    elif(a <= c and d <= b):
        print(d - c)
    elif(c <= a and b <= d):
        print(b - a)


if __name__ == "__main__":
    main()

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

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

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):


import numpy as np

A,B,C,D=list(map(int,input().split(" ")))
R=np.zeros((100,))

if B<100:
    R[B]+=-1
if D<100:
    R[D]+=-1

R[A]+=1
R[C]+=1

Rcum=np.cumsum(R)
print((Rcum==2).sum())

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())
if A <= C <= D <= B:
    print(D-C)
elif C <= A <= B <= D:
    print(B-A)
elif C <= A <= D <= B:
    print(D-A)
elif A <= C <= B <= D:
    print(B-C)
else:
    print(0)

Solution (Python):
A,B,C,D  =map(int,input().split())
AB = [str(i) for i in range(A,B+1)]
CD = [str(j) for j in range(C,D+1)]
count = 0

for a in range(101):
  if str(a) in AB and str(a) in CD:
    count += 1
if count == 0:
  print(0)
else:
  print(count-1)

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(abs(min(b,d)-max(a,c)))

Solution (Python):
from sys import stdin
from itertools import groupby

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

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

Solution (Python):
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)

Solution (Python):
import numpy as np

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

alice = np.zeros(max(B, D))
bob = np.zeros(max(B, D))

alice[A:B] = 1
bob[C:D] = 1



print(np.sum(alice + bob == 2))

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

k = 100

la = [0]*(k+1)
lb = [0]*(k+1)

for i in range(a,b+1):
	
	la[i] = la[i] + 1

for i in range(c,d+1):
	
	lb[i] = lb[i] + 1

ans = 0
for i in range(k+1):
	
	if la[i]==lb[i]==1:
		ans = ans + 1

print( ans-1 if ans!=0 else 0)

Solution (Python):
A,B,C,D = map(int,input().split())
ans = 0
alice = [i for i in range(A,B+1)]
bob = [i for i in range(C,D+1)]
for i in alice:
    if(i in bob):
        ans += 1
print(max((ans - 1),0))

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=map(int,input().split(" "))
alice=list(range(a,b+1))
bob=list(range(c,d+1))
both=list(set(alice).intersection(set(bob)))
if both==[]:
    print(0)
else:
    print(both[-1]-both[0])

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

Solution (Python):
a, b, c, d = map(int, input().split())
length = max(b,d)
checker = [0] * length
for i in range(a, b):
    checker[i] = 1
for i in range(c, d):
    checker[i] = 1
ans = (b-a) + (d-c) -sum(checker)
print(ans)

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):
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())
Alice = [A,B]
Bob = [C,D]
array = [Alice,Bob]
array.sort()
if array[0][1] <= array[1][0]:
    print(0)
elif array[1][1] <= array[0][1]:
    print(array[1][1]-array[1][0])
else:
    print(array[0][1]-array[1][0])

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

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

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):

line = [int(i) for i in input().split()]
v1 = line[0]
v2 = line[1]
v3 = line[2]
v4 = line[3]

s1 = set(range(v1,v2+1))
s2 = set(range(v3,v4+1))

inter = s1.intersection(s2)

res = len(inter)-1
if res == -1 : res = 0
print(res)

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())
print(max(min(b,d)-max(a,c),0))

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 min(B,D)-max(A,C)<0:
    print(0)
else:
    X=max(A,C)
    Y=min(B,D)
    print(Y-X)

Solution (Python):
def examB():
    A, B, C, D = LI()
    ans = max(0,min(B,D) - max(A,C))
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Solution (Python):

a, b, c, d = [int(s) for s in input().split()]

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

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

Solution (Python):
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)
elif b <= c or d <= a:
    print(0)
else:
    print(0)

Solution (Python):


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

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

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

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

print(max(0,f-e))

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(min(b,d)-max(a,c),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(b,d) - max(a,c))))

Solution (Python):
A,B,C,D = map(int,input().split())
 
alice = [i for i in range(A,B + 1)]
bob = [i for i in range(C,D + 1)]
 
common = [i for i in bob if i in alice]

if len(common) == 0:
  print(0)
else:
  print(len(common)-1)

Solution (Python):
a,b,c,d=map(int, input().split())
x=list(range(a,b+1))
l=[]
for i in range(c,d+1):
  if i in x:
    l.append(i)
if len(l)==0:
  print(0)
elif len(l)==1:
  print(0)
else:
  print(l[-1]-l[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, b, c, d = map(int, input().split())

start = max(a, c)
stop = min(b, d)
ans = stop-start

print(0 if ans < 0 else ans)

Solution (Python):
aliceStart, aliceStop, bobStart, bobStop = map(int, input().split())
start = max(aliceStart, bobStart)
stop = min(aliceStop, bobStop)
ans = stop - start
if ans < 0:
  ans = 0
print(ans)

Solution (Python):
a,b,c,d=map(int,input().split())
al=[]
bl=[]
for i in range(a,b+1):
    al.append(i)
for i in range(c,d+1):
    bl.append(i)
albl=set(al)&set(bl)
if len(albl)==0:
    print(0)
else:
    print(len(albl)-1)

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

if a < c:
  st = c
else:
  st = a
if b < d:
  ed = b
else:
  ed =d
if ed-st < 0:
  print("0")
else:
  print(ed-st)

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

sw1 = 0
sw2 = 0
count  = 0
for i in range(100):
    if i == a:
        sw1 = 1
    elif i == b:
        sw1 = 0
    if i == c:
        sw2 = 1
    elif i == d:
        sw2 = 0

    if sw1 == 1 and sw2 == 1:
        count += 1

print(count)

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())
print(max(min(B, D) - max(A, C), 0))

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c,d = inpl()
res = 0
for i in range(a,d+1):
    if i <= b and i >= c:
        res += 1
print(max(0,res-1))

Solution (Python):
a, b, c, d = map(int, input().split())
alice = [i for i in range(a,b+1)]
bob = [i for i in range(c,d+1)]

ans = [i for i in alice if i in bob]
print(len(ans)-1 if ans != [] else 0)

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

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

Solution (Python):

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

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

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

Solution (Python):
from sys import stdin

a, b, c, d = map(int, stdin.readline().rstrip().split())

start = a if a >= c else c
end = b if b <= d else d

print((end - start) if end >= start else 0)

Solution (Python):
a = list(input().split())

b = int(a[0])
c = int(a[1])
d = int(a[2])
e = int(a[3])

if max(b,d) < min(c,e):
    print(min(c,e)-max(b,d))       

elif max(b,d)>=min(c,e):
        print(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,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())
alice = set(list(range(A,B+1)))
bob = set(list(range(C,D+1)))
if list(alice&bob) == []:
    print(0)
else:
    print(len(alice&bob)-1)

Solution (Python):
a_start, a_end, b_start, b_end = map(int, input().rstrip("\n").split())

if a_end < b_start or b_end < a_start:
    print(0)
else:
    print(min(a_end, b_end) - max(a_start, b_start))

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

if b<c or d<a:
	ans=0
elif a<=c and b<=d:
	ans=b-c 
elif a<=c and d<b:
	ans=d-c 
elif c<a and d<=b:
	ans=d-a 
elif c<a and b<d:
	ans=b-a 

print(ans)

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

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

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    a, b, c, d = list(map(int, input().rstrip('\n').split()))
    if b < c:
        print(0)
    elif d < a:
        print(0)
    else:
        print(min(b, d) - max(a, c))


if __name__ == '__main__':
    solve()

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(lambda x: int(x), input().split())
start=max(a,c)
end=min(b,d)
ans=max(0,end-start)
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())
print(max(-max(A,C)+min(B,D),0))

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())
print(max(min(b,d)-max(a,c),0))

Solution (Python):


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

start = max(A,C)
end = min(B,D)

print(max(0,end-start))

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<=d:
    t = min(b-c,b-a)
elif a<d<b:
    t = min(d-a,d-c)
else:
    t = 0
print(t)

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

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

    if ans <= 0:
        print(0)
    else:
        print(ans)


if __name__ == '__main__':
    main()

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

if a - c <= 0:
    s = c
else:
    s = a

if b - d <= 0:
    e = b
else:
    e = d

ans = e - s
print(ans if ans > 0 else 0)

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)
    elif b < c:
        print(0)
elif c < a:
    if b <= d:
        print(b - a)
    elif a <= d:
        print(d - a)
    elif d < a:
        print(0)

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

if max(A,C) > min(B,D):
    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(0)
if max(A,C) <= min(B,D):
    print(min(B,D) - max(A,C))

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())
ontime = min(b, d) - max(a, c)
if ontime < 0:
  ontime = 0
print(ontime)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d = list(map(int, input().rstrip('\n').split()))
    if b < c or d < a:
        print(0)
    else:
        print(min(b, d) - max(a, c))


if __name__ == '__main__':
    slove()

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())
ans = min(B,D)-max(A,C)
print(max(ans,0))

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

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())
print(max(min(b,d)-max(a,c),0))

Solution (Python):
def main():
    a,b,c,d=map(int,input().split(' '))
    ans = 0
    alice=[1 if a<=i<b else 0 for i in range(100)]
    bob=[1 if c<=i<d else 0 for i in range(100)]
    for i,j in zip(alice,bob):
        if i+j ==2:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d = list(map(int, input().rstrip('\n').split()))
    if b <= c or d <= a:
        print(0)
    else:
        print(abs(min(d, b) - max(c, a)))


if __name__ == '__main__':
    slove()

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

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

Solution (Python):
import os

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

for i in range(max(a,c),min(b,d)):
    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())

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

Solution (Python):
A, B, C, D = map(int, input().split())
ans = 0
for i in range(0, 101):
  if A <= i and i < B and C <= i and 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):



def main():


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



if __name__ == "__main__":
    main()

Solution (Python):
a,b,c,d=map(int,input().split())
if a<=c:
    print(min(b,d)-c) if c<=b else print("0")
else:
    print(min(b,d)-a) if a<=d 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(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())

ans = 0
Alice = False
Bob = False

for i in range(0,101):
    if a <= i <= b:
        Alice = True
    else:
        Alice = False
    
    if c <= i <= d:
        Bob = True
    else:
        Bob = False
    
    if Alice and Bob:
        ans += 1

if ans == 0:
    print(0)
else:
    print(ans-1)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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


if __name__ == '__main__':
    main()

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:
    if b < c:
        answer = 0
    elif b < d:
        answer = b - c
    else:
        answer = d - c
else:
    if d < a:
        answer = 0
    elif d < b:
        answer = d - a
    else:
        answer = b - a
print(answer)

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())
alice = [i for i in range(A, B)]
bob = [i for i in range(C, D)]


ans = 0

for i in alice:
    if i in bob:
        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())
over = set(range(a, b)) & set(range(c, d))
print(len(over))

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 = max(0, min(B, D) - max(A, C))
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())
res = 0
for i in range(101):
  if a <= i < b and c <= i < d:
    res += 1
print(res)

Solution (Python):

A,B,C,D=map(int,input().split())
if B<C or D<A:
  print(0)
else:
  Min = max([A,C])
  Max=min([B,D])
  print(Max-Min)

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())
if a<=c:
  if b<=c:
    answer = 0
  else:
    if d<=b:
      answer = d-c
    else:
      answer = b-c
else:
  if d<=a:
    answer = 0
  else:
    if d<=b:
      answer = d-a
    else:
      answer = b-a
print(answer)

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())
time = min(b,d) - max(a,c)
print(max(0, time))

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

alice = set(range(A,B+1))
bob = set(range(C,D+1))

res = len(alice & bob)
print(res - 1 if res else 0)

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

if b <= c:
  print(0)
  sys.exit()
else:
  print(min(d - c, b - c))

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

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

if B<=C:
  ans = 0
elif D<=A:
  ans = 0
  
elif A<=C and D<=B: 
  ans = D-C
elif A>=C and D>=B:
  ans = B-A

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

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