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):
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

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

    tmp = set(list(range(a,b+1))) & set(list(range(c, d+1)))
    print(max(0, len(tmp)-1))


if __name__ == '__main__':
    main()

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

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

if A>=D or C>=B:
    print(0)
else:
    li1 = [B,D]
    li2 = [A,C]
    print(min(li1)-max(li2))

Solution (Python):
A,B,C,D=map(int,input().split())
Ans = [0] * 101
for i in range(100+1):
    if A<=i and i<B:
        Ans[i]+=1
    if C<=i and i<D:
        Ans[i]+=1

print(Ans.count(2))

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

beg = max(a_beg, b_beg)
end = min(a_end, b_end)

ans = max(0, end - beg)

print(ans)

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

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

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

Solution (Python):
a,b,c,d=map(int,input().split())
S,F,countS,countF = 0,0,0,0
if a<=c:
  countS = c
  S = a
else:
  countS = a
  S = c
if b <= d:
  countF = b
  F = d
else:
  countF = d
  F = b
count=0
flagC = False
for i in range(S,F+1):
  if flagC:
    count+=1
  if i == countS:
    flagC = True
  if i == countF:
    break
print(count)

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

Solution (Python):

import math

import itertools
from collections import deque
from collections import Counter

from fractions  import gcd

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

Solution (Python):
a,b,c,d = map(int,input().split())
li = [1]*100
for i in range(a):
    li[i] = 0
for i in range(100-b):
    li[i+b] = 0
for i in range(c):
    li[i] = 0
for i in range(100-d):
    li[i+d] = 0
print(li.count(1))

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

if finish - start < 0:
  print(0)
else:
  print(finish - start)

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

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

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

A,B,C,D = MI()

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

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 c>b or 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):
NN =input().split()
a = int(NN[0])
b = int(NN[1])
c = int(NN[2])
d = int(NN[3])
list1=[a,b,c,d]
list1.sort()
ans = list1[2] -list1[1]
if b < c or d < a:
  print(0)
else:
  print(ans)

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

diff = end - start
if not diff >= 0:
    diff = 0
print(diff)

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

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

Solution (Python):
a1,a2,b1,b2 = map(int,input().split())
a1,a2,b1,b2
count = 0
if a1 <= b1:
    for i in range(a2+1):       
        if i > b1 and i <= b2:
            count += 1
elif b1 <= a1:
    for i in range(b2+1):
        if i > a1 and i <= a2:
            count += 1
print(count)

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

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

answer = 0

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

answer = max(0, upper - lower)

print(answer)

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

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

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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

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

Solution (Python):

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

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

for j in range(c, d + 1):
    arr[j] += 1

ans = len([cnt for cnt in arr if cnt >= 2])

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

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

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

else:
    print(0)

Solution (Python):


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


if D <= A or B <= C:
    print(0)
else:
    l = sorted([A, B, C, D])
    print(l[2] - l[1])

Solution (Python):

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

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

Solution (Python):
import numpy as np
a,b,c,d = map(int,input().split())
t = [0]*101

t[a] += 1
t[b] -= 1
t[c] += 1
t[d] -= 1

t = list(np.cumsum(t))

print(t.count(2))

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(a,c)))

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

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

if start <= end:
    print(end - start)
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())
x = [0]*(202)
x[a] += 1
x[b] -= 1
x[c] += 1
x[d] -= 1
for i in range(201):
    x[i+1] += x[i]
ans = 0
for i in range(202):
    if x[i] == 2:
        ans += 1
print(ans)

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

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

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

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

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

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

if __name__=='__main__':
    a,b,c,d=readinput()
    ans=main(a,b,c,d)
    print(ans)

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

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

Solution (Python):
A,B,C,D = map(int,input().split())
M = [0]*100

for n in range(A,B):
  M[n-1]+=1
  
for n in range(C,D):
  M[n-1]+=1
  
print(M.count(2))

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

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

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

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

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

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

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

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

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

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

push =[0]*102
push[A+1]+=1
push[B+1] -=1
push[C+1] +=1
push[D+1] -= 1
count = 0
for i in range(1,len(push)):
    push[i] = push[i] + push[i-1]
    if push[i]==2:
        count +=1
print(count)

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

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


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

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


