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 <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

ll to_ll(string s) {
	ll res;
	stringstream ss(s);
	ss >> res;
	return res;
}

int main() {
	ll D; cin >> D;
	
	ll ans = 0;
	
	FOR(k, 1, 11) {
		string tmp(k, '0');
		
		ll t[6];
		REP(i, k / 2) {
			tmp[i] = '1';
			t[i] = to_ll(tmp);
			tmp[i] = '0';
			
			tmp[k - 1 - i] = '1';
			t[i] -= to_ll(tmp);
			tmp[k - 1 - i] = '0';
		}
		
		ll ma = 1;
		REP(i, k / 2) ma *= 10;
		
		for (ll tt = 0; tt < ma; tt++) {
			string a(k, '0');
			
			ll now = D;
			bool ng = false;
			
			ll ttt = tt;
			REP(i, k / 2) {
				a[i] = ttt % 10 + '0';
				now += t[i] * (ttt % 10);
				ttt /= 10;
			}
			
			REP(i, k / 2) {
				ll div = now / t[i];
				
				if (div >= 10) { ng = true; break; }
				else  {
					a[k - 1 - i] = div + '0';
					now -= t[i] * div;
				}
			}
			
			if (a[0] == '0' || now != 0) ng = true;
			if (ng) continue;
			
			ll p = 1;
			REP(i, (k + 1) / 2) p *= 10 - max(a[i] - '0', a[k - 1 - i] - '0');
			ans += p;
			
			break;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}