#include void Z_algorithm(char S[], int Z[]) { int i, j, k, l; for (l = 0; S[l] != 0; l++); Z[0] = l; for (i = 1, j = 0; i < l; i++) { for (; i + j < l && S[i+j] == S[j]; j++); Z[i] = j; if (j == 0) continue; for (k = 1; k < j && k + Z[k] < j; k++) Z[i+k] = Z[k]; i += k - 1; j -= k; } } long long div_mod(long long x, long long y, long long z) { if (x % y == 0) return x / y; else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y; } #define NTT_MAX 22 #define NTT_d_MAX (1 << NTT_MAX) const int Mod = 998244353, bit[24] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608}, bit_inv[24] = {1, 499122177, 748683265, 873463809, 935854081, 967049217, 982646785, 990445569, 994344961, 996294657, 997269505, 997756929, 998000641, 998122497, 998183425, 998213889, 998229121, 998236737, 998240545, 998242449, 998243401, 998243877, 998244115, 998244234}, root[24] = {1, 998244352, 911660635, 372528824, 929031873, 452798380, 922799308, 781712469, 476477967, 166035806, 258648936, 584193783, 63912897, 350007156, 666702199, 968855178, 629671588, 24514907, 996173970, 363395222, 565042129, 733596141, 267099868, 15311432}, root_inv[24] = {1, 998244352, 86583718, 509520358, 337190230, 87557064, 609441965, 135236158, 304459705, 685443576, 381598368, 335559352, 129292727, 358024708, 814576206, 708402881, 283043518, 3707709, 121392023, 704923114, 950391366, 428961804, 382752275, 469870224}; void NTT_inline(int kk, int a[], int x[]) { int h, hh, i, ii, j, jj, k, l, r = bit[kk], d = bit[kk-1], tmpp, cur, prev; int *pi, *pii, *pj, *pjj; static int y[2][NTT_d_MAX]; long long tmp; for (i = 0; i < r; i++) y[0][i] = a[i]; for (k = 1, kk--, cur = 1, prev = 0; kk >= 0; k++, kk--, cur ^= 1, prev ^= 1) { for (h = 0, tmp = 1; h << (kk + 1) < r; h++, tmp = tmp * root[k] % Mod) { for (hh = 0, pi = &(y[cur][h<= Mod) *pi -= Mod; *pii = *pj - tmpp; if (*pii < 0) *pii += Mod; } } } for (i = 0; i < r; i++) x[i] = y[prev][i]; } void NTT_reverse_inline(int kk, int a[], int x[]) { int h, hh, i, ii, j, jj, k, l, r = bit[kk], d = bit[kk-1], tmpp, cur, prev; int *pi, *pii, *pj, *pjj; static int y[2][NTT_d_MAX]; long long tmp; for (i = 0; i < r; i++) y[0][i] = a[i]; for (k = 1, kk--, cur = 1, prev = 0; kk >= 0; k++, kk--, cur ^= 1, prev ^= 1) { for (h = 0, tmp = 1; h << (kk + 1) < r; h++, tmp = tmp * root_inv[k] % Mod) { for (hh = 0, pi = &(y[cur][h<= Mod) *pi -= Mod; *pii = *pj - tmpp; if (*pii < 0) *pii += Mod; } } } for (i = 0; i < r; i++) x[i] = y[prev][i]; } #define NTT_THR 70 // Compute c[0-dc] = a[0-da] * b[0-db] (naive) void FPS_prod_naive(int da, int db, int dc, int a[], int b[], int c[]) { int i, j, sa, sb; static int supp_a[NTT_d_MAX], supp_b[NTT_d_MAX]; static long long tmp[NTT_d_MAX]; for (i = 0, sa = 0; i <= da; i++) if (a[i] != 0) supp_a[sa++] = i; for (i = 0, sb = 0; i <= db; i++) if (b[i] != 0) supp_b[sb++] = i; for (i = 0; i <= dc; i++) tmp[i] = 0; for (i = 0; i < sa; i++) for (j = 0; j < sb && supp_a[i] + supp_b[j] <= dc; j++) tmp[supp_a[i] + supp_b[j]] += (long long)a[supp_a[i]] * b[supp_b[j]] % Mod; for (i = 0; i <= dc; i++) c[i] = tmp[i] % Mod; } // Compute c[0-dc] = a[0-da] * b[0-db] (NTT) void FPS_prod_NTT(int da, int db, int dc, int a[], int b[], int c[]) { int i, k; static int aa[NTT_d_MAX], bb[NTT_d_MAX], cc[NTT_d_MAX]; for (k = 0; bit[k] <= da + db; k++); for (i = 0; i <= da; i++) aa[i] = a[i]; for (i = da + 1; i < bit[k]; i++) aa[i] = 0; for (i = 0; i <= db; i++) bb[i] = b[i]; for (i = db + 1; i < bit[k]; i++) bb[i] = 0; static int x[NTT_d_MAX], y[NTT_d_MAX], z[NTT_d_MAX]; NTT_inline(k, aa, x); if (db == da) { for (i = 0; i <= da; i++) if (a[i] != b[i]) break; if (i <= da) NTT_inline(k, bb, y); else for (i = 0; i < bit[k]; i++) y[i] = x[i]; } else NTT_inline(k, bb, y); for (i = 0; i < bit[k]; i++) z[i] = (long long)x[i] * y[i] % Mod; NTT_reverse_inline(k, z, cc); for (i = 0; i <= dc; i++) c[i] = (long long)cc[i] * bit_inv[k] % Mod; } // Compute c[0-dc] = a[0-da] * b[0-db] void FPS_prod(int da, int db, int dc, int a[], int b[], int c[]) { int i, sa, sb; if (da > dc) da = dc; if (db > dc) db = dc; for (i = 0, sa = 0; i <= da && sa <= NTT_THR; i++) if (a[i] != 0) sa++; for (i = 0, sb = 0; i <= db && sb <= NTT_THR; i++) if (b[i] != 0) sb++; if (sa <= NTT_THR || sb <= NTT_THR) FPS_prod_naive(da, db, dc, a, b, c); else FPS_prod_NTT(da, db, dc, a, b, c); } int main() { int N, M, K; char S[500001], T[500001]; scanf("%d %d %d", &N, &M, &K); scanf("%s", S); scanf("%s", T); int i, Z[1000001]; char R[1000001]; for (i = 0; i < M; i++) R[i] = (T[i] >= 'A' && T[i] <= 'Z')? T[i]: T[i] - 'a' + 'A'; for (i = 0; i < N; i++) R[i+M] = (S[i] >= 'A' && S[i] <= 'Z')? S[i]: S[i] - 'a' + 'A'; R[N+M] = 0; Z_algorithm(R, Z); int a[500001] = {}, b[500001] = {}, c[1000001]; for (i = 0; i < N; i++) a[i] = (S[i] >= 'A' && S[i] <= 'Z')? 1: Mod - 1; for (i = 0; i < M; i++) b[M-i-1] = (T[i] >= 'A' && T[i] <= 'Z')? 1: Mod - 1; FPS_prod(N - 1, M - 1, N + M - 2, a, b, c); for (i = 0; i <= N + M - 2; i++) if (c[i] >= 1000000) c[i] -= Mod; int ans = 0; for (i = 0; i <= N - M; i++) if (Z[i+M] >= M && c[i+M-1] < M && c[i+M-1] >= M - K * 2) ans++; printf("%d\n", ans); fflush(stdout); return 0; }