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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>
#include <unordered_set>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;


const int S = 1e5 + 7;
const int mod = 1e9 + 7;
int tab[2][S], n, m, k, cnt[11], matrix[2][S];

// inject here

void dfs(int r, int c){
    matrix[r][c] = 0;
    vector<int> vecs = {1, 0, 0, -1, -1, 0, 0, 1};
    for (int i = 0; i < 8; i += 2){
        int new_r = vecs[i] + r;
        int new_c = (vecs[i + 1] + c + n) % n;
        if (!(0 <= new_r && new_r < 2)) continue;
        if (!matrix[new_r][new_c]) continue;
        dfs(new_r, new_c);
    }
   // exit(0);
}

int islands(int beg, int en){
    for (int i = 0; i < 2; i ++){
        for (int j = 0; j < n; j ++){
            matrix[i][j] = (
                beg <= tab[i][j] - 1 &&
                en  >= tab[i][j] - 1
            );
        }
    }

    int res = 0;
    for (int i = 0; i < 2; i ++){
        for (int j = 0; j < n; j ++){
            if (matrix[i][j]){
                res ++;
                dfs(i, j);
            }
        }
    }
    //cout << res << "\n";
    return res;
}

void solve(){
    cin >> n >> k;
    for (int i = 0; i < 2; i ++){
        for (int j = 0; j < n; j ++){
            cin >> tab[i][j];
        }
    } 

    for (int l = 0; l < n * 2; l ++){
        for (int r = l; r < n * 2; r ++){
         //   cout << l << " " << r << endl;
            cnt[islands(l, r)] ++;
        }
    }
    for (int i = 1; i <= k; i ++){
        cout << cnt[i] << " ";
    }
    cout << endl;
}
// 6 + 5 + 4 + 3 + 2 + 1

int main(){
    ios_base::sync_with_stdio(0);
    int t = 1;
  //  cin >> t;
    while (t --)
        solve();

    return 0;
}