Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long LL;
const LL N=21,M=(1<<19)+3,mo=1e9+7;

int dir[N][N],m2[N],next[N];
int n,m,k,a,b,c;
LL f[2][N][M],g[N][M];

int main()
{
	cin>>n>>m>>k; --n;
	fo(i,1,k){
		scanf("%d%d%d",&a,&b,&c);
		dir[a][b]=c+1;
	}
	int u=0,v;
	f[0][0][0]=1;
	m2[1]=1;
	fo(i,2,n+1)m2[i]=m2[i-1]<<1;
	int zd=(m2[n]<<1)-1;
	fo(p,1,m){
		v=u^1;
		fo(l,0,n)fo(i,0,zd)f[v][l][i]=0;
		fo(l,0,n)fo(i,0,zd)g[l][i]=0;
		fd(i,zd,0){
			LL ok=f[u][0][i]%mo; next[n]=n+1;
			fd(l,n,2)if(i&m2[l])next[l-1]=l;else next[l-1]=next[l];
    		if(!i)g[0][0]=ok;
			fo(l,1,n){
				if((i&m2[l])==0&&dir[p][l]!=1&&next[l]!=n+1)
				f[u][l][(i^m2[next[l]])^m2[l]]=f[u][l][(i^m2[next[l]])^m2[l]]+ok;
				ok=(f[u][l][i]+ok)%mo;
				if(dir[p][l]&&(((i&m2[l])>0)-(dir[p][l]==2)))break;
				if(next[l]==n+1&&(i&m2[l])>0)g[l][i]=ok;
			}
		}
		fo(i,0,n-1)
		fo(l,0,zd)if(g[i][l]){
			g[i][l]=g[i][l]%mo;
			if(dir[p][i+1]!=2)g[i+1][l]=g[i+1][l]+g[i][l];
			if(dir[p][i+1]!=1)g[i+1][l^m2[i+1]]=g[i+1][l^m2[i+1]]+g[i][l];
		}
		fo(i,0,zd)f[v][0][i]=g[n][i];
		u=v;
	}
	LL ans=0;
	fo(i,0,zd)ans=(ans+f[v][0][i])%mo;
	cout<<ans;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:46: error: reference to 'next' is ambiguous
   34 |                         LL ok=f[u][0][i]%mo; next[n]=n+1;
      |                                              ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:13:21: note:                 'int next [21]'
   13 | int dir[N][N],m2[N],next[N];
      |                     ^~~~
a.cc:35:45: error: reference to 'next' is ambiguous
   35 |                         fd(l,n,2)if(i&m2[l])next[l-1]=l;else next[l-1]=next[l];
      |                                             ^~~~
/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:13:21: note:                 'int next [21]'
   13 | int dir[N][N],m2[N],next[N];
      |                     ^~~~
a.cc:35:62: error: reference to 'next' is ambiguous
   35 |                         fd(l,n,2)if(i&m2[l])next[l-1]=l;else next[l-1]=next[l];
      |                                                              ^~~~
/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:13:21: note:                 'int next [21]'
   13 | int dir[N][N],m2[N],next[N];
      |                     ^~~~
a.cc:35:72: error: reference to 'next' is ambiguous
   35 |                         fd(l,n,2)if(i&m2[l])next[l-1]=l;else next[l-1]=next[l];
      |                                                                        ^~~~
/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:13:21: note:                 'int next [21]'
   13 | int dir[N][N],m2[N],next[N];
      |                     ^~~~
a.cc:38:64: error: reference to 'next' is ambiguous
   38 |                                 if((i&m2[l])==0&&dir[p][l]!=1&&next[l]!=n+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:13:21: note:                 'int next [21]'
   13 | int dir[N][N],m2[N],next[N];
      |                     ^~~~
a.cc:39:47: error: reference to 'next' is ambiguous
   39 |                                 f[u][l][(i^m2[next[l]])^m2[l]]=f[u][l][(i^m2[next[l]])^m2[l]]+ok;
      |                                               ^~~~
/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:13:21: note:                 'int next [21]'
   13 | int dir[N][N],m2[N],next[N];
      |                     ^~~~
a.cc:39:78: error: reference to 'next' is ambiguous
   39 |                                 f[u][l][(i^m2[next[l]])^m2[l]]=f[u][l][(i^m2[next[l]])^m2[l]]+ok;
      |                                                                              ^~~~
/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:13:21: note:                 'int next [21]'
   13 | int dir[N][N],m2[N],next[N];
      |                     ^~~~
a.cc:42:36: error: reference to 'next' is ambiguous
   42 |                                 if(next[l]==n+1&&(i&m2[l])>0)g[l][i]=ok;
      |                                    ^~~~
/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:13:21: note:                 'int next [21]'
   13 | int dir[N][N],m2[N],next[N];
      |                     ^~~~