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: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}


ll ten[20];

ll val = 0;
void f(int L, int R, ll D) {
  if (L > R) {
    if (D == 0) val++;
    return;
  }

  if (abs(D) > ten[R+1]) return;
  // cout << L << " " << R << " " << D << endl;

  if (L == R) {
    f(L+1, R-1, D);
  } else {
    for (int i = 0; i <= 9; i++) {
      if (L == 0 && i == 0) continue;
      for (int j = 0; j <= 9; j++) {
        ll D2 = D - (ten[R] - ten[L]) * (j - i);
        f(L+1, R-1, D2);
      }
    }
  }

}

int main2() {
  ll D = nextLong();

  ten[0] = 1;
  REP(i, 19) ten[i+1] = ten[i] * 10;

  ll ans = 0;
  for (int k = 1; k <= 12; k++) {
    val = 0;
    f(0, k-1, D);
    if (k > 1 && k % 2 == 1) val *= 10;
    ans += val;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}