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 <= i; j ++ ) {
            if(i - j == n ) ans ++;
        }
    }
//    db(ans);
    return ans;
}
int main()
{

    p10[0]=1;
    for(int i=1;i<20;i++) p10[i] = 10*p10[i-1];
//    db(p10[19]);
    long long d;
    cin>> d;
//    long long br = 0;
//    for(int i = 1;i <= 100000;i ++ ) {
//        string t = to_string(i);
//        string v = t; reverse(v.begin(), v.end());
//        int num1 = 0, num2 = 0;
//        for(int i = 0; i < v.size() ; i ++ ) num1 = 10 * num1 + v[i] - '0';
//        for(int i = 0; i < t.size(); i ++ ) num2 = 10 * num2 + t[i] - '0';
////        if(num1 == num2 + d ){
////            cout << num1 << " " << num2 << endl;
////        }
//    }
//    db(br);
    Ulong ans = 0;
    for(int n = 19; n >= 1; n-- ) {
        vector<Ulong> base;
        for(int i = n , j = 0; i > j; i --, j ++) {
            base.pb(p10[i]- p10[j]);
        }
//        for(auto a: base ) cout << a << " " ; puts("");
        long long now = d;
        Ulong add = 1;
        bool flag = 1;
        for(int i=0;i<base.size(); i ++ ) {
            Ulong vagfol = now / base[i];
            if(vagfol >= 10 ) {
                flag = 0;
                break;
            }
            if(i == 0 ) add *= func(vagfol ,1) ;
            else add *= func(vagfol , 0);
            now -= vagfol * base[i];
        }
//        db(flag);
//        db(add);
        if(flag == 0 || now ) continue;
        if(n%2==0) ans += add * 10;
    }
    cout << ans << endl;
    return 0;
}