Find the closest palindromic number Given a number N, output/return X so that N+X is a palindrome, where |X| has to be as small as possible.

Palindrome: A number is a palindrome, if its sequence of digits is the same when reading them from left to right as when reading from right to left. 95359 and 6548456 are symmetric, 123 and 2424 are not. Numbers with leading zeros such as 020 are not a palindrome.

Input is a positive integer smaller than 1015. Read it from stdin, as a method-parameter, whatever.

Output has to be an integer (positive or negative) and ought to be 0 if the input is already a palindrom. You may write your output to stdout, return it from a function or whatever you like. If there are 2 numbers (e.g. 2 and -2) that satisfy the requirements, output only one of them.

Examples:

Input             Output
3                 0
234               -2
1299931           -10
126               5 or -5 (only one of them)
Pyth, 26 20
Lnb_bWP`+QZ=Z-g0ZZ)Z

Updated to meet the new rules.
The program runs in an infinite loop which tests every possible increment, in the order 0, -1, 1, -2, -2 ...
Explanation:
Q=eval(input())     implicit
Z=0                 implicit
Lnb_b               def P(b): return b != rev(b)
WP`+QZ              while P(repr(Q+Z)):
=Z-g0ZZ             Z=(0&gt;=Z)-Z
)                   &lt;end while&gt;
Z                   print(Z)

Example run:
python3 pyth.py programs/palin.pyth &lt;&lt;&lt; 965376457643450
-2969881

This took 23 seconds.

Bonus solution, same character count:
Wn`+QZ_`+QZ=Z-g0ZZ)Z