P9917 "RiOI-03" Grid.
Background
During a training lecture in 2022, a problem appeared in the slides whose input variables were strictly ordered by the initials of MLE’s real name. MLE wanted to use the initials of [vectorwyx](https://www.luogu.com.cn/user/238408) as the input variables in their own problem, and thus this problem was created.
Unfortunately, [vectorwyx](https://www.luogu.com.cn/user/238408) has now retired. Everyone has their own dreams, and each shines in their own way.
Description
**Please read the Constraints of this problem carefully.**
You are given an $n \times n$ square grid with $n$ rows and $n$ columns. Initially, all cells are red. There are $n$ queries. Each query recolors an entire row or an entire column to red or white. After each query, output the perimeter of all red cells. The queries are not independent.
Input Format
The first line contains a positive integer $n$.
Each of the next $n$ lines contains three positive integers $w, y, x$. $w$ indicates the color: $w=1$ means recolor to red, and $w=0$ means recolor to white. $y$ indicates row or column: $y=1$ means recolor the entire $x$-th row, and $y=0$ means recolor the entire $x$-th column.
Output Format
There are $n$ lines. Each line contains one integer, representing the perimeter of the red region after each modification.
Explanation/Hint
### Sample Explanation
[Sample image explanation](https://www.luogu.com.cn/paste/rvrhouei).
### Constraints
For $100\%$ of the data, $3\leq n \leq 10^6 $, $1