#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, k = 0, a, b, c;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> a >> b >> c;
    if (c > 1 and b >= 1) {
      k += 3;
      c -= 2;
      b -= 1;
    } else {
      if (b > 1 and a >= 1) {
        k += 3;
        b -= 2;
        a -= 1;
      }
    }
  }
  cout << k;
}
