This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved.

First, Aoi came up with the following idea for the competitive programming problem:

Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies.

Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array).

After that, she will do $n$ duels with the enemies with the following rules:  If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing.  The candy which Yuzu gets will be used in the next duels. 

Yuzu wants to win all duels. How many valid permutations $P$ exist?

This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea:

Let's define $f(x)$ as the number of valid permutations for the integer $x$.

You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$.

Your task is to solve this problem made by Akari.


-----Input-----

The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$).

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$.


-----Output-----

In the first line, print the number of good integers $x$.

In the second line, output all good integers $x$ in the ascending order.

It is guaranteed that the number of good integers $x$ does not exceed $10^5$.


-----Examples-----
Input
3 2
3 4 5

Output
1
3

Input
4 3
2 3 5 6

Output
2
3 4

Input
4 3
9 1 1 1

Output
0




-----Note-----

In the first test, $p=2$.  If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good.  If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good.  If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good.  If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. 

So, the only good number is $3$.

In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.

Difficulty: HARD

Solutions:
def smallest_winner(matrix, starting_x, x):
	for m in matrix:
		if m > x:
			starting_x += m - x
			x += m - x
		x += 1
	return starting_x

def biggest_winner(matrix, p, maxi):
	for i in range(len(matrix)):
		if i + p - 1 >= len(matrix):
			break
		maxi = min(maxi, matrix[i + p - 1] - i)
	return maxi
(n, p) = map(int, input().split())
matrix = sorted(list(map(int, input().split())))
res = [i for i in range(smallest_winner(matrix, 1, 1), biggest_winner(matrix, p, matrix[-1]))]
print(len(res))
print(' '.join(map(str, res)))


def smallest_winner(matrix):
	starting_x = 1
	x = 1
	for m in matrix:
		if m > x:
			starting_x += m - x
			x += m - x
		x += 1
	return starting_x

def biggest_winner(matrix, p):
	maxi = matrix[-1]
	for i in range(len(matrix)):
		if i + p - 1 >= len(matrix):
			break
		temp = matrix[i + p - 1] - i
		maxi = min(maxi, temp)
	return maxi

def check_multiple(matrix):
	count = 0
	maxi = 0
	for i in range(1, len(matrix)):
		if matrix[i] == matrix[i - 1]:
			count += 1
		else:
			count = 1
		maxi = max(maxi, count)
	return maxi

def solve(n, p, matrix):
	matrix = sorted(matrix)
	min_x = smallest_winner(matrix)
	max_x = biggest_winner(matrix, p) - 1
	return [i for i in range(min_x, max_x + 1)]
(n, p) = map(int, input().split())
matrix = map(int, input().split())
res = solve(n, p, matrix)
print(len(res))
print(' '.join(map(str, res)))


from sys import stdin, stdout

def asterism(n, p, a):
	res = []
	a.sort()
	l = a[n - 1]
	for i in range(n - 1, -1, -1):
		l = max(a[i], l)
		l -= 1
	l += 1
	minl = l
	if check(bs(minl, a), minl, a, p):
		return res
	h = max(minl, a[n - 1] - 1)
	while l < h:
		m = (l + h + 1) // 2
		idx = bs(m, a)
		if not check(idx, m, a, p):
			l = m
		else:
			h = m - 1
	for i in range(minl, l + 1):
		res.append(i)
	return res

def check(idx, v, a, p):
	for i in range(len(a)):
		if idx + 1 - i >= p:
			return True
		v += 1
		idx += 1
		if idx == len(a):
			break
		while idx < len(a) and a[idx] <= v:
			idx += 1
		idx -= 1
	return False

def bs(v, a):
	l = 0
	h = len(a) - 1
	while l < h:
		m = (l + h + 1) // 2
		if a[m] > v:
			h = m - 1
		else:
			l = m
	return l
(n, p) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
res = asterism(n, p, a)
stdout.write(str(len(res)) + '\n')
if len(res) > 0:
	stdout.write(' '.join(map(str, res)) + '\n')


