Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy and would like your help to find the shortest possible route that meets the requirements. The city is laid out in a square grid pattern, and is large enough that for the sake of the problem it can be considered infinite.


-----Input-----

Input will consist of a single integer N (1 ≤ N ≤ 10^6), the number of city blocks that must be enclosed by the route.


-----Output-----

Print the minimum perimeter that can be achieved.


-----Examples-----
Input
4

Output
8

Input
11

Output
14

Input
22

Output
20



-----Note-----

Here are some possible shapes for the examples:

[Image]

Difficulty: EASY

Solutions:
from math import sqrt, floor, ceil

def min_route(n):
	(ls, us) = (floor(sqrt(n)), ceil(sqrt(n)))
	p1 = 4 * ls + 2
	p2 = 4 * us
	if ls < n - ls ** 2:
		return p2
	return min(p1, p2)

def main():
	n = int(input().strip())
	print(min_route(n))
main()


from sys import stdin, stdout
n = int(stdin.readline())
(l, r) = (0, n + 1)
while r - l > 1:
	m = r + l >> 1
	if m * m > n:
		r = m
	else:
		l = m
if n > 1:
	ans = 8 + (l - 2) * 4
else:
	ans = 4
n -= l * l
for i in range(l):
	if not i:
		if n:
			ans += 2
			n -= 1
	elif n:
		n -= 1
for i in range(l):
	if not i:
		if n:
			ans += 2
			n -= 1
	elif n:
		n -= 1
stdout.write(str(ans))


import math
n = int(input())
a = int(math.sqrt(n))
ans = 4 * a
n = n - a * a
ans += 2 * math.ceil(n / a)
print(ans)


import sys
import math
n = [int(i) for i in sys.stdin.read().strip().split('\n')][0]
a = math.ceil(math.sqrt(n))
b = n // a
r = n - a * b
p = 2 * a + 2 * b + (2 if r else 0)
print(p)


import math
n = int(input())
a = math.floor(math.sqrt(n))
if a ** 2 >= n:
	print(a * 4)
elif a * (a + 1) >= n:
	print(a * 4 + 2)
else:
	print(a * 4 + 4)


import math
a = int(input())
base_cercana = int(math.sqrt(a))
if a == base_cercana ** 2:
	print(base_cercana * 4)
else:
	faltante = a - base_cercana ** 2
	if faltante <= base_cercana:
		h = faltante * 2 + 2
		print(base_cercana * 4 + h - 2 * faltante)
	else:
		faltante = faltante - base_cercana
		h = faltante * 2 + 2
		print(base_cercana * 4 + h - 2 * faltante + 2)


n = int(input())
i = 1
Cnt_of_cnt = 1
Cnt = 0
Cnt2 = 0
Res = 4
while i <= n:
	while Cnt < Cnt_of_cnt:
		Cnt += 1
		i += 1
	if i <= n:
		Res += 2
		Cnt2 += 1
		Cnt = 0
		if Cnt2 >= 2:
			Cnt_of_cnt += 1
			Cnt2 = 0
print(Res)


mas = list(map(int, input().split()))
t = mas[0]
kv = 1
while (kv + 1) ** 2 <= t:
	kv += 1
s = 4 * kv
if t - kv ** 2 == 0:
	print(s)
elif t - kv ** 2 <= kv:
	print(s + 2)
else:
	print(s + 4)


import math
a = int(input())
s = int(math.sqrt(a))
d = a // s
if a % s != 0:
	d += 1
print((s + d) * 2)


__author__ = 'Alexander'

def Task(inp1):
	n = int(inp1)
	sqr = [1]
	least = 1
	for i in range(2, 1001):
		least = i
		sqr.append(i ** 2)
		if n >= sqr[i - 2] and n < sqr[i - 1]:
			break
	least -= 1
	resid = n - sqr[-2]
	if resid == 0:
		res = least * 4
	elif resid <= least:
		res = least * 4 + 2
	else:
		res = least * 4 + 4
	return res

def Main():
	inp1 = input()
	outp = Task(inp1)
	print('{}\n'.format(outp))

def Test():
	assert Task(4) == 8
Main()


a = int(input())
r = 1
while r < 1001:
	if r ** 2 > a:
		r = r - 1
		break
	elif r ** 2 == a:
		break
	else:
		r = r + 1
if (a - r ** 2) % r == 0:
	t = (a - r ** 2) // r
else:
	t = (a - r ** 2) // r + 1
print(4 * r + 2 * t)


n = int(input())
ans = 1000000000.0
for i in range(1, 1000001):
	y = i
	x = (n + y - 1) // y
	ans = min(ans, 2 * x + 2 * y)
print(ans)


import math
k = int(input())
result = 0
base = 0
for a in range(k + 1)[::-1]:
	x = math.sqrt(a)
	if math.floor(x) == x:
		base = x
		k -= a
		result += 4 * x
		break
while k:
	if k >= base:
		k -= base
		result += 2
	else:
		result += 2
		k = 0
print(int(result))


from math import sqrt, floor

def isPerfect(N):
	if sqrt(N) - floor(sqrt(N)) != 0:
		return False
	else:
		return True

def getClosestPerfectSquare(N):
	if isPerfect(N):
		print(N, '0')
		return
	aboveN = -1
	belowN = -1
	n1 = 0
	n1 = N + 1
	while True:
		if isPerfect(n1):
			aboveN = n1
			break
		else:
			n1 += 1
	n1 = N - 1
	while True:
		if isPerfect(n1):
			belowN = n1
			break
		else:
			n1 -= 1
	diff1 = aboveN - N
	diff2 = N - belowN
	if diff1 > diff2:
		return (belowN, diff2)
	else:
		return (aboveN, -diff1)
N = int(input())
if isPerfect(N):
	print(int(sqrt(N) * 4))
else:
	ans1 = getClosestPerfectSquare(N)
	(a, b) = ans1
	if b > 0:
		print(int(sqrt(a) * 4 + 2))
	elif b < 0:
		print(int(sqrt(a) * 4))


from math import *
n = int(input())
a = ceil(sqrt(n))
b = ceil(n / a)
print((a + b) * 2)


import math
n = int(input())
up = math.ceil(math.sqrt(n))
down = int(math.sqrt(n))
if n > up * down or math.sqrt(n) == down:
	print(4 * up)
else:
	print(4 * up - 2)


cnt = lambda s, i: s.count(i)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
n = ii()
s = int(n ** 0.5)
print(4 * s + 2 * (0 < n - s ** 2 <= s) + 4 * (n - s ** 2 > s))


n = int(input())
sq = int(n ** (1 / 2))
ans = sq * 4
if n - sq ** 2 > sq:
	ans += 4
