## 1. Abridged problem statement

You start with an empty string and a cursor at the beginning. Given a sequence of key presses consisting of lowercase letters (`'a'` through `'z'`), `L` (move cursor left), and `R` (move cursor right), process each key:
- Letter: insert it immediately before the cursor position (the cursor ends up just after the new character).
- `L`: move cursor left if not already at the start.
- `R`: move cursor right if not already at the end.

After all operations, output the resulting string.

---

## 2. Detailed editorial

We need to process up to 1,000,000 operations in order, with cursor movements and insertions. Naively using a resizable array and performing insertions in the middle would be O(N^2) in the worst case.

Instead, we maintain a doubly linked list of characters and an iterator pointing to the current cursor position. The cursor position is the iterator to the element after which the next insertion will occur. All operations on a `std::list` iterator are O(1):

- Letter `c`: insert `c` before the iterator (i.e., just to the left of the cursor position in the logical text).
- `L`: if the iterator is not at the beginning, decrement it.
- `R`: if the iterator is not at the end, increment it.

At the end, read the list in order to get the final text.

Time complexity: O(N). Space complexity: O(N).

An equivalent implementation uses two stacks (the "split buffer" approach): `left` stores characters to the left of the cursor, `right` stores characters to the right (in reverse). Letter push goes onto `left`; `L` pops from `left` to `right`; `R` pops from `right` to `left`. Final string is `left` followed by `right` reversed.

---

## 3. C++ Solution

```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

string s;

void read() {
    cin >> s;
}

void solve() {
    list<char> ans;
    auto it = ans.begin();

    for(auto c: s) {
        if(c == 'L') {
            if(it != ans.begin()) {
                it--;
            }
        } else if(c == 'R') {
            if(it != ans.end()) {
                it++;
            }
        } else {
            ans.insert(it, c);
        }
    }

    for(auto c: ans) {
        cout << c;
    }
    cout << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

---

## 4. Python solution with detailed comments

```python
import sys
def main():
    data = sys.stdin.read().strip()
    # We'll treat 'left' and 'right' as stacks.
    left = []   # characters to the left of the cursor
    right = []  # characters to the right of the cursor

    for c in data:
        if c == 'L':
            if left:
                # Move one char from left to right (cursor moves left)
                right.append(left.pop())
        elif c == 'R':
            if right:
                # Move one char from right to left (cursor moves right)
                left.append(right.pop())
        else:
            # Letter insertion: push onto left (cursor moves right)
            left.append(c)

    # The final text is left + reversed(right)
    # right is in reverse order of actual text to its right
    sys.stdout.write(''.join(left) + ''.join(reversed(right)))

if __name__ == "__main__":
    main()
```

---

## 5. Compressed editorial

Use a doubly linked list with an iterator as the cursor, or equivalently two stacks (left/right of cursor). Letters insert before the cursor; `L` moves the cursor left; `R` moves it right. All operations are O(1). Final string is read from the list in order. Total time O(N), space O(N).
