#include #include #include #include #include #include #include #include using namespace std; int main() { long long n, m, k, sum1= 0; string op; cin >> n >> m >> k >> op; vector hori(m), ver(n); for (int i = 0; i < m; i++) cin >> hori[i]; for (int i = 0; i < n; i++) cin >> ver[i]; if (op == "+"){ for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ sum1 += (hori[j] + ver[i]); sum1 %= k; } } } else { for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ sum1 += (hori[j] * ver[i]); if (sum1 > 1e18) sum1 %= k; } } } cout << sum1%k << endl; }