Time limit
1s
Memory limit
128 MB
You have N pebbles. You drop each pebble on an integer grid point of the coordinate plane. A grid point is a point whose x-coordinate and y-coordinate are both integers. For example, (1, 1) and (0, -9) are grid points, while (-2, 3.5) and (pi, 7.14) are not.
Consider the smallest axis-aligned rectangle that contains all pebbles. If three pebbles are placed at (2, 4), (4, 8), and (5, 5), then the smallest rectangle containing them has width 3 and height 4, so its perimeter is 14. The width and height of the rectangle must each be at least 1.
Given N, place the pebbles on grid points so that the perimeter of the rectangle containing all pebbles is as small as possible.
The first line contains the number of pebbles N (1 <= N <= 500,000,000).
Print the minimum possible perimeter.