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 5.4.1) (judge verdict: Wrong Answer)

#include <cstdio>
#include <algorithm>
#define R register
#define ll long long
using namespace std;

ll base[40];
int D;
int ans=0;

inline void dfs(int now,int len,ll sum)
{
	if(now==(len+1)/2+1)
	{
		if(sum==D) ans++;
		return ;
	}
	if(sum>=D) return;
	for(R int a1=1;a1<=9;a1++)
		for(R int an=0;an<=9;an++)
			dfs(now+1,len,sum+(ll)(base[len-now]-base[now-1])*(an-a1));
}

int main()
{
	scanf("%d",&D);
	base[0]=1;
	for(R int i=1;i<=18;i++) base[i]=base[i-1]*10;
	for(R int i=1;i<=7;i++) dfs(1,i,0);
	if(ans) printf("%d\n",ans);
}