#include using namespace std; typedef long long ll; const unsigned P = 1000000007U; struct RollingHash { int n; vector pow, phash; RollingHash() {}; template RollingHash(const T& s, unsigned long long Q = 1) { n = s.size(); pow.resize(n + 1); phash.resize(n + 1); pow[0] = Q; phash[0] = 0; for(int i = 0; i < n; i++) { pow[i + 1] = pow[i] * P; phash[i + 1] = s[i] + phash[i] * P; } } unsigned long long get(int i) const { return phash[i]; } unsigned long long get(int i, int j) const { return get(j) - get(i) * pow[j - i]; } }; RollingHash h[100000]; string s[100000]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, M, x, d; cin >> N; for(int i = 0; i < N; i++) { cin >> s[i]; h[i] = RollingHash(s[i]); } cin >> M >> x >> d; ll ans = 0; for(int k = 0; k < M; k++) { int i = (x / (N - 1)) + 1; int j = (x % (N - 1)) + 1; if(i > j) swap(i, j); else j++; x = (x + d) % (N * (N - 1)); //cerr << "i : " << i << ", j : " << j << endl; i--, j--; int ok = 0, ng = min(s[i].size(), s[j].size()) + 1; while(abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if(h[i].get(0, mid) == h[j].get(0, mid)) ok = mid; else ng = mid; } //cerr << "ok : " << ok << endl; ans += ok; } cout << ans << endl; }