Update both the scores
straightScore += ( a [ prev ] * b [ prev ] + a [ next ] * b [ next ] ) NEW_LINE reverseScore += ( a [ prev ] * b [ next ] + a [ next ] * b [ prev ] ) NEW_LINE res = max ( res , max ( straightScore , reverseScore ) ) NEW_LINE prev -= 1 NEW_LINE next += 1 NEW_LINE