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

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

Submission status: Accepted

Solution code:
from sys import stdin

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

start = a if a >= c else c
end = b if b <= d else d

print((end - start) if end >= start else 0)

Submission status: Accepted

Solution code:
a = list(input().split())

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

if max(b,d) < min(c,e):
    print(min(c,e)-max(b,d))       

elif max(b,d)>=min(c,e):
        print(0)

Submission status: Accepted

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

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())
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())
alice = set(list(range(A,B+1)))
bob = set(list(range(C,D+1)))
if list(alice&bob) == []:
    print(0)
else:
    print(len(alice&bob)-1)

Submission status: Accepted

Solution code:
a_start, a_end, b_start, b_end = map(int, input().rstrip("\n").split())

if a_end < b_start or b_end < a_start:
    print(0)
else:
    print(min(a_end, b_end) - max(a_start, b_start))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    a, b, c, d = list(map(int, input().rstrip('\n').split()))
    if b < c:
        print(0)
    elif d < a:
        print(0)
    else:
        print(min(b, d) - max(a, c))


if __name__ == '__main__':
    solve()

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(lambda x: int(x), 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())
print(max(-max(A,C)+min(B,D),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())
print(max(min(b,d)-max(a,c),0))

Submission status: Accepted

Solution code:
#Two switches B

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

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

print(max(0,end-start))

Submission status: Accepted

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

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

ans = e - s
print(ans if ans > 0 else 0)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d = list(map(int, input().rstrip('\n').split()))
    if b < c or d < a:
        print(0)
    else:
        print(min(b, d) - max(a, c))


if __name__ == '__main__':
    slove()

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())
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 a >= d:
  print(0)
elif d >= b > c and a <= c:
  print(b-c)
elif b >= d > a and c <= a:
  print(d-a)
else:
  print(min(b-a, d-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:
def main():
    a,b,c,d=map(int,input().split(' '))
    ans = 0
    alice=[1 if a<=i<b else 0 for i in range(100)]
    bob=[1 if c<=i<d else 0 for i in range(100)]
    for i,j in zip(alice,bob):
        if i+j ==2:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
if a[1] <= a[2]:
  print(0)
  exit()
elif a[0]<=a[2] and a[2] <= a[1] and a[1]<=a[3]:
  print(a[1]-a[2])
  exit()
elif a[0]<=a[2] and a[3]<=a[1]:
  print(a[3]-a[2])
  exit()
elif a[2]<=a[0] and a[1]<=a[3]:
  print(a[1]-a[0])
  exit()
elif a[2]<=a[0] and a[0] <= a[3] and a[3]<=a[1]:
  print(a[3]-a[0])
  exit()
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 slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d = list(map(int, input().rstrip('\n').split()))
    if b <= c or d <= a:
        print(0)
    else:
        print(abs(min(d, b) - max(c, a)))


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

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

if B<=D:
  end=B
else:
  end=D

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

Submission status: Accepted

Solution code:
import os

a,b,c,d = (int(x) for x in input().split())
ans = 0

for i in range(max(a,c),min(b,d)):
    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
for i in range(0, 101):
  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:



def main():


    a,b,c,d = map(int,input().split())
    if b <= c or d <= a : print(0);exit()
    print(min(b,d)-max(a,c))
        



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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:
# ABC070 B - Two Switches
a,b,c,d = map(int,input().split())

ans = 0
Alice = False
Bob = False

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


ans = 0

for i in alice:
    if i in bob:
        ans += 1

print(ans)

Submission status: Accepted

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

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

# solve & output
print(max(0, min(B, D) - max(A, C)))

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
over = set(range(a, b)) & set(range(c, d))
print(len(over))

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())
res = 0
for i in range(101):
  if a <= i < b and c <= i < d:
    res += 1
print(res)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
A,B,C,D=map(int,input().split())
if B<C or D<A:
  print(0)
else:
  Min = max([A,C])
  Max=min([B,D])
  print(Max-Min)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8

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

Submission status: Accepted

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

alice = set(range(A,B+1))
bob = set(range(C,D+1))

res = len(alice & bob)
print(res - 1 if res else 0)

Submission status: Accepted

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

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

elif A<=C and B>=C and B<=D:
  ans = B-C
else:
  ans = D-A
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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())
start = max(a, c)
stop = min(b, d)
val = stop - start

if val <= 0:
    print(0)
elif val > 0:
    print(val)

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
 
a,b,c,d = na()

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

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


A, B, C, D = map(int, sys.stdin.readline().split())

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    a,b,c,d=map(int,input().split())
    print(max(0,min(d,b)-max(a,c)))
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

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

left = max(a, c)
right = min(b, d)

print(max(right - left, 0))

