The Mirror Cat Leaves a Mirror Behind When It Dies
Time limit1sMemory limit1024 MB
Given N cats in fire order, each living cat emits beams in four directions blocked by any mirror; a cat dies if hit, leaving a mirror below its cell; count survivors.
- Level
Medium6 of 10
- Topics
- Simulation, Hash map, Sorting, Implementation
- Solved
- No attempts yet
Problem


On an island in the grid-based Didimon Adventure, mirror cats live together. While surveying their ecosystem, Didi discovered a shocking fact. A mirror cat fires a beam that melts every living creature it touches in the four cardinal directions. That beam passes through other mirror cats and reaches the edge of the grid no matter where it is fired from. Mirror cats evolved to carry a mirror on their tail to protect their own body from companions, and that mirror is always located in the cell just below the mirror cat. The mirror blocks the beam and is not melted by it. Also, since matte is the trend these days, the mirror does not reflect the beam. Because a mirror cat leaves a mirror behind when it dies, the mirror stays in its place even after the mirror cat is melted away.


Didi found out that the order in which the mirror cats fire their beams is fixed. However, a mirror cat that has already disappeared to someone's beam cannot fire its beam even when its turn comes. When all living mirror cats have each fired a beam once in order, write a program to find the number of mirror cats that survive to the end.
Input
The first line gives the integer , the number of mirror cats ().
From the second line, lines give the grid positions of the mirror cats in the order they fire their beams, separated by spaces (). It is guaranteed that no two mirror cats share a position, and that no mirror cat's position coincides with any mirror's position.
Output
Output the number of mirror cats that survive to the end.