1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int x;
    cin>>x;
    if(x<0) x=x*(-1);
    int a, b, c, n=0, k=0, m;

    a=x;
    do
    {
        x=x/10;
        n++;
    }while(x>0);
    x=a;

    a=x%10;
    if(x>=10) k=k+((a+1)*2);
    else k=k+(a*2);
    

    b=x%100;
    if( ((b-a)*2) > 0) k=k+((b-a)*2);
    

    for(int i=1; i<n-1; i++)
    {
        
        m=pow(10,i);
        b=(x - (x%m))/10;
        if( (b-(a+1))*(a+i) > 0)
        {
            if(i==n-2) k=k+((b-(a+1))*(a+i));
            else k=k+((b-(a+1))*2);

        }
    }

    cout<<k;


}