#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#define hmap gp_hash_table<ll, ll>

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
  FAST/**/
  
  ll n;
  cin>>n;
  
  ll arr[n];
  rep(n)
        cin>>arr[i];// mx = max(mx, arr[i]), sum += arr[i];
  ll maxi[n], psum[n];
  maxi[0] = psum[0] = arr[0];
  for(ll i=1;i<n;i++)
        psum[i] = psum[i-1] + arr[i]*(i+1), maxi[i] = max(maxi[i-1], arr[i]);
  ll sm = 0;        
  rep(n)
  {
      sm += arr[i];
      ll ans = (i+1)*(maxi[i]+sm-arr[i]) + sm;
      if(i>0)
            ans -= psum[i-1];
      else ans = 2*arr[0];
      cout<<ans<<"\n";
  }
    
  return 0;
}
   
   
 
#include <bits/stdc++.h>
//#include <atcoder/modint>
//using namespace atcoder;
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;
const ll INF = (1LL<<61);

template<class T> bool chmin(T &a, const T b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

void no(){
    cout<<"UNSOLVABLE"<<endl;
    exit(0);
}

unordered_map<char, int> num;

ll conv(string &s){
    ll res = 0;
    if(num[s[0]] == 0) return 0;
    for(char c : s) (res *= 10) += num[c];
    return res;
}

void judge(vector<string> &s){
    vec tmp(3);
    rep(i, 3) tmp[i] = conv(s[i]);
    if(tmp[0] + tmp[1] == tmp[2] && *min_element(ALL(tmp)) > 0){
        rep(i, 3) cout<<tmp[i]<<endl;
        exit(0);
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<string> s(3);
    set<char> cs;
    rep(i, 3){
        cin>>s[i];
        for(char c : s[i]) cs.insert(c);
    }
    if(cs.size() > 10){
        no();
    }else{
        vec ord(10);
        iota(ALL(ord), 0);
        do{
            int i = 0;
            for(char c : cs) num[c] = ord[i++];
            judge(s);
        }while(next_permutation(ALL(ord)));
    }
    no();
}