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

using namespace std;

#ifdef LOCAL
#include "debug.h"
#define dassert assert
#else
#define debug(...)
#define dassert(...)
#endif

#define x first
#define y second
#define ir(a, x, b) ((a) <= (x) && (x) <= (b))
#define vec vector
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define remin(a, b) a = min(a, b)

using ll = long long;

const int NN = 210;
int dp[NN][NN][2*NN][2][2];
const int INF = 1e9;
void solve(int *a, int *b, int N, int M) {
    // n, m, k, rise?, last == n
    // memset(dp, 0, sizeof(int)*NN*NN*2*NN*2*2);
    rep (n, 0, N+1) rep (m, 0, M+1) rep (k, 0, N+M+1) rep (rise, 0, 2) rep (is_n, 0, 2) {
        dp[n][m][k][rise][is_n] = INF;
    }
    if (N >= 2) {
        dp[2][0][2][a[0] < a[1]][1] = 2;
    }
    dp[1][1][2][a[0] < b[0]][0] = 2;
    dp[1][1][2][b[0] < a[0]][1] = 2;
    if (M >= 2) {
        dp[0][2][2][b[0] < b[1]][0] = 2;
    }
    rep (n, 0, N+1) rep (m, 0, M+1) rep (k, 2, N+M+1) rep (rise, 0, 2) rep (is_n, 0, 2) {
        if (dp[n][m][k][rise][is_n] == INF) continue;
        int last = is_n ? a[n-1] : b[m-1];
        int last_rise = dp[n][m][k][rise][is_n];
        debug(n, m, k, rise, is_n, last, last_rise);
        // take n
        if (n < N) {
            bool new_rise = last < a[n];
            int new_rise_len = (rise == new_rise) ? last_rise+1 : 2;
            int score = max(k, new_rise_len);
            remin(dp[n+1][m][score][new_rise][1], new_rise_len);
        }
        // take m
        if (m < M) {
            bool new_rise = last < b[m];
            int new_rise_len = (rise == new_rise) ? last_rise+1 : 2;
            int score = max(k, new_rise_len);
            remin(dp[n][m+1][score][new_rise][0], new_rise_len);
        }
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int N, M;
    cin >> N >> M;
    vec<int> a(N), b(M);
    rep (i, 0, N) {
        cin >> a[i]; --a[i];
    }
    rep (i, 0, M) {
        cin >> b[i]; --b[i];
    }
    vec<int> ct(N+M+1);
    rep (i, 0, N) rep (j, 0, M) {
        solve(&a[i], &b[j], N-i, M-j);
        rep (n, 1, N-i+1) rep (m, 1, M-j+1) {
            // debug("moved to", i, n, j, m);
            rep (k, 2, N+M+1) {
                rep (x, 0, 2) rep (y, 0, 2) if (dp[n][m][k][x][y] != INF) {
                    ct[k]++;
                    debug(i, n, j, m, k);
                    goto sex;
                }
            }
            // dassert(b);
            sex:;
        }
        // return 0;
    }
    
    rep (i, 1, ct.size()) {
        cout << ct[i] << " ";
    }
    cout << endl;
    return 0;
}