← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	// Fast I/O
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	// Reading n
	if _, err := fmt.Fscan(reader, &n); err != nil {
		return
	}

	a := make([]int, n)
	sumA := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
		sumA += a[i]
	}

	// Sort a in descending order to apply Erdős-Gallai checks efficiently
	sort.Slice(a, func(i, j int) bool {
		return a[i] > a[j]
	})

	// Prefix sums of a (1-based for convenience in formulas)
	p := make([]int, n+1)
	for i := 0; i < n; i++ {
		p[i+1] = p[i] + a[i]
	}

	// Function to calculate sum_{j=start}^{n} min(a[j-1], limit)
	// indices of a are 0..n-1
	calcSumMin := func(start int, limit int) int {
		if start > n {
			return 0
		}
		// a is sorted descending. Find index i such that a[i] < limit.
		// We search in range [start-1, n).
		// We need the first index idx >= start-1 where a[idx] < limit.
		
		// slice to search is a[start-1:]
		offset := start - 1
		count := n - offset
		
		idx := sort.Search(count, func(i int) bool {
			return a[offset+i] < limit
		})
		idx += offset // Convert back to absolute index in a
		
		// Elements in a[start-1 ... idx-1] are >= limit, so min(a[k], limit) = limit
		cntBig := idx - (start - 1)
		term1 := cntBig * limit
		
		// Elements in a[idx ... n-1] are < limit, so min(a[k], limit) = a[k]
		term2 := p[n] - p[idx]
		
		return term1 + term2
	}

	// Precompute constraints
	// We want to find x such that the sequence a + {x} is graphical.
	// Let the sorted sequence of a + {x} be d_1 >= ... >= d_{n+1}.
	// The position of x depends on its value.
	// Let c be the count of elements in a that are >= x.
	// Then d_1...d_c are from a, d_{c+1} = x, d_{c+2}...d_{n+1} are the rest of a.
	
	// Conditions derived from EG theorem:
	// 1. For k <= c: min(x, k) >= Val_k
	//    Where Val_k = S_k - k(k-1) - sum_{j=k+1}^n min(a_j, k)
	//    Actually, if Val_k > k, no solution. Else we need x >= Val_k.
	// 2. For p >= c: x <= H_p
	//    Where H_p = p(p+1) + sum_{j=p+1}^n min(a_j, p+1) - S_p
	
	val := make([]int, n+1)
	for k := 1; k <= n; k++ {
		s_k := p[k]
		term := calcSumMin(k+1, k)
		val[k] = s_k - k*(k-1) - term
	}

	h := make([]int, n+2)
	// Calculate H_p for p = 1 to n
	for pIdx := 1; pIdx <= n; pIdx++ {
		s_p := p[pIdx]
		term := calcSumMin(pIdx+1, pIdx+1)
		h[pIdx] = pIdx*(pIdx+1) + term - s_p
	}
	
	// Special case for c=0, we need H_0 corresponding to checking index 1 (where x is)
	// H_0 = 0*(1) + sum_{j=1}^n min(a_j, 1) - 0
	h0 := calcSumMin(1, 1)

	// Suffix min for H to quickly check "for all p >= c, x <= H_p"
	suffixMinH := make([]int, n+2)
	inf := int(2e18) // Sufficiently large
	suffixMinH[n+1] = inf
	curMin := inf
	for i := n; i >= 1; i-- {
		if h[i] < curMin {
			curMin = h[i]
		}
		suffixMinH[i] = curMin
	}

	var results []int
	
	// Max Val_k encountered so far for k <= c
	curMaxVal := -inf
	possible := true

	// Iterate over possible split points c (number of a_i >= x)
	// x will belong to range roughly (a[c], a[c-1]]
	for c := 0; c <= n; c++ {
		// Update conditions from Val_{c}
		if c > 0 {
			if val[c] > c {
				possible = false // Impossible if Val_k > k
			}
			if val[c] > curMaxVal {
				curMaxVal = val[c]
			}
		}
		if !possible {
			break
		}

		// Range for x implied by sort order with a
		// If c=0, x > a[0] (but max x is n). Actually x can be > a[0].
		// If c=n, x <= a[n-1] and x >= 0.
		// a is 0-indexed: a[0] >= ... >= a[n-1]
		// x is inserted after c elements.
		// So x <= a[c-1] (if c>0)
		// x > a[c] (if c<n) => x >= a[c] + 1
		
		upper := n
		if c > 0 {
			upper = a[c-1]
		}
		
		lower := 0
		if c < n {
			lower = a[c] + 1
		}
		
		// Constraint x >= curMaxVal
		// Constraint x <= min_{p=c}^n H_p
		// Note: indices for H are 1..n.
		// If c=0, we need min(H_0, min_{p=1}^n H_p)
		
		limitH := curMin
		if c == 0 {
			limitH = h0
			if n > 0 && suffixMinH[1] < limitH {
				limitH = suffixMinH[1]
			}
		} else {
			limitH = suffixMinH[c]
		}
		
		start := lower
		if curMaxVal > start {
			start = curMaxVal
		}
		end := upper
		if limitH < end {
			end = limitH
		}

		if start <= end {
			// Total sum of degrees must be even.
			// sumA + x = even
			parity := sumA % 2
			
			// Adjust start to match parity
			s := start
			if s%2 != parity {
				s++
			}
			for x := s; x <= end; x += 2 {
				results = append(results, x)
			}
		}
	}

	if len(results) == 0 {
		fmt.Fprintln(writer, -1)
	} else {
		sort.Ints(results)
		for i, v := range results {
			if i > 0 {
				fmt.Fprint(writer, " ")
			}
			fmt.Fprint(writer, v)
		}
		fmt.Fprintln(writer)
	}
}
```