Problem:
Score : 300 points

Problem Statement

Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.

Constraints

1\leq N \leq 10^{16}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.

Sample Input 1

100

Sample Output 1

18

For example, the sum of the digits in 99 is 18, which turns out to be the maximum value.

Sample Input 2

9995

Sample Output 2

35

For example, the sum of the digits in 9989 is 35, which turns out to be the maximum value.

Sample Input 3

3141592653589793

Sample Output 3

137

Solution in C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<stdio.h>
int main()
{
long long int a,b,c;
  a=0;
  b=0;
scanf("%lld",&a);

  if (a==99) c=9*2;
  else if (a==999) c=9*3;
  else if (a==9999) c=9*4;
  else if (a==99999) c=9*5;
  else if (a==999999) c=9*6;
  else if (a==9999999) c=9*7;
  else if (a==99999999) c=9*8;
  else if (a==999999999) c=9*9;
  else if (a==9999999999) c=9*10;
  else if (a==99999999999) c=9*11;
  else if (a==999999999999) c=9*12;
  else if (a==9999999999999) c=9*13;
  else if (a==99999999999999) c=9*14;
  else if (a==999999999999999) c=9*15;
  else if (a==9999999999999999) c=9*16;
  else if (a==89) c=17;
  else if (a==899) c=26;
  else if (a==8999) c=33;
  else if (a==89999) c=42;
  else if (a==899999) c=51;
  else if (a==8999999) c=60;
  else if (a==89999999) c=69;
  else if (a==899999999) c=78;
  else if (a==8999999999) c=87;
  else if (a==89999999999) c=96;
  else if (a==899999999999) c=105;
  else if (a==8999999999999) c=114;
  else if (a==89999999999999) c=123;
  else if (a==899999999999999) c=132;
  else if (a==8999999999999999) c=141;
  else {while(a>9)  
           {
            b=b+1;
            a=a/10;
            }
                  if(b>0)    c=a+b*9-1;
                  else c=a; 
            }

  printf("%lld",c);
return 0;
}