nums = list(map(int,input().split()))
# DFS + Back tracking
courses = {
0: list(range(20))+[31],
1: [5,20,21,22]+[28,29,30,31],
2: [10,23,24]+[28,29,30,31],
3: [15,25,26,27]+[28,29,30,31],
}
scores = list(range(0,40,2))+[13,16,19]+[22,24]+[28,27,26]+[25,30,35,40]
horses = [
[0,0] for _ in range(4) # courses, course index
]
board = [0] * 32
answer = 0
result = 0
def dfs(turn):
global answer,result
if turn == 10:
answer = max(result, answer)
else:
for horse in horses:
if horse[0] != 5: # end horse
if horse[1]+nums[turn]>=len(courses[horse[0]]):
board[courses[horse[0]][horse[1]]] = 0
prev_horse = [horse[0],horse[1]]
horse[0] = 5
dfs(turn+1)
horse[0] = prev_horse[0]
board[courses[horse[0]][horse[1]]] = 1
else:
prev_horse = [horse[0],horse[1]]
next_idx = courses[horse[0]][horse[1]+nums[turn]]
score = scores[next_idx]
if board[next_idx] == 0:
result += score
board[courses[horse[0]][horse[1]]] = 0
board[next_idx] = 1
if next_idx in [5,10,15] and horse[0]==0:
horse[0] = next_idx//5
horse[1] = 0
else:
horse[1] = horse[1]+nums[turn]
dfs(turn+1)
board[next_idx] = 0
result -= score
horse[0],horse[1] = prev_horse[0],prev_horse[1]
board[courses[horse[0]][horse[1]]] = 1
else:
continue
dfs(0)
print(answer)