Codeforces 8E Beads

This is a difficult one. First. If we have a method “solve”, given some fixed digits and given some undetermined…