if __name__ == '__main__':
    main()

Solution (Python):


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

late_start = 0
first_stop = 0
same_time = 0

late_start = max(A, C)
first_stop = min(B, D)
if first_stop - late_start > 0:
    same_time = first_stop - late_start
else:
    same_time = 0

print(same_time)

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

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

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

cnt = [0] * 101
for i in range(a, b):
    cnt[i] += 1
for i in range(c, d):
    cnt[i] += 1

ans = len(list(filter(lambda x: x == 2, cnt)))
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())
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())

Alice = []
for i in range(A,B):
  Alice.append(i)

Bob = []
for s in range(C,D):
  Bob.append(s)

count = 0  
B = B - A

for i in range(B):
  if Alice[i] in Bob:
    count += 1
print(count)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

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

Solution (Python):

A,B,C,D = map(int, input().split())
f = []
s = []

if A <= C:
    f = [A, B]
    s = [C, D]
else:
    s = [A, B]
    f = [C, D]

ans = 0
if f[1] <= s[0]:
    ans = 0
elif s[1] <= f[1]:
    ans = s[1] - s[0]
elif f[1] <= s[1]:
    ans = f[1] - s[0]

print(ans)

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

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

area = [0 for i in range(max([b,d])+1)]

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

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

answer = 0
for i in area:
  if i == 2:
    answer += 1

print(answer)

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

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

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

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

alice = [0]*100
bob = [0]*100

alice[A:B] = [1]*(B-A)
bob[C:D] = [1]*(D-C)

print(sum([alice[i]*bob[i] for i in range(100)]))

Solution (Python):
import sys
A,B,C,D = map(int,input().split())
if A < 0 or B < 0 or B <= A or A > 100 or B > 100:
    sys.exit()
if C < 0 or D < 0 or D <= C or C > 100 or D > 100:
    sys.exit()

count = 0
for I in range(A,B):
    for J in range(C,D):
        if I == J:
            count += 1
print(count)

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

count = 0

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

if count!=0:
  count = count - 1

print(count)

Solution (Python):
A,B,C,D = map(int,input().split())
print(len(set(range(A+1,B+1)) & set(range(C+1,D+1))))

Solution (Python):
import math

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    A, B, C, D = mi()
    print(len(set(range(A, B))&set(range(C, D))))

if __name__ == '__main__':
    main()

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

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

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

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

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

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

print (max(e-s,0))

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

if a > c:
  maxac = a
else:
  maxac = c
if b < d:
  minbd = b
else:
  minbd = d

res = minbd - maxac
if res < 0:
  print(0)
else:
  print(res)

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())
ans = min(b, d) - max(a, c)
ans = max(0, ans)
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().strip().split()))

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

else:
  print(0)

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

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

Solution (Python):



import os
import sys







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

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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    A, B, C, D = map(int,input().split())
    if A <= C:
        if B-C <= 0:
            ans = 0
            return ans
        elif B-C > 0 and B <= D:
            ans = B-C
            return ans
        elif B-C > 0 and B > D:
            ans = D-C
            return ans

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

    elif A >= D:
        ans = 0
        return ans

print(main())

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

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

print(max(0, upper - lower))

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


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

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

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

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

Solution (Python):
nums = [int (e) for e in input().split()]

lower = min(nums[1], nums[3])
upper = max(nums[0], nums[2])

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

Solution (Python):
def calc(a, b, c, d) :
  if c < a and b < d :
    return b - a
  elif a <= c <= b : 
    if d < b : 
      return d - c
    else : 
      return b - c
  elif a <= d <= b :
    return d - a
  else : 
    return 0

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

print(calc(a, b, c, d))

Solution (Python):
A, B, C, D = map(int, input().split())
a = set(range(A, B))
b = set(range(C, D))
c = a& b

print(len(c))

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())
al = set(range(a, b))
bo = set(range(c, d))
print(len(al & bo))

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

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

print(max(0,ans))

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

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

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

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

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

Solution (Python):
n = list(map(int, input().split()))
sum = 0
min = min(n)
max = max(n)
len = max - min
sum = n[1]-n[0] + n[3]-n[2]
sum = sum -len
if(sum < 0):
    sum = 0
print(sum)

Solution (Python):

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


