Order is different

ans is correct how to maintain the order of output i.e increasing order?