you give n x n grid place 1 x 1 x 1 cube axisaligne x y z axeseach value v gridij represent tower v cube place cell jwe view projection cubes xy yz zx planesA projection like shadow map 3dimensional figure 2dimensional plane we view shadow look cube sidereturn total area projection Example 1input grid 1234output 17explanation here projection shadow shape axisaligne planeexample 2input grid 2Output 5Example 3input grid 1002output 8 Constraintsn gridlength gridilength1 n 500 gridij 50