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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include <bits/stdc++.h>

using namespace std;

int get_value(vector<int> array, int bottom_value, int top_value){
    int result = 0;
    int tmp = 1;
    for(int i = 0; i < 6; i++){
        if(array[i] >= top_value or array[i] < bottom_value){
            
            result += tmp;
        }
        tmp *= 2;
    }
    return result;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    vector<vector<int>> canvas;
    vector<int> tmp;
    for(int i = 0; i < n; i++){
        tmp.push_back(0);
    }
    canvas.push_back(tmp);
    vector<int> tmp1 = tmp;
    canvas.push_back(tmp1);

    vector<vector<int>> neighbours;
    
    for(int i = 0; i < 2*n; i++){
        vector<int> tmp;
        // tmp.push_back(0);
        // tmp.push_back(0);
        // tmp.push_back(0);

        neighbours.push_back(tmp);
    }
    
    vector<vector<int>> results;
    for(int i = 0; i < 2*n; i++){
        vector<int> tmp;
        for(int j = 0; j < 2*n+1; j++){
            tmp.push_back(0);
        }
        results.push_back(tmp);
    }

    for(int i = 0; i < n; i++){
        int value;
        cin >> value;
        canvas[0][i] = value - 1;
    }
    for(int i = 0; i < n; i++){
        int value;
        cin >> value;
        canvas[1][i] = value - 1;
    }

    for(int i = 0; i < n; i++){
        neighbours[canvas[0][i]].push_back(canvas[1][(i-1 + n)%n]);
        neighbours[canvas[0][i]].push_back(canvas[1][i]);
        neighbours[canvas[0][i]].push_back(canvas[1][(i+1)%n]);

        neighbours[canvas[1][i]].push_back(canvas[0][(i-1 + n)%n]);
        neighbours[canvas[1][i]].push_back(canvas[0][i]);
        neighbours[canvas[1][i]].push_back(canvas[0][(i+1)%n]);
    }


    for(int i = 0; i < 2*n; i++){
        vector<bool> heap;
        for(int j = 0; j < 2*n; j++)
            heap.push_back(false);
        
        for(int j = 0; j < i; j++) {
            if(heap[j]){
                vector<int> tmp_neighbours;
                tmp_neighbours.push_back(neighbours[j][0]);
                tmp_neighbours.push_back(neighbours[j][1]);
                tmp_neighbours.push_back(neighbours[j][2]);
                tmp_neighbours.push_back(neighbours[neighbours[j][1]][0]);
                tmp_neighbours.push_back(neighbours[neighbours[j][1]][1]);
                tmp_neighbours.push_back(neighbours[neighbours[j][1]][2]);
                int value = get_value(tmp_neighbours, j, 2*n);

                if(
                    value == 1 ||
                    value == 2 ||
                    value == 4 ||
                    value == 12 ||
                    value == 3 ||
                    value == 33 ||
                    value == 6 ||
                    value == 13 ||
                    value == 7 ||
                    value == 37
                )
                    results[i][2*n] += 1;
                else if(
                    value == 42 ||
                    value == 43 ||
                    value == 46 ||
                    value == 47
                )
                    results[i][2*n] -= 1;
                else if(value == 5)
                    results[i][2*n] += 2;
            }
            for(int x = 0; x < 3; x++)
                heap[neighbours[j][x]] = true;
        }

        for(int j = 2*n - 1; j > i - 1; j--){
            results[i][j] = results[i][j+1];

            if(heap[j]){
                vector<int> tmp_neighbours;
                tmp_neighbours.push_back(neighbours[j][0]);
                tmp_neighbours.push_back(neighbours[j][1]);
                tmp_neighbours.push_back(neighbours[j][2]);
                tmp_neighbours.push_back(neighbours[neighbours[j][1]][0]);
                tmp_neighbours.push_back(neighbours[neighbours[j][1]][1]);
                tmp_neighbours.push_back(neighbours[neighbours[j][1]][2]);
                int value = get_value(tmp_neighbours, i, j);

                if(
                    value == 1  + 16 ||
                    value == 2  + 16 ||
                    value == 4  + 16 ||
                    value == 12 + 16 ||
                    value == 3  + 16 ||
                    value == 33 + 16 ||
                    value == 6  + 16 ||
                    value == 13 + 16 ||
                    value == 7  + 16 ||
                    value == 37 + 16 
                )
                    results[i][j] += 1;
                else if(
                    value == 42 + 16 ||
                    value == 43 + 16 ||
                    value == 46 + 16 ||
                    value == 47 + 16
                )
                    results[i][j] -= 1;
                else if(value == 5 + 16)
                    results[i][j] += 2;
            }
            for(int x = 0; x < 3; x++)
                heap[neighbours[j][x]] = true;
        }
    }

    // for(int i = 0; i < 2*n; i++){
    //     for(int j = 0; j < 2*n+1; j++){
    //         cout << results[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    vector<int> final_results;
    for(int i = 0; i < k+1; i++)
        final_results.push_back(0);

    for(int i = 0; i < 2*n + 1; i++){
        for(int j = 2*n; j > i; j--){
            if(results[i][j] <= k)
                final_results[results[i][j]] += 1;
        }
    }

    for(int i = 1; i < k+1; i++){
        if(i == 1)
            cout << final_results[0] + final_results[1] << " ";
        else
            cout << final_results[i] << " ";
    }
    cout << endl;


    return 0;
}