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 <cstring>
#define LL long long

LL D,p10[100];

LL dfs(int l,LL d,int flag){
	if(l<=1){
		if(d!=0) return 0;
		if(!l) return 1;
		return flag?10:9;
	}
	if(d%10!=0 && l>=15) return 0;
	LL temp=(d%10+10)%10;
	LL ans=0;
	if(temp<=9)
		ans+=(9-temp+flag)*dfs(l-2,(d-temp*(1-p10[l-1]))/10,1);
	if(temp-10>=-9)
		ans+=(temp-1+flag)*dfs(l-2,(d-(temp-10)*(1-p10[l-1]))/10,1);
	return ans;
}

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	p10[0]=1;
	for(int i=1;i<100;i++) p10[i]=p10[i-1]*10;
	scanf("%lld",&D);
	LL ans=0;
	for(int i=1;i<=30;i++)
		ans+=dfs(i,D,0);
	printf("%lld\n",ans);
}