#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

bool isRepeated(string s1) {
  size_t N = s1.size();
  string result = s1.substr(0,2);
  int j = 0;
  for (int i = 2; i < N;i++) {
    if (s1[i] == result[j])
      j++;
    else {
      for (; j >= 0; j--) {
        result.push_back(s1[i-j]);
      }
      j = 0;
    }
  }
  return j == result.size();
}



int main() {
  string s = "ababc";
  bool result = isRepeated(s);
  cout << "is " << s << " repeated? " << result << endl;
  return 0;
}