#include <bits/stdc++.h>
using namespace std;
const int maxx = 2005;
const long long mod = 1e9 + 7;
int a[maxx], b[maxx];
long long dp[maxx][maxx];
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) {
    long long cnt = 0;
    for (int j = 1; j <= m; j++) {
      cnt += dp[i - 1][j], cnt %= mod;
      if (a[i] == b[j]) {
        dp[i][j] = cnt + 1, dp[i][j] %= mod;
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
  long long ans = 1;
  for (int i = 1; i <= m; i++) {
    cout << dp[n][i] << endl;
    ans += dp[n][i], ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
