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 (A > D) or (C > B):
    print(0)
else:
    S = sorted([A,B,C,D])
    print(S[-2] - S[-3])

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

if (D-A)*(B-C)<=0:
    print(0)
    exit()
elif A<=C and D<=B:
    print(D-C)
    exit()
elif C<=A and B<=D:
    print(B-A)
    exit()
else:
    print(min(D-A,B-C))

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

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

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

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

Solution (Python):









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

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

print(str(sec))

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

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

print(str(sec))

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

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

Solution (Python):

A = list(map(int, input().split()))
time = 0

if A[1] >= A[2] or A[3] >= A[0]:
    
    if A[1] >= A[3] >= A[2] >= A[0]:
        time = A[3] - A[2]
    elif A[3] >= A[1] >= A[2] >= A[0]:
        time = A[1] - A[2]
    
    elif A[3] >= A[1] >= A[0] >= A[2]:
        time = A[1] - A[0]
    elif A[1] >= A[3] >= A[0] >= A[2]:
        time = A[3] - A[0]
    else:
        time = 0    
else:
    time = 0

print(time)

Solution (Python):
a,b,c,d = map(int,input().split())
li = [0] * 100
for i in range(a,b):
    li[i] += 1
for i in range(c,d):
    li[i] += 1
ans = li.count(2)
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 = [int(el) for el in input().split(' ')]
A = set([i for i in range(a, b+1)])
B = set([j for j in range(c, d+1)])
common = A.intersection(B)
if common:
    print(max(common) - min(common))
else:
    print(0)

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


if __name__ == "__main__":
    solve()

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

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

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

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 = read()
    result = think(a, b, c, d)
    write(result)


def read():
    return read_int(4)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b, c, d):
    if b <= c or d <= a:
        return 0
    elif a <= c and d <= b:
        return d - c
    elif c <= a and b <= d:
        return b - a
    else:
        if a == c:
            return min(b, d) - a
        elif a < c:
            return abs(c - b)
        else:  
            return abs(d - a)


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

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

if len(alice) <= len(bob):
    target = alice
    other = bob
else:
    target = bob
    other = alice

for i in range(len(target)):
    if target[i] in other:
        ans += 1
print(ans)

Solution (Python):

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

Solution (Python):




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

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

    print(t)


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

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

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

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

Solution (Python):

a, b, c, d = map(int, input().split())
check = [0] * 101

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

for i in range(c, d+1):
  if check[i] == 1 :
    check[i] = 2

if check.count(2) != 0:
  print(check.count(2)-1)
else:
  print(0)

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

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

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

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

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

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

Solution (Python):
s=input().split()

if int(s[2])>int(s[0]):
  if int(s[2])>int(s[1]):
    print("0")
  else:
    if int(s[3])>int(s[1]):
      print(int(s[1])-int(s[2]))
    else:
      print(int(s[3])-int(s[2]))
else:
  if int(s[0])>int(s[3]):
    print("0")
  else:
    if int(s[3])>int(s[1]):
      print(int(s[1])-int(s[0]))
    else:
      print(int(s[3])-int(s[0]))

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

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

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

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

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

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

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

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


print(max(0,num_max - num_min))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, D = MAP()

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

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

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

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

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

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

alice = [a, b]
bob = [c, d]

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

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

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


if a > c:
    a,b,c,d = c,d,a,b

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

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

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

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

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

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

Solution (Python):


import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    A, B, C, D = read_h()

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


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):
row = list(map(int, input().split()))
start = max(row[0], row[2])
end = min(row[1], row[3])
ans = max(end-start, 0)
print(ans)

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

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

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

d = [i for i in alice if i in bob]

if d == []:
    print(0)
else:
    print(d[-1]-d[0])

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

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

Solution (Python):

a, b, c, d = map(int, input().split())
ans = 0
cd = []
for i in range(c, d):
    cd.append(i)
for i in range(a, b):
    if i in cd:
        ans += 1
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())



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