def binary(arr, x, n, p):
	less = 0
	for i in range(n):
		while less < n and x + i >= arr[less]:
			less += 1
		C = less - i
		if C <= 0:
			return -1
		if C >= p:
			return 1
	return 0

def help():
	(n, p) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	arr.sort()
	start = 0
	end = 1000000001
	mini = 1000000001
	while start <= end:
		mid = (start + end) // 2
		temp = binary(arr, mid, n, p)
		if temp == 0:
			mini = min(mid, mini)
		if temp >= 0:
			end = mid - 1
		else:
			start = mid + 1
	start = 0
	end = 1000000001
	maxi = 0
	while start <= end:
		mid = (start + end) // 2
		temp = binary(arr, mid, n, p)
		if temp == 0:
			maxi = max(mid, maxi)
		if temp > 0:
			end = mid - 1
		else:
			start = mid + 1
	if maxi < mini:
		print(0)
		print()
		return
	print(maxi - mini + 1)
	for i in range(mini, maxi + 1):
		print(i, end=' ')
	print()
for _ in range(1):
	help()


(n, p) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
startno = l[-1] - n + 1
ans = []
for i in range(startno, l[-1] + 1):
	ind = 0
	flag = True
	for j in range(n):
		while ind < n and l[ind] <= i + j:
			ind += 1
		if ind >= n:
			if p <= n - j:
				flag = False
			break
		if (ind - j) % p == 0:
			flag = False
			break
	if flag == True:
		ans.append(i)
print(len(ans))
ans.sort()
print(*ans)


def func(length, prime):
	nums = sorted(map(int, input().split()))
	mini = max(nums[0], nums[-1] - length + 1)
	maxi = min(mini + length, nums[-1] + 1)
	L = maxi - mini
	idxs = [0] * length
	for i in range(L - 1, -1, -1):
		if mini + i == nums[-1]:
			idxs[-1] = length - i
			break
	for i in range(length - 2, -1, -1):
		diff = nums[i + 1] - nums[i]
		idxs[i] = min(length, idxs[i + 1] + diff)
	for i in range(length):
		idxs[i] -= length - 1 - i
	from collections import defaultdict
	num2i = defaultdict(set)
	bad = [False] * (length + 1)
	bad[0] = True
	for i in range(prime, length + 1, prime):
		bad[i] = True
	flag = False
	for (i, n) in enumerate(idxs):
		if n == i + 1:
			if bad[n]:
				flag = True
				break
		else:
			num2i[n].add(i)
	res = []
	incri = 0
	for x in range(mini, maxi):
		if flag:
			break
		if not any((bad[k + incri] for k in num2i.keys())):
			res.append(x)
		incri += 1
		for k in list(num2i.keys()):
			v = num2i[k]
			if k + incri - 1 in v:
				v.remove(k + incri - 1)
				if bad[k + incri]:
					flag = True
					break
				if not v:
					num2i.pop(k)
	print(len(res))
	print(' '.join(map(str, res)) if res else '')
for i in range(1):
	(n, k) = map(int, input().split())
	func(n, k)


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = 1
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		[n, p] = inlt()
		a = inlt()
		a.sort()
		ans = []
		maxi = a[-1]
		mini = max(a[-1] - n, a[0])
		for x in range(maxi, mini - 1, -1):
			flag = 0
			for j in range(n - 1, -1, -1):
				if a[j] <= x:
					break
				else:
					filled = n - 1 - j
					start = a[j] - x
					left = n - start - filled
					if left <= 0 or left % p == 0:
						flag = 1
						break
			if flag == 0:
				if j + 1 < p:
					ans.append(x)
		ans.reverse()
		print(len(ans))
		pr_list(ans)
main()


import sys, math, cmath, time
start_time = time.time()

def solve():
	(n, p) = invr()
	a = inlt()
	a.sort()
	q = a[-1]
	w = max(a[0], q - (n - 1))
	qw = []
	qq = 0
	for i in range(w, q + 1):
		while qq < n and a[qq] <= i:
			qq = qq + 1
		qw.append(qq)
	ww = []
	for i in range(len(qw)):
		if qw[i] >= p:
			break
		qwqw = 1
		for j in range(i, len(qw)):
			if qw[j] + i - j >= p or qw[j] + i - j <= 0:
				qwqw = 0
				break
		if qwqw == 1:
			ww.append(w + i)
	print(len(ww))
	print(*ww)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = (q[ord(a[i]) - 97], 1)
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	b = [[0] * n for i in range(n)]
	for i in range(len(a)):
		for j in range(len(a)):
			b[i][j] = a[j][i]
	return b
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


