Problem: One day, Hongcow goes to the store and sees a brand new deck of n special cards. Each individual card is either red or blue. He decides he wants to buy them immediately. To do this, he needs to play a game with the owner of the store.

This game takes some number of turns to complete. On a turn, Hongcow may do one of two things: 

  * Collect tokens. Hongcow collects 1 red token and 1 blue token by choosing this option (thus, 2 tokens in total per one operation). 
  * Buy a card. Hongcow chooses some card and spends tokens to purchase it as specified below. 



The i-th card requires ri red resources and bi blue resources. Suppose Hongcow currently has A red cards and B blue cards. Then, the i-th card will require Hongcow to spend max(ri - A, 0) red tokens, and max(bi - B, 0) blue tokens. Note, only tokens disappear, but the cards stay with Hongcow forever. Each card can be bought only once.

Given a description of the cards and their costs determine the minimum number of turns Hongcow needs to purchase all cards.

Input

The first line of input will contain a single integer n (1 ≤ n ≤ 16).

The next n lines of input will contain three tokens ci, ri and bi. ci will be 'R' or 'B', denoting the color of the card as red or blue. ri will be an integer denoting the amount of red resources required to obtain the card, and bi will be an integer denoting the amount of blue resources required to obtain the card (0 ≤ ri, bi ≤ 107).

Output

Output a single integer, denoting the minimum number of turns needed to acquire all the cards.

Examples

Input

3
R 0 1
B 1 0
R 1 1


Output

4


Input

3
R 3 0
R 2 0
R 1 0


Output

6

Note

For the first sample, Hongcow's four moves are as follows: 

  1. Collect tokens 
  2. Buy card 1
  3. Buy card 2
  4. Buy card 3

Note, at the fourth step, Hongcow is able to buy card 3 because Hongcow already has one red and one blue card, so we don't need to collect tokens.

For the second sample, one optimal strategy is as follows: 

  1. Collect tokens 
  2. Collect tokens 
  3. Buy card 2
  4. Collect tokens 
  5. Buy card 3
  6. Buy card 1

At the fifth step, even though Hongcow has a red token, Hongcow doesn't actually need to spend it, since Hongcow has a red card already.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
  return out << "(" << pair.first << ", " << pair.second << ")";
}
template <class A, class B, class C>
struct Triple {
  A first;
  B second;
  C third;
  bool operator<(const Triple& t) const {
    if (first != t.first) return first < t.first;
    if (second != t.second) return second < t.second;
    return third < t.third;
  }
};
template <class T>
void ResizeVec(T&, vector<long long>) {}
template <class T>
void ResizeVec(vector<T>& vec, vector<long long> sz) {
  vec.resize(sz[0]);
  sz.erase(sz.begin());
  if (sz.empty()) {
    return;
  }
  for (T& v : vec) {
    ResizeVec(v, sz);
  }
}
template <class A, class B, class C>
ostream& operator<<(ostream& out, Triple<A, B, C> t) {
  return out << "(" << t.first << ", " << t.second << ", " << t.third << ")";
}
template <class T>
ostream& operator<<(ostream& out, vector<T> vec) {
  out << "(";
  for (auto& v : vec) out << v << ", ";
  return out << ")";
}
struct Info {
  long long turns, red, blue;
  bool operator<(const Info& oth) const {
    if (turns != oth.turns) return turns < oth.turns;
    if (red != oth.red) return red < oth.red;
    return blue < oth.blue;
  }
  friend ostream& operator<<(ostream& out, Info i) {
    return out << "(" << i.turns << ", " << i.red << ", " << i.blue << ")";
  }
};
bool IsDominated(Info i1, Info i2) {
  i1.red += i2.turns - i1.turns;
  i1.blue += i2.turns - i1.turns;
  return i1.red <= i2.red && i1.blue <= i2.blue;
}
const long long N = 16;
vector<Info> res[1 << N];
long long has_red[1 << N];
long long has_blue[1 << N];
long long is_red[N];
long long r[N], b[N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  if (0) cout << fixed << setprecision(10);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < (n); ++i) {
    char c;
    cin >> c;
    if (c == 'R') {
      is_red[i] = 1;
    }
    cin >> r[i] >> b[i];
  }
  res[0].push_back({0, 0, 0});
  for (long long mask = 0; mask < (1 << n); ++mask) {
    if (mask == 0) {
      continue;
    }
    for (long long last = 0; last < (n); ++last) {
      if (!(mask & (1 << last))) {
        continue;
      }
      long long prv_mask = mask - (1 << last);
      has_red[mask] = has_red[prv_mask] + (is_red[last]);
      has_blue[mask] = __builtin_popcount(mask) - has_red[mask];
      for (auto& prv_res : res[prv_mask]) {
        long long cost_r = max(0ll, r[last] - has_red[prv_mask]);
        long long cost_b = max(0ll, b[last] - has_blue[prv_mask]);
        long long need_turns =
            max(max(0ll, cost_r - prv_res.red), cost_b - prv_res.blue);
        auto new_res = prv_res;
        new_res.turns += need_turns;
        new_res.red += need_turns;
        new_res.blue += need_turns;
        new_res.red -= cost_r;
        new_res.blue -= cost_b;
        (mask, last, new_res, need_turns);
        assert(new_res.red == 0 || new_res.blue == 0);
        bool fail = false;
        for (auto& R : res[mask]) {
          if (IsDominated(new_res, R)) {
            fail = true;
            break;
          }
        }
        if (!fail) {
          vector<Info> new_heh;
          for (auto& R : res[mask]) {
            if (!IsDominated(R, new_res)) {
              new_heh.push_back(R);
            }
          }
          new_heh.push_back(new_res);
          res[mask] = new_heh;
        }
      }
    }
    (mask, res[mask]);
  }
  long long best = 1e9;
  for (auto& H : res[(1 << n) - 1]) {
    mini(best, H.turns);
  }
  cout << best + n << endl;
  return 0;
}