import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Dzmitry Paulenka
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        long n = in.nextLong();
        long k = in.nextLong();
        if (n == 1) {
            out.println(0);
            return;
        }
        if (k * (k - 1) < 2 * (n - 1)) {
            out.println(-1);
            return;
        }

        long sq2 = 4 * k * k - 4 * k + 1 - 4 * (2 * n - 2);
        double sqrt = Math.sqrt(sq2);
        long sq = (long) sqrt;
        if ((sq + 1) * (sq + 1) == sq2) {
            sq = sq + 1;
        } else if ((sq - 1) * (sq - 1) == sq2) {
            sq = sq - 1;
        }

        if (sq*sq == sq2) {
            long kmin = (sq + 3) / 2;
            out.println(k - kmin + 1);
        } else {
            long km = Math.max(2, (long) ((sqrt + 3) / 2.0) - 2);
            while (((km + k - 2)*(k - km + 1) >= 2*(n-1))) {
                ++km;
            }
            out.println(k - km + 2);
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import static java.lang.Math.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Character.*;

@SuppressWarnings("unused")
public class round176B {
    static BufferedReader br = new BufferedReader(new InputStreamReader(
            System.in));
    static StringTokenizer st = new StringTokenizer("");

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

    static String next() throws Exception {
        while (true) {
            if (st.hasMoreTokens()) {
                return st.nextToken();
            }
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            st = new StringTokenizer(s);
        }
    }

    public static void main(String[] args) throws Exception {
        long n = parseLong(next());
        long k = parseLong(next());
        if(n == 1){
            System.out.println(0);
            return;
        }
        if (n <= k) {
            System.out.println(1);
            return;
        }
        if ((((k * (k + 1)) / 2) - 1) - (k - 2) < n) {
            System.out.println(-1);
        } else {
            long lo = 1;
            long hi = k + 1;
            int best = Integer.MAX_VALUE;
            while (lo < hi) {
                long mid = lo + ((hi - lo) / 2);
                long first = ((mid * (2 + (2 + (mid - 1)))) / 2) - (mid - 1);
                long last = ((mid * (k - mid + 1 + k)) / 2) - (mid - 1);
                if (n < first) {
                    hi = mid;
                } else {
                    if (n >= first && n <= last) {
                        hi = mid;
                        best = min(best, (int) mid);
                    } else
                        lo = mid + 1;
                }
            }
            System.out.println(best);
        }
    }
}


import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Pipeline
// 2013/03/23
public class P287B{
	Scanner sc=new Scanner(System.in);

	long n, k;

	void run(){
		n=sc.nextLong();
		k=sc.nextLong();
		solve();
	}

	void solve(){
		long left=-1, right=k+1;
		for(; right-left>1;){
			long m=(left+right)/2;
			long ub=k*(k+1)/2-(k-m)*(k-m+1)/2-(m-1);
			if(ub>=n){
				right=m;
			}else{
				left=m;
			}
		}
		println(""+(right>k?-1:right));
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		Locale.setDefault(Locale.US);
		new P287B().run();
	}
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class B {
	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		long n = sc.nextLong();
		int k = sc.nextInt();

		if(n==1){
			System.out.println(0);
			return;
		}
		n=n-1;
		int count = 0;
		long nextK = k-1;
		while(true){
			//System.out.println("n = " + n);

			if(nextK < 1 || (nextK <= 1 && n >1)){
				System.out.println(-1);
				return;
			}

			nextK = Math.min(n, nextK);
			if(n==nextK){
				System.out.println(count+1);
				return;
			}
			//System.out.println("nextK = " + nextK);

			//search for a of a...nextK
			long bSum = nextK * (nextK+1)/2;
			long a = nextK;
			long decrement = 1;
			while(bSum - (a-1)*a/2 <= n && a>=1){
				a-= decrement;
				decrement *= 2;
			}
			a+=decrement/2;

			//System.out.println("a = " + a);

			count += nextK-a+1;
			//System.out.println("count = " + count);
			long nDecr = bSum-a*(a-1)/2;
			//System.out.println("bSum = " + bSum);
			//System.out.println("nDecr = " + nDecr);
			n -= nDecr;
			nextK = a-1;
			if(n==0){
				System.out.println(count);
				return;
			}
		}
	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

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

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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


import	java.util.*;
public	class	Main{
	public	static	void	main(String[]args){
		Scanner	cin=new	Scanner(System.in);
		long	z=cin.nextLong()-1<<1,n=cin.nextInt(),l=-1,r=1+n,m;
		while(l<(m=l+r>>1))	if(z>(m+n-1)*(n-m))	r=m;else	l=m;
		if(0<l)	l=n-l;
		System.out.print(l);
	}
}


// practice with rainboy
import java.io.*;
import java.util.*;

public class CF256B extends PrintWriter {
	CF256B() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF256B o = new CF256B(); o.main(); o.flush();
	}

	long count(int n, int x, int y, int r) {
		long a = 2L * r * r + 2 * r + 1;
		int w;
		if ((w = 1 - (x - r)) > 0)
			a -= (long) w * w;
		if ((w = 1 - (y - r)) > 0)
			a -= (long) w * w;
		if ((w = (x + r) - n) > 0)
			a -= (long) w * w;
		if ((w = (y + r) - n) > 0)
			a -= (long) w * w;
		if ((w = r - 1 - (x - 1) - (y - 1)) > 0)
			a += (long) w * (w + 1) / 2;
		if ((w = r - 1 - (x - 1) - (n - y)) > 0)
			a += (long) w * (w + 1) / 2;
		if ((w = r - 1 - (n - x) - (y - 1)) > 0)
			a += (long) w * (w + 1) / 2;
		if ((w = r - 1 - (n - x) - (n - y)) > 0)
			a += (long) w * (w + 1) / 2;
		return a;
	}
	void main() {
		int n = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int c = sc.nextInt();
		int lower = -1, upper = c;
		while (upper - lower > 1) {
			int r = (lower + upper) / 2;
			if (count(n, x, y, r) >= c)
				upper = r;
			else
				lower = r;
		}
		println(upper);
	}
}


import java.io.*;
import java.util.*;

public class B {

	final String filename = new String("B").toLowerCase();

	int n;
	int r, c;

	void solve() throws Exception {
		n = nextInt();

		r = nextInt() - 1;
		c = nextInt() - 1;
		long count = nextLong();

		long left = -1, right = n * 2L;

		while (left < right - 1) {
			long mid = (left + right) / 2;

			if (getSq(n, r, c, mid) >= count) {
				right = mid;
			} else {
				left = mid;
			}
		}

//		for (int i = 0; i <= 10; i++) {
//			System.err.println(getSq(n, r, c, i));
//		}

		out.println(right);
	}

	long getSq(int n, int x, int y, long size) {
		long cur = (size + 1) * (size + 1) + size * size;

		cur -= get(x + size - (n - 1));
		cur -= get(y + size - (n - 1));
		cur -= get(-(x - size));
		cur -= get(-(y - size));

		cur += getCorner((x + 1) + (y + 1) - (size + 1));
		cur += getCorner((x + 1) + (n - y) - (size + 1));
		cur += getCorner((n - x) + (y + 1) - (size + 1));
		cur += getCorner((n - x) + (n - y) - (size + 1));

		return cur;
	}

	private long getCorner(long min) {
		if (min >= 0) {
			return 0;
		}
		min = -min;
		return min * (min + 1) / 2;
	}

	long get(long a) {
		if (a <= 0) {
			return 0;
		}
		return a * a;
	}

	void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			// in = new BufferedReader(new FileReader("input.txt"));
			// out = new PrintWriter("output.txt");

			solve();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

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

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

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

}


import java.util.Scanner;
public class Problem {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        int side = input.nextInt()-1;
        int x = input.nextInt()-1;
        int y = input.nextInt()-1;
        long target = input.nextLong();

        int[] to_sides = {y, side - x, side - y, x};
        int[] to_corners = {(y+1)+(side-x+1),(side-x+1)+(side-y+1),(side-y+1)+(x+1),
            (x+1)+(y+1)};
        int min = Math.min(Math.min(y, x), Math.min(side - x, side - y));
        int[] after_pass = {1, 1, 1, 1};
        int[] corner_share = {1,1,1,1};
        int steps = 0 , i;
        long init = 1 ;
        int grown = 4;
        while (init < target) {
            init += grown;
            steps++;
            if (steps >= min) {
                for (i = 0; i < 4; i++) {
                    if (steps > to_sides[i]) {
                        init -= after_pass[i];
                        after_pass[i] += 2;
                    }
                    if (steps >= to_corners[i]){
                        init += corner_share[i]++;
                        //corner_share[i]++;
                    }
                }
            }
            grown += 4;
        }
        System.out.println(steps);
    }
}


import java.util.Scanner;

public class B {
	public static final boolean DEBUG = false;
	Scanner sc;

	public void debug(Object o) {
		if (DEBUG) {
			int ln = Thread.currentThread().getStackTrace()[2].getLineNumber();
			String fn = Thread.currentThread().getStackTrace()[2].getFileName();
			System.out.println("(" + fn + ":" + ln+ "): " + o);
		}
	}

	public void pln(Object o) {
		System.out.println(o);
	}

	long getNumber(int x, int y, int n, int m) {
		int n1 = Math.max(0, x + m - n);
		int n2 = Math.max(0, y + m - n);
		int n3 = Math.max(0, 1 - (x - m));
		int n4 = Math.max(0, 1 - (y - m));

		int n12 = Math.max(0, n1 + n2 - m - 1);
		int n23 = Math.max(0, n2 + n3 - m - 1);
		int n34 = Math.max(0, n3 + n4 - m - 1);
		int n41 = Math.max(0, n4 + n1 - m - 1);

//		debug(n1 + " " + n2 + " " + n3 + " " + n4);
//		debug(n12 + " " + n23 + " " + n34 + " " + n41);

		int m1 = m+1;
		long nr = 1 + ((long)m1)*m1*2 - m1*2;
		nr -= ((long)n1)*n1 + ((long)n2)*n2 + ((long)n3)*n3 + ((long)n4)*n4;
		nr += ((long)n12)*(n12+1)/2 + ((long)n23)*(n23+1)/2 + ((long)n34)*(n34+1)/2 + ((long)n41)*(n41+1)/2;

		return nr;
	}
	public void run() {
//		pln(getNumber(1, 1, 10000, 10000000));
//		pln(getNumber(1000, 1000, 1000, 1000000));
//		if (true) return;

		sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int c = sc.nextInt();

		if (c <= 1) {
			pln(0);
			return;
		}

		int ll = 0;
		int rr = 2*n+20;

		while(true) {
			int m = (ll+rr) / 2;
			if (getNumber(x, y, n, m) >= c) {
				rr = m;
			}
			else {
				ll = m;
			}
//			debug(ll + " " + rr);

			if (rr - ll < 3) {
				for (int m2=ll; m2<=rr; m2++) {
					if (getNumber(x, y, n, m2) >= c) {
						pln(m2);
						return;
					}
				}
			}
		}

	}
	public static void main(String[] args) {
		B t = new B();
		t.run();
	}
}


//package codeforces.cf156;
import java.io.*;
import java.util.Arrays;

public class ProblemB {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    long[] readInts() throws IOException {
        String[] strings = reader.readLine().split(" ");
        long[] ints = new long[strings.length];
        for(int i = 0; i < ints.length; i++) {
            ints[i] = Long.parseLong(strings[i]);
        }
        return ints;
    }

    long foo(long a) {
        return a > 0 ? a * a : 0;
    }
    long boo(long a) {
        return a <= 0 ? 0 : a * (a + 1) / 2;
    }

    void solve() throws IOException {
        long[] tt = readInts();
        long n = tt[0];
        long x = tt[1];
        long y = tt[2];
        long c = tt[3];
        long lo = -1, hi = 2 * 1000 * 1000 * 1000 + 2;
//        hi = 5;
        while(hi - lo > 1) {
            long m = (lo + hi) / 2;
            long s = 2 * m * m + 2 * m + 1;
            s -= foo(m - x + 1) + foo(m - y + 1) + foo(x + m - n) + foo(y + m - n);
            s += boo(m + 1 - (n + 1 + n + 1 - x - y)) + boo(m + 1 - (n + 1 - x + y)) + boo(m + 1 - (n + 1 - y + x))
                    + boo(m + 1 - (x + y));
            if(s < c) lo = m;
            else hi = m;
        }
        writer.println(hi);
        writer.flush();
    }

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


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;
    }
}


