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: Accepted)

//#include<bits/stdc++.h>
//using namespace std;
//typedef long long ll;
//ll d,x,ans;
//vector<ll>vec,res;
//ll next(ll a)
//{
//	ll cnt=10;
//	while(a%10==0)
//	{
//		a/=10;
//		cnt*=10;
//	}
//	if(a<100)return -1;
//	return a/100*cnt;
//}
//void dfs(int x,ll k)
//{
//	cout<<x<<' '<<k<<endl;
//	if(x==vec.size())
//	{
//		if(k==0)
//		{
//			ll cnt=1;
//			for(int i=0;i<res.size();i++)
//				cnt*=9ll-res[i];
//			ans+=cnt;
//		}
//		return;
//	}
//	res.push_back(k%10);
//	dfs(x+1,abs(k-k%10*vec[x])/10);
//	res.pop_back();
//	if(k%10!=0)
//	{
//		res.push_back(10-k%10);
//		dfs(x+1,abs(k+(10-k%10)*vec[x])/10);
//		res.pop_back();
//	}
//}
//int main()
//{
//	cin>>d;
//	if(d%9!=0)
//	{
//		cout<<0;
//		return 0;
//	}
//	d/=9;
//	for(int i=2;;i++)
//	{
//		x*=10ll;
//		x++;
//		ll y=x;
//		vec.clear();
//		res.clear();
//		vec.push_back(x);
//		while(next(y)!=-1)
//		{
//			vec.push_back(next(y));
//			y=next(y);
//		}
//		for(int j=0;j<vec.size();j++)cout<<vec[j]<<' ';
//		cout<<endl;
//		if(vec[vec.size()-1]>d)
//		{
//			if(i%2==1)dfs(0,d);
//			cout<<ans;
//			return 0;
//		}
//		dfs(0,d);
//	}
//	return 0;
//} 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll rt[30];
int main()
{
	ll D;
	cin>>D;
	rt[0]=1;
	for(int i=1;i<30;i++)rt[i]=rt[i-1]*10ll;
	ll ret=0;
	for(int i=2;i<=20;i++)
	{
		int k=i/2;
		for(int S=0;S<1<<k;S++)
		{
			ll way=i%2==1?10:1,zan=D;
			for(int j=0;j<k;j++)
			{
				ll d=llabs(zan)%10ll;
				if(zan<0)
				{
					d=10-d;
					d%=10;
				}
				if(S>>j&1)
				{
					ll nm=10ll-d;
					if(j==0)nm--;
					way*=nm;
					zan+=d*rt[i-2*j-1];
					zan-=d;
				}
				else
				{
					ll nm=d;
					if(j==0)nm--;
					if(nm<0)
					{
						way=0;
						break;
					}
					way*=nm;
					zan-=(10ll-d)*rt[i-2*j-1];
					zan+=10ll-d;
				}
				zan/=10ll;
			}
			if(zan==0)ret+=way;
		}
	}
	cout<<ret<<endl;
	return 0;
}