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



Sample input:
0 75 25 100


Sample output:
50

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
x = 0
if A <= C:
  if B <= D and B >= C:
    x = abs(B - C)
  elif D < B:
    x = abs(D - C)
elif C < A:
  if B <= D:
    x = abs(B - A)
  elif D < B and A <= D:
    x = abs(A - D)
print(x)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

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

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a, b, c, d = (int(_) for _ in input().split())
    ab = [0]*101
    cd = [0]*101
    for i in range(a,b+1):
        ab[i] = 1
    for i in range(c,d+1):
        cd[i] = 1
    ans = 0
    for i in range(0,101):
        if(ab[i] == 1 and cd[i] ==1):
            ans +=1
    print(max(ans-1,0))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding utf-8 -*-

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

if a<=c<b or a<=d<b:
    x=max(a,c)
    y=min(b,d)
    print(abs(y-x))
elif c<=a<d or c<=b<d:
    x=max(a,c)
    y=min(b,d)
    print(abs(y-x))


else:
    print("0")

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

print(max(0, ans-1))

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math

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)

Submission status: Accepted

Solution code:
def aaa(x,y):
    if (y <= a) or (x <=c) :
        print(0)
    elif a < y and y < x :
        print(y-a)
    elif a < c and c < x :
        print(x-c)
    else :
        print(x-a)

a,b,c,d = map(int,input().split())
if (d-c) < (b-a) :
    aaa(d,b)
else :
    aaa(b,d)

Submission status: Accepted

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

start = 100
stop = 0

for i in range(101):
    if A <= i <= B and C <= i <= D:
        start = min(start, i)
        stop = max(stop, i)

if start == 100 and stop == 0:
    ans = 0
else:
    ans = stop - start

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
def main():
    input = sys.stdin.readline
    try:
        a,b,c,d = map(int, input().split())
        ans = min(b, d) - max(a, c)
        if ans > 0:
            print(ans)
        else:
            print(0)
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

turnon = 0
for i in range(100):
    alice, bob = 0, 0

    if a <= i < b:
        alice = 1

    if c <= i < d:
        bob = 1

    turnon += alice * bob

print(turnon)

Submission status: Accepted

Solution code:
T = [int(n) for n in input().split()]

alice = [0] * max(T)
alice[T[0]:T[1]] = [1] * (T[1] - T[0])

bob = [0] * max(T)
bob[T[2]:T[3]] = [1] * (T[3] - T[2])

turnon = [0] * max(T)
for i in range(max(T)):
    turnon[i] = alice[i] * bob[i]

print(sum(turnon))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = list(map(int, input().split()))
a = list(range(n[0], n[1]+1))
b = list(range(n[2], n[3]+1))
print(max(0, len(set(a) & set(b))-1))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(ans)

Submission status: Accepted

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

time = 0
for i in range(100):
    if i >= a and i < b and i >= c and i < d:
        time += 1
print(time)

Submission status: Accepted

Solution code:
import sys
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())

a, b, c, d = nm()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
start = sorted([a, c], reverse=True)
end = sorted([b, d])
time = end[0] - start[0]
if time > 0:
  print(time)
else:
  print("0")

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split(' '))
start = 0
end = 0

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

if A < C:
    start = C
else:
    start = A

if B < D:
    end = B
else:
    end = D

print(end - start)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Alice = set(range(A, B))
Bob = set(range(C, D))
print(len(Alice & Bob))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = [ int(i) for i in input().split() ]
a1 = [ [a[0],0,0], [a[1],1,0], [a[2],0,1],[a[3],1,1] ]
a1 = sorted(a1)
# fs ss se fe
# fs ss fe se
# fs fe ss se
# ss fs fe se
if a1[0][2] == a1[3][2]:
    print( a1[2][0] - a1[1][0] )
elif a1[0][2] == a1[2][2]:
    print( a1[2][0] - a1[1][0] )
else:
    print(0)

Submission status: Accepted

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


if a < c :
	x = c
else:
	x = a

if b < d :
	y = b
else:
	y = d

print(max(0,y - x))

Submission status: Accepted

Solution code:
a = map(int, raw_input().split())
an = sorted(a)
if (a[1] <= a[2]) | (a[3] <= a[0]):
	print 0
else:
	print an[2] - an[1]

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
a, b, c, d = map(int, input().split())

print(np.clip(min(b, d) - max(a, c), 0, None))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
x=max(a,c)
y=min(b,d)
z=0
if y-x>=0:
    z=y-x
print(z)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans if ans >0 else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,D = map(int, input().split())
s, e = 0,0
if C > A:
    s = C
else:
    s = A
if D > B :
    e = B
else :
    e = D
if s > e :
    print(0)
else :
    print(e - s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

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

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    A = list(map(int, input().split()))

    start = max(A[0], A[2])
    end = min(A[1], A[3])

    ans = max(0, end - start)

    return ans


if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(100):
  Alice=0
  Bob=0
  if(a<=i and i<b):
    Alice=1
  if(c<=i and i<d):
    Bob=1
  if(Alice==1 and Bob==1):
    ans+=1
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input().split())
AB = set(range(A,B))
CD = set(range(C,D))
ans = len(AB & CD)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def max(a,b):
    if a>b:
        return a
    else:
        return b
