#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int MX = 100010;
int n, m, s, e;
int a[MX], b[MX];
int right_a[MX], right_b[MX];
int dp[MX]; //dp[�ő��]: �ŏ��ʒu

int main(){
	cin >> n >> m >> s >> e;
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];

	set<pi> bs;
	map<int, int> pos;
	rep(i, m){
		pos[b[i]] = i;
		bs.insert(mp(b[i], i));
	}
	rep(i, m) right_b[i] = pos[b[i]];
	pos.clear();
	rep(i, n) pos[a[i]] = i;
	rep(i, n) right_a[i] = pos[a[i]];

	int ans = 0;
	int lim = s / e;
	rep(i, lim + 1) dp[i] = inf;
	dp[0] = -1;

	rep(i, n) for(int j = lim; j >= 0; j--) if(dp[j] < inf){

		set<pi>::iterator it = bs.lower_bound(mp(a[i], dp[j] + 1));
		if(it != bs.end() && it->first == a[i]){
			dp[j + 1] = min(dp[j + 1], it->second);

			int cost = n - m - right_a[a[i]] - right_b[b[it->second]] - 2;
			if(cost + (j + 1) * e <= s) ans = max(ans, j + 1);
		}
	}
	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int MX = 100010;
int n, m, s, e;
int a[MX], b[MX];
int dp[MX]; //dp[�ő��]: �ŏ��ʒu

int main(){
	cin >> n >> m >> s >> e;
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];

	set<pi> bs;
	rep(i, m) bs.insert(mp(b[i], i));

	int ans = 0;
	int lim = s / e;
	rep(i, lim + 1) dp[i] = inf;
	dp[0] = -1;

	rep(i, n) for(int j = lim; j >= 0; j--) if(dp[j] < inf){

		set<pi>::iterator it = bs.lower_bound(mp(a[i], dp[j] + 1));
		if(it != bs.end() && it->first == a[i]){
			dp[j + 1] = min(dp[j + 1], it->second);

			int cost = i + it->second + 2;
			if(cost + (j + 1) * e <= s) ans = max(ans, j + 1);
		}
	}
	cout << ans << endl;

	return 0;
}


#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define maxn 100005

int dp[2][maxn];
int X[maxn];
int Y[maxn];
int main()
{
    int n,m,s,e;
    scanf("%d%d%d%d",&n,&m,&s,&e);
    for(int i=0;i<n;i++)   scanf("%d",X+i);
    for(int i=0;i<m;i++)   scanf("%d",Y+i);
    int fin=0;
    int sign=0;
    for(int i = 1; i <= n; ++i)
    {
        int k = i & 1;
        for(int j = 1; j <= m; ++j)
        {
            if(X[i-1] == Y[j-1])
            {
                dp[k][j] = dp[k^1][j-1] + 1;
            }
            else if(dp[k][j-1] > dp[k^1][j])
            {
                dp[k][j] = dp[k][j-1];
            }
            else
            {
                dp[k][j] = dp[k^1][j];
            }
            if(dp[k][j]*e+i+j>s)  break;
            fin=max(fin,dp[k][j]);
        }
        if(fin*e+i>=s)   break;
    }
    cout<<fin<<endl;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <queue>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
using namespace std;

const int N = 100010;
const int INF = 1000000000;
const int B = 29;
const int B1 = 10007;
const long long Mod = 1000000007;

#define PII pair<int,int>
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define LL(x) (x<<1)
#define RR(x) (x<<1|1)
#define MID(a,b) ((a+b)>>1)

set<int> pb[N];
set<int>::iterator it;
int dp[2][350];

int solve(int a[], int n, int b[], int m, int s, int E){
    for(int i=1; i<=m; i++)
        pb[b[i]].insert(i);

    int EN = s/E+10;
    int ans = 0, p = 0;
    for(int i=0; i<EN; i++)
        dp[p][i] = m+1;
    dp[0][0] = 0;
    for(int i=1; i<=n; i++){
        dp[p^1][0] = 0;
        for(int j=1; j<EN; j++){
            dp[p^1][j] = dp[p][j];
            if(dp[p][j-1]<m+1){
                it = pb[a[i]].upper_bound(dp[p][j-1]);
                if(it != pb[a[i]].end()){
                    dp[p^1][j] = min(dp[p^1][j], *it);
                }
            }
            if(dp[p^1][j]<=m){
                if(j*E+i+dp[p^1][j]<=s)
                    ans = max(ans, j);
            }
        }
        p^=1;
    }

    for(int i=1; i<=m; i++)
        pb[b[i]].clear();
    return ans;
}

int a[N], b[N], n, m, s, E;

int main()
{
    scanf("%d%d%d%d", &n, &m, &s, &E);
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
    }
    for(int i=1; i<=m; i++){
        scanf("%d", &b[i]);
    }
    int ans = solve(a, n, b, m, s, E);
    ans = max(ans, solve(b, m, a, n, s, E));
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <queue>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
using namespace std;

const int N = 100010;
const int INF = 1000000000;
const int B = 29;
const int B1 = 10007;
const long long Mod = 1000000007;

#define PII pair<int,int>
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define LL(x) (x<<1)
#define RR(x) (x<<1|1)
#define MID(a,b) ((a+b)>>1)

set<int> pb[N];
set<int>::iterator it;
int dp[2][350];

int solve(int a[], int n, int b[], int m, int s, int E){
    for(int i=1; i<=m; i++)
        pb[b[i]].insert(i);

    int EN = s/E+10;
    int ans = 0, p = 0;
    for(int i=0; i<EN; i++)
        dp[p][i] = m+1;
    dp[0][0] = 0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<EN; j++)
            dp[p^1][j] = m+1;
        dp[p^1][0] = 0;
        for(int j=1; j<EN; j++){
            if(dp[p][j-1]==m+1)
                continue;
            it = pb[a[i]].upper_bound(dp[p][j-1]);
            if(it == pb[a[i]].end())
                continue;
            dp[p^1][j] = min(dp[p^1][j], *it);
            if(dp[p^1][j]<=m){
                if(i<n || dp[p^1][j]<m){
                    if(j*E+i+dp[p^1][j]<=s)
                        ans = max(ans, j);
                }
            }
        }
        p^=1;
    }

    for(int i=1; i<=m; i++)
        pb[b[i]].clear();
    return ans;
}

int a[N], b[N], n, m, s, E;

int main()
{
    scanf("%d%d%d%d", &n, &m, &s, &E);
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
    }
    for(int i=1; i<=m; i++){
        scanf("%d", &b[i]);
    }
    int ans = solve(a, n, b, m, s, E);
    ans = max(ans, solve(b, m, a, n, s, E));
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <queue>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
using namespace std;

const int N = 100010;
const int INF = 1000000000;
const int B = 29;
const int B1 = 10007;
const long long Mod = 1000000007;

#define PII pair<int,int>
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define LL(x) (x<<1)
#define RR(x) (x<<1|1)
#define MID(a,b) ((a+b)>>1)

set<int> pb[N];
set<int>::iterator it;
int dp[2][350];

int solve(int a[], int n, int b[], int m, int s, int E){
    for(int i=1; i<=m; i++)
        pb[b[i]].insert(i);

    int EN = s/E+10;
    int ans = 0, p = 0;
    for(int i=0; i<EN; i++)
        dp[p][i] = m+1;
    dp[0][0] = 0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<EN; j++)
            dp[p^1][j] = dp[p][j];
        dp[p^1][0] = 0;
        for(int j=1; j<EN; j++){
            if(dp[p][j-1]!=m+1){
                it = pb[a[i]].upper_bound(dp[p][j-1]);
                if(it != pb[a[i]].end())
                    dp[p^1][j] = min(dp[p^1][j], *it);
            }
            if(dp[p^1][j]<=m){
                if(i<n || dp[p^1][j]<m){
                    if(j*E+i+dp[p^1][j]<=s)
                        ans = max(ans, j);
                }
            }
        }
        p^=1;
    }

    for(int i=1; i<=m; i++)
        pb[b[i]].clear();
    return ans;
}

int a[N], b[N], n, m, s, E;

int main()
{
    scanf("%d%d%d%d", &n, &m, &s, &E);
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
    }
    for(int i=1; i<=m; i++){
        scanf("%d", &b[i]);
    }
    int ans = solve(a, n, b, m, s, E);
    ans = max(ans, solve(b, m, a, n, s, E));
    cout<<ans<<endl;
    return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <complex>
#include <numeric>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>

using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define FOR(i, a, b) for (int i(a), _b(b); i < _b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, b) for (int i(a), _b(b); i >= _b; --i)
#define FORE(e, v) for (int e = head[v]; e >= 0; e = E[e].next)
#define UN(a) sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define CL(a, v) memset(a, v, sizeof a)
#define pb push_back
#define X first
#define Y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const ll INF_LL = 1000000000000000000LL;
const double pi = 2 * acos(0.0);

template<class T> void smin(T& a, T b) { if (a > b) a = b; }
template<class T> void smax(T& a, T b) { if (a < b) a = b; }
template<class T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template<class T> T sqr(T a) { return a * a; }

template<class T1, class T2>
ostream& operator << (ostream& out, const pair<T1, T2>& p) {
  out << p.X << ',' << p.Y;
  return out;
}
template<class T> void outp(const vector<T>& v) {
  cout << sz(v) << ":";
  REP(i, sz(v)) cout << " " << v[i];
  cout << endl;
}
template<class T> void outp(T* v, int n) {
  cout << n << ":";
  REP(i, n) cout << " " << *v++;
  cout << endl;
}

const int h = 102;
int n, m, k;
int a[h][h];
bool r[h];
vi q;

