#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const long long LINF = INF * 1ll * INF;
const double PI = acos(-1.0);
using namespace std;
long long Sum(long long a, long long b) {
  if (a < b) return 0;
  return a * (a + 1) / 2 - (b) * (b - 1) / 2;
}
int main(void) {
  long long n, x, y, c;
  cin >> n >> x >> y >> c;
  x--, y--;
  long long low = 0, high = n * 2;
  int ans = -1;
  while (low <= high) {
    long long mid = (low + high) >> 1;
    long long tot = 0;
    int left = max(0ll, x - mid), right = min(n - 1, x + mid);
    long long ly = max(0ll, y - (mid - (x - left)));
    long long ry = max(0ll, y - (mid - (right - x)));
    if (ly == 0)
      tot += (y + 1) * (x - left + 1);
    else {
      if (y >= mid) {
        tot += Sum(mid + 1, y - ly + 1);
      } else {
        long long eqpos = max(0ll, x - (mid - y));
        tot += Sum(y + 1, y - ly + 1);
        tot += 1ll * (x - eqpos) * (y + 1);
      }
    }
    if (ry == 0)
      tot += (y + 1) * (right - x + 1);
    else {
      if (y >= mid) {
        tot += Sum(mid + 1, y - ry + 1);
      } else {
        long long eqpos = min(n - 1, x + (mid - y));
        tot += Sum(y + 1, y - ry + 1);
        tot += (eqpos - x) * (y + 1);
      }
    }
    tot -= min(y + 1, mid + 1);
    ly = min(n - 1, y + (mid - (x - left)));
    ry = min(n - 1, y + (mid - (right - x)));
    if (ly == n - 1)
      tot += (n - y) * (x - left + 1);
    else {
      if (y + mid <= n - 1) {
        tot += Sum(mid + 1, ly - y + 1);
      } else {
        long long eqpos = max(0ll, x - (mid - (n - 1 - y)));
        tot += Sum(n - y, ly - y + 1);
        tot += (x - eqpos) * (n - y);
      }
    }
    if (ry == 0)
      tot += (n - y) * (right - x + 1);
    else {
      if (y + mid <= n - 1) {
        tot += Sum(mid + 1, ry - y + 1);
      } else {
        int eqpos = min(n - 1, x + (mid - (n - 1 - y)));
        tot += Sum(n - y, ry - y + 1);
        tot += (eqpos - x) * (n - y);
      }
    }
    tot -= (x - left);
    tot -= right - x;
    tot -= min(mid + 1, n - y);
    tot--;
    if (tot >= c) {
      ans = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  cout << ans << endl;
}

### Prompt

Generate a Cpp solution 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;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const long long LINF = INF * 1ll * INF;
const double PI = acos(-1.0);
using namespace std;
long long Sum(long long a, long long b) {
  if (a < b) return 0;
  return a * (a + 1) / 2 - (b) * (b - 1) / 2;
}
int main(void) {
  long long n, x, y, c;
  cin >> n >> x >> y >> c;
  x--, y--;
  long long low = 0, high = n * 2;
  int ans = -1;
  while (low <= high) {
    long long mid = (low + high) >> 1;
    long long tot = 0;
    int left = max(0ll, x - mid), right = min(n - 1, x + mid);
    long long ly = max(0ll, y - (mid - (x - left)));
    long long ry = max(0ll, y - (mid - (right - x)));
    if (ly == 0)
      tot += (y + 1) * (x - left + 1);
    else {
      if (y >= mid) {
        tot += Sum(mid + 1, y - ly + 1);
      } else {
        long long eqpos = max(0ll, x - (mid - y));
        tot += Sum(y + 1, y - ly + 1);
        tot += 1ll * (x - eqpos) * (y + 1);
      }
    }
    if (ry == 0)
      tot += (y + 1) * (right - x + 1);
    else {
      if (y >= mid) {
        tot += Sum(mid + 1, y - ry + 1);
      } else {
        long long eqpos = min(n - 1, x + (mid - y));
        tot += Sum(y + 1, y - ry + 1);
        tot += (eqpos - x) * (y + 1);
      }
    }
    tot -= min(y + 1, mid + 1);
    ly = min(n - 1, y + (mid - (x - left)));
    ry = min(n - 1, y + (mid - (right - x)));
    if (ly == n - 1)
      tot += (n - y) * (x - left + 1);
    else {
      if (y + mid <= n - 1) {
        tot += Sum(mid + 1, ly - y + 1);
      } else {
        long long eqpos = max(0ll, x - (mid - (n - 1 - y)));
        tot += Sum(n - y, ly - y + 1);
        tot += (x - eqpos) * (n - y);
      }
    }
    if (ry == 0)
      tot += (n - y) * (right - x + 1);
    else {
      if (y + mid <= n - 1) {
        tot += Sum(mid + 1, ry - y + 1);
      } else {
        int eqpos = min(n - 1, x + (mid - (n - 1 - y)));
        tot += Sum(n - y, ry - y + 1);
        tot += (eqpos - x) * (n - y);
      }
    }
    tot -= (x - left);
    tot -= right - x;
    tot -= min(mid + 1, n - y);
    tot--;
    if (tot >= c) {
      ans = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  cout << ans << endl;
}

```