print(max(0,mi - ma))

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(ans-1, 0))

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

stt = max(A, C)
end = min(B, D)
print(max(end-stt, 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 i >= A and B > i and i >= C and D > i:
        ans += 1

print (ans)

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

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

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

if A < C :
	if B < D: 
		judge(B-C)
	else: 
		judge(D-C)
else:
	if B > D:
		judge(D-A)
	else:
		judge(B-A)

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

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

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

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

if upp > low:
    print(upp - low)
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] = [int(x) for x in input().split()]

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

A, B, C, D = LI()
time = [0]*100
time[A:B] = list(map(lambda x: x+1, time[A:B]))
time[C:D] = list(map(lambda x: x+1, time[C:D]))
print(time.count(2))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

A, B, C, D = LI()
time = [0]*100
time[A:B] = list(map(lambda x: x+1, time[A:B]))
time[C:D] = list(map(lambda x: x+1, time[C:D]))
print(time.count(2))

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

Solution (Python):
a,b,c,d = list(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):
l=input().split()
A,B,C,D=int(l[0]),int(l[1]),int(l[2]),int(l[3])
s=0
for i in range(100):
    if A<=i<B:
        if C<=i<D:
            s+=1
print(s)

Solution (Python):
a_start,a_stop,b_start,b_stop = map(int,input().split())
later_start = max([a_start,b_start])
early_stop = min([a_stop,b_stop])
if early_stop > later_start:
  print(early_stop - later_start)
else:
  print("0")

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

count = min([b, d]) - max([a, c])
if count < 0:
    count = 0

print(count)

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):
def main():
    A, B, C, D = map(int, input().split())
    if C > B or A > D:
        print(0)
    else:
        print(min(B, D) - max(A, C))


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

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

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

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

A, B, C, D = nl()

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

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

resolve()

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

Solution (Python):


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

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=map(int,input().split())
ans=[0]*100
for i in range(a,b):
    ans[i]=1
for i in range(c,d):
    ans[i]+=1
print(ans.count(2))

Solution (Python):
def abc():
    a, b, c, d = map(int, input().split())
    alice = range(a, b+1)
    bob = range(c, d+1)
    l = len(set(alice) & set(bob))
    if l > 0:
        l -= 1
    print(l)


abc()

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

if B <= C or A >= D:
    print('0')
    exit()
elif B <= D:
    if A >= C:
        print('{}'.format(B-A))
        exit()
    else:
        print('{}'.format(B-C))
        exit()
else:
    if A >= C:
        print('{}'.format(D-A))
        exit()
    else:
        print('{}'.format(D-C))
        exit()

Solution (Python):

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

start = A 
if A < C :
    start = C
end = B
if B > D :
    end = D
time = end - start
if time < 0:
    time = 0
    
print (time)

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

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

if a>c:
    sta=a
else:
    sta=c

if b>d:
    end=d
else:
    end=b

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

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


ans = 0

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

Solution (Python):
from sys import stdin
A,B,C,D = [int(x) for x in stdin.readline().rstrip().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())
total = 0

if B <= C or A >= D:
    pass
elif B <= D and A <= C:
    total = B - C
elif B <= D and A > C:
    total = B - A
elif B > D and A <= C:
    total = D - C
else:
    total = D - A

print(total)

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

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

l = []
for i in e:
  if i in d:
    l.append(i)
if l == []:
  print(0)
else:
  print(len(l)-1)

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

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

Solution (Python):
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")








A, B, C, D = list(map(int, sys.stdin.readline().split()))

print(len(set(list(range(A, B))) & set(list(range(C, D)))))

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

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())
print(max(len(set(range(a,b+1))&set(range(c,d+1)))-1,0))

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


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

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

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

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

Solution (Python):
A, B, C, D = map(int, input().split())
print(len({i for i in range(A,B)} & {j for j in range(C,D)}))

Solution (Python):
a, b , c, d = list(map(int, input().strip().split()))
lst = []
lstt = []
for i in range(a, b + 1):
    lst.append(i)

