codeparrot/codecomplex huggingface dataset:
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.io.*;
import java.util.*;

public class bender {
    static long[] dx = new long[]{0, 1, 0, -1};
    static long[] dy = new long[]{-1, 0, 1, 0};
    static long n, x, y, c;
    
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("bender.in"));
        
        StringTokenizer dxdync = new StringTokenizer(in.readLine());
        n = Long.parseLong(dxdync.nextToken());
        x = Long.parseLong(dxdync.nextToken());
        y = Long.parseLong(dxdync.nextToken());
        c = Long.parseLong(dxdync.nextToken());
        
        long a = 0;
        long b = c;
        
        while(a < b){
            long m = (a + b)/2;
            
            long[] dxn = new long[4];
            long[] dyn = new long[4];
            
            for(int d = 0; d < 4; d++){
                dxn[d] = x + dx[d] * m;
                dyn[d] = y + dy[d] * m;
            }
            
            long ret = (m+1)*(m+1) + m*m;
            
            ret -= h(1 - dyn[0]);
            ret -= h(dyn[2] - n);
            ret -= h(dxn[1] - n);
            ret -= h(1 - dxn[3]);
            
            ret += q(1 - dyn[0] - (n-x+1));
            ret += q(1 - dyn[0] - x);
            ret += q(dyn[2] - n - (n - x + 1));
            ret += q(dyn[2] - n - (x));
            
            if (ret < c) a = m + 1;
            else b = m;
        }
        
        System.out.println(a);
    }
    
    public static long h(long x) {
        if (x <= 0) return 0;
        return 2*q(x) - x;
    }
    private static long q(long x){
        if (x <= 0) return 0;
        return x*(x+1)/2;
    }
}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
//package code;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
import java.util.TreeMap;


/**
 *
 * @author malek
 */

public class MainA {

    public static void main(String[] args) throws Exception {
        //String cwd = System.getProperty("user.dir") + "\\";
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        PrintStream out = new PrintStream(System.out);
        //Scanner in = new Scanner(new BufferedInputStream(new FileInputStream(cwd + "src\\code\\in.in")));
        //PrintStream out = new PrintStream(cwd + "src\\code\\out.out");
        //=======================
        Solution solution = new Solution(in, out);
        solution.solve();
        //=======================
        in.close();
        out.close();
    }
    static private class Solution {
        final int inf = (int)1e9;
        //final int MAX_N = 1000 * 1000 + 100;
        int n, x, y, c;

        int f(int u, int r, int sec){
            if(u == 0 && r == 0)
                return 0;
            if(u == 0){
                return r - 1;
            }
            if(r == 0){
                return u - 1;
            }
            return Math.min(sec - 1, u - 1 + r - 1);
        }

        boolean isok(int sec){
            int up = x - 1;
            int down = n - x;
            int right = n - y;
            int left = y - 1;
            int u = 0, d = 0, r = 0, l = 0;
            int total = 1;
            int add = 4;
            for(int i = 1; i <= sec; i++){
                int cc = 0;
                if(i > up && ++cc > 0) u++;
                if(i > down && ++cc > 0) d++;
                if(i > right && ++cc > 0) r++;
                if(i > left && ++cc > 0) l++;
                total += add - cc;
                total -= Math.max(0, f(u, r, i));
                total -= Math.max(0, f(u, l, i));
                total -= Math.max(0, f(d, r, i));
                total -= Math.max(0, f(d, l, i));
                if(total >= c) return true;
                add += 4;
            }
            return false;
        }

        public void solve() {
            n = in.nextInt();
            x = in.nextInt();
            y = in.nextInt();
            c = in.nextInt();
            if(c == 1){
                out.println(0);
                return;
            }
            int lo = 0, hi = 60000;
            while(lo < hi){
                int mid = (lo + hi)/2;
                if(isok(mid)){
                    hi = mid;
                }
                else{
                    lo = mid + 1;
                }
            }
            out.println(lo);
        }

        public Solution(Scanner in, PrintStream out) {
            this.in = in;
            this.out = out;
        }

        Scanner in;
        PrintStream out;
    }
}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.io.*;
import java.math.*;
import java.util.*;

public class B {
    public static void main(String[] args) throws Exception {
        new B().solve(System.in, System.out);
        // new FileInputStream(new File("input.txt")),
        // new PrintStream(new FileOutputStream(new File("output.txt"))));
    }

    void solve(InputStream _in, PrintStream out) throws IOException {
        // BufferedReader in = new BufferedReader(new InputStreamReader(_in));
        // String[] sp;
        Scanner sc = new Scanner(_in);

        long n = sc.nextLong();
        long x = sc.nextLong() - 1;
        long y = sc.nextLong() - 1;
        long c = sc.nextLong();

        long ub = 2 * n;
        long lb = -1;
        while (lb + 1 < ub) {
            long k = (lb + ub) / 2;

            long l, u, r, d;
            l = Math.max(0, x - k);
            u = Math.max(0, y - k);
            r = Math.min(n - 1, x + k);
            d = Math.min(n - 1, y + k);

            long ss = 0;
            // lu
            long lu = x - (k - (y - u));
            if (l < lu) {
                long a = lu - l;
                ss += a * (a + 1) / 2;
            }
            // ld
            long ld = x - (k - (d - y));
            if (l < ld) {
                long a = ld - l;
                ss += a * (a + 1) / 2;
            }
            // ru
            long ru = x + (k - (y - u));
            if (ru < r) {
                long a = r - ru;
                ss += a * (a + 1) / 2;
            }
            // rd
            long rd = x + (k - (d - y));
            if (rd < r) {
                long a = r - rd;
                ss += a * (a + 1) / 2;
            }

            long cc = (r + 1 - l) * (d + 1 - u) - ss;

            if (c <= cc) {
                // ok
                ub = k;
            } else {
                // ng
                lb = k;
            }
        }
        out.println(ub);
    }
}

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class B {
    static Scanner in; static int next() throws Exception {return in.nextInt();};
//	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
//	static BufferedReader in;
    static PrintWriter out;

    public static long count(long k, long x, long y, long n) {
        long sum = 2*k*(k+1)+1;
        if (k >= x-1) {
            sum -= (k-x+1)*(k-x+1);
        }
        if (k >= y-1) {
            sum -= (k-y+1)*(k-y+1);
        }
        if (k + x >= n) {
            sum -= (k+x-n)*(k+x-n);
        }
        if (k + y >= n) {
            sum -= (k+y-n)*(k+y-n);
        }

        if (k > x+y-1) {
            sum += ((k+1-x-y)*(k+1-x-y+1))/2;
        }

        if (k > n-x+y) {
            sum += ((k+x-n-y)*(k+x-n-y+1))/2;
        }

        if (k > n-y+x) {

            sum += ((k+y-n-x)*(k+y-n-x+1))/2;
        }

        if (k > 2*n-x-y+1) {

            sum += ((k-2*n+x+y-1)*(k-2*n+x+y))/2;
        }
        return sum;
    }

    public static void main(String[] args) throws Exception {
        in = new Scanner(System.in);
//		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
//		in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        long n = in.nextLong(), x = in.nextLong(), y = in.nextLong(), c = in.nextLong();

        long res = 0;
        while (count(res, x, y, n) < c) res++;
        out.println(res);


        out.println();
        out.close();
    }
}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

public class P {

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt();
		long C = sc.nextLong();

		int lo = 0, hi = (int) (1e6);
		int answer = -1;
		while (lo <= hi) {
			int L = lo + (hi - lo) / 2;
			long area = 0;
			for (int steps = 0; steps <= L; ++steps) { // L + 1 steps to right
				if (y + steps > N)
					break;
				long up = Math.min(x, 1 + L - steps), down = Math.min(N - x, L - steps);
				area += up + down;
			}

			for (int steps = 1; steps <= L; ++steps) { // L steps to left
				if (y - steps < 1)
					break;
				long up = Math.min(x, 1 + L - steps), down = Math.min(N - x, L - steps);
				area += up + down;
			}
			if (area >= C) {
				answer = L;
				hi = L - 1;
			} else
				lo = L + 1;
		}
		out.println(answer);

		out.flush();
		out.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

	}
}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.util.Scanner;

public class Main {
	
	static Scanner cin = new Scanner(System.in);
	static int n, x, y;
	static long c;
	