elif 1 <= n - sq ** 2 <= sq:
	ans += 2
print(ans)


from math import sqrt
n = int(input())
a = int(sqrt(n))
x = n - a ** 2
if x == 0:
	print(4 * a)
elif x <= a:
	print(4 * a + 2)
else:
	print(4 * a + 4)


import math

def main():
	n = int(input())
	solver(n)

def solver(n):
	length = math.ceil(n ** 0.5)
	if length * (length - 1) >= n:
		width = length - 1
	else:
		width = length
	print(2 * (length + width))
main()


from math import sqrt, ceil
n = int(input())
k = int(ceil(sqrt(n)))
print(4 * k if n > k * k - k else 4 * k - 2)


from math import floor, ceil
n = int(input())
f = floor(n ** 0.5)
c = ceil(n ** 0.5)
if c * f < n:
	c += 1
print(2 * f + 2 * c)


n = int(input())
a = int(n ** 0.5)
if a * a != n:
	a += 1
if a * (a - 1) >= n:
	b = a - 1
else:
	b = a
rs = (a + b) * 2
print(rs)


import math
t = int(input())
a = int(math.sqrt(t))
b = math.ceil(t / a)
print(a * 2 + b * 2)


import math
n = int(input())
b = math.floor(math.sqrt(n))
bb = b * b
if bb == n:
	print(b * 4)
else:
	left = n - bb
	if left <= b:
		print(b * 4 + 2)
	else:
		print(b * 4 + 4)


import math
n = int(input())
sqr_lnt = math.floor(math.sqrt(n))
sqr_parameter = 4 * sqr_lnt
res = n - sqr_lnt ** 2
if res > sqr_lnt:
	res1 = res - sqr_lnt
	current_parameter = 2 * (sqr_lnt + (sqr_lnt + 1))
	new_parameter = 2 * (res1 + 1) - 2 * res1
	fin_parameter = current_parameter + new_parameter
elif res == 0:
	fin_parameter = 4 * sqr_lnt
elif res < sqr_lnt:
	newer_parameter = 2 * (res + 1) - 2 * res
	fin_parameter = sqr_parameter + newer_parameter
elif res == sqr_lnt:
	fin_parameter = 2 * (sqr_lnt + (sqr_lnt + 1))
print(fin_parameter)


n = int(input())
i = 1
while i * i <= n:
	i += 1
i -= 1
k = n - i * i
if k == 0:
	print(i * 4)
elif k <= i:
	print(2 + 4 * i)
else:
	print(4 + 4 * i)


n = int(input())
x = int(n ** 0.5)
y = int((x + 1) ** 2 / x)
if int(x ** 2) == n:
	print(4 * x)
else:
	for i in range(x, y + 1):
		if i * x >= n:
			print(2 * (i + x))
			break


from math import ceil

def minimal_perimeter(side, area):
	other_side = ceil(area / side)
	return 2 * (side + other_side)
area = int(input())
minimal_perimeter_for_area = minimal_perimeter(area, area)
for i in range(2, area):
	minimal_perimeter_for_area = min(minimal_perimeter(i, area), minimal_perimeter_for_area)
print(minimal_perimeter_for_area)


n = int(input())
a = int(n ** 0.5 + 1 - 1e-10)
print(2 * (a + 0 - -n // a))


n = int(input())
t = int(n ** 0.5)
s = n // t
if s * t != n:
	print(2 * (s + t) + 2)
else:
	print(2 * (s + t))


from math import *
n = int(input())
m = int(sqrt(n))
if m * m == n:
	print(4 * m)
else:
	i = m * m
	j = (m + 1) * (m + 1)
	if abs(i - n) < abs(j - n):
		a = (2 * m + 1) * 2
	else:
		a = 4 * (m + 1)
	print(a)


a = int(input())
if a ** 0.5 % 1 == 0:
	print(int(a ** 0.5 * 4))
else:
	i = a
	while i ** 0.5 % 1 != 0:
		i -= 1
	ans = i ** 0.5 * 4
	a = (a - i + i ** 0.5 - 1) // i ** 0.5 * 2
	print(int(a + ans))


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
n = get_int()
s = math.floor(math.sqrt(n))
if n > s * s:
	diff = n - s * s
	if diff > s:
		print(4 * s + 4)
	else:
		print(4 * s + 2)
else:
	print(4 * s)


n = int(input())
if n ** 0.5 % 1 == 0:
	print(int(4 * n ** 0.5))
else:
	count = 0
	temp = int(n ** 0.5) + 1
	temp2 = temp ** 2
	while temp2 >= n:
		temp2 -= temp
		count += 1
	print(int(2 * (temp + temp - count + 1)))


import math
n = int(input())
a = math.ceil(n ** 0.5)
b = math.ceil(n / a)
print(2 * a + 2 * b)


import math

def divisors(n):
	n = int(n)
	d1 = math.ceil(math.sqrt(n))
	d2 = math.ceil(n / d1)
	return d1 * 2 + d2 * 2
n = input()
print(divisors(n))


n = int(input())
x = 10 ** 6
y = x
for i in range(1, n + 1):
	if x + y > i + ((n - 1) // i + 1):
		x = (n - 1) // i + 1
		y = i
print(2 * (x + y))


n = int(input())
sq = int(n ** 0.5)
if n != sq * sq:
	sq += 1
	start = sq * 4
	now = sq * sq
	s1 = sq
	s2 = sq
	while now - s1 >= n:
		now -= s1
		s2 -= 1
		(s1, s2) = (min(s1, s2), max(s1, s2))
		start -= 2
	print(start)
else:
	print(4 * sq)


from math import *
N = int(input())
print(2 * ceil(2 * sqrt(N)))


import math
n = int(input())
x = int(math.floor(math.sqrt(n)))
n = n - x * x
p = 4 * x
while n > 0:
	p += 2
	n -= x
	x += 1
print(p)


import math
x = int(input().strip())
root = int(round(math.sqrt(x)))
rem = x - root * root
perim = root * 4
(s1, s2) = (root, rem - root)
if rem < root:
	s1 = rem
	s2 = 0
if s1 > 0:
	perim += 2
if s2 > 0:
	perim += 2
print(perim)


from math import sqrt

def cal_add(x):
	return 2 if x > 0 else 0
n = int(input())
k = int(sqrt(n))
r = n - k ** 2
rs = k * 4
a = r if r <= k else r - k
b = r - a
rs += cal_add(a) + cal_add(b)
print(rs)


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)

def tup():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
from math import log2, sqrt
from collections import Counter, defaultdict
from itertools import permutations
import re
from math import floor, sqrt, ceil

def bark():
	n = I()
	print(next((2 * i for i in range(1000000) if i // 2 * (i // 2 + i % 2) >= n)))
bark()


from math import gcd, ceil
from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su
n = inin()
(i, j) = (1, 1)
while i * j < n:
	i += 1
	if i * j >= n:
		break
	j += 1
print(2 * i + 2 * j)


N = int(input())
x = int(N ** 0.5)
if x * x == N:
	print(4 * x)
else:
	y = x * x
	x += 1
	z = x * x
	if abs(N - y) > abs(z - N):
		print(4 * x)
	else:
		print(4 * x - 2)


from math import ceil, floor, sqrt

def main():
	n = int(input())
	first_line = floor(sqrt(n))
	second_line = ceil(n / first_line)
	print((first_line + second_line) * 2)
main()


n = int(input())
nearestsq = int(n ** 0.5)
ans = nearestsq * 4
n -= nearestsq ** 2
while n >= nearestsq:
	ans += 2
	n -= nearestsq
if n:
	ans += 2
print(ans)


n = int(input())
i = 1
p = 0
t = 0
while True:
	if p * i >= n:
		t = 1
		break
	elif i * i >= n:
		break
	p = i
	i = i + 1
if t == 1:
	print(p * 2 + i * 2)
else:
	print(i * 4)


import math as m
x = int(input())
print(2 * (m.floor(m.sqrt(x)) + m.ceil(x / m.floor(m.sqrt(x)))))


from math import sqrt
n = int(input())
a = (int(sqrt(n)) + n // int(sqrt(n))) * 2
print(a if n % int(sqrt(n)) == 0 else a + 2)


def solve(n):
	a = n ** 0.5
	b = int(a)
	if a == int(a):
		return 4 * int(a)
	elif n > b * b and n <= b * (b + 1):
		return 4 * b + 2
	else:
		return 4 * (b + 1)
n = int(input())
print(solve(n))


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : input()
t = 1
for _ in range(t):
	n = ii()
	x = int(math.sqrt(n))
	ans = x * 2
	n -= x * x
	w = n // x
	if n % x == 0:
		ans += 2 * (x + w)
	else:
		ans += 2 * (x + 1 + w)
	print(ans)


import math
n = int(input())
m = math.sqrt(n)
l = int(m)
if m - l == 0:
	print(int(m * 4))
else:
	print(l * 4 + 2 * math.ceil((n - l ** 2) / l))


n = int(input())
i = 1
while True:
	(start, end) = (i ** 2 - i + 1, i ** 2)
	if start <= n <= end:
		print(i * 4)
		exit()
	elif n < start:
		print(i * 4 - 2)
		exit()
	i += 1


from math import ceil, floor
from math import sqrt
n = int(input())
l = sqrt(n)
if ceil(l) == floor(l):
	print(int(4 * l))
else:
	g1 = ceil(l)
	g2 = floor(l)
	m = (g1 + g2) / 2
	if l >= m:
		print(ceil(l) * 4)
	else:
		print((ceil(l) + floor(l)) * 2)


n = int(input())
if n == 1:
	print(4)
elif n == 2:
	print(6)
elif n == 3:
	print(8)
else:
	i = 2
	while i * i < n:
		i += 1
	if i * i > n:
		i -= 1
	c = 4 * i
	d = n - i * i
	if d > 0:
		l = d // i
		if d % i == 0:
			c += l * 2
		else:
			c += (l + 1) * 2
	print(c)


n = int(input())
a = n ** 0.5
al = int(a)
ar = int(a) + 1
if al * al >= n:
	print(al * 4)
elif al * ar >= n:
	print((al + ar) * 2)
else:
	print(ar * 4)


A = int(input())
ans = 10 ** 18
x = 1
while x ** 2 <= A:
	y = (A + x - 1) // x
	ans = min(ans, 2 * (x + y))
	x += 1
print(ans)


import math

def compute(l, n):
	l2 = math.ceil(n / l)
	return 2 * l + 2 * l2
n = int(input())
best = 9999999999
for i in range(1, n + 1):
	best = min(best, compute(i, n))
print(best)


import math
n = int(input())
x = math.floor(n ** 0.5)
sel = n - x ** 2
if sel == 0:
	print(4 * x)
elif sel <= x:
	print(4 * x + 2)
else:
	print((x + 1) * 4)


from math import sqrt
n = int(input())
a = int(sqrt(n))
if (a + 1) * (a + 1) <= n:
	a += 1
left = n - a * a
b = a
c = a + left // a
ans = 2 * b + 2 * c
if b * c < n:
	ans += 2
print(ans)


n = int(input())
x = int(n ** 0.5)
y = n // x
if x * y != n:
	print(2 * (x + y) + 2)
else:
	print(2 * (x + y))


n = int(input())
num = int(pow(n, 0.5))
ans = 4 * num
if n - num * num:
	diff = n - num * num
	div = diff // num
	if diff % num == 0:
		print(ans + 2 * div)
	else:
		print(ans + 2 * div + 2)
else:
	print(ans)


n = int(input())
square = 1
while square ** 2 <= n:
	square += 1
square -= 1
left = n - square ** 2
if left > 0:
	if left <= square:
		print(4 * square + 2)
	else:
		print(4 * square + 4)
else:
	print(4 * square)


import math
n = int(input())
if math.sqrt(n) == int(math.sqrt(n)):
	print(int(math.sqrt(n)) * 4)
else:
	l = []
	x = int(math.sqrt(n))
	for i in range(x, x + 2):
		for j in range(x, x + 2):
			if i * j >= n:
				l.append(2 * i + 2 * j)
	print(min(l))


import math
n = int(input())
a = math.ceil(n ** 0.5)
b = math.floor(n ** 0.5)
if a * b < n:
	b += 1
print((b + a) * 2)


import math
n = int(input())
mn = 2 * n + 2
for i in range(n, min(4 * n, n + 1000)):
	s = int(math.sqrt(i))
	for j in range(s, 0, -1):
		if i % j == 0:
			mn = min(mn, 2 * (j + i // j))
			break
print(mn)


import math

def find_perim(x, y, n):
	curr_area = x * y
	if curr_area == n or curr_area - x < n or curr_area - y < n:
		return 2 * x + 2 * y
	elif curr_area - x >= n:
		return find_perim(x - 1, y, n)
	elif curr_area - y >= n:
		return find_perim(x, y - 1, n)
	else:
		for i in range(n):
			curr_area -= i
			if curr_area == n:
				return 2 * x + 2 * y
			elif curr_area < n:
				break
		return -1
n = int(input())
x = math.ceil(math.sqrt(n))
perim = find_perim(x, x, n)
print(perim)


import math
dientich = int(input())
canh = int(math.sqrt(dientich))
if canh * canh == dientich:
	print(4 * canh)
	exit()
else:
	tmp = dientich - canh * canh
	rs = 4 * canh
	while tmp > 0:
		if tmp > canh:
			rs += 2
			tmp -= canh
		else:
			rs += 2
			tmp = 0
print(rs)


n = int(input())
a = int(n ** 0.5)
big_square = a ** 2
else_square = n - big_square
answer = int(a * 4)
if a ** 2 != n:
	if else_square - a > 0:
		answer += 4
	else:
		answer += 2
print(answer)


n = int(input())
for i in range(1, 1001):
	if i * i >= n:
		if i * (i - 1) >= n:
			print(2 * i + 2 * (i - 1))
		else:
			print(4 * i)
		break


from math import sqrt, ceil, floor
N = int(input())
s = sqrt(N)
q = floor(s)
r = N - q ** 2
w = True
while w:
	if r >= q + 1:
		print(q * 4 + 4)
		w = False
		break
	elif r >= 1:
		print(q * 4 + 2)
		w = False
		break
	else:
		print(q * 4)
		break
		w = False


N = int(input())
cnt = 0
while True:
	cnt += 1
	if N < cnt * cnt:
		cnt -= 1
		N -= cnt * cnt
		break
res = cnt * 4
if N > 0:
	N -= 1
	res += 2
if N > cnt - 1:
	N -= cnt - 1
	if N > 0:
		N -= 1
		res += 2
print(res)


from math import floor, ceil, sqrt
n = int(input())
a = floor(sqrt(n))
b = ceil(sqrt(n))
if n == a * a:
	print(4 * a)
elif n <= a * b:
	print(2 * (a + b))
else:
	print(4 * b)


from math import sqrt, floor
N = int(input())
start = floor(sqrt(N))
rnd = start * 4
init_blk = start * start
put = 0
for blk in range(init_blk + 1, N + 1):
	if blk - init_blk == 1 or blk - init_blk == start + 1:
		rnd += 2
print(rnd)


import math
p = 0
sq = 0
n = int(input())
sq = math.sqrt(n)
if int(sq) * math.ceil(sq) >= n:
	p = int(sq) + math.ceil(sq)
else:
	p = int(sq) + math.ceil(sq) + 1
print(p * 2)


import math
n = int(input())
t = int(n ** 0.5)
k = n - t ** 2
a = 4 * t + math.ceil(k / t) * 2
print(a)


n = int(input())
h = int(n ** 0.5)
w = (n + h - 1) // h
print(2 * (w + h))


import math
n = int(input())
p = int(math.sqrt(n))
for x in range(p, n + 1):
	if x * p >= n:
		print(2 * (x + p))
		break


import math
n = int(input())
x = math.ceil(math.sqrt(n))
y = n // x
while x * y < n:
	y += 1
print(2 * (x + y))


a = int(input())
i = 1
while i * i <= a:
	i += 1
i -= 1
ans = i * 4
if a - i * i == 0:
	print(ans)
elif a - i * i <= i:
	print(ans + 2)
elif a - i * i <= 2 * i:
	print(ans + 4)


N = int(input())
x = int((N - 1) ** 0.5 + 1)
print(x + (N + x - 1) // x * 2 + x)


from math import sqrt
n = int(input())
side_of_s = int(sqrt(n))
are_of_s = side_of_s * side_of_s
rest = n - are_of_s
output = side_of_s * 4
if rest > 0:
	output += 2
	rest -= side_of_s
if rest > 0:
	output += 2
print(output)


n = int(input())
INF = float('inf')
num = INF
for i in range(1, n + 1):
	q = n // i + int(n % i != 0)
	num = min(num, 2 * q + 2 * i)
print(num)


import math
n = int(input())
print(math.ceil(math.sqrt(n) * 2) * 2)


import math
x = int(input())
q = int(math.sqrt(x))
c = x - q * q
print(4 * q + 2 * math.ceil(c / q))


from math import ceil
print(2 * ceil(2 * int(input()) ** 0.5))


import math
N = int(input())
m = 10 ** 18
for x in range(1, N + 1):
	y = math.ceil(N / x)
	if 2 * (x + y) < m:
		(a, b) = (x, y)
		m = 2 * (x + y)
	x += 1
print(2 * (a + b))


S = int(input())
minL = int(S ** (1 / 2))
if minL * minL >= S:
	print(4 * minL)
elif minL * (minL + 1) >= S:
	print(4 * minL + 2)
else:
	print(4 * minL + 4)


from math import trunc, sqrt
a = int(input())
n = trunc(sqrt(a))
if n * n == a:
	print(4 * n)
elif n * (n + 1) >= a:
	print(2 * (n + n + 1))
else:
	print(4 * (n + 1))


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
x = int(mt.sqrt(n))
print(2 * (x + mt.ceil(n / x)))


try:
	import math
	n = int(input())
	x = int(math.sqrt(n))
	if x * x >= n:
		per = 4 * x
	elif x * (x + 1) >= n:
		per = 4 * x + 2
	elif (x + 1) * (x + 1) >= x:
		per = 4 * x + 4
	print(per)
except EOFError:
	pass


print(2 * int(2 * int(input()) ** 0.5 + 0.9999))


import math
from random import random

def getInt():
	return int(input())

def getInts():
	line = input().split()
	return [int(l) for l in line]

def getFloat():
	return float(input())

def getFloats():
	line = input().split()
	return [float(l) for l in line]

def getStrings():
	line = input().split()
	return line
A = getInt()
n = math.floor(math.sqrt(A))
if n * n == A:
	print(4 * n)
elif n * (n + 1) >= A:
	print(4 * n + 2)
else:
	print(4 * n + 4)


import sys
import math
import bisect
import itertools
import random
import re

def main():
	n = int(input())
	min_val = 10 ** 18
	for i in range(1, n + 1):
		j = (n + i - 1) // i
		val = (i + j) * 2
		min_val = min(min_val, val)
	print(min_val)
main()


import math
n = int(input())
l = int(math.ceil(math.sqrt(n)))
print(l + 2 * (l - 1) + (n - l * (l - 1) > 0) * 2 + l)


n = int(input())
p = 1
while p * p < n:
	p += 1
print(4 * p - 2 * ((p * p - n) // p))


alph = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
r = int(n ** 0.5)
if r * r == n:
	print(4 * r)
elif n - r ** 2 <= (r + 1) ** 2 - n:
	print(4 * r + 2)
else:
	print(4 * r + 4)


import math
N = int(input())
x = int(math.sqrt(N))
r = N - x * x
p = 4 * x
if r:
	p += 2 if r <= x else 4
print(p)


import sys
input = sys.stdin.readline
n = int(input())
ans = 10 ** 9
for i in range(1, 2000):
	if i * i >= n:
		ans = i * 4
		break
	if i * (i + 1) >= n:
		ans = i * 4 + 2
		break
print(ans)


import math

def main():
	n = int(input())
	length = int(math.sqrt(n))
	if length * length == n:
		print(length * 4)
	elif length * (length + 1) >= n:
		print((length * 2 + 1) * 2)
	else:
		print((length + 1) * 4)

def __starting_point():
	main()
__starting_point()


n = int(input())
i = 1
j = 1
f = 'i'
for k in range(0, n):
	area = i * j
	if area >= n:
		break
	if f == 'i':
		i += 1
		f = 'j'
	else:
		j += 1
		f = 'i'
print(2 * i + 2 * j)


N = int(input())
Rows = int(N ** 0.5)
Columns = N // Rows
print(2 * (Columns + Rows) if Rows * Columns == N else 2 * (Columns + Rows) + 2)


import math
n = int(input())
x = math.ceil(math.sqrt(n))
y = math.ceil(n / x)
print(2 * (x + y))


n = int(input())
i = 1
while i ** 2 < n:
	i += 1
if i ** 2 == n:
	print(4 * i)
else:
	rows = n // i
	print((i + rows) * 2 + (n % i != 0) * 2)


n = int(input())
(i, j, c) = (1, 2, 1)
while n >= c + 2 * i:
	c += 2 * i
	i += 1
	j += 2
print(2 * (j, j + 1)[n >= c + i])


import math
n = int(input())
p = n ** (1 / 2)
r = int(math.sqrt(n))
print(4 * 2 + (r - 2) * 4 + 2 * math.ceil((n - r * r) / r))


import math
n = int(input())
a = int(math.ceil(math.sqrt(n)))
b = a + 1
a1 = (n - n % a) / a * 2 + 2 * a
if n % a != 0:
	a1 += 2
a2 = (n - n % b) / b * 2 + 2 * b
if n % b != 0:
	a2 += 2
print(int(min(a1, a2)))


import math as m
n = int(input())
x = int(m.sqrt(n))
p = x * x
peri = 4 * x
q = n - p
while q > x:
	peri += 2
	q -= x
if q != 0:
	peri += 2
print(peri)


import math
n = int(input())
e = int(math.sqrt(n))
if n % e == 0:
	extra = 0
else:
	extra = 1
print(int(e * 2 + 2 * (n // e + extra)))


print(2 * int(0.99999 + 2 * int(input()) ** 0.5))


n = int(input())
a = 1
while a * a < n:
	a += 1
if a * (a - 1) >= n:
	print(2 * a + 2 * (a - 1))
else:
	print(4 * a)


n = int(input())
i = 0
while i * i <= n:
	i += 1
t = i - 1
j = 1
while t * j < n:
	j += 1
print(2 * (t + j))


from math import sqrt
n = int(input())
a = 0
b = 0
c = 0
a = int(sqrt(n))
while a * b < n:
	b += 1
if a * b > n:
	b -= 1
if a * b == n:
	print(2 * (a + b))
else:
	c = n - a * b
	a = 2 * (a + b) - c
	c = c + 2
	print(a + c)


n = int(input())
a = 1
while a * a <= n:
	a += 1
a -= 1
p = a * 4
df = n - a * a
count = df // a
p = p + 2 * count
df -= count * a
if df > 0:
	p += 2
print(p)


n = int(input())
from math import sqrt
k = int(sqrt(n))
if k == sqrt(n):
	print(4 * k)
elif n <= k * (k + 1):
	print(2 * (2 * k + 1))
else:
	print(4 * (k + 1))


n = int(input())
l = 1
r = n
m = 0
while r - l > 1:
	m = int((l + r) / 2)
	if m * m > n:
		r = m
	else:
		l = m
if m * m > n:
	m -= 1
if n > 2 and m * m != n:
	if m * m + m >= n:
		print(4 * m + 2)
	else:
		print(4 * m + 4)
elif n == 1:
	print(4)
elif n == 2:
	print(6)
if m * m == n:
	print(4 * m)


n = int(input())
a = int(n ** 0.5)
area = 4 * a
if n == 2:
	area = 6
elif n == 3:
	area = 8
elif a * a != n and n - a * a <= a:
	area += 2
elif a * a != n:
	a += 1
	area = a * 4
print(area)


import math
n = int(input())
a = math.ceil(math.sqrt(n))
if a ** 2 - n < a:
	print(a * 4)
else:
	print(a * 4 - (a ** 2 - n) // a * 2)


from collections import deque as de
import math
from sys import stdin, stdout
import re
from collections import Counter as cnt
from functools import reduce
from itertools import groupby as gb
from bisect import bisect_left as bl, bisect_right as br

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def lcm(x, y):
	lcm = x * y // math.gcd(x, y)
	return lcm

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def checkisap(list):
	d = list[1] - list[0]
	for i in range(2, len(list)):
		temp = list[i] - list[i - 1]
		if temp != d:
			return False
	return True

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def si():
	return list(map(int, input()))

def indict():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(value)] = int(index) + 1
	return dic

def frqdict():
	dic = {}
	for (index, value) in enumerate(input().split()):
		if int(value) not in dic:
			dic[int(value)] = 1
		else:
			dic[int(value)] += 1
	return dic
n = ii()
if math.ceil(math.sqrt(n)) == math.floor(math.sqrt(n)):
	print(int(4 * math.sqrt(n)))
else:
	temp = math.floor(math.sqrt(n))
	diff = n - temp * temp
	if diff <= temp:
		print(int(4 * temp + 2))
	else:
		print(int(4 * temp + 4))


b = int(input())
d = 1
k = 2
n = abs(b - d ** 2)
r = abs(b - k ** 2)
while True:
	if r > n:
		break
	else:
		d += 1
		k += 1
		n = abs(b - d ** 2)
		r = abs(b - k ** 2)
h = d ** 2
g = 0
if b > h:
	g = d + d + (d + 1) + (d + 1)
else:
	g = d + d + d + d
print(g)


n = int(input())
temp = int(n ** 0.5)
n -= temp ** 2
if n // temp != n / temp:
	print(temp * 4 + (n // temp + 1) * 2)
else:
	print(temp * 4 + n // temp * 2)


import math

class Solver:

	def main(self):
		n = int(input().strip())
		x = int(math.sqrt(n))
		o = n - x * x
		p = 4 * x
		if o > 0:
			p += 2
		if o > x:
			p += 2
		print(p)
Solver().main()


import math
n = int(input())
a = math.floor(math.sqrt(n))
b = a
while a * b <= n:
	b += 1
b -= 1
rectangle = 2 * a + b
appendix = n % (a * b)
if appendix > 0:
	rectangle += b - appendix
	appendix += 2
else:
	rectangle += b
print(rectangle + appendix)


def approach_sum_squares(n):
	i = 1
	s = 1
	for d in range(3, n, 2):
		s += d
		if s > n:
			break
		i += 1
	return i

def min_perim(n):
	k = approach_sum_squares(n)
	n -= k * k
	picks = 4 * k
	if n == 0:
		return picks
	if n <= k:
		return picks + 2
	if n > k:
		return picks + 4
n = int(input().strip())
print(min_perim(n))


from math import sqrt
Input = lambda : map(int, input().split())
N = int(input())
Column = int(sqrt(N))
Row = N // Column
if Column * Row == N:
	print((Column + Row) * 2)
else:
	print((Column + Row) * 2 + 2)


from math import *
N = int(input())
if N == 2:
	print(6)
elif floor(sqrt(N)) ** 2 == N or floor(sqrt(N + 1)) ** 2 == N + 1:
	print(4 * ceil(sqrt(N)))
elif N - floor(sqrt(N)) ** 2 <= floor(sqrt(N)):
	print(4 * floor(sqrt(N)) + 2)
else:
	print(4 * floor(sqrt(N)) + 4)


import math
num = int(input())
side = math.ceil(num ** 0.5)
if (side - 1) * side >= num:
	ans = (side * 2 - 1) * 2
else:
	ans = side * 4
print(ans)


from math import sqrt
t = int(input())
base = int(sqrt(t))
if base != sqrt(t):
	if t - base * base <= base:
		p = base * 4 + 2
	else:
		p = (base + 1) * 2 + base * 2 + 2
else:
	p = 4 * base
print(p)


import math
N = int(input())
m = int(math.sqrt(N))
n = math.ceil(N / m)
ans = (m + n) * 2
print(ans)


n = int(input())
a = 1
b = 1
while 1:
	if a * b >= n:
		break
	if a < b:
		a = b
	elif a == b:
		b = b + 1
print((a + b) * 2)


n = int(input())
a = int(n ** 0.5)
n -= a ** 2
print(a * 4 + 2 * (n > 0) + 2 * (n > a))


n = int(input())
sqrt = n ** 0.5
if sqrt == int(sqrt):
	print(int(sqrt) * 4)
else:
	sqrt = int(sqrt)
	if sqrt * (sqrt + 1) >= n:
		print(2 * (sqrt + sqrt + 1))
	else:
		print(4 * (sqrt + 1))


a = int(input())
for i in range(1, 1000000):
	if i * i >= a:
		if i * (i - 1) >= a:
			print(2 * (i + i - 1))
		else:
			print(4 * i)
		break


a = int(input())
b = 1
while b * b <= a:
	b += 1
b -= 1
if a == b * b:
	print(b * 4)
elif a - b * b <= b:
	print(b * 4 + 2)
else:
	print(b * 4 + 2 + 2)


n = int(input())
a = int(n ** 0.5)
if n == a * a:
	print(a * 4)
elif (n - a * a) % a == 0:
	print(4 * a + 2 * ((n - a * a) // a))
else:
	print(4 * a + 2 * ((n - a * a) // a) + 2)


import math
n = int(input())
w = int(math.sqrt(n))
if w * w == n:
	print(w * 4)
else:
	remain = n - w * w
	if remain % w == 0:
		e = remain // w
	else:
		e = remain // w + 1
	print(2 * e + 4 * w)


import math
n = int(input())
d = math.sqrt(n)
a = int(math.ceil(d))
qua = a * a
p = a * 4
while True:
	if qua - a >= n:
		qua -= a
		p -= 2
	else:
		break
print(p)


n = int(input())
d = n ** 0.5
x = 0
if int(d) ** 2 == n:
	x = int(d)
else:
	x = int(d) + 1
for i in range(x, 0, -1):
	if i * x == n:
		print(2 * x + 2 * i)
		break
	if i * x < n:
		print(2 * x + 2 * (i + 1))
		break


import math
n = int(input())
x = math.sqrt(n)
if math.floor(x) * math.ceil(x) >= n:
	P = (math.floor(x) + math.ceil(x)) * 2
else:
	P = math.ceil(x) * 4
print(P)


import math
n = int(input())
for i in range(0, n * n):
	if math.sqrt(n + i) == int(math.sqrt(n + i)):
		break
a = math.sqrt(n + i)
p = 4 * a
if a * a - n >= a:
	p = 2 * (a + (a - 1))
print(int(p))


import math
n = int(input())
srt = int(math.sqrt(n))
diff = srt * srt - n
if diff != 0:
	srt = srt + 1
	diff = srt * srt - n
parimeter = 4 * srt
if diff > 0:
	parimeter = parimeter - int(diff / srt) * 2
print(parimeter)


import math
N = int(input())
root = int(N ** 0.5)
sq = root * root
rem = N - sq
p = 4 * root + 2 * math.ceil(rem / root)
print(p)


def is_perfect_square(n):
	return (n ** 0.5).is_integer()
a = int(input())
if is_perfect_square(a) == True:
	print(int(a ** 0.5 * 4))
else:
	l = []
	for i in range(1, a):
		if i ** 2 <= a:
			l.append(i)
	m = max(l)
	q = a // m
	rem = a % m
	print(2 * (q + m) + 2 if rem != 0 else 2 * (q + m) + rem)


n = int(input())
print(next((2 * i for i in range(1000000) if i // 2 * (i // 2 + i % 2) >= n)))


import math
n = int(input())
p = int(math.sqrt(n))
q = math.ceil(n / p)
print(2 * (p + q))


n = int(input())
from math import sqrt, ceil
w = ceil(sqrt(n))
h = ceil(n / w)
print(2 * (h + w))


import math
n = int(input())
if math.sqrt(n).is_integer():
	print(int(math.sqrt(n) * 4))
else:
	n1 = int(math.sqrt(n))
	if n - math.pow(n1, 2) > n1:
		print(n1 * 4 + 4)
	else:
		print(n1 * 4 + 2)


a = int(input())
b = int(pow(a, 0.5))
if a == b * b:
	print(4 * b)
elif a <= b * (b + 1):
	print(4 * b + 2)
else:
	print(4 * b + 4)


import math
n = int(input())
val = []
min_size = []
for i in range(math.trunc(math.sqrt(1000000)) + 1):
	val.append(i * (i - 1) + 1)
	min_size.append(4 * i)
	val.append(i * i + 1)
	min_size.append(4 * i + 2)
last = 0
for idx in range(len(val)):
	if n < val[idx]:
		print(last)
		break
	else:
		last = min_size[idx]


from math import ceil
x = int(input())
t = x ** (1 / 2)
if int(t) * ceil(t) >= x:
	print((int(t) + ceil(t)) * 2)
else:
	print(ceil(t) * 4)


n = int(input())
if n == 1:
	print(4)
else:
	main_square = int(n ** 0.5 // 1) + (n ** 0.5 % 1 > 0)
	minus_squares = main_square ** 2 - n
	perimetr = main_square * 4 - 2 * (minus_squares // main_square)
	print(perimetr)


from math import floor
n = int(input())
q = floor(n ** 0.5)
print(2 * (q + (n + q - 1) // q))


from math import floor
from math import sqrt
a = int(input())
sqr = floor(sqrt(a))
f2 = sqr
while sqr * f2 < a:
	f2 += 1
print((sqr + f2) * 2)


N = int(input())
import math
a1 = int(math.sqrt(N))
a2 = int(math.ceil(math.sqrt(N)))
if N - a1 * a1 <= a1:
	if N == a1 * a1:
		print(4 * a1)
	else:
		print(4 * a1 + 2)
else:
	print(4 * a2)


import math

def main():
	N = int(input())
	down = int(math.sqrt(N))
	if down ** 2 == N:
		print(down * 4)
	else:
		up = down + 1
		if up * down < N:
			down += 1
		print((down + up) * 2)
main()


n = int(input())
a = 1
while a * a <= n:
	a += 1
a -= 1
n -= a * a
b = a + n // a
ans = 0
if n % a != 0:
	ans = 2
print((a + b) * 2 + ans)


n = int(input())
x = 1
while x ** 2 < n:
	x += 1
if x ** 2 > n:
	x -= 1
t = n - x ** 2
ans = 4 * x
if t != 0:
	b = t // x
	z = t % x
	ans += 2 * b
	if z > 0:
		ans += 2
print(ans)


from math import *
n = int(input())
x = n ** 0.5
if x == ceil(x):
	print('%d' % (4 * x))
else:
	x = ceil(x)
	y = n // x
	if n != x * y:
		y += 1
	print('%d' % (2 * (x + y)))


from math import sqrt
a = int(input())
st = sqrt(a) // 1
ost = a - st ** 2
if ost == 0:
	print(int(st * 4))
elif ost / st <= 1:
	print(int(st * 4 + 2))
else:
	print(int(st * 4 + 4))


import math

def min_perimeter(n):
	sq = math.floor(math.sqrt(n))
	rem = n - sq ** 2
	if rem == 0:
		return sq * 4
	elif rem <= sq:
		return sq * 4 + 2
	else:
		return sq * 4 + 4
n = int(input())
print(min_perimeter(n))


a = int(input())
b = int(a ** (1 / 2)) ** 2
if b - a == 0:
	print(int(4 * b ** (1 / 2)))
elif a - b <= b ** (1 / 2) and b - a != 0:
	print(int(4 * b ** (1 / 2) + 2))
else:
	print(int(4 * (b ** (1 / 2) + 1)))


import math
n = int(input())
ans = 10 ** 9 + 1
for a in range(1, int(n ** 0.5 + 2)):
	b = n // a
	c = 2 * (a + b)
	if n % a != 0:
		c += 2
	ans = min(ans, c)
print(ans)


import math
m = int(input())
y = math.sqrt(m)
x = int(y)
z = m - x * x
if z > x:
	print(2 * (2 * x + 2))
elif z == 0:
	print(4 * x)
else:
	print(2 * (2 * x + 1))


import math
n = int(input())
a = int(math.sqrt(n))
b = n - a * a
ans = 4 * a + 2 * (b > 0) + 2 * (b > a)
print(ans)


n = int(input())
a = 10 ** 6 * [0]
a[0] = 4
a[1] = 6
(flag, abc) = (0, 0)
(init, cnt) = (2, 2)
for i in range(2, 10 ** 6):
	a[i] = 8 + abc
	cnt -= 1
	if cnt == 0:
		abc += 2
		if flag == 0:
			cnt = init
			flag = 1
		elif flag == 1:
			init += 1
			cnt = init
			flag = 0
print(a[n - 1])


n = int(input())
s = int(pow(n, 0.5))
front = (s + 1) * (s + 1)
back = s * s
if n - back > front - n:
	print(4 * (s + 1))
elif n == back:
	print(4 * s)
else:
	print(4 * s + 2)


def binarysearch(sequence, value):
	(lo, hi, mid) = (0, 1000, 0)
	if value == 1000000:
		return 1000000
	while lo < hi:
		mid = (lo + hi) // 2
		if sequence[mid] <= value and sequence[mid + 1] > value:
			return a[mid]
		elif sequence[mid] > value:
			hi = mid
		elif sequence[mid] < value:
			lo = mid
	return a[mid]
n = int(input())
a = [i ** 2 for i in range(1, 1001)]
used = binarysearch(a, n)
left = n - used
side = int(used ** 0.5)
ans = 4 * side
if left and left > side:
	print(ans + 4)
elif left:
	print(ans + 2)
else:
	print(ans)


import math
from sys import stdin
ip = stdin.readline
n = int(ip())
sqroot = math.floor(n ** 0.5)
diff = n - sqroot ** 2
ans = sqroot << 2
if diff == 0:
	pass
elif diff <= sqroot:
	ans += 2
else:
	ans += 4
print(ans)


N = int(input())
ans = 2 * N + 2
for a in range(1, N // 2 + 2):
	b = (N + a - 1) // a
	ans = min(ans, 2 * (a + b))
print(ans)


import math
n = int(input())
sn = math.floor(math.sqrt(n))
if n == math.pow(sn, 2):
	res = 4 * sn
elif sn * (sn + 1) >= n:
	res = 4 * sn + 2
else:
	res = 4 * sn + 4
print(res)


import math
n = int(input())
m = round(math.sqrt(n))
p = math.ceil(n / m)
print(2 * m + 2 * p)


import sys

def main():
	n = int(sys.stdin.readline().strip())
	m = int(n ** 0.5)
	p = 2 * m
	rest = n - m ** 2
	if rest == 0:
		print(4 * m)
	elif rest <= m:
		print(4 * m + 2)
	else:
		print(4 * m + 4)
main()


n = int(input())
from math import sqrt
sq = int(sqrt(n))
if sq ** 2 != n:
	sq += 1
d = sq ** 2 - n
print(4 * sq - 2 * (d // sq))


n = int(input())
m = n ** (1 / 2.0)
if m == int(m):
	m = int(m)
else:
	m = int(m) + 1
a = m
b = m
while a * b >= n:
	b = b - 1
b = b + 1
print((a + b) * 2)


import math
from math import gcd, floor, sqrt, log

def iin():
	return int(input())

def sin():
	return input().strip()

def listin():
	return list(map(int, input().strip().split()))

def liststr():
	return list(map(str, input().strip().split()))

def ceill(x):
	return int(x) if x == int(x) else int(x) + 1

def ceilldiv(x, d):
	return x // d if x % d == 0 else x // d + 1

def LCM(a, b):
	return a * b // gcd(a, b)

def solve():
	n = iin()
	h = ceill(sqrt(n))
	w = ceilldiv(n, h)
	print(2 * (h + w))
t = 1
for hula in range(t):
	solve()


from math import ceil, sqrt
x = int(input())
a = ceil(sqrt(x))
r = 2 * a + 2 * ceil(x / a)
print(r)


n = int(input())
a = int(n ** (1 / 2))
if n % a == 0:
	print(2 * (a + n // a))
else:
	print(2 * (a + n // a + 1))


from math import ceil, sqrt

def guard(n):
	a = int(ceil(sqrt(n)))
	if n <= a * (a - 1):
		p = 2 * a - 1
	else:
		p = 2 * a
	return 2 * p
print(guard(int(input())))


n = int(input())
k = int(n ** 0.5)
print(2 * (k + k + (k * k < n) + (k * k + k < n)))


import math
n = int(input())
a = int(math.sqrt(n))
b = a * a
print(2 * math.ceil((n - b) / a) + a * 4)


from math import sqrt, ceil
n = int(input())
x = int(sqrt(n))
if x * x == n:
	print(4 * x)
else:
	a = x
	b = ceil(n / a)
	print(2 * (a + b))


import math
n = int(input())

def sqq(n):
	m = math.floor(math.sqrt(n))
	for i in range(max(0, m - 10), m + 20):
		if i * i > n:
			return i - 1
m = sqq(n)
if n == m * m:
	print(4 * m)
elif n <= m * (m + 1):
	print(2 * (m + m + 1))
else:
	print(4 * (m + 1))


n = int(input())
i = 1
sum = 0
x = 1
t = 1
while True:
	if t % 2 == 1:
		sum += x
	else:
		sum += x * 2 - x
		x += 1
	t += 1
	if n <= sum:
		break
a = sum ** (1 / 2)
if a == int(a):
	print(int(4 * a))
else:
	print(4 * int(a) + 2)


import math
n = int(input())
round_up_sqrt_n = math.ceil(n ** 0.5)
print(4 * round_up_sqrt_n - 2 * math.floor((round_up_sqrt_n ** 2 - n) / round_up_sqrt_n))


import math
a = int(input())
b = int(a ** (1 / 2))
output = 4 * b
if a - b ** 2 == 0:
	output += 0
elif a - b ** 2 <= b:
	output += 2
else:
	output += 4
print(output)


from math import sqrt
n = int(input())
m = l = int(sqrt(n))
while (m + 1) * l < n:
	m += 1
ans = 2 * (m + l)
if n - m * l > 0:
	ans += 2
print(ans)


from math import sqrt
size = int(input())
found = False
for i in range(int(sqrt(size)) + 2):
	for j in range(int(sqrt(size)) + 2):
		if i * j >= size:
			if not found:
				sizes = [i, j]
			found = True
print(2 * (sizes[0] + sizes[1]))


alph = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
r = int(n ** 0.5)
h = int(n / r) + int(n % r != 0)
print(2 * (h + r))


def main():
	N = int(input())
	sqrt = int(N ** 0.5)
	square = sqrt * sqrt
	if square == N:
		print(4 * sqrt)
	else:
		diff = N - square
		if diff <= sqrt:
			print(2 * (2 * sqrt + 1))
		else:
			print(4 * (sqrt + 1))
main()


n = int(input())
if n == 1:
	print(4)
elif n == 2:
	print(6)
elif n == 3:
	print(8)
else:
	i = 2
	while i ** 2 <= n:
		i = i + 1
	i = i - 1
	n = n - i * i
	peri = 4 * i
	while n >= i:
		peri += 2
		n = n - i
	if n != 0:
		peri = peri + 2
	print(peri)


import math as m
n = int(input())
r = m.floor(m.sqrt(n))
x = r * r
y = n - x
if y == 0:
	print(r * 4)
elif y <= r:
	print(r * 4 + 2)
else:
	print(r * 4 - (y - 1) + y + 1 + 2)


N = int(input())
a = int(N ** 0.5)
N -= a * a
print(4 * a + 2 * ((N > 0) + (N > a)))


import math
a = int(input())
b = math.ceil(math.sqrt(a))
c = math.ceil(a / b)
print(2 * (b + c))


import math
n = int(input())
square_root = int(math.sqrt(n))
remaining = n - square_root * square_root
if remaining > square_root:
	print(4 * square_root + 4)
elif remaining == square_root:
	print(4 * square_root + 2)
elif remaining == 0:
	print(4 * square_root)
elif remaining < square_root:
	print(4 * square_root + 2)


n = int(input())
p = int(n ** 0.5)
if not (n - p ** 2) % p:
	print(p * 4 + (n - p ** 2) // p * 2)
else:
	print(p * 4 + ((n - p ** 2) // p + 1) * 2)


from math import sqrt
n = int(input())
k = int(sqrt(n))
s = 4 * k
if k * k < n:
	s += 2
	if k * (k + 1) < n:
		s += 2
print(s)


N = int(input())
k = 1
for i in range(1, N + 1):
	if i * i == N:
		k = 4 * i
		break
	elif i * i > N:
		break
if k != 1:
	print(k)
elif i * (i - 1) < N:
	print(4 * i)
elif i * (i - 1) > N:
	print(4 * i - 2)
else:
	print(4 * i - 2)


import math
n = int(input())
x = math.floor(n ** 0.5)
y = math.ceil(n ** 0.5)
if n - x * x < y * y - n:
	print(4 * x + 2)
elif n - x * x > y * y - n:
	print(4 * y)
else:
	print(4 * x)


from math import sqrt
n = int(input())
p = n
while True:
	x = sqrt(p)
	y = int(x)
	if x - y == 0:
		break
	p += 1
d = p - n
a = int(sqrt(p))
pm = 0
if d < a:
	pm = a * 4
else:
	pm = a * 2 + (a - 1) * 2
print(pm)


a = int(input())
if a == 1:
	print(4)
else:
	p = a * 2 + 2
	for k in range(1, a // 2 + 1):
		f = a // k
		if a % k == 0:
			u = a // k * 2 + 2 * k
			if u < p:
				p = u
		else:
			u = a // k * 2 + 2 * k + 2
			if u < p:
				p = u
	print(p)


n = int(input())
print(min((a + (n + a - 1) // a for a in range(1, n + 1))) * 2)