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<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
int n;
ll ans,sum[25];
ll dp(int len,int j,ll S){
	if(j==len-j)return (!S)*10;
	if(j>len-j)return !S;ll tmp=S/(sum[len-j]-sum[j]);
	if(abs(tmp)>=10)return 0;//printf("%d\n",)
	int fail=10-abs(tmp)-(!j),suc=10-abs(tmp)-1-(!j);if(suc<0)suc=0;
	if(tmp<0)return dp(len,j+1,S-tmp*(sum[len-j]-sum[j]))*fail+dp(len,j+1,S-(tmp-1)*(sum[len-j]-sum[j]))*suc;
	else return dp(len,j+1,S-tmp*(sum[len-j]-sum[j]))*fail+dp(len,j+1,S-(tmp+1)*(sum[len-j]-sum[j]))*suc;
}
int main(){
//	freopen("test.in","r",stdin);
//	freopen("mysol.out","w",stdout);
	scanf("%d",&n);
	if(n%9)return 0*puts("0");sum[0]=1;
	for(int i=1;i<=19;i++)sum[i]=sum[i-1]*10;
	for(int i=1;i<=19;i++){
		int tmp=n;ans+=dp(i,0,n);
	}printf("%lld\n",ans);
}