Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T> void max_self(T& a, T b) {
    a = max(a, b);
}
 
// dp[n][m]
 
bool first_row_or_column(pair<int,int> p) {
    return p.first == 0 || p.second == 0;
}
 
const int INF = 1e9 + 5;
 
int main() {
    string a, b;
    cin >> a >> b;
    vector<vector<pair<int,pair<int,int>>>> dp(a.length() + 1,
        vector<pair<int,pair<int,int>>>(b.length() + 1, {-INF,{0,0}}));
    dp[0][0] = {0, {0,0}};
    // dp[i][j] - the max total length so far
    for(int i = 0; i < (int) a.length(); ++i) {
        for(int j = 0; j < (int) b.length(); ++j) {
            if(a[i] == b[j]) {
                max_self(dp[i+1][j+1], make_pair(dp[i][j].first + 1, make_pair(i,j)));
            }
            max_self(dp[i+1][j], make_pair(dp[i][j].first, make_pair(i,j)));
            max_self(dp[i][j+1], make_pair(dp[i][j].first, make_pair(i,j)));
        }
    }
    pair<int,pair<int,int>> answer = {0,{0,0}};
    for(int i = 0; i <= (int) a.length(); ++i) {
        for(int j = 0; j <= (int) b.length(); ++j) {
            max_self(answer, make_pair(dp[i][j].first, make_pair(i, j)));
        }
    }
    string s;
    pair<int,int> cur = answer.second;
    while(!first_row_or_column(cur)) {
        int i = cur.first;
        int j = cur.second;
        pair<int,int> previous = dp[i][j].second; // a cell from which we came to (i,j)
        
        if(previous == make_pair(i - 1, j - 1)) {
            assert(a[i-1] == b[j-1]);
            s += a[i-1];
        }
        cur = previous;
    }
    
    reverse(s.begin(), s.end());
    cout << s << endl;
}
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T> void max_self(T& a, T b) {
    a = max(a, b);
}

// dp[n][m]

bool first_row_or_column(pair<int,int> p) {
    return p.first == 0 || p.second == 0;
}

const int INF = 1e9 + 5;

int main() {
    string a, b;
    cin >> a >> b;
    vector<vector<pair<int,pair<int,int>>>> dp(a.length() + 1,
        vector<pair<int,pair<int,int>>>(b.length() + 1, {-INF,{0,0}}));
    dp[0][0] = {0, {0,0}};
    // dp[i][j] - the max total length so far
    for(int i = 0; i < (int) a.length(); ++i) {
        for(int j = 0; j < (int) b.length(); ++j) {
            if(a[i] == b[j]) {
                max_self(dp[i+1][j+1], make_pair(dp[i][j].first + 1, make_pair(i,j)));
            }
            max_self(dp[i+1][j], make_pair(dp[i][j].first, make_pair(i,j)));
            max_self(dp[i][j+1], make_pair(dp[i][j].first, make_pair(i,j)));
        }
    }
    pair<int,pair<int,int>> answer = {0,{0,0}};
    for(int i = 0; i <= (int) a.length(); ++i) {
        for(int j = 0; j <= (int) b.length(); ++j) {
            max_self(answer, make_pair(dp[i][j].first, make_pair(i, j)));
        }
    }
    string s;
    pair<int,int> cur = answer.second;
    while(!first_row_or_column(cur)) {
        int i = cur.first;
        int j = cur.second;
        pair<int,int> previous = dp[i][j].second; // a cell from which we came to (i,j)
        
        if(previous == make_pair(i - 1, j - 1)) {
            assert(a[i-1] == b[j-1]);
            s += a[i-1];
        }
        cur = previous;
    }
    
    reverse(s.begin(), s.end());
    cout << s << endl;
}















Compiler output:
a.cc:55:1: error: expected declaration before '}' token
   55 | }
      | ^
a.cc:59:28: error: redefinition of 'template<class T> void max_self(T&, T)'
   59 | template <typename T> void max_self(T& a, T b) {
      |                            ^~~~~~~~
a.cc:4:28: note: 'template<class T> void max_self(T&, T)' previously declared here
    4 | template <typename T> void max_self(T& a, T b) {
      |                            ^~~~~~~~
a.cc:65:6: error: redefinition of 'bool first_row_or_column(std::pair<int, int>)'
   65 | bool first_row_or_column(pair<int,int> p) {
      |      ^~~~~~~~~~~~~~~~~~~
a.cc:10:6: note: 'bool first_row_or_column(std::pair<int, int>)' previously defined here
   10 | bool first_row_or_column(pair<int,int> p) {
      |      ^~~~~~~~~~~~~~~~~~~
a.cc:69:11: error: redefinition of 'const int INF'
   69 | const int INF = 1e9 + 5;
      |           ^~~
a.cc:14:11: note: 'const int INF' previously defined here
   14 | const int INF = 1e9 + 5;
      |           ^~~
a.cc:71:5: error: redefinition of 'int main()'
   71 | int main() {
      |     ^~~~
a.cc:16:5: note: 'int main()' previously defined here
   16 | int main() {
      |     ^~~~