#include <iostream>
#include <vector>
#include <cstdio>
#include <bitset>
using namespace std;

int bit(int bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}


int main(){
	int n,a,b,c,mask,ret;
	while(cin >> n && n){
		vector<int> data(5001,0);
		data[5000] = 63;
		ret = 0;
		while(n--){
			cin >> a >> b >> c;
			c--;
			if(a==1){
				mask  =  ( (1<<b)-1 ) << c;
				for(int i=0;i+1<data.size();i++){
					if(data[i+1] & mask){
						data[i] += mask;
						break;
					}
				}
			}else{
				mask  = 1 << c;
				for(int i=0;i+1<data.size();i++){
					if(data[i+1] & mask){
						for(int j=0;j<b;j++)
							data[i-j]+=mask;
						break;
					}
				}		
			}
			vector<int>::iterator it = data.begin();
			while(it != data.end()){
				if((*it) == 31){
					it = data.erase(it);
					it--;
				}
				it++;
			}
		}
		for(int i=0;i<data.size()-1;i++){
			ret += bit( data[i] );
		}
		cout << ret << endl;
	}
}