AtCoder Beginner Contest 070 - Two Switches

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-----
0 75 25 100

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


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


def main():
	(A, B, C, D) = list(map(int, input().split()))
	if D <= A or B <= C:
		ans = 0
	if C <= A and A <= D:
		ans = D - A
	if C <= B and B <= D:
		ans = B - C
	if A <= C and D <= B:
		ans = D - C
	if C <= A and B <= D:
		ans = B - A
	print(ans)

def __starting_point():
	main()
__starting_point()


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


(A, B, C, D) = list(map(int, input().split(' ')))
print(max(min(B, D) - max(A, C), 0))


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


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


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


a = list(map(int, input().split()))
print(max([min(a[1::2]) - max(a[::2]), 0]))


A = list(map(int, input().split()))
print(str(max(min(A[1], A[3]) - max(A[0], A[2]), 0)))


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


(a, b, c, d) = list(map(int, input().split()))
ans = 0
for i in range(201):
	if a <= i < b and c <= i < d:
		ans += 1
print(ans)


(A, B, C, D) = list(map(int, input().split()))
mint = max(A, C)
maxt = min(B, D)
dt = max(0, maxt - mint)
print(dt)


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


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


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


(A, B, C, D) = [int(t) for t in input().split()]
t = min(B, D) - max(A, C)
print(max(0, t))


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


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


(A, B, C, D) = map(int, input().split())
st = max(A, C)
gl = min(B, D)
print(max(gl - st, 0))


(a, b, c, d) = (int(x) for x in input().split())
if a <= c <= b:
	if d <= b:
		print(d - c)
	else:
		print(b - c)
elif c <= a:
	if b <= d:
		print(b - a)
	elif a <= d <= b:
		print(d - a)
	else:
		print(0)
else:
	print(0)


url = 'https://atcoder.jp//contests/abc070/tasks/abc070_b'

def main():
	t = list(map(int, input().split()))
	start = max(t[0], t[2])
	end = min(t[1], t[3])
	if end >= start:
		print(end - start)
	else:
		print(0)

def __starting_point():
	main()
__starting_point()


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


(A, B, C, D) = map(int, input().split())
start = max(A, C)
end = min(B, D)
print(end - start if end - start > 0 else 0)


def answer(a: int, b: int, c: int, d: int) -> int:
	return len(set(range(a, b)) & set(range(c, d)))

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

def __starting_point():
	main()
__starting_point()


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

def __starting_point():
	main()
__starting_point()


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


(a, b, c, d) = map(int, input().split())
print(sum((1 for i in range(0, 101) if a <= i < b and c <= i < d)))


import re
import copy

def accept_input():
	(ast, aen, bst, ben) = list(map(int, input().split()))
	return (ast, aen, bst, ben)

def process(s):
	if s == '#':
		return 1
	else:
		return 0
(ast, aen, bst, ben) = accept_input()
if ast >= bst and ast <= ben:
	print(min(ben, aen) - ast)
elif ast < bst:
	if aen < bst:
		print(0)
	else:
		print(min(aen, ben) - bst)
else:
	print(0)


(a, b, c, d) = map(int, input().split())
x = set(range(a, b)) & set(range(c, d))
print(len(x))


(A, B, C, D) = list(map(int, input().split()))
ali = '0' * 101
bob = '0' * 101
ali = ali[:A] + '1' * (B - A) + ali[B + 1:]
bob = bob[:C] + '1' * (D - C) + bob[D + 1:]
ans = int(ali, 2) & int(bob, 2)
print(bin(ans).count('1'))


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


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


(A, B, C, D) = map(int, input().split())
print(len(set(range(A + 1, B + 1)) & set(range(C + 1, D + 1))))


(a, b, c, d) = map(int, input().split())
alice = set((i for i in range(a, b + 1)))
bob = set((j for j in range(c, d + 1)))
s = alice & bob
print(max(len(alice & bob) - 1, 0))


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


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


(a, b, c, d) = tuple(map(lambda x: int(x), input().split(' ')))
start = max(a, c)
end = min(b, d)
print(max(end - start, 0))


(A, B, C, D) = list(map(int, input().split()))
alice = [1 if A <= t < B else 0 for t in range(0, 110)]
bob = [1 if C <= t < D else 0 for t in range(0, 110)]
overlap = [1 for (a, b) in zip(alice, bob) if a > 0 and b > 0]
print(len(overlap))


(A, B, C, D) = map(int, input().split())
if B <= C or D <= A:
	print(0)
else:
	min_n = max(A, C)
	max_n = min(B, D)
	print(max_n - min_n)


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


def answer(a: int, b: int, c: int, d: int) -> int:
	return max(0, min(b, d) - max(a, c))

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

def __starting_point():
	main()
__starting_point()


l = list(map(int, input().split()))
print(max(0, min(l[1], l[3]) - max(l[0], l[2])))


(a, b, c, d) = list(map(int, input().split()))
x = [0] * 101
cnt = 0
for i in range(a, b + 1):
	x[i] = 1
for i in range(c, d + 1):
	if x[i] == 1:
		cnt += 1
if cnt == 0:
	print(cnt)
else:
	print(cnt - 1)


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


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


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


