rhombic = Array.new(100).map{Array.new(100, 0)}

n = 0
m = 0
while s = gets
  list = s.chomp.split(",").map{|v| v.to_i}
  list.inject(n > list.size ? m % n + 1 : 0) do |index, v|
    rhombic[m][index] = v
    index + 1
  end
  n = [n, list.size].max
  m += 1
end

dp = Array.new(100).map{Array.new(100, 0)}
dp[0][0] = rhombic[0][0]

for i in 1..2*(n-1)
  dp[i][0] = rhombic[i][0] + dp[i-1][0]
end

for i in 1..2*(n-1)
  for j in 1..n-1
    dp[i][j] = [dp[i-1][j-1], dp[i-1][j]].max + rhombic[i][j]
  end
end

res = 0
for i in 0..n-1
  res = [res, dp[2*(n-1)][i]].max
end

puts res