This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int MAX = 5005;
int moves = 1;
vi cuts;	// position to start adding letters
string curr;
void Init() {
	cuts.pb(0);
}
void print() {
	cout<<"cuts: ";
	for (int x : cuts)
		cout<<x<<" ";
	cout<<endl;
	cout<<"curr: "<<curr<<endl;
}
void TypeLetter(char L) {
	if ((int)(curr.size()) == cuts.back())
		curr += L;
	else
		curr[cuts.back()] = L;
	cuts.pb(cuts.back() + 1);
//	print();
	moves++;
}
void UndoCommands(int U) {
	cuts.pb(cuts[moves - U - 1]);
//	print();
	moves++;
}
char GetLetter(int P) {
	return curr[P];
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |