import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { new Main().run(); } final long MOD=(long)1e8+7; int MAX=(int)3e5+1; long[] fac=new long[MAX]; long[] inv=new long[MAX]; long[] ifac=new long[MAX]; { fac[0]=fac[1]=ifac[0]=ifac[1]=inv[0]=inv[1]=1; for (int i=2;i=MOD?(a+b-MOD):(a+b); } long binom(int n,int k) { if(n<0||k<0||n-k<0) return 0; return fac[n]*ifac[k]%MOD*ifac[n-k]%MOD; } long f(int H, int W, int[][] P, int s, int K) { long ans=1; int prey=0,prex=0; for (int i=0;i<=K;++i) { if ((s>>P[i][2])%2==0) continue; if (!(P[i][0]>=prey&&P[i][1]>=prex)) return 0; int dy=P[i][0]-prey; int dx=P[i][1]-prex; ans=ans*binom(dy+dx,dy)%MOD; prey=P[i][0]; prex=P[i][1]; } return ans; } void run() { FastScanner sc=new FastScanner(); int H=sc.nextInt(); int W=sc.nextInt(); int K=sc.nextInt(); int[][] P=new int[K+1][3]; for (int i=0;ia[0]).thenComparing(a->a[1])); long[] dist=new long[1<=0;--s) { if ((s>>i)%2==1) continue; dist[s|1< Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }