Median Pyramid Hard

AtCoder - agc006_d