#include #include #include using namespace std; int main() { int n; string a, b; cin >> n >> a >> b; vector d(n + 1, 0); for(int i = 0; i < n; ++i) { int m = 0; int last = 0; for(int j = 0; j < n; ++j) { auto t = max({m, d[j + 1], last + (a[i] == b[j])}); last = d[j + 1]; m = d[j + 1] = t; } } // This gives a wrong answer currently, but it will TLE before that time anyway. cout << d.back() << endl; }