#include <iostream>
using namespace std;

int  hei;
char fld[5002];

void typeW(int s, int l)
{
	int line = 0;
	for(int x=s; x<s+l; x++)
	{
		line |= (1<<x);
	}

	for(int y=hei; y>=0; y--)
	{
		if(fld[y]&line)
		{
			fld [y+1] |= line;
			hei = (y+1>hei?y+1:hei);
			break;
		}
	}
}

void typeH(int s, int l)
{
	int line = (1<<s);
	for(int y=hei; y>=0; y--)
	{
		if(fld[y]&line)
		{
			for(int y2=0; y2<l; y2++)
			{
				fld [y+y2+1] |= line;
				hei = (y+y2+1>hei?y+y2+1:hei);
			}
			break;
		}
	}
}

void eraseline()
{
	for(int y=1; y<=hei; )
	{
		if(fld[y] == 31)
		{
			hei--;
			for(int y2=y; y2<=hei+1; y2++)
			{
				fld[y2] = fld[y2+1];
			}
		}
		else
		{
			y++;
		}
	}
}

int main()
{
	int n,d,p,q,c;
	while(cin >> n, n)
	{
		hei = 0;
		fld[0] = 31;
		for(int y=1; y<5002; y++)
		{
			fld[y] = 0;
		}

		while(n--)
		{
			cin >> d >> p >> q;		
			if(d==1) typeW(q-1,p);
			if(d==2) typeH(q-1,p);
			eraseline();
		}
	
		c=0;
		for(int y=1; y<=hei; y++)
		for(int x=0; x<5;    x++)
		{
			if(fld[y]&(1<<x)) c++;
		}

		cout << c << endl;
	}

	return 0;
}