#include #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using str = string; using pl = pair; template using ml = map; using mll = ml; using sl = set; using dbl = double; using pd = pair; template using vec = vector; template using vv = vec>; template using vp = vec>; using vl = vec; using vvl = vec; using vs = vec; using vc = vec; using vpl = vec; using vd = vec; using vpd = vec; using tl3 = tuple; const double INF = std::numeric_limits::infinity(); #define LL(x) \ ll x; \ cin >> x; #define STR(s) \ str s; \ cin >> s; #define VL(a, n) \ vl a(n); \ cin >> a; #define all(obj) (obj).begin(), (obj).end() #define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i) #define rep(i, n) reps(i, 0, n) #define rrep(i, n) reps(i, 1, n + 1) #define repds(i, a, n) for (ll i = (n - 1); i >= (a); i--) #define repd(i, n) repds(i, 0, n) #define rrepd(i, n) repds(i, 1, n + 1) #define rep2(i, j, x, y) rep(i, x) rep(j, y) template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template ostream &operator<<(ostream &os, const pair &p) { os << p.first << " " << p.second; return os; } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const vector &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template ostream &operator<<(ostream &os, const set &s) { os << vec(s.begin(), s.end()); return os; } template istream &operator>>(istream &is, vector &v) { for (T &in : v) is >> in; return is; } void print() { cout << '\n'; } template void print(const T &t) { cout << t << '\n'; } template void print(const Head &head, const Tail &...tail) { cout << head << ' '; print(tail...); } void print_accurate(dbl x) { cout << scientific << setprecision(15) << x << '\n'; } void repr_(const ll &x) { cerr << x; } void repr_(const int &x) { cerr << x; } void repr_(const dbl &x) { cerr << x; } void repr_(const str &x) { cerr << x; } void repr_(const char &x) { cerr << x; } void repr_(const char *x) { cerr << x; } template void repr_(const pair &p); template void repr_(const map &m); template void repr_(const vec &v); template void repr_(const set &s); template void repr_(const pair &p) { cerr << '('; repr_(p.first); cerr << ", "; repr_(p.second); cerr << ')'; } template void repr_(const vec &v) { cerr << '['; for (int i = 0; i < (int)v.size(); i++) { repr_(v[i]); if (i + 1 != (int)v.size()) cerr << ", "; } cerr << ']'; } template void repr_(const set &s) { cerr << '{'; vec v = vec(all(s)); for (int i = 0; i < (int)v.size(); i++) { repr_(v[i]); if (i + 1 != (int)v.size()) cerr << ", "; } cerr << '}'; } template void repr_(const map &m) { cerr << '{'; vp v = vp(all(m)); for (int i = 0; i < (int)v.size(); i++) { repr_(v[i].first); cerr << ": "; repr_(v[i].second); if (i + 1 != (int)v.size()) cerr << ", "; } cerr << '}'; } template void repr_(const Head &head, const Tail &...tail) { repr_(head); repr_(' '); repr_(tail...); } template void repr(const T &t) { repr_(t); cerr << '\n'; } template void repr(const Head &head, const Tail &...tail) { repr_(head); repr_(' '); repr(tail...); } void solve() { ll N, M, W; cin >> N >> M >> W; vl A(N), B(N), C(M), D(M); cin >> A >> B >> C >> D; vl s, t; ll ans = 0; rep(i, N) { s.push_back(i); } rep(i, M) { t.push_back(i); } do { do { ll i, j, w, v; i = j = w = v = 0; while (1) { if ((i < N) && (w + A.at(s.at(i)) <= W)) { w += A.at(s.at(i)); v += B.at(s.at(i)); chmax(ans, v); i++; continue; } if ((j < M) && (w - C.at(t.at(j)) >= 0)) { w -= C.at(t.at(j)); v -= D.at(t.at(j)); chmax(ans, v); j++; continue; } break; } } while (next_permutation(all(t))); } while (next_permutation(all(s))); print(ans); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); solve(); return 0; }