
83  ZOJ Monthly, September 2009  G
After the final BOSS is defeated, the hero found that the whole castle is collapsing (very familiar scene, isn't it). Escape from the castle is easy, just need to cross a few rooms. But as the Hero is full of adventurous spirit, he decides to visit every room before he escape the castle. The castle is a rectangle with N * M rooms in it. Two rooms are connected if they share a common edge. The hero starts in the top left room. And the bottom left room is the only way out. After the hero visits a room and leaves it, it will collapse immediately(Another familiar scene). So he can visit each room only once. The diagram shows one tour over a castle with 4 * 10 rooms: Input There are multiply cases (<20), process to the end of file. Each case contains a line with two Integer N and M (2 <= N <= 7, 1 <= M <=10^9). Ouput For each case, if it's impossible to visit every room exactly once and get to the bottom left room, output "Impossible". Otherwise, output the number of tours as it describe above. Beacause the answer can be huge, you just need to output the answer MOD 7777777. Sample Input 3 2 3 3 4 10 Sample Output Impossible 2 2329 Author: WANG, Yelei Source: ZOJ Monthly, September 2009 