a = [int(x) for x in input().split()]
print(max(0, min(a[1], a[3]) - max(a[0], a[2])))


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


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


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


(A, B, C, D) = map(int, input().split())
if C < A and D <= A or (B <= C and C < D):
	time = 0
elif A <= C and D <= B:
	time = D - C
elif C <= A and B <= D:
	time = B - A
elif C <= A and D <= B:
	time = D - A
elif A <= C and B <= D:
	time = B - C
print(time)


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


lst = input().split()
A = int(lst[0])
B = int(lst[1])
C = int(lst[2])
D = int(lst[3])
if B <= C or D <= A:
	print(0)
elif A <= C <= B and C <= B <= D:
	print(B - C)
elif C <= A <= D and A <= D <= B:
	print(D - A)
else:
	print(min([B - A, D - C]))


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


(a, b, c, d) = map(int, input().split())
s1 = set(range(a, b))
s2 = set(range(c, d))
print(len(s1 & s2))


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


with open(0) as f:
	(a, b, c, d) = map(int, f.read().split())
f = lambda x: 0 if x < 0 else x
print(f(min(b, d) - max(a, c)))


l = list(map(int, input().split()))
ans = min(l[1], l[3]) - max(l[0], l[2])
print(ans if ans > 0 else 0)


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


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


(A, B, C, D) = map(int, input().split())
L = max(A, C)
R = min(B, D)
print(max(0, R - L))


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


(a, b, c, d) = (int(x) for x in input().split())
ans1 = max(0, min(b, d) - max(a, c))
print(ans1)


(a1, a2, b1, b2) = map(int, input().split())
print(max(min(a2, b2) - max(b1, a1), 0))


(A, B, C, D) = map(int, input().split())
if A > D or B < C:
	print(0)
	return
if C > A:
	A = C
if D < B:
	B = D
print(B - A)


(A, B, C, D) = map(int, input().split())
lower = max(A, C)
upper = min(B, D)
print(max(upper - lower, 0))


(A, B, C, D) = [int(i) for i in input().split()]
t1 = max(A, C)
t2 = min(B, D)
print(max(0, t2 - t1))


a = list(map(int, input().split()))
n = min(a[1], a[3]) - max(a[0], a[2])
print(n if n > 0 else 0)


import sys

def IS():
	return sys.stdin.readline().rstrip()

def II():
	return int(IS())

def MII():
	return list(map(int, IS().split()))

def MIIZ():
	return list(map(lambda x: x - 1, MII()))

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

def __starting_point():
	main()
__starting_point()


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


(A, B, C, D) = map(int, input().split())
start = max(A, C)
end = min(B, D)
ans = max(end - start, 0)
print(ans)


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


LI = lambda : list(map(int, input().split()))
(A, B, C, D) = LI()

def main():
	x = max(A, C)
	y = min(B, D)
	ans = max(0, y - x)
	print(ans)

def __starting_point():
	main()
__starting_point()


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

def __starting_point():
	main()
__starting_point()


(A, B, C, D) = map(int, input().split())
a = list(range(A, B))
b = list(range(C, D))
a_b_and = set(a) & set(b)
print(len(a_b_and))


import numpy as np
(A, B, C, D) = map(int, input().split())
a = [0 for _ in range(100)]
b = [0 for _ in range(100)]
a[A:B] = [1 for _ in range(B - A)]
b[C:D] = [1 for _ in range(D - C)]
c = np.array(a) * np.array(b)
print(c.sum())


import math
import numpy as np
import sys
import os
from operator import mul
sys.setrecursionlimit(10 ** 7)

def _S():
	return sys.stdin.readline().rstrip()

def I():
	return int(_S())

def LS():
	return list(_S().split())

def LI():
	return list(map(int, LS()))
if os.getenv('LOCAL'):
	inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0] + '.txt'
	sys.stdin = open(inputFile, 'r')
INF = float('inf')
IINF = 10 ** 18
MOD = 10 ** 9 + 7
(A, B, C, D) = LI()
if B <= C or D <= A:
	ans = 0
elif C <= A and B <= D:
	ans = B - A
elif A <= C and D <= B:
	ans = D - C
elif A <= C and B <= D:
	ans = B - C
elif C <= A and D <= B:
	ans = D - A
else:
	ans = 'error'
print(ans)


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


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


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


(A, B, C, D) = map(int, input().split())
l = max(A, C)
r = min(B, D)
print(0 if r - l < 0 else r - l)


t = [0] * 101
(a, b, c, d) = list(map(int, input().split()))
for i in range(a, b):
	t[i] += 1
for j in range(c, d):
	t[j] += 1
print(t.count(2))


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


(A, B, C, D) = map(int, input().split())
X = set([i for i in range(A, B)])
print(sum([1 for i in range(C, D) if i in X]))


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


(A, B, C, D) = list(map(int, input().split()))
bottom = max(A, C)
top = min(B, D)
if top - bottom > 0:
	print(top - bottom)
else:
	print(0)


(A, B, C, D) = [int(i) for i in input().split()]
ans = max(min(B, D) - max(A, C), 0)
print(ans)


(A, B, C, D) = map(int, input().split())
stt = max(A, C)
end = min(B, D)
print(max(end - stt, 0))