Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.

For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.

There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.

The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.

Output

Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.

Examples

Input

4
1 2 1 2


Output

7 3 0 0 


Input

3
1 1 1


Output

6 0 0 

Note

In the first sample, color 2 is dominant in three intervals:

  * An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color. 
  * An interval [4, 4] contains one ball, with color 2 again. 
  * An interval [2, 4] contains two balls of color 2 and one ball of color 1. 



There are 7 more intervals and color 1 is dominant in all of them.
#include <bits/stdc++.h>
using namespace std;
struct item {
  int key, prior;
  int max, keymax;
  int cnt;
  int open;
  item *l, *r;
  item() {}
  item(int key, int prior, int open)
      : key(key),
        prior(prior),
        l(NULL),
        r(NULL),
        max(open),
        keymax(key),
        open(open),
        cnt(1) {}
};
typedef item* pitem;
int cnt(pitem t) { return t ? t->cnt : 0; }
void print(pitem t) {
  if (!t) return;
  print(t->l);
  cout << ' ' << t->key << '-' << t->cnt << ' ' << t->max << '-' << t->keymax
       << ' ';
  print(t->r);
}
void push(pitem it) {}
void upd_cnt(pitem t) {
  if (t) {
    t->cnt = 1 + cnt(t->l) + cnt(t->r);
  } else {
    return;
  }
  t->max = t->open;
  t->keymax = t->key;
  if (t->l and (t->l->max > t->max or
                (t->l->max == t->max and t->l->keymax < t->keymax))) {
    t->max = t->l->max;
    t->keymax = t->l->keymax;
  }
  if (t->r and (t->r->max > t->max or
                (t->r->max == t->max and t->r->keymax < t->keymax))) {
    t->max = t->r->max;
    t->keymax = t->r->keymax;
  }
}
void merge(pitem& t, pitem l, pitem r) {
  if (!l || !r) {
    t = l ? l : r;
    upd_cnt(l);
    upd_cnt(r);
  } else {
    if (l->prior > r->prior)
      merge(l->r, l->r, r), t = l;
    else
      merge(r->l, l, r->l), t = r;
  }
  upd_cnt(t);
}
void split(pitem t, pitem& l, pitem& r, int key, int add = 0) {
  if (!t) return void(l = r = 0);
  int cur_key = add + cnt(t->l);
  if (key <= t->key)
    split(t->l, l, t->l, key, add), r = t;
  else
    split(t->r, t->r, r, key, add + 1 + cnt(t->l)), l = t;
  upd_cnt(t);
}
int main() {
  int n;
  cin >> n;
  vector<int> c(n);
  int x;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    c[i] = x - 1;
  }
  vector<int> ans(n);
  vector<int> rr(n);
  for (int i = 0; i < n; ++i) {
    rr[i] = rand();
  }
  for (int l = 0; l < n; ++l) {
    for (int j = 0; j < n; ++j) {
      rr[j] = 0;
    }
    int curmax = -1;
    int curkey = 0;
    for (int r = l; r < n; ++r) {
      rr[c[r]]++;
      if ((rr[c[r]] > curmax) or (rr[c[r]] == curmax and c[r] < curkey)) {
        curkey = c[r];
        curmax = rr[c[r]];
      }
      ans[curkey]++;
    }
  }
  for (int i = 0; i < n; ++i) {
    printf("%d ", ans[i]);
  }
  return 0;
}
