SP2185 MUSIC - Musical Optimization

Description

Bessie the cow used to write musical melody. A musical melody is represented as a sequence of N (1

Input Format

\* Line 1: The single integer N. \* Lines 2..N+1: Line i+1 contains the single integer A $ _{i} $ .

Output Format

\* Line 1: A single integer that represents the minimum number of steps needed to make the given musical melody perfect. If there are no solutions, output -1 instead.