Literally 1984


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

Tom "The Move Semantic" Frew is the manager of AUCPL inc., whether you like it or not. In order to make sure that he can stay busy eating seeds, he has recently hired exactly n new employees and needs to set up a cubicle for each of them.

The office floor is a massive empty grid, where each cubicle is a 1 \times 1 square. Since Tom "The Move Semantic" Frew wants his ducks in a row or whatever how the saying goes, he strictly requires that all n cubicles must be arranged together to form a single, solid A \times B rectangular block (where A and B are positive integers such that A \times B = n).

To make sure that Tom "The Move Semantic" Frew makes sure that all of his slaves employees are working on his various bird projects, he wants to install glass partitions. A single glass partition has a length of 1 unit. Glass partitions must be placed on every side of every 1 \times 1 cubicle.

  • If two cubicles are adjacent and share a side, they will share a single glass partition between them.
  • Glass partitions must also be placed along the entire outer perimeter of the A \times B rectangular block.

Tom "The Move Semantic" Frew is a cheepskate (haha get it?) and hence wants to choose the dimensions A and B of the rectangular block such that the total number of 1 \times 1 glass partitions used is minimized.

Given n, find the minimum number of glass partitions required.

Input

The only line of each test case contains a single integer n (1 \le n \le 10^{9}) — the exact number of cubicles to be built.

Output

For each test case, output a single integer: the minimum number of glass partitions required to build exactly n cubicles in a solid rectangular block.

Example

Input 1
4
Output 1
12

Tom "The Move Semantic" Frew can arrange the cubicles as a 1 \times 4 rectangle or a 2 \times 2 rectangle.

  • If arranged as 1 \times 4: There are 5 vertical walls of length 1 and 2 horizontal walls of length 4. Total partitions = 5 \times 1 + 2 \times 4 = 13.
  • If arranged as 2 \times 2: There are 3 vertical walls of length 2 and 3 horizontal walls of length 2. Total partitions = 3 \times 2 + 3 \times 2 = 12.

The minimum number of partitions is 12.

Input 2
6
Output 2
17

The optimal arrangement is a 2 \times 3 (or 3 \times 2) rectangle. There will be 4 vertical walls of length 2 (requiring 4 \times 2 = 8 partitions) and 3 horizontal walls of length 3 (requiring 3 \times 3 = 9 partitions). The total is 8 + 9 = 17.


Comments

There are no comments at the moment.