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 5.4.1) (judge verdict: Accepted)

#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)


ll p10[20];
ll temp[20];
ll ans;
void f(ll rest,ll keta,ll c){
	
	if(c>(keta-1)/2){
		//終わり
		ll t=1;
		rep(i,0,c)t*=10-temp[i]-!i;
		ans+=t;
		return;
	}
	int t=(10-rest%10)%10;
	
	//正のとき
	if(llabs(rest-(p10[keta-1-c*2]-1)*t)<p10[keta-1-c*2]){
		temp[c]=t;
		f((rest-(p10[keta-1-c*2]-1)*t)/10,keta,c+1);
	}
	//負のとき
	if(t!=0&&llabs(rest-(p10[keta-1-c*2]-1)*(t-10))<p10[keta-1-c*2]){
		temp[c]=10-t;
		f((rest-(p10[keta-1-c*2]-1)*(t-10))/10,keta,c+1);
	}
}

int main(){
	ll d;
	scanf("%lld",&d);
		
	p10[0]=1;
	rep(i,1,20)p10[i]=p10[i-1]*10;
	
	rep(i,1,19)f(d,i,0);
	printf("%lld",ans);
}