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++ (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>

#define ll long long
#define reg register
#define rep(i, a, b) for(int i = a; i <= b; ++i)

using namespace std;
int d, N = 17;
ll ans, a, b = 1;
int main() {
    scanf ("%d", &d);
    if (d % 9) {
        puts("0");
        return 0;
    }
    d /= 9;
    rep (i, 1, N) {
        reg ll res = 1, tmp = d, all = a * 10 + 1, l = b, r = 1;
        rep (j, 0, i / 2) {
            reg ll tmp = tmp % (r * 10) / r;            
            reg ll x = 10 - abs(tmp);
            if (!j) x--;
            res *= x, tmp -= all * tmp, all -= l + r, l /= 10, r *= 10;
        }
        b *= 10, a = a * 10 + 1;
        if(!tmp) ans += res;
    }
    printf ("%lld\n", ans);
    return 0;
}