#include using namespace std; //#pragma GCC optimize("Ofast") #define rep(i,n) for(long long i=0;i<(long long)(n);i++) #define REP(i,k,n) for(long long i=k;i<(long long)(n);i++) #define RREP(i,k,n) for(long long i=n;i>=(long long)(k);i--) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define eb emplace_back #define lb(v,k) (lower_bound(all(v),k)-v.begin()) #define ub(v,k) (upper_bound(all(v),k)-v.begin()) #define fi first #define se second #define pi M_PI #define PQ(T) priority_queue #define SPQ(T) priority_queue,greater> #define show(x) cout<<#x<<": " #define newline cout<<'\n'; using ll=long long; using S=multiset; using P=pair; using PP=tuple; using vp=vector

; using vi=vector; using vvi=vector; using vvvi=vector; constexpr ll inf=1001001001001001; constexpr int INF=1001001001; constexpr int mod=1000000007; //or 998244353 template bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template bool chmax(T&a,T b){if(a bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template void out(T a){cout< void outp(T a){cout<<'('< void outvp(T v){rep(i,v.size())cout<<'('< void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout< void outvv(T v){rep(i,v.size())outv(v[i]);} template void YesNo(T b){if(b)out("Yes");else out("No");} template void yesno(T b){if(b)out("yes");else out("no");} template void YESNO(T b){if(b)out("YES");else out("NO");} void decimal(int x){cout<0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;} vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;} void solve(){ int n,k; cin>>n>>k; vi a(n); rep(i,n) cin>>a[i]; reverse(all(a)); int sum=0; rep(i,n) sum+=a[i]; int p=1,x=0;; rep(i,n){ x+=p*a[i]; p*=k; x%=sum; p%=sum; } out(x); } signed main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }