straightforwar encoding of magic sequence problem