#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int n, u, r;   vector<int> b, k;   vector<int> p;   void exec(vector<int> a, int type, int count) {     if (count < u) {       if (type == 0) {         for (int i = 0; i < n; ++i) a[i] = a[i] ^ b[i];         exec(a, 1, count + 1);       } else {         vector<int> aa(n);         for (int i = 0; i < n; ++i) aa[i] = a[p[i]] + r;         int rest = u - count - 1;         long long cur_cand = 0;         if (rest & 1) {           vector<int> aaa(n);           for (int i = 0; i < n; ++i) aaa[i] = aa[i] ^ b[i];           cur_cand = inner_product(aaa.begin(), aaa.end(), k.begin(), 0LL);         } else {           cur_cand = inner_product(aa.begin(), aa.end(), k.begin(), 0LL);         }         ans = max(cur_cand, ans);         exec(aa, 0, count + 1);         exec(aa, 1, count + 1);       }     } else {       long long cand = inner_product(a.begin(), a.end(), k.begin(), 0LL);       ans = max(cand, ans);     }   }   int main() {     cin >> n >> u >> r;     vector<int> a(n);     b.resize(n);     k.resize(n);     p.resize(n);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     for (int i = 0; i < n; ++i) cin >> k[i];     for (int i = 0; i < n; ++i) {       cin >> p[i];       --p[i];     }     for (int i = 0; i < n; ++i) {       ans += k[i] * (u & 1 ? a[i] ^ b[i] : a[i]);     }     exec(a, 1, 0);     exec(a, 0, 0);     cout << ans;     return 0;   }   