func_code_string: #include <bits/stdc++.h>   using namespace std;   struct node {     long long w, id;     bool friend operator<(node a, node b) {       if (a.w == b.w)         return a.id < b.id;       else         return a.w < b.w;     }   } a[1000004];   long long b[1000004][4];   long long l[1000004];   long long r[1000004];   int main() {     long long n, x;     cin >> n >> x;     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i].w);       a[i].id = i;     }     sort(a + 1, a + 1 + n);     long long cnt = 1;     b[cnt][0] = b[cnt][1] = a[1].id;     b[cnt][3] = a[1].w;     for (int i = 2; i <= n; ++i) {       if (a[i].w == a[i - 1].w)         b[cnt][1] = a[i].id;       else {         cnt++;         b[cnt][0] = b[cnt][1] = a[i].id;         b[cnt][3] = a[i].w;       }     }     long long ans = 0;     long long base = 0;     long long lmax = 1;     long long rmin = cnt;     for (int i = 1; i <= cnt; ++i) {       if (b[i][0] > base) {         base = b[i][1];         l[i] = base;         lmax = i;       } else         break;     }     base = 1e9;     for (int i = cnt; i >= 1; --i) {       if (b[i][1] < base) {         base = b[i][0];         r[i] = base;         rmin = i;       } else         break;     }     if (lmax < rmin) {       for (int i = 1; i <= lmax; ++i) {         int pos = upper_bound(r + (int)rmin, r + (int)cnt + 1, l[i]) - r;         if (pos < cnt + 1)           ans += (b[cnt][3] - b[pos - 1][3]) * (b[i + 1][3] - b[i][3]);       }       cout << ans + (x - b[cnt][3] + 1) * b[lmax + 1][3] +                   (b[cnt][3] - b[rmin - 1][3]) * b[1][3];     } else {       cout << x * (x + 1) / 2 << endl;     }   }   