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
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 200 + 5;

int dp[nmax][nmax][85][2][2];

int freq[nmax * 2];

signed main() {
  cin.tie(0) -> sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> b(m);
  
  for(auto &x : a) cin >> x;
  for(auto &x : b) cin >> x;
  
  int limit = n + m;
  if(limit >= 80)
    limit = 7;
  
  for(int l_begin = 0; l_begin < n; l_begin++) {
    //cerr << "uwu " << l_begin << '\n';
    for(int r_begin = 0; r_begin < m; r_begin++) {
      
      for(int i = l_begin; i <= n; i++)
        for(int j = r_begin; j <= m; j++)
          for(int k = 2; k <= limit; k++)
            for(int a = 0; a < 2; a++)
              for(int b = 0; b < 2; b++)
                dp[i][j][k][a][b] = nmax + 10000;
      
      if(l_begin + 2 <= n)
        dp[l_begin + 2][r_begin][2][a[l_begin] < a[l_begin + 1]][0] = 2;
      if(r_begin + 2 <= m)
        dp[l_begin][r_begin + 2][2][b[r_begin] < b[r_begin + 1]][1] = 2;
      if(l_begin + 1 <= n && r_begin + 1 <= m) {
        dp[l_begin + 1][r_begin + 1][2][b[r_begin] < a[l_begin]][0] = 2;
        dp[l_begin + 1][r_begin + 1][2][a[l_begin] < b[r_begin]][1] = 2;
      }
      
      for(int sum = l_begin + r_begin + 2; sum <= n + m; sum++) {
        for(int l = max(sum - m, l_begin); l <= n; l++) {
          int r = sum - l;
          if(r > m) continue;
          if(r < r_begin) break;
          for(int accumulate = 2; accumulate <= limit; accumulate++) {
            for(int dir = 0; dir < 2; dir++) {
              for(int last_from = 0; last_from < 2; last_from++) {
                if((last_from == 0 && l == 0) || (last_from == 1 && r == 0)) continue;
                int lastv = (last_from == 0? a[l - 1] : b[r - 1]);
                dp[l + 1][r][dir == (lastv < a[l])? accumulate + 1 : 2][lastv < a[l]][0] = min(dp[l + 1][r][dir == (lastv < a[l])? accumulate + 1 : 2][lastv < a[l]][0], 
                                                                                                  max(dp[l][r][accumulate][dir][last_from], dir == (lastv < a[l])? accumulate + 1 : 2));
                
                dp[l][r + 1][dir == (lastv < b[r])? accumulate + 1 : 2][lastv < b[r]][1] = min(dp[l][r + 1][dir == (lastv < b[r])? accumulate + 1 : 2][lastv < b[r]][1], 
                                                                                                  max(dp[l][r][accumulate][dir][last_from], dir == (lastv < b[r])? accumulate + 1 : 2));
              }
            }
          }
        }
      }
      
      for(int l = l_begin + 1; l <= n; l++)
        for(int r = r_begin + 1; r <= m; r++) {
          int mn = nmax * 100 + 5;
          for(int accumulate = 2; accumulate <= limit; accumulate++) {
            for(int a = 0; a < 2; a++)
              for(int b = 0; b < 2; b++) {
                mn = min(mn, dp[l][r][accumulate][a][b]);
              }
          }
          
          //cerr << l_begin + 1 << ' ' << l << '\t' << r_begin + 1 << ' ' << r << " \t == \t " << mn << '\n';
          
          freq[mn]++;
        }
    }
  }
  
  for(int i = 1; i <= n + m; i++) 
    cout << freq[i] << ' ';
  cout << '\n';
  
  
}
    
/**
  Anul asta nu se da centroid
  -- Rugaciunile mele
*/