#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n;
	while (scanf("%d", &n), n) {
		int E[15]{};
		rep(i, n) {
			int d, p, q; scanf("%d%d%d", &d, &p, &q); q--;
			if (d == 1) {
				rep(i, p)E[q + i]++;
			}
			else E[q] += p;
			int Min = *min_element(E, E + 5);
			rep(i, 5)E[i] -= Min;
		}
		printf("%d\n", accumulate(E, E + 5, 0));
	}
}