#include<bits/stdc++.h>
#include<string>

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s[3];
    cin>>s[0]>>s[1]>>s[2];
    map<char , ll> pos;
    ll idx = 0;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < sz(s[i]); j++){
            if(pos.find(s[i][j]) == pos.end()){
                pos[s[i][j]] = idx;
                idx++;
            }
        }
    }
    if(idx > 10){
        cout<<"UNSOLVABLE\n";
        return 0;
    }
    vector<ll> d(10);
    iota(all(d) , 0);
    do {
        vector<ll> ans(3);
        bool flag = 1;
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < sz(s[i]); j++){
                ans[i] *= 10;
                ans[i] += d[pos[s[i][j]]];
            }
            if(d[pos[s[i][0]]] == 0){
                flag = 0;
                break;
            }
        }
        if(flag && ans[0] + ans[1] == ans[2]){
            for(int k = 0; k < 3; k++){
                cout<<ans[k]<<"\n";
            }
            return 0;
        }
    }while(next_permutation(all(d)));

    cout<<"UNSOLVABLE\n";
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define lowbit(x) x&-x
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin())
#define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x),0,sizeof((x)))
#define Rint register int
#define ls (u<<1)
#define rs (u<<1|1)
typedef unsigned int unit;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(ull &x) { scanf("%llu", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.fi);putchar(' '); _W(x.se);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MOD=998244353,mod=998244353;
ll qpow(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
const int MAXN=2e6+10,MAXM=3e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX;
const int inv2=(MOD+1)/2;
const int Lim=1<<20;

void solve()
{
    ll n,k,ans=0;
    R(n,k);
    for(ll i=2;i<=n*2;i++)
    {
        if(i>k+1)
        {
            ans=(ans+min(i-1,n*2-i+1)*max(min(i-k-1,n*2-(i-k)+1),0ll));
            //W(i,i-1,n*2-i+1,i-k-1,n*2-(i-k)+1);
        }
    }
    W(ans);
}

int main()
{
    int T=1;
    //scanf("%d",&T);
    for(int kase=1;kase<=T;kase++)
    {
        //printf("Case #%d: ",kase);
        solve();
    }
    return 0;
}
