import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;

public class LipshitzSequence
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++)
			arr[i] = sc.nextInt();

		int[] diff = new int[n-1];
		for (int j = 1; j < n; j++)
			diff[j-1] = Math.abs(arr[j] - arr[j-1]);
		int[] left = new int[n-1];
		int[] right = new int[n-1];

		Stack<Integer> st = new Stack<Integer>();
		for (int j = 0; j < n-1; j++)
		{
			while(!st.isEmpty() && diff[st.peek()]<diff[j])
				st.pop();
			if(st.isEmpty())
				left[j] = -1;
			else
				left[j] = st.peek();
			st.push(j);
		}

		st = new Stack<Integer>();
		for (int j = n-2; j >= 0; j--)
		{
			while(!st.isEmpty() && diff[st.peek()]<=diff[j])
				st.pop();
			if(st.isEmpty())
				right[j] = n-1;
			else
				right[j] = st.peek();
			st.push(j);
		}

		for (int i = 0; i < q; i++)
		{
			int l = sc.nextInt()-1;
			int r = sc.nextInt()-1;

			long ans = 0;
			for (int j = l; j < r; j++)
				ans += 1l*diff[j]*(((Math.min(right[j], r) - (j))*((j) - Math.max(l-1, left[j]))));
			pw.println(ans);
		}
		pw.flush();
		pw.close();
	}
	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;

public class E {

	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt(), q = sc.nextInt(), x[] = new int[n], len = n - 1;
		for(int i = 0; i < n; ++i)
		{
			x[i] = sc.nextInt();
			if(i > 0)
				x[i - 1] = Math.abs(x[i - 1] - x[i]);
		}
		int[] b = new int[len], e = new int[len];
		Stack<Integer> s = new Stack<Integer>();
		for(int i = 0; i < len; ++i)
		{
			while(!s.isEmpty() && x[s.peek()] <= x[i])
				s.pop();
			b[i] = s.isEmpty() ? -1 : s.peek();
			s.push(i);
		}
		s = new Stack<Integer>();
		for(int i = len - 1; i >= 0; --i)
		{
			while(!s.isEmpty() && x[s.peek()] < x[i])
				s.pop();
			e[i] = s.isEmpty() ? len : s.peek();
			s.push(i);
		}

		while(q-->0)
		{
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;

			long ans = 0;
			for(int i = l; i < r; ++i)
				ans += 1l * x[i] * (Math.min(e[i], r) - i) * (i - Math.max(b[i], l - 1));
			out.println(ans);
		}
		out.flush();
		out.close();
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public Scanner(FileReader r){	br = new BufferedReader(r);}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException { return Double.parseDouble(next()); }

		public boolean ready() throws IOException {return br.ready();}

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), q = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            for (; q > 0; --q) {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;
                long ans = gao(a, l, r + 1);
                out.println(ans);
            }
        }

        long gao(int[] a, int l, int r) {
            if (r - l < 2) {
                return 0;
            }
            long ret = 0;
            int[] L = new int[a.length];
            for (int i = l + 1; i < r; ++i) {
                L[i] = Math.abs(a[i] - a[i - 1]);
            }
            int[] dq = new int[a.length];
            int head = 0, tail = 0;
            int[] cnt = new int[a.length];
            long sum = 0;
            for (int i = l + 1; i < r; ++i) {
                while (head < tail) {
                    int u = dq[tail - 1];
                    if (L[u] > L[i]) {
                        break;
                    }
                    sum -= (long) L[u] * cnt[u];
                    --tail;
                }
                if (head == tail) {
                    cnt[i] = i - l;
                } else {
                    cnt[i] = i - dq[tail - 1];
                }
                dq[tail++] = i;
                sum += (long) L[i] * cnt[i];
                ret += sum;
            }
            return ret;
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.awt.Point;
import java.awt.geom.Line2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.GuardedObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.io.InputStream;
import java.math.BigInteger;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		long var=System.currentTimeMillis();
		solver.solve(1, in, out);
		/*if(System.getProperty("ONLINE_JUDGE")==null){
			out.println("["+(double)(System.currentTimeMillis()-var)/1000+"]");
		}*/
		out.close();
	}
}
class Pair {
	long x,y,index;
	Pair(long x,long y,int index){
		this.x=x;
		this.y=y;
		this.index=index;
	}
	public String toString(){
		return this.x+" "+this.y+" ";
	}

}
class tupple{
	long x,y,z;
	ArrayList<String> list=new ArrayList<>();
	tupple(long x,long y,long z){
		this.x=x;
		this.y=y;
		this.z=z;
	}
	tupple(tupple cl){
		this.x=cl.x;
		this.y=cl.y;
		this.z=cl.z;
		this.list=cl.list;
	}
}
class Edge{
	int u;
	int v;
	int time;
	long cost;
	public Edge(int u,int v){
		this.u=u;
		this.v=v;
		time=Integer.MAX_VALUE;
	}
	public int other(int x){
		if(u==x)return v;
		return u;
	}
}
class Ss{
	Integer a[]=new Integer[3];
	Ss(Integer a[]){
		this.a=a;

	}
	public int hashCode(){
		return a[0].hashCode()+a[1].hashCode()+a[2].hashCode();
	}
	public boolean equals(Object o){
		Ss x=(Ss)o;
		for(int i=0;i<3;i++){
			if(x.a[i]!=this.a[i]){
				return false;
			}
		}
		return true;

	}
}
class queary{
	int type;
	int l;
	int r;
	int index;
	queary(int type,int l,int r){
		this.type=type;
		this.l=l;
		this.r=r;
	}
}
class boat implements Comparable<boat>{
	int capacity;
	int index;
	boat(int capacity,int index)
	{
		this.capacity=capacity;
		this.index=index;
	}
	@Override
	public int compareTo(boat o) {
		// TODO Auto-generated method stub
		return this.capacity-o.capacity;
	}
}
class angle{
	double x,y,angle;
	int index;
	angle(int x,int y,double angle){
		this.x=x;
		this.y=y;
		this.angle=angle;
	}
}
class TaskC {
	static long mod=(long)(1e9+7);
//	  SegTree tree;
	//    int min[];
	/*static int prime_len=100001;
	static int prime[]=new int[prime_len];
	static ArrayList<Integer> primes=new ArrayList<>();
	static ArrayList<Integer> list=new ArrayList<>();
	static{
		//System.out.println("lifhgifwrek");
		for(int i=2;i<=Math.sqrt(prime.length);i++){
			for(int j=i*i;j<prime.length;j+=i){

				prime[j]=i;

			}
		}
		for(int i=2;i<prime.length;i++){
			if(prime[i]==0){
				list.add(i);
			}

		}
	//	System.out.println("end");

	//	prime[0]=true;
	//	prime[1]=1;
	}
	/*
	 * 	long pp[]=new long[10000001];
			pp[0]=0;
			pp[1]=1;
			for(int i=2;i<pp.length;i++){
				if(prime[i]!=0){
					int gcd=(int)greatestCommonDivisor(i/prime[i], prime[i]);
					pp[i]=(pp[i/prime[i]]*pp[prime[i]]*gcd)/pp[(int)gcd];
				}
				else
					pp[i]=i-1;
			}

	 * */

			public void solve(int testNumber, FastScanner in, PrintWriter out) throws IOException {
				int n=in.nextInt();
				int q=in.nextInt();
				int a[]=new int[n];
				for(int i=0;i<n;i++){
					a[i]=in.nextInt();
				}
				int d[]=new int[n];
				for(int i=0;i<n-1;i++){
					d[i]=Math.abs(a[i]-a[i+1]);
				}
				int n_max[]=new int[n];
				n_max[n-2]=Integer.MAX_VALUE;
				for(int i=n-3;i>=0;i--){
					if(d[i]<d[i+1]){
						n_max[i]=i+1;
					}
					else{
						int x=n_max[i+1];
						while(x<n && d[x]<d[i]){
							x=n_max[x];
						}
						n_max[i]=x;
					}
				}
				//System.out.println("hi");
				int p_max[]=new int[n];
				p_max[0]=Integer.MIN_VALUE;
				for(int i=1;i<n;i++){
					if(d[i]<=d[i-1]){
						p_max[i]=i-1;
					}
					else{
						int x=p_max[i-1];
						while(x>=0 && d[x]<=d[i]){
							x=p_max[x];
						}
						p_max[i]=x;
					}
				}
				//out.println(Arrays.toString(d));
				//out.println(Arrays.toString(p_max));
				//out.println(Arrays.toString(n_max));

				for(int i=0;i<q;i++){
					int l=in.nextInt()-1;
					int r=in.nextInt()-1;
					long ans=0;
					for(int j=l;j<r;j++){
					//	out.println((j-Math.max(p_max[j],l-1))+" "+(Math.min(r, n_max[j])-j));
						ans+=d[j]*(j-Math.max(p_max[j],l-1))*(Math.min(r, n_max[j])-(j));
					}
					out.println(ans);
				}

			}
			static class pairs{
				String company,color;
				String type;
				boolean visit=false;
				pairs(String company,String color,String type){
					this.company=company;
					this.color=color;
					this.type=type;
				}
			}
		BigInteger BMOD=BigInteger.valueOf(mod);
		private long inv(long q) {
	        return BigInteger.valueOf(q).modInverse(BMOD).longValue();
	    }

