Implemted a upper bound fix

This version still gets Time Limit excedded