#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
ll mpow(ll a, ll n,ll mod)
{ll ret=1;ll b=a;while(n) {if(n&1)
    ret=(ret*b)%mod;b=(b*b)%mod;n>>=1;}
return (ll)ret;
}
using namespace std;
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
using namespace std;
#define N (int)1e5+5
int dp[N][22];
int a[N],n,q;
int diff[N];
void comp(){
    int i,j;
    int x=n-1;
    for(i=0;i<x;i++){
        dp[i][0]=diff[i];
    }
    for(i=1;(1<<i)<=x;i++){
        for(j=0;j+(1<<i)-1<x;j++){
            dp[j][i]=max(dp[j][i-1],dp[j+(1<<(i-1))][i-1]);
        }
    }
}
int query(int i,int j){
    int k=(j-i+1);
    int p=0;
    while((1<<p)<=k)p++;
    p--;
    if(dp[i][p]>=dp[j-(1<<p)+1][p])
        return dp[i][p];
    else
        return dp[j-(1<<p)+1][p];
}
int main(){
    int i,j;
    cin>>n>>q;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n-1;i++)
        diff[i]=abs(a[i]-a[i+1]);
    comp();
    while(q--){
        int x,y;
        cin>>x>>y;
        x--;y--;
        y--;
        int ans=0;
        for(j=x;j<=y;j++){
            int lo=x,hi=j;
            while(lo<hi){
                int mid=(lo+hi)>>1;
                if(query(mid,j-1)>=diff[j])
                    lo=mid+1;
                else
                    hi=mid;
            }
            int L=lo;
            lo=j;
            hi=y;
            while(lo<hi){
                int mid=(lo+hi+1)>>1;
                if(query(j,mid)>diff[j])
                    hi=mid-1;
                else
                    lo=mid;
            }
            int acl=j-1;
            int acr=lo+1;
            ans+=(acr-j)*diff[j];
            ans+=((j+1)-L)*diff[j];
            ans+=(acl-L+1)*(acr-(j+2)+1)*diff[j];
          //  cout<<acr<<" "<<acr-j<<" ";
         //   cout<<(j+1)-L<<" ";
        //    cout<<(acl-L+1)*(acr-(j+2)+1)<<" ";
            ans-=diff[j];

        }
        cout<<ans<<endl;
    }
    return 0;
}
//4 3 7 8 2 1 2 1


#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
ll mpow(ll a, ll n,ll mod)
{ll ret=1;ll b=a;while(n) {if(n&1)
    ret=(ret*b)%mod;b=(b*b)%mod;n>>=1;}
return (ll)ret;
}
using namespace std;
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
using namespace std;
#define N (int)1e5+5
ll dp[N][22];
ll a[N],n,q;
ll diff[N];
void comp(){
    int i,j;
    int x=n-1;
    for(i=0;i<x;i++){
        dp[i][0]=diff[i];
    }
    for(i=1;(1<<i)<=x;i++){
        for(j=0;j+(1<<i)-1<x;j++){
            dp[j][i]=max(dp[j][i-1],dp[j+(1<<(i-1))][i-1]);
        }
    }
}
int query(int i,int j){
    int k=(j-i+1);
    int p=0;
    while((1<<p)<=k)p++;
    p--;
    if(dp[i][p]>=dp[j-(1<<p)+1][p])
        return dp[i][p];
    else
        return dp[j-(1<<p)+1][p];
}
int main(){
    int i,j;
    cin>>n>>q;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n-1;i++)
        diff[i]=abs(a[i]-a[i+1]);
    comp();
    while(q--){
        int x,y;
        cin>>x>>y;
        x--;y--;
        y--;
        ll ans=0;
        for(j=x;j<=y;j++){
            int lo=x,hi=j;
            while(lo<hi){
                int mid=(lo+hi)>>1;
                if(query(mid,j-1)>=diff[j])
                    lo=mid+1;
                else
                    hi=mid;
            }
            int L=lo;
            lo=j;
            hi=y;
            while(lo<hi){
                int mid=(lo+hi+1)>>1;
                if(query(j,mid)>diff[j])
                    hi=mid-1;
                else
                    lo=mid;
            }
            ll acl=j-1;
            ll acr=lo+1;
            ans+=(acr-j)*diff[j];
            ans+=((j+1)-L)*diff[j];
            ans+=(acl-L+1)*(acr-(j+2)+1)*diff[j];
          //  cout<<acr<<" "<<acr-j<<" ";
         //   cout<<(j+1)-L<<" ";
        //    cout<<(acl-L+1)*(acr-(j+2)+1)<<" ";
            ans-=diff[j];

        }
        cout<<ans<<endl;
    }
    return 0;
}
//4 3 7 8 2 1 2 1


#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
ll mpow(ll a, ll n,ll mod)
{ll ret=1;ll b=a;while(n) {if(n&1)
    ret=(ret*b)%mod;b=(b*b)%mod;n>>=1;}
return (ll)ret;
}
using namespace std;
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
using namespace std;
#define N (int)1e5+5
int dp[N][22];
int a[N],n,q;
int diff[N];
void comp(){
    int i,j;
    int x=n-1;
    for(i=0;i<x;i++){
        dp[i][0]=diff[i];
    }
    for(i=1;(1<<i)<=x;i++){
        for(j=0;j+(1<<i)-1<x;j++){
            dp[j][i]=max(dp[j][i-1],dp[j+(1<<(i-1))][i-1]);
        }
    }
}
int query(int i,int j){
    int k=(j-i+1);
    int p=0;
    while((1<<p)<=k)p++;
    p--;
    if(dp[i][p]>=dp[j-(1<<p)+1][p])
        return dp[i][p];
    else
        return dp[j-(1<<p)+1][p];
}
int main(){
    int i,j;
    scanf("%d%d",&n,&q);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n-1;i++)
        diff[i]=abs(a[i]-a[i+1]);
    comp();
    while(q--){
        int x,y;
        scanf("%d%d",&x,&y);
        x--;y--;
        y--;
        ll ans=0;
        for(j=x;j<=y;j++){
            int lo=x,hi=j;
            while(lo<hi){
                int mid=(lo+hi)>>1;
                if(query(mid,j-1)>=diff[j])
                    lo=mid+1;
                else
                    hi=mid;
            }
            int L=lo;
            lo=j;
            hi=y;
            while(lo<hi){
                int mid=(lo+hi+1)>>1;
                if(query(j,mid)>diff[j])
                    hi=mid-1;
                else
                    lo=mid;
            }
            ll acl=j-1;
            ll acr=lo+1;
            ll x=diff[j];
            ans+=(acr-j)*x;
            ans+=((j+1)-L)*x;
            ans+=(acl-L+1)*(acr-(j+2)+1)*x;
          //  cout<<acr<<" "<<acr-j<<" ";
         //   cout<<(j+1)-L<<" ";
        //    cout<<(acl-L+1)*(acr-(j+2)+1)<<" ";
            ans-=x;

        }
        printf("%lld\n",ans);
    }
    return 0;
}
//4 3 7 8 2 1 2 1


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main(int argc, char const *argv[])
{
	int n,q;
	cin>>n>>q;
	vector<int> arr;
	for (int i = 0; i < n; ++i)
	{
		int temp;
		cin>>temp;
		arr.push_back(temp);
	}
	vector<int> diff,nextlarger(n-1),lastlarger(n-1);
	for (int i = 0; i < n-1; ++i)
	{
		diff.push_back(abs(arr[i+1]-arr[i]));
	}
	stack<int> next,prev;
	for (int i = n-2; i >=0; i--)
	{
		while(!next.empty() && diff[next.top()] <= diff[i]) next.pop();
		if(next.empty()) nextlarger[i] = n-1;
		else nextlarger[i] = next.top();
		next.push(i);
	}
	for (int i = 0; i < n-1; ++i)
	{
		while(!prev.empty() && diff[prev.top()] < diff[i]) prev.pop();
		if(prev.empty()) lastlarger[i] = -1;
		else lastlarger[i] = prev.top();
		prev.push(i);
	}
	for (int i = 0; i < q; ++i)
	{
		int l,r;
		cin>>l>>r;
		l--;
		r-=2;
		lli sol = 0;
		for(int j = l; j <= r; j++) {
			int x = max(lastlarger[j] + 1, l);
			int y = min(r, nextlarger[j] - 1);
			// cout<<x<<y<<endl;
			sol += (lli)(j-x+(lli)1)*(y-j+(lli)1)*(lli)diff[j];
		}
		cout<<sol<<endl;
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <cmath>
#include <iostream>
using namespace std;
int a[100001], ml[100001], mr[100001];
int main()
{
    int n, val, pre, l, r, i, j, q;
    scanf("%d%d", &n, &q); scanf("%d", &pre);
    for (i = 1; i < n; i++)
    {
        scanf("%d", &val);
        a[i] = abs(val-pre);
        pre = val;
    }
    while (q--)
    {
        scanf("%d%d", &l, &r);
        memset(ml, 0, sizeof ml);
        memset(mr, 0, sizeof mr);
        ml[l] = 0;
        for (i = l+1; i < r; i++)
        {
            if (a[i] >= a[i-1])
            {
                j = i-1;
                while (true)
                {
                    while (ml[j] != 0) j -= ml[j];
                    j--;
                    while (j >= l && a[j] <= a[i] && ml[j] == 0) j--;
                    if (j < l || a[j] > a[i])
                    {
                        ml[i] = i - j - 1;
                        break;
                    }
                }
            }
            else ml[i] = 0;
        }

        mr[r-1] = 0;
        for (i = r-2; i >= l; i--)
        {
            if (a[i] > a[i+1])
            {
                j = i+1;
                while (true)
                {
                    while (mr[j] != 0) j += mr[j];
                    j++;
                    while (j < r && a[j] < a[i] && mr[j] == 0) j++;
                    if (j == r || a[j] >= a[i])
                    {
                        mr[i] = j - i - 1;
                        break;
                    }
                }
            }
            else mr[i] = 0;
        }
        long long ret = 0;
        for (i = l; i < r; i++)
            ret += (long long)a[i] * (long long)(ml[i] + mr[i] + ml[i]*mr[i] + 1);
        printf("%I64d\n", ret);
    }
}


#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int a[100001], ml[100001], mr[100001];
int main()
{
    int n, val, pre, l, r, i, j, q;
    scanf("%d%d", &n, &q); scanf("%d", &pre);
    for (i = 1; i < n; i++)
    {
        scanf("%d", &val);
        a[i] = abs(val-pre);
        pre = val;
    }
    while (q--)
    {
        scanf("%d%d", &l, &r);
        memset(ml, 0, sizeof ml);
        memset(mr, 0, sizeof mr);
        ml[l] = 0;
        for (i = l+1; i < r; i++)
        {
            if (a[i] >= a[i-1])
            {
                j = i-1;
                while (true)
                {
                    while (ml[j] != 0) j -= ml[j];
                    j--;
                    while (j >= l && a[j] <= a[i] && ml[j] == 0) j--;
                    if (j < l || a[j] > a[i])
                    {
                        ml[i] = i - j - 1;
                        break;
                    }
                }
            }
            else ml[i] = 0;
        }

        mr[r-1] = 0;
        for (i = r-2; i >= l; i--)
        {
            if (a[i] > a[i+1])
            {
                j = i+1;
                while (true)
                {
                    while (mr[j] != 0) j += mr[j];
                    j++;
                    while (j < r && a[j] < a[i] && mr[j] == 0) j++;
                    if (j == r || a[j] >= a[i])
                    {
                        mr[i] = j - i - 1;
                        break;
                    }
                }
            }
            else mr[i] = 0;
        }
        long long ret = 0;
        for (i = l; i < r; i++)
            ret += (long long)a[i] * (long long)(ml[i] + mr[i] + ml[i]*mr[i] + 1);
        printf("%I64d\n", ret);
    }
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
using namespace std;
int a[100001], ml[100001], mr[100001];
int main()
{
    int n, val, pre, l, r, i, j, q;
    scanf("%d%d", &n, &q); scanf("%d", &pre);
    for (i = 1; i < n; i++)
    {
        scanf("%d", &val);
        a[i] = abs(val-pre);
        pre = val;
    }
    while (q--)
    {
        scanf("%d%d", &l, &r);
        memset(ml, 0, sizeof ml);
        memset(mr, 0, sizeof mr);
        ml[l] = 0;
        for (i = l+1; i < r; i++)
        {
            if (a[i] >= a[i-1])
            {
                j = i-1;
                while (true)
                {
                    while (ml[j] != 0) j -= ml[j];
                    j--;
                    while (j >= l && a[j] <= a[i] && ml[j] == 0) j--;
                    if (j < l || a[j] > a[i])
                    {
                        ml[i] = i - j - 1;
                        break;
                    }
                }
            }
            else ml[i] = 0;
        }

        mr[r-1] = 0;
        for (i = r-2; i >= l; i--)
        {
            if (a[i] > a[i+1])
            {
                j = i+1;
                while (true)
                {
                    while (mr[j] != 0) j += mr[j];
                    j++;
                    while (j < r && a[j] < a[i] && mr[j] == 0) j++;
                    if (j == r || a[j] >= a[i])
                    {
                        mr[i] = j - i - 1;
                        break;
                    }
                }
            }
            else mr[i] = 0;
        }
        long long ret = 0;
        for (i = l; i < r; i++)
            ret += (long long)a[i] * (long long)(ml[i] + mr[i] + ml[i]*mr[i] + 1);
        printf("%I64d\n", ret);
    }
}


#include <stdio.h>
#include <string.h>
#include <cmath>
#include <iostream>
using namespace std;
long long a[100001], ml[100001], mr[100001];
int main()
{
    int n, val, pre, l, r, i, j, q;
    scanf("%d%d", &n, &q); scanf("%d", &pre);
    for (i = 1; i < n; i++)
    {
        scanf("%d", &val);
        a[i] = abs(val-pre);
        pre = val;
    }
    while (q--)
    {
        scanf("%d%d", &l, &r);
        memset(ml, 0, sizeof ml);
        memset(mr, 0, sizeof mr);
        ml[l] = 0;
        for (i = l+1; i < r; i++)
        {
            if (a[i] >= a[i-1])
            {
                j = i-1;
                while (true)
                {
                    while (ml[j] != 0) j -= ml[j];
                    j--;
                    while (j >= l && a[j] <= a[i] && ml[j] == 0) j--;
                    if (j < l || a[j] > a[i])
                    {
                        ml[i] = i - j - 1;
                        break;
                    }
                }
            }
            else ml[i] = 0;
        }

        mr[r-1] = 0;
        for (i = r-2; i >= l; i--)
        {
            if (a[i] > a[i+1])
            {
                j = i+1;
                while (true)
                {
                    while (mr[j] != 0) j += mr[j];
                    j++;
                    while (j < r && a[j] < a[i] && mr[j] == 0) j++;
                    if (j == r || a[j] >= a[i])
                    {
                        mr[i] = j - i - 1;
                        break;
                    }
                }
            }
            else mr[i] = 0;
        }
        long long ret = 0;
        for (i = l; i < r; i++)
            ret += a[i] * (long long)(ml[i] + mr[i] + ml[i]*mr[i] + 1LL);
        printf("%I64d\n", ret);
    }
}


#include<bits/stdc++.h>
using namespace std;
int n,q,a[100010],pre[100010],pos[100010],l,r;
long long ans;
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>q;
	for(register int i=1;i<=n;++i)
		cin>>a[i];
	for(register int i=1;i<n;++i){
		a[i]=max(a[i],a[i+1])-min(a[i],a[i+1]);
		pre[i]=1;
		for(register int j=i-1;j>=1;)
			if(a[i]>a[j])pre[i]+=pre[j],j-=pre[j];
			else break;
	}
	for(register int i=n-1;i>=1;--i){
		pos[i]=1;
		for(register int j=i+1;j<n;)
			if(a[i]>=a[j])pos[i]+=pos[j],j+=pos[j];
			else break;
	}
	while(q--){
		cin>>l>>r;
		ans=0;
		for(register int i=l;i<r;++i)
			ans+=(long long)min(i-l+1,pre[i])*min(r-i,pos[i])*a[i];
		cout<<ans<<'\n';
	}
}


#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=1001100;
int num[maxn];
int c[maxn];
int l[maxn],r[maxn];
int n;
int st[maxn];
int t=0;
int u,v;
int ABS(int x)
{
    if(x>0) return x;
    return -x;
}
void init()
{
    for(int i=0;i<n-1;++i) c[i]=ABS(num[i+1]-num[i]);
    --n;
    t=0;
    for(int i=0;i<n;++i)
    {
        while(t>0&&c[st[t-1]]<c[i]) t--;
        l[i]=t==0?0:(st[t-1]+1);
        st[t++]=i;
    }
    t=0;
    for(int i=n-1;i>=0;--i)
    {
        while(t>0&&c[st[t-1]]<=c[i]) t--;
        r[i]=t==0?n-1:st[t-1]-1;
        st[t++]=i;
    }
}
ll query(int x,int y)
{
    ll tot=0;
    ll L,R;
    for(int i=x;i<=y;++i)
    {
        L=max(x,l[i]);
        R=min(y,r[i]);
        tot+=(ll)(i-L+1)*(ll)(R-i+1)*(ll)c[i];
    }
    return tot;
}
int main()
{
    int q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",&num[i]);
    init();
    //for(int i=0;i<n;++i) cout<<i<<" "<<c[i]<<endl;
    //for(int i=0;i<n;++i) cout<<i<<" "<<l[i]<<" "<<r[i]<<endl;
    for(int i=0;i<q;++i)
    {
        scanf("%d%d",&u,&v);
        printf("%lld\n",query(u-1,v-2));
    }
    return 0;
}


#include<cstdio>
#include<cmath>
#include<stdlib.h>
#include<map>
#include<set>
#include<time.h>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define eps 1e-8
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)<0?-(a):(a))

