Auxiliary Project

Choose any multiset of digits whose total lit segments equals n, and maximize the sum of the digits.

Medium4GreedyMathNo attempts yetTime limit3sMemory limit512 MB

Problem

Anna has just finished her course project. She has many leftover seven-segment LED displays and one small power source. A display draws power in proportion to the number of lit segments, so a 9 draws twice as much power as a 7.

One display shows one digit from 0 to 9, and the number of segments each digit lights is fixed.

Digit0123456789
Segments6255456376

Anna may use as many displays as she likes, and she wants exactly nn segments lit in total. Find the largest possible sum of the digits she displays.

Input

The only line contains one integer nn, the number of segments that must be lit. (2n1062 \le n \le 10^6)

Output

Print one integer, the largest possible sum of digits displayed at the same time.

Note

For n=4n = 4 a single 4 is displayed. A 7 is worth more but lights only three segments, so the fourth segment would go unused. For n=7n = 7 the displays show 4 and 7, and for n=6n = 6 they show two 7s.