use std::min

Change-Id: I8ffaf5e5ed418901658ca6b7e3d1ad369ee0baba
delete all programs at the end

Change-Id: I6a2e0a70e9b6eadcb869596471f702bca4145336