Toy Factory(LintCode 496):

Problem