Language: C++

#include <bits/stdc++.h>

using namespace std;

int n,w;
int dp[3001][3001];
pair<int,int> index[3001][3001];

void solve(){
    string a,b;
    cin >> a;
    cin >> b;

    for(int i = 0;i <= a.length();i++){
        for(int j = 0;j <= b.length();j++){
            dp[i][j] = 0;
            index[i][j] = make_pair(-1,-1);
        }
    }
    for(int i = 0;i < a.length();i++){
        for(int j = 0;j < b.length();j++){
            if(a[i] == b[j]){
                dp[i+1][j+1] = dp[i][j]+1;
                index[i+1][j+1] = make_pair(i,j);
            }
            else{
                if(dp[i][j+1] > dp[i+1][j]){
                    dp[i+1][j+1] = dp[i][j+1];
                    index[i+1][j+1] = index[i][j+1];
                }
                else{
                    dp[i+1][j+1] = dp[i+1][j];
                    index[i+1][j+1] = index[i+1][j];
                }
            }
        }
    }
    string ans = "";
    pair<int,int> rev = index[a.length()][b.length()];
    while(rev.first >= 0){
        ans = a[rev.first] + ans;
        rev = index[rev.first][rev.second];
    }
    cout << ans << endl;
}

int main(){
    solve();
}


Compiler output:
a.cc:7:31: error: 'std::pair<int, int> index [3001][3001]' redeclared as different kind of entity
    7 | pair<int,int> index[3001][3001];
      |                               ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:1:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void solve()':
a.cc:17:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   17 |             index[i][j] = make_pair(-1,-1);
      |                  ^
a.cc:24:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   24 |                 index[i+1][j+1] = make_pair(i,j);
      |                      ^
a.cc:29:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   29 |                     index[i+1][j+1] = index[i][j+1];
      |                          ^
a.cc:29:44: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   29 |                     index[i+1][j+1] = index[i][j+1];
      |                                            ^
a.cc:33:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   33 |                     index[i+1][j+1] = index[i+1][j];
      |                          ^
a.cc:33:44: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   33 |                     index[i+1][j+1] = index[i+1][j];
      |                                            ^
a.cc:39:30: error: invalid types '<unresolved overloaded function type>[std::__cxx11::basic_string<char>::size_type {aka long unsigned int}]' for array subscript
   39 |     pair<int,int> rev = index[a.length()][b.length()];
      |                              ^
a.cc:42:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   42 |         rev = index[rev.first][rev.second];
      |                    ^