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
#include <iostream>
#include <cstring>

using namespace std;

long long p[200000], c[200000], pp[2][100000], r[200000], h[200000];
long long n, k, q, i, ps, mm, m, j, a, b, x,s[3],y, v[11],z;





int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	cin >> n;
	cin >> k;
	for (j = 0; j < 11; j++) v[j] = 0;
	for (i = 0; i < 2; i++)
		for (j = 0; j < n; j++) {
			cin >> a;
			p[a - 1] = j;
			c[a - 1] = i;
			pp[i][j] = a - 1;


		}
	for (i = 0; i < 2 * n; i++) {
		x = 0;
		for (j = i; j < 2 * n; j++) {
			x++;
			a = p[j];
			b = c[j];
			r[j] = j;
			s[0] = pp[(b + 1) % 2][a];
			s[1] = pp[b][(a + 1) % n];
			s[2] = pp[b][(n + a - 1) % n];
			for(m=0;m<3;m++)
				if (s[m] < j && s[m] >= i) {
					a = s[m];
					b = 0;
					while (r[a] != a) {
						h[b] = a;
						b++;
						a = r[a];
					}
					q = j;
					while (r[q] != q) {
						h[b] = q;
						b++;
						q = r[q];
					}
					if (a != q) {
						x--;
						for (y = 0; y < ps; y++)
							r[h[y]] = q;
						r[a] = q;
					}
				}
			//printf("%ld ", i);
			//printf("%ld ", j);
			//printf("%ld \n",x);
			if(x<11)
				v[x] += 1;

			}

			
		}
	for (j = 1; j <= k; j++)
		printf("%ld ", v[j]);
	}