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>
namespace IO {
char gc() { return getchar(); }
template <typename Tp>
bool get1(Tp &x) {
  bool neg = 0;
  char c = gc();
  while (c != EOF && (c < '0' || c > '9') && c != '-') c = gc();
  if (c == '-') c = gc(), neg = 1;
  if (c == EOF) return false;
  x = 0;
  for (; c >= '0' && c <= '9'; c = gc()) x = x * 10 + c - '0';
  if (neg) x = -x;
  return true;
}
template <typename Tp>
void printendl(Tp x) {
  if (x < 0) putchar('-'), x = -x;
  static short a[40], sz;
  sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
  puts("");
}
}  // namespace IO
using IO::get1;
using IO::printendl;
const int inf = 0x3f3f3f3f;
const long long Linf = 1ll << 61;
const int maxn = 150111;
struct BIT {
  int bit[maxn];
  void add(int x, int v) {
    for (; x < maxn; x += x & -x) bit[x] += v;
  }
  int query(int x) {
    int ret = 0;
    for (; x; x -= x & -x) ret += bit[x];
    return ret;
  }
  void clear() { memset(bit, 0, sizeof(bit)); }
};
BIT pre;
long long sum, ans[maxn];
namespace SGT {
struct node {
  int mx, smx, mxcnt, tag;
  node() { mx = smx = mxcnt = tag = 0; }
  void Tag(int v) {
    mx += v;
    tag += v;
  }
};
node seg[(1 << 19) + 100];
void push(int t) {
  if (seg[t].tag) {
    if (seg[(t * 2)].mx + seg[t].tag == seg[t].mx) seg[(t * 2)].Tag(seg[t].tag);
    if (seg[(t * 2 + 1)].mx + seg[t].tag == seg[t].mx)
      seg[(t * 2 + 1)].Tag(seg[t].tag);
    seg[t].tag = 0;
  }
}
void pull(int t) {
  if (seg[(t * 2)].mx > seg[(t * 2 + 1)].mx) {
    seg[t].mx = seg[(t * 2)].mx;
    seg[t].mxcnt = seg[(t * 2)].mxcnt;
    seg[t].smx = std::max(seg[(t * 2)].smx, seg[(t * 2 + 1)].mx);
  } else if (seg[(t * 2 + 1)].mx > seg[(t * 2)].mx) {
    seg[t].mx = seg[(t * 2 + 1)].mx;
    seg[t].mxcnt = seg[(t * 2 + 1)].mxcnt;
    seg[t].smx = std::max(seg[(t * 2 + 1)].smx, seg[(t * 2)].mx);
  } else {
    seg[t].mx = seg[(t * 2)].mx;
    seg[t].mxcnt = seg[(t * 2)].mxcnt + seg[(t * 2 + 1)].mxcnt;
    seg[t].smx = std::max(seg[(t * 2)].smx, seg[(t * 2 + 1)].smx);
  }
}
void modify(int l, int r, int v, int tl, int tr, int t) {
  if (seg[t].mx <= v) return;
  if (seg[t].smx < v && l <= tl && tr <= r) {
    sum -= 1ll * pre.query(seg[t].mx) * seg[t].mxcnt;
    seg[t].Tag(v - seg[t].mx);
    sum += 1ll * pre.query(seg[t].mx) * seg[t].mxcnt;
    return;
  }
  push(t);
  int mid = (tl + tr) / 2;
  if (l <= mid) modify(l, r, v, tl, mid, (t * 2));
  if (r > mid) modify(l, r, v, mid + 1, tr, (t * 2 + 1));
  pull(t);
}
void activate(int p, int v, int tl, int tr, int t) {
  if (tl == tr) {
    seg[t].mx = v;
    seg[t].mxcnt = 1;
    seg[t].smx = 0;
    sum += pre.query(v);
    return;
  }
  push(t);
  int mid = (tl + tr) / 2;
  if (p <= mid)
    activate(p, v, tl, mid, (t * 2));
  else
    activate(p, v, mid + 1, tr, (t * 2 + 1));
  pull(t);
}
void debug(int tl, int tr, int t) {
  if (tl == tr) {
    printf("l= %d r= %d mx= %d mxcnt= %d smx= %d\n", tl, tr, seg[t].mx,
           seg[t].mxcnt, seg[t].smx);
    return;
  }
  push(t);
  int mid = (tl + tr) / 2;
  debug(tl, mid, (t * 2));
  debug(mid + 1, tr, (t * 2 + 1));
}
}  // namespace SGT
int n, a[maxn], pos[maxn];
void ins(int p) {
  if (p > 1) SGT::modify(1, p - 1, p - 1, 1, n, 1);
  pre.add(p, 1);
  sum -= pre.query(p);
  SGT::activate(p, n, 1, n, 1);
}
void solve() {
  pre.clear();
  memset(SGT::seg, 0, sizeof(SGT::seg));
  for (int i = 0; i < (1 << 19) + 10; i++) SGT::seg[i] = SGT::node();
  for (int i = 1; i <= n; i++) pos[a[i]] = i;
  sum = 0;
  for (int i = 1; i <= n; i++) {
    ins(pos[i]);
    ans[i] += sum;
  }
}
int main() {
  get1(n);
  for (int i = 1; i <= n; i++) get1(a[i]);
  solve();
  std::reverse(a + 1, a + n + 1);
  solve();
  for (int i = 1; i <= n; i++) {
    ans[i] += i;
    printendl(ans[i]);
  }
  return 0;
}
