#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1,  0, 0, -1, -1,  1, 1};
vi dj = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    vc<string> s(3);
    rep(i, 3) cin >> s[i];
    map<char, ll> Mp; // その文字に割り当てられたものを何倍するか
    set<char> heads; // 先頭の文字
    rep(i, 3) {
        heads.insert(s[i][0]);
        ll scale = 1;
        for (int j = sz(s[i])-1; j >= 0; j--) {
            if (i == 2) {
                Mp[s[i][j]] -= scale;
            }
            else {
                Mp[s[i][j]] += scale;
            }
            scale *= 10;
        }
    }
    if (sz(Mp) > 10) {
        cout << "UNSOLVABLE" << endl;
        return 0;
    }
    
    map<char, int> Mp2; // 各文字に何の文字入れるか
    vi p(10);
    rep(i, 10) p[i] = i;
    do {
        int now = 0; // 今何番目の要素か
        ll sum = 0;
        for (auto x : Mp) {
            sum += p[now] * x.second;
            if (heads.count(x.first) && p[now] == 0) sum = 1e18; // 先頭は0じゃダメ
            Mp2[x.first] = p[now];
            now++;
        }

        if (sum == 0) {
            rep(i, 3) {
                ll ans = 0;
                rep(j, sz(s[i])) {
                    ans *= 10;
                    ans += Mp2[s[i][j]];
                }
                cout << ans << endl;
            }
            return 0;
        }
      Mp2.clear();
    } while (next_permutation(all(p)));

    cout << "UNSOLVABLE" << endl;
    
    return 0;
}
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4", "avx")

#ifdef __APPLE__
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>
#else
# include <bits/stdc++.h>
#endif

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const int max_n = 100+10, inf = 1000111222;

int dp[2*max_n];

bool is_start[2*max_n];
bool is_end[2*max_n];
bool is_pair_present[2*max_n][2*max_n];
bool in_some_pair[2*max_n];

void add_start(int a)
{
    if (is_start[a] || is_end[a]){
        cout<<"No"<<"\n";
        exit(0);
    }
    is_start[a]=1;
}

void add_end(int b)
{
    if (is_start[b] || is_end[b]){
        cout<<"No"<<"\n";
        exit(0);
    }
    is_end[b]=1;
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    int n;
    cin>>n;
    for (int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        if (a==-1 && b==-1){

        }
        else if (a==-1){
            add_end(b);
        }
        else if (b==-1){
            add_start(a);
        }
        else{
            if (a>=b){
                cout<<"No"<<"\n";
                exit(0);
            }
            add_start(a);
            add_end(b);
            is_pair_present[a][b]=1;
            in_some_pair[a]=1;
            in_some_pair[b]=1;
        }
    }
    dp[0]=1;
    for (int f=0;f<2*n;f++){
        if (dp[f]){
//            cout<<"dp f :: "<<f<<"\n";
            int l=f+1;
            for (int r=l+1;r + ((r-l)-1)<=2*n;r++){
                bool ok=1;
                for (int i=l;i<r;i++){
                    if (is_pair_present[i][r+(i-l)]){
                        continue;
                    }
//                    cout<<i<<" "<<is_start[i]<<" "<<r+(i-l)<<" "<<is_end[r+(i-l)]<<"\n";
                    if (is_start[i] && is_end[r+(i-l)]){
                        ok=0;
                    }
                }
                for (int i=l;i<r;i++){
                    if (is_pair_present[i][r+(i-l)]){
                        continue;
                    }
                    if (in_some_pair[i]){
                        ok=0;
                    }
                    if (is_end[i]){
                        ok=0;
                    }
                }
                for (int i=r;i<r+(r-l);i++){
                    if (is_pair_present[l+(i-r)][i]){
                        continue;
                    }
                    if (in_some_pair[i]){
                        ok=0;
                    }
                    if (is_start[i]){
                        ok=0;
                    }
                }
//                cout<<r<<" "<<ok<<"\n";
                if (ok){
                    dp[r + ((r-l)-1)]=1;
                }
            }
        }
    }
    cout<<(dp[2*n]?"Yes":"No")<<"\n";
}
