#include using namespace std; #define rep(i,a,b) for(int i=a;i struct SegTree { V comp(V l, V r) { return min(l, r); }; vector val; SegTree() { val = vector(NV * 2, def); } V get(int l, int r) { //[l,r] if (l > r) return def; l += NV; r += NV + 1; V ret = def; while (l < r) { if (l & 1) ret = comp(ret, val[l++]); if (r & 1) ret = comp(ret, val[--r]); l /= 2; r /= 2; } return ret; } void update(int i, V v) { i += NV; val[i] = v; while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]); } void add(int i, V v) { update(i, val[i + NV] + v); } }; //----------------------------------------------------------------- int N, M, X, D; string S[101010]; //----------------------------------------------------------------- void init() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; rep(i, 0, N) cin >> S[i]; cin >> M >> X >> D; } //----------------------------------------------------------------- int lcp(string a, string b) { int cnt = 0; rep(i, 0, min(a.length(), b.length())) { if (a[i] == b[i]) cnt = i + 1; else break; } return cnt; } //----------------------------------------------------------------- int m[101010], mm[101010]; SegTree st; void pre() { rep(i, 0, N) mm[i] = i; sort(mm, mm + N, [&](int a, int b) { return S[a] < S[b]; }); rep(i, 0, N) m[mm[i]] = i; sort(S, S + N); rep(i, 1, N) st.update(i, lcp(S[i - 1], S[i])); } //----------------------------------------------------------------- int main() { init(); pre(); ll ans = 0; ll x = X, d = D, n = N; rep(q, 0, M) { int i = (x / (n - 1)) + 1; int j = (x % (n - 1)) + 1; if (i > j) swap(i, j); else j++; //fprintf(stderr, "Finish : %d/%d\n", i, M); int a = m[i - 1], b = m[j - 1]; if (a > b) swap(a, b); if (a == b) { ans += S[a].length(); continue; } int c = st.get(a + 1, b); ans += c; //cout << S[a] << " + " << S[b] << " = " << c << endl; x = (x + d) % (n * (n - 1)); } cout << ans << endl; }