#include <bits/stdc++.h>
using namespace std;
const int N = 6000;
long long n, x, y, c;
long long comp(long long l, long long r, long long h) {
  long long len = max(0LL, r - l + 1);
  return len * h;
}
long long line(long long l, long long r, long long start) {
  long long len = r - l + 1;
  if (len <= 0) return 0LL;
  return (len * (len + 1) / 2LL + len * (start - 1));
}
bool check(long long len) {
  long long lx = max(1LL, x - len);
  long long rx = min(n, x + len);
  long long uy = max(1LL, y - len);
  long long dy = min(n, y + len);
  long long l = lx, r = x;
  long long pl = lx - 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long midd = len - (x - mid);
    long long h = max(1LL, y - midd);
    if (h != uy) {
      pl = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  l = x, r = rx;
  long long pr = rx + 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long midd = len - (mid - x);
    long long h = max(1LL, y - midd);
    if (h != uy) {
      pr = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  pl++;
  pr--;
  long long up = comp(pl, pr, y - uy);
  long long ly = len - (x - lx);
  ly = max(1LL, y - ly);
  long long ry = len - (rx - x);
  ry = max(1LL, y - ry);
  up += line(lx, pl - 1, y - ly);
  up += line(pr + 1, rx, y - ry);
  l = lx, r = x;
  pl = lx - 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long midd = len - (x - mid);
    long long h = min(n, y + midd);
    if (h != dy) {
      pl = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  l = x, r = rx;
  pr = rx + 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long midd = len - (mid - x);
    long long h = min(n, y + midd);
    if (h != dy) {
      pr = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  pl++;
  pr--;
  long long dw = comp(pl, pr, dy - y);
  ly = len - (x - lx);
  ly = min(n, y + ly);
  ry = len - (rx - x);
  ry = min(n, y + ry);
  dw += line(lx, pl - 1, ly - y);
  dw += line(pr + 1, rx, ry - y);
  return dw + up + (rx - lx + 1) >= c;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x >> y >> c;
  if (c == 1) return cout << 0, 0;
  long long l = 0, r = n * 4, ans = n * 4;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans;
  return 0;
}

### Prompt

Please create a solution in cpp to the following problem:

Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.

We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on.

For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1).

In how many seconds will Mr. Bender get happy?

Input

The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 109; 1 ≤ x, y ≤ n; c ≤ n2).

Output

In a single line print a single integer — the answer to the problem.

Examples

Input

6 4 3 1


Output

0


Input

9 3 8 10


Output

2

Note

Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 6000;
long long n, x, y, c;
long long comp(long long l, long long r, long long h) {
  long long len = max(0LL, r - l + 1);
  return len * h;
}
long long line(long long l, long long r, long long start) {
  long long len = r - l + 1;
  if (len <= 0) return 0LL;
  return (len * (len + 1) / 2LL + len * (start - 1));
}
bool check(long long len) {
  long long lx = max(1LL, x - len);
  long long rx = min(n, x + len);
  long long uy = max(1LL, y - len);
  long long dy = min(n, y + len);
  long long l = lx, r = x;
  long long pl = lx - 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long midd = len - (x - mid);
    long long h = max(1LL, y - midd);
    if (h != uy) {
      pl = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  l = x, r = rx;
  long long pr = rx + 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long midd = len - (mid - x);
    long long h = max(1LL, y - midd);
    if (h != uy) {
      pr = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  pl++;
  pr--;
  long long up = comp(pl, pr, y - uy);
  long long ly = len - (x - lx);
  ly = max(1LL, y - ly);
  long long ry = len - (rx - x);
  ry = max(1LL, y - ry);
  up += line(lx, pl - 1, y - ly);
  up += line(pr + 1, rx, y - ry);
  l = lx, r = x;
  pl = lx - 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long midd = len - (x - mid);
    long long h = min(n, y + midd);
    if (h != dy) {
      pl = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  l = x, r = rx;
  pr = rx + 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long midd = len - (mid - x);
    long long h = min(n, y + midd);
    if (h != dy) {
      pr = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  pl++;
  pr--;
  long long dw = comp(pl, pr, dy - y);
  ly = len - (x - lx);
  ly = min(n, y + ly);
  ry = len - (rx - x);
  ry = min(n, y + ry);
  dw += line(lx, pl - 1, ly - y);
  dw += line(pr + 1, rx, ry - y);
  return dw + up + (rx - lx + 1) >= c;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x >> y >> c;
  if (c == 1) return cout << 0, 0;
  long long l = 0, r = n * 4, ans = n * 4;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans;
  return 0;
}

```