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

a = time_list[0]
b = time_list[1]
c = time_list[2]
d = time_list[3]

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

print(output)

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

a = [input[0], input[1]]
b = [input[2], input[3]]

if a[0] > b[0]:
    a, b = b, a

if a[1] <= b[0]:
    print(0)
elif b[1] <= a[1]:
    print(b[1] - b[0])
else:
    print(a[1] - b[0])

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

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

if a > c:
    minx = a
elif a <= c:
    minx = c

if b <= d:
    maxy = b
elif b > d:
    maxy = d

if minx >= maxy:
    print(0)
elif minx < maxy:
    print(maxy - minx)

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

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

if seconds <= 0:
    seconds = 0

print(seconds)

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

seconds = 0

if (b <= c) or (d <= a):
    seconds = 0
elif a - c >= 0:
    if d - b >= 0:
        seconds = b - a
    else:
        seconds = d - a
elif a - c <= 0:
    if b - d >= 0:
        seconds = d - c
    else:
        seconds = b - c
else:
    seconds = "a:{0}, b:{1}, c:{2}, d:{3}".format(a, b, c, d)

print(seconds)

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

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    a, b, c, d = mi()
    cnt = 0
    for i in range(101):
        if a <= i <= b-1 and c <= i <= d-1:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

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

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

print(sec)

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


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

Solution (Python):
A, B, C, D = map(int, input().split())
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())

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

if ed - st > 0:
    print(ed-st)
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):
def resolve():
    
    
    
    a, b, c, d = map(int, input().split())
    
    
    
    
    
    

    A = [i for i in range(a, b+1)]
    B = [i for i in range(c, d+1)]

    cnt = 0
    for a in A:
        for b in B:
            if a == b:
                cnt += 1
                break

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


resolve()

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






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






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def Yes(): print("Yes"); return
def No(): print("No"); return


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





A,B,C,D = inputIL()

b1 = (1<<B)-(1<<A)
b2 = (1<<D)-(1<<C)
ans = b1 & b2
print(count_bit(ans))

Solution (Python):


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

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

result = end - start
if result < 0:
    result = 0

print(result)

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

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

ans = [0] * 110

for i in range(a, b):
    ans[i] += 1
for j in range(c, d):
    ans[j] += 1

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

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

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

Solution (Python):
a, b, c, d = 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)]
res = [0 for _ in range(100)]

for i in range(len(res)):
    res[i] = alice[i] * bob[i]

print(sum(res))

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

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

x = [i for i in range(A, B+1)] + [i for i in range(C, D+1)]
l = len(x) - len(set(x))
if l > 0:
    print(l-1)
else:
    print(0)

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

i = max(a,c)
j = min(b,d)
ans = max(0, j - i)
print(ans)

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

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

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

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

Solution (Python):
A, B, C, D = map(int, input().split())
if B <= C or D <= A:
    print(0)
elif 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 = map(int,input().split())

"""
case1
a b c d   →0

case2
a c b d  → b-c

case3
a c d b → d-c

case4
c a 

start →開始時刻のmax
end →終了時刻のmin



"""
starttime = max(a,c)
endtime  = min(b,d)

if starttime < endtime:
    result  = endtime - starttime
else:
    result = 0




"""
if b<=c :
    result = 0
else:  
    if b < d:  
        result  = b - c
    else:  
        result  = d -c
"""



print(result)

Solution (Python):
A,B,C,D = map(int, input().split())
a = []
b = []
for i in range(A,B+1):
    a.append(i)
for i in range(C,D+1):
    b.append(i)
print(max(len(set(a)&set(b))-1,0))

Solution (Python):
A,B,C,D=list(map(int,input().split()))
AB=set(tuple(list(range(A,B+1))))
CD=set(tuple(list(range(C,D+1))))
f=AB.intersection(CD)
print(max(len(f)-1,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 b <= c :
    print(0)
elif a <= c and c <= b :
    print(b-c)
elif a <= d and d <= b :
    print(d-a)
elif d <= a :
    print(0)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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


if __name__ == '__main__':
    resolve()

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

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

if s <= 0:
    s = 0

print(s)

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

Solution (Python):
a,b,c,d=[int(_) for _ in 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())

s1=set()
s2=set()

for i in range(a,b+1):
    s1.add(i)

for i in range(c,d+1):
    s2.add(i)

s1_s2_and=s1&s2
if len(s1_s2_and)==0:
    print(0)
else:
    print(len(s1_s2_and)-1)

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

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

"""
count = 0

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

print(count)
"""

lower = max(A, C)
upper = min(B, D)

ans = max(0, upper - lower)

print(ans)

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

count = 0

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

print(count)

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

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

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

    print(ans)


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):
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):
import sys
A, B, C, D = map(int, input().split())
s, g = 0, 0
if A <= C:
    s = C
    if B < s:
        print(0)
        sys.exit()
