Fixed bugs and passed input tests