import java.io.*; import java.util.*; class Main { static final long MOD=201712111; static final long I9=powerMod(9,MOD-2); static long[][][]dp2; static long powerMod(long x, long exponent) { long prod = 1; for (int i = 63; i >= 0; --i) { prod = (prod * prod) % MOD; if ((exponent & 1L << i) != 0) { prod = (prod * x) % MOD; } } return prod; } Main(int h,int w,int[][]b){ int[][]dp=new int[h][w]; dp[0][0]=b[0][0]==-1?1:b[0][0]; for(int i=0;i0)m=Math.min(m,dp[i-1][j]+c); if(j>0)m=Math.min(m,dp[i][j-1]+c); dp[i][j]=m; } int indet=0; for(int[]r:b) for(int rr:r) if(rr==-1)indet++; long[][]dp2=new long[2][1<0&&dp[i][j]==dp[i-1][j]+c; boolean lft=j>0&&dp[i][j]==dp[i][j-1]+c; int lftS=s>>1|1; int upS=s>>1|1<<(w-1); long ans; if(lft&&up) ans=(dp2[pr][lftS]+dp2[pr][upS]-dp2[pr][lftS|upS]+MOD)%MOD; else if(lft) ans=dp2[pr][lftS]; else if(up) ans=dp2[pr][upS]; else throw new Error(); dp2[u][s]=ans*factor%MOD; } } out.println(dp[h-1][w-1]); long ans=powerMod(9,indet); ans=ans*dp2[(h*w-1)%2][1]%MOD; out.println(ans); } public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int h=sc.nextInt(); int w=sc.nextInt(); String[]s=new String[h]; for(int i=0;i