Language: C++

/*
ID: div1der
LANG: C++ 17
MOOD: CALM
READINESS: PRETTY WELL
*/

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1
#define bin(l, r) (l + r + 1) >> 1

#define ml " "
#define nl endl

#define fo(i, a, b) for (int i = a; i <= b; ++ i)
#define foo(i, a, b) for (int i = a; i >= b; -- i)

#define meme(a, b) memset(a, b, sizeof a)

#define TOKAEV_NE_MOY_PRESIDENT return 0

template <typename T>
void printArr(const T * arr, int s, int fn) {
    for (int i = s; i <= fn; ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <typename T>
long long minArr(const T * arr, int s, int fn) {
    ll res = 1e16 + 1;
    for (int i = s; i <= fn; ++ i) {
        res = min(res, arr[i]);
    }
    return res;
}

template <typename T>
void printVec(const T * arr) {
    for (int i = 0; i < sz(arr); ++ i) cout << arr[i] << " ";
    cout << '\n';
}

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 2e5 + 10;
const int NN = 1e3 + 10;
const int MXLOG = 30;
const int NNN = 2e3 + 9;
const int MOD = 1e9 - 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const double PI = acos(-1);

ll a[N], ans, t[N][30], n;
    
void build() {
    for (int i = 0; i < n; ++ i)
        t[i][0] = i;
    for (int j = 1; (1 << j) <= n; ++ j) {
        for (int i = 0; (1 << j) + i - 1 < n; ++ i) {
            if (a[t[i][j - 1]] < a[t[i + (1 << (j - 1))][j - 1]])
                t[i][j] = t[i][j - 1];
            else
                t[i][j] = t[(1 << (j - 1)) + i][j - 1];
        }
    }
}

int get(int l, int r){
    int len = (int)(log(r - l + 1) * 1.0) / log(2.0);
    if (a[t[l][len]] < a[t[r - (1 << len) + 1][len]])
        return t[l][len];
    else
        return t[r - (1 << len) + 1][len];
}

void func(int l, int r) {
    if (l == r){
        ans += a[l];
        return;
    }
    int mn = get(l, r);
    ans += (mn - l + 1) * (r - mn + 1) * a[mn];
    if (l <= mn - 1)
        func(l, mn - 1);
    if (r >= mn + 1) 
        func(mn + 1, r);
}

int main () {
    #ifdef div1der
    #endif
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    
    to_pray();

    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) {
        scnaf("%lld", &a[i];)
    }

    build();

    func(0, n - 1);

    printf("%lld\n", sum);

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:155:28: error: expected ')' before ';' token
  155 |         scnaf("%lld", &a[i];)
      |              ~             ^
      |                            )
a.cc:155:29: error: expected primary-expression before ')' token
  155 |         scnaf("%lld", &a[i];)
      |                             ^
a.cc:162:22: error: 'sum' was not declared in this scope
  162 |     printf("%lld\n", sum);
      |                      ^~~