def heaps(firstHeap, secondHeap, thirdHeap):
    total1 = 0
    total2 = 0

    while secondHeap > 2:
        firstHeap -= 1
        secondHeap -= 2
        total1 += 3

    while secondHeap > 0 and thirdHeap > 0:
        secondHeap -= 1
        thirdHeap -= 2
        total2 += 3
    
    return total1 + total2
