The expected cost of a molecule in the reaction pathway is the cumulative penalties of all reactions and end-point molecules from the sub-pathway from the molecule as target molecule to its sub-branches, (Eq. 3). The expected cost of a molecule is also equal to the penalty of the reaction linked with the molecule as a product, plus expected costs of all reactants in the reaction. For example, in Figure , the expected cost of 𝑚 / is the sum of penalty of a building block 𝑚 " , and a max-length molecule 𝑚 01 , plus the penalty of reactions 𝑟 0 and 𝑟 ! .