import std.stdio;
import std.algorithm;

void main() {
    int n; 
    while (readf("%d\n", &n), n) {
        int[] L = new int[5];
        foreach (_; 0 .. n) {
            int d, p, q; readf("%d %d %d\n", &d, &p, &q);
            if (d == 1) {
                foreach (i; q - 1 .. q - 1 + p) {
                    L[i]++;
                }
            } else {
                L[q - 1] += p;
            }
            while (L.all!"a > 0") {
                foreach (ref l; L) {
                    l--;
                }
            }
        }
        L.reduce!"a + b".writeln;
    }
}