#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define bit(n) (1LL<<(n)) #define sz(x) ((int)(x).size()) #define ten(n) ((int)1e##n) #define fst first #define snd second using ll=long long; using pii=pair;using pll=pair;using pil=pair;using pli=pair; using vs=vector;using vvs=vector;using vvvs=vector; using vb=vector;using vvb=vector;using vvvb=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; template bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } ll ri(){ll l;cin>>l;return l;} string rs(){string s;cin>>s;return s;} templateT read(){T t;cin>>t;return t;} templateostream&operator<<(ostream&o,const pair&p){return o<<'('<ostream&operator<<(ostream&o,const vector&t){o<<"{";forr(e,t)o<void e_r_r(vs::iterator it,T a,Args... args){cerr<substr((*it)[0]==' ',it->length())<<" = "< P, H; RollingHash64() {} /** * O(N) */ void init(const string & S) { N = sz(S); P.resize(N+1, 1); H.resize(N+1, 0); for (int i = 0; i < N; i++) { int c = (int) (S[i] - ' '); H[i+1] = H[i] * base + c; P[i+1] = P[i] * base; } } /** * S全体のハッシュ値を返す * O(1) */ long long hash() const { return hash(0, N); } /** * S の [l, r) のハッシュ値を返す * O(1) */ long long hash(int l, int r) const { return H[r] - H[l] * P[r - l]; } /** * S の [l1, r1) と [l2, r2) のハッシュ値が等しいかを返す * O(1) */ bool equals(int l1, int r1, int l2, int r2) const { if (l1 < 0 || l2 < 0) return false; if (r1 > N || r2 > N) return false; if (r1 - l1 != r2 - l2) return false; return hash(l1, r1) == hash(l2, r2); } /** * S の p1 からの len 文字と p2 からの len 文字が等しいかを返す * O(1) */ bool equals(int p1, int p2, int len) const { return equals(p1, p1 + len, p2, p2 + len); } /** * S の pos 以降と other が等しいかを返す * O(1) */ bool equals(int pos, const RollingHash64 &other) const { int r = pos + other.N; if (r >= N) return false; return hash(pos, r) == hash(0, other.N); } /** * S の p1 からと p2 からで共通する文字列の長さを返す。 * O(log(N)) */ int lcp(int p1, int p2) const { int ok = 0; int ng = min(N - p1, N - p2) + 1; while (ng - ok > 1) { int mid = (ok + ng) / 2; (equals(p1, p1 + mid, p2, p2 + mid) ? ok : ng) = mid; } return ok; } }; void Main() { ll n = ri(); //int mod = 1e9+9; //int base = 114511; //rh.add_mod(mod, base); vector rh(n); rep(i, n) { rh[i].init(rs()); } ll m = ri(); ll x = ri(); ll d = ri(); ll ans = 0; rep(k, 1, m+1) { ll i = (x / (n - 1)) + 1; ll j = (x % (n - 1)) + 1; if (i > j) swap(i, j); else j++; x = (x + d) % (n * (n - 1)); RollingHash64 &r1 = rh[i-1]; RollingHash64 &r2 = rh[j-1]; { int ok = 0; int ng = min(r1.N, r2.N) + 1; while (ng - ok > 1) { int mid = (ok + ng) / 2; (r1.hash(0, mid) == r2.hash(0, mid) ? ok : ng) = mid; } ans += ok; } } cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }