you give n x n grid place 1 x 1 x 1 cube each value v gridij represent tower v cube place cell jAfter placing cube decide glue directly adjacent cube form irregular 3d shapesreturn total surface area result shapesnote the face shape count surface area Example 1input grid 1234output 34example 2input grid 111101111output 32example 3input grid 222212222output 46 Constraintsn gridlength gridilength1 n 500 gridij 50