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;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
int n, m, i, j, a[150005], p[150005];
long long ans;
struct seg {
  int s[150005];
  void add(int x, int y) {
    while (x <= n) {
      s[x] += y;
      x += (x & -x);
    }
  }
  int query(int x) {
    int ss = 0;
    while (x) {
      ss += s[x];
      x -= (x & -x);
    }
    return ss;
  }
  struct ii {
    int mx, smx, num;
  } tr[600005];
  int tag[600005];
  ii merge(ii x, ii y) {
    ii z;
    z.mx = max(x.mx, y.mx);
    z.smx = 0;
    z.num = 0;
    if (x.mx != z.mx)
      z.smx = max(z.smx, x.mx);
    else
      z.num += x.num;
    if (y.mx != z.mx)
      z.smx = max(z.smx, y.mx);
    else
      z.num += y.num;
    if (x.smx != z.mx) z.smx = max(z.smx, x.smx);
    if (y.smx != z.mx) z.smx = max(z.smx, y.smx);
    return z;
  }
  void pushup(int x) { tr[x] = merge(tr[x + x], tr[x + x + 1]); }
  void upd(int x, int y) {
    tag[x] = min(tag[x], y);
    tr[x].mx = min(tr[x].mx, y);
  }
  void pushdo(int x) {
    upd(x + x, tag[x]);
    upd(x + x + 1, tag[x]);
    tag[x] = n;
  }
  void update1(int x, int l, int r, int y, int c) {
    if (l == r) {
      tr[x].num = 1;
      tr[x].mx = c;
      tr[x].smx = 0;
      return;
    }
    pushdo(x);
    int mid = (l + r) / 2;
    if (y <= mid)
      update1(x + x, l, mid, y, c);
    else
      update1(x + x + 1, mid + 1, r, y, c);
    pushup(x);
  }
  void update2(int x, int l, int r, int ql, int qr, int c) {
    if (ql <= l && r <= qr) {
      if (c >= tr[x].mx) {
        return;
      }
      if (c > tr[x].smx) {
        ans -= 1ll * tr[x].num * (query(tr[x].mx) - query(c));
        upd(x, c);
        return;
      }
    }
    pushdo(x);
    int mid = (l + r) / 2;
    if (ql <= mid) update2(x + x, l, mid, ql, qr, c);
    if (qr > mid) update2(x + x + 1, mid + 1, r, ql, qr, c);
    pushup(x);
  }
  void build(int x, int l, int r) {
    tr[x].mx = tr[x].smx = tr[x].num = 0;
    tag[x] = n;
    if (l == r) {
      return;
    }
    int mid = (l + r) / 2;
    build(x + x, l, mid);
    build(x + x + 1, mid + 1, r);
  }
} t1, t2;
int main() {
  read(n);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    read(a[i]);
    p[a[i]] = i;
  }
  t1.build(1, 1, n);
  t1.build(1, 1, n);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    int x = p[i];
    if (x > 1) t1.update2(1, 1, n, 1, x - 1, x - 1);
    if (x < n) t2.update2(1, 1, n, 1, n - x, n - x);
    t1.add(x, 1);
    t2.add(n - x + 1, 1);
    t1.update1(1, 1, n, x, n);
    t2.update1(1, 1, n, n - x + 1, n);
    ans += i;
    printf("%lld\n", ans);
  }
  return 0;
}
