#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const long long LINF = (1LL << 62);   const int INF = 1 << 30;   const int NS = 100010;   const int MS = 19;   const int MOD = 1000000007;   const double PI = acos(-1.0);   int n, m, q, h[NS];   pair<int, int> s[NS];   int L[NS], R[NS];   int solve() {}   int main() {     while (~scanf( %d %d , &n, &q)) {       m = n - 1;       for (int i = 1; i <= n; i++) {         scanf( %d , &h[i]);         if (i > 1) {           h[i - 1] = abs(h[i - 1] - h[i]);           s[i - 1] = make_pair(h[i - 1], i - 1);         }       }       sort(s + 1, s + m + 1);       set<int> idSet;       idSet.insert(0);       idSet.insert(n);       for (int i = m; i >= 1; i--) {         int pos = s[i].second;         idSet.insert(pos);         __typeof(idSet.begin()) it = idSet.find(pos);         L[pos] = *(--it);         it++, it++;         R[pos] = *(it);       }       int x, y;       for (int qi = 0; qi < q; qi++) {         scanf( %d %d , &x, &y);         long long ans = 0;         for (int i = x; i < y; i++) {           int lb = i - max(L[i], x - 1);           int rb = min(R[i], y) - i;           ans += 1LL * h[i] * lb * rb;         }         printf( %I64d n , ans);       }     }     return 0;   }   