Strawberry Shortcake is packing cupcakes for her friend Blueberry Tallcake. Shortcake has three different flavors of cupcakes: strawberry, blueberry, and pineberry. She has a $$$N \times M$$$ dimension cupcake container, initially empty, and will place cupcakes into empty spots one-by-one until the container is full.
As Shortcake places cupcakes into the container, she observes the formation of regions of the same cupcake flavor. She formally defines a single 'region' as a maximal connected group of cupcakes of the same flavor, where two cupcakes are considered connected if they are orthogonally adjacent to each other or there is a chain of adjacent cupcakes from one to the other. Shortcake is curious and wonders how many distinct regions exist in the container after each cupcake is placed.
The first line of input contains $$$N,\ M,\ (1 \leq N, M \leq 300)$$$, the number of rows and columns in the cupcake container.
The next $$$N \times M$$$ lines each contain $$$i,\ j,\ f\ (1 \leq i \leq N,\ 1 \leq j \leq M)$$$ meaning Shortcake places a cupcake of flavor $$$f = $$$ S, B, or P (strawberry, blueberry, or pineberry) at position $$$(i, j)$$$ in the container.
For each cupcake that Shortcake places, output the number of distinct regions that exist in the container after she places the cupcake.
2 22 1 P1 2 P2 2 S1 1 P
1 2 3 2
2 31 3 S1 2 P1 1 P2 1 P2 2 B2 3 B
1 2 2 2 3 3
3 32 3 B3 1 P3 2 S1 1 B3 3 S1 2 B1 3 B2 2 P2 1 P
1 2 3 4 4 4 3 4 3
