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
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
a, b, c, d = map(int, input().split())
arr = [0] * 101

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

for j in range(c, d + 1):
    arr[j] += 1

ans = len([cnt for cnt in arr if cnt >= 2])

print(ans - 1 if ans != 0 else 0)

Submission status: Accepted

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

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

else:
    print(0)

Submission status: Accepted

Solution code:
# coding: utf-8

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


if D <= A or B <= C:
    print(0)
else:
    l = sorted([A, B, C, D])
    print(l[2] - l[1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a,b,c,d = map(int, input().split())
start_later = max(a,c)
stop_earlier = min(b,d)
res = stop_earlier - start_later
print(res if res > 0 else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
a,b,c,d = map(int,input().split())
t = [0]*101

t[a] += 1
t[b] -= 1
t[c] += 1
t[d] -= 1

t = list(np.cumsum(t))
#print(t)
print(t.count(2))

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

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

if start <= end:
    print(end - start)
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())
x = [0]*(202)
x[a] += 1
x[b] -= 1
x[c] += 1
x[d] -= 1
for i in range(201):
    x[i+1] += x[i]
ans = 0
for i in range(202):
    if x[i] == 2:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def main(a,b,c,d):
    l=max(a,c)
    r=min(b,d)
    return max(r-l,0)

if __name__=='__main__':
    a,b,c,d=readinput()
    ans=main(a,b,c,d)
    print(ans)

Submission status: Accepted

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

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())
M = [0]*100

for n in range(A,B):
  M[n-1]+=1
  
for n in range(C,D):
  M[n-1]+=1
  
print(M.count(2))

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

Submission status: Accepted

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

ans = max(end-start, 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(d,b)-max(a,c))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

push =[0]*102
push[A+1]+=1
push[B+1] -=1
push[C+1] +=1
push[D+1] -= 1
count = 0
for i in range(1,len(push)):
    push[i] = push[i] + push[i-1]
    if push[i]==2:
        count +=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

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


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

late_start = 0
first_stop = 0
same_time = 0

late_start = max(A, C)
first_stop = min(B, D)
if first_stop - late_start > 0:
    same_time = first_stop - late_start
else:
    same_time = 0

print(same_time)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = len(list(filter(lambda x: x == 2, cnt)))
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())

Alice = []
for i in range(A,B):
  Alice.append(i)

Bob = []
for s in range(C,D):
  Bob.append(s)

count = 0  
B = B - A

for i in range(B):
  if Alice[i] in Bob:
    count += 1
print(count)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

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

Submission status: Accepted

Solution code:
# ABC070_B
A,B,C,D = map(int, input().split())
f = []
s = []
# 先にボタンを押し始めたほうをfに格納する
if A <= C:
    f = [A, B]
    s = [C, D]
else:
    s = [A, B]
    f = [C, D]

ans = 0
if f[1] <= s[0]:
    ans = 0
elif s[1] <= f[1]:
    ans = s[1] - s[0]
elif f[1] <= s[1]:
    ans = f[1] - s[0]

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

Submission status: Accepted

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

area = [0 for i in range(max([b,d])+1)]

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

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

answer = 0
for i in area:
  if i == 2:
    answer += 1

print(answer)

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

Submission status: Accepted

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

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

alice = [0]*100
bob = [0]*100

alice[A:B] = [1]*(B-A)
bob[C:D] = [1]*(D-C)

print(sum([alice[i]*bob[i] for i in range(100)]))

Submission status: Accepted

Solution code:
import sys
A,B,C,D = map(int,input().split())
if A < 0 or B < 0 or B <= A or A > 100 or B > 100:
    sys.exit()
if C < 0 or D < 0 or D <= C or C > 100 or D > 100:
    sys.exit()

count = 0
for I in range(A,B):
    for J in range(C,D):
        if I == J:
            count += 1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0

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

if count!=0:
  count = count - 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

def ii():
    return int(input())

def main():
    A, B, C, D = mi()
    print(len(set(range(A, B))&set(range(C, D))))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

if a < c:
    s = c
else:
    s = a

if b < d:
    e = b
else:
    e = d

print (max(e-s,0))

Submission status: Accepted

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

if a > c:
  maxac = a
else:
  maxac = c
if b < d:
  minbd = b
else:
  minbd = d

res = minbd - maxac
if res < 0:
  print(0)
else:
  print(res)

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

Submission status: Accepted

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

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

else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
if a < c:
    if c < b and b < d:
        print(b - c)
    elif c < b and d <= b:
        print(d - c)
    else:
        print(0)
else:
    if a < d and d < b:
        print(d - a)
    elif a < d and b <= d:
        print(b - a)
    else:
        print(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());print([0,min(b,d)-max(a,c)][min(b,d)-max(a,c)>0])

Submission status: Accepted

Solution code:
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# ac_py.main
# Date: 2020/06/14
# Filename: main 
# Author: acto_mini

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    A, B, C, D = map(int,input().split())
    if A <= C:
        if B-C <= 0:
            ans = 0
            return ans
        elif B-C > 0 and B <= D:
            ans = B-C
            return ans
        elif B-C > 0 and B > D:
            ans = D-C
            return ans

    elif A > C and A < D:
        if B <= D:
            ans = B-A
            return ans
        elif B > D:
            ans = D-A
            return ans

    elif A >= D:
        ans = 0
        return ans

print(main())

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

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


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nums = [int (e) for e in input().split()]

lower = min(nums[1], nums[3])
upper = max(nums[0], nums[2])

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

Submission status: Accepted

