Problem:


Score : 200 points

Problem Statement

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

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

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

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

Constraints

0≤A<B≤100

0≤C<D≤100

All input values are integers.

Input

Input is given from Standard Input in the following format:  

A B C D

Output

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

Sample Input 1

0 75 25 100

Sample Output 1

50

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

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

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

Sample Input 2

0 33 66 99

Sample Output 2

0

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

Sample Input 3

10 90 20 80

Sample Output 3

60



Sample input:
0 75 25 100


Sample output:
50

Submission status: Accepted

Solution code:
A,B,C,D=map(int,input().split())
if B<=C or D<=A:
    print(0)
else:
    X=[A,B,C,D]
    X=sorted(X)
    print(X[2]-X[1])

Submission status: Accepted

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

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

Submission status: Accepted

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

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

if right >= left:
    print(0)
elif right < left:
    print(left - right)

Submission status: Accepted

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

Submission status: Accepted

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

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


    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A,B,C,D=map(int,input().split())
    a,b=0,0
    for i in range(A,B):
        a|=1<<i
    for i in range(C,D):
        b|=1<<i
    print(bin(a&b).count('1'))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = end - start

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

Submission status: Accepted

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

resolve()

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

if C >= B:
    print(0)
elif D <= A:
    print(0)
else:
    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())
count = 0
for i in range(101):
	if (A<=i<=B and C<=i<=D and A!=D and B!=C):
		count += 1
if (count>0):
	count -= 1
print(int(count))

Submission status: Accepted

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

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

Submission status: Accepted

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

alice_push_time = set(list(range(a, b + 1))) 
bob_push_time = set(list(range(c, d + 1)))

both_push_time = len(alice_push_time & bob_push_time)


if both_push_time > 0:
  both_push_time -= 1
print(both_push_time)

Submission status: Accepted

Solution code:
x = map(int, input().split())
x = sorted(zip(x, [1, -1, 1, -1]))
if x[1][1] == 1:
  print(x[2][0] - x[1][0])
else:
  print(0)

Submission status: Accepted

Solution code:
import numpy as np

A, B, C, D = map(int, input().split())
x = sorted(zip([A, B, C, D], [1, -1, 1, -1]))
if x[1][1] == 1:
  print(x[2][0] - x[1][0])
else:
  print(0)

Submission status: Accepted

Solution code:
import numpy as np

A, B, C, D = map(int, input().split())
x, y = zip(*sorted(zip([A, B, C, D], [1, -1, 1, -1])))
z = np.diff(x)[np.cumsum(y)[:-1] == 2]
print(z[0] if len(z) == 1 else 0)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,C,D=map(int,input().split())
samelst=[]
for ali in range(A,B):
  for bob in range(C,D):
    if ali==bob:
      samelst.append(ali)
print(len(samelst))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# solution

n,m,k,j = map(int, input().split())
print(max(0, min(m,j)-max(n,k)))

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
  
print(time.count(2))

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

Submission status: Accepted

Solution code:

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

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

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())
alice=[0]*(b-a+1)
bob=[0]*(d-c+1)
ct=0
for i in range (a,b+1):
    alice[ct]=i
    ct+=1
ct=0
for i in range (c,d+1):
    bob[ct]=i
    ct+=1
ans=len(set(alice)&set(bob))
if ans==0:
    print(ans)
else:
    print(ans-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ABC 070: B – Two Switches
a, b, c, d = map(int, input().split())
print(min(b, d) - max(a, c) if min(b, d) >= max(a, c) else 0)

Submission status: Accepted

Solution code:
# ABC 070: B – Two Switches
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 and b <= d:
    print(b - c)
elif c <= a and d <= b:
    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())
ans = 0
for i in range(101):
    if A<=i<B and C<=i<D:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if lower<=upper:
    print(upper-lower)
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())

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

Submission status: Accepted

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

length = 0

if b <= c or d <= a:
    length = 0
elif b <= d and c <= d and a <= c:
    length = b - c
elif d <= b and a <= d and c <= a:
    length = d -a
elif b <= d and c <= a:
    length = b - a
elif d <= b and a <= c:
    length = d - c

print (length)

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

ans = 0
for a in alice:
    if a in bob:
        ans += 1
if ans != 0:
    print(ans - 1)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
