you re mission old popular strategy game Dune II Battle for Arrakis the map mission represent rectangular matrix size n time m initially a_i j unit army cell jYou want prepare final battle want army exactly cell map ie nm1 cell contain 0 unit army remain cell contain entire armyto possibly zero number move during select exactly unit cell adjacent cell Ie cell j unit cell 1 j j 1 1 j j 1 of course want army exactly cell fast possible so want know minimum number move need thatand course life go situation map change there q update ith update denote integer x y z this update affect army cell x y update number unit cell x y z ie replace a_x y zAlso want determine minimum number move need entire army exactly cell update apply initial map in word map ith update equal initial map update apply