Source: TSTST-2023-P7
Category: Operations and Strategies

Problem: "The Bank of Pittsburgh issues coins that have a heads side and a tails side.
Vera has a row of $2023$ such coins alternately tails-up and heads-up,
with the leftmost coin tails-up.

In a \emph{move}, Vera may flip over one of the coins in the row,
subject to the following rules:
\begin{itemize}
  \item On the first move, Vera may flip over any of the $2023$ coins.
  \item On all subsequent moves, Vera may only flip over
    a coin adjacent to the coin she flipped on the previous move.
  (We do not consider a coin to be adjacent to itself.)
\end{itemize}
Determine the smallest possible number of moves Vera can
make to reach a state in which every coin is heads-up."

Answer: 4044

Reference solution:
The answer is $4044$. In general, replacing $2023$ with $4n+3$, the answer is $8n+4$. For $2023$, we have $n = 505$, so the minimum number of moves is $8(505) + 4 = 4044$.

**Lower Bound:**
Let the coins be indexed $1, 2, \ldots, 4n+3$ from left to right. The initial state alternates between tails-up and heads-up, starting with tails-up. Thus, the $2n+2$ odd-indexed coins start tails-up, and the $2n+1$ even-indexed coins start heads-up. 

Because Vera may only flip a coin adjacent to the previously flipped coin, her sequence of moves forms a connected walk on the path graph of the coins. Observe that the first coin (index $1$) and the last coin (index $4n+3$) both start tails-up, so they must be flipped at least once. Since the sequence of moves is a connected walk that visits both endpoints of the path, it must visit every coin at least once.

Every even-indexed coin starts heads-up and must end heads-up, so it must be flipped an even number of times. Since every coin is flipped at least once, each of the $2n+1$ even-indexed coins must be flipped at least twice. Therefore, the total number of flips of even-indexed coins, denoted $E$, satisfies $E \ge 2(2n+1) = 4n+2$.

Let $O$ be the total number of flips of odd-indexed coins. Because adjacent coins have different parities, the walk strictly alternates between odd-indexed and even-indexed coins. Consequently, the total number of visits to odd and even indices can differ by at most $1$, meaning $|O - E| \le 1$. Since $E \ge 4n+2$, it follows that $O \ge 4n+1$.

Every odd-indexed coin starts tails-up and must end heads-up, so it must be flipped an odd number of times. The total number of odd flips $O$ is the sum of the flip counts of the $2n+2$ odd-indexed coins. Since $2n+2$ is an even number, $O$ is the sum of an even number of odd integers, which means $O$ must be even. Given that $O \ge 4n+1$ and $O$ is even, we must actually have $O \ge 4n+2$.

Therefore, the total number of flips is $O + E \ge (4n+2) + (4n+2) = 8n+4$. For $n=505$, this gives a minimum of $4044$ flips.

**Construction:**
We provide a valid sequence of $8n+4$ flips that achieves the goal. 
For $k=0,1,\dots,n-1$, Vera flips the following sequence of $8$ coins in order:
\[ 4k+1, 4k+2, 4k+3, 4k+2, 4k+3, 4k+4, 4k+3, 4k+4 \]
Then, at the end, she flips the final $4$ coins:
\[ 4n+1, 4n+2, 4n+3, 4n+2 \]

To verify this is a valid sequence of moves, note that within each chunk, consecutive coins are adjacent. Furthermore, the last coin of the chunk for $k$ is $4k+4$, which is adjacent to the first coin of the chunk for $k+1$, $4k+5$. The last coin of the $(n-1)$-th chunk is $4n$, which is adjacent to the first coin of the final sequence, $4n+1$. Thus, the entire sequence forms a valid walk.

Finally, we count the number of times each coin is flipped:
- In the $k$-th chunk ($0 \le k \le n-1$), coin $4k+1$ is flipped $1$ time (odd), coin $4k+2$ is flipped $2$ times (even), coin $4k+3$ is flipped $3$ times (odd), and coin $4k+4$ is flipped $2$ times (even).
- In the final sequence, coin $4n+1$ is flipped $1$ time (odd), coin $4n+2$ is flipped $2$ times (even), and coin $4n+3$ is flipped $1$ time (odd).

