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>
#define LL long long
using namespace std;
LL sum = 0;
LL Pow[20];
int main(){
	LL d;
	Pow[1] = 1;
	for(int i = 2; i <= 19; i++) Pow[i] = Pow[i - 1] * 10;
	scanf("%lld", &d);
	LL s = d;
	for(int i = 2; i <= 19; i++){
		s = d;
		LL tmp = 1;
		if(Pow[i + 1] - 1 < d) continue;
		int k = (i + 1) / 2;
		for(int j = i; j > k; j--){
			LL t = Pow[j] - Pow[i - j + 1];
			if(s < t) tmp *= 9 + (i != j);
			else if(s >= t){
				int kk = s / t;
				if(kk >= 10) break;
				tmp *= 9 - kk + + (i != j);
				s -= kk * t;
			}
		}
		if(i % 2) tmp *= 10;
		if(s) tmp = 0;
		sum += tmp;
	}
	cout << sum << endl;
}