#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;
		}
	}
}

int dp[101][2][101][2][101][2];
int used[101][2][101][2][101][2];



int bfs(vector<pii> &start)
{
	int ans = INT_MAX;
	queue<vector<pii>> q;
	q.push(start);
	used[start[0].first][start[0].second][start[1].first][start[1].second][start[2].first][start[2].second] = 1;
	dp[start[0].first][start[0].second][start[1].first][start[1].second][start[2].first][start[2].second] = 0;
	while (!q.empty())
	{
		auto v = q.front();
		q.pop();
		if (v[0].first == 1 && v[1].first == 1 && v[2].first == 0)
		{
			ans = min({ ans, dp[1][v[0].second][1][v[1].second][0][v[2].second] });
			break;
		}
		if (v[0].first == 0 && v[1].first == 1 && v[2].first == 1)
		{
			ans = min({ ans, dp[0][v[0].second][1][v[1].second][1][v[2].second] });
			break;
		}
		if (v[0].first == 1 && v[1].first == 0 && v[2].first == 1)
		{
			ans = min({ ans, dp[1][v[0].second][0][v[1].second][1][v[2].second] });
			break;
		}

		forn(i, 0, v.size())
		{
			forn(j, 0, v.size())
			{
				if (i == j) continue;
				if (v[i].first == 0) continue;
				if (v[j].first != 0 && v[i].second != v[j].second) continue;
				auto to = v;
				if (to[j].first == 0)
				{
					to[j].first++;
					to[j].second = to[i].second;
				}
				to[i].first--;
				if (to[i].second == 1) to[i].second = 0;
				else to[i].second = 1;
				if (!used[to[0].first][to[0].second][to[1].first][to[1].second][to[2].first][to[2].second])
				{
					dp[to[0].first][to[0].second][to[1].first][to[1].second][to[2].first][to[2].second] = dp[v[0].first][v[0].second][v[1].first][v[1].second][v[2].first][v[2].second] + 1;
					used[to[0].first][to[0].second][to[1].first][to[1].second][to[2].first][to[2].second] = 1;
					q.push(to);
				}
				
			}
		}
	}
	return ans;
}


LL some_logic(vector<pii>& 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;
}




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);

	LL t, n, m, k, x, l, r;
	vector<pair<int, int>> 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;
}