Problem:
Score : 300 points

Problem Statement

2N players are running a competitive table tennis training on N tables numbered from 1 to N.

The training consists of rounds.
In each round, the players form N pairs, one pair per table.
In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.

The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.

Similarly, the loser of the match on table X plays on table X+1 in the next round,
except for the loser of the match on table N who stays at table N.

Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at will.
What is the smallest number of rounds after which the friends can get to play a match against each other?

Constraints

2 \leq N \leq 10^{18}

1 \leq A < B \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the smallest number of rounds after which the friends can get to play a match against each other.

Sample Input 1

5 2 4

Sample Output 1

1

If the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.

Sample Input 2

5 2 3

Sample Output 2

2

If both friends win two matches in a row, they will both move to table 1.

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		// 入力
		string[] input = Console.ReadLine().Split(' ');
		var n = long.Parse(input[0]); //問題数
        var m = long.Parse(input[1]); //ジャッジ数
		var v = long.Parse(input[2]); //投票数
        var p = long.Parse(input[3]); //選ばれる問題数

        string[] problem = Console.ReadLine().Split(' ');
        long[] score = new long[n];
        for (int i = 0; i < n; i++)
        {
            score[i] = long.Parse(problem[i]);
        }

        //配列を降順でソート
        Array.Sort(score);

        bool ok = false;
        long ans = -1;
        for (int i = 0; i < n; i++)
        {
            long[] tmp = new long[n];
            for (int j = 0; j <n; j++)
            {
                tmp[j] = score[j];
            }


            tmp[i] = tmp[i] + m ;
            int tmp2 = 0;
            for (int j = i+1; j < n; j++)
            {
                tmp2++;
                if (v-tmp2>=0)
                {
                    tmp[j] = tmp[j] + m;
                }
                else
                {
                    break;
                }
                
            }

            IEnumerable<long> count = tmp.Where( value => value>tmp[i] );
            if (p > count.Count())
            {
                ok = true;
            }

            if (ok)
            {
                IEnumerable<long> number = score.Where( value => value>=score[i] );
                ans = number.Count();
                break;
            }
            
        }
        //出力
        Console.WriteLine(ans);
	}
}