#include <bits/stdc++.h>
using namespace std;
long long int dp0[2005][2005];
long long int dp1[2005][2005];
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long int> S(N + 1);
  vector<long long int> T(M + 1);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  dp0[0][0] = 1;
  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < M + 1; j++) {
      dp0[i + 1][j] += dp0[i][j];
      dp0[i + 1][j] = (dp0[i + 1][j] + 1000000007) % 1000000007;
      dp1[i][j] = dp0[i][j];
      dp1[i][j] = (dp1[i][j] + 1000000007) % 1000000007;
      dp1[i][j + 1] += dp1[i][j];
      dp1[i][j + 1] = (dp1[i][j + 1] + 1000000007) % 1000000007;
      if (S[i] == T[j]) {
        dp0[i + 1][j + 1] += dp0[i][j];
        dp0[i + 1][j + 1] = (dp0[i + 1][j + 1] + 1000000007) % 1000000007;
      }
    }
  }
  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < M + 1; j++) {
      cout << dp1[i][j] << " ";
    }
    cout << endl;
  }
  cout << dp1[N][M] << endl;
  return 0;
}
