Starting from an all-zero array, find the minimum number of single-element increments and whole-array doublings that produce the target array B.
You have an array AAA of length NNN whose every element is 0. You can perform these two operations.
Given an array BBB, write a program that finds the minimum number of operations needed to make AAA equal to BBB.
The first line contains the size of the array, NNN. (1≤N≤501 \le N \le 501≤N≤50)
The second line contains the NNN elements of BBB, separated by spaces. Each element is an integer between 0 and 1,000, inclusive.
Print the minimum number of operations that turns AAA into BBB on the first line.