#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


int main(){
  ll n;
  cin >> n;

  string s;
  cin >> s;

  char dna;
  ll a=0,t=0,c=0,g=0,count=0;
  for(ll i=0;i<n-1;i++){

      a=0;
      t=0;
      c=0;
      g=0;

        for(ll k=i;k<n;k++){
          dna=s.at(k);
          if(dna=='A') a++;
          else if(dna=='T') t++;
          else if(dna=='C') c++;
          else if(dna=='G') g++;

          if(a==t && a!=0 && t!=0 && c==g) count++;
          else if(c==g && c!=0 && g!=0 && a==t) count++;
        }

  }



  cout << count << endl;
  return 0;

}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

string a, b, c, p;
set<char> st;
char mp[26];

ll str_to_num(string s) {
	ll res = 0;
	for (char x : s) res = 10*res + mp[x-'a'];
	return res;
}


int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	
	cin>>a>>b>>c;

	for (char x : a) st.insert(x);
	for (char x : b) st.insert(x);
	for (char x : c) st.insert(x);

	if (st.size() > 10) {
		cout<<"UNSOLVABLE"<<endl;
		return 0;
	}

	int n = 0;
	for (char x : st) mp[x-'a'] = 'a' + n++;

	for (char &x : a) x = mp[x-'a'];
	for (char &x : b) x = mp[x-'a'];
	for (char &x : c) x = mp[x-'a'];
	
	p = "abcdefghij";
	do {
		if (p[0] == a[0] || p[0] == b[0] || p[0] == c[0]) {
			continue; // no leading zeros
		}

		n = 0;
		for (char x : p) mp[x-'a'] = n++;

		ll aa = str_to_num(a);
		ll bb = str_to_num(b);
		ll cc = str_to_num(c);

		if (aa + bb == cc) {
			cout<<aa<<endl<<bb<<endl<<cc<<endl;
			return 0;
		}
	} while (next_permutation(p.begin(), p.end()));

	cout<<"UNSOLVABLE"<<endl;
}
