#include int *pX = nullptr; int N = 0; int GetDiff ( int idx1 , int idx2 ); int main ( void ) { scanf ( "%d" , &N ); pX = new int [ N ]; int diff , diffbuf; for ( int i = 0; i < N; i++ ) { scanf ( "%d" , pX + i ); } for ( int i = 0; i < ( N - 1 ); i++ ) { //printf ( "Call\n" ); if ( i == 0 ) { diff = GetDiff ( i , i + 1 ); } else { diffbuf = GetDiff ( i , i + 1 ); if ( diffbuf != -1 ) { if ( diffbuf < diff ) diff = diffbuf; } } if ( diff == 1 )break; } delete []pX; if ( diff == -1 ) diff = 0; printf ( "%d\n" , diff ); return 0; } int GetDiff ( int idx1 , int idx2 ) { //printf ( "%d %d\n" , idx1 , idx2 ); bool bEnableCurrent = false; int Current; if ( *( pX + idx1 ) != *( pX + idx2 ) ) { bEnableCurrent = true; Current = *( pX + idx1 ) - *( pX + idx2 ); if ( Current < 0 ) Current *= -1; if ( Current == 1 ) return Current; } int diff= -1 , idxnext; idxnext = idx2 + 1; diff = ( idxnext < N ) ? GetDiff ( idx1 , idxnext ) : -1; if ( diff == 1 )return diff; if ( bEnableCurrent ) { if (diff != -1 )return ( Current < diff ) ? Current : diff; return Current; } return diff; }