const int MAXN = 100001;
int ipta[MAXN], iptb[MAXN];
int dp[2][310];
vector<int> vt[MAXN];
int main()
{
// freopen("in.txt", "r", stdin);
int a, b, all, c, cnt;
while (~RIV(a, b, all, c))
{
int cur = 0;
CLR(dp, INF);
REP(i, MAXN) vt[i].clear();
cnt = (all + c - 1) / c;
FE(i, 1, a) RI(ipta[i]);
FE(i, 1, b)
{
RI(iptb[i]);
vt[iptb[i]].push_back(i);
}
int ans = 0;
FE(i, 1, a)
{
dp[cur][0] = 0;
cur ^= 1;
CLR(dp[cur], INF);
FE(j, 1, cnt)
{
int pre = dp[cur ^ 1][j - 1];
int p = upper_bound(all(vt[ipta[i]]), pre) - vt[ipta[i]].begin();
if (p == vt[ipta[i]].size()) p = INF;
else p = vt[ipta[i]][p];
dp[cur][j] = min(dp[cur ^ 1][j], p);
if (dp[cur ^ 1][j] > p && p + i + j * c <= all)
ans = max(ans, j);
}
}
WI(ans);
}
return 0;
}