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 = list(map(int, input().split()))
X = max(a, c)
Y = min(b, d)
print(max(0, Y-X))

Submission status: Accepted

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

if s >= b:
  print(0)
else:
  print(b - s)

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 = [int(i) for i in input().split()]
def check(a, b, c, d):
  if b <= c or d<=a:
    return 0
  elif c<=a and a<=d and d<=b: 
    return d-a
  elif a<=c and d<=b:
    return d-c
  elif c<=a and b<=d:
    return b-a
  elif a<=c and c<= b and b<=d:
    return b-c
print(check(a,b,c,d))

Submission status: Accepted

Solution code:
A,B,C,D = [int(x) for x 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:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

def swap(s,pos):
    s[pos]-=1
    s[pos+1]+=1
    print(s)
    if pos == n-2: return s
    if s[pos+2] == 0: swap(s,pos+1)
    return s

pl = 'abcdefghijklmnopqrstuvwxyz'

#n = ip()                              #入力整数1つ
#h,w= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
a,b,c,d= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
e = set([i for i in range(a,b)])
f = set([i for i in range(c,d)])
print(len(e & f))

Submission status: Accepted

Solution code:
times = [int(x) for x in input().split()]

print(max(0, min(times[1], times[3]) - max(times[0], times[2])))

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if b <= c or d <= a: # abcd, cdab
    print(0)
elif a <= c:
    if b <= d: # acbd
        print(b-c)
    else: # acdb
        print(d-c)
else:
    if b <= d: # cabd
        print(b-a)
    else: # cadb
        print(d-a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input().split())
li =[0]*100
for i in range(a,b):
  li[i]+=1
for i in range(c,d):
  li[i]+=1
print(li.count(2))

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

Submission status: Accepted

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

print(len([i for i in range(A, B) if C <= i and i < D]))

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 += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

"""
もし B < Dなら、 C - B
もし B > Dなら、 D - B

A < x < B
と
C < x < D
の共通範囲

"""

A_B_time = []
C_D_time = []

for i in range(A,B):
    A_B_time.append(i)
for i in range(C,D):
    C_D_time.append(i)


def calc_common_range(time1, time2):
    common_range = []
    for i in time1:
        if i in time2:
            common_range.append(i)
    return common_range


print(len(calc_common_range(A_B_time, C_D_time)))

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

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
Alice=range(a,b+1)
Bob=range(c,d+1)
Alice_Bob=set(Alice)&set(Bob)
if len(Alice_Bob)!=0:
  print(len(Alice_Bob)-1)
else:
  print(0)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
l = [0] * 102

l[A] += 1
l[B] -= 1
l[C] += 1
l[D] -= 1

for i in range(1, len(l)):
    l[i] += l[i - 1]

ans = 0

for i in range(0, len(l)):
    if l[i] == 2:
        ans += 1

print(ans)

Submission status: Accepted

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

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(len(set(range(A, B+1)) & set(range(C, D+1)))-1, 0))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,D=map(int,input().split())
Alice={s for s in range(A,B+1)}
Bob={s for s in range(C,D+1)}

print(len(Alice & Bob)-1 if len(Alice & Bob)!=0 else 0)

Submission status: Accepted

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

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

if B-A + D-C <= sup - inf:
    print(0)
else:
    print(B-A+D-C - (sup - inf))

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input().split(" "))
list = [0] * 101
for j in range(A,B):
    list[j] += 1
for j in range(C,D):
    list[j] += 1
#print(list)
count = 0
for i in range(101):
    if list[i] == 2:
        count += 1
print(count)

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
A=[0 for i in range(100)]
for i in range(a,b):
  A[i]+=1
for j in range(c,d):
  A[j]+=1
