Problem:
Longest Common Subsequence
For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \{a,b,c,b,d,a,b\}$ and $Y = \{b,d,c,a,b,a\}$, the sequence $\{b,c,a\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\{b,c,a\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\{b,c,b,a\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\{b,c,b,a\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater.
Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters.
Input
The input consists of multiple datasets. In the first line, an integer $q$ which is the number of datasets is given. In the following $2 \times q$ lines, each dataset which consists of the two sequences $X$ and $Y$ are given.
Output
For each dataset, print the length of LCS of $X$ and $Y$ in a line.
Constraints
$1 \leq q \leq 150$
$1 \leq$ length of $X$ and $Y$ $\leq 1,000$
$q \leq 20$ if the dataset includes a sequence whose length is more than 100
Sample Input 1
3
abcbdab
bdcaba
abc
abc
abc
bc
Sample Output 1
4
3
2
Reference
Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const ll INF=1ll<<60;
int main(){
    int q;
    cin>>q;
    while(q--){
        string s,t;
        cin>>s>>t;
        vector dp(s.size()+1,vector<int>(t.size()+1));
        rep(i,s.size()+1)dp[i][0]=0;
        rep(i,t.size()+1)dp[0][i]=0;
        rep(i,s.size()){
            rep(j,t.size()){
                if(s[i]==t[j]){
                    dp[i+1][j+1]=dp[i][j]+1;
                }else{
                    dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
                }
            }
        }
        cout<<dp[s.size()][t.size()]<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 7424
final_rank: 12

code_snippet: #include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
using ld = long double;
ll INF = 2e18;
#define PI 3.14159265358979323846264338327950l
// namespace multip = boost::multiprecision;
// using lll = multip::int128_t;
using P = pair<ll, ll>;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
using vl = vc<ll>; using vvl = vv<ll>; using vvvl = vv<vl>; using vvvvl = vv<vvl>;
using vs = vc<string>; using vvs = vv<string>;
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define drep(i,n) for (ll i = (n)-1; i >= 0; i--)
#define nfor(i, s, n) for (ll i = (s); i < (n); i++)
#define dfor(i, s, n) for (ll i = (s)-1; i>=n; i--)
#define nall(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define em emplace
#define pob pop_back
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define YN { cout << "Yes" << endl; } else { cout << "No" << endl; }
#define dame cout << -1 << endl
#define minval(vec) *min_element(nall(vec))
#define maxval(vec) *max_element(nall(vec))
#define binaryS(vec, x) *lower_bound(nall(vec), x)
#define yu_qurid(x, y) (x) * (x) + (y) * (y)
#define mannhattan(x1, x2, y1, y2) abs(x1-x2)+abs(y1-y2)
#define vc_cout(v){ll n= size(v); rep(i,n)cout<<v[i]<<" ";cout << endl;}
#define vvc_cout(v){ll n= size(v);rep(i,n){rep(j,size(v[i])){cout<<v[i][j]<<" ";}cout<<endl;}}
// 少数の出力
void print(ld x) { printf("%.20Lf\n", x); }

// グリット用
vector<ll> dx = {1, 0, -1, 0};
vector<ll> dy = {0, 1, 0, -1};
bool in_grid(ll i, ll j, ll h, ll w) {
    return 0 <= i and i < h and 0 <= j and j < w;
}

// 動的計画法による最長共通部分列の最適解を計算する関数
void lcs(vvl &c, string x, string y) {
    ll m = x.size();
    ll n = y.size();

    /*
    c[i][j]を以下の漸化式で計算する
                0                           if i = 0 or j = 0
    c[i][j] =   c[i-1][j-1] + 1             if i, j > 0 and xi = yi
                max(c[i][j-1], c[i-1][j])   if i, j > 0 and xi != yi
    */
    for (int i = 1; i < m+1; i++) {
        for (int j = 1; j < n+1; j++) {
            if (x[i-1] == y[j-1]) {
                c[i][j] = c[i-1][j-1] + 1;
            }
            else c[i][j] = max(c[i][j-1], c[i-1][j]);
        }
    }
}

// main
void solve() {
    ll q;
    cin >> q;
    while(q--) {
        string x, y;
        cin >> x >> y;
        ll m = x.size();
        ll n = y.size();
        // c[i][j]をxi, yjのLCS(最長共通部分列)の長さとする2次元配列
        vector<vector<ll>> memo(m+1, vector<ll>(n+1, 0));
        lcs(memo, x, y);
        cout << memo[m][n] << endl;
    }

    return;
}

int main() {
    solve();
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 11264
final_rank: 18

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

int lcs(const string& X, const string& Y) {
    int m = X.length();
    int n = Y.length();
    
    // dp[i][j] = XのiつまでとYのjつまでのLCSの長さ
    vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
    
    // dp
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (X[i - 1] == Y[j - 1]) {
                // 文字が一致する場合、前の状態に1を加える
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                // 文字が一致しない場合、XかYのどちらかを1つ減らした状態の最大値
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    
    return dp[m][n];
}

int main() {
    int q;
    cin >> q;
    
    for (int i = 0; i < q; i++) {
        string X, Y;
        cin >> X >> Y;
        cout << lcs(X, Y) << endl;
    }
}
accuracy: 1
time_ms: 40
memory_kb: 7012
final_rank: 15

code_snippet: #include <iostream>
#include <string>
using namespace std;

int L[1001][1001];

int main() {
    int q;
    cin >> q;
    for (int idx=1; idx<q+1; idx++) {
        string X, Y;
        cin >> X >> Y;

        int n = X.size();
        int m = Y.size();

        for (int i=0; i<n+1; i++) {
            for (int j=0; j<m+1; j++) {
                if (i == 0 || j == 0) {
                    L[i][j] = 0;
                }
                else if (X[i-1]==Y[j-1]) {
                    L[i][j] =  1 + L[i-1][j-1];
                }
                else {
                    L[i][j] = max(L[i][j-1], L[i-1][j]);
                }
            }
        }
        cout << L[n][m] << endl;
    }
}
accuracy: 1
time_ms: 30
memory_kb: 7268
final_rank: 8

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

using namespace std;

int f[1005][1005];
int main()
{
    int q;
    cin >> q;
    while (q--)
    {
        string s1, s2;
        cin >> s1 >> s2;
        s1=' '+s1;
        s2=' '+s2;
        int n = s1.size()-1, m = s2.size()-1;
        memset(f,0,sizeof(f));
        int ans=0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                if(s1[i]==s2[j])
                    f[i][j]=f[i-1][j-1]+1;
                else{
                    f[i][j]=max(f[i-1][j],f[i][j-1]);
                }
                
            }
        }
        cout<<f[n][m]<<endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7312
final_rank: 5

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int lcs(const std::string& X, const std::string& Y) {
    int m = X.size();
    int n = Y.size();
    std::vector<std::vector<int>> c(m + 1, std::vector<int>(n + 1, 0));

    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (X[i - 1] == Y[j - 1])
                c[i][j] = c[i - 1][j - 1] + 1;
            else
                c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
        }
    }
    return c[m][n]; // LCS の長さ
}

int main() {
    int n;
    std::cin >> n;

    for (int i = 0; i < n; ++i) {
        std::string s1, s2;
        std::cin >> s1 >> s2;
        std::cout << lcs(s1, s2) << "\n";
    }

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 7036
final_rank: 17

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

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)

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

    int N;
    cin >> N;
    vector<int> res_list(N);

    rep(i, N) {
        string X, Y;
        cin >> X >> Y;
        int S = X.size();
        int T = Y.size();

        vector<vector<int>> dp(S + 1, vector<int>(T + 1, 0));
        for (int j = 1; j < S + 1; ++j) {
            for (int k = 1; k < T + 1; ++k) {
                char x = X[j - 1], y = Y[k - 1];
                if (x == y) dp[j][k] = dp[j - 1][k - 1] + 1;
                dp[j][k] = max({dp[j][k], dp[j - 1][k], dp[j][k - 1]});
            }
        }

        res_list[i] = dp[S][T];
    }
    rep(i, N) cout << res_list[i] << endl;
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 7032
final_rank: 16

code_snippet: #include <iostream>
#include <string>
using namespace std;

#if 0
AOJで正しいことが確認された。
#endif

int main() {
    int k;
    cin >> k;
    for (int i = 1; i <= k; i++) {
        string X, Y;
        cin >> X >> Y;
        int m = X.length();
        int n = Y.length();
        int L[1001][1001];
        for (int i = 0; i <= m; i++) {
            L[i][0] = 0;
        }
        for (int j = 0; j <= n; j++) {
            L[0][j] = 0;
        }
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                if (X[i - 1] == Y[j - 1]) {
                    L[i][j] = L[i - 1][j - 1] + 1;
                } else {
                    L[i][j] = max(L[i - 1][j], L[i][j - 1]);
                } 
            }
        }
        cout << L[m][n] << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 7356
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <cstdint>

// コンパイラに対するヒントのためのマクロ変数
#define likely(x)   __builtin_expect(!!(x), 1) // よく起こりやすい条件分岐
#define unlikely(x) __builtin_expect(!!(x), 0) // あまり起きない条件分岐

uint16_t N; // データセットの数

int main() {
    std::cin >> N; // データセットの数の挿入

    std::string x; // 最初の文字列
    std::string y; // 二番目の文字列

    uint16_t xs, ys; // x, y の文字列の長さを保存する変数

    std::vector<std::vector<uint16_t>> table; // q は高々 99 なので uint16_t 型の二次元配列を用意する

    for (uint16_t i = 0; i<N; ++i) {
        // 文字列の読み込み
        std::cin >> x;
        std::cin >> y;
        xs = x.size();
        ys = y.size();

        table.assign(ys+1, std::vector<uint16_t>(xs+1, 0)); // 文字列の長さ +1 分の配列の長さを確保する

        for (uint16_t r=0; r<ys; ++r) { // 行に関するループ
            for (uint16_t c=0; c<xs; ++c) { // 列に関するループ
                if (x[c] == y[r]) { // 文字が一致する場合
                    table[r+1][c+1] = table[r][c] + 1;
                } else {
                    table[r+1][c+1] = std::max(table[r][c+1], table[r+1][c]);
                }
            }
        }
        
        std::cout << table[ys][xs] << "\n";
    }
}
accuracy: 1
time_ms: 20
memory_kb: 5336
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <cstdint>

// コンパイラに対するヒントのためのマクロ変数
#define likely(x)   __builtin_expect(!!(x), 1) // よく起こりやすい条件分岐
#define unlikely(x) __builtin_expect(!!(x), 0) // あまり起きない条件分岐

uint16_t N; // データセットの数

int main() {
    std::cin >> N; // データセットの数の挿入

    std::string x; // 最初の文字列
    std::string y; // 二番目の文字列

    uint16_t xs, ys; // x, y の文字列の長さを保存する変数

    std::vector<std::vector<uint16_t>> table; // q は高々 99 なので uint16_t 型の二次元配列を用意する

    for (uint16_t i = 0; i<N; ++i) {
        // 文字列の読み込み
        std::cin >> x;
        std::cin >> y;
        xs = x.size();
        ys = y.size();

        table.assign(ys+1, std::vector<uint16_t>(xs+1, 0)); // 文字列の長さ +1 分の配列の長さを確保する

        for (uint16_t r=0; r<ys; ++r) { // 行に関するループ
            for (uint16_t c=0; c<xs; ++c) { // 列に関するループ
                if (unlikely(x[c] == y[r])) { // 文字が一致する場合
                    table[r+1][c+1] = table[r][c] + 1;
                } else {
                    table[r+1][c+1] = std::max(table[r][c+1], table[r+1][c]);
                }
            }
        }
        
        std::cout << table[ys][xs] << "\n";
    }
}
accuracy: 1
time_ms: 30
memory_kb: 5344
final_rank: 2

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

int lcs(string& x, string& y)
{
    vector<vector<int>> dp(x.length()+1, vector<int>(y.length()+1));

    for(int i = 0; i <= (int)x.length(); i++)
        for(int j = 0; j <= (int)y.length(); j++)
        {
            if(i == 0 || j == 0)
            {
                dp[i][j] = 0;
            }
            else if(x[i-1] == y[j-1])
            {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    
    return dp[x.length()][y.length()];
}

int main()
{
    int q;
    cin >> q;
    for(int query = 0; query < q; query++)
    {
        string x, y;
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
}
accuracy: 1
time_ms: 40
memory_kb: 6980
final_rank: 14

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

int lcs(char* A, char* B) {
    int m = strlen(A);
    int n = strlen(B);
    int L[m+1][n+1];
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            if (i == 0 || j == 0) {
                L[i][j] = 0;
            } else if (A[i-1] == B[j-1]) {
                L[i][j] = L[i-1][j-1] + 1;
            } else {
                L[i][j] = max(L[i-1][j], L[i][j-1]);
            }
        }
    }
    return L[m][n];
}

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        char A[1000], B[1000];
        cin >> A >> B;
        int result = lcs(A, B);
        cout << result << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7272
final_rank: 4

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

using namespace std;

struct Init {
  Init() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
} init;

#ifdef LOCAL
#define d(x) cout << "\033[36m" << #x << "\033[0m" << " = " << (x) << '\n'
#else
#define d(x) ((void)0)
#endif

using ll = long long;
using i128 = __int128;
template <class T>
using pq_max = priority_queue<T>;
template <class T>
using pq_min = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using vc = vector<T>;
#define all(x) (x).begin(), (x).end()
#define len(x) ll(x.size())
#define eb emplace_back
#define rep(i, a, b) for (ll i = (a); i < (b); i++)

template <typename T, typename U>
T SUM(const U& A) {
  return std::accumulate(A.begin(), A.end(), T{});
}
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))

template <class C, class T>
inline long long LB(const C& c, const T& x) {
  return lower_bound(c.begin(), c.end(), x) - c.begin();
}
template <class C, class T>
inline long long UB(const C& c, const T& x) {
  return upper_bound(c.begin(), c.end(), x) - c.begin();
}
template <class T, class S>
inline bool chmax(T& a, const S& b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T& a, const S& b) {
  return (a > b ? a = b, 1 : 0);
}
template <typename T, typename U>
vector<T> cumsum(const vector<U>& A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  for (int i = 0; i < N; i++) {
    B[i + 1] = B[i] + A[i];
  }
  if (off == 0) B.erase(B.begin());
  return B;
}
void solve() {
  string a, b;
  cin >> a >> b;
  vc<vc<int>> dp(len(a) + 1, vc<int>(len(b) + 1));
  rep(i, 1, len(a) + 1) rep(j, 1, len(b) + 1) {
    if (a[i - 1] == b[j - 1]) chmax(dp[i][j], dp[i - 1][j - 1] + 1);
    chmax(dp[i][j], dp[i - 1][j]);
    chmax(dp[i][j], dp[i][j - 1]);
  }
  cout << dp[len(a)][len(b)] << '\n';
}
int main() {
  int n;
  cin >> n;
  while (n--) solve();

  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 6940
final_rank: 13

code_snippet: #include <bits/stdc++.h>
#pragma GCC target("avx2")
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#pragma GCC optimize("unroll-loops")

#ifdef ONLINE_JUDGE
#include <boost/multiprecision/cpp_int.hpp>
#include <atcoder/all>
#endif
#ifdef LOCAL
#define GLIBCXX_DEBUG
#define endl endl<<flush
#else
#define endl "\n"
#endif
using namespace std;using ll=long long;using ull=unsigned long long;using dl=long double;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define rrep(i,n) for(ll i=1; i<=(n); i++)
#define drep(i,n) for(ll i=(n)-1; i>=0; i--)
#define xfor(i,s,e) for(ll i=(s); i<(e); i++)
#define rxfor(i,s,e) for(ll i=(s); i<=(e); i++)
#define dfor(i,s,e) for(ll i=(s)-1; i>=(e); i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define popcnt(s) ll(__popcount<ull>(uint64_t(s)))
template<typename T>istream&operator>>(istream&is,pair<T,T>&v){is>>v.first>>v.second;return is;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(auto&in:v)is>>in;return is;}
template<typename T, typename U>ostream&operator<<(ostream&os,pair<T,U>&v){os<<v.first<<" "<<v.second;return os;}
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(auto&in:v)os<<in<<' ';return os;}
ll modpow(ll a, ll b, ll mod) {ll res = 1;while (b > 0) {if (b & 1) res = (res * a) % mod;a = (a * a) % mod;b >>= 1;}return res;}
ll powl(ll a, ll b) {ll res = 1;while (b > 0) {if (b & 1) res = (res * a);a = (a * a);b >>= 1;}return res;}
#define pow2(a) (a)*(a)
/*MOD MUST BE A PRIME NUMBER!!*/ll moddiv(const ll a, const ll b, const ll mod) {ll modinv = modpow(b, mod-2, mod);return (a * modinv) % mod;}
constexpr ll INF = 2e15;
ll nC2(const ll i){return i>2?i*(i-1)/2:0;}ll nC3(const ll i){return i>3?i*(i-1)*(i-2)/6:0;}ll nC4(const ll i){return i>4?i*(i-1)*(i-2)*(i-3)/24:0;}ll nC5(const ll i){return i>5?i*(i-1)*(i-2)*(i-3)*(i-4)/120:0;}ll nC6(const ll i){return i>6?i*(i-1)*(i-2)*(i-3)*(i-4)*(i-5)/720:0;}
void warshall_floyd(vector<vector<ll>>& dist) {const ull n = dist.size();rep(k, n) rep(i, n) rep(j, n) {dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);}}
#define YES {cout<<"Yes\n";return 0;}
#define NO {cout<<"No\n";return 0;}
#define yn YES else NO
#ifdef ONLINE_JUDGE
using lll = boost::multiprecision::cpp_int;
//using lll = boost::multiprecision::int128_t;
using namespace atcoder;
//using mint = modint1000000007;
using mint = modint998244353;
//using mint = modint; // custom mod
//atcoder::modint::set_mod(m);
// DSU == UnionFind
#endif
#define vc vector
using P = pair<ll, ll>;using vl = vc<ll>;using vb=vc<bool>;using vs=vc<string>;using vvl=vc<vl>;using vp=vc<P>;
template<typename T>void cs(vector<T>&v){xfor(i,1,v.size())v[i]+=v[i-1];}

vl dx = {-1, 1, 0, 0, -1, 1, -1, 1};
vl dy = {0, 0, 1, -1, -1, -1, 1, 1};

constexpr ll mod = 998244353;

void solve() {
    string x,y;
    cin>>x>>y;
    vvl dp(x.size()+1, vl(y.size()+1, -INF));
    dp[0][0]=0;
    rep(i,x.size())rep(j,y.size()){
        if (x[i]==y[j]){
            ++dp[i][j];
            chmax(dp[i+1][j+1], dp[i][j]);
        } else {
            chmax(dp[i+1][j+1], dp[i][j]);
            chmax(dp[i+1][j], dp[i][j]);
            chmax(dp[i][j+1], dp[i][j]);
        }
    }
    rep(i,y.size()){
        chmax(dp[x.size()][i+1], dp[x.size()][i]);
    }
    rep(i, x.size()) {
        chmax(dp[i+1][y.size()], dp[i][y.size()]);
    }

    cout << dp[x.size()][y.size()] << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(50);

    ll n = 1;
    cin >> n;
    while (n--) {
        solve();
    }
}
accuracy: 1
time_ms: 80
memory_kb: 11056
final_rank: 20

code_snippet: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main(){
    int q;
    cin >> q;

    for (int i=0; i<q; i++){
        string X, Y;
        cin >> X;
        cin >> Y;

        int x_length = X.length();
        int y_length = Y.length();

        vector<vector<int>> dp(x_length+1, vector<int>(y_length+1, 0));
        
        for (int x=0; x<x_length; x++){
            for (int y=0; y<y_length; y++){
                if (X[x] == Y[y]) dp[x+1][y+1] = dp[x][y]+1;
                dp[x+1][y+1] = max(dp[x+1][y+1], dp[x+1][y]);
                dp[x+1][y+1] = max(dp[x+1][y+1], dp[x][y+1]);
            }
        }
        cout << dp[x_length][y_length] << endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 7396
final_rank: 10

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

int main ()
{
    int t;
    cin>>t;
    while(t--)
   {
    string s1,s2;
    cin >> s1>>s2;
    int n=s1.size() , m= s2.size();
    int arr[n+1][m+1];
    for (int i =0;i<=n;i++)
    {
        arr[i][0]=0;
    }
    for (int i=0;i<=m;i++)
    {
        arr[0][i]=0;
    }
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            if (s1[i-1]==s2[j-1])
            {
                arr[i][j]=arr[i-1][j-1]+1;
            }
            else{
                if(arr[i-1][j]>= arr[i][j-1])
                {
                    arr[i][j]= arr[i-1][j];
                }
                else{
                    arr[i][j]= arr[i][j-1];
                }
            }
        }
    }
    cout <<arr[n][m] << endl;
  }


    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7188
final_rank: 3

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include<sstream>
#include<list>
#include<iomanip>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <bitset>
#include <cassert>
#include <stdlib.h>
#include <stdio.h>
#include <random>
#include <chrono>
using namespace std;
const long long LINF = 3e18 + 7;
const int MAX_N = 5000010;
const int MAX_W = 10002;
const int MAX_ARRAYK = 100000;
double PI = 3.14159265358979323846;
const int INF = 2147483647;
//using ll = long long;

int Q;
string X;
string Y;


int main() {

	cin >> Q;
	for (int q = 0; q < Q; q++) {
		cin >> X;
		cin >> Y;

		vector<vector<int>> dp(X.length() + 1, vector<int>(Y.length() + 1));

		for (int i = 0; i < X.length(); i++) {
			for (int j = 0; j < Y.length(); j++) {
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
				if (X[i] == Y[j]) {
					dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
				}
			}
		}
		cout << dp[X.length()][Y.length()] << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 7300
final_rank: 9

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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    string s1, s2;
    cin >> s1 >> s2;
    int n = s1.size(), m = s2.size();
    int a[n+1][m+1];
    char track[n+1][m+1];
    for(int i=0; i<=n; i++)
    {
        a[i][0] = 0;
    }
    for(int i=0; i<=m; i++)
    {
        a[0][i] = 0;
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(s1[i-1] == s2[j-1])
            {
                a[i][j] = a[i-1][j-1] + 1;
                track[i][j] = 'D';
            }
            else
            {
                if(a[i-1][j] >= a[i][j-1])
                {
                    a[i][j] = a[i-1][j];
                    track[i][j] = 'U';
                }
                else
                {
                    a[i][j] = a[i][j-1];
                    track[i][j] = 'L';
                }
            }
        }
    
    }
    cout << a[n][m] << endl;
    }
    
}
accuracy: 1
time_ms: 20
memory_kb: 8224
final_rank: 7

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

int main(){
    int q;
    cin >> q;

    for(int i=0; i<q; i++){
        string s, t;
        cin >> s >> t;
        int ss = (int)s.size();
        int tt = (int)t.size();
        vector<vector<int>> dp(ss+1, vector<int>(tt+1, 0));
        
        for(int i=1; i<=ss; i++){
            for(int j=1; j<=tt; j++){
                if(s[i-1] == t[j-1])dp[i][j] = dp[i-1][j-1]+1;
                else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }
        }
        cout << dp[ss][tt] << endl;
    }
}
accuracy: 1
time_ms: 30
memory_kb: 7400
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(T) T.begin(), T.end()
using ll = long long;
using P = pair<int, int>;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
void chmax(ll& x, ll y) { x = max(x, y); }
void chmin(ll& x, ll y) { x = min(x, y); }

void solve() {
    string x, y;
    cin >> x >> y;
    ll n = x.size(), m = y.size();
    vector dp(n + 1, vector<ll>(m + 1));
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, m) {
            if (x[i] == y[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1);
            chmax(dp[i + 1][j + 1], dp[i + 1][j]);
            chmax(dp[i + 1][j + 1], dp[i][j + 1]);
        }
    }
    cout << dp[n][m] << '\n';
}

int main() {
    // LCS
    ll t;
    cin >> t;
    rep(ti, t) solve();
}
accuracy: 1
time_ms: 60
memory_kb: 11264
final_rank: 19