#include <iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
bool cmp(int a,int b) //降序
{
return a > b;
}
int getNumber(int a[],int len) //从数组取出数字
{
int sum = 0;
for(int i=len-1;i>=0;i--)
{
sum = sum*10 + a[i];
}
return sum;
}
void saveArray(int a[],int len,int n){ //数字存入数组
for(int i=0;i<len;i++)
a[i] = 0;
len--;
while(len >=0 && n!=0){
a[len--] = n % 10;
n = n / 10;
}
}
int main()
{
int a[4] = {0};
int number;
scanf("%d",&number);
int i=3;
do{
a[i--] = number % 10;
number = number / 10;
}while(number != 0 && i>=0);
int in_number;
int de_number;
int result;
do{
sort(a,a+4); //升序
in_number = getNumber(a,4);
sort(a,a+4,cmp);//降序
de_number = getNumber(a,4);
result = in_number - de_number;
printf("%04d - %04d = %04d\n",in_number,de_number,result);
saveArray(a,4,result);
}while(result != 0 && result != 6174);
return 0;
}