dp = [0, 0] gets.to_i.times do a, b = gets.split.map &:to_i dp = [ [dp[0] + a, -2[dp[1]] * (dp[1] + a * 2)].max, [dp[0] + b, -2[dp[1]] * (dp[1] + b * 2)].max ] end puts dp.max