#include <iostream>
#include <vector>
using namespace std;
struct node {
int idx;
int path_idx;
};
node horse[4];
bool visited[34];
vector<pair<int, int> > adj[4];
vector<pair<int, int> > tmp_v[4] = { { {21,0} },
{ {22,13},{23,16},{24,19},{25,25},{31,30},{32,35},{20,40},{21,0} },
{ {29,22},{30,24},{25,25},{31,30},{32,35},{20,40},{21,0} },
{ {28,28},{27,27},{26,26},{25,25},{31,30},{32,35},{20,40},{21,0} } };
int ans = 0;
int dice[10];
node move(int i, int cnt) {
int idx = horse[i].idx;
int path_idx = horse[i].path_idx;
idx += cnt;
if (idx >= adj[path_idx].size()) idx = adj[path_idx].size() - 1;
// 경로 1로 변경되는 경우
if (adj[path_idx][idx].first == 5) {
path_idx = 1;
}
// 경로 2
else if (adj[path_idx][idx].first == 10) {
path_idx = 2;
}
// 경로 3
else if (adj[path_idx][idx].first == 15) {
path_idx = 3;
}
if (adj[path_idx][idx].first != 21 && visited[adj[path_idx][idx].first]) return { -1,-1 };
return { idx,path_idx };
}
void dfs(int dice_idx, int sum) {
if (dice_idx == 10) {
if (ans < sum) ans = sum;
return;
}
for (int i = 0; i < 4; i++) {
// 해당 말이 도착한 경우 제외
if (adj[horse[i].path_idx][horse[i].idx].first == 21) continue;
node tmp = move(i, dice[dice_idx]);
if (tmp.idx == -1) continue;
// 현재 위치, 다음 위치 갱신
int next_idx = adj[tmp.path_idx][tmp.idx].first;
int cur_idx = adj[horse[i].path_idx][horse[i].idx].first;
int next_w = adj[tmp.path_idx][tmp.idx].second;
visited[cur_idx] = false;
visited[next_idx] = true;
node tmp1 = horse[i];
horse[i] = tmp;
dfs(dice_idx + 1, sum + next_w);
if (next_idx != 21) {
visited[next_idx] = false;
}
visited[adj[tmp1.path_idx][tmp1.idx].first] = true;
horse[i] = tmp1;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
for (int i = 0; i <= 20; i++) {
adj[0].push_back({ i,i * 2 });
if (i <= 5) {
adj[1].push_back({ i,i * 2 });
}
if (i <= 10) {
adj[2].push_back({ i,i * 2 });
}
if (i <= 15) {
adj[3].push_back({ i,i * 2 });
}
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < tmp_v[i].size(); j++) {
adj[i].push_back(tmp_v[i][j]);
}
}
for (int i = 0; i < 10; i++) {
cin >> dice[i];
}
dfs(0, 0);
cout << ans << "\n";
return 0;
}