#include #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define pb push_back #define mp make_pair #define fst first #define snd second #define show(x) cout << #x << " = " << x << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define pii pair #define vi vector using namespace std; template ostream& operator<<(ostream& o, const pair& p) { return o << "(" << p.first << "," << p.second << ")"; } template ostream& operator<<(ostream& o, const vector& vc) { o << "sz = " << vc.size() << endl << "["; for (const T& v : vc) o << v << ","; o << "]"; return o; } using ll = long long; constexpr ll MOD = 1000000007; using psi = pair; constexpr int MAX = 100000; string str[MAX]; unordered_map mpp[MAX]; inline int lcp(ll i, ll j) { if (mpp[i].find(j) != mpp[i].end()) { return mpp[i].at(j); } const string& s1 = str[i]; const string& s2 = str[j]; int cnt = 0; rep(k, min(s1.size(), s2.size())) { if (s1[k] != s2[k]) { break; } else { cnt++; } } mpp[i][j] = cnt; return cnt; } int main() { ll N; cin >> N; rep(i, N) { cin >> str[i]; } ll M, x, d; cin >> M >> x >> d; ll sum = 0; rep(i, M) { ll I = (x / (N - 1)) + 1; ll J = (x % (N - 1)) + 1; if (I > J) { swap(I, J); } else { J = J + 1; } const ll t = lcp(I - 1, J - 1); sum += t; x = (x + d) % (N * (N - 1)); } cout << sum << endl; return 0; }