Solution for Balanced Smileys problem