Add the cost to overall cost
cost += abs ( index [ arr [ i ] ] - i ) NEW_LINE else : NEW_LINE if ( arr [ i ] > arr [ i - 1 ] + arr [ i + 1 ] ) : NEW_LINE print ( " - 1" ) NEW_LINE return NEW_LINE else : NEW_LINE