#include "bits/stdc++.h" #ifdef WINT_MIN #define __MAI #endif using namespace std; typedef unsigned int uint; typedef long long int ll; typedef unsigned long long int ull; #define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout< ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<=l;--cnt) #define BIGINT 0x7FFFFFFF #define MD 1000000007ll #define PI 3.1415926535897932384626433832795 void printbit(int u) { if (u == 0)cout << 0; else { int s = 0, k = 0; for (; 0>= 1, k++)s = (s << 1) | (u & 1); for (; 0>= 1)cout << (s & 1); } }template ostream& operator <<(ostream &o, const pair p) { o << "(" << p.first << ":" << p.second << ")"; return o; } #define TIME chrono::system_clock::now() #define MILLISEC(t) (chrono::duration_cast(t).count()) namespace { std::chrono::system_clock::time_point t; void tic() { t = TIME; } void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - t)); } std::chrono::system_clock::time_point tle = TIME; #ifdef __MAI void safe_tle(int msec) { assert(MILLISEC(TIME - tle) < msec); } #else #define safe_tle(k) ; #endif } #ifndef __MAI namespace { class MaiScanner { public: template void input_integer(T& var) { var = 0; T sign = 1; int cc = getchar_unlocked(); for (; cc<'0' || '9'>(int& var) { input_integer(var); return *this; } MaiScanner& operator>>(long long& var) { input_integer(var); return *this; } }; } MaiScanner scanner; #else #define getchar_unlocked _getchar_nolock #define scanner cin #endif inline int lcp(string& s1, string& s2) { int s = min(s1.size(), s2.size()); int i; for (i = 0; s1[i] == s2[i] && i < s; ++i) {} return i; } int width, height; int m, n, kei; string str[100010]; map mark; int main() { ll x, d; ll l, r; cin >> n; repeat(n) { cin >> str[cnt]; } cin >> m >> x >> d; ll result = 0; for (ll k = 1; k <= m; ++k) { l = (x / (n - 1)); r = (x % (n - 1)); if (l > r) swap(l, r); else { r = r + 1; } x = (x + d) % (n * (n - 1)); ll key = (l << 32) | r; if (mark.count(key)) { result += mark[key]; } else { result += mark[key] = lcp(str[l], str[r]); } } cout << result << endl; return 0; }