int main() {
#ifdef LocalHost
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif

  scanf("%d%d%d", &n, &m, &k);
  REP(i, n) REP(j, m) scanf("%d", &a[i][j]);
  int ans = 0;
  REP(i, n-1) {
    int e = 0;
    REP(j, m) if (a[i][j] == a[i+1][j]) ++e;
    if (e != 0 && e != m) ans += min(e, m-e);
  }
  REP(i, n-1) {
    int e = 0;
    REP(j, m) if (a[i][j] == a[i+1][j]) ++e;
    int t = ans - min(e, m-e);
    bool oke = m-e <= k;
    bool okc = e <= k;
    if (oke) {
      if (okc) q.pb(i);
      else r[i] = true;
    } else {
      if (okc) r[i] = false;
      else {
        ans = INF;
        break;
      }
    }
  }
  if (ans != 0 && ans != INF) {
    ans = INF;
    REP(u, 1<<sz(q)) {
      REP(i, sz(q)) r[q[i]] = 1&(u>>i);
      int sum = 0;
      REP(j, m) {
        int s0 = 0, s1 = 0;
        int v = 0;
        REP(i, n) {
          if (v != a[i][j]) ++s0;
          if (!r[i]) v = 1 - v;
        }
        v = 1;
        REP(i, n) {
          if (v != a[i][j]) ++s1;
          if (!r[i]) v = 1 - v;
        }
        sum += min(s0, s1);
      }
      smin(ans, sum);
    }
  }
  printf("%d\n", ans <= k ? ans : -1);

#ifdef LocalHost
  cout << endl << endl << "TIME: " << clock() << endl;
#endif
  return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <complex>
#include <numeric>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>

using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define FOR(i, a, b) for (int i(a), _b(b); i < _b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, b) for (int i(a), _b(b); i >= _b; --i)
#define FORE(e, v) for (int e = head[v]; e >= 0; e = E[e].next)
#define UN(a) sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define CL(a, v) memset(a, v, sizeof a)
#define pb push_back
#define X first
#define Y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const ll INF_LL = 1000000000000000000LL;
const double pi = 2 * acos(0.0);

template<class T> void smin(T& a, T b) { if (a > b) a = b; }
template<class T> void smax(T& a, T b) { if (a < b) a = b; }
template<class T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template<class T> T sqr(T a) { return a * a; }

template<class T1, class T2>
ostream& operator << (ostream& out, const pair<T1, T2>& p) {
  out << p.X << ',' << p.Y;
  return out;
}
template<class T> void outp(const vector<T>& v) {
  cout << sz(v) << ":";
  REP(i, sz(v)) cout << " " << v[i];
  cout << endl;
}
template<class T> void outp(T* v, int n) {
  cout << n << ":";
  REP(i, n) cout << " " << *v++;
  cout << endl;
}

const int h = 100011;
int n, m, s, e;
int a[h], b[h];
vi ub[h];

int find(int v, int r) {
  if (ub[v].empty()) return -1;
  int i = lower_bound(all(ub[v]), r) - ub[v].begin() - 1;
  return i >= 0 ? ub[v][i] : -1;
}

const int K = 303;
int d[K];

int main() {
#ifdef LocalHost
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif

  scanf("%d%d%d%d", &n, &m, &s, &e);
  REP(i, n) scanf("%d", a+i);
  REP(j, m) scanf("%d", b+j);
  REP(j, m) ub[b[j]].pb(j);
  int l = 0, r = s / e + 1;
  while (l + 1 < r) {
    int k = (l + r) / 2;
    int f = s - k * e;
    //printf("%d: %d\n", k, f);
    CL(d, -1);
    int p = 0;
    FORD(i, n-1, 0) {
      d[0] = max(-1, f - i - 1);
      //printf("%d ", d[0]);
      FORD(j, p, 0) smax(d[j+1], find(a[i], d[j]));
      if (d[p+1] != -1) ++p;
      if (p == k) break;
    }
    //printf("\n");
    //outp(d, k+1);
    if (d[k] == -1) r = k;
    else l = k;
  }
  printf("%d\n", l);

#ifdef LocalHost
  cout << endl << endl << "TIME: " << clock() << endl;
#endif
  return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <complex>
#include <numeric>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>

using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define FOR(i, a, b) for (int i(a), _b(b); i < _b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, b) for (int i(a), _b(b); i >= _b; --i)
#define FORE(e, v) for (int e = head[v]; e >= 0; e = E[e].next)
#define UN(a) sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define CL(a, v) memset(a, v, sizeof a)
#define pb push_back
#define X first
#define Y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const ll INF_LL = 1000000000000000000LL;
const double pi = 2 * acos(0.0);

template<class T> void smin(T& a, T b) { if (a > b) a = b; }
template<class T> void smax(T& a, T b) { if (a < b) a = b; }
template<class T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template<class T> T sqr(T a) { return a * a; }

template<class T1, class T2>
ostream& operator << (ostream& out, const pair<T1, T2>& p) {
  out << p.X << ',' << p.Y;
  return out;
}
template<class T> void outp(const vector<T>& v) {
  cout << sz(v) << ":";
  REP(i, sz(v)) cout << " " << v[i];
  cout << endl;
}
template<class T> void outp(T* v, int n) {
  cout << n << ":";
  REP(i, n) cout << " " << *v++;
  cout << endl;
}

const int h = 100011;
int n, m, s, e;
int a[h], b[h];
vi ub[h];

int find(int v, int r) {
  if (ub[v].empty()) return -1;
  int i = lower_bound(all(ub[v]), r) - ub[v].begin() - 1;
  return i >= 0 ? ub[v][i] : -1;
}

const int K = 303;
int d[K], dn[K];

int main() {
#ifdef LocalHost
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif

  scanf("%d%d%d%d", &n, &m, &s, &e);
  REP(i, n) scanf("%d", a+i);
  REP(j, m) scanf("%d", b+j);
  REP(j, m) ub[b[j]].pb(j);
  int l = 0, r = 301;
  while (l + 1 < r) {
    int k = (l + r) / 2;
    int f = s - k * e;
    //printf("%d: %d\n", k, f);
    CL(d, -1);
    FORD(i, n-1, 0) {
      d[0] = max(-1, f - i - 1);
      //printf("%d ", d[0]);
      REP(j, k+1) {
        if (d[j] == -1) break;
        dn[j+1] = find(a[i], d[j]);
        //printf("%d ", dn[j+1]);
      }
      //printf("\n");
      FOR(j, 1, k+1) {
        if (d[j] == -1) {
          d[j] = dn[j];
          break;
        }
        smax(d[j], dn[j]);
      }
    }
    //printf("\n");
    //outp(d, k+1);
    if (d[k] == -1) r = k;
    else l = k;
  }
  printf("%d\n", l);

#ifdef LocalHost
  cout << endl << endl << "TIME: " << clock() << endl;
#endif
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <time.h>
#include <queue>
#include <cctype>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#define Mod 1000000007
#define INT 2147483647
#define pi acos(-1.0)
#define eps 1e-4
#define lll __int64
#define ll long long
using namespace std;
#define N 100007

int dp[N][305];
int a[N],b[N];
vector<int> v[N];

int main()
{
    int n,m,s,e;
    int i,j;
    scanf("%d%d%d%d",&n,&m,&s,&e);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=m;i++)
    {
        scanf("%d",&b[i]);
        v[b[i]].push_back(i);
    }
    int S = s/e;
    for(i=1;i<=n;i++)
    {
        dp[i][0] = -1;
        for(j=1;j<=S;j++)
            dp[i][j] = Mod;
    }
    for(i=1;i<=m;i++)   //a的第一个对应的最小位置
    {
        if(b[i] == a[1])
        {
            dp[1][1] = i;
            break;
        }
    }
    //meiju
    vector<int>::iterator it;
    for(i=2;i<=n;i++)
    {
        for(j=0;j<=S;j++)
        {
            dp[i][j] = min(dp[i][j],dp[i-1][j]);  //当前位置不删
            it = upper_bound(v[a[i]].begin(),v[a[i]].end(),dp[i-1][j]);
            if(it != v[a[i]].end())    //如果能找到，更新最小位置
                dp[i][j+1] = min(dp[i][j+1],*it);
        }
    }
    int res = -Mod;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=S;j++)
        {
            if(i + dp[i][j] + j*e <= s)   //满足能量范围
                res = max(res,j);
        }
    }
    printf("%d\n",res);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <time.h>
#include <queue>
#include <cctype>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#define Mod 1000000007
#define INT 2147483647
#define pi acos(-1.0)
#define eps 1e-4
#define lll __int64
#define ll long long
using namespace std;
#define N 100007

int dp[N][305];
int a[N],b[N];
vector<int> v[N];

int main()
{
    int n,m,s,e;
    int i,j;
    scanf("%d%d%d%d",&n,&m,&s,&e);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=m;i++)
    {
        scanf("%d",&b[i]);
        v[b[i]].push_back(i);
    }
    int S = s/e;
    for(i=1;i<=n;i++)
    {
        dp[i][0] = -1;
        for(j=1;j<=S;j++)
            dp[i][j] = Mod;
    }
    for(i=1;i<=m;i++)   //a的第一个对应的最小位置
    {
        if(b[i] == a[1])
        {
            dp[1][1] = i;
            break;
        }
    }
    //meiju
    vector<int>::iterator it;
    for(i=2;i<=n;i++)
    {
        for(j=1;j<=S;j++)
        {
            dp[i][j] = min(dp[i][j],dp[i-1][j]);  //当前位置不删
            it = lower_bound(v[a[i]].begin(),v[a[i]].end(),dp[i-1][j-1]);
            if(it != v[a[i]].end())    //如果能找到，更新最小位置
                dp[i][j] = min(dp[i][j],*it);
        }
    }
    int res = -Mod;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=S;j++)
        {
            if(i + dp[i][j] + j*e <= s)   //满足能量范围
                res = max(res,j);
        }
    }
    printf("%d\n",res);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <time.h>
#include <queue>
#include <cctype>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#define Mod 1000000007
#define INT 2147483647
#define pi acos(-1.0)
#define eps 1e-4
#define lll __int64
#define ll long long
using namespace std;
#define N 100007

int dp[N][305];
int a[N],b[N];
vector<int> v[N];

int main()
{
    int n,m,s,e;
    int i,j;
    scanf("%d%d%d%d",&n,&m,&s,&e);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=m;i++)
    {
        scanf("%d",&b[i]);
        v[b[i]].push_back(i);
    }
    int S = s/e;
    for(i=1;i<=n;i++)
    {
        dp[i][0] = -1;
        for(j=1;j<=S;j++)
            dp[i][j] = Mod;
    }
    for(i=1;i<=m;i++)   //a的第一个对应的最小位置
    {
        if(b[i] == a[1])
        {
            dp[1][1] = i;
            break;
        }
    }
    //meiju
    vector<int>::iterator it;
    for(i=2;i<=n;i++)
    {
        for(j=1;j<=S;j++)
        {
            dp[i][j] = min(dp[i][j],dp[i-1][j]);  //当前位置不删
            it = upper_bound(v[a[i]].begin(),v[a[i]].end(),dp[i-1][j-1]);
            if(it != v[a[i]].end())    //如果能找到，更新最小位置
                dp[i][j] = min(dp[i][j],*it);
        }
    }
    int res = -Mod;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=S;j++)
        {
            if(i + dp[i][j] + j*e <= s)   //满足能量范围
                res = max(res,j);
        }
    }
    printf("%d\n",res);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;

#define N 100005
int n , m , S , E;
int a[N] , b[N];
int f[N][302] , g[N];
int p[N][302];

//vector<int> C[N];
void work() {
    int i , j , x ;
    scanf("%d%d%d%d",&n,&m,&S,&E);
    for (i = 1 ; i <= n ; ++ i) {
        scanf("%d",&a[i]);
    }
    for (i = 1 ; i <= m ; ++ i) {
        scanf("%d",&b[i]);
        //C[b[i]].push_back(i);
    }
    //f[i][j] , A前i个数，消除j次，B的最小下标
    memset(f , 63 , sizeof(f));
    for (i = 0 ; i <= 300 ; ++ i)
        g[i] = m + 1;
    for (i = 1 ; i <= 300 ; ++ i)
        for (j = 1 ; j <= 100000 ; ++ j)
            p[j][i] = m + 1;
    for (j = m ; j >= 1 ; -- j) {
        p[b[j]][0] = j;
    }
    f[0][0] = 0 , g[0] = 0;
    for (i = 1 ; i <= n ; ++ i) {
        for (j = 300 ; j >= 0 ; -- j) {
            f[i][j] = f[i - 1][j];
            if (j) {
                x = g[j - 1];
                if (j == 1) {
                    ++ j;
                    -- j;
                }
                //while (x <= n && p[j] >= x) {

                //}
                /*for (k = x + 1 ; k <= m ; ++ k)
                    if (b[k] == a[i])
                        break;*/
                //vector<int>::iterator it = upper_bound(C[a[i]].begin() , C[a[i]].end() , x);
                int k = p[a[i]][j - 1];
                if (k != m + 1)
                    f[i][j] = min(f[i][j] , k);
            }
            while (f[i][j] < g[j]) {
                p[b[g[j]]][j] = g[j];
                -- g[j];
            }

        }
    }
    int ans = 0;
    for (i = 0 ; i <= n ; ++ i)
        for (j = 0 ; j <= 300 ; ++ j) {
            if (f[i][j] >= 0x3F3F3F3F) continue;
            if (i + f[i][j] + j * E <= S)
                ans = max(ans , j);
        }
    printf("%d\n" , ans);
}

int main(){
    //freopen("1.txt" , "r" , stdin);
   //puts("100000 100000 300000 1000");
   // for (int i = 1 ; i <= 200000 ; ++ i)
     //   printf("%d " , 1);
//    while (~scanf("%s", s))
        work();
    return 0;
}
/*
100000 100000 300000 1000

*/


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;

#define N 100005
int n , m , T , S , E;
int a[N] , b[N];
int f[N][302] , g[N];
int p[N][302];

void work() {
    int i , j ;
    scanf("%d%d%d%d",&n,&m,&S,&E);
    for (i = 1 ; i <= n ; ++ i) {
        scanf("%d",&a[i]);
    }
    for (i = 1 ; i <= m ; ++ i) {
        scanf("%d",&b[i]);
    }
    T = S / E;
    memset(f , 63 , sizeof(f));
    for (i = 0 ; i <= T ; ++ i)
        g[i] = m + 1;
    for (i = 0 ; i <= T ; ++ i)
        for (j = 1 ; j <= 100000 ; ++ j)
            p[j][i] = m + 1;
    for (j = m ; j >= 1 ; -- j) {
        p[b[j]][0] = j;
    }
    f[0][0] = 0 , g[0] = 0;
    for (i = 1 ; i <= n ; ++ i) {
        for (j = T ; j >= 0 ; -- j) {
            f[i][j] = f[i - 1][j];
            if (j) {
                int k = p[a[i]][j - 1];
                if (k <= m)
                    f[i][j] = min(f[i][j] , k);
            }
            while (f[i][j] < g[j]) {
                p[b[g[j]]][j] = g[j];
                -- g[j];
            }
        }
    }
    int ans = 0;
    for (i = 0 ; i <= n ; ++ i)
        for (j = 0 ; j <= T ; ++ j) {
            if (i + f[i][j] + j * E <= S)
                ans = max(ans , j);
        }
    printf("%d\n" , ans);
}

