malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int sumb[64];   int xorb[64];   long long s, r;   int maxx = 0;   void bits() {     int i = 0;     long long bf = s;     while (bf) {       sumb[i] = bf % 2;       ++i;       bf /= 2;     }     maxx = i;     bf = r;     i = 0;     while (bf) {       xorb[i] = bf % 2;       ++i;       bf /= 2;       maxx = max(maxx, i);     }   }   long long ansv[2][65][2][2];   bool ch[2][65][2][2];   long long calc(int ost, int pos, int f1, int f2) {     if (ch[ost][pos][f1][f2]) {       return ansv[ost][pos][f1][f2];     }     ch[ost][pos][f1][f2] = 1;     if (pos >= 64) {       if (ost == 0 && f1 == f2 && f2 == 1) {         return 1;       } else {         return 0;       }     }     long long ans = 0;     for (long long(x1) = 0; (x1) < (2); ++(x1)) {       for (long long(x2) = 0; (x2) < (2); ++(x2)) {         long long p;         if ((x1 + x2 + ost) % 2 == sumb[pos] &&             ((x1 == x2 && 0 == xorb[pos]) || (x1 != x2 && 1 == xorb[pos]))) {           p = calc(((x1 + x2 + ost) > 1), pos + 1, (x1 != 0) || f1,                    (x2 != 0) || f2);           ans += p;         }       }     }     return ansv[ost][pos][f1][f2] = ans;   }   int main() {     ios::sync_with_stdio(false);     cin >> s >> r;     bits();     cout << calc(0, 0, 0, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long add(long long a, long long b) {     return ((a % 1000000007LL) + (b % 1000000007LL)) % 1000000007LL;   }   inline long long mul(long long a, long long b) {     return ((a % 1000000007LL) * (b % 1000000007LL)) % 1000000007LL;   }   inline long long sub(long long a, long long b) {     return ((a % 1000000007LL) - (b % 1000000007LL) + 1000000007LL) %            1000000007LL;   }   long long dp[1001][2001];   long long findAns(long long i, long long j, long long n, long long k,                     long long a[], long long key[], long long p) {     if (i == n) {       return 0;     }     if (j >= k) {       return -1000000000000000000LL;     }     if (dp[i][j] != -1) {       return dp[i][j];     }     long long ret;     long long ret1 = findAns(i, j + 1, n, k, a, key, p);     long long ret2 = findAns(i + 1, j + 1, n, k, a, key, p);     if (ret1 == -1000000000000000000LL && ret2 == -1000000000000000000LL) {       ret = -1000000000000000000LL;     } else if (ret1 == -1000000000000000000LL) {       ret = max(abs(a[i] - key[j]) + abs(key[j] - p), ret2);     } else if (ret2 == -1000000000000000000LL) {       ret = ret1;     } else {       ret = min(ret1, max(abs(a[i] - key[j]) + abs(key[j] - p), ret2));     }     return dp[i][j] = ret;   }   void Flash() {     long long n, k, p;     cin >> n >> k >> p;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long key[k];     for (long long i = 0; i < k; i++) {       cin >> key[i];     }     sort(a, a + n), sort(key, key + k);     memset(dp, -1, sizeof(dp));     long long ans = findAns(0, 0, n, k, a, key, p);     cout << ans <<   n ;   }   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     ;     long long t = 1;     for (long long i = 1; i <= t; i++) {       Flash();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000007;   int v[N];   vector<int> pos[N];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> v[i];       pos[v[i]].push_back(i);     }     for (int i = 0; i < N; ++i) {       reverse(pos[i].begin(), pos[i].end());     }     set<int> s;     long long cnt = 0;     for (int i = 0; i < n; ++i) {       s.insert(v[i]);       cnt += s.size();     }     long long ans = 2ll * cnt;     long long cur = 0;     for (int l = 0; l < n; ++l) {       int x = v[l];       pos[x].pop_back();       int j = n;       if (pos[x].size()) j = pos[x].back();       cnt -= 1;       cnt -= (j - l - 1);       ans += 2ll * cnt;     }     ans -= n;     cout << fixed << setprecision(10)          << (ans / (1.0 * ((long long)n * (long long)n))) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, m;     cin >> n >> m;     vector<string> xs(n);     for (int i = 0; i < n; i++) cin >> xs[i];     int cur = 0;     int curB = 0;     set<int> ans;     for (int i = 0; i < xs.size() - 1; i++) {       int j = 0;       while (j < xs[i].size()) {         if (xs[i][j] != xs[i + 1][j] && !ans.count(j)) {           break;         }         j++;       }       if (j < m && xs[i][j] > xs[i + 1][j]) {         ans.insert(j);         i = -1;       }     }     cout << ans.size();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int num = 200001;   long long a[401];   int main() {     int t, n;     cin >> t;     int str, cur;     int fl = 0;     while (t--) {       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) a[n + i] = a[i];       cur = 2 * n;       int first = 1;       for (int i = 0; i < cur; i++) {         if (a[i] == first) {           first++;         } else {           first = 1;         }         if (first == n) {           fl = 1;           break;         }       }       first = n;       for (int i = 0; i < cur; i++) {         if (a[i] == first)           first--;         else           first = n;         if (first == 1) {           fl = 1;           break;         }       }       if (fl)         cout <<  YES n ;       else         cout <<  NO n ;       fl = 0;       for (int i = 0; i < cur; i++) a[i] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int pw = 1 << 17;   const int maxn = 1e5 + 20;   int ans[maxn];   void work() {     int n, x;     cin >> n >> x;     if (n == 1) {       printf( YES n );       cout << x << endl;       return;     } else if (n == 2 && x == 0) {       printf( NO n );       return;     }     printf( YES n );     int t = x;     for (int i = 0; i < n; ++i) ans[i] = i;     for (int i = 0; i < n - 1; ++i) {       t ^= ans[i];     }     if (t <= n - 2) {       ans[t] ^= pw;       if (t == n - 2)         ans[t - 1] ^= pw;       else if (t == 0)         ans[t + 1] ^= pw;       else         ans[t + 1] ^= pw;     }     ans[n - 1] = t;     int res = 0;     for (int i = 0; i < n; ++i) {       printf( %d  , ans[i]);       res ^= ans[i];     }   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<int> st;     int x;     int sz = 0;     for (int i = 0; i < n; i++) {       cin >> x;       if (sz > 3) continue;       if (st.find(x) == st.end()) {         sz++;         st.insert(x);       }     }     if (sz > 3)       cout <<  NO  << endl;     else if (sz < 3)       cout <<  YES  << endl;     else {       auto it = st.begin();       int a, b, c;       a = *it;       it++;       b = *it;       it++;       c = *it;       if (b - a == c - b)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[105];   char temp[105];   int main() {     int n;     scanf( %d%*c , &n);     while (n--) {       int cnt = 0;       bool flag = false;       bool first = false;       gets(a);       int len = strlen(a);       for (int i = len - 5; i <= len; i++) temp[cnt++] = a[i];       if (strncmp(a,  miao. , 5) == 0) first = true;       if (strcmp(temp,  lala. ) == 0) flag = true;       if (first && !flag)         printf( Rainbow s n );       else if (!first && flag)         printf( Freda s n );       else         printf( OMG>.< I don t know! n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int X = 100000 + 5;   long long C[1005][1005];   long long n, m;   long long iis, ii, jjs, jj, cc;   void calc() {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cc += C[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         ii += C[i][j] * (i * 4 + 2);         iis += (i * 4 + 2) * (i * 4 + 2) * C[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         jj += C[i][j] * (j * 4 + 2);         jjs += (j * 4 + 2) * (j * 4 + 2) * C[i][j];       }     }   }   long long dist(long long x, long long y) {     x *= 4;     y *= 4;     long long s = iis + x * x * cc - 2 * x * ii + jjs + y * y * cc - 2 * y * jj;     return s;   }   long long foo(long long x, long long& z) {     long long lo = 0, hi = m, mm = LLONG_MAX;     while (lo + 2 < hi) {       long long ml = lo + (hi - lo) / 3, mr = hi - (hi - lo) / 3;       long long l = dist(x, ml), r = dist(x, mr);       if (l <= r)         hi = mr;       else         lo = ml;     }     for (int i = 0; i <= 2; i++) {       long long cc = dist(x, lo + i);       if (cc < mm) {         mm = cc;         z = lo + i;       }     }     return mm;   }   void MAIN() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> C[i][j];       }     }     calc();     long long mm = LLONG_MAX, xx = -1, yy = -1;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         long long z = dist(i, j);         if (z < mm) {           mm = z;           xx = i;           yy = j;         }       }     }     cout << mm <<   n  << xx <<     << yy;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << setprecision(12);     MAIN();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[2000], b[2000];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i] >> b[i];     }     int k = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; j++) {         if (j != i) {           if (a[i] == b[j]) {             k++;             break;           }         }       }     }     cout << n - k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q, adj[4][200123];   int vis[4][200123];   void show() {     for (int i = 1; i <= 2; ++i) {       for (int j = 1; j <= n; ++j) {         cout << adj[i][j] <<    ;       }       cout << endl;     }   }   int dfs(int i, int j, char v) {     if (i == 2 and (j == (n + 1))) return 1;     if (i <= 0 or i > 2 or j <= 0 or j > n) return 0;     if (vis[i][j]) return 0;     vis[i][j] = 1;     if ((adj[i][j] == 1 or adj[i][j] == 2) and (v ==  e )) {       return dfs(i, j + 1,  e );     } else if (adj[i][j] == 1 or adj[i][j] == 2) {       return 0;     }     if (v ==  e ) {       return dfs(i + 1, j,  c ) or dfs(i - 1, j,  b );     } else if (v ==  c ) {       return dfs(i, j + 1,  e );     } else if (v ==  b ) {       return dfs(i, j + 1,  e );     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     char c;     string s;     cin >> q;     while (q--) {       cin >> n;       cin >> s;       for (int i = 0; i < n; ++i) {         adj[1][i + 1] = s[i] -  0 ;       }       cin >> s;       for (int i = 0; i < n; ++i) {         adj[2][i + 1] = s[i] -  0 ;       }       cout << (dfs(1, 1,  e ) ?  YES n  :  NO n );       for (int i = 1; i <= 2; ++i) {         for (int j = 1; j <= n; ++j) {           vis[i][j] = 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct edge {     int a;     int b;     int c;   };   int n, m;   edge roads[10000];   vector<int> out[200];   double matrix[200][200];   double const eps = 1e-10;   double val[200];   bool isZero(double r) { return r < eps && r > -eps; }   void flip(int r1, int r2) {     for (int i = 1; i <= n; i++) {       double fill = matrix[r1][i];       matrix[r1][i] = matrix[r2][i];       matrix[r2][i] = fill;     }   }   void scale(int r1, double c) {     for (int i = 1; i <= n; i++) {       matrix[r1][i] *= c;     }   }   void add(int r1, int r2, double c) {     for (int i = 1; i <= n; i++) {       matrix[r1][i] += matrix[r2][i] * c;     }   }   void solve_system() {     for (int cur = 2; cur <= n - 1; cur++) {       int i;       for (i = cur; i <= n - 1; i++) {         if (!isZero(matrix[i][cur])) {           swap(i, cur);           break;         }       }       if (i == n) continue;       scale(cur, 1 / matrix[cur][cur]);       for (int j = cur + 1; j <= n - 1; j++) {         if (!isZero(matrix[j][cur])) {           add(j, cur, -matrix[j][cur]);         }       }     }     for (int cur = n - 1; cur >= 2; cur--) {       if (isZero(matrix[cur][cur]))         continue;       else {         val[cur] = -matrix[cur][1];       }       for (int j = cur - 1; j >= 2; j--) {         add(j, cur, -matrix[j][cur]);       }     }   }   void set_up() {     for (int i = 0; i < 200; i++) {       val[i] = 0;       for (int j = 0; j < 200; j++) {         matrix[i][j] = 0;       }     }     val[1] = 1;     for (int i = 2; i <= n - 1; i++) {       matrix[i][i] = out[i].size();       for (int j = 0; j < out[i].size(); j++) {         matrix[i][out[i][j]] -= 1;       }     }   }   void print_mat() {     for (int i = 2; i <= n - 1; i++) {       for (int j = 1; j <= n; j++) {         printf( %f  , matrix[i][j]);       }       printf(  n );     }   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d %d %d , &roads[i].a, &roads[i].b, &roads[i].c);       out[roads[i].a].push_back(roads[i].b);       out[roads[i].b].push_back(roads[i].a);     }     set_up();     solve_system();     double scale = 1e10;     for (int i = 0; i < m; i++) {       double dif = val[roads[i].a] - val[roads[i].b];       if (isZero(dif))         continue;       else {         scale = min(scale, abs(roads[i].c / dif));       }     }     double total = 0;     for (int i = 0; i < out[1].size(); i++) {       total += val[1] - val[out[1][i]];     }     printf( %.10f n , total * scale);     for (int i = 0; i < m; i++) {       double dif = val[roads[i].a] - val[roads[i].b];       printf( %.10f n , scale * dif);     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000005];   int main() {     int n;     cin >> n;     multiset<long long> s;     for (int i = 1; i <= n; i++) {       cin >> a[i];       s.insert(a[i]);     }     long long ans = 1e9;     for (int i = 1; i <= n; i++) {       s.erase(s.find(a[i]));       long long mi = *s.begin();       auto it = s.end();       it--;       long long ma = *it;       ans = min(ans, ma - mi);       s.insert(a[i]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( O8 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long int N = 60 + 5, mod = 1e9 + 7, inf = 1e12, maxq = 5e5 + 30,                       maxm = 1e3 + 30;   const long double eps = 0.0000001;   long long int poww(long long int a, long long int b) {     return (!b ? 1                : (b & 1 ? a * poww(a * a % mod, b / 2) % mod                         : poww(a * a % mod, b / 2) % mod));   }   int mat[N][N][N];   int dp[maxm][N][N];   int d[N][N][N][N];   int n, m, r;   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(d, 63, sizeof d);     cin >> n >> m >> r;     for (int i = 1; i < m + 1; i++)       for (int j = 1; j < n + 1; j++)         for (int k = 1; k < n + 1; k++) cin >> mat[i][j][k];     for (int i = 1; i < n + 1; i++)       for (int j = 1; j < n + 1; j++)         for (int k = 1; k < m + 1; k++) d[0][i][j][k] = mat[k][i][j];     for (int k = 1; k < n + 1; k++)       for (int i = 1; i < n + 1; i++)         for (int j = 1; j < n + 1; j++) {           if (i != j) {             for (int x = 1; x < m + 1; x++) {               d[k][i][j][x] =                   min(d[k - 1][i][j][x], d[k - 1][i][k][x] + d[k - 1][k][j][x]);             }           }         }     for (int i = 1; i < n + 1; i++)       for (int j = 1; j < n + 1; j++) {         if (i != j) {           for (int k = 1; k < m + 1; k++) {             if (k > 1) {               if (dp[0][i][j] > d[n][i][j][k]) dp[0][i][j] = d[n][i][j][k];             } else               dp[0][i][j] = d[n][i][j][k];           }         } else           dp[0][i][j] = 0;       }     for (int k = 1; k < 1001; k++) {       for (int i = 1; i < n + 1; i++) {         for (int j = 1; j < n + 1; j++) {           dp[k][i][j] = dp[k - 1][i][j];           if (i == j) continue;           for (int y = 1; y < n + 1; y++)             if (dp[k - 1][i][y] + dp[0][y][j] < dp[k][i][j])               dp[k][i][j] = dp[k - 1][i][y] + dp[0][y][j];         }       }     }     int x, y, z;     for (int i = 0; i < r; i++) {       cin >> x >> y >> z;       cout << dp[z][x][y] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, odd, up, down;     odd = up = down = 0;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] % 2 != 0) odd++;     }     for (int i = 0; i < n; i++) {       if (a[i] % 2 == 0)         cout << a[i] / 2 << endl;       else {         int x;         if (up < odd / 2) {           if (a[i] > 0)             cout << (a[i] / 2 + 1) << endl;           else             cout << (a[i] / 2) << endl;           up++;         } else {           if (a[i] > 0)             cout << (a[i] / 2) << endl;           else             cout << (a[i] / 2 - 1) << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   int n, K, a[N];   long long checkl(int x) {     long long sum = 0;     for (int i = 0; i < n; ++i) {       sum += max(0, x - a[i]);     }     return sum;   }   long long checkr(int x) {     long long sum = 0;     for (int i = 0; i < n; ++i) {       sum += max(0, a[i] - x);     }     return sum;   }   int main() {     scanf( %d%d , &n, &K);     long long sum = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       sum += a[i];     }     sort(a, a + n);     int l = 0, r = 1e9;     while (l < r) {       int m = l + r + 1 >> 1;       if (checkl(m) <= K) {         l = m;       } else {         r = m - 1;       }     }     int L = l;     l = 0, r = 1e9;     while (l < r) {       int m = l + r >> 1;       if (checkr(m) <= K) {         r = m;       } else {         l = m + 1;       }     }     int R = r;     printf( %d n , max(R - L, sum % n == 0 ? 0 : 1));   }
#include <bits/stdc++.h>   using namespace std;   int prior(string a) {     if (a ==  rat ) {       return 0;     } else if (a ==  woman  || a ==  child ) {       return 1;     } else if (a ==  man ) {       return 2;     } else       return 3;   }   int main() {     int n, i, j;     int k[4] = {0};     string b[4][100];     cin >> n;     string a[100][2];     for (i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1];     }     for (i = 0; i < n; i++) {       b[prior(a[i][1])][k[prior(a[i][1])]] = a[i][0];       k[prior(a[i][1])]++;     }     for (i = 0; i < 4; i++) {       for (j = 0; j < k[i]; j++) {         cout << b[i][j] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n;     cin >> n;     getchar();     string s;     cin >> s;     int ans = 1000000;     string cnt =   ;     for (int i = 0; i < n; ++i) {       cnt += s[i];       string s1 = cnt;       string s2 = s.substr(i + 1, i + 1);       if (s1 == s2) {         int x = (n - 2 * (i + 1)) + 1 + i + 1;         if (ans > x) {           ans = x;         }       }     }     printf( %d n , min(ans, n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long ans = 0;     for (int rep = 0; rep < 2; rep++) {       for (int r = 2; r < n; r++) {         long long sum = a[r - 1];         for (int l = r - 2; l >= 0; l--) {           if (a[l] < a[r] && sum == (a[l] ^ a[r])) {             ans++;           }           sum += a[l];           if (__builtin_clzll(sum) < __builtin_clzll(a[r])) {             break;           }         }       }       if (rep == 0) {         reverse(a.begin(), a.end());       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>      using namespace std;      int main()   {       int t;       cin>>t;       while(t--)       {           int n;           cin>>n;           int a[n],b[n],sum=0,sum2=0;           vector<int>v1;           vector<int>v2;           for(int i=0;i<n;i++)           {               cin>>a[i];               sum+=a[i];           }           for(int i=0;i<n;i++)           {               cin>>b[i];               sum2+=b[i];           }           if(sum==sum2){           for(int i=0;i<n;i++)           {               if(a[i]>b[i])               {                   for(int j=0;j<a[i]-b[i];j++)                       v1.push_back(i+1);               }               if(b[i]>a[i])               {                   for(int j=0;j<b[i]-a[i];j++)                       v2.push_back(i+1);               }           }           cout<<v1.size()<<endl;           for(int i=0;i<v1.size();i++)               cout<<v1[i]<<   <<v2[i]<<endl;           }           else               cout<< -1 <<endl;       }   }
#include <bits/stdc++.h>   using namespace std;   long long ans, p, s;   int N;   struct node {     int a[2];     node *L, *R;     node() {       a[0] = a[1] = 0;       L = R = NULL;     }     void add() {       if (L == NULL) L = new node();       if (R == NULL) R = new node();     }   };   void update(node *no, long long x, int h, int inc) {     no->add();     if (h < 0) return;     if (!(x & (1LL << h)))       no->a[0]++, update(no->L, x, h - 1, inc);     else       no->a[1]++, update(no->R, x, h - 1, inc);   }   long long query(node *no, long long x, int h) {     if (h < 0) return 0;     no->add();     if (!(x & (1LL << h)) && no->a[1]) return (1LL << h) + query(no->R, x, h - 1);     if ((x & (1LL << h)) && no->a[0]) return (1LL << h) + query(no->L, x, h - 1);     if (no->a[0]) return query(no->L, x, h - 1);     if (no->a[1]) return query(no->R, x, h - 1);     return 0LL;   }   int main(int argc, char **argv) {     node *no;     no = new node();     scanf( %d , &N);     vector<long long> a(N);     for (auto &x : a) scanf( %I64d , &x);     update(no, s, 42, 1);     for (int i = (N - 1); i >= (0); i--) {       s ^= a[i];       ans = max(ans, s);       update(no, s, 42, 1);     }     for (int i = (0); i < (N); i++) {       p ^= a[i];       s ^= a[i];       update(no, s, 42, -1);       ans = max(ans, query(no, p, 42));       ans = max(ans, p);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fn(long long x) {     long long ret = (x * (x + 1)) / 2;     if (x < 0) ret = 0;     return ret;   }   long long fn(long long R, long long K1, long long K2) {     long long ret = 0;     K1 = min(K1, R - 1);     K2 = min(K2, R);     if (R - K1 >= K2) return ((K1 + 1) * K2);     ret -= fn(R - K1 - 1);     ret += fn(K2);     ret += (R - K2) * K2;     return ret;   }   long long N, X, Y, C;   long long bin(long long start, long long end) {     if (start > end) return start;     long long mid = (start + end) / 2;     long long ret = 1, foo = 0;     foo = fn(mid, N - X, N - Y);     ret += foo;     foo = fn(mid, N - Y, X - 1);     ret += foo;     foo = fn(mid, X - 1, Y - 1);     ret += foo;     foo = fn(mid, Y - 1, N - X);     ret += foo;     if (ret >= C)       return bin(start, mid - 1);     else       return bin(mid + 1, end);   }   inline void ReadInput(void) {     scanf( %lld , &N);     scanf( %lld , &X);     scanf( %lld , &Y);     scanf( %lld , &C);   }   inline void solve(void) {     if (C == 1)       cout << 0 << endl;     else       cout << bin(1, 2 * N) << endl;   }   inline void Refresh(void) {}   int main() {     ReadInput();     solve();     return 0;   }