Turning on the lights
InterviewTime limit2sMemory limit512 MB
Bessie walks through lit adjacent rooms to press switches that light new rooms, and every room ever lit counts.
Problem
Farmer John built a new barn with rooms. The rooms carry the coordinates through . Bessie the cow is afraid of the dark and wants as many rooms lit as possible.
Bessie starts in , the only room whose light is on. Some rooms hold a switch that turns the light of another room on and off. For example, a switch in can control the light of . Bessie can press a switch only while she is inside the room that holds it. She can enter a room only when its light is on, and from a room she moves to a room adjacent in one of the four directions.
A room that Bessie lights counts even if she never gets inside it. Room , lit from the start, counts as well. Find the largest number of rooms Bessie can have lit.
Input
The first line contains two integers and . (, )
Each of the next lines contains four integers , , , . It means a switch in room turns the light of room on and off. () One room can hold several switches, and several switches can control the light of the same room.
Output
Print the largest number of rooms Bessie can have lit.
Hint
In the first example Bessie uses the switch in to light and . Walking to lets her light , and from she lights . Room stays dark, so she can never press the switch inside it. Five rooms is the most she can light.