#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using Int = long long;
using Uint = unsigned long long;
using Real = long double;
using Int128 = __int128;
using Uint128 = __uint128_t;
// #define _KOSHKA56692
#ifdef _KOSHKA56692
const int MAX = 1e8;
char mem[MAX];
int mempos = 0;
void *operator new(size_t sz) {
    void *res = mem + mempos;
    mempos += sz;
    return res;
}
void operator delete(void *) {}
void operator delete(void *, size_t) {}
#endif
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
istream &operator>>(istream &in, Int128 &num) { Int R; in >> R; num = R; return in; }
ostream &operator<<(ostream &out, const Int128 &num) { out << Int(num); return out; }
istream &operator>>(istream &in, Uint128 &num) { Uint R; in >> R; num = R; return in; }
ostream &operator<<(ostream &out, const Uint128 &num) { out << Uint(num); return out; }

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    #define int Int
    int n, m, s;
    cin >> n >> m >> s;
    vector<int> a(n), b(m);
    vector<int> prefsum(n + 1);
    for (auto &el : a) {
        cin >> el;
    }
    for (int i = 0; i < n; ++i) {
        prefsum[i + 1] = prefsum[i] + a[i];
    }
    for (auto &el : b) {
        cin >> el;
        --el;
    }
    if (n == m) {
        int mn = *min_element(a.begin(), a.end());
        cout << (s / mn) << '\n';
        return 0;
    }
    vector<vector<int>> ixs(21), ixs2(21);
    for (int i = 0; i < n; ++i) {
        ixs[a[i]].push_back(i);
    }
    for (int i = 1; i <= 20; ++i) {
        ixs2[i] = ixs[i];
        for (auto &el : ixs2[i]) {
            el = -el;
        }
        reverse(ixs2.begin(), ixs2.end());
    }
    int answ = 0;
    for (auto start : b) {
    /*
        int le = -1, ri = start + 1;
        while (ri - le > 1) {
           auto mi = le + (ri - le) / 2;
           if (prefsum[start + 1] - prefsum[mi] > s) {
               le = mi;
           } else {
               ri = mi;
           }
       }
       for (int i = ri; i < start; ++i) {
            int re = s, cnt = 0;
            if (prefsum[start + 1] - prefsum[i] > re) {
                continue;
            }
            re -= prefsum[start + 1] - prefsum[i];
            cnt += start + 1 - i;
            cnt += (re / a[i]);
            answ = max(answ, cnt);
        }
        answ = max(answ, s / a[start]);
        le = start, ri = n;
        while (ri - le > 1) {
           auto mi = le + (ri - le) / 2;
           if (prefsum[mi + 1] - prefsum[start] > s) {
               ri = mi;
           } else {
               le = mi;
           }
        }
        for (int i = start + 1; i < ri; ++i) {
            int re = s, cnt = 0;
            if (prefsum[i + 1] - prefsum[start] > re) {
                continue;
            }
            re -= prefsum[i + 1] - prefsum[start];
            cnt += i + 1 - start;
            cnt += (re / a[i]);
            answ = max(answ, cnt);
        }
    */
        for (int to = 1; to <= 20; ++to) {
            auto it = lower_bound(ixs[to].begin(), ixs[to].end(), start);
            if (it != ixs[to].end()) {
                int i = *it;
                int re = s, cnt = 0;
                if (prefsum[i + 1] - prefsum[start] > re) {
                    continue;
                }
                re -= prefsum[i + 1] - prefsum[start];
                cnt += i + 1 - start;
                cnt += (re / a[i]);
                answ = max(answ, cnt);
            }
            it = lower_bound(ixs2[to].begin(), ixs2[to].end(), -start);
            if (it != ixs2[to].end()) {
                int i = -(*it);
                int re = s, cnt = 0;
                if (prefsum[start + 1] - prefsum[i] > re) {
                    continue;
                }
                re -= prefsum[start + 1] - prefsum[i];
                cnt += start + 1 - i;
                cnt += (re / a[i]);
                answ = max(answ, cnt);
           }
        }
    }
    cout << answ << '\n';
    return 0;
}
