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(' '))
if c <= a <= b <= d:
    print(b - a)
elif a <= c <= d <= b:
    print(d - c)
elif a <= c <= b <= d:
    print(b - c)
elif c <= a <= d <= b:
    print(d - a)
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):
a, b, c, d = map(int, input().split())

t1, t2 = max(a, c), min(b, d)
if t2-t1 < 0:
    t = 0
else:
    t = t2 - t1

print(t)

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

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

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

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

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

t = min([B,D])-max([A,C])

if t<0: t = 0 

print(t)

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())
arr=[0]*101

arr[a]+=1
arr[b]+=-1
arr[c]+=1
arr[d]+=-1
ans=0


for x in range(1,100):
    arr[x]+=arr[x-1]


for x in arr:
    if x==2:
        ans+=1
print(ans)

Solution (Python):
A, B, C, D = map(int, input().split())
d_AB = B - A
d_DC = D - C
set_AB = set()
set_CD = set()
for i in range(A, B + 1):
    set_AB.add(i)
for i in range(C, D + 1):
    set_CD.add(i)
if len(set_AB.intersection(set_CD)) == 0:
    print(0)
else:
    print(len(set_AB.intersection(set_CD)) - 1)

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

right_boundary =D
left_boundary = C

if (B<C)or(D<A):
    print(0)
else:
    if C<A:
        left_boundary = A
    else:
        pass
    if B<D:
        right_boundary = B
    else:
        pass
    
    print(right_boundary - left_boundary)

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

right_boundary =D
left_boundary = C

if (B<C)or(D<A):
    print(0)
else:
    if C<A:
        left_boundary = A
    else:
        pass
    if B<D:
        right_boundary = B
    else:
        pass
    
    print(right_boundary - left_boundary)

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

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

solve()

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

Solution (Python):
import math
import sys

def getinputdata():

    
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

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


mindata = a  if a>c else c
maxdata = b  if b<d else d



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

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

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

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

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

print(max(end - begin, 0))

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

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

print(max(0, upper - lower))

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

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

Solution (Python):





if __name__ == '__main__':
    times = list(map(int, input().split()))

    alice_start = times[0]
    alice_end = times[1]
    bob_start = times[2]
    bob_end = times[3]

    if (bob_end < alice_start) or (alice_end < bob_start):
        print(0)
    else:
        sorted_times = sorted(times)
        print(sorted_times[2] - sorted_times[1])

Solution (Python):
a,b,c,d=map(int,input().split())
if a<=c<=b and a<=d<=b:
    print(d-c)
elif c<=a<=d and c<=b<=d:
    print(b-a)
elif a<=c<=b:
    print(b-c)
elif a<=d<=b:
    print(d-a)
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())
lisa = []
lisb = []
for n in range((b-a)+1):
  lisa.append(n + a)
for m in range((d-c)+1):
  lisb.append(m + c)
ans = 0
for i in range(101):
  if i in lisa and i in lisb:
    ans += 1
if ans > 0:
  print(ans-1)
else:
  print(ans)

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

alice = set([num for num in range(A, B + 1)])
bob = set([num for num in range(C, D + 1)])

if len(alice & bob) == 0:
    print("0")
else:
    print(max(alice & bob) - min(alice & bob))

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

x = max(a,c)
y = min(b,d)

res = y-x

if res < 0:
    print(0)
else:
    print(res)

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

if upper-lower > 0:
    print (upper-lower)
else:
    print ("0")

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

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

low=[a,c]
high=[b,d]
print(0 if max(low)>min(high) else min(high)-max(low))

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

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

if A >= C:
    temp_max = A
else:
    temp_max = C
if B <= D:
    temp_min = B
else:
    temp_min = D


ans = temp_min-temp_max
if ans >=0:
    print(ans)
else:
    print("0")

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

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

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

a = 0
b = min(s[1::2]) - max(s[::2])

if(b > 0):
    a = b

print(a)

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)])
print(-len(alice | bob)+len(alice)+len(bob))

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

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

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

print(sum(map(lambda x: x[0]*x[1], zip(alice, bob))))

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

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

ans = 0 if b < c or d < a else end - start



print(ans)

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

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

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

if(b<=c or d<=a):
    print("0")
    sys.exit()
if(a<=c):
    if(b<d):
        print(b-c)
    else:
        print(d-c)
else:
    if(d<b):
        print(d-a)
    else:
        print(b-a)

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

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

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

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

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

Solution (Python):
list = input().split()
a = int(list[0])
b = int(list[1])
c = int(list[2])
d = int(list[3])
result = 0
if a < b and c < d:
    if (a >= c and b <= d) or (a <= c and b >= d):
        result = min(b-a,d-c)
    elif a <= c and c <= b:
        result = b - c
    elif c <= a and a <= d:
        result =  d - a
print(result)

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

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

if x <= 0:
    print("0")
else:
    print(x)

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

