codeparrot/codecomplex huggingface dataset:
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
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() );
    }
}
}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
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();
    }

}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
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(); 		
	}
}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
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;
		}
	}

}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
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);
    }

}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
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);
    }
}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
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();
	}

}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
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());
	}

}
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
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
// Problem: 256_B. Mr. Bender and Square
// Time complexity: logn
import java.io.*;
import java.util.*;

public class BBi implements Runnable {
	public static void main(String[] args) {
		new Thread(new BBi()).run();
	}

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer in;
	PrintWriter out = new PrintWriter(System.out);

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

		return in.nextToken();
	}

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

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

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

	int n, x, y;

	public long count(long z) {
		long total = 0;

		long[][] c = new long[][] { { x, y }, { y, n - x + 1 },
				{ n - x + 1, n - y + 1 }, { n - y + 1, x } };

		for (int i = 0; i < c.length; i++) {
			long inside = z;

			for (int j = 0; j < c[i].length; j++) {
				if (z > c[i][j]) {
					total += Math.min(z - c[i][j], c[i][1 - j]) * c[i][j];
					inside -= (z - c[i][j]);
				}
			}

			if (z > c[i][0] && z > c[i][1]) {
				total -= Math.min(z - c[i][0], c[i][1])
						* Math.min(z - c[i][1], c[i][0]);
			}

			if (inside > 0)
				total += inside * (inside + 1) / 2;
		}

		for (int i = 0; i < c.length; i++) {
			total -= Math.min(z, c[i][0]);
		}

		return total + 1;
	}

	public long solve(int n, int x, int y, long c) throws IOException {
		this.n = n;
		this.x = x;
		this.y = y;
		
		long l = 0;
		long r = 2L * n + 2;
		while (r - l > 1) {
			long z = (l + r) / 2;

			if (c <= count(z)) {
				r = z;
			} else {
				l = z;
			}
		}

		return r - 1;
	}

	public void run() {
		try {
			out.println(solve(nextInt(), nextInt(), nextInt(), nextLong()));
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}