#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class DengklekMakingChains { public:
	int maxBeauty(vector <string> chains)
	{
		int best = 0;
		for(int C=0; C<chains.size(); ++C) {
			best = max(best, single(chains[C]));
		}

		for(int L=0; L<chains.size(); ++L)
		{
			int vl = c__( string(chains[L].rbegin(), chains[L].rend()) );
			for(int R=0; R<chains.size(); ++R) if( L != R )
			{
				int v = vl + c__(chains[R]);
				for(int C=0; C<chains.size(); ++C) if(C!=L && C!=R)
					v += all(chains[C]);
				best = max(best, v);
			}
		}
		return best;
	}

	int single(const string& s)
	{
		int best = 0;
		for(int i=0; i<3; ++i)
			for(int k=i+1; k<=3; ++k) {
				int v = 0;
				for(int a=i; a<k; ++a)
					if(s[a]!='.')
						v += s[a]-'0';
					else
						goto next;
				best = max(best, v);
			next:;
			}
		return best;
	}
	int all(const string& s)
	{
		int v = 0;
		for(int a=0; a<3; ++a)
			if(s[a]!='.')
				v += s[a]-'0';
			else
				return 0;
		return v;
	}
	int c__(const string& s)
	{
		int v = 0;
		for(int a=0; a<3; ++a)
			if(s[a]!='.')
				v += s[a]-'0';
			else
				return v;
		return v;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, DengklekMakingChains().maxBeauty(chains));}
int main(){

CASE(0)
	string chains_[] = {".15", "7..", "402", "..3"};
	  vector <string> chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); 
	int _ = 19; 
	// .15 402 7..
END
CASE(1)
	string chains_[] = {"..1", "7..", "567", "24.", "8..", "234"};
	  vector <string> chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); 
	int _ = 36; 
	// ..1 567 234 8..
END
CASE(2)
	string chains_[] = {"...", "..."};
	  vector <string> chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); 
	int _ = 0; 
END
CASE(3)
	string chains_[] = {"16.", "9.8", ".24", "52.", "3.1", "532", "4.4", "111"};
	  vector <string> chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); 
	int _ = 28; 
	// .24 532 111 9.8
	// or
	// 9.8 532 111 16.
END
CASE(4)
	string chains_[] = {"..1", "3..", "2..", ".7."};
	  vector <string> chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); 
	int _ = 7; 
	// .7.
END
CASE(5)
	string chains_[] = {"412", "..7", ".58", "7.8", "32.", "6..", "351", "3.9", "985", "...", ".46"};
	  vector <string> chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); 
	int _ = 58; 
	// .58 412 351 985 7.8
END
CASE(6)
	string chains_[] = {"9..", "..9"};
	  vector <string> chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); 
	int _ = 18; 
END
CASE(7)
	string chains_[] = {"..1"};
	  vector <string> chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); 
	int _ = 1; 
END
}
// END CUT HERE