Every odd-indexed coin is flipped an odd number of times (either $1$ or $3$), so it ends heads-up. Every even-indexed coin is flipped an even number of times (exactly $2$), so it ends heads-up. The total number of flips is $8n+4 = 4044$, as desired.

Grading guidelines:
(Partial) 1. Observed that any valid move sequence is a walk on the path graph (each move goes to an adjacent coin), hence the parity of the index alternates at every step and the numbers of odd- and even-index flips differ by at most 1 (i.e. |O−E|≤1). 2. Proved that both endpoints must be flipped (since they start tails), hence the walk must visit every vertex at least once (so every coin is flipped at least once). 3. Used initial/final states to derive parity constraints: each even-index coin starts and ends heads so must be flipped an even number of times (hence at least twice), and/or each odd-index coin starts tails so must be flipped an odd number of times. (Almost) 1. Established the lower bound 4044 (or in general 8n+4 for 4n+3 coins) using endpoint-visit implies all visited, even coins need ≥2 flips, |O−E|≤1, and the extra parity correction forcing O to be even, but did not give a construction achieving it. 2. Gave the intended block-walk construction (the repeating 8-move pattern plus the final 4 moves) and argued adjacency/flip-parities correctly for most coins, but made a localized indexing/endpoint mistake (e.g. at the transition between blocks or in the last 4 coins) that prevents full verification. 3. Solution is almost complete, but made minor mistakes which are not negligible.

Construction task:
Provide an explicit construction for the sequence of coins Vera flips to achieve this in the minimum number of moves.

Construction requirements:
- Output a single Python list of integers representing the 1-based indices of the coins flipped in order.
- The list must have the minimum possible length for the 2023 coins.
- Each integer must be between 1 and 2023 inclusive.
- The absolute difference between any two adjacent elements in the list must be exactly 1.
- The sequence of flips must result in all 2023 coins being heads-up (i.e., odd-indexed coins are flipped an odd number of times, and even-indexed coins are flipped an even number of times).
- Put ONLY the Python list expression inside the `<construct>...</construct>` block. You may use a list comprehension to make it compact. Do not use markdown code fences or add any extra text.

Reference construction:
[4 * k + d for k in range(505) for d in (1, 2, 3, 2, 3, 4, 3, 4)] + [2021, 2022, 2023, 2022]

Verifier code:
import sys
from collections import Counter

def verify():
    text = sys.stdin.read().strip()
    if not text:
        print("Empty input.")
        return

    try:
        # Evaluate the construction string. We use eval() because the instruction 
        # explicitly allows list comprehensions, which ast.literal_eval does not support.
        seq = eval(text)
    except Exception as e:
        print(f"Parse error: {e}")
        return

    if not isinstance(seq, list):
        print("Output must be a single Python list.")
        return
        
    if len(seq) != 4044:
        print(f"Expected list of length 4044, but got {len(seq)}.")
        return
        
    for i, coin in enumerate(seq):
        if not isinstance(coin, int):
            print(f"Element at index {i} is not an integer: {coin}")
            return
        if not (1 <= coin <= 2023):
            print(f"Coin index out of range at position {i}: {coin}")
            return
            
    for i in range(len(seq) - 1):
        if abs(seq[i] - seq[i+1]) != 1:
            print(f"Adjacent elements at indices {i} and {i+1} do not have an absolute difference of 1: {seq[i]} and {seq[i+1]}")
            return
            
    counts = Counter(seq)
    
    for i in range(1, 2024):
        expected_parity = i % 2
        actual_parity = counts[i] % 2
        if expected_parity != actual_parity:
            print(f"Coin {i} has incorrect flip parity. Expected {expected_parity}, got {actual_parity} (flipped {counts[i]} times).")
            return
            
    print("True")

if __name__ == "__main__":
    verify()