Language: C++

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll index[ohara];
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    rep(i,n){
        cin>>a[i];
        index[a[i]-1]=i;
    }
    multiset<ll> st;
    st.insert(LINF);
    st.insert(n);
    st.insert(-LINF);
    st.insert(-1);
    st.insert(index[n-1]);
    rrrep(ii,n-2,0){
        ll i,j,k,l;
        int jok=1,iok=1,kok=1,lok=1;
        auto it=st.upper_bound(index[ii]);
        j=*it;
        it++;
        l=*it;
        it=st.lower_bound(index[ii]);
        it--;
        k=*it;
        it--;
        i=*it;
        //cout<<i<<" "<<j<<" "<<k<<" "<<l<<"\n";

        if(j==LINF){
            j=0;l=0;
            jok=0;lok=0;
        }
        if(k==-LINF){
            k=0;i=0;
            kok=0;iok=0;
        }
        if(l==LINF){
            l=0;
            lok=0;
        }
        if(i==-LINF){
            i=0;
            iok=0;
        }
        if(iok)i=k-i;
        if(kok==1)k=index[ii]-k;
        if(lok)l=l-j;
        if(jok)j=j-index[ii];
        //cout<<ii<<" "<<i<<" "<<j<<" "<<k<<" "<<l<<"\n";
        ans+=(i*j+k*l)*(ii+1);
        st.insert(index[ii]);
    }
    Cout(ans);
    return 0;
}

Compiler output:
a.cc:35:15: error: 'll index [1000010]' redeclared as different kind of entity
   35 | ll index[ohara];
      |               ^
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 'int main()':
a.cc:49:14: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   49 |         index[a[i]-1]=i;
      |              ^
a.cc:56:20: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   56 |     st.insert(index[n-1]);
      |                    ^
a.cc:60:37: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   60 |         auto it=st.upper_bound(index[ii]);
      |                                     ^
a.cc:64:32: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   64 |         it=st.lower_bound(index[ii]);
      |                                ^
a.cc:88:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   88 |         if(kok==1)k=index[ii]-k;
      |                          ^
a.cc:90:25: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   90 |         if(jok)j=j-index[ii];
      |                         ^
a.cc:93:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   93 |         st.insert(index[ii]);
      |                        ^