#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if (y < x) x = y; } template static void amax(T &x, U y) { if (x < y) x = y; } template void countingSort(int n, const T v[], T dest[], int cnt[/*B*/], int B, Func f) { if (n <= (B >> 4) || n <= 16) { memcpy(dest, v, sizeof(T) * n); std::stable_sort(dest, dest + n, [f](const T &a, const T &b) -> bool { return f(a) < f(b); }); return; } for (int j = 0; j < B; ++ j) cnt[j] = 0; for (int i = 0; i < n; ++ i) ++ cnt[f(v[i])]; for (int j = 1; j < B; ++ j) cnt[j] += cnt[j - 1]; for (int i = n - 1; i >= 0; -- i) dest[-- cnt[f(v[i])]] = v[i]; } int main() { int N; int Q; unsigned long long seed; while (~scanf("%d%d%llu", &N, &Q, &seed)) { auto next = [&seed]() { seed = seed ^ (seed << 13); seed = seed ^ (seed >> 7); seed = seed ^ (seed << 17); return (int)(seed >> 33); }; rep(i, 10000) next(); vector A(N), tmp(N); rep(i, N) A[i] = next(); int cnt[1 << 11]; countingSort(N, A.data(), tmp.data(), cnt, 1 << 11, [](int x) { return x & 0x7ff; }); A.swap(tmp); countingSort(N, A.data(), tmp.data(), cnt, 1 << 10, [](int x) { return x >> 11 & 0x3ff; }); A.swap(tmp); countingSort(N, A.data(), tmp.data(), cnt, 1 << 10, [](int x) { return x >> 21 & 0x3ff; }); A.swap(tmp); vector> X(Q), tmp2(Q); rep(qi, Q) X[qi] = { next(), qi }; countingSort(Q, X.data(), tmp2.data(), cnt, 1 << 11, [](pair x) { return x.first & 0x7ff; }); X.swap(tmp2); countingSort(Q, X.data(), tmp2.data(), cnt, 1 << 10, [](pair x) { return x.first >> 11 & 0x3ff; }); X.swap(tmp2); countingSort(Q, X.data(), tmp2.data(), cnt, 1 << 10, [](pair x) { return x.first >> 21 & 0x3ff; }); X.swap(tmp2); ll anssum = 0; { int ai = 0; for (auto q : X) { for (; ai < N && A[ai] < q.first; ++ ai); anssum ^= (ll)ai * q.second; } } printf("%lld\n", anssum); } return 0; }