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>
template <typename T>
inline void chkmin(T &a, const T &b) {
  a = a < b ? a : b;
}
template <typename T>
inline void chkmax(T &a, const T &b) {
  a = a > b ? a : b;
}
using namespace std;
const int MAXN = 150005, MAXT = 300005;
int arr[MAXN], pla[MAXN], bit[MAXN], n;
void add(int x, int y) {
  for (++x; x <= n; x += x & -x) bit[x] += y;
}
int ask(int x) {
  int res = 0;
  for (++x; x; x -= x & -x) res += bit[x];
  return res;
}
struct Tree {
  Tree *ls, *rs;
  int mx, sx, cx, tx, tt;
  long long ax;
  Tree() { sx = -1e9, tx = 1e9, cx = 1; }
};
struct SegmentTreeBeats {
  Tree nd[MAXT], *rt;
  int tot;
  void pushup(Tree *k) {
    k->ax = k->ls->ax + k->rs->ax;
    if (k->ls->mx < k->rs->mx) {
      k->mx = k->rs->mx;
      k->cx = k->rs->cx;
      k->sx = max(k->ls->mx, k->rs->sx);
    } else if (k->ls->mx > k->rs->mx) {
      k->mx = k->ls->mx;
      k->cx = k->ls->cx;
      k->sx = max(k->rs->mx, k->ls->sx);
    } else {
      k->mx = k->ls->mx;
      k->cx = k->ls->cx + k->rs->cx;
      k->sx = max(k->ls->sx, k->rs->sx);
    }
  }
  void cover(Tree *k, int mx, int ad, int l, int r) {
    if (k->tx < 1e9) k->tx += ad;
    k->mx += ad;
    k->sx += ad;
    k->tt += ad;
    k->ax += (long long)ad * (r - l);
    chkmin(k->tx, mx);
    if (k->sx < k->tx && k->mx > k->tx) {
      k->ax -= (long long)(k->mx - k->tx) * k->cx;
      k->mx = k->tx;
    }
  }
  void pushdown(Tree *k, int l, int r) {
    int mid = (l + r) >> 1;
    cover(k->ls, k->tx, k->tt, l, mid);
    cover(k->rs, k->tx, k->tt, mid, r);
    k->tx = 1e9, k->tt = 0;
  }
  void modify(int a, int b, int x, int y, int l, int r, Tree *k) {
    bool flag = x == 1e9 && !y;
    if (k->mx <= k->tx && (flag || a >= r || b <= l)) return;
    if (a <= l && b >= r && !flag) {
      cover(k, x, y, l, r);
      if (k->mx <= k->tx) return;
      x = 1e9, y = 0;
    }
    int mid = (l + r) >> 1;
    pushdown(k, l, r);
    modify(a, b, x, y, l, mid, k->ls);
    modify(a, b, x, y, mid, r, k->rs);
    pushup(k);
  }
  void modify(int a, int b, int x, int y) { modify(a, b, x, y, 0, n, rt); }
  void build(Tree *&k, int l, int r) {
    k = nd + (tot++);
    if (l + 1 == r) return;
    int mid = (l + r) >> 1;
    build(k->ls, l, mid);
    build(k->rs, mid, r);
  }
  void build() { build(rt, 0, n); }
} sl, sr;
set<int> ss;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
    pla[--arr[i]] = i;
  }
  sl.build();
  sr.build();
  for (int i = 0; i < n; i++) {
    int p = pla[i], q = ask(p);
    auto it = ss.insert(p).first;
    if (q > 0) sr.modify(0, *(--it) + 1, q - 1, 0);
    if (p + 1 < n) {
      sr.modify(p + 1, n, 1e9, 1);
      sl.modify(p + 1, n, 1e9, -1);
      sl.modify(p + 1, n, -(q + 1), 0);
    }
    sr.modify(p, p + 1, 1e9, i - q);
    sl.modify(p, p + 1, 1e9, q);
    add(p, 1);
    printf("%lld\n", sr.rt->ax + sl.rt->ax + i + 1);
  }
  return 0;
}
