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 <bits/stdc++.h>
using namespace std;
int D,DD;
long long ans=1,anss=0,m;
long long now,r;
long long bin[16];
int main()
{
	scanf("%d",&D);
	bin[0]=1;
	DD=D;
	for (int i=1;i<=15;i++) bin[i]=10LL*bin[i-1];
for (int S=15;S;S--)
{
	D=DD;
	ans=1;
	long long cnt=0;
	for (int i=S-1;i>=0;i--)
		if (i>(S-1)/2) cnt+=bin[i]; else cnt-=bin[i];
	if (D>9LL*cnt) break;
	int i=S-1;
	m=9;
	if (D%m!=0) break;
	while (D>=0&&i>S-1-i)
	{
		now=bin[i]-bin[S-1-i];
		m=10LL*m;
		if ((D%now)%m==0)
		{
			r=D/now;
			if (i==S-1) ans=1LL*ans*(9-r); else ans=1LL*ans*(10-r);
			D=D%now;
		} else
		{
			r=(D/now)+1;
			D=now-D%now;
			if (i==S-1) ans=1LL*ans*(9-r); else ans=1LL*ans*(10-r);
		}
		cnt-=bin[i]-bin[S-1-i];
		if (D>9LL*cnt) break;
		i--;
	}
	if (D==0&&S%2==1) 
	{
		if (S==1) ans=9LL*ans; else ans=10LL*ans;
	}
	if (D==0) anss+=ans;
}
	cout << anss << endl;
	return 0;
}