prime=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
perfer=[9,16,25,36,49]
special=[7,12,17,22,27,35,40,45,50]

def in_prime(loc,m):
    for i in range(1,7):
        if m[loc+i]:
            return loc+i-1
    return loc+6
def in_perfer(loc,m):
    for i in range(1,7):
        if m[loc-i]:
            return loc-i+1
    return loc-6
def judge(x1,x2):
    for i in special:
        if x1i:
            return True
    return False
def in_special(x1,x2,d,m):
    for i in range(x2,x1,-d):
        if not m[i]:
            return i
    return x1

def move(l,distance):
    end=l+distance
    if maps[end] or end>52:return l
    if end in prime:
        return in_prime(end,maps)
    elif end in perfer:
        return in_perfer(end,maps)
    elif judge(l,end):
        end=end-end%distance
        return in_special(l,end,distance,maps)
    return end

def oppoent_move(index):
    num=oppoent.index(min(oppoent))
    location=oppoent[num]
    maps[location]=False
    new_location=move(location,actions[index])
    maps[new_location]=True
    oppoent[num]=new_location

def player_move(index):
    num=player.index(min(player))
    location=player[num]
    maps[location]=False
    new_location=move(location,actions[index])
    maps[new_location]=True
    player[num]=new_location

for i in range(5):
    maps=[False for i in range(53)]
    line=list(map(int,input().split()))
    for i in line[:6]:
        maps[i]=True
    oppoent,player,actions=line[:3],line[3:6],line[7:]
    oppoent.sort()
    player.sort()
    for i in range(line[6]):
        if i%2==0:oppoent_move(i)
        else:player_move(i)
    result=str(sum(oppoent))+" "+str(sum(player))
    print(result)