/* ACM ICPC Southeast Regional Contest 2009 Mosaic Author: Yiu Yu Ho */ import java.io.*; import java.util.*; public class mosaicYiu { public Scanner in = new Scanner(System.in); public PrintStream out = System.out; public int Mod = 1000000; public int rn, cn, lim; public void main() { int r, c, set; int S; cn = in.nextInt(); while(cn > 0) { rn = in.nextInt(); //We tile the rectangle in a row major order, as we proceed, we keep track of the interface between //the completely tiled area and the completely un-tiled area, which should consist of cn+1 cells. //That is, if we are tiling cell (r, c), then cells before (r, c) in the row-major order must all be //tiled (occupied) and cells after (r+1, c) in the row-major order must be empty (unoccupied), the //status (tiled-ness) of cells in between (r, c) and (r+1, c), inclusive, are kept track by the bit mask. lim = 1 << (cn+1); int[] cur, nxt; cur = new int[lim]; cur[0] = 1 % Mod; for(r=0;r 0) { if(in(0, set)) { //already filled, move to the next tile inheriting the current state S = (set >> 1); nxt[S] = (nxt[S] + cur[set]) % Mod; } else { //not filled, try all 5 possible tilings if(c+1 < cn && !in(1, set) && !in(cn, set)) { S = (set >> 1); S = on(0, S); S = on(cn-1, S); //xx //x. nxt[S] = (nxt[S] + cur[set]) % Mod; S = on(cn, S); //xx //xx nxt[S] = (nxt[S] + cur[set]) % Mod; } if(c+1 < cn && !in(cn, set)) { S = (set >> 1); S = on(cn-1, S); S = on(cn, S); //x. //xx nxt[S] = (nxt[S] + cur[set]) % Mod; } if(c+1 < cn && !in(1, set)) { S = (set >> 1); S = on(0, S); S = on(cn, S); //xx //.x nxt[S] = (nxt[S] + cur[set]) % Mod; } if(c > 0 && !in(cn-1, set) && !in(cn, set)) { S = (set >> 1); S = on(cn-2, S); S = on(cn-1, S); //.x //xx nxt[S] = (nxt[S] + cur[set]) % Mod; } } }//end for set = 0 .. lim-1 cur = nxt; }//end for r = 0 .. rn-1, c = 0 .. cn-1 //At the end, we want every before (rn+1, 0) to be tiled, and in the interface there are no tiles. out.println(cur[0]); cn = in.nextInt(); } } //Check if bit x is on (the corresponding cell is tiled) public boolean in(int x, int set) { return (set & (1<