#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>

using namespace std;
using lint = long long;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<lint> cnt(2, 0);
    while (n--) {
        string s;
        cin >> s;
        ++cnt[count(s.begin(), s.end(), '1') % 2];
    }

    cout << cnt[0] * cnt[1] << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)
#define Rep(i,s,n) for(int i = n; i >= (int)(s); i--)

int main(){
	int n;
	cin >> n;
	vector<ll>r, g, b;
	rep(i, 0, 2 * n) {
		ll a;
		char c;
		cin >> a >> c;
		if (c == 'R') r.push_back(a);
		else if (c == 'G') g.push_back(a);
		else b.push_back(a);
	}
	sort(r.begin(), r.end());
	sort(g.begin(), g.end());
	sort(b.begin(), b.end());
	ll rg = 1e16, rb = 1e16, bg= 1e16;
	if (g.size() != 0) {
		rep(i, 0, r.size()) {
			ll v = r[i];
			int pos = lower_bound(g.begin(), g.end(), v) - g.begin();
			if(pos != g.size())rg = min(rg, abs(v - g[pos]));
			if (pos != 0) rg = min(rg, abs(v - g[pos - 1]));
		}
	}
	if (b.size() != 0) {
		rep(i, 0, r.size()) {
			ll v = r[i];
			int pos = lower_bound(b.begin(), b.end(), v) - b.begin();
			if(pos != b.size())rb = min(rb, abs(v - b[pos]));
			if (pos != 0) rb = min(rb, abs(v - b[pos - 1]));
		}
	}
	if (g.size() != 0) {
		rep(i, 0, b.size()) {
			ll v = b[i];
			int pos = lower_bound(g.begin(), g.end(), v) - g.begin();
			if(pos != g.size())bg = min(bg, abs(v - g[pos]));
			if (pos != 0) bg = min(bg, abs(v - g[pos - 1]));
		}
	}
	if (r.size() % 2 == 0 && g.size() % 2 == 0 && b.size() % 2 == 0) cout << 0 << endl;
	else if (r.size() % 2 == 0) {
		ll ans = min(bg, rg + rb);
		cout << ans << endl;
	}
	else if (g.size() % 2 == 0) {
		ll ans = min(rb, rg + bg);
		cout << ans << endl;
	}
	else {
		ll ans = min(rg, rb + bg);
		cout << ans << endl;
	}
}