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

template <typename T> T gcd(T x, T y) { return y != 0 ? gcd(y, x % y) : x; }

/**
 * @brief 約数列挙
 */
template <typename T> vector<T> divisor(T n) {
    vector<T> res;
    for (T i = 1; i * i <= n; i++)
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);

    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        for (int d : divisor(A[i])) {
            mp[d] = gcd(mp[d], A[i]);
        }
    }

    int ans = 0, m = *min_element(A.begin(), A.end());
    for (auto x : mp) {
        if (x.first > m) continue;
        ans += (x.first == x.second);
    }
    cout << ans << '\n';
    return 0;
}
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<numeric>
#include<queue>


#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long
#define MOD 1000000007
#define INF 9223372036854775800
#define pi 3.14159265359

using namespace std;

int main(){


ll int N;
cin >> N;
vector< ll int > a(2*N);
vector< char > c(2*N);
rep(i,2*N) cin >> a[i] >> c[i];
map< char, vector< ll int > > ma;
rep(i,2*N){
	ma[c[i]].push_back(a[i]);
}
ll int fk;
fk = ma['R'].size();
fk = ma['G'].size();
fk = ma['B'].size();
char c1 = 'j';
char c2 = 'j';
char c3 = 'j';
bool f = false;
ll int count = 0;
for( auto i: ma ){
	count += 1;
	if( i.second.size()%2 == 1 && !f ){
		c1 = i.first;
		f = true;
	}
	else if( i.second.size()%2 == 1 && f ){
		c2 = i.first;
	}
	else{
		c3 = i.first;
	}
}
if( !f ){
	cout << 0 << endl;
	return 0;
}
if( c1 == 'j' || c2 == 'j' || c3 == 'j' ){
	return 0;
}
vector< pair< ll int, char > > d;
vector< pair< ll int, char > > d2;
vector< pair< ll int, char > > d3;
for( ll int i:ma[c1] ){
	pair< ll int , char > kari;
	kari.first = i;
	kari.second = c1;
	d.push_back(kari);
	d2.push_back(kari);
}
for( ll int i:ma[c2] ){
	pair< ll int , char > kari;
	kari.first = i;
	kari.second = c2;
	d.push_back(kari);
	d3.push_back(kari);
}
sort(d.begin(),d.end());
for( ll int i:ma[c3] ){
	pair< ll int , char > kari;
	kari.first = i;
	kari.second = c3;
	d2.push_back(kari);
	d3.push_back(kari);
}

sort(d2.begin(),d2.end());
sort(d3.begin(),d3.end());
ll int ans = INF;
rep(i,d.size()-1){
	if( d[i].second != d[i+1].second ){
		ans = min( ans, abs(d[i].first-d[i+1].first));
	}
}
ll int dk2 = INF;
ll int dk3 = INF;
if( !d2.empty() ){
rep(i,d2.size()-1){
	if( d2[i].second != d2[i+1].second ){
		dk2 = min( dk2, abs(d2[i].first-d2[i+1].first));
	}
}
}
if( !d3.empty() ){
rep(i,d3.size()-1){
	if( d3[i].second != d3[i+1].second ){
		dk3 = min( dk3, abs(d3[i].first-d3[i+1].first));
	}
}
}
if( dk2 != INF && dk3 != INF ){
	ans = min( ans, dk2+ dk3);
}
	
cout << ans << endl;








	return 0;

}

