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

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

first_stop = min(b, d)
last_start = max(a, c)

if first_stop - last_start <= 0:
    print(0)
else:
	print(first_stop - last_start)

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

s = max(a,c)
e = min(b,d)

if e-s<=0:
    print(0)
else:
    print(e-s)

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

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

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

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

print(max(upper-lower, 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(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())

if B >= C and D >= A:
    Slist = [A, B, C, D]
    Slist.sort()
    print(Slist[2] - Slist[1])
else:
    print(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(0,min(B,D)-max(A,C)))

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

Solution (Python):
A, B, C, D = list(map(int, input().strip().split(' ')))
print(max(0, len({i for i in range(A, B+1)} & {j for j in range(C, D+1)})-1))

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

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

range_AB = [ x for x in range(A, B ) ]
range_CD = [ x for x in range(C, D ) ]

duration = 0

for x in range_AB:
    if x in range_CD:
        duration = duration + 1
        
print(duration)

Solution (Python):
a,b,c,d = map(int, input().split())
temp = [1 if i >= a and i < b else 0 for i in range(101)]
temp = [j+1 if i >= c and i < d else j for (i,j) in enumerate(temp)]
print(str(len([i for i in temp if i == 2])))

Solution (Python):


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

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

print(ans)

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

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(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 solve():
    A, B, C, D = list(map(int, input().split()))
    start = max(A, C)
    end = min(B, D)

    ans = max(end-start, 0)
    print(ans)

if __name__ == "__main__":
    solve()

Solution (Python):

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

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

Solution (Python):

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

if B<=C:
  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 A<=D and D<=B:
  print(D-A)
elif D<=A:
  print(0)
elif C<=A and A<=D and D<=B:
  print(D-A)
elif A<=C and D<=B:
  print(D-C)
elif A<=C and C<=B and C<=D:
  print(C-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(min(b,d)-max(a,c) if min(b,d)>max(a,c) else 0)

Solution (Python):
A=[int(i) for i in input().split()]

if A[0]<=A[2]:
    if A[1]<A[2]:
        print(0)
    elif A[1]>=A[3]:
        print(A[3]-A[2])
    else:
        print(A[1]-A[2])

else:
    if A[3]<A[0]:
        print(0)
    elif A[3]>=A[1]:
        print(A[1]-A[0])
    else:
        print(A[3]-A[0])

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

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 D < A:
    print(0)
else:
    print(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())

minBD = min(b, d)
maxAC = max(a, c)

if maxAC < minBD: print(minBD-maxAC)
else: print(0)

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

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

Solution (Python):

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

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

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):
l=a,b,c,d=list(map(int,input().split()))
l1=sorted(l)
if (l1.index(c)==0 and l1.index(d)==1) or (l1.index(c)==2):
        print(0)
elif l1.index(c)==0 and l1.index(d)==2:
        print(d-a)
elif l1.index(c)==1 and l1.index(d)==3:
        print(b-c)
elif l1.index(c)==1 and l1.index(d)==2:
        print(d-c)
elif l1.index(c)==0 and l1.index(d)==3:
        print(b-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())
e = min(b,d)-max(a,c)
if e < 0:
    print(0)
else:
    print(e)

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

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

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

Solution (Python):
tmp = (input())

A = int(tmp.split(" ")[0])
B = int(tmp.split(" ")[1])
C = int(tmp.split(" ")[2])
D = int(tmp.split(" ")[3])

Alice = {str(x): "A" for x in range(A, B + 1)}
Bob = {str(x): "A" for x in range(C, D + 1)}

cnt = 0

for k, v in Alice.items():
  if k in Bob:
    cnt += 1
    
if cnt -1 == -1:
  print(0)
else:
  print(cnt - 1)

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

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

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

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

print(ans)

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

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

elif a<=c<=b and a<=d<=b:
    print(d-c)
elif a<=c<=b:
    print(b-c)
elif c<=a<=d:
    print(d-a)
else:
    print(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())
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())
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(" "))

Alice = [0]*A+[1]*(B-A)+[0]*200
Bob = [0]*C+[1]*(D-C)+[0]*200

print(sum([Alice[x]*Bob[x] for x in range(200)]))

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

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

Solution (Python):
import sys
from collections import Counter

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

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

if ans < 0:
    ans = 0

print(ans)

Solution (Python):
import sys
from collections import Counter

a, b, c, d = map(int, input().split())
f_array = [0, 0]
l_array = [0, 0]

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

elif a < c:
    f_array[0], f_array[1] = a, b
    l_array[0], l_array[1] = c, d
else:
    f_array[0], f_array[1] = c, d
    l_array[0], l_array[1] = a, b

if f_array[1] < l_array[1]:
    if f_array[1] - l_array[0] < 0:
        print(0)
    else:
        print(f_array[1] - l_array[0])
    sys.exit()
else:
    print(l_array[1] - l_array[0])

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

if b > c:
    result = b-c
if b > d:
    result -= b-d
if a > c:
    result -= a-c

print(result if result >= 0 else 0)

Solution (Python):

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

    return a, b, c, d

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

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

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

if __name__ == '__main__':
    submit()

Solution (Python):

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

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

if __name__ == '__main__':
    solve()

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

Solution (Python):
a=list(map(int,input().split()));print(max([min(a[1::2])-max(a[::2]),0]))

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

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a,b,c,d = f()
    print(max(min(b,d) - max(a, c),0))

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(sum(1 for i in range(0, 101) if a<=i<b and c<=i<d))

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

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

start = 0
alice_time = (a, b)
bob_time = (c, d)

max_end = max(b, d)
alice_zone = [0] * max_end
bob_zone = [0] * max_end
alice_zone[a:b] = [1] * len(alice_zone[a:b])
bob_zone[c:d] = [1] * len(bob_zone[c:d])

kasanari_zone = [alice * bob for alice, bob, in zip(alice_zone, bob_zone)]
print(sum(kasanari_zone))

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

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

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

Solution (Python):


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

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

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    a, b, c, d = (int(_) for _ in input().split())
    ab = [0]*101
    cd = [0]*101
    for i in range(a,b+1):
        ab[i] = 1
    for i in range(c,d+1):
        cd[i] = 1
    ans = 0
    for i in range(0,101):
        if(ab[i] == 1 and cd[i] ==1):
            ans +=1
    print(max(ans-1,0))
if __name__ == '__main__':
    main()

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

Solution (Python):


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

if a<=c<b or a<=d<b:
    x=max(a,c)
    y=min(b,d)
    print(abs(y-x))
elif c<=a<d or c<=b<d:
    x=max(a,c)
    y=min(b,d)
    print(abs(y-x))


else:
    print("0")

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())
Min = min(A, C)
Max = max(B, D)
ans = 0
for i in range(Min, Max+1):
    if A <= i <= B and C <= i <= D:
        ans += 1

