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)

// Mirrored
// * frank_c1
// * 2017 / 09 / 27 

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int a[20], b[20], m, K, mode = 0;
LL pw[20];

int calc(int len) {
	if (len == 1) return 0;
	int w = (len + 1) >> 1, mx = 1, cnt = 0;
	for (int i = 1; i <= w; ++i) mx *= 10;
	for (int i = 1; i < mx; ++i) {
		int x = i, c = 0, g = 0, succ = 1; LL s = 0, rs = 0;
		for (; x; x /= 10) b[++c] = x % 10;
		for (int j = 1; j <= w; ++j) {
			s += pw[j - 1] * b[j]; rs += pw[len - j] * b[j];
			int now = a[j] + b[j] + g; g = now / 10; 
			if (j == 1 && (!mode && now % 10 == 0)) {
				succ = 0; break;
			}
			if (j * 2 <= len) s += pw[len - j] * (now % 10), rs += pw[j - 1] * (now % 10);
		} if (succ && s + K == rs) ++cnt; 
	} return cnt;
}

int main() {
	int n;
	scanf("%d", &n);
	LL ret = 1;
	if (n % 10 == 0) n /= 10, ret *= 9, mode = 1;
	while (n % 10 == 0) n /= 10, ret *= 10; K = n;
	for (; n; n /= 10) a[++m] = n % 10;
	pw[0] = 1; 
	for (int i = 1; i <= m; ++i) pw[i] = pw[i - 1] * 10;
	ret *= (calc(m) + calc(m + 1));
	printf("%lld\n", ret);
	return 0;
}