Solution code:
def calc(a, b, c, d) :
  if c < a and b < d :
    return b - a
  elif a <= c <= b : 
    if d < b : 
      return d - c
    else : 
      return b - c
  elif a <= d <= b :
    return d - a
  else : 
    return 0

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

print(calc(a, b, c, d))

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
a = set(range(A, B))
b = set(range(C, D))
c = a& b

print(len(c))

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())
al = set(range(a, b))
bo = set(range(c, d))
print(len(al & bo))

Submission status: Accepted

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

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

print(max(0,ans))

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
min_time = 0
if B > C and D > A:
    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:
def resolve():
    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
    print(count)
resolve()

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:
# coding = SJIS
a, b, c, d = map(int, input().split())
ans = max(min(b, d) - max(a, c), 0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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


def func(a_sec, b_sec, c_sec, d_sec):
    if a_sec < c_sec <= b_sec < d_sec:
        temp = b_sec - c_sec
    elif c_sec < a_sec <= d_sec < b_sec:
        temp = d_sec - a_sec
    elif a_sec <= c_sec < d_sec <= b_sec:
        temp = d_sec - c_sec
    elif c_sec <= a_sec < b_sec <= d_sec:
        temp = b_sec - a_sec
    else:
        temp = 0

    print(temp)


func(a_sec=a, b_sec=b, c_sec=c, d_sec=d)

Submission status: Accepted

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

Submission status: Accepted

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

range_AB = range(A, B + 1)
range_CD = range(C, D + 1)

if set(range_AB) & set(range_CD):
    print(len(set(range_AB) & set(range_CD)) - 1)
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())
if A > C:
    A, B, C, D = C, D, A, B
print(max(0, min(D, B)-C))

Submission status: Accepted

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

A=i[0]
B=i[1]
C=i[2]
D=i[3]

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    A, B, C, D = map(int, input().split())
    double  = 0
    for i in range(101):
        if A <= i <= B and C <= i <= D: double += 1
    print(double - 1 if double > 1 else 0)

    return  0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def main():
    #n = int(input())
    a,b,c,d = map( int, input().split())
    if c>=b or a>=d:
        print(0)
    elif a<=c and b>=d:
        print(d-c)
    elif c<=a and d>=b:
        print(b-a)
    elif a >= c:
        print(d-a)
    elif c >= a:
        print(b-c)
    
    
if __name__ == '__main__':
    main()

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

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

Submission status: Accepted

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

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

print(max(0, maxv - minv))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    a = [int(i) for i in input().split()]

    if min(a[3],a[1]) - max(a[0],a[2]) > 0:
        print(min(a[3],a[1]) - max(a[0],a[2]))
    else:
        print(0)

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input().split())
Alice = ['1' if i>=a and i<=b else '0' for i in range(101)]
Bob = ['1' if i>=c and i<=d else '0' for i in range(101)]
ans = 0
for i in range(101):
    if Alice[i]=='1' and Bob[i]=="1":
        ans+=1
print(0 if ans==0 else ans-1)

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input().split())
ab = [i for i in range(a,b+1)]
cd = [i for i in range(c,d+1)]

inter = set(ab).intersection(set(cd))

if len(inter) != 0:
  print(len(inter) - 1)
else:
  print(0)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 29 19:25:06 2020

@author: naoki
"""
import sys

A,B,C,D = map(int,input().split())
time = [A,B,C,D]
time.sort()
if B <= C or D <= A:
    print(0)
    sys.exit()
else:
    print(time[2]-time[1])

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

Submission status: Accepted

Solution code:
A,B,C,D=map(int,input().split())
if C<=B:
    if A<=C:
        if D>=B:
            print(B-C)
        else:
            print(D-C)
    else:
        if D>=B:
            print(B-A)
        elif A<=D<B:
            print(D-A)
        else:
            print(0)
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:
    ans = 0
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())
x = len(set(range(a, b + 1)) & set(range(c, d + 1))) - 1
print(x if x >= 0 else 0)

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
alice = list(range(a, b))
bob = list(range(c, d))
l = alice + bob
s = set(alice + bob)
print(len(l) - len(s))

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
left=max(a,c)
right=min(b,d)
ans = right-left
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 and d<=b:
  print(d-c)
elif c<=a and b<=d:
  print(b-a)
elif a<=c:
  print(abs(b-c))
else:
  print(abs(a-d))

Submission status: Accepted

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


def solve(A: int, B: int, C: int, D: int):
    print(max(0, min(B, D) - max(A, C)))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())
Alice=False
Bob=False
time=0
for i in range(101):
    if i==A:
        Alice=True
    if i==B:
        Alice=False
    if i==C:
        Bob=True
    if i==D:
        Bob=False
    if Alice==True and Bob==True:
        time+=1
print(time)

Submission status: Accepted

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

for i in range(a, b+1):
    l[i] += 1
    
for i in range(c, d+1):
    l[i] += 1
ans = 0
for i in l:
    if i == 2: ans += 1
print(max(ans-1, 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

numbers = sys.stdin.readline().split(' ')

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

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

Submission status: Accepted

Solution code:
import sys
numbers = sys.stdin.readline().split(' ')

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


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num_list= list(map(int,input().split()))
li_A=list(range(num_list[0],num_list[1]))
li_B=list(range(num_list[2],num_list[3]))

li_C=range(0, 10)
li_A+=li_B

len_1=len(li_A)
len_2=len(set(li_A))
print(len_1-len_2)

Submission status: Accepted

Solution code:
time_list = [ int(i) for i in input().split()]

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

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

print(output)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

if seconds <= 0:
    seconds = 0

print(seconds)

Submission status: Accepted

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

seconds = 0

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

print(seconds)

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

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