#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 1000000007
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define MP make_pair
#define VI vector<int>
#define VII vector<int>::iterator
#define EB emplace_back
#define SI set<int>
#define SII set<int>::iterator
#define QI queue<int>
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
int inc(const int &a, const int &b) { return a + b >= MOD ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
int res = 1;
while(k)
{
if(k & 1) Mul(res, x);
Sqr(x), k >>= 1;
}
return res;
}
// int f[35][2];
const LL INF = 1e18;
int n, m, r;
int a[35], b[35], k[35], p[35];
int w[35], g[35][35];
LL ans;
void dfs(int x, int op)
{
// printf("now : ");
// for(int i = 1; i <= n; ++i)
// printf("%d ", w[i]);
// puts("");
if((m - x + 1 + 1 ) & 1)
{
LL res = 0;
for(int i = 1; i <= n; ++i)
res += 1LL * w[i] * k[i];
chkmx(ans, res);
}
if(x == m + 1) return;
if(op == 0)
{
for(int i = 1; i <= n; ++i) g[x][i] = w[i];
for(int i = 1; i <= n; ++i) w[i] = g[x][p[i]] + r;
dfs(x + 1, 0);
for(int i = 1; i <= n; ++i) w[i] = g[x][i];
for(int i = 1; i <= n; ++i) w[i] ^= b[i];
dfs(x + 1, 1);
for(int i = 1; i <= n; ++i) w[i] = g[x][i];
}
if(op == 1)
{
for(int i = 1; i <= n; ++i) g[x][i] = w[i];
for(int i = 1; i <= n; ++i) w[i] = g[x][p[i]] + r;
dfs(x + 1, 0);
for(int i = 1; i <= n; ++i) w[i] = g[x][i];
}
}
int main()
{
// f[1][0] = f[1][1] = 1;
// for(int i = 2; i <= 30; ++i)
// {
// f[i][0] = f[i - 1][0] + f[i - 1][1];
// f[i][1] = f[i - 1][0];
// }
// printf("%d\n", f[30][0] + f[30][1]);
scanf("%d %d %d", &n, &m, &r);
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), w[i] = a[i];
for(int i = 1; i <= n; ++i) scanf("%d", &b[i]);
for(int i = 1; i <= n; ++i) scanf("%d", &k[i]);
for(int i = 1; i <= n; ++i) scanf("%d", &p[i]);
ans = -INF;
dfs(1, 0);
printf("%lld\n", ans);
return 0;
}
987B - High School Become Human | 1223A - CME |
1658B - Marin and Anti-coprime Permutation | 14B - Young Photographer |
143A - Help Vasilisa the Wise 2 | 320A - Magic Numbers |
1658A - Marin and Photoshoot | 514A - Chewbaсca and Number |
382A - Ksenia and Pan Scales | 734B - Anton and Digits |
1080A - Petya and Origami | 1642D - Repetitions Decoding |
1440A - Buy the String | 1658F - Juju and Binary String |
478A - Initial Bet | 981A - Antipalindrome |
365A - Good Number | 1204B - Mislove Has Lost an Array |
1409D - Decrease the Sum of Digits | 1476E - Pattern Matching |
1107A - Digits Sequence Dividing | 1348A - Phoenix and Balance |
1343B - Balanced Array | 1186A - Vus the Cossack and a Contest |
1494A - ABC String | 1606A - AB Balance |
1658C - Shinju and the Lost Permutation | 1547C - Pair Programming |
550A - Two Substrings | 797B - Odd sum |