#include using namespace std; #define endl '\n' typedef long long ll; const int N = 1e5 + 10; ll n; string s[N]; ll m, x, d; vector h[N]; inline bool check(ll a, ll b, ll c) { if (min(s[a].size(), s[b].size()) < c) return 0; return h[a][c] == h[b][c]; } int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> n; for (ll i = 1; i <= n; i++) { cin >> s[i]; h[i].resize(s[i].size() + 1, 0); ll pw = 1; for (ll j = 1; j <= s[i].size(); j++) h[i][j] = h[i][j - 1] + pw * s[i][j - 1], pw *= 131; } cin >> m >> x >> d; ll ans = 0; for (ll i = 1; i <= m; i++) { ll a = (x / (n - 1)) + 1, b = (x % (n - 1)) + 1; if (a > b) swap(a, b); else b += 1; x = (x + d) % (n * (n - 1)); ll l = 0, r = 1e6, res = l; while (r >= l) { ll mid = (l + r) >> 1; if (check(a, b, mid)) res = mid, l = mid + 1; else r = mid - 1; } ans += res; } cout << ans << endl; return 0; }