SP33210 ADACUT - Ada and Alley

Description

As you might already know, Ada the Ladybug is a farmer. She has a long alley of trees. She wants the alley to look good so she has decided to make the heights of all trees equal. She has two possible operations: she can either cut the top of a tree, decreasing its height by one (at cost of **1**) **or** cut the tree down (at cost of **height $ _{i} $** ).

Input Format

The first line of input will contain **1 , the number of trees.** The next line will contain **N** integers 0

Output Format

Print the minimal cost to make the height of all trees in alley equal.