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.
//package CodeForces.Round673;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

/**
 * Created by ilya on 07.05.16.
 */

public class C673 {
    public static void main(String[] args) {
        sc sc = new sc();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        int t[] = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
        }
       /* int n = 5000;
        Random r = new Random();
        int t[] = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = r.nextInt(100);
        }
        long start = System.currentTimeMillis();*/
        int[] o =solve(t, n);
//        long end = System.currentTimeMillis();
        for (int i = 1; i < n + 1; i++) {
            out.print(o[i] +" ");
        }
/*        out.println();
        out.println("---------------");
        out.println(((double) (end-start))/1000);*/
        out.close();
    }

    public static int[] solve(int [] t, int n){
        int [] a = new int[n+1];
        HashMap<Integer, Integer> max ;
        //int maxK =0, minL = 5001;
        for (int i = 0; i < n; i++) {
            //a[t[i]]++;
            int maxK =0, minL = 5001;
            max = new HashMap<>();
            for (int j = i; j < n; j++) {
                if (max.containsKey(t[j])) {
                    max.put(t[j], max.get(t[j])+1);
                }
                else {
                    max.put(t[j], 1);
                }
                if (maxK < max.get(t[j])) {
                    maxK = max.get(t[j]);
                    minL = t[j];
                }
                else if (maxK == max.get(t[j]) && minL > t[j]){
                    maxK = max.get(t[j]);
                    minL = t[j];
                }
                a[minL]++;
            }
            //if (t[i] == minL) maxK--;
            //max.put(minL, max.get(minL)-1);
        }
        return a;
        /*int [] a = new int[n+1];
        HashMap<Integer, Integer> min = new HashMap<>();
        for (int j = 0; j < n-1; j++) {
            if (min.containsKey(t[j])) {
                min.put(t[j], min.get(t[j])+1);
            }
            else {
                min.put(t[j], 1);
            }
            ArrayList<Map.Entry<Integer, Integer>> e = new ArrayList<>(min.entrySet());
            Collections.sort(e, (x, y) -> y.getValue() - x.getValue() == 0 ? x.getKey() - y.getKey() : y.getValue() - x.getValue());
            a[e.get(0).getKey()]+=(j*(j+1))/2;
        }

        return a;*/
        /*int [] a = new int[n+1];
        HashMap<Integer, Integer> min;
        for (int i = 0; i < n; i++) {
            min = new HashMap<>();
            min.put(t[i], 1);
            a[t[i]]++;
            for (int j = i+1; j < n; j++) {
                if (min.containsKey(t[j])) {
                    min.put(t[j], min.get(t[j])+1);
                }
                else {
                    min.put(t[j], 1);
                }
                ArrayList<Map.Entry<Integer, Integer>> e = new ArrayList<>(min.entrySet());
                Collections.sort(e, (x, y) -> y.getValue() - x.getValue() == 0 ? x.getKey() - y.getKey() : y.getValue() - x.getValue());
                a[e.get(0).getKey()]++;
            }
        }
        return a;*/
    }

    public static class sc {
        BufferedReader br;
        StringTokenizer st;

        public sc() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        Integer nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