			static void dfs(List<Integer>[] graph, boolean[] used, List<Integer> res, int u) {
		    used[u] = true;
		    for (int v : graph[u])
		      if (!used[v])
		        dfs(graph, used, res, v);
		    res.add(u);
		  }

		  public static List<Integer> topologicalSort(List<Integer>[] graph) {
		    int n = graph.length;
		    boolean[] used = new boolean[n];
		    List<Integer> res = new ArrayList<>();
		    for (int i = n-1; i >0; i--)
		      if (!used[i])
		        dfs(graph, used, res, i);
		    Collections.reverse(res);
		    return res;
		  }

		public static long[][] mulmatrix(long m1[][],long m2[][],long mod){
			long ans[][]=new long[m1.length][m2[0].length];
			for(int i=0;i<m1.length;i++){
				for(int j=0;j<m2[0].length;j++){
					for(int k=0;k<m1.length;k++){
						ans[i][j]+=(m1[i][k]*m2[k][j]);
						ans[i][j]%=mod;
					}
				}
			}
			return ans;
		}
		public static long[][] matrixexpo(long m[][],String n,long mod){
			if(n.equals("1")){
				return m.clone();
			}
			if(n.equals("10")){
				return mulmatrix(m, m , mod);
			}
			else{
				long temp [][]=matrixexpo(m,n.substring(0,n.length()-1),mod);
				temp=mulmatrix(temp, temp, mod);
				if(n.charAt(n.length()-1)=='0')return temp;
				else return mulmatrix(temp, m,mod);
			}
		}
		public static boolean isCompatible(long x[],long y[]){

			for(int i=0;i<x.length-1;i++){
				if(x[i]==y[i] && x[i+1]==y[i+1] && x[i]==x[i+1] && y[i]==y[i+1]){
					return false;
				}
			}
			return true;
		}

		int phi(int n) {
		    int res = n;
		    for (int i = 2; i * i <= n; ++i) {
		        if (n % i == 0) {
		            while (n % i == 0) {
		                n /= i;
		            }
		            res -= res / i;
		        }
		    }
		    if (n != 1) {
		        res -= res / n;
		    }
		    return res;
		}
		long pow(long x,long y,long mod){
			if(y<=0){
				return 1;
			}
			if(y==1){
				return x%mod;
			}
			long temp=pow(x,y/2,mod);
			if(y%2==0){
				return (temp*temp)%mod;
			}
			else{
				return (((temp*temp)%mod)*x)%mod;
			}
		}

/*		long DP(int id,int mask){
			//System.out.println("hi"+dp[id][mask]+" "+id+" "+Integer.toBinaryString(mask));
			if(id==0 && mask==0){
				dp[0][mask]=1;
				return 1;
			}
			else if(id==0){
				dp[0][mask]=0;
				return 0;
			}
			if(dp[id][mask]!=-1){

				return dp[id][mask];
			}
			long ans=0;
			for(int i=0;i<n;i++){
				if((mask & (1<<i))!=0 && c[i][id]>=1){
						ans+=DP(id-1,mask ^ (1 << i));
						ans%=mod;
				}
			}
			ans+=DP(id-1,mask);
			ans%=mod;
			dp[id][mask]=ans;
			return ans;
		}*/
		    static long greatestCommonDivisor (long m, long n){
		        	long x;
		        	long y;
		        	while(m%n != 0){
		        		x = n;
		        		y = m%n;
		        		m = x;
		        		n = y;
		        	}
		        	return n;
		        }
		    	long no_of_primes(long m,long n,long k){
		    		long count=0,i,j;
		    		int primes []=new int[(int)(n-m+2)];
		    		   if(m==1)    primes[0] = 1;
		    	        for(i=2; i<=Math.sqrt(n); i++)
		    	        {
		    	            j = (m/i);    j *= i;
		    	            if(j<m)
		    	                j+=i;
		    	            for(; j<=n; j+=i)
		    	             {
		    	                 if(j!=i)
		    	                    primes[(int)(j-m)] = 1;
		    	             }
		    	        }

		    	for(i=0; i<=n-m; i++)
		    	            if(primes[(int)i]==0 && (i-1)%k==0)
		    	                count++;
		    	return count;
		    	}
}
class SegTree {
	int n;
	long  t[];
	long mod=(long)(1000000007);
	SegTree(int n,long  t[]){
		this.n=n;
		this.t=t;
		//build();
	}

	void build() {  // build the tree

 		for (int i = n - 1; i > 0; --i)
 			t[i]=(t[i<<1]+t[i<<1|1]);
 	}

 	 void modify(int p, long value) {  // set value at position p
 	  for (t[p += n]=value; p > 1; p >>= 1) t[p>>1] = (t[p] + t[p^1]);
 	}

 	 long query(int l, int r) {  // sum on interval [l, r)
 	  long res=0;

 	  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
 		    if ((l&1)!=0) res=(res+t[l++]);
 		    if ((r&1)!=0) res=(res+t[--r]);
 		  }
 	  return res;
 	}

	//
//
//
}
class FastScanner
{

	private InputStream stream;
	private byte[] buf = new byte[8192];
	private int curChar;
	private int snumChars;
	private SpaceCharFilter filter;

	public FastScanner(InputStream stream) {
		this.stream = stream;
	}

	public int snext() {
		if (snumChars == -1)
			throw new InputMismatchException();
		if (curChar >= snumChars) {
			curChar = 0;
			try {
				snumChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (snumChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}
	public int nextInt() {
		int c = snext();
		while (isSpaceChar(c))
			c = snext();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = snext();
		}

		int res = 0;

		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = snext();
		} while (!isSpaceChar(c));

		return res * sgn;
	}

	public long nextLong() {
		int c = snext();
		while (isSpaceChar(c))
			c = snext();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = snext();
		}

		long res = 0;

		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = snext();
		} while (!isSpaceChar(c));

		return res * sgn;
	}

	public String readString() {
		int c = snext();
		while (isSpaceChar(c))
			c = snext();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = snext();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}
 class UF {

    private int[] parent;  // parent[i] = parent of i
    private byte[] rank;   // rank[i] = rank of subtree rooted at i (never more than 31)
    private int count;     // number of components
    public UF(int N) {
        if (N < 0) throw new IllegalArgumentException();
        count = N;
        parent = new int[N];
        rank = new byte[N];
        for (int i = 0; i < N; i++) {
            parent[i] = i;
            rank[i] = 0;
        }
    }

    public int find(int p) {
        if (p < 0 || p >= parent.length) throw new IndexOutOfBoundsException();
        while (p != parent[p]) {
            parent[p] = parent[parent[p]];    // path compression by halving
            p = parent[p];
        }
        return p;
    }
    public int count() {
        return count;
    }

    public boolean connected(int p, int q) {
        return find(p) == find(q);
    }

    public boolean union(int p, int q) {
        int rootP = find(p);
        int rootQ = find(q);
        if (rootP == rootQ) return false;

        // make root of smaller rank point to root of larger rank
        if      (rank[rootP] < rank[rootQ]) parent[rootP] = rootQ;
        else if (rank[rootP] > rank[rootQ]) parent[rootQ] = rootP;
        else {
            parent[rootQ] = rootP;
            rank[rootP]++;
        }
        count--;
        return true;
    }

}