Solution (Python):

line = input().rstrip().split()

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

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

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

if x < 0:
	print(0)
	
else:
	print(x)

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

Solution (Python):
a, b, c, d = list(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 = [int(i) for i in input().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,raw_input().split())
print max(0,min(b,d)-max(a,c))

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

if a >= d or b <= c:
    e = 0
elif a <= c <= b <= d:
    e = b - c
elif c <= a <= d <= b:
    e = d - a
elif a <= c <= d <= b:
    e = d - c
elif c <= a <= b <= d:
    e = b - a

print(e)

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

start = A if C < A else C
end = B if B < D else D

print(max(end - start, 0))

Solution (Python):
a, b, c, d = [int(x) for x in raw_input().split()]
if a > c:
	(a, b), (c, d) = (c, d), (a, b)
if b <= d:
	if b - c < 0:
		print 0
	else:
		print b - c
else:
	print d - c

Solution (Python):
A, B, C, D = map(int, input().split())
res = list(set(range(A, B+1)) & set(range(C, D+1)))
try:
    print(res[-1] - res[0])
except:
    print(0)

Solution (Python):
num = input().split()
num = [int(x) for x in num]

if num[1] < num[2] or num[3] < num[0]:
    print(0)
elif num[1] > num[2]:
    print(min(num[1], num[3])-max(num[2], num[0]))
else:
    print(min(num[3],num[1]) - max(num[0], num[2]))

Solution (Python):
time = []
time = list(map(int, input().split()))

if max(time[0], time[2]) > min(time[1], time[3]):
    print (0)

else :
    print (min(time[1], time[3]) - max(time[0], time[2]))

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

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

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

Solution (Python):
timestr = input().split()
time = []
for x in timestr:
    time.append(int(x))
l = min([time[1], time[3]])
s = max([time[0], time[2]])
d = l - s
if d < 0:
    print(0)
else:
    print(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())
ret = 0
for i in range(101):
    if a<=i<b and c<=i<d: ret += 1
print(ret)

Solution (Python):





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

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

if __name__ == "__main__": main()

Solution (Python):
a = map(int,raw_input().split())
count = 0
for i in range(0,101):
 if a[0] <= i and i < a[1] and a[2] <= i and i < a[3]:
  count += 1
print count

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

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

Solution (Python):

push_alice, remove_alice, push_bob, remove_bob = (int(i) for i in input().split())

if push_alice > push_bob:
    start_time = push_alice
else:
    start_time = push_bob

if remove_alice < remove_bob:
    end_time = remove_alice
else:
    end_time = remove_bob

result = end_time - start_time
if result <= 0:
    print('0')
else:
    print('{0}'.format(result))

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

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

Solution (Python):
s = input().split()
A = int(s[0])
B = int(s[1])
C = int(s[2])
D = int(s[3])
 
a_c = max(A, C)
b_d = min(B, D)
 
if b_d - a_c > 0:
  print(b_d - a_c)
else:
  print("0")

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

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

Solution (Python):
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    A, B, C, D = map(int, input().split())
    dp = [0] * 1000
    for i in range(A, B):
        dp[i] += 1
    for i in range(C, D):
        dp[i] += 1
    print(dp.count(2))


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

Solution (Python):
a = list(map(int,input().split()))
counter = 0
for i in range (101):
  if a[0] <= i <= a[1] and a[2] <= i <= a[3]:
    counter += 1
if counter > 0:
  print ('{0}'.format(counter - 1))
else:
  print ('{0}'.format(0))

Solution (Python):

"""
http://abc070.contest.atcoder.jp/tasks/abc070_b
"""


def solve(A, B, C, D):
    start = max(A, C)
    end = min(B, D)
    duration = end - start
    if duration < 0:
        return 0
    else:
        return duration


def main():
    A, B, C, D = [int(x) for x in input().strip().split(' ')]
    result = solve(A, B, C, D)
    print(result)


if __name__ == '__main__':
    main()

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):
def solve(): 
    A, B, C, D = list(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 (A == C)  and (B == D):
        print(B - A)
    elif A == C or B == D:
        print(min(abs(B-A), abs(D-C)))
    else:
        print(0)
        
        
solve()

Solution (Python):
line = raw_input()
A, B, C, D = line.split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)


if C > B:
    print 0
elif A > D:
    print 0
elif A > C:
    if B > D:
        print D - A
    else:
        print B - A
else:
    if B > D:
        print D - C
    else:
        print B - C

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

Solution (Python):
n = [0] * 100
a, b, c, d = map(int, input().split())
while a < b:
    n[a] += 1
    a += 1
while c < d:
    n[c] += 1
    c += 1
print(n.count(2))

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

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

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

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

Solution (Python):

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

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

a = max(0, b-a)

print(a)

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

