Problem:
たのしいカードゲーム(Card Game is Fun)
1 から1000 までのどれかの整数が書かれたカードがたくさんある．アンナとブルーノはそれらのカードを用いて，次のようなゲームをする．
アンナは
A
枚，ブルーノは
B
枚のカードからなる山を持つ．アンナは
A
枚のカードの中から任意の何枚か（0 枚でもよい）を捨てて新しい山を作る．ブルーノは
B,
枚のカードからなる山の一番上から何枚か（0枚でもよい）と，一番下から何枚か（0 枚でもよい）を捨てて新しい山を作る．ただし，捨てる際に残ったカードの並び替えは行わない．このように作った2 つの山が一致していたら，一方の山に含まれるカードの枚数が2 人の得点になる．ただし，2 つの山が一致するとは，山に含まれるカードの枚数n が同じで，かつ上からi 番目(1 ≤
i
≤
n
) に書かれたカードの整数が全て同じであることである．
例えば，アンナが5 枚のカードの山を持ち，書かれている整数は上から順に1,2,3,4,5 であり，ブルーノが4 枚のカードの山を持ち，書かれている整数が上から順に3,1,4,1 であったとする．このとき，アンナが2,3,5 のカードを捨て，ブルーノが一番上の3 と一番下の1 のカードを捨てると2 人の山が一致する．このとき，残った山の一方に含まれるカードの枚数は2 枚なので，2 人は得点2 を得る．
2 人の得点の最大値を求めたい．
課題
アンナとブルーノが持っているカードの山の情報が与えられたときに，2 人の得点の最大値を求めるプ
ログラムを作成せよ．
制限
1 ≤
A
≤ 5000
1 ≤
B
≤ 5000
カードに書かれている整数は1 以上1000 以下である．
入力
標準入力から以下のデータを読み込め．
1 行目には，整数
A
,
B
が空白を区切りとして書かれている．
2 行目には，
A
個の整数が空白を区切りとして書かれており，
i
番目の整数(1 ≤
i
≤
A
) はアンナの持っている山の上から
i
番目のカードに書かれている整数を表す．
3 行目には，
B
個の整数が空白を区切りとして書かれており，
j
番目の整数(1 ≤
j
≤
B
) はブルーノの持っている山の上からj 番目のカードに書かれている整数を表す．
出力
標準出力に，得点の最大値を表す整数を1 行で出力せよ．
採点基準
採点用データのうち，配点の10%分については，
A
≤ 10,
B
≤ 10 を満たす．
採点用データのうち，配点の50%分については，
A
≤ 100,
B
≤ 100 を満たす．
入出力例
入力例 1
5 4
1 2 3 4 5
3 1 4 1
出力例 1
2
この入出力例は問題文中の例に対応している．
入力例 2
6 5
4 1 5 2 3 4
4 5 4 2 3
出力例 2
3
この入出力例では，2 人が得点3 を得る方法が2 通り存在する．アンナが1, 2, 3 のカードを捨てブルーノが2, 3 のカードを捨てたとき, 2 人の山は上から順に4, 5, 4 となり, 2 人の得点は3 点となる. また, アンナが1, 5, 4 のカードを捨てブルーノが一番上の4 と5 のカードを捨てたとき, 2 人の山は上から順に4, 2, 3となり, 2 人の得点は3 点となる.
問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include<utility>
#include<set>
#include<deque>
#include <unordered_map>
#include<string>
#include<cmath>

using namespace std;
int mm = -100000;
const int MOD = 10000;
int main() {
	int N, W;
	cin >> N >> W;
	vector<int>A(N);
	vector<int>B(W);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	for (int i = 0; i < W; i++) {
		cin >> B[i];
	}
	int ans = 0;
	vector<vector<int>>dp(N + 1, vector<int>(W + 1, 0));
	
	for (int i = 1; i < N + 1; i++) {
		for (int j = 1; j < W + 1; j++) {
			int X = 0;
			if (A[i - 1] == B[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}

			dp[i][j] = max(dp[i - 1][j], dp[i][j]);

			ans = max(ans, dp[i][j]);
		}
	}

	

	cout << ans<<endl;
}
accuracy: 1
time_ms: 50
memory_kb: 101040
final_rank: 15

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

int main() {
    int A, B;
    cin >> A >> B;
    vector<int> v1(A), v2(B);
    for(int i=0; i<A; ++i) {
        cin >> v1[i];
    }
    for(int i=0; i<B; ++i) {
        cin >> v2[i];
    }
    int res = 0;
    for(int i=0; i<B; ++i) {
        int r = i;
        for(int j=0; j<A && r<B; ++j) {
            if(v2[r] == v1[j]) {
                r++;
            }
        }
        res = max(res, r - i);
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3456
final_rank: 6

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, ll iter = 100) {
  rep(iter) {
    double x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll A, B;
  cin >> A >> B;
  vi a(A), b(B);
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  ll ans = 0;
  rep(i, B) {
    ll seq = 0;
    ll k = 0;
    rep(j, i, B) {
      while ((k < A) and (a[k] != b[j])) k++;
      if (k < A) {
        k++;
        seq++;
      } else {
        break;
      }
    }
    chmax(ans, seq);
  }
  print(ans);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3540
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#include <random>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vvvvvll = vector<vvvvll>;
using vvvvvvll = vector<vvvvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vvvvd = vector<vvvd>;
using vvvvvd = vector<vvvvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;
#define tN(t) (t==1?XN:YN)
#define tS(t) (t==1?XS:YS)
#define tA(t) (t==1?XA:YA)

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}


vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
    fact.resize(n + 5);
    factinv.resize(n + 5);
    inv.resize(n + 5);
    fact.at(0) = fact.at(1) = 1;
    factinv.at(0) = factinv.at(1) = 1;
    inv.at(1) = 1;
    for (ll i = 2; i < n + 5; i++) {
        fact.at(i) = (fact.at(i - 1) * i) % mod;
        inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
        factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
    }

}
ll nCk(ll n, ll k) {
    if (n < k) return 0;
    return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}
ll modPow(long long a, long long n, long long p = mod) {
    if (n == 0) return 1; // 0乗にも対応する場合
    if (n == 1) return a % p;
    if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    long long t = modPow(a, n / 2, p);
    return (t * t) % p;
}



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

    ll N,M;
    cin>>N>>M;
    vll A(N),B(M);
    rep(i,N)cin>>A[i];
    rep(i,M)cin>>B[i];
    ll an=0;
    rep(i,M){
        ll j=i;
        ll t=0;
        ll res=0;
        while(t<N){
            if(B[j]==A[t]){
                j++;
                res++;
            }
            t++;
            if(j==M)break;
        }
        chmax(an,res);
    }
    cout<<an<<endl;


}
accuracy: 1
time_ms: 20
memory_kb: 3520
final_rank: 9

code_snippet: #include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;

    vector<int> anna(a), bruno(b);
    for (int i = 0; i < a; ++i) cin >> anna[i];
    for (int i = 0; i < b; ++i) cin >> bruno[i];

    deque<vector<int>> ab;
    ab.push_back(vector<int>(a + 1, 0));
    ab.push_back(vector<int>(a + 1, 0));

    int max_len = 0;
    for (int row = 1; row <= b; ++row) {
        for (int col = 1; col <= a; ++col) {
            if (bruno[row - 1] == anna[col - 1]) {
                ab[1].at(col) = ab[0].at(col - 1) + 1;
            } else {
                ab[1].at(col) = ab[1].at(col - 1);
            }
            max_len = max(max_len, ab[1].at(col));
        }
        ab.pop_front();
        ab.push_back(vector<int>(a + 1, 0));
    }
    cout << max_len << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3524
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
//typedef long long ll;
typedef int ll;
typedef pair<ll, ll> P;
const long long INF = 1e9;
template <typename T>
void input_arr(vector<T>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
}
template <typename T, typename Q>
void input_arr(vector<pair<T, Q>>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
}
template <typename T>
void input_arr(vector<vector<T>>& A, ll H, ll W) {
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
}
int main() {
    ll N, M; cin >> N >> M;
    vector<ll>A(N), B(M);
    input_arr(A, N); input_arr(B, M);
    ll ans = -1;
    for (ll i = 0; i < M; i++) {
        ll sum = 0, pos = i;
        for (ll j = 0; j < N; j++) {
            if (pos >= M) break;
            if (A[j] == B[pos]) {
                sum++;
                pos++;
            }
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3476
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<int> a(n),b(m);
  for ( int i=0; i<n; i++ ) cin>>a[i];
  for ( int i=0; i<m; i++ ) cin>>b[i];
  int ans=0;
  for ( int i=0; i<m; i++ ) {
    int j=i,k=0;
    while ( j<m ) {
      while ( k<n && b[j]!=a[k] ) k++;
      if ( k==n ) break;
      j++;
      k++;
    }
    ans=max(ans,j-i);
  }
  cout<<ans<<'\n';
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3480
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)

int main(){
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    
    int ans = 0;
    rep(c, m){
        int at = c, cnt = 0;
        rep(i, n){
            if(at < m && a[i] == b[at]){
                at++;
                cnt++;
            }
        }
        
        ans = max(ans, cnt);
    }
    
    cout << ans << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3476
final_rank: 11

code_snippet: #include<iostream>

using namespace std;

int dp[5001][5001];

int main()
{
	int A, B;
	cin >> A >> B;
	int* a = new int[A];
	int* b = new int[B];
	for (int i = 0; i < A; i++)
		cin >> a[i];
	for (int i = 0; i < B; i++)
		cin >> b[i];
	dp[0][0] = 0;
	int ans = 0;
	for (int i = 0; i < A; i++)
	{
		for (int j = 0; j < B; j++)
		{
			if (a[i] == b[j])
			{
				for (int k = 0; k <= i; k++)
					dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[k][j] + 1);
				ans = max(dp[i + 1][j + 1], ans);
			}
			else
				dp[i + 1][j + 1] = 0;
		}
	}
	cout << ans << endl;

	//system("pause");
}
accuracy: 1
time_ms: 740
memory_kb: 100824
final_rank: 17

code_snippet: #define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<regex>
#include<random>
using namespace std;
#define int long long
#define uint unsigned long long
const int mod=1e9+7;
const int Mod=998244353;
const int inf=mod*mod;
const double eps=1e-9;
short dp[5001][5001];
signed main(){
	int n,m,a[5000],b[5000];
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<m;i++)
		cin>>b[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(a[i]==b[j])
				dp[i+1][j+1]=dp[i][j]+1;
			else
				dp[i+1][j+1]=dp[i][j+1];
		}
	}
	short ans=0;
	for(int j=0;j<=m;j++)
		ans=max(ans,dp[n][j]);
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 52360
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  int ans = 0;
  rep(i, m) {
    int k = 0;
    rep(j, n) {
      if (i + k < n && b[i + k] == a[j]) k++;
    }
    ans = max(ans, k);
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3484
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < N; i++)

int main()
{
    int A, B;
    cin >> A >> B;
    int AA[A], BB[B];
    rep(i, A) cin >> AA[i];
    rep(i, B) cin >> BB[i];
    int maxv = 0;
    int i = 0, k = 0;
    rep(j, B)
    {
        i = 0;
        k = 0;
        while (1)
        {
            if (AA[i] == BB[j + k])
            {
                k++;
                if (j + k >= B)
                {
                    maxv = max(maxv, k);
                    break;
                }
            }
            i++;
            if (i >= A)
            {
                maxv = max(maxv, k);
                break;
            }
        }
    }
    cout << maxv << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3136
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
using ll=long long;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=n;i--;)
#define rrep2(i,n) for(ll i=n;i--;)
#define rrep3(i,a,b) for(ll i=b;i-->(a);)
#define rrep4(i,a,b,c) for(ll i=(a)+((b)-(a)-1)/(c)*(c);i>=(a);i-=c)
#define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(i) begin(i), end(i)
#define rall(i) (i).rbegin(), (i).rend()
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))
#define elif else if
template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> ll sum(const T& a){ return accumulate(all(a), 0LL); }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }
const int INF =0x3fffffff;
const ll INFll =0x1fffffffffffffff;// 4times ok
const int MOD= int(1e9)+7;
const int MODD=998244353;
using P= pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using VVl=vector<vector<ll>>;
using VVd=vector<vector<ld>>;
using Vd=vector<ld>;
using tuplis = array<ll, 3>;
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
const ll four[] = {0, 1, 0, -1, 0};
const ll eight[] = {0, 1, 1, 0, -1, -1, 1, -1, 0};
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll isqr(ll x){ll r=sqrt(x)-1;while((r+1)*(r+1)<=x)r++;return r;}
vector<ll> divisor(ll x){vector<ll> ans; for(ll i = 1; i * i <= x; i++) if(x % i == 0) ans.push_back(i); rrep(ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]); return ans; }
int scan(){ return getchar(); }
void scan(int& a){ scanf("%d", &a); }
void scan(unsigned& a){ scanf("%u", &a); }
void scan(long& a){ scanf("%ld", &a); }
void scan(long long& a){ scanf("%lld", &a); }
void scan(unsigned long long& a){ scanf("%llu", &a); }
void scan(char& a){ do{ a = getchar(); }while(a == ' ' || a == '\n'); }
void scan(float& a){ scanf("%f", &a); }
void scan(double& a){ scanf("%lf", &a); }
void scan(long double& a){ scanf("%Lf", &a); }
void scan(vector<bool>& a){ for(unsigned i = 0; i < a.size(); i++){ int b; scan(b); a[i] = b; } }
void scan(char a[]){ scanf("%s", a); }
void scan(string& a){ cin >> a; }
template<class T> void scan(vector<T>&);
template<class T, size_t size> void scan(array<T, size>&);
template<class T, class L> void scan(pair<T, L>&);
template<class T, size_t size> void scan(T(&)[size]);
template<class T> void scan(vector<T>& a){ for(auto&& i : a) scan(i); }
template<class T> void scan(deque<T>& a){ for(auto&& i : a) scan(i); }
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i); }
template<class T, class L> void scan(pair<T, L>& p){ scan(p.first); scan(p.second); }
template<class T, size_t size> void scan(T (&a)[size]){ for(auto&& i : a) scan(i); }
template<class T> void scan(T& a){ cin >> a; }
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){ scan(head); in(tail...); }
void print(){ putchar(' '); }
void print(bool a){ printf("%d", a); }
void print(int a){ printf("%d", a); }
void print(unsigned a){ printf("%u", a); }
void print(long a){ printf("%ld", a); }
void print(long long a){ printf("%lld", a); }
void print(unsigned long long a){ printf("%llu", a); }
void print(char a){ printf("%c", a); }
void print(char a[]){ printf("%s", a); }
void print(const char a[]){ printf("%s", a); }
void print(float a){ printf("%.15f", a); }
void print(double a){ printf("%.15f", a); }
void print(long double a){ printf("%.15Lf", a); }
void print(const string& a){ for(auto&& i : a) print(i); }
template<class T> void print(const complex<T>& a){ if(a.real() >= 0) print('+'); print(a.real()); if(a.imag() >= 0) print('+'); print(a.imag()); print('i'); }
template<class T> void print(const vector<T>&);
template<class T, size_t size> void print(const array<T, size>&);
template<class T, class L> void print(const pair<T, L>& p);
template<class T, size_t size> void print(const T (&)[size]);
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T> void print(const deque<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T, size_t size> void print(const array<T, size>& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T, class L> void print(const pair<T, L>& p){ print(p.first); putchar(' '); print(p.second); }
template<class T, size_t size> void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ putchar(' '); print(*i); } }
template<class T> void print(const T& a){ cout << a; }
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
#define INT(...) int __VA_ARGS__; in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__; in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__; in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size); in(name)
#define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); in(name)

int main() {
   LL(n,m);
   VEC(ll,a,n);
   VEC(ll,b,m);
   ll ans=0;
   auto f=[&](ll s){
       ll ret=0;
       rep(n){
           if(s==m)return ret;
           if(b[s]==a[i]){
               ret++;
               s++;
           }
       }
       return ret;
   };
   rep(m){
       chmax(ans,f(i));
   }
   out(ans);
}
accuracy: 1
time_ms: 10
memory_kb: 3652
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n,m);
    vector<int> s(n),t(m);
    in(s,t);
    int ans=0,cnt=0;
    for(int j=0;j<m;j++){
        cnt=0;
        for(int i=0;i<n;i++){
            if(j+cnt<m&&s[i]==t[j+cnt]){
                cnt++;
                chmax(ans,cnt);
            }
        }
    }
    out(ans);
}
accuracy: 1
time_ms: 20
memory_kb: 3252
final_rank: 5

code_snippet: #pragma region Macros
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define drep(i,n) for(ll i = n-1;i >= 0;i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)\
    vector<type> name(size);\
    IN(name)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)\
    vector<vector<type>> name(h, vector<type>(w));\
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)\
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
using namespace std;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define si(c) (int)(c).size()
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DBL(...)\
    double __VA_ARGS__;\
    IN(__VA_ARGS__)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) {
    scan(head);
    IN(tail...);
}
template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
vi iota(int n) {
    vi a(n);
    iota(all(a), 0);
    return a;
}
template <typename T> vi iota(vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(all(res), 0);
    sort(all(res), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    sort(all(y));
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
int popcount(ll x) { return __builtin_popcountll(x); }
int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}
#define i128 __int128_t
#define ull unsigned long long int
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(15);
    }
} setup_io;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" :", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#define LOCAL
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << 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...);
}
#pragma endregion
//#include<atcoder/all>
//using namespace atcoder;
int main(){
    INT(n,m);
    VEC(int,a,n);
    VEC(int,b,m);
    ll ret = 0;
    rep(from,m){
        for(int i = 0,j = from;j < m;){
            while(i < n && a[i] != b[j])i++;
            if(i == n)break;
            i++;j++;
            chmax(ret,j-from);
        }
    }
    cout << ret << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3508
final_rank: 8

code_snippet: #pragma region Macros
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define drep(i,n) for(ll i = n-1;i >= 0;i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)\
    vector<type> name(size);\
    IN(name)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)\
    vector<vector<type>> name(h, vector<type>(w));\
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)\
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
using namespace std;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define si(c) (int)(c).size()
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DBL(...)\
    double __VA_ARGS__;\
    IN(__VA_ARGS__)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) {
    scan(head);
    IN(tail...);
}
template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
vi iota(int n) {
    vi a(n);
    iota(all(a), 0);
    return a;
}
template <typename T> vi iota(vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(all(res), 0);
    sort(all(res), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    sort(all(y));
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
int popcount(ll x) { return __builtin_popcountll(x); }
int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}
#define i128 __int128_t
#define ull unsigned long long int
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(15);
    }
} setup_io;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" :", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#define LOCAL
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << 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...);
}
#pragma endregion
//#include<atcoder/all>
//using namespace atcoder;
int main(){
    // dp[i][j]:Aのiまで(iつかう)、Bのjまで(j使う)時の最大値
    // if(a[i] == b[j])dp[i][j] = max(dp[x][j-1])+1;
    // else dp[i][j] = 0;
    INT(n,m);
    VEC(int,a,n);
    VEC(int,b,m);
    vv(int,dp,n+1,m+1);
    vector<int> maxi(m+1);
    rep(i,n){
        vector<int> tmp(m+1);
        rep(j,m){
            if(a[i] == b[j]){
                dp[i][j] = 1;
                if(j)dp[i][j] += maxi[j-1];
            }
            // trace(i,j,dp[i][j]);
            chmax(tmp[j],dp[i][j]);
        }
        rep(j,m)chmax(maxi[j],tmp[j]);
    }
    cout << *max_element(all(maxi)) << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 101020
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using usize = std::size_t;

const i32 INF = 1001001001;
const i64 LINF = 1001001001001001;
const u32 MOD1 = 1000000007;
const u32 MOD2 = 998244353;

using namespace std;

i32 wx[5050][1010],wy[5050][1010];
i32 dp[5050][5050];

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    i32 a,b;
    cin>>a>>b;
    i32 x[a],y[b];
    for(i32 i=0;i<a;i++)cin>>x[i];
    for(i32 i=0;i<b;i++)cin>>y[i];
    for(i32 i=0;i<5050;i++)for(i32 j=0;j<1010;j++)wx[i][j]=wy[i][j]=INF;
    for(i32 i=a-1;i>=0;i--){
        for(i32 j=0;j<1010;j++)wx[i][j]=wx[i+1][j];
        wx[i][x[i]]=i;
    }
    for(i32 i=b-1;i>=0;i--){
        for(i32 j=0;j<1010;j++)wy[i][j]=wy[i+1][j];
        wy[i][y[i]]=i;
    }
    for(i32 i=0;i<a;i++){
        for(i32 j=0;j<b;j++){
            for(i32 k=0;k<1010;k++){
                if(wx[i+1][k]==INF||wy[j+1][k]==INF)continue;
                if(dp[i][j]>0&&wy[j+1][k]!=j+1)continue;
                dp[wx[i+1][k]][wy[j+1][k]]=max(dp[wx[i+1][k]][wy[j+1][k]],dp[i][j]+1);
            }
        }
    }
    i32 ans=0;
    for(i32 i=0;i<5050;i++)for(i32 j=0;j<5050;j++)ans=max(ans,dp[i][j]);
    cout<<ans<<endl;
}
accuracy: 0.03333333333333333
time_ms: 30
memory_kb: 42964
final_rank: 20

code_snippet: #include <bits/stdc++.h>

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using usize = std::size_t;

const i32 INF = 1001001001;
const i64 LINF = 1001001001001001;
const u32 MOD1 = 1000000007;
const u32 MOD2 = 998244353;

using namespace std;

i32 wx[5050][1010],wy[5050][1010];
i32 dp[5050][5050];

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    i32 a,b;
    cin>>a>>b;
    i32 x[a],y[b];
    for(i32 i=0;i<a;i++)cin>>x[i];
    for(i32 i=0;i<b;i++)cin>>y[i];
    for(i32 i=0;i<5050;i++)for(i32 j=0;j<1010;j++)wx[i][j]=wy[i][j]=INF;
    for(i32 i=a-1;i>=0;i--){
        for(i32 j=0;j<1010;j++)wx[i][j]=wx[i+1][j];
        wx[i][x[i]]=i;
    }
    for(i32 i=b-1;i>=0;i--){
        for(i32 j=0;j<1010;j++)wy[i][j]=wy[i+1][j];
        wy[i][y[i]]=i;
    }
    for(i32 i=0;i<a;i++){
        for(i32 j=0;j<b;j++){
            for(i32 k=0;k<1010;k++){
                if(wx[i][k]==INF||wy[j][k]==INF)continue;
                if(dp[i][j]>0&&(wy[j][k]!=j+1&&y[j+1]!=k))continue;
                dp[wx[i][k]][wy[j][k]]=max(dp[wx[i][k]][wy[j][k]],dp[i][j]+1);
            }
        }
    }
    i32 ans=0;
    for(i32 i=0;i<5050;i++)for(i32 j=0;j<5050;j++)ans=max(ans,dp[i][j]);
    cout<<ans<<endl;
}
accuracy: 0.13333333333333333
time_ms: 40
memory_kb: 43440
final_rank: 19

