func_code_string: #include <bits/stdc++.h>   using namespace std;   char buf[25];   struct node {     long long x, y;     bool operator<(node tp) const {       if (x != tp.x) return x < tp.x;       return y < tp.y;     }   };   map<long long, long long> h1, h2;   map<node, long long> t, q;   const long long inf = 1e17;   const long long maxn = 200010;   long long L1[maxn], R1[maxn], l1[maxn], r1[maxn], s1[maxn], a[maxn];   long long L2[maxn], R2[maxn], l2[maxn], r2[maxn], s2[maxn];   long long n, m, sum1, sum2;   long long ans;   long long read() {     long long x = 0, f = 0;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = 1;     } while (ch <  0  || ch >  9 );     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return f ? -x : x;   }   void write(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (!x) {       putchar( 0 );       return;     }     long long cnt = 0;     while (x) {       buf[++cnt] =  0  + x % 10;       x /= 10;     }     for (long long i = cnt; i >= 1; --i) putchar(buf[i]);   }   signed main() {     srand(19267180);     n = read();     m = read();     for (long long i = 1; i <= n; ++i) {       h1[i] = (1ll * rand() * rand() * rand() * rand() % inf + inf) % inf;       h2[i] = (1ll * rand() * rand() * rand() * rand() % inf + inf) % inf;       sum1 = h1[i] ^ sum1;       sum2 = h2[i] ^ sum2;     }     for (long long i = 1; i <= n; ++i) {       long long l = read(), r = read();       ++a[l];       --a[r + 1];       s1[l] ^= h1[i];       s1[r + 1] ^= h1[i];       L1[l - 1] ^= h1[i];       R1[r + 1] ^= h1[i];       s2[l] ^= h2[i];       s2[r + 1] ^= h2[i];       L2[l - 1] ^= h2[i];       R2[r + 1] ^= h2[i];     }     for (long long i = m - 1; i >= 1; --i) L1[i] ^= L1[i + 1], L2[i] ^= L2[i + 1];     for (long long i = 2; i <= m; ++i) {       R1[i] ^= R1[i - 1], s1[i] ^= s1[i - 1];       R2[i] ^= R2[i - 1], s2[i] ^= s2[i - 1];     }     for (long long i = 2; i <= m; ++i) s1[i] ^= s1[i - 1], s2[i] ^= s2[i - 1];     for (long long i = 1; i <= m; ++i) {       l1[i] = s1[i - 1] ^ R1[i], r1[i] = s1[i] ^ L1[i];       l2[i] = s2[i - 1] ^ R2[i], r2[i] = s2[i] ^ L2[i];     }     for (long long i = m; i >= 1; --i) {       t[(node){r1[i], r2[i]}] += 1;       q[(node){r1[i], r2[i]}] += i;       long long x_1 = sum1 ^ l1[i], x_2 = sum2 ^ l2[i];       ans += q[(node){x_1, x_2}] - 1ll * t[(node){x_1, x_2}] * (i - 1);     }     for (long long i = 1; i <= m; ++i) a[i] += a[i - 1];     long long x = 0;     for (long long i = 1; i <= m; ++i) {       if (a[i] == 0)         ++x;       else         x = 0;       if (x)         if (i == m || a[i + 1] != 0)           for (long long j = 1; j <= x; ++j) ans -= 1ll * j * (x - j + 1);     }     write(ans);     return 0;   }   