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 + 5;
const int inf = 1e9 + 7;
int a[N], ind[N], mrk[N];
int nxL[N], nxR[N];
long long sm[N], ans = 0, lans = 0;
int freq[2][N];
struct node {
  int l, r, zl, zr, cl, cr;
  int lz, rz, ccl, ccr;
} seg[N * 4];
void addS(int i, long long v) {
  for (++i; i < N; i += i & -i) sm[i] += v;
}
long long sumS(int i) {
  long long ret = 0;
  for (++i; i > 0; i -= i & -i) ret += sm[i];
  return ret;
}
void addF(int j, int i, int v) {
  for (++i; i < N; i += i & -i) freq[j][i] += v;
}
int sumF(int j, int i) {
  int ret = 0;
  for (++i; i > 0; i -= i & -i) ret += freq[j][i];
  return ret;
}
void build(int l, int r, int k) {
  seg[k] = {inf, -1, inf, -1, 0, 0, inf, -1, 0, 0};
  if (l == r) return;
  int m = (l + r) / 2;
  build(l, m, k * 2);
  build(m + 1, r, k * 2 + 1);
}
void prop(int l, int r, int k) {
  if (seg[k].lz != inf) {
    if (l != r) {
      if (seg[k * 2].l < seg[k].lz && seg[k * 2].zl > seg[k].lz)
        seg[k * 2].lz = seg[k].lz;
      if (seg[k * 2 + 1].l < seg[k].lz && seg[k * 2 + 1].zl > seg[k].lz)
        seg[k * 2 + 1].lz = seg[k].lz;
    }
    seg[k].l = seg[k].lz;
    seg[k].lz = inf;
  }
  if (seg[k].rz != -1) {
    if (l != r) {
      if (seg[k * 2].r > seg[k].rz && seg[k * 2].zr < seg[k].rz)
        seg[k * 2].rz = seg[k].rz;
      if (seg[k * 2 + 1].r > seg[k].rz && seg[k * 2 + 1].zr < seg[k].rz)
        seg[k * 2 + 1].rz = seg[k].rz;
    }
    seg[k].r = seg[k].rz;
    seg[k].rz = -1;
  }
}
void mergeL(int k) {
  seg[k].l = min(seg[k * 2].l, seg[k * 2 + 1].l);
  if (seg[k * 2].l > seg[k * 2 + 1].l) {
    seg[k].zl = min(seg[k * 2].l, seg[k * 2 + 1].zl);
    seg[k].ccl = seg[k * 2 + 1].ccl;
  } else if (seg[k * 2].l < seg[k * 2 + 1].l) {
    seg[k].zl = min(seg[k * 2].zl, seg[k * 2 + 1].l);
    seg[k].ccl = seg[k * 2].ccl;
  } else {
    seg[k].zl = min(seg[k * 2].zl, seg[k * 2 + 1].zl);
    seg[k].ccl = seg[k * 2].ccl + seg[k * 2 + 1].ccl;
  }
}
void mergeR(int k) {
  seg[k].r = max(seg[k * 2].r, seg[k * 2 + 1].r);
  if (seg[k * 2].r > seg[k * 2 + 1].r) {
    seg[k].zr = max(seg[k * 2].zr, seg[k * 2 + 1].r);
    seg[k].ccr = seg[k * 2].ccr;
  } else if (seg[k * 2].r < seg[k * 2 + 1].r) {
    seg[k].zr = max(seg[k * 2].r, seg[k * 2 + 1].zr);
    seg[k].ccr = seg[k * 2 + 1].ccr;
  } else {
    seg[k].zr = max(seg[k * 2].zr, seg[k * 2 + 1].zr);
    seg[k].ccr = seg[k * 2].ccr + seg[k * 2 + 1].ccr;
  }
}
void setV(int l, int r, int k, int x, int lv, int rv) {
  prop(l, r, k);
  if (r < x || x < l) return;
  if (l == r) {
    if (lv != inf) {
      if (seg[k].l == inf) {
        ans += sumS(l);
      } else {
        ans += sumS(seg[k].l - 1);
        addF(0, seg[k].l - 1, -1);
      }
      addF(0, lv - 1, 1);
      ans -= sumS(lv - 1);
      seg[k].l = lv;
      seg[k].cl = seg[k].ccl = 1;
      mrk[l] = 1;
    }
    if (rv != -1) {
      if (seg[k].r == -1) {
        ans -= sumS(r - 1);
      } else {
        ans -= sumS(seg[k].r);
        addF(1, seg[k].r, -1);
      }
      addF(1, rv, 1);
      ans += sumS(rv);
      seg[k].r = rv;
      seg[k].cr = seg[k].ccr = 1;
    }
    return;
  }
  int m = (l + r) / 2;
  setV(l, m, k * 2, x, lv, rv);
  setV(m + 1, r, k * 2 + 1, x, lv, rv);
  mergeL(k);
  mergeR(k);
  seg[k].cl = seg[k * 2].cl + seg[k * 2 + 1].cl;
  seg[k].cr = seg[k * 2].cr + seg[k * 2 + 1].cr;
}
void applyMin(int l, int r, int k, int x, int y, int v) {
  prop(l, r, k);
  if (y < l || r < x || seg[k].r <= v) return;
  if (x <= l && r <= y && seg[k].zr < v) {
    seg[k].rz = v;
    addF(1, seg[k].r, -seg[k].ccr);
    ans -= sumS(seg[k].r) * 1ll * seg[k].ccr;
    addF(1, v, seg[k].ccr);
    ans += sumS(v) * 1ll * seg[k].ccr;
    prop(l, r, k);
    return;
  }
  if (l == r) return;
  int m = (l + r) / 2;
  applyMin(l, m, k * 2, x, y, v);
  applyMin(m + 1, r, k * 2 + 1, x, y, v);
  mergeR(k);
}
void applyMax(int l, int r, int k, int x, int y, int v) {
  prop(l, r, k);
  if (y < l || r < x || seg[k].l >= v) return;
  if (x <= l && r <= y && seg[k].zl > v) {
    seg[k].lz = v;
    addF(0, seg[k].l - 1, -seg[k].ccl);
    ans += sumS(seg[k].l - 1) * 1ll * seg[k].ccl;
    addF(0, v - 1, seg[k].ccl);
    ans -= sumS(v - 1) * 1ll * seg[k].ccl;
    prop(l, r, k);
    return;
  }
  if (l == r) return;
  int m = (l + r) / 2;
  applyMax(l, m, k * 2, x, y, v);
  applyMax(m + 1, r, k * 2 + 1, x, y, v);
  mergeL(k);
}
node qry(int l, int r, int k, int x, int y) {
  prop(l, r, k);
  if (x <= l && r <= y) return seg[k];
  int m = (l + r) / 2;
  if (y <= m) return qry(l, m, k * 2, x, y);
  if (m < x) return qry(m + 1, r, k * 2 + 1, x, y);
  node lhs = qry(l, m, k * 2, x, y);
  node rhs = qry(m + 1, r, k * 2 + 1, x, y);
  lhs.cl += rhs.cl, lhs.cr += rhs.cr;
  return lhs;
}
int main() {
  int n;
  scanf("%d", &n);
  stack<int> first;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    while (!first.empty() && a[first.top()] > a[i]) first.pop();
    nxL[i] = 0, nxR[i] = n + 1;
    if (!first.empty()) nxL[i] = first.top();
    first.push(i);
    ind[a[i]] = i;
  }
  while (!first.empty()) first.pop();
  for (int i = n; i; i--) {
    while (!first.empty() && a[first.top()] > a[i]) first.pop();
    if (!first.empty()) nxR[i] = first.top();
    first.push(i);
  }
  build(1, n, 1);
  printf("1\n");
  int lo = ind[1], hi = ind[1];
  addS(ind[1], 1);
  setV(1, n, 1, ind[1], ind[1], ind[1]);
  for (int i = 2; i <= n; i++) {
    lo = min(ind[i], lo);
    hi = max(ind[i], hi);
    if (lo <= nxL[ind[i]]) applyMin(1, n, 1, lo, nxL[ind[i]], nxL[ind[i]]);
    if (nxR[ind[i]] <= hi) applyMax(1, n, 1, nxR[ind[i]], hi, nxR[ind[i]]);
    setV(1, n, 1, hi, lo, -1);
    setV(1, n, 1, lo, inf, hi);
    setV(1, n, 1, nxL[ind[i]], lo, -1);
    setV(1, n, 1, nxR[ind[i]], inf, hi);
    long long tmp = 0, zx = 0;
    if (ind[i] + 1 <= n) {
      node cur = qry(1, n, 1, ind[i] + 1, n);
      ans += cur.cl - cur.cr;
    }
    ans += mrk[ind[i]];
    addS(ind[i], 1);
    ans -= sumF(0, n) - sumF(0, ind[i] - 1);
    ans += sumF(1, n) - sumF(1, ind[i] - 1);
    printf("%I64d\n", ans - i);
  }
  return 0;
}
