#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    vector<string> s(3);
    for (int i = 0; i < 3; ++i) {
        cin>>s[i];
    }
    map<char,int> mp;
    int cnt=0;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < s[i].size(); ++j) {
            char c=s[i][j];
            if(mp.find(c)==mp.end()) {
                mp[c]=cnt;
                ++cnt;
            }
            s[i][j]='0'+mp[c];
        }
    }
    if(cnt>=11) {
        cout<<"UNSOLVABLE"<<endl;
        return 0;
    }

    vector<int> perm(10);
    for (int i = 0; i < 10; ++i) {
        perm[i]=i;
    }
    vector<string> t(3,"");
    do{
        t.assign(3,"");
        for (int i = 0; i < 3; ++i) {
            for(auto c:s[i]) {
                t[i].push_back('0'+perm[c-'0']);
            }
        }
        if(t[0][0]=='0'||t[1][0]=='0'||t[2][0]=='0')continue;
        ll a=stoll(t[0]);
        ll b=stoll(t[1]);
        ll c=stoll(t[2]);
        if(a+b==c) {
            cout<<a<<endl;
            cout<<b<<endl;
            cout<<c<<endl;
            return 0;
        }
    }while(next_permutation(perm.begin(),perm.end()));
    cout<<"UNSOLVABLE"<<endl;
    return 0;
}
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <vector <bool>> edge (n, vector <bool> (n));
    for(int u = 0; u < n; u++)
    {
        string row;
        cin >> row;
        for(int v = 0; v < n; v++)
            edge[u][v] = (row[v] == '1');
        edge[u][u] = true;
    }

    for(int w = 0; w < n; w++)
        for(int u = 0; u < n; u++)
            for(int v = 0; v < n; v++)
                if(edge[u][w] && edge[w][v])
                    edge[u][v] = true;

    long double answer = 0;
    for(int u = 0; u < n; u++)
    {
        int cnt = 0;
        for(int v = 0; v < n; v++)
            cnt += edge[v][u];

        answer += (long double) 1 / cnt;
    }
    cout << fixed << setprecision(10) << answer << "\n";
    return 0;
}