import java.awt.Point;
import java.awt.geom.Line2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.GuardedObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.io.InputStream;
import java.math.BigInteger;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        long var=System.currentTimeMillis();
        solver.solve(1, in, out);
        /*if(System.getProperty("ONLINE_JUDGE")==null){
            out.println("["+(double)(System.currentTimeMillis()-var)/1000+"]");
        }*/
        out.close();
    }
}
class Pair {
    long x,y,index;
    Pair(long x,long y,int index){
        this.x=x;
        this.y=y;
        this.index=index;
    }
    public String toString(){
        return this.x+" "+this.y+" ";
    }

}
class tupple{
    long x,y,z;
    ArrayList<String> list=new ArrayList<>();
    tupple(long x,long y,long z){
        this.x=x;
        this.y=y;
        this.z=z;
    }
    tupple(tupple cl){
        this.x=cl.x;
        this.y=cl.y;
        this.z=cl.z;
        this.list=cl.list;
    }
}
class Edge{
    int u;
    int v;
    int time;
    long cost;
    public Edge(int u,int v){
        this.u=u;
        this.v=v;
        time=Integer.MAX_VALUE;
    }
    public int other(int x){
        if(u==x)return v;
        return u;
    }
}
class Ss{
    Integer a[]=new Integer[3];
    Ss(Integer a[]){
        this.a=a;

    }
    public int hashCode(){
        return a[0].hashCode()+a[1].hashCode()+a[2].hashCode();
    }
    public boolean equals(Object o){
        Ss x=(Ss)o;
        for(int i=0;i<3;i++){
            if(x.a[i]!=this.a[i]){
                return false;
            }
        }
        return true;

    }
}
class queary{
    int type;
    int l;
    int r;
    int index;
    queary(int type,int l,int r){
        this.type=type;
        this.l=l;
        this.r=r;
    }
}
class boat implements Comparable<boat>{
    int capacity;
    int index;
    boat(int capacity,int index)
    {
        this.capacity=capacity;
        this.index=index;
    }
    @Override
    public int compareTo(boat o) {
        // TODO Auto-generated method stub
        return this.capacity-o.capacity;
    }
}
class angle{
    double x,y,angle;
    int index;
    angle(int x,int y,double angle){
        this.x=x;
        this.y=y;
        this.angle=angle;
    }
}
class TaskC {
    static long mod=(long)(1e9+7);
//    SegTree tree;
    //    int min[];
    /*static int prime_len=100001;
    static int prime[]=new int[prime_len];
    static ArrayList<Integer> primes=new ArrayList<>();
    static ArrayList<Integer> list=new ArrayList<>();
    static{
        //System.out.println("lifhgifwrek");
        for(int i=2;i<=Math.sqrt(prime.length);i++){
            for(int j=i*i;j<prime.length;j+=i){

                prime[j]=i;

            }
        }
        for(int i=2;i<prime.length;i++){
            if(prime[i]==0){
                list.add(i);
            }

        }
    //  System.out.println("end");

    //  prime[0]=true;
    //  prime[1]=1;
    }
    /*
     *  long pp[]=new long[10000001];
            pp[0]=0;
            pp[1]=1;
            for(int i=2;i<pp.length;i++){
                if(prime[i]!=0){
                    int gcd=(int)greatestCommonDivisor(i/prime[i], prime[i]);
                    pp[i]=(pp[i/prime[i]]*pp[prime[i]]*gcd)/pp[(int)gcd];
                }
                else
                    pp[i]=i-1;
            }

     * */

            public void solve(int testNumber, FastScanner in, PrintWriter out) throws IOException {
                int n=in.nextInt();
                int q=in.nextInt();
                int a[]=new int[n];
                for(int i=0;i<n;i++){
                    a[i]=in.nextInt();
                }
                int d[]=new int[n];
                for(int i=0;i<n-1;i++){
                    d[i]=Math.abs(a[i]-a[i+1]);
                }
                int n_max[]=new int[n];
                n_max[n-2]=Integer.MAX_VALUE;
                for(int i=n-3;i>=0;i--){
                    if(d[i]<d[i+1]){
                        n_max[i]=i+1;
                    }
                    else{
                        int x=n_max[i+1];
                        while(x<n && d[x]<d[i]){
                            x=n_max[x];
                        }
                        n_max[i]=x;
                    }
                }
                //System.out.println("hi");
                int p_max[]=new int[n];
                p_max[0]=Integer.MIN_VALUE;
                for(int i=1;i<n;i++){
                    if(d[i]<=d[i-1]){
                        p_max[i]=i-1;
                    }
                    else{
                        int x=p_max[i-1];
                        while(x>=0 && d[x]<=d[i]){
                            x=p_max[x];
                        }
                        p_max[i]=x;
                    }
                }
                //out.println(Arrays.toString(d));
                //out.println(Arrays.toString(p_max));
                //out.println(Arrays.toString(n_max));

                for(int i=0;i<q;i++){
                    int l=in.nextInt()-1;
                    int r=in.nextInt()-1;
                    long ans=0;
                    for(int j=l;j<r;j++){
                    //  out.println((j-Math.max(p_max[j],l-1))+" "+(Math.min(r, n_max[j])-j));
                        ans+=(long)d[j]*(long)(j-Math.max(p_max[j],l-1))*(long)(Math.min(r, n_max[j])-(j));
                    }
                    out.println(ans);
                }

            }
            static class pairs{
                String company,color;
                String type;
                boolean visit=false;
                pairs(String company,String color,String type){
                    this.company=company;
                    this.color=color;
                    this.type=type;
                }
            }
        BigInteger BMOD=BigInteger.valueOf(mod);
        private long inv(long q) {
            return BigInteger.valueOf(q).modInverse(BMOD).longValue();
        }

            static void dfs(List<Integer>[] graph, boolean[] used, List<Integer> res, int u) {
            used[u] = true;
            for (int v : graph[u])
              if (!used[v])
                dfs(graph, used, res, v);
            res.add(u);
          }

          public static List<Integer> topologicalSort(List<Integer>[] graph) {
            int n = graph.length;
            boolean[] used = new boolean[n];
            List<Integer> res = new ArrayList<>();
            for (int i = n-1; i >0; i--)
              if (!used[i])
                dfs(graph, used, res, i);
            Collections.reverse(res);
            return res;
          }

        public static long[][] mulmatrix(long m1[][],long m2[][],long mod){
            long ans[][]=new long[m1.length][m2[0].length];
            for(int i=0;i<m1.length;i++){
                for(int j=0;j<m2[0].length;j++){
                    for(int k=0;k<m1.length;k++){
                        ans[i][j]+=(m1[i][k]*m2[k][j]);
                        ans[i][j]%=mod;
                    }
                }
            }
            return ans;
        }
        public static long[][] matrixexpo(long m[][],String n,long mod){
            if(n.equals("1")){
                return m.clone();
            }
            if(n.equals("10")){
                return mulmatrix(m, m , mod);
            }
            else{
                long temp [][]=matrixexpo(m,n.substring(0,n.length()-1),mod);
                temp=mulmatrix(temp, temp, mod);
                if(n.charAt(n.length()-1)=='0')return temp;
                else return mulmatrix(temp, m,mod);
            }
        }
        public static boolean isCompatible(long x[],long y[]){

            for(int i=0;i<x.length-1;i++){
                if(x[i]==y[i] && x[i+1]==y[i+1] && x[i]==x[i+1] && y[i]==y[i+1]){
                    return false;
                }
            }
            return true;
        }

        int phi(int n) {
            int res = n;
            for (int i = 2; i * i <= n; ++i) {
                if (n % i == 0) {
                    while (n % i == 0) {
                        n /= i;
                    }
                    res -= res / i;
                }
            }
            if (n != 1) {
                res -= res / n;
            }
            return res;
        }
        long pow(long x,long y,long mod){
            if(y<=0){
                return 1;
            }
            if(y==1){
                return x%mod;
            }
            long temp=pow(x,y/2,mod);
            if(y%2==0){
                return (temp*temp)%mod;
            }
            else{
                return (((temp*temp)%mod)*x)%mod;
            }
        }

/*      long DP(int id,int mask){
            //System.out.println("hi"+dp[id][mask]+" "+id+" "+Integer.toBinaryString(mask));
            if(id==0 && mask==0){
                dp[0][mask]=1;
                return 1;
            }
            else if(id==0){
                dp[0][mask]=0;
                return 0;
            }
            if(dp[id][mask]!=-1){

                return dp[id][mask];
            }
            long ans=0;
            for(int i=0;i<n;i++){
                if((mask & (1<<i))!=0 && c[i][id]>=1){
                        ans+=DP(id-1,mask ^ (1 << i));
                        ans%=mod;
                }
            }
            ans+=DP(id-1,mask);
            ans%=mod;
            dp[id][mask]=ans;
            return ans;
        }*/
            static long greatestCommonDivisor (long m, long n){
                    long x;
                    long y;
                    while(m%n != 0){
                        x = n;
                        y = m%n;
                        m = x;
                        n = y;
                    }
                    return n;
                }
                long no_of_primes(long m,long n,long k){
                    long count=0,i,j;
                    int primes []=new int[(int)(n-m+2)];
                       if(m==1)    primes[0] = 1;
                        for(i=2; i<=Math.sqrt(n); i++)
                        {
                            j = (m/i);    j *= i;
                            if(j<m)
                                j+=i;
                            for(; j<=n; j+=i)
                             {
                                 if(j!=i)
                                    primes[(int)(j-m)] = 1;
                             }
                        }

                for(i=0; i<=n-m; i++)
                            if(primes[(int)i]==0 && (i-1)%k==0)
                                count++;
                return count;
                }
}
class SegTree {
    int n;
    long  t[];
    long mod=(long)(1000000007);
    SegTree(int n,long  t[]){
        this.n=n;
        this.t=t;
        //build();
    }

    void build() {  // build the tree

        for (int i = n - 1; i > 0; --i)
            t[i]=(t[i<<1]+t[i<<1|1]);
    }

     void modify(int p, long value) {  // set value at position p
      for (t[p += n]=value; p > 1; p >>= 1) t[p>>1] = (t[p] + t[p^1]);
    }

     long query(int l, int r) {  // sum on interval [l, r)
      long res=0;

      for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if ((l&1)!=0) res=(res+t[l++]);
            if ((r&1)!=0) res=(res+t[--r]);
          }
      return res;
    }

    //
//
//
}
class FastScanner
{

    private InputStream stream;
    private byte[] buf = new byte[8192];
    private int curChar;
    private int snumChars;
    private SpaceCharFilter filter;

    public FastScanner(InputStream stream) {
        this.stream = stream;
    }

