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<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in cnt(in dc, const VI& ddg, bool fst){
  if(dc==0){
    if(sz(ddg)==0)
      return 1;
    return 0;
  }
  if(dc==1){
    if(sz(ddg)==0)
      return 10;
    return 0;
  }
  in gl=0;
  if(sz(ddg)>0){
    gl=ddg[0];
    gl%=10;
    gl+=10;
    gl%=10;
  }
  in wy=0;
  VI cn;
  for(in c=-9;c<=9;++c){
    if((9*c%10+10)%10==gl)
      cn.PB(-c);
  }
  if(cn.empty())
    return 0;
  in cw;
  forv(z,cn){
    in df=cn[z];
    cw=0;
    for(in v1=(fst?1:0);v1<=9;++v1){
      if(v1+df>=0 && v1+df<=9 &&(!fst || v1+df>0))
	++cw;
    }
    VI td=ddg;
    while(sz(td)<dc)
      td.PB(0);
    forn(i,dc-1){
      td[i]+=df*9;
    }
    td.PB(0);
    in cc;
    forn(i,sz(td)-1){
      cc=td[i]/10;
      td[i]-=cc*10;
      td[i+1]+=cc;
      if(td[i]<0){
	td[i]+=10;
	td[i+1]-=1;
      }
    }
    assert(td[0]==0);
    forn(i,sz(td)-1){
      td[i]=td[i+1];
    }
    while(sz(td)>0 && td.back()==0)
      td.pop_back();
    cw*=cnt(dc-2,td,0);
    wy+=cw;
  }
  return wy;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in d;
  cin>>d;
  in sm=0;
  VI dd;
  while(d){
    dd.PB(d%10);
    d/=10;
  }
  for(in dc=2;dc<=50;++dc){
    sm+=cnt(dc,dd,1);
  }
  cout<<sm<<endl;
  return 0;
}