#include #include #include #pragma warning(disable : 4996) using namespace std; const int mod1 = 1000000439; const int mod2 = 1000000637; const int bs = 100000969; int N, M, a, b, c[100009]; long long x, d; char s[800009]; vector h1[100009], h2[100009]; int main() { scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%s", s); while (s[c[i]]) c[i]++; h1[i].resize(c[i] + 1); h2[i].resize(c[i] + 1); for (int j = 0; j < c[i]; j++) { h1[i][j + 1] = (1LL * h1[i][j] * bs + s[j]) % mod1; h2[i][j + 1] = (1LL * h2[i][j] * bs + s[j]) % mod2; } } scanf("%d %lld %lld", &M, &x, &d); long long t = 1LL * N * (N + 1), ret = 0; for (int i = 1; i <= M; i++) { int a = x / (N - 1), b = x % (N - 1); if (a > b) swap(a, b); else b++; int l = 0, r = min(c[a], c[b]) + 1; while (r - l > 1) { int m = (l + r) >> 1; if (h1[a][m] == h1[b][m] && h2[a][m] == h2[b][m]) l = m; else r = m; } ret += l; x = (x + d >= t ? x + d - t : x + d); } printf("%lld\n", ret); return 0; }