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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    a, b, c, d = mi()
    cnt = 0
    for i in range(101):
        if a <= i <= b-1 and c <= i <= d-1:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(sec)

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

st = max(a, c)
ed = min(b, d)

if ed - st > 0:
    print(ed-st)
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:
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    a, b, c, d = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

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

    cnt = 0
    for a in A:
        for b in B:
            if a == b:
                cnt += 1
                break

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


resolve()

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

A,B,C,D = inputIL()

b1 = (1<<B)-(1<<A)
b2 = (1<<D)-(1<<C)
ans = b1 & b2
print(count_bit(ans))

Submission status: Accepted

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

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

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

result = end - start
if result < 0:
    result = 0

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0] * 110

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

print(ans.count(2))

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

Submission status: Accepted

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

Submission status: Accepted

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

alice = [1 if a <= i < b else 0 for i in range(100)]
bob = [1 if c <= i < d else 0 for i in range(100)]
res = [0 for _ in range(100)]

for i in range(len(res)):
    res[i] = alice[i] * bob[i]

print(sum(res))

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

Submission status: Accepted

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

x = [i for i in range(A, B+1)] + [i for i in range(C, D+1)]
l = len(x) - len(set(x))
if l > 0:
    print(l-1)
else:
    print(0)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:


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

"""
case1
a b c d   →0

case2
a c b d  → b-c

case3
a c d b → d-c

case4
c a 

start →開始時刻のmax
end →終了時刻のmin



"""
starttime = max(a,c)
endtime  = min(b,d)

if starttime < endtime:
    result  = endtime - starttime
else:
    result = 0




"""
if b<=c :
    result = 0
else:  ## c < b 
    if b < d:  ## c < b < d
        result  = b - c
    else:  ## c < d <= b
        result  = d -c
"""



print(result)

Submission status: Accepted

Solution code:
A,B,C,D = map(int, input().split())
a = []
b = []
for i in range(A,B+1):
    a.append(i)
for i in range(C,D+1):
    b.append(i)
print(max(len(set(a)&set(b))-1,0))

Submission status: Accepted

Solution code:
A,B,C,D=list(map(int,input().split()))
AB=set(tuple(list(range(A,B+1))))
CD=set(tuple(list(range(C,D+1))))
f=AB.intersection(CD)
print(max(len(f)-1,0))

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

if s <= 0:
    s = 0

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc070/tasks/abc070_b

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

s1=set()
s2=set()

for i in range(a,b+1):
    s1.add(i)

for i in range(c,d+1):
    s2.add(i)

s1_s2_and=s1&s2
if len(s1_s2_and)==0:
    print(0)
else:
    print(len(s1_s2_and)-1)

Submission status: Accepted

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

Submission status: Accepted

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

"""
count = 0

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

print(count)
"""

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

ans = max(0, upper - lower)

print(ans)

Submission status: Accepted

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

count = 0

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

print(count)

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
A, B, C, D = map(int, input().split())
s, g = 0, 0
if A <= C:
    s = C
    if B < s:
        print(0)
        sys.exit()
else:
    s = A
    if D < s:
        print(0)
        sys.exit()

if B <= D:
    g = B
else:
    g = D

print(g - s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

Submission status: Accepted

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

ans=0

if A<C:
    A=C
if D<B:
    B=D

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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




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

Submission status: Accepted

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

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

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

# BとDのうち小さい方-AとCのうち大きい方　で求まる
if min(B,D)>=max(A,C):
    ans = min(B,D)-max(A,C)

    


print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    A,B,C,D = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    if B<C or D<A:
        cnt = 0
    else:
        cnt = min(B,D)-max(A,C)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
A, B, C, D = ri_()
print(max(0, min(B, D) - max(A, C)))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

# 単にif min(b, d) >= max(a, c): min(b, d) - max(a, c) else 0でいいじゃん
# めっちゃ集中力切れてた

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

Submission status: Accepted

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

Submission status: Accepted

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

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(B,D)-A)
else:
    print(0)

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):
    time =0
else:
    if A < C: # Bの方があとに押した場合
        if B < D:
            time = B-C
        else:
            time = D-C
    else:
        if B<D:
            time = B-A
        else:
            time = D-A
print(time)

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

Submission status: Accepted

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

l_ab = []
l_cd = []
for i in range(a,b+1):
    l_ab.append(i)
for i in range(c,d+1):
    l_cd.append(i)


print(max(0,len(set(l_ab)&set(l_cd))-1))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
A, B, C, D = MAP()

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

print(a if a > 0 else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline().rstrip

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:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

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())
alice = [_ for _ in range(a, b + 1)]
bob = [_ for _ in range(c, d + 1)]
dt = list(set(alice) & set(bob))
print(dt[-1] - dt[0] if dt != [] else 0)

Submission status: Accepted

Solution code:
x=list(map(int,input().split()))
if x[1]<x[3]:
    x=x
elif x[1]>x[3]:
    x=[x[2],x[3],x[0],x[1]]
else:
    x=[min(x[0],x[2]),x[1],max(x[0],x[2]),x[3]]
a,b,c,d=x

print(max(0,b-c) if a<c else b-a)

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
lisa=[]
for i in range(a,b):
  lisa.append(i)
lisb=[]
for j in range(c,d):
  lisb.append(j)
count=0
for k in range(0,len(lisa)):
  if lisa[k] in lisb:
    count+=1
print(count)

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
al = set([i for i in range(a, b)])
bo = set([i for i in range(c, d)])
print(len(al&bo))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, C, D = list(map(int, input().split()))
if A <= C:
    x = [A, B]
    y = [C, D]
else:
    y = [A, B]
    x = [C, D]
if x[1] <= y[1]:
    d = x[1] - y[0]
else:
    d = y[1] - y[0]
if d < 0:
    d = 0
print(d)

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

Submission status: Accepted

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

if a > c:
    a, c = c, a
if b > d:
    b, d = d, b
ans = b - c
if ans < 0:
    ans = 0

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if B <= C or D <= A:
  print(dis)
elif 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)

Submission status: Accepted

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

Submission status: Accepted

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

time = [0]*101

for i in range(A,B):
    time[i] += 1
for i in range(C,D):
    time[i] += 1

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

print(ans)

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())
cnt=0
for i in range(max(A,B,C,D)):
    if  A<=i<B and C<=i<D:
        cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans=0

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

if ans>=0:
    print(ans)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
A, B, C, D = map(int, sys.stdin.readline().split())
s = max(A, C)
f = min(B, D)
if f -s >= 0:
    print(f - s)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s1, f1, s2, f2 = map(int,input().split())
sec = min(f1,f2) - max(s1,s2)
print(sec if sec >= 0 else "0")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ABC070B

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

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())
a_b=set(range(a,b+1))
c_d=set(range(c,d+1))
print(len(a_b&c_d)-1 if len(a_b&c_d)!=0  else 0)

Submission status: Accepted

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