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;
const int N = 2e5 + 10;
int n, a[N], b[N];
int sz[N * 4], mx[N * 4], tg[N * 4], se[N * 4], ct[N * 4];
long long su[N * 4], ans[N];
inline void cl() {
  memset(sz, 0, sizeof(sz));
  memset(mx, 0, sizeof(mx));
  memset(tg, 0, sizeof(tg));
  memset(se, 0, sizeof(se));
  memset(ct, 0, sizeof(ct));
  memset(su, 0, sizeof(su));
}
inline void up(int o) {
  mx[o] = max(mx[o << 1], mx[o << 1 | 1]);
  ct[o] = 0;
  sz[o] = sz[o << 1] + sz[o << 1 | 1];
  su[o] = su[o << 1] + su[o << 1 | 1];
  (mx[o] == mx[o << 1]) && (ct[o] += ct[o << 1]);
  (mx[o] == mx[o << 1 | 1]) && (ct[o] += ct[o << 1 | 1]);
  se[o] = mx[o << 1] == mx[o << 1 | 1] || !mx[o << 1] || !mx[o << 1 | 1]
              ? max(se[o << 1], se[o << 1 | 1])
              : max(min(mx[o << 1], mx[o << 1 | 1]),
                    max(se[o << 1], se[o << 1 | 1]));
}
inline void ad(int o, long long x) {
  if (mx[o]) mx[o] += x;
  if (se[o]) se[o] += x;
  tg[o] += x;
  su[o] += sz[o] * x;
}
inline void pm(int o, long long x) {
  if (x < mx[o]) su[o] -= ct[o] * (mx[o] - x), mx[o] = x;
}
inline void pd(int o) {
  ad(o << 1, tg[o]);
  ad(o << 1 | 1, tg[o]);
  tg[o] = 0;
  pm(o << 1, mx[o]);
  pm(o << 1 | 1, mx[o]);
}
void upd(int o, int l, int r, int x, int y) {
  if (l == r) {
    mx[o] = su[o] = y;
    sz[o] = ct[o] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  pd(o);
  x > mid ? upd(o << 1 | 1, mid + 1, r, x, y) : upd(o << 1, l, mid, x, y);
  up(o);
}
int que(int o, int l, int r, int x) {
  if (l == r) return sz[o];
  int mid = (l + r) >> 1;
  pd(o);
  return x > mid ? sz[o << 1] + que(o << 1 | 1, mid + 1, r, x)
                 : que(o << 1, l, mid, x);
}
void add(int o, int l, int r, int ql, int qr, int x) {
  if (ql <= l && r <= qr) {
    ad(o, x);
    return;
  }
  if (ql > r || qr < l) return;
  int mid = (l + r) >> 1;
  pd(o);
  add(o << 1, l, mid, ql, qr, x);
  add(o << 1 | 1, mid + 1, r, ql, qr, x);
  up(o);
}
void umin(int o, int l, int r, int ql, int qr, int x) {
  if (ql > r || qr < l) return;
  int mid = (l + r) >> 1;
  if (ql <= l && r <= qr) {
    if (mx[o] <= x) return;
    if (se[o] > x)
      pd(o), umin(o << 1, l, mid, ql, qr, x),
          umin(o << 1 | 1, mid + 1, r, ql, qr, x), up(o);
    else
      pm(o, x);
    return;
  }
  pd(o);
  umin(o << 1, l, mid, ql, qr, x);
  umin(o << 1 | 1, mid + 1, r, ql, qr, x);
  up(o);
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%d", a + i), b[a[i]] = i;
  for (int i = (1); i <= (n); ++i) {
    add(1, 1, n, b[i] + 1, n, 1);
    int x = que(1, 1, n, b[i]);
    if (i > 1) umin(1, 1, n, 1, b[i] - 1, x);
    upd(1, 1, n, b[i], i);
    ans[i] = sz[1] + su[1];
  }
  for (int i = (1); i <= (n); ++i) b[i] = n - b[i] + 1;
  cl();
  for (int i = (1); i <= (n); ++i) {
    add(1, 1, n, b[i] + 1, n, 1);
    int x = que(1, 1, n, b[i]);
    if (i > 1) umin(1, 1, n, 1, b[i] - 1, x);
    upd(1, 1, n, b[i], i);
    printf("%lld\n", ans[i] - 1ll * i * (i + 1) + su[1]);
  }
  return 0;
}
