PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000029. Sắp chữ số và hiệu chia hết cho chín (Number Theory for Newbies)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sắp chữ số và hiệu chia hết cho chín (Number Theory for Newbies)

Number Theory for Newbies

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Rearrange all digits of a positive integer NN to form the largest number AA and the smallest number BB, neither with leading zeros. Compute A−BA-B and express the difference as 9⋅q9\cdot q in the required format.

Input

One line with decimal integer NN.

Output

Print exactly A - B = D = 9 * Q, where D=A−BD=A-B and Q=D/9Q=D/9.

Subtasks

  • Subtask 1 (20 points): 1≤N≤10001 \le N \le 1000
  • Subtask 2 (30 points): 1≤N≤1061 \le N \le 10^{6}
  • Subtask 3 (50 points): 1≤N≤1091 \le N \le 10^{9} (Phuoc Hung OJ version bound)

Examples

Input

3021

Output

3210 - 1023 = 2187 = 9 * 243

Explanation

The maximum arrangement is 32103210 and the minimum without leading zeros is 10231023. Their difference is 2187=9×2432187=9\times243.