The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of $n$ vertices. Each vertex $i$ has its own value $a_i$. All vertices are connected in series by edges. Formally, for every $1 \leq i < n$ there is an edge between the vertices of $i$ and $i+1$.

Denote the function $f(l, r)$, which takes two integers $l$ and $r$ ($l \leq r$):

    We leave in the tree only vertices whose values ​​range from $l$ to $r$.    The value of the function will be the number of connected components in the new graph. 

Your task is to calculate the following sum: $$\sum_{l=1}^{n} \sum_{r=l}^{n} f(l, r) $$


-----Input-----

The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of vertices in the tree.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n$) — the values of the vertices.


-----Output-----

Print one number — the answer to the problem.


-----Examples-----
Input
3
2 1 3

Output
7
Input
4
2 1 1 3

Output
11
Input
10
1 5 2 5 5 3 10 6 5 1

Output
104


-----Note-----

In the first example, the function values ​​will be as follows:   $f(1, 1)=1$ (there is only a vertex with the number $2$, which forms one component)  $f(1, 2)=1$ (there are vertices $1$ and $2$ that form one component)  $f(1, 3)=1$ (all vertices remain, one component is obtained)  $f(2, 2)=1$ (only vertex number $1$)  $f(2, 3)=2$ (there are vertices $1$ and $3$ that form two components)  $f(3, 3)=1$ (only vertex $3$)  Totally out $7$.

In the second example, the function values ​​will be as follows:   $f(1, 1)=1$  $f(1, 2)=1$  $f(1, 3)=1$  $f(1, 4)=1$  $f(2, 2)=1$  $f(2, 3)=2$  $f(2, 4)=2$  $f(3, 3)=1$  $f(3, 4)=1$  $f(4, 4)=0$ (there is no vertex left, so the number of components is $0$)  Totally out $11$.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
v = [0] + [int(e) for e in input().split()]
ans = 0
for a, b in zip(v[:-1], v[1:]):
    if a < b:
        ans += (b-a)*(n-b+1)
    else:
        ans += b*(a-b)
print(ans)


N = int(input())
A = [int(a) for a in input().split()]

def calc(a0, b0):
    a, b = min(a0, b0), max(a0, b0)
    return b-1 + (a-1) * (b-a-1) + N-a + (b-a-1) * (N-b)

def calc0(a):
    return N+(a-1)*(N-a)

s = calc0(A[0]) + calc0(A[-1])
for i in range(N-1):
    s += calc(A[i], A[i+1])

print(s//2)


import sys
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))

s = a[0] * (n - a[0] + 1)
for i in range (1, n):
    if a[i - 1] < a[i]:
        s = s + (a[i] - a[i-1]) * (n - a[i] + 1)
    if a[i - 1] > a[i]:
        s = s + a[i] * (a[i-1] - a[i])

print(s)



n = int(input()) + 1
res = 0
a = tuple(map(int, input().split()))
for ai in a:
    res += ai * (n - ai)
for ai, aj in map(sorted, list(zip(a, a[1:]))):
    res -= ai * (n - aj)
print(res)


n=int(input())
d=list(map(int,input().split()))
a=[0]
a.extend(d)
an=0
for i in range(n+1):
    if a[i]>a[i-1]:
        an+=(a[i]-a[i-1])*(n-a[i]+1)
    if a[i]<a[i-1]:
        an+=(a[i])*(a[i-1]-a[i])
##    print(an)
print(an)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

b = []
for x in a:
    if not b or b[-1] != x:
        b.append(x)
p = defaultdict(list)
for i in range(len(b)):
    p[b[i]].append(i)

