#include <string>
#include <iostream>
#include <vector>

using namespace std;

class kmp {
	string& sample;
	vector<size_t> prefix;
	int last_prefix;
public:
	kmp(string& sample) :sample(sample), prefix(sample.length()) {
		last_prefix = prefix[0] = 0;
		for (size_t i=1; i<sample.length(); i++) {
			next(sample[i]);
			prefix[i] = last_prefix;
		}
		reset();
	}
	
	bool next(char c) {
		while (last_prefix > 0 && sample[last_prefix] != c)
			last_prefix = prefix[last_prefix-1];
			
		if (sample[last_prefix] == c)
			last_prefix++;
			
		return last_prefix == sample.length();
	}
	
	void reset()  {
		last_prefix = 0;
	}
};

int main() {
	string sample = "aabaa";
	string text = "aabaabaaaabaabaaab";
	
	kmp matcher(sample);
	
	for (size_t i=0; i<text.length(); i++) {
		if (matcher.next(text[i])) {
			cout << i + 1 - sample.length() << endl;
		}
	}
}