//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;
    }
}


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);
    }
}

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//


import java.io.OutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author BSRK Aditya (bsrkaditya@gmail.com)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {

    long n,x,y,c;

	public void solve(int testNumber, InputReader in, OutputWriter out) {
        n = in.readInt();
        x = in.readInt();
        y = in.readInt();
        c = in.readInt();

        int lo = -1;
        int hi = (int)c;

        while(lo+1<hi) {
            int mi = (lo+hi)/2;
            if(P(mi)) hi = mi; else lo = mi;
        }
        out.printLine(hi);
	}

    private boolean P(int t) {
        if(t == -1) return false;

        int ans = 0;
        for(long i = Math.max(1,y-t); i <= Math.min(y+t,n); ++i) {
            long a = Math.abs(y - i);
            ans += D(Math.max(1,x-t+a), Math.min(n,x+t-a));
            if(ans >= c) return true;
        }

        return false;
    }

    private long D(long a, long b) {
        return b - a + 1;
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

}


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();
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Main implements Runnable {
    private BufferedReader br;
    private StringTokenizer tok;
    private PrintWriter out;

    static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    int[] a;
    int[] b;
    int[] p;

    int getCeils(int id, int step) {
        if (step > a[id] + b[id] - 1) {
            return 0;
        }
        if (a[id] < b[id]) {
            if (step < a[id]) {
                return step;
            }
            if (step >= a[id] && step <= b[id]) {
                return a[id];
            }
            ++p[id];
            return a[id] - p[id];
        } else {
            if (step < b[id]) {
                return step;
            }
            if (step >= b[id] && step <= a[id]) {
                return b[id];
            }
            ++p[id];
            return b[id] - p[id];
        }
    }

    void solve() throws IOException {
        int n = nextInt(), x = nextInt(), y = nextInt(), c = nextInt();
        long s = 1;
        int step = 0;
        a = new int[4];
        b = new int[4];
        p = new int[4];
        a[0] = x - 1; b[0] = n - y;
        a[1] = x - 1; b[1] = y - 1;
        a[2] = n - x; b[2] = y - 1;
        a[3] = n - x; b[3] = n - y;
        int xf = x + 1, xb = x - 1, yf = y + 1, yb = y - 1;
        while (s < c) {
            ++step;
            if (xf <= n) {
                ++s;
                ++xf;
            }
            if (xb > 0) {
                ++s;
                --xb;
            }
            if (yf <= n) {
                ++s;
                ++yf;
            }
            if (yb > 0) {
                ++s;
                --yb;
            }
            if (step == 1) {
                continue;
            }
            for (int i = 0; i < 4; ++i) {
                s += getCeils(i, step - 1);
            }
        }
        out.println(step);
    }

    public void run() {
        try {
            if (ONLINE_JUDGE) {
                br = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                br = new BufferedReader(new FileReader(new File("input.txt")));
                out = new PrintWriter(new File("output.txt"));
            }
            solve();
            br.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

    String nextString() throws IOException {
        return nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }
}


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());
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main {

	private void solve() throws IOException {
		int n = nextInt();
		int x = nextInt();
		int y = nextInt();
		int c = nextInt();

		int lux = x;
		int luy = y + 1;

		int rux = x + 1;
		int ruy = y;

		int ldx = x - 1;
		int ldy = y;

		int rdx = x;
		int rdy = y - 1;

		int k = 1;
		int res = 0;
		while (k < c) {
			lux--;
			luy--;
			rux--;
			ruy++;
			rdx++;
			rdy++;
			ldx++;
			ldy--;
			int p = 0;
			p += lu(x - 1, luy, lux, y, n);
			p += ru(x, ruy, rux, y + 1, n);
			p += ld(x, ldy, ldx, y - 1, n);
			p += rd(x + 1, rdy, rdx, y, n);
			k += p;
			res++;
		}

		println(res);
	}

	private int lu(int x1, int y1, int x2, int y2, int n) {
		if (y1 > 0 && x2 > 0) {
			return x1 - x2 + 1;
		} else if (y1 > 0 && x2 < 1) {
			return x1;
		} else if (y1 < 1 && x2 > 0) {
			return y2;
		} else if (x1 - (1 - y1) > 0) {
			return lu(x1 - (1 - y1), 1, x2, y2, n);
		} else {
			return 0;
		}
	}

	private int ru(int x1, int y1, int x2, int y2, int n) {
		if (y1 <= n && x2 > 0) {
			return x1 - x2 + 1;
		} else if (y1 <= n && x2 < 1) {
			return x1;
		} else if (y1 > n && x2 > 0) {
			return n - y2 + 1;
		} else if (x1 - (y1 - n) > 0) {
			return ru(x1 - (y1 - n), n, x2, y2, n);
		} else {
			return 0;
		}
	}

	private int ld(int x1, int y1, int x2, int y2, int n) {
		if (y1 > 0 && x2 <= n) {
			return x2 - x1 + 1;
		} else if (y1 > 0 && x2 > n) {
			return n - x1 + 1;
		} else if (y1 < 1 && x2 <= n) {
			return y2;
		} else if (x1 + (1 - y1) <= n) {
			return ld(x1 + (1 - y1), 1, x2, y2, n);
		} else {
			return 0;
		}
	}

	private int rd(int x1, int y1, int x2, int y2, int n) {
		if (y1 <= n && x2 <= n) {
			return x2 - x1 + 1;
		} else if (y1 <= n && x2 > n) {
			return n - x1 + 1;
		} else if (y1 > n && x2 <= n) {
			return n - y2 + 1;
		} else if (x1 + (y1 - n) <= n) {
			return rd(x1 + (y1 - n), n, x2, y2, n);
		} else {
			return 0;
		}
	}

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

	@SuppressWarnings("unused")
	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	@SuppressWarnings("unused")
	private double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	@SuppressWarnings("unused")
	private long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	@SuppressWarnings("unused")
	private void println(Object o) {
		writer.println(o);
	}

	@SuppressWarnings("unused")
	private void print(Object o) {
		writer.print(o);
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer st;

	private void run() throws IOException {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		reader = new BufferedReader(new InputStreamReader(System.in));
		writer = new PrintWriter(System.out);
		solve();
		writer.close();
		System.err.println(System.currentTimeMillis() - time);
	}

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

}


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);
	}
}


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);
		}

	}

}


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;
	}

}


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;
	}
}


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);
    }
}


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());
	    }
	}

}


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();
    }
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
	public void solve(int testNumber, InputReader in, OutputWriter out) {

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

        long tl, tr, tt = -1, t;
        tl = 0;
        tr = (long) 4e9;
        while(tl<tr){
            t = (tl+tr)>>1;

            long cc = f(n, t, x, y);
            if(cc>=c){
                tt = t;
                tr = t;
            }else tl = t+1;
        }

        out.writeln(tt);
	}

    public static long f(long n, long t, long x, long y){

        long res = (t*t+t)/2 * 4 + 1;
        long s;

        if(x-t<1){
            s = t-x+1;
            res -= s*s;
        }
        if(y-t<1){
            s = t-y+1;
            res -= s*s;
        }
        if(x+t>n){
            s = x+t-n;
            res -= s*s;
        }
        if(y+t>n){
            s = y+t-n;
            res -= s*s;
        }

        s = t-(Math.abs(x-1)+Math.abs(y-1))-1;
        if(s>0) res+=(s*s+s)/2;

        s = t-(Math.abs(x-1)+Math.abs(n-y))-1;
        if(s>0) res+=(s*s+s)/2;

        s = t-(Math.abs(n-x)+Math.abs(n-y))-1;
        if(s>0) res+=(s*s+s)/2;

        s = t-(Math.abs(n-x)+Math.abs(y-1))-1;
        if(s>0) res+=(s*s+s)/2;

        return res;
    }
}

class InputReader{
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next(){
        while (tokenizer == null || !tokenizer.hasMoreTokens()){
            try{
                tokenizer = new StringTokenizer(reader.readLine());
            }catch (IOException e){
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

    }

class OutputWriter{
    private PrintWriter out;

    public OutputWriter(Writer out){
        this.out = new PrintWriter(out);
    }

    public OutputWriter(OutputStream out){
        this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));
    }

    public void write(Object ... o){
        for(Object x : o) out.print(x);
    }

    public void writeln(Object ... o){
        write(o);
        out.println();
    }

    public void close(){
        out.close();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Alex
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        int n;
        int startrow;
        int startcol;
        long want;

        boolean check(long time) {
            long max = (long) 2 * time * (time + 1) + 1;
            long highest = startrow - time;
            if(highest < 0) {
                max -= Math.abs(highest) * Math.abs(highest);
            }
            long lowest = startrow + time;
            if(lowest >= n) {
                max -= Math.abs(lowest - n + 1) * Math.abs(lowest - n + 1);
            }
            long leftmost = startcol - time;
            if(leftmost < 0) {
                max -= Math.abs(leftmost) * Math.abs(leftmost);
            }
            long rightmost = startcol + time;
            if(rightmost >= n) {
                max -= Math.abs(rightmost - n + 1) * Math.abs(rightmost - n + 1);
            }
            long upperright = time - (startrow + 1) - (n - startcol);
            if(upperright >= 0) {
                max += (upperright + 1) * (upperright + 2) / 2;
            }
            long lowerright = time - (n - startrow) - (n - startcol);
            if(lowerright >= 0) {
                max += (lowerright + 1) * (lowerright + 2) / 2;
            }
            long upperleft = time - (startrow + 1) - (startcol + 1);
            if(upperleft >= 0) {
                max += (upperleft + 1) * (upperleft + 2) / 2;
            }
            long lowerleft = time - (n - startrow) - (startcol + 1);
            if(lowerleft >= 0) {
                max += (lowerleft + 1) * (lowerleft + 2) / 2;
            }
            return max >= want;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.readInt();
            startrow = in.readInt() - 1;
            startcol = in.readInt() - 1;
            want = in.readLong();
            long low = 0, high = 2 * n;
            while(low < high) {
                long mid = (low + high) / 2;
                if(check(mid)) high = mid;
                else low = mid + 1;
            }
            out.printLine(low);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if(numChars == -1)
                throw new InputMismatchException();
            if(curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch(IOException e) {
                    throw new InputMismatchException();
                }
                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while(isSpaceChar(c))
                c = read();
            int sgn = 1;
            if(c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if(c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while(!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while(isSpaceChar(c))
                c = read();
            int sgn = 1;
            if(c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if(c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while(!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if(filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }
}


import java.util.*;
import java.math.*;
import java.io.*;
public class b2 {
public static void main(String[] args) throws IOException
{
    input.init(System.in);
    int n = input.nextInt(), x = input.nextInt(), y = input.nextInt(),  c = input.nextInt();
    long lo = 0, hi = 2*n;
    while(hi > lo+1)
    {
        long mid = (hi+lo)/2;
        long covered = go(n, x, y, mid);
        if(covered < c)
            lo = mid;
        else hi = mid;
    }
    if(go(n, x, y, lo) < c) lo++;
    System.out.println(lo);

}
public static long go(int n, int x, int y, long d)
{
    long res = d*d + (d+1)*(d+1);
    long maxLeft = d - x;
    if(maxLeft >= 0) res -= (maxLeft+1)*(maxLeft+1);
    long maxTop = d - y;
    if(maxTop >= 0) res -= (maxTop+1)*(maxTop+1);
    long maxRight = d - (n+1-x);
    if(maxRight >= 0) res -= (maxRight+1)*(maxRight+1);
    long maxBot = d - (n+1-y);
    if(maxBot >= 0) res -= (maxBot+1)*(maxBot+1);
    long maxTopLeft = d - (x+y);
    if(maxTopLeft >= 0) res += (maxTopLeft+1)*(maxTopLeft+2)/2;
    long maxTopRight = d - ((n+1-x)+y);
    if(maxTopRight >= 0) res += (maxTopRight+1)*(maxTopRight+2)/2;
    long maxBotLeft = d - (x+(n+1-y));
    if(maxBotLeft >= 0) res += (maxBotLeft+1)*(maxBotLeft+2)/2;
    long maxBotRight = d - ((n+1-x)+(n+1-y));
    if(maxBotRight >= 0) res += (maxBotRight+1)*(maxBotRight+2)/2;
    return res;

}
public static class input {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

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

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

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

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


import java.io.*;
import java.util.*;

public class ProblemB {
    InputReader in; PrintWriter out;
    void solve() {
        int n = in.nextInt();
        int x = in.nextInt();
        int y = in.nextInt();
        int c = in.nextInt();
        int cur = 1;
        for (int k = 1; k <= c; k++) {
//          out.println(k + " " + cur);
            if (cur >= c) {
                out.println(k - 1);
                return;
            }
            //x + i; y + k - i;
            int iLess = n - x;
            int iMore = y + k - n;
            if (iLess > k)
                iLess = k;
            if (iMore < 0)
                iMore = 0;
//          out.println("iless == " + iLess + " imore == " + iMore);
            int add = iLess - iMore + 1;
            if (add < 0)
                add = 0;
//          out.println("add == " + add);
            cur += add;
            //x + i; y - k + i;
            iLess = n - x;
            iMore = 1 + k - y;
            if (iLess > k)
                iLess = k;
            if (iMore < 0)
                iMore = 0;
//          out.println("iless == " + iLess + " imore == " + iMore);
            add = iLess - iMore + 1;
            if (add < 0)
                add = 0;
//          out.println("add == " + add);
            cur += add;
            //x - i; y - k + i;
            iLess = x - 1;
            iMore = 1 + k - y;
            if (iLess > k)
                iLess = k;
            if (iMore < 0)
                iMore = 0;
//          out.println("iless == " + iLess + " imore == " + iMore);
            add = iLess - iMore + 1;
            if (add < 0)
                add = 0;
//          out.println("add == " + add);
            cur += add;
            //x - i; y + k - i;
            iLess = x - 1;
            iMore = y + k - n;
            if (iLess > k)
                iLess = k;
            if (iMore < 0)
                iMore = 0;
//          out.println("iless == " + iLess + " imore == " + iMore);
            add = iLess - iMore + 1;
            if (add < 0)
                add = 0;
//          out.println("add == " + add);
            cur += add;
//          out.println("cur == " + cur);
            //delete double
            if (x + k <= n)
                cur--;
            if (y - k >= 1)
                cur--;
            if (x - k >= 1)
                cur--;
            if (y + k <= n)
                cur--;
        }
//      throw new RuntimeException();
    }

    ProblemB(){
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        try {
            if (oj) {
                in = new InputReader(System.in);
                out = new PrintWriter(System.out);
            }
            else {
                Writer w = new FileWriter("output.txt");
                in = new InputReader(new FileReader("input.txt"));
                out = new PrintWriter(w);
            }
        } catch(Exception e) {
            throw new RuntimeException(e);
        }
        solve();
        out.close();
    }
    public static void main(String[] args){
        new ProblemB();
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public InputReader(FileReader fr) {
        reader = new BufferedReader(fr);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.concurrent.LinkedBlockingQueue;

public class D {

    static long n;
    static long x;
    static long y;
    static long c;
    static long f(long t){
        long s=0;
        if(t==0)
            s=1;
        else{
            s=(4+4*t)/2*t+1;
        }
        if(x+t>n){
            long c=x+t-n;
            s-=c*c;
        }
        if(x-t<=0){
            long c=t-x+1;
            s-=c*c;
        }
        if(y+t>n){
            long c=y+t-n;
            s-=c*c;
        }
        if(y-t<=0){
            long c=t-y+1;
            s-=c*c;
        }
        if(t>x+y-1){
            long m=t-x-y+1;
            s+=m*(m+1)/2;
        }
        if (t>x+n-y) {
            long m=t-x-n+y;
            s+=m*(m+1)/2;
        }
        if (t>n-x+y) {
            long m=t-n-y+x;
            s+=m*(m+1)/2;
        }
        if (t>n-x+n-y+1) {
            long m=t-2*n+x+y-1;
            s+=m*(m+1)/2;
        }
        return s;
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);

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

        long l=0;
        long r=2*n;
        while(l<r){
            long m=(l+r)/2;
            long ff=f(m);
            if(ff<c){
                l=m+1;
            }
            else{
                r=m;
            }
        }
        out.println(l);
        out.close();
    }

}


//package round156;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class B {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni(), x = ni(), y = ni();
		long c = nl();
		int l = x-1, r = n-x;
		int u = y-1, d = n-y;
		long low = -1, high = 2*n+3;
		while(high - low > 1){
			long t = (high + low) / 2;
			long num = diag(t, l, u) + diag(t, r, u) + diag(t, l, d) + diag(t, r, d)
					+ hor(t, l) + hor(t, r) + hor(t, u) + hor(t, d) + 1;
			if(num >= c){
				high = t;
			}else{
				low = t;
			}
		}
		out.println(high);
	}

	long hor(long t, int n)
	{
		return Math.min(t, n);
	}

	long diag(long t, long r, long u)
	{
		if(t > 2+r+u-2){
			return r*u;
		}

		long ret = t*(t-1)/2;
		if(t > r)ret -= (t-r)*(t-r-1)/2;
		if(t > u)ret -= (t-u)*(t-u-1)/2;
		return ret;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import static java.lang.Math.*;
import java.io.*;
import java.util.*;

public class A {
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

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

	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}

	boolean bit(int m, int i) {
		return (m & (1 << i)) > 0;
	}

	int n, x, y, c;

 	long cnt(int m) {
 		long ret=0;
 		for (int i=max(1, y-m); i<=min(n, y+m); i++) {
 			int x1 = max(1, x - (m - abs(i - y)));
 			int x2 = min(n, x + (m - abs(i - y)));
 			ret += x2 - x1 + 1;
 		}
 		return ret;
 	}

	public void run() {
		in  = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		n = nextInt();
		x = nextInt();
		y = nextInt();
		c = nextInt();

		int l = 0, r = 1000000;
		int ans=0;
		while (l <= r) {
			int m = (l+r) / 2;
			if (cnt(m) >= c) {
				ans = m;
				r = m-1;
			} else l=m+1;
		}

		out.println(ans);

		out.close();
	}

	class Pair implements Comparable<Pair> {
		long x,y;
		public Pair(long x, long y) {
			this.x=x;
			this.y=y;
		}
		public int compareTo(Pair o) {
			if (x != o.x) return sign(o.x - x);
			return sign(y - o.y);
		}
	}

	int sign(long x) {
		if (x < 0) return -1;
		if (x > 0) return 1;
		return 0;
	}

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


import java.io.*;
import java.util.*;

public class MrBenderAndSquare {

	static long n, x, y, c;

	public static void main(String[] args) throws IOException {
		Kattio io = new Kattio(System.in);
		n = io.getLong();
		x = io.getLong();
		y = io.getLong();
		c = io.getLong();
//		for (int i = 0; i < 10; i++) io.println(f(i));
//		io.println();
		long lo = 0;
		long hi = c;
		while (lo < hi) {
			long mid = lo + (hi - lo) / 2;
			if (f(mid) >= c) {
				hi = mid;
			} else {
				lo = mid + 1;
			}
		}
		io.println(lo);
		io.close();
	}

	static long f(long t) {
		long res = 0;
		// Sides
		long left = Math.max(0, t - (x - 1));
		res -= left*left;
		long right = Math.max(0, t - (n - x));
		res -= right*right;
		long up = Math.max(0, t - (y - 1));
		res -= up*up;
		long down = Math.max(0, t - (n - y));
		res -= down*down;
		// Middle
		res += 1 + 2*t*(t+1);
		// Corners
		long upLeft = Math.max(0, t - (x + y) + 1);
		long upRight = Math.max(0, t - (n - x + 1 + y) + 1);
		long downLeft = Math.max(0, t - (x + n - y + 1) + 1);
		long downRight = Math.max(0, t - (n - x + 1 + n - y + 1) + 1);
		res += upLeft * (upLeft + 1) / 2;
		res += upRight * (upRight + 1) / 2;
		res += downLeft * (downLeft + 1) / 2;
		res += downRight * (downRight + 1) / 2;
		return res;
	}

	static class Kattio extends PrintWriter {
		public Kattio(InputStream i) {
			super(new BufferedOutputStream(System.out));
			r = new BufferedReader(new InputStreamReader(i));
		}
		public Kattio(InputStream i, OutputStream o) {
			super(new BufferedOutputStream(o));
			r = new BufferedReader(new InputStreamReader(i));
		}

		public boolean hasMoreTokens() {
			return peekToken() != null;
		}

		public int getInt() {
			return Integer.parseInt(nextToken());
		}

		public double getDouble() {
			return Double.parseDouble(nextToken());
		}

		public long getLong() {
			return Long.parseLong(nextToken());
		}

		public String getWord() {
			return nextToken();
		}

		private BufferedReader r;
		private String line;
		private StringTokenizer st;
		private String token;

		private String peekToken() {
			if (token == null)
				try {
					while (st == null || !st.hasMoreTokens()) {
						line = r.readLine();
						if (line == null) return null;
						st = new StringTokenizer(line);
					}
					token = st.nextToken();
				} catch (IOException e) { }
				return token;
		}

		private String nextToken() {
			String ans = peekToken();
			token = null;
			return ans;
		}
	}

}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int side = in.readInt();
		int row = in.readInt() - 1;
		int column = in.readInt() - 1;
		int required = in.readInt();
		long left = 0;
		long right = 2 * side - 2;
		while (left < right) {
			long current = (left + right) / 2;
			long result = calculate(row, column, current) + calculate(column, side - row - 1, current) +
				calculate(side - row - 1, side - column - 1, current) + calculate(side - column - 1, row, current) + 1;
			if (result >= required)
				right = current;
			else
				left = current + 1;
		}
		out.printLine(left);
	}

	private long calculate(int row, int column, long current) {
		column++;
		long total = 0;
		long mn = Math.min(row, column);
		long mx = Math.max(row, column);
		if (current <= mn)
			return current * (current + 1) / 2;
		total += mn * (mn + 1) / 2;
		current -= mn;
		mx -= mn;
		if (current <= mx)
			return total + mn * current;
		total += mn * mx;
		current -= mx;
		if (current < mn)
			return total + (mn - 1) * mn / 2 - (mn - current - 1) * (mn - current) / 2;
		return total + (mn - 1) * mn / 2;
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	public static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

    public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{

    public static long howMany(long n, long x, long y, long s){
        long res = 0;
        int cnt = 0;
        long[] px = new long[9];
        long[] py = new long[9];
        if(x - s < 1){
            px[cnt] = 1;
            py[cnt++] = y-x+s+1 <= n ? y-x+s+1 : n;
            px[cnt] = 1;
            py[cnt++] = x+y-s-1 > 0? x+y-s-1: 1;
            res += 6;
        }else{
            px[cnt] = x-s;
            py[cnt++] = y;
            res += 2;
        }

        if(y - s < 1){
            py[cnt] = 1;
            px[cnt++] = x+y-s-1 > 0 ? x+y-s-1 : 1;
            py[cnt] = 1;
            px[cnt++] = x-(y-s)+1 <= n ? x-y+s+1: n;
            res += 6;
        }else{
            px[cnt] = x;
            py[cnt++] = y-s;
            res += 2;
        }

        if(x + s > n){
            px[cnt] = n;
            py[cnt++] = y-(x+s)+n > 0 ? y-(x+s)+n : 1;
            px[cnt] = n;
            py[cnt++] = x+s+y - n <= n ? x+s+y-n : n;
            res += 6;
        }else{
            px[cnt] = x+s;
            py[cnt++] = y;
            res += 2;
        }

        if(y + s > n){
            py[cnt] = n;
            px[cnt++] = x+y+s-n <= n? x+y+s-n : n;
            py[cnt] = n;
            px[cnt++] = n-(y+s-x) > 0 ? n-(y+s-x) :1;
            res += 6;
        }else{
            px[cnt] = x;
            py[cnt++] = y+s;
            res += 2;
        }

        px[cnt] = px[0];
        py[cnt] = py[0];

        long ret = 0;
        long sum = 0;
        for(int i = 0; i < cnt; i++){
            ret += px[i]*py[i+1]-py[i]*px[i+1];
            sum += Math.max(Math.abs(px[i]-px[i+1]), Math.abs(py[i]-py[i+1]))+1;
        }
        return (4*ret + 4*sum - res)/8;
    }

    public static void main(String[] args) throws Exception{
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer str = new StringTokenizer(r.readLine());
        int n = Integer.parseInt(str.nextToken());
        int x = Integer.parseInt(str.nextToken());
        int y = Integer.parseInt(str.nextToken());
        long c = Long.parseLong(str.nextToken());
        if(c == 1){
            System.out.println(0);
            return;
        }
        long high = 1;
        while(howMany(n, x, y, high) < c){
            high <<= 1;
        }
        long low = high>>1;
        while(high - low > 1){
            long med = (high+low)/2;
            if(howMany(n, x, y, med) < c){
                low = med;
            }else{
                high = med;
            }
        }
        System.out.println(high);
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class taskB {

    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        taskB solver = new taskB();
        solver.open();
        long time = System.currentTimeMillis();
        solver.solve();
        if (!"true".equals(System.getProperty("ONLINE_JUDGE"))) {
            System.out.println("Spent time: "
                    + (System.currentTimeMillis() - time));
            System.out.println("Memory: "
                    + (Runtime.getRuntime().totalMemory() - Runtime
                    .getRuntime().freeMemory()));
        }
        solver.close();
    }

    public void open() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    public String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null)
                return null;
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

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

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

    public double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }

    long n, x, y, c;

    long sq(long n) {
        if (n <= 0) return 0;
        return n * n;
    }

    long lrsp(long len, long max) {
        long cnt = Math.min(len, max);
        long arpr = (1 + cnt) * cnt / 2;
        if (len > max) arpr += (len - max) * max;
        return arpr;
    }

    long onn(long len) {
        long up, down, left, right;
        long toup = x - 1, todown = n - x, toleft = y - 1, toright = n - y;
        left = Math.min(toleft, len);
        right = Math.min(toright, len);
        down = up = sq(len);
        up -= sq(len - toup);
        down -= sq(len - todown);
        len--;
        if (toright < len) {
            up -= lrsp(len - toright, toup);
            down -= lrsp(len - toright, todown);
        }
        if (toleft < len) {
            up -= lrsp(len - toleft, toup);
            down -= lrsp(len - toleft, todown);
        }

        return 1 + up + down + left + right;
    }

    public void solve() throws NumberFormatException, IOException {
        n = nextInt();
        x = nextInt();
        y = nextInt();
        c = nextInt();
        long down = 0, up = 2 * n + 13;
        while (up - down > 2) {
            long tmp = (up + down) / 2;
            if (onn(tmp) >= c) up = tmp;
            else down = tmp;
        }
        if (onn(down) >= c) out.println(down);
        else if (onn(down + 1) >= c) out.println(down + 1);
        else if (onn(down + 2) >= c) out.println(down + 2);
        else out.println(down + 3);
    }

    public void close() {
        out.flush();
        out.close();
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class Solution
{
    static long n, x, y, c;

    static boolean can (long len)
    {
        BigInteger blen = BigInteger.valueOf(len);

        //BigInteger sum = blen.multiply(blen.add(BigInteger.ONE)).multiply(blen.shiftLeft(1).add(BigInteger.ONE)).divide(BigInteger.valueOf(6));
        BigInteger sum = BigInteger.ONE;
        sum = sum.add(blen.multiply(blen.add(BigInteger.ONE)).shiftLeft(1));

        long a1 = Math.max(0, len - x);
        sum = sum.subtract(BigInteger.valueOf(a1).multiply(BigInteger.valueOf(a1)));

        long a2 = Math.max(0, len - y);
        sum = sum.subtract(BigInteger.valueOf(a2).multiply(BigInteger.valueOf(a2)));

        long a3 = Math.max(0, len - (n - 1 - x));
        sum = sum.subtract(BigInteger.valueOf(a3).multiply(BigInteger.valueOf(a3)));

        long a4 = Math.max(0, len - (n - 1 - y));
        sum = sum.subtract(BigInteger.valueOf(a4).multiply(BigInteger.valueOf(a4)));

        if (y - a1 + 1 < 0)
        {
            long b1 = Math.abs(y - a1 + 1);
            sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf(b1 + 1)).shiftRight(1));
        }

        if (y - a3 + 1 < 0)
        {
            long b1 = Math.abs(y - a3 + 1);
            sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf(b1 + 1)).shiftRight(1));
        }

        if (y + a1 - 1 >= n)
        {
            long b1 = y + a1 - n;
            sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf(b1 + 1)).shiftRight(1));
        }

        if (y + a3 - 1 >= n)
        {
            long b1 = y + a3 - n;
            sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf(b1 + 1)).shiftRight(1));
        }

        return sum.compareTo(BigInteger.valueOf(c)) >= 0;
    }

    public static void main (String argv[])
    {
        Scanner in = new Scanner(System.in);

        n = in.nextLong();
        x = in.nextLong();
        y = in.nextLong();
        c = in.nextLong();
        x--; y--;

        long lf = 0, rg = 2 * 1000 * 1000 * 1000 + 3;

        while (lf != rg)
        {
            long mid = (lf + rg) >> 1;

            if (can(mid))
                rg = mid;
            else
                lf = mid + 1;
        }

        System.out.println(lf);
    }
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Solution {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

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

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	long fang(int s, int x, int y) {
		if (x > y) { int t = x; x = y; y = t; }
		if (s + 1 <= x) {
			return (long)(s + 1) * (s + 2) / 2;
		}
		if (s + 1 <= y) {
			return (long)x * (x + 1) / 2 + (long)(s + 1 - x) * x;
		}
		if (s + 1 >= x + y - 1) {
			return (long)x * y;
		}
		long q = x + y - 1 - s - 1;
		return (long)x * y - q * (q + 1) / 2;
	}

	long f(int s, int n, int x, int y) {
		long ans = fang(s, n - x + 1, n - y + 1) + fang(s, n - x + 1, y) + fang(s, x, n - y + 1) + fang(s, x, y);
		ans -= Math.min(s + 1, n - x + 1) + Math.min(s + 1, x) + Math.min(s + 1, n - y + 1) + Math.min(s + 1, y);
		return ans + 1;
	}

	void solve() throws Exception {
		int n = nextInt();
		int x = nextInt(), y = nextInt();
		long c = nextInt();
		if (c == 1) {
			out.println(0);
			return;
		}
		int bg = 0, ed = 2 * n;
		while (ed > bg + 1) {
			int mm = (bg + ed) / 2;
			if (f(mm, n, x, y) >= c) ed = mm; else bg = mm;
		}
		out.println(ed);
	}

	void run() {
		try {
			Locale.setDefault(Locale.US);
//			in = new BufferedReader(new FileReader("input.txt"));
//			out = new PrintWriter("output.txt");
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Solution().run();
	}

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.TreeSet;

public class B {
	public static void main(String[] args) {
		MScanner sc = new MScanner();
		PrintWriter out = new PrintWriter(System.out);

		long N = sc.nextLong();
		long X = sc.nextLong();
		long Y = sc.nextLong();
		long C = sc.nextLong();

		long low = 0;
		long high = N*2;
		long mid = 0;
		long ans = 0;
		while (low <= high) {
			mid = (low + high) >> 1;
			long painted = F(mid, X-1, Y-1, N);
			if (painted < C) {
				low = mid + 1;
			} else {
				ans = mid;
				high = mid - 1;
			}
		}
		out.println(ans);
		out.close();

	}

	private static long F(long mid, long x, long y, long n) {
		long base = 2 * mid * (mid + 1) + 1;
		base -= excess(mid - x);
		base -= excess(mid - y);
		base -= excess(mid - (n-1-x));
		base -= excess(mid - (n-1-y));
		base += corner(mid - (x + y + 1));
		base += corner(mid - (x + (n - y - 1) + 1));
		base += corner(mid - ((n - x - 1) + y + 1));
		base += corner(mid - (1 + (n - 1 - y) + (n - 1 - x)));
		return base;
	}

	private static long corner(long a) {
		if (a < 0)return 0;
		return (a * a + a) >> 1;
	}

	private static long excess(long thing) {
		if(thing<0)return 0;
		return thing * thing;
	}

	static class MScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public MScanner() {
			stream = System.in;
			// stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

		int[] nextInt(int N) {
			int[] ret = new int[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextInt();
			return ret;
		}

		int[][] nextInt(int N, int M) {
			int[][] ret = new int[N][M];
			for (int a = 0; a < N; a++)
				ret[a] = nextInt(M);
			return ret;
		}

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

		long[] nextLong(int N) {
			long[] ret = new long[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextLong();
			return ret;
		}

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

		double[] nextDouble(int N) {
			double[] ret = new double[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextDouble();
			return ret;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] next(int N) {
			String[] ret = new String[N];
			for (int a = 0; a < N; a++)
				ret[a] = next();
			return ret;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

		String[] nextLine(int N) {
			String[] ret = new String[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextLine();
			return ret;
		}

	}
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Main implements Runnable {

	int n;

	boolean inBound (int x, int y) {
		return x >= 1 && y >= 1 && x <= n && y <= n;
	}

	void solve() throws Exception {
		n = sc.nextInt();
		int y = sc.nextInt();
		int x = sc.nextInt();
		int c = sc.nextInt();

		int yu = y;
		int yd = y;
		int xl = x;
		int xr = x;

		int current = 1;
		int time = 0;
		while (current < c) {
			time++;
			yu--;
			yd++;
			xl--;
			xr++;
			// left - up
			{
				int cur = time - 1;
				if (yu < 1) {
					cur -= (-yu);
				}
				if (xl < 1) {
					cur -= (-xl);
				}
				if (cur > 0) {
					current += cur;
				}
			}
			// right - up
			{
				int cur = time - 1;
				if (yu < 1) {
					cur -= (-yu);
				}
				if (xr > n) {
					cur -= (xr - n - 1);
				}
				if (cur > 0) {
					current += cur;
				}
			}
			// left - down
			{
				int cur = time - 1;
				if (yd > n) {
					cur -= (yd - n - 1);
				}
				if (xl < 1) {
					cur -= (-xl);
				}
				if (cur > 0) {
					current += cur;
				}
			}
			// right - down
			{
				int cur = time - 1;
				if (yd > n) {
					cur -= (yd - n - 1);
				}
				if (xr > n) {
					cur -= (xr - n - 1);
				}
				if (cur > 0) {
					current += cur;
				}
			}

			if (inBound(x, yd)) current++;
			if (inBound(x, yu)) current++;
			if (inBound(xl, y)) current++;
			if (inBound(xr, y)) current++;
		}

		out.println(time);
	}

	BufferedReader in;
	PrintWriter out;
	FastScanner sc;

	static Throwable uncaught;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable t) {
			Main.uncaught = t;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread t = new Thread(null, new Main(), "", (1 << 26));
		t.start();
		t.join();
		if (uncaught != null) {
			throw uncaught;
		}
	}

}

class FastScanner {

	BufferedReader reader;
	StringTokenizer strTok;

	public FastScanner(BufferedReader reader) {
		this.reader = reader;
	}

	public String nextToken() throws IOException {
		while (strTok == null || !strTok.hasMoreTokens()) {
			strTok = new StringTokenizer(reader.readLine());
		}
		return strTok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

}


import java.util.*;
import java.math.*;
import java.io.*;

public class Main
	{
	public static void main(String args[]) throws IOException
		{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//System.out.println(f(1,100,30));
		String S[]=br.readLine().split(" ");
		int N=Integer.parseInt(S[0]);
		int x=Integer.parseInt(S[1]);
		int y=Integer.parseInt(S[2]);
		int c=Integer.parseInt(S[3]);
		int lo=0;
		//System.out.println(Long.MAX_VALUE);
		int hi=1000000000;
		while(hi-lo>=10)
			{
			int steps=(hi+lo)/2;
			//System.out.println("checking "+steps+" hi= "+hi+" lo = "+lo);
			long total=f(x,y,steps)+f(N-x+1,y,steps)+f(N-x+1,N-y+1,steps)+f(x,N-y+1,steps);
			//System.out.println(f(x,y,steps)+" "+f(N-x+1,y,steps)+" "+f(N-x+1,N-y+1,steps)+" "+f(x,N-y+1,steps));
			total-=3;			//x,y
			total-=Math.min(steps,x-1);			//left
			total-=Math.min(steps,y-1);			//down
			total-=Math.min(steps,N-x);			//right
			total-=Math.min(steps,N-y);			//up
			//System.out.println("total = "+total);
			if(total>=c)
				hi=steps+1;
			else
				lo=steps-1;
			}
		for(int steps=lo;steps<=hi;steps++)
			{
			//System.out.println("checking "+steps);
			long total=f(x,y,steps)+f(N-x+1,y,steps)+f(N-x+1,N-y+1,steps)+f(x,N-y+1,steps);
			total-=3;			//x,y
			total-=Math.min(steps,x-1);			//left
			total-=Math.min(steps,y-1);			//down
			total-=Math.min(steps,N-x);			//right
			total-=Math.min(steps,N-y);			//up
			//System.out.println("total = "+total);
			if(total>=c)
				{
				System.out.println(steps);
				return;
				}
			}
		}
	public static long f(long a, long b, long steps)
		{
		//System.out.println("f("+a+","+b+","+steps+")");
		steps++;
		long A=Math.min(a,b);
		long B=Math.max(a,b);
		long ans=0;
		if(steps>=(A+B))
			{
			//System.out.println("case 1");
			ans= A*B;
			}
		else if(steps<=A)
			{
			//System.out.println("case 2");
			ans= (steps*(steps+1))/2;
			}
		else if(steps>A&&steps<=B)
			{
			//System.out.println("case 3");
			ans= (A*(A+1))/2+(steps-A)*A;
			}
		else if(steps>B)
			{
			//System.out.println("case 4");
			ans= (A*(A+1))/2+(B-A)*A+(steps-B)*A-((steps-B)*(steps-B+1))/2;
			}
		//System.out.println("\treturning "+ans);
		return ans;
		}
	}

//must declare new classes here


import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class Reader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(s()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = i();}return ret;}
    }

           //       |----|       /\      |    |   -----   |
           //       |   /       /  \     |    |     |     |
           //       |--/       /----\    |----|     |     |
           //       |   \     /      \   |    |     |     |
           //       |    \   /        \  |    |   -----   -------

    public static long check(long mid,long x,long y,long n)
    {
        long ans=2*mid*mid+2*mid+1;
        long uleft=Math.max(0,mid-x+1);
        long dleft=Math.max(0,mid-(n-x));
        long lleft=Math.max(0,mid-y+1);
        long rleft=Math.max(0,mid-(n-y));
        ans-=uleft*uleft+dleft*dleft+lleft*lleft+rleft*rleft;

        ans+=(Math.max(0,mid-(x+y-1))*(Math.max(0,mid-(x+y-1))+1))/2;
        ans+=(Math.max(0,mid-(x+n-y))*(Math.max(0,mid-(x+n-y))+1))/2;
        ans+=(Math.max(0,mid-(y+n-x))*(Math.max(0,mid-(y+n-x))+1))/2;
        ans+=(Math.max(0,mid-(n-x+n-y+1))*(Math.max(0,mid-(n-x+n-y+1))+1))/2;
        return ans;
    }
    public static void main(String[] args)throws IOException
    {
        PrintWriter out= new PrintWriter(System.out);
        Reader sc=new Reader();
        long n=sc.l();
        long x=sc.l();
        long y=sc.l();
        long c=sc.l();
        long low=0;
        long high=(long)Math.pow(10,9);
        while(low<high)
        {
            long mid=(low+high)/2;
            if(check(mid,x,y,n)>=c)
            high=mid;
            else
            low=mid+1;
        }
        out.println(low);
        out.flush();
    }
}