Language: C++

/*input
abcabab
ab
 
*/
 
/*
                                                    ______________
                                                          |       )
                         /*input
abcabab
ab
 
*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

vector <int> z_function(string str) {
  int n = str.size();
  int l = 0, r = 0;
  vector <int> z(n, 0);
  for (int i = 1; i < n; i++) {
    if (i <= r)
        z[i] = min(z[i - l], r - i + 1);
    while (i + z[i] < n && str[z[i]] == str[i + z[i]])
        ++z[i];
    if (i + z[i] > r)
        l = i, r = i + z[i] - 1;
  }
  return z;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string str1, str2;
  cin >> str1 >> str2;
  int n = str1.size();
  int m = str2.size();
  string temp = str1;
  while (n < m) {
    str1 += temp;
    n = str1.size();
  }
  vector <int> vec = z_function(str2 + "#" + str1 + str1);
  // out(vec);
  int ans = 0;
  int c = 0;
  for (int i = m + 1; i < vec.size(); i++) {
    c += (vec[i] == m);
    if (vec[i] != m) break;
  }
  if (c >= n)
    ans = max(ans, c);
  for (int i = m + 1; i < vec.size();) {
    int c = 0;
    if (vec[i] == m) {
      while (i < vec.size() && vec[i] == m) {
        c++;
        i += m;
      }
      if (i < vec.size()) {
        i -= m;
        i++;
      }
      ans = max(ans, c);
    } else {
      i++;
    }
  }
  if (ans >= n) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}                                 |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

vector <int> z_function(string str) {
  int n = str.size();
  int l = 0, r = 0;
  vector <int> z(n, 0);
  for (int i = 1; i < n; i++) {
    if (i <= r)
        z[i] = min(z[i - l], r - i + 1);
    while (i + z[i] < n && str[z[i]] == str[i + z[i]])
        ++z[i];
    if (i + z[i] > r)
        l = i, r = i + z[i] - 1;
  }
  return z;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string str1, str2;
  cin >> str1 >> str2;
  int n = str1.size();
  int m = str2.size();
  string temp = str1;
  while (n < m) {
    str1 += temp;
    n = str1.size();
  }
  vector <int> vec = z_function(str2 + "#" + str1 + str1);
  // out(vec);
  int ans = 0;
  int c = 0;
  for (int i = m + 1; i < vec.size(); i++) {
    c += (vec[i] == m);
    if (vec[i] != m) break;
  }
  if (c >= n)
    ans = max(ans, c);
  for (int i = m + 1; i < vec.size();) {
    int c = 0;
    if (vec[i] == m) {
      while (i < vec.size() && vec[i] == m) {
        c++;
        i += m;
      }
      if (i < vec.size()) {
        i -= m;
        i++;
      }
      ans = max(ans, c);
    } else {
      i++;
    }
  }
  if (ans >= n || (n == m && ans > 0)) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

Compiler output:
a.cc:165:35: error: expected unqualified-id before '|' token
  165 | }                                 |   )   /
      |                                   ^
a.cc:205:5: error: redefinition of 'int mod'
  205 | int mod = 1000000007;
      |     ^~~
a.cc:59:5: note: 'int mod' previously defined here
   59 | int mod = 1000000007;
      |     ^~~
a.cc:206:11: error: redefinition of 'const int inf'
  206 | const int inf = 1034567891;
      |           ^~~
a.cc:60:11: note: 'const int inf' previously defined here
   60 | const int inf = 1034567891;
      |           ^~~
a.cc:207:10: error: redefinition of 'const ll LL_INF'
  207 | const ll LL_INF = 1234567890123456789ll;
      |          ^~~~~~
a.cc:61:10: note: 'const ll LL_INF' previously defined here
   61 | const ll LL_INF = 1234567890123456789ll;
      |          ^~~~~~
a.cc:218:6: error: redefinition of 'template<class Arg1> void __f(const char*, Arg1&&)'
  218 | void __f(const char* name, Arg1&& arg1){
      |      ^~~
a.cc:72:6: note: 'template<class Arg1> void __f(const char*, Arg1&&)' previously declared here
   72 | void __f(const char* name, Arg1&& arg1){
      |      ^~~
a.cc:222:6: error: redefinition of 'template<class Arg1, class ... Args> void __f(const char*, Arg1&&, Args&& ...)'
  222 | void __f(const char* names, Arg1&& arg1, Args&&... args){
      |      ^~~
a.cc:76:6: note: 'template<class Arg1, class ... Args> void __f(const char*, Arg1&&, Args&& ...)' previously declared here
   76 | void __f(const char* names, Arg1&& arg1, Args&&... args){
      |      ^~~
a.cc:232:27: error: redefinition of 'template<class T> T GCD(T, T)'
  232 | template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
      |                           ^~~
a.cc:86:27: note: 'template<class T> T GCD(T, T)' previously declared here
   86 | template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
      |                           ^~~
a.cc:233:32: error: redefinition of 'template<class T> std::string toString(T)'
  233 | template < typename T > string toString(T a)       { return to_string(a); }
      |                                ^~~~~~~~
a.cc:87:32: note: 'template<class T> std::string toString(T)' previously declared here
   87 | template < typename T > string toString(T a)       { return to_string(a); }
      |                                ^~~~~~~~
a.cc:234:30: error: redefinition of 'template<class T> void toInt(std::string, T&)'
  234 | template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
      |                              ^~~~~
a.cc:88:30: note: 'template<class T> void toInt(std::string, T&)' previously declared here
   88 | template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
      |                              ^~~~~
a.cc:235:12: error: redefinition of 'int add(int, int)'
  235 | inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
      |            ^~~
a.cc:89:12: note: 'int add(int, int)' previously defined here
   89 | inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
      |            ^~~
a.cc:236:12: error: redefinition of 'int sub(int, int)'
  236 | inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
      |            ^~~
a.cc:90:12: note: 'int sub(int, int)' previously defined here
   90 | inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
      |            ^~~
a.cc:237:12: error: redefinition of 'int mul(int, int)'
  237 | inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
      |            ^~~
a.cc:91:12: note: 'int mul(int, int)' previously defined here
   91 | inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
      |            ^~~
a.cc:238:12: error: redefinition of 'int powr(int, ll)'
  238 | inline int powr(int a, ll b){
      |            ^~~~
a.cc:92:12: note: 'int powr(int, ll)' previously defined here
   92 | inline int powr(int a, ll b){
      |            ^~~~
a.cc:247:12: error: redefinition of 'int inv(int)'
  247 | inline int inv(int a){ return powr(a, mod - 2);}
      |            ^~~
a.cc:101:12: note: 'int inv(int)' previously defined here
  101 | inline int inv(int a){ return powr(a, mod - 2);}
      |            ^~~
a.cc:249:14: error: redefinition of 'std::vector<int> z_function(std::string)'
  249 | vector <int> z_function(string str) {
      |              ^~~~~~~~~~
a.cc:103:14: note: 'std::vector<int> z_function(std::string)' previously defined here
  103 | vector <int> z_function(string str) {
      |              ^~~~~~~~~~
a.cc:264:5: error: redefinition of 'int main()'
  264 | int main()
      |     ^~~~
a.cc:118:5: note: 'int main()' previously defined here
  118 | int main()
      |     ^~~~