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)

#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define ll long long
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define fd(i,x,y) for(ll i=x;i>=y;i--)
#define MAX_CNT maxn
using namespace std;

const ll maxn=10000007;

ll n,Ans;
ll _10[15];

void Init(){
	_10[0]=1;
	fo(i,1,14) _10[i]=_10[i-1]*10;
	scanf("%lld",&n);
}

ll Now,Rev,cnt;
void dfs(int v,int Num,int Cur){
	//if (cnt>MAX_CNT) return;
	if (Now && abs(Rev-Now-n)>_10[Num*2-v]*10) return;
	if (Now && Rev-Now<-_10[Num*2-v]*10) return;
	cnt++;
	if (v>Num){
		if (Now<_10[Num*2-1]) return ;
		if (Rev-Now==n){
			Ans++;
		}
		return;
	}
	fo(i,0,9){
		int x=i+Cur+n/_10[v-1]%10;
		Now+=i*_10[v-1]+x%10*_10[Num*2-v];
		Rev+=x%10*_10[v-1]+i*_10[Num*2-v];
		dfs(v+1,Num,x/10);
		Now-=i*_10[v-1]+x%10*_10[Num*2-v];
		Rev-=x%10*_10[v-1]+i*_10[Num*2-v];
	}
}
void Dfs(int v,int Num,int Cur){
	//if (cnt>MAX_CNT) return;
	if (Now && abs(Rev-Now-n)>_10[Num*2-v-1]*10) return;
	if (Now && Rev-Now<-_10[Num*2-v-1]*10) return;
	cnt++;
	if (v>Num){
		if (Now<_10[Num*2-2]) return ;
		if (Rev-Now==n) {
			Ans++;
		}
		return;
	}
	if (v==Num){
		fo(i,0,9){
			Now+=i*_10[v-1];
			Rev+=i*_10[v-1];
			Dfs(v+1,Num,0);
			Now-=i*_10[v-1];
			Rev-=i*_10[v-1];
		}
	}else fo(i,0,9){
		ll x=i+Cur+n/_10[v-1]%10;
		Now+=i*_10[v-1]+x%10*_10[Num*2-1-v];
		Rev+=x%10*_10[v-1]+i*_10[Num*2-1-v];
		Dfs(v+1,Num,x/10);
		Now-=i*_10[v-1]+x%10*_10[Num*2-1-v];
		Rev-=x%10*_10[v-1]+i*_10[Num*2-1-v];
	}
}
void Solve(){
	fo(i,1,7){
		dfs(1,i,0);
		Dfs(1,i,0);
	}
}

void Print(){
	printf("%lld\n",Ans);
	//printf("%lld",cnt);
}

int main(){
	Init();	
	Solve();
	Print();
	return 0;
}