#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <class T>
istream &operator>>(istream &in, vector<T> &a) {
  for (auto &i : a) in >> i;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> a) {
  for (auto &i : a) out << i << ' ';
  return out;
}
template <class T, class U>
istream &operator>>(istream &in, pair<T, U> &a) {
  in >> a.first >> a.second;
  return in;
}
template <class T, class U>
ostream &operator>>(ostream &out, pair<T, U> a) {
  out << a.first << a.second;
  return out;
}
inline void Start() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
}
struct card {
  char c;
  int r, b;
  card() {}
  card(char c, int r, int b) : c(c), r(r), b(b) {}
};
int foo(vector<card> a) {
  int num = 0, i = 0, n = (int)a.size(), r = 0, b = 0, R = 0, B = 0;
  while (i < n) {
    if (max(a[i].r - R, 0) <= r && max(a[i].b - B, 0) <= b) {
      r -= max(a[i].r - R, 0), b -= max(a[i].b - B, 0);
      (a[i].c == 'R' ? R : B)++;
      ++i, ++num;
    } else {
      int num_do = max(a[i].r - R - r, a[i].b - B - b);
      num += num_do;
      r += num_do, b += num_do;
    }
  }
  return num;
}
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
double rng() { return double(mt()) / double((ull)-1); }
double t0 = 1000., t = t0;
double P(int was, int now) {
  if (now - was < 0)
    return 1;
  else
    return exp(double(was - now) / t);
}
signed main() {
  Start();
  int n;
  cin >> n;
  vector<card> a;
  for (int i = 0; i < n; ++i) {
    card cd;
    cin >> cd.c >> cd.r >> cd.b;
    a.emplace_back(cd);
  }
  random_shuffle((a).begin(), (a).end());
  int iterations = 1000000, ans = 1e9;
  vector<int> fncs;
  while (iterations--) {
    t *= 0.9999;
    auto b = a;
    for (int i = 0; i < max(1, int(double(n) * t / t0)); ++i)
      swap(b[mt() % n], b[mt() % n]);
    int was = foo(a), now = foo(b);
    if (rng() <= P(was, now)) a = b, was = now;
    fncs.emplace_back(was);
  }
  cerr << t << endl;
  cout << *min_element((fncs).begin(), (fncs).end());
  return 0;
}
