Constructing the Array

CodeForces - 1353D