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 9.2.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> g,v;
map<ll,ll> ANS,mp,mp1;
ll ans = 0,d,pw10[20],digit;
ll solve(int n,ll d) {
	if (n == 1)	{
		if (d == 0) return 10;
		return 0;
	}
	if (n == 0) return d == 0;
	ll x = pw10[n-1] - 1;
	for (int i = -9; i <= 9; i++) {
		if ( abs(d - x*i) < pw10[n-1] ) {
			if ((d - x*i)%10 == 0) {
				ll f = 0;
				if (digit == n) f = mp1[i];
				else f = mp[i];
			return solve(n-2,(d - x*i)/10)*f;
		}
		}
	}
	return 0;
}
main() {
	ll d;
	cin >> d;
	pw10[0] = 1;
	for (int i = 1; i <= 18; i++) 
		pw10[i] = pw10[i-1]*10;
	for (int i = 0; i <= 9; i++)
	for (int j = 0;j  <= 9; j++)
		mp[i-j]++;
	for (int i = 1; i <= 9; i++)
	for (int j = 1; j <= 9; j++) {
		mp1[i-j]++;
	}
	ll ans = 0;
	for (int i = 1; i <= 18; i++) {
		digit = i;
		ans += solve(i,d);
	}
	cout << ans;
}