Problem:


Score : 200 points

Problem Statement

Alice and Bob are controlling a robot. They each have one switch that controls the robot.

Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.

Bob started holding down his button C second after the start-up, and released his button D second after the start-up.

For how many seconds both Alice and Bob were holding down their buttons?

Constraints

0≤A<B≤100

0≤C<D≤100

All input values are integers.

Input

Input is given from Standard Input in the following format:  

A B C D

Output

Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.

Sample Input 1

0 75 25 100

Sample Output 1

50

Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.

Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.

Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.

Sample Input 2

0 33 66 99

Sample Output 2

0

Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.

Sample Input 3

10 90 20 80

Sample Output 3

60



Sample input:
0 75 25 100


Sample output:
50

Submission status: Accepted

Solution code:
a,b,c,d=map(int, input().split())
count = 0
ablist = []
cdlist = []
for i in range(a, b+1):
    ablist.append(i)
for i in range(c, d+1):
    cdlist.append(i)
# print(ablist)
# print(cdlist)
for i in ablist:
    # print(i)
    if i in cdlist:
        count += 1

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

Submission status: Accepted

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

def main():
    if (b < c) | (d < a):
        print('0')
        return None
    else:
        x = max(a, c)
        y = min(b, d)
        print(abs(x-y))
main()

Submission status: Accepted

Solution code:
import numpy as np

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

A = np.array([False] * 101)
B = np.array([False] * 101)

A[a:b] = True
B[c:d] = True

ans = np.logical_and(A, B).sum()
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())

if A==C:
    print(min(B-A,D-C))

elif A<C:
    if B>=D:
        print(max(0,D-C))
    elif B<=D:
        print(max(0,B-C))

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

    elif D<=B:
        print(max(D-A,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(a,b,c,d):
    lst = [(a,"start",),(b,"end"),(c,"start"),(d,"end")]
    lst.sort(key = lambda x:x[0])
    overlap = 0
    time = 0
    temp = 0
    for i in lst:
        if overlap == 2:
            time = i[0] - temp
        if i[1] == "start":
            overlap += 1
            temp = i[0]

        if i[1] == "end":
            overlap -= 1



    return time



if __name__ == "__main__":
    a,b,c,d = map(int,input().split())
    print(solve(a,b,c,d))

Submission status: Accepted

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

time = [0] * 101

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

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

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

print(max(0, ans - 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())
ax=[i for i in range(a,b)]
cx=[i for i in range(c,d)]
AX=set(ax)
CX=set(cx)
print(len(AX&CX))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a, b, c, d = map(int, input().split())

if d < a or b < c:
    print("0")
elif c <= a and b <= d:
    print(b-a)
elif a <= c and d <= b:
    print(d-c)
elif c <= a:
    print(d-a)
else:
    print(b-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:
import sys
input = sys.stdin.readline
li = [int(i) for i in input().split()]
if li[0] < li[2] :
    if li[2] >= li[1] :
        print(0)
    else :
        li.sort()
        print(li[2]-li[1])
elif li[2] > li[0] :
    if li[0] >= li[3] :
        print(0)
    else :
        li.sort()
        print(li[2]-li[1])
elif li[0] == 99 and li[1] == 100 and li[2] == 0 and li[3] == 1 :
    print(0)
else :
    li.sort()
    print(li[2]-li[1])

Submission status: Accepted

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

sMax = max([a,c])
gMin = min([b,d])

if sMax >= gMin:
  print(0)
else:
  print(gMin - sMax)

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

if a < c:
    if b > c:
        if b < d:
            ans = b - c
        else:
            ans = d - c
else:
    if d > a:
        if d < b:
            ans = d - a
        else:
            ans = b - a

print(ans)

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

a = []
b = []

for i in range(A, B + 1):
  a.append(i)

for i in range(C, D + 1):
  b.append(i)

a.extend(b)

ans = [x for x in set(a) if a.count(x) > 1]
if len(ans) == 0:
  print(len(ans))
else:
  print(len(ans) - 1)

Submission status: Accepted

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

Submission status: Accepted

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

Alice = [i for i in range(a, b)]
Bob = [i for i in range(c, d)]

same = set(Alice) & set(Bob)
print(len(same))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline().strip
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())
start,stop = max(a,c), min(b,d)
print(stop-start if start<stop else 0)

Submission status: Accepted

Solution code:


import numpy as np

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ABCD = input().split()
A,B,C,D = int(ABCD[0]), int(ABCD[1]), int(ABCD[2]),int(ABCD[3])
low = max(A,C)
high = min(B,D)

if low < high:
  print(high-low)
else:
  print(0)

Submission status: Accepted

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

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

Submission status: Accepted

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

Alice_time = set(range(A,B+1))
Bob_time = set(range(C, D+1))

seki_set = Alice_time.intersection(Bob_time)
seki_list = list(seki_set)

if  seki_list == []:
    print(0)
else:
    print(max(seki_list) - min(seki_list))

Submission status: Accepted

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

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

print(max(end - start, 0))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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


count = 0
for i in range(a, b+1):
    if i in range(c, d+1):
        count += 1
print(max(0, count-1))

Submission status: Accepted

Solution code:
i = list(map(int, input().split()))
s = i[0] if i[0] > i[2]  else i[2]
e = i[1] if i[1] < i[3]  else i[3]
r = e - s if e - s > 0 else 0
print(r)

Submission status: Accepted

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

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

ans = 0
for i in on_btn:
  if i == 2:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
ans = 0
# 求める秒数は(二つのスイッチのうち先に離された方の時刻) - (二つのスイッチのうち後に押された時刻)となる．
_min = min(b, d)
_max = max(a, c)
ans = _min - _max
if ans < 0:
  print(0)
else:
  print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
ab=list(range(a,b+1))
cd=list(range(c,d+1))
dif=list(set(ab) & set(cd))
if len(dif)!=0:
  print(dif[-1]-dif[0])
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
x=0
if c>=a and b<=d:x=b-c
elif a>=c and d<=b:x=d-a
ans=[d-c,x,b-a][int(a>=c)+int(b<=d)]
print(ans if ans>0 else 0)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

A, B, C, D = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

if B <= C:
    print(0)
    exit()

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

print(max(0, B - C))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#N = int(input())
#S = str(input())

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

Submission status: Accepted

Solution code:

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

ans = min(b,d) - max(a,c)
if ans < 0:
    print(0)
else:
    print(ans)
"""
if d<a:#0
    print(0)
elif c<a and a<d<b:#1
    print(d-a)
elif c<a and b<d:#2
    print(b-a)
elif a<c and d<b:#3
    print(d-c)
elif a<c<b and b<d:#4
    print(b-c)
elif b<c:#5
    print(0)
"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a,b,c,d = map(int,input().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,D = (int(i) for i in input().split())
Alice_time = set(range(A,B+1))
Bob_time = set(range(C,D+1))
common_time = Alice_time & Bob_time
common_time_list = list(common_time)
common_time_list_sorted = sorted(common_time_list)
if len(common_time_list_sorted) > 1:
    print(common_time_list_sorted[-1]-common_time_list_sorted[0])
else:
    print(0)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if k>=l:
    print(0)
else:
    print(l-k)

Submission status: Accepted

Solution code:
import sys

a, b, c, d = map(int, sys.stdin.readline().split())

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

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

Submission status: Accepted

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

alice = set(range(a, b+1))
bob = set(range(c, d+1))

ans = len(alice & bob)

print(max(ans - 1, 0))

Submission status: Accepted

Solution code:
import sys
a,b,c,d = map(int, sys.stdin.readline().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 (d < a or b < c): print(0)
else: print(min(b, d) - max(a, c))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    ls = [0] * 101
    a, b, c, d = list(map(int, readline().split()))
    for i in range(a, b):
        ls[i] += 1
    for i in range(c, d):
        ls[i] += 1
    print(ls.count(2))


if __name__ == '__main__':
    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=[int(i) for i in input().split()]
if(c-b>0 or a-d>0):
    print(0)
    exit()
start=max(a,c)
end=min(b,d)
print(end-start)

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

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
if b<c:
    print(0)
elif 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 d >= b:
#   if b - a -c < 0:
#     print(0)
#   else:
#     print(b - a - c)
# else:
#   if d
ans = 0
al = range(a,b + 1)
bo = range(c,d + 1)
for l in al:
  if l in bo:
    ans += 1
if ans > 0:
  print(ans - 1)
else:
  print(0)

Submission status: Accepted

Solution code:

c=input().split()
for i in range(len(c)):
    c[i]=int(c[i])
if c[1]<c[2] or c[3]<c[0]:
    print(0)
else:
    c.sort()
    print(c[2]-c[1])

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

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

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

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

Submission status: Accepted

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

if C <= B and A <= C:
    if D <= B:
        time = D - C
    else:
        time = B - C

if D >= A and A >= C:
    if D <= B:
        time = D - A
    else:
        time = B - A

print(time)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
ABCD=list(map(int,input().split()))
A=ABCD[0]
B=ABCD[1]
C=ABCD[2]
D=ABCD[3]

E=list(range(A,B+1))
F=list(range(C,D+1))

if len(list(set(E)&set(F)))==0:
    print(0)
else:
    print(len(list(set(E)&set(F)))-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max(0, t))

Submission status: Accepted

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

alice = []
bob = []
for i in range(a, b+1):
    alice.append(i)
#print(alice)
for j in range(c, d+1):
    bob.append(j)
#print(bob)

count=0
for i in range(len(alice)):
    if alice[i] in bob:
        count += 1

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

Submission status: Accepted

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

print(max(time, 0))

Submission status: Accepted

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

X = max(A,C)
Y = min(B,D)

ans = max(Y - X,0)
print(ans)

Submission status: Accepted

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

    if not (0 <= a and a < b and b <= 100 and 0 <= c and c < d and d <= 100):
        return
    if not (isinstance(a, int) and isinstance(b, int) and isinstance(c, int) and isinstance(d, int)):
        return
    
    if(b <= c or d <= a):
        print(0)
    elif(a <= c and c < b and b <= d):
        print(b - c)
    elif(c <= a and a < d and d <= b):
        print(d - a)
    elif(a <= c and d <= b):
        print(d - c)
    elif(c <= a and b <= d):
        print(b - a)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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:
##### 解けた #####

import numpy as np

A,B,C,D=list(map(int,input().split(" ")))
R=np.zeros((100,))

if B<100:
    R[B]+=-1
if D<100:
    R[D]+=-1

R[A]+=1
R[C]+=1

Rcum=np.cumsum(R)
print((Rcum==2).sum()) # 2人同時に押している時間

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:
#Two Switches
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 C <= A <= D <= B:
    print(D-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())
AB = [str(i) for i in range(A,B+1)]
CD = [str(j) for j in range(C,D+1)]
count = 0

for a in range(101):
  if str(a) in AB and str(a) in CD:
    count += 1
if count == 0:
  print(0)
else:
  print(count-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import groupby

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

alice = np.zeros(max(B, D))
bob = np.zeros(max(B, D))

alice[A:B] = 1
bob[C:D] = 1

# print(alice)
# print(bob)
print(np.sum(alice + bob == 2))

Submission status: Accepted

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

k = 100

la = [0]*(k+1)
lb = [0]*(k+1)

for i in range(a,b+1):
	#print(i)
	la[i] = la[i] + 1

for i in range(c,d+1):
	#print(i)
	lb[i] = lb[i] + 1

ans = 0
for i in range(k+1):
	#print(i)
	if la[i]==lb[i]==1:
		ans = ans + 1

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

Submission status: Accepted

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

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=map(int,input().split(" "))
alice=list(range(a,b+1))
bob=list(range(c,d+1))
both=list(set(alice).intersection(set(bob)))
if both==[]:
    print(0)
else:
    print(both[-1]-both[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:
a, b, c, d = map(int, input().split())
length = max(b,d)
checker = [0] * length
for i in range(a, b):
    checker[i] = 1
for i in range(c, d):
    checker[i] = 1
ans = (b-a) + (d-c) -sum(checker)
print(ans)

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

Submission status: Accepted

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

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:
    l=sorted([a,b,c,d])
    print(l[2]-l[1])

Submission status: Accepted

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

line = [int(i) for i in input().split()]
v1 = line[0]
v2 = line[1]
v3 = line[2]
v4 = line[3]

s1 = set(range(v1,v2+1))
s2 = set(range(v3,v4+1))

inter = s1.intersection(s2)

res = len(inter)-1
if res == -1 : res = 0
print(res)

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

Submission status: Accepted

Solution code:
def examB():
    A, B, C, D = LI()
    ans = max(0,min(B,D) - max(A,C))
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

Solution code:
# ABC 070: B – Two Switches
a, b, c, d = [int(s) for s in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(max(0,f-e))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input().split())
 
alice = [i for i in range(A,B + 1)]
bob = [i for i in range(C,D + 1)]
 
common = [i for i in bob if i in alice]

if len(common) == 0:
  print(0)
else:
  print(len(common)-1)

Submission status: Accepted

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

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

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

print(0 if ans < 0 else ans)

Submission status: Accepted

Solution code:
aliceStart, aliceStop, bobStart, bobStop = map(int, input().split())
start = max(aliceStart, bobStart)
stop = min(aliceStop, bobStop)
ans = stop - start
if ans < 0:
  ans = 0
print(ans)

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
al=[]
bl=[]
for i in range(a,b+1):
    al.append(i)
for i in range(c,d+1):
    bl.append(i)
albl=set(al)&set(bl)
if len(albl)==0:
    print(0)
else:
    print(len(albl)-1)

Submission status: Accepted

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

if a < c:
  st = c
else:
  st = a
if b < d:
  ed = b
else:
  ed =d
if ed-st < 0:
  print("0")
else:
  print(ed-st)

Submission status: Accepted

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

sw1 = 0
sw2 = 0
count  = 0
for i in range(100):
    if i == a:
        sw1 = 1
    elif i == b:
        sw1 = 0
    if i == c:
        sw2 = 1
    elif i == d:
        sw2 = 0

    if sw1 == 1 and sw2 == 1:
        count += 1

print(count)

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:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c,d = inpl()
res = 0
for i in range(a,d+1):
    if i <= b and i >= c:
        res += 1
print(max(0,res-1))

Submission status: Accepted

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

ans = [i for i in alice if i in bob]
print(len(ans)-1 if ans != [] else 0)