#t51. 四位黑洞数

四位黑洞数

The Four-Digit Black Hole Number

Problem Description

The black hole number (also called trap number, or the "Kaprekar problem") is a class of numbers with a peculiar transformation property. Any four-digit number whose digits are not all the same will, after a finite number of "rearrange-and-subtract" operations, always reach 61746174. The resulting 61746174 is the four-digit black hole number. (495495 is the three-digit black hole number.) The so-called "rearrange-and-subtract" operation means: subtract the smallest number formed by rearranging the digits from the largest number formed by rearranging the digits.

For example, for the four-digit number 12341234:

  • 1st operation: 4321−1234=30874321 - 1234 = 3087;
  • 2nd operation: 8730−378=83528730 - 378 = 8352 (note: 03780378 is written as 378378);
  • 3rd operation: 8532−2358=61748532 - 2358 = 6174;

after which it stays at the black hole number 61746174. If the four digits of the number are all the same, one operation yields 00.

Given any four-digit number, write a program that prints the rearrange-and-subtract process.

Input Format

A four-digit number given on one line.

Output Format

Print the rearrange-and-subtract process in the following format:

index: largestRearrangedNumber - smallestRearrangedNumber = difference

The index starts from 11 and continues until 61746174 appears on the right side of the equals sign.

Sample Input

1234

Sample Output

1: 4321 - 1234 = 3087
2: 8730 - 378 = 8352
3: 8532 - 2358 = 6174

Sample Explanation

The input four-digit number is 12341234. First rearrange the digits 1,2,3,41,2,3,4 to get the largest number 43214321 and the smallest number 12341234, subtract to get 30873087. Then repeat the operation on 30873087: rearrange to get the largest number 87308730 and the smallest number 03780378 (written as 378378), subtract to get 83528352. Continue: rearrange to get largest 85328532 and smallest 23582358, subtract to get 61746174, and the process ends.

Constraints

The input four-digit number satisfies 1000≤n≤99991000 \le n \le 9999.