Balance problem

code from here