Source: IMOSLC-2021-P2
Category: Extremal Problems

Problem: Given an integer $n \\geq 3$. There are $m \\g We want to color the beads using $n$ colors such that in any consecutive $n + 1$ beads, all colors appear at least once. Find the largest positive integer $m$ for which this is impossible.

Answer: n^2-n-1

Reference solution:
We claim that the largest positive integer $m$ for which such a coloring is impossible is $m = n^2-n-1$.

First, we prove that when $m=n^{2}-n-1$, the coloring cannot be achieved. Assume for the sake of contradiction that a valid coloring exists. By the Pigeonhole Principle, there exists a color that appears at most $\left\lfloor\frac{n^{2}-n-1}{n}\right\rfloor=n-2$ times. Let $c \le n-2$ be the number of times this color appears. These $c$ beads divide the remaining $m-c$ beads into $c$ consecutive blocks (intervals) around the necklace. By the Pigeonhole Principle, the maximum length of such a block is at least 
$$ \left\lceil\frac{m-c}{c}\right\rceil \ge \left\lceil\frac{m-(n-2)}{n-2}\right\rceil = \left\lceil\frac{n^{2}-2n+1}{n-2}\right\rceil = \left\lceil n + \frac{1}{n-2}\right\rceil = n+1, $$
where we used the fact that $n \ge 3$. This means there must be a consecutive block of at least $n+1$ beads without that color, which contradicts the requirement that any consecutive $n+1$ beads contain all $n$ colors. Thus, $m = n^2-n-1$ is impossible.

Next, we prove that when $m \ge n^{2}-n$, a valid coloring can always be achieved. Let $m=kn+j$, where $0\le j\le n-1$. Since $m \ge n^2-n = (n-1)n$, we have $k \ge n-1$, which implies $k \ge j$. We divide the $m$ beads into $k$ groups as follows:
- $k-j$ groups of length $n$, coloring each group with the sequence of colors $1, 2, 3, \dots, n$;
- $j$ groups of length $n+1$, coloring each group with the sequence of colors $1, 1, 2, 3, \dots, n$.

It is easy to verify that this coloring satisfies the requirement. Since the minimum group length is $n$, any $n+1$ consecutive beads can span at most two adjacent groups. If the $n+1$ beads are entirely contained within a single group, it must be a group of length $n+1$, which is colored $1, 1, 2, \dots, n$ and thus contains all $n$ colors. If they span two adjacent groups, they consist of the last $x$ beads of the first group and the first $y$ beads of the second group, where $x, y \ge 1$ and $x+y = n+1$. The first group ends with the colors $n-x+1, n-x+2, \dots, n$. The second group begins with the colors $1, 2, \dots, y$ (if its length is $n$) or $1, 1, 2, \dots, y-1$ (if its length is $n+1$). In either case, the second group provides the colors $1, 2, \dots, y-1$ (and also $1$ if $y=1$). Since $x+y = n+1$, we have $y-1 = n-x$. Therefore, the union of the colors from both parts contains $\{n-x+1, \dots, n\} \cup \{1, \dots, n-x\}$, which is exactly the set of all $n$ colors. 

In general, let $m = kn + j$, where $0 \le j \le n-1$; then a valid coloring is achievable if and only if $k \ge j$.

Grading guidelines:
(Partial) 1. Showed an upper bound by a pigeonhole/block argument: picked a least frequent color, bounded its number of occurrences by at most n−2 when m=n^2−n−1, and concluded there is a gap of at least n+1 consecutive beads missing that color, contradicting the condition. 2. Gave a workable construction idea for large m (e.g. repeating 1,2,…,n in blocks, possibly inserting one extra repeated color to make length n+1 blocks) and correctly argued that any n+1 consecutive beads lie in at most two adjacent blocks. 3. Correctly reduced the problem to writing m=kn+j (0≤j≤n−1) and stated/derived the key feasibility condition k≥j (equivalently m≥n^2−n), even if the proof or construction is incomplete. (Almost) 1. Correctly proved impossibility for m=n^2−n−1 using the least-frequent-color and longest-gap estimate, and correctly described a valid coloring for all m≥n^2−n, but left a small gap in checking the boundary/wrap-around case for the necklace (windows crossing the end/start). 2. Gave the block construction for m=kn+j with k≥j and verified the two-block window check, but made a localized counting error (floor/ceiling or off-by-one) in the impossibility part that does not affect the main strategy. 3. Solution is almost complete, but made minor mistakes which are not negligible.

Construction task:
For the specific case $n=100$, output a valid coloring of a circular necklace with $m=12345$ beads using the $n$ colors, such that any consecutive $n+1$ beads contain all $n$ colors at least once. 

Construction requirements:
- Output a single Python expression that evaluates to a list of 12345 integers.
- The integers must be from 1 to 100, representing the colors of the beads in order around the necklace.
- The configuration must satisfy the condition that any window of 101 consecutive beads (including wrap-around) contains all 100 colors.
- The construction must be a single, raw Python expression (e.g., using list concatenation, multiplication, and `range()`).
- Do not include any explanations, comments, markdown formatting, assignments, or any non-expression content.
- Put ONLY the Python expression inside the construction block.

Reference construction:
list(range(1, 101)) * 78 + ([1] + list(range(1, 101))) * 45

Verifier code:
import sys

def verify():
    payload = sys.stdin.read().strip()
    if not payload:
        print("Empty input.")
        return
        
    try:
        # Evaluate the raw construction payload using Python's eval()
        # as requested by user intent to support list concatenation, multiplication, and range()
        beads = eval(payload)
    except Exception as e:
        print(f"Failed to evaluate expression: {e}")
        return
        
    if not isinstance(beads, list):
        print("Evaluated result is not a list.")
        return
        
    if len(beads) != 12345:
        print(f"List length is {len(beads)}, expected 12345.")
        return
        
    for idx, bead in enumerate(beads):
        if not isinstance(bead, int) or isinstance(bead, bool):
            print(f"Element at index {idx} is not an integer.")
            return
        if not (1 <= bead <= 100):
            print(f"Element at index {idx} is {bead}, expected between 1 and 100.")
            return
            
    # Simulate the circular nature of the necklace by appending the first 100 elements
    extended_beads = beads + beads[:100]
    
    # Iterate over all sliding windows of length 101
    for i in range(len(beads)):
        window = extended_beads[i:i+101]
        distinct_colors = set(window)
        if len(distinct_colors) != 100:
            print(f"Window starting at index {i} does not contain all 100 colors.")
            return
            
    print("True")

if __name__ == "__main__":
    verify()