Under construction

Still being built. Things may change

Copying Coins

Time limit1sMemory limit1024 MB

Summary
Given an N by N grid with one coin at (x, y), find the minimum number of directional machine runs needed to fill every cell with coins.
Level

Easy3 of 10

Topics
Implementation, Simulation
Solved
No attempts yet

Problem

Raymu is sad because he has no money, and one day he finds a machine. The machine is a square with side length NN, made of 1×11 \times 1 cells. Cells are addressed by coordinates: the bottom-left cell is (1,1)(1, 1) and the top-right cell is (N,N)(N, N). At the start, only the cell (x,y)(x, y) has a coin, and all other cells are empty. Here (x,y)(x, y) is the cell x−1x-1 steps right and y−1y-1 steps up from (1,1)(1, 1).

Raymu can run the machine once in one of four directions: up, down, left, or right. Every coin in the machine moves in the direction the machine runs, and new coins appear along the path each coin travels. Raymu wants to fill every cell of the machine with coins, and he wants to minimize the number of runs. Given the side length and the starting position of the coin, find the minimum number of runs needed to fill every cell.

Input

The first line contains the side length NN of the machine. (1≤N≤5 0001 \leq N \leq 5\ 000)

The second line contains two integers xx and yy separated by a space, the starting position of the coin. (1≤x,y≤N1 \leq x, y \leq N)

Output

Print the minimum number of machine runs.

Examples2

  1. Example 1

    Input
    4
    2 1
    
    Expected output
    3
    
  2. Example 2

    Input
    1
    1 1
    
    Expected output
    0