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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int main(){
  ll d;
  int ans_c = 0;

  scanf("%lld",&d);

  
  for(int m=2;m<=11;m+=2){

    int t = m/2;
    
    ll p = (ll)pow(10,t);
    
    for(ll i=0;i<p;i++){
      
      ll q = 1;
      ll rest = d;
      string s,s2;
      char com[30];
      char s2_c[30];

      sprintf(com,"%%0%dd",t);
      sprintf(s2_c,com,i);
      s2 = s2_c;
      
      for(int j=0;j<t;j++){
        q *= 10;

        ll r = rest%q/(q/10);

        int b = (r + (s2[j]-'0'))%10;
        rest += (r + (s2[j]-'0'))/10 * q;
        
        s = "0" + s;
        s[0] += b; 
      }
      
      //reverse(s2.begin(),s2.end());
      
      string ans = s2 + s;
      
      ll w1 = stoll(ans);

      reverse(ans.begin(),ans.end());

      ll w2 = stoll(ans);
      
      if(w1-w2 == d && ans[0] != '0'){
        ans_c ++;
      }
      
      string ans2 = s2 + "0" + s;
      
      w1 = stoll(ans2);
      
      reverse(ans2.begin(),ans2.end());
      
      w2 = stoll(ans2);
      
      if(w1-w2 == d && ans2[0] != '0'){
        ans_c += 10;
      }
      
    }
    
  }

  for(int k=0;k<10;k++){
    string ans2 = "0";
    
    ans2[0] += k;
    
    int w1 = stoll(ans2);
    
    int w2 = stoll(ans2);
    
    if(w1-w2 == d && ans2[0] != '0'){
      ans_c ++;
      debug(ans2);
    }
  }
  
  cout << ans_c << endl;
  
  return 0;
}