#include #include #include #include using namespace std; ifstream fin("potriveala.in"); ofstream fout("potriveala.out"); const int P = 73; const int MAXN = 251000; const int MOD1 = 6123619; const int MOD2 = 6123619; bool v[MOD1]; int n; string a, b; bool solve(int how_many) { for (int i = 0; i < MOD1; ++i) v[i] = 0; int hash1 = 0, hash2 = 0, P1 = 1, P2 = 1; for (int i = 0; i < how_many; ++i) { hash1 = (hash1 * P + (int)a[i]) % MOD1; // hash2 = (hash2 * P + (int)a[i]) % MOD2; if (i != 0) { P1 = (P1 * P) % MOD1; // P2 = (P2 * P) % MOD2; } } v[hash1] = 1; for (int i = how_many; i < a.size(); ++i) { hash1 = ((hash1 - (a[i - how_many] * P1) % MOD1 + MOD1) * P + a[i]) % MOD1; // hash2 = ((hash2 - (a[i - how_many] * P2) % MOD2 + MOD2) * P + a[i]) % MOD2; v[hash1] = 1; } hash1 = 0, hash2 = 0; for (int i = 0; i < how_many; ++i) { hash1 = (hash1 * P + (int)b[i]) % MOD1; //hash2 = (hash2 * P + (int)b[i]) % MOD2; } if (v[hash1]) return 1; for (int i = how_many; i < b.size(); ++i) { hash1 = ((hash1 - (b[i - how_many] * P1) % MOD1 + MOD1) * P + b[i]) % MOD1; //hash2 = ((hash2 - (b[i - how_many] * P2) % MOD2 + MOD2) * P + b[i]) % MOD2; if (v[hash1]) return 1; } return 0; } int cautare_binara() { int st = 0, dr = a.size(), last = 0; while (st <= dr) { int mid = (st + dr) / 2; if (solve(mid)) { st = mid + 1; last = mid; } else dr = mid - 1; } return last; } int main() { fin >> a >> b; while (b.size() < a.size()) b += b; fout << cautare_binara(); return 0; }