#include #define rep(i, l, r) for (int i = (l); i <= (r); i++) #define per(i, r, l) for (int i = (r); i >= (l); i--) #define int long long #define debug(x) cout << #x << '=' << x << '\n' #define all(vc) ((vc).begin(), (vc).end()) #define SZ(vc) (int)((vc).size()) #define pb push_back using namespace std; template inline void tomax(tp &a, tp b) { a=(b>a?b:a); } template inline void tomin(tp &a, tp b) { a=(b inline void read(tp& n) { tp x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); n = x * f; } template inline void write(tp x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } typedef unsigned long long ULL; typedef long long LL; typedef pair PII; typedef __int128 int128; typedef double db; const int N = 1e5 + 5; int n; string s[N]; int m,x,d; vector h[N]; bool check(int a, int b, int c) { if (min(SZ(s[a]),SZ(s[b]))> n; rep(i, 1, n) { cin >> s[i]; h[i].resize(SZ(s[i])+1, 0); int pw=1; rep(j, 1, SZ(s[i])) h[i][j] = h[i][j-1]+pw*s[i][j-1],pw*=131; } cin >> m >> x >>d; int ans = 0; rep(i, 1, m) { int a = (x/(n-1))+1, b = (x%(n-1))+1; if (a>b) swap(a,b); else b+=1; x = (x+d) % (n*(n-1)); int l = 0, r = 1e6; r += 1; while (l>1); if (check(a,b,mid)) l = mid+1; else r = mid; } ans+=l-1; } cout << ans << '\n'; return 0; }