import sys
input = sys.stdin.readline
inputr = lambda : sys.stdin.readline().rstrip('\n')
from collections import Counter
(n, p) = map(int, input().split())
A = sorted(map(int, input().split()))
B = sorted(Counter(A).items())
M = max(n, p) + 1
fact = [1] * M
for i in range(2, M):
	fact[i] = fact[i - 1] * i % p
ifact = [1] * M
ifact[p - 1] = pow(fact[p - 1], p - 2, p)
for i in range(p - 1, -1, -1):
	ifact[i - 1] = ifact[i] * i % p
min_pow = x = 1
for (k, v) in B:
	if x < k:
		min_pow += k - x
		x = k
	x += v

def check(x):
	i = 0
	r = 1
	candef = 0
	while True:
		while i < len(B) and x >= B[i][0]:
			candef += B[i][1]
			i += 1
		if i == len(B):
			r *= fact[candef]
			r %= p
			break
		need = B[i][0] - x
		if candef < need:
			r = 0
			break
		r *= fact[candef] * ifact[candef - need]
		r %= p
		candef -= need
		x += need
	return r != 0
lo = min_pow
hi = max(A) + 1
while lo < hi:
	m = (lo + hi) // 2
	if check(m):
		lo = m + 1
	else:
		hi = m
print(hi - min_pow)
print(*range(min_pow, hi))


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mx = -float('inf')
for i in range(n):
	if a[i] - i > mx:
		mx = a[i] - i
		imx = i
flag = True
nmx = -float('inf')
for i in range(p - 1, n):
	if mx + i - (p - 1) >= a[i]:
		flag = False
		break
	nmx = max(nmx, mx + i - p - a[i] + 1)
if flag:
	print(-nmx)
	for i in range(0, -nmx):
		print(mx + i, end=' ')
	print()
else:
	print(0)


import sys
input = sys.stdin.readline
(n, p) = map(int, input().split())
A = sorted(map(int, input().split()))
MAX = A[-1]
start = max(A[0], MAX - (n - 1))
S = []
ind = 0
for c in range(start, MAX + 1):
	while ind < n and A[ind] <= c:
		ind += 1
	S.append(ind)
SS = [S[i] - i for i in range(len(S))]
MAX = 10 ** 9
MIN = 0
for i in range(len(S)):
	if SS[i] <= 0:
		MIN = max(MIN, 1 - SS[i])
	elif p - 1 - S[i] + i < i:
		MAX = min(MAX, p - 1 - S[i] + i)
ANS = []
for i in range(MIN, MAX + 1):
	ANS.append(start + i)
print(len(ANS))
print(*ANS)


import math
from collections import defaultdict, deque
from sys import stdin
from bisect import bisect_left, bisect_right

def mp():
	return map(int, stdin.readline().split())

def ml():
	return list(map(int, stdin.readline().split()))

def isGood(a, x):
	for i in range(n):
		v = bisect_right(a, x + i) - i
		if v % p == 0:
			return False
	return True
for _ in range(1):
	(n, p) = mp()
	a = ml()
	a.sort()
	base = a[0]
	(m, ansArray) = (a[n - 1], [])
	for i in range(1, n):
		base += a[i] - a[i - 1] - 1
	for x in range(base, m):
		if isGood(a, x):
			ansArray.append(x)
	print(len(ansArray))
	print(*ansArray)


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	from collections import Counter
	input = sys.stdin.readline
	(N, p) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	x0 = -1
	for i in range(N):
		x0 = max(x0, A[i] - i)
	x1 = A[p - 1]
	dic = {}
	i = 0
	for x in range(x0, x0 + 10 ** 5 + 1):
		while True:
			if i == N - 1:
				break
			if A[i + 1] <= x:
				i += 1
			else:
				break
		dic[x] = i + 1
	ans = []
	for x in range(x0, x1):
		flg = 1
		for i in range(N):
			if (dic[x + i] - i) % p == 0:
				flg = 0
				break
		if flg:
			ans.append(x)
	print(len(ans))
	print(*ans)
