
#include<iostream>
using namespace std;
#define W 5
#define H 5100
#define BLANK 0
#define BLOCK 1
int main()
{
  int n,d,p,q;
  int field[H+2][W];
  int i,j,k;
  bool flag;
  int count;
  while(cin>>n,n){
    for(i=0;i<H+1;i++)for(j=0;j<W;j++)field[i][j]=BLANK;
    for(j=0;j<W;j++)field[i][j]=BLOCK;
    while(n-->0){
      cin>>d>>p>>q;
      // ¡u«
      if(d==1){
	j=q-1;
	flag=false;
	for(i=0;i<H+2;i++){
	  for(k=0;k<p;k++)if(field[i][j+k]==BLOCK)flag=true;
	  if(flag){
	    for(k=0;k<p;k++)field[i-1][j+k]=BLOCK;
	    break;
	  }
	}
      }
      // cu«
      if(d==2){
	j=q-1;
	for(i=0;i<H+2;i++){
	  if(field[i][j]==BLOCK){
	    for(k=1;k<=p;k++)field[i-k][j]=BLOCK;
	    break;
	  }
	}
      }
      // Á
      for(i=H;i>=0;i--){
	flag=true;
	for(j=0;j<W;j++)if(field[i][j]==BLANK)flag=false;
	if(flag){
	  for(j=0;j<W;j++)field[i][j]=BLANK;
	  for(k=i;k>0;k--)for(j=0;j<W;j++)field[k][j]=field[k-1][j];
	  i++;
	}
      }
    }
    // \¦
    /*
    for(i=H-8;i<H+2;i++){
      for(j=0;j<W;j++){
	cout<<field[i][j]<<" ";
      }
      cout<<endl;
    }
    cout<<endl;
    */
    count=0;
    for(i=H-8;i<H+1;i++)for(j=0;j<W;j++)if(field[i][j]==BLOCK)count++;
    cout<<count<<endl;
  }
}