#include <iostream>
#include <vector>
#define endl "\n"
using namespace std;
int N, Block_Cnt, Score, Figure_Num = 1;
int Area[10][4][2];
vector<pair<int, pair<int, int>>> V;
int dx[] = { 0, 0, 1, -1 };
int dy[] = { 1, -1, 0, 0 };
int Min(int A, int B) { if (A < B) return A; return B; }
int Max(int A, int B) { if (A > B) return A; return B; }
void Input()
{
cin >> N;
for (int i = 0; i < N; i++)
{
int a, b, c; cin >> a >> b >> c;
V.push_back(make_pair(a, make_pair(b, c)));
}
}
void Setting_Block(int Shape, int x, int y)
{
if (Shape == 1)
{
int B_Idx = y + 1;
while (B_Idx < 10 && Area[B_Idx][x][0] == 0) B_Idx++; B_Idx--;
Area[B_Idx][x][0] = Figure_Num;
int G_Idx = x + 1;
while (G_Idx < 10 && Area[G_Idx][y][1] == 0) G_Idx++; G_Idx--;
Area[G_Idx][y][1] = Figure_Num++;
Block_Cnt += 2;
}
else if (Shape == 2)
{
int B_Idx = y + 2;
while (B_Idx < 10 && Area[B_Idx][x][0] == 0) B_Idx++; B_Idx--;
Area[B_Idx][x][0] = Figure_Num;
Area[B_Idx - 1][x][0] = Figure_Num;
int G_Idx = x + 1;
while (G_Idx < 10 && Area[G_Idx][y][1] == 0 && Area[G_Idx][y + 1][1] == 0) G_Idx++; G_Idx--;
Area[G_Idx][y][1] = Figure_Num;
Area[G_Idx][y + 1][1] = Figure_Num++;
Block_Cnt += 4;
}
else
{
int B_Idx = y + 1;
while (B_Idx < 10 && Area[B_Idx][x][0] == 0 && Area[B_Idx][x + 1][0] == 0) B_Idx++; B_Idx--;
Area[B_Idx][x][0] = Figure_Num;
Area[B_Idx][x + 1][0] = Figure_Num;
int G_Idx = x + 2;
while (G_Idx < 10 && Area[G_Idx][y][1] == 0) G_Idx++; G_Idx--;
Area[G_Idx][y][1] = Figure_Num;
Area[G_Idx - 1][y][1] = Figure_Num++;
Block_Cnt += 4;
}
}
void Remove(int Idx, int Color)
{
for (int i = 0; i < 4; i++)
{
if (Area[Idx][i][Color] == 0) continue;
Area[Idx][i][Color] = 0;
Block_Cnt--;
}
}
pair<int, int> Find_Partner(int Idx, int Pos, int Color)
{
if (Color == 0)
{
for (int i = 0; i < 4; i++)
{
int n_Idx = Idx + dx[i];
int n_Pos = Pos + dy[i];
if (n_Idx >= 4 && n_Idx < 10 && n_Pos >= 0 && n_Pos < 4)
{
if (Area[Idx][Pos][Color] == Area[n_Idx][n_Pos][Color])
{
if (Idx == n_Idx) return{ 3, i };
return{ 2, i };
}
}
}
return{ 1, -1 };
}
for (int i = 0; i < 4; i++)
{
for (int i = 0; i < 4; i++)
{
int n_Idx = Idx + dx[i];
int n_Pos = Pos + dy[i];
if (n_Idx >= 4 && n_Idx < 10 && n_Pos >= 0 && n_Pos < 4)
{
if (Area[Idx][Pos][Color] == Area[n_Idx][n_Pos][Color])
{
if (Idx == n_Idx) return{ 2, i };
return{ 3, i };
}
}
}
return{ 1, -1 };
}
}
void Move(int Index, int Color)
{
if (Index == 3) return;
int Idx = Index - 1;
for (int i = 0; i < 4; i++)
{
if (Area[Idx][i][Color] == 0) continue;
int Pos = i;
int F_Num = Figure_Num[Area][Idx][i];
pair<int, int> Shape = Find_Partner(Idx , Pos, Color);
if (Shape.first == 1)
{
int n_Idx = Idx + 1;
Area[n_Idx][i][Color] = Area[Idx][i][Color];
Area[Idx][i][Color] = 0;
}
else if (Shape.first == 2)
{
int P_Idx = Idx + dx[Shape.second];
int P_Pos = Pos + dy[Shape.second];
if (Color == 0)
{
int Standard_Idx = Max(P_Idx, Idx);
int Partner_Idx = Min(P_Idx, Idx);
int n_Idx = Standard_Idx + 1;
int nP_Idx = Partner_Idx + 1;
Area[n_Idx][i][Color] = Area[Standard_Idx][i][Color];
Area[nP_Idx][i][Color] = Area[Partner_Idx][i][Color];
Area[Partner_Idx][i][Color] = 0;
}
else
{
int n_Idx = Idx + 1;
int nP_Idx = P_Idx + 1;
Area[n_Idx][i][Color] = Area[Idx][i][Color];
Area[nP_Idx][i][Color] = Area[P_Idx][i][Color];
Area[Idx][i][Color] = 0;
Area[P_Idx][i][Color] = 0;
}
}
else
{
int P_Idx = Idx + dx[Shape.second];
int P_Pos = Pos + dy[Shape.second];
if(Color == 0)
{
int n_Idx = Idx + 1;
int nP_Idx = P_Idx + 1;
Area[n_Idx][i][Color] = Area[Idx][i][Color];
Area[nP_Idx][i][Color] = Area[P_Idx][i][Color];
Area[Idx][i][Color] = 0;
Area[P_Idx][i][Color] = 0;
}
else
{
int Standard_Idx = Max(Idx, P_Idx);
int Partner_Idx = Min(Idx, P_Idx);
int n_Idx = Standard_Idx + 1;
int nP_Idx = Partner_Idx + 1;
Area[n_Idx][i][Color] = Area[Standard_Idx][i][Color];
Area[nP_Idx][i][Color] = Area[Partner_Idx][i][Color];
Area[Partner_Idx][i][Color] = 0;
}
}
}
Move(Index - 1, Color);
}
void Remove_Full_Block()
{
bool Flag = false;
for (int Color = 0; Color < 2; Color++)
{
for (int i = 4; i < 10; i++)
{
int Cnt = 0;
for (int j = 0; j < 4; j++)
{
if (Area[i][j][Color] == 0) break;
Cnt++;
}
if (Cnt == 4)
{
Flag = true;
Score++;
Remove(i, Color);
Move(i, Color);
}
}
}
if (Flag == true) Remove_Full_Block();
}
void Check_Special_Point()
{
for (int Color = 0; Color < 2; Color++)
{
int Cnt = 0;
for(int i = 4; i < 6; i++)
{
for (int j = 0; j < 4; j++)
{
if (Area[i][j][Color] == 0) continue;
Cnt++;
break;
}
}
for (int i = 0; i < Cnt; i++)
{
Remove(9, Color);
Move(9, Color);
}
}
}
void Solution()
{
for (int i = 0; i < V.size(); i++)
{
int t = V[i].first;
int x = V[i].second.first;
int y = V[i].second.second;
Setting_Block(t, x, y);
Remove_Full_Block();
Check_Special_Point();
}
cout << Score << endl << Block_Cnt << endl;
}
void Solve()
{
Input();
Solution();
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
Solve();
return 0;
}