<image>


Arrange integers (0 or more and 99 or less) in a rhombus as illustrated in Fig. 1. Create a program that reads the data representing the rhombus and outputs the maximum value of the sum of the integers that pass when starting from the top and proceeding to the bottom according to the following rules.

* At each step, you can proceed to the lower left diagonal or the lower right diagonal.



For example, in the example of Fig. 1, as shown in Fig. 2, when 7,3,8,7,5,7,8,3,7 is selected and passed, the sum is the maximum 55 (7 + 3 + 8). + 7 + 5 + 7 + 8 + 3 + 7 = 55).



Input

As shown in the input example, a comma-separated sequence of integers is given to the diamond. Each line does not contain whitespace. The input example corresponds to Fig. 1. There are less than 100 rows of data.

Output

Outputs the maximum value of the sum of integers that pass according to the rules on one line.

Example

Input

7
3,8
8,1,0
2,7,4,4
4,5,2,6,5
2,7,4,4
8,1,0
3,8
7


Output

55
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

void solve()
{
	string str;
	int data[100][100] = {0};
	int count1 = 0;
	int count2 = 0;
	while(getline(cin, str))
	{
		str += ',';
		int n = str.size();
		string temp;
		int size = 0;
		for(int i = 0; i < n; ++i)
		{
			if(str[i] == ',')
			{
				char* c = new char[size];
				for(int j = 0; j < size; ++j)
				{
					c[j] = temp[j];
				}
				data[count1][count2] = atoi(c);
				delete c;
				++count2;
				size = 0;
				temp.clear();
			}
			else
			{
				temp += str[i];
				++size;
			}
		}
		++count1;
		count2 = 0;
		str.clear();
	}
	int Ans[100][100] = {0};
	Ans[0][0] = data[0][0];
	for(int i = 1; i < (count1 + 1) / 2; ++i)
	{
		for(int j = 0; j < i; ++j)
		{
			Ans[i][j]     = max(data[i][j] + Ans[i - 1][j], Ans[i][j]);
			Ans[i][j + 1] = max(data[i][j + 1] + Ans[i - 1][j], Ans[i][j + 1]);
		}
	}
	for(int i = (count1 + 1) / 2; i < count1; ++i)
	{
		for(int j = 0; j < count1 - i; ++j)
		{
			Ans[i][j] = max(data[i][j] + Ans[i - 1][j], data[i][j] + Ans[i - 1][j + 1]);
		}
	}
	cout << Ans[count1 - 1][0] << endl;
}

int main()
{
	solve();
	return(0);
}