	private static long f(int mid) {
		long block = 1 + 4 * (long)(mid + 1) * mid / 2;
		int l = y - mid;
		int r = y + mid;
		int u = x - mid;
		int d = x + mid;
		if(l <= 0)
			block -= (long)(1 - l) * (1 - l);
		if(r > n)
			block -= (long)(r - n) * (r - n);
		if(u <= 0)
			block -= (long)(1 - u) * (1 - u);
		if(d > n)
			block -= (long)(d - n) * (d - n);
		if(u <= 0 && 1 - u > n - y + 1) {
			int t = (1 - u) - (n - y + 1);
			block += (long)t * (1 + t) / 2;
		}
		if(u <= 0 && (1 - u) > y) {
			int t = (1 - u) - y;
			block += (long)t * (1 + t) / 2;
		}
		if(d > n && d - n > n - y + 1) {
			int t = (d - n) - (n - y + 1);
			block += (long)t * (1 + t) / 2;
		}
		if(d > n && d - n > y) {
			int t = (d - n) - y;
			block += (long)t * (1 + t) / 2;
		}
//		System.out.println(block);
		return block;
	}
	
	public static void main(String args[]) {
		
		n = cin.nextInt();
		x = cin.nextInt();
		y = cin.nextInt();
		c = cin.nextLong();
		
		int low = 0, high = 1000000000;
		int ans = -1;
		while(low <= high) { 
			int mid = (low + high) / 2;
//			System.out.println(mid + " " + f(mid));
			if(f(mid) >= c) {
				ans = mid;
				high = mid - 1;
			} else {
				low = mid + 1;
			}
		}
		System.out.println(ans);
	}
}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.util.Scanner;
import java.math.BigInteger;
import java.io.*;

public class Main{

	/**
	 * @param args
	 */
	static BigInteger n, x, y, c;
	static BigInteger mk[] = new BigInteger[8];
	public static BigInteger f(BigInteger t) {
		return t.multiply(t);
	}
	
	public static BigInteger g(BigInteger t) {
		return t.multiply(t.add(BigInteger.ONE)).shiftRight(1);
	}
	
	public static int solve(BigInteger z) {
		BigInteger ret = z.multiply(z.add(BigInteger.ONE)).shiftLeft(1);
		ret = ret.add(BigInteger.ONE);
		//System.out.println(z + " " + ret);
		for(int i = 0; i < 8; i += 2) {
			if(z.compareTo(mk[i]) > 0) {
				ret = ret.subtract(f(z.subtract(mk[i])));
			}
		}
		for(int i = 1; i < 8; i += 2) {
			if(z.compareTo(mk[i]) > 0) {
				ret = ret.add(g(z.subtract(mk[i])));
			}
		}
		//System.out.println(z + " " + ret);
		if(ret.compareTo(c) >= 0) return 1;
		return 0;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()) {
			n = cin.nextBigInteger();
			x = cin.nextBigInteger();
			y = cin.nextBigInteger();
			c = cin.nextBigInteger();
			mk[0] = x.subtract(BigInteger.ONE);
			mk[2] = n.subtract(y);
			mk[4] = n.subtract(x);
			mk[6] = y.subtract(BigInteger.ONE);
			mk[1] = mk[0].add(mk[2]).add(BigInteger.ONE);
			mk[3] = mk[2].add(mk[4]).add(BigInteger.ONE);
			mk[5] = mk[4].add(mk[6]).add(BigInteger.ONE);
			mk[7] = mk[6].add(mk[0]).add(BigInteger.ONE);
			BigInteger beg = BigInteger.ZERO, end = mk[0], mid;
			for(int i = 1; i < 8; ++i) if(end.compareTo(mk[i]) < 0) end = mk[i];
			while(beg.compareTo(end) < 0) {
				mid = beg.add(end).shiftRight(1);
				if(solve(mid) == 1) end = mid;
				else beg = mid.add(BigInteger.ONE);
			}
			System.out.println(end);
		}

	}

}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	static long[] dx = new long[]{0, 1, 0, -1};
	static long[] dy = new long[]{-1, 0, 1, 0};
	public static void main(String[] args) {
		Scanner r = new Scanner(System.in);
		
		long N = r.nextLong();
		long X = r.nextLong();
		long Y = r.nextLong();
		long C = r.nextLong();
		
		long lo = 0, hi = N * 2;
		
		while(lo < hi){
			long T = (lo + hi) / 2;
			
			long[] NX = new long[4];
			long[] NY = new long[4];
			
			for(int d = 0; d < 4; d++){
				NX[d] = X + dx[d] * T;
				NY[d] = Y + dy[d] * T;
			}
			
			long ret = (T + 1) * (T + 1) + T * T;
			
			ret -= half(1 - NY[0]);
			ret -= half(NY[2] - N);
			ret -= half(NX[1] - N);
			ret -= half(1 - NX[3]);
			
			ret += quarter(1 - NY[0] - (N - X + 1));
			ret += quarter(1 - NY[0] - (X));
			ret += quarter(NY[2] - N - (N - X + 1));
			ret += quarter(NY[2] - N - (X));
			
			if(ret < C)lo = T + 1;
			else hi = T;
		}
		
		System.out.println(lo);
		
	}
	private static long half(long x) {
		if(x <= 0)return 0;
		else return 2 * quarter(x) - x;
	}
	private static long quarter(long x){
		if(x <= 0)return 0;
		return x * (x + 1) / 2;
	}

}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.util.*;

