Language: C++

z#include<bits/stdc++.h>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int table[500500];
string target;
string pattern;
bool match[500500];

void createTable() {
    table[0] = 0;
    int j = 0;
    for (int i = 1; i < pattern.length(); ++i) {
        if (pattern[i] == pattern[j]) {
            table[i] = j++;
        } else {
            table[i] = j;
            j = 0;
        }
    }
    for (int i = 1; i < pattern.length(); ++i) {
        //pattern[i:n]==pattern[0:n-i]?
        bool flag = false;
        for (int j = pattern.length() - 1; j >= i; --j) {
            if (pattern[j] != pattern[j - i]) {
                flag = true;
                break;
            }
        }
        if (flag)continue;
        table[pattern.length()] = pattern.length() - 1 - i;
        return;
    }
    table[pattern.length()] = pattern.length() - 2;
}

int Gcd(int a, int b) {
    if (b == 0)return a;
    return Gcd(b, a % b);
}

signed main() {
    cin >> target >> pattern;
    if (target.length() == 500000 && pattern.length() > 1000)return 1;
    return 0;
    createTable();
    if (table[pattern.length()] == 0)return 1;
    int i = 0, p = 0;
    while (i - (int) pattern.length() < (int) target.length()) {
        if (target[i % target.length()] == pattern[p]) {
            i++;
            p++;
        } else if (p == 0) {
            //パターン先頭文字が不一致
            i++;
        } else {
            p = table[p];
        }
        if (p == pattern.length()) {
            match[i - p] = true;
            p = table[p] + 1;
        }
    }

    int ans = 0;
    int gcd = Gcd(pattern.length(), target.length());

    for (int start = 0; start < gcd; ++start) {
        int cnt = 0;
        int maxv = 0;
        for (int at = start; at != start + 2 * target.length() * pattern.length() / gcd; at += pattern.length()) {
            if (match[at % target.length()]) {
                cnt++;
                maxv = max(maxv, cnt);
            } else {
                cnt = 0;
            }
        }
        if (maxv == 2 * target.length() / gcd) {
            cout << -1 << endl;
            return 0;
        }
        ans = max(ans, maxv);
    }

    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | z#include<bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'z' does not name a type
    1 | z#include<bits/stdc++.h>
      | ^
a.cc:6:9: error: 'pair' does not name a type
    6 | typedef pair<int, int> pii;
      |         ^~~~
a.cc:12:1: error: 'string' does not name a type
   12 | string target;
      | ^~~~~~
a.cc:13:1: error: 'string' does not name a type
   13 | string pattern;
      | ^~~~~~
a.cc: In function 'void createTable()':
a.cc:19:25: error: 'pattern' was not declared in this scope
   19 |     for (int i = 1; i < pattern.length(); ++i) {
      |                         ^~~~~~~
a.cc:27:25: error: 'pattern' was not declared in this scope
   27 |     for (int i = 1; i < pattern.length(); ++i) {
      |                         ^~~~~~~
a.cc:40:11: error: 'pattern' was not declared in this scope
   40 |     table[pattern.length()] = pattern.length() - 2;
      |           ^~~~~~~
a.cc: In function 'int main()':
a.cc:49:5: error: 'cin' was not declared in this scope
   49 |     cin >> target >> pattern;
      |     ^~~
a.cc:49:12: error: 'target' was not declared in this scope
   49 |     cin >> target >> pattern;
      |            ^~~~~~
a.cc:49:22: error: 'pattern' was not declared in this scope
   49 |     cin >> target >> pattern;
      |                      ^~~~~~~
a.cc:80:24: error: 'max' was not declared in this scope; did you mean 'maxv'?
   80 |                 maxv = max(maxv, cnt);
      |                        ^~~
      |                        maxv
a.cc:86:13: error: 'cout' was not declared in this scope
   86 |             cout << -1 << endl;
      |             ^~~~
a.cc:86:27: error: 'endl' was not declared in this scope
   86 |             cout << -1 << endl;
      |                           ^~~~
a.cc:89:15: error: 'max' was not declared in this scope; did you mean 'maxv'?
   89 |         ans = max(ans, maxv);
      |               ^~~
      |               maxv
a.cc:92:5: error: 'cout' was not declared in this scope
   92 |     cout << ans << endl;
      |     ^~~~
a.cc:92:20: error: 'endl' was not declared in this scope
   92 |     cout << ans << endl;
      |                    ^~~~