update index and twosum