n = gets.to_i
hs = Array.new(n) { |i| gets.chomp.split.map(&:to_i) }
dp = Array.new(n) { Array.new(3){ - Float::INFINITY } }

dp[0] = hs[0]

1.upto(n - 1) do |i|
  0.upto(2) do |k|
    dp[i][k] = [dp[i - 1][k - 1], dp[i - 1][k - 2]].max + hs[i][k]
  end
end

puts dp[n - 1].max