for i in range(c, d+1):
    lstt.append(i)

one = set(lst)
two = set(lstt)

inter = one & two
if len(inter)-1 > 0:
    print(len(inter)-1)
else:
    print(0)

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

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

Solution (Python):

import sys


def solve(A: int, B: int, C: int, D: int):
    if A < C:
        ret = min(B - C, D - C)
    else:
        ret = min(D - A, B - A)
    ret = max(0, ret)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    D = int(next(tokens))  
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

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

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

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

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

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

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

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

a_li = [0 for i in range(100)]
b_li = [0 for i in range(100)]
a_li[a:b] = [1 for i in range(a,b)]
b_li[c:d] = [1 for i in range(c,d)]

li = []
for i,j in zip(a_li, b_li):
  li.append(i+j)

print(li.count(2))

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

duration1 = range(A, B+1)
duration2 = range(C, D+1)

print(max([len([i for i in duration1 if i in duration2])-1,0]))

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

if y - x <= 0:
    print(0)
else:
    print(y - x)

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

Solution (Python):
A, B, C, D = [int(i) for i in input().split()]
print(len(set(range(A, B)) & set(range(C, D))))

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

Solution (Python):
A_start, A_end, B_start, B_end = map(int, input().split())


start = A_start if A_start > B_start else B_start
end = B_end if A_end > B_end else A_end
if end - start < 0:
    print(0)
else:
    print(end - start)

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

Solution (Python):

def main(A, B, C, D):
    start = min(A, C)
    end = max(B, D)
    alice_list = [1 if A <= i < B else 0 for i in range(start, end)]
    bob_list = [1 if C <= i < D else 0 for i in range(start, end)]

    print(sum([all(t) for t in zip(alice_list, bob_list)]))
    

if __name__ == "__main__":
    A, B, C, D = [int(x) for x in input().split()]

    main(A, B, C, D)

def test1(capsys):
    inputs = [0, 75, 25, 100]
    out = 50
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test3(capsys):
    inputs = [0, 33, 66, 99]
    out = 0
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test4(capsys):
    inputs = [10, 90, 20, 80]
    out = 60
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test5(capsys):
    inputs = [10, 50, 50, 90]
    out = 0
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

Solution (Python):
A, B, C, D = map(int, input().split())
alice = []
bob = []
for i in range(0, 100):
	alice.append(0)
	bob.append(0)
for i in range(A, B):
	alice[i] = 1
for i in range(C, D):
	bob[i] = 1
cnt = 0
for i in range(0, 100):
	cnt += alice[i]*bob[i]
print(cnt)

Solution (Python):
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    i = inputs[0].split()
    times = {"a": {}, "b": {}}
    times["a"]["start"] = int(i[0])
    times["a"]["end"] = int(i[1])
    times["b"]["start"] = int(i[2])
    times["b"]["end"] = int(i[3])

    first_start = "a" if times["a"]["start"] < times["b"]["start"] else "b"
    second_start = "b" if first_start == "a" else "a"

    first_end = "a" if times["a"]["end"] < times["b"]["end"] else "b"
    second_end = "b" if first_end == "a" else "a"

    if second_start == first_end:
        return times[first_end]["end"] - times[second_start]["start"]
    if times[first_end]["end"] < times[second_start]["start"]:
        return 0

    return (
        (times[second_end]["end"] - times[first_start]["start"])
        - (times[second_start]["start"] - times[first_start]["start"])
        - (times[second_end]["end"] - times[first_end]["end"])
    )


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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

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

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

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

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

Solution (Python):
a,b,c,d=map(int,input().split())
if b<=c or d<=a:
  print(0)
elif a<c:
  print(min(d,b)-c)
else:
  print(min(b,d)-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())
a=[A,B,C,D]
a.sort()
if B<C:
  print(0)
elif A>D:
  print(0)
else:
  print(a[2]-a[1])

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

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