#include <iostream>
#include <queue>
#include <string>

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::string s;
	std::cin >> s;
	std::queue<int> normal;
	std::queue<int> priority;
	int number = 1;
	for (int i = 0; i < (int)s.size(); i++) {
		switch (s[i]) {
			case 'Z':
				normal.push(number);
				number++;
				break;
			case 'P':
				priority.push(number);
				number++;
				break;
			case 'G':
				if (priority.empty()) {
					std::cout << normal.front() << '\n';
					normal.pop();
				} else {
					std::cout << priority.front() << '\n';
					priority.pop();
				}
				break;
		}
	}
	return 0;
}
