Case 1 : When N is odd
if ( N % 2 == 1 ) { var first_maxima = N / 2 ; var second_maxima = first_maxima + 1 ; var ans1 = 3000000000000000000 , ans2 = 3000000000000000000 ; var from_left = - 1 , from_right = - 1 ; var from = - 1 ; for ( var i = 0 ; i < n ; ++ i ) { if ( v [ i ] > first_maxima ) { from = i ; break ; } else { var diff = first_maxima - v [ i ] ; if ( diff < ans1 ) { ans1 = diff ; from_left = v [ i ] ; } } } from_right = v [ from ] ; var diff1 = first_maxima - from_left ; var diff2 = from_right - second_maxima ; if ( diff1 < diff2 ) document . write ( N + " " + from_left ) ; else document . write ( N + " " + from_right ) ; }