def func(a_sec, b_sec, c_sec, d_sec):
    if a_sec < c_sec <= b_sec < d_sec:
        temp = b_sec - c_sec
    elif c_sec < a_sec <= d_sec < b_sec:
        temp = d_sec - a_sec
    elif a_sec <= c_sec < d_sec <= b_sec:
        temp = d_sec - c_sec
    elif c_sec <= a_sec < b_sec <= d_sec:
        temp = b_sec - a_sec
    else:
        temp = 0

    print(temp)


func(a_sec=a, b_sec=b, c_sec=c, d_sec=d)

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

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

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

range_AB = range(A, B + 1)
range_CD = range(C, D + 1)

if set(range_AB) & set(range_CD):
    print(len(set(range_AB) & set(range_CD)) - 1)
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())
if A > C:
    A, B, C, D = C, D, A, B
print(max(0, min(D, B)-C))

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

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

A=i[0]
B=i[1]
C=i[2]
D=i[3]

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

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    A, B, C, D = map(int, input().split())
    double  = 0
    for i in range(101):
        if A <= i <= B and C <= i <= D: double += 1
    print(double - 1 if double > 1 else 0)

    return  0

if __name__ == "__main__":
    solve()

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

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

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

minv = max(A, C)
maxv = min(B, D)

print(max(0, maxv - minv))

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

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

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

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

Solution (Python):
if __name__ == '__main__':
    a = [int(i) for i in input().split()]

    if min(a[3],a[1]) - max(a[0],a[2]) > 0:
        print(min(a[3],a[1]) - max(a[0],a[2]))
    else:
        print(0)

Solution (Python):
a,b,c,d = map(int,input().split())
Alice = ['1' if i>=a and i<=b else '0' for i in range(101)]
Bob = ['1' if i>=c and i<=d else '0' for i in range(101)]
ans = 0
for i in range(101):
    if Alice[i]=='1' and Bob[i]=="1":
        ans+=1
print(0 if ans==0 else ans-1)

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

inter = set(ab).intersection(set(cd))

if len(inter) != 0:
  print(len(inter) - 1)
else:
  print(0)

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

"""
Created on Fri May 29 19:25:06 2020

@author: naoki
"""
import sys

A,B,C,D = map(int,input().split())
time = [A,B,C,D]
time.sort()
if B <= C or D <= A:
    print(0)
    sys.exit()
else:
    print(time[2]-time[1])

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

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

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

Solution (Python):
A,B,C,D=map(int,input().split())
if C<=B:
    if A<=C:
        if D>=B:
            print(B-C)
        else:
            print(D-C)
    else:
        if D>=B:
            print(B-A)
        elif A<=D<B:
            print(D-A)
        else:
            print(0)
else:
    print(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,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())
x = len(set(range(a, b + 1)) & set(range(c, d + 1))) - 1
print(x if x >= 0 else 0)

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

Solution (Python):
a, b, c, d = map(int, input().split())
alice = list(range(a, b))
bob = list(range(c, d))
l = alice + bob
s = set(alice + bob)
print(len(l) - len(s))

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

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

Solution (Python):

import sys


def solve(A: int, B: int, C: int, D: int):
    print(max(0, min(B, D) - max(A, C)))
    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())
Alice=False
Bob=False
time=0
for i in range(101):
    if i==A:
        Alice=True
    if i==B:
        Alice=False
    if i==C:
        Bob=True
    if i==D:
        Bob=False
    if Alice==True and Bob==True:
        time+=1
print(time)

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

for i in range(a, b+1):
    l[i] += 1
    
for i in range(c, d+1):
    l[i] += 1
ans = 0
for i in l:
    if i == 2: ans += 1
print(max(ans-1, 0))

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

Solution (Python):
import sys

numbers = sys.stdin.readline().split(' ')

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

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

Solution (Python):
import sys
numbers = sys.stdin.readline().split(' ')

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


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

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

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

Solution (Python):
num_list= list(map(int,input().split()))
li_A=list(range(num_list[0],num_list[1]))
li_B=list(range(num_list[2],num_list[3]))

li_C=range(0, 10)
li_A+=li_B

len_1=len(li_A)
len_2=len(set(li_A))
print(len_1-len_2)