a,c,s,m=1e6+7;main(t){for(scanf("%d%*d",&c);~scanf("%d",&a);s+=t)for(t=1;a--;t=t*c%m);a=!printf("%d",s%m);}