criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N;
  cin>>N;
  vector<ll> P(N);
  ll point[N+1];
  for(ll i=0;i<N;++i) {
    cin>>P[i];
    point[P[i]] = i;
  }
  set<ll> st;
  st.insert(-1);
  st.insert(N);
  ll ans = 0;
  auto l=st.begin(), ll=st.begin(), r=st.end(), rr=st.end(), index=st.end();
  for(ll i=N;i>=1;--i) {
    st.insert(point[i]);
    index = st.find(point[i]);
    r = next(index);
    l = prev(index);
    if(*r==N) {
      if(*l==-1) {
        continue;
      }
      else {
        ll = prev(l);
        ans += i*(*r-*index)*(*l-*ll);
      }
    }
    else {
      rr = next(r);
      if(*l==-1) {
        ans += i*(*index-*l)*(*rr-*r);
      }
      else {
        ll = prev(l);
        ans += i*(*index-*l)*(*rr-*r)+i*(*l-*ll)*(*r-*index);
      }
    }
  }
  cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:9: error: expected ';' before 'i'
   40 |   for(ll i=N;i>=1;--i) {
      |         ^~
      |         ;
a.cc:40:14: error: 'i' was not declared in this scope
   40 |   for(ll i=N;i>=1;--i) {
      |              ^
Language: C++


#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
// #define MOD 1000000007
#define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int n;cin>>n;
  vector<int> vec (n,0);
  vector<int> pos (n+1,0);
  for (int i = 0; i < n; i++)
  {`
    cin>>vec[i];
    pos[vec[i]] = i;
  }
  multiset<int> st = {-1,-1,n,n};
  int res = 0;
  for (int i = n; i > 0; i--) 
  {
    st.insert(pos[i]);
    auto itr = st.lower_bound(pos[i]);
    auto l1 = prev(itr);//(前に小さい数のイテレーター)
    auto l2 = prev(l1);
    auto r1 = next(itr);//(次に大きい数のイテレーター)
    auto r2 = next(r1);
    res += ((*l1 - *l2)*(*r1 - pos[i]) + (*r2 - *r1)*(pos[i] - *l1))*vec[pos[i]];
    // DEBUG(res,"\n");
  }
  cout<<res<<endl;
  

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Compiler output:
a.cc:56:4: error: stray '`' in program
   56 |   {`
      |    ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
vector<int>BIT;
int sumUp(int a) {
  int ret = 0;
  while (a) {
    ret += BIT[a];
    a -= a & -a;
  }
  return ret;
}
void add(int n, int v, int N) {
  while (v <= N) {
    BIT[v] += n;
    v += v & -v;
  }
}
int main () {
  int N;
  cin >> N;
  BIT.assign(200002, 0);
  vector<int>P(N + 2);
  vector<int>F(N + 2);
  for (int i = 2; i <= N + 1; i ++) {
    cin >> P[i];
    F[P[i]] = i;
  }
  add(1, F[N], N + 2);
  add(1, 1, N + 2);
  add(1, N + 2, N + 2);
  int ans = 0;
  for (int i = N - 1; i >= 1; i --) {
    int mi = F[i];
    int ma = N + 2;
    int ke = sumUp(F[i]);
    while (ma != mi) {
      int mu = (ma + mi) / 2;
      if (sumUp(mu) < ke + 1) mi = mu + 1;
      else ma = mu;
    }
    R1 = mi;
    ma = N + 2;
    int R2 = N + 2;
    if (R1 != N + 2) {
      ke ++;
      while (ma != mi) {
        int mu = (ma + mi) / 2;
        if (sumUp(mu) < ke + 1) mi = mu + 1;
        else ma = mu;
      }
      R2 = mi;
    }
    mi = 0;
    ma = F[i];
    while (ma != mi) {
      int mu = (ma + mi) / 2;
      if (sumUp(mu) < ke) mi = mu + 1;
      else ma = mu;
    }
    L1 = ma;
    int L2 = 0;
    if (L1) {
      mi = 0;
      ke --;
      while (ma != mi) {
        int mu = (ma + mi) / 2;
        if (sumUp(mu) < ke) mi = mu + 1;
        else ma = mu;
      }
      L2 = mi;
    }
    int kj = F[i];
    ans += ((R1 - kj) * (L1 - L2) + (R2 - R1) * (kj - L1)) * i;
    add(1, kj, N + 2);
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:41:5: error: 'R1' was not declared in this scope; did you mean 'y1'?
   41 |     R1 = mi;
      |     ^~
      |     y1
a.cc:60:5: error: 'L1' was not declared in this scope; did you mean 'y1'?
   60 |     L1 = ma;
      |     ^~
      |     y1
Language: C++

#pragma once
#include <iostream>
#include <string>
#include <vector>
#include<limits>
#include<stack>
#include<queue>
#include<math.h>
#include <iomanip>

#define rep(i,n) for(auto i=0;i<(n);i++)
#define all(vs) (vs).begin(),(vs).end()
#define roundup(A,B) (A)/(B)+(A%B==0?0:1)
#define maximize(A,B) A=max((A),(B))
#define read(type,name) type name;cin>>name
#define ll long long

using namespace std;
template<typename T>
T MAX() { return numeric_limits<T>::max(); }

//二次元テーブル
template<typename T>
class Table {
public:
	Table(int height, int width, T value) {
		if (width < 0)throw std::exception("Width should be > 0");
		if (height < 0)throw std::exception("height should be > 0");
		this->wid = width;
		this->hgt = height;
		vs = new T[width * height];
		for (auto i = 0; i < width * height; i++)vs[i] = value;
	}
	Table(const Table& table) {
		hgt = table.hgt;
		wid = table.wid;
		vs = new T[hgt * wid];
		for (size_t i = 0; i < table.size(); i++) {
			vs[i] = table.vs[i];
		}
	}
	Table(Table&& table) {
		hgt = table.hgt;
		wid = table.wid;
		swap(vs, table.vs);
	}
	~Table() {
		if (vs)delete[] vs;
	}
	Table& operator=(const Table& table) {
		if (table == *this)return *this;
		this->wid = table.wid;
		this->hgt = table.hgt;
		if (vs)delete[] vs;
		vs = new T[wid * hgt];
		for (auto i = 0; i < wid * hgt; i++)vs[i] = table.vs[i];
	}
	Table& operator=(Table&& table) {
		wid = table.wid;
		hgt = table.hgt;
		swap(vs, table.vs);
	}
	inline T& at(int y, int x) {
		if (wid > x)throw out_of_range("x>width.");
		if (hgt > y)throw out_of_range("y>height.");
		return vs[x + y * wid];
	}
	int size()const { return wid * hgt; }
	int width()const { return wid; };
	int height()const { return hgt; };
	T* begin() { return vs; }
	T* end() { return vs + wid * hgt; }
	T& operator()(int y, int x) { return vs[x + y * wid]; }
	const T& operator()(int y, int x)const { return vs[x + y * wid]; }
private:
	int wid, hgt;
	T* vs;
};

Compiler output:
a.cc:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: C++

#include <std/bitc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<int, int>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
	ll n; cin >> n;
	vector<ll> pos(n+1);
	for(int i = 0; i < n; ++i){
		ll a; cin >> a;
		pos[a] = i+1;
	}

	ll ans = 0;
	set<ll> se{0, n+1};
	for(ll i = n; i > 0; --i){
		auto r1 = se.lower_bound(pos[i]);
		auto l1 = r1;
		--l1;

		ll num = 0;

		if (*l1 != 0) {
			auto l2 = l1;
			--l2;
			num += (*l1 - *l2) * (*r1 - pos[i]);
		}

		if (*r1 != n+1) {
			auto r2 = r1;
			++r2;
			num += (pos[i] - *l1) * (*r2 - *r1);
		}

		ans += num * i;
		se.insert(pos[i]);
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc:1:10: fatal error: std/bitc++.h: No such file or directory
    1 | #include <std/bitc++.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin >>N;
  int P[N];
  int ans=0;
  for(int i=0;i<N;++i){
    cin >> P[i];
  }
  int max=0;
  int max2=0;
  for(int i=0;i<N-1;++i) {
    for(int j=i+1;j<N;++j) {
      if(j==i+1) {
        if(P[i]>=P[j]) {
        max=P[i];
        max2=p[j];
        }else{
        max=P[j];
        max2=P[i];
        }
      }
      if(j>i+1) {
        if(P[j]>=max) {
          max2=max;
          max=P[j];
        }
        ans+=max2;
      }
    }
  }
  cout <<ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:14: error: 'p' was not declared in this scope
   17 |         max2=p[j];
      |              ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
using l = long;

l main(){
    l a,e,y,x,n,N;cin >> N;n=0;e=0;
    map<l,l> w;
    for(l i=0;i<N;i++){cin>>a;w[a]=i;}
    
    multiset<l> S;
    vector<l> d={-1,-1,N,N};
    for(l i=0;i<4;i++)S.insert(d[i]);

    for(l i=N;i>=1;i--){
        l k=w[i];
        S.insert(k);
        auto t=S.lower_bound(k),p=t,q=t,r=t,s=t;
        p--;p--;q--;r++;s++;s++;

        n+=(*q-*p)*(*r-k)+(k-*q)*(*s-*r);
        e+=n;
    }

    cout<<e<<endl;
}


Compiler output:
a.cc:5:1: error: '::main' must return 'int'
    5 | l main(){
      | ^
Language: C++

#include<iostream>
#include<numeric>
#include<set>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

uint64_t getZ() {
  uint64_t v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int const MAXN = 2e5;
int ix[MAXN], P[MAXN];

int main() {
  int N = getZ();
  for(int i = 0; i < N; ++i) P[i] = getZ();
  std::iota(ix, ix+N, 0);
  std::sort(ix, ix+N, [&](int l, int r){ return P[l] > P[r]; });
  int64_t ans = 0;
  std::multiset<int> S;
  S.insert(-1); S.insert(-1); S.insert(N); S.insert(N);
  for(auto i: ix) {
    int64_t p = P[i];
    auto it = S.lower_bound(i);
    int il1 = * --it, il2 = *--it;
    it = S.upper_bound(i);
    int ir1 = *it++, ir2 = *it;
    ans += p*((il1-il2)*(ir1-i) + (i-il1)*(ir2-ir1));
    S.insert(i);
  }
  fin(ans);
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:22:8: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
   22 |   std::sort(ix, ix+N, [&](int l, int r){ return P[l] > P[r]; });
      |        ^~~~
      |        qsort
Language: C

#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> o(N);
  iota(ALL(o), 0);

  sort(ALL(o), [A](int l, int r){
      return A[l] > A[r];
      });

  multiset<int> s;
  s.insert(-1); s.insert(N);
  s.insert(-1); s.insert(N);

  int ans = 0;
  REP(i, N){
    int I = o[i];
    auto it = s.upper_bound(I);
    int r1 = *it; it++;
    int r2 = *it; it--; it--;
    int l2 = *it; it--;
    int l1 = *it;
    
    ans += ((l2-l1)*(r1-I)+(I-l2)*(r2-r1))*A[I];
    s.insert(I);
  }

  cout << ans << "\n";

  return 0;
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;

int S[100010],T[100010],n,P[100010];

long long int  ans;
int main(){
  
	cin >> n;
  
	int p[100010];
	for (int i=1;i<=n;i++)
		cin>>a[i];
  
  for(int i=1;i<=n;i++){
		w[p[i]]=i;
    
		S[i]=i-1;
    
		T[i]=i+1;
	}
	
	for (int i=1;i<=n;i++){
      
		int b=S[P[i]],a=S[b];
      
		int c=T[P[i]],d=T[c];
      
		if (b!=0) ans += 1ll*(b-a)*(c-P[i])*i;
		if (c!=n+1) ans += 1ll*(d-c)*(P[i]-b)*i;
		
		S[c]=b;
		T[b]=c;
	}
	
	cout<<ans << endl;
	
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:22: error: 'a' was not declared in this scope
   13 |                 cin>>a[i];
      |                      ^
a.cc:16:17: error: 'w' was not declared in this scope
   16 |                 w[p[i]]=i;
      |                 ^
Language: C++


#include <iostream>
#include <vector>
using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> P(N);
  auto * const p = &P[0];
  for (int i = 0; i < N; ++i)
    cin >> p[i];
  long long sum = 0;

  auto Pcpy(P);
  std::sort(Pcpy.begin(), Pcpy.end(), std::greater<int>());
  const auto global_second = Pcpy[1];

  for (int i = 0, _i = N - 1; i < _i; ++i)
  {
    auto first = (p[i] < p[i + 1] ? p[i + 1] : p[i]);
    auto second = (p[i] < p[i + 1] ? p[i] : p[i + 1]);
    sum += second;
    int j = i + 2;
    for (; j < N; ++j)
    {
      if (global_second == second)
        break;
      if (second < p[j])
      {
        if (first < p[j])
        {
          second = first;
          first = p[j];
        }
        else
          second = p[j];
      }
      sum += second;
    }
    sum += (N - j)*global_second;
  }
  cout << sum;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:8: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
   17 |   std::sort(Pcpy.begin(), Pcpy.end(), std::greater<int>());
      |        ^~~~
      |        qsort
Language: C++

#include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>

#define fir first
#define sec second
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define All(s) (c).begin(), (c).end()
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long int ll;
const ll INF = 10241024;
int N;
vector<int> p(1e5+1);
void input(){
    cin >> N;
    rep(i,N){
        cin >> p[i];
        p[i]--;
        //cout << P[i] << endl;
    }
}

void solve(){
    input();
    vector<int> locate(N);

    rep(i,N){
        locate[P[i]] = i;
    }
    set<int> s;
    ll ans = 0;
    for(int i = N -1; i >= 0;i--){
        int x = locate[i];
        ll c = 0;
        {
            vector<int> l(2, -1);
            vector<int> r(2, N);
            s.insert(i);
            {
                auto it = s.find(i);
                rep(j, 2){
                    if(it == s.begin()) break;
                    --it;
                    l[j] = *it;
                }
             }
        
            {
                auto it = s.find(i);
                rep(j, 2){
                    ++it;
                    if(it == s.end()) break;
                    r[j] = *it;
                }
            }


            vector<int> ls(2);
            ls[0] = i - l[0];ls[1] = l[0] - l[1];
            vector<int> rs(2);
            rs[0] = r[0] - i;rs[1] = r[1] - r[0];

            c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
        }
            ans += c*(x+1);

    }
    return;
}
int main () {
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:37:16: error: 'P' was not declared in this scope
   37 |         locate[P[i]] = i;
      |                ^
Language: C++

#include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>

#define fir first
#define sec second
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define All(s) (c).begin(), (c).end()
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long int ll;
const ll INF = 10241024;
int N;
vector<int> P(1e5+1);
void input(){
    cin >> N;
    rep(i,N){
        cin >> P[i];
        p[i]--;
        //cout << P[i] << endl;
    }
}

void solve(){
    input();
    vector<int> locate(N);

    rep(i,N){
        locate[P[i]] = i;
    }
    set<int> s;
    ll ans = 0;
    for(int i = N -1; i >= 0;i--){
        int x = v[i];
        ll c = 0;

        vector<int> l(2, -1);
        vector<int> r(2, N);
        
        s.insert(i);
        auto it = s.find(i);
        rep(j, 2){
            if(it == s.begin()) break;
            --it;
            l[j] = *it;
        }

        auto it = s.find(i);
        rep(j, 2){
            ++it;
            if(it == s.end()) break;
            r[j] = *it;
        }

        vector<int> ls(2);
        ls[0] = i - l[0];ls[1] = l[0] - l[1];
        vector<int> rs(2);
        rs[0] = r[0] - i;rs[1] = r[1] - r[0];

        c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
        
        ans += c*(x+1);

    }
    return;
}
int main () {
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void input()':
a.cc:27:9: error: 'p' was not declared in this scope
   27 |         p[i]--;
      |         ^
a.cc: In function 'void solve()':
a.cc:42:17: error: 'v' was not declared in this scope
   42 |         int x = v[i];
      |                 ^
a.cc:56:14: error: conflicting declaration 'auto it'
   56 |         auto it = s.find(i);
      |              ^~
a.cc:49:14: note: previous declaration as 'std::_Rb_tree_const_iterator<int> it'
   49 |         auto it = s.find(i);
      |              ^~
Language: C++

#include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>

#define fir first
#define sec second
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define All(s) (c).begin(), (c).end()
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long int ll;
const ll INF = 10241024;
int N;
vector<int> P;
void input(){
    rep(i,N){
        cin >> P[i];
    }
}

void solve(){
    input();
    int ans = 0;

    for(int l=0;l<N-2;l++){
        int fir = max(P[l], P[l+1]);
        int sec = min(P[l], P[l+1]);

        ans += sec;

        for(int r=l+1;r<N;r++){
            if(P[r] <= sec)continue;
            else if(sec < P[r] && P[r] < fir){
                sec = P[r];
            }
            else if(firstt < P[r]){
                sec = P[r];
                swap(sec, fir);
            }
            ans += sec;
        }
    }

    cout << ans << endl;
    return;
}
int main () {
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:44:21: error: 'firstt' was not declared in this scope; did you mean 'first'?
   44 |             else if(firstt < P[r]){
      |                     ^~~~~~
      |                     first
Language: C++

#include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>

#define fir first
#define sec second
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define All(s) (c).begin(), (c).end()
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long int ll;
const ll INF = 10241024;
int N;
vector<int> P;
void input(){
    rep(i,N){
        cin >> P[i];
    }
}

void solve(){
    input();
    int ans = 0;

    for(int l=0;l<N-2;l++){
        int fir = max(P[l], P[l+1]);
        int sec = min(P[l], P[l+1]);

        ans += sec;

        for(int r=l+1;r<N;r++){
            if(P[r] <= second)continue;
            else if(sec < P[r] && p[r] < fir){
                sec = P[r];
            }
            else if(firstt < P[r]){
                sec = P[r];
                swap(sec, fir);
            }
            ans += sec;
        }
    }

    cout << ans << endl;
    return;
}
int main () {
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:41:35: error: 'p' was not declared in this scope
   41 |             else if(sec < P[r] && p[r] < fir){
      |                                   ^
a.cc:44:21: error: 'firstt' was not declared in this scope; did you mean 'first'?
   44 |             else if(firstt < P[r]){
      |                     ^~~~~~
      |                     first
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    int p[n+1];
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        p[t] = i+1;
    }
    long long ans = 0;
    multiset<int> s;
    s.insert(0);
    s.insert(0);
    s.insert(n+1);
    s.insert(n+1);
    s.insert(p[n];
    for(int i=n-1; i>1; i--){
        int w,x,y,z;
        auto u = upper_bound(s.begin(),s.end(),p[i]);
        y = *u;
        z = *(++u);
        u = upper_bound(s.begin(),s.end(),p[i]);
        x = *(--u);
        w = *(--u);
        ans += i*((x-w)*(y-p[i])+(p[i]-x)*(z-y));
        s.insert(p[i]);
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:18: error: expected ')' before ';' token
   19 |     s.insert(p[n];
      |             ~    ^
      |                  )
Language: C++

N=int(input())
P=list(map(int, input().split()))
ans=0
for i in range(N-1):
    max1=max(P[i],P[i+1])
    max2=min(P[i],P[i+1])
    ans+=max2
    for j in range(i+2,N):
        if max1<P[j]:
            max2=max1
            max1=P[j]
            ans+=max2
        elif max2<P[j] and P[j]<max1:
            max2=P[j]
            ans+=max2
        else:
            ans+=max2
print(ans)


Compiler output:
a.cc:1:1: error: 'N' does not name a type
    1 | N=int(input())
      | ^
Language: C++

#include <cstddef>
#include <iostream>
#include <vector>
#include <set>

#include <signal.h>
#define BOOST_STACKTRACE_USE_ADDR2LINE
#include <boost/stacktrace.hpp>

#define rep(i, n) for (size_t i = 0; i < n; ++i)
#define rev(i, n) for (size_t i = n - 1; i < n; --i)
#define as static_cast
typedef long long ll;
using namespace std;

void handler(int signum) {
  ::signal(signum, SIG_DFL);
  cout << boost::stacktrace::stacktrace() << endl;
  ::raise(SIGABRT);
}

int main(int, char const *[])
{
  ::signal(SIGSEGV, &handler);
  ::signal(SIGABRT, &handler);

  size_t n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  ll ans=0;
  set<size_t> s;
  vector<size_t> ix(n);
  rep(i, n) ix[as<size_t>(p[i]-1)]=i;
  rev (j, n) {
    size_t i=ix[j];
    ll c=0;

    s.insert(i);
    int w,x,y,z;

    { // find w, x
      vector<int> wx(2, -1);
      auto it=s.find(i);
      rev(k, 2) {
        if (it == s.begin()) break;
        --it;
        wx[k]=as<int>(*it);
      }
      w=wx[0];x=wx[1];
    }

    { // find y, z
      vector<int> yz(2, as<int>(n));
      auto it=s.find(i);
      rep(k, 2) {
        ++it;
        if (it == s.end()) break;
        yz[k]=as<int>(*it);
      }
      y=yz[0];z=yz[1];
    }

    c=(x-w)*(y-as<int>(i))+(as<int>(i)-x)*(z-y);
    ans+=as<int>(j+1)*c;
  }

  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc:8:10: fatal error: boost/stacktrace.hpp: No such file or directory
    8 | #include <boost/stacktrace.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100010];
long long ans;
struct pairr{
	int first;
	int second;
};
struct node{
	pairr pa;
	int pos;
};
//map<node,long long>mp;
long long turn(pairr p,int k){
	if(k>=n)return 0;
	if(a[k]>p.first)p.second=p.first,p.first=a[k];
	else if(a[k]>p.second)p.second==a[k];
	node x;
	x.pa.first=p.first;
	x.pa.second=p.second;
	x.pos=k;
	if(mp[x])return mp[x];
	mp[x]=p.second+turn(p,k+1);
	return mp[x];
}
int main(){
	ios_base::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-1;i++){
//		pair<int,int>p;
		pairr p;
		p.first=max(a[i],a[i+1]);
		p.second=min(a[i],a[i+1]);
		ans+=p.second;
		ans+=turn(p,i+2);
	}
	cout<<ans;
	return 0;
}


Compiler output:
a.cc: In function 'long long int turn(pairr, int)':
a.cc:24:12: error: 'mp' was not declared in this scope; did you mean 'p'?
   24 |         if(mp[x])return mp[x];
      |            ^~
      |            p
a.cc:25:9: error: 'mp' was not declared in this scope; did you mean 'p'?
   25 |         mp[x]=p.second+turn(p,k+1);
      |         ^~
      |         p
Language: C++

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
using namespace std;
#define INF 100000
#define MAX 100000
#define MOD 1000000007n
typedef long long ll;
typedef pair<int,int> P;
//typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    int N;
    multiset<int> S;
    int p[110000];
    vector<P> V;
    
    cin>>N;
    for(int i=0;i<2;i++){
        S.insert(0);
        S.insert(N+1);
    }

    for(int i=0;i<N;i++){
        cin>>p[i+1];
        V.push_back(P(p[i+1],i+1));
    }
    sort(V.begin(),V.end());
    reverse(V.begin(),V.end());
    ll ret=0;
    for(int i=0;i<N;i++){
        P v=V[i];
        ll num=V.first;
        int id=v.second;
        auto it=S.lower_bound(id);
        int R1=*it++;
        int R2=*it--;
        it--;
        int L1=*it--;
        int L2=*it;
        ret+=num*(R2-R1)*(id-L1);
        ret+=num*(L1-L2)*(R1-id);
        S.insert(id);
    }
    cout<<ret<<endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:44:18: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
   44 |         ll num=V.first;
      |                  ^~~~~
Language: C++

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
using namespace std;
#define INF 100000
#define MAX 100000
#define MOD 1000000007n
typedef long long ll;
typedef pair<int,int> P;
//typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    int N;
    multiset<int> S;
    int p[110000];
    vector<P> V;
    
    cin>>N;
    for(int i=0;i<2;i++){
        S.insert(0);
        S.insert(N+1);
    }

    for(int i=0;i<N;i++){
        cin>>p[i+1];
        V.push_back(P(p[i+1],i+1));
    }
    sort(V.begin(),V.end());
    reverse(V.begin(),V.end());
    ll ret=0;
    for(int i=0;i<N;i++){
        P v=V[i];
        ll num=V.first;
        int id=v.second;
        auto it=S.lower_bound(id);
        int R1=*it++;
        int R2=*it--;
        it--;
        int L1=*it--;
        int L2=*it;
        ret+=num*(R2-R1)*(id-L1);
        ret+=num*(L1-L2)*(R1-id);
        S.insert(id);
    }
    cout<<ret<<endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:24:5: error: 'multiset' was not declared in this scope
   24 |     multiset<int> S;
      |     ^~~~~~~~
a.cc:9:1: note: 'std::multiset' is defined in header '<set>'; this is probably fixable by adding '#include <set>'
    8 | #include <cmath>
  +++ |+#include <set>
    9 | #include <limits>
a.cc:24:14: error: expected primary-expression before 'int'
   24 |     multiset<int> S;
      |              ^~~
a.cc:30:9: error: 'S' was not declared in this scope
   30 |         S.insert(0);
      |         ^
a.cc:43:18: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
   43 |         ll num=V.first;
      |                  ^~~~~
a.cc:45:17: error: 'S' was not declared in this scope
   45 |         auto it=S.lower_bound(id);
      |                 ^
Language: C++

#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int main(void){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i, n){
        cin>>a[i];
    }
    rep(i, n) a[i]--;
    vector<int>idx(n);
    rep(i, n)idx[a[i]]=i;
    set<int>s;
    ll ans=0;
    for(int x=n-1;x>=0;x--){
        int i=idx[x];//xの場所
        ll c=0;
        s.insert(i);
        vector<int>l(2, -1);
        vector<int>r(2, n);
        auto it;
        it=s.find(i);
        rep(j, 2){
            if(it==s.begin()) break;
            --it;
            l[j]=*it;
        }
        it=s.find(i);
        rep(j, 2){
            ++it;
            if(it==s.end()) break;
            r[j]=*it;
        }

        vector<int>ls(2);
        ls[0]=i-l[0];
        ls[1]=l[0]-l[1];
        vector<int>rs(2);
        rs[0]=r[0]-i;
        rs[1]=r[1]-r[0];

        c=(ll)ls[0]*rs[1]+(ll)ls[1]*rs[0];

        ans+=c*(x+1);
    }
    cout<<ans<<endl;



}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:9: error: declaration of 'auto it' has no initializer
   24 |         auto it;
      |         ^~~~
Language: C++

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

//pair<値,位置のインデックス>でソートしておけば、位置がわかる！！
//大きい順、小さい順にみて、データ構造をうまく使い計算量を減らす
//XについてYを数えたものの合計を、YについてXを数えたものの合計と言い換える

void solve() {
	int n; cin >> n;
    vector<P> p(n);
    rep(i, n) {
        ll x; cin >> x;
		p[i] = P(x, i);
    }
	sort(all(p));
	reverse(all(p));
	//自分より大きいもの位置さえわかれば良さそう
	//大きい順に考えればok
	ll ans = 0;
	set<int> se;
	se.insert(-1);
	se.insert(n);
    rep(i, n) {
		ll y = p[i].fr; int k = p[i].sc;
		se.insert(k);
		auto ite = se.lower_bound(k);
		auto ma = ite, mi = ite;
		ma += 2; mi -= 2;
		ans += y * (*ma - *mi - 1);
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:78:20: error: no match for 'operator+=' (operand types are 'std::_Rb_tree_const_iterator<int>' and 'int')
   78 |                 ma += 2; mi -= 2;
      |                 ~~~^~~~
a.cc:78:29: error: no match for 'operator-=' (operand types are 'std::_Rb_tree_const_iterator<int>' and 'int')
   78 |                 ma += 2; mi -= 2;
      |                          ~~~^~~~
Language: C++

#include <bits/stdc++.h>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i].first;
        p[i].first = -p[i].first;
        p[i].second = i;
    }
    sort(p.begin(), p.end());
    set<int> s;
    s.insert(-1);
    s.insert(n);
    long res = 0;
    for (auto pair : p) {
        int x = pair.first;
        int y = pair.second;
        auto next = s.lower_bound(y);
        auto prev = next;
        prev--;
        long s;
        if ((*next) != n) {
            auto nnext = next;
            nnext++;
            s += 1ll * (y - *prev) * (*nnext - *next);
        }
        if ((*prev) != -1) {
            auto pprev = prev;
            pprev--;
            s += 1ll * (*prev - *pprev) * (*next - y);
        }
        res += x * s;
        s.insert(y);
    }
    cout << res;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:11: error: request for member 'insert' in 's', which is of non-class type 'long long int'
   48 |         s.insert(y);
      |           ^~~~~~
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
const int INF=1001001001;
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  rep(i,n)a[i]--;
  vector<int>idx(n);
  rep(i,n) idx[a[i]]=i;
  ll ans=0;
  for (int x=n-1;x>=0;--x){
    int i = idx[x];
    ll c=0;
    { //calc c
      s.insert(i);
      vector<int> l(2,-1);
      vector<int> r(2,n);
      {//calc l
        auto it=s.find(i);
        rep(j,2){
          if (it==s.begin()) break;
          --it;
          l[j]=*it;
        }
      }
      {//calc r
        auto it=s.find(i);
        rep(j,2){
          ++it;
          if (it==s.end()) break;          
          r[j]=*it;
        }
      }
      vector<int> ls(2);
      ls[0]=i-l[0]; ls[1]=l[0]-l[1];
      vector<int> rs(2);
      rs[0]=r[0]-i; rs[1]=r[1]-r[0]; 
      c=(ll)ls[0]*rs[1]+(ll)ls[1]*rs[0];
    }
    ans+=c*(x+1);
  }
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:7: error: 's' was not declared in this scope
   19 |       s.insert(i);
      |       ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
const int INF=1001001001;
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  rep(i,n)a[i]--;
  vector<int>idx(n);
  rep(i,n) idx[a[i]]=i;
  set<int>s;
  for (int x=n-1;x>=0;--x){
    int i = idx[x];
    ll c=0;
    { //calc c
      s.insert(i);
      vector<int> l(2,-1);
      vector<int> r(2,n);
      {//calc l
        auto it=s.find(i);
        rep(j,2){
          if (it==s.begin()) break;
          --it;
          l[j]=*it;
        }
      }
      {//calc r
        auto it=s.find(i);
        rep(j,2){
          ++it;
          if (it==s.end()) break;          
          r[j]=*it;
        }
      }
      vector<int> ls(2);
      ls[0]=i-l[0]; ls[1]=l[0]-l[1];
      vector<int> rs(2);
      rs[0]=r[0]-i; rs[1]=r[1]-r[0]; 
      c=(ll)ls[0]*rs[1]+(ll)ls[1]*rs[0];
    }
    ans+=c*(x+1);
  }
  cout<<ans<<endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   44 |     ans+=c*(x+1);
      |     ^~~
      |     abs
a.cc:46:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   46 |   cout<<ans<<endl;
      |         ^~~
      |         abs
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

void print(vector<pair<int, int>>& a) {
	for (auto p : a) {
		cout << p.first << " " << p.second << "\n";
	}
	cout << "\n";
}

void LeftSuns(vector<pair<int, int>>& rez, vector<int>& a) {
	vector<int> f_stack;
	vector<int> s_stack;
	vector<int> dimas;
	for (int i = 0; i < a.size(); ++i) {
		while (!s_stack.empty() && s_stack.back() < a[i]) {
			rez[s_stack.back() - 1].second = i;
			s_stack.pop_back();
		}
		while (!f_stack.empty() && f_stack.back() < a[i]) {
			rez[f_stack.back() - 1].first = i;
			dimas.push_back(f_stack.back());
			f_stack.pop_back();
		}
		while (!dimas.empty()) {
			s_stack.push_back(dimas.back());
			dimas.pop_back();
		}
		f_stack.push_back(a[i]);
	}
}

int main() {
	
	int n;
	cin >> n;
	vector<int> a(n);
	vector<pair<int, int>> left_suns(n, { -1, -1 });
	vector<pair<int, int>> right_suns(n, { -1, -1 });
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	LeftSuns(left_suns, a);
	RightSuns(right_suns, a);
	
	print(left_suns);
	print(right_suns);

	system("pause");
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:9: error: 'RightSuns' was not declared in this scope; did you mean 'right_suns'?
   49 |         RightSuns(right_suns, a);
      |         ^~~~~~~~~
      |         right_suns
Language: C++

#include <iostream>
 
int main()
{
  int n;
  std::cin >> n;
  int Ps[n]
  for(int i=0; i<n; i++)
    std::cin >> Ps[i];
  
  int sum = 0;
  for(int i=0; i<n-1; i++){
    int max = n;
    int secondmax = n-1;
    if(Ps[i] < Ps[i+1]){
      max = Ps[i+1];
      secondmax = Ps[i];
    }else{
      max = Ps[i];
      secondmax = Ps[i+1];
    }
    sum += secondmax;
    for(int j=i+2; j<n; j++){
		if(Ps[j] < secondmax){
          sum += secondmax;
        }else if(Ps[j] < max){
          secondmax = Ps[j];
          sum += secondmax;
        }else{
          secondmax = max;
          max = Ps[j];
          sum += secondmax;
        }
    }
    std::cout << sum;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:3: error: expected initializer before 'for'
    8 |   for(int i=0; i<n; i++)
      |   ^~~
a.cc:8:16: error: 'i' was not declared in this scope
    8 |   for(int i=0; i<n; i++)
      |                ^
a.cc:15:8: error: 'Ps' was not declared in this scope
   15 |     if(Ps[i] < Ps[i+1]){
      |        ^~
a.cc:24:20: error: 'Ps' was not declared in this scope
   24 |                 if(Ps[j] < secondmax){
      |                    ^~
Language: C++

#include <iostream>
#include <algorithm>

int * vec;
int n;
long long ans = 0;

bool check_mon_up(int * start, int * end)
{
	if (end - start <= 1)
		return true;
	
	for (auto i = start; i < end - 1; i++)
		if (*i >= *(i + 1))
			return false;
	return true;
}

bool chec_mon_do(int * start, int * end)
{
	if (end - start <= 1)
		return true;

	for (auto i = start; i < end - 1; i++)
		if (*i <= *(i + 1))
			return false;
	return true;
}

int * m_find_max(int * start, int * end)
{
	int max = -1;
	int * numb = nullptr;
	for (int * i = start; i < end; i++)
		if (max < *i) max = *i, numb = i;
	return numb;
}

void m_find_two_max(int * start, int * end, int *& max, int *& tax)
{
	int mm = -1, mt = -1;
	for (int * i = start; i < end; i++)
	{
		if (*i > mm)
		{
			mt = mm;
			mm = *i;
			tax = max;
			max = i;
		}
		else if (*i > mt)
		{
			mt = *i;
			tax = i;
		}
	}
}

void m_find_tax(int * start, int * end, int * max, int *& tax)
{
	int mm = *max, mt = -1;
	for (int * i = start; i < end; i++)
		if (*i > mt)
			if (i != max)
			{
				tax = i;
				mt = *i;
			}
}

void fu(int * start, int * end, int * max)
{
	if (end - start == 1)
		return;
	int * tax = 0;
	m_find_tax(start, end, max, tax);
	if (tax == max)
		return;
	if (tax > max)
	{
		ans += (long long)(*tax) * (max - start + 1) * (end - tax);
		fu(start, tax, max);
	}
	else
	{
		ans += (long long)(*tax) * (tax - start + 1) * (end - max);
		fu(tax + 1, end, max);
	}
	return;
}

void func(int * start, int * end)
{
	if (end - start <= 1)
		return;
	if (end - start == 2)
	{
		ans += (long long)std::min(*(end - 1), *start);
		return;
	}
	if (check_mon_up(start, end))
	{
		for (int i = 0; i < end - start - 1; i++)
			ans += (long long)(*(start + i)) * (i + 1);
		return;
	}
	if (chec_mon_do(start, end))
	{
		for (int i = 1; i < end - start; i++)
			ans += (long long)(*(start + i)) * (end - start - i);
		return;
	}
	int * max = m_find_max(start, end);
	fu(start, end, max);
	func(start, max);
	func(max + 1, end);
	return;
}

bool read_int_unlocked(int * out)
{
	int c = 0;
	*out = 0;
	c = _getchar_nolock();
	for (; '0' <= c && c <= '9'; c = _getchar_nolock())
		*out += (*out) * 10 + c - '0';
	return true;
}

int main()
{
	std::ios::sync_with_stdio(false);
	read_int_unlocked(&n);
	vec = new int[n];
	int * const start = vec;
	int * const end = vec + n;
	for (int * i = start; i < end; i++)
		read_int_unlocked(i);
	func(start, end);
	std::cout << ans;
	system("pause");
	return 0;
}

Compiler output:
a.cc: In function 'bool read_int_unlocked(int*)':
a.cc:124:13: error: '_getchar_nolock' was not declared in this scope; did you mean 'getchar_unlocked'?
  124 |         c = _getchar_nolock();
      |             ^~~~~~~~~~~~~~~
      |             getchar_unlocked
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

const int MIN = -2147483647;

using type = long long;

using namespace std;

type * vec;
int n;
long long ans = 0;

bool check_mon_up(type * start, type * end)
{
	if (end - start <= 1)
		return true;
	
	for (auto i = start; i < end - 1; i++)
		if (*i >= *(i + 1))
			return false;
	return true;
}

bool chec_mon_do(type * start, type * end)
{
	if (end - start <= 1)
		return true;

	for (auto i = start; i < end - 1; i++)
		if (*i <= *(i + 1))
			return false;
	return true;
}

type * m_find_max(type * start, type * end)
{
	int max = MIN;
	type * numb = nullptr;
	for (type * i = start; i < end; i++)
		if (max < *i) max = *i, numb = i;
	return numb;
}

void m_find_two_max(type * start, type * end, type *& max, type *& tax)
{
	int mm = MIN, mt = MIN;
	for (type * i = start; i < end; i++)
	{
		if (*i > mm)
		{
			mt = mm;
			mm = *i;
			tax = max;
			max = i;
		}
		else if (*i > mt)
		{
			mt = *i;
			tax = i;
		}
	}
}

void m_find_tax(type * start, type * end, type * max, type *& tax)
{
	int mm = *max, mt = MIN;
	for (type * i = start; i < end; i++)
		if (*i > mt)
			if (i != max)
			{
				tax = i;
				mt = *i;
			}
}

void fu(type * start, type * end, type * max)
{
	if (end - start == 1)
		return;
	type * tax = 0;
	m_find_tax(start, end, max, tax);
	if (tax == max)
		return;
	if (tax > max)
	{
		ans += (*tax) * (max - start + 1) * (end - tax);
		fu(start, tax, max);
	}
	else
	{
		ans += (*tax) * (tax - start + 1) * (end - max);
		fu(tax + 1, end, max);
	}
	return;
}

void func(type * start, type * end)
{
	if (end - start <= 1)
		return;
	if (end - start == 2)
	{
		ans += min(*(end - 1), *start);
		return;
	}
	if (check_mon_up(start, end))
	{
		for (int i = 0; i < end - start - 1; i++)
			ans += (*(start + i)) * (i + 1);
		return;
	}
	if (chec_mon_do(start, end))
	{
		for (int i = 1; i < end - start; i++)
			ans += (*(start + i)) * (end - start - i);
		return;
	}
	type * max = m_find_max(start, end);
	fu(start, end, max);
	func(start, max);
	func(max + 1, end);
	return;
}

int main()
{
	cin >> n;
	vec = new type[n];
	type * const start = vec;
	type * const end = vec + n;
	for (type * i = start; i < end; i++)
		scanf_s("%lld", i);
	func(start, end);
	cout << ans;
	//system("pause");
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:134:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
  134 |                 scanf_s("%lld", i);
      |                 ^~~~~~~
      |                 scanf
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

const int MIN = -2147483647;

using type = long long;

using namespace std;

type * vec;
int n;
long long ans = 0;

bool check_mon_up(type * start, type * end)
{
	if (end - start <= 1)
		return true;
	
	for (auto i = start; i < end - 1; i++)
		if (*i >= *(i + 1))
			return false;
	return true;
}

bool chec_mon_do(type * start, type * end)
{
	if (end - start <= 1)
		return true;

	for (auto i = start; i < end - 1; i++)
		if (*i <= *(i + 1))
			return false;
	return true;
}

type * m_find_max(type * start, type * end)
{
	int max = MIN;
	type * numb = nullptr;
	for (type * i = start; i < end; i++)
		if (max < *i) max = *i, numb = i;
	return numb;
}

void m_find_two_max(type * start, type * end, type *& max, type *& tax)
{
	int mm = MIN, mt = MIN;
	for (type * i = start; i < end; i++)
	{
		if (*i > mm)
		{
			mt = mm;
			mm = *i;
			tax = max;
			max = i;
		}
		else if (*i > mt)
		{
			mt = *i;
			tax = i;
		}
	}
}

void m_find_tax(type * start, type * end, type * max, type *& tax)
{
	int mm = *max, mt = MIN;
	for (type * i = start; i < end; i++)
		if (*i > mt)
			if (i != max)
			{
				tax = i;
				mt = *i;
			}
}

void fu(type * start, type * end, type * max)
{
	if (end - start == 1)
		return;
	type * tax = 0;
	m_find_tax(start, end, max, tax);
	if (tax == max)
		return;
	if (tax > max)
	{
		ans += (*tax) * (max - start + 1) * (end - tax);
		fu(start, tax, max);
	}
	else
	{
		ans += (*tax) * (tax - start + 1) * (end - max);
		fu(tax + 1, end, max);
	}
	return;
}

void func(type * start, type * end)
{
	if (end - start <= 1)
		return;
	if (end - start == 2)
	{
		ans += min(*(end - 1), *start);
		return;
	}
	if (check_mon_up(start, end))
	{
		for (int i = 0; i < end - start - 1; i++)
			ans += (*(start + i)) * (i + 1);
		return;
	}
	if (chec_mon_do(start, end))
	{
		for (int i = 1; i < end - start; i++)
			ans += (*(start + i)) * (end - start - i);
		return;
	}
	type * max = m_find_max(start, end);
	fu(start, end, max);
	func(start, max);
	func(max + 1, end);
	return;
}

int main()
{
	cin >> n;
	vec = new type[n];
	type * const start = vec;
	type * const end = vec + n;
	for (type * i = start; i < end; i++)
		scanf_s("%d", i);
	func(start, end);
	printf_s("%d", ans);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:134:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
  134 |                 scanf_s("%d", i);
      |                 ^~~~~~~
      |                 scanf
a.cc:136:9: error: 'printf_s' was not declared in this scope; did you mean 'printf'?
  136 |         printf_s("%d", ans);
      |         ^~~~~~~~
      |         printf