Since F is continuous on a closed domain, there must exist a maximum value. Fixing x2,x3,⋯,xn, then F(x1) is a function of x1:
F(x1)=∣x1−x2∣+∣x1−x3∣+⋯+∣x1−xn∣+2⩽i<j⩽n∑∣xi−xj∣.
Thus, F(x1) attains its maximum value if and only if ∣x1−x2∣+∣x1−x3∣+⋯+∣x1−xn∣ attains its maximum value. Since 0⩽xi⩽1, by the lemma mentioned above, when F(x1) attains its maximum value, it must be that x1∈{0,1}. By symmetry, when F attains its maximum value, it must be that xi∈{0,1}(1⩽i⩽n).
Therefore, we can assume that when F attains its maximum value, xi has k zeros and n−k ones. Then,
F⩽(0−0)×Ck2+(1−1)×Cn−k2+Ck1Cn−k1=k(n−k)⩽[2k+(n−k)]2=4n2
Since F is an integer, we have F⩽[4n2].
Equality holds when x1=x2=⋯=x[2n]=0,x[2n]+1=⋯=xn=1. Therefore, the maximum value of F is [4n2].