P18127 [ICPC 2026 Seoul R] Potion Shop
Description
Two apprentices at a potion shop play a game using the remaining ingredients. There are $n$ containers, and the $i$-th container holds $a_i$ magic crystals.
The players alternate turns. On each turn, the current player must make exactly one potion using either of the following methods:
1. **Specialized potion:** Choose a nonempty container and remove any positive number of crystals from it, up to the number currently in that container.
2. **Lesser potion:** Remove a total of between $1$ and $p-1$ crystals, inclusive, from any number of containers. The crystals may be taken from a single container or distributed among multiple containers.
A player cannot use more crystals from a container than it currently holds. Used crystals are removed. A player who cannot make a potion on their turn loses. Both players play optimally.
For example, suppose there are two containers, each holding one crystal, and $p=3$. The first player can remove both crystals in a single lesser-potion move, leaving no legal move for the second player. This corresponds to Sample Input/Output 1.
After the initial inventory, $q$ updates are performed. Each update sets the number of crystals in one container to a given value. The new value may be smaller than, equal to, or greater than the current value. Updates are applied cumulatively in the order given in the input. Determine the winner of a game starting from the initial inventory and from the inventory immediately after each update. These hypothetical games do not change the inventory.
Input Format
Your program is to read from standard input. The first line contains three integers $n$, $p$, and $q$ ($1 \le n \le 200{,}000$, $2 \le p \le 10^9$, $0 \le q \le 200{,}000$), where $n$ is the number of containers, $p$ is the exclusive upper bound on the number of crystals used in a lesser potion, and $q$ is the number of updates.
The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0 \le a_i \le 10^{18}$), the initial numbers of crystals in the containers.
Each of the following $q$ lines contains two integers $x$ and $v$ ($1 \le x \le n$, $0 \le v \le 10^{18}$). This update sets the number of crystals in container $x$ to $v$.
Output Format
Your program is to write to standard output. Print $q+1$ lines, one for the initial inventory and one for the inventory after each update, in order. Print `FIRST` if the first player has a winning strategy. Otherwise, print `SECOND`.