#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int inf = 99999999;   int n;   char c[20];   int r[20];   int b[20];   int dp[1 << 16][123];   int main() {     int n;     cin >> n;     int maxi = 0;     int ans1 = 0;     int ans2 = 0;     for (int i = 0; i < n; i++) {       cin >> c[i] >> r[i] >> b[i];       maxi += i;       ans1 += r[i];       ans2 += b[i];     }     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     for (int i = 1; i < 1 << n; i++) {       for (int j = 0; j < n; j++) {         if (i >> j & 1) {           int R = 0;           int B = 0;           for (int k = 0; k < n; k++) {             if (k != j && i >> k & 1) {               R += c[k] ==  R ;               B += c[k] ==  B ;             }           }           R = min(R, r[j]);           B = min(B, b[j]);           for (int k = 0; k <= maxi; k++) {             if (dp[i ^ (1 << j)][k] != -1) {               dp[i][k + R] = max(dp[i][k + R], dp[i ^ (1 << j)][k] + B);             }           }         }       }     }     int ans = max(ans1, ans2);     for (int i = 0; i <= maxi; i++) {       if (dp[(1 << n) - 1][i] != -1) {         ans = min(ans, max(ans2 - dp[(1 << n) - 1][i], ans1 - i));       }     }     cout << ans + n;     return 0;   }   