package main import ( "fmt" "sort" ) var MOD_VAL int = 1000000000 + 7 func fact(n int) int { if n <= 1 { return n } return n * fact(n-1) % MOD_VAL } func countBits(v int) (n int) { for v > 0 { n += v & 1 v >>= 1 } return } var N, K int var as, nBits []int func main() { fmt.Scan(&N, &K) as = make([]int, K) nBits = make([]int, K) for i := 0; i < K; i++ { fmt.Scan(&as[i]) nBits[i] = countBits(as[i]) } fmt.Println(solve()) } func solve() int { sort.Ints(as) for i := 0; i < K-1; i++ { if as[i]|as[i+1] != as[i+1] { return 0 } } if len(nBits) == 0 || len(nBits) > 0 && nBits[len(nBits)-1] < N { nBits = append(nBits, N) } sort.Ints(nBits) // fmt.Printf("N = %d, K = %d\n", N, K) // fmt.Println(as) // fmt.Println(nBits) preVal := 0 ret := 1 for _, v := range nBits { gap := v - preVal if gap == 0 { ret = 0 break } ret *= fact(gap) ret %= MOD_VAL preVal = v } return ret }