#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<string> split_naive(const string &s, char delim) {
	vector<string> elems;
	string item;
	for(char ch:s){
		if(ch==delim){
			if(!item.empty()) elems.push_back(item);
			item.clear();
		}
		else{
			item += ch;
		}
	}
	if(!item.empty()) elems.push_back(item);
	return elems;
}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

class BellmanFord{
	vector<ll> dist;
	set<ll> visit;
	bool ignore_unrelated_loop{false};

	bool CanReachImpl(int start,int end,ConnectNodeInfo& connect){
		bool reach=false;
		if(start==end) return true;

		for(int i=0,ei=connect[start].size();i<ei;i++){
			auto res = visit.emplace(connect[start][i].first);
			if(!res.second) continue;
			reach |= CanReachImpl(connect[start][i].first,end,connect);
		}
		return reach;
	}
	bool CanReach(int start,int end,ConnectNodeInfo& connect){
		visit.clear();
		visit.emplace(start);
		return CanReachImpl(start,end,connect);
	}
public:
	pair<ll,bool> CalcShortestPath(int start,int end,ConnectNodeInfo& connect){
		dist.resize(connect.size(),1LL<<60);

		dist[start] = 0;
		for(int i=0,ei=dist.size();i<ei;i++){
			for(int u=0,eu=connect.size();u<eu;u++){
				for(int v=0,ev=connect[u].size();v<ev;v++){
					auto& e = connect[u][v];

					if(dist[e.first]>dist[u]+e.second){
						dist[e.first] = dist[u]+e.second;
						if(i==ei-1){
							if(!ignore_unrelated_loop || (CanReach(start,u,connect) && CanReach(u,end,connect))){
								return make_pair(dist[end],false);
							}
						}
					}
				}
			}
		}
		return make_pair(dist[end],true);
	}
	void SetIgnoreUnrelatedLoop(bool flag){ignore_unrelated_loop=flag;}
};

int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	string S;
	vector<string> A;
	while(cin>>S){
		A.push_back(S);
	}
	int num = A.size();
	int EVN = num/2+1;
	int VN = EVN*EVN;
	ConnectNodeInfo connect(VN);
	int sum = 0;
	int ans = 0;
	REP(i,num){
		auto T = split_naive(A[i],',');
		for(int j=0,ej=T.size();j<ej;j++){
			int y;
			sscanf(T[j].c_str(),"%d",&y);
			if(!i) ans = y;
			if(i<EVN){
				if(j>0) connect.AddDirectionalConnection(sum-ej,sum,-y);
				if(j<ej-1) connect.AddDirectionalConnection(sum-ej+1,sum,-y);
			}
			else{
				connect.AddDirectionalConnection(sum-ej-1,sum,-y);
				connect.AddDirectionalConnection(sum-ej,sum,-y);
			}
			sum++;
		}
	}

	BellmanFord BF;
	auto res = BF.CalcShortestPath(0,VN-1,connect);

	out(ans-res.first);
	
	return 0;
}


Measured memory_bytes: 3476