(Base on the solution of Ali Alramdan, IMO 2023's team member)
For two times Khalid visits a square on two different directions, one of them he will go up and go right for the other. Let f(i,j) be the number of time Khalid visited square (i,j) so f(0,0)=s for some positive integer s and
f(i,j)=2f(i−1,j)+f(i,j−1).
By induction on i+j, one can prove that the color of cell (i,j) after precisely s walks is f(i,j)mod2 where 1 is black and 0 is white. Define g(i,j)=f(i,j)⋅2i+j for 0≤i,j≤n−1, then
g(i,j)=g(i−1,j)+g(i,j−1).
Since g(0,0)=f(0,0)=s, then base on the Pascal triangle formula, one can get
g(i,j)=s⋅(ii+j)⟹f(i,j)=2i+js⋅(ii+j).
Thus for all squares to be white again, we need to find f(i,j) to be even for all i,j≤n−1, or
v2(s)+v2((ii+j))≥i+j+1.
Now take s=s0=22n−1−v2((n−12n−2)) which is the smallest positive integer such that f(n−1,n−1) is even. We will prove that this choice is also such that: f(i,j) are all even for all 0≤i,j≤n−1. We deduce to prove for j=n−1 since the remaining values can be restore by these values as some linear combinations of even numbers with integer coefficients. Put k=v2((n−12n−2)) then we need to prove for that
v2((n−12n−2−i))≥k−1,∀i=0,1,…,k.
Note that
(n−12n−2−i)=(n−12n−2)⋅(2n−2)(2n−3)…(2n−1−i)(n−1)(n−2)…(n−i)
implies that each even term of the product in the denominator of the fraction has its corresponding half in the numerator, so it could eat at most one 2 from the prime factorization, hence
v2((n−12n−2−i))≥v2((n−12n−2))−⌊2i⌋=k−⌊2i⌋≥k−i.
Therefore, the minimum value of s is s0 defined as above. ☐