    public int snext() {
        if (snumChars == -1)
            throw new InputMismatchException();
        if (curChar >= snumChars) {
            curChar = 0;
            try {
                snumChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (snumChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public int nextInt() {
        int c = snext();
        while (isSpaceChar(c))
            c = snext();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = snext();
        }

        int res = 0;

        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = snext();
        } while (!isSpaceChar(c));

        return res * sgn;
    }

    public long nextLong() {
        int c = snext();
        while (isSpaceChar(c))
            c = snext();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = snext();
        }

        long res = 0;

        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = snext();
        } while (!isSpaceChar(c));

        return res * sgn;
    }

    public String readString() {
        int c = snext();
        while (isSpaceChar(c))
            c = snext();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = snext();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}
 class UF {

    private int[] parent;  // parent[i] = parent of i
    private byte[] rank;   // rank[i] = rank of subtree rooted at i (never more than 31)
    private int count;     // number of components
    public UF(int N) {
        if (N < 0) throw new IllegalArgumentException();
        count = N;
        parent = new int[N];
        rank = new byte[N];
        for (int i = 0; i < N; i++) {
            parent[i] = i;
            rank[i] = 0;
        }
    }

    public int find(int p) {
        if (p < 0 || p >= parent.length) throw new IndexOutOfBoundsException();
        while (p != parent[p]) {
            parent[p] = parent[parent[p]];    // path compression by halving
            p = parent[p];
        }
        return p;
    }
    public int count() {
        return count;
    }

    public boolean connected(int p, int q) {
        return find(p) == find(q);
    }

    public boolean union(int p, int q) {
        int rootP = find(p);
        int rootQ = find(q);
        if (rootP == rootQ) return false;

        // make root of smaller rank point to root of larger rank
        if      (rank[rootP] < rank[rootQ]) parent[rootP] = rootQ;
        else if (rank[rootP] > rank[rootQ]) parent[rootQ] = rootP;
        else {
            parent[rootQ] = rootP;
            rank[rootP]++;
        }
        count--;
        return true;
    }

}


import java.io.*;
import java.util.*;

public class CF {
	FastScanner in;
	PrintWriter out;

	class Solver {
		ArrayList<Integer> pos = new ArrayList<>();
		ArrayList<Integer> diffs = new ArrayList<>();
		int last = -1;
		long ans = 0;
		int cnt = 1;
		long curSum = 0;

		Solver(int last) {
			this.last = last;
		}

		void addNumber(int x) {
			int curDiff = Math.abs(x - last);
			while (diffs.size() > 0 && diffs.get(diffs.size() - 1) <= curDiff) {
				int curFrom = diffs.size() == 1 ? 0 : pos.get(pos.size() - 2);
				int len = pos.get(pos.size() - 1) - curFrom;
				curSum -= len * 1L * diffs.get(diffs.size() - 1);
				diffs.remove(diffs.size() - 1);
				pos.remove(pos.size() - 1);
			}
			int curFrom = diffs.size() == 0 ? 0 : pos.get(pos.size() - 1);
			curSum += (cnt - curFrom) * 1L * curDiff;
			diffs.add(curDiff);
			pos.add(cnt);
			last = x;
			cnt++;
			ans += curSum;
		}
	}

	void solve() {
		int n = in.nextInt();
		int q = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}

		for (int i = 0; i < q; i++) {
			int fr = in.nextInt() - 1;
			int to = in.nextInt() - 1;
			Solver solve = new Solver(a[fr]);
			for (int j = fr + 1; j <= to; j++) {
				solve.addNumber(a[j]);
			}
			out.println(solve.ans);
		}
	}

	void run() {
		try {
			in = new FastScanner(new File("CF.in"));
			out = new PrintWriter(new File("CF.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new CF().runIO();
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hieu Le
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        private int[] tree;
        private int[] a;
        private int[] delta;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            a = new int[n];
            for (int i = 0; i < n; ++i)
                a[i] = in.nextInt();
            delta = new int[n - 1];
            for (int i = 0; i < n - 1; ++i)
                delta[i] = Math.abs(a[i] - a[i + 1]);
            tree = new int[4 * n];
            build(0, 0, delta.length - 1);

            for (int i = 0; i < q; ++i) {
                int left = in.nextInt() - 1;
                int right = in.nextInt() - 1;
                out.println(compute(left, right));
            }
        }

        private long compute(int left, int right) {
            if (left == right)
                return 0;
            int maxIndex = query(0, 0, delta.length - 1, left, right - 1);
            long result = (long) (maxIndex - left + 1) * (right - (maxIndex + 1) + 1) * delta[maxIndex];
            return result + compute(left, maxIndex) + compute(maxIndex + 1, right);
        }

        private int query(int index, int low, int high, int left, int right) {
            if (high < left || low > right)
                return -1;
            if (left <= low && high <= right)
                return tree[index];

            int mid = low + (high - low) / 2;
            int maxLeft = query(2 * index + 1, low, mid, left, right);
            int maxRight = query(2 * index + 2, mid + 1, high, left, right);

            if (maxLeft == -1)
                return maxRight;
            if (maxRight == -1)
                return maxLeft;

            return (delta[maxLeft] > delta[maxRight]) ? maxLeft : maxRight;
        }

        private void build(int index, int low, int high) {
            if (low == high) {
                tree[index] = low;
                return;
            }

            int mid = low + (high - low) / 2;
            int leftIndex = 2 * index + 1;
            int rightIndex = 2 * index + 2;
            build(leftIndex, low, mid);
            build(rightIndex, mid + 1, high);

            if (delta[tree[leftIndex]] > delta[tree[rightIndex]])
                tree[index] = tree[leftIndex];
            else
                tree[index] = tree[rightIndex];
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        private static final int BUFFER_SIZE = 32768;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), BUFFER_SIZE);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hieu Le
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        private int[] a;
        private int[] delta;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            a = new int[n];
            for (int i = 0; i < n; ++i)
                a[i] = in.nextInt();
            delta = new int[n - 1];
            for (int i = 0; i < n - 1; ++i)
                delta[i] = Math.abs(a[i] - a[i + 1]);

            for (int i = 0; i < q; ++i) {
                int left = in.nextInt() - 1;
                int right = in.nextInt() - 1;
                out.println(compute(left, right));
            }
        }

        private long compute(int left, int right) {
            long result = 0;
//        Stack<Integer> differences = new Stack<>();
            int[] stack = new int[right - left];
            int head = -1;
            for (int i = left; i < right; ++i) {
                while (head >= 0 && delta[stack[head]] <= delta[i]) {
                    int top = stack[head--];
                    int low = (head < 0) ? left : stack[head] + 1;
                    int high = i;
                    result += (long) delta[top] * (top - low + 1) * (high - top);
                }
                stack[++head] = i;

//            while (!differences.isEmpty() && delta[differences.peek()] <= delta[i]) {
//                int top = differences.pop();
//                int low = (differences.isEmpty()) ? left : differences.peek() + 1;
//                int high = i;
//                result += (long) delta[top] * (top - low + 1) * (high - top);
//            }
//            differences.push(i);
            }

            while (head >= 0) {
                int top = stack[head--];
                int low = (head < 0) ? left : stack[head] + 1;
                int high = right;
                result += (long) delta[top] * (top - low + 1) * (high - top);
            }

//        while (!differences.isEmpty()) {
//            int top = differences.pop();
//            int low = (differences.isEmpty()) ? left : differences.peek() + 1;
//            int high = right;
//            result += (long) delta[top] * (top - low + 1) * (high - top);
//        }
            return result;
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        private static final int BUFFER_SIZE = 32768;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), BUFFER_SIZE);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hieu Le
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        private int[] a;
        private int[] delta;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            a = new int[n];
            for (int i = 0; i < n; ++i)
                a[i] = in.nextInt();
            delta = new int[n - 1];
            for (int i = 0; i < n - 1; ++i)
                delta[i] = Math.abs(a[i] - a[i + 1]);

            for (int i = 0; i < q; ++i) {
                int left = in.nextInt() - 1;
                int right = in.nextInt() - 1;
                out.println(compute(left, right));
            }
        }

        private long compute(int left, int right) {
            long result = 0;
            Stack<Integer> differences = new Stack<>();
            for (int i = left; i < right; ++i) {
                while (!differences.isEmpty() && delta[differences.peek()] <= delta[i]) {
                    int top = differences.pop();
                    int low = (differences.isEmpty()) ? left : differences.peek() + 1;
                    int high = i;
//                System.err.printf("%d %d %d\n", top, low, high);
                    result += (long) delta[top] * (top - low + 1) * (high - top);
                }
                differences.push(i);
            }

            while (!differences.isEmpty()) {
                int top = differences.pop();
                int low = (differences.isEmpty()) ? left : differences.peek() + 1;
                int high = right;
                result += (long) delta[top] * (top - low + 1) * (high - top);
            }
            return result;
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        private static final int BUFFER_SIZE = 32768;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), BUFFER_SIZE);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.*;
import java.util.*;

public class test {
    int INF = (int)1e9;
    long MOD = 1000000007;

    int n, q;
    int[] a, d, l, r;

