P7901 "PMOI-0" One-Stroke Drawing

Background

(Originally LZOI-1. The rename has been approved by PMOI members.)

Description

Yan Zhuo $d$ is at a point with coordinates $(x,y)$ in a $2n \times 2n$ matrix. Now lhm needs to arbitrarily choose a point in the matrix as the starting point, then visit $k$ points in order, with the following movement rules: - Each move can only choose a point adjacent (up, down, left, or right) to the current point as the target point of this move. Points outside the matrix cannot be chosen. - In each round of movement, the path must visit all points in the matrix exactly once, and no point may be visited more than once. After visiting all points, that round of movement ends. - Note that after visiting $k$ points in order, the last round of movement may not be completed. Now lhm wants to know: at minimum, how many times will he pass through Yan Zhuo $d$.

Input Format

The first line contains four positive integers $n,k,x,y$.

Output Format

Output one integer on the first line, representing the answer.

Explanation/Hint

### Sample Explanation ![](https://cdn.luogu.com.cn/upload/image_hosting/37e99o4k.png) $\color{red}d$ represents Yan Zhuo $d$'s position, and the red line shows lhm's path in the first round. ### Constraints **This problem uses bundled testdata.** | Subtask ID | Score | $n,k\le$ | | :----------: | :----------: | :----------: | | $1$ | $30$ | $10^4$ | | $2$ | $30$ | $10^9$ | | $3$ | $40$ | $10^{18}$ | For all testdata, it is guaranteed that $1\le n,k\le10^{18}$ and $1\le x,y\le 2n$. Translated by ChatGPT 5