Problem:
Score : 800 points

Problem Statement

For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.

You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?

Constraints

D is an integer.

1 ≤ D < 10^9

Input

Input is given from Standard Input in the following format:

D

Output

Print the number of the positive integers N such that rev(N) = N + D.

Sample Input 1

63

Sample Output 1

2

There are two positive integers N such that rev(N) = N + 63: N = 18 and 29.

Sample Input 2

75

Sample Output 2

0

There are no positive integers N such that rev(N) = N + 75.

Sample Input 3

864197532

Sample Output 3

1920

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
int a[20],b[20],ten[9];
int d;
int i,j,k,l,t,n,m,tot,top;
ll num,sum,wdc,pp,ans;
bool czy;
int main(){
    ten[0]=1;
    fo(i,1,8) ten[i]=ten[i-1]*10;
    scanf("%d",&d);
    pp=1;
    if (d%10==0){
        czy=1;
        while (d%10==0){
            d/=10;
            pp*=10;
        }
        pp=pp/10*9;
    }
    fo(l,1,7)
    fo(i,0,ten[l]-1){
        t=0;
        k=i;
        top=0;
        fo(j,1,l){
            a[++top]=k%10;
            k/=10;
        }
        k=i+d;
        tot=0;
        fo(j,1,top){
            b[++tot]=k%10;
            k/=10;
        }
        if (!czy&&b[1]==0) continue;
        reverse(b+1,b+tot+1);
        fo(j,1,tot) a[++top]=b[j];
        num=0;
        wdc=1;
        fo(j,1,top){
            num+=(ll)a[j]*wdc;
            wdc*=10;
        }
        sum=0;
        wdc=1;
        reverse(a+1,a+top+1);
        fo(j,1,top){
            sum+=(ll)a[j]*wdc;
            wdc*=10;
        }
        if (num+(ll)d==sum){
            ans++;
        }
        //continue;
        reverse(a+1,a+top+1);
        top-=tot;
        a[++top]=0;
        fo(j,1,tot) a[++top]=b[j];
        num=0;
        wdc=1;
        fo(j,1,top){
            num+=(ll)a[j]*wdc;
            wdc*=10;
        }
        sum=0;
        wdc=1;
        reverse(a+1,a+top+1);
        fo(j,1,top){
            sum+=(ll)a[j]*wdc;
            wdc*=10;
        }
        if (num+(ll)d==sum){
            ans+=10;
        }
    }
    ans*=pp;
    printf("%lld\n",ans);
}