    int[] gol() {
        l = new int[n];
        Stack<Integer> stack = new Stack<>();
        for(int i=1; i<n; i++) {
            int j = l[i] = i;
            while(stack.size()>0 && d[stack.peek()]<d[i]) {
                j = stack.pop();
            }
            l[i] = l[j];
            stack.push(i);
        }
        return l;
    }

    int[] gor() {
        r = new int[n];
        Stack<Integer> stack = new Stack<>();
        for(int i=n-1; i>0; i--) {
            int j = r[i] = i;
            while(stack.size()>0 && d[stack.peek()]<=d[i]) {
                j = stack.pop();
            }
            r[i] = r[j];
            stack.push(i);
        }
        return r;
    }

    void solve(InputReader in, PrintWriter out) throws IOException {
        n = in.nextInt();
        q = in.nextInt();
        a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
        }
        d = new int[n];
        for(int i=1; i<n; i++) {
            d[i] = Math.abs(a[i]-a[i-1]);
        }
        l = gol();
        r = gor();
//        show(d);
//        show(l);
//        show(r);
        while(q-->0) {
            int a = in.nextInt();
            int b = in.nextInt()-1;
//            show("ab", a, b);
            long rs = 0;
            for(int i=a; i<=b; i++) {
                int mi = Math.max(l[i], a);
                int mx = Math.min(r[i], b);
//                show("mul", i, mi, mx, (i-mi+1l), (mx-i+1l), (i-mi+1l) * (mx-i+1l));
                rs += d[i] * (i-mi+1l) * (mx-i+1l);
            }
            out.println(rs);
        }
    }

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-->0) {
            new test().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }

    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }

    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }

    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        RMQ rmq;

        long eval(int l, int r) {
            if (l >= r) {
                return 0;
            }
            int m = rmq.rmq(l, r);
            long ans = 1L * (m - l + 1) * (r - m) * rmq.s[m];
            ans += eval(l, m);
            ans += eval(m + 1, r);
            return ans;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            long[] s = new long[n - 1];
            for (int i = 1; i < n; i++) {
                s[i - 1] = Math.abs(a[i] - a[i - 1]);
            }

            rmq = new RMQ(s, n - 1);

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                long ans = eval(l, r);
                out.println(ans);
            }
        }

        class RMQ {
            long[] s;
            int[][] st;
            int[] p2;
            int n;

            public RMQ(long[] s, int n) {
                this.s = s;
                int z = 0;
                while ((1 << z) <= n) {
                    z++;
                }
                st = new int[z][n];
                this.n = n;
                for (int i = 0; i < n; i++) {
                    st[0][i] = i;
                }
                for (int i = 1; i < z; i++) {
                    for (int j = 0; j + (1 << i) <= n; j++) {
                        int q1 = st[i - 1][j];
                        int q2 = st[i - 1][j + (1 << (i - 1))];
                        if (s[q1] > s[q2]) {
                            st[i][j] = q1;
                        } else {
                            st[i][j] = q2;
                        }
                    }
                }
                p2 = new int[n + 1];
                p2[1] = 0;
                for (int i = 2; i <= n; i++) {
                    p2[i] = p2[i / 2] + 1;
                }
            }

            int rmq(int l, int r) {
                int k = p2[r - l];
                int q1 = st[k][l];
                int q2 = st[k][r - (1 << k)];
                if (s[q1] > s[q2]) {
                    return q1;
                } else {
                    return q2;
                }
            }

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        RMQ rmq;

        long eval(int l, int r) {
            if (l >= r) {
                return 0;
            }
            int m = rmq.rmq(l, r);
            long ans = 1L * (m - l + 1) * (r - m) * rmq.s[m];
            ans += eval(l, m);
            ans += eval(m + 1, r);
            return ans;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            long[] s = new long[n - 1];
            for (int i = 1; i < n; i++) {
                s[i - 1] = Math.abs(a[i] - a[i - 1]);
            }

            rmq = new RMQ(s, n - 1);

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                long ans = eval(l, r);
                out.println(ans);
            }
        }

        class RMQ {
            long[] s;
            int[][] st;
            int[] p2;
            int n;

            public RMQ(long[] s, int n) {
                this.s = s;
                int z = 0;
                while ((1 << z) < n) {
                    z++;
                }
                st = new int[z][n];
                this.n = n;
                for (int i = 0; i < n; i++) {
                    st[0][i] = i;
                }
                for (int i = 1; i < z; i++) {
                    for (int j = 0; j + (1 << i) <= n; j++) {
                        int q1 = st[i - 1][j];
                        int q2 = st[i - 1][j + (1 << (i - 1))];
                        if (s[q1] > s[q2]) {
                            st[i][j] = q1;
                        } else {
                            st[i][j] = q2;
                        }
                    }
                }
                p2 = new int[n + 1];
                p2[1] = 0;
                for (int i = 2; i <= n; i++) {
                    p2[i] = p2[i / 2] + 1;
                }
            }

            int rmq(int l, int r) {
                int k = p2[r - l];
                int q1 = st[k][l];
                int q2 = st[k][r - (1 << k)];
                if (s[q1] > s[q2]) {
                    return q1;
                } else {
                    return q2;
                }
            }

        }

    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {

    static StringTokenizer st;
    static BufferedReader br;
    static PrintWriter pw;
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int q = nextInt();
        int[]a = new int[n+1];
        for (int i = 1; i <= n; i++) {
            a[i] = nextInt();
        }
        int[]stek = new int[n+1];
        int size = 0;
        int[]val = new int[n+1];
        long[]ans = new long[n+1];
        for (int i = 2; i <= n; i++) {
            val[i] = Math.abs(a[i]-a[i-1]);
        }
        while (q-->0) {
            int L = nextInt();
            int R = nextInt();
            long sum = 0;
            size = 0;
            for (int i = L+1; i <= R; i++) {
                int s = val[i];
                while (size > 0 && s >= val[stek[size]]) {
                    size--;
                }
                if (size==0) {
                    long x = (long)(i-L) * s;
                    sum += x;
                    ans[i] = x;
                }
                else {
                    long x = (long)(i-stek[size]) * s + ans[stek[size]];
                    sum += x;
                    ans[i] = x;
                }
                stek[++size] = i;
            }
            pw.println(sum);
        }
        pw.close();
    }
    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
    private static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
    private static String next() throws IOException {
        while (st==null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }
}


// practice with rainboy
import java.io.*;
import java.util.*;

public class CF601B extends PrintWriter {
	CF601B() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF601B o = new CF601B(); o.main(); o.flush();
	}

	Integer[] ii;
	int[] aa, ll, rr;
	boolean[] used;
	long solve(int n, int ql, int qr) {
		for (int i = ql - 1; i <= qr + 1; i++) {
			ll[i] = rr[i] = i;
			used[i] = false;
		}
		long ans = 0;
		for (int h = 0; h < n; h++) {
			int i = ii[h];
			if (i < ql || i > qr)
				continue;
			int l = i, r = i;
			used[i] = true;
			if (used[i - 1])
				l = ll[i - 1];
			if (used[i + 1])
				r = rr[i + 1];
			rr[l] = r;
			ll[r] = l;
			ans += (long) (i - l + 1) * (r - i + 1) * aa[i];
		}
		return ans;
	}
	void main() {
		int n = sc.nextInt();
		int q = sc.nextInt();
		aa = new int[n + 1];
		for (int i = 1; i <= n; i++)
			aa[i] = sc.nextInt();
		for (int i = 1; i <= n - 1; i++)
			aa[i] = Math.abs(aa[i + 1] - aa[i]);
		n--;
		ii = new Integer[n];
		for (int h = 0; h < n; h++)
			ii[h] = h + 1;
		Arrays.sort(ii, (i, j) -> aa[i] - aa[j]);
		ll = new int[n + 2];
		rr = new int[n + 2];
		used = new boolean[n + 2];
		while (q-- > 0) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			println(solve(n, l, r - 1));
		}
	}
}


// practice with rainboy
import java.io.*;
import java.util.*;

public class CF601B extends PrintWriter {
	CF601B() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF601B o = new CF601B(); o.main(); o.flush();
	}

	long solve(int[] aa, int n) {
		Integer[] ii = new Integer[n];
		for (int h = 0; h < n; h++)
			ii[h] = h + 1;
		Arrays.sort(ii, (i, j) -> aa[i] - aa[j]);
		int[] ll = new int[n + 2];
		int[] rr = new int[n + 2];
		boolean[] used = new boolean[n + 2];
		for (int i = 0; i < n + 2; i++)
			ll[i] = rr[i] = i;
		long ans = 0;
		for (int h = 0; h < n; h++) {
			int i = ii[h], l = i, r = i;
			used[i] = true;
			if (used[i - 1])
				l = ll[i - 1];
			if (used[i + 1])
				r = rr[i + 1];
			rr[l] = r;
			ll[r] = l;
			ans += (long) (i - l + 1) * (r - i + 1) * aa[i];
		}
		return ans;
	}
	void main() {
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] aa = new int[n];
		for (int i = 0; i < n; i++)
			aa[i] = sc.nextInt();
		for (int i = 0; i < n - 1; i++)
			aa[i] = Math.abs(aa[i + 1] - aa[i]);
		n--;
		while (q-- > 0) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			int m = r - l;
			int[] bb = new int[m + 2];
			for (int j = 0; j < m; j++)
				bb[1 + j] = aa[l + j];
			println(solve(bb, m));
		}
	}
}


