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:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
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] = LS()
    return l
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

A, B, C, D = LI()
time = [0]*100
time[A:B] = list(map(lambda x: x+1, time[A:B]))
time[C:D] = list(map(lambda x: x+1, time[C:D]))
print(time.count(2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l=input().split()
A,B,C,D=int(l[0]),int(l[1]),int(l[2]),int(l[3])
s=0
for i in range(100):
    if A<=i<B:
        if C<=i<D:
            s+=1
print(s)

Submission status: Accepted

Solution code:
a_start,a_stop,b_start,b_stop = map(int,input().split())
later_start = max([a_start,b_start])
early_stop = min([a_stop,b_stop])
if early_stop > later_start:
  print(early_stop - later_start)
else:
  print("0")

Submission status: Accepted

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

count = min([b, d]) - max([a, c])
if count < 0:
    count = 0

print(count)

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


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input().split())
# distance from max of less value(A,C) to min of larger value
start = max(A,C)
end = min(B,D)
print(max(0,end-start))

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input().split())
if A > D 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 and C <= B:
  print(B-C)
else:
  print(D-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:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

A, B, C, D = nl()

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

Submission status: Accepted

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

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
ans=[0]*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:
def abc():
    a, b, c, d = map(int, input().split())
    alice = range(a, b+1)
    bob = range(c, d+1)
    l = len(set(alice) & set(bob))
    if l > 0:
        l -= 1
    print(l)


abc()

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

if B <= C or A >= D:
    print('0')
    exit()
elif B <= D:
    if A >= C:
        print('{}'.format(B-A))
        exit()
    else:
        print('{}'.format(B-C))
        exit()
else:
    if A >= C:
        print('{}'.format(D-A))
        exit()
    else:
        print('{}'.format(D-C))
        exit()

Submission status: Accepted

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

start = A 
if A < C :
    start = C
end = B
if B > D :
    end = D
time = end - start
if time < 0:
    time = 0
    
print (time)

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

Submission status: Accepted

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

if a>c:
    sta=a
else:
    sta=c

if b>d:
    end=d
else:
    end=b

ans=end-sta
if ans<0:
    ans=0
print(ans)

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

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

Submission status: Accepted

Solution code:
from sys import stdin
A,B,C,D = [int(x) for x in stdin.readline().rstrip().split()]
Alice = set(range(A,B))
Bob   = set(range(C,D))
print(len(Alice & Bob))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

if B <= C or A >= D:
    pass
elif B <= D and A <= C:
    total = B - C
elif B <= D and A > C:
    total = B - A
elif B > D and A <= C:
    total = D - C
else:
    total = D - A

print(total)

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int,input().split())
e = list(range(a,b+1))
d = list(range(c,d+1))
#print(e)
l = []
for i in e:
  if i in d:
    l.append(i)
if l == []:
  print(0)
else:
  print(len(l)-1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string

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

sys.setrecursionlimit(2147483647)
INF = float("inf")

# S = sys.stdin.readline().rstrip()
# for c in string.ascii_lowercase:
#     if c not in S:
#         print(c)
#         exit()
# print('None')

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

print(len(set(list(range(A, B))) & set(list(range(C, D)))))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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 = map(int,input().split())
print(max(len(set(range(a,b+1))&set(range(c,d+1)))-1,0))

Submission status: Accepted

Solution code:
a, b, c, d = list(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:
    a,b,c,d = c,d,a,b
# aのスタートが常に最小

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
print(len({i for i in range(A,B)} & {j for j in range(C,D)}))

Submission status: Accepted

Solution code:
a, b , c, d = list(map(int, input().strip().split()))
lst = []
lstt = []
for i in range(a, b + 1):
    lst.append(i)

for i in range(c, d+1):
    lstt.append(i)

one = set(lst)
two = set(lstt)

inter = one & two
if len(inter)-1 > 0:
    print(len(inter)-1)
else:
    print(0)

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
if a[2]>=a[1]or a[0]>=a[3]:
  print(0)
else:
  a.sort(reverse=True)
  print(a[1]-a[2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, D: int):
    if A < C:
        ret = min(B - C, D - C)
    else:
        ret = min(D - A, B - A)
    ret = max(0, ret)
    print(ret)
    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))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if stop - start <= 0:
    print(0)
else:
    print(stop - start)

Submission status: Accepted

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

a_li = [0 for i in range(100)]
b_li = [0 for i in range(100)]
a_li[a:b] = [1 for i in range(a,b)]
b_li[c:d] = [1 for i in range(c,d)]

li = []
for i,j in zip(a_li, b_li):
  li.append(i+j)

print(li.count(2))

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:
A, B, C, D = [int(s) for s in input().split()]

duration1 = range(A, B+1)
duration2 = range(C, D+1)

print(max([len([i for i in duration1 if i in duration2])-1,0]))

Submission status: Accepted

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

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

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()]
print(len(set(range(A, B)) & set(range(C, D))))

