Beautiful Matrix

CodeForces - 263A