This is another continuation of https://cohost.org/fizbin/post/202670-a-supposed-straightf (programming puzzle about balanced strings) - if you haven't read that, this likely won't make sense, and you might not want to read this until you've tried solving the problem yourself one or more times.