func_code_string: #include <bits/stdc++.h>   using namespace std;   typedef int arr32[5000010];   arr32 x, rk, l, r;   int n;   long long ans;   bool cmp(const int &a, const int &b) { return x[a] < x[b]; }   void erase(int x) { r[l[x]] = r[x], l[r[x]] = l[x]; }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %d , x + i);       rk[i] = i, l[i] = i - 1, r[i] = i + 1;     }     sort(rk + 1, rk + n + 1, cmp);     for (int i = 1; i <= n - 2; ++i) {       int p = rk[i];       if (l[p] == 0)         ans += x[p], erase(p);       else if (r[p] == n + 1)         ans += x[p], erase(p);       else         ans += min(x[l[p]], x[r[p]]), erase(p);     }     cout << ans << endl;   }   