Fixed minor bug, now works correctly - accepted by Kattis