#include #include using namespace std; int main(void){ 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]; long long sumOfB = accumulate(b.begin(), b.end(), 0); vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; long long ans = 0; if (op == '+'){ for (int i = 0; i < n; i++){ ans += (m * a[i] + sumOfB); ans %= k; } } else{ for (int i = 0; i < n; i++){ ans += (a[i] * sumOfB); ans %= k; } } cout << ans << endl; }