print(max(0, ans-1))

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

Solution (Python):

import copy
import random
import bisect 
import math

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

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

print(cnt)

Solution (Python):
def aaa(x,y):
    if (y <= a) or (x <=c) :
        print(0)
    elif a < y and y < x :
        print(y-a)
    elif a < c and c < x :
        print(x-c)
    else :
        print(x-a)

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

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

start = 100
stop = 0

for i in range(101):
    if A <= i <= B and C <= i <= D:
        start = min(start, i)
        stop = max(stop, i)

if start == 100 and stop == 0:
    ans = 0
else:
    ans = stop - start

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

Solution (Python):
def main():
    input = sys.stdin.readline
    try:
        a,b,c,d = map(int, input().split())
        ans = min(b, d) - max(a, c)
        if ans > 0:
            print(ans)
        else:
            print(0)
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    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 = [int(n) for n in input().split()]

turnon = 0
for i in range(100):
    alice, bob = 0, 0

    if a <= i < b:
        alice = 1

    if c <= i < d:
        bob = 1

    turnon += alice * bob

print(turnon)

Solution (Python):
T = [int(n) for n in input().split()]

alice = [0] * max(T)
alice[T[0]:T[1]] = [1] * (T[1] - T[0])

bob = [0] * max(T)
bob[T[2]:T[3]] = [1] * (T[3] - T[2])

turnon = [0] * max(T)
for i in range(max(T)):
    turnon[i] = alice[i] * bob[i]

print(sum(turnon))

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

Solution (Python):
n = list(map(int, input().split()))
a = list(range(n[0], n[1]+1))
b = list(range(n[2], n[3]+1))
print(max(0, len(set(a) & set(b))-1))

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

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

print(ans)

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 c<=a<=d:
  if b<d:
    print(b-a)
  else:
    print(d-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 = [int(item) for item in input().split()]

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

Solution (Python):
import sys
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())

a, b, c, d = nm()

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

Solution (Python):
a, b, c, d = map(int, input().split())
start = sorted([a, c], reverse=True)
end = sorted([b, d])
time = end[0] - start[0]
if time > 0:
  print(time)
else:
  print("0")

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

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

if A < C:
    start = C
else:
    start = A

if B < D:
    end = B
else:
    end = D

print(end - start)

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

Alice = set(range(A, B))
Bob = set(range(C, D))
print(len(Alice & Bob))

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):
a,b,c,d = map(int, input().split())
s = max(a,c)
f = min(b,d)
if s < f:
  print(f - s)
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 = [ int(i) for i in input().split() ]
a1 = [ [a[0],0,0], [a[1],1,0], [a[2],0,1],[a[3],1,1] ]
a1 = sorted(a1)




if a1[0][2] == a1[3][2]:
    print( a1[2][0] - a1[1][0] )
elif a1[0][2] == a1[2][2]:
    print( a1[2][0] - a1[1][0] )
else:
    print(0)

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


if a < c :
	x = c
else:
	x = a

if b < d :
	y = b
else:
	y = d

print(max(0,y - x))

Solution (Python):
a = map(int, raw_input().split())
an = sorted(a)
if (a[1] <= a[2]) | (a[3] <= a[0]):
	print 0
else:
	print an[2] - an[1]

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

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

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

print(np.clip(min(b, d) - max(a, c), 0, None))

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

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

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

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

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

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

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())
cnt = 0
for i in range(100):
  if A<=i<B and C<=i<D:
    cnt += 1
print(cnt)

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

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

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    A = list(map(int, input().split()))

    start = max(A[0], A[2])
    end = min(A[1], A[3])

    ans = max(0, end - start)

    return ans


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

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

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

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

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

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

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

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

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

print(ans)

Solution (Python):
a, b, c, d = [int(_) for _ in input().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())
print(max(0, min(B, D) - max(A, C)))

Solution (Python):
def max(a,b):
    if a>b:
        return a
    else:
        return b
def min(a,b):
    if a>b:
        return b
    else:
        return a
a0,a1,b0,b1 = map(int,input().split())
if a1<b0 or b1<a0:
    print(0)
else:
    print(min(a1,b1)-max(a0,b0))

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

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

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

count = 0
i = start
while i < end:
    count += 1
    i += 1
print(count)

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

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

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

Solution (Python):
a1,a2,b1,b2=map(int,input().split())
print(max(min(a2,b2)-max(b1,a1),0))

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

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

Solution (Python):
def two_switches(A: int, B: int, C: int, D: int) -> int:
    if B <= C or D <= A:
        
        return 0
    if A <= C and D <= B:
        
        return D - C
    if C <= A and B <= D:
        
        return B - A
    if A <= C:
        
        
        
        return B - C
    
    
    
    
    return D - A


if __name__ == "__main__":
    A, B, C, D = map(int, input().split())
    ans = two_switches(A, B, C, D)
    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())
alice = set([i for i in range(A, B)])
bob = set([i for i in range(C, D)])
result = len(alice & bob)
print (result)

Solution (Python):
A1, A2, B1, B2 = map(int, input().split())
if A1 <= B1 <= A2 <= B2:
    print(A2 - B1)
elif B1 <= A1 <= B2 <= A2:
    print(B2 - A1)
elif A1 <= B1 <= B2 <= A2:
    print(B2 - B1)
elif B1 <= A1 <= A2 <= B2:
    print(A2 - A1)
else:
    print(0)

Solution (Python):
a,b,c,d=(int(i) for i in input().split())
t =b if b<=d else d
if b <= c or d<=a:
    print(0)
elif a <=c:
    print(t-c)
else:
    print(t-a)

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

timer = 0
both_push_time = 0
for t in range(101):
    if t < a or t < c:
        continue
    elif a <= t < b and c <= t < d: 
        timer += 1
    else:
        break

print(timer)

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)
if ans > 0:
    print(ans)
else:
    print(0)

Solution (Python):
A, B, C, D = map(int, input().split())
log = [(A,"Alice"),(B,"Alice"),(C,"Bob"),(D,"Bob")]

sorted_log = sorted(log)

if sorted_log[0][1] == sorted_log[1][1]:
    print(0)
else:
    print(sorted_log[2][0]-sorted_log[1][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 <= B and A <= D <= B:
    print(D-C)
elif A <= C <= B and B <= D:
    print(B-C)
elif C <= A <= D and A <= D <= B:
    print(D-A)
elif C <= A and B <= D:
    print(B-A)
else:
    print(0)

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

Solution (Python):
A,B,C,D = map(int,input().split())
line1 = list(range(A,B))
line2 = list(range(C,D))
line1_line2_and = set(line1) & set(line2)
line1_line2_and_list = list(line1_line2_and)
botton = len(line1_line2_and_list) 
print(botton)

Solution (Python):
a,b,c,d = 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())
if D <= A or B <= C:
    print(0)
else:
    print(min(B,D)-max(A,C))

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

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

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

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

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

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

Solution (Python):


import re

n = input("")
n = re.split(" ",n)

if(int(n[0]) <= int(n[2])):
    if(int(n[1]) <= int(n[2])):
        print(0)
    else:
        if(int(n[1]) <= int(n[3])):
            print(int(n[1]) - int(n[2]))
        else:
            print(int(n[3]) - int(n[2]))

else:
    if(int(n[3]) <= int(n[0])):
        print(0)
    else:
        if(int(n[3]) <= int(n[1])):
            print(int(n[3]) - int(n[0]))
        else:
            print(int(n[1]) - int(n[0]))