Auxiliary Project

Anna has just nished her course project. She has a lot of seven-segment LED displays as leftovers and a small power source. Each display consumes power proportionally to the number of lit segments, e.g. '9’consumes twice more power than ‘7’.

Anna wonders what is the maximum possible sum of digits she is able to achieve, if her power source is able to light n segments, and she wants to light exactly n segments.

Input

The single line of the input contains one integer n ----- the number of segments that should be lit(2<=n<=10^6).

Output

Output a single integer ----- the maximum possible sum of digits that can be displayed simultaneously.

Sample Input

4
7
6

Sample Output

4
11
14


如图的数字显示方式,每个线段需要一个能量,有n个能量,在尽可能把所有能量都用上的情况下是的组成的所有的数字之和最大。


通过模拟

n output
2 1
3 7
4 4
5 8
6 14
7 11
8 15
9 21
10 18

2个能量是1
3个能量是7
4个能量是4
5个能量是3+2个能量 7+1=8
6个能量是3+3—7+7=14
7个能量是3+4个能量 7+4=11
8个能量是3+3+2个能量 7+7+1=15
发现都是由2、3、4个能量为基础来组成的
so直接对3取模
n%3=0 全是7
n%3=1 把 3+3+3+3+…+3 中最后一个3换成4
n%3=2 最后一个是2点能量3+3+3+…+2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
int main()
{
int n;
scanf("%d", &n);
int m = n % 3;
int c = n / 3;
if (m == 0)
{
return 0 * printf("%d\n", c * 7);
}
if (m == 1)
{
return 0 * printf("%d\n", (c - 1) * 7 + 4);
}
if (m == 2)
{
return 0 * printf("%d\n", c * 7 + 1);
}
}