// #define DEBUGGING #include using namespace std; #define endl '\n' #define ALL(V) (V).begin(), (V).end() #define ALLR(V) (V).rbegin(), (V).rend() template using V = vector; template using VV = V>; using ll = int64_t; using ull = uint64_t; using PLL = pair; template const T& var_min(const T &t) { return t; } template const T& var_max(const T &t) { return t; } template const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); } template const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); } template void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); } template void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); } namespace init__ { struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; } #ifdef DEBUGGING // #include "../debug/debug.cpp" #include "../../debug/debug.cpp" #else #define DEBUG(...) 0 #define DEBUG_SEPARATOR_LINE 0 #endif template T make_v(T init) { return init; } template auto make_v(T init, size_t s, Tail... tail) { #define rec make_v(init, tail...) return V(s, rec); #undef rec } const ssize_t size = (1 << 24) + 10; const ssize_t input_size = 1e3; int32_t x[size]; int32_t sum_x[size]; int32_t X[input_size], Y[input_size], A[input_size], B[input_size], ans_pre[input_size]; #define scast64 static_cast #define cast32 (int32_t) int main() { int32_t M, N, mulX, addX, mulY, addY, MOD; cin >> M >> N >> mulX >> addX >> mulY >> addY >> MOD; int32_t *ptr_arr[] = { X, Y, A, B, }; for(int32_t i = 0; i < 4; i++) for(int32_t j = 0; j < M; j++) cin >> ptr_arr[i][j]; int32_t pre_x, pre_y; for(int32_t i = 0; i < N; i++) { int32_t nxt_x; int32_t nxt_y; if(i < M) { nxt_x = X[i]; nxt_y = Y[i]; } else { nxt_x = cast32((scast64(pre_x) * scast64(mulX) + scast64(addX)) % scast64(MOD)); nxt_y = cast32((scast64(pre_y) * scast64(mulY) + scast64(addY)) % scast64(MOD)); } x[nxt_x] += nxt_y; pre_x = nxt_x; pre_y = nxt_y; } for(int i = 1; i < size; i++) { for(int j = 1; scast64(i) * scast64(j) < scast64(size); j++) { sum_x[i] += x[i * j]; DEBUG(sum_x[i]); } } int32_t pre_a, pre_b; int32_t sum = 0; for(int32_t i = 0; i < N; i++) { int32_t nxt_a, nxt_b; int32_t ans = 0; if(i < M) { nxt_a = A[i]; nxt_b = B[i]; } else { nxt_a = cast32((scast64(pre_a) * scast64(mulX) + scast64(addX + MOD - 1)) % scast64(MOD) + 1); nxt_b = cast32((scast64(pre_b) * scast64(mulY) + scast64(addY + MOD - 1)) % scast64(MOD) + 1); } DEBUG(make_pair(nxt_a, nxt_b)); ans += sum_x[nxt_a]; if(scast64(nxt_a) * scast64(nxt_b) < scast64(MOD)) ans -= sum_x[nxt_a * nxt_b]; if(i < M) cout << ans << endl; DEBUG(ans); sum ^= ans; pre_a = nxt_a; pre_b = nxt_b; } cout << sum << endl; return 0; }