#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using ll = long long;
using namespace __gnu_pbds;
using ord_set = tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>;

//#define int ll

const int INF = 1e9 + 1;

void solve() {
    int n, m, T;
    cin >> n >> m >> T;
    vector<int> a(n), b(m);
    vector<ll> pref(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        pref[i + 1] = pref[i] + a[i];
    }
    ll ans = 0;
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        b[i]--;
    }
    vector<ll> answer(n);
    vector<int> pos(21, -1);
    for (int i = 0; i < n; i++) {
        pos[a[i]] = i;
        for (int j = 1; j <= n; j++) {
            if (pos[j] == -1) {
                continue;
            }
            ll t = pref[i + 1] - pref[pos[j]];
            if (T > t) {
                answer[i] = max(answer[i], (T - t) / j + i - pos[j] + 1);
            }
        }
    }
    pos.assign(21, -1);
    for (int i = n - 1; i >= 0; i--) {
        pos[a[i]] = i;
        for (int j = 1; j <= n; j++) {
            if (pos[j] == -1) {
                continue;
            }
            ll t = pref[pos[j] + 1] - pref[i];
            if (T > t) {
                answer[i] = max(answer[i], (T - t) / j + pos[j] - i + 1);
            }
        }
    }
    for (int i = 0; i < m; i++) {
        ans = max(ans, answer[b[i]]);
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt = 1;
//    cin >> tt;
    while (tt--) {
        solve();
    }
}