Submission status: Accepted

Solution code:
A_start, A_end, B_start, B_end = map(int, input().split())


start = A_start if A_start > B_start else B_start
end = B_end if A_end > B_end else A_end
if end - start < 0:
    print(0)
else:
    print(end - start)

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:

def main(A, B, C, D):
    start = min(A, C)
    end = max(B, D)
    alice_list = [1 if A <= i < B else 0 for i in range(start, end)]
    bob_list = [1 if C <= i < D else 0 for i in range(start, end)]

    print(sum([all(t) for t in zip(alice_list, bob_list)]))
    

if __name__ == "__main__":
    A, B, C, D = [int(x) for x in input().split()]

    main(A, B, C, D)

def test1(capsys):
    inputs = [0, 75, 25, 100]
    out = 50
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test3(capsys):
    inputs = [0, 33, 66, 99]
    out = 0
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test4(capsys):
    inputs = [10, 90, 20, 80]
    out = 60
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test5(capsys):
    inputs = [10, 50, 50, 90]
    out = 0
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
alice = []
bob = []
for i in range(0, 100):
	alice.append(0)
	bob.append(0)
for i in range(A, B):
	alice[i] = 1
for i in range(C, D):
	bob[i] = 1
cnt = 0
for i in range(0, 100):
	cnt += alice[i]*bob[i]
print(cnt)

Submission status: Accepted

Solution code:
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    i = inputs[0].split()
    times = {"a": {}, "b": {}}
    times["a"]["start"] = int(i[0])
    times["a"]["end"] = int(i[1])
    times["b"]["start"] = int(i[2])
    times["b"]["end"] = int(i[3])

    first_start = "a" if times["a"]["start"] < times["b"]["start"] else "b"
    second_start = "b" if first_start == "a" else "a"

    first_end = "a" if times["a"]["end"] < times["b"]["end"] else "b"
    second_end = "b" if first_end == "a" else "a"

    if second_start == first_end:
        return times[first_end]["end"] - times[second_start]["start"]
    if times[first_end]["end"] < times[second_start]["start"]:
        return 0

    return (
        (times[second_end]["end"] - times[first_start]["start"])
        - (times[second_start]["start"] - times[first_start]["start"])
        - (times[second_end]["end"] - times[first_end]["end"])
    )


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
ans = 0
for t in range(101):
    if a <= t < b and c <= t < d:
        ans += 1
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:
  print(min(d,b)-c)
else:
  print(min(b,d)-a)

Submission status: Accepted

Solution code:
A,B,C,D=map(int,input().split())
a=[A,B,C,D]
a.sort()
if B<C:
  print(0)
elif A>D:
  print(0)
else:
  print(a[2]-a[1])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

first_stop = min(b, d)
last_start = max(a, c)

if first_stop - last_start <= 0:
    print(0)
else:
	print(first_stop - last_start)

Submission status: Accepted

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

s = max(a,c)
e = min(b,d)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max(upper-lower, 0))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
A, B, C, D = map(int, input().split())

if B >= C and D >= A:
    Slist = [A, B, C, D]
    Slist.sort()
    print(Slist[2] - Slist[1])
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, D = list(map(int, input().strip().split(' ')))
print(max(0, len({i for i in range(A, B+1)} & {j for j in range(C, D+1)})-1))

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input().split())
ans = 0
if b>=c and d>=a:
    s = [a,b,c,d]
    s.sort()
    ans = (s[2]-s[1])
print(ans)

Submission status: Accepted

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

range_AB = [ x for x in range(A, B ) ]
range_CD = [ x for x in range(C, D ) ]

duration = 0

for x in range_AB:
    if x in range_CD:
        duration = duration + 1
        
print(duration)

Submission status: Accepted

Solution code:
a,b,c,d = map(int, input().split())
temp = [1 if i >= a and i < b else 0 for i in range(101)]
temp = [j+1 if i >= c and i < d else j for (i,j) in enumerate(temp)]
print(str(len([i for i in temp if i == 2])))

Submission status: Accepted

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

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

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

print(ans)

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 min(B, D)-max(A, C)>0:
	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(min(b, d) - max(a, c), 0))

