#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; struct RollingHash { static const int C = 31, C2 = 29, P = 1000000007, P2 = 1000000009; int _n; vector pw, pw2, hs, hs2; RollingHash() {} RollingHash(const string &st) :_n((int)st.size()), pw(_n + 1), pw2(_n + 1), hs(_n + 1), hs2(_n + 1) { pw[0] = pw2[0] = 1; rep(i, _n) { pw[i + 1] = (pw[i] * C) % P; pw2[i + 1] = (pw2[i] * C2) % P2; hs[i + 1] = (C*hs[i] + st[i]) % P; hs2[i + 1] = (C2*hs2[i] + st[i]) % P2; } } // [l, r) pii getHash(int l, int r) { int res, res2; res = (hs[r] - hs[l] * pw[r - l]) % P; res2 = (hs2[r] - hs2[l] * pw2[r - l]) % P2; if (res < 0)res += P; if (res2 < 0)res2 += P2; return mp(res, res2); } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector rhs(N); vi len(N); rep(i, N) { string s; cin >> s; rhs[i] = RollingHash(s); len[i] = sz(s); } ll M, x, d, ans = 0; cin >> M >> x >> d; while (M--) { ll l = (x / (N - 1)) + 1, r = (x % (N - 1)) + 1; if (l > r)swap(l, r); else r++; x = (x + d) % (N*(N - 1ll)); --l; --r; int lb = 0, ub = min(len[l], len[r]) + 1, mid; while (ub - lb > 1) { mid = (lb + ub) / 2; (rhs[l].getHash(0, mid) == rhs[r].getHash(0, mid) ? lb : ub) = mid; } ans += lb; } cout << ans << endl; }