Let's denote a function 

<image>

You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.

Input

The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array. 

Output

Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.

Examples

Input

5
1 2 3 1 3


Output

4


Input

4
6 6 5 5


Output

0


Input

4
6 6 4 4


Output

-8

Note

In the first example:

  1. d(a1, a2) = 0; 
  2. d(a1, a3) = 2; 
  3. d(a1, a4) = 0; 
  4. d(a1, a5) = 2; 
  5. d(a2, a3) = 0; 
  6. d(a2, a4) = 0; 
  7. d(a2, a5) = 0; 
  8. d(a3, a4) = - 2; 
  9. d(a3, a5) = 0; 
  10. d(a4, a5) = 2. 
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.BufferedReader;
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);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = 1;
            HashSet<Integer> exists = new HashSet<>();
            int[] arr = new int[n + 1], sortedArr = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                arr[i] = in.nextInt();
                if (exists.add(arr[i])) {
                    sortedArr[m++] = arr[i];
                }
            }
            m--;
            Arrays.sort(sortedArr, 1, m + 1);
            SegmentTree sumQuery = SegmentTree.RSumQ(m, new long[m + 1]);
            SegmentTree occQuery = SegmentTree.RSumQ(m, new long[m + 1]);
            BigInteger answer = BigInteger.ZERO;
            for (int i = 1; i <= n; i++) {
                int j = Arrays.binarySearch(sortedArr, 1, m + 1, arr[i]);
                answer = answer.add(new BigInteger(String.valueOf(occQuery.rangeQuery(j, j) * arr[i] - sumQuery.rangeQuery(j, j))));

                int i1, i2;

                if (j > 1) i1 = sortedArr[j - 1] == arr[i] - 1 ? j - 2 : j - 1;
                else i1 = -1;

                if (j < m) i2 = sortedArr[j + 1] == arr[i] + 1 ? j + 2 : j + 1;
                else i2 = m + 1;

                if (i1 != -1) {
                    occQuery.rangeUpdate(1, i1, 1);
                    sumQuery.rangeUpdate(1, i1, arr[i]);
                }

                if (i2 != m + 1) {
                    occQuery.rangeUpdate(i2, m, 1);
                    sumQuery.rangeUpdate(i2, m, arr[i]);
                }
            }
            out.println(answer);
        }

    }

    static class InputReader {
        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

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

    }

    static abstract class SegmentTree {
        public int n;
        public long[] arr;
        public long[] tree;
        public long[] lazy;

        public SegmentTree(int n, int[] arr) {
            this.n = n;
            this.arr = new long[n + 1];
            tree = new long[4 * n + 1];
            lazy = new long[4 * n + 1];
            for (int i = 1; i <= n; i++) {
                this.arr[i] = arr[i];
            }
            build(1, 1, n);
        }

        public SegmentTree(int n, long[] arr) {
            this.n = n;
            this.arr = new long[n + 1];
            tree = new long[4 * n + 1];
            lazy = new long[4 * n + 1];
            for (int i = 1; i <= n; i++) {
                this.arr[i] = arr[i];
            }
            build(1, 1, n);
        }

        public int left(int node) {
            return node << 1;
        }

        public int right(int node) {
            return left(node) + 1;
        }

        public int middle(int l, int r) {
            return (l + r) >> 1;
        }

        public abstract long combine(long a, long b);

        public abstract void update(int node, int l, int r, long value);

        public abstract void propagate(int node, int l, int r, long value);

        public abstract long getNeutralElement();

        public void doLazy(int node, int l, int r) {
            if (lazy[node] != 0) {
                update(node, l, r, lazy[node]);
                if (l != r) {
                    propagate(node, l, r, lazy[node]);
                }
                lazy[node] = 0;
            }
        }

        public void build(int node, int l, int r) {
            if (l == r) {
                tree[node] = arr[l];
            } else {
                int m = middle(l, r);
                build(left(node), l, m);
                build(right(node), m + 1, r);
                tree[node] = combine(tree[left(node)], tree[right(node)]);
            }
        }

        public long rangeQuery(int node, int l, int r, int s, int e) {
            if (r < s || l > e) return getNeutralElement();
            doLazy(node, l, r);
            if (s <= l && r <= e) return tree[node];
            int m = middle(l, r);
            return combine(rangeQuery(left(node), l, m, s, e), rangeQuery(right(node), m + 1, r, s, e));
        }

        public void rangeUpdate(int node, int l, int r, int s, int e, long v) {
            if (r < s || l > e) return;
            doLazy(node, l, r);
            if (s <= l && r <= e) {
                update(node, l, r, v);
                if (l != r) {
                    propagate(node, l, r, v);
                }
                return;
            }
            int m = middle(l, r);
            rangeUpdate(left(node), l, m, s, e, v);
            rangeUpdate(right(node), m + 1, r, s, e, v);
            tree[node] = combine(tree[left(node)], tree[right(node)]);
        }

        public long rangeQuery(int l, int r) {
            return rangeQuery(1, 1, n, l, r);
        }

        public void rangeUpdate(int l, int r, int v) {
            rangeUpdate(1, 1, n, l, r, v);
        }

        public static SegmentTree RSumQ(int n, long[] arr) {
            return new SegmentTree(n, arr) {

                public long combine(long a, long b) {
                    return a + b;
                }


                public void update(int node, int l, int r, long value) {
                    this.tree[node] += (r - l + 1) * value;
                }


                public void propagate(int node, int l, int r, long value) {
                    this.lazy[this.left(node)] += value;
                    this.lazy[this.right(node)] += value;
                }


                public long getNeutralElement() {
                    return 0;
                }
            };
        }

    }
}