Submission status: Accepted

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

def solve():
    A, B, C, D = list(map(int, input().split()))
    start = max(A, C)
    end = min(B, D)

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

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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) else 0)

Submission status: Accepted

Solution code:
A=[int(i) for i in input().split()]
#Alice turns the swich on faster than Bob
if A[0]<=A[2]:
    if A[1]<A[2]:
        print(0)
    elif A[1]>=A[3]:
        print(A[3]-A[2])
    else:
        print(A[1]-A[2])
#bob turns the swich on faster than alice
else:
    if A[3]<A[0]:
        print(0)
    elif A[3]>=A[1]:
        print(A[1]-A[0])
    else:
        print(A[3]-A[0])

Submission status: Accepted

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

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

Submission status: Accepted

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

minBD = min(b, d)
maxAC = max(a, c)

if maxAC < minBD: print(minBD-maxAC)
else: print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc070/tasks/abc070_b
A, B, C, D = map(int, input().split())
ans = min(B, D) - max(A, C)
if C > B and C > A or A > C and A > D:
    print(0)
else:
    print(ans)

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:
a, b, c, d = map(int, input().split())
x = min(b,d) - max(a,c)

print(x if x > 0 else 0)

Submission status: Accepted

Solution code:
l=a,b,c,d=list(map(int,input().split()))
l1=sorted(l)
if (l1.index(c)==0 and l1.index(d)==1) or (l1.index(c)==2):
        print(0)
elif l1.index(c)==0 and l1.index(d)==2:
        print(d-a)
elif l1.index(c)==1 and l1.index(d)==3:
        print(b-c)
elif l1.index(c)==1 and l1.index(d)==2:
        print(d-c)
elif l1.index(c)==0 and l1.index(d)==3:
        print(b-a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
tmp = (input())

A = int(tmp.split(" ")[0])
B = int(tmp.split(" ")[1])
C = int(tmp.split(" ")[2])
D = int(tmp.split(" ")[3])

Alice = {str(x): "A" for x in range(A, B + 1)}
Bob = {str(x): "A" for x in range(C, D + 1)}

cnt = 0

for k, v in Alice.items():
  if k in Bob:
    cnt += 1
    
if cnt -1 == -1:
  print(0)
else:
  print(cnt - 1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

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

Alice = [0]*A+[1]*(B-A)+[0]*200
Bob = [0]*C+[1]*(D-C)+[0]*200

print(sum([Alice[x]*Bob[x] for x in range(200)]))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

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:
import sys
from collections import Counter

a, b, c, d = map(int, input().split())
f_array = [0, 0]
l_array = [0, 0]

if a == c:
    if b == d:
        print(b - a)
    else:
        print(min(b - a, d - c))
    sys.exit()    

elif a < c:
    f_array[0], f_array[1] = a, b
    l_array[0], l_array[1] = c, d
else:
    f_array[0], f_array[1] = c, d
    l_array[0], l_array[1] = a, b

if f_array[1] < l_array[1]:
    if f_array[1] - l_array[0] < 0:
        print(0)
    else:
        print(f_array[1] - l_array[0])
    sys.exit()
else:
    print(l_array[1] - l_array[0])

Submission status: Accepted

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

if b > c:
    result = b-c
if b > d:
    result -= b-d
if a > c:
    result -= a-c

print(result if result >= 0 else 0)

Submission status: Accepted

Solution code:

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

    return a, b, c, d

def submit():
    a, b, c, d = read_input()

    if b < c or d < a:
        print(0)
        return

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

if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
# ABC070B - Two Switches
a, b, c, d = list(map(int, input().rstrip().split()))
print(max(0, min(b, d) - max(a, c)))

Submission status: Accepted

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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=list(map(int,input().split()));print(max([min(a[1::2])-max(a[::2]),0]))

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a,b,c,d = f()
    print(max(min(b,d) - max(a, c),0))

solve()

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())
print(sum(1 for i in range(0, 101) if a<=i<b and c<=i<d))

Submission status: Accepted

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

Submission status: Accepted

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

start = 0
alice_time = (a, b)
bob_time = (c, d)

max_end = max(b, d)
alice_zone = [0] * max_end
bob_zone = [0] * max_end
alice_zone[a:b] = [1] * len(alice_zone[a:b])
bob_zone[c:d] = [1] * len(bob_zone[c:d])

kasanari_zone = [alice * bob for alice, bob, in zip(alice_zone, bob_zone)]
print(sum(kasanari_zone))

Submission status: Accepted

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