#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <climits>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <string>
#include <queue>
#include <random>

#define int long long

#pragma GCC optimize("03,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using ll = long long;
using ld = long double;
using namespace std;

const ll INF = 1e18;


vector<int> pref;

int get_sum(int l, int r) {
	if (l > r) {
		return 0;
	}
	int ans = pref[r];
	if (l != 0) {
		ans -= pref[l - 1];
	}
	return ans;
}

void solve() {
	int n, m, t;
	cin >> n >> m >> t;
	vector<int> a(n);
	pref.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> b(m);
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		b[i]--;
	}
	pref[0] = a[0];
	for (int i = 1; i < n; i++) {
		pref[i] = pref[i - 1] + a[i];
	}
	int mx = 0;
	vector<vector<int>> pl(n, vector<int>(30));
	vector<vector<int>> pr(n, vector<int>(30));
	vector<int> left(30, -1);
	for (int i = 0; i < n; i++) {
		left[a[i]] = i;
		pl[i] = left;
	}
	vector<int> right(30, INF);
	for (int i = n - 1; i >= 0; i--) {
		right[a[i]] = i;
		pr[i] = right;
	}
	for (auto& p : b) {
		for (int i = 0; i < 30; i++) {
			int l = pl[p][i];
			if (l == -1) continue;
			int d = get_sum(l + 1, p);
			if (t < d) continue;
			mx = max(mx, p - l);
			int rem = t - d;
			mx = max(mx, p - l + (rem / a[l]));
		}
		for (int i = 0; i < 30; i++) {
			int r = pr[p][i];
			if (r == INF) continue;
			int d = get_sum(p, r - 1);
			if (t < d) continue;
			mx = max(mx, r - p);
			int rem = t - d;
			mx = max(mx, r - p + (rem / a[r]));
		}
	}
	cout << mx;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}