#include using namespace std; const unsigned long long h = 947239; int main() { int n; cin >> n; vector s(n); vector> hh(n); for (int i = 0; i < n; i++) { cin >> s[i]; hh[i].resize(s[i].size() + 1); hh[i][0] = 0; for (int j = 0; j < s[i].size(); j++) { hh[i][j + 1] = hh[i][j] * h + s[i][j]; } } int m, x, d; cin >> m >> x >> d; int sum = 0; for (int k = 1; k <= m; k++) { int i, j; i = (x / (n - 1)); j = (x % (n - 1)); if (i > j) { swap(i, j); } else { j++; } x = (x + d) % (n * (n - 1)); int l = 0; int r = min(s[i].size(), s[j].size()); while (r - l > 1) { int mid = (l + r) / 2; if (hh[i][mid] == hh[j][mid]) { l = mid; } else { r = mid; } } sum += l; } cout << sum << endl; return 0; }