Rebuild the memoization formula to correspond to Rong's requirement on easy additional analysis, removed the unefficient buffering.