def min(a,b):
    if a>b:
        return b
    else:
        return a
a0,a1,b0,b1 = map(int,input().split())
if a1<b0 or b1<a0:
    print(0)
else:
    print(min(a1,b1)-max(a0,b0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 070 B 
A,B,C,D= map(int,input().split())
if B < C:
    print(0)
    exit()
if D < A:
    print(0)
    exit()
if A <= C:
    start =C
else:
    start =A
if B <=D:
    end =B
else:
    end =D
print(end-start)

Submission status: Accepted

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

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

count = 0
i = start
while i < end:
    count += 1
    i += 1
print(count)

Submission status: Accepted

Solution code:
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

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

Submission status: Accepted

Solution code:
a1,a2,b1,b2=map(int,input().split())
print(max(min(a2,b2)-max(b1,a1),0))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def two_switches(A: int, B: int, C: int, D: int) -> int:
    if B <= C or D <= A:
        # 交わらない。
        return 0
    if A <= C and D <= B:
        # Alice が Bob を完全に含む
        return D - C
    if C <= A and B <= D:
        # Bob が Alice を完全に含む
        return B - A
    if A <= C:
        # A-----B
        #   C----D
        # こんな感じ
        return B - C
    # 残りは C <= A
    #    A-------B
    # C----D
    # こんな感じ
    return D - A


if __name__ == "__main__":
    A, B, C, D = map(int, input().split())
    ans = two_switches(A, B, C, D)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A1, A2, B1, B2 = map(int, input().split())
if A1 <= B1 <= A2 <= B2:
    print(A2 - B1)
elif B1 <= A1 <= B2 <= A2:
    print(B2 - A1)
elif A1 <= B1 <= B2 <= A2:
    print(B2 - B1)
elif B1 <= A1 <= A2 <= B2:
    print(A2 - A1)
else:
    print(0)

Submission status: Accepted

Solution code:
a,b,c,d=(int(i) for i in input().split())
t =b if b<=d else d
if b <= c or d<=a:
    print(0)
elif a <=c:
    print(t-c)
else:
    print(t-a)

Submission status: Accepted

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

timer = 0
both_push_time = 0
for t in range(101):
    if t < a or t < c:
        continue
    elif a <= t < b and c <= t < d: #b or d秒後にはスイッチを離す
        timer += 1
    else:
        break

print(timer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
log = [(A,"Alice"),(B,"Alice"),(C,"Bob"),(D,"Bob")]

sorted_log = sorted(log)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input().split())
line1 = list(range(A,B))
line2 = list(range(C,D))
line1_line2_and = set(line1) & set(line2)
botton = len(line1_line2_and) 
print(botton)

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input().split())
line1 = list(range(A,B))
line2 = list(range(C,D))
line1_line2_and = set(line1) & set(line2)
line1_line2_and_list = list(line1_line2_and)
botton = len(line1_line2_and_list) 
print(botton)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
l = [0 for _ 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(0, 101):
  if l[i] == 2:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/use/bin/env python3

import re

n = input("")
n = re.split(" ",n)

if(int(n[0]) <= int(n[2])):
    if(int(n[1]) <= int(n[2])):
        print(0)
    else:
        if(int(n[1]) <= int(n[3])):
            print(int(n[1]) - int(n[2]))
        else:
            print(int(n[3]) - int(n[2]))

else:
    if(int(n[3]) <= int(n[0])):
        print(0)
    else:
        if(int(n[3]) <= int(n[1])):
            print(int(n[3]) - int(n[0]))
        else:
            print(int(n[1]) - int(n[0]))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n = S()
    n1 = n[::-1]
    for i in range(len(n)):
        if n1[i] != n[i]:
            print("No")
            return
    print("Yes")
    return

#B
def B():
    a, b, c, d = LI()
    ans = [0 for i in range(101)]
    ans[a] += 1
    ans[b] -= 1
    ans[c] += 1
    ans[d] -= 1
    for i in range(100):
        ans[i+1] += ans[i]
    print(ans.count(2))
#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

Solution code:
import math
def p(d): print(d)
def i(): return input()

def LI():  # Line Integer
    # 1行 1つの数字
    return int(input())
def LIS():  # Line IntegerS
    # 1行 mつの数字
    return [int(x) for x in input().split()]
def MLIS(n):  # Multi Line IntegerS
    # n行 mつの数字
    return [[int(x) for x in input().split()] for y in range(n)]
def LC():  # Line Character
    # 1行 1つの文字
    return input()
def LCS(): # Line CharacterS
    # 1行 nつの文字
    return [x for x in input().split()]
def MLCS(n): # Multi Line CharacterS
    # n行 mつの数字
    return [[x for x in input().split()] for y in range(n)]

def alp2int(alphabet):
    # アルファベットの番号を返す
    return ord(alphabet) - ord('a')
def int2alp(num):
    # 番号からアルファベットを返す
    return chr(num + ord('a'))
def cnt2dic(lst, dic={}):
    # 同じものをカウントして辞書型にする
    for x in lst:
        key = str(x)
        if key in dic:
            dic[key] += 1
        else:
            dic[key] = 1
    return dic
def dic2lst(dic, key=lambda x:x[1]):
    # 辞書をタプルの配列にする
    return sorted(list(dic.items()), key=key);

def A():
    a = LC()
    if a[0] == a[2]:
        print('Yes')
    else:
        print('No')

def B():
    a, b, c, d = LIS()
    s = max(a, c)
    e = min(b, d)
    if s < e:
        p(e-s)
    else:
        p(0)

def C():
    pass

def D():
    pass

def E():
    pass

def F():
    pass

def G():
    pass

def H():
    pass

B()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
n = S()
if n == n[::-1]:
    print("Yes")
else:
    print("No")
"""
#B
a,b,c,d = LI()
print(max(0,min(b,d)-max(c,a)))
#C
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#D
"""
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
Q,k = LI()
d = [-1 for i in range(n)]
d[k-1] = 0
q = deque()
q.append(k-1)
while q:
    x = q.pop()
    for y,c in v[x]:
        if d[y] == -1:
            d[y] = d[x]+c
            q.append(y)
for i in range(Q):
    x,y = LI()
    x -= 1
    y -= 1
    print(d[x]+d[y])
"""


#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

A,B,C,D = read_int()
Max = max(A,B,C,D)

Alice = [True if i >= A and i < B  else False for i in range(Max)]
Bob = [True if i >= C and i < D  else False for i in range(Max)]
Overlap = [True if Alice[i] and Bob[i] else False for i in range(Max)]

sec = 0
for o in Overlap:
    if o:
        sec += 1

print(sec)

Submission status: Accepted

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

def diff(x, y):
    time = x - y
    return time

if A < C:
    t = diff(B, C)
    if C > B:
        t = 0
    elif D < B:
        t = diff(D, C)
else:
    t = diff(D, A)
    if A > D:
        t = 0
    elif B < D:
        t = diff(B, A)

print(t)

Submission status: Accepted

Solution code:
a, b, c, d = (int(i) for i in input().split())

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

Submission status: Accepted

Solution code:
#ABC 070 B - Two Switches
A,B,C,D = map(int, input().split())
s = A if A>=C else C
f = B if B<=D else D
ans = f-s if f-s>0 else 0
print(ans)

Submission status: Accepted

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

if A >= C:
    start = A
else:
    start = C

if B >= D:
    end = D
else:
    end = B

time = end - start

if time < 0:
    time = 0

print(time)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
A = list(map(int, input().split()))
B = sorted(A)
print(0 if (A[2]>A[1] or A[0]>A[3]) else B[2]-B[1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
alice = [1 if a <= i < b else 0 for i in range(0, 101)]
bob = [1 if c <= i < d else 0 for i in range(0, 101)]
print(len(['' for i in range(0, 101) if alice[i] == bob[i] == 1]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    a,b,c,d = [int(_) for _ in input().split()]
    print(max(min(b,d)-max(a,c),0))
    
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 0)

Submission status: Accepted

Solution code:
""" AtCoder """

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

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

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
ma = max([A,C])
mi = min([B,D])
if ma <= mi:
    print(mi-ma)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
	a, b, c, d = map(int, input().split(" "))
	
	if c >= b or a >= d:
		print(0)
		sys.exit()
		
	bb = min(b, d)
	aa = max(a, c)
	
	print(bb - aa)
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
	a, b, c, d = map(int, input().split(" "))
	
	if c >= b or a >= d:
		print(0)
		sys.exit()
	
	if a <= c and b >= d:
		print(d - c)
		sys.exit()
	
	if a >= c and b <= d:
		print(b - a)
		sys.exit()
		
	if a < c:
		print(b - c)
		sys.exit()
		
	if a > c:
		print(d - a)
		sys.exit()
		
	if d < b:
		print(d - c)
		sys.exit()
		
	if d > b:
		print(b - c)
		sys.exit()
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
from itertools import accumulate
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

l = [0]*101
l[A] += 1
l[B] -= 1
l[C] += 1
l[D] -= 1
l = list(accumulate(l))
print(l.count(2))

Submission status: Accepted

Solution code:
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 0)

Submission status: Accepted

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

if t[1] <= t[2] or t[3] <= t[0]:
    print(0)
else:
    t.remove(min(t))
    t.remove(max(t))
    print(abs(t[1]-t[0]))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
a, b, c, d = map(int, input().split())
ans = 0
if a < d and b > c:
    n = sorted([a, b, c, d])
    ans = n[2] - n[1]
print(ans)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input().split())
p = [[a,'A'],[b,'B'],[c,'C'],[d,'D']]
p.sort()

if (p[1][1] == 'B' and p[2][1] == 'C') or (p[1][1] == 'D' and p[2][1] == 'A'):
    print(0)
else:
    print(p[2][0] - p[1][0])