using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST{ static void Main(){ Sol mySol =new Sol(); mySol.Solve(); } } class Sol{ public void Solve(){ checked{ int[][] WF=new int[N][]; for(int i=0;i=mod)nCr[i][j]-=mod; } } long[][] iPown=new long[1001][]; for(int i=0;i<1001;i++){ iPown[i]=new long[1001]; iPown[i][0]=1; for(int j=1;j<=1000;j++){ iPown[i][j]=iPown[i][j-1]*i; if(iPown[i][j-1]>=mod)iPown[i][j-1]%=mod; } } long ans=0; for(int ii=0;ii A[j] surj: // n->k surj:Σ(-1)^{k-i}*kCi*i^n, i=1 to k int n=A[ii]; int k=A[jj]; long surj=0; for(int i=1;i<=k;i++){ long term=nCr[k][i]*iPown[i][n]; if(term>=mod)term%=mod; if((k-i)%2==0)surj+=term; if((k-i)%2!=0)surj+=mod-term; if(surj>=mod)surj%=mod; } ans+=surj; if(ans>=mod)ans%=mod; } } Console.WriteLine(ans); } } int N,M; int[] A; bool[,] Mp; public Sol(){ var d=ria(); N=d[0];M=d[1]; A=ria(); Mp=new bool[N,N]; for(int i=0;iint.Parse(e));} static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));} static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));} }