#include using namespace std; #define all(v) (v).begin(),(v).end() #define pb(a) push_back(a) #define rep(i, n) for(int i=0;i> n >> m >> w; vector a(n), b(n), c(m), d(m); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, m) cin >> c[i]; rep(i, m) cin >> d[i]; ll ans = 0; int mask1 = 1 << n; int mask2 = 1 << m; vector> dp(mask1, vector(mask2, -INF)); dp[0][0] = 0; rep(bit1, mask1) { rep(bit2, mask2) { ll sum = 0; rep(i, n) if(bit1 >> i & 1) sum += a[i]; rep(i, m) if(bit2 >> i & 1) sum -= c[i]; if(sum < 0 || sum > w) continue; rep(i, n) { if(bit1 >> i & 1) { continue; } if(a[i] + sum <= w) chmax(dp[bit1 ^ (1 << i)][bit2], dp[bit1][bit2] + b[i]); } rep(i, m) { if(bit2 >> i & 1) { continue; } if(-c[i] + sum >= 0LL) chmax(dp[bit1][bit2 ^ (1 << i)], dp[bit1][bit2] - d[i]); } chmax(ans, dp[bit1][bit2]); } } cout << ans << endl; return 0; }