#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <regex>
#include <random>
#include <iomanip>
#pragma comment(linker, "/STACK:360777216")

using LL = long long;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int> 
#define pll pair<LL,LL> 
#define vi vector<int>
#define vll vector<LL>
#define vvll vector<vector<LL>>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
const int  INF = 2 * 1000 * 1000 * 1000;
LL MOD = 1e9 + 7;
LL LINF = (LL)4e18;
double EPS = 1e-7;

using namespace std;

LL gcd(LL a, LL b) {
	return b ? gcd(b, a % b) : a;
}


LL lcm(LL a, LL b) {
	return a / gcd(a, b) * b;
}

const LL max_er = 1e2;
vi pp(max_er + 1, 1);
vll min_div(max_er + 1, -1);
vll res(max_er + 1, -1);
vll primes;

void eratosfen()
{
	pp[0] = pp[1] = 0;
	for (LL i = 2; i <= max_er; ++i)
	{
		if (!pp[i]) continue;
		min_div[i] = i;
		for (LL j = i * i; j <= max_er; j += i)
		{
			pp[j] = 0;
			if (min_div[j] == -1) min_div[j] = i;
		}
	}
}


LL some_logic(vector<pll>& v)
{	
	LL sum = v[0].first + v[1].first + v[2].first;
	if (v[2].first == 0)
	{
		if (v[1].first == 0 && v[0].first == 2) return 1;
		if (v[1].first == 0 && v[0].first > 2) return sum;
		if (v[0].first == 1 && v[1].first == 1) return 0;
		if (v[0].first == 2 && v[1].first == 1 && v[0].second == v[1].second) return 1;
		if (v[0].first == 1 && v[1].first == 2 && v[0].second == v[1].second) return 1;
		return sum - 1;
	}

	bitset<3> b1, b2;
	vi idxs, idxs_more;
	forn(i, 0, 3)
	{
		if (v[i].first == 1) idxs.push_back(i);
		else if (v[i].first > 1) idxs_more.push_back(i);
		b1[i] = v[i].first % 2;
		b2[i] = v[i].second;
	}

	if (idxs.size() <= 1)
	{
		if (b1 == b2 || b1 == ~b2) return sum - 1ll;
		return sum - 2ll;
	}
	else if (idxs.size() == 3) return 1;
	else
	{
		if (v[idxs[0]].second == v[idxs[1]].second)
		{
			vector<pll> new_v = { v[idxs_more[0]], {1, v[idxs[0]].second}, {0, 0} };
			return some_logic(new_v) + 1;
		}
		return v[idxs_more[0]].first;
	}
}



int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(10);

	vector<pll> vs(3);
	forn(i, 0, 3)
	{
		char ch = 'R';
		cin >> vs[i].first;
		if (vs[i].first)
		{
		    cin >> ch;
		}
		vs[i].second = ch == 'R';

	}
	sort(rall(vs));

	LL ans = some_logic(vs);

	cout << ans << endl;

	return 0;
}