else:
    s = A
    if D < s:
        print(0)
        sys.exit()

if B <= D:
    g = B
else:
    g = D

print(g - s)

Solution (Python):
A,B,C,D = list(map(int,input().split()))
N = sum([1 for i in range(0,101) if A < i <= B and C < i <=D])
print(N)

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

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

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

ans=0

if A<C:
    A=C
if D<B:
    B=D

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

print(ans)

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







    









if min(B,D)>=max(A,C):
    ans = min(B,D)-max(A,C)

    


print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


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

    if B <= C or D <= A:
        ans = 0
    else:
        ans = min(B, D) - 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):
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    A,B,C,D = list(map(int,_in[0].split(' ')))  
    
    if B<C or D<A:
        cnt = 0
    else:
        cnt = min(B,D)-max(A,C)
    
    print(cnt)

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

Solution (Python):

import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7

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

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

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

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

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

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

print(ans)

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

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

print(ans)

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

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

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


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

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

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

l_ab = []
l_cd = []
for i in range(a,b+1):
    l_ab.append(i)
for i in range(c,d+1):
    l_cd.append(i)


print(max(0,len(set(l_ab)&set(l_cd))-1))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
A, B, C, D = MAP()

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-a, d-c, b-c, d-a), 0))

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

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

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

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

Solution (Python):
a, b, c, d = map(int, input().split())
alice = [_ for _ in range(a, b + 1)]
bob = [_ for _ in range(c, d + 1)]
dt = list(set(alice) & set(bob))
print(dt[-1] - dt[0] if dt != [] else 0)

Solution (Python):
x=list(map(int,input().split()))
if x[1]<x[3]:
    x=x
elif x[1]>x[3]:
    x=[x[2],x[3],x[0],x[1]]
else:
    x=[min(x[0],x[2]),x[1],max(x[0],x[2]),x[3]]
a,b,c,d=x

print(max(0,b-c) if a<c else b-a)

Solution (Python):
a,b,c,d=map(int,input().split())
lisa=[]
for i in range(a,b):
  lisa.append(i)
lisb=[]
for j in range(c,d):
  lisb.append(j)
count=0
for k in range(0,len(lisa)):
  if lisa[k] in lisb:
    count+=1
print(count)

Solution (Python):
a, b, c, d = map(int, input().split())
al = set([i for i in range(a, b)])
bo = set([i for i in range(c, d)])
print(len(al&bo))

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

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

answer=0
for i in range(100):
  if A<=i<B and C<=i<D:
    answer+=1
    
print(answer)

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

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

Solution (Python):
A, B, C, D = list(map(int, input().split()))
if A <= C:
    x = [A, B]
    y = [C, D]
else:
    y = [A, B]
    x = [C, D]
if x[1] <= y[1]:
    d = x[1] - y[0]
else:
    d = y[1] - y[0]
if d < 0:
    d = 0
print(d)

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

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

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

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

if a > c:
    a, c = c, a
if b > d:
    b, d = d, b
ans = b - c
if ans < 0:
    ans = 0

print(ans)

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

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

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

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

time = [0]*101

for i in range(A,B):
    time[i] += 1
for i in range(C,D):
    time[i] += 1

ans = 0
for i in time:
    if i == 2:
        ans += 1

print(ans)

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

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

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

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

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

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

ans=0

if A<C:
    if B<=D:
        ans=B-C
    else:
        ans=D-C
else:
    if B<=D:
        ans=B-A
    else:
        ans=D-A

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

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

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

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

Solution (Python):
s1, f1, s2, f2 = map(int,input().split())
sec = min(f1,f2) - max(s1,s2)
print(sec if sec >= 0 else "0")

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

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

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

Solution (Python):
a,b,c,d=map(int,input().split())
a_b=set(range(a,b+1))
c_d=set(range(c,d+1))
print(len(a_b&c_d)-1 if len(a_b&c_d)!=0  else 0)

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

Solution (Python):
A,B,C,D=map(int,input().split())
if B<=C or D<=A:
    print(0)
else:
    X=[A,B,C,D]
    X=sorted(X)
    print(X[2]-X[1])

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

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

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

if '__main__' == __name__:
    resolve()

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

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

if a > c:
    right = a
elif a <= c:
    right = c

if b <= d:
    left = b
elif b > d:
    left = d

if right >= left:
    print(0)
elif right < left:
    print(left - right)

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

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

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


    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A,B,C,D=map(int,input().split())
    a,b=0,0
    for i in range(A,B):
        a|=1<<i
    for i in range(C,D):
        b|=1<<i
    print(bin(a&b).count('1'))

if __name__ == '__main__':
    main()

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

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

ans = end - start

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

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

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

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

resolve()

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

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

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

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

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

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