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

alice = set([num for num in range(A, B + 1)])
bob = set([num for num in range(C, D + 1)])

if len(alice & bob) == 0:
    print("0")
else:
    print(max(alice & bob) - min(alice & bob))

Submission status: Accepted

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

x = max(a,c)
y = min(b,d)

res = y-x

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

low=[a,c]
high=[b,d]
print(0 if max(low)>min(high) else min(high)-max(low))

Submission status: Accepted

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

Submission status: Accepted

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

if A >= C:
    temp_max = A
else:
    temp_max = C
if B <= D:
    temp_min = B
else:
    temp_min = D


ans = temp_min-temp_max
if ans >=0:
    print(ans)
else:
    print("0")

Submission status: Accepted

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

la=[a,c]
lb=[b,d]
if(max(la)>min(lb)):
    print(0)
else:
    print(min(lb)-max(la))

Submission status: Accepted

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

a = 0
b = min(s[1::2]) - max(s[::2])

if(b > 0):
    a = b

print(a)

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
alice = set([i for i in range(A, B)])
bob = set([i for i in range(C, D)])
print(-len(alice | bob)+len(alice)+len(bob))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(sum(map(lambda x: x[0]*x[1], zip(alice, bob))))

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

ans = 0 if b < c or d < a else end - start



print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if(b<=c or d<=a):
    print("0")
    sys.exit()
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:
a, b, c, d = raw_input().split(' ');time= int(min(int(b), int(d))) - int(max(int(a), int(c)));print(time if time>0 else 0)

Submission status: Accepted

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

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:
#!/usr/bin/env python

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list = input().split()
a = int(list[0])
b = int(list[1])
c = int(list[2])
d = int(list[3])
result = 0
if a < b and c < d:
    if (a >= c and b <= d) or (a <= c and b >= d):
        result = min(b-a,d-c)
    elif a <= c and c <= b:
        result = b - c
    elif c <= a and a <= d:
        result =  d - a
print(result)

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:
def solve():
    A, B, C, D = list(map(int, input().split()))
    ans = min(B,D) - max(A,C)
    if ans < 0:
        ans = 0
    print(ans)
    
solve()

Submission status: Accepted

Solution code:
# coding: utf-8
line = input().rstrip().split()

