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

Solution (Python):
def resolve():
    ap, ar, bp, br = map(int, input().split())

    if ar <= bp or br <= ap:
        return print(0)
    else:
        u = max(ap, bp)
        o = min(ar, br)
        ans = o - u
        print(ans)

if __name__ == '__main__':
    resolve()

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

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

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

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

print(ans)

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

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    a,b,c,d=MI()
    s=max(a,c)
    t=min(b,d)
    print(max(0,t-s))

main()

Solution (Python):

a,b,c,d=map(int,input().split())
alice=set(range(a,b))
bob=set(range(c,d))
print(len(alice&bob))

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

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

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

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

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

if alice & bob:
    print(len(alice & bob)-1)

else:
    print(0)

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

Solution (Python):

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

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

Solution (Python):


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

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

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

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

print(ans)

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

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

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

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

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 =[i for i in range(a,b+1)]
y =[j for j in range(c,d+1)]

z = len(x+y) - len(set(x+y))
if z == 0:
    print(0)
else:
    print(z-1)

Solution (Python):


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

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


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

Solution (Python):
a, b, c, d = map(int, input().split())
s = max(a, c)
e = min(b, d)
ans = max(0, e - s)
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())

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

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

print(ans)

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

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

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

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


if __name__ == "__main__":
    main()

Solution (Python):
x = list(map(int, input().split()))
imos = [0]*(max(x) + 2)
imos[x[0]] += 1
imos[x[1]+1] -= 1
imos[x[2]] += 1
imos[x[3]+1] -= 1
for i in range(len(imos)-1):
    imos[i+1] += imos[i]
print(max(imos.count(2) - 1, 0))

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

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

if __name__ == '__main__':
    main()

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

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

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

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

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

if end - start > 0 :
    print(end - start)
else :
    print(0)

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


if __name__ == '__main__':
    main()

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

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

print(max(0, q-1))

Solution (Python):
a, b, c, d = (int(i) for i in input().split(" "))
alice_times = set([i for i in range(a, b + 1)])
bob_times = set([i for i in range(c, d + 1)])

if len(set(alice_times & bob_times)) > 0:
    print(len(set(alice_times & bob_times)) - 1)
else:
    print(0)

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

if(b>=d):
    e=d
else:
    e=b

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

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

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

Solution (Python):



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

time_start = max(A,C)
time_end = min(B,D)

if time_start <= time_end:
    ans = time_end - time_start
else:
    ans = 0

print(ans)

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

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

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

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

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

ans=0
for i in range(101):
    if a<=i and i<b and c<=i and i<d:
        ans+=1
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())
if b<=c or d<=a:
    print(0)
else:
    print(min(d,b)-max(a,c))

Solution (Python):
def twoswiches(a , b , c , d):

    ans = min(b , d) - max(a , c)
    return ans if ans > 0 else 0

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

if __name__ == '__main__':
    main()

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

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

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

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

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

r = max(0, end - start)
print(int(r))

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

Start=[A,C]
End=[B,D]

Start.sort()
End.sort()

print(max(0,End[0]-Start[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())

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

if min_max - max_min > 0:
  print(min_max - max_min)
else:
  print(0)

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

Solution (Python):
A,B,C,D = map(int, input().split())
A2B = set(range(A,B+1))
C2B = set(range(C,D+1))
tmp = list(A2B&C2B)
tmp.sort()
print(0) if len(tmp)==0 else print(tmp[-1] - tmp[0])

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

if A >= C:
    if D >= B:
        ans = B - A
    else:
        ans = D - A
elif C > A:
    if D >= B:
        ans = B - C
    else:
        ans = D - C

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

Solution (Python):


import math


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

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

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

print(ans)

Solution (Python):
als, ale, bs, be = map(int, input().split())
s = max(als, bs)
e = min(ale, be)
ans = e-s
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)]
y = [i for i in range(c, d)]
s = 0
for i in x:
    if i in y:
        s += 1
print(s)

Solution (Python):
a,b,c,d=map(int,input().split())
r=0
for x in range(a,b+1):
    for y in range(c,d+1):
        if x==y:r+=1
print(max(0,r-1))

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

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

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


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

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

