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 Ruby (2.3.3) (judge verdict: Accepted)

d = gets.to_i

ans = 0
20.downto(2) do |n_keta|
	cur = -d
	cnt = 1
	if -cur % 10 == 1
		break
	elsif -cur % 10 == 0
		cnt *= 9
	else
		sa = 10 - (-cur % 10)
		cnt *= 9 - sa
		cur += sa * (10 ** (n_keta - 1) - 1)
	end
	if cur > 0
		cur /= 10
	else
		cur = -(-cur / 10)
	end
	1.upto(n_keta / 2 - 1) do |i|
		if cur == 0
			cnt *= 10
		elsif cur > 0
			sa = (10 - cur % 10) % 10
			cnt *= 10 - sa
			cur = cur - sa * (10 ** (n_keta - 1 - i * 2) - 1)
		else
			sa = (10 - (-cur % 10)) % 10
			cnt *= 10 - sa
			cur = cur + sa * (10 ** (n_keta - 1 - i * 2) - 1)
		end
		if cur > 0
			cur /= 10
		else
			cur = -(-cur / 10)
		end
	end
	next if cur != 0
	if n_keta % 2 == 1
		ans += cnt * 10
	else
		ans += cnt
	end
end
p ans