← Home
package main

import (
	"bufio"
	"bytes"
	"io"
	"math/bits"
	"os"
	"strconv"
)

func main() {
	data, _ := io.ReadAll(os.Stdin)
	pos := 0
	next := func() uint64 {
		for pos < len(data) && (data[pos] < '0' || data[pos] > '9') {
			pos++
		}
		var x uint64
		for pos < len(data) && data[pos] >= '0' && data[pos] <= '9' {
			x = x*10 + uint64(data[pos]-'0')
			pos++
		}
		return x
	}

	n := int(next())

	const M = 64
	powCnt := make([]int, M)
	lbCnt := make([]int, M)

	maxLb := 0
	maxPow := -1

	for i := 0; i < n; i++ {
		v := next()
		lb := 0
		if v > 1 {
			lb = bits.Len64(v - 1)
		}
		lbCnt[lb]++
		if lb > maxLb {
			maxLb = lb
		}
		if v&(v-1) == 0 {
			k := bits.Len64(v) - 1
			powCnt[k]++
			if k > maxPow {
				maxPow = k
			}
		}
	}

	J := maxLb
	if maxPow+1 > J {
		J = maxPow + 1
	}
	if J < 1 {
		J = 1
	}

	A := make([]int, J+2)
	for j := J; j >= 1; j-- {
		A[j] = A[j+1] + lbCnt[j]
	}

	bnext := 0
	nextL := []int{0}
	nextR := []int{0}

	for j := J; j >= 2; j-- {
		b := powCnt[j-1]
		curL := make([]int, b+1)
		curR := make([]int, b+1)
		has := false
		for h := 0; h <= b; h++ {
			idx := h
			if idx > bnext {
				idx = bnext
			}
			if nextL[idx] <= nextR[idx] {
				need := A[j] - h
				if nextR[idx] >= need {
					lt := nextL[idx]
					if need > lt {
						lt = need
					}
					l := h + lt
					r := h + nextR[idx]
					if !has {
						curL[h] = l
						curR[h] = r
						has = true
					} else {
						curL[h] = curL[h-1]
						curR[h] = curR[h-1]
						if r > curR[h] {
							curR[h] = r
						}
					}
					continue
				}
			}
			if has {
				curL[h] = curL[h-1]
				curR[h] = curR[h-1]
			} else {
				curL[h] = 1
				curR[h] = 0
			}
		}
		nextL, nextR = curL, curR
		bnext = b
	}

	diff := make([]int, n+3)
	b0 := powCnt[0]

	for h := 0; h <= b0; h++ {
		idx := h
		if idx > bnext {
			idx = bnext
		}
		if nextL[idx] <= nextR[idx] {
			need := A[1] - h
			if nextR[idx] >= need {
				lt := nextL[idx]
				if need > lt {
					lt = need
				}
				l := h + lt
				r := h + nextR[idx]
				upper := r
				lim := n - h
				if upper > lim {
					upper = lim
				}
				if l <= upper {
					ml := n - upper
					mr := n - l
					if ml < 1 {
						ml = 1
					}
					if mr > n {
						mr = n
					}
					if ml <= mr {
						diff[ml]++
						diff[mr+1]--
					}
				}
			}
		}
	}

	var out bytes.Buffer
	cur := 0
	first := true
	for m := 1; m <= n; m++ {
		cur += diff[m]
		if cur > 0 {
			if !first {
				out.WriteByte(' ')
			}
			first = false
			out.WriteString(strconv.Itoa(m))
		}
	}
	if first {
		out.WriteString("-1")
	}
	out.WriteByte('\n')

	w := bufio.NewWriterSize(os.Stdout, 1<<20)
	w.Write(out.Bytes())
	w.Flush()
}