ans = cur = 0
for r in range(1, n + 1):
    for i in p[r]:
        cur += r
        if len(b) == 1:
            pass
        elif i == 0:
            if b[i + 1] < b[i]:
                cur -= b[i + 1]
        elif i == len(b) - 1:
            if b[i - 1] < b[i]:
                cur -= b[i - 1]
        else:
            mx = max(b[i - 1], b[i + 1])
            mn = min(b[i - 1], b[i + 1])
            if mx < b[i]:
                cur -= mx + mn
            elif mn < b[i]:
                cur -= mn
    ans += cur
print(ans)

# AC
import sys


class Main:
    def __init__(self):
        self.buff = None
        self.index = 0

    def __next__(self):
        if self.buff is None or self.index == len(self.buff):
            self.buff = sys.stdin.readline().split()
            self.index = 0
        val = self.buff[self.index]
        self.index += 1
        return val

    def next_int(self):
        return int(next(self))

    def solve(self):
        n = self.next_int()
        x = [self.next_int() for _ in range(0, n)]
        ans = 0
        for i in range(0, n):
            ans += x[i] * (n - x[i] + 1)
            if i > 0:
                ans -= min(x[i], x[i - 1]) * (n - max(x[i], x[i - 1]) + 1)
        print(ans)


def __starting_point():
    Main().solve()

__starting_point()

n = int(input())
a = list(map(int,input().split()))
ans = a[0] * (n-a[0]+1)
for i in range(1, n):
    if a[i-1] == a[i]: continue
    elif a[i-1] < a[i]: ans+= (a[i]-a[i-1]) * (n-a[i]+1)
    elif a[i-1] > a[i]: ans+= a[i] * (a[i-1]-a[i])
print(ans)

n=int(input())
t=input().split()
t[0]=int(t[0])
s=t[0]*(n-t[0]+1)
for i in range(1,n):
 t[i]=int(t[i])
 if t[i]>t[i-1]:s=s+(t[i]-t[i-1])*(n-t[i]+1)
 else:s=s+t[i]*(t[i-1]-t[i])
print(s)

import sys
input = sys.stdin.readline

n=int(input())
A=[0]+list(map(int,input().split()))

ANS=0
for i in range(1,n+1):
    if A[i]>A[i-1]:
        ANS+=(n-A[i]+1)*(A[i]-A[i-1])
    else:
        ANS+=A[i]*(A[i-1]-A[i])

print(ANS)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.insert(0, 0)

    total = 0
    for i in range(1, n + 1):
        if a[i - 1] > a[i]:
            total += a[i] * (a[i - 1] - a[i])
        elif a[i - 1] < a[i]:
            total += (a[i] - a[i - 1]) * (n - a[i] + 1)

    print(total)


def __starting_point():
    main()

__starting_point()

n = int(input())
a = list(map(int,input().split()))
ans = n*n*(n+1)//2
rd = 0
for i in range(n-1):
    l = min(a[i],a[i+1])
    r = max(a[i],a[i+1])
    rd += l*(n-r+1)
