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<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

ll pow10(ll x) {
	ll a = 1;
	REP(i, 1, x) {
		a *= 10;
	}
	return a;
}

ll par(ll t, ll i) {
	return 10 - abs(t) - (i == 0);
}

ll f(ll k,ll i) {
	return pow10(k - i) - pow10(i);
}

ll h(ll k, ll n, ll i) {
	if (i * 2 > k) {
		return (n == 0);
	}
	else if (i * 2 == k) {
		return (n == 0) * 10;
	}
	else {
		ll t = n / f(k, i);
		if (t >= 10) {
			return 0;
		}
		ll res = par(t, i)* h(k, n - t * f(k, i), i + 1);
		if (t != 9) {
			res += par(t + 1, i) * h(k, -n + (t + 1)*f(k, i), i + 1);
		}
		return res;
	}
}

ll g(ll k, ll n) {
	return h(k, n, 0);
}

int main() {
	ll n;
	cin >> n;
	if (n % 9 != 0) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	REP(k, 1, 100000) {
		if (n < f(k, (k - 1) / 2)) {
			break;
		}
		ans += g(k, n);
	}
	cout << ans << endl;
}