add sys.stdout.flush() before second solution