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
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll

const int MAX_N = 1e5;
int g[2][MAX_N];

int n, k;
int next(int i) {
  return (i+1)%n;
}
int prev(int i) {
  int ret = i-1;
  if (ret < 0) ret += n;
  return ret;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> g[0][i];
  for (int i = 0; i < n; i++) cin >> g[1][i];
  vector<int> ans(2*n+1);
  vector<vector<int>> edg(2*n+1);
  for (int i = 0; i < n; i++) {
    edg[g[0][i]].push_back(g[1][i]);
    edg[g[0][i]].push_back(g[0][next(i)]);
    edg[g[0][i]].push_back(g[0][prev(i)]);
    edg[g[1][i]].push_back(g[0][i]);
    edg[g[1][i]].push_back(g[1][next(i)]);
    edg[g[1][i]].push_back(g[1][prev(i)]);
  }
  for (int l = 1; l <= 2*n; l++) {
    vector<int> P(2*n+1);
    vector<int> act(2*n+1);
    for (int i = 1; i <= 2*n; i++) P[i] = i;
    int res = 0;
    function<int(int)> find = [&] (int i) {
      if (P[i] == i) return i;
      return P[i] = find(P[i]);
    };
    auto join = [&] (int i, int j) {
      P[find(i)] = P[find(j)];
    };
    for (int r = l; r <= 2*n; r++) {
      res++;
      act[r] = 1;
      for (int v : edg[r]) {
        if (act[v] && find(r) != find(v)) {
          res--;
          join(v, r);
        }
      }
      ans[res]++;
    }
  }
  for (int i = 1; i <= k; i++) cout << ans[i] << ' ';
  cout << '\n';
}