The numbers $1, 2, \ldots, 10000$ are placed in the cells of a $100 \times 100$ square grid, each number appearing exactly once. In this arrangement, numbers that differ by $1$ are located in adjacent cells. We then calculate the distances between the centers of every pair of cells where the numbers differ by exactly $5000$. Let $S$ be the minimum of these distances. What is the largest value $S$ can take?

Let's think step by step and output the final answer within \boxed{}.
user