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>
int n, a[150001];
long long cnt[150001];
namespace Isonan {
int a[150001], pos[150001];
struct point {
  int mx, skdmx, cmx;
  long long sma, smx;
} se[1600001];
point merge(point a, point b) {
  if (a.mx == b.mx)
    return (point){a.mx, std::max(a.skdmx, b.skdmx), a.cmx + b.cmx,
                   a.sma + b.sma, a.smx + b.smx};
  else if (a.mx < b.mx)
    std::swap(a, b);
  return (point){a.mx, std::max(a.skdmx, b.mx), a.cmx, a.sma, a.smx};
}
int lazy[1600001], add[1600001], val[1600001];
void pushdown(int x, int y) {
  lazy[x] = std::min(lazy[x], y);
  se[x].mx = std::min(se[x].mx, y);
}
void addit(int x, int y) {
  se[x].smx += 1ll * se[x].cmx * y;
  add[x] += y;
}
void spread(int x) {
  if (lazy[x] < 0x7f7f7f7f) {
    pushdown(x << 1, lazy[x]);
    pushdown(x << 1 | 1, lazy[x]);
    lazy[x] = 0x7f7f7f7f;
  }
  if (add[x]) {
    addit(x << 1, add[x]);
    addit(x << 1 | 1, add[x]);
    add[x] = 0;
  }
}
void pushup(int root) {
  se[root] = merge(se[root << 1], se[root << 1 | 1]);
  val[root] = val[root << 1] + val[root << 1 | 1];
}
long long cnt0, cnt1, cnt2, calc;
int c[150001];
void upd(int ind) {
  for (; ind; ind -= ind & -ind) ++c[ind];
}
int query(int ind) {
  if (ind > n) return 0;
  int tot = 0;
  for (; ind <= n; ind += ind & -ind) tot += c[ind];
  return tot;
}
void update(int root, int l, int r, int e) {
  spread(root);
  if (l > e) {
    calc += val[root];
    return;
  }
  if (e >= r) {
    if (se[root].mx <= e) {
      addit(root, 1);
      return;
    } else if (se[root].skdmx <= e) {
      cnt0 += se[root].cmx, cnt1 += se[root].smx,
          cnt2 += se[root].smx - 1ll * (query(se[root].mx)) * se[root].cmx;
      pushdown(root, e);
      addit(root, 1);
      return;
    }
  }
  update(root << 1, l, (l + r) >> 1, e),
      update(root << 1 | 1, ((l + r) >> 1) + 1, r, e);
  pushup(root);
}
void change(int root, int l, int r, int e, int add) {
  spread(root);
  if (l == r) {
    val[root] = 1;
    se[root] = (point){0x7f7f7f7f, 0, 1, add, add};
    return;
  }
  if ((l + r) >> 1 >= e)
    change(root << 1, l, (l + r) >> 1, e, add);
  else
    change(root << 1 | 1, ((l + r) >> 1) + 1, r, e, add);
  pushup(root);
}
void build(int root, int l, int r) {
  val[root] = add[root] = 0;
  lazy[root] = 0x7f7f7f7f;
  se[root] = (point){0x7f7f7f7f, 0, 0, 0, 0};
  if (l == r) return;
  build(root << 1, l, (l + r) >> 1);
  build(root << 1 | 1, ((l + r) >> 1) + 1, r);
}
void solve() {
  build(1, 1, n);
  for (int i = 1; i <= n; i++) pos[a[i]] = i, c[i] = 0;
  for (int i = 1; i <= n; i++) {
    calc = cnt0 = cnt1 = cnt2 = 0;
    update(1, 1, n, pos[i]);
    cnt[i] += cnt2 + 1ll * cnt0 * calc - cnt1;
    change(1, 1, n, pos[i], calc);
    upd(pos[i]);
  }
}
}  // namespace Isonan
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) Isonan::a[i] = a[i];
  Isonan::solve();
  for (int i = 1; i <= n; i++) Isonan::a[n - i + 1] = a[i];
  Isonan::solve();
  for (int i = 1; i <= n; i++) {
    cnt[i] += cnt[i - 1];
    printf("%lld\n", ((1ll * i * (i + 1)) >> 1ll) - cnt[i]);
  }
}
