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>
const long long maxn = 2e5 + 9, mod = 998244353, inf = 1e9;
long long Read() {
  long long x(0), f(1);
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3ll) + (x << 1ll) + c - '0';
    c = getchar();
  }
  return x * f;
}
void Chkmin(long long &x, long long y) {
  if (y < x) x = y;
}
void Chkmax(long long &x, long long y) {
  if (y > x) x = y;
}
long long add(long long x, long long y) {
  return x += y, x >= mod ? x - mod : x;
}
long long dec(long long x, long long y) { return x -= y, x < 0 ? x + mod : x; }
long long mul(long long x, long long y) { return 1ll * x * y % mod; }
long long Pow(long long base, long long b) {
  long long ret(1);
  while (b) {
    if (b & 1) ret = mul(ret, base);
    base = mul(base, base);
    b >>= 1;
  }
  return ret;
}
struct Sgtbeats {
  struct node {
    long long mx, smx, mi, smi, mxnum, minum, sum, tag, num, val;
  } a[maxn << 2];
  void Build(long long nw, long long l, long long r) {
    a[nw] = (node){0, -inf, 0, inf, 0, 0, 0, 0, 0, 0};
    if (l == r) return;
    long long mid(l + r >> 1);
    Build(nw << 1, l, mid);
    Build(nw << 1 | 1, mid + 1, r);
  }
  void Push1(long long nw, long long x) {
    a[nw].sum += (x - a[nw].mx) * a[nw].mxnum;
    if (a[nw].smi == a[nw].mx) a[nw].smi = x;
    if (a[nw].mi == a[nw].mx) a[nw].mi = x;
    a[nw].mx = x;
  }
  void Push2(long long nw, long long x) {
    a[nw].sum += (x - a[nw].mi) * a[nw].minum;
    if (a[nw].smx == a[nw].mi) a[nw].smx = x;
    if (a[nw].mx == a[nw].mi) a[nw].mx = x;
    a[nw].mi = x;
  }
  void Update(long long nw) {
    long long lt(nw << 1), rt(nw << 1 | 1), tag(a[nw].tag), num(a[nw].num);
    a[nw] = a[rt];
    a[nw].tag = tag;
    if (a[lt].mx > a[nw].mx)
      a[nw].mx = a[lt].mx, a[nw].mxnum = a[lt].mxnum,
      a[nw].smx = std::max(a[lt].smx, a[rt].mx);
    else if (a[lt].mx == a[nw].mx)
      a[nw].mxnum += a[lt].mxnum, Chkmax(a[nw].smx, a[lt].smx);
    else
      Chkmax(a[nw].smx, a[lt].mx);
    if (a[lt].mi < a[nw].mi)
      a[nw].mi = a[lt].mi, a[nw].minum = a[lt].minum,
      a[nw].smi = std::min(a[lt].smi, a[rt].mi);
    else if (a[lt].mi == a[nw].mi)
      a[nw].minum += a[lt].minum, Chkmin(a[nw].smi, a[lt].smi);
    else
      Chkmin(a[nw].smi, a[lt].mi);
    a[nw].sum += a[lt].sum;
    a[nw].num += a[lt].num;
  }
  void Pushdown(long long nw) {
    long long lt(nw << 1), rt(nw << 1 | 1);
    long long x;
    if (x = a[nw].tag) {
      if (a[lt].num) {
        a[lt].tag += x;
        a[lt].mx += x;
        a[lt].mi += x;
        a[lt].sum += x * a[lt].num;
        if (a[lt].smx != -inf) a[lt].smx += x;
        if (a[lt].smi != inf) a[lt].smi += x;
      }
      if (a[rt].num) {
        a[rt].tag += x;
        a[rt].mx += x;
        a[rt].mi += x;
        a[rt].sum += x * a[rt].num;
        if (a[rt].smx != -inf) a[rt].smx += x;
        if (a[rt].smi != inf) a[rt].smi += x;
      }
      a[nw].tag = 0;
    }
    if (a[lt].num) {
      if (a[nw].mx < a[lt].mx) Push1(lt, a[nw].mx);
      if (a[nw].mi > a[lt].mi) Push2(lt, a[nw].mi);
    }
    if (a[rt].num) {
      if (a[nw].mx < a[rt].mx) Push1(rt, a[nw].mx);
      if (a[nw].mi > a[rt].mi) Push2(rt, a[nw].mi);
    }
  }
  void Modify(long long nw, long long l, long long r, long long x,
              long long v) {
    if (l == r) {
      a[nw].val = 1;
      a[nw].num = 1;
      a[nw].sum = v;
      a[nw].mi = v;
      a[nw].mx = v;
      a[nw].mxnum = a[nw].minum = 1;
      return;
    }
    Pushdown(nw);
    long long mid(l + r >> 1);
    if (x <= mid)
      Modify(nw << 1, l, mid, x, v);
    else
      Modify(nw << 1 | 1, mid + 1, r, x, v);
    Update(nw);
  }
  void Modifyadd(long long nw, long long l, long long r, long long lt,
                 long long rt, long long x) {
    if (!a[nw].num) return;
    if (lt <= l && rt >= r) {
      a[nw].tag += x;
      a[nw].mx += x;
      a[nw].mi += x;
      a[nw].sum += x * a[nw].num;
      if (a[nw].smi != inf) a[nw].smi += x;
      if (a[nw].smx != -inf) a[nw].smx += x;
      return;
    }
    Pushdown(nw);
    long long mid(l + r >> 1);
    if (lt <= mid) Modifyadd(nw << 1, l, mid, lt, rt, x);
    if (rt > mid) Modifyadd(nw << 1 | 1, mid + 1, r, lt, rt, x);
    Update(nw);
  }
  void Modifymax(long long nw, long long l, long long r, long long lt,
                 long long rt, long long x) {
    if (!a[nw].num) return;
    if (lt <= l && rt >= r) {
      if (a[nw].mi >= x) return;
      if (a[nw].smi > x) {
        a[nw].sum += (x - a[nw].mi) * a[nw].minum;
        if (a[nw].smx == a[nw].mi) a[nw].smx = x;
        if (a[nw].mx == a[nw].mi) a[nw].mx = x;
        a[nw].mi = x;
        return;
      }
    }
    Pushdown(nw);
    long long mid(l + r >> 1);
    if (lt <= mid) Modifymax(nw << 1, l, mid, lt, rt, x);
    if (rt > mid) Modifymax(nw << 1 | 1, mid + 1, r, lt, rt, x);
    Update(nw);
  }
  void Modifymin(long long nw, long long l, long long r, long long lt,
                 long long rt, long long x) {
    if (!a[nw].num) return;
    if (lt <= l && rt >= r) {
      if (a[nw].mx <= x) return;
      if (a[nw].smx < x) {
        a[nw].sum += (x - a[nw].mx) * a[nw].mxnum;
        if (a[nw].smi == a[nw].mx) a[nw].smi = x;
        if (a[nw].mi == a[nw].mx) a[nw].mi = x;
        a[nw].mx = x;
        return;
      }
    }
    Pushdown(nw);
    long long mid(l + r >> 1);
    if (lt <= mid) Modifymin(nw << 1, l, mid, lt, rt, x);
    if (rt > mid) Modifymin(nw << 1 | 1, mid + 1, r, lt, rt, x);
    Update(nw);
  }
} T;
long long n;
long long sum[maxn], a[maxn], ans[maxn], pos[maxn];
namespace Bit {
long long tr[maxn];
long long Lowbit(long long x) { return x & (-x); }
void Init() {
  for (long long i = 1; i <= n; ++i) tr[i] = 0;
}
void Modify(long long x) {
  for (; x <= n; x += Lowbit(x)) tr[x]++;
}
long long Query(long long x) {
  long long ret(0);
  for (; x; x -= Lowbit(x)) ret += tr[x];
  return ret;
}
}  // namespace Bit
int main() {
  n = Read();
  for (long long i = 1; i <= n; ++i) a[i] = Read(), pos[a[i]] = i;
  T.Build(1, 1, n);
  Bit::Init();
  for (long long i = 1; i <= n; ++i) {
    long long x(pos[i]);
    T.Modify(1, 1, n, x, 1);
    if (x < n) T.Modifyadd(1, 1, n, x + 1, n, 1);
    long long q(Bit::Query(x) + 1);
    if (x < n) T.Modifymax(1, 1, n, x + 1, n, q + 1);
    ans[i] -= T.a[1].sum;
    Bit::Modify(x);
  }
  T.Build(1, 1, n);
  Bit::Init();
  for (long long i = 1; i <= n; ++i) {
    long long x(pos[i]);
    T.Modify(1, 1, n, x, i);
    long long q(Bit::Query(x) + 1);
    if (x != 1) T.Modifymin(1, 1, n, 1, x - 1, q - 1);
    if (x < n) T.Modifyadd(1, 1, n, x + 1, n, 1);
    ans[i] += T.a[1].sum;
    Bit::Modify(x);
  }
  for (long long i = 1; i <= n; ++i) ans[i] += i;
  for (long long i = 1; i <= n; ++i) printf("%lld\n", ans[i]);
  return 0;
}