code_snippet: #include <bits/stdc++.h>

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using usize = std::size_t;

const i32 INF = 1001001001;
const i64 LINF = 1001001001001001;
const u32 MOD1 = 1000000007;
const u32 MOD2 = 998244353;

using namespace std;

i32 wx[5050][1010],wy[5050][1010];
i32 dp[5050][5050];

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    i32 a,b;
    cin>>a>>b;
    i32 x[a],y[b];
    for(i32 i=0;i<a;i++)cin>>x[i];
    for(i32 i=0;i<b;i++)cin>>y[i];
    for(i32 i=0;i<5050;i++)for(i32 j=0;j<1010;j++)wx[i][j]=wy[i][j]=INF;
    for(i32 i=a-1;i>=0;i--){
        for(i32 j=0;j<1010;j++)wx[i][j]=wx[i+1][j];
        wx[i][x[i]]=i;
    }
    for(i32 i=b-1;i>=0;i--){
        for(i32 j=0;j<1010;j++)wy[i][j]=wy[i+1][j];
        wy[i][y[i]]=i;
    }
    for(i32 i=0;i<a;i++){
        for(i32 j=0;j<b;j++){
            for(i32 k=0;k<1010;k++){
                if(wx[i][k]==INF||wy[j][k]==INF)continue;
                if(dp[i][j]>0&&wy[j][k]!=j+1)continue;
                dp[wx[i][k]][wy[j][k]]=max(dp[wx[i][k]][wy[j][k]],dp[i][j]+1);
            }
        }
    }
    i32 ans=0;
    for(i32 i=0;i<5050;i++)for(i32 j=0;j<5050;j++)ans=max(ans,dp[i][j]);
    cout<<ans<<endl;
}
accuracy: 0.13333333333333333
time_ms: 30
memory_kb: 43392
final_rank: 18

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n),b(m);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<m; i++){
        cin >> b[i];
    }
    int ans = 0;
    for(int i=0; i<m; i++){
        int p = i;
        for(int j=0; j<n; j++){
            if(a[j] == b[p]){
                p++;
                if(p == m) break;
            }
        }
        ans = max(ans, p-i);
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3484
final_rank: 2