int main(){
    work();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;

#define N 100005
int n , m , S , E;
int a[N] , b[N];
int f[N][302] , g[N] , p[N];

void work() {
    int i , j , k , x , y;
    scanf("%d%d%d%d",&n,&m,&S,&E);
    for (i = 1 ; i <= n ; ++ i) {
        scanf("%d",&a[i]);
    }
    for (i = 1 ; i <= m ; ++ i) {
        scanf("%d",&b[i]);
    }
    //f[i][j] , A前i个数，消除j次，B的最小下标
    memset(f , 63 , sizeof(f));
    for (i = 0 ; i <= 300 ; ++ i)
        g[i] = 1 << 30 , p[i] = n + 1;
    f[0][0] = 0 , g[0] = 0;
    for (i = 1 ; i <= n ; ++ i) {
        for (j = 300 ; j >= 0 ; -- j) {
            f[i][j] = f[i - 1][j];
            if (j) {
                x = g[j - 1];
                //while (x <= n && p[j] >= x) {

                //}
                for (k = x + 1 ; k <= m ; ++ k)
                    if (b[k] == a[i])
                        break;
                if (k <= m)
                    f[i][j] = min(f[i][j] , k);
            }
            g[j] = min(g[j] , f[i][j]);
        }
    }
    int ans = 0;
    for (i = 0 ; i <= n ; ++ i)
        for (j = 0 ; j <= 300 ; ++ j) {
            if (f[i][j] >= 0x3F3F3F3F) continue;
            if (i + f[i][j] + j * E <= S)
                ans = max(ans , j);
        }
    printf("%d\n" , ans);
}

int main(){
   // freopen("1.txt" , "r" , stdin);
//    while (~scanf("%s", s))
        work();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;

#define N 100005
int n , m , S , E;
int a[N] , b[N];
int f[N][302] , g[N] , p[N];
vector<int> C[N];
void work() {
    int i , j , x ;
    scanf("%d%d%d%d",&n,&m,&S,&E);
    for (i = 1 ; i <= n ; ++ i) {
        scanf("%d",&a[i]);
    }
    for (i = 1 ; i <= m ; ++ i) {
        scanf("%d",&b[i]);
        C[b[i]].push_back(i);
    }
    //f[i][j] , A前i个数，消除j次，B的最小下标
    memset(f , 63 , sizeof(f));
    for (i = 0 ; i <= 300 ; ++ i)
        g[i] = 1 << 30 , p[i] = m + 1;
    f[0][0] = 0 , g[0] = 0;
    for (i = 1 ; i <= n ; ++ i) {
        for (j = 300 ; j >= 0 ; -- j) {
            f[i][j] = f[i - 1][j];
            if (j) {
                x = g[j - 1];
                //while (x <= n && p[j] >= x) {

                //}
                /*for (k = x + 1 ; k <= m ; ++ k)
                    if (b[k] == a[i])
                        break;*/
                vector<int>::iterator it = upper_bound(C[a[i]].begin() , C[a[i]].end() , x);
                if (it != C[a[i]].end())
                    f[i][j] = min(f[i][j] , *it);
            }
            g[j] = min(g[j] , f[i][j]);
        }
    }
    int ans = 0;
    for (i = 0 ; i <= n ; ++ i)
        for (j = 0 ; j <= 300 ; ++ j) {
            if (f[i][j] >= 0x3F3F3F3F) continue;
            if (i + f[i][j] + j * E <= S)
                ans = max(ans , j);
        }
    printf("%d\n" , ans);
}

int main(){
    work();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;

#define N 100005
int n , m , S , E;
int a[N] , b[N];
int f[N][302] , g[N];
int p[N][302];

//vector<int> C[N];
void work() {
    int i , j , x ;
    scanf("%d%d%d%d",&n,&m,&S,&E);
    for (i = 1 ; i <= n ; ++ i) {
        scanf("%d",&a[i]);
    }
    for (i = 1 ; i <= m ; ++ i) {
        scanf("%d",&b[i]);
        //C[b[i]].push_back(i);
    }
    //f[i][j] , A前i个数，消除j次，B的最小下标
    memset(f , 63 , sizeof(f));
    for (i = 0 ; i <= 300 ; ++ i)
        g[i] = m + 1;
    for (i = 0 ; i <= 300 ; ++ i)
        for (j = 1 ; j <= 100000 ; ++ j)
            p[j][i] = m + 1;
    for (j = m ; j >= 1 ; -- j) {
        p[b[j]][0] = j;
    }
    f[0][0] = 0 , g[0] = 0;
    for (i = 1 ; i <= n ; ++ i) {
        for (j = 300 ; j >= 0 ; -- j) {
            f[i][j] = f[i - 1][j];
            if (j) {
                x = g[j - 1];
                //while (x <= n && p[j] >= x) {

                //}
                /*for (k = x + 1 ; k <= m ; ++ k)
                    if (b[k] == a[i])
                        break;*/
                //vector<int>::iterator it = upper_bound(C[a[i]].begin() , C[a[i]].end() , x);
                int k = p[a[i]][j - 1];
                if (k <= m)
                    f[i][j] = min(f[i][j] , k);
            }
            while (f[i][j] < g[j]) {
                p[b[g[j]]][j] = g[j];
                -- g[j];
            }

        }
    }
    int ans = 0;
    for (i = 0 ; i <= n ; ++ i)
        for (j = 0 ; j <= 300 ; ++ j) {
            if (f[i][j] >= 0x3F3F3F3F) continue;
            if (i + f[i][j] + j * E <= S)
                ans = max(ans , j);
        }
    printf("%d\n" , ans);
}

int main(){
   // freopen("1.txt" , "r" , stdin);
   //puts("100000 100000 300000 1000");
   // for (int i = 1 ; i <= 200000 ; ++ i)
     //   printf("%d " , 1);
//    while (~scanf("%s", s))
        work();
    return 0;
}
/*
100000 100000 300000 1000

*/


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DFOR(i,a,b) for(int i=a;i>=b;i--)
#define mp(x,y) make_pair((int)x,(int)y)
#define zs(x) (int)x.size()
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; FOR(i,a,b) cout << x[i] << ' '; cout << endl;}
#define ll long long
#define DEBUG 0
#define nmax 100111
#define mmax 100000
#define oo 10000000
int n,m,s,e;
int a[nmax];
int b[nmax];
int dmax;
int f[nmax];
vector<int> v[nmax];
int ans;

void readInput(){
    scanf("%d%d%d%d",&n,&m,&s,&e);
    FOR(i,1,n) scanf("%d",a+i);
    FOR(i,1,m) scanf("%d",b+i);
    if (DEBUG==1){
        PR(a,1,n);
        PR(b,1,m);
    }
}

void init(){
    dmax= s/e;
    FOR(i,1,dmax)f[i]=oo; f[0]=0;
    FOR(i,1,m) v[b[i]].push_back(i);
    FOR(i,1,mmax) if (zs(v[i])>0)sort(v[i].begin(),v[i].end());
    ans=0;
}

inline int find_pos(vector<int> v, int index){
    int res=0;
    int ss= zs(v);
    if (ss==0) return 0;
    if (v[ss-1]<=index) return 0;
    int f=0;
    int l=ss-1;
    while (f<l){
        int tmp =(f+l)/2;
        if (v[tmp]<=index) f=tmp+1; else  l= tmp;
    }
    res=v[f];
    return res;
}

void solve(){
    FOR(i,1,n){
        if (DEBUG==1){
            BUG(i);
        }
        int value=a[i];

        DFOR(j,dmax-1,0){

            int index= f[j];
            if (index==oo) continue;
            int t= find_pos(v[value],index);
            if (t==0) continue;
            if (i+t+(j+1)*e<=s){
                ans= max(ans,j+1);
            }
            f[j+1]=min(f[j+1],t);
        }
    }
}

void writeOutput(){
    printf("%d",ans);
}

int main(){
    if (DEBUG==1){
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    }
    readInput();
    init();
    solve();
    writeOutput();
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DFOR(i,a,b) for(int i=a;i>=b;i--)
#define mp(x,y) make_pair((int)x,(int)y)
#define sz(x) (int)x.size()
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; FOR(i,a,b) cout << x[i] << ' '; cout << endl;}
#define ll long long
#define DEBUG 0
#define nmax 100111
#define mmax 100000
#define oo 10000000
int n,m,s,e;
int a[nmax];
int b[nmax];
int dmax;
int f[nmax];
vector<int> v[nmax];
int ans;

void readInput(){
    scanf("%d%d%d%d",&n,&m,&s,&e);
    FOR(i,1,n) scanf("%d",a+i);
    FOR(i,1,m) scanf("%d",b+i);
    if (DEBUG==1){
        //PR(a,1,n);
        //PR(b,1,m);
    }
}

void init(){
    dmax= s/e;
    FOR(i,1,dmax)f[i]=oo; f[0]=0;
    FOR(i,1,m) v[b[i]].push_back(i);
    FOR(i,1,mmax) if (sz(v[i])>0)sort(v[i].begin(),v[i].end());
    ans=0;
}

inline int find_pos(vector<int> v, int index){
    int res=0;
    int ss= sz(v);
    if (ss==0) return 0;
    if (v[ss-1]<=index) return 0;
    int f=0;
    int l=ss-1;
    while (f<l){
        int tmp =(f+l)>>1;
        if (v[tmp]<=index) f=tmp+1; else  l= tmp;
    }
    res=v[f];
    return res;
}

void solve(){
    FOR(i,1,n){
        if (DEBUG==1){
            //BUG(i);
        }
        int value=a[i];
        int t=oo;
        if (i+ans*e>s) break;
        DFOR(j,dmax-1,0)if (f[j]<oo){
            int index= f[j];
            t= find_pos(v[value],index);
            //int pos= upper_bound(all(v[value]),index)-v[value].begin();
            if (t!=0){
                if (i+t+(j+1)*e<=s){
                    ans= max(ans,j+1);
                }
                f[j+1]=min(f[j+1],t);
            }

        }
    }
}

void writeOutput(){
    printf("%d",ans);
}

int main(){
    if (DEBUG==2){
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    }
    readInput();
    if (DEBUG==1) {
        cout<<"Init"<<endl;
    }
    init();
    if(DEBUG==1){
        cout<<"Solve"<<endl;
    }
    solve();
    writeOutput();
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DFOR(i,a,b) for(int i=a;i>=b;i--)
#define mp(x,y) make_pair((int)x,(int)y)
#define sz(x) (int)x.size()
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; FOR(i,a,b) cout << x[i] << ' '; cout << endl;}
#define ll long long
#define DEBUG 0
#define nmax 100111
#define mmax 100000
#define oo 10000000
int n,m,s,e;
int a[nmax];
int b[nmax];
int dmax;
int f[nmax];
vector<int> v[nmax];
int ans;

void readInput(){
    scanf("%d%d%d%d",&n,&m,&s,&e);
    FOR(i,1,n) scanf("%d",a+i);
    FOR(i,1,m) scanf("%d",b+i);
    if (DEBUG==1){
        //PR(a,1,n);
        //PR(b,1,m);
    }
}

void init(){
    dmax= s/e;
    FOR(i,1,dmax)f[i]=oo; f[0]=0;
    FOR(i,1,m) v[b[i]].push_back(i);
    FOR(i,1,mmax) if (sz(v[i])>0)sort(v[i].begin(),v[i].end());
    ans=0;
}

inline int find_pos(vector<int> v, int index,int l=oo){
    int res=0;
    int ss= sz(v);
    if (ss==0) return 0;
    if (v[ss-1]<=index) return 0;
    int f=0;
    if (l>=ss) l=ss-1;
    while (f<l){
        int tmp =(f+l)>>1;
        if (v[tmp]<=index) f=tmp+1; else  l= tmp;
    }
    res=v[f];
    return res;
}

void solve(){
    FOR(i,1,n){
        if (DEBUG==1){
            //BUG(i);
        }
        int value=a[i];
        int t=oo;
        if (i+ans*e>s) break;
        DFOR(j,dmax-1,0)if (f[j]<oo){
            int index= f[j];
            t= find_pos(v[value],index,t);
            //int pos= upper_bound(all(v[value]),index)-v[value].begin();
            if (t!=0){
                if (i+t+(j+1)*e<=s){
                    ans= max(ans,j+1);
                }
                f[j+1]=min(f[j+1],t);
            }

        }
    }
}

void writeOutput(){
    printf("%d",ans);
}

int main(){
    if (DEBUG==2){
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    }
    readInput();
    if (DEBUG==1) {
        cout<<"Init"<<endl;
    }
    init();
    if(DEBUG==1){
        cout<<"Solve"<<endl;
    }
    solve();
    writeOutput();
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DFOR(i,a,b) for(int i=a;i>=b;i--)
#define mp(x,y) make_pair((int)x,(int)y)
#define zs(x) (int)x.size()
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; FOR(i,a,b) cout << x[i] << ' '; cout << endl;}
#define ll long long
#define DEBUG 0
#define nmax 100111
#define mmax 100000
#define oo 10000000
int n,m,s,e;
int a[nmax];
int b[nmax];
int dmax;
int f[nmax];
vector<int> v[nmax];
int ans;

void readInput(){
    scanf("%d%d%d%d",&n,&m,&s,&e);
    FOR(i,1,n) scanf("%d",a+i);
    FOR(i,1,m) scanf("%d",b+i);
    if (DEBUG==1){
        PR(a,1,n);
        PR(b,1,m);
    }
}

void init(){
    dmax= s/e;
    FOR(i,1,dmax)f[i]=oo; f[0]=0;
    FOR(i,1,m) v[b[i]].push_back(i);
    FOR(i,1,mmax) if (zs(v[i])>0)sort(v[i].begin(),v[i].end());
    ans=0;
}

int find_pos(vector<int> v, int index){
    int res=0;
    int ss= zs(v);
    if (ss==0) return 0;
    if (v[ss-1]<=index) return 0;
    int f=0;
    int l=ss-1;
    while (f<l){
        int tmp =(f+l)/2;
        if (v[tmp]<=index) f=tmp+1; else  l= tmp;
    }
    res=v[f];
    if(DEBUG==1){
        printf("Find pos: %4d\n",res);
    }
    return res;
}

void solve(){
    FOR(i,1,n){
        if (DEBUG==1){
            BUG(i);
        }
        int value=a[i];

        DFOR(j,dmax-1,0){

            int index= f[j];
            if (index==oo) continue;
            //cout<<1111<<endl;
            if (DEBUG==1){
                printf("Tim vector: %4d || Vi tri: %4d\n",value,index);
            }
            int t= find_pos(v[value],index);
            if (t==0) continue;
            if (i+t+(j+1)*e<=s){
                ans= max(ans,j+1);
            }
            f[j+1]=min(f[j+1],t);
             if (DEBUG==1){
                BUG(j);
                BUG(t);
                BUG(ans);
                BUG(f[j+1]);
            }
        }
    }
}

void writeOutput(){
    printf("%d",ans);
}

int main(){
    if (DEBUG==1){
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    }
    readInput();
    init();
    solve();
    writeOutput();
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DFOR(i,a,b) for(int i=a;i>=b;i--)
#define mp(x,y) make_pair((int)x,(int)y)
#define zs(x) (int)x.size()
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; FOR(i,a,b) cout << x[i] << ' '; cout << endl;}
#define ll long long
#define DEBUG 0
#define nmax 100111
#define mmax 100000
#define oo 1000000
int n,m,s,e;
int a[nmax];
int b[nmax];
int dmax;
int f[nmax];
vector<int> v[nmax];
int ans;

void readInput(){
    scanf("%d%d%d%d",&n,&m,&s,&e);
    FOR(i,1,n) scanf("%d",a+i);
    FOR(i,1,m) scanf("%d",b+i);
    if (DEBUG==1){
        PR(a,1,n);
        PR(b,1,m);
    }
}

void init(){
    dmax= s/e;
    FOR(i,1,dmax)f[i]=oo; f[0]=0;
    FOR(i,1,m) v[b[i]].push_back(i);
    FOR(i,1,mmax) if (zs(v[i])>0)sort(v[i].begin(),v[i].end());
    ans=0;
}

int find_pos(vector<int> v, int index){
    int res=0;
    int ss= zs(v);
    if (v[ss-1]<=index) return 0;
    int f=0;
    int l=ss-1;
    while (f<l){
        int tmp =(f+l)/2;
        if (v[tmp]<=index) f=tmp+1; else  l= tmp;
    }
    res=v[f];
    if(DEBUG==1){
        printf("Find pos: %4d\n",res);
    }
    return res;
}

void solve(){
    FOR(i,1,n){
        if (DEBUG==1){
            BUG(i);
        }
        int value=a[i];

        DFOR(j,dmax-1,0){

            int index= f[j];
            if (index==oo) continue;
            //cout<<1111<<endl;
            if (DEBUG==1){
                printf("Tim vector: %4d || Vi tri: %4d\n",value,index);
            }
            int t= find_pos(v[value],index);
            if (t==0) continue;
            if (i+t+(j+1)*e<=s){
                ans= max(ans,j+1);
            }
            f[j+1]=min(f[j+1],t);
             if (DEBUG==1){
                BUG(j);
                BUG(t);
                BUG(ans);
                BUG(f[j+1]);
            }
        }
    }
}

void writeOutput(){
    printf("%d",ans);
}

int main(){
    if (DEBUG==2){
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    }
    readInput();
    init();
    solve();
    writeOutput();
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DFOR(i,a,b) for(int i=a;i>=b;i--)
#define mp(x,y) make_pair((int)x,(int)y)
#define sz(x) (int)x.size()
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; FOR(i,a,b) cout << x[i] << ' '; cout << endl;}
#define ll long long
#define DEBUG 0
#define nmax 100111
#define mmax 100000
#define oo 10000000
int n,m,s,e;
int a[nmax];
int b[nmax];
int dmax;
int f[nmax];
vector<int> v[nmax];
int ans;

void readInput(){
    scanf("%d%d%d%d",&n,&m,&s,&e);
    FOR(i,1,n) scanf("%d",a+i);
    FOR(i,1,m) scanf("%d",b+i);
    if (DEBUG==1){
        //PR(a,1,n);
        //PR(b,1,m);
    }
}

void init(){
    dmax= s/e;
    FOR(i,1,dmax)f[i]=oo; f[0]=0;
    FOR(i,1,m) v[b[i]].push_back(i);
    FOR(i,1,mmax) if (sz(v[i])>0)sort(v[i].begin(),v[i].end());
    ans=0;
}

inline int find_pos(vector<int> v, int index,int ss){
    if (v[ss-1]<=index) return 0;
    int f=0;
    int l=ss-1;
    while (f<l){
        int tmp =(f+l)>>1;
        if (v[tmp]<=index) f=tmp+1; else  l= tmp;
    }
    return v[f];
}

void solve(){
    FOR(i,1,n){

        int value=a[i];
        int t=oo;
        int ss= sz(v[value]);
        if (i+ans+(ans+1)*e>=s) break;
        if (ss==0) continue;
        DFOR(j,ans,0)if (f[j]<oo){
            int index= f[j];
            t= find_pos(v[value],index,ss);
            //int pos= upper_bound(all(v[value]),index)-v[value].begin();
            if (t!=0){
                if ((i+t+(j+1)*e<=s) && ((j+1)>ans)){
                    ans=j+1;
                    if (i+ans+ans*e>=s) break;
                }
                if(f[j+1]>t) f[j+1]=t;
            }

        }
    }
}

void writeOutput(){
    printf("%d",ans);
}

int main(){
    if (DEBUG==1){
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    }
    readInput();
    init();
    solve();
    writeOutput();
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DFOR(i,a,b) for(int i=a;i>=b;i--)
#define mp(x,y) make_pair((int)x,(int)y)
#define zs(x) (int)x.size()
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; FOR(i,a,b) cout << x[i] << ' '; cout << endl;}
#define ll long long
#define DEBUG 0
#define nmax 100111
#define mmax 100000
#define oo 10000000
int n,m,s,e;
int a[nmax];
int b[nmax];
int dmax;
int f[nmax];
vector<int> v[nmax];
int ans;

void readInput(){
    scanf("%d%d%d%d",&n,&m,&s,&e);
    FOR(i,1,n) scanf("%d",a+i);
    FOR(i,1,m) scanf("%d",b+i);
    if (DEBUG==1){
        PR(a,1,n);
        PR(b,1,m);
    }
}

void init(){
    dmax= s/e;
    FOR(i,1,dmax)f[i]=oo; f[0]=0;
    FOR(i,1,m) v[b[i]].push_back(i);
    FOR(i,1,mmax) if (zs(v[i])>0)sort(v[i].begin(),v[i].end());
    ans=0;
}

inline int find_pos(vector<int> v, int index){
    int res=0;
    int ss= zs(v);
    if (ss==0) return 0;
    if (v[ss-1]<=index) return 0;
    int f=0;
    int l=ss-1;
    while (f<l){
        int tmp =(f+l)/2;
        if (v[tmp]<=index) f=tmp+1; else  l= tmp;
    }
    res=v[f];
    return res;
}

void solve(){
    FOR(i,1,n){
        int value=a[i];
        DFOR(j,dmax-1,0)if (f[j]<oo){
            int index= f[j];
            int t= find_pos(v[value],index);
            if (t!=0){
                if (i+t+(j+1)*e<=s){
                    ans= max(ans,j+1);
                }
                f[j+1]=min(f[j+1],t);
            }

        }
    }
}

void writeOutput(){
    printf("%d",ans);
}

int main(){
    if (DEBUG==2){
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    }
    readInput();
    init();
    solve();
    writeOutput();
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#define INF 1000000000

using namespace std;

int n,m,e,c;
int sol,cost;
int p1[100005];
int p2[100005];
int curr[100005];
int next[100005];
vector < int > v[100005];

int find(int x,int minp){
    int lo=0,hi=v[x].size()-1,mi;
    while(lo<hi){
        mi=(lo+hi)>>1;
        if (v[x][mi]<=minp) lo=mi+1;
        else hi=mi;
    }
//    printf ("%d %d %d -> %d\n",x,minp,lo,v[x][lo]);
    return v[x][lo];
}

int main(){
    scanf ("%d%d%d%d",&n,&m,&e,&c);
    for (int i=1;i<=n;++i)
        scanf ("%d",p1+i);
    for (int i=1;i<=m;++i)
        scanf ("%d",p2+i);
    for (int i=1;i<=m;++i)
        v[p2[i]].push_back(i);
    for (int i=0;i<100000;++i)
        v[i].push_back(INF);
/*    for (int i=1;i<10;++i){
        for (int j=0;j<v[i].size();++j)
            printf ("%d ",v[i][j]);
        printf("\n");
    }/**/
    for(int i=1;i<=n;++i){
        if(curr[i-1]) curr[i]=min(curr[i-1],find(p1[i],0));
        else curr[i]=find(p1[i],0);
    }
    for (int i=1;i<=n;++i)
        next[i]=curr[i];

    while(e>c && curr[n]!=INF){
        e-=c;
        sol++;
        for (int i=1;i<=n;++i)
            curr[i]=next[i];
/*        printf("............................\n");
        for (int i=1;i<=n;++i)
            printf ("%d ",curr[i]);
        printf ("\n");*/
        for (int i=1;i<=n;++i){
//            printf ("%d %d %d\n",p1[i],curr[i-1],next[i-1]);
            if((curr[i-1] != INF) && curr[i-1]) next[i]=min(next[i-1], find(p1[i],curr[i-1]));
            else next[i]=INF;
        }
/*        for (int i=1;i<=n;++i)
            printf ("%d ",curr[i]);
        printf ("\n");*/
    }
    cost=INF;
    for (int i=1;i<=n;++i)
        cost=min(cost,i+curr[i]);
    sol=max(0,sol-(e<cost));
    printf ("%d ",sol);

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#define INF 1000000000

using namespace std;

int n,m,e,c;
int sol,cost;
int p1[100005];
int p2[100005];
int curr[100005];
int next[100005];
vector < int > v[300005];

int find(int x,int minp){
    int lo=0,hi=v[x].size()-1,mi;
    while(lo<hi){
        mi=(lo+hi)>>1;
        if (v[x][mi]<=minp) lo=mi+1;
        else hi=mi;
    }
//    printf ("%d %d %d -> %d\n",x,minp,lo,v[x][lo]);
    return v[x][lo];
}

int main(){
    scanf ("%d%d%d%d",&n,&m,&e,&c);
    for (int i=1;i<=n;++i)
        scanf ("%d",p1+i);
    for (int i=1;i<=m;++i)
        scanf ("%d",p2+i);
    for (int i=1;i<=m;++i)
        v[p2[i]].push_back(i);
    for (int i=0;i<300000;++i)
        v[i].push_back(INF);
/*    for (int i=1;i<10;++i){
        for (int j=0;j<v[i].size();++j)
            printf ("%d ",v[i][j]);
        printf("\n");
    }/**/
    for(int i=1;i<=n;++i){
        if(curr[i-1]) curr[i]=min(curr[i-1],find(p1[i],0));
        else curr[i]=find(p1[i],0);
    }
    for (int i=1;i<=n;++i)
        next[i]=curr[i];

    while(e>c+cost && next[n]!=INF){
        e-=c;
        sol++;
        for (int i=1;i<=n;++i)
            curr[i]=next[i];
/*        printf("............................\n");
        for (int i=1;i<=n;++i)
            printf ("%d ",curr[i]);
        printf ("\n");*/
        for (int i=1;i<=n;++i){
//            printf ("%d %d %d\n",p1[i],curr[i-1],next[i-1]);
            if((curr[i-1] != INF) && curr[i-1]) next[i]=min(next[i-1], find(p1[i],curr[i-1]));
            else next[i]=INF;
        }
    cost=INF;
    for (int i=1;i<=n;++i)
        cost=min(cost,i+curr[i]);
    }
//    sol=max(0,sol-(e<cost));
    printf ("%d ",sol);

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#define INF 1000000000

using namespace std;

int n,m,e,c;
int sol,cost;
int p1[100005];
int p2[100005];
int curr[100005];
int next[100005];
vector < int > v[100005];

int find(int x,int minp){
    int lo=0,hi=v[x].size(),mi;
    while(lo<hi){
        mi=(lo+hi)>>1;
        if (v[x][mi]<=minp) lo=mi+1;
        else hi=mi;
    }
//    printf ("%d %d %d -> %d\n",x,minp,lo,v[x][lo]);
    return v[x][lo];
}

int main(){
    scanf ("%d%d%d%d",&n,&m,&e,&c);
    for (int i=1;i<=n;++i)
        scanf ("%d",p1+i);
    for (int i=1;i<=m;++i)
        scanf ("%d",p2+i);
    for (int i=1;i<=m;++i)
        v[p2[i]].push_back(i);
    for (int i=0;i<100000;++i)
        v[i].push_back(INF);
/*    for (int i=1;i<10;++i){
        for (int j=0;j<v[i].size();++j)
            printf ("%d ",v[i][j]);
        printf("\n");
    }/**/
    for(int i=1;i<=n;++i){
        if(curr[i-1]) curr[i]=min(curr[i-1],find(p1[i],0));
        else curr[i]=find(p1[i],0);
    }
    for (int i=1;i<=n;++i)
        next[i]=curr[i];
//    printf("\n");
    while(e>c+cost && curr[n]!=INF){
        e-=c;
        sol++;
        for (int i=1;i<=n;++i)
            curr[i]=next[i];
/*        printf("............................\n");
        for (int i=1;i<=n;++i)
            printf ("%d ",curr[i]);
        printf ("\n");*/
        for (int i=1;i<=n;++i){
//            printf ("%d %d %d\n",p1[i],curr[i-1],next[i-1]);
            if((curr[i-1] != INF) && curr[i-1]) next[i]=min(next[i-1], find(p1[i],curr[i-1]));
            else next[i]=INF;
        }
/*        for (int i=1;i<=n;++i)
            printf ("%d ",curr[i]);
        printf ("\n");*/
    }
    cost=INF;
    for (int i=1;i<=n;++i)
        cost=min(cost,i+curr[i]);
    printf ("%d ",sol-(e<cost));

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#define INF 1000000000

using namespace std;

int n,m,e,c;
int sol,cost;
int p1[100005];
int p2[100005];
int curr[100005];
int next[100005];
vector < int > v[300005];

int find(int x,int minp){
    int lo=0,hi=v[x].size()-1,mi;
    while(lo<hi){
        mi=(lo+hi)>>1;
        if (v[x][mi]<=minp) lo=mi+1;
        else hi=mi;
    }
//    printf ("%d %d %d -> %d\n",x,minp,lo,v[x][lo]);
    return v[x][lo];
}

int main(){
    scanf ("%d%d%d%d",&n,&m,&e,&c);
    for (int i=1;i<=n;++i)
        scanf ("%d",p1+i);
    for (int i=1;i<=m;++i)
        scanf ("%d",p2+i);
    for (int i=1;i<=m;++i)
        v[p2[i]].push_back(i);
    for (int i=0;i<300000;++i)
        v[i].push_back(INF);
/*    for (int i=1;i<10;++i){
        for (int j=0;j<v[i].size();++j)
            printf ("%d ",v[i][j]);
        printf("\n");
    }/**/
    for(int i=1;i<=n;++i){
        if(curr[i-1]) curr[i]=min(curr[i-1],find(p1[i],0));
        else curr[i]=find(p1[i],0);
    }
    for (int i=1;i<=n;++i)
        next[i]=curr[i];

    while(e>c && curr[n]!=INF){
        e-=c;
        sol++;
        for (int i=1;i<=n;++i)
            curr[i]=next[i];
/*        printf("............................\n");
        for (int i=1;i<=n;++i)
            printf ("%d ",curr[i]);
        printf ("\n");*/
        for (int i=1;i<=n;++i){
//            printf ("%d %d %d\n",p1[i],curr[i-1],next[i-1]);
            if((curr[i-1] != INF) && curr[i-1]) next[i]=min(next[i-1], find(p1[i],curr[i-1]));
            else next[i]=INF;
        }
/*        for (int i=1;i<=n;++i)
            printf ("%d ",curr[i]);
        printf ("\n");*/
    }
    cost=INF;
    for (int i=1;i<=n;++i)
        cost=min(cost,i+curr[i]);
    sol=max(0,sol-(e<cost));
    printf ("%d ",sol);

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#define INF 1000000000

using namespace std;

int n,m,e,c;
int sol,cost;
int p1[100005];
int p2[100005];
int curr[100005];
int next[100005];
vector < int > v[300005];

int find(int x,int minp){
    int lo=0,hi=v[x].size()-1,mi;
    while(lo<hi){
        mi=(lo+hi)>>1;
        if (v[x][mi]<=minp) lo=mi+1;
        else hi=mi;
    }
//    printf ("%d %d %d -> %d\n",x,minp,lo,v[x][lo]);
    return v[x][lo];
}

int main(){
    scanf ("%d%d%d%d",&n,&m,&e,&c);
    for (int i=1;i<=n;++i)
        scanf ("%d",p1+i);
    for (int i=1;i<=m;++i)
        scanf ("%d",p2+i);
    for (int i=1;i<=m;++i)
        v[p2[i]].push_back(i);
    for (int i=0;i<300000;++i)
        v[i].push_back(INF);
/*    for (int i=1;i<10;++i){
        for (int j=0;j<v[i].size();++j)
            printf ("%d ",v[i][j]);
        printf("\n");
    }/**/
    for(int i=1;i<=n;++i){
        if(curr[i-1]) curr[i]=min(curr[i-1],find(p1[i],0));
        else curr[i]=find(p1[i],0);
    }
    for (int i=1;i<=n;++i)
        next[i]=curr[i];

    while(e>c+cost && next[n]!=INF){
        e-=c;
        sol++;
        for (int i=1;i<=n;++i)
            curr[i]=next[i];
/*        printf("............................\n");
        for (int i=1;i<=n;++i)
            printf ("%d ",curr[i]);
        printf ("\n");*/
        for (int i=1;i<=n;++i){
//            printf ("%d %d %d\n",p1[i],curr[i-1],next[i-1]);
            if((curr[i-1] != INF) && curr[i-1]) next[i]=min(next[i-1], find(p1[i],curr[i-1]));
            else next[i]=INF;
        }
        cost=INF;
        for (int i=1;i<=n;++i)
            cost=min(cost,i+curr[i]);
    }
    sol=max(0,sol-(e<cost));
    printf ("%d ",sol);

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#define INF 1000000000

using namespace std;

int n,m,e,c;
int sol,cost;
int p1[100005];
int p2[100005];
int curr[100005];
int next[100005];
vector < int > v[100005];

int find(int x,int minp){
    int lo=0,hi=v[x].size(),mi;
    while(lo<hi){
        mi=(lo+hi)>>1;
        if (v[x][mi]<=minp) lo=mi+1;
        else hi=mi;
    }
//    printf ("%d %d %d -> %d\n",x,minp,lo,v[x][lo]);
    return v[x][lo];
}

int main(){
    scanf ("%d%d%d%d",&n,&m,&e,&c);
    for (int i=1;i<=n;++i)
        scanf ("%d",p1+i);
    for (int i=1;i<=m;++i)
        scanf ("%d",p2+i);
    for (int i=1;i<=m;++i)
        v[p2[i]].push_back(i);
    for (int i=0;i<100000;++i)
        v[i].push_back(INF);
/*    for (int i=1;i<10;++i){
        for (int j=0;j<v[i].size();++j)
            printf ("%d ",v[i][j]);
        printf("\n");
    }/**/
    for(int i=1;i<=n;++i){
        if(curr[i-1]) curr[i]=min(curr[i-1],find(p1[i],0));
        else curr[i]=find(p1[i],0);
    }
    for (int i=1;i<=n;++i)
        next[i]=curr[i];
//    printf("\n");
    while(e>c+cost && curr[n]!=INF){
        e-=c;
        sol++;
        for (int i=1;i<=n;++i)
            curr[i]=next[i];
/*        printf("............................\n");
        for (int i=1;i<=n;++i)
            printf ("%d ",curr[i]);
        printf ("\n");*/
        for (int i=1;i<=n;++i){
//            printf ("%d %d %d\n",p1[i],curr[i-1],next[i-1]);
            if((curr[i-1] != INF) && curr[i-1]) next[i]=min(next[i-1], find(p1[i],curr[i-1]));
            else next[i]=INF;
        }
/*        for (int i=1;i<=n;++i)
            printf ("%d ",curr[i]);
        printf ("\n");*/
    }
    cost=INF;
    for (int i=1;i<=n;++i)
        cost=min(cost,i+curr[i]);
    sol=max(0,sol-(e<cost));
    printf ("%d ",sol);

    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
int n, m, k,a[100010], b[100010];
int dp[100010][310];
int s,e;
vector<int>pos[100010];
int early[100010];
#define top 100010
int main() {
    //freopen("input.txt", "r", stdin);
    int Cas = 0;
    //scanf("%d", &Cas);

    while(scanf("%d%d%d%d", &n, &m, &s, &e) != EOF) {
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
        }

        for(int i = 1; i <= m; i++) {
            scanf("%d", &b[i]);
            pos[b[i]].push_back(i);
        }

        for(int i = 0; i < 100010; i++) {
            pos[i].push_back(top);
        }

        memset(early, -1, sizeof(early));

        for(int i = 0; i < top; i++) {
            for(int j = 0; j <= 300; j++) {
                dp[i][j] = 1000000;
            }
        }

        dp[0][0] = 0;
        early[0] = 0;
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            for(int j = 0; j <= 300; j++) {
                dp[i][j] = dp[i - 1][j];
                if(j >= 1 && early[j - 1] != -1) {
                    int tmp = upper_bound(pos[a[i]].begin(), pos[a[i]].end(), early[j - 1]) - pos[a[i]].begin();
                    if(pos[a[i]][tmp] == top) {

                    } else{
                        dp[i][j] = min(dp[i][j], pos[a[i]][tmp]);
                        if(i + dp[i][j] + e * j<= s) {
                            ans = max(j, ans);
                        }
                    }
                }
                if(early[j] == -1 || early[j] > dp[i][j]) {
                    early[j] = dp[i][j];
                }
            }
        }
        printf("%d\n", ans);

    }
    return 0;
}


#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define maxn 100005

int dp[2][maxn];
int X[maxn];
int Y[maxn];
int main()
{
    int n,m,s,e;
    scanf("%d%d%d%d",&n,&m,&s,&e);
    for(int i=0;i<n;i++)   scanf("%d",X+i);
    for(int i=0;i<m;i++)   scanf("%d",Y+i);
    int fin=0;
    int sign=0;
    for(int i = 1; i <= n; ++i)
    {
        int k = i & 1;
        for(int j = 1; j <= m; ++j)
        {
            if(X[i-1] == Y[j-1])
            {
                dp[k][j] = dp[k^1][j-1] + 1;
            }
            else if(dp[k][j-1] > dp[k^1][j])
            {
                dp[k][j] = dp[k][j-1];
            }
            else
            {
                dp[k][j] = dp[k^1][j];
            }
            if(dp[k][j]*e+i+j>s)  break;
            fin=max(fin,dp[k][j]);
        }
        if(fin*e+i>=s)   break;
    }
    cout<<fin<<endl;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
int n, m, k,a[100010], b[100010];
int dp[100010][310];
int s,e;
vector<int>pos[100010];
int early[100010];
#define top 100010
int main() {
    //freopen("input.txt", "r", stdin);
    int Cas = 0;
    //scanf("%d", &Cas);

    while(scanf("%d%d%d%d", &n, &m, &s, &e) != EOF) {
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
        }

        for(int i = 1; i <= m; i++) {
            scanf("%d", &b[i]);
            pos[b[i]].push_back(i);
        }

        for(int i = 0; i < 100010; i++) {
            pos[i].push_back(top);
        }

        memset(early, -1, sizeof(early));

        for(int i = 0; i < top; i++) {
            for(int j = 0; j <= 300; j++) {
                dp[i][j] = 1000000;
            }
        }

        dp[0][0] = 0;
        early[0] = 0;
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            for(int j = 300; j >= 0; j--) {
                dp[i][j] = dp[i - 1][j];
                if(j >= 1 && early[j - 1] != -1) {
                    int tmp = upper_bound(pos[a[i]].begin(), pos[a[i]].end(), early[j - 1]) - pos[a[i]].begin();
                    if(pos[a[i]][tmp] == top) {

                    } else{
                        dp[i][j] = min(dp[i][j], pos[a[i]][tmp]);
                        if(i + dp[i][j] + e * j<= s) {
                            ans = max(j, ans);
                        }
                    }
                }
                if(dp[i][j] <= m)
                if(early[j] == -1 || early[j] > dp[i][j]) {
                    early[j] = dp[i][j];
                }
            }
        }
        printf("%d\n", ans);

    }
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
using namespace std;
const int INF = 0x7f7f7f7f,MAXV = 100010,MAXN = 100010,MAXD = 350;
typedef set<int> si;
typedef si::iterator itor;
si idx[MAXV];
int dp[MAXD];
int a[MAXN],b[MAXN];
int main()
{
 /*#ifndef ONLINE_JUNDGE
 freopen("codeforces243C.in","r",stdin);freopen("codeforces243C.out","w",stdout);
 #endif*/
 int n,m,s,e;scanf("%d%d%d%d",&n,&m,&s,&e);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&a[i]);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&b[i]);
 for(int i = 1;i<=n;i++)
	 idx[a[i]].insert(i);
  int ans = 0;
  dp[0] = -1;
  for(int i = 1;i<333;i++)
	   dp[i] = INF;
  for(int i = 1;i<n;i++){
   for(int d = 305;d>=0;d--){
     itor it = idx[b[i]].upper_bound(dp[d]);
	 if(it != idx[b[i]].end() )
	 {
		 dp[d+1] = min(dp[d+1],*it);
		 if((d+1)*e+i+(*it) <=s)
			  ans = max(ans,d+1);
	 }
	}
  }
  printf("%d\n",ans);
  /*#ifndef ONLINE_JUNDGE
  fclose(stdin);fclose(stdout);
 #endif*/
 return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
using namespace std;
const int INF = 0x7f7f7f7f,MAXV = 100010,MAXN = 100010,MAXD = 333;
typedef set<int> si;
typedef si::iterator itor;
si idx[MAXV];
int dp[MAXD];
int a[MAXN],b[MAXN];
int main()
{
 #ifndef ONLINE_JUNDGE
 freopen("codeforces243C.in","r",stdin);freopen("codeforces243C.out","w",stdout);
 #endif
 int n,m,s,e;scanf("%d%d%d%d",&n,&m,&s,&e);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&a[i]);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&b[i]);
 for(int i = 1;i<=n;i++)
	 idx[a[i]].insert(i);
  int ans = 0;
  dp[0] = -1;
  for(int i = 1;i<333;i++)
	   dp[i] = INF;
  for(int i = 1;i<n;i++){
   for(int d = 305;d>=0;d--){
     itor it = idx[b[i]].upper_bound(dp[d]);
	 if(it != idx[b[i]].end() )
	 {
		 dp[d+1] = min(dp[d+1],*it);
		 if((d+1)*e+i+(*it) <=s)
			  ans = max(ans,d+1);
	 }
	}
  }
  printf("%d\n",ans);
  #ifndef ONLINE_JUNDGE
  fclose(stdin);fclose(stdout);
 #endif
 return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
#include <cassert>
using namespace std;
const int INF = 0x7f7f7f7f,MAXV = 100010,MAXN = 100010,MAXD = 350;
typedef set<int> si;
typedef si::iterator itor;
si idx[MAXV];
int dp[MAXD];
int a[MAXN],b[MAXN];
int main()
{
 /*#ifndef ONLINE_JUNDGE
 freopen("codeforces243C.in","r",stdin);freopen("codeforces243C.out","w",stdout);
 #endif*/
 int n,m,s,e;scanf("%d%d%d%d",&n,&m,&s,&e);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&a[i]);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&b[i]);
 for(int i = 1;i<=n;i++)
	 idx[a[i]].insert(i);
  int ans = 0;
  dp[0] = -1;
  for(int i = 1;i<333;i++)
	   dp[i] = INF;
  for(int i = 1;i<=m;i++){
   for(int d = 305;d>=0;d--){
     itor it = idx[b[i]].upper_bound(dp[d]);
	 if(it != idx[b[i]].end() )
	 {
		 dp[d+1] = min(dp[d+1],*it);
		 if((d+1)*e+i+(*it) <=s)
			  ans = max(ans,d+1);
	 }
	}
  }
  printf("%d\n",ans);
  /*#ifndef ONLINE_JUNDGE
  fclose(stdin);fclose(stdout);
 #endif*/
 return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
#include <cassert>
using namespace std;
const int INF = 0x7f7f7f7f,MAXV = 100010,MAXN = 100010,MAXD = 350;
typedef set<int> si;
typedef si::iterator itor;
si idx[MAXV];
int dp[MAXD];
int a[MAXN],b[MAXN];
int main()
{
 /*#ifndef ONLINE_JUNDGE
 freopen("codeforces243C.in","r",stdin);freopen("codeforces243C.out","w",stdout);
 #endif*/
 int n,m,s,e;scanf("%d%d%d%d",&n,&m,&s,&e);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&a[i]);
 for(int i = 1;i<=m;i++)
	  scanf("%d",&b[i]);
 for(int i = 1;i<=n;i++)
	 idx[a[i]].insert(i);
  int ans = 0;
  dp[0] = -1;
  for(int i = 1;i<333;i++)
	   dp[i] = INF;
  for(int i = 1;i<=m;i++){
   for(int d = 305;d>=0;d--){
     itor it = idx[b[i]].upper_bound(dp[d]);
	 if(it != idx[b[i]].end() )
	 {
		 dp[d+1] = min(dp[d+1],*it);
		 if((d+1)*e+i+(*it) <=s)
			  ans = max(ans,d+1);
	 }
	}
  }
  printf("%d\n",ans);
  /*#ifndef ONLINE_JUNDGE
  fclose(stdin);fclose(stdout);
 #endif*/
 return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
#include <cassert>
using namespace std;
const int INF = 0x7f7f7f7f,MAXV = 100010,MAXN = 100010,MAXD = 350;
typedef set<int> si;
typedef si::iterator itor;
si idx[MAXV];
int dp[MAXD];
int a[MAXN],b[MAXN];
int main()
{
 #ifndef ONLINE_JUNDGE
 freopen("codeforces243C.in","r",stdin);freopen("codeforces243C.out","w",stdout);
 #endif
 int n,m,s,e;scanf("%d%d%d%d",&n,&m,&s,&e);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&a[i]);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&b[i]);
 for(int i = 1;i<=n;i++)
	 idx[a[i]].insert(i);
  int ans = 0;
  dp[0] = -1;
  for(int i = 1;i<333;i++)
	   dp[i] = INF;
  for(int i = 1;i<=m;i++){
   for(int d = 305;d>=0;d--){
     itor it = idx[b[i]].upper_bound(dp[d]);
	 if(it != idx[b[i]].end() )
	 {
		 dp[d+1] = min(dp[d+1],*it);
		 if((d+1)*e+i+(*it) <=s)
			  ans = max(ans,d+1);
	 }
	}
  }
  printf("%d\n",ans);
  #ifndef ONLINE_JUNDGE
  fclose(stdin);fclose(stdout);
 #endif
 return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
using namespace std;
const int INF = 0x7f7f7f7f,MAXV = 100010,MAXN = 100010,MAXD = 350;
typedef set<int> si;
typedef si::iterator itor;
si idx[MAXV];
int dp[MAXD];
int a[MAXN],b[MAXN];
int main()
{
 #ifndef ONLINE_JUNDGE
 freopen("codeforces243C.in","r",stdin);freopen("codeforces243C.out","w",stdout);
 #endif
 int n,m,s,e;scanf("%d%d%d%d",&n,&m,&s,&e);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&a[i]);
 for(int i = 1;i<=n;i++)
	  scanf("%d",&b[i]);
 for(int i = 1;i<=n;i++)
	 idx[a[i]].insert(i);
  int ans = 0;
  dp[0] = -1;
  for(int i = 1;i<333;i++)
	   dp[i] = INF;
  for(int i = 1;i<n;i++){
   for(int d = 305;d>=0;d--){
     itor it = idx[b[i]].upper_bound(dp[d]);
	 if(it != idx[b[i]].end() )
	 {
		 dp[d+1] = min(dp[d+1],*it);
		 if((d+1)*e+i+(*it) <=s)
			  ans = max(ans,d+1);
	 }
	}
  }
  printf("%d\n",ans);
  #ifndef ONLINE_JUNDGE
  fclose(stdin);fclose(stdout);
 #endif
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long N=1e5+5;
long long n,m,s,e,a[N],dp[N][350],ans,x;
vector<long long>q[N];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m>>s>>e;
    for(long long i=1;i<=n;i++){
        cin>>a[i];
    }
    for(long long i=1;i<=n;i++){
        cin>>x;
        q[x].push_back(i);
    }
    for(long long i=0;i<=n;i++){
        for(long long j=0;j<=300;j++){
            dp[i][j]=2e9;
        }
    }
    dp[0][0]=0;
    for(long long j=0;j<=300;j++){
        for(long long i=0;i<n;i++){
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            vector<long long>::iterator it=lower_bound(q[a[i+1]].begin(),q[a[i+1]].end(),dp[i][j]+1);
            if(it==q[a[i+1]].end()){
                continue;
            }
            dp[i+1][j+1]=min(dp[i+1][j+1],*it);
        }
    }
    for(long long i=0;i<=n;i++){
        for(long long j=1;j<=300;j++){
            if(i+j*e+dp[i][j]<=s){
                ans=max(ans,j);
            }
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
const long long N=1e5+5;
long long n,m,s,e,k,a[N],dp[N][350],ans,x;
vector<long long>q[N];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m>>s>>e;
    for(long long i=1;i<=n;i++){
        cin>>a[i];
    }
    for(long long i=1;i<=m;i++){
        cin>>x;
        q[x].push_back(i);
    }
    for(long long i=0;i<=n+2;i++){
        for(long long j=0;j<=300;j++){
            dp[i][j]=2e9;
        }
    }
    dp[0][0]=0;
    for(long long j=0;j<=300;j++){
        for(long long i=0;i<n;i++){
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            vector<long long>::iterator it=lower_bound(q[a[i+1]].begin(),q[a[i+1]].end(),dp[i][j]+1);
            if(it==q[a[i+1]].end()){
                continue;
            }
            dp[i+1][j+1]=min(dp[i+1][j+1],*it);
        }
    }
    for(long long i=0;i<=n;i++){
        for(long long j=1;j<=300;j++){
            if(i+j*e+dp[i][j]<=s){
                ans=max(ans,j);
            }
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

#define MAXL 200001
int a[MAXL], b[MAXL];

vector<int> v[MAXL];
int dp[MAXL][301];

int main()
{
    int n, m, s, e;
    scanf("%d%d%d%d", &n, &m, &s, &e);

    for (int ni = 1; ni <= n; ni++) {
        scanf("%d", &a[ni]);
        v[a[ni] ].push_back(ni);
    }

    for (int mi = 1; mi <= m; mi++)
        scanf("%d", &b[mi]);

    int c = s/e;

    for (int ci = 1; ci <= c; ci++)
        dp[0][ci] = n+1;

    for (int mi = 1; mi <= m; mi++)
        for (int ci = 1; ci <= c; ci++) {
            auto it = upper_bound(v[b[mi] ].begin(), v[b[mi] ].end(), dp[mi-1][ci-1]);
            if (it != v[b[mi] ].end()) {
                dp[mi][ci] = *it;
            } else {
                dp[mi][ci] = n+1;
            }
        }

    int ans = 0;

    for (int ci = 1; ci <= c; ci++) {
        int need = s+1;

        for (int mi = 1; mi <= m; mi++) {
            if (dp[mi][ci] == n+1) continue;
            need = min(need, mi+dp[mi][ci]);
        }

        if (need+e*ci <= s) {
            ans = ci;
        } else {
            break;
        }
    }

    printf("%d\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define MAXL 200001
int a[MAXL], b[MAXL];

vector<int> v[MAXL];
int dp[MAXL][301];

int main()
{
    int n, m, s, e;
    scanf("%d%d%d%d", &n, &m, &s, &e);

    for (int ni = 1; ni <= n; ni++) {
        scanf("%d", &a[ni]);
        v[a[ni] ].push_back(ni);
    }

    for (int mi = 1; mi <= m; mi++)
        scanf("%d", &b[mi]);

    int c = s/e;

    for (int ci = 1; ci <= c; ci++)
        dp[0][ci] = n+1;

    for (int ci = 1; ci <= c; ci++)
        for (int mi = 1; mi <= m; mi++)
        {
            auto it = upper_bound(v[b[mi] ].begin(), v[b[mi] ].end(), dp[mi-1][ci-1]);
            if (it != v[b[mi] ].end()) {
                dp[mi][ci] = *it;
            } else {
                dp[mi][ci] = n+1;
            }

            dp[mi][ci] = min(dp[mi][ci], dp[mi-1][ci]);
        }

    int ans = 0;

    for (int ci = 1; ci <= c; ci++) {
        int need = s+1;

        for (int mi = 1; mi <= m; mi++) {
            if (dp[mi][ci] == n+1) continue;
            need = min(need, mi+dp[mi][ci]);
        }

        if (need+e*ci <= s) {
            ans = ci;
        } else {
            break;
        }
    }

    printf("%d\n", ans);
}


#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______
 * |\  \|\  \  |\  ___ \  |\  ___ \
 * \ \  \/  /|_\ \   __/| \ \   __/|
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 100010;
int dp[500][mxN];
const int INF = mxN*10;

vector<int> inds[mxN];
int A[mxN];
int B[mxN];

int bt(int cnt,int mxInd) {
	if(cnt == 0) {
		return -1;
	}
	if(mxInd+1 < cnt) {
		return INF;
	}
	int & ref = dp[cnt][mxInd];
	if(ref != -1)
		return ref;
	ref = bt(cnt,mxInd-1);
	int last = bt(cnt-1,mxInd-1);
	int it = upper_bound(inds[A[mxInd]].begin(),inds[A[mxInd]].end(),last) - inds[A[mxInd]].begin();
	if(it < (int)inds[A[mxInd]].size())
		ref = min(ref,inds[A[mxInd]][it]);
	return ref;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int N,M,s,e;
	cin>>N>>M>>s>>e;
	for(int i = 0;i < N;i++) {
		cin>>A[i];
	}
	for(int i = 0;i < M;i++) {
		cin>>B[i];
		inds[B[i]].push_back(i);
	}
	memset(dp,-1,sizeof dp);
	int res = 0;
	for(int i = 0;i < N;i++) {
		for(int j = 0,c = 0;c <= s;c += e,j++) {
			int to = bt(j,i);
//			cerr<<j<<' '<<i<<' '<<to<<'\n';
			if(to > M)
				continue;
			if(to + i + 2 + c > s)
				continue;
			res = max(res,j);
		}
	}
	cout<<res<<'\n';
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
#define debug(x) cerr << #x << " = " << x << "\n";
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, m, s, e, o, z = 0, a[100005] = {}, d[302][100005] = {};
    vector<int> b[100005] = {};
    cin >> n >> m >> s >> e;
    fr1(n) cin >> a[i];
    fr1(m) cin >> o, b[o].push_back(i);
    fr1(100000) b[i].push_back(100003);
    fr1(300) {
        int m = 1000005;
        if (i == 1) m = 0;
        for (int j = 1; j <= n; j++) {
            if (m >= b[a[j]].back()) d[i][j] = 1000005;
            else d[i][j] = *upper_bound(b[a[j]].begin(), b[a[j]].end(), m);
            m = min(m, d[i - 1][j]);
        }
        //for (int j = 1; j <= n; j++) cout << d[i][j] << ' '; cout << '\n';
        for (int j = 1; j <= n; j++) if (i * e + j + d[i][j] <= s) z = i;
    }
    cout << z;
}


#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
#define debug(x) cerr << #x << " = " << x << "\n";
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, m, s, e, o, z = 0, a[100005] = {}, d[302][100005] = {};
    vector<int> b[100005] = {};
    cin >> n >> m >> s >> e;
    fr1(n) cin >> a[i];
    fr1(m) cin >> o, b[o].push_back(i);
    fr1(100000) b[i].push_back(100003);
    fr1(300) {
        int m = 100005;
        if (i == 1) m = 0;
        for (int j = 1; j <= n; j++) {
            if (m >= b[a[j]].back()) d[i][j] = 100005;
            else d[i][j] = *upper_bound(b[a[j]].begin(), b[a[j]].end(), m);
            m = min(m, d[i - 1][j]);
        }
        //for (int j = 1; j <= n; j++) cout << d[i][j] << ' '; cout << '\n';
        for (int j = 1; j <= n; j++) if (i * e + j + d[i][j] <= s) z = i;
    }
    cout << z;
}


#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
#define debug(x) cerr << #x << " = " << x << "\n";
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, m, s, e, o, z = 0, a[100005] = {}, d[302][100005] = {};
    vector<int> b[100005] = {};
    cin >> n >> m >> s >> e;
    fr1(n) cin >> a[i];
    fr1(m) cin >> o, b[o].push_back(i);
    fr1(300) {
        int m = 100005;
        for (int j = 1; j <= n; j++) {
            m = min(m, d[i - 1][j]);
            if (m >= b[a[j]].back()) d[i][j] = 100005;
            else d[i][j] = *upper_bound(b[a[j]].begin(), b[a[j]].end(), m);
        }
        //for (int j = 1; j <= n; j++) cout << d[i][j] << ' '; cout << '\n';
        for (int j = 1; j <= n; j++) if (i * e + j + d[i][j] <= s) z = i;
    }
    cout << z;
}


#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
#define debug(x) cerr << #x << " = " << x << "\n";
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, m, s, e, o, z = 0, a[100005] = {}, d[302][100005] = {};
    vector<int> b[100005] = {};
    cin >> n >> m >> s >> e;
    fr1(n) cin >> a[i];
    fr1(m) cin >> o, b[o].push_back(i);
    fr1(100000) b[i].push_back(100003);
    fr1(300) {
        int m = 100005;
        for (int j = 1; j <= n; j++) {
            m = min(m, d[i - 1][j]);
            if (m >= b[a[j]].back()) d[i][j] = 100005;
            else d[i][j] = *upper_bound(b[a[j]].begin(), b[a[j]].end(), m);
        }
        //for (int j = 1; j <= n; j++) cout << d[i][j] << ' '; cout << '\n';
        for (int j = 1; j <= n; j++) if (i * e + j + d[i][j] <= s) z = i;
    }
    cout << z;
}


#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
#define debug(x) cerr << #x << " = " << x << "\n";
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, m, s, e, o, z = 0, a[100005] = {}, d[302][100005] = {};
    vector<int> b[100005] = {};
    cin >> n >> m >> s >> e;
    fr1(n) cin >> a[i];
    fr1(m) cin >> o, b[o].push_back(i);
    fr1(100000) b[i].push_back(100003);
    fr1(300) {
        int m = 1000005;
        for (int j = 1; j <= n; j++) {
            if (m >= b[a[j]].back()) d[i][j] = 1000005;
            else d[i][j] = *upper_bound(b[a[j]].begin(), b[a[j]].end(), m);
            m = min(m, d[i - 1][j]);
        }
        //for (int j = 1; j <= n; j++) cout << d[i][j] << ' '; cout << '\n';
        for (int j = 1; j <= n; j++) if (i * e + j + d[i][j] <= s) z = i;
    }
    cout << z;
}


#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
#define debug(x) cerr << #x << " = " << x << "\n";
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, m, s, e, o, z = 0, a[100005] = {}, d[302][100005] = {};
    vector<int> b[100005] = {};
    cin >> n >> m >> s >> e;
    fr1(n) cin >> a[i];
    fr1(m) cin >> o, b[o].push_back(i);
    fr1(100000) b[i].push_back(1000006);
    fr1(300) {
        int m = 1000006;
        if (i == 1) m = 0;
        for (int j = 1; j <= n; j++) {
            if (m >= b[a[j]].back()) d[i][j] = 1000006;
            else d[i][j] = *upper_bound(b[a[j]].begin(), b[a[j]].end(), m);
            m = min(m, d[i - 1][j]);
        }
        //for (int j = 1; j <= n; j++) cout << d[i][j] << ' '; cout << '\n';
        for (int j = 1; j <= n; j++) if (i * e + j + d[i][j] <= s) z = i;
    }
    cout << z;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define sc scanf
#define pr printf
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const int N = 100100;

using namespace std;

int n;
int m;
int s;
int e;
int a[N];
int b[N];
int d[N][330];
vector < int > v[N];

int main()
{
    //fin("input.txt");
    //fout("output.txt");
    ios_base::sync_with_stdio(0);
    cin >> n >> m >> s >> e;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= m; i++){
        cin >> b[i];
        v[b[i]].push_back(i);
    }
    for(int i = 1; i < N; i++){
        v[i].push_back(m + 1);
        for(int j = 1; j <= 300; j++)
            d[i][j] = m + 1;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        int h = 0;
        for(int j = 0; j <= 300; j++){
            d[i + 1][j] = min(d[i + 1][j], d[i][j]);
            while(h + 1 < v[a[i]].size() && v[a[i]][h] <= d[i][j])
                h++;
            d[i + 1][j + 1] = min(d[i + 1][j + 1], v[a[i]][h]);
            if(v[a[i]][h] <= m && (j + 1) * e + i + v[a[i]][h] <= s)
                ans = max(ans, j + 1);
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int N=100005,inf=0x3f3f3f3f;
int n,m,up,cost;
int a[N],b[N];
int dp[305][N];//dp[i,j]表示长度为i的公共子序列,a串匹配到j时b的最小位置
vector<int>Pos[N];
#define PB push_back
int main()
{
    freopen("codeforces425C_data.in","r",stdin);
    int i,j,ans=0;
    cin >> n >> m >> up >> cost;
    for(i=1;i<=n;i++) cin >> a[i];
    for(i=1;i<=m;i++)
    {
        cin >> b[i]; Pos[b[i]].PB(i);
    }
    for(i=1;i<=n;i++) Pos[a[i]].PB(inf);
    for(i=1;i<=up/cost;i++)
    {
        dp[i][0]=inf;
        for(j=1;j<=n;j++)
        {
            dp[i][j]=min(inf,dp[i][j-1]);
            int oo=lower_bound(Pos[a[j]].begin(),Pos[a[j]].end(),min(dp[i-1][j-1]+1,inf))-Pos[a[j]].begin();
            if(oo>m) continue;
            dp[i][j]=min(dp[i][j],Pos[a[j]][oo]);
            if(i*cost+dp[i][j]+j<=up) ans=i;
        }
    }
    cout << ans <<endl;
    return 0;
}


/*
题意：两数列a[],b[],进行若干轮操作，每次操作花费e，
将a的一个前缀和b的一个前缀（两前缀的最后一个数字必须相同）删除，并得到虚拟1元，
最后的一次操作是将剩下的a[],b[]全部清空，花费是之前把a[],b[]删除的总数字个数，使得虚拟ans元变为真实ans元。
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0; bool f=0; char ch=' ';
    while(!isdigit(ch))    {f|=(ch=='-'); ch=getchar();}
    while(isdigit(ch)) {s=(s<<3)+(s<<1)+(ch^48); ch=getchar();}
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0) {putchar('-'); x=-x;}
    if(x<10) {putchar(x+'0'); return;}
    write(x/10); putchar((x%10)+'0');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=100005,inf=0x3f3f3f3f;
int n,m,up,cost;
int a[N],b[N];
int dp[305][N];//dp[i,j]表示长度为i的公共子序列,a串匹配到j时b的最小位置
vector<int>Pos[N];
#define PB push_back
int main()
{
    freopen("codeforces425C_data.in","r",stdin);
    int i,j,ans=0;
    R(n); R(m); R(up); R(cost);
    for(i=1;i<=n;i++) R(a[i]);
    for(i=1;i<=m;i++)
    {
        R(b[i]); Pos[b[i]].PB(i);
    }
    for(i=1;i<=n;i++) Pos[a[i]].PB(inf);
    for(i=1;i<=up/cost;i++)
    {
        dp[i][0]=inf;
        for(j=1;j<=n;j++)
        {
            dp[i][j]=min(inf,dp[i][j-1]);
            int oo=lower_bound(Pos[a[j]].begin(),Pos[a[j]].end(),min(dp[i-1][j-1]+1,inf))-Pos[a[j]].begin();
            if(oo>m) continue;
            dp[i][j]=min(dp[i][j],Pos[a[j]][oo]);
            if(i*cost+dp[i][j]+j<=up) ans=i;
        }
    }
    Wl(ans);
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define mid ((l+r)>>1)
using namespace std;
const int maxn =100005;
int a[maxn];
int b[maxn];
vector<int>vv[maxn];
int dp[305][maxn];
int minn[305][maxn];
int main()
{
    int n,m,s,e;
    cin >> n >> m >> s >> e;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    for(int i=1;i<=m;i++){
        cin >> b[i];
        vv[b[i]].push_back(i);
    }
    memset(minn,0,sizeof minn);
    for(int i=1;i<=300;i++){
        for(int j=0;j<=n;j++){
            minn[i][j]=0x3f3f3f3f;
        }
    }
    memset(minn,0,sizeof(minn));
    for(int i=1;i<=300;i++)
        for(int j=0;j<=n;j++)
            minn[i][j]=0x3f3f3f3f;
    int output = 0 ;
    for(int i=1;i<=300;i++){
        for(int j=1;j<=n;j++){
            int pre = minn[i-1][j-1];
            minn[i][j]=minn[i][j-1];
            int ans = -1;
            int l = 0 ;
            int r = vv[a[j]].size()-1;
            while(r-l>=0){
                if(vv[a[j]][mid]>pre)
                {
                    ans = vv[a[j]][mid];
                    r= mid-1;
                }
                else
                    l = mid+1;
            }
            if(ans==-1) continue;
            if(i*e+j+ans<=s) output = i;
            minn[i][j] = min(minn[i][j-1],ans);
        }
    }
    cout << output << endl;
    int ans = 0 ;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mid ((l+r)>>1)
const int maxn =100005;
int seg[4*maxn];
void build(int i,int l,int r){
        seg[i]=0;
    if(l==r)
        return ;
    build(i<<1,l,mid);
    build(i<<1|1,mid+1,r);
}
void update(int i,int l,int r,int pos,int val){
    if(l==r){
        seg[i]=val;
        return ;
    }
    if(mid>=pos)
        update(i<<1,l,mid,pos,val);
    else
        update(i<<1|1,mid+1,r,pos,val);
    seg[i]=max(seg[i<<1],seg[i<<1|1]);
}
int query(int i,int l,int r,int L,int R){
    if(L<=l&&R>=r){
        return seg[i];
    }
    int ret = 0 ;
    if(mid>=L)
        ret = max(ret,query(i<<1,l,mid,L,R));
    if(mid<R)
        ret = max(ret,query(i<<1|1,mid+1,r,L,R));
    return ret;
}
int a[maxn];
int b[maxn];
map<int,int>mm;
int main()
{
    int n,m,s,e;
    cin >> n >> m >> s >> e;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    for(int i=1;i<=m;i++){
        cin >> b[i];
        mm[b[i]]=i;
    }
    int ans = 0 ;
    for(int i=1;i<=n;i++){
        int num = mm[a[i]];
        if(num==0) continue;
        int qry = query(1,1,n,1,num);
        //cout <<qry+1 << " \n"[i==n];
        if(i+num+(qry+1)*e<=s)
            ans = qry+1;
        update(1,1,n,num,qry+1);
    }
    cout << ans << endl;
    return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
const int N=100050;
const int S=317;
const int inf=1e9+7;
int a[N],b[N],Min[N][S];
vector<int> pos[N];
int min(int a, int b){ return a>b?b:a;}
int max(int a, int b){ return a>b?a:b;}
int main()
{
	int s,e,n,m,i,j;
	scanf("%i %i %i %i",&n,&m,&s,&e);
	for(i=1;i<=n;i++) scanf("%i",&a[i]);
	for(i=1;i<=m;i++) scanf("%i",&b[i]),pos[b[i]].pb(i);
	for(i=1;i<S;i++) Min[0][i]=inf;
	int sol=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<S;j++)
		{
			Min[i][j]=Min[i-1][j];
			int id=upper_bound(pos[a[i]].begin(),pos[a[i]].end(),Min[i-1][j-1])-pos[a[i]].begin();
			if(id!=pos[a[i]].size())
			{
				Min[i][j]=min(Min[i][j],pos[a[i]][id]);
			}
			if(e*j+i+Min[i][j]<=s) sol=max(sol,j);
			//if(j<8) printf("%i ",Min[i][j]);
		}
		//printf("\n");
	}
	printf("%i\n",sol);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v[100010];
int n,m,s,ans,e,b,i,j,a[100010],dyn[410][100010];
int main()
{
    cin>>n>>m>>s>>e;
    for(i=1;i<=n;i++)cin>>a[i];
    for(i=1;i<=m;i++)
    {
        cin>>b;
        v[b].push_back(i);
    }
    memset(dyn,127,sizeof(dyn));
    for(i=0;i<=n;i++)dyn[0][i]=0;
    for(j=0;j<=s/e;j++)
        for(i=0;i<=n;i++)
        {
            dyn[j][i+1]=min(dyn[j][i+1],dyn[j][i]);
            auto t=upper_bound(v[a[i+1]].begin(),v[a[i+1]].end(),dyn[j][i]);
            if(t!=v[a[i+1]].end())
                dyn[j+1][i+1]=min(dyn[j+1][i+1],*t);
            if(j*e+i+dyn[j][i]<=s)
                ans=max(ans,j);
        }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 123456;
const int M = 345;

int n, m, S, E;
int a[N], b[N], f[N][M];
vector<int> e[N];

int bs(vector<int>& v, int p) {
	int q = lower_bound(v.begin(), v.end(), p) - v.begin();
	if (q == v.size()) return m;
	else return q;
}

int main() {
	cin >> n >> m >> S >> E;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < m; ++i) { cin >> b[i]; e[b[i]].push_back(i); }
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= S / E; ++j) {
			f[i][j] = m + 1;
			if (j == 0) f[i][j] = 0;
			if (i - 1 >= 0) f[i][j] = min(f[i][j], f[i - 1][j]);
			if (i - 1 >= 0 && j - 1 >= 0) f[i][j] = min(f[i][j], bs(e[a[i]], f[i - 1][j - 1]) + 1);
			if (f[i][j] != m + 1 && j * E + (i + 1) + f[i][j] <= S) ans = max(ans, j);
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 123456;
const int M = 345;

int n, m, S, E;
int a[N], b[N], f[N][M];
vector<int> e[N];

int bs(vector<int>& v, int p) {
	int q = lower_bound(v.begin(), v.end(), p) - v.begin();
	if (q == v.size()) return m;
	else return q;
}

int main() {
	cin >> n >> m >> S >> E;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < m; ++i) { cin >> b[i]; e[b[i]].push_back(i); }
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= S / E; ++j) {
			f[i][j] = m + 1;
			if (j == 0) f[i][j] = 0;
			if (i == 0 && j == 1) f[i][j] = min(f[i][j], bs(e[a[i]], 0) + 1);
			if (i - 1 >= 0) f[i][j] = min(f[i][j], f[i - 1][j]);
			if (i - 1 >= 0 && j - 1 >= 0) f[i][j] = min(f[i][j], bs(e[a[i]], f[i - 1][j - 1]) + 1);
			if (f[i][j] != m + 1 && j * E + (i + 1) + f[i][j] <= S) ans = max(ans, j);
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 123456;
const int M = 345;

int n, m, S, E;
int a[N], b[N], f[N][M];
vector<int> e[N];

int bs(vector<int>& v, int p) {
	int q = lower_bound(v.begin(), v.end(), p) - v.begin();
	if (q == v.size()) return m;
	else return v[q];
}

int main() {
	cin >> n >> m >> S >> E;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < m; ++i) { cin >> b[i]; e[b[i]].push_back(i); }
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= S / E; ++j) {
			f[i][j] = m + 1;
			if (j == 0) f[i][j] = 0;
			else if (j == 1) f[i][j] = min(f[i][j], bs(e[a[i]], 0) + 1);
			if (i - 1 >= 0) f[i][j] = min(f[i][j], f[i - 1][j]);
			if (i - 1 >= 0 && j - 1 >= 0) f[i][j] = min(f[i][j], bs(e[a[i]], f[i - 1][j - 1]) + 1);
			if (f[i][j] != m + 1 && j * E + (i + 1) + f[i][j] <= S) ans = max(ans, j);
		}
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <utility>
#include <bitset>
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define per(i,b,a) for (int i=(b)-1;i>=(a);i--)
#define REP(i,a,b) for (int i=(a);i<=(b);i++)
#define PER(i,b,a) for (int i=(b);i>=(a);i--)
using namespace std;
typedef long long LL;

const int INF = 0x3f3f3f3f;

const int MAXN = 1000005; // 1e6;
int n,m,a[MAXN],b[MAXN];
int e,s;
vector<int> G[MAXN];
int dp[MAXN];
int main()
{
//        G[1].pb(1);
//        cout<<*G[1].end()<<endl;
        scanf("%d%d%d%d",&n,&m,&s,&e);
        rep(i,1,n+1) scanf("%d",a+i);
        rep(i,1,m+1) scanf("%d",b+i), G[b[i]].pb(i);
        rep(i,0,n+1) dp[i]=INF;
        int cnt = 0,ans = 0;
        for (int i = s-e; i>=0; i-=e)
        {
                cnt++;
                int now = INF;
                if (i==s-e) now=0;
                rep(j,1,n+1)
                {
                        int p = upper_bound(G[a[j]].begin(),G[a[j]].end(),now) - G[a[j]].begin();
                        now = min(now,dp[j]);
                        if (p != G[a[j]].size()) dp[j]=G[a[j]][p];
                        else dp[j]=INF;
                        if (j+dp[j] <= i) ans = max(ans,cnt);
                }
        }
        cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 10, K = 310, C = 26, INF = 1e9;

int dp[N][K], nex[N][C];
int a[N], b[N], res = 0;
vector<int> ind[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m, s, e, limit; cin >> n >> m >> s >> e;
	limit = s/e;

	for(int i=0; i<n; i++)
		cin >> a[i];
	for(int i=0; i<m; i++){
		cin >> b[i];
		ind[b[i]].pb(i);
	}

	memset(dp, -1, sizeof dp);
	for(int j=1; j<= limit; j++)
		dp[0][j] = INF;

	for(int i=1; i<=n; i++){
		for(int j=1; j<=limit; j++){
			dp[i][j] = dp[i - 1][j];
			int id = upper_bound(ind[a[i - 1]].begin(), ind[a[i - 1]].end(), dp[i - 1][j - 1])
				- ind[a[i - 1]].begin();
			if(id < (int)ind[a[i - 1]].size())
				dp[i][j] = min(dp[i][j], ind[a[i - 1]][id]);
			if(s - e * j - i - dp[i][j] -  1>= 0)
				res = max(res, j);
		}
	}
	cout << res << endl;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 10, K = 310, C = 26, INF = 1e9;

int dp[N][K], nex[N][C];
int a[N], b[N], res = 0;
vector<int> ind[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m, s, e, limit; cin >> n >> m >> s >> e;
	limit = s/e;

	for(int i=0; i<n; i++)
		cin >> a[i];
	for(int i=0; i<m; i++){
		cin >> b[i];
		ind[b[i]].pb(i);
	}

	memset(dp, -1, sizeof dp);
	for(int j=1; j<= limit; j++)
		dp[0][j] = INF;

	for(int i=1; i<=n; i++){
		for(int j=1; j<=limit; j++){
			dp[i][j] = dp[i - 1][j];
			int id = upper_bound(ind[a[i - 1]].begin(), ind[a[i - 1]].end(), dp[i - 1][j - 1])
				- ind[a[i - 1]].begin();
			if(id < (int)ind[a[i - 1]].size())
				dp[i][j] = min(dp[i][j], ind[a[i - 1]][id]);
			if(s - e * j - i - dp[i][j] - 2 >= 0)
				res = max(res, j);
		}
	}
	cout << res << endl;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

const int maxn = 1e5+100;

vector<int>G[maxn];
int dp[302][maxn];
int A[maxn];
int B[maxn];
int main()
{
    int n, m , s, e;
    int i, j, k;
    scanf("%d%d%d%d", &n, &m, &s, &e);
    for(i = 1; i <= n; i++)
    {
        scanf("%d",&A[i]);
    }
    for(i = 1; i <= m; i++)
    {
        scanf("%d", &B[i]);
        G[B[i]].push_back(i);
    }
    memset(dp, -1, sizeof dp);
    memset(dp[0], 0, sizeof dp[0]);
    int d= s/e;
    int ans = 0;
    for(i = 1; i<= d; i++)
    {
        for(j = i; j <= n; j++)
        {
            dp[i][j] = dp[i][j-1];
            if(dp[i-1][j-1] != -1)
            {
                vector<int> ::iterator it;
                it = lower_bound(G[A[j]].begin(), G[A[j]].end() ,dp[i-1][j-1]+1 );
                if(it != G[A[j]].end())
                {
                    if(dp[i][j] == -1) dp[i][j] = (*it);
                    else dp[i][j] =min(dp[i][j], (*it));
                }
            }

            if( dp[i][j] != -1 &&i * e + j + dp[i][j] <=s) ans = max(ans, i);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

//defines
#define openin freopen("input.txt","r",stdin)
#define openout freopen("output.txt","w",stdout)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define int long long
#define mod 1000000007
#define repr(i,x,y) for (__typeof(x) i=x;i>=y;i--)
#define rep(i,x,y) for (__typeof(x) i=x;i<=y;i++)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

/* Print pair */
template <typename T,typename S>
ostream & operator << (ostream &os , const pair<T,S> &v) {
    os << "(" ;
    os << v.first << "," << v.second << ")" ;
    return os ;
}
/* Print vector */
template <typename T>
ostream & operator << (ostream &os , const vector<T> &v) {
    os << "[" ;
    int sz = v.size() ;
    for(int i = 0 ; i < sz ; ++i) {
        os << v[i] ;
        if(i!=sz-1)os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print set */
template <typename T>
ostream & operator << (ostream &os , const set<T> &v) {
    T last = *v.rbegin() ;
    os << "[" ;
    for(auto it : v) {
        os << it  ;
        if(it != last) os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print Map */
template <typename T,typename S>
ostream & operator << (ostream &os , const map<T,S> &v) {
    for(auto it : v) {
        os << it.first << " : " << it.second << "\n" ;
    }
    return os ;
}
int power(int a , int b)
{
    int res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % mod ;
        }
        b/=2 ;
        a = (a*a) % mod ;
    }
    return res ;
}

//debug
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = 1e5 + 5 ;
int arr[N] , brr[N] ;
vector<int> pos[N] ;
int DP[N][405] ;
int32_t main()
{
    fast;
    int n , m , s , e ;
    cin >> n >> m >> s >> e ;
    for(int i = 1 ; i <= n ; ++i) cin >> arr[i] ;
    for(int j = 1 ; j <= m ; ++j) cin >> brr[j] ;
    for(int i = 1 ; i <= m ; ++i) {
        pos[brr[i]].push_back(i) ;
    }
    int k = s/e ;
    int ans = 0 ;
    for(int j = 1 ; j <= k ; ++j) DP[0][j] = mod ;
    for(int i = 1 ; i <= n ; ++i) {
        for(int j = 1 ; j <= k ; ++j) {
            DP[i][j] = DP[i-1][j] ;
            auto it = lower_bound(all(pos[arr[i]]),DP[i-1][j-1]+1) ;
            if(it != pos[arr[i]].end()) {
                DP[i][j] = min(DP[i][j] , *it) ;
            }
            if(s - j*e - (DP[i][j] + i) >= 0) {
                ans = max(ans , j) ;
            }
        }
    }
    cout << ans << endl ;
    return 0;
}