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
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>
#include <ctime>

using namespace std;
typedef long long LL;
#define INF 1000000000
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define FS first
#define SD second
#define MP make_pair
#define ZERO(t) memset(t, 0, sizeof(t))
#define MINUS(t) memset(t, -1, sizeof(t))
#define MOD 1000000007
#define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
#define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))

int UN[200005];
int N[200005][3];
int T[200005][2];

int find(int x){
  return UN[x]==x?x:UN[x]=find(UN[x]); 
}

void join(int x,int y){ 
  UN[find(x)]=find(y);
}

LL result[12];

int CHECK[4];

int check(int n) {
  int res = n;
  FOR(i,0,n) {
    FOR(j,i+1,n) {
      if (CHECK[i] == CHECK[j]) {
        --res;
        break;
      }
    }
  }
  return res;
}

int main() {
  int n, k; scanf("%d%d", &n, &k);
  FOR(i,0,2) {
    FOR(j,0,n) {
      scanf("%d", &T[j][i]);
    }
  }
  FOR(i,0,2) {
    FOR(j,0,n) {
      int v = T[j][i];
      N[v][0] = T[j][(i + 1) % 2];
      N[v][1] = T[(j + 1) % n][i];
      N[v][2] = T[(j - 1 + n) % n][i];
    }
  }
  
  FORE(a,1,2*n) {
    int cur = 0;
    FORE(b,a,2*n) UN[b] = b;
    FORE(b,a,2*n) {
      int cc = 0;
      FOR(i,0,3) {
        int nei = N[b][i];
        if (nei >= a && nei <= b) CHECK[cc++] = find(nei);
      }
      int before = check(cc);
      cc = 0;
      FOR(i,0,3) {
        int nei = N[b][i];
        if (nei >= a && nei <= b) join(nei, b);
      }
      FOR(i,0,3) {
        int nei = N[b][i];
        if (nei >= a && nei <= b) CHECK[cc++] = find(nei);
      }
      CHECK[cc++] = find(b);
      
      int after = check(cc);
      cur += (after - before);
      if (cur <= k) result[cur]++;
    }
  }
  FORE(i,1,k) printf("%lld ", result[i]);
  printf("\n");
}