#include<cstdio>
#define fo(x,a,b) for(int x=(a),_e=(b);x<=_e;x++)
#define fd(x,a,b) for(int x=(a),_e=(b);x>=_e;x--)
typedef long long ll;
const int N=5005;
int a[N][4],pd[N],n,ans;
char c[N];
int main(){
	scanf("%d",&n);scanf("%s",c+1);
	pd['A']=0, pd['T']=1, pd['C']=2, pd['G']=3;
	fo(i,1,n) {
		fo(j,0,3) a[i][j]=a[i-1][j];
		a[i][pd[c[i]]]++;
	}

	fo(i,1,n) {
		fo(j,i+1,n) {
			if(a[j][0]-a[i-1][0]==a[j][1]-a[i-1][1] && a[j][2]-a[i-1][2]==a[j][3]-a[i-1][3])
				++ans;
		}
	}
	printf("%d",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define M_PI	3.14159265358979323846

typedef pair<int, int> P;

int main(){
    string s[3];
    int num = 0;
    vector<int> kaisu(26, 0);
    vector<int> jun(26, 0);

    REP(i, 3) {
        cin >> s[i];
        REP(j, s[i].size()) kaisu[s[i][j] - 'a']++;
    }

    REP(i, kaisu.size()) {
        if(0 < kaisu[i]) {
            jun[i] = num;
            num++;
        }
        if(num > 10) {
            cout << "UNSOLVABLE" << endl;
            return 0;
        }
    }

    vector<int> v(10);
    REP(i, v.size()) v[i] = i;

    do{
        bool b = false;
        vector<string> ss(3);
        REP(i, ss.size()) ss[i] = s[i];
        REP(i, 3) {
            REP(j, s[i].size()) {
                int n = v[jun[s[i][j] - 'a']];
                ss[i][j] = '0' + n;
            }

            if(ss[i][0] == '0') b = true; 
        }
        if(b) continue;

        vector<ll> ans(3);
        REP(i, ans.size()) ans[i] = stol(ss[i]);

        if(ans[0] + ans[1] == ans[2]) {
            cout << ans[0] << endl;
            cout << ans[1] << endl;
            cout << ans[2] << endl;
            return 0;
        }
    } while(next_permutation(v.begin(), v.end()));

    cout << "UNSOLVABLE" << endl;

    return 0;
}
