#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define MOD 1000000007 int main() { int n, m, k; cin >> n >> m >> k; char op; cin >> op; vector b(m); for (int i = 0; i < m; ++i) { cin >> b[i]; } vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } ll bsum = 0; for (int i = 0; i < m; ++i) { bsum += b[i]; bsum %= k; } ll ans = 0; for (int i = 0; i < n; ++i) { ll res = 0; if (op == '+') { res = (m * a[i]) % k; res = (res + bsum) % k; } else { res = a[i]; res = (res * bsum) % k; } ans = (ans + res) % k; } cout << ans << endl; return 0; }