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];
struct stt
{
    int f,s;
};
stt 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].f=i+1,next[i][j].s=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].f=i+1,next[i][j].s=j;
        }
        else
        {

            mx=b;
            next[i][j].f=i,next[i][j].s=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].f,b=next[i][j].s;
        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:29:9: error: reference to 'next' is ambiguous
   29 |         next[i][j].f=i+1,next[i][j].s=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:18:5: note:                 'stt next [3008][3008]'
   18 | stt next[3008][3008];
      |     ^~~~
a.cc:29:26: error: reference to 'next' is ambiguous
   29 |         next[i][j].f=i+1,next[i][j].s=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:18:5: note:                 'stt next [3008][3008]'
   18 | stt next[3008][3008];
      |     ^~~~
a.cc:38:13: error: reference to 'next' is ambiguous
   38 |             next[i][j].f=i+1,next[i][j].s=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:18:5: note:                 'stt next [3008][3008]'
   18 | stt next[3008][3008];
      |     ^~~~
a.cc:38:30: error: reference to 'next' is ambiguous
   38 |             next[i][j].f=i+1,next[i][j].s=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:18:5: note:                 'stt next [3008][3008]'
   18 | stt next[3008][3008];
      |     ^~~~
a.cc:44:13: error: reference to 'next' is ambiguous
   44 |             next[i][j].f=i,next[i][j].s=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:18:5: note:                 'stt next [3008][3008]'
   18 | stt next[3008][3008];
      |     ^~~~
a.cc:44:28: error: reference to 'next' is ambiguous
   44 |             next[i][j].f=i,next[i][j].s=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:18:5: note:                 'stt next [3008][3008]'
   18 | stt next[3008][3008];
      |     ^~~~
a.cc: In function 'void print()':
a.cc:56:11: error: reference to 'next' is ambiguous
   56 |         a=next[i][j].f,b=next[i][j].s;
      |           ^~~~
/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:18:5: note:                 'stt next [3008][3008]'
   18 | stt next[3008][3008];
      |     ^~~~
a.cc:56:26: error: reference to 'next' is ambiguous
   56 |         a=next[i][j].f,b=next[i][j].s;
      |                          ^~~~
/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:18:5: note:                 'stt next [3008][3008]'
   18 | stt next[3008][3008];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:66:12: error: reference to 'next' is ambiguous
   66 |     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:18:5: note:                 'stt next [3008][3008]'
   18 | stt next[3008][3008];
      |     ^~~~
a.cc:66:27: error: reference to 'next' is ambiguous
   66 |     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:18:5: note:                 'stt next [3008][3008]'
   18 | stt next[3008][3008];
      |     ^~~~