main()


(n, p) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
smalls = [l[i] - i for i in range(n)]
tols = [l[i] - i + p - 1 for i in range(p - 1, n)]
smol = max(smalls)
tol = min(tols)
out = list(range(smol, tol))
print(len(out))
print(' '.join(map(str, out)))


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
d = {}

def bin(a, k):
	cnt = bsr(a, k)
	for i in range(n):
		if cnt >= p:
			return True
		cnt -= 1
		k += 1
		if k in d:
			cnt += d[k]
	return False
dp = [1] * 100001
for _ in range(t):
	(n, p) = list(map(int, stdin.readline().rstrip().split()))
	a = list(map(int, stdin.readline().rstrip().split()))
	a.sort()
	for i in range(n):
		a[i] -= i
	mi = max(a)
	for i in range(n):
		a[i] += p - 1
	ma = min(a[p - 1:])
	print(max(ma - mi, 0))
	print(*list(range(mi, ma)))


import bisect
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
xmin = a[-1] - n + 1
v = []
for x in range(xmin, xmin + n):
	v.append(bisect.bisect(a, x))
mods = [0] * p
mod_shift = 0
mi = n + 1
xs = []
for i in range(len(v) - 1, -1, -1):
	mi = min(mi - 1, v[i])
	mod_shift = (mod_shift + 1) % p
	mods[(mod_shift + v[i]) % p] += 1
	if i < p and mi >= 0 and (mods[mod_shift] == 0):
		xs.append(xmin + i)
print(len(xs))
print(*xs[::-1])


from bisect import bisect_right as br
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
(n, p) = MI()
aa = LI()
aa.sort()

def low(x):
	for i in range(n):
		if br(aa, i + x) - i < 1:
			return False
	return True
l = min(aa) - 1
r = max(aa) + 1
while l + 1 < r:
	x = (l + r) // 2
	if low(x):
		r = x
	else:
		l = x
mn = r

def high(x):
	for i in range(n):
		if br(aa, i + x) - i >= p:
			return False
	return True
l = mn - 1
r = max(aa) + 1
while l + 1 < r:
	x = (l + r) // 2
	if high(x):
		l = x
	else:
		r = x
mx = l
ans = list(range(mn, mx + 1))
print(len(ans))
print(*ans)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
(n, p) = MI()
a = sorted(LI())
for i in range(n):
	a[i] -= i
mi = max(a)
for i in range(n):
	a[i] += p - 1
ma = min(a[p - 1:])
print(max(ma - mi, 0))
print(*list(range(mi, ma)))


import sys
from collections import deque, defaultdict
from itertools import product
input = sys.stdin.buffer.readline
(n, p) = map(int, input().split())
ls = list(map(int, input().split()))
ls.sort()
(a, b) = (max(ls[-1] - (n - 1), 1), ls[-1])
res = []
for u in range(a, b, 1):
	sm = 1
	for i in range(n):
		if ls[i] <= u:
			sm *= i + 1
			sm %= p
		else:
			d = ls[i] - u
			sm *= i + 1 - d
			sm %= p
	if sm:
		res.append(u)
print(len(res))
print(*res)


import sys
input = sys.stdin.readline
import bisect
(n, p) = map(int, input().split())
a = [int(i) for i in input().split() if i != '\n']
a.sort()
(j, k) = (a[0], a[0])
for i in range(1, n):
	if a[i] - k > 1:
		j += a[i] - k - 1
		k = a[i]
	else:
		k += 1
unique = [1]
for i in range(1, n):
	unique.append(unique[-1] + 1)
mina = a[-1]
for i in range(n):
	bis = bisect.bisect(unique, i + p)
	mina = min(mina, a[bis - 1] - i)
	if bis == n:
		break
