Language: C++

#include<bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define ll long long
#define pb push_back
#define mkp make_pair
#define inf 1e9
#define rn 100007
#define ppi pair<int,int>
#define mod 1000000007

int n,k,dp[3008][3008];
ppi next[3008][3008];
string s1,s2;
int fun(int i,int j)
{
    if(i>=s1.size()||j>=s2.size())
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    int mx=-1,a,b;
    if(s1[i]==s2[j])
    {
        next[i][j]= {i+1,j+1};
        mx=fun(i+1,j+1)+1;
    }
    else
    {
        a=fun(i+1,j),b=fun(i,j+1);
        if(a>b)
        {
            mx=a;
            next[i][j]= {i+1,j};
        }
        else
        {

            mx=b;
            next[i][j]= {i,j+1};
        }
    }
    return dp[i][j]=mx;
}
void print()
{
    int i=0,j=0,a,b;
    while(i!=-1&&j!=-1)
    {
        if(s1[i]==s2[j])
            cout<<s1[i];
        a=next[i][j].first,b=next[i][j].second;
        i=a,j=b;
    }
    cout<<endl;

}
int main()
{
    cin>>s1>>s2;
    memset(dp,-1,sizeof dp);
    memset(next,-1,sizeof next);
    fun(0,0);
    print();
}


Compiler output:
a.cc: In function 'int fun(int, int)':
a.cc:25:9: error: reference to 'next' is ambiguous
   25 |         next[i][j]= {i+1,j+1};
      |         ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:14:5: note:                 'std::pair<int, int> next [3008][3008]'
   14 | ppi next[3008][3008];
      |     ^~~~
a.cc:34:13: error: reference to 'next' is ambiguous
   34 |             next[i][j]= {i+1,j};
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:14:5: note:                 'std::pair<int, int> next [3008][3008]'
   14 | ppi next[3008][3008];
      |     ^~~~
a.cc:40:13: error: reference to 'next' is ambiguous
   40 |             next[i][j]= {i,j+1};
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:14:5: note:                 'std::pair<int, int> next [3008][3008]'
   14 | ppi next[3008][3008];
      |     ^~~~
a.cc: In function 'void print()':
a.cc:52:11: error: reference to 'next' is ambiguous
   52 |         a=next[i][j].first,b=next[i][j].second;
      |           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:14:5: note:                 'std::pair<int, int> next [3008][3008]'
   14 | ppi next[3008][3008];
      |     ^~~~
a.cc:52:30: error: reference to 'next' is ambiguous
   52 |         a=next[i][j].first,b=next[i][j].second;
      |                              ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:14:5: note:                 'std::pair<int, int> next [3008][3008]'
   14 | ppi next[3008][3008];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:62:12: error: reference to 'next' is ambiguous
   62 |     memset(next,-1,sizeof next);
      |            ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:14:5: note:                 'std::pair<int, int> next [3008][3008]'
   14 | ppi next[3008][3008];
      |     ^~~~
a.cc:62:27: error: reference to 'next' is ambiguous
   62 |     memset(next,-1,sizeof next);
      |                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:14:5: note:                 'std::pair<int, int> next [3008][3008]'
   14 | ppi next[3008][3008];
      |     ^~~~