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<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int d0[50],d1[50],m,mm;
long long ans,d,wei,te,ten[18];
//81000 wei+3
void dfs(int x,long long v,long long s){
	if (abs(v)>d*110) return;//12
	//printf("%d %lld %lld\n",x,v,s);
	if (x>mm){//>m
		if (v==d){
			//printf("%d %lld %lld\n",x,v,s);
			if (m&1) ans+=s*10;else ans+=s;//(m>2)&&
		}
		return;
	}
	if (x==1){
		fo(i,-9,8) dfs(x+1,v+i*(ten[m-x]-ten[x-1]),s*d1[i+20]);//m-i+1 i
		return;
	}
	fo(i,-9,9) dfs(x+1,v+i*(ten[m-x]-ten[x-1]),s*d0[i+20]);
}
inline void sol(int wei){
	if (wei<=1) return;
	m=wei;mm=m/2;
	dfs(1,0,1);
}
int main(){
	scanf("%lld",&d);
	if (d%9!=0){
		printf("0\n");
		return 0;
	}
	if (d==9){
		printf("8\n");
		return 0;
	}
	ten[0]=1;fo(i,1,17) ten[i]=ten[i-1]*10;
	fo(i,0,9) fo(j,0,9) d0[i-j+20]++;
	fo(i,0,9) fo(j,1,9) d1[i-j+20]++;
	te=d;
	while (te){
		wei++;
		te/=10;
	}
	//printf("%lld\n",wei);
	fo(i,-8,8) sol(wei+i);
	printf("%lld\n",ans);
	return 0;
}