public class cf256b {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long x = in.nextLong()-1;
		long y = in.nextLong()-1;
		long c = in.nextLong();
		
		long lo = 0, hi = 2*n+10;
		while(hi - lo > 2) {
			long mid = (hi+lo)/2;
			if(calc(n,x,y,mid) >= c)
				hi = mid;
			else
				lo = mid;
		}
		while(calc(n,x,y,lo) < c) lo++;
		System.out.println(lo);
	}
	static long calc(long n, long x, long y, long t) {
		long ans = (2*t)*(t+1)+1;
		
		long top = Math.max(0,t-x);
		long bottom = Math.max(0,t-(n-1-x));
		long left = Math.max(0,t-y);
		long right = Math.max(0,t-(n-1-y));
		ans -= top*top + bottom*bottom + left*left + right*right;
		
		long tl = Math.max(0, t - (x+y+1));
		long tr = Math.max(0, t - (x+(n-1-y)+1));
		long bl = Math.max(0, t - ((n-1-x)+y+1));
		long br = Math.max(0, t - ((n-1-x) + (n-1-y) + 1));
		
		ans += (tl*tl+tl)/2 + (tr*tr+tr)/2 + (bl*bl+bl)/2 + (br*br+br)/2;
		return ans;
	}
}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.util.*;
import java.math.BigInteger;

import javax.naming.BinaryRefAddr;

