#include <bits/stdc++.h>   using namespace std;   int n, u, r, i;   bool flag = false;   long long max_score = 0;   vector<long long> a, b, k, p;   inline long long score(vector<long long> a) {     long long s = 0;     for (i = (0); i < (n); ++i) {       s += a[i] * k[i];     }     return s;   }   vector<long long> permute(const vector<long long> &a) {     vector<long long> temp(a.size());     for (i = (0); i < (n); ++i) {       temp[i] = a[p[i] - 1] + r;     }     return temp;   }   void recurse(vector<long long> a, long long remain) {     if (remain % 2 == 0) {       long long sc = score(a);       if (!flag || max_score < sc) {         max_score = sc;         flag = true;       }     }     if (remain == 0) return;     recurse(permute(a), remain - 1);     remain--;     for (i = (0); i < (n); ++i) {       a[i] = a[i] ^ b[i];     }     if (remain % 2 == 0) {       long long sc = score(a);       if (!flag || max_score < sc) {         max_score = sc;         flag = true;       }     }     if (remain == 0) return;     recurse(permute(a), remain - 1);   }   int main(int argc, char *argv[]) {     cin >> n >> u >> r;     a = vector<long long>(n);     b = vector<long long>(n);     p = vector<long long>(n);     k = vector<long long>(n);     for (i = (0); i < (n); ++i) {       cin >> a[i];     }     for (i = (0); i < (n); ++i) {       cin >> b[i];     }     for (i = (0); i < (n); ++i) {       cin >> k[i];     }     for (i = (0); i < (n); ++i) {       cin >> p[i];     }     recurse(a, u);     cout << max_score << endl;     return 0;   }   