#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int W[10000];
int H;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> N) {
    if (N == 0) break;
    rep(i, 10000) W[i] = 0;

    H = 1;
    rep(i, N) {
      int d, p, q;
      cin >> d >> p >> q;
      int mask = 1;
      if (d == 1) {
        mask = (1<<p)-1;
        p = 1;
      }
      mask <<= (q-1);
      rep(_, p) {
        int h = H;
        for (int y=H; y>=0; y--) {
          if ((W[y] & mask) == 0) h = min(h, y);
          else break;
        }
        if (h == H) H++;
        W[h] |= mask;
      }
    }
    int s = 0;
    rep(i, 10000) {
      //cout<<bitset<5>(W[i])<<"\n";
      if (W[i] == 31) continue;
      s += __builtin_popcount(W[i]);
    }
    cout << s << "\n";
  }
  return 0;
}