#include using namespace std; struct iostream_init_struct { iostream_init_struct() { std::cin.tie(0); std::cin.sync_with_stdio(false); } } iostream_init; #include #include #include int N; string s[100000]; int M, x, d, i, j; void next() { i = (x / (N - 1)); j = (x % (N - 1)); if (i > j) { int temp = i; i = j; j = temp; } else { j = j + 1; } x = (x + d) % (N * (N - 1)); } int LCP() { int ret = 0; while (ret < min(s[i].size(), s[j].size())) { if (s[i][ret] == s[j][ret]) { ++ret; } else { break; } } return ret; } int main() { cin >> N; for (int i = 0; i < N; ++i) { cin >> s[i]; } cin >> M >> x >> d; int sum = 0; for (int indx = 0; indx < M; ++indx) { next(); sum += LCP(); } cout << sum << endl; }