Notice that,
S=∑k=1n((k−1)xk−(n−k)xk)=∑k=1n(xk(2k−n−1))⩽∑k≥2n+1(xk(2k−n−1)).
When n is odd,
S⩽k=2n+1∑n(xk(2k−n−1))⩽k=2n+1∑n(2k−n−1)=4n2−1,
When x1=x2=⋯=x2n−1=0,x2n+1=x2n+3=⋯=xn=1, the equality can be achieved;
When n is even,
S⩽∑k=2n+2n(xk(2k−n−1))⩽∑k=2n+2n(2k−n−1)=4n2,
When x1=x2=⋯=x2n=0,x2n+1=x2n+2=⋯=xn=1, the equality can be achieved.
Thus, the maximum possible value is [4n2], where [x] denotes the greatest integer not exceeding the real number x.