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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 20;

int d, dig;
long long ans = 0;
long long p10[MAXN];
int b[MAXN];

void check(int L)
{
	// cerr << L << " : ";
	// for(int i = 0; i <= (L - 1) / 2; i++)
	// 	cerr << b[i] << ' ';
	// cerr << endl;
	long long ret = 9 - abs(b[0]);
	for(int i = 1; i <= (L - 1) / 2; i++)
		ret *= 10 - abs(b[i]);
	ans += ret;
}

void search(int h, int L, long long lef)
{
	if(h == (L - 1) / 2)
	{
		long long lam = (L & 1) ? p10[h] : p10[L - h - 1] - p10[h];
		if(lef % lam != 0)
			return ;
		long long tmp = lef / lam;
		if(-9 <= tmp && tmp <= 9)
		{
			b[h] = tmp;
			check(L);
		}
		return ;
	}
	long long lam = p10[L - h - 1] - p10[h];
	long long tmp1 = ceil((double)lef / lam), tmp2 = floor((double)lef / lam);
	if(-9 <= tmp1 && tmp1 <= 9)
	{
		b[h] = tmp1;
		search(h + 1, L, lef - tmp1 * lam);
	}
	if(tmp1 != tmp2 && -9 <= tmp2 && tmp2 <= 9)
	{
		b[h] = tmp2;
		search(h + 1, L, lef - (tmp2) * lam);
	}
}

void calc(int L)
{
	memset(b, 0, sizeof(b));
	search(0, L, d);
}

void work()
{
	dig = (int)(log10(d) + 1e-12) + 1;
	p10[0] = 1;
	for(int i = 1; i <= 18; i++)
		p10[i] = p10[i - 1] * 10;
	for(int i = dig; i <= 2 * dig; i++)
		calc(i);
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> d;

	work();

	return 0;
}