#include using namespace std; typedef long long ll; #define inf 10e17 #define rep(i,n) for(long long i=0; i()) #define debug(x) std::cerr << (x) << std::endl; #define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; } template inline void chmax(T &ans, T t) { if (t > ans) ans = t;} template inline void chmin(T &ans, T t) { if (t < ans) ans = t;} int main() { ll n, m, k; string op; cin >> n >> m >> k >> op; vector b(m), a(n); if (op == "+") { ll s = 0, t = 0; rep(i, m) { cin >> b[i]; s += b[i] * n; s %= k; } rep(i, n) { cin >> a[i]; t += a[i] * m; t %= k; } cout << (s + t) % k << endl; } else { ll s = 0; rep(i, m) { cin >> b[i]; s += b[i]; s %= k; } ll ans = 0; rep(i, n) { cin >> a[i]; ans += a[i] * s; ans %= k; } cout << ans << endl; } }