A dice tower

4.8

8 votes
Greedy Algorithms, Algorithms, Basics of Greedy Algorithms, Greedy algorithm
Problem

Bob is a big fan of cubical dices. He builds a dice tower by stacking the dice one on top of the other. A cubical dice and a dice tower are displayed as follows:

                                                ​​​​​​        ​​​​​        

Lee was given an integer . He set out to build a tower with a minimum height, with the sum of points on all of its outer surfaces equaling the provided number (outer surface: the side surface, the top, and bottom faces).

You had to assist Lee in calculating the minimum number of dice needed to build the tower.

 Input format

  • The first line contains an integer denoting the number of test cases.
  • The first line of each test case contains an integer .

Output format

For each test case, print the only integer that denotes the number of dices in the required tower in a new line. If no such tower exists, print .

Constraints

Sample Input
3
1
21
34
Sample Output
-1
1
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first testcase, no such tower exits whose outer surface sum is .

For the second testcase, the number of dices required is . Therefore, the outer surface sum is .

For the third testcase, the number of dices required is . The outer surface of first dice is . The outer surface of second dice is 

Editor Image

?