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 <bits/stdc++.h>

using namespace std;

int D,ans;
int ten[15];

void cnt(int n){
  for(int i1=1; i1<9; i1++){
    int N1=0; int num1=0;
    N1+=(ten[n-1]-ten[0])*i1; num1+=(9-i1);
    if(n<=3){
      if(N1==D){
        if(n%2==0) ans+=num1;
        if(n%2==1) ans+=(num1*10);
        return;
      }
    }
    if(n<=3) continue;
    for(int i2=-9; i2<=9; i2++){
      int N2=0; int num2=0;
      N2+=(ten[n-1]-ten[0])*i1; num2+=(9-i1);
      N2+=(ten[n-2]-ten[1])*i2; num2*=(10-abs(i2));
      if(n<=5){
        if(N2==D){
          if(n%2==0) ans+=num2;
          if(n%2==1) ans+=(num2*10);
          return;
        }
      }
      if(n<=5) continue;
      for(int i3=-9; i3<=9; i3++){
        int N3=0; int num3=0;
        N3+=(ten[n-1]-ten[0])*i1; num3+=(9-i1);
        N3+=(ten[n-2]-ten[1])*i2; num3*=(10-abs(i2));
        N3+=(ten[n-3]-ten[2])*i3; num3*=(10-abs(i3));
        if(n<=7){
          if(N3==D){
            if(n%2==0) ans+=num3;
            if(n%2==1) ans+=(num3*10);
            return;
            }
        }
        if(n<=7) continue;
        for(int i4=-9; i4<=9; i4++){
          int N4=0; int num4=0;
          N4+=(ten[n-1]-ten[0])*i1; num4+=(9-i1);
          N4+=(ten[n-2]-ten[1])*i2; num4*=(10-abs(i2));
          N4+=(ten[n-3]-ten[2])*i3; num4*=(10-abs(i3));
          N4+=(ten[n-4]-ten[3])*i4; num4*=(10-abs(i4));
          if(n<=9){
              if(N4==D){
                if(n%2==0) ans+=num4;
                if(n%2==1) ans+=(num4*10);
                return;
              }
          }
          if(n<=9) continue;
          for(int i5=-9; i5<=9; i5++){
            int N5=0; int num5=0;
            N5+=(ten[n-1]-ten[0])*i1; num5+=(9-i1);
            N5+=(ten[n-2]-ten[1])*i2; num5*=(10-abs(i2));
            N5+=(ten[n-3]-ten[2])*i3; num5*=(10-abs(i3));
            N5+=(ten[n-4]-ten[3])*i4; num5*=(10-abs(i4));
            N5+=(ten[n-5]-ten[4])*i5; num5*=(10-abs(i5));
            if(n<=10){
              if(N5==D){
                if(n%2==0) ans+=num5;
                if(n%2==1) ans+=(num5*10);
                return;
              }
            }
          }
        }
      }
    }
  }
  return;
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>D;

int mul=0;
while(D%10==0){
  D=D/10; mul++;
}
int x=1,dig=0;
while(D/x){
  x*=10; dig++;
}

ten[0]=1;
for(int i=1; i<10; i++){
  ten[i]=ten[i-1]*10;
}

if(dig==1){
  cnt(dig+1);
}else{
  cnt(dig);
  cnt(dig+1);
}
ans*=(9*mul);

cout<<ans<<endl;

}