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: Wrong Answer)

/*
 * DATE : 2017-06-03
 * Algo :
*/
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define Long                    long long
#define Ulong                   unsigned long long
#define FOR(I,A,B)              for(long long i=0; i < n ; i++ )
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-9
#define F                       first
#define S                       second
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl;
#define Di(x)                   int x; cin>>x
#define in(x)                   input(x)
#define in2(x,y)                input(x), input(y)
#define in3(x,y,z)              input(x), input(y),input(z)
#define ins(x)                  scanf("%s",x)
#define ind(x)                  scanf("%lf",&x)
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)

template<class T > void input(T &x){
    char c = getchar();x = 0;
    for(;(c<48 || c>57);c = getchar());
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
}
inline long long bigmod(long long p,long long e,long long M){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/

const int N = 1001;

Ulong p10[20];
long long pre[10];


int func(int n,int t)
{

    int ans = 0;
    for(int i = 0; i < 10;i ++ ) {
        for(int j = t; j <10; j ++ ) {
            if(i - j == n ) ans ++;
        }
    }
//    db(ans);
    return ans;
}

Ulong ans = 0;
vector<Ulong> base;
long long findMin(int pos)
{
    long long ret = 0;
    for(int i = pos;i < base.size(); i ++ ) {
        ret += -9LL * base[pos];
    }
    return ret;
}
long long findMax(int pos)
{
    long long ret = 0;
    for(int i = pos;i < base.size(); i ++ ) {
        ret += 9LL * base[pos];
    }
    return ret;
}
long long d;
long long solve(int now,long long sum)
{
    if(now == base.size()) {
        return (sum == d);
    }
    long long ret = 0;
    if(base[now]== 0) {
        if(sum == d ) return 10;
        return 0;
    }
    for(int i= -9;i<10;i++){
        int t = func(i, now == 0 ? 1: 0);
        long long p1 = findMin(now+1);
        long long p2 = findMax(now+1);
        if(sum + base[now] * i + p1 > d ) continue;
        if(sum + base[now] * i + p2 < d ) continue;
        ret += solve(now+1,sum + base[now] * i) * t ;


    }
//    db(now);
//    db(sum);
//    db(ret);
    return ret;
}
int main()
{

    p10[0]=1;
    for(int i=1;i<20;i++) p10[i] = 10*p10[i-1];

    cin>> d;

    for(int n = 19; n >= 1; n-- ) {
        base.clear();
        for(int i = n , j = 0; i >= j; i --, j ++) {
            base.pb(p10[i]- p10[j]);
        }

        //db(base.size());
        ans += solve(0,0);


    }
    cout << ans << endl;
    return 0;
}