Ildar is the algorithm teacher of William and Harris. Today, Ildar is teaching Cartesian Tree. However, Harris is sick, so Ildar is only teaching William.

A cartesian tree is a rooted tree, that can be constructed from a sequence of distinct integers. We build the cartesian tree as follows:

  1. If the sequence is empty, return an empty tree;
  2. Let the position of the maximum element be x;
  3. Remove element on the position x from the sequence and break it into the left part and the right part (which might be empty) (not actually removing it, just taking it away temporarily);
  4. Build cartesian tree for each part;
  5. Create a new vertex for the element, that was on the position x which will serve as the root of the new tree. Then, for the root of the left part and right part, if exists, will become the children for this vertex;
  6. Return the tree we have gotten.



For example, this is the cartesian tree for the sequence 4, 2, 7, 3, 5, 6, 1:

<image>

After teaching what the cartesian tree is, Ildar has assigned homework. He starts with an empty sequence a.

In the i-th round, he inserts an element with value i somewhere in a. Then, he asks a question: what is the sum of the sizes of the subtrees for every node in the cartesian tree for the current sequence a?

Node v is in the node u subtree if and only if v = u or v is in the subtree of one of the vertex u children. The size of the subtree of node u is the number of nodes v such that v is in the subtree of u.

Ildar will do n rounds in total. The homework is the sequence of answers to the n questions.

The next day, Ildar told Harris that he has to complete the homework as well. Harris obtained the final state of the sequence a from William. However, he has no idea how to find the answers to the n questions. Help Harris!

Input

The first line contains a single integer n (1 ≤ n ≤ 150000).

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n). It is guarenteed that each integer from 1 to n appears in the sequence exactly once.

Output

Print n lines, i-th line should contain a single integer — the answer to the i-th question.

Examples

Input


5
2 4 1 5 3


Output


1
3
6
8
11


Input


6
1 2 4 5 6 3


Output


1
3
6
8
12
17

Note

After the first round, the sequence is 1. The tree is

<image>

The answer is 1.

After the second round, the sequence is 2, 1. The tree is

<image>

The answer is 2+1=3.

After the third round, the sequence is 2, 1, 3. The tree is

<image>

The answer is 2+1+3=6.

After the fourth round, the sequence is 2, 4, 1, 3. The tree is

<image>

The answer is 1+4+1+2=8.

After the fifth round, the sequence is 2, 4, 1, 5, 3. The tree is

<image>

The answer is 1+3+1+5+1=11.
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return f == -1 ? ~x + 1 : x;
}
const long long inf = 1e9 + 7;
long long n;
long long a[150010], pos[150010];
struct info {
  long long sum, mx, sec;
  long long cmx, cnt, tag, admx;
};
struct sgmb {
  info tre[600010];
  void pushup(long long p) {
    if (!tre[p << 1].cnt) tre[p << 1].mx = tre[p << 1].sec = -inf;
    if (!tre[p << 1 | 1].cnt) tre[p << 1 | 1].sec = tre[p << 1 | 1].mx = -inf;
    if (tre[p << 1].cmx == tre[p << 1].cnt) tre[p << 1].sec = -inf;
    if (tre[p << 1 | 1].cmx == tre[p << 1 | 1].cnt) tre[p << 1 | 1].sec = -inf;
    if (tre[p << 1].mx > tre[p << 1 | 1].mx) {
      tre[p].mx = tre[p << 1].mx, tre[p].cmx = tre[p << 1].cmx;
      tre[p].sec = max(tre[p << 1].sec, tre[p << 1 | 1].mx);
    } else if (tre[p << 1].mx < tre[p << 1 | 1].mx) {
      tre[p].mx = tre[p << 1 | 1].mx, tre[p].cmx = tre[p << 1 | 1].cmx;
      tre[p].sec = max(tre[p << 1 | 1].sec, tre[p << 1].mx);
    } else
      tre[p].mx = tre[p << 1].mx,
      tre[p].cmx = tre[p << 1].cmx + tre[p << 1 | 1].cmx,
      tre[p].sec = max(tre[p << 1].sec, tre[p << 1 | 1].sec);
    tre[p].cnt = tre[p << 1].cnt + tre[p << 1 | 1].cnt;
    tre[p].sum = tre[p << 1].sum + tre[p << 1 | 1].sum;
  }
  void pushdown(long long p, long long l, long long r) {
    if (tre[p].admx) {
      long long mx = max(tre[p << 1].cnt ? tre[p << 1].mx : -inf,
                         tre[p << 1 | 1].cnt ? tre[p << 1 | 1].mx : -inf);
      if (tre[p << 1].mx == mx)
        tre[p << 1].mx += tre[p].admx,
            tre[p << 1].sum += tre[p << 1].cmx * tre[p].admx,
            tre[p << 1].admx += tre[p].admx;
      if (tre[p << 1 | 1].mx == mx)
        tre[p << 1 | 1].mx += tre[p].admx,
            tre[p << 1 | 1].sum += tre[p << 1 | 1].cmx * tre[p].admx,
            tre[p << 1 | 1].admx += tre[p].admx;
      tre[p].admx = 0;
    }
    pushup(p);
    if (tre[p].tag) {
      tre[p << 1].tag += tre[p].tag;
      tre[p << 1 | 1].tag += tre[p].tag;
      tre[p << 1].mx += tre[p].tag, tre[p << 1 | 1].mx += tre[p].tag;
      tre[p << 1].sec += tre[p].tag, tre[p << 1 | 1].sec += tre[p].tag;
      tre[p << 1].sum += tre[p << 1].cnt * tre[p].tag,
          tre[p << 1 | 1].sum += tre[p << 1 | 1].cnt * tre[p].tag;
      tre[p].tag = 0;
    }
  }
  void update(long long p, long long l, long long r, long long pos,
              long long k) {
    if (l == r) {
      tre[p].mx = k, tre[p].sec = -inf, tre[p].cmx = 1, tre[p].cnt = 1,
      tre[p].sum = k;
      tre[p].tag = tre[p].admx = 0;
      return;
    }
    long long mid = l + r >> 1;
    pushdown(p, l, r);
    pushup(p);
    if (pos <= mid)
      update(p << 1, l, mid, pos, k);
    else
      update(p << 1 | 1, mid + 1, r, pos, k);
    pushup(p);
  }
  void build(long long p, long long l, long long r) {
    if (l == r) {
      tre[p].mx = tre[p].sec = -inf, tre[p].cnt = tre[p].cmx = 0;
      tre[p].sum = 0;
      return;
    }
    long long mid = l + r >> 1;
    build(p << 1, l, mid);
    build(p << 1 | 1, mid + 1, r);
    pushup(p);
  }
  void add(long long p, long long l, long long r, long long L, long long R,
           long long k) {
    if (L > R) return;
    if (!tre[p].cnt) return;
    if (l >= L && r <= R) {
      tre[p].mx += k, tre[p].sec += k;
      tre[p].tag += k;
      tre[p].sum += tre[p].cnt * k;
      return;
    }
    long long mid = l + r >> 1;
    pushdown(p, l, r);
    if (L <= mid) add(p << 1, l, mid, L, R, k);
    if (R > mid) add(p << 1 | 1, mid + 1, r, L, R, k);
    pushup(p);
  }
  void min(long long p, long long l, long long r, long long L, long long R,
           long long k) {
    if (L > R) return;
    if (tre[p].mx <= k || !tre[p].cnt) return;
    if (l >= L && r <= R) {
      if (tre[p].cnt == tre[p].cmx) {
        tre[p].admx -= tre[p].mx - k;
        tre[p].sum -= (tre[p].mx - k) * tre[p].cmx;
        tre[p].mx = k;
        return;
      } else if (tre[p].sec <= k) {
        tre[p].admx -= tre[p].mx - k;
        tre[p].sum -= (tre[p].mx - k) * tre[p].cmx;
        tre[p].mx = k;
        return;
      } else {
        pushdown(p, l, r);
        long long mid = l + r >> 1;
        min(p << 1, l, mid, L, R, k);
        min(p << 1 | 1, mid + 1, r, L, R, k);
        pushup(p);
        return;
      }
    }
    pushdown(p, l, r);
    pushup(p);
    long long mid = l + r >> 1;
    if (L <= mid) min(p << 1, l, mid, L, R, k);
    if (R > mid) min(p << 1 | 1, mid + 1, r, L, R, k);
    pushup(p);
  }
  long long qcnt(long long p, long long l, long long r, long long L,
                 long long R) {
    if (L > R) return 0;
    if (l >= L && r <= R) return tre[p].cnt;
    pushdown(p, l, r);
    long long mid = l + r >> 1;
    long long res = 0;
    if (L <= mid) res += qcnt(p << 1, l, mid, L, R);
    if (R > mid) res += qcnt(p << 1 | 1, mid + 1, r, L, R);
    return res;
  }
} T1, T2;
signed main() {
  n = read();
  for (long long i = 1; i <= n; ++i) a[i] = read(), pos[a[i]] = i;
  T1.build(1, 1, n);
  T2.build(1, 1, n);
  for (long long i = 1; i <= n; ++i) {
    long long p = T1.qcnt(1, 1, n, 1, pos[i]) + 1;
    T1.update(1, 1, n, pos[i], i + 1);
    T1.add(1, 1, n, pos[i] + 1, n, 1);
    T1.min(1, 1, n, 1, pos[i] - 1, p);
    T2.update(1, 1, n, pos[i], 0);
    T2.min(1, 1, n, pos[i] + 1, n, -p + 1);
    T2.add(1, 1, n, pos[i] + 1, n, -1);
    long long ans = T1.tre[1].sum + T2.tre[1].sum;
    printf("%lld\n", ans - i);
  }
}
