#include <bits/stdc++.h>   inline int Get() {     char ch;     while ((ch = getchar()) <  0  || ch >  9 )       ;     int Num = ch -  0 ;     while ((ch = getchar()) >=  0  && ch <=  9 )       Num = (Num << 3) + (Num << 1) + ch -  0 ;     return Num;   }   const int N = 1e5 + 5;   int n, m, a[N], count[N << 2], sum[N << 2], rev[N << 2];   std ::vector<int> vec0[N], vec1[N];   void build(int k, int l, int r) {     sum[k] = r - l + 1;     if (l == r) return;     int mid = l + r >> 1;     build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);   }   void down(int k) {     if (rev[k]) {       count[k << 1] = sum[k << 1] - count[k << 1], rev[k << 1] ^= 1;       count[k << 1 | 1] = sum[k << 1 | 1] - count[k << 1 | 1],                      rev[k << 1 | 1] ^= 1;       rev[k] = 0;     }   }   void modify(int k, int l, int r, int x, int y) {     if (x <= l && r <= y) {       rev[k] ^= 1, count[k] = sum[k] - count[k];       return;     }     int mid = l + r >> 1;     down(k);     if (x <= mid) modify(k << 1, l, mid, x, y);     if (y > mid) modify(k << 1 | 1, mid + 1, r, x, y);     count[k] = count[k << 1] + count[k << 1 | 1];   }   int query(int k, int l, int r, int x, int y) {     if (x <= l && r <= y) return count[k];     int mid = l + r >> 1;     down(k);     if (y <= mid) return query(k << 1, l, mid, x, y);     if (x > mid) return query(k << 1 | 1, mid + 1, r, x, y);     return query(k << 1, l, mid, x, y) + query(k << 1 | 1, mid + 1, r, x, y);   }   int main() {     n = Get(), m = Get();     for (int i = 1; i <= n; ++i) a[i] = Get();     std ::sort(a + 1, a + n + 1);     for (int i = 1; i <= m; ++i) {       int l = std ::lower_bound(a + 1, a + n + 1, Get()) - a;       int r = std ::upper_bound(a + 1, a + n + 1, Get()) - a - 1;       if (1 <= l && l <= n && 1 <= r && r <= n && l <= r)         vec0[l].push_back(r), vec1[r].push_back(l);     }     long long ans = (long long)n * (n - 1) * (n - 2) / 6;     build(1, 1, n);     for (int i = 1; i <= n; ++i) {       for (int k = 0, sze = vec0[i].size(); k < sze; ++k)         modify(1, 1, n, i, vec0[i][k]);       int res = (i > 1 ? i - 1 - query(1, 1, n, 1, i - 1) : 0) +                 (i < n ? query(1, 1, n, i + 1, n) : 0);       ans -= (long long)res * (res - 1) / 2;       for (int k = 0, sze = vec1[i].size(); k < sze; ++k)         modify(1, 1, n, vec1[i][k], i);     }     printf( %I64d n , ans);   }   