Submission status: Accepted

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

if C <= A:
    if D <= A:
        result = 0
    elif A <= D and D <= B:
        result = D - A
    else:
        result = B - A
elif A <= C and C <= B:
    if D <= B:
        result = D - C
    else:
        result = B - C
else:
    result = 0

print(result)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans=[0]*101
for i in range(a,b):
    ans[i]+=1
for i in range(c,d):
    ans[i]+=1
    
kai=0
for i in range(101):
    if ans[i]==2:
        kai+=1
print(kai)

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

start = C if A < C else A
end = B if B < D else D
ans = 0 if start > end else end - start
print(ans)

Submission status: Accepted

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

start = max(a, c)
end = min(b, d)
time = 0
if start < end:
    time = end - start

print(time)

Submission status: Accepted

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

Alice_list = []
Bob_list = []

def fill_list(AB_list, starting, ending):
    for idx in range(101):
        if idx < starting:
            AB_list.append(0)
        elif starting <= idx < ending:
            AB_list.append(1)
        else:
            AB_list.append(0)

fill_list(Alice_list, A, B)
fill_list(Bob_list, C, D)

print([x+y for (x,y) in zip(Alice_list,Bob_list)].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 print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,C,D = map(int, input().split())
Alice = [0]*(A) + [1]*(B-A) + [0]*(101-B)
Bob = [0]*(C) + [1]*(D-C) + [0]*(101-D)
print(sum([i*j for i,j in zip(Alice,Bob)]))

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split());print(max(0,min(b-a,d-a,b-c,d-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())
count = 0
for i in range(max(a, c), min(b, d)):
    count += 1
print(count)

Submission status: Accepted

Solution code:


def min(a, b):
	if a > b:
		return b
	else:
		return a

def max(a, b):
	if a > b:
		return a
	else:
		return b



def main():
	linie = input()
	vector = [int(x) for x in linie.split()]
	time = (-1) * (max(vector[2], vector[0]) - min(vector[1], vector[3]))
	if time < 0:
		print(0)
	else:
		print(time)




if __name__ == "__main__":
	main()

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

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


s=0
e=0

if a > d or b < c:
    print(0)
    exit()

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

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

print(e-s)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = input().split()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])

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

Submission status: Accepted

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

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

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

ans = end - start

if ans < 0:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:


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

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

Submission status: Accepted

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

start = 0
end = 0

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

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

time = end-start

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

Submission status: Accepted

Solution code:
# coding: utf-8
A, B, C, D = map(int, input().split())
time = [0 for i in range(100)]
for i in range(A, B):
    time[i] += 1
for i in range(C, D):
    time[i] += 1
ans = 0
for i in range(len(time)):
    if time[i] == 2:
        ans += 1
print(ans)

Submission status: Accepted

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

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

if A < C:
    start = C
else:
    start = A

if B < D:
    end = B
else:
    end = D

answer = end - start
if answer > 0:
    print(answer)
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-1 and c<=i<=d-1:
        ans+=1
print(ans)

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().strip().split(' '))
print(max(0, min(b,d) - max(a,c)))

Submission status: Accepted

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

if n[1] < n[2]:
    print(0)
elif n[3] < n[0]:
    print(0)
else:
    m = sorted(n)
    print(m[2]-m[1])

Submission status: Accepted

Solution code:
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

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

Submission status: Accepted

Solution code:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

Submission status: Accepted

Solution code:
# ABC070b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

Submission status: Accepted

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

import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

Solution code:
#ABC 070 B Two Switches

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

if a <= c:
    kaishi = c
else:
    kaishi = a
    
if b <= d:
    shuryo = b
else:
    shuryo = d

if kaishi > shuryo:
    print(0)
else:
    print(shuryo - kaishi)

Submission status: Accepted

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


if __name__ == "__main__":
    test()

Submission status: Accepted

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

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

else:
    base1 = max([a,c])
    base2 = min([b,d])
    print(base2-base1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

result = 0

if B <= C or D <= A:
    print(result)
    exit()
if A <= C :
    if B >= D:
        result = D-C
    if B < D:
        result = B-C
if A > C:
    if B >=D:
        result = D-A
    if B <D:
        result = B-A

print(result)

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())
arr=[0]*101

for i in range(0,101):
    if i>=A and i<=B:
        arr[i]+=1
    if i>=C and i<=D:
        arr[i]+=1
ans=arr.count(2)
print(ans-1 if ans>1 else 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())
if b <= c or d <= a:
  print(0)
else:
  print(min(b,d)-max(a,c))

Submission status: Accepted

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

start_time = max(a, c)
stop_time = min(b, d)

if start_time > stop_time:
    print(0)
else:
    print(stop_time - start_time)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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