#include<bits/stdc++.h>
using namespace std;
bool cmp(char a,char b){
if(a!=b){
return a>b;
}
}
int main(){
string s;
cin>>s;
while(s.length()<4){
s='0'+s;
}
{
sort(s.begin(),s.end(),cmp);
string a1=s;
sort(s.begin(),s.end());
string a2=s;
int _sum=stoi(a1)-stoi(a2);
s=to_string(_sum);
while(s.length()<4){
s='0'+s;
}
cout<<a1<<" - "<<a2<<" = "<<s<<endl;
}while(s!="6174"&&s!="0000");
return 0;
}
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b){
if(a!=b){
return a>b;
}
}
int getnum1(int a){
vector<int> ppp;
while(a/10!=0){
ppp.push_back(a%10);
a=a/10;
}
ppp.push_back(a);
while(ppp.size()<4){
ppp.push_back(0);
}
sort(ppp.begin(),ppp.end());
return ppp[0]*1000+ppp[1]*100+ppp[2]*10+ppp[3];
}
int getnum2(int a){
vector<int> ppp;
while(a/10!=0){
ppp.push_back(a%10);
a=a/10;
}
ppp.push_back(a);
while(ppp.size()<4){
ppp.push_back(0);
}
sort(ppp.begin(),ppp.end(),cmp);
return ppp[0]*1000+ppp[1]*100+ppp[2]*10+ppp[3];
}
int main()
{
int n;
cin>>n;
if((n%10==n/1000)&&(n%10==(n/10)%10)&&(n%10==(n/100)%10)&&n>=1000){
printf("%04d - %04d = 0000",n,n);
return 0;
}
int temp=n;
do{
printf("%04d - %04d = %04d\n",getnum2(temp),getnum1(temp),getnum2(temp)-getnum1(temp));
temp=getnum2(temp)-getnum1(temp);
}while(temp!=6174);
return 0;
}