Alice = set([])
Bob = set([])

for i in range(A, B + 1):
  Alice.add(i)
for i in range(C, D + 1):
  Bob.add(i)

ans = Alice & Bob
ans = list(ans)
if len(ans) == 0:
  print(0)
  exit()
print(ans[-1] - ans[0])

Solution (Python):
a, b, c, d = map(int, input().split())
if a >= d or c >= b:
	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)
else:
  x=set([i for i in range(a,b)])
  y=set([i for i in range(c,d)])
  z= x & y
  print(len(z))

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

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

print(max(min_t-max_t, 0))

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

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

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

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())
A = set([i for i in range(a,b+1)])
B = set([i for i in range(c,d+1)])

print(len(A&B) if len(A&B)==0 else len(A&B)-1)

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

a_b = set(range(a,b))
c_d = set(range(c,d))

time = a_b & c_d

print(len(time))

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

print(max(0,s))

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

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


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())
ans = max(min(b, d) - max(a, c), 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=[int(i)for i in input().split()]
s=a if a>c else c
e=b if b<d else d
print(e-s if e>s else 0)

Solution (Python):
A, B, C, D = map(int, input().split())
l = [i for i in range(A, B)] + [i for i in range(C, D)]
result = [i for i in set(l) if l.count(i) > 1]
print(len(result))

Solution (Python):
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools



read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

Solution (Python):
import math
import calendar
import fractions
import itertools

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

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

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

Solution (Python):

A, B, C, D = map(int, input().split())
l = [0 for i in range(101)]
for i in range(A, B):
    l[i] += 1
for i in range(C, D):
    l[i] += 1
ans = 0
for i in range(len(l)):
    if l[i] == 2:
        ans += 1
print(ans)

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

Solution (Python):
import math

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

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

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

Solution (Python):


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

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())
P = [0 for _ in range(102)]
for p in range(A, B): P[p] += 1
for p in range(C, D): P[p] += 1
count = 0
for p in P:
  if p == 2: count += 1
print(count)

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

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

Solution (Python):
a_start, a_end, b_start, b_end = map(int, input().split())

if a_start < b_start:
    f_start, f_end = a_start, a_end
    s_start, s_end = b_start, b_end
else:
    f_start, f_end = b_start, b_end
    s_start, s_end = a_start, a_end

overlap_time = 0
if f_end <= s_start:
    overlap_time = 0
elif s_start < f_end and s_end < f_end:
    overlap_time = s_end - s_start
else:
    overlap_time = f_end - s_start

print(overlap_time)

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c,d=INTM()
    ct=min(b,d)-max(a,c)
    print(max(0,ct))
if __name__ == '__main__':
    do()

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

Solution (Python):

import sys, re, os
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
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    a,b,c,d = MAP()
    
    if min(b, d) - max(a, c) >= 0:
        print(min(b, d) - max(a, c))
    else:
        print(0)
if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
A, B, C, D = [int(x) for x in input().split()]
if A<=B<=C<=D:
    ans = 0
elif A<=C<=B<=D:
    ans = B-C
elif C<=A<=B<=D:
    ans = B-A
elif C<=A<=D<=B:
    ans = D-A
elif A<=C<=D<=B:
    ans = D-C
elif C<=A<=D<=B:
    ans = D-A    
else:
    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 c <= b and b <= d:
  ans = b - c
elif a <= c and c <= d and d <= b:
  ans = d - c
elif c <= a and a <= b and b <= d:
  ans = b - a
else:
  ans = d - a
  
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())

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

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

ans = 0
for _t in t:
    if _t == 2:
        ans += 1
print(ans)

Solution (Python):
a,b,c,d=map(int, input().split())
count = 0
ablist = []
cdlist = []
for i in range(a, b+1):
    ablist.append(i)
for i in range(c, d+1):
    cdlist.append(i)


for i in ablist:
    
    if i in cdlist:
        count += 1

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

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

def main():
    if (b < c) | (d < a):
        print('0')
        return None
    else:
        x = max(a, c)
        y = min(b, d)
        print(abs(x-y))
main()

Solution (Python):
import numpy as np

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