// practice with rainboy
import java.io.*;
import java.util.*;

public class CF601B extends PrintWriter {
	CF601B() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF601B o = new CF601B(); o.main(); o.flush();
	}

	int[] ll, rr;
	boolean[] used;
	long solve(int[] aa, int o, int n) {
		Integer[] ii = new Integer[n];
		for (int h = 0; h < n; h++)
			ii[h] = h + 1;
		Arrays.sort(ii, (i, j) -> aa[o + i - 1] - aa[o + j - 1]);
		for (int i = 0; i < n + 2; i++)
			ll[i] = rr[i] = i;
		Arrays.fill(used, false);
		long ans = 0;
		for (int h = 0; h < n; h++) {
			int i = ii[h], l = i, r = i;
			used[i] = true;
			if (used[i - 1])
				l = ll[i - 1];
			if (used[i + 1])
				r = rr[i + 1];
			rr[l] = r;
			ll[r] = l;
			ans += (long) (i - l + 1) * (r - i + 1) * aa[o + i - 1];
		}
		return ans;
	}
	void main() {
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] aa = new int[n];
		for (int i = 0; i < n; i++)
			aa[i] = sc.nextInt();
		for (int i = 0; i < n - 1; i++)
			aa[i] = Math.abs(aa[i + 1] - aa[i]);
		n--;
		ll = new int[n + 2];
		rr = new int[n + 2];
		used = new boolean[n + 2];
		while (q-- > 0) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			println(solve(aa, l, r - l));
		}
	}
}


// practice with rainboy
import java.io.*;
import java.util.*;

public class CF601B extends PrintWriter {
	CF601B() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF601B o = new CF601B(); o.main(); o.flush();
	}

	long solve(int[] aa, int n) {
		Integer[] ii = new Integer[n];
		for (int h = 0; h < n; h++)
			ii[h] = h + 1;
		Arrays.sort(ii, (i, j) -> aa[i] - aa[j]);
		int[] ll = new int[n + 2];
		int[] rr = new int[n + 2];
		boolean[] used = new boolean[n + 2];
		for (int i = 0; i < n + 2; i++)
			ll[i] = rr[i] = i;
		long ans = 0;
		for (int h = 0; h < n; h++) {
			int i = ii[h], l = i, r = i;
			used[i] = true;
			if (used[i - 1])
				l = ll[i - 1];
			if (used[i + 1])
				r = rr[i + 1];
			rr[l] = r;
			ll[r] = l;
			ans += (long) (i - l + 1) * (r - i + 1) * aa[i];
		}
		return ans;
	}
	void main() {
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] aa = new int[n];
		int[] bb = new int[n + 2];
		for (int i = 0; i < n; i++)
			aa[i] = sc.nextInt();
		for (int i = 0; i < n - 1; i++)
			aa[i] = Math.abs(aa[i + 1] - aa[i]);
		n--;
		while (q-- > 0) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			int m = r - l;
			for (int j = 0; j < m; j++)
				bb[1 + j] = aa[l + j];
			println(solve(bb, m));
		}
	}
}


// practice with rainboy
import java.io.*;
import java.util.*;

public class CF601B extends PrintWriter {
	CF601B() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF601B o = new CF601B(); o.main(); o.flush();
	}

	long solve(int[] aa, int n) {
		Integer[] ii = new Integer[n];
		for (int h = 0; h < n; h++)
			ii[h] = h + 1;
		Arrays.sort(ii, (i, j) -> aa[i] - aa[j]);
		int[] ll = new int[n + 2];
		int[] rr = new int[n + 2];
		boolean[] used = new boolean[n + 2];
		for (int i = 0; i < n + 2; i++)
			ll[i] = rr[i] = i;
		long ans = 0;
		for (int h = 0; h < n; h++) {
			int i = ii[h], l = i, r = i;
			used[i] = true;
			if (used[i - 1])
				l = ll[i - 1];
			if (used[i + 1])
				r = rr[i + 1];
			rr[l] = r;
			ll[r] = l;
			ans += (long) (i - l + 1) * (r - i + 1) * aa[i];
		}
		return ans;
	}
	void main() {
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] aa = new int[n];
		for (int i = 0; i < n; i++)
			aa[i] = sc.nextInt();
		for (int i = 0; i < n - 1; i++)
			aa[i] = Math.abs(aa[i + 1] - aa[i]);
		n--;
		while (q-- > 0) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			int m = r - l;
			int[] bb = new int[m + 2];
			for (int j = 0; j < m; j++)
				bb[1 + j] = aa[l + j];
			println(solve(bb, m));
		}
	}
}


import java.io.*;
import java.util.*;

public class TaskB {
  public static void main(String[] args) throws IOException {
    TaskB tB = new TaskB();
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter output = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    tB.solve(input, output);
    output.close();
  }

  public void solve(BufferedReader input, PrintWriter output) throws IOException {
    StringTokenizer st = new StringTokenizer(input.readLine());
    int n = Integer.parseInt(st.nextToken());
    int q = Integer.parseInt(st.nextToken());

    int[] a = new int[n];
    st = new StringTokenizer(input.readLine());
    for(int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(st.nextToken());
    }

    // absolute difference between a[i] and a[i + 1]
    // if i < j < k then L(i,j) or L(j,k) >= L(i,k)
    int[] diff = new int[n - 1];
    for (int i = 0; i < n - 1; i++) {
      diff[i] = Math.abs(a[i] - a[i + 1]);
    }

    for (int query = 0; query < q; query++) {
      st = new StringTokenizer(input.readLine());
      int low = Integer.parseInt(st.nextToken()) - 1;
      int high = Integer.parseInt(st.nextToken()) - 2;
      int[] lengthLeft = countLeft(diff, low, high);
      int[] lengthRight = countRight(diff, low, high);

      if (low > high) {
        output.println(0);
        continue;
      }
      long result = 0L;
      for (int idx = low; idx <= high; idx++) {
        result += (1L) * diff[idx] * lengthLeft[idx] * lengthRight[idx];
      }
      output.println(result);
    }
  }

  // lengthLeft[i] the max length of the sequence (j,i) where j <= i such that a[i] >= a[j]
  private int[] countLeft(int[] arr, int left, int right) {
    int[] count = new int[arr.length];
    Stack<Cell> stack = new Stack<Cell>();
    for (int idx = left; idx <= right; idx++) {
      count[idx] = 1;
      if (!stack.empty()) {
        while (!stack.empty() && stack.peek().value <= arr[idx]) {
          Cell top = stack.pop();
          count[idx] += count[top.idx];
        }
      }
      stack.push(new Cell(idx, arr[idx]));
    }
    return count;
  }

  // lengthRight[i] same as lengthLeft, but to the right but a[i] > a[j] if j != i
  private int[] countRight(int[] arr, int left, int right) {
    int[] count = new int[arr.length];
    Stack<Cell> stack = new Stack<Cell>();
    for (int idx = right; idx >= left; idx--) {
      count[idx] = 1;
      if (!stack.empty()) {
        while (!stack.empty() && stack.peek().value < arr[idx]) {
          Cell top = stack.pop();
          count[idx] += count[top.idx];
        }
      }
      stack.push(new Cell(idx, arr[idx]));
    }
    return count;
  }

  private class Cell {
    private int idx;
    private int value;

    private Cell(int idx, int value) {
      this.idx = idx;
      this.value = value;
    }
  }
}


import java.io.*;
import java.util.*;

public class TaskB {
  public static void main(String[] args) throws IOException {
    TaskB tB = new TaskB();
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter output = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    tB.solve(input, output);
    output.close();
  }

  public void solve(BufferedReader input, PrintWriter output) throws IOException {
    StringTokenizer st = new StringTokenizer(input.readLine());
    int n = Integer.parseInt(st.nextToken());
    int q = Integer.parseInt(st.nextToken());

    int[] a = new int[n];
    st = new StringTokenizer(input.readLine());
    for(int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(st.nextToken());
    }

    // absolute difference between a[i] and a[i + 1]
    // if i < j < k then L(i,j) or L(j,k) >= L(i,k)
    int[] diff = new int[n - 1];
    for (int i = 0; i < n - 1; i++) {
      diff[i] = Math.abs(a[i] - a[i + 1]);
    }

    int[] lengthLeft = new int[n - 1];
    int[] lengthRight = new int[n - 1];

    for (int query = 0; query < q; query++) {
      st = new StringTokenizer(input.readLine());
      int low = Integer.parseInt(st.nextToken()) - 1;
      int high = Integer.parseInt(st.nextToken()) - 2;
      countLeft(diff, low, high, lengthLeft);
      countRight(diff, low, high, lengthRight);

      if (low > high) {
        output.println(0);
        continue;
      }
      long result = 0L;
      for (int idx = low; idx <= high; idx++) {
        result += (1L) * diff[idx] * lengthLeft[idx] * lengthRight[idx];
      }
      output.println(result);
    }
  }

