#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rrep(i,a,b) for(ll i=a;i>=b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
#define all(x)  x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
const ll INF = 1e18+7;
const ll mod = 998244353;
const ll MAXN = 2e6+100;
 
ll poww(ll a, ll b) {    
    if(b<0) return 0LL;
    ll ans = 1;
    while (b) {
        if (b & 1)ans = ans * a;
        a = a * a;
        b >>= 1;
    }   
    return ans;
}
ll binpow(ll a, ll b)
{
    if (b < 0) return 0LL;
    if (a <= 0)return 0LL;
    a %= mod;
    
    ll ans = 1LL;
    while (b) {
        if (b & 1)ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll modinv(ll n) {
    return binpow(n, mod - 2);
}

vector<pair<ll,ll>> func(vector<ll> a, vector<ll> b) {
    vector<ll> x((ll)(b.size()),INF);
    ll i=0,j=0;
    while(i<(ll)a.size() && j<(ll)b.size()) {
        x[j] = min(x[j],abs(a[i]-b[j]));
        if(a[i]<=b[j]) i++;
        else j++;
    }
    vector<pair<ll,ll>> temp;
    FOR(i,(ll)(x.size())) {
        temp.pb(mp(x[i],i));
    }
    sort(all(temp));
    return temp;
}

void solve() {
    ll n; cin>>n;
    vector<ll> r,g,b;
    FOR(i,2*n) {
        ll a; char c; cin>>a>>c;
        if(c=='R') r.pb(a);
        if(c=='G') g.pb(a);
        if(c=='B') b.pb(a);
    }
    ll sr = r.size(), sb = b.size(), sg = g.size();
    
    sort(all(r)); sort(all(g)); sort(all(b));
    if(sr%2==0 && sb%2==0 && sg%2==0) {
        cout<<0; 
    }
    else {
        if(sr%2 && sb%2) {
            vector<pair<ll,ll>> t = func(r,b);
            ll mn = t[0].fi;
            if(sg > 0) {
                vector<pair<ll,ll>> t1,t2;
                t1 = func(r,g); t2 = func(b,g);
                if(t1[0].se!=t2[0].se) {
                    mn = min(mn,t1[0].fi+t2[0].fi);
                }
                else {
                    mn = min(mn,min(t1[1].fi + t2[0].fi, t1[0].fi + t2[1].fi));
                }
            }
            cout<<mn;
        }
        else if(sr%2 && sg%2) {
            
            vector<pair<ll,ll>> t = func(r,g);
            ll mn = t[0].fi;
            if(sb > 0) {
                vector<pair<ll,ll>> t1,t2;
                t1 = func(r,b); t2 = func(g,b);
                if(t1[0].se!=t2[0].se) {
                    mn = min(mn,t1[0].fi+t2[0].fi);
                }
                else {
                    mn = min(mn,min(t1[1].fi + t2[0].fi, t1[0].fi + t2[1].fi));
                }
            }
            cout<<mn;
        }
        else {
            vector<pair<ll,ll>> t = func(g,b);
            ll mn = t[0].fi;
            if(sr > 0) {
                vector<pair<ll,ll>> t1,t2;
                t1 = func(g,r); t2 = func(b,r);
                if(t1[0].se!=t2[0].se) {
                    mn = min(mn,t1[0].fi+t2[0].fi);
                }
                else {
                    mn = min(mn,min(t1[1].fi + t2[0].fi, t1[0].fi + t2[1].fi));
                }
            }
            cout<<mn;
        }
    }
}
 
int main() {
    IOS; 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    //ll no_of_test_cases; cin>>no_of_test_cases; 
    ll no_of_test_cases = 1;
    //cout<<fixed<<setprecision(10);
    
    for(ll i=1; i<=no_of_test_cases; i++) {
        solve();
    } 
    return 0; 
} 
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define rep(i, n) for ( int i = 0; i < (int)(n); i += 1)
#define rrep(i, n) for ( int i = (n) - 1; i >= 0; i -= 1)
#define range(i, l, r) for ( int i = (int)(l); i < (int)(r); (i) += 1 )
#define rrange(i, l, r) for ( int i = (int)(r)-1; i >= (int)(l); (i) -= 1 )
#define debug(x) cerr << #x << ": " << (x) << endl;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << ' ' << p.second; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &v) { for ( pair<T1, T2> x : v ) { os << x << "\n"; } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> v) { if(!v.empty()) { os << v.front(); v.pop(); } while (!v.empty()) { os << " " << v.front(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> v) { if(!v.empty()) { os << v.top(); v.pop(); } while (!v.empty()) { os << " " << v.top(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
template <typename T> ostream &operator<<(ostream &os, const deque<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
using ull = unsigned long long;
using ll = long long;
using Pll = pair<ll, ll>;
using P = pair<int, int>;
constexpr ll INF64 = INT64_MAX / 2;
constexpr int INF32 = INT32_MAX / 2;
constexpr int dy[] = { 0, -1, 1, 0, -1, 1, -1, 1 };
constexpr int dx[] = { -1, 0, 0, 1, -1, -1, 1, 1 };
constexpr int mod998244353 = 998244353;
constexpr int mod1000000007 = (int)1e9 + 7;
constexpr char newl = '\n';
// clang-format on

int main() {
  int n;
  string s;
  cin>>n>>s;
  vector<int> a(n+1);
  for(auto &A:a) cin>>A;

  ll k=INF64;
  rep(i,n) chmin(k,abs(a[i]-a[i+1]));

  vector<vector<int>> ans(k,vector<int>(n+1));
  rep(j,n+1){
    int rem=a[j]%k;
    rep(i,k){
      ans[i][j]=a[j]/k;
      if(i<rem) ans[i][j]++;
    }
  }

  cout<<k<<endl;
  rep(i,k){
    cout<<ans[i]<<newl;
  }
}