A = np.array([False] * 101)
B = np.array([False] * 101)

A[a:b] = True
B[c:d] = True

ans = np.logical_and(A, B).sum()
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())

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

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

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

    elif D<=B:
        print(max(D-A,0))

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

Solution (Python):
def solve(a,b,c,d):
    lst = [(a,"start",),(b,"end"),(c,"start"),(d,"end")]
    lst.sort(key = lambda x:x[0])
    overlap = 0
    time = 0
    temp = 0
    for i in lst:
        if overlap == 2:
            time = i[0] - temp
        if i[1] == "start":
            overlap += 1
            temp = i[0]

        if i[1] == "end":
            overlap -= 1



    return time



if __name__ == "__main__":
    a,b,c,d = map(int,input().split())
    print(solve(a,b,c,d))

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

time = [0] * 101

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

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

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

print(max(0, ans - 1))

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

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

Solution (Python):

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
li = [int(i) for i in input().split()]
if li[0] < li[2] :
    if li[2] >= li[1] :
        print(0)
    else :
        li.sort()
        print(li[2]-li[1])
elif li[2] > li[0] :
    if li[0] >= li[3] :
        print(0)
    else :
        li.sort()
        print(li[2]-li[1])
elif li[0] == 99 and li[1] == 100 and li[2] == 0 and li[3] == 1 :
    print(0)
else :
    li.sort()
    print(li[2]-li[1])

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

sMax = max([a,c])
gMin = min([b,d])

if sMax >= gMin:
  print(0)
else:
  print(gMin - sMax)

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 = 0

if a < c:
    if b > c:
        if b < d:
            ans = b - c
        else:
            ans = d - c
else:
    if d > a:
        if d < b:
            ans = d - a
        else:
            ans = b - a

print(ans)

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

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

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

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

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

a = []
b = []

for i in range(A, B + 1):
  a.append(i)

for i in range(C, D + 1):
  b.append(i)

a.extend(b)

ans = [x for x in set(a) if a.count(x) > 1]
if len(ans) == 0:
  print(len(ans))
else:
  print(len(ans) - 1)

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

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

Alice = [i for i in range(a, b)]
Bob = [i for i in range(c, d)]

same = set(Alice) & set(Bob)
print(len(same))

Solution (Python):
import sys
input = sys.stdin.readline().strip
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())
start,stop = max(a,c), min(b,d)
print(stop-start if start<stop else 0)

Solution (Python):


import numpy as np

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

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

Solution (Python):
ABCD = input().split()
A,B,C,D = int(ABCD[0]), int(ABCD[1]), int(ABCD[2]),int(ABCD[3])
low = max(A,C)
high = min(B,D)

if low < high:
  print(high-low)
else:
  print(0)

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

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

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

Alice_time = set(range(A,B+1))
Bob_time = set(range(C, D+1))

seki_set = Alice_time.intersection(Bob_time)
seki_list = list(seki_set)

if  seki_list == []:
    print(0)
else:
    print(max(seki_list) - min(seki_list))

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

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

print(max(end - start, 0))

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

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

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

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

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

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

Solution (Python):


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


count = 0
for i in range(a, b+1):
    if i in range(c, d+1):
        count += 1
print(max(0, count-1))

Solution (Python):
i = list(map(int, input().split()))
s = i[0] if i[0] > i[2]  else i[2]
e = i[1] if i[1] < i[3]  else i[3]
r = e - s if e - s > 0 else 0
print(r)

Solution (Python):
a, b, c, d = map(int, input().split())
on_btn = [0]*(101)

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

ans = 0
for i in on_btn:
  if i == 2:
    ans += 1
print(ans)

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

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

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

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

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

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

Solution (Python):
a,b,c,d=map(int,input().split())
ab=list(range(a,b+1))
cd=list(range(c,d+1))
dif=list(set(ab) & set(cd))
if len(dif)!=0:
  print(dif[-1]-dif[0])
else:
  print(0)

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

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

Solution (Python):
import sys

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

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

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

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

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

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

Solution (Python):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

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







if B <= C:
    print(0)
    exit()

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

print(max(0, B - C))

Solution (Python):

 
import math
import itertools
import sys
import copy
 

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