  // lengthLeft[i] the max length of the sequence (j,i) where j <= i such that a[i] >= a[j]
  private void countLeft(int[] arr, int left, int right, int[] count) {
    Arrays.fill(count, 0);
    Stack<Cell> stack = new Stack<Cell>();
    for (int idx = left; idx <= right; idx++) {
      count[idx] = 1;
      if (!stack.empty()) {
        while (!stack.empty() && stack.peek().value <= arr[idx]) {
          Cell top = stack.pop();
          count[idx] += count[top.idx];
        }
      }
      stack.push(new Cell(idx, arr[idx]));
    }
  }

  // lengthRight[i] same as lengthLeft, but to the right but a[i] > a[j] if j != i
  private void countRight(int[] arr, int left, int right, int[] count) {
    Arrays.fill(count, 0);
    Stack<Cell> stack = new Stack<Cell>();
    for (int idx = right; idx >= left; idx--) {
      count[idx] = 1;
      if (!stack.empty()) {
        while (!stack.empty() && stack.peek().value < arr[idx]) {
          Cell top = stack.pop();
          count[idx] += count[top.idx];
        }
      }
      stack.push(new Cell(idx, arr[idx]));
    }
  }

  private class Cell {
    private int idx;
    private int value;

    private Cell(int idx, int value) {
      this.idx = idx;
      this.value = value;
    }
  }
}


import java.io.*;
import java.util.*;

public class TaskB {
  public static void main(String[] args) {
    TaskB tB = new TaskB();
    Scanner input = new Scanner(System.in);
    PrintWriter output = new PrintWriter(System.out);
    tB.solve(input, output);
    output.close();
  }

  private int n, q;
  private int[] a;
  private int[] diff;
  private int[] stack;
  private int[] lengthLeft;
  private int[] lengthRight;

  public void solve(Scanner input, PrintWriter output) {
    n = input.nextInt();
    q = input.nextInt();

    a = new int[n];
    for(int i = 0; i < n; i++) {
      a[i] = input.nextInt();
    }

    diff = new int[n - 1];
    for (int i = 0; i < n - 1; i++) {
      diff[i] = Math.abs(a[i] - a[i + 1]);
    }

    stack = new int[n];
    lengthLeft = new int[n - 1];
    lengthRight = new int[n - 1];
    // if i < j < k then L(i,j) or L(j,k) >= L(i,k)
    for (int query = 0; query < q; query++) {
      int low = input.nextInt() - 1;
      int high = input.nextInt() - 1;

      countLeft(low, high);
      countRight(low, high);
      long result = 0L;
      for (int idx = low; idx < high; idx++) {
        result += (1L) * diff[idx] * lengthLeft[idx] * lengthRight[idx];
      }
      output.println(result);
    }
  }

  // lengthLeft[i] the max length of the sequence (j,i) where j <= i such that a[i] >= a[j]
  private void countLeft(int low, int high) {
    Arrays.fill(lengthLeft, 0);
    int top = -1;
    for (int i = low; i < high; i++) {
      lengthLeft[i] = 1;
      if (top >= 0) { // not empty
        while (top >= 0 && diff[stack[top]] <= diff[i])
          lengthLeft[i] += lengthLeft[stack[top--]];
      }
      stack[++top] = i;
    }
  }

  // lengthRight[i] same as lengthLeft, but to the right but a[i] > a[j] if j != i
  private void countRight(int low, int high) {
    Arrays.fill(lengthRight, 0);
    int top = -1;
    for (int i = high - 1; i >= low; i--) {
      lengthRight[i] = 1;
      if (top >= 0) { // not empty
        while (top >= 0 && diff[stack[top]] < diff[i])
          lengthRight[i] += lengthRight[stack[top--]];
      }
      stack[++top] = i;
    }
  }

  private class Cell {
    private int idx;
    private int value;

    private Cell(int idx, int value) {
      this.idx = idx;
      this.value = value;
    }
  }
}


import java.io.*;
import java.util.*;

public class TaskB {
  public static void main(String[] args) {
    TaskB tB = new TaskB();
    Scanner input = new Scanner(System.in);
    PrintWriter output = new PrintWriter(System.out);
    tB.solve(input, output);
    output.close();
  }

  private int n, q;
  private int[] a;
  private int[] diff;
  private int[] stack;
  private int[] lengthLeft;
  private int[] lengthRight;

  public void solve(Scanner input, PrintWriter output) {
    n = input.nextInt();
    q = input.nextInt();

    a = new int[n];
    for(int i = 0; i < n; i++) {
      a[i] = input.nextInt();
    }

    diff = new int[n - 1];
    for (int i = 0; i < n - 1; i++) {
      diff[i] = Math.abs(a[i] - a[i + 1]);
    }

    stack = new int[n];
    lengthLeft = new int[n - 1];
    lengthRight = new int[n - 1];
    // if i < j < k then L(i,j) or L(j,k) >= L(i,k)
    for (int query = 0; query < q; query++) {
      int low = input.nextInt() - 1;
      int high = input.nextInt() - 1;

      countLeft(low, high);
      countRight(low, high);
      long result = 0L;
      for (int idx = low; idx < high; idx++) {
        result += (1L) * diff[idx] * lengthLeft[idx] * lengthRight[idx];
      }
      output.println(result);
    }
  }

  // lengthLeft[i] the max length of the sequence (j,i) where j <= i such that a[i] >= a[j]
  private void countLeft(int low, int high) {
    int top = -1;
    for (int i = low; i < high; i++) {
      lengthLeft[i] = 1;
      if (top >= 0) { // not empty
        while (top >= 0 && diff[stack[top]] <= diff[i])
          lengthLeft[i] += lengthLeft[stack[top--]];
      }
      stack[++top] = i;
    }
  }

  // lengthRight[i] same as lengthLeft, but to the right but a[i] > a[j] if j != i
  private void countRight(int low, int high) {
    int top = -1;
    for (int i = high - 1; i >= low; i--) {
      lengthRight[i] = 1;
      if (top >= 0) { // not empty
        while (top >= 0 && diff[stack[top]] < diff[i])
          lengthRight[i] += lengthRight[stack[top--]];
      }
      stack[++top] = i;
    }
  }
}


import java.io.PrintWriter;
import java.util.*;

public class TaskB {
  public static void main(String[] args) {
    TaskB tB = new TaskB();
    PrintWriter pw = new PrintWriter(System.out);
    tB.solve(new Scanner(System.in), pw);
    pw.close();
  }

  public void solve(Scanner input, PrintWriter output) {
    int n = input.nextInt();
    int q = input.nextInt();
    int[] a = new int[n];
    for(int i = 0; i < n; i++) {
      a[i] = input.nextInt();
    }

    // absolute difference between a[i] and a[i + 1]
    // if i < j < k then L(i,j) or L(j,k) >= L(i,k)
    int[] diff = new int[n - 1];
    for (int i = 0; i < n - 1; i++) {
      diff[i] = Math.abs(a[i] - a[i + 1]);
    }

    for (int query = 0; query < q; query++) {
      int low = input.nextInt() - 1;
      int high = input.nextInt() - 2;
      int[] lengthLeft = countLeft(diff, low, high);
      int[] lengthRight = countRight(diff, low, high);

      if (low > high) {
        output.println(0);
        continue;
      }
      long result = 0L;
      for (int idx = low; idx <= high; idx++) {
        result += (1L) * diff[idx] * lengthLeft[idx] * lengthRight[idx];
      }
      output.println(result);
    }
  }

  // lengthLeft[i] the max length of the sequence (j,i) where j <= i such that a[i] >= a[j]
  private int[] countLeft(int[] arr, int left, int right) {
    int[] count = new int[arr.length];
    Stack<Cell> stack = new Stack<Cell>();
    for (int idx = left; idx <= right; idx++) {
      count[idx] = 1;
      if (!stack.empty()) {
        while (!stack.empty() && stack.peek().value <= arr[idx]) {
          Cell top = stack.pop();
          count[idx] += count[top.idx];
        }
      }
      stack.push(new Cell(idx, arr[idx]));
    }
    return count;
  }

  // lengthRight[i] same as lengthLeft, but to the right but a[i] > a[j] if j != i
  private int[] countRight(int[] arr, int left, int right) {
    int[] count = new int[arr.length];
    Stack<Cell> stack = new Stack<Cell>();
    for (int idx = right; idx >= left; idx--) {
      count[idx] = 1;
      if (!stack.empty()) {
        while (!stack.empty() && stack.peek().value < arr[idx]) {
          Cell top = stack.pop();
          count[idx] += count[top.idx];
        }
      }
      stack.push(new Cell(idx, arr[idx]));
    }
    return count;
  }

  private class Cell {
    private int idx;
    private int value;

