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

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;


namespace Atcoder01
{
    /*class Program
    {
        //ABC96B
        static void Main()
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = int.Parse(Console.ReadLine());
            Array.Sort(input);
            int Ans = input[0] + input[1];
            var ans = input.Max();
            for (int i = 0; i < N; i++)
            {
                ans = ans * 2;
            }
            Console.WriteLine(ans + Ans);
        }
    }*/
    //ABC94B
    /*class Program
    {
        static void Main()
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] gate = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int M = input[1];
            int X = input[2];
            int cost1 = 0;
            int cost2 = 0;
            for (int i = 0;i<X;i++)
            {
                if (gate.Contains(i))
                {
                    cost1++;
                }
            }
            for (int i = X;i<= N+1;i++)
            {
                if (gate.Contains(i))
                {
                    cost2++;
                }
            }
            List<int> Answer = new List<int>();
            Answer.Add(cost1);
            Answer.Add(cost2);
            Console.WriteLine(Answer.Min());
        }
    }*/
    //ABC93B
    /*class Program
    {
        static void Main()
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = input[0];
            int B = input[1];
            int K = input[2];
            List<BigInteger> array = new List<BigInteger>();
            List<BigInteger> answer = new List<BigInteger>();
            for (BigInteger i = A;i<=B;i++)
            {
                array.Add(i);
            }
            for(BigInteger i =A;i<A+K;i++)
            {
                answer.Add(i);
            }
            for (BigInteger i = B; i > B-K;i--)
            {
                answer.Add(i);
            }
            answer.Sort();
            IEnumerable<BigInteger> result = answer.Distinct();
            foreach (BigInteger aa in result)
            {
                if (array.Contains(aa)) {
                    Console.WriteLine(aa);
                }
            }
        }*/
    /*static void Main()
    {
        int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int A = input[0];
        int B = input[1];
        int K = input[2];
        List<int> ans1 = new List<int>();
        for (int i=A;i<A+K;i++)
        {
            ans1.Add(i);
        }
        for (int i =B-K+1;i<=B;i++)
        {
            ans1.Add(i);
        }
        ans1.Sort();
        IEnumerable<int> result = ans1.Distinct();
        foreach (BigInteger aa in result)
        {
            if (A<=aa && aa<=B) {
                Console.WriteLine(aa);
            }
        }
       }
    }*/
    //ABC92B
    /*class Program
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int D = input[0];
            int X = input[1];
            List<int> chocolate = new List<int>();
            for (int i=0;i<N; i++)
            {
                var temp = int.Parse(Console.ReadLine());
                chocolate.Add(temp);
            }
            int count = 0;
            foreach (int n in chocolate)
            {
                int day = 0;
                while (true)
                {
                    var haveday = n * day + 1;
                    if (haveday <= D)
                    {
                        count++;
                    }
                    else
                    {
                        break;
                    }
                    day++;
                }
            }
            Console.WriteLine(count + X);
        }
    }*/
    //ABC89B
    /*class Program
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            bool flag = false;
            char[] arare = Console.ReadLine().ToCharArray();
            foreach (char n in arare)
            {
                if (n == 'Y')
                {
                    flag = true;
                }
            }
            if (flag == true)
            {
                Console.WriteLine("Four");
            }
            else
            {
                Console.WriteLine("Three");
            }
        }
    }*/
    //ABC86B
    /*class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split();
            var a = input[0] + input[1];
            int Ans = Convert.ToInt32(a.ToString());
            double mm = Math.Sqrt((double)Ans);
            if (mm == (int)mm)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }*/
    //ABC84B
    /*class Program 
    {
        static void Main()
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = input[0];
            int B = input[1];
            var S = Console.ReadLine();
            if (S.Length == A + B + 1)
            {
                for (int i = 0; i < S.Length; i++)
                {
                    if (A == i)
                    {
                        if (S[i] == '-')
                        {
                            var temp1 = S.Substring(0, i);
                            if (temp1.All(char.IsDigit))
                            {
                                temp1 = S.Substring(i + 1, S.Length - (i+1));
                                if (temp1.All(char.IsDigit))
                                {
                                    Console.WriteLine("Yes");
                                }
                                else
                                {
                                    Console.WriteLine("No");
                                }
                            }
                            else
                            {
                                Console.WriteLine("No");
                            }
                        }
                        else
                        {
                            Console.WriteLine("No");
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }*/
    //ABC79B
    /*class Program
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            List<BigInteger> ryka = new List<BigInteger>();
            ryka.Add(2);
            ryka.Add(1);
            int count = 2;
            while (count <= N)
            {
                var temp = ryka[count - 2] + ryka[count - 1];
                ryka.Add(temp);
                count++;
            }
            Console.WriteLine(ryka[N]);
        }
    }*/
    //ABC78B
    /*class Program
    {
        static void Main()
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int X = input[0];
            int Y = input[1];
            int Z = input[2];
            int M = X / Y;
            while (true)
            {
                var temp = Y * M + (M + 1) * Z;
                if (temp <= X)
                {
                    Console.WriteLine(M);
                    break;
                }
                else
                {
                    M--; 
                }
            }
        }
    }*/
    /*class Program
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            int Answer = 0;
            while(true)
            {
                var ans = Math.Sqrt(N);
                if (ans == (int)ans)
                {
                    Answer = N;
                    break;
                }
                N--;
            }
            Console.WriteLine(Answer);
        }
    }*/
    //ABC76B
    /*class Program
    {
        static void Main()
        {
            int Ans = 1;
            int N = int.Parse(Console.ReadLine());
            int K = int.Parse(Console.ReadLine());
            for(int i = 0; i < N; i++)
            {
                var A = Ans * 2;
                var B = Ans + K;
                if (A < B)
                {
                    Ans = A;
                }
                else
                {
                    Ans = B;
                }
            }
            Console.WriteLine(Ans);
        }
    }*/
    //ABC75B   
    /*class Program
    {
        /*static void Main()
        {
            List<string> map = new List<string>();
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int i = 0;i< input[0];i++)
            {
                var temp = Console.ReadLine();
                map.Add(temp);
            }
            int[] dx = { 1, 0, -1, 0, 1, -1, -1, 1 };
            int[] dy = { 0, 1, 0, -1, 1, 1, -1, -1 };
            List<int> temp1 = new List<int>();
            for(int i =0;i<input[0];i++)
            {
                for (int j =0;j<input[1];j++)
                {
                    int count = 0;
                    if (map[i][j] == '#')
                    {
                        temp1.Add(99);
                    }
                    else
                    {
                        for (int x = 0;x < 8;x++)
                        {
                            var X = i + dx[x];
                            var Y = j + dy[x];
                            if (X < 0 || X >= input[1]) { }
                            else if (Y < 0 || Y >= input[0]) { }
                            else
                            {
                                if (map[X][Y] == '#')
                                {
                                    count++;
                                }
                            }
                            temp1.Add(count);
                        }
                    }
                }
            }

        }*/
    /*static void Main()
    {
        int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        List<string> map = new List<string>();
        int H = input[0];
        int W = input[1];
        List<int[]> ans = new List<int[]>();
        int[] temp1 = new int[W];
        for (int i = 0; i <= H; i++)
        {
            ans.Add(temp1);
        }
        int[] dx = { 1, 0, -1, 0, 1, -1, -1, 1 };
        int[] dy = { 0, 1, 0, -1, 1, 1, -1, -1 };
        for (int i = 0; i < H; i++)
        {
            var temp = Console.ReadLine();
            map.Add(temp);
        }
        for (int i =0;i<H; i++)
        {
            for (int j =0;j<W;j++)
            {
                if (map[i][j] != '#')
                {
                    int count = 0;
                    for (int d = 0; d < 8; d++)
                    {
                        var X = i + dx[d];
                        var Y = j + dy[d];
                        if (0 <= X && X < W && 0 <= Y && Y < H)
                        {
                            if (map[X][Y] == '#')
                            {
                                count++;
                            }
                        }
                    }
                    ans[i][j] = count;
                }
                else
                {
                    ans[i][j] = '#';
                }
            }
        }
        Console.WriteLine();
    }*/

    // }
    //ABC73B
    /*class Program
    {
        static void Main()
        {
            List<int[]> ans = new List<int[]>();
            int N = int.Parse(Console.ReadLine());
            for (int i = 0;i <N;i++)
            {
                var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
                ans.Add(temp);
            }
            int aa = 0;
            foreach (int[] m in ans)
            {
                var answer = Math.Abs(m[0] - m[1])+1;
                aa += answer;
            }
            Console.WriteLine(aa);
        }            if (A == C && B == D)
            {
                Console.WriteLine("1");
            }
    } */
    //ABC70B
    class Program
    {
        static void Main()
        {
            int[] N = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = N[0];
            int B = N[1];
            int C = N[2];
            int D = N[3];
            if (C <= B && D >= A)
            {
                if (C <= A && D >= A)
                {
                    Console.WriteLine(Math.Abs(D - A));
                }
                else if (C <= A)
                {
                    Console.WriteLine(Math.Abs(A - B));
                }
                else if (B >= D && C >= A)
                {
                    Console.WriteLine(Math.Abs(D - C));
                }
                else if (C >= A)
                {
                    Console.WriteLine(Math.Abs(B - C));
                }
            }
            else
            {
                Console.WriteLine("0");
            }
        }
    }
}