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 = 1e6 + 7;
int n, p[N], g[N], f[N];
long long ans;
inline int read() {
  int num = 0;
  char g = getchar();
  while (g < 48 || 57 < g) g = getchar();
  while (47 < g && g < 58)
    num = (num << 1) + (num << 3) + g - 48, g = getchar();
  return num;
}
inline void write(long long v) {
  if (v > 9) write(v / 10);
  putchar(v % 10 + '0');
}
namespace t1 {
int a, b, c, p, lt[N], rt[N], pos[N];
struct node {
  int v1, v2, v3, v4, c1, c2;
} e[N];
inline void build(int l, int r, int t) {
  lt[t] = l, rt[t] = r;
  if (l == r) {
    pos[l] = t;
    return;
  }
  int d = (l + r) >> 1;
  build(l, d, t << 1), build(d + 1, r, t << 1 | 1);
}
inline void getl(int t, int k) {
  if (lt[t] == rt[t]) {
    if (e[t].v1 > k) {
      if (a == 0) a = e[t].v1;
      b++;
      c = e[t].v1;
    }
    return;
  }
  if (e[t].v1 > k) {
    if (a == 0) a = e[t].v1;
    b += e[t].c1 + e[t].c2;
    c = e[t].v4;
  } else if (e[t].v2 > k) {
    getl(t << 1, k);
    if (a == 0) a = e[t].v2;
    b += e[t].c2;
    c = e[t].v4;
  } else if (e[t].v2 == 0)
    getl(t << 1, k);
  else if (e[t].v1 == 0)
    getl(t << 1 | 1, k);
  else if (e[t].v4 > k)
    getl(t << 1 | 1, k);
}
inline void adds(int u, int k) {
  u = pos[u];
  e[u].c1 = 1, e[u].v1 = k, e[u].v2 = k, e[u].v3 = k, e[u].v4 = k, u = u / 2;
  while (u > 0) {
    e[u].c1 = e[u << 1].c1 + e[u << 1].c2, e[u].v1 = e[u << 1].v1,
    e[u].v3 = e[u << 1].v4;
    if (!e[u << 1].v1) e[u].v1 = e[u << 1].v2;
    a = 0, b = 0, c = e[u].v3;
    getl(u << 1 | 1, e[u << 1].v4);
    e[u].v2 = a, e[u].c2 = b, e[u].v4 = c;
    u = u >> 1;
  }
}
inline void getsum(int l, int r, int t, int ql, int qr) {
  if (l == ql && r == qr) {
    getl(t, c);
    return;
  }
  int d = (l + r) >> 1;
  if (ql <= d) getsum(l, d, t << 1, ql, min(qr, d));
  if (d + 1 <= qr) getsum(d + 1, r, t << 1 | 1, max(d + 1, ql), qr);
}
inline void getnxt(int l, int r, int t, int ql, int qr, int c) {
  if (l == ql && r == qr) {
    if (l == r) {
      if (e[t].v1 > c) p = l;
      return;
    }
    int d = (l + r) >> 1;
    if (e[t].v3 > c) getnxt(l, d, t << 1, l, d, c);
    if (p > 0)
      return;
    else if (e[t].v4 > c)
      getnxt(d + 1, r, t << 1 | 1, d + 1, r, c);
    return;
  }
  int d = (l + r) >> 1;
  if (ql <= d) getnxt(l, d, t << 1, ql, min(qr, d), c);
  if (p > 0) return;
  if (d + 1 <= qr) getnxt(d + 1, r, t << 1 | 1, max(d + 1, ql), qr, c);
}
}  // namespace t1
namespace t2 {
int a, b, c, p, lt[N], rt[N], pos[N];
struct node {
  int v1, v2, v3, v4, c1, c2;
} e[N];
inline void build(int l, int r, int t) {
  lt[t] = l, rt[t] = r;
  if (l == r) {
    pos[l] = t;
    return;
  }
  int d = (l + r) >> 1;
  build(l, d, t << 1), build(d + 1, r, t << 1 | 1);
}
inline void getl(int t, int k) {
  if (lt[t] == rt[t]) {
    if (e[t].v1 > k) {
      if (a == 0) a = e[t].v1;
      b++;
      c = e[t].v1;
    }
    return;
  }
  if (e[t].v1 > k) {
    if (a == 0) a = e[t].v1;
    b += e[t].c1 + e[t].c2;
    c = e[t].v4;
  } else if (e[t].v2 > k) {
    getl(t << 1, k);
    if (a == 0) a = e[t].v2;
    b += e[t].c2;
    c = e[t].v4;
  } else if (e[t].v2 == 0)
    getl(t << 1, k);
  else if (e[t].v1 == 0)
    getl(t << 1 | 1, k);
  else if (e[t].v4 > k)
    getl(t << 1 | 1, k);
}
inline void adds(int u, int k) {
  u = pos[u];
  e[u].c1 = 1, e[u].v1 = k, e[u].v2 = k, e[u].v3 = k, e[u].v4 = k, u = u / 2;
  while (u > 0) {
    e[u].c1 = e[u << 1].c1 + e[u << 1].c2, e[u].v1 = e[u << 1].v1,
    e[u].v3 = e[u << 1].v4;
    if (!e[u << 1].v1) e[u].v1 = e[u << 1].v2;
    a = 0, b = 0, c = e[u].v3;
    getl(u << 1 | 1, e[u << 1].v4);
    e[u].v2 = a, e[u].c2 = b, e[u].v4 = c;
    u = u >> 1;
  }
}
inline void getsum(int l, int r, int t, int ql, int qr) {
  if (l == ql && r == qr) {
    getl(t, c);
    return;
  }
  int d = (l + r) >> 1;
  if (ql <= d) getsum(l, d, t << 1, ql, min(qr, d));
  if (d + 1 <= qr) getsum(d + 1, r, t << 1 | 1, max(d + 1, ql), qr);
}
inline void getnxt(int l, int r, int t, int ql, int qr, int c) {
  if (l == ql && r == qr) {
    if (l == r) {
      if (e[t].v1 > c) p = l;
      return;
    }
    int d = (l + r) >> 1;
    if (e[t].v3 > c) getnxt(l, d, t << 1, l, d, c);
    if (p > 0)
      return;
    else if (e[t].v4 > c)
      getnxt(d + 1, r, t << 1 | 1, d + 1, r, c);
    return;
  }
  int d = (l + r) >> 1;
  if (ql <= d) getnxt(l, d, t << 1, ql, min(qr, d), c);
  if (p > 0) return;
  if (d + 1 <= qr) getnxt(d + 1, r, t << 1 | 1, max(d + 1, ql), qr, c);
}
}  // namespace t2
inline int lowbit(int v) { return (v & (-v)); }
inline void addx(int v) {
  while (v <= n) f[v]++, v += lowbit(v);
}
inline int getval(int v) {
  int sum = 0;
  while (v > 0) sum += f[v], v -= lowbit(v);
  return sum;
}
inline int getsum(int l, int r) {
  if (l > r) swap(l, r);
  l++, r--;
  if (l > r) return 0;
  return getval(r) - getval(l - 1);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) p[i] = read(), g[p[i]] = i;
  t1::build(1, n, 1), t2::build(1, n, 1);
  for (int i = 1; i <= n; i++) {
    ans += i;
    t1::a = 0, t1::b = 0, t1::c = 0, t1::getsum(1, n, 1, n - g[i] + 1, n);
    t2::a = 0, t2::b = 0, t2::c = 0, t2::getsum(1, n, 1, g[i], n);
    int l1 = t1::b, l2 = t2::b;
    ans -= 1ll * l1 * l2;
    if (l1 <= l2) {
      int x = t1::a, y = 0;
      while (x > 0) {
        t1::p = 0, t1::getnxt(1, n, 1, n - g[x] + 1, n, x), y = n - t1::p + 1;
        if (t1::p == 0) y = 0;
        t2::a = 0, t2::b = 0, t2::c = x, t2::getsum(1, n, 1, g[i], n),
        ans -= 1ll * getsum(g[x], y) * t2::b;
        int lt = g[i], rt = n, ct = x, pos = g[i];
        while (lt <= rt) {
          int d = (lt + rt) >> 1;
          t2::p = 0, t2::getnxt(1, n, 1, g[i], d, x);
          if (t2::p == 0)
            pos = d, lt = d + 1;
          else
            rt = d - 1;
        }
        t2::a = 0, t2::b = 0, t2::c = 0, t2::getsum(1, n, 1, g[i], pos);
        ans = ans - getsum(g[i] - 1, pos + 1) + t2::b;
        if (y == 0) break;
        x = p[y];
      }
    } else {
      int x = t2::a, y = 0;
      while (x > 0) {
        t2::p = 0, t2::getnxt(1, n, 1, g[x], n, x), y = t2::p;
        if (t2::p == 0) y = n + 1;
        t1::b = 0, t1::c = x, t1::getsum(1, n, 1, n - g[i] + 1, n),
        ans -= 1ll * getsum(g[x], y) * t1::b;
        int lt = 1, rt = g[i], ct = x, pos = g[i];
        while (lt <= rt) {
          int d = (lt + rt) >> 1;
          t1::p = 0, t1::getnxt(1, n, 1, n - g[i] + 1, n - d + 1, x);
          if (t1::p == 0)
            pos = d, rt = d - 1;
          else
            lt = d + 1;
        }
        t1::a = 0, t1::b = 0, t1::c = 0,
        t1::getsum(1, n, 1, n - g[i] + 1, n - pos + 1);
        ans = ans - getsum(pos - 1, g[i] + 1) + t1::b;
        if (y == n + 1) break;
        x = p[y];
      }
    }
    t1::adds(n - g[i] + 1, i);
    t2::adds(g[i], i), addx(g[i]);
    write(ans), putchar('\n');
  }
}