    private Cell(int idx, int value) {
      this.idx = idx;
      this.value = value;
    }
  }
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.Stack;
import java.util.StringTokenizer;

public class P {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt(), Q = sc.nextInt();
		int[] a = sc.nextIntArray(N);
		int[] d = new int[N - 1];
		for (int i = 1; i < N; i++)
			d[i - 1] = Math.abs(a[i - 1] - a[i]);
		int[] l = adjL(d, N - 1);
		int[] r = adjR(d, N - 1);
		while (Q-- > 0) {
			int li = sc.nextInt() - 1, ri = sc.nextInt() - 1;
			long answer = 0;
			for (int i = li; i < ri; i++)
				answer += 1l * d[i] * (Math.min(r[i], ri) - i) * (i - Math.max(l[i], li - 1));
			out.println(answer);
		}

		out.flush();
		out.close();

	}

	static int[] adjR(int[] x, int N) {
		Stack<Integer> s = new Stack<Integer>();
		int[] r = new int[N];
		for (int i = N - 1; i >= 0; i--) {
			while (!s.isEmpty() && x[s.peek()] < x[i])
				s.pop();
			if (s.isEmpty())
				r[i] = N;
			else
				r[i] = s.peek();
			s.push(i);
		}
		return r;
	}

	static int[] adjL(int[] x, int N) {
		Stack<Integer> s = new Stack<Integer>();
		int[] l = new int[N];
		for (int i = 0; i < N; i++) {
			while (!s.isEmpty() && x[s.peek()] <= x[i])
				s.pop();
			if (s.isEmpty())
				l[i] = -1;
			else
				l[i] = s.peek();
			s.push(i);
		}
		return l;
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(String f) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(f));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public int[] nextIntArray1(int n) throws IOException {
			int[] a = new int[n + 1];
			for (int i = 1; i <= n; i++)
				a[i] = nextInt();
			return a;
		}

		public int[] shuffle(int[] a, int n) {
			int[] b = new int[n];
			for (int i = 0; i < n; i++)
				b[i] = a[i];
			Random r = new Random();
			for (int i = 0; i < n; i++) {
				int j = i + r.nextInt(n - i);
				int t = b[i];
				b[i] = b[j];
				b[j] = t;
			}
			return b;
		}

		public int[] nextIntArraySorted(int n) throws IOException {
			int[] a = nextIntArray(n);
			a = shuffle(a, n);
			Arrays.sort(a);
			return a;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public long[] nextLongArray1(int n) throws IOException {
			long[] a = new long[n + 1];
			for (int i = 1; i <= n; i++)
				a[i] = nextLong();
			return a;
		}

		public long[] nextLongArraySorted(int n) throws IOException {
			long[] a = nextLongArray(n);
			Random r = new Random();
			for (int i = 0; i < n; i++) {
				int j = i + r.nextInt(n - i);
				long t = a[i];
				a[i] = a[j];
				a[j] = t;
			}
			Arrays.sort(a);
			return a;
		}
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class D {
	public static void main(String[] args)throws Throwable {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);

		int n=sc.nextInt(),q=sc.nextInt();
		int [] a=new int [n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		int [] b=new int [n-1];
		for(int i=1;i<n;i++)
			b[i-1]=Math.abs(a[i]-a[i-1]);
		n--;
		int [] before=new int [n];
		int [] after=new int [n];
		Arrays.fill(before, -1);
		Arrays.fill(after, n);
		Stack<Integer> stack=new Stack<Integer>();
		for(int i=0;i<n;i++){
			while(!stack.isEmpty() && b[stack.peek()]<=b[i])
				stack.pop();
			if(!stack.isEmpty())
				before[i]=stack.peek();
			stack.push(i);
		}
		stack.clear();
		for(int i=n-1;i>=0;i--){
			while(!stack.isEmpty() && b[stack.peek()]<b[i])
				stack.pop();
			if(!stack.isEmpty())
				after[i]=stack.peek();
			stack.push(i);
		}
		while(q-->0){
			int l=sc.nextInt()-1;
			int r=sc.nextInt()-2;
			long ans=0;
			for(int i=l;i<=r;i++){
				int pre=before[i];
				int post=after[i];
				pre=Math.max(pre+1, l);
				post=Math.min(post-1, r);
				ans+=b[i]*(i-pre+1)*(post-i+1);
			}
			pw.println(ans);
		}

		pw.flush();
		pw.close();
	}

	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {while (st == null || !st.hasMoreElements()) {
			try {st = new StringTokenizer(br.readLine());}
			catch (IOException e) {e.printStackTrace();}}
		return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class D {
	public static void main(String[] args)throws Throwable {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);

		int n=sc.nextInt(),q=sc.nextInt();
		int [] a=new int [n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		int [] b=new int [n-1];
		for(int i=1;i<n;i++)
			b[i-1]=Math.abs(a[i]-a[i-1]);
		n--;
		int [] before=new int [n];
		int [] after=new int [n];
		Arrays.fill(before, -1);
		Arrays.fill(after, n);
		Stack<Integer> stack=new Stack<Integer>();
		for(int i=0;i<n;i++){
			while(!stack.isEmpty() && b[stack.peek()]<=b[i])
				stack.pop();
			if(!stack.isEmpty())
				before[i]=stack.peek();
			stack.push(i);
		}
		stack.clear();
		for(int i=n-1;i>=0;i--){
			while(!stack.isEmpty() && b[stack.peek()]<b[i])
				stack.pop();
			if(!stack.isEmpty())
				after[i]=stack.peek();
			stack.push(i);
		}
		while(q-->0){
			int l=sc.nextInt()-1;
			int r=sc.nextInt()-2;
			long ans=0;
			for(int i=l;i<=r;i++){
				int pre=before[i];
				int post=after[i];
				pre=Math.max(pre+1, l);
				post=Math.min(post-1, r);
				ans+=1L*b[i]*(i-pre+1)*(post-i+1);
			}
			pw.println(ans);
		}

		pw.flush();
		pw.close();
	}

	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {while (st == null || !st.hasMoreElements()) {
			try {st = new StringTokenizer(br.readLine());}
			catch (IOException e) {e.printStackTrace();}}
		return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Vector;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Stack;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemBLipshitzSequence solver = new ProblemBLipshitzSequence();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemBLipshitzSequence {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int q = in.readInt();
            long[] a = in.readLongArray(n);
            long[] d = new long[n - 1];
            for (int i = 0; i < n - 1; i++) {
                d[i] = Math.abs(a[i + 1] - a[i]);
            }
            int[] f = new int[n - 1];
            int[] b = new int[n - 1];
            Arrays.fill(f, n - 1);
            Arrays.fill(b, -1);
            Stack<Integer> stack = new Stack<>();
            for (int i = 0; i < n - 1; i++) {
                while (!stack.isEmpty() && d[stack.peek()] < d[i]) {
                    f[stack.pop()] = i;
                }
                stack.push(i);
            }
            stack = new Stack<>();
            for (int i = n - 2; i >= 0; i--) {
                while (!stack.isEmpty() && d[stack.peek()] <= d[i]) {
                    b[stack.pop()] = i;
                }
                stack.push(i);
            }
            while (q-- > 0) {
                int l = in.readInt() - 1;
                int r = in.readInt() - 2;
                BigInteger ans = BigInteger.ZERO;
                for (int i = l; i <= r; i++) {
                    long t1 = Math.min(r + 1, f[i]);
                    long t2 = Math.max(l - 1, b[i]);
                    ans = ans.add(BigInteger.valueOf((t1 - i) * (i - t2)).multiply(BigInteger.valueOf(d[i])));
                }
                out.println(ans);
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long[] readLongArray(int size) {
            long[] ans = new long[size];
            for (int i = 0; i < size; i++) ans[i] = readLong();
            return ans;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Vector;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Stack;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemBLipshitzSequence solver = new ProblemBLipshitzSequence();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemBLipshitzSequence {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int q = in.readInt();
            long[] a = in.readLongArray(n);
            long[] d = new long[n - 1];
            for (int i = 0; i < n - 1; i++) {
                d[i] = Math.abs(a[i + 1] - a[i]);
            }
            int[] f = new int[n - 1];
            int[] b = new int[n - 1];
            Arrays.fill(f, n - 1);
            Arrays.fill(b, -1);
            Stack<Integer> stack = new Stack<>();
            for (int i = 0; i < n - 1; i++) {
                while (!stack.isEmpty() && d[stack.peek()] < d[i]) {
                    f[stack.pop()] = i;
                }
                stack.push(i);
            }
            stack = new Stack<>();
            for (int i = n - 2; i >= 0; i--) {
                while (!stack.isEmpty() && d[stack.peek()] <= d[i]) {
                    b[stack.pop()] = i;
                }
                stack.push(i);
            }
            while (q-- > 0) {
                int l = in.readInt() - 1;
                int r = in.readInt() - 2;
                BigInteger ans = BigInteger.ZERO;
                for (int i = l; i <= r; i++) {
                    int t1 = Math.min(r + 1, f[i]);
                    int t2 = Math.max(l - 1, b[i]);
                    ans = ans.add(BigInteger.valueOf((t1 - i) * (i - t2)).multiply(BigInteger.valueOf(d[i])));
                }
                out.println(ans);
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long[] readLongArray(int size) {
            long[] ans = new long[size];
            for (int i = 0; i < size; i++) ans[i] = readLong();
            return ans;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}