struct nod
{
    int pos;
    int num;
}nd[100005];
long long r[100005],l[100005];
stack <nod>stk;
int main()
{
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&nd[i].num);
        nd[i].pos=i;
    }
    for(int i=0;i<n-1;i++)
    {
        nd[i].num=ABS(nd[i+1].num-nd[i].num);
    }
    while(q--)
    {
        int L,R;
        scanf("%d%d",&L,&R);
        L--;
        R--;
        while(!stk.empty())
            stk.pop();
        for(int i=L;i<R;i++)
        {
            if(stk.empty())
                stk.push(nd[i]);
            else
            {
                while(!stk.empty())
                {
                    nod tmp=stk.top();
                    if(tmp.num<nd[i].num)
                    {
                        r[tmp.pos]=i-1;
                        stk.pop();
                    }
                    else
                        break;
                }
                stk.push(nd[i]);
            }
        }
//        printf("!");
        int rit=stk.top().pos;
        while(!stk.empty())
        {
            r[stk.top().pos]=rit;
            stk.pop();
        }
//        printf("!!");
        for(int i=R-1;i>=L;i--)
        {
            if(stk.empty())
                stk.push(nd[i]);
            else
            {
                while(!stk.empty())
                {
                    nod tmp=stk.top();
                    if(tmp.num<=nd[i].num)
                    {
                        l[tmp.pos]=i+1;
                        stk.pop();
                    }
                    else
                        break;
                }
                stk.push(nd[i]);
            }
        }
        int lft=stk.top().pos;
        while(!stk.empty())
        {
            l[stk.top().pos]=lft;
            stk.pop();
        }
        long long ans=0;
        for(int i=L;i<R;i++)
        {
//            printf("\t%I64d %I64d\n",l[i],r[i]);
            ans=ans+(i-l[i]+1)*(r[i]-i+1)*nd[i].num;
//            printf("\t\t%I64d\n",ans);
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;

int inline abs(int x) { return x < 0 ? -x : x; }

const int maxn = 100000 + 10;

int n, Q;

int a[maxn], d[maxn];

int l[maxn], r[maxn], cur[maxn];

//BIT
int C[maxn];

inline int lowbit(int x) { return x & (-x); }

int query1(int x) {
	int ans = 0;
	while(x) {
		ans = max(ans, C[x]);
		x -= lowbit(x);
	}
	return ans;
}

void update1(int x, int v) {
	while(x <= n) {
		C[x] = max(C[x], v);
		x += lowbit(x);
	}
}

int query2(int x) {
	int ans = n + 1;
	while(x) {
		ans = min(ans, C[x]);
		x -= lowbit(x);
	}
	return ans;
}

void update2(int x, int v) {
	while(x <= n) {
		C[x] = min(C[x], v);
		x += lowbit(x);
	}
}

int main()
{
	//freopen("D.txt", "r", stdin);

	scanf("%d%d", &n, &Q);
	for(int i = 0; i < n; i++) scanf("%d", a + i);
	for(int i = 1; i < n; i++) d[i] = abs(a[i] - a[i-1]);

	n--;
	for(int i = 1; i <= n; i++) a[i] = d[i];

	//Discrete
	sort(a + 1, a + 1 + n);
	int tot = unique(a + 1, a + 1 + n) - a - 1;
	for(int i = 1; i <= n; i++)
		d[i] = lower_bound(a + 1, a + 1 + tot, d[i]) - a;

	memset(C, 0, sizeof(C));
	for(int i = 1; i <= n; i++) {
		l[i] = query1(tot - d[i] + 1) + 1;
		update1(tot - d[i] + 1, i);
	}

	for(int i = 1; i <= tot; i++) C[i] = n + 1;
	for(int i = n; i >= 1; i--) {
		r[i] = query2(tot - d[i]) - 1;
		update2(tot - d[i] + 1, i);
	}

	while(Q--) {
		int L, R; scanf("%d%d", &L, &R);
		if(L == R) {
			printf("0\n");
			continue;
		}
		R--;
		LL ans = 0;
		for(int i = L; i <= R; i++) {
			int toL = max(l[i], L);
			int toR = min(r[i], R);
			ans += (LL)a[d[i]] * (i-toL+1) * (toR-i+1);
		}
		printf("%lld\n", ans);
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100005],righty[100005],lefty[100005],h[100005];
int main()
{
	int n,q;
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n-1;i++)
	h[i]=abs(a[i+1]-a[i]);
	stack<int> temp;
	for(int i=1;i<=n-1;i++)
	{
		while(!temp.empty()&&h[i]>h[temp.top()])
		{
			righty[temp.top()]=i;
			temp.pop();
		}
		temp.push(i);
	}
	while(!temp.empty())
	{
		righty[temp.top()]=n;
		temp.pop();
	}
	for(int i=n-1;i>=1;i--)
	{
		while(!temp.empty()&&h[i]>=h[temp.top()])
		{
			lefty[temp.top()]=i;
			temp.pop();
		}
		temp.push(i);
	}
	while(!temp.empty())
	{
		lefty[temp.top()]=0;
		temp.pop();
	}
	while(q--)
	{
		int l,r;
		long long ans=0;
		scanf("%d%d",&l,&r);
		//l--;
		r--;
		for(int j=l;j<=r;j++)
		{
			ans+=1ll*h[j]*(j-max(lefty[j],l-1))*(min(righty[j],r+1)-j);
		}
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>
#define inf 1e9
#define X first
#define Y second

using namespace std;
typedef __int64 LL;
typedef pair<int, int> P;
const int maxn = 1e5+10;

int n, q;
int a[maxn], b[maxn];
int L[maxn], R[maxn];

int _abs(int x)
{
    if(x < 0) return -x;
    return x;
}

P st[maxn];
int top = -1;

void init()
{
    for(int i = 1;i<n;i++)
        b[i] = abs(a[i + 1] - a[i]);
    top = -1;
    st[++top] = P(inf, 0);
    for(int i = 1;i<n;i++)
    {
        int j;
        for(j = top;j>=0;j--)
        {
            if(b[i]<=st[j].X)   break;
            else    R[st[j].Y] = i-1;
        }
        L[i] = st[j].Y+1;
        top = j;
        st[++top] = P(b[i], i);
    }
    for(int i = 0;i<=top;i++)
        R[st[i].Y] = n - 1;
}

void solve(int l, int r)
{
    LL ans = 0;
    for(int i = l;i<r;i++)
    {
        LL left = (i - max(L[i], l) + 1);
        LL right = (min(R[i], r - 1) - i + 1);
        ans += left * right * b[i];
    }
    cout<<ans<<endl;
}

int main()
{
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    init();
    while(q--)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        solve(u, v);
    }
    return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll __int64
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5+5;
int n, q;
int a[maxn], b[maxn];
int l[maxn], r[maxn];
pii hehe[maxn];

void init(){
    for(int i = 1;i<n;i++)  b[i] = abs(a[i] - a[i+1]);
    int cnt = -1;
    hehe[++cnt] = make_pair(INF, 0);
    int j;
    for(int i = 1;i<n;i++){
        for(j = cnt;j>=0;j--){
            if(b[i] <= hehe[j].first)   break;
            else    r[hehe[j].second] = i-1;
        }
        l[i] = hehe[j].second+1;
        cnt = j;
        hehe[++cnt] = make_pair(b[i], i);
    }
    for(int i = 0;i<=cnt;i++)   r[hehe[i].second] = n-1;
}

int main(){
    scanf("%d%d", &n, &q);
    for(int i = 1;i<=n;i++)
        scanf("%d", &a[i]);
    init();
    while(q--){
        int u, v;
        scanf("%d%d", &u, &v);
        ll ans = 0;
        for(int i = u;i<v;i++){
            ll k1 = i-max(l[i], u)+1;
            ll k2 = min(r[i], v-1)-i+1;
            ans += (k1*k2*b[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define inf 1e9
#define X first
#define Y second

using namespace std;
typedef __int64 LL;
typedef pair<int, int> P;
const int maxn = 1e5+10;

int a[maxn], b[maxn];
int l[maxn], r[maxn];
P st[maxn];
int n, q;

void init()
{
    for(int i = 1;i<n;i++)
        b[i] = abs(a[i + 1] - a[i]);
    int top = -1;
    st[++top] = P(inf, 0);
    for(int i = 1;i<n;i++)
    {
        int j;
        for(j = top;j>=0;j--)
        {
            if(b[i]<=st[j].X)   break;
            else    r[st[j].Y] = i-1;
        }
        l[i] = st[j].Y+1;
        top = j;
        st[++top] = P(b[i], i);
    }
    for(int i = 0;i<=top;i++)
        r[st[i].Y] = n - 1;
}

void solve(int ll, int rr)
{
    LL ans = 0;
    for(int i = ll;i<rr;i++)
    {
        LL L = i-max(l[i], ll)+1;
        LL R = min(r[i], rr-1)-i+1;
        ans += L*R*b[i];
    }
    cout<<ans<<endl;
}

int main()
{
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    init();
    while(q--)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        solve(u, v);
    }
    return 0;
}


/*======================================================
# Author: whai
# Last modified: 2015-11-25 12:48
# Filename: d1.cpp
======================================================*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define LL __int64
#define PB push_back
#define P pair<int, int>
#define X first
#define Y second

const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int a[N];
int b[N];
int L[N], R[N];

int _abs(int x)
{
    if(x < 0) return -x;
    return x;
}

P st[N];
int top = -1;

void predo(int n)
{
    for(int i = 1; i < n; ++i)
    {
        b[i] = _abs(a[i + 1] - a[i]);
    }
    //for(int i = 1; i < n; ++i) {
    //  cout<<b[i]<<' ';
    //}
    //cout<<endl;
    top = -1;
    st[++top] = P(INF, 0);
    for(int i = 1; i < n; ++i)
    {
        int j;
        for(j = top; j >= 0; --j)
        {
            if(b[i] <= st[j].X) break;
            else R[st[j].Y] = i - 1;
        }
        L[i] = st[j].Y + 1;
        top = j;
        st[++top] = P(b[i], i);
    }
    for(int i = 0; i <= top; ++i)
    {
        R[st[i].Y] = n - 1;
    }
    //for(int i = 1; i < n; ++i) {
    //  cout<<L[i]<<' '<<R[i]<<endl;
    //}
}

void gao(int l, int r)
{
    LL ans = 0;
    for(int i = l; i < r; ++i)
    {
        LL left = (i - max(L[i], l) + 1);
        LL right = (min(R[i], r - 1) - i + 1);
        ans += left * right * b[i];
    }
    cout<<ans<<endl;

}

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)
    {
        scanf("%d", &a[i]);
    }
    predo(n);
    for(int i = 0; i < m; ++i)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        gao(u, v);
    }
    return 0;
}


#include<bits/stdc++.h>
#define inf 1e9

using namespace std;
const int maxn = 1e5+10;
typedef pair<int, int> P;
typedef __int64 LL;

int a[maxn], b[maxn];
int l[maxn], r[maxn];
P st[maxn];
int n, q;

void init()
{
    for(int i = 1;i<n;i++)
        b[i] = abs(a[i+1]-a[i]);
    int top = -1;
    st[++top] = P(inf, 0);
    for(int i = 1;i<n;i++)
    {
        int j;
        for(j = top;j>=0;j--)
        {
            if(b[i]<=st[j].first)   break;
            else        r[st[j].second] = i-1;
        }
        l[i] = st[j].second+1;
        top = j;
        st[++top] = P(b[i], i);
        for(int i = 0;i<=top;i++)
            r[st[i].second] = n-1;
    }
}

void solve(int ll, int rr)
{
    LL ans = 0;
    for(int i = ll;i<rr;i++)
    {
        LL L = i-max(l[i], ll)+1;
        LL R = min(r[i], rr-1)-i+1;
        ans += L*R*b[i];
    }
    cout<<ans<<endl;
}

int main()
{
    scanf("%d%d", &n, &q);
    for(int i = 1;i<=n;++i)
        scanf("%d", &a[i]);
    init();
    while(q--)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        solve(u, v);
    }
    return 0;
}


#include<bits/stdc++.h>
#define inf 1e9

using namespace std;
const int maxn = 1e5+10;
typedef pair<int, int> P;
typedef __int64 LL;

int a[maxn], b[maxn];
int l[maxn], r[maxn];
P st[maxn];
int n, q;

int _abs(int x)
{
    if(x < 0) return -x;
    return x;
}

void init()
{
    for(int i = 1;i<n;i++)
        b[i] = _abs(a[i+1]-a[i]);
    int top = -1;
    st[++top] = P(inf, 0);
    for(int i = 1;i<n;i++)
    {
        int j;
        for(j = top;j>=0;j--)
        {
            if(b[i]<=st[j].first)   break;
            else        r[st[j].second] = i-1;
        }
        l[i] = st[j].second+1;
        top = j;
        st[++top] = P(b[i], i);
        for(int i = 0;i<=top;i++)
            r[st[i].second] = n-1;
    }
}

void solve(int ll, int rr)
{
    LL ans = 0;
    for(int i = ll;i<rr;i++)
    {
        LL L = i-max(l[i], ll)+1;
        LL R = min(r[i], rr-1)-i+1;
        ans += L*R*b[i];
    }
    cout<<ans<<endl;
}

int main()
{
    scanf("%d%d", &n, &q);
    for(int i = 1;i<=n;++i)
        scanf("%d", &a[i]);
    init();
    while(q--)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        solve(u, v);
    }
    return 0;
}


#include<bits/stdc++.h>
#define inf 1e9
#define X first
#define Y second

using namespace std;
typedef __int64 LL;
typedef pair<int, int> P;
const int maxn = 1e5+10;

int n, q;
int a[maxn], b[maxn];
int L[maxn], R[maxn];

int _abs(int x)
{
    if(x < 0) return -x;
    return x;
}

P st[maxn];
int top = -1;

void init()
{
    for(int i = 1;i<n;i++)
        b[i] = _abs(a[i + 1] - a[i]);
    top = -1;
    st[++top] = P(inf, 0);
    for(int i = 1;i<n;i++)
    {
        int j;
        for(j = top;j>=0;j--)
        {
            if(b[i]<=st[j].X)   break;
            else    R[st[j].Y] = i-1;
        }
        L[i] = st[j].Y+1;
        top = j;
        st[++top] = P(b[i], i);
    }
    for(int i = 0;i<=top;i++)
        R[st[i].Y] = n - 1;
}

void solve(int l, int r)
{
    LL ans = 0;
    for(int i = l;i<r;i++)
    {
        LL left = (i - max(L[i], l) + 1);
        LL right = (min(R[i], r - 1) - i + 1);
        ans += left * right * b[i];
    }
    cout<<ans<<endl;
}

int main()
{
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    init();
    while(q--)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        solve(u, v);
    }
    return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll __int64
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5+5;
int n, q;
int a[maxn], b[maxn];
int l[maxn], r[maxn];
pii hehe[maxn];

void init(){
    for(int i = 1;i<n;i++)  b[i] = abs(a[i] - a[i+1]);
    int cnt = -1;
    hehe[++cnt] = make_pair(INF, 0);
    int j;
    for(int i = 1;i<n;i++){
        for(j = cnt;j>=0;j--){
            if(b[i] <= hehe[j].first)   break;
            else    r[hehe[j].second] = i-1;
        }
        l[i] = hehe[j].second+1;
        cnt = j;
        hehe[++cnt] = make_pair(b[i], i);
    }
    for(int i = 0;i<=cnt;i++)   r[hehe[i].second] = n-1;
}

int main(){
    scanf("%d%d", &n, &q);
    for(int i = 1;i<=n;i++)
        scanf("%d", &a[i]);
    init();
    while(q--){
        int u, v;
        scanf("%d%d", &u, &v);
        int ans = 0;
        for(int i = u;i<v;i++){
            ll k1 = i-max(l[i], u)+1;
            ll k2 = min(r[i], v-1)-i+1;
            ans += (k1*k2*b[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define inf 1e9
#define X first
#define Y second

using namespace std;
const int maxn = 1e5+10;
typedef pair<int, int> P;
typedef __int64 LL;

int a[maxn], b[maxn];
int l[maxn], r[maxn];
P st[maxn];
int n, q;

int _abs(int x)
{
    if(x < 0) return -x;
    return x;
}

void init()
{
    for(int i = 1;i<n;i++)
        b[i] = _abs(a[i+1]-a[i]);
    int top = -1;
    st[++top] = P(inf, 0);
    for(int i = 1;i<n;i++)
    {
        int j;
        for(j = top;j>=0;j--)
        {
            if(b[i]<=st[j].X)   break;
            else        r[st[j].Y] = i-1;
        }
        l[i] = st[j].Y+1;
        top = j;
        st[++top] = P(b[i], i);
        for(int i = 0;i<=top;i++)
            r[st[i].Y] = n-1;
    }
}

void solve(int ll, int rr)
{
    LL ans = 0;
    for(int i = ll;i<rr;i++)
    {
        LL L = i-max(l[i], ll)+1;
        LL R = min(r[i], rr-1)-i+1;
        ans += L*R*b[i];
    }
    cout<<ans<<endl;
}

int main()
{
    scanf("%d%d", &n, &q);
    for(int i = 1;i<=n;++i)
        scanf("%d", &a[i]);
    init();
    while(q--)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        solve(u, v);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i = 1;i <= n;i ++)
#define mp make_pair
#define sec second
#define frt first
int h,tp,n,q,a[1000005];
pair<int,int> stk[1005];
typedef __int64 LL;
LL ans,tmp;
void Qry(int id,int val)
{
	while(tp - 2 >= h)
	{
		if(stk[tp - 1].sec <= val)
			tmp -= 1ll * stk[tp - 1].sec * (stk[tp - 1].frt - stk[tp - 2].frt),tp --;
		else break;
	}
	stk[tp ++] = mp(id,val);
	tmp += 1ll * val * (id - stk[tp - 2].frt);
}
int main()
{
	scanf("%d%d",&n,&q);
	Rep(i,n)scanf("%d",&a[i]);
	Rep(p,q)
	{
		int l,r;
		ans = 0;
		tmp = 0;
		h = tp = 0;
		scanf("%d%d",&l,&r);
		stk[tp ++] = mp(l,0x3fffffff);
		for(int i = l + 1;i <= r; i ++)Qry(i,abs(a[i] - a[i - 1])),ans += tmp;
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i = 1;i <= n;i ++)
#define mp make_pair
#define sec second
#define frt first
int tp,n,q,a[1000005];
pair<int,int> stk[1005];
typedef long long LL;
LL ans,tmp;
void Qry(int id,int val)
{
	while(tp > 1)
	{
		if(stk[tp - 1].sec <= val)
			tmp -= 1ll * stk[tp - 1].sec * (stk[tp - 1].frt - stk[tp - 2].frt),tp --;
		else break;
	}
	stk[tp ++] = mp(id,val);
	tmp += 1ll * val * (id - stk[tp - 2].frt);
	ans += tmp;
}
int main()
{
	scanf("%d%d",&n,&q);
	Rep(i,n)scanf("%d",&a[i]);
	Rep(i,q)
	{
		int l,r;
		ans = 0;
		tmp = 0;
		tp = 0;
		scanf("%d%d",&l,&r);
		stk[tp ++] = mp(l,0x3f3f3f);
		for(int j = l + 1;j <= r; j ++)Qry(j,abs(a[j] - a[j - 1]));
		printf("%lld\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i = 1;i <= n;i ++)
#define mp make_pair
#define sec second
#define frt first
int tp,n,q,a[1000005];
pair<int,int> stk[1005];
typedef long long LL;
LL ans,tmp;
void Qry(int id,int val)
{
	while(tp >= 2)
	{
		if(stk[tp - 1].sec <= val)
			tmp -= 1ll * stk[tp - 1].sec * (stk[tp - 1].frt - stk[tp - 2].frt),tp --;
		else break;
	}
	stk[tp ++] = mp(id,val);
	tmp += 1ll * val * (id - stk[tp - 2].frt);
}
int main()
{
	scanf("%d%d",&n,&q);
	Rep(i,n)scanf("%d",&a[i]);
	Rep(i,q)
	{
		int l,r;
		ans = 0;
		tmp = 0;
		tp = 0;
		scanf("%d%d",&l,&r);
		stk[tp ++] = mp(l,0x3fffffff);
		for(int j = l + 1;j <= r; j ++)Qry(j,abs(a[j] - a[j - 1])),ans += tmp;
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i = 1;i <= n;i ++)
#define mp make_pair
#define sec second
#define frt first
int tp,n,q,a[100005];
pair<int,int> stk[100005];
typedef long long LL;
LL ans,tmp;
void Qry(int id,int val)
{
	while(tp > 1)
	{
		if(stk[tp - 1].sec <= val)
			tmp -= 1ll * stk[tp - 1].sec * (stk[tp - 1].frt - stk[tp - 2].frt),tp --;
		else break;
	}
	stk[tp ++] = mp(id,val);
	tmp += 1ll * val * (id - stk[tp - 2].frt);
}
int main()
{
	scanf("%d%d",&n,&q);
	Rep(i,n)scanf("%d",&a[i]);
	Rep(p,q)
	{
		int l,r;
		ans = 0;
		tmp = 0;
		tp = 0;
		scanf("%d%d",&l,&r);
		stk[tp ++] = mp(l,0x3fffffff);
		for(int i = l + 1;i <= r; i ++)Qry(i,abs(a[i] - a[i - 1])),ans += tmp;
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i = 1;i <= n;i ++)
#define mp make_pair
#define sec second
#define frt first
int tp,n,q,a[1000005];
pair<int,int> stk[1005];
typedef long long LL;
LL ans,tmp;
void Qry(int id,int val)
{
	while(tp >= 2)
	{
		if(stk[tp - 1].sec <= val)
			tmp -= 1ll * stk[tp - 1].sec * (stk[tp - 1].frt - stk[tp - 2].frt),tp --;
		else break;
	}
	stk[tp ++] = mp(id,val);
	tmp += 1ll * val * (id - stk[tp - 2].frt);
	ans += tmp;
}
int main()
{
	scanf("%d%d",&n,&q);
	Rep(i,n)scanf("%d",&a[i]);
	Rep(i,q)
	{
		int l,r;
		ans = 0;
		tmp = 0;
		tp = 0;
		scanf("%d%d",&l,&r);
		stk[tp ++] = mp(l,0x3fffffff);
		for(int j = l + 1;j <= r; j ++)Qry(j,abs(a[j] - a[j - 1]));
		printf("%lld\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i = 1;i <= n;i ++)
#define mp make_pair
#define sec second
#define frt first
int tp,n,q,a[1000005];
pair<int,int> stk[1005];
typedef long long LL;
LL ans,tmp;
void Qry(int id,int val)
{
	while(tp > 1)
	{
		if(stk[tp - 1].sec <= val)
			tmp -= 1ll * stk[tp - 1].sec * (stk[tp - 1].frt - stk[tp - 2].frt),tp --;
		else break;
	}
	stk[tp ++] = mp(id,val);
	tmp += 1ll * val * (id - stk[tp - 2].frt);
	ans += tmp;
}
int main()
{
	scanf("%d%d",&n,&q);
	Rep(i,n)scanf("%d",&a[i]);
	Rep(i,q)
	{
		int l,r;
		ans = 0;
		tmp = 0;
		tp = 0;
		scanf("%d%d",&l,&r);
		stk[tp ++] = mp(l,1 << 30);
		for(int j = l + 1;j <= r; j ++)Qry(j,abs(a[j] - a[j - 1]));
		printf("%lld\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i = 1;i <= n;i ++)
#define mp make_pair
#define sec second
#define frt first
int tp,n,q,a[1000005];
pair<int,int> stk[1005];
typedef long long LL;
LL ans,tmp;
void Qry(int id,int val)
{
	while(tp > 1)
	{
		if(stk[tp - 1].sec <= val)
			tmp -= 1ll * stk[tp - 1].sec * (stk[tp - 1].frt - stk[tp - 2].frt),tp --;
		else break;
	}
	stk[tp ++] = mp(id,val);
	tmp += 1ll * val * (id - stk[tp - 2].frt);
	ans += tmp;
}
int main()
{
	scanf("%d%d",&n,&q);
	Rep(i,n)scanf("%d",&a[i]);
	Rep(i,q)
	{
		int l,r;
		ans = 0;
		tmp = 0;
		scanf("%d%d",&l,&r);
		stk[tp ++] = mp(l,1 << 30);
		for(int j = l + 1;j <= r; j ++)Qry(j,abs(a[j] - a[j - 1]));
		printf("%lld\n",ans);
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
typedef __int64 LL;
typedef unsigned __int64 LLU;
const int nn=110000;
const int inf=0x3fffffff;
const LL inf64=(LL)inf*inf;
const double eps = 1e-12;
const int mod = 1000000007;
using namespace std;
int n,q;
int a[nn];
int l,r;
LL tem;
pair<int,int>que[nn];
int tou,wei;
void add(int id,int val)
{
    while(wei-2>=tou)
    {
        if(val>=que[wei-1].second)
        {
            tem-=1LL*que[wei-1].second*(que[wei-1].first-que[wei-2].first);
            wei--;
        }
        else
            break;
    }
    que[wei++]=make_pair(id,val);
    tem+=1LL*val*(id-que[wei-2].first);
}
int main()
{
    int i;
    while(scanf("%d%d",&n,&q)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        while(q--)
        {
            scanf("%d%d",&l,&r);
            LL ans=0;
            tem=0;
            tou=wei=0;
            que[wei++]=make_pair(l,inf);
            for(i=l+1;i<=r;i++)
            {
                add(i,abs(a[i]-a[i-1]));
                ans+=tem;
            }
            printf("%I64d\n",ans);
        }
    }
    return 0;
}


/* ***********************************************
Author :111qqz
Created Time :2015年12月22日 星期二 22时58分35秒
File Name :code/cf/#333/D.cpp
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair
#define left lllllxy
#define right rrrrrxy
using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;
const int N=1E5+7;
int n ;
int q;
LL a[N],b[N];
int left[N];
int right[N];
int main()
{
    #ifndef  ONLINE_JUDGE
    freopen("code/in.txt","r",stdin);
  #endif

    cin>>n;
    cin>>q;
    for ( int i = 1 ; i <= n ; i++)
    {
        cin>>a[i];

    }
    for ( int i = 2 ;i  <= n ; i++)
    {
        b[i] = abs(a[i]-a[i-1]);
    }

    while (q--)
    {
        int l,r;
        scanf("%d %d",&l,&r);
        l++;

        for ( int i = l ; i <= r ; i++)        //以b[i]为最大值，最左能到达多远。
        {
        left[i] = i ;
        while (left[i]>l&&b[i]>b[left[i]-1])
            left[i] = left[left[i]-1];
        }
        for ( int i = r ; i >= l ; i--)         //最右能到达多远。
        {
        right[i] = i;
        while (right[i] < r &&b[i]>=b[right[i]+1])
            right[i] = right[right[i] + 1];
            }
        LL ans= 0 ;
        for ( int i = l ; i <= r ; i++)
        ans +=(LL)(right[i]-i+1)*(LL)(i-left[i]+1)*b[i];
        cout<<ans<<endl;

    }

  #ifndef ONLINE_JUDGE
  fclose(stdin);
  #endif
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
namespace io
{
    //long long
    int F()
    {
        /*long long*/int n;
        char Ch,F=0;
        while(((Ch=getchar())<'0' || Ch>'9') && Ch!='-') ;
        Ch=='-'?n=F=0:(n=Ch-'0',F=1);
        while((Ch=getchar())>='0'&&Ch<='9') n*=10,n+=Ch-'0';
        return F?n:-n;
    }
}
int a[111111];
int l[111111];
int r[111111];
int s[111111];
int p[111111];
int top=0;
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	//freopen(".in","w",stdout);
	int n,q;
	n=io::F();q=io::F();
	for(register int i=1;i<=n;++i)
		a[i]=io::F();
	for(register int i=1;i<=n;++i)
		a[i]=abs(a[i]-a[i+1]);
	a[n]=1000000000;
	for(register int i=1;i<=n;++i)
	{
		while(top&&s[top]<=a[i])r[p[top--]]=i-1;
		s[++top]=a[i];
		p[top]=i;
	}
	top=0;
	a[0]=1000000000;
	for(register int i=n-1;i>=0;--i)
	{
		while(top&&s[top]<a[i])l[p[top--]]=i+1;
		s[++top]=a[i];
		p[top]=i;
	}
	int x,y;
	for(register int i=1;i<=q;++i)
	{
		x=io::F(),y=io::F();
		long long ans=0;
		for(register int j=x;j<y;++j)
		{
			ans+=(long long)a[j]*(long long)(j-dmax(x,l[j])+1)*(dmin(y-1,r[j])-j+1);
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (root+root)
#define sag (root+root+1)
#define orta ((bas+son)/2)
#define ll long long
#define pii pair<int,int>

const int N=1e5+5;
const int mod=1e9+7;
const int inf=1e9+7;

int n,q,i,x,y,diff,beg,j;
int A[N];

ll t,ans;

stack<pii > s;

main(){

	scanf("%d %d",&n,&q);

	for(i=1 ; i<=n ; i++)
		scanf("%d",A+i);

	for(i=1 ; i<=q ; i++){
		scanf("%d %d",&x,&y);
		ans=t=0;
		while(s.size())
			s.pop();
		for(j=x+1 ; j<=y ; j++){
			diff=abs(A[j]-A[j-1]);
			beg=j;
			while(s.size() and s.top().st<=diff){
				t-=(ll)s.top().st*(beg-s.top().nd);
				beg=s.top().nd;
				s.pop();
			}
			t+=(ll)diff*(j-beg+1);
			s.push(mp(diff,beg));
			ans+=t;
		}
		printf("%lld\n",ans);
	}

}


#include<bits/stdc++.h>

using namespace std;

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (root+root)
#define sag (root+root+1)
#define orta ((bas+son)/2)
#define ll long long
#define pii pair<int,int>

const int N=1e5+5;
const int mod=1e9+7;
const int inf=1e9+7;

int n,q,i,x,y,diff,beg,j;
int A[N];

ll t,ans;

stack<pii > s;

main(){

	scanf("%d %d",&n,&q);

	for(i=1 ; i<=n ; i++)
		scanf("%d",A+i);

	for(i=1 ; i<=q ; i++){
		scanf("%d %d",&x,&y);
		ans=t=0;
		while(s.size())
			s.pop();
		for(j=x+1 ; j<=y ; j++){
			diff=abs(A[j]-A[j-1]);
			beg=j;
			while(s.size() and s.top().st<=diff){
				t-=s.top().st*(beg-s.top().nd);
				beg=s.top().nd;
				s.pop();
			}
			t+=diff*(j-beg+1);
			s.push(mp(diff,beg));
			ans+=t;
		}
		printf("%lld\n",ans);
	}

}


#include <iostream>
#include <cstdio>
#include <cmath>
typedef long long ll;
using namespace std;
const int nmax = 131072, inf = 1 << 29;
int n, a[nmax], l[nmax], r[nmax];
ll ans;
int main()
{
	int i, j, q, u, v;
	cin >> n >> q;
	for (i = 0; i < n; i++)
		scanf("%d", a + i);
	for (i = n - 1; i; i--)
		a[i] = abs(a[i] - a[i - 1]);
	a[0] = a[n] = inf;
	n--;
	/*for (i = 1; i <= n; i++)
		printf("%d ", a[i]);
	printf("\n");*/
	l[0] = 0;
	for (i = 1; i <= n; i++)
	{
		for (j = i - 1; a[j] <= a[i]; j = l[j]);
		l[i] = j;
	}
	r[n + 1] = n + 1;
	for (i = n; i; i--)
	{
		for (j = i + 1; a[j] < a[i]; j = r[j]);
		r[i] = j;
	}
	/*for (i = 1; i <= n; i++)
		printf("l %d  r %d\n", l[i], r[i]);*/
	while (q--)
	{
		scanf("%d%d", &u, &v);
		v--;
		ans = 0;
		for (i = u; i <= v; i++)
			ans += (i - max(l[i], u - 1)) * ll(min(r[i], v + 1) - i) * a[i];
		printf("%I64d\n", ans);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#define mid ((l+r)>>1)
#define ls (n>>1)
#define rs ((n>>1)+1)
using namespace std;
/*long long treemin[100001];
long long treemax[100001];
long long treeans[100001];
long long a[100001];
void bulid(int n,int l,int r){
	if(l==r){
		treemin[n]=a[l];
		treemax[n]=a[r];
		treeans[n]=0;
		return;
	}
	else{
		build(ls,l,mid);
		bulid(rs,mid+1,r);
		treemin[n]=min()
	}
}*/
long long dp[5001][5001];
long long ans[5001][5001];
long long a[10001];
int main(){
	int n,q;cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int k=1;k<=n;k++)
	for(int i=1;i+k-1<=n;i++){
		int j=i+k-1;
		if(i==j)continue;
		dp[i][j]=max(dp[i+1][j],dp[i][j-1]);
		dp[i][j]=max(dp[i][j],(long long)ceil(abs(a[j]-a[i])*1.0/(k-1)));
		ans[i][j]=ans[i+1][j]+ans[i][j-1]-ans[i+1][j-1]+dp[i][j];
	}
	int x,y;
	for(int i=1;i<=q;i++){
		cin>>x>>y;
		cout<<ans[x][y]<<'\n';
	}
}


#include<iostream>
#include<cstdio>
#include<cmath>
#define mid ((l+r)>>1)
#define ls (n>>1)
#define rs ((n>>1)+1)
using namespace std;
/*long long treemin[100001];
long long treemax[100001];
long long treeans[100001];
long long a[100001];
void bulid(int n,int l,int r){
	if(l==r){
;
		treeans[n]=0;
		return;
	}
	else{
		build(ls,l,mid);
		bulid(rs,mid+1,r);
		treemin[n]=min()
	}
}*/
long long dp[3001][3001];
long long ans[3001][3001];
long long a[10001];
int main(){
	int n,q;cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int k=1;k<=n;k++)
	for(int i=1;i+k-1<=n;i++){
		int j=i+k-1;
		if(i==j)continue;
		dp[i][j]=max(dp[i+1][j],dp[i][j-1]);
		dp[i][j]=max(dp[i][j],(long long)ceil(abs(a[j]-a[i])*1.0/(k-1)));
		ans[i][j]=ans[i+1][j]+ans[i][j-1]-ans[i+1][j-1]+dp[i][j];
	}
	int x,y;
	for(int i=1;i<=q;i++){
		cin>>x>>y;
		cout<<ans[x][y]<<'\n';
	}
}


#include<iostream>
#include<cstdio>
#include<cmath>
#define mid ((l+r)>>1)
#define ls (n>>1)
#define rs ((n>>1)+1)
using namespace std;
/*
		treemax[n]=a[r];
		treeans[n]=0;
		return;
	}
	else{
		build(ls,l,mid);
		bulid(rs,mid+1,r);
		treemin[n]=min()
	}
}*/
long long dp[3001][3001];
long long ans[3001][3001];
long long a[10001];
int main(){
	int n,q;cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int k=1;k<=n;k++)
	for(int i=1;i+k-1<=n;i++){
		int j=i+k-1;
		if(i==j)continue;
		dp[i][j]=max(dp[i+1][j],dp[i][j-1]);
		dp[i][j]=max(dp[i][j],(long long)ceil(abs(a[j]-a[i])*1.0/(k-1)));
		ans[i][j]=ans[i+1][j]+ans[i][j-1]-ans[i+1][j-1]+dp[i][j];
	}
	int x,y;
	for(int i=1;i<=q;i++){
		cin>>x>>y;
		cout<<ans[x][y]<<'\n';
	}
}


#include<iostream>
#include<cstdio>
#include<cmath>
#define mid ((l+r)>>1)
#define ls (n>>1)
#define rs ((n>>1)+1)
using namespace std;
/*long long treemin[100001];
long long treemax[100001];
long long treeans[100001];
long long a[100001];
void bulid(int n,int l,int r){
	if(l==r){
		treemin[n]=a[l];
		treemax[n]=a[r];
		treeans[n]=0;
		return;
	}
	else{
		build(ls,l,mid);
		bulid(rs,mid+1,r);
		treemin[n]=min()
	}
}*/
int dp[5001][5001];
int ans[5001][5001];
int a[10001];
int main(){
	int n,q;cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int k=1;k<=n;k++)
	for(int i=1;i+k-1<=n;i++){
		int j=i+k-1;
		if(i==j)continue;
		dp[i][j]=max(dp[i+1][j],dp[i][j-1]);
		dp[i][j]=max(dp[i][j],(int)ceil(abs(a[j]-a[i])*1.0/(k-1)));
		ans[i][j]=ans[i+1][j]+ans[i][j-1]-ans[i+1][j-1]+dp[i][j];
	}
	int x,y;
	for(int i=1;i<=q;i++){
		cin>>x>>y;
		cout<<ans[x][y]<<'\n';
	}
}


#include<iostream>
#include<cstdio>
#include<cmath>
#define mid ((l+r)>>1)
#define ls (n>>1)
#define rs ((n>>1)+1)
using namespace std;
/*long long treemin[100001];
long long treemax[100001];
long long treeans[100001];
long long a[100001];
void bulid(int n,int l,int r){
	if(l==r){
		treemin[n]=a[l];
		treemax[n]=a[r];
		treeans[n]=0;
		return;
	}
	else{
		build(ls,l,mid);
		bulid(rs,mid+1,r);
		treemin[n]=min()
	}
}*/
long long dp[3001][3001];
long long ans[3001][3001];
long long a[10001];
int main(){
	int n,q;cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int k=1;k<=n;k++)
	for(int i=1;i+k-1<=n;i++){
		int j=i+k-1;
		if(i==j)continue;
		dp[i][j]=max(dp[i+1][j],dp[i][j-1]);
		dp[i][j]=max(dp[i][j],(long long)ceil(abs(a[j]-a[i])*1.0/(k-1)));
		ans[i][j]=ans[i+1][j]+ans[i][j-1]-ans[i+1][j-1]+dp[i][j];
	}
	int x,y;
	for(int i=1;i<=q;i++){
		cin>>x>>y;
		cout<<ans[x][y]<<'\n';
	}
}


#include<iostream>
#include<cstdio>
#include<cmath>
#define mid ((l+r)>>1)
#define ls (n>>1)
#define rs ((n>>1)+1)
using namespace std;
/*long long treemin[100001];
long long treemax[100001];
long long treeans[100001];
long long a[100001];
void bulid(int n,int l,int r){
	if(l==r){
		treemin[n]=a[l];
		treemax[n]=a[r];
		treeans[n]=0;
		return;
	}
	else{
		build(ls,l,mid);
		bulid(rs,mid+1,r);
		treemin[n]=min()
	}
}*/
long long dp[3001][3001];
long long ans[5001][5001];
long long a[10001];
int main(){
	int n,q;cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int k=1;k<=n;k++)
	for(int i=1;i+k-1<=n;i++){
		int j=i+k-1;
		if(i==j)continue;
		dp[i][j]=max(dp[i+1][j],dp[i][j-1]);
		dp[i][j]=max(dp[i][j],(long long)ceil(abs(a[j]-a[i])*1.0/(k-1)));
		ans[i][j]=ans[i+1][j]+ans[i][j-1]-ans[i+1][j-1]+dp[i][j];
	}
	int x,y;
	for(int i=1;i<=q;i++){
		cin>>x>>y;
		cout<<ans[x][y]<<'\n';
	}
}


#include<iostream>
#include<cstdio>
#include<cmath>
#define mid ((l+r)>>1)
#define ls (n>>1)
#define rs ((n>>1)+1)
using namespace std;
/*long long treemin[100001];
long long treemax[100001];
long long treeans[100001];
long long a[100001];
void bulid(int n,int l,int r){
	if(l==r){
		treemin[n]=a[l];
		treemax[n]=a[r];
		treeans[n]=0;
		return;
	}
	else{
		build(ls,l,mid);
		bulid(rs,mid+1,r);
		treemin[n]=min()
	}
}*/
long long dp[3001][3001];
long long ans[3001][3001];
long long a[10001];
int main(){
	int n,q;cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int k=1;k<=n;k++)
	for(int i=1;i+k-1<=n;i++){
		int j=i+k-1;
		if(i==j)continue;
		dp[i][j]=max(dp[i+1][j],dp[i][j-1]);
		dp[i][j]=max(dp[i][j],(long long)ceil(abs(a[j]-a[i])*1.0/(k-1)));
		ans[i][j]=ans[i+1][j]+ans[i][j-1]-ans[i+1][j-1]+dp[i][j];
	}
	int x,y;
	for(int i=1;i<=q;i++){
		cin>>x>>y;
		cout<<ans[x][y];
	}
}


#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
    system("halt");
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 100500
using namespace std;
int n,m;
int tmp[N];
int ttmp[N];
int l[N],r[N];
int main()
{
    int s,e;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&tmp[i]);
    }
    for(int i=1;i<n;i++)
    {
        ttmp[i]=max(tmp[i],tmp[i+1])-min(tmp[i],tmp[i+1]);
    }
    /*for(int i=1;i<=n;i++)
    {
        printf("%d ",ttmp[i]);
    }
    puts("");*/
    for(int i=1;i<n;i++)
    {
        l[i]=1;
        for(int j=i-1;j>=1;)
        {
            if(ttmp[i]>ttmp[j])
            {
                l[i]+=l[j];
                j-=l[j];
            }
            else
            {
                break;
            }
        }
    }
    /*for(int i=1;i<n;i++)
    {
        printf("%d ",l[i]);
    }
    puts("");*/
    for(int i=n-1;i>=1;i--)
    {
        r[i]=1;
        for(int j=i+1;j<n;)
        {
            if(ttmp[i]>=ttmp[j])
            {
                r[i]+=r[j];
                j+=r[j];
            }
            else
            {
                break;
            }
        }
    }
    /*for(int i=1;i<n;i++)
    {
        printf("%d ",r[i]);
    }
    puts("");*/
    long long ans;
    for(int i=1;i<=m;i++)
    {
        ans=0;
        scanf("%d%d",&s,&e);
        for(int j=s;j<e;j++)
        {
            long long ll=min(j-s+1,l[j]);
            long long rr=min(e-j,r[j]);
            ans+=(ll*rr*ttmp[j]);
        }
        printf("%I64d\n",ans);
    }
}


#include<iostream>
#include<stack>
#include<queue>
#include<cmath>
using namespace std;
struct node{
	long long data;
	long long pos;
};
node a[100001];
int fr[100001],bk[100001];
stack<node>stk;
int main(){
	int  n,q;cin>>n>>q;
	long long buff=0;long long x;
	cin>>buff;
	for(int i=1;i<=n-1;i++){
		cin>>x;
		a[i].data=abs(buff-x);
		a[i].pos=i;
		buff=x;
	}
	//	for(int i=1;i<=n;i++)cout<<a[i].data<<' ';
	//	cout<<'\n';
	for(int i=1;i<=n-1;i++)
	{
		while(!stk.empty()&&a[i].data>=stk.top().data)stk.pop();
		if(stk.empty())fr[i]=1;
		else fr[i]=stk.top().pos+1;
		stk.push(a[i]);
	}
	while(!stk.empty())stk.pop();
	for(int i=n-1;i>=1;i--){
		while(!stk.empty()&&a[i].data>stk.top().data)stk.pop();
		if(stk.empty())bk[i]=n-1;
                else bk[i]=stk.top().pos-1;
                stk.push(a[i]);
	}
	//	for(int i=1;i<=n-1;i++){
	//	cout<<fr[i]<<' '<<bk[i]<<'\n';}
	for(int i=1;i<=q;i++){
		int x,y;cin>>x>>y;y--;
		long long ans=0;
		for(int i=x;i<=y;i++){
			ans+=(i-max(x,fr[i])+1)*(min(y,bk[i])-i+1)*a[i].data;
		}
		cout<<ans<<'\n';
	}
}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<int,int> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int,pair<int,int> > iii;
#define PI 3.141592653589793
#define mod 1000000009
# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF 100000
# define LG 20
typedef pair<int,pair<int,int> > pii;
# define INF_D 10000000000.00

int main()
{
	int n,q;
	cin >> n >> q;
	ll a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	while(q--)
	{
		ll u,v;
		ll ans=0;
		cin >> u >> v;
		u--;v--;
		ll b[n],lt[n],rt[n];
		ll k=0;
		for(int i=u;i<v;i++)
			b[k++]=abs(a[i+1]-a[i]);
		stack<ii>st;
		for(int i=0;i<k;i++)
		{
			while(!st.empty() && st.top().ff<=b[i]) st.pop();
			if(st.empty())
				lt[i]=-1;
			else
				lt[i]=st.top().ss;
			st.push(mp(b[i],i));
		}
		while(!st.empty())
			st.pop();
		for(int i=k-1;i>=0;i--)
		{
			while(!st.empty() && st.top().ff<b[i]) st.pop();
			if(st.empty())
				rt[i]=k;
			else
				rt[i]=st.top().ss;
			st.push(mp(b[i],i));
		}
		for(ll i=0;i<k;i++)
		{
			//trace3(b[i],lt[i],rt[i]);
			ans+=b[i]*(i-lt[i])*(rt[i]-i);
		}
		cout << ans<<"\n";

	}
}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<int,int> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int,pair<int,int> > iii;
#define PI 3.141592653589793
#define mod 1000000009
# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF 100000
# define LG 20
typedef pair<int,pair<int,int> > pii;
# define INF_D 10000000000.00

int main()
{
	int n,q;
	cin >> n >> q;
	ll a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	while(q--)
	{
		ll u,v;
		ll ans=0;
		cin >> u >> v;
		u--;v--;
		ll b[n],lt[n],rt[n];
		ll k=0;
		for(int i=u;i<v;i++)
			b[k++]=abs(a[i+1]-a[i]);
		stack<ii>st;
		for(int i=0;i<k;i++)
		{
			while(!st.empty() && st.top().ff<b[i]) st.pop();
			if(st.empty())
				lt[i]=-1;
			else
				lt[i]=st.top().ss;
			st.push(mp(b[i],i));
		}
		while(!st.empty())
			st.pop();
		for(int i=k-1;i>=0;i--)
		{
			while(!st.empty() && st.top().ff<=b[i]) st.pop();
			if(st.empty())
				rt[i]=k;
			else
				rt[i]=st.top().ss;
			st.push(mp(b[i],i));
		}
		for(ll i=0;i<k;i++)
		{
			//trace3(b[i],lt[i],rt[i]);
			ans+=b[i]*(i-lt[i])*(rt[i]-i);
		}
		cout << ans<<"\n";

	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 100010;
int n, q;
int left[MAXN], right[MAXN];
long long a[MAXN], b[MAXN];

int main()
{

	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++)
		scanf("%I64d", &a[i]);
	for (int i = 2; i <= n; i++)
		b[i] = abs(a[i] - a[i-1]);
	for (int kk = 0; kk < q; kk++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		l++;
		long long ans = 0LL;
		for (int i = l; i <= r; i++)
		{
			left[i] = i;
			while (left[i] > l && b[i] > b[left[i]-1])
				left[i] = left[left[i]-1];
		}
		for (int i = r; i >= l; i--)
		{
			right[i] = i;
			while (right[i] < r && b[i] >= b[right[i]+1])
				right[i] = right[right[i]+1];
		}
		for (int i = l; i <= r; i++)
		{
			ans += (right[i]-i+1) * (i-left[i]+1) * b[i];
		}
		printf("%I64d\n", ans);
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 100010;
int n, q;
int left[MAXN], right[MAXN];
long long a[MAXN], b[MAXN];

int main()
{

	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++)
		scanf("%I64d", &a[i]);
	for (int i = 2; i <= n; i++)
		b[i] = abs(a[i] - a[i-1]);
	for (int kk = 0; kk < q; kk++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		l++;
		long long ans = 0LL;
		for (int i = l; i <= r; i++)
		{
			left[i] = i;
			while (left[i] > l && b[i] > b[left[i]-1])
				left[i] = left[left[i]-1];
		}
		for (int i = r; i >= l; i--)
		{
			right[i] = i;
			while (right[i] < r && b[i] >= b[right[i]+1])
				right[i] = right[right[i]+1];
		}
		for (int i = l; i <= r; i++)
			ans += (long long)(right[i]-i+1) * (long long)(i-left[i]+1) * b[i];
		printf("%I64d\n", ans);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

#define point pair <long long, long long>

vector <point> v;
set <long long> S;

long long n, q;
long long a, b;
long long niz[101000];
long long sol;

int main (void) {
    cin >> n >> q;
    for (int i=1; i<=n; ++i) {
        cin >> niz[i];
    }
    for (int i=0; i<q; ++i) {
        cin >> a >> b;

        for (int j=a; j<b; ++j) {
            v.push_back( point ( abs(niz[j] - niz[j+1]), j ) );
        }

        sort(v.begin(), v.end());
        S.insert(a);
        S.insert(b);
        for (int i=v.size()-1; i>=0; --i) {
            set<long long>::iterator it = S.upper_bound(v[i].second);
            long long r1 = *it;
            it--;
            long long l1 = *it;
            //cout << "l1 : r1 " << l1 << " " << r1 << endl;
            //cout << v[i].second - l1 + 1<< " " << r1 - ( v[i].second + 1 ) + 1 << endl;
            //cout << "val " << v[i].first << endl;
            sol = sol + (v[i].second - l1 + 1) * (r1 - ( v[i].second + 1 ) + 1) * v[i].first;
            S.insert(v[i].second);
            S.insert(v[i].second + 1);
        }

        S.clear();
        v.clear();
        cout << sol << endl;
        sol = 0;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;

#define inf (1ll << 50)
#define point pair <long long, long long>

stack <point> S;

long long n, q, val, vr, poz;
long long a, b;
int niz[101000];
long long sol;

int main (void) {
    cin >> n >> q;
    for (int i=1; i<=n; ++i) {
        scanf("%d", &niz[i]);
    }
    for (int i=0; i<q; ++i) {
        cin >> a >> b;
        S.push(point(inf, a-1));
        for (int j=a; j<b; ++j) {
            val = abs(niz[j] - niz[j+1]);
            while (S.top().first < val) {
                poz = S.top().second;
                vr = S.top().first;
                S.pop();
                sol = sol + vr * (j - poz) * (poz - S.top().second);
            }
            S.push(point(val, j));
        }
        while (S.size() > 1) {
            poz = S.top().second;
            vr = S.top().first;
            S.pop();
            sol = sol + vr * (b - poz) * (poz - S.top().second);
        }

        cout << sol << endl;
        while(S.size() > 0) S.pop();
        sol = 0;
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <set>
using namespace std;

#define point pair <long long, long long>

vector <point> v;
set <int> S;

long long n, q;
long long a, b;
int niz[101000];
long long sol;

int main (void) {
    cin >> n >> q;
    for (int i=1; i<=n; ++i) {
        scanf("%d", &niz[i]);
    }
    for (int i=0; i<q; ++i) {
        cin >> a >> b;

        for (int j=a; j<b; ++j) {
            v.push_back( point ( abs(niz[j] - niz[j+1]), j ) );
        }

        sort(v.begin(), v.end());
        S.insert(a);
        S.insert(b);
        for (int i=v.size()-1; i>=0; --i) {
            set<int>::iterator it = S.upper_bound(v[i].second);
            long long r1 = *it;
            it--;
            long long l1 = *it;
            //cout << "l1 : r1 " << l1 << " " << r1 << endl;
            //cout << v[i].second - l1 + 1<< " " << r1 - ( v[i].second + 1 ) + 1 << endl;
            //cout << "val " << v[i].first << endl;
            sol = sol + (v[i].second - l1 + 1) * (r1 - ( v[i].second + 1 ) + 1) * v[i].first;
            S.insert(v[i].second);
            S.insert(v[i].second + 1);
        }

        S.clear();
        v.clear();
        cout << sol << endl;
        sol = 0;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

#define point pair <int, int>

vector <point> v;
set <int> S;

int n, q;
int a, b;
int niz[101000];
long long sol;

int main (void) {
    cin >> n >> q;
    for (int i=1; i<=n; ++i) {
        cin >> niz[i];
    }
    for (int i=0; i<q; ++i) {
        cin >> a >> b;

        for (int j=a; j<b; ++j) {
            v.push_back( point ( abs(niz[j] - niz[j+1]), j ) );
        }

        sort(v.begin(), v.end());
        S.insert(a);
        S.insert(b);
        for (int i=v.size()-1; i>=0; --i) {
            set<int>::iterator it = S.upper_bound(v[i].second);
            int r1 = *it;
            it--;
            int l1 = *it;
            //cout << "l1 : r1 " << l1 << " " << r1 << endl;
            //cout << v[i].second - l1 + 1<< " " << r1 - ( v[i].second + 1 ) + 1 << endl;
            //cout << "val " << v[i].first << endl;
            sol = sol + (v[i].second - l1 + 1) * (r1 - ( v[i].second + 1 ) + 1) * v[i].first;
            S.insert(v[i].second);
            S.insert(v[i].second + 1);
        }

        S.clear();
        v.clear();
        cout << sol << endl;
        sol = 0;
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#define lson (p<<1)
#define rson (lson | 1)
using namespace std;
const int N = 1e5+100;
typedef long long llg;
llg a[N],dis[N],tree[N<<2];
int up[N],down[N];

void update(int p,int l,int r,int x,llg y)
{
	if(l == r)
	{
		tree[p] = max(tree[p],y);
		return ;
	}
	int m = r+l>>1;
	if(x<=m) update(lson,l,m,x,y);
	else update(rson,m+1,r,x,y);
	tree[p] = max(tree[lson],tree[rson]);
}

llg get(int p,int l,int r,int s,int t)
{
	if(s>t) return 0;
	if(s<=l && r<=t)
	{
		return tree[p];
	}
	int m = l+r>>1;
	if(t<=m) return get(lson,l,m,s,t);
	if(s>m) return get(rson,m+1,r,s,t);
	return max(get(lson,l,m,s,t), get(rson,m+1,r,s,t));
}

int main()
{
	int n,q;
	while(~scanf("%d%d",&n,&q))
	{
		for(int i=1; i<=n; i++)
		{
			scanf("%I64d",&a[i]);
		}
		for(int i=1; i<n; i++)
		{
			dis[i] = abs(a[i+1] - a[i] );
		}
		memset(tree,0,sizeof(tree));
		for(int i=1; i<n; i++)
		{
			update(1,1,n-1,i,dis[i]);
		}
		int l,r,m;
		for(int i=1; i<n; i++)
		{
			l = 1;
			r = i;
			while(l<=r)
			{
				m  = r + l >> 1;
				if( get(1,1,n-1,m,i-1) >= dis[i] ) l = m+1;
				else r = m-1;
			}
			down[i] = l;
			l = i;
			r = n-1;
			while(l<=r)
			{
				m = (r + l >> 1);
				if( get(1,1,n-1,i+1,m) > dis[i]) r = m-1;
				else l = m+1;
			}
			up[i] = l-1;
		}
		for(int i=0; i<q; i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			llg ans = 0;
			for(int j = x; j<y; j++)
			{
				ans += (llg)( j - max(x,down[j]) + 1LL ) * ( min(y-1,up[j]) - j + 1LL ) * dis[j];
			}
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#define lson (p<<1)
#define rson (lson | 1)
using namespace std;
const int N = 1e5+100;
typedef long long llg;
llg a[N],dis[N],tree[N<<2];
int up[N],down[N];

void update(int p,int l,int r,int x,llg y)
{
	if(l == r)
	{
		tree[p] = max(tree[p],y);
		return ;
	}
	int m = r+l>>1;
	if(x<=m) update(lson,l,m,x,y);
	else update(rson,m+1,r,x,y);
	tree[p] = max(tree[lson],tree[rson]);
}

llg get(int p,int l,int r,int s,int t)
{
	if(s>t) return 0;
	if(s<=l && r<=t)
	{
		return tree[p];
	}
	int m = l+r>>1;
	if(t<=m) return get(lson,l,m,s,t);
	if(s>m) return get(rson,m+1,r,s,t);
	return max(get(lson,l,m,s,t), get(rson,m+1,r,s,t));
}

int main()
{
	int n,q;
	while(~scanf("%d%d",&n,&q))
	{
		for(int i=1; i<=n; i++)
		{
			scanf("%I64d",&a[i]);
		}
		for(int i=1; i<n; i++)
		{
			dis[i] = abs(a[i+1] - a[i] );
		}
		memset(tree,0,sizeof(tree));
		for(int i=1; i<n; i++)
		{
			update(1,1,n-1,i,dis[i]);
		}
		int l,r,m;
		for(int i=1; i<n; i++)
		{
			l = 1;
			r = i;
			while(l<=r)
			{
				m  = r + l >> 1;
				if( get(1,1,n-1,m,i-1) > dis[i] ) l = m+1;
				else r = m-1;
			}
			down[i] = l;
			l = i;
			r = n-1;
			while(l<=r)
			{
				m = (r + l >> 1);
				if( get(1,1,n-1,i+1,m) >= dis[i]) r = m-1;
				else l = m+1;
			}
			up[i] = l-1;
		}
		for(int i=0; i<q; i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			llg ans = 0;
			for(int j = x; j<y; j++)
			{
				ans += (llg)( j - max(x,down[j]) + 1LL ) * ( min(y-1,up[j]) - j + 1LL ) * dis[j];
			}
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#define lson (p<<1)
#define rson (lson | 1)
using namespace std;
const int N = 1e5+100;
typedef long long llg;
llg a[N],dis[N],tree[N<<2];
int up[N],down[N];

void update(int p,int l,int r,int x,llg y)
{
	if(l == r)
	{
		tree[p] = max(tree[p],y);
		return ;
	}
	int m = r+l>>1;
	if(x<=m) update(lson,l,m,x,y);
	else update(rson,m+1,r,x,y);
	tree[p] = max(tree[lson],tree[rson]);
}

llg get(int p,int l,int r,int s,int t)
{
	if(s>t) return 0;
	if(s<=l && r<=t)
	{
		return tree[p];
	}
	int m = l+r>>1;
	if(t<=m) return get(lson,l,m,s,t);
	if(s>m) return get(rson,m+1,r,s,t);
	return max(get(lson,l,m,s,t), get(rson,m+1,r,s,t));
}

int main()
{
	int n,q;
	while(~scanf("%d%d",&n,&q))
	{
		for(int i=1; i<=n; i++)
		{
			scanf("%I64d",&a[i]);
		}
		for(int i=1; i<n; i++)
		{
			dis[i] = abs(a[i+1] - a[i] );
		}
		memset(tree,0,sizeof(tree));
		for(int i=1; i<n; i++)
		{
			update(1,1,n-1,i,dis[i]);
		}
		int l,r,m;
		for(int i=1; i<n; i++)
		{
			l = 1;
			r = i;
			while(l<r)
			{
				m  = r + l >> 1;
				if( get(1,1,n-1,m,i-1) >= dis[i] ) l = m+1;
				else r = m;
			}
			down[i] = l;
			l = i;
			r = n-1;
			while(l<r)
			{
				m = (r + l >> 1) + 1;
				if( get(1,1,n-1,i+1,m) > dis[i]) r = m-1;
				else l = m;
			}
			up[i] = l;
		}
		for(int i=0; i<q; i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			llg ans = 0;
			for(int j = x; j<y; j++)
			{
				ans += (llg)( j - max(x,down[j]) + 1LL ) * ( min(y-1,up[j]) - j + 1LL ) * dis[j];
			}
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <list>
#include <algorithm>
#include <math.h>
#include <iostream>
#define INF 0x3f3f3f3f
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define mp make_pair
#define VI vector<int>
#define pii pair<int,int>
#define LL long long
#define pb push_back
#define MAXN 100000
#define LG 12
#define uedge(g,a,b) g[a].pb(b), g[b].pb(a)
#define dedge(g,a,b) g[a].pb(b)
using namespace std;
int rmq[LG][MAXN];
int n, q;
int h[MAXN], d[MAXN];
void pre(){
    for(int i=0; i<n-1; i++) rmq[0][i] = i;
    for(int i=1; i<LG; i++){
        for(int j=0; j + (1<<(i-1)) < n-1; j++){
            if(d[rmq[i-1][j]] > d[rmq[i-1][j + (1<<(i-1))]]){
                rmq[i][j] = rmq[i-1][j];
            }else{
                rmq[i][j] = rmq[i-1][j + (1<<(i-1))];
            }
        }
    }
}
int RMQ(int i, int j){
    int l = (int)log2(j-i+1);
    if(d[rmq[l][i]] > d[rmq[l][j - (1<<(l)) + 1]]){
        return rmq[l][i];
    }else return rmq[l][j - (1<<(l)) + 1];
}
int query(int x, int y){
    if(x>y) return 0;
    if(x<0 || y<0) return 0;
    if(x>n-1 || y > n-1) return 0;
    if(x==y) return d[x];
    else{
        int p = RMQ(x,y);
        int v = d[p];
        int s = v * (y - p + 1) * (p - x + 1);
        return s + query(x,p-1) + query(p+1,y);
    }
}
int main(){
    scanf("%d %d", &n, &q);
    for(int i=0; i<n; i++) scanf("%d", &h[i]);
    for(int i=0; i<n-1; i++) d[i] = abs(h[i+1]-h[i]);
    pre();
    for(int i=0; i<q; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        x--; y--;
        if(x==y) printf("0\n");
        printf("%d\n", query(x,y-1));
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <list>
#include <algorithm>
#include <math.h>
#include <iostream>
#define INF 0x3f3f3f3f
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define mp make_pair
#define VI vector<int>
#define pii pair<int,int>
#define LL long long
#define pb push_back
#define MAXN 100000
#define LG 18
#define uedge(g,a,b) g[a].pb(b), g[b].pb(a)
#define dedge(g,a,b) g[a].pb(b)
#define LL long long
using namespace std;
int rmq[LG][MAXN];
int n, q;
LL h[MAXN], d[MAXN];
void pre(){
    for(int i=0; i<n-1; i++) rmq[0][i] = i;
    for(int i=1; i<LG; i++){
        for(int j=0; j + (1<<(i-1)) < n-1; j++){
            if(d[rmq[i-1][j]] > d[rmq[i-1][j + (1<<(i-1))]]){
                rmq[i][j] = rmq[i-1][j];
            }else{
                rmq[i][j] = rmq[i-1][j + (1<<(i-1))];
            }
        }
    }
}
LL myabs(LL a){
    if(a<0) return a*-1LL;
    return a;
}
int RMQ(int i, int j){
    int l = (int)log2(j-i+1);
    if(d[rmq[l][i]] > d[rmq[l][j - (1<<(l)) + 1]]){
        return rmq[l][i];
    }else return rmq[l][j - (1<<(l)) + 1];
}
LL query(int x, int y){
    if(x>y) return 0;
    if(x<0 || y<0) return 0;
    if(x>n-1 || y > n-1) return 0;
    if(x==y) return d[x];
    else{
        int p = RMQ(x,y);
        LL v = d[p];
        LL s = v * (LL)(y - p + 1) * (LL)(p - x + 1);
        return s + query(x,p-1) + query(p+1,y);
    }
}
int main(){
    scanf("%d %d", &n, &q);
    for(int i=0; i<n; i++) scanf("%I64d", &h[i]);
    for(int i=0; i<n-1; i++) d[i] = myabs(h[i+1]-h[i]);
    pre();
    for(int i=0; i<q; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        x--; y--;
        if(x==y) printf("0\n");
        printf("%I64d\n", query(x,y-1));
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <list>
#include <algorithm>
#include <math.h>
#include <iostream>
#define INF 0x3f3f3f3f
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define mp make_pair
#define VI vector<int>
#define pii pair<int,int>
#define LL long long
#define pb push_back
#define MAXN 100000
#define LG 12
#define uedge(g,a,b) g[a].pb(b), g[b].pb(a)
#define dedge(g,a,b) g[a].pb(b)
#define LL long long
using namespace std;
int rmq[LG][MAXN];
int n, q;
LL h[MAXN], d[MAXN];
void pre(){
    for(int i=0; i<n-1; i++) rmq[0][i] = i;
    for(int i=1; i<LG; i++){
        for(int j=0; j + (1<<(i-1)) < n-1; j++){
            if(d[rmq[i-1][j]] > d[rmq[i-1][j + (1<<(i-1))]]){
                rmq[i][j] = rmq[i-1][j];
            }else{
                rmq[i][j] = rmq[i-1][j + (1<<(i-1))];
            }
        }
    }
}
LL myabs(LL a){
    if(a<0) return a*-1LL;
    return a;
}
int RMQ(int i, int j){
    int l = (int)log2(j-i+1);
    if(d[rmq[l][i]] > d[rmq[l][j - (1<<(l)) + 1]]){
        return rmq[l][i];
    }else return rmq[l][j - (1<<(l)) + 1];
}
LL query(int x, int y){
    if(x>y) return 0;
    if(x<0 || y<0) return 0;
    if(x>n-1 || y > n-1) return 0;
    if(x==y) return d[x];
    else{
        int p = RMQ(x,y);
        LL v = d[p];
        LL s = v * (LL)(y - p + 1) * (LL)(p - x + 1);
        return s + query(x,p-1) + query(p+1,y);
    }
}
int main(){
    scanf("%d %d", &n, &q);
    for(int i=0; i<n; i++) scanf("%I64d", &h[i]);
    for(int i=0; i<n-1; i++) d[i] = myabs(h[i+1]-h[i]);
    pre();
    for(int i=0; i<q; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        x--; y--;
        if(x==y) printf("0\n");
        printf("%I64d\n", query(x,y-1));
    }
    return 0;
}


#include <bits/stdc++.h>
#define fi "d.inp"
#define fo "d.out"
#define For(i,a,b) for(long long i=a;i<=b;i++)
#define Ford(i,a,b) for(long long i=a;i>=b;i--)
using namespace std;
long long ans,n,a[200001],q,Next[200001],Back[200001];
typedef pair<long long,long long> ii;
vector <ii> vt;
set <long long> th;
set <long long>::iterator it;
int main()
{

    scanf("%lld %lld", &n, &q);
    For(i,1,n) scanf("%lld", &a[i]);
    For(i,1,n-1)
    {
        vt.push_back(ii(abs(a[i]-a[i+1]),i));
    }
    sort(vt.begin(),vt.end());
    th.insert(0);
    th.insert(n);
    long long t,l,r,t1,Ne,Ba;
    Ford(i,n-2,0)
    {
        t = vt[i].first;
        l = vt[i].second;
        it = th.lower_bound(l);
        Next[i] = (*it);
        it--;
        Back[i] = *it;
        // if (Next[i]==n) Next[i] = n-1;
        // if (Back[i]==0) Back[i] = 1;
        th.insert(vt[i].second);
    }
    while (q--)
    {
        ans = 0;
        scanf("%lld %lld", &l, &r);
        r--;
        Ford(i,n-1,0)
        {
            if (vt[i].second>=l&&vt[i].second<=r)
            {
                if(Next[i]<=r) Ne = Next[i];
                else Ne = r+1;
                t = (Ne-vt[i].second);
                if(Back[i]>=l) Ba = Back[i];
                else Ba = l-1;
                t1 = (vt[i].second-Ba);
                ans += vt[i].first*t1*t;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define fi "d.inp"
#define fo "d.out"
#define For(i,a,b) for(long long i=a;i<=b;i++)
#define Ford(i,a,b) for(long long i=a;i>=b;i--)
using namespace std;
long long ans,n,a[200001],q,Next[200001],Back[200001];
typedef pair<long long,long long> ii;
vector <ii> vt;
set <long long> th;
set <long long>::iterator it;
int main()
{

    scanf("%lld %lld", &n, &q);
    For(i,1,n) scanf("%lld", &a[i]);
    For(i,1,n-1)
    {
        vt.push_back(ii(abs(a[i]-a[i+1]),i));
    }
    sort(vt.begin(),vt.end());
    th.insert(0);
    th.insert(n);
    long long t,l,r,t1,Ne,Ba;
    Ford(i,n-2,0)
    {
        t = vt[i].first;
        l = vt[i].second;
        it = th.lower_bound(l);
        Next[i] = (*it);
        it--;
        Back[i] = *it;
        th.insert(vt[i].second);
    }
    while (q--)
    {
        ans = 0;
        scanf("%lld %lld", &l, &r);
        r--;
        Ford(i,n-1,0)
        {
            if (vt[i].second>=l&&vt[i].second<=r)
            {
                if(Next[i]<=r) Ne = Next[i];
                else Ne = r+1;
                t = (Ne-vt[i].second);
                if(Back[i]>=l) Ba = Back[i];
                else Ba = l-1;
                t1 = (vt[i].second-Ba);
                ans += vt[i].first*t1*t;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define SIZE (100000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%I64d", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%I64d\n", (a))
#define Ps(a) printf("%s\n", (a))
#define CLR(a, b) memset(a, (b), sizeof(a))
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define ll __int64
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define PI acos(-1.0)
const long long MOD = 1000000007;
using namespace std;
int a[SIZE],v[SIZE];
int tree[SIZE<<2];

void build(int l,int r,int rt)
{
    if(l == r)
    {
        tree[rt] = v[l];
        return ;
    }
    int mid = (l+r)>>1;
    build(lson);
    build(rson);
    tree[rt] = max(tree[rt<<1] , tree[rt<<1|1]);
}

int get_left(int L,int R,int l,int r,int rt,int v)
{
    if(tree[rt] < v)
        return L;
    else if(l == r) return R+1;
    int mid = (l+r)>>1;
    if(l == L && r == R)
    {
        if(tree[rt<<1|1] < v)   return get_left(L,mid,lson,v);
        else    return get_left(mid+1,R,rson,v);
    }

    if(R<=mid)  return get_left(L,R,lson,v);
    else if(L>mid)  return get_left(L,R,rson,v);
    else
    {
        int pos = get_left(mid+1,R,rson,v);
        if(pos > mid+1) return pos;
        else    return get_left(L,mid,lson,v);
    }
}
int get_right(int L,int R,int l,int r,int rt,int v)
{
    if(tree[rt] <= v)
        return R;
    else if(l == r) return L-1;
    int mid = (l+r)>>1;
    if(l == L && r == R)
    {
        if(tree[rt<<1] <= v)   return get_right(mid+1,R,rson,v);
        else    return get_right(L,mid,lson,v);
    }

    if(R<=mid)  return get_right(L,R,lson,v);
    else if(L>mid)  return get_right(L,R,rson,v);
    else
    {
        int pos = get_right(L,mid,lson,v);
        if(pos < mid) return pos;
        else    return get_right(mid+1,R,rson,v);
    }
}
int main()
{
    int n,m;
    Ri(n),Ri(m);
    for(int i = 1; i <= n; i++)
        Ri(a[i]);
    n--;
    for(int i = 1; i <= n; i++)
        v[i] = abs(a[i+1]-a[i]);

    build(1,n,1);

    int l,r;
    while(m--)
    {
        Ri(l),Ri(r);r--;
        ll ans = 0;
        for(int i = l; i <= r; i++)
        {
            ll left = i;
            if(l<i)
                left = get_left(l,i-1,1,n,1,v[i]);
            ll right = i;
            if(r>i)
                right = get_right(i+1,r,1,n,1,v[i]);
            ans += (i-left+1)*(right-i+1)*v[i];
        }
        Pl(ans);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define SIZE (100000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%I64d", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%I64d\n", (a))
#define Ps(a) printf("%s\n", (a))
#define CLR(a, b) memset(a, (b), sizeof(a))
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define ll __int64
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define PI acos(-1.0)
const long long MOD = 1000000007;
using namespace std;
/*
题意见：Codeforces Round #333 (Div. 2)  D - Lipshitz Sequence
    首先，简化问题，找出性质：max{向上取整(abs(vv[i]-vv[j])/(j-i)),j>i}一定是取自max{向上取整(abs(vv[i]-vv[j])/(j-i)),j==i+1}中
    用v[i]表示abs(a[i+1]-a[i]) ,我们就可以只用v[]就求出关于子区间权值的答案
    所以我们枚举v[i] 看这个v[i]对答案有多少贡献
    如何计算贡献呢：在[l,r)范围，枚举每个v[]，看看这个v[]向左向右做多能覆盖到哪里
    然后这个v[]对答案的贡献就是左区间个数*右区间个数*v[]

    通过线段树来求：
    1，某个点向左第一个比它大的位点，（为了防止重复，这里其实是向左第一个大于等于它的位置）
    2，这个点向右第一个比它大的位点。
    线段树这两步操作可以完全初始化出来
*/
int a[SIZE],v[SIZE];
int tree[SIZE<<2];
int n;
void build(int l,int r,int rt)
{
    if(l == r)
    {
        tree[rt] = v[l];
        return ;
    }
    int mid = (l+r)>>1;
    build(lson);
    build(rson);
    tree[rt] = max(tree[rt<<1] , tree[rt<<1|1]);
}

int get_left(int L,int R,int l,int r,int rt,int v)
{
    if(tree[rt] < v)
        return L;
    else if(l == r) return R+1;
    int mid = (l+r)>>1;
    if(l == L && r == R)
    {
        if(tree[rt<<1|1] < v)   return get_left(L,mid,lson,v);
        else    return get_left(mid+1,R,rson,v);
    }

    if(R<=mid)  return get_left(L,R,lson,v);
    else if(L>mid)  return get_left(L,R,rson,v);
    else
    {
        int pos = get_left(mid+1,R,rson,v);
        if(pos > mid+1) return pos;
        else    return get_left(L,mid,lson,v);
    }
}
int get_right(int L,int R,int l,int r,int rt,int v)
{
    if(tree[rt] <= v)
        return R;
    else if(l == r) return L-1;
    int mid = (l+r)>>1;
    if(l == L && r == R)
    {
        if(tree[rt<<1] <= v)   return get_right(mid+1,R,rson,v);
        else    return get_right(L,mid,lson,v);
    }

    if(R<=mid)  return get_right(L,R,lson,v);
    else if(L>mid)  return get_right(L,R,rson,v);
    else
    {
        int pos = get_right(L,mid,lson,v);
        if(pos < mid) return pos;
        else    return get_right(mid+1,R,rson,v);
    }
}
int L[SIZE],R[SIZE];
void init()
{
    for(int i = 1; i <= n; i++)
    {
        if(i == 1)  L[i] = 1;
        else        L[i] = get_left(1,i-1,1,n,1,v[i]);

        if(i == n)  R[i] = n;
        else        R[i] = get_right(i+1,n,1,n,1,v[i]);
    }
}

int main()
{
    int m;
    Ri(n),Ri(m);
    for(int i = 1; i <= n; i++)
        Ri(a[i]);
    n--;
    for(int i = 1; i <= n; i++)
        v[i] = abs(a[i+1]-a[i]);

    build(1,n,1);
    init();

    int l,r;
    while(m--)
    {
        Ri(l),Ri(r);r--;
        ll ans = 0;
        for(int i = l; i <= r; i++)
        {
            ans += (ll)(i-max(L[i],l)+1)*(min(R[i],r)-i+1)*v[i];
        }
        Pl(ans);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define SIZE (100000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%I64d", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%I64d\n", (a))
#define Ps(a) printf("%s\n", (a))
#define CLR(a, b) memset(a, (b), sizeof(a))
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define ll __int64
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define PI acos(-1.0)
const long long MOD = 1000000007;
using namespace std;
/*
题意见：Codeforces Round #333 (Div. 2)  D - Lipshitz Sequence
    首先，简化问题，找出性质：max{向上取整(abs(vv[i]-vv[j])/(j-i)),j>i}一定是取自max{向上取整(abs(vv[i]-vv[j])/(j-i)),j==i+1}中
    用v[i]表示abs(a[i+1]-a[i]) ,我们就可以只用v[]就求出关于子区间权值的答案
    所以我们枚举v[i] 看这个v[i]对答案有多少贡献
    如何计算贡献呢：在[l,r)范围，枚举每个v[]，看看这个v[]向左向右做多能覆盖到哪里
    然后这个v[]对答案的贡献就是左区间个数*右区间个数*v[]

    通过线段树来求：
    1，某个点向左第一个比它大的位点，（为了防止重复，这里其实是向左第一个大于等于它的位置）
    2，这个点向右第一个比它大的位点。
    线段树这两步操作可以完全初始化出来
*/
int a[SIZE],v[SIZE];
int tree[SIZE<<2];
int n;
void build(int l,int r,int rt)
{
    if(l == r)
    {
        tree[rt] = v[l];
        return ;
    }
    int mid = (l+r)>>1;
    build(lson);
    build(rson);
    tree[rt] = max(tree[rt<<1] , tree[rt<<1|1]);
}

int get_left(int L,int R,int l,int r,int rt,int v)
{
    if(tree[rt] < v)
        return L;
    else if(l == r) return R+1;
    int mid = (l+r)>>1;
    if(l == L && r == R)
    {
        if(tree[rt<<1|1] < v)   return get_left(L,mid,lson,v);
        else    return get_left(mid+1,R,rson,v);
    }

    if(R<=mid)  return get_left(L,R,lson,v);
    else if(L>mid)  return get_left(L,R,rson,v);
    else
    {
        int pos = get_left(mid+1,R,rson,v);
        if(pos > mid+1) return pos;
        else    return get_left(L,mid,lson,v);
    }
}
int get_right(int L,int R,int l,int r,int rt,int v)
{
    if(tree[rt] <= v)
        return R;
    else if(l == r) return L-1;
    int mid = (l+r)>>1;
    if(l == L && r == R)
    {
        if(tree[rt<<1] <= v)   return get_right(mid+1,R,rson,v);
        else    return get_right(L,mid,lson,v);
    }

    if(R<=mid)  return get_right(L,R,lson,v);
    else if(L>mid)  return get_right(L,R,rson,v);
    else
    {
        int pos = get_right(L,mid,lson,v);
        if(pos < mid) return pos;
        else    return get_right(mid+1,R,rson,v);
    }
}
int L[SIZE],R[SIZE];
void init()
{
    for(int i = 1; i <= n; i++)
    {
        if(i == 1)  L[i] = 1;
        else        L[i] = get_left(1,i-1,1,n,1,v[i]);

        if(i == n)  R[i] = n;
        else        R[i] = get_right(i+1,n,1,n,1,v[i]);
    }
}

int main()
{
    int m;
    Ri(n),Ri(m);
    for(int i = 1; i <= n; i++)
        Ri(a[i]);
    n--;
    for(int i = 1; i <= n; i++)
        v[i] = abs(a[i+1]-a[i]);

    build(1,n,1);
    init();

    int l,r;
    while(m--)
    {
        Ri(l),Ri(r);r--;
        ll ans = 0;
        for(int i = l; i <= r; i++)
        {
            ans += (i-max(L[i],l)+1)*(min(R[i],r)-i+1)*v[i];
        }
        Pl(ans);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define SIZE (100000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%I64d", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%I64d\n", (a))
#define Ps(a) printf("%s\n", (a))
#define CLR(a, b) memset(a, (b), sizeof(a))
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define ll __int64
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define PI acos(-1.0)
const long long MOD = 1000000007;
using namespace std;
int a[SIZE],v[SIZE],mx[SIZE][18];
int n,m;
void rmqinit()
{
    for(int i = 1; i <= n; i++) mx[i][0] = v[i];
    int L = (log(n * 1.0) / log(2.0));
    for(int i = 1; i <= L; i++)
        for(int j = 1; j <= n; j++)
        {
            mx[j][i] = mx[j][i - 1];
            if(j + (1 << (i - 1)) <= n)
                mx[j][i] = max(mx[j][i], mx[j + (1 << (i - 1))][i - 1]);
        }
}

int rmqmax(int l,int r)	//询问[l,r]区间的最大值
{
    int k = (log((r - l + 1) * 1.0) / log(2.0));
    return max(mx[l][k] , mx[r - (1 << k) + 1][k]);
}
int L[SIZE],R[SIZE];
void init()
{
    int l,r;
    for(int i = 1; i <= n; i++)             //遍历每一个v[]
    {
        l = 1,r = i;
        while(l<r)                          //用二分的方法找到i左边第一个比v[i]大的值的位置，放入L[i]
        {
            int mid = (l+r)>>1;
            if(rmqmax(mid,i-1) < v[i]) r = mid;
            else l = mid+1;
        }
        L[i] = l;

        l = i,r = n;
        while(l<r)                          //用二分的方法找到i右边第一个比v[i]大的值的位置，放入R[i]
        {
            int mid = (l+r+1)>>1;
            if(rmqmax(i+1,mid) <= v[i])   l=mid;
            else    r = mid-1;
        }
        R[i] = l;
    }
}
int main()
{
    Ri(n),Ri(m);
    for(int i = 1; i <= n; i++)
        Ri(a[i]);
    n--;
    for(int i = 1; i <= n; i++)
        v[i] = abs(a[i+1]-a[i]);

    rmqinit();
    init();

    int l,r;
    while(m--)
    {
        Ri(l),Ri(r);
        r--;
        ll ans = 0;
        for(int j = l; j <= r; j++)     ans += (ll)(j-max(l,L[j])+1)*(min(R[j],r)-j+1)*v[j];
        Pl(ans);
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int a[100010];
int d[100010];
int main() {
    int n, q;
    while (cin >> n >> q) {
        for (int i = 0; i < n; i++)
            cin >> a[i];
        for (int i = 1; i < n; i++)
            d[i] = abs(a[i] - a[i-1]);
        while (q--) {
            int l, r;
            cin >> l >> r;
            int sum = 0;
            for (int i = l; i < r; i++) {
                int b = i - 1;
                while (b >= l && d[b] < d[i])
                    b--;
                int e = i + 1;
                while (e < r && d[e] <= d[i])
                    e++;
                sum += (i-b) * (e-i) * d[i];
            }
            cout << sum << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int a[100010];
ll d[100010];
int L[100010];
int R[100010];
int stack[100010];
int main() {
    int n, q;
    while (cin >> n >> q) {
        for (int i = 0; i < n; i++)
            cin >> a[i];
        for (int i = 1; i < n; i++)
            d[i] = abs(a[i] - a[i-1]);
        int top = 0;
        for (int i = 1; i < n; i++) {
            if (top == 0) {
                L[i] = 0;
            }
            else if (d[stack[top-1]] > d[i]) {
                L[i] = stack[top-1];
            }
            else {
                while (top > 0 && d[stack[top-1]] <= d[i]) {
                    top--;
                }
                if (top == 0)
                    L[i] = 0;
                else
                    L[i] = stack[top-1];
            }
            stack[top++] = i;
        }
        top = 0;
        for (int i = n-1; i >= 1; i--) {
            if (top == 0) {
                R[i] = n;
            }
            else if (d[stack[top-1]] >= d[i]) {
                R[i] = stack[top-1];
            }
            else {
                while (top > 0 && d[stack[top-1]] < d[i]) {
                    top--;
                }
                if (top == 0)
                    R[i] = n;
                else
                    R[i] = stack[top-1];
            }
            stack[top++] = i;
        }
        while (q--) {
            int l, r;
            cin >> l >> r;
            ll sum = 0;
            for (int i = l; i < r; i++) {
                int b = max(L[i], l-1);
                int e = min(R[i], r);
                sum += d[i] * (i-b) * (e-i);
            }
            cout << sum << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int a[100010];
ll d[100010];
int main() {
    int n, q;
    while (cin >> n >> q) {
        for (int i = 0; i < n; i++)
            cin >> a[i];
        for (int i = 1; i < n; i++)
            d[i] = abs(a[i] - a[i-1]);
        while (q--) {
            int l, r;
            cin >> l >> r;
            ll sum = 0;
            for (int i = l; i < r; i++) {
                int b = i - 1;
                while (b >= l && d[b] < d[i])
                    b--;
                int e = i + 1;
                while (e < r && d[e] <= d[i])
                    e++;
                sum += d[i] * (i-b) * (e-i);
            }
            cout << sum << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;

const int N = 100010;

inline int Abs(int x) {
    return (x < 0) ? (-x) : (x);
}

int n, q;
int a[N], b[N], l[N], r[N];

int main() {
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; ++i)
	scanf("%d", &a[i]);
    for (int i = 1; i < n; ++i)
	a[i] = Abs(a[i] - a[i + 1]);
    int k = 0;
    for (int i = 1; i < n; ++i) {
	while (k && a[b[k]] < a[i]) --k;
	l[i] = (k) ? (b[k] + 1) : (1);
	b[++k] = i;
    }
    k = 0;
    for (int i = n - 1; i; --i) {
	while (k && a[b[k]] <= a[i]) --k;
	r[i] = (k) ? (b[k] - 1) : (n);
	b[++k] = i;
    }
    while (q--) {
	int l, r;
	scanf("%d%d", &l, &r);
	LL res = 0;
	for (int i = l; i < r; ++i)
	    res += LL(a[i]) * (min(::r[i], r - 1) - i + 1) * (i - max(::l[i], l) + 1);
	printf("%lld\n", res);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
using namespace std;

typedef long long llint;
typedef pair< int, int > pii;

#define pb push_back
#define X first
#define Y second
#define TRACE(x) cout<<#x<<" = "<<x<<endl;
const int maxn = 100005;
int arr[ maxn ];
int diff[ maxn ];
int n, q;

void stvori_diff( int l, int r ) {
    for ( int i = 0; i < r - l + 1; i++ ) {
        diff[ i ] = abs( arr[ i + l + 1 ] - arr[ i + l ] );
    }
}
int manji_lijevo[ maxn ];
int manji_jednak_desno[ maxn ];
stack < pii > s;
int main () {
    cin >> n >> q;
    for ( int i = 0; i < n; i++ ) {
        cin >> arr[ i ];
    }
    while ( q-- ) {
        int l, r; cin >> l >> r;
        l--; r--;
        stvori_diff(l, r);
        int d = r - l + 1;
        while ( !s.empty() ) s.pop();
        for ( int i = 0; i < d - 1; i++ ) {
            manji_lijevo[ i ] = 0;
            while ( !s.empty() and s.top().X < diff[ i ] ) {
                s.pop();
            }
            if ( s.empty() ) manji_lijevo[ i ] = i;
            else manji_lijevo[ i ] = i - s.top().Y - 1;
            s.push( pii (diff[ i ], i ) );
        }
        while ( !s.empty() ) s.pop();
        for ( int i = d - 2; i >= 0; i-- ) {
            manji_jednak_desno[ i ] = 0;
            while ( !s.empty() and s.top().X <= diff[ i ] ) {
                s.pop();
            }

            if ( s.empty() ) manji_jednak_desno[ i ] = d - 2 - i;
            else manji_jednak_desno[ i ] = s.top().Y - i - 1 ;
            s.push( pii (diff[ i ], i ) );

        }
        llint ans = 0;
        //for ( int i = 0; i < d - 1; i++ ) cout << manji_jednak_desno[ i ] << " ";
        for ( int i = 0; i < d - 1; i++ ) {
            ans += diff[ i ];
            ans += diff[ i ] * manji_jednak_desno[ i ];
            ans += diff[ i ] * manji_lijevo[ i ];
            ans += diff[ i ] * manji_jednak_desno[ i ] * manji_lijevo[ i ];
            //TRACE( ans ); TRACE( i );
        }
        cout << ans << endl;

    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
using namespace std;

typedef long long llint;
typedef pair< int, int > pii;

#define pb push_back
#define X first
#define Y second
#define TRACE(x) cout<<#x<<" = "<<x<<endl;

const int maxn = 100005;
int arr[maxn];
int diff[maxn];
int n, q;

void stvori_diff (int l, int r) {
    for (int i = 0; i < r - l + 1; i++) {
        diff[i] = abs( arr[i + l + 1] - arr[i + l] );
    }
}

int minL[maxn];
int minJedD[maxn];
stack < pii > s;

int main () {
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    while (q--) {
        int l, r; cin >> l >> r;
        l--; r--;
        stvori_diff(l, r);
        int d = r - l + 1;
        while (!s.empty()) s.pop();
        for (int i = 0; i < d - 1; i++) {
            minL[i] = 0;
            while (!s.empty() and s.top().X < diff[i])
                s.pop();
            if (s.empty()) minL[i] = i;
            else minL[i] = i - s.top().Y - 1;
            s.push(pii(diff[ i ], i ));
        }
        while (!s.empty()) s.pop();
        for (int i = d - 2; i >= 0; i--) {
            minJedD[i] = 0;
            while (!s.empty() and s.top().X <= diff[i])
                s.pop();
            if (s.empty()) minJedD[i] = d - 2 - i;
            else minJedD[i] = s.top().Y - i - 1 ;
            s.push(pii(diff[ i ], i));
        }
        llint ans = 0;
        for (int i = 0; i < d - 1; i++) {
            ans += diff[i];
            ans += diff[i] * minJedD[i];
            ans += diff[i] * minL[i];
            ans += diff[i] * minJedD[i] * minL[i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
using namespace std;

typedef long long llint;
typedef pair< int, int > pii;

#define pb push_back
#define X first
#define Y second
#define TRACE(x) cout<<#x<<" = "<<x<<endl;
const int maxn = 100005;
int arr[ maxn ];
llint diff[ maxn ];
int n, q;

void stvori_diff( int l, int r ) {
    for ( int i = 0; i < r - l + 1; i++ ) {
        diff[ i ] = abs( arr[ i + l + 1 ] - arr[ i + l ] );
    }
}
int manji_lijevo[ maxn ];
int manji_jednak_desno[ maxn ];
stack < pii > s;
int main () {
    cin >> n >> q;
    for ( int i = 0; i < n; i++ ) {
        cin >> arr[ i ];
    }
    while ( q-- ) {
        int l, r; cin >> l >> r;
        l--; r--;
        stvori_diff(l, r);
        int d = r - l + 1;
        while ( !s.empty() ) s.pop();
        for ( int i = 0; i < d - 1; i++ ) {
            manji_lijevo[ i ] = 0;
            while ( !s.empty() and s.top().X < diff[ i ] ) {
                s.pop();
            }
            if ( s.empty() ) manji_lijevo[ i ] = i;
            else manji_lijevo[ i ] = i - s.top().Y - 1;
            s.push( pii (diff[ i ], i ) );
        }
        while ( !s.empty() ) s.pop();
        for ( int i = d - 2; i >= 0; i-- ) {
            manji_jednak_desno[ i ] = 0;
            while ( !s.empty() and s.top().X <= diff[ i ] ) {
                s.pop();
            }

            if ( s.empty() ) manji_jednak_desno[ i ] = d - 2 - i;
            else manji_jednak_desno[ i ] = s.top().Y - i - 1 ;
            s.push( pii (diff[ i ], i ) );

        }
        llint ans = 0;
        //for ( int i = 0; i < d - 1; i++ ) cout << manji_jednak_desno[ i ] << " ";
        for ( int i = 0; i < d - 1; i++ ) {
            ans += diff[ i ];
            ans += diff[ i ] * manji_jednak_desno[ i ];
            ans += diff[ i ] * manji_lijevo[ i ];
            ans += diff[ i ] * manji_jednak_desno[ i ] * manji_lijevo[ i ];
            //TRACE( ans ); TRACE( i );
        }
        cout << ans << endl;

    }
    return 0;
}