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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

#define int short
bool chmin(int& x, int y) { return y < x ? x = y, true : false; }

const int N = 101;
const int INF = 1010;
int n, m;
int a[N], b[N];
signed ans[2 * N];
int dp[N][N][2 * N][2][2];

void solve(int sa, int sb) {
  for (int i = 0; i <= n - sa; i++) {
    for (int j = 0; j <= m - sb; j++) {
        for (int k = 0; k <= i + j; k++) {
          for (int x = 0; x < 2; x++) {
            for (int y = 0; y < 2; y++) {
            dp[i][j][k][x][y] = INF;
          }
        }
      }
    }
  }
  dp[1][0][1][0][0] = 1;
  dp[1][0][1][0][1] = 1;
  dp[0][1][1][1][0] = 1;
  dp[0][1][1][1][1] = 1;
  for (int i = 0; i <= n - sa; i++) {
    for (int j = 0; j <= m - sb; j++) {
      for (int k = 0; k <= i + j; k++) {
        for (int x = 0; x < 2; x++) {
          for (int y = 0; y < 2; y++) {
            if (dp[i][j][k][x][y] == INF) {
              continue;
            }
            int lst = x == 0 ? a[sa + i - 1] : b[sb + j - 1];
            if (i < n - sa) {
              int d = lst > a[sa + i];
              int kk = d == y ? k + 1 : 2;
              chmin(dp[i + 1][j][kk][0][d], max(dp[i][j][k][x][y], kk));
            }
            if (j < m - sb) {
              int d = lst > b[sb + j];
              int kk = d == y ? k + 1 : 2;
              chmin(dp[i][j + 1][kk][1][d], max(dp[i][j][k][x][y], kk));
            }
          }
        }
      }
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      solve(i, j);
      for (int k = 1; k <= n - i; k++) {
        for (int l = 1; l <= m - j; l++) {
          int mn = INF;
          for (int x = 0; x < mn; x++) {
            for (int y = 0; y < 2; y++) {
              for (int z = 0; z < 2; z++) {
                chmin(mn, dp[k][l][x][y][z]);
              }
            }
          }
          ans[mn] += 1;
        }
      }
    }
  }
  for (int i = 1; i <= n + m; i++) {
    cout << ans[i] << " \n"[i == n + m];
  }
}