#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

ll N;
ll A[200000];

int main(){
    cin>>N;
    rep(i,N) cin>>A[i];

    vector<ll> sum(N,0);
    vector<ll> t(N,0);
    rep(i,N) sum[i]=A[i];
    rep(i,N-1) sum[i+1]+=sum[i];
    //rep(i,N) cout<<sum[i]<<' ';cout<<endl;
    rep(i,N) t[i]=sum[i];
    rep(i,N-1) sum[i+1]=max(sum[i+1],sum[i]);

    rep(i,N-1) t[i+1]+=t[i];
    //rep(i,N) cout<<sum[i]<<' ';cout<<endl;

    ll ans=0;
    rep(i,N-1){
        ans=max(ans,t[i]+sum[i+1]);
    }
    ans=max(ans,t[0]);

    // ll maxi=-INF;
    // ll idx=0;
    // rep(i,N){
    //     if(t[i]>maxi){
    //         maxi=t[i];
    //         idx=i;
    //     }
    // }

    cout<<ans<<endl;
    
    return 0;
}
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;



int main() {
    vector<string> s(3);
    REP(i, 3)
        cin >> s[i];

    set<char> chars;
    REP(i, 3){
        for(auto c: s[i]) chars.insert(c);
    }
    if(chars.size() > 10){
        cout << "UNSOLVABLE" << endl;
        return 0;
    }


    vector<int> nums(10);
    iota(nums.begin(), nums.end(), 0);
    vector<int> nums_orig(nums);

    vector<ll> ans = {-1, -1, -1};

    do{
        next_permutation(nums.begin(), nums.end());
        map<char, int> assoc;
        int i = 0;
        for(auto c: chars){
            assoc[c] = nums[i];
            i++;
        }
        vector<string> new_str(s);
        vector<ll> new_num(3);
        REP(i, 3){
            REP(j, new_str[i].size()){
                new_str[i][j] = assoc[new_str[i][j]] + '0';
            }
            new_num[i] = stoll(new_str[i]);
        }
        if(
            (new_str[0][0] == '0')
         || (new_str[1][0] == '0')
         || (new_str[2][0] == '0')) continue;
        
        if(new_num[0] + new_num[1] == new_num[2]){
            ans = new_num;
            break;
        }

    } while(nums != nums_orig);
    
    if(ans[0] != -1){
        for(auto t: ans) cout << t << endl;
    }
    else{
        cout << "UNSOLVABLE" << endl;
    }
    return 0;
}