func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool umax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   long long POW(long long a, long long p, long long M) {     if (!p) return 1LL;     long long T = POW(a, p / 2, M);     T = T * T % M;     if (p & 1) T = T * (a % M) % M;     return T;   }   long long SQRT(long long a) {     long long b = (long long)sqrtl(((double)a) + 0.5);     while (b * b < a) ++b;     while (b * b > a) --b;     return (b * b == a) ? b : -1;   }   const long long MOD = 1e9 + 7;   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     long long n, m;     cin >> n >> m;     if (n == 1) {       cout << 0 << endl;       return 0;     }     vector<vector<long long>> guess(n + 1);     long long f = 0;     long long N = 2e5;     long long fq[4 * N];     memset(fq, 0, sizeof(fq));     for (long long i = 1; i <= n; i++) fq[N + i] = 1;     for (long long i = 1; i <= n; i++) {       long long mx = min(n, i + m + 1);       f += 2 * (mx - i + 1) - 1;     }     long long st;     for (long long i = 1; i <= m; i++) {       long long a;       cin >> a;       guess[a].push_back(i);     }     for (long long i = 1; i <= n; i++) {       if (guess[i].empty()) continue;       long long ss = guess[i][0];       for (long long j = 1; j <= guess[i].size(); ++j) {         if (j < guess[i].size() && guess[i][j] == guess[i][j - 1] + 1)           continue;         else {           long long ct = 0;           for (long long k = i - ss; k >= i - guess[i][j - 1]; --k) {             long long org = min(n, k + m + 1);             long long wt = min(n, k + m - (guess[i][j - 1] + (k - i) + 1) + 1);             f -= fq[N + k] * (org - wt);             ct += fq[N + k];             fq[N + k] = 0;           }           fq[N + i - guess[i][j - 1] - 1] += ct;           if (j < guess[i].size()) ss = guess[i][j];         }       }     }     memset(fq, 0, sizeof(fq));     for (long long i = 1; i <= n; i++) fq[i] = 1;     for (long long i = n; i >= 1; i--) {       if (guess[i].empty()) continue;       long long ss = guess[i][0];       for (long long j = 1; j <= guess[i].size(); ++j) {         if (j < guess[i].size() && guess[i][j] == guess[i][j - 1] + 1)           continue;         else {           long long ct = 0;           for (long long k = i + ss; k <= i + guess[i][j - 1]; ++k) {             long long org = max(1LL, k - m - 1);             long long wt = max(1LL, k - m + (guess[i][j - 1] - (k - i) + 1) - 1);             f -= fq[k] * (wt - org);             ct += fq[k];             fq[k] = 0;           }           fq[i + guess[i][j - 1] + 1] += ct;           if (j < guess[i].size()) ss = guess[i][j];         }       }     }     cout << f << endl;     cerr <<  Time elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s n ;     return 0;   }   