some changes: 1. ++i; 2. if (ans<0){ return -1;}