← Home
package main

import (
	"fmt"
)

func count(t, n, x, y int64) int64 {
	res := 2*t*t + 2*t + 1
	if h := t - x + 1; h > 0 {
		res -= h * h
	}
	if h := t + x - n; h > 0 {
		res -= h * h
	}
	if h := t - y + 1; h > 0 {
		res -= h * h
	}
	if h := t + y - n; h > 0 {
		res -= h * h
	}

	if k := t - x - y + 1; k > 0 {
		res += k * (k + 1) / 2
	}
	if k := t - x + y - n; k > 0 {
		res += k * (k + 1) / 2
	}
	if k := t + x - y - n; k > 0 {
		res += k * (k + 1) / 2
	}
	if k := t + x + y - 2*n - 1; k > 0 {
		res += k * (k + 1) / 2
	}

	return res
}

func main() {
	var n, x, y, c int64
	if _, err := fmt.Scan(&n, &x, &y, &c); err != nil {
		return
	}

	l, r := int64(0), int64(2e9)
	ans := r
	for l <= r {
		mid := l + (r-l)/2
		if count(mid, n, x, y) >= c {
			ans = mid
			r = mid - 1
		} else {
			l = mid + 1
		}
	}
	fmt.Println(ans)
}