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 MAGIC = 1e6;
const int INF = 2e6;
int n;
int a[150005], pos[150005];
long long sum[600005], fir[600005], sec[600005], cnt[600005], siz[600005];
long long add[600005], chk[600005];
inline void init() {
  memset(sum, 0, sizeof(sum));
  memset(fir, 0x3c, sizeof(fir));
  memset(sec, 0x3c, sizeof(sec));
  memset(add, 0, sizeof(add));
  memset(chk, 0, sizeof(chk));
  memset(siz, 0, sizeof(siz));
  memset(cnt, 0, sizeof(cnt));
}
inline void pushdown(int v) {
  if ((add[v] || chk[v]) && (v << 1 | 1) <= n * 4) {
    if (chk[v] && chk[v] > fir[v << 1]) {
      sum[v << 1] += cnt[v << 1] * (chk[v] - fir[v << 1]);
      fir[v << 1] = chk[v];
    }
    if (add[v])
      sum[v << 1] += siz[v << 1] * add[v], fir[v << 1] += add[v],
          sec[v << 1] += add[v];
    if (chk[v] && chk[v] > fir[v << 1 | 1]) {
      sum[v << 1 | 1] += cnt[v << 1 | 1] * (chk[v] - fir[v << 1 | 1]);
      fir[v << 1 | 1] = chk[v];
    }
    if (add[v])
      sum[v << 1 | 1] += siz[v << 1 | 1] * add[v], fir[v << 1 | 1] += add[v],
          sec[v << 1 | 1] += add[v];
    if (chk[v]) chk[v << 1] = max(chk[v << 1], chk[v] - add[v << 1]);
    add[v << 1] += add[v];
    if (chk[v])
      chk[v << 1 | 1] = max(chk[v << 1 | 1], chk[v] - add[v << 1 | 1]);
    add[v << 1 | 1] += add[v];
    add[v] = chk[v] = 0;
  }
}
inline void pushup(int v) {
  fir[v] = min(fir[v << 1], fir[v << 1 | 1]);
  sum[v] = sum[v << 1] + sum[v << 1 | 1];
  siz[v] = siz[v << 1] + siz[v << 1 | 1];
  cnt[v] = 0;
  if (fir[v << 1] == fir[v]) cnt[v] += cnt[v << 1];
  if (fir[v << 1 | 1] == fir[v]) cnt[v] += cnt[v << 1 | 1];
  sec[v] = INF;
  if (fir[v << 1] != fir[v]) sec[v] = min(sec[v], fir[v << 1]);
  if (fir[v << 1 | 1] != fir[v]) sec[v] = min(sec[v], fir[v << 1 | 1]);
  sec[v] = min(sec[v], min(sec[v << 1], sec[v << 1 | 1]));
}
inline void insert(int pos, int val, int v = 1, int l = 1, int r = n) {
  if (l == r) {
    fir[v] = val;
    sec[v] = INF;
    sum[v] = val;
    cnt[v] = 1;
    siz[v] = 1;
    add[v] = chk[v] = 0;
  } else {
    pushdown(v);
    int m = l + r >> 1;
    if (pos <= m)
      insert(pos, val, v << 1, l, m);
    else
      insert(pos, val, v << 1 | 1, m + 1, r);
    pushup(v);
  }
}
inline void increase(int a, int b, int val, int v = 1, int l = 1, int r = n) {
  if (a <= l && r <= b) {
    add[v] += val;
    fir[v] += val;
    sec[v] += val;
    sum[v] += siz[v] * val;
  } else if (r < a || b < l)
    return;
  else {
    pushdown(v);
    int m = l + r >> 1;
    increase(a, b, val, v << 1, l, m);
    increase(a, b, val, v << 1 | 1, m + 1, r);
    pushup(v);
  }
}
inline void checkmax(int a, int b, int val, int v = 1, int l = 1, int r = n) {
  if (a <= l && r <= b) {
    if (val <= fir[v])
      return;
    else if (fir[v] < val && val < sec[v]) {
      sum[v] += cnt[v] * (val - fir[v]);
      fir[v] = val;
      chk[v] = max(chk[v], val - add[v]);
    } else {
      if (l == r) {
        fir[v] = val;
        sum[v] = val;
      } else {
        int m = l + r >> 1;
        pushdown(v);
        checkmax(a, b, val, v << 1, l, m);
        checkmax(a, b, val, v << 1 | 1, m + 1, r);
        pushup(v);
      }
    }
  } else if (r < a || b < l)
    return;
  else {
    pushdown(v);
    int m = l + r >> 1;
    checkmax(a, b, val, v << 1, l, m);
    checkmax(a, b, val, v << 1 | 1, m + 1, r);
    pushup(v);
  }
}
int bit[150005];
inline void update(int p, int v) {
  while (p <= n) {
    bit[p] += v;
    p += p & -p;
  }
}
inline int query(int p) {
  int ret = 0;
  while (p) {
    ret += bit[p];
    p -= p & -p;
  }
  return ret;
}
inline void monitor() {
  printf(
      "#1: fir=%lld, sec=%lld, cnt=%lld, siz=%lld, sum=%lld, chk=%lld, "
      "add=%lld\n",
      fir[4], sec[4], cnt[4], siz[4], sum[4], chk[4], add[4]);
  printf(
      "#2: fir=%lld, sec=%lld, cnt=%lld, siz=%lld, sum=%lld, chk=%lld, "
      "add=%lld\n",
      fir[5], sec[5], cnt[5], siz[5], sum[5], chk[5], add[5]);
  printf(
      "#1~2: fir=%lld, sec=%lld, cnt=%lld, siz=%lld, sum=%lld, chk=%lld, "
      "add=%lld\n",
      fir[2], sec[2], cnt[2], siz[2], sum[2], chk[2], add[2]);
}
long long ans[150005];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= (n); ++i) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  init();
  for (int i = 1; i <= (n); ++i) {
    int p = pos[i];
    insert(p, 0);
    int rel = query(p) + 1;
    update(p, 1);
    increase(p + 1, n, 1);
    checkmax(p + 1, n, rel);
    ans[i] -= sum[1];
  }
  memset(bit, 0, sizeof(bit));
  init();
  for (int i = 1; i <= (n); ++i) {
    int p = pos[i];
    insert(n + 1 - p, n - i);
    int rel = query(p) + 1;
    update(p, 1);
    increase(1, n - p, -1);
    checkmax(n - p + 2, n, n + 1 - rel);
    ans[i] += (long long)i * (n + 1) - sum[1];
  }
  for (int i = 1; i <= (n); ++i) ans[i] -= i;
  for (int i = 1; i <= (n); ++i) cout << ans[i] << endl;
  return 0;
}
