#include #include #include #include #include #include #include #include #include #include using namespace std; int main() { long long n, k, cnt, r = 0, mod = 0; cin >> n >> k; vector a(n); for (int i = 0; i < n; i++){ cin >> a[i]; mod += a[i]; } for (int i = 0; i < n; i++){ r *= k; r += a[i]; r %= mod; } cout << r << endl; }