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;
int read() {
  char c = getchar();
  int x = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
  return x;
}
const int N = 2e5 + 10;
int a[N], pos[N];
const int inf = 0x3f3f3f3f;
bool Fuck = 0;
namespace Seg1 {
const int M = (N << 1);
int mx[M], cmx[M], add[M], tag[M], lc[M], rc[M], se[M], siz[M], rt1, cnt;
long long sum[M];
void pushup(int p) {
  siz[p] = siz[lc[p]] + siz[rc[p]];
  sum[p] = sum[lc[p]] + sum[rc[p]];
  if (mx[lc[p]] > mx[rc[p]]) {
    cmx[p] = cmx[lc[p]];
    mx[p] = mx[lc[p]];
    se[p] = max(mx[rc[p]], se[lc[p]]);
  } else if (mx[rc[p]] > mx[lc[p]]) {
    cmx[p] = cmx[rc[p]];
    mx[p] = mx[rc[p]];
    se[p] = max(mx[lc[p]], se[rc[p]]);
  } else {
    cmx[p] = cmx[rc[p]] + cmx[lc[p]];
    mx[p] = mx[lc[p]];
    se[p] = max(se[lc[p]], se[rc[p]]);
  }
}
void pushadd(int p, long long v) {
  add[p] += v;
  se[p] += v;
  sum[p] += 1ll * siz[p] * v, mx[p] += v;
}
void pushAdd(int p, long long v) {
  sum[p] += 1ll * cmx[p] * v;
  mx[p] += v;
  tag[p] += v;
}
void pushdown(int p) {
  if (tag[p]) {
    int Mx = max(mx[lc[p]], mx[rc[p]]);
    if (lc[p] && mx[lc[p]] == Mx) {
      assert(cmx[lc[p]] != 0);
      pushAdd(lc[p], tag[p]);
    }
    if (rc[p] && mx[rc[p]] == Mx) {
      assert(cmx[rc[p]] != 0);
      pushAdd(rc[p], tag[p]);
    }
    tag[p] = 0;
  }
  if (add[p]) {
    if (lc[p]) pushadd(lc[p], add[p]);
    if (rc[p]) pushadd(rc[p], add[p]);
    add[p] = 0;
  }
}
void ins(int &p, int l, int r, int nxt, int pos) {
  if (!p) p = ++cnt;
  pushdown(p);
  tag[p] = 0;
  se[p] = -inf;
  add[p] = 0;
  if (l == r) {
    mx[p] = nxt;
    sum[p] = nxt;
    siz[p] = 1;
    cmx[p] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    ins(lc[p], l, mid, nxt, pos);
  else
    ins(rc[p], mid + 1, r, nxt, pos);
  pushup(p);
}
void modify_min(int p, int l, int r, int a, int b, int v) {
  if (mx[p] <= v || !p || a > b) return;
  if (a <= l && b >= r && se[p] < v) {
    pushAdd(p, v - mx[p]);
    return;
  }
  pushdown(p);
  int mid = (l + r) >> 1;
  if (a <= mid) modify_min(lc[p], l, mid, a, b, v);
  if (b > mid) modify_min(rc[p], mid + 1, r, a, b, v);
  pushup(p);
}
void modify_add(int p, int l, int r, int a, int b, int v) {
  if (!p || a > b) return;
  if (a <= l && b >= r) {
    pushadd(p, v);
    return;
  }
  pushdown(p);
  int mid = (l + r) >> 1;
  if (a <= mid) modify_add(lc[p], l, mid, a, b, v);
  if (b > mid) modify_add(rc[p], mid + 1, r, a, b, v);
  pushup(p);
}
long long ask(int p, int l, int r, int a, int b) {
  if (!p || a > b) return 0;
  if (a <= l && b >= r) return sum[p];
  pushdown(p);
  int mid = (l + r) >> 1;
  long long ans = 0;
  if (a <= mid) ans += ask(lc[p], l, mid, a, b);
  if (b > mid) ans += ask(rc[p], mid + 1, r, a, b);
  return ans;
}
}  // namespace Seg1
namespace Seg2 {
const int M = (N << 1);
int mn[M], cmn[M], add[M], tag[M], lc[M], rc[M], se[M], siz[M], rt2, cnt;
long long sum[M];
void pushup(int p) {
  siz[p] = siz[lc[p]] + siz[rc[p]];
  sum[p] = sum[lc[p]] + sum[rc[p]];
  if (mn[lc[p]] < mn[rc[p]]) {
    cmn[p] = cmn[lc[p]];
    mn[p] = mn[lc[p]];
    se[p] = min(mn[rc[p]], se[lc[p]]);
  } else if (mn[rc[p]] < mn[lc[p]]) {
    cmn[p] = cmn[rc[p]];
    mn[p] = mn[rc[p]];
    se[p] = min(mn[lc[p]], se[rc[p]]);
  } else {
    cmn[p] = cmn[rc[p]] + cmn[lc[p]];
    mn[p] = mn[lc[p]];
    se[p] = min(se[lc[p]], se[rc[p]]);
  }
}
void pushadd(int p, long long v) {
  add[p] += v;
  se[p] += v;
  sum[p] += 1ll * siz[p] * v;
  mn[p] += v;
}
void pushAdd(int p, long long v) {
  sum[p] += 1ll * cmn[p] * v;
  mn[p] += v;
  tag[p] += v;
}
void pushdown(int p) {
  if (add[p]) {
    if (lc[p]) pushadd(lc[p], add[p]);
    if (rc[p]) pushadd(rc[p], add[p]);
    add[p] = 0;
  }
  if (tag[p]) {
    int Mn = min(mn[lc[p]], mn[rc[p]]);
    if (lc[p] && mn[lc[p]] == Mn) pushAdd(lc[p], tag[p]);
    if (rc[p] && mn[rc[p]] == Mn) pushAdd(rc[p], tag[p]);
    tag[p] = 0;
  }
}
void ins(int &p, int l, int r, int pre, int pos) {
  if (!p) p = ++cnt;
  pushdown(p);
  tag[p] = 0;
  se[p] = inf;
  if (l == r) {
    mn[p] = pre;
    cmn[p] = 1;
    siz[p] = 1;
    sum[p] = pre;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    ins(lc[p], l, mid, pre, pos);
  else
    ins(rc[p], mid + 1, r, pre, pos);
  pushup(p);
}
void modify_max(int p, int l, int r, int a, int b, int v) {
  if (mn[p] >= v || !p || a > b) return;
  if (a <= l && b >= r && se[p] > v) {
    pushAdd(p, v - mn[p]);
    return;
  }
  pushdown(p);
  int mid = (l + r) >> 1;
  if (a <= mid) modify_max(lc[p], l, mid, a, b, v);
  if (b > mid) modify_max(rc[p], mid + 1, r, a, b, v);
  pushup(p);
}
void modify_add(int p, int l, int r, int a, int b, int v) {
  if (!p || a > b) return;
  if (a <= l && b >= r) {
    pushadd(p, v);
    return;
  }
  pushdown(p);
  int mid = (l + r) >> 1;
  if (a <= mid) modify_add(lc[p], l, mid, a, b, v);
  if (b > mid) modify_add(rc[p], mid + 1, r, a, b, v);
  pushup(p);
}
long long ask(int p, int l, int r, int a, int b) {
  if (!p || a > b) return 0;
  if (a <= l && b >= r) return sum[p];
  pushdown(p);
  int mid = (l + r) >> 1;
  long long ans = 0;
  if (a <= mid) ans += ask(lc[p], l, mid, a, b);
  if (b > mid) ans += ask(rc[p], mid + 1, r, a, b);
  return ans;
}
}  // namespace Seg2
using Seg1::rt1;
using Seg2::rt2;
int BIT[N], n;
void add(int x, int y) {
  for (; x <= n; x += (x & (-x))) BIT[x] += y;
}
int ask(int x) {
  int ans = 0;
  for (; x; x -= (x & (-x))) ans += BIT[x];
  return ans;
}
void calc(int n) {
  long long ans = Seg1::sum[rt1] - Seg2::sum[rt2] - n;
  printf("%lld\n", ans);
}
int main() {
  n = read();
  Seg2::mn[0] = inf;
  Seg2::se[0] = inf;
  Seg2::tag[0] = inf;
  for (int i = 1; i <= n; ++i) a[i] = read(), pos[a[i]] = i;
  for (int i = 1; i <= n; ++i) {
    int p = pos[i];
    add(p, 1);
    int rk = ask(p);
    Seg1::ins(rt1, 1, n, i + 1, p);
    Seg2::ins(rt2, 1, n, 0, p);
    Seg1::modify_add(rt1, 1, n, p + 1, n, 1);
    Seg1::modify_min(rt1, 1, n, 1, p - 1, rk);
    Seg2::modify_add(rt2, 1, n, p + 1, n, 1);
    Seg2::modify_max(rt2, 1, n, p + 1, n, rk);
    calc(i);
  }
  return 0;
}
