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

#include <cstdio>

const int N = 10 + 5;
typedef long long LL;

int d;

LL ans = 0;
bool odd;

void dfs(int bit, LL lval, LL rval, LL ret, LL ways, int st) {
	// std::printf("dfs(bit = %d, lval = %lld, rval = %lld, ret = %lld, ways = %lld)\n", bit, lval, rval, ret, ways);
	if(bit == 0) {
		if(ret == d) ans += ways * (odd ? 10 : 1);
		return;
	}
	for(int i = st; i <= 9; i++)
		dfs(bit - 1, lval / 10, rval * 10, ret + (lval - rval) * i, ways * (10 - i - st), 0);
}

int main() {
	std::scanf("%d", &d);
	int b = 0, tmp = d;
	LL v = 1;
	while(tmp) b++, v *= 10, tmp /= 10;
	v /= 10;
	odd = (b & 1), dfs(b >> 1, v, 1, 0, 1, 1);
	// odd = !(b & 1), dfs((b + 1) >> 1, v * 10, 1, 0, 1, 1);
	std::printf("%lld\n", ans);
	return 0;
}