#include <bits/stdc++.h>
using namespace std;

int main() {
    string s; cin >> s;
    int tmp = 8;
    map<char,int> sub;
    for(int i = 0; i < (int) s.size(); i++) sub[s.at(i)]++;
    vector<string> oct(0);
    int count = 1;


    bool result = false;
    if(s.size() == 1) {
        if(s == "8") result = true;
    } else if((int) s.size() == 2) {
        count = 2;
        while(tmp * count < 100) {
            oct.push_back(to_string(tmp * count));
            count++;
        }
        for(int i = 0; i < (int) oct.size(); i++) {
            bool isOk = true;
            map<char,int> tar = sub;
            for(int j = 0; j < (int) oct.at(i).size(); j++) {
                bool ari = false;
                if(tar[oct.at(i).at(j)] > 0) {
                    ari = true;
                    tar[oct.at(i).at(j)]--;
                }
                if(ari) continue;
                else {
                    isOk = false;
                    break;
                }
            }
            if(isOk) {
                result = true;
                break;
            }
        }
     
    } else {
        count = 13;
        while(tmp * count < 1000) {
            oct.push_back(to_string(tmp * count));
            count++;
        }
        for(int i = 0; i < (int) oct.size(); i++) {
            bool isOk = true;
            map<char,int> tar = sub;
            for(int j = 0; j < (int) oct.at(i).size(); j++) {
                bool ari = false;
                if(tar[oct.at(i).at(j)] > 0) {
                    ari = true;
                    tar[oct.at(i).at(j)]--;
                }
                if(ari) continue;
                else {
                    isOk = false;
                    break;
                }
            }
            if(isOk) {
                result = true;
                break;
            }
        }
    }
    if(result) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
//Shinchan Loves Coding :))
#include<bits/stdc++.h>

using namespace std;

#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);
#define double long double
#define int long long int
#define en "\n"
#define fi first
#define se second
#define PB push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define rep(i,x,y) for(int i=x ; i<y ; i++)
#define erep(i,x,y) for(int i=x ; i<=y ; i++)
#define erepr(i,x,y) for(int i=x ; i>=y ; i--)
#define repr(i,x,y) for(int i=x ; i>y ; i--)

typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> pii;

//--------------------------------------------------------------------------------------------------------------------------------------------------------------

const int no=3e6+5,modulo=1e9+7,inf=1e18,N=2e3+1;
const double PI = 3.1415926535897932384;
int ar[no] ,br[no],cr[no];//,dr[no],er[no];
//int used[no];
//int color[no];
//pii adj[no];
//vi adj[no] ;
//LOWER_BOUND(n) - FIRST ELEMENT GREATER THAN EQUAL TO n
//UPPER_BOUND(n) - FIRST ELEMENT GREATER THAN n

//--------------------------------------------------------------------------------------------------------------------------------------------------------------                                                                        

map<char,int> fir,sec;

int make(string s) {
    string ans="";
    for(auto &ii : s) {
        ans+=(char)(sec[ii]+'0');
    }
    int x=0,k=ans.size();
    reverse(all(ans));
    rep(i,0,k) {
        x+=pow(10,i)*(ans[i]-'0');
    }
    return x;
}

void solve () {
    int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0,w=0,k=0; 
    vector<string> v(3);
    rep(i,0,3) {
        cin>>v[i];
        rep(j,0,v[i].size()) {
            if(!j) fir[v[i][j]]++;
            sec[v[i][j]]++;
        }
    } 
    if(sec.size()>=11) {
        cout<<"UNSOLVABLE";
        return ;
    }
    rep(i,0,10) {
        ar[i]=i;
    }
    do {
        a=0;
        for(auto ii : sec) {
            sec[ii.fi]=ar[a];
            a++;
        }
        bool ok=0;
        for(auto ii : fir) {
            if(sec[ii.fi]==0) {ok=1;}
        }
        if(!ok) {
            x=make(v[0]);
            y=make(v[1]);
            z=make(v[2]);
            // cout<<x<<" "<<y<<" "<<z<<en;
            if(x+y==z) {
                cout<<x<<"\n"<<y<<"\n"<<z<<en;
                return ;
            }
        }

    } while(next_permutation(ar,ar+10));
    cout<<"UNSOLVABLE";
}

inline void runn() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);      
    freopen("output.txt","w",stdout);   
    #endif
}

signed main() {
    night_rider
    runn(); 
    int t=1;
    cout<<fixed<<setprecision(15);
  //  cin>>t;
    rep(i,1,t+1) {
       // cout << "Case #" << i << ": ";
        solve();
    }
}
