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;
  
  b=0;
scanf("%lld",&a);
while(a>9)  
 {
  b=b+1;
  a=a/10;
 }
if (a=10^2-1) c=9*2;
else if (a=10^3-1) c=9*3;
  else if (a=10^4-1) c=9*4;
  else if (a=10^5-1) c=9*5;
  else if (a=10^6-1) c=9*6;
  else if (a=10^7-1) c=9*7;
  else if (a=10^8-1) c=9*8;
  else if (a=10^9-1) c=9*9;
  else if (a=10^10-1) c=9*10;
  else if (a=10^11-1) c=9*11;
  else if (a=10^12-1) c=9*12;
  else if (a=10^13-1) c=9*13;
  else if (a=10^14-1) c=9*14;
  else if (a=10^15-1) c=9*15;
  else if (a=10^16-1) c=9*16;
else if(b>0)   c=a+b*9-1;
else c=a;  
   
  printf("%lld",c);
return 0;
}