for i in range(n):
    rd += max((a[i]-2)*(a[i]-1)//2,0)
    rd += n-1
    rd += (n-a[i])*(n-a[i]-1)//2
ans -= rd
print(ans)


def in_int():
    return int(input())
def in_list():
    return [int(x) for x in input().split()]
n=in_int()
ns=in_list()

ans=0
for i in range(n-1):
    # a=min(ns[i],ns[i+1])
    # b=max(ns[i],ns[i+1])
    a,b=ns[i],ns[i+1]
    if a>b:
        ans+=(a-b)*(n-a+1)
    else:
        ans+=a*(b-a)
    # print(ans)
    # ans+=a*(b-a)
    # ans+=(n-b+1)*(b-a)
    # print(ans)
a=ns[-1]
ans+=a*(n-a+1)
# print(ans)
# ans+=n*(n+1)//2
print(ans)

# 2 1 3
# 1 2 3 4 5 6 7
# 3 5


# 計算該點 左邊不包但包自己的區間數
n = int(input())
nums = list(map(int,input().split()))

# count the first one
ans = nums[0] * (n - nums[0] + 1)

for i in range(1,n):
    if nums[i] > nums[i-1]:
        ans += (nums[i] - nums[i-1]) * (n - nums[i] + 1)
    elif nums[i] < nums[i-1]:
        ans += (nums[i-1] - nums[i]) * nums[i]
print(ans)


#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Codeforces Round #553 (Div. 2)

Problem E. Number of Components

:author:         Kitchen Tong
:mail:    kctong529@gmail.com

Please feel free to contact me if you have any question
regarding the implementation below.
"""

__version__ = '1.0'
__date__ = '2019-04-20'

import sys


def count_contribution(n, ax, ay):
    if ay > ax:
        return (ay - ax) * (n - ay + 1)
    elif ay < ax:
        return ay * (ax - ay)
    else:
        return 0

def solve(n, a):
    result = a[0] * (n - a[0] + 1)
    for i in range(1, len(a)):
        result += count_contribution(n, a[i-1], a[i])
    return result


def main(argv=None):
    n = int(input())
    a = list(map(int, input().split()))
    print(solve(n, a))
    return 0


def __starting_point():
    STATUS = main()
    return(STATUS)


__starting_point()



n = int(input())
arr = list(map(int,input().split()))

ans = 0
ans += arr[0]*(n-arr[0]+1)
for i in range(1,n):
    if(arr[i-1] < arr[i]):
        ans += (arr[i] - arr[i-1])*(n - arr[i] +1)

    if(arr[i-1] > arr[i]):
        ans += arr[i]*( arr[i-1] - arr[i])

print(ans)

    


n = int(input())
a = [int(x) for x in input().split()]

ans = a[0] * (n - a[0] + 1)
for i in range(1, n):
  if a[i] > a[i - 1]:
    ans += (a[i] - a[i - 1]) * (n - a[i] + 1)
  elif a[i] < a[i - 1]:
    ans += a[i] * (a[i - 1] - a[i])
print(ans)

n = int(input())
a = [int(x) for x in input().split()]
s = 0
s = a[0] * (n - a[0] + 1)
for i in range(len(a)-1):
   if a[i] < a[i+1]:
      s += (a[i+1]-a[i])*(n-a[i+1]+1)
   elif a[i] > a[i+1]:
      s += (a[i]-a[i+1])*a[i+1]
print(s)


n = int(input())
a = [0]
b = [int(i) for i in input().split()]
a+=b
ans = 0
for i in range(1,n+1):
	if(a[i-1]<a[i]):
		ans+=(a[i]-a[i-1])*(n-a[i]+1)
	else:
		ans+=a[i]*(a[i-1]-a[i])
print(ans)


n = int(input())
a = [0] + list(map(int, input().split()))

ans = 0

for i, j in zip(a[:-1], a[1:]):
    if i < j:
        ans += (j - i) * (n - j + 1)
    else:
        ans += j * (i - j)
print(ans)


n = int(input()) + 1
res = 0
a = tuple(map(int, input().split()))
for ai in a:
    res += ai * (n - ai)
for ai, aj in map(sorted, zip(a, a[1:])):
    res -= ai * (n - aj)
print(res)

n = int(input()) + 1
res = 0
a = tuple(map(int, input().split()))
for ai in a:
    res += ai * (n - ai)
for ai, aj in map(sorted, list(zip(a, a[1:]))):
    res -= ai * (n - aj)
print(res)
###


n = int(input()) + 1
res = 0
a = tuple(map(int, input().split()))
for ai in a:
    res += ai * (n - ai)
for ai, aj in map(sorted, list(zip(a, a[1:]))):
    res -= ai * (n - aj)
print(res)
#


n = int(input()) + 1
res = 0
a = tuple(map(int, input().split()))
for ai in a:
    res += ai * (n - ai)
for ai, aj in map(sorted, list(zip(a, a[1:]))):
    res -= ai * (n - aj)
print(res)
##