#include using namespace std; int ok( vector< int > a, int asum, int len, int &minv ){ int need = ( len + 1 ) / 2; for( int i = 1; i <= len / 2; ++i ) need += 2 * i; if( need > asum ) return 0; int mov = 0; for( int i = len; i < a.size(); ++i ) mov += a[ i ]; int ptr = 0; for( int i = 1; i <= len / 2; ++i ){ if( a[ ptr ] - i > 0 ) mov += abs( a[ ptr ] - i ); ++ptr; } if( a[ ptr ] - ( len + 1 ) / 2 > 0 ) mov += abs( a[ ptr ] - ( len + 1 ) / 2 ); ++ptr; for( int i = len / 2; i >= 1; --i ){ if( a[ ptr ] - i > 0 ) mov += abs( a[ ptr ] - i ); ++ptr; } minv = min( minv, mov ); return 1; } signed main(){ int N; cin >> N; vector< int > A( N ); int asum = 0; for( int i = 0; i < N; ++i ) cin >> A[ i ], asum += A[ i ]; int ans = 0x3f3f3f3f; for( int i = 1; ok( A, asum, i, ans ); i += 2 ) ; cout << ans << endl; return 0; }