Java code passed, python fails on test 5