out = list(range(j, mina))
sys.stdout.write(str(len(out)) + '\n')
out = ' '.join(map(str, out))
sys.stdout.write(out)


import io
import os
from bisect import bisect_right
from collections import Counter
from functools import lru_cache

def solve(N, P, A):
	assert len(A) == N
	assert P <= N
	A.sort()
	minX = float('-inf')
	for x in A[::-1]:
		minX -= 1
		minX = max(minX, x)
	maxX = A[-1]

	@lru_cache(maxsize=None)
	def getNumLessEq(y):
		return bisect_right(A, y)
	ans = []
	for x in range(minX, maxX + 1):
		isBad = False
		for i in range(N):
			numLessEq = getNumLessEq(x + i) - i
			if numLessEq % P == 0:
				isBad = True
				break
		if not isBad:
			ans.append(x)
	return str(len(ans)) + '\n' + ' '.join(map(str, ans))
if False:
	N = 2000
	P = 1999
	A = list(range(1, N + 1))
	solve(N, P, A)
	exit()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N, P) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, P, A)
print(ans)


import sys
lines = sys.stdin.readlines()
(n, p) = map(int, lines[0].strip().split(' '))
arr = list(map(int, lines[1].strip().split(' ')))
arr.sort()
counter = {}
for a in arr:
	if a not in counter:
		counter[a] = 0
	counter[a] += 1
lower = max(arr[-1] - n + 1, 1)
(a, b, c, d) = (lower - 1, -1, -1, arr[-1] + 1)

def check(val):
	pt = 0
	cnt = 0
	while pt < n and arr[pt] <= val:
		cnt += 1
		pt += 1
	if cnt >= p:
		return 1
	while cnt > 0:
		val += 1
		cnt -= 1
		if val in counter:
			cnt += counter[val]
		if cnt >= p:
			return 1
		if val >= arr[-1]:
			break
	if cnt <= 0 or val < arr[-1]:
		return -1
	else:
		return 0
exist = False
while a < d - 1:
	mid = (a + d) // 2
	res = check(mid)
	if res == 1:
		d = mid
	elif res == -1:
		a = mid
	else:
		exist = True
		break
if exist:
	b = mid
	c = mid
	while a < b - 1:
		mid = (a + b) // 2
		res = check(mid)
		if res == 0:
			b = mid
		else:
			a = mid
	while c < d - 1:
		mid = (c + d) // 2
		if check(mid) == 1:
			d = mid
		else:
			c = mid
if exist:
	print(c - b + 1)
	print(' '.join(map(str, range(b, c + 1))))
else:
	print(0)
	print()


import copy
con = 10 ** 9 + 7
INF = float('inf')

def getlist():
	return list(map(int, input().split()))

def main():
	(N, P) = getlist()
	A = getlist()
	A = sorted(A)
	Xlis = []
	dif = 0
	for i in range(N):
		dif = max(dif, A[i] - i)
	for i in range(N):
		A[i] -= dif
	for s in range(N):
		B = copy.deepcopy(A)
		B.append(INF)
		for t in range(N):
			B[t] -= s
		array = [None] * N
		i = 0
		j = 0
		while True:
			if B[j] <= i:
				j += 1
			else:
				array[i] = j - i
				i += 1
			if i >= N:
				break
		jud = 'Yes'
		for t in range(N):
			if array[t] % P == 0:
				jud = 'No'
				break
		if jud == 'Yes':
			Xlis.append(s + dif)
	print(len(Xlis))
	print(*Xlis)
main()


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
left = 0
right = 10 ** 9 + 1
while right - left > 1:
	mid = left + (right - left) // 2
	x = mid
	flag = 1
	for i in range(n):
		if a[i] <= x:
			x += 1
		else:
			flag = 0
			break
	if flag:
		right = mid
	else:
		left = mid
ansleft = right
left = 0
right = 10 ** 9 + 1
while right - left > 1:
	mid = left + (right - left) // 2
	x = mid
	flag = 1
	r = 0
	for i in range(n):
		while r < n:
			if a[r] <= x:
				r += 1
			else:
				break
		if r - i >= p:
			flag = 0
			break
		x += 1
	if flag:
		left = mid
	else:
		right = mid
