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 std::max;
using std::min;
const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3f;
__inline__ __attribute__((always_inline)) unsigned int rnd() {
  static unsigned int seed = 416;
  return seed += 0x71dad4bfu, seed ^= seed >> 5, seed += 0xc6f74d88u,
         seed ^= seed << 17, seed += 0x25e6561u, seed ^= seed >> 13;
}
template <typename _Tp>
_Tp gcd(const _Tp &a, const _Tp &b) {
  return (!b) ? a : gcd(b, a % b);
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {
  return a >= 0 ? a : -a;
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {
  (a < b) && (a = b);
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {
  (b < a) && (a = b);
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) void read(_Tp &x) {
  char ch(getchar());
  bool f(false);
  while (!isdigit(ch)) f |= ch == 45, ch = getchar();
  x = ch & 15, ch = getchar();
  while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();
  f && (x = -x);
}
template <typename _Tp, typename... Args>
__inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {
  read(t);
  read(args...);
}
template <typename _Tp, typename... Args>
__inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b,
                                                  const Args &...args) {
  return a < b ? min(a, args...) : min(b, args...);
}
template <typename _Tp, typename... Args>
__inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b,
                                                  const Args &...args) {
  return a < b ? max(b, args...) : max(a, args...);
}
__inline__ __attribute__((always_inline)) int read_str(char *s) {
  char ch(getchar());
  while (ch == ' ' || ch == '\r' || ch == '\n') ch = getchar();
  char *tar = s;
  *tar = ch, ch = getchar();
  while (ch != ' ' && ch != '\r' && ch != '\n' && ch != EOF)
    *(++tar) = ch, ch = getchar();
  return tar - s + 1;
}
const int N = 150005;
int n;
struct node1 {
  int v1, c1, v2;
  __inline__ __attribute__((always_inline)) node1 operator+(
      const node1 &o) const {
    if (o.v1 > v1)
      return (node1){o.v1, o.c1, max(v1, o.v2)};
    else if (o.v1 == v1)
      return (node1){v1, c1 + o.c1, max(v2, o.v2)};
    else
      return (node1){v1, c1, max(v2, o.v1)};
  }
};
struct node2 {
  int v1, c1, v2;
  __inline__ __attribute__((always_inline)) node2 operator+(const node2 &o) {
    if (o.v1 < v1)
      return (node2){o.v1, o.c1, min(v1, o.v2)};
    else if (o.v1 == v1)
      return (node2){v1, c1 + o.c1, min(v2, o.v2)};
    else
      return (node2){v1, c1, min(v2, o.v1)};
  }
};
struct seg_tr1 {
  struct Node {
    int ls, rs;
    long long sum1, sum2, sum, tag;
  } f[N << 1];
  int node_cnt;
  __inline__ __attribute__((always_inline)) void pushup(int x) {
    f[x].sum1 = f[f[x].ls].sum1 + f[f[x].rs].sum1;
    f[x].sum2 = f[f[x].ls].sum2 + f[f[x].rs].sum2;
    f[x].sum = f[f[x].ls].sum + f[f[x].rs].sum;
  }
  int build(int l, int r) {
    int cur = ++node_cnt;
    if (l == r) return cur;
    int mid = (l + r) >> 1;
    f[cur].ls = build(l, mid);
    f[cur].rs = build(mid + 1, r);
    return cur;
  }
  __inline__ __attribute__((always_inline)) void upd(int cur, int val, int l,
                                                     int r) {
    f[cur].sum2 += 1ll * (r - l + 1) * val;
    f[cur].sum += 1ll * f[cur].sum1 * val;
    f[cur].tag += val;
  }
  __inline__ __attribute__((always_inline)) void pushdown(int cur, int l,
                                                          int r) {
    if (f[cur].tag) {
      int mid = (l + r) >> 1;
      upd(f[cur].ls, f[cur].tag, l, mid);
      upd(f[cur].rs, f[cur].tag, mid + 1, r);
      f[cur].tag = 0;
    }
  }
  void Update1(int pos, int val, int l, int r, int cur) {
    if (l == r) {
      f[cur].sum1 += val;
      f[cur].sum += 1ll * val * f[cur].sum2;
      return;
    }
    pushdown(cur, l, r);
    int mid = (l + r) >> 1;
    if (pos <= mid)
      Update1(pos, val, l, mid, f[cur].ls);
    else
      Update1(pos, val, mid + 1, r, f[cur].rs);
    pushup(cur);
  }
  void Update2(int L, int R, int val, int l, int r, int cur) {
    if (L <= l && r <= R) {
      upd(cur, val, l, r);
      return;
    }
    pushdown(cur, l, r);
    int mid = (l + r) >> 1;
    if (L <= mid) Update2(L, R, val, l, mid, f[cur].ls);
    if (R > mid) Update2(L, R, val, mid + 1, r, f[cur].rs);
    pushup(cur);
  }
  __inline__ __attribute__((always_inline)) long long Query() {
    return f[1].sum;
  }
} tr;
struct seg_tr2 {
  struct Node {
    int ls, rs;
    node1 maxx;
    node2 minn;
    int tag1, tag2;
  } f[N << 1];
  int node_cnt;
  __inline__ __attribute__((always_inline)) void pushup(int x) {
    f[x].maxx = f[f[x].ls].maxx + f[f[x].rs].maxx;
    f[x].minn = f[f[x].ls].minn + f[f[x].rs].minn;
  }
  int build(int l, int r) {
    int cur = ++node_cnt;
    f[cur].tag1 = n + 1, f[cur].tag2 = 0;
    f[cur].maxx = (node1){n + 1, 0, 0};
    f[cur].minn = (node2){0, 0, n + 1};
    if (l == r) return cur;
    int mid = (l + r) >> 1;
    f[cur].ls = build(l, mid);
    f[cur].rs = build(mid + 1, r);
    return cur;
  }
  __inline__ __attribute__((always_inline)) void upd1(int x, int val) {
    chmin(f[x].maxx.v1, val);
    chmin(f[x].tag1, val);
  }
  __inline__ __attribute__((always_inline)) void upd2(int x, int val) {
    chmax(f[x].minn.v1, val);
    chmax(f[x].tag2, val);
  }
  __inline__ __attribute__((always_inline)) void pushdown(int cur) {
    if (f[cur].tag1 < n + 1)
      upd1(f[cur].ls, f[cur].tag1), upd1(f[cur].rs, f[cur].tag1),
          f[cur].tag1 = n + 1;
    if (f[cur].tag2 > 0)
      upd2(f[cur].ls, f[cur].tag2), upd2(f[cur].rs, f[cur].tag2),
          f[cur].tag2 = 0;
  }
  void upd_chmin(int L, int R, int l, int r, int cur, int val) {
    if (val >= f[cur].maxx.v1) return;
    if (l != r) pushdown(cur);
    int mid = (l + r) >> 1;
    if (L <= l && r <= R) {
      if (val <= f[cur].maxx.v2) {
        upd_chmin(L, R, l, mid, f[cur].ls, val);
        upd_chmin(L, R, mid + 1, r, f[cur].rs, val);
        pushup(cur);
      } else {
        if (f[cur].maxx.c1)
          tr.Update1(f[cur].maxx.v1, -f[cur].maxx.c1, 0, n + 1, 1);
        upd1(cur, val);
        if (f[cur].maxx.c1)
          tr.Update1(f[cur].maxx.v1, f[cur].maxx.c1, 0, n + 1, 1);
      }
      return;
    }
    if (L <= mid) upd_chmin(L, R, l, mid, f[cur].ls, val);
    if (R > mid) upd_chmin(L, R, mid + 1, r, f[cur].rs, val);
    pushup(cur);
  }
  void upd_chmax(int L, int R, int l, int r, int cur, int val) {
    if (val <= f[cur].minn.v1) return;
    if (l != r) pushdown(cur);
    int mid = (l + r) >> 1;
    if (L <= l && r <= R) {
      if (val >= f[cur].minn.v2) {
        upd_chmax(L, R, l, mid, f[cur].ls, val);
        upd_chmax(L, R, mid + 1, r, f[cur].rs, val);
        pushup(cur);
      } else {
        if (f[cur].minn.c1)
          tr.Update1(f[cur].minn.v1, f[cur].minn.c1, 0, n + 1, 1);
        upd2(cur, val);
        if (f[cur].minn.c1)
          tr.Update1(f[cur].minn.v1, -f[cur].minn.c1, 0, n + 1, 1);
      }
      return;
    }
    if (L <= mid) upd_chmax(L, R, l, mid, f[cur].ls, val);
    if (R > mid) upd_chmax(L, R, mid + 1, r, f[cur].rs, val);
    pushup(cur);
  }
  void add_val(int pos, int l, int r, int cur) {
    if (l == r) {
      f[cur].maxx = (node1){n + 1, 1, 0};
      f[cur].minn = (node2){0, 1, n + 1};
      tr.Update1(n + 1, 1, 0, n + 1, 1);
      tr.Update1(0, -1, 0, n + 1, 1);
      return;
    }
    pushdown(cur);
    int mid = (l + r) >> 1;
    if (pos <= mid)
      add_val(pos, l, mid, f[cur].ls);
    else
      add_val(pos, mid + 1, r, f[cur].rs);
    pushup(cur);
  }
} __;
int t[N], a[N];
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]), t[a[i]] = i;
  tr.build(0, n + 1);
  __.build(1, n);
  tr.Update2(n + 1, n + 1, 1, 0, n + 1, 1);
  for (int i = 1; i <= n; ++i) {
    int p = t[i];
    __.add_val(p, 1, n, 1);
    if (p > 1) __.upd_chmin(1, p - 1, 1, n, 1, p);
    if (p < n) __.upd_chmax(p + 1, n, 1, n, 1, p);
    tr.Update2(p, n + 1, 1, 0, n + 1, 1);
    printf("%lld\n", tr.Query() - i);
  }
  return 0;
}
