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>
struct gss {
  int f, s, c;
  long long v;
};
struct segt {
  gss dat;
  long long tag, asv;
  int siz;
} T[1111111];
long long max(long long x, long long y) { return (x < y) ? y : x; }
gss operator+(gss x, gss y) {
  gss ret = x;
  ret.v += y.v;
  ret.f = max(x.f, y.f), ret.c = 0;
  if (x.f == ret.f) x.f = 0, ret.c += x.c;
  if (y.f == ret.f) y.f = 0, ret.c += y.c;
  ret.s = max(max(x.f, x.s), max(y.f, y.s));
  return ret;
}
void pushu(int p) {
  T[p].dat = T[p << 1].dat + T[p << 1 | 1].dat,
  T[p].siz = T[p << 1].siz + T[p << 1 | 1].siz;
}
void push(int p, long long d) {
  long long dt = T[p].dat.f - d;
  if (dt < 0) return;
  T[p].dat.f = d, T[p].dat.v -= T[p].dat.c * dt, T[p].tag = d;
}
void forall(int p, long long d) {
  if (!T[p].dat.s) T[p].dat.s = -1e9;
  T[p].dat.f += d, T[p].dat.s += d, T[p].dat.v += T[p].siz * d, T[p].asv += d;
  if (T[p].tag) T[p].tag += d;
}
gss init(int x) { return gss{x, -(1 << 20), 1, x}; }
void pushd(int p) {
  if (T[p].asv)
    forall(p << 1, T[p].asv), forall(p << 1 | 1, T[p].asv), T[p].asv = 0;
  if (T[p].tag)
    push(p << 1, T[p].tag), push(p << 1 | 1, T[p].tag), T[p].tag = 0;
}
int n;
void updata(int l, int r, long long d, int p = 1, int pl = 1, int pr = n) {
  if ((!d) || l > pr || pl > r) return;
  if (l <= pl && pr <= r)
    if (T[p].dat.s < d) {
      if (T[p].dat.f > d) push(p, d);
      return;
    }
  int mid = (pl + pr) >> 1;
  pushd(p), updata(l, r, d, p << 1, pl, mid),
      updata(l, r, d, p << 1 | 1, mid + 1, pr), pushu(p);
}
void insert(int c, long long d, int p = 1, int pl = 1, int pr = n) {
  if (pl == pr) {
    T[p].dat = init(d), T[p].siz = 1;
    return;
  }
  int mid = (pl + pr) >> 1, dir = c > mid;
  int sl = pl, sr = pr;
  pushd(p), dir ? pl = mid + 1 : pr = mid, insert(c, d, p << 1 | dir, pl, pr),
                  pushu(p);
}
void addup(int l, int r, long long d, int p = 1, int pl = 1, int pr = n) {
  if ((!d) || l > pr || pl > r) return;
  if (l <= pl && pr <= r) return forall(p, d);
  int mid = (pl + pr) >> 1;
  pushd(p), addup(l, r, d, p << 1, pl, mid),
      addup(l, r, d, p << 1 | 1, mid + 1, pr), pushu(p);
}
const int V = 1 << 18;
struct BIT {
  int s[1111111];
  void ins(int x, int d) {
    for (; x < V; x += (x & -x)) s[x] += d;
  }
  int qry(int x) {
    int ret = 0;
    for (; x; x -= (x & -x)) ret += s[x];
    return ret;
  }
  void clr() { memset(s, 0, sizeof s); }
} TR;
int p[1111111], r[1111111];
long long d[1111111];
void solve() {
  register int i;
  memset(T, 0, sizeof T), TR.clr();
  for (i = 1; i <= n; i++) r[p[i]] = i;
  for (i = 1; i <= n; i++)
    updata(1, r[i] - 1, TR.qry(r[i] - 1)), TR.ins(r[i], 1), insert(r[i], i),
        addup(r[i] + 1, n, 1), d[i] = T[1].dat.v;
}
long long ans[1111111];
int main() {
  scanf("%d", &n);
  register int i, t;
  for (i = 1; i <= n; i++) scanf("%d", p + i);
  solve();
  for (i = 1; i <= n; i++) ans[i] = d[i];
  for (i = 1; i < n - i + 1; i++)
    t = p[i], p[i] = p[n - i + 1], p[n - i + 1] = t;
  solve();
  for (i = 1; i <= n; i++) printf("%lld\n", ans[i] + d[i] - i * 1ll * i);
}
