#include #include #include #include #define MOD 1000000007 long long int power(long long int a, long long int b) { long long int ans = 1; long long int k = a; while(b) { if(b%2==1) ans*=k, ans%=MOD; k*=k, k%=MOD; b/=2; } return ans; } int n; std::vector< std::vector > mul(std::vector< std::vector > A, std::vector< std::vector > B) { std::vector< std::vector > M; M.resize(n+1); for(int i=0;i > func(std::vector< std::vector > M, long long int k) { if(k==1) return M; else if(k%2==1) { std::vector< std::vector > M2 = func(M,k-1); M2 = mul(M2,M); return M2; } else { std::vector< std::vector > M2 = func(M,k/2); M2 = mul(M2,M2); return M2; } } std::vector< std::vector > M; std::vector< std::pair > index; std::map< std::pair , int> hash; int check[110]; int main() { long long int a; int b,c; scanf("%lld%d%d",&a,&b,&c); if(a==1) { for(int i=1;i<=c;i++) { int d; scanf("%d",&d); if(d==1) { printf("1\n"); return 0; } } printf("0\n"); return 0; } for(int i=1;i<=b;i++) for(int j=1;j<=b+1;j++) index.push_back(std::make_pair(i,j)); n = index.size(); // 0~n M.resize(n+1); for(int i=0;i P = index[j]; if(P.first==d) continue; M[j][hash[std::make_pair(d,d)]] = 0; } } std::vector< std::vector > M2 = func(M,a-1); long long int ans = 0; for(int i=0;i P2 = index[i]; if(check[P2.first]==1 && P2.first==P2.second) continue; for(int j=0;j P = index[j]; if(P.second==1) { ans += M2[i][j], ans %= MOD; } } } long long int ans2 = power(b,a); printf("%lld\n",(ans2-ans+MOD)%MOD); }