Stores the required sum
let final_ans = 0 ; let temp = N ; while ( ind > 1 ) { let val = temp - prefix [ ind - 1 ] ; if ( ind % 2 != 0 ) { temp = prefix [ ind - 2 ] + parseInt ( ( val + 1 ) / 2 , 10 ) ; } else { temp = prefix [ ind - 2 ] + parseInt ( ( val + 3 ) / 4 , 10 ) ; } -- ind ;