Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int n;
int k=0;
int p[3010];
int left[3010]={};
int deru[3010]={};
int dezu[3010];
int big[3010]={};
int kosu[3010]={};
ll mae;
ll kazu;
ll sum;
ll ans=0;
int main()
{
	cin >> n;
	rep(i, n)
	{
		cin >> p[i];
		if(p[i]!=0)
		{
			deru[p[i]-1]=1;
			left[i+1]=left[i];
		}
		else
		{
			left[i+1]=left[i]+1;
		}
	}
	rep(i, n)
	{
		if(deru[i]==0)
		{
			dezu[k]=i;
			k++;
		}
	}
	rep(i, n)
	{
		if(deru[n-1-i]==0)
		{
			big[n-1-i]=big[n-i]+1;
		}
	}
	mae=1;
	repp(i, 1, k)
	{
		mae*=i;
		mae%=MOD;
	}
	kazu=(mae*k)%MOD;
	sum=(kazu*(kazu+1))%MOD;
	sum=(sum*500000004)%MOD;
	rep(i, n)
	{
		if(p[i]!=0)
		{
			rep(j, i)
			{
				if(p[i]<p[j])
				{
					kosu[i]++;
				}
			}
			ans+=(kosu[i]*kazu);
			ans+=(((big[p[i]-1]*left[i])%MOD)*mae)%MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:25: error: reference to 'left' is ambiguous
   32 |                         left[i+1]=left[i];
      |                         ^~~~
In file included from /usr/include/c++/14/streambuf:43,
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54,
                 from a.cc:1:
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:14:5: note:                 'int left [3010]'
   14 | int left[3010]={};
      |     ^~~~
a.cc:32:35: error: reference to 'left' is ambiguous
   32 |                         left[i+1]=left[i];
      |                                   ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:14:5: note:                 'int left [3010]'
   14 | int left[3010]={};
      |     ^~~~
a.cc:36:25: error: reference to 'left' is ambiguous
   36 |                         left[i+1]=left[i]+1;
      |                         ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:14:5: note:                 'int left [3010]'
   14 | int left[3010]={};
      |     ^~~~
a.cc:36:35: error: reference to 'left' is ambiguous
   36 |                         left[i+1]=left[i]+1;
      |                                   ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:14:5: note:                 'int left [3010]'
   14 | int left[3010]={};
      |     ^~~~
a.cc:75:45: error: reference to 'left' is ambiguous
   75 |                         ans+=(((big[p[i]-1]*left[i])%MOD)*mae)%MOD;
      |                                             ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:14:5: note:                 'int left [3010]'
   14 | int left[3010]={};
      |     ^~~~