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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}


string rev(string s) {
  REP(i, s.size()) {
    s[i] = 'A'+(1-(s[i]-'A'));
  }
  return s;
}
int main2() {
  int N = nextLong();
  int M = 1 << N;

  vector<string> ans;
  ans.push_back("AB");

  for (int m = 1; m <= N-1; m++) {
    vector<string> n_ans;
    n_ans.push_back(string(1<<m, 'A') + string(1<<m, 'B'));
    for (string s : ans) {
      n_ans.push_back(s + s);
    }
    for (string s : ans) {
      n_ans.push_back(s + rev(s));
    }
    ans = n_ans;
  }

  cout << (M - 1) << endl;
  for (string s : ans)
    cout << s << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int n;
vector<ll> with[3];
int cnt[3];

int getID(char c) {
    switch (c) {
        case 'R': return 0;
        case 'G': return 1;
        case 'B': return 2;
    }
    return -1;
}

signed main() {
    cin >> n;
    for (int i = 0; i < n * 2; i++) {
        ll a;
        char c;
        cin >> a >> c;
        int id = getID(c);
        with[id].push_back(a);
        cnt[id]++;
    }
    bool allEven = all_of(cnt, cnt + 3, [](int elem)->bool {
        return elem % 2 == 0;
    });
    if (allEven) {
        return cout << 0 << endl, 0;
    }
    if (cnt[0] % 2 == 0) {
        swap(cnt[2], cnt[0]);
        swap(with[2], with[0]);
    }
    else if (cnt[1] % 2 == 0) {
        swap(cnt[2], cnt[1]);
        swap(with[2], with[1]);
    }
    assert(cnt[2] % 2 == 0);
    ll pos1 = 1e18;//posibilities
    ll pos2[2] = {pos1, pos1};
    vector<pair<ll, int>> only01;
    for (int i = 0; i < 2; i++) {
        for (ll c : with[i]) {
            only01.emplace_back(c, i);
        }
    }
    sort(only01.begin(), only01.end());
    for (int i = 1; i < (int)only01.size(); i++) {
        auto [preFi, preSe] = only01[i - 1];
        auto [currFi, currSe] = only01[i];
        if (currSe != preSe) {
            pos1 = min(pos1, currFi - preFi);
        }
    }
    vector<pair<ll, int>> all;
    for (int i = 0; i < 3; i++) {
        for (ll c : with[i]) {
            all.emplace_back(c, i);
        }
    }
    sort(all.begin(), all.end());
    for (int i = 1; i < n * 2; i++) {
        auto [preFi, preSe] = all[i - 1];
        auto [currFi, currSe] = all[i];
        if (preSe == 0 && currSe == 2 || preSe == 2 && currSe == 0) {
            pos2[0] = min(pos2[0], currFi - preFi);
        }
        else if (preSe == 1 && currSe == 2 || preSe == 2 && currSe == 1) {
            pos2[1] = min(pos2[1], currFi - preFi);
        }
    }
    cout << min(pos2[0] + pos2[1], pos1) << endl;
    return 0;
}
