scanf("%d%d", &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++) ap[a[i]] = 0; for (int i = 1; i <= n; i++) { if (ap[a[i]]) pa[i] = ap[a[i]]; ap[a[i]] = i; } for (int i = 1; i <= n; i++) ap[a[i]] = 0; for (int i = n; i >= 1; i--) { if (ap[a[i]]) sa[i] = ap[a[i]]; ap[a[i]] = i; }
i64 t = 0; for (int i = 1; i <= m; i++) ap[b[i]] = 0; for (int i = 1; i <= m; i++) { if (ap[b[i]]) { (t += pw[i] * (i - ap[b[i]]) % P) %= P; } ap[b[i]] = i; } i64 s = 0; for (int i = 1; i <= m; i++) { if (pa[i]) (s += pw[i] * (i - pa[i]) % P) %= P; }
tp = 0; for (int i = 1; i + m - 1 <= n; i++) { if (s == t) ans[++tp] = i; if (i + m - 1 == n) break; if (sa[i] && sa[i] <= i + m - 1) { (s += P - pw[sa[i] - i + 1] * (sa[i] - i) % P) %= P; } s = (s * iB) % P; if (i < pa[i + m]) { (s += pw[m] * (i + m - pa[i + m]) % P) %= P; } }
printf("%d\n", tp); for (int i = 1; i <= tp; i++) { printf("%d%c", ans[i], " \n"[i == tp]); } } return0; }