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)

#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define debug(x) #x << " = " << (x) << " "
using ll = long long;
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

ll solve_n(ll d, int log_n) {
    array<ll, 18> repunit; repunit[0] = 0; repeat (i, repunit.size()-1) repunit[i+1] = repunit[i] * 10 + 1;
    ll acc = 1;
    ll ten = 1;
    for (int i = 0; ; ++ i) {
        ll e = repunit[log_n+1-i] - repunit[i];
        if (e == 0) acc *= 10;
        if (e <= 0) break;
        int k = -9;
        while (k + 1 < 10 and (k + 1) * e <= d) ++ k;
        d -= k * e;
        ten *= 10;
        while (d % ten != 0 and k + 1 < 10) {
            ++ k;
            d -= e;
        }
        int digits = 0;
        repeat (a, 10) repeat (b, 10) {
            if (i == 0 and b == 0) continue;
            if (a - b == k) {
                digits += 1;
            }
        }
        acc *= digits;
    }
    return d == 0 ? acc : 0;
}
ll solve(ll d) {
    if (d % 9 != 0) return 0;
    d /= 9;
    ll result = 0;
    repeat (n, 15) {
        result += solve_n(d, n);
    }
    return result;
}

int main() {
    int d; scanf("%d", &d);
    printf("%lld\n", solve(d));
    return 0;
}