1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <cstdio>

int n,inp[200001],i,j,bfsT[200001],first,last,wyn,lastlayerind,currlayerval;

char color[200001];

struct node{
	int val;
	node *next;
};

node *tempnode;

node* graph[200001];


void countWyn(int start){
	for(j=0;j<=n;j++)
		color[j]=0;
	color[start]=1;
	bfsT[0]=start;
	first=0;last=0;lastlayerind=0;currlayerval=1;wyn=0;
	while(first<=last){
		tempnode = graph[bfsT[first]];
		while(tempnode != NULL){
			if(color[tempnode->val]==0){
				color[tempnode->val]++;
				bfsT[++last]=tempnode->val;
				wyn+=currlayerval;
		//		printf("+ %d Dodaje wyn %d\n",tempnode->val,currlayerval);
			}
			tempnode=tempnode->next;
		}
		//
		first++;
		if(lastlayerind<first){
			lastlayerind=last;
			currlayerval++;
		}
	}
	printf("%d ",wyn);
	
}

int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&inp[i]);
		graph[i]=NULL;
	}
	// create graph
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(i!=j){
				if(((i<j)&&(inp[i]>inp[j]))
				||((i>j)&&(inp[i]<inp[j]))){
					tempnode = new node;
					tempnode->val = j;
					tempnode->next=graph[i];
					graph[i]=tempnode;
			//		printf("nod %d %d,\n",i,j);
				}
			}
		}
	//	printf("==============================\n");
	}
	
	for(i=1;i<=n;i++){
		countWyn(i);
	}
		
	return 0;
}