On a torus-like hexagonal grid, decide whether nm/4 vertices can each dominate a closed neighborhood of 4 vertices, covering every vertex.
Hard8MathCombinatoricsImplementationBrute forceNo attempts yetTime limit2sMemory limit512 MBThe Saturn bee (Apis saturnii) builds its hive in the shape of a ring. A beehive is a hexagonal grid, and we model it as a graph whose edges are walls and whose vertices are the joins between walls. Flatten every hexagon a little so that it becomes a 1×2 rectangle. Then every vertex gets an integer coordinate, and vertex (i,j) is adjacent to (i,j−1), to (i,j+1), and to (i+1,j) when i+j is odd or to (i−1,j) when i+j is even.
To turn an n×m grid into a ring the edges wrap around. If n and m are both even, an edge with endpoint (n,j) ends at (0,j) instead, and an edge with endpoint (i,m) ends at (i,0). If one of the two numbers is odd, the bees twist the grid so that both sides match: if n is odd then (n,j) becomes (0,j+1), and if m is odd then (i,m) becomes (i+1,0). The swarm mind knows the handshaking lemma and never builds a beehive in which n and m are both odd. Figure A.1 shows a few beehives.

Figure A.1: Example beehives
Each soldier bee sits on a vertex and controls that vertex together with the 3 vertices adjacent to it. The swarm mind knows that nm/4 bees are needed to control the whole hive, so the swarm carries exactly that many soldiers. Some beehives turn out to be hard to guard, and the Saturn bees refuse to live there.
Decide whether a beehive is a suitable home for a swarm.
The first line contains two integers n and m (2≤m,n≤10000). At least one of n and m is even.
Print possible if nm/4 bees can guard an n×m beehive, and impossible otherwise. If nm is not divisible by 4 the swarm cannot be assembled, so print impossible.