#include<bits/stdc++.h>
using namespace std;


vector<vector<int>> in;
pair<string,int> c(string s){
  stringstream ss(s);
  int n;
  ss>>n;
  char c;
  string res;
  ss>> c;
  ss>>res;
  return make_pair(res,n);
}
vector<int> comv(string s){
  vector<int> res;
  while(s.size()!=0){
    auto cc = c (s);
    s = cc.first;
    res.push_back(cc.second);
  }
  return res;
}
bool input(){
  string s;
  in.clear();
  while(cin>>s){
    auto next = comv(s);
    if(in.size()!=0&&in[in.size()-1].size()>next.size()){
      vector<int> tmp = next;
      int diff = in[in.size()-1].size()-next.size();
      next = vector<int>();
      for(int i=0;i<diff;i++){
        next.push_back(0);
      }
      for(int i=0;i<tmp.size();i++){
        next.push_back(tmp[i]);
      }
    }
    in.push_back(next);
  }
  return true;
}

vector<vector<int>> dp;

int solve(){
  dp.clear();
  dp.resize(in.size());
  for(int i=0;i<in.size();i++){
    dp[i].resize(in[i].size());
    for(int j=0;j<in[i].size();j++){
      dp[i][j] = 0;
    }
  }
  dp[0][0] = in[0][0];

  for(int i=1;i<in.size();i++){
    for(int j=0;j<in[i].size();j++){
      dp[i][j] = dp[i-1][j];
      if(j-1>=0) dp[i][j] = max(dp[i][j],dp[i-1][j-1]);
      dp[i][j] += in[i][j];
    }
  }
  return dp[dp.size()-1][dp[dp.size()-1].size()-1];
}


int main(){
  input();
  cout<<solve()<<endl;
}