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

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
if A < C:
    a, b, c, d = A, B, C, D
else:
    a, b, c, d = C, D, A, B

if b <= c:
    print(0)
    exit()

print(min(b, d) - c)

Submission status: Accepted

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

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

#a c b dなら　b-c
#a c d bなら　d-c
#c a d bなら　d-a
#c a b dなら　b-a

an = [A, B, C, D]
an.sort()

if an == [A, C, B, D]:
    print((B - C))
elif an == [A, C, D, B]:
    print((D - C))
elif an == [C, A, D, B]:
    print((D - A))
elif an == [C, A, B, D]:
    print((B - 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 = 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())
X, Y = 0, 0
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,b,c,d = map(int,input().split())

if a > c:
  start = a
else:
  start = c

if b < d:
  end = b
else:
  end = d

print(0 if end-start < 0 else end-start)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

risuto1 = []
risuto2 = []
for i in range(A,B+1):
    risuto1.append(i)
for i in range(C,D+1):
    risuto2.append(i)
kotae = len(set(risuto1) & set(risuto2)) 

if kotae == 0:
    print("0")
else:
    print(list(set(risuto1) & set(risuto2))[-1] - list(set(risuto1) & set(risuto2))[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 B <= C or D <= A:
    print(0)
else:
    if C < B:
        print(min(B, D)-max(C, A))
    elif A < D:
        print(min(B, D)-max(A, C))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input_list = list(map(int, input().split()))
a = input_list[0]
b = input_list[1]
c = input_list[2]
d = input_list[3]

Alice_range = set(range(a,b))
Bob_range = set(range(c,d))
same_time = len(Alice_range & Bob_range)

print(same_time)

Submission status: Accepted

Solution code:
listA = list(map(int, input().split()))
if min(listA[3], listA[1])-max(listA[0], listA[2])<0:
    print(0)
else:
    print(min(listA[3], listA[1])-max(listA[0], listA[2]))

Submission status: Accepted

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

if b <= c or d <= a:
    print("0")
    exit(0)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, d = list(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 = map(int, input().split())

l = max(a, c)
r = min(b, d)

if l <= r:
    print(r - l)
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a,b,c,d = li()

on = [0]*101

for i in range(101):
    if a <= i <= b and c <= i <= d:
        on[i] += 1
        
print(max(sum(on)-1, 0))

Submission status: Accepted

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

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

s = sorted([A,B,C,D])

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

Submission status: Accepted

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

Submission status: Accepted

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

def func1(k,l):
    if k>l:
        return l
    else:
        return k

def func(x):
    if (x[2]>x[1]) or (x[0]>x[3]):
        return 0
    else:
        if x[0]>x[2]:
            return (func1(x[1],x[3])-x[0])
        else:
            return (func1(x[1],x[3])-x[2])

print(func(n))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
imos = [0 for i in range(102)]
imos[A] += 1
imos[B] -= 1
imos[C] += 1
imos[D] -= 1
for i in range(1, 101):
    imos[i] += imos[i - 1]
cnt = 0
for i in range(101):
    if imos[i] == 2:
        cnt += 1
print(cnt)

Submission status: Accepted

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

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:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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


if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
a, b, c, d = [int(v) for v in input().split()]
ans = min(b, d) - max(a, c)
if ans < 0:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    A, B, C, D = li_input()
    L = [0] * 101

    for i in range(101):
        if A <= i < B:
            L[i] += 1

        if C <= i < D:
            L[i] += 1

    ans = 0

    for l in L:
        if l == 2:
            ans += 1

    print(ans)


main()

Submission status: Accepted

Solution code:
A,B,C,D = list(map(int, input().split()))
ans = sum([(A <= i and i < B) and (C <= i and i < D) for i in range(101)])
print (ans)

Submission status: Accepted

Solution code:
import numpy
a, b, c, d = map(int, input().split())
l = [0]*110
l[a] += 1
l[b] -= 1
l[c] += 1
l[d] -= 1
l = numpy.cumsum(l)
print(list(l).count(2))

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:
    print(0)

elif D <= A:
    print(0)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if higher<lower:
  print(0)
else:
  print(higher-lower)

Submission status: Accepted

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

Submission status: Accepted

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

if c - b > 0 or a - d > 0:
    print('0')
else:
    time_list.sort()
    print(time_list[2] - time_list[1])

Submission status: Accepted

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

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

width = right - left
print(width if width>0 else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# vim: set fileencoding=utf-8 :
a1, a2, b1, b2 = map(int, raw_input().split())

# Aが動いてる間に
if a1 <= b1 <= a2:
    # Bが先に終わる
    if b2 <= a2:
        print(b2 - b1)
    else:
        print(a2 - b1)
elif b1 <= a1 <= b2:
    # Bが先に終わる
    if a2 <= b2:
        print(a2 - a1)
    else:
        print(b2 - a1)
else:
    print(0)

Submission status: Accepted

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

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

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

sys.exit(0)

Submission status: Accepted

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

def main():
    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)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
l={i for i in range(a,b+1)}&{i for i in range(c,d+1)}
if not l:
  print(0)
else:
  print(len(l)-1)

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
ans=[0 for _ in range(100)]
for i in range(a,b):
    ans[i] += 1
for i in range(c,d):
    ans[i] += 1
print(ans.count(2))

Submission status: Accepted

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

a = []
for i in range(A,B+1):
    a.append(i)
b = []
for i in range(C,D+1):
    b.append(i)
c = set(a)&set(b)
if c ==set():
    print(0)
else:
	print(len(c)-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

e=max([a,c])
f=min([b,d])

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

Submission status: Accepted

Solution code:
import sys

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

if b < c or d < a:
  print(0)
  sys.exit()

if a < c:
  if b < d:
    print(b - c)
    sys.exit()
  else:
    print(d - c)
else:
  if b < d:
    print(b - a)
  else:
    print(d - a)

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:
"""
https://abc070.contest.atcoder.jp/tasks/abc070_b
"""
[a,b,c,d]=[int(i) for i in input().split()]
#abcd,cdab,
if b<c or d<a:
    print(0)
#acbd
elif a<=c and c<=b and b<=d:
    print(b-c)
#cabd
elif c<=a and b<=d:
    print(b-a)
#cadb
elif c<=a and d<=b:
    print(d-a)
#acdb
elif a<=c and d<=b:
    print(d-c)

Submission status: Accepted

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

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

if min_BD >= max_AC:
    print(min_BD - max_AC)
else:
    print(0)

Submission status: Accepted

Solution code:
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 A > C and 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,raw_input().split())
print sum([1 if A<=x and x+1<=B and C<=x and x+1<=D else 0 for x in range(100)])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
# -*- coding: utf-8 -*-

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

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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_s, A_e, B_s, B_e = map(int, input().split())
# print(A_s, A_e, B_s, B_e)

lower = max(A_s, B_s)
upper = min(A_e, B_e)

print(max(0, upper - lower))

Submission status: Accepted

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

Submission status: Accepted

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

def cal(n):
    global B, D
    if B <= D:
        print(B-n)
    else:
        print(D-n)

if A >= D or B <= C:
    print(0)
elif A >= C:
    cal(A)
else:
    cal(C)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	a, b, c, d = map(int, input().split())
	print(max(0, min(b, d) - max(a, c)))

if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int,input().split())
if (min(b, d) - max(a, c)) <= 0:
    print('0')
else :
    print('{}'.format(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(0)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

alice = [0] * 101
bob = [0] * 101

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

cnt = 0
for i in range(max(b,d)):
    if alice[i] == 1 and bob[i] == 1:
        cnt += 1

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

elif A < C:
    print(min(B - C, D - C))

else:
    print(min(D - A, B - A))

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 dup(A, B):
    r = 0
    for x in A:
        if x in B:
          r = r + 1
    return r-1 if r != 0 else 0


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

A = range(a, b+1)
B = range(c, d+1)

result = dup(A, B) if len(A) <= len(B) else dup(B, A)

print(result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def smaller(x, y):
	if x < y: return x
	else: return y

def calc(a, b, c, d):
	if b < c: return 0
	else: return smaller(b, d) - c

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

if A > C:
	tmp1 = A
	tmp2 = B
	A = C
	B = D
	C = tmp1
	D = tmp2

print calc(A, B, C, D)

Submission status: Accepted

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

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

t1, t2 = max(a, c), min(b, d)
if t2-t1 < 0:
    t = 0
else:
    t = t2 - t1

print(t)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

t = min([B,D])-max([A,C])

if t<0: t = 0 

print(t)

Submission status: Accepted

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

Submission status: Accepted

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

arr[a]+=1
arr[b]+=-1
arr[c]+=1
arr[d]+=-1
ans=0


for x in range(1,100):
    arr[x]+=arr[x-1]


for x in arr:
    if x==2:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
d_AB = B - A
d_DC = D - C
set_AB = set()
set_CD = set()
for i in range(A, B + 1):
    set_AB.add(i)
for i in range(C, D + 1):
    set_CD.add(i)
if len(set_AB.intersection(set_CD)) == 0:
    print(0)
else:
    print(len(set_AB.intersection(set_CD)) - 1)

Submission status: Accepted

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

right_boundary =D
left_boundary = C

if (B<C)or(D<A):
    print(0)
else:
    if C<A:
        left_boundary = A
    else:
        pass
    if B<D:
        right_boundary = B
    else:
        pass
    
    print(right_boundary - left_boundary)

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

solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

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


mindata = a  if a>c else c
maxdata = b  if b<d else d



print(maxdata-mindata if maxdata>mindata else 0)

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)

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

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
ans=[0 for j in range(101)]
for i in range(a,b):
  ans[i]+=1
for j in range(c,d):
  ans[j]+=1
cnt=0
for k in range(101):
  if ans[k]==2:
    cnt+=1
print(cnt)

Submission status: Accepted

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

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:
# ABC 070 B

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

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

print(max(end - begin, 0))

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:
# -*- coding: utf-8 -*-

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

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

print(max(0, upper - lower))

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:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    times = list(map(int, input().split()))

    alice_start = times[0]
    alice_end = times[1]
    bob_start = times[2]
    bob_end = times[3]

    if (bob_end < alice_start) or (alice_end < bob_start):
        print(0)
    else:
        sorted_times = sorted(times)
        print(sorted_times[2] - sorted_times[1])

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
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())
lisa = []
lisb = []
for n in range((b-a)+1):
  lisa.append(n + a)
for m in range((d-c)+1):
  lisb.append(m + c)
ans = 0
for i in range(101):
  if i in lisa and i in lisb:
    ans += 1
if ans > 0:
  print(ans-1)
else:
  print(ans)