public class acm
{
    public static BigInteger n;
    public static BigInteger TWO = new BigInteger("2");
    public static BigInteger solve(BigInteger x, BigInteger y, BigInteger c)
    {
        BigInteger res = (c.add(BigInteger.ONE)).multiply(c.add(BigInteger.ONE));
        res = res.add(c.multiply(c));
        BigInteger k;
        
        //up
        k = c.subtract(x.subtract(BigInteger.ONE)); 
        if(k.compareTo(BigInteger.ZERO) > 0)
            res = res.subtract(k.multiply(k));

        //left
        k = c.subtract(y.subtract(BigInteger.ONE)); 
        if(k.compareTo(BigInteger.ZERO) > 0)
            res = res.subtract(k.multiply(k));

        //down
        k = c.subtract(n.subtract(x)); 
        if(k.compareTo(BigInteger.ZERO) > 0)
            res = res.subtract(k.multiply(k));


        //right
        k = c.subtract(n.subtract(y));
        if(k.compareTo(BigInteger.ZERO) > 0)
            res = res.subtract(k.multiply(k));


        //upleft
        k = c.subtract(x.add(y).subtract(BigInteger.ONE));
        if(k.compareTo(BigInteger.ZERO) > 0)
            res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO));


        //upright
        k = c.subtract(x.add(n).subtract(y));
        if(k.compareTo(BigInteger.ZERO) > 0)
            res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO));


        //dwleft
        k = c.subtract(y.add(n).subtract(x));
        if(k.compareTo(BigInteger.ZERO) > 0)
            res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO));


        //dwleft
        k = c.subtract(n.subtract(x).add(n.subtract(y)).add(BigInteger.ONE));
        if(k.compareTo(BigInteger.ZERO) > 0)
            res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO));



        return res;
    }
    
    public static void main(String[] args)
    {TWO = new BigInteger("2");
        Scanner in = new Scanner(System.in);
        n = new BigInteger(in.next());
        BigInteger x = new BigInteger(in.next());
        BigInteger y = new BigInteger(in.next());
        BigInteger c = new BigInteger(in.next());

        
        BigInteger left = new BigInteger("0");
        BigInteger right = new BigInteger("1000000000000");
        while(left.compareTo(right) < 0)
        {
            BigInteger val = left.add(right).divide(TWO);

            if(solve(x, y, val).compareTo(c) >= 0)
                right = val;
            else
                left = val.add(BigInteger.ONE);
        }

        System.out.println(left);
    } 
}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class ProblemB {

public static void main(String[] args) throws IOException {
		
		ProblemB solver = new ProblemB();
		solver.init();
		solver.solve();
	}
	
	private void init() {
		
	}

	private void solve() throws IOException {
		 
		Reader in = new Reader(System.in);
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		
		int n = in.nextInt();
		int x = in.nextInt();
		int y = in.nextInt();
		int c = in.nextInt();
		
		long lo = 0;
		long hi = 2 * n;
		
		while (lo < hi) {
			long mid = (lo + hi)/2;
			long r = count(n, x , y, mid);
			if (r < c) {
				lo = mid + 1;
			} else {
				hi = mid;;
			}
		}
		out.println(lo);
		out.flush();
		out.close();
	}
	
	private long count(int n, int x, int y, long steps) {
		long r = 1  + 2 * steps * (1 + steps);
		r -= countWall(x - 1 - steps);
		r -= countWall(y - 1 - steps);
		r -= countWall(n - (x + steps));
		r -= countWall(n - (y + steps));
		r += countCorner(steps - (x - 1) - (y - 1) - 1);
		r += countCorner(steps - (y - 1) - (n - x) - 1);
		r += countCorner(steps - (n - x) - (n - y) - 1);
		r += countCorner(steps - (x - 1) - (n - y) - 1);
		
		return r;
	}

	private long countCorner(long x) {
		if (x <= 0) return 0;
		return x * ( x + 1) / 2;
	}

	private long countWall(long x) {
		if (x >= 0) return 0;
		return x * x;
	}

	private static class Reader {
	    BufferedReader reader;
	    StringTokenizer tokenizer;

	    /** call this method to initialize reader for InputStream */
	    Reader(InputStream input) {
	        reader = new BufferedReader(
	                     new InputStreamReader(input) );
	        tokenizer = new StringTokenizer("");
	    }

	    /** get next word */
	    public String next() throws IOException {
	        while ( ! tokenizer.hasMoreTokens() ) {
	            //TODO add check for eof if necessary
	            tokenizer = new StringTokenizer(
	                   reader.readLine() );
	        }
	        return tokenizer.nextToken();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt( next() );
	    }
	    
	    public double nextDouble() throws IOException {
	        return Double.parseDouble( next() );
	    }
	    
	    public long nextLong() throws IOException {
	    	return Long.parseLong(next());
	    }
	}

}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.io.*;
import java.util.*;

public class Example {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(in.readLine());
            } catch (Exception e) {
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    public void run() throws Exception {
        //in = new BufferedReader(new FileReader("input.txt"));
        //out = new PrintWriter(new FileWriter("output.txt"));
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();
        in.close();
    }
    long n, x, y, c;

    boolean check(long z) {
        long res = 1 + 2 * z * (z + 1);
        long bx1 = z - x + 1;
        long by1 = z - y + 1;
        long bxn = z - n + x;
        long byn = z - n + y;

        if (bx1 > 0) {
            res -= bx1 * bx1;
        }
        if (bxn > 0) {
            res -= bxn * bxn;
        }
        if (by1 > 0) {
            res -= by1 * by1;
        }
        if (byn > 0) {
            res -= byn * byn;
        }

        if (z > x + y - 1) {
            long m = z - x - y + 1;
            res += m * (m + 1) / 2;
        }
        if (z > x + n - y) {
            long m = z - x - n + y;
            res += m * (m + 1) / 2;
        }
        if (z > n - x + y) {
            long m = z - n - y + x;
            res += m * (m + 1) / 2;
        }
        if (z > n - x + n - y + 1) {
            long m = z - 2 * n + x + y - 1;
            res += m * (m + 1) / 2;
        }
        
        return res >= c;
    }

    public void solve() throws Exception {
        n = nextLong();
        x = nextLong();
        y = nextLong();
        c = nextLong();
        long l = 0;
        long r = 2 * n;
        while (r > l) {
            long mid = (r + l) / 2;
            if (check(mid)) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        out.println(r);
    }

    public static void main(String[] args) throws Exception {
        new Example().run();
    }
}