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>
clock_t t = clock();
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T& t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
char __sr[1 << 21], __z[20];
int __C = -1, __zz = 0;
inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }
inline void print(register int x) {
  if (__C > 1 << 20) Ot();
  if (x < 0) __sr[++__C] = '-', x = -x;
  while (__z[++__zz] = x % 10 + 48, x /= 10)
    ;
  while (__sr[++__C] = __z[__zz], --__zz)
    ;
  __sr[++__C] = '\n';
}
void file() {}
inline void chktime() {}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) ret = ret * x;
  return ret;
}
}  // namespace my_std
using namespace my_std;
int n;
int a[303030];
long long ans[303030];
int p[303030];
int fp[303030];
void add(int x) {
  for (; x <= n; ++fp[x], x += (x & (-x)))
    ;
}
int query(int x) {
  int ret = 0;
  for (; x; ret += fp[x], x -= (x & (-x)))
    ;
  return ret;
}
long long cur = 0;
namespace seg {
int cnt[303030 << 2];
void modify(int k, int l, int r, int x, int w) {
  if (!x) return;
  cnt[k] += w;
  if (l == r) return cur += 1ll * query(x) * w, void();
  int mid = (l + r) >> 1;
  if (x <= mid)
    modify(k << 1, l, mid, x, w);
  else
    modify(k << 1 | 1, mid + 1, r, x, w);
}
int query(int k, int l, int r, int x, int y) {
  if (x <= l && r <= y) return cnt[k];
  int mid = (l + r) >> 1, ret = 0;
  if (x <= mid) ret += query(k << 1, l, mid, x, y);
  if (y > mid) ret += query(k << 1 | 1, mid + 1, r, x, y);
  return ret;
}
}  // namespace seg
int mx[303030 << 2], cm[303030 << 2], mxx[303030 << 2], tag[303030 << 2];
void pushup(int k) {
  mx[k] = max(mx[k << 1], mx[k << 1 | 1]);
  if (mx[k << 1] != mx[k << 1 | 1])
    mxx[k] = max(
        {mxx[k << 1], mxx[k << 1 | 1], mx[k << 1] + mx[k << 1 | 1] - mx[k]}),
    cm[k] = mx[k << 1] > mx[k << 1 | 1] ? cm[k << 1] : cm[k << 1 | 1];
  else
    mxx[k] = max(mxx[k << 1], mxx[k << 1 | 1]),
    cm[k] = cm[k << 1] + cm[k << 1 | 1];
}
void pushdown(int);
void Tag(int k, int w, int flg) {
  if (w >= mx[k]) return;
  if (w > mxx[k]) {
    tag[k] = w;
    if (flg) seg::modify(1, 1, n, mx[k], -cm[k]);
    mx[k] = w;
    if (flg) seg::modify(1, 1, n, mx[k], cm[k]);
    return;
  }
  pushdown(k);
  Tag(k << 1, w, flg), Tag(k << 1 | 1, w, flg);
  tag[k] = 1e9;
  pushup(k);
}
void pushdown(int k) {
  if (tag[k] > n) return;
  Tag(k << 1, tag[k], 0), Tag(k << 1 | 1, tag[k], 0), tag[k] = 1e9;
}
void modify(int k, int l, int r, int x, int w) {
  if (l == r)
    return seg::modify(1, 1, n, mx[k], -1), mx[k] = w, cm[k] = 1,
                                            seg::modify(1, 1, n, mx[k], 1);
  pushdown(k);
  int mid = (l + r) >> 1;
  if (x <= mid)
    modify(k << 1, l, mid, x, w);
  else
    modify(k << 1 | 1, mid + 1, r, x, w);
  pushup(k);
}
void change(int k, int l, int r, int x, int y, int w) {
  if (x <= l && r <= y) return Tag(k, w, 1);
  int mid = (l + r) >> 1;
  pushdown(k);
  if (x <= mid) change(k << 1, l, mid, x, y, w);
  if (y > mid) change(k << 1 | 1, mid + 1, r, x, y, w);
  pushup(k);
}
void work() {
  for (int i = (1); i <= (n); i++) p[a[i]] = i;
  memset(tag, 0x3f, sizeof(tag));
  for (int i = (1); i <= (n); i++) modify(1, 1, n, i, 0);
  memset(fp, 0, sizeof(fp));
  memset(seg::cnt, 0, sizeof(seg::cnt));
  cur = 0;
  set<int> s;
  for (int i = (1); i <= (n); i++) {
    s.insert(p[i]);
    auto it = s.find(p[i]);
    if (it != s.begin() && *(s.begin()) + 1 < p[i])
      change(1, 1, n, *(s.begin()) + 1, p[i] - 1, p[i] - 1);
    if (next(it) != s.end()) modify(1, 1, n, *next(it), n);
    if (next(it) != s.end() && it != s.begin() && a[*prev(it)] < a[*next(it)])
      seg::modify(1, 1, n, *next(it) - 1, -1);
    if (it == s.begin())
      seg::modify(1, 1, n, p[i] - 1, -1), modify(1, 1, n, p[i], n);
    int c = seg::query(1, 1, n, p[i], n);
    cur += c;
    assert(seg::cnt[1] >= 0);
    assert(c >= 0);
    add(p[i]);
    ans[i] += cur;
  }
}
int main() {
  file();
  read(n);
  for (int i = (1); i <= (n); i++) read(a[i]);
  work();
  reverse(a + 1, a + n + 1);
  work();
  for (int i = (1); i <= (n); i++) printf("%lld\n", ans[i] - i);
  return 0;
}
