Language: C++

// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

// kmp をやるための前計算
vector<int> makeTable(const string& s) {
  int n = s.size();
  vector<int> ret(n+1);
  ret[0] = -1;
  int j = -1;
  for (int i = 0; i < n; i++) {
    while (j >= 0 && s[i] != s[j]) j = ret[j];
    ret[i+1] = ++j;
  }
  return ret;
}

// str の中に word とマッチする場所のリストを返す
// ret のそれぞれの要素 el は, 「str[el] からの文字列が word と一致する」ことを示す


set<int> found;
int n,m;
map<int, int> used;
map<int, int> memo;

set<int> kmp(const string& str, const string& word) {
  vector<int> table = makeTable(word);
  set<int> ret;
  int m = 0, i = 0, n = str.size();
  while (m+i < n) {
    if (word[i] == str[m+i]) {
      if (++i == (int)(word.size())) {
        ret.insert(m);
        m = m+i-table[i];
        i = table[i];
      }
    } else {
      m = m+i-table[i];
      if (i > 0) i = table[i];
    }
  }
  return ret;
}

int dfs(int i){
  dump(i);
  assert(i<=n-1);
  if (memo[i]>0) return memo[i];

  used[i] = 1;
  int ni = (i+m)%n;

  if(used[ni] && memo[ni]>0){  // found previous result
    memo[i] = memo[ni]+1;
    return memo[i];
  }
  else if (used[ni]){  // found loop
    memo[i] = INF;
    return memo[i];
  }
  else if (found.find(ni)!=found.end()){
    memo[i] = dfs(ni)+1;
    return memo[i];
  }
  else{
    memo[i] = 1;
    return memo[i];
  }
}
int solve(){
  string os,t;cin>>os>>t;
  n = sz(os);
  m = sz(t);
  while (sz(s)<sz(t)){
    s += os;
  }
  s += os;

  dump(s,t);
  found = kmp(s, t);
  dump(found);

  each(e, found){
    if (e<=n-1) dfs(e);
    else{ break; }
  }
  dump(used);
  dump(memo);

  int ans = 0;
  each(el, memo){
    chmax(ans, el.second);
  }
  if (ans>=INF){
    cout << -1 << endl;
  }
  else{
    cout << ans << endl;
  }

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Compiler output:
a.cc: In function 'long long int solve()':
a.cc:122:13: error: 's' was not declared in this scope
  122 |   while (sz(s)<sz(t)){
      |             ^
a.cc:22:22: note: in definition of macro 'sz'
   22 | #define sz(x) ((int)(x).size())
      |                      ^
a.cc:125:3: error: 's' was not declared in this scope
  125 |   s += os;
      |   ^