w=input().split(" ")
a=int(w[0])
b=int(w[1])
c=int(w[2])
d=int(w[3])
ans=0
for t in range(100):
    sum=0
    if t>=a and t<b:
        sum+=1
    if t>=c and t<d:
        sum+=1
    if sum==2:
        ans+=1
print(ans)

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:
A, B, C, D = map(int, input().split())

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

print(0)

Submission status: Accepted

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

Submission status: Accepted

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

if a<=c:
  num1=c
  
else:
  num1=a
  
if b<=d:
  num2=b
  
else:
  num2=d
  
if num1<=num2:
  print(num2-num1)
  
else:
  print(0)

Submission status: Accepted

Solution code:
a,b,c,d=[int(i) for i in input().split()]
if b<=c or d<=a:
    print(0)
elif a<=c and b<=d:
    print(b-c)
elif a>=c and b>=d:
    print(d-a)
elif a<=c and b>=d:
    print(d-c)
else:
    print(b-a)

Submission status: Accepted

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

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

Submission status: Accepted

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

a = list(range(A,B+1))
b = list(range(C,D+1))
#print(set(a) &set(b))

x = set(a) &set(b)
if len(x) == 0 :
  print(0)
else :
  print(max(x)-min(x))

Submission status: Accepted

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

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())
ans = -1

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

for sec in AB:
    if sec in CD:
        ans += 1

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

Submission status: Accepted

Solution code:

import math
#import itertools
#import statistics
#import numpy as np
#import collections
#n = int(input())
a, b, c, d = list(map(int, input().split()))
#a = list(map(int, input().split()))
if a < c and b < c:
    print(0)
elif 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:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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(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())
if b<=c or d<=a:
    print(0)
else:
    time=[]
    time.append(a)
    time.append(b)
    time.append(c)
    time.append(d)
    time.sort()
    print(time[2]-time[1])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
############################################
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 min(B,D)-max(A,C) < 0:
  print(0)
else:
  print(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())

if A >= C:
    start = A
else:
    start = C

if B >= D:
    end = D
else:
    end = B

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7



def main():
  a,b,c,d = map(int,input().split())
  if b >= c:
    if a <= d:
      l = max(a,c)
      r = min(b,d)
      print(abs(r-l))
      exit()
    else:
      print(0)
      exit()
  else:
    print(0)
    exit()
if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

num_list = [a, b, c, d]
num_list.sort()

time = 0

if a >= d or b <= c:
    time = 0
else:
    time = num_list[-2] - num_list[1]

print("{}".format(time))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if ans != 0:
    ans = ans - 1

print(ans)

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
a,b,c,d = iim()

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

Submission status: Accepted

Solution code:
A,B,C,D=list(map(int, input().split()))
ma=min(B,D)
mi=max(A,C)
c=ma-mi
if c<0:
  c=0
print(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 = (int(x) for x in input().split())
ans1 = max(0, min(b,d) - max(a,c))
print(ans1)

Submission status: Accepted

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

if res < 0:
    res = 0

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

#print(*ans, sep='\n')

Submission status: Accepted

Solution code:
# import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # queue
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    a,b,c,d = map(int,input().split())
    ans = 0
    if a<=c:
        if b<=c: pass
        elif b>=d: ans = d - c
        else: ans = b - c
    else:
        if a>=d: pass
        elif b<=d: ans = b - a
        else: ans = d - a
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC070.B
A,B,C,D = map(int,input().split())
L1 = [A,C]
L2 = [B,D]
L1.sort()
L2.sort()
x = L2[0]-L1[1]
if x <0:
    print(0)
elif x >=0:
    print(x)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,C,D = map(int, input().split())
x=min(B,D)-max(A,C)
if x>0:
    print(x)
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 = [int(x) for x in input().split()]

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

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

simultaneously = end - start

if simultaneously > 0:
    print(simultaneously)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Sun Mar 22 23:25:40 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

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

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

list=[0]*101
#A~B秒までの要素を+1
for i in range(A[0],A[1]+1):
  list[i]+=1
#C~D秒までの要素を+1
for i in range(A[2],A[3]+1):
  list[i]+=1
if list.count(2)>=1:
  print(list.count(2)-1)
else:
  print(0)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input().split())
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:
A, B, C, D = map(int, input().split(' '))
print(max(0, min(B, D) - max(A, C)))