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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if a > c:
    a, c = c, a
    b, d = d, b

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

print(ans)

Submission status: Accepted

Solution code:
A,B,C,D = map(int, input().rstrip().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())
As = [i for i in range(a, (b + 1))]
Bs = [i for i in range(c, (d + 1))]

ans = []
for A in As:
    for B in Bs:
        if A == B:
            ans.append(A)
if ans:
    print(ans[-1] - ans[0])
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(s,0))

Submission status: Accepted

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


def solve(A: int, B: int, C: int, D: int):
    print(len(set(range(A, B)) & set(range(C, D))))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,c,d = list(map(int,input().split()))
m1 = min(a,b)
m2 = min(c,d) 
m3 = max(a,b)
m4 = max(c,d) 

x = m1 if m1 > m2 else m2
y = m3 if m3 < m4 else m4
print(y-x if y-x > 0 else 0)

Submission status: Accepted

Solution code:
a,b,c,d = [int(x) for x in 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:
    st = c
else:
    st = a

if b < d:
    ed = b
else:
    ed = d

if st < ed:
    print(ed-st)
else:
    print(0)

Submission status: Accepted

Solution code:
#abc070 b 
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())
ab = [ 1 if a<= i and i < b else 0 for i in range(100)]
cd = [ 1 if c<= i and i < d else 0 for i in range(100)]
cnt = 0

for i in range(100):
    if ab[i] == 1 and cd[i] == 1:
        cnt += 1

print(cnt)

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:
A, B, C, D = [int(i) for i in input().split()]

if A < C:
    start_time = C
else :
    start_time = A

if B > D:
    stop_time = D
else :
    stop_time = B
    

if stop_time-start_time <= 0:
    print(0)
else :
    print(stop_time-start_time)

Submission status: Accepted

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

l, r = max(a, c), min(b, d)

print(max(0, r - l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():

    A,B,C,D=map(int,input().split())
    val=len(set(range(A,B+1)) & set(range(C,D+1)))
    print(val-1 if val>0 else 0)

resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
## coding: UTF-8
s = input().split()
t = [int(p) for p in s]
#print(t)

'''
#print(max(t))
count = 0
for i in range(1, max(t)+1):
    if(t[0] < i and i <= t[1] and t[2] < i and i <= t[3]):
        count += 1
print(count)
'''

start = max(t[0], t[2])
goal = min(t[1], t[3])
time = max(0, goal - start)
#print(start)
#print(goal)
print(time)

Submission status: Accepted

Solution code:
## coding: UTF-8
s = input().split()
t = [int(p) for p in s]
#print(t)

#print(max(t))
count = 0
for i in range(1, max(t)+1):
    if(t[0] < i and i <= t[1] and t[2] < i and i <= t[3]):
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
fromA, toA, fromB, toB = map(int, input().split())

if fromA >= fromB:
  st = fromA
else:
  st = fromB
  
if toA <= toB:
  ed = toA
else:
  ed = toB

ret = ed - st
if ret < 0:
  ret = 0

print(ret)

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

Submission status: Accepted

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

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

for i in range(101):
	if a[0]<=i and a[1]>=i and a[2]<=i and a[3]>=i:
		x=x+1
if x==0:
	print(0)
else:
	print(x-1)

Submission status: Accepted

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

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:
import sys
input = sys.stdin.readline

A, B, C, D = map(int, input().split(' '))
min_bd = min(B, D)
max_ac = max(A, C)
diff = min_bd - max_ac
ans = 0
if diff > 0:
    ans = abs(diff)
print(ans)

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:
import sys
input = sys.stdin.readline

A, B, C, D = map(int, input().split(' '))
a_switch = set()
b_switch = set()
for i in range(A+1, B+1):
    a_switch.add(i)
for i in range(C+1, D+1):
    b_switch.add(i)
ans = len(a_switch & b_switch)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def resolve():
    ap, ar, bp, br = map(int, input().split())

    if ar <= bp or br <= ap:
        return print(0)
    else:
        u = max(ap, bp)
        o = min(ar, br)
        ans = o - u
        print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    a,b,c,d=MI()
    s=max(a,c)
    t=min(b,d)
    print(max(0,t-s))

main()

Submission status: Accepted

Solution code:
#070_B
a,b,c,d=map(int,input().split())
alice=set(range(a,b))
bob=set(range(c,d))
print(len(alice&bob))

Submission status: Accepted

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

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

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

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 alice & bob:
    print(len(alice & bob)-1)

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
#ABC070

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

Submission status: Accepted

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

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:
a, b, c, d = list(map(int, input().split(' ')))

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

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

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

Submission status: Accepted

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

z = len(x+y) - len(set(x+y))
if z == 0:
    print(0)
else:
    print(z-1)

Submission status: Accepted

Solution code:
# coding: utf-8

(a,b,c,d) = map(int, input().rstrip().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())


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x = list(map(int, input().split()))
imos = [0]*(max(x) + 2)
imos[x[0]] += 1
imos[x[1]+1] -= 1
imos[x[2]] += 1
imos[x[3]+1] -= 1
for i in range(len(imos)-1):
    imos[i+1] += imos[i]
print(max(imos.count(2) - 1, 0))

Submission status: Accepted

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

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

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

if upper >= lower:
    print(upper - lower)
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 (d >= b and c <= a) or (b >= d and a <= c):
    print(min(d - c, b - a))
elif b >= d:
    print(d - a)
else:
    print(b - c)

Submission status: Accepted

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

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

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(max(0, q-1))

Submission status: Accepted

Solution code:
a, b, c, d = (int(i) for i in input().split(" "))
alice_times = set([i for i in range(a, b + 1)])
bob_times = set([i for i in range(c, d + 1)])

if len(set(alice_times & bob_times)) > 0:
    print(len(set(alice_times & bob_times)) - 1)
else:
    print(0)

Submission status: Accepted

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

if(b>=d):
    e=d
else:
    e=b

if (e-s)<0:
    print(0)
else:
    print(e-s)

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

Submission status: Accepted

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

#----------
A,B,C,D = list(map(int, input().rstrip().split()))
#----------
time_start = max(A,C)
time_end = min(B,D)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans=0
for i in range(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())
if b<=c or d<=a:
    print(0)
else:
    print(min(d,b)-max(a,c))

Submission status: Accepted

Solution code:
def twoswiches(a , b , c , d):

    ans = min(b , d) - max(a , c)
    return ans if ans > 0 else 0

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, D = [int(x) for x in input().split()]
a = set(range(A, B))
b = set(range(C, D))
print(len(a & b))

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

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

r = max(0, end - start)
print(int(r))

Submission status: Accepted

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

Start=[A,C]
End=[B,D]

Start.sort()
End.sort()

print(max(0,End[0]-Start[1]))

Submission status: Accepted

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

max_min = max(a, c)
min_max = min(b, d)

if min_max - max_min > 0:
  print(min_max - max_min)
else:
  print(0)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,C,D = map(int, input().split())
A2B = set(range(A,B+1))
C2B = set(range(C,D+1))
tmp = list(A2B&C2B)
tmp.sort()
print(0) if len(tmp)==0 else print(tmp[-1] - tmp[0])

Submission status: Accepted

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

if A >= C:
    if D >= B:
        ans = B - A
    else:
        ans = D - A
elif C > A:
    if D >= B:
        ans = B - C
    else:
        ans = D - C

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
als, ale, bs, be = map(int, input().split())
s = max(als, bs)
e = min(ale, be)
ans = e-s
if ans < 0:
  print(0)
else:
  print(ans)

Submission status: Accepted

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

x = [i for i in range(a, b)]
y = [i for i in range(c, d)]
s = 0
for i in x:
    if i in y:
        s += 1
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Alice = set([])
Bob = set([])

for i in range(A, B + 1):
  Alice.add(i)
for i in range(C, D + 1):
  Bob.add(i)

ans = Alice & Bob
ans = list(ans)
if len(ans) == 0:
  print(0)
  exit()
print(ans[-1] - ans[0])

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
if a >= d or c >= b:
	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:
  x=set([i for i in range(a,b)])
  y=set([i for i in range(c,d)])
  z= x & y
  print(len(z))

Submission status: Accepted

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

max_t = max(a, c)
min_t = min(b, d)

print(max(min_t-max_t, 0))

Submission status: Accepted

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

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:
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())
A = set([i for i in range(a,b+1)])
B = set([i for i in range(c,d+1)])

print(len(A&B) if len(A&B)==0 else len(A&B)-1)

Submission status: Accepted

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

a_b = set(range(a,b))
c_d = set(range(c,d))

time = a_b & c_d

print(len(time))

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(A: int, B: int, C: int, D: int):
    print(max(0, min(B,D)-max(A,C)))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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()]
s=a if a>c else c
e=b if b<d else d
print(e-s if e>s else 0)

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
l = [i for i in range(A, B)] + [i for i in range(C, D)]
result = [i for i in set(l) if l.count(i) > 1]
print(len(result))

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

start = max(A, C)
end = min(B, D)
ans = max(0, end - start)
print(ans)

Submission status: Accepted

Solution code:
import math
import calendar
import fractions
import itertools

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())

A,B,C,D = splitintinput()
if B <= C 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())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
P = [0 for _ in range(102)]
for p in range(A, B): P[p] += 1
for p in range(C, D): P[p] += 1
count = 0
for p in P:
  if p == 2: count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if a_start < b_start:
    f_start, f_end = a_start, a_end
    s_start, s_end = b_start, b_end
else:
    f_start, f_end = b_start, b_end
    s_start, s_end = a_start, a_end

overlap_time = 0
if f_end <= s_start:
    overlap_time = 0
elif s_start < f_end and s_end < f_end:
    overlap_time = s_end - s_start
else:
    overlap_time = f_end - s_start

print(overlap_time)

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c,d=INTM()
    ct=min(b,d)-max(a,c)
    print(max(0,ct))
if __name__ == '__main__':
    do()

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

Submission status: Accepted

Solution code:
# 要復習
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    a,b,c,d = MAP()
    
    if min(b, d) - max(a, c) >= 0:
        print(min(b, d) - max(a, c))
    else:
        print(0)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

t = [0]*101
for i in range(a, b):
    t[i] += 1

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

ans = 0
for _t in t:
    if _t == 2:
        ans += 1
print(ans)