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 REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

ll ans, d;
ll ten[20];
ll mp[11];

void dfs(int l, int r, ll now, ll cou){
	if(l > r){
		if(now == d)ans += cou;
		return;
	}
	ll tmp = mp[l] * ten[l] - mp[l] * ten[r] * (l != r);
	dfs(l+1, r-1, now + tmp, cou * (10 - mp[l] - (l == 0)));
	tmp = (mp[l] - 10) * ten[l] - (mp[l] - 10) * ten[r] * (l != r);
	mp[l+1]++;
	dfs(l+1, r-1, now + tmp, cou * (10 + (mp[l] - 10) - (l == 0)));
	mp[l+1]--;
}

void init() {
	ten[0] = 1;
	REP(i,18)ten[i+1] = ten[i] * 10;
}

int main(){
	
	init();
	
	cin >> d;
	ll dd = d;
	REP(i, 11){
		mp[i] = dd % 10;
		dd /= 10;
	}	
	
	for(int i = 1;i <= 17;i++){
		dfs(0, i, 0, 1);
	}
	cout << ans << endl;
	
	return 0;
}