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: Wrong Answer)

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int val[12][7];
void Find_Val(){
	for (int i=2;i<11;i++){
		for (int j=0;j<i/2;j++){
			val[i][j]=(pow(10,i-1-2*j)-1)*pow(10,j);
		}
	}
}
int Ans;
vector<int>v;
int need;
void DFS(int bit,int dep){
	if (dep==bit/2){
		if (need)  re;
		int cur=pow(10,bit&1);
		for (int i=0;i<sz(v);i++)
			cur*=(10-(!i)-v[i]);
		Ans+=cur;
		re;
	}
	for (int i=0;i<10;i++){
		if (need-i*val[bit][dep]<0)
			re;
		need-=i*val[bit][dep]; v.pb(i);
		DFS(bit,dep+1);
		need+=i*val[bit][dep]; v.erase(v.end()-1);
	}
}
signed main()
{
	int n;
	cin>>n;
	if (n%9){
		cout<<0;
		re 0;
	}
	Find_Val();
	need=n;
	for (int i=0;i<11;i++){
		DFS(i,0);
	}
	cout<<Ans;
	re 0;
}