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>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int> pii;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}

ll D;
ll ans;

ll pw[12];
int vv[12];

ll calc(int bb,int num){
//	for(int i=0;i<bb;i++)cout<<vv[i]<<' ';cout<<endl;
	if(num%2==1&&vv[bb-1]!=0)return 0;
	ll tmp=1;
	for(int i=0;i<bb;i++){
		int cnt=0;
		for(int j=0+(i==0);j<10;j++){
			if(j+vv[i]>=0&&j+vv[i]<10){
				cnt++;
			}
		}
		tmp=tmp*cnt;
	}
	return tmp;
}
void dfs(int i,int num,ll sum){
	if(i==(num+1)/2){
		if(sum==D){
			ans+=calc((num+1)/2,num);	
		}
		return;
	}
	for(int diff=-9;diff<=9;diff++){
		ll tmp=pw[num-1-i]-pw[i];
		tmp=tmp/9;
		vv[i]=diff;
		dfs(i+1,num,sum+tmp*diff);
	}
}

int main(){
	cin>>D;
	if(D%9!=0){
		cout<<0<<endl;
		return 0;
	}
	pw[0]=1;
	for(int i=1;i<12;i++)pw[i]=pw[i-1]*10;
	
	D=D/9;
	for(int num=2;num<=10;num++){
		dfs(0,num,0);
	}
	cout<<ans<<endl;
	return 0;
}