Facebook Hacker Cup 2013 Qualification Round Problem 1 - Beautiful Strings - Python