Solution (Python):
A, B, C, D = map(int, input().split())
set_A = set(range(A, B+1))
set_B = set(range(C, D+1))
intersect_AB = set_A.intersection(set_B)
print(len(intersect_AB)-1 if intersect_AB else 0)

Solution (Python):
A,B,C,D=map(int,input().split())
x=min(B,D)-max(A,C)
if x>0:
    print(x)
else:
    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())
a=[0]*101
for i in range(A,B):
  a[i]+=1
for i in range(C,D):
  a[i]+=1
print( sum([ 1 for x in a if x >= 2]) )

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

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

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

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

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):
def main():
    a, b, c, d = map(int, input().split())

    maxv = a if a > c else c
    minv = b if b < d else d
    time = minv - maxv if minv - maxv > 0 else 0
    print(time)
    

if __name__ == "__main__":
    main()

Solution (Python):

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

d = min(a[1], a[3]) - max(a[0], a[2])

print(max(d, 0))

Solution (Python):


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

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

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

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

    max_start = max(A, C)
    min_finish = min(B, D)
    t_sub = min_finish - max_start
    
    if(t_sub < 0):
        print(0)
    else:
        print(t_sub)
    
if __name__=="__main__":
    main()

Solution (Python):
a,b,c,d=map(int,raw_input().split())
l1,l2=range(a,b),range(c,d)
print len(set(l1).intersection(l2))

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):
abcd = [int(i) for i in input().split()]

total = (abcd[1] - abcd[0]) + (abcd[3] - abcd[2])
gap = max(abcd) - min(abcd)

if gap>=total:
	print(0)
else:
	print(total-gap)

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

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

Solution (Python):

a, b, c, d = list(map(int, input().split()))
s1 = set([x for x in range(a, b + 1)])
s2 = set([x for x in range(c, d + 1)])
print(max(len(s1 & s2) - 1, 0))

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

Solution (Python):


def main():
    lst = list(map(int, input().split(' ')))
    left = max(lst[0], lst[2])
    right = min(lst[1], lst[3])
    print(max(right-left, 0))


if __name__ == '__main__':
    main()

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

res = 0

for i in range(101) :
    if (a <= i and i < b) and (c <= i and i < d):
        res += 1

print(res)

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

if a >= c:
    tmpa = a
else:
    tmpa = c

if b >= d:
    tmpb = d
else:
    tmpb = b

ans = tmpb - tmpa

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

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

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



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

Solution (Python):
import sys
a, b, c, d = (int(i) for i in input().split())
if b-c<=0 or d-a<=0 or b-a<=0 or d-c<=0:
    print(0)
    sys.exit()
else:
    an = min(b-a,d-c,b-c,d-a)
    print(an)

Solution (Python):
s1,e1,s2,e2 = map(int, input().split())
if s1 > s2:
    start = s1
else:
    start = s2
if e1 > e2:
    end = e2
else:
    end = e1
if end - start < 0:
    print(0)
else:
    print(end - start)

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

Solution (Python):
alice = [False for _ in range(100)]
bob = [False for _ in range(100)]

a,b,c,d = map(int,input().split(" "))
for i in range(a,b):
    alice[i] = True

for i in range(c,d):
    bob[i] = True

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

print(count)

Solution (Python):
xa, ya, xb, yb = map(int, input().split())
 
if xa > xb:
    x = xa
else:
    x = xb
if ya > yb:
    y = yb
else:
    y = ya
ans = y - x
if ans <= 0:
    print(0)
else:
    print(ans)

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

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

mm = max(a, c)
nn = min(b, d)

print(max(0, nn - mm))

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=[int(i) for i in input().strip().split(' ')]

'''
入力は他の人のを見た
'''

max=0
min=0

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

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

Solution (Python):
a, b, c, d= [int(i) for i in input().strip().split(' ')]
if c>=b or d<=a:
  print(0)
elif c>=a and c<=b:
  if d<=b:
    print(d-c)
  else:
    print(b-c)
elif d>=a:
  if d<=b:
    print(d-a)
  else:
      print(b-a)

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

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


print(max(0,count-1))

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

k = [x for x in range(0, 101) if a <= x <= b and c <= x <= d]

if not k:
    print(0)
else:
    print(max(k) - min(k))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**1
gosa = 1.0 / 10**9
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    a,b,c,d = LI()
    t = min(b,d) - max(a,c)
    if t > 0:
        return t

    return 0



print(main())

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

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

else:
	if(A > C):
		E = A
	else:
		E = C

	if(B > D):
		F = D
	else:
		F = B

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

Solution (Python):
line=input().split()
a=int(line[0])
b=int(line[1])
c=int(line[2])
d=int(line[3])
s=max(a,c)
e=min(b,d)
print(max(0,e-s))

Solution (Python):


a,b,c,d=map(int,raw_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())
S1 = set()
S2 = set()
for i in range(A, B):
  S1.add(i)
for i in range(C, D):
  S2.add(i)
print(len(S1.intersection(S2)))

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