A = int(line[0])
B = int(line[1])
C = int(line[2])
D = int(line[3])

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, d = list(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 = [int(i) for i in 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:
a,b,c,d = map(int,raw_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 >= d or b <= c:
    e = 0
elif a <= c <= b <= d:
    e = b - c
elif c <= a <= d <= b:
    e = d - a
elif a <= c <= d <= b:
    e = d - c
elif c <= a <= b <= d:
    e = b - a

print(e)

Submission status: Accepted

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

start = A if C < A else C
end = B if B < D else D

print(max(end - start, 0))

Submission status: Accepted

Solution code:
a, b, c, d = [int(x) for x in raw_input().split()]
if a > c:
	(a, b), (c, d) = (c, d), (a, b)
if b <= d:
	if b - c < 0:
		print 0
	else:
		print b - c
else:
	print d - c

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
res = list(set(range(A, B+1)) & set(range(C, D+1)))
try:
    print(res[-1] - res[0])
except:
    print(0)

Submission status: Accepted

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

if num[1] < num[2] or num[3] < num[0]:
    print(0)
elif num[1] > num[2]:
    print(min(num[1], num[3])-max(num[2], num[0]))
else:
    print(min(num[3],num[1]) - max(num[0], num[2]))

Submission status: Accepted

Solution code:
time = []
time = list(map(int, input().split()))

if max(time[0], time[2]) > min(time[1], time[3]):
    print (0)

else :
    print (min(time[1], time[3]) - max(time[0], time[2]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
timestr = input().split()
time = []
for x in timestr:
    time.append(int(x))
l = min([time[1], time[3]])
s = max([time[0], time[2]])
d = l - s
if d < 0:
    print(0)
else:
    print(d)

Submission status: Accepted

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

Submission status: Accepted

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



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

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

if __name__ == "__main__": main()

Submission status: Accepted

Solution code:
a = map(int,raw_input().split())
count = 0
for i in range(0,101):
 if a[0] <= i and i < a[1] and a[2] <= i and i < a[3]:
  count += 1
print count

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
push_alice, remove_alice, push_bob, remove_bob = (int(i) for i in input().split())

if push_alice > push_bob:
    start_time = push_alice
else:
    start_time = push_bob

if remove_alice < remove_bob:
    end_time = remove_alice
else:
    end_time = remove_bob

result = end_time - start_time
if result <= 0:
    print('0')
else:
    print('{0}'.format(result))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    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)
        elif A > C:
            if B < D:
                print(B-A)
            else:
                print(D-A)
        else:
            if B < D:
                print(B-A)
            else:
                print(D-A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input().split()
A = int(s[0])
B = int(s[1])
C = int(s[2])
D = int(s[3])
 
a_c = max(A, C)
b_d = min(B, D)
 
if b_d - a_c > 0:
  print(b_d - a_c)
else:
  print("0")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    A, B, C, D = map(int, input().split())
    dp = [0] * 1000
    for i in range(A, B):
        dp[i] += 1
    for i in range(C, D):
        dp[i] += 1
    print(dp.count(2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your 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(0,min(b,d)-max(a,c)))

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
counter = 0
for i in range (101):
  if a[0] <= i <= a[1] and a[2] <= i <= a[3]:
    counter += 1
if counter > 0:
  print ('{0}'.format(counter - 1))
else:
  print ('{0}'.format(0))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://abc070.contest.atcoder.jp/tasks/abc070_b
"""


def solve(A, B, C, D):
    start = max(A, C)
    end = min(B, D)
    duration = end - start
    if duration < 0:
        return 0
    else:
        return duration


def main():
    A, B, C, D = [int(x) for x in input().strip().split(' ')]
    result = solve(A, B, C, D)
    print(result)


if __name__ == '__main__':
    main()

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:
def solve(): # 070A - Palindromic Number
    A, B, C, D = list(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)
    elif (A == C)  and (B == D):
        print(B - A)
    elif A == C or B == D:
        print(min(abs(B-A), abs(D-C)))
    else:
        print(0)
        
        
solve()

Submission status: Accepted

Solution code:
line = raw_input()
A, B, C, D = line.split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)


if C > B:
    print 0
elif A > D:
    print 0
elif A > C:
    if B > D:
        print D - A
    else:
        print B - A
else:
    if B > D:
        print D - C
    else:
        print B - C

Submission status: Accepted

Solution code:
n = [0] * 100
a, b, c, d = map(int, input().split())
while a < b:
    n[a] += 1
    a += 1
while c < d:
    n[c] += 1
    c += 1
print(n.count(2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

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

a = max(0, b-a)

print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
set_A = set(range(A, B+1))
set_B = set(range(C, D+1))
intersect_AB = set_A.intersection(set_B)
print(len(intersect_AB)-1 if intersect_AB else 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(x)
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())
a=[0]*101
for i in range(A,B):
  a[i]+=1
for i in range(C,D):
  a[i]+=1
print( sum([ 1 for x in a if x >= 2]) )

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    maxv = a if a > c else c
    minv = b if b < d else d
    time = minv - maxv if minv - maxv > 0 else 0
    print(time)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
tmp = input()
a = [int(a) for a in tmp.split()]

d = min(a[1], a[3]) - max(a[0], a[2])

print(max(d, 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:
    if(A>=C):
        begin = A
    else:
        begin = C
    if(D<=B):
        end = D
    else:
        end = B
    print(end-begin)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    max_start = max(A, C)
    min_finish = min(B, D)
    t_sub = min_finish - max_start
    
    if(t_sub < 0):
        print(0)
    else:
        print(t_sub)
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
a,b,c,d=map(int,raw_input().split())
l1,l2=range(a,b),range(c,d)
print len(set(l1).intersection(l2))

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:
abcd = [int(i) for i in input().split()]

total = (abcd[1] - abcd[0]) + (abcd[3] - abcd[2])
gap = max(abcd) - min(abcd)

if gap>=total:
	print(0)
else:
	print(total-gap)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
a, b, c, d = list(map(int, input().split()))
s1 = set([x for x in range(a, b + 1)])
s2 = set([x for x in range(c, d + 1)])
print(max(len(s1 & s2) - 1, 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:


def main():
    lst = list(map(int, input().split(' ')))
    left = max(lst[0], lst[2])
    right = min(lst[1], lst[3])
    print(max(right-left, 0))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

res = 0

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

print(res)

Submission status: Accepted

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

if a >= c:
    tmpa = a
else:
    tmpa = c

if b >= d:
    tmpb = d
else:
    tmpb = b

ans = tmpb - tmpa

if ans < 0:
    print 0
else:
    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())
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 or d<a):print(0)
##elif(b==c or d==a):
##    if(b == 0 or d==0):print(0)
##    else:print(1)
else:
    start = a if a>c else c
    end = b if b<d else d
    print(end - start)

Submission status: Accepted

Solution code:
import sys
a, b, c, d = (int(i) for i in input().split())
if b-c<=0 or d-a<=0 or b-a<=0 or d-c<=0:
    print(0)
    sys.exit()
else:
    an = min(b-a,d-c,b-c,d-a)
    print(an)

Submission status: Accepted

Solution code:
s1,e1,s2,e2 = map(int, input().split())
if s1 > s2:
    start = s1
else:
    start = s2
if e1 > e2:
    end = e2
else:
    end = e1
if end - start < 0:
    print(0)
else:
    print(end - start)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
alice = [False for _ in range(100)]
bob = [False for _ in range(100)]

a,b,c,d = map(int,input().split(" "))
for i in range(a,b):
    alice[i] = True

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

count = 0
for i in range(100):
    if alice[i] and bob[i]:
        count += 1

print(count)

Submission status: Accepted

Solution code:
xa, ya, xb, yb = map(int, input().split())
 
if xa > xb:
    x = xa
else:
    x = xb
if ya > yb:
    y = yb
else:
    y = ya
ans = y - x
if ans <= 0:
    print(0)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

mm = max(a, c)
nn = min(b, d)

print(max(0, nn - mm))

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=[int(i) for i in input().strip().split(' ')]

'''
入力は他の人のを見た
'''

max=0
min=0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
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 = [int(i) for i in 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())
if A<=C and B<=D and B>C:
 print(B-C)
elif A<C and B>D:
 print(D-C)
elif A>C and B<D:
 print(B-A)
elif A>=C and B>=D and D>A:
 print(D-A)
else:
 print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
count=0
for i in range(101):
    if i>=a and i<=b and i>= c and i<=d:
        count +=1


print(max(0,count-1))

Submission status: Accepted

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

k = [x for x in range(0, 101) if a <= x <= b and c <= x <= d]

if not k:
    print(0)
else:
    print(max(k) - min(k))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**1
gosa = 1.0 / 10**9
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    a,b,c,d = LI()
    t = min(b,d) - max(a,c)
    if t > 0:
        return t

    return 0



print(main())

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):
		E = A
	else:
		E = C

	if(B > D):
		F = D
	else:
		F = B

	print(F - E)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC070B

a,b,c,d=map(int,raw_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 = map(int, input().split())
S1 = set()
S2 = set()
for i in range(A, B):
  S1.add(i)
for i in range(C, D):
  S2.add(i)
print(len(S1.intersection(S2)))

Submission status: Accepted

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

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,B,C,D = C,D,A,B

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def create_set(a, b, out):
    for i in range(a, b):
        out.add(i)

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

alice = set()
bob = set()
create_set(a, b, alice)
create_set(c, d, bob)

total = alice & bob

time_total = 0
for i in total:
    time_total += 1

print(time_total)

Submission status: Accepted

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

f = set([i for i in range(A, B)])
g = set([i for i in range(C, D)])
print(len(list(f.intersection(g))))

Submission status: Accepted

Solution code:
a_s, a_f, b_s, b_f = [int(x) for x in input().rstrip().split()]
result = min(a_f, b_f) - max(a_s, b_s)
if result > 0:
	print(result)
else:
	print("0")

Submission status: Accepted

Solution code:
a,b,c,d = map(int,raw_input().split())
t = [0 for _ in xrange(101)]
t[a] += 1
t[b] -= 1
t[c] += 1
t[d] -= 1
for i in xrange(len(t)):
  if(i > 0): t[i] += t[i-1]
count = 0
for i in xrange(len(t)):
  if(t[i] == 2): count += 1
print count

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def Q2(x):
    A, B, C, D = x[0], x[1], x[2], x[3]
    time_lower = max(A, C)
    time_upper = min(B, D)
    return max(0, time_upper - time_lower)

l = [int(i) for i in input().split()]
print(Q2(l))

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
if A > C:
    tmpA = A
    tmpB = B
    A = C
    B = D
    C = tmpA
    D = tmpB
if D > B:
    if C > B:
        print(0)
    else:
        print(B-C)
else:
    print(D-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:
# Two Switches

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

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

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

Submission status: Accepted

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

k = [ i for i in range(0,101) if A <= i <= B and C <= i <= D]
if not k:
    print(0)
else:
    print(max(k) - min(k))

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

Submission status: Accepted

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


def solve(A, B, C, D):
    if A < C:
        if B < C:
            return 0
        elif A <= C and D <= B:
            return (D - C)
        else:
            return (B - C)
    else:
        if D < A:
            return 0
        elif C <= A and B <= D:
            return (B - A)
        else:
            return (D - A)

print(solve(A, B, C, D))

Submission status: Accepted

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

t=0
if(C<A):
 if(D<=A):
  t=0
 if(A<D<=B):
  t=D-A
 if(B<D):
  t=B-A

if(A<C):
 if(B<=C):
  t=0
 if(C<B<=D):
  t=B-C
 if(D<B):
  t=D-C

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

Submission status: Accepted

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