     6: 155
 
 
-   PARENT_POSITION_COST = 1000
-   EMPTY_PAGE_COST = 1000
+   PARENT_POSITION_COST = 500
+   EMPTY_PAGE_COST = 200
 
    PAGE_MARGIN = '1000px'
    START = 1

      @broken.push INF
      @nextBreak.push null

     @breakCostMap = {}
     @breakCostPositionMap = {}
     @breakCost = []

     for i in @mainNodes
      @breakCost.push (@getBreakCost @map.nodes[i]) +
                      (@getBreakTopCost @map.nodes[i])

     n = @mainNodes.length - 1
     while n >= 1

     p = Math.max p, 0.01
     #p = Math.sqrt p
     p = Math.min 1, p
     return EMPTY_PAGE_COST * (1 / p - 1)

    _parentPositionCost: (pos) ->
     p = pos / @pageHeight
     p = Math.max p, 0.01
     #p = Math.sqrt p
     p = Math.min 1, p
     return PARENT_POSITION_COST * (1 / p - 1)


    getNodeBreakCost: (node) ->
     if BREAK_COST[node.type]?
      return BREAK_COST[node.type]
     else if node.type is 'section'
      return SECTION_BREAK_COST[node.level]
     else
      throw new Error 'Unknown type'

    getBreakCost: (node) ->
     parent = node.parent()
     cost = 0

     if parent?
      cost += @getNodeBreakCost parent
      while parent?
       pos = (@getOffsetTop node.elem, @elems.main) -
             (@getOffsetTop parent.elem, @elems.main)
       cost += @_parentPositionCost pos
       parent = parent.parent()
     else
      if node.type isnt 'article'
       throw new Error 'Node without a parent'

     return cost

    getOffsetTop: (elem, parent) ->
     top = 0
