hw3: add boundary checks to input