little Dormi receive histogram n bar height a_1 a_2 ldot a_n Christmas however play new histogram realize imperfection today want modify likingTo modify histogram Little Dormi able perform follow operation arbitrary number time Select index 1 le le n a_i0 assign a_i a_i1Little Dormi define ugliness score histogram perform number operation sum vertical length outline number operation perform and histogram perfect possible like minimize ugliness score modifying number operationshowever histogram large Little Dormi have trouble minimize ugliness score Little Dormis old brother help find minimal uglinessconsider follow example histogram 4 column height 4896 the blue region represent histogram red line represent vertical portion outline currently vertical length outline 44136 18 little Dormi modify histogram ugliness 18however Little Dormi apply operation column 2 twice column 3 result histogram height 4776 now total vertical length outline red line 431614 ugliness 14317 dollar it prove optimal