from collections import deque
def calc(state, B, C):
score = 0
total = 0
for i in range(2):
for j in range(3):
if state[i*3+j] == state[(i+1)*3+j]:
score += B[i][j]
total += B[i][j]
for i in range(3):
for j in range(2):
if state[i*3+j] == state[i*3+(j+1)]:
score += C[i][j]
total += C[i][j]
return score
def simulate(state, turn, memo, B, C):
if state in memo:
return memo[state]
if 0 not in state:
return calc(state, B, C)
next_turn = 3-turn
if turn == 1:
score = 0
else:
score = float("inf")
for i in range(9):
if state[i] == 0:
next_state = list(state)
next_state[i] = turn
next_state = tuple(next_state)
next_score = simulate(next_state, next_turn, memo, B, C)
if turn == 1:
score = max(score, next_score)
else:
score = min(score, next_score)
memo[state] = score
return score
def main():
B = [list(map(int, input().split())) for _ in range(2)]
C = [list(map(int, input().split())) for _ in range(3)]
memo = {}
state = (0, 0, 0, 0, 0, 0, 0, 0, 0)
score = simulate(state, 1, memo, B, C)
total = sum(map(sum, B)) + sum(map(sum, C))
print(score)
print(total-score)
if __name__ == "__main__":
main()