ansright = left
ans = [i for i in range(ansleft, ansright + 1)]
print(len(ans))
print(*ans)


def read_list():
	return list(map(int, input().strip().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
(n, p) = read_list()
a = read_list()
a.sort()
mi = max((a[i] - i for i in range(n)))
res = []
ll = []
x = mi
now = x
i = 0
dic = [[-1]]
for step in range(n):
	while i < n and now >= a[i]:
		i += 1
	now += 1
	tmp = (i - step) % p
	tmp = (p - tmp) % p
	if step >= tmp:
		dic.append([tmp, step])
dic.pop(0)
for i in range(len(dic) - 1, 0, -1):
	if dic[i][0] <= dic[i - 1][1] - 1:
		dic[i - 1][1] = dic[i][1]
		dic[i - 1][0] = min(dic[i][0], dic[i - 1][0])
		dic.pop(i)
las = 0
for d in dic:
	flag = True
	for i in range(las, d[0]):
		if i >= p - 1:
			flag = False
			break
		res.append(mi + i)
	las = d[1] + 1
	if not flag:
		break
if dic:
	for i in range(dic[-1][-1] + 1, p - 1):
		res.append(mi + i)
print(len(res))
print_list(res)


import sys

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def solve():
	(n, p) = LI()
	a = LI()
	a.sort()
	ap = [i for i in a[p - 1:]]
	ap = [ap[i] - i for i in range(len(ap))]
	M = min(ap)
	b = [a[i] - i for i in range(n)]
	m = max(b)
	ans = list(range(m, M))
	print(len(ans))
	print(*ans)
	return
solve()


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	from collections import Counter
	input = sys.stdin.readline
	(N, p) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	x0 = -1
	for i in range(N):
		x0 = max(x0, A[i] - i)
	x1 = A[p - 1]
	dic = {}
	i = 0
	for x in range(x0, x0 + 2 * 10 ** 5 + 1):
		while True:
			if i == N - 1:
				break
			if A[i + 1] <= x:
				i += 1
			else:
				break
		dic[x] = i + 1
	ok = x0 - 1
	ng = x1
	mid = (ok + ng) // 2
	while ng - ok > 1:
		x = mid
		flg = 1
		for i in range(N):
			if (dic[x + i] - i) % p == 0:
				flg = 0
				break
		if flg:
			ok = mid
		else:
			ng = mid
		mid = (ok + ng) // 2
	print(ok - x0 + 1)
	X = list(range(x0, ok + 1))
	print(*X)
main()


import sys
input = sys.stdin.readline

def judge1(x):
	c = 0
	ri = 0
	now = x
	for _ in range(n):
		while ri < n:
			if a[ri] <= now:
				c += 1
				ri += 1
			else:
				break
		if c == 0:
			return False
		c -= 1
		now += 1
	return True

def judge2(x):
	c = 0
	ri = 0
	now = x
	for _ in range(n):
		while ri < n:
			if a[ri] <= now:
				c += 1
				ri += 1
			else:
				break
		if c >= p:
			return False
		c -= 1
		now += 1
	return True
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
(l, r) = (0, 10 ** 9)
while l <= r:
	m = (l + r) // 2
	if judge1(m):
		r = m - 1
	else:
		l = m + 1
s = l
(l, r) = (0, 10 ** 9)
while l <= r:
	m = (l + r) // 2
	if judge2(m):
		l = m + 1
	else:
		r = m - 1
t = r
if s > t:
	print(0)
	exit()
print(t - s + 1)
print(*[i for i in range(s, t + 1)])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from bisect import bisect_right

def main():
	(n, pr) = RL()
	arr = RLL()
	arr.sort()
	mis = [arr[i] - i for i in range(n)]
	lb = max(mis)
	ub = arr[-1]
	res = []
	for i in range(lb, ub + 1):
		p = bisect_right(arr, i)
		now = 1
		ind = p
		bn = 0
		suf = p
		while ind:
			now = now * ind % pr
			ind -= 1
			bn += 1
			while suf < n and i + bn >= arr[suf]:
				ind += 1
				suf += 1
		if now % pr != 0:
			res.append(i)
	print(len(res))
	print(*res)
main()


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
ansls = []
mx = max(a)
mn = max([a[i] - i for i in range(n)])
ansmx = -1
for j in range(p - 1, n)[::-1]:
	ansmx = max(ansmx, n - max(mn, a[j]) + mn - (n - j - 1))
while ansmx < p:
	ans += 1
	ansls.append(mn)
	mn += 1
	ansmx += 1
print(ans)
print(*ansls)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
(n, p) = sp()
arr = l()
arr.sort()
answer = []
c = C(arr)
for x in range(arr[-1] - n + 1, arr[-1]):
	(temp, r) = (0, True)
	for i in range(n):
		if arr[i] >= x:
			break
		temp += 1
	i = x
	while i < x + n:
		temp += c[i]
		i += 1
		if not temp % p:
			r = False
			break
		temp -= 1
	if r:
		answer.append(x)
out(len(answer))
out(*answer)


(n, p) = map(int, input().split())
arr = list(map(int, input().split()))
(l, r) = (0, float('inf'))
arr.sort()
for i in range(len(arr)):
	l = max(l, arr[i] - i)
	if i + 1 >= p:
		r = min(r, arr[i] - i + p - 1)
print(max(0, r - l))
res = []
for i in range(l, r):
	res.append(i)
print(*res)


from sys import stdin
(n, p) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
a.sort()
x = 0
aa = []
j = 0
for i in range(n):
	if x + i < a[i]:
		x = a[i] - i
	if a[i] != a[j]:
		aa.append((a[j], i - j))
		j = i
else:
	aa.append((a[j], n - j))
C = 2000
(c, d) = (0, 0)
for i in range(len(aa)):
	if aa[i][0] <= x:
		c += aa[i][1]
	else:
		_d = aa[i][0] - x
		itv = _d - d
		d = _d
		c = c + aa[i][1] - itv
		if d + c >= p:
			C = min(C, p - 1 - c)
	if c >= p:
		C = -1
		break
print(C + 1)
print(' '.join([str(ans) for ans in range(x, x + C + 1)]))


import sys
import math
from math import factorial, inf, gcd, sqrt
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
from bisect import *
import random
sys.setrecursionlimit(10 ** 5)

def rarray():
	return [int(i) for i in input().split()]
t = 1
for ii in range(t):
	(n, p) = rarray()
	a = rarray()
	a.sort()
	(al, ar) = (a[0], a[p - 1] - 1)
	for i in range(n):
		(l, r) = (al + i, ar + i)
		if i + p - 1 < n:
			r = min(r, a[i + p - 1] - 1)
		if i + 1 < n:
			l = max(l, a[i + 1] - 1)
		al = max(al, l - i)
		ar = min(ar, r - i)
	if al > ar:
		print(0)
		print()
		continue
	print(ar - al + 1)
	for i in range(al, ar + 1):
		print(i, end=' ')
	print()


import sys
input = lambda : sys.stdin.readline().rstrip()
(n, p) = map(int, input().split())
A = sorted([int(i) for i in input().split()])
A = [A[i] - int(i) for i in range(n)]
AA = [A[-1]]
for i in range(n - 1):
	AA.append(min(AA[-1], A[n - 2 - i]))
AA = AA[::-1]
Ans = []
for i in range(max(A), max(A) + p + 1):
	if i - AA[p - 1] + 1 < p:
		Ans.append(i)
print(len(Ans))
print(*Ans)


from sys import stdin, gettrace
from collections import Counter
from functools import reduce
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():
	(n, p) = map(int, inputi().split())
	aa = [int(a) for a in inputi().split()]
	aa.sort()
	minx = 0
	pos = [0] * n
	for (i, a) in enumerate(aa):
		minx = max(minx, a - i)
		pos[i] = i + 1 - aa[i]
	res = []
	for x in range(minx, minx + n):
		for i in range(n):
			if min(pos[i] + x, i + 1) % p == 0:
				break
		else:
			res.append(x)
	print(len(res))
	print(' '.join(map(str, res)))
main()