sorry that i mus be forget to that minus sign during .I will update the correct code again with ~1 and using std::min one .