import Data.List

main = do
    line<-getLine
    line<-getLine
    let a = [read x::Int|x<-words line]
    let aL = [x+y|(x,y)<-zip a [1..]]
    let aR = sort [y-x|(x,y)<-zip a [1..]]
    print $ sum_aR aR aL 0 0

sum_aR :: [Int] -> [Int] ->Int -> Int ->Int
sum_aR aR aL n s
    | n == length aL = s
    | otherwise = sum_aR aR aL (n+1) (s+(upper_bound aR (aL!!n)) - (lower_bound aR (aL!!n)))

lower_bound :: [Int]->Int->Int
lower_bound a t = __lower_bound__ a 0 (length a) t

__lower_bound__ :: [Int]->Int->Int->Int->Int
__lower_bound__ a first 0  _= first
__lower_bound__ a first len target = do
    let half = div len 2
    let middle = first + half
    if a!!middle < target 
        then __lower_bound__ a (middle+1) (len-half-1) target 
        else __lower_bound__ a first half target

upper_bound :: [Int]->Int->Int
upper_bound a t = __upper_bound__ a 0 (length a) t

__upper_bound__ :: [Int]->Int->Int->Int->Int
__upper_bound__ a first 0 _ = first
__upper_bound__ a first len target = do
    let half = div len 2
    let middle = first + half 
    if a!!middle > target
        then __upper_bound__ a first half target
        else __upper_bound__ a (middle+1) (len-half-1) target


