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: Wrong Answer

Solution code:
import sys

# sys.stdin = open('b1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    a, b, c, d = read_int_list()
    res = c - (b - a)
    if res < 0:
        print(abs(res))
    else:
        print('0')


main()

Submission status: Wrong Answer

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


if A < C:
  a = C
else:
  a = A

if B < D:
  b = B
else:
  b = D
  
if B<=C:
  res = 0
else:
  res = (b-a)
  
print(res)

Submission status: Wrong Answer

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

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

counter=0
for i in range(1,101):
    if A<=i and i<B and C<=i and i<D:
        counter+=1
print(counter)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

    sw = [0] * 101
    sw[A] = 1
    sw[B] = -1
    sw[C] = 1
    sw[D] = -1
    for i in range(1, 101):
        sw[i] = sw[i-1] + sw[i]

    ans = sw.count(2)
    print(ans)

main()

Submission status: Wrong Answer

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


if A < C:
  a = C
else:
  a = A

if B < D:
  b = B
else:
  b = D
  
if B<C:
  res = 0
else:
  res = (b-a)
  
print(res)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:


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

    xs = [0] * 101
    xs[a] = 1
    xs[b] = -1
    xs[c] = 1
    xs[d] = -1

    cursum = 0
    t = 0
    for x in xs:
        cursum += x
        if cursum == 2:
            t += 1

    print(t)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    A, B, C, D = ILI()
    return A, B, C, D


def solve(A, B, C, D):
    l_ans = [0] * 101
    for a in range(A, B + 1):
        l_ans[a] += 1
    for b in range(C, C + 1):
        l_ans[b] += 1

    ans = 0
    for a in l_ans:
        if a == 2:
            ans += 1

    if ans != 0:
        ans -= 1

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:


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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



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

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

if __name__ == "__main__": main()

Submission status: Wrong Answer

Solution code:
cnt=0
a,b,c,d=map(int,raw_input().split())
t=[0 for i in range(101)]
for i in range(a,b+1):
    t[i]=1
for j in range(c,d+1):
    t[j]=t[j]+1
for i in range(1,101):
    if t[i]==2: cnt=cnt+1
if cnt==0:
    print 0
else:
    print cnt-1

Submission status: Accepted

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

Submission status: Accepted

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

t1 = max(A, C)
t2 = min(B, D)

print(max(0, t2 - t1))

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

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

M1 = max(A, C)
M2 = min(B, D)

M = M2 - M1

if M > 0:
    print(M)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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


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

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

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

Submission status: Accepted

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

mint = max(A, C)
maxt = min(B, D)

dt = max(0, maxt - mint)
print(dt)

Submission status: Accepted

Solution code:
A, B, C, D = 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))

Submission status: Accepted

Solution code:
import re
import copy

def accept_input():
    ast,aen,bst,ben = 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)

Submission status: Accepted

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

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=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
if c<a<d:
  if b>d:
    print(d-a)
  else:
    print(b-a)
if a<=c:
  if b<c:
    print(0)
  elif c<=b<=d:
    print(b-c)
  else:
    print(d-c)
if a>=d:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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:
a, b, c, d = map(int, input().split())
aa = [0 for i in range(101)]
bb = [0 for i in range(101)]
ans = 0
for i in range(a, b):
    aa[i] = 1
for i in range(c, d):
    bb[i] = 1
for i in range(101):
    if aa[i] == 1 and bb[i] == 1:
        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:
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]))

Submission status: Accepted

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

Submission status: Accepted

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


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


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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()