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 = 3e5 + 1;
const int ts = 1 << 21;
int n;
long long mx[ts], se[ts], mxc[ts];
int sz;
long long ch[N];
long long df[N];
void pass(int id, int c) {
  if (mx[c] > mx[id]) mx[c] = mx[id];
}
void push(int id) {
  pass(id, id * 2);
  pass(id, id * 2 + 1);
}
void pull(int id) {
  mx[id] = max(mx[id * 2], mx[id * 2 + 1]);
  mxc[id] = 0;
  if (mx[id] == mx[id * 2]) mxc[id] += mxc[id * 2];
  if (mx[id] == mx[id * 2 + 1]) mxc[id] += mxc[id * 2 + 1];
  se[id] = max(se[id * 2], se[id * 2 + 1]);
  if (mx[id * 2] != mx[id]) se[id] = max(se[id], mx[id * 2]);
  if (mx[id * 2 + 1] != mx[id]) se[id] = max(se[id], mx[id * 2 + 1]);
}
void upd(int id, int l, int r, int ql, int qr, int v) {
  if (l > qr || r < ql || mx[id] <= v) return;
  if (ql <= l && r <= qr && se[id] < v) {
    ch[++sz] = mx[id];
    df[mx[id]] -= mxc[id];
    mx[id] = v;
    ch[++sz] = mx[id];
    df[mx[id]] += mxc[id];
    return;
  }
  push(id);
  int mid = (l + r) / 2;
  upd(id * 2, l, mid, ql, qr, v);
  upd(id * 2 + 1, mid + 1, r, ql, qr, v);
  pull(id);
}
void upd2(int id, int l, int r, int p, int v) {
  if (l == r) {
    ch[++sz] = mx[id];
    df[mx[id]] -= mxc[id];
    mx[id] = v;
    ch[++sz] = mx[id];
    df[mx[id]] += mxc[id];
    return;
  }
  push(id);
  int mid = (l + r) / 2;
  if (p <= mid)
    upd2(id * 2, l, mid, p, v);
  else
    upd2(id * 2 + 1, mid + 1, r, p, v);
  pull(id);
}
void build(int id, int l, int r) {
  mx[id] = 0;
  mxc[id] = r - l + 1;
  se[id] = -1e9;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
}
long long bit1[N], bit2[N];
void bupd1(int id, long long v) {
  for (int i = id; i <= n; i += i & -i) bit1[i] += v;
}
void bupd2(int id, long long v) {
  for (int i = id; i <= n; i += i & -i) bit2[i] += v;
}
long long bqry1(int id) {
  long long res = 0;
  for (int i = id; i >= 1; i -= i & -i) res += bit1[i];
  return res;
}
long long bqry2(int id) {
  long long res = 0;
  for (int i = id; i >= 1; i -= i & -i) res += bit2[i];
  return res;
}
int a[N], p[N];
long long ans[N];
set<int> s, t;
void magic(int mg) {
  s.clear();
  t.clear();
  build(1, 1, n);
  for (int i = 1; i <= n; i++) bit1[i] = bit2[i] = 0;
  s.insert(p[1]);
  t.insert(p[1]);
  bupd1(p[1], 1);
  int mx = p[1];
  upd2(1, 1, n, p[1], p[1]);
  bupd2(p[1], -1);
  long long tot = -1;
  for (int i = 2; i <= n; i++) {
    int cur = p[i];
    auto it = s.lower_bound(cur);
    bool rm = (it == s.end());
    int nxt = 0;
    if (!rm) nxt = *it;
    if (it == s.begin()) {
      tot -= bqry1(cur);
      bupd2(cur, -1);
      t.insert(cur);
      upd2(1, 1, n, cur, mx);
    } else {
      int prv = *(--it);
      upd(1, 1, n, 1, prv, prv);
      if (rm)
        mx = cur;
      else {
        upd2(1, 1, n, nxt, mx);
        if (t.find(nxt) == t.end()) {
          tot -= bqry1(nxt);
          bupd2(nxt, -1);
          t.insert(nxt);
        }
      }
      upd2(1, 1, n, *s.begin(), mx);
    }
    s.insert(cur);
    tot += bqry2(n) - bqry2(cur - 1);
    bupd1(cur, 1);
    for (int j = 1; j <= sz; j++) {
      if (ch[j] != 0 && df[ch[j]] != 0) {
        tot += df[ch[j]] * bqry1(ch[j]);
        bupd2(ch[j], df[ch[j]]);
        df[ch[j]] = 0;
      }
    }
    sz = 0;
    ans[i] += tot;
  }
}
void solve() {
  for (int i = 1; i <= n; i++) {
    p[a[i]] = i;
    ans[i] = 0;
  }
  magic(1);
  for (int i = 1; i <= n; i++) p[i] = n + 1 - p[i];
  magic(0);
  for (int i = 1; i <= n; i++) ans[i] += 1;
  for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  solve();
}