print(A.count(2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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

print(s.count(2))

Submission status: Accepted

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

x = []
for i in range(A, B, 1):
  x.append(i)
y = []
for j in range(C, D, 1):
  y.append(j)
  
z = x + y

z_duplicate = [k for k in set(z) if z.count(k) > 1]
print(len(z_duplicate))

Submission status: Accepted

Solution code:
int_a, int_b, int_c, int_d = map(int,input().split())

range_a = range(int_a, int_b)
range_b = range(int_c, int_d)

print(len(set(range_a).intersection(set(range_b))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
print(max(0, len(set(range(a, b+1)) & set(range(c, d+1)))-1))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

maxi = min(b, d)
mini = max(a, c)

if maxi - mini <= 0:
    print("0")
else:
    print(maxi-mini)

Submission status: Accepted

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

if a > c:
    min = a
else:
    min = c

if b < d:
    max = b
else:
    max = d

if max - min <= 0:
    print("0")
    exit()
else:
    print(max-min)

Submission status: Accepted

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

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a, b, c, d = list(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())
start = c if a<c else a
end = b if b<d else d

print(end-start if start<end else 0)

Submission status: Accepted

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

alice = [False] * 101
bob = [False] * 101

for i in range(a,b):
    alice[i] = True

for i in range(c,d):
    bob[i] = True

ans = sum([x and y for x, y in zip(alice, bob)])
print(ans)

Submission status: Accepted

Solution code:
as1,ae,bs,be = map(int,input().split())
da = {as1:'AS',ae:'AE'}
db = {bs:'BS',be:'BE'}
order = [as1,ae,bs,be]
order.sort()
Alice = False
Bob = False
start = -1
end = -1
for t in order:
  if t in da and da[t] == 'AS':
    Alice = True
  if t in db and db[t] == 'BS':
    Bob = True
  if t in da and da[t] == 'AE':
    Alice = False
  if t in db and db[t] == 'BE':
    Bob = False
  if Alice and Bob:
    start = t
  if start != -1 and (not(Alice) or not(Bob)):
    end = t
    break
#print(str(start) + " " + str(end))
print(str(end-start))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
A,B,C,D = [int(n) for n in input().split()]
# N = int(input())
# A = [0]*N
# for i in range(N):
#     A[i] = int(input())
ans = min(B,D) - max(A,C)
print(ans if ans > 0 else 0)

Submission status: Accepted

Solution code:
a,b,c,d=(int(i) for i in input().split())
#print(a,b,c,d)
ans=0
for i in range(100+1):
  if a<i and i<=b and c<i and i<=d:
    ans+=1
    
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:
import sys
from itertools import product

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    A, B, C, D = il()
    return max(min(B, D) - max(A, C), 0)


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
lists = [0]*101
for i in range(101):
  if a<=i and i<b and c<=i and i<d:
    lists[i] = 1
print(sum(lists))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
print(max(len({i for i in range(a, b+1)} & {j for j in range(c, d+1)})-1, 0))

Submission status: Accepted

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

alice = [True if A <= i < B else False for i in range(max(B, D))]
bob = [True if C <= i < D else False for i in range(max(B, D))]

print(list(zip(alice, bob)).count((True, True)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
times = list(map(int, input().split()))
count = 0
for i in range(min(times), max(times)+1):
    if times[0] <= i < times[1] and times[2] <= i < times[3]:
        count += 1
print(count)

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-c, d-a, d-c, b-a))

Submission status: Accepted

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


abc070_b()

Submission status: Accepted

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

count=[0]*100
answer=0
for i in range(0,100):
    if (i>=a and i<b):
        count[i]+=1

    if (i>=c and i<d):
        count[i]+=1


for i in range(0,100):
    if count[i]==2:
        answer+=1


print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if A > C:
    A, C = C, A
    B, D = D, B

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max(0,up-lo))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split(" "))
if A < C:
  one = [A, B]
  two = [C, D]
else:
  two = [A, B]
  one = [C, D]
if one[1] < two[0]:
  print(0)
  exit(0)
if one[1] >= two[1]:
  print(two[1] - two[0])
  exit(0)
if one[1] < two[1]:
  print(one[1] - two[0])
  exit(0)

Submission status: Accepted

Solution code:
import collections as cl

A,B,C,D = [int(i) for i in input().split()]
arr = [0]*100

for i in range(A,B) :
    arr[i] += 1

for i in range(C,D) :
    arr[i] += 1

c = cl.Counter(arr)
print(c[2])

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
A=a[0]
B=a[1]
C=a[2]
D=a[3]
yeah=max(A,C)
yipee=min(B,D)
if yeah >= yipee:
    print("0")
else:
    print(str(yipee-yeah))

Submission status: Accepted

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

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

result = max(e - s, 0)

print(result)

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input().split())
counter = 0
for num1 in range(A,B):
    for num2 in range(C,D):
        if num1 == num2:
            counter += 1
print(counter)
#go

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a=input().strip().split(" ")
a=[int(i) for i in a]

b=[]
c=[]

b.append(a[0])
b.append(a[2])

c.append(a[1])
c.append(a[3])

b.sort()
c.sort()

Sum=c[0]-b[1]

if(Sum<=0):
    print("0")
else:
    print(Sum)

Submission status: Accepted

Solution code:
A, B, C, D = map(int, raw_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())
a_b = [i for i in range(a, b+1)]
c_d = [i for i in range(c, d+1)]
counter = -1
flg = "False"

for i in range(len(a_b)):
  for j in range(len(c_d)):
    if a_b[i] == c_d[j]:
      counter += 1
      flg = "True"

if flg == "True":
  print(counter)
else:
  print(0)

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

Submission status: Accepted

Solution code:
A_start, A_stop, B_start, B_stop = map(int, input().split())
if A_start <= B_start:
    if A_stop <= B_start:
        time = 0
    elif (A_stop > B_start) & (A_stop <= B_stop):
        time = A_stop - B_start
    else:
        time = B_stop - B_start
else:
    if B_stop <= A_start:
        time = 0
    elif (B_stop > A_start) & (B_stop <= A_stop):
        time = B_stop - A_start
    else:
        time = A_stop - A_start
print(time)

Submission status: Accepted

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

Submission status: Accepted

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

list_alice = []
for i in range(a, b):
  list_alice.append(i)
  
list_bob = []
for i in range(c, d):
  list_bob.append(i)

print(len(list(set(list_alice) & set(list_bob))))

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

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 = [ int(i) for i in input().split() ]
c = 0
for i in range(101):
    if A <= i < B and C <= i < D:
        c += 1
print(c)

Submission status: Accepted

Solution code:
inputList = list(map(int, input().split(' ')))
A = inputList[0]
B = inputList[1]
C = inputList[2]
D = inputList[3]
answer = 0
if D <= A:
    answer = 0
elif C <= A <= D <= B:
    answer = (D-A)
elif C <= A and B <= D:
    answer = (B-A)
elif A <= C and D <= B:
    answer = (D-C)
elif A <= C <= B <= D:
    answer = (B-C)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

ab = [str(x) for x in range(a, b+1)]

cd = [str(x) for x in range(c, d+1)]

set_abcd = set(ab) & set(cd)

if len(set_abcd) <= 0:
	print(0)
else:
	print(len(set_abcd) - 1)

Submission status: Accepted

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

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

if upper < lower:
  print('0')
else:
  print(upper - lower)

Submission status: Accepted

Solution code:
T = [int(i) for i in input().split()]
if T[0] >= T[3] or T[2] >= T[1]:
  print(0)
elif T[0] >= T[2]:
  print(min(T[3] - T[0], T[1] - T[0]))
elif T[2] >= T[0]:
  print(min(T[3] - T[2], T[1] - T[2]))

Submission status: Accepted

Solution code:
ali1, ali2, bob1, bob2 = map(int, input().split())

if ali1 <= bob1 <= ali2: 
    if ali1 <= bob2 <= ali2:
        print(bob2 -bob1)
    else:
        print(ali2 - bob1)
elif bob1 <= ali1 <=bob2:
    if bob1 <= ali2 <= bob2:
        print(ali2 - ali1)
    else:
        print(bob2 - ali1)
else:
    print(0)

Submission status: Accepted

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

    if c <= a < b <= d:
        return b - a

    if a <= c < d <= b:
        return d - c

    if a <= c < b <= d:
        return b - c

    if c <= a < d <= b:
        return d - a

    if b <= c or d <= a:
        return 0


if __name__ == '__main__':
    print(abc070_b())

Submission status: Accepted

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

Submission status: Accepted

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

e = max(e)
f = min(f)

if (f-e) >= 0:
  print(f-e)
else:
  print(0)

Submission status: Accepted

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

if A < C:
    if B - C > 0:
        print(min(B - C, B - A, D - C))
    else:
        print("0")
elif C < A:
    if D - A > 0:
        print(min(D - A, B - A, D - C))
    else:
        print("0")
else:
    print(min(B - A, D - C))

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
t_start = max(a[0], a[2])
t_stop = min(a[1], a[3])
t = t_stop-t_start
if t > 0:
    print(t)
else :
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
x, y = sorted([(a, b), (c, d)])
if x[1] <= y[0]:
    print(0)
else:
    print(min(y[1], x[1]) - y[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 = list(map(int, input().split()))
alice = 0
bob = 0
ans = 0
for i in range(0, 101):
    if i == a[0]:
        alice = 1
    if i == a[1]:
        alice = 0
    if i == a[2]:
        bob = 1
    if i == a[3]:
        bob = 0

    ans += alice * bob
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, C, D = list(map(int, input().rstrip().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(' '))

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

Submission status: Accepted

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

def between_time(before, after):
  diff = after - before
  if diff > 0:
    return diff
  else:
    return 0
  
if a > c:
  start = a
else:
  start = c

if b > d:
  fin = d
else:
  fin = b

print(between_time(start, fin))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input().split())
m = [0]*102
m[a] += 1
m[b] -= 1
m[c] += 1
m[d] -= 1
for i in range(1,102):
    m[i] += m[i-1]
print(m.count(2))

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
a,b,c,d = map(int, input().split())

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, d = list(map(int, input().rstrip().split()))
time = []
t_max = max([b, d])
for t in range(t_max + 1):
    if a <= t <= b:
        flag_alice = 1
    else:
        flag_alice = 0
    if c <= t <= d:
        flag_bob = 1
    else:
        flag_bob = 0
    time.append([flag_alice, flag_bob])
switch = 0
for t in time:
    if t == [1, 1]:
        switch += 1
if switch > 0:
    switch -= 1
print(switch)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


def main() -> int:
    a = next_int()
    b = next_int()
    c = next_int()
    d = next_int()

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


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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