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$.

Source: codeforces | Difficulty: HARD
Tags: Sorting

Combinatorics

Complete search

Number theory

Mathematics


Solutions:
import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 9
mod = 998244353
(n, p) = mdata()
A = mdata()
A.sort()
m = 0
l = []
for i in range(n):
	m = max(m, A[i] - i)
for i in range(m, 2001):
	flag = 1
	for j in range(p - 1, n):
		if j - (A[j] - i) + 1 >= p:
			flag = 0
			break
	if flag == 1:
		l.append(i)
	else:
		break
out(len(l))
outl(l)


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)))


import sys
input = sys.stdin.readline
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = []
import bisect
for i in range(min(a), max(a) + 1):
	cnt = 1
	for j in range(i, i + n):
		k = i + n - j
		m = bisect.bisect_right(a, j)
		cnt *= k - n + m
		cnt %= p
	if cnt % p != 0:
		ans.append(i)
print(len(ans))
print(*ans)


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 main():
	(n, p) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	factp = [1] * p
	for i in range(2, p):
		factp[i] = factp[i - 1] * i % p
	mxm = max(a)
	ht = [0] * (mxm + 1)
	for elem in a:
		ht[elem] = ht[elem] + 1
	for i in range(1, mxm + 1):
		ht[i] += ht[i - 1]
	x = [False] * mxm
	start = max(mxm - n + 1, 1)
	for cand in range(start, mxm):
		ans = ht[cand]
		delta = 1
		for delta in range(1, n - 1):
			ans = ans * (ht[min(cand + delta, mxm)] - delta) % p
			delta = delta + 1
		if ans != 0:
			x[cand] = True
	stdout.write(str(x.count(True)))
	stdout.write('\n')
	res = []
	for i in range(start, mxm):
		if x[i]:
			res.append(str(i))
	stdout.write(' '.join(res))
	stdout.write('\n')
	return
main()


import bisect
import sys
input = sys.stdin.readline
(n, p) = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
mins = arr[0]
maxs = arr[-1]
ans = []
for x in range(mins, maxs):
	pattern = [0] * n
	for i in range(n - 1, -1, -1):
		if arr[i] <= x:
			pattern[i] = n
		elif arr[i] > x + i:
			pattern[i] = 0
		else:
			pattern[i] = n - (arr[i] - x)
	pattern = pattern[::-1]
	for i in range(n):
		if pattern[i] == 0 or (pattern[i] - i) % p == 0 or pattern[i] - i <= 0:
			break
	else:
		ans.append(x)
print(len(ans))
print(*ans)


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 asterism(p, a):
	(n, m, M) = (len(a), 1, max(a) - 1)
	for i in range(n):
		m = max(m, a[i] - i)
	for i in range(n - p + 1):
		M = min(M, a[p + i - 1] - i - 1)
	print(max(0, M - m + 1))
	for i in range(m, M + 1):
		print(i, end=' ')
asterism(int(input().split()[1]), sorted([int(i) for i in input().split()]))


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()


from bisect import *
(n, p) = map(int, input().split())
z = list(map(int, input().split()))
z.sort()
x = min(z)
t = max(z)
ans = []
while x < t:
	temp = [0 for i in range(len(z))]
	i = 0
	sc = x
	flag = 0
	while i < len(temp):
		m = bisect_right(z, sc)
		temp[i] = m - i
		i += 1
		sc += 1
	flag = 0
	for i in range(len(temp)):
		if temp[i] <= 0:
			flag = 1
			break
	if flag == 1:
		x += 1
		continue
	else:
		for i in range(len(temp)):
			if temp[i] % p == 0:
				flag = 1
				break
		if flag == 1:
			x += 1
			continue
		else:
			ans.append(x)
			x += 1
			continue
print(len(ans))
print(*ans)


(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)


from sys import stdin
input = stdin.readline
(n, p) = list(map(int, input().split()))
c = list(map(int, input().split()))
dobre = []
for x in range(1, 2001):
	dobry = True
	miejsca = []
	for i in range(n):
		eps = max(c[i] - x, 0)
		cyk = max(n - eps, 0)
		miejsca.append(cyk)
	if min(miejsca) == 0:
		continue
	conajmniej = [0] * (n + 1)
	zajete = [0] * (n + 1)
	for i in miejsca:
		zajete[n - i] += 1
	sumapref = 0
	for i in range(n + 1):
		j = n - i
		sumapref += zajete[i]
		conajmniej[j] = sumapref
	for i in range(n):
		j = n - i
		if conajmniej[j] - i >= p or conajmniej[j] - i <= 0:
			dobry = False
			break
	if dobry:
		dobre.append(x)
print(len(dobre))
print(*dobre)


(n, p) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
a.sort()
result = []
for x in range(a[-1]):
	fail = 0
	for i in range(len(a) - 1, -1, -1):
		if x + i < a[i]:
			fail = 1
			break
		elif p <= min(i + 1, i - (a[i] - x - 1)):
			fail = 1
			break
	if fail == 0:
		result.append(str(x))
print(len(result))
if result:
	print(' '.join(result))


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
from math import factorial

def permute(n, k):
	return factorial(n) // factorial(n - k)

def ifact(n):
	if n >= p:
		return 0
	return pow(fact[n], p - 2, p)

def brute(x):
	from itertools import permutations
	r = 0
	for perm in permutations(range(n)):
		cx = x
		for i in perm:
			if cx < A[i]:
				break
			cx += 1
		else:
			r += 1
	return r % p
good = []
for x in range(1, 2001):
	sx = 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
	if r != 0:
		good.append(sx)
print(len(good))
print(*good)


import sys
input = lambda : sys.stdin.readline().rstrip()
(n, p) = map(int, input().split())
A = sorted([int(i) for i in input().split()])
st = A[0]
gl = 2001
Ans = []
for i in range(st, gl):
	for (j, a) in enumerate(A):
		if i + j < a or min(j + 1, i + j - a + 1) >= p:
			break
	else:
		Ans.append(i)
print(len(Ans))
print(*Ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, p) = map(int, input().split())
	a = sorted(map(int, input().split()))
	(ans, ma) = ([], max(a))
	for i in range(1, ma + 1):
		(k, z, zz, pp) = (0, i, 0, 1)
		while zz < n:
			while k < n and z >= a[k]:
				k += 1
			pp = pp * max(0, k - zz) % p
			zz += 1
			z += 1
		if pp:
			ans.append(i)
	print(len(ans))
	print(*ans)
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')
main()


from bisect import bisect_left, bisect_right

class Result:

	def __init__(self, index, value):
		self.index = index
		self.value = value

class BinarySearch:

	def __init__(self):
		pass

	@staticmethod
	def greater_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_right(func, num)
			if index == len(func):
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(omega) <= num:
				return Result(None, None)
			while alpha < omega:
				if func(alpha) > num:
					return Result(alpha, func(alpha))
				if omega == alpha + 1:
					return Result(omega, func(omega))
				mid = (alpha + omega) // 2
				if func(mid) > num:
					omega = mid
				else:
					alpha = mid

	@staticmethod
	def less_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_left(func, num) - 1
			if index == -1:
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(alpha) >= num:
				return Result(None, None)
			while alpha < omega:
				if func(omega) < num:
					return Result(omega, func(omega))
				if omega == alpha + 1:
					return Result(alpha, func(alpha))
				mid = (alpha + omega) // 2
				if func(mid) < num:
					alpha = mid
				else:
					omega = mid
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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
bs = BinarySearch()
for _ in range(int(input()) if not True else 1):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	sa = sorted(a)
	di = {}
	for i in range(n):
		if a[i] in di:
			di[a[i]] += [i]
		else:
			di[a[i]] = [i]
	ans = []
	for i in range(1, sa[-1] + 1):
		pos = True
		c = []
		for j in range(n):
			val = bs.less_than(i + j + 1, sa)
			if val.value is None:
				pos = False
				break
			(val, ind) = (val.value, val.index)
			c += [ind + 1]
		if not pos:
			continue
		for j in range(n):
			if (c[j] - j) % x == 0 or c[j] - j < 0:
				pos = False
				break
		if not pos:
			continue
		ans += [i]
	print(len(ans))
	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 bisect
import sys
input = sys.stdin.readline
(n, p) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr1 = sorted(arr1)
mins = 0
for i in range(n):
	mins = max(mins, arr1[i] - i)
maxs = arr1[p - 1]
arr2 = [0] * n
for i in range(n):
	arr2[i] = (p - (n - arr1[n - i - 1] - i)) % p
arr2 = arr2[::-1]
can = set(range(p))
pos = bisect.bisect_right(arr1, maxs - 1)
for i in range(pos, n):
	can.discard(arr2[i])
ans = []
prev = pos
for x in range(maxs - 1, mins - 1, -1):
	pos = bisect.bisect_right(arr1, x)
	if pos == prev:
		if x % p in can:
			ans.append(x)
	else:
		for i in range(pos, prev):
			can.discard(arr2[i])
		if x % p in can:
			ans.append(x)
	prev = pos
ans = ans[::-1]
print(len(ans))
print(*ans)


import sys
INF = 10 ** 18
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()
YesNo = lambda b: bool([print('Yes')] if b else print('No'))
YESNO = lambda b: bool([print('YES')] if b else print('NO'))
int1 = lambda x: int(x) - 1

class BIT:

	def __init__(self, n):
		self.num = n
		self.dat = [0] * (self.num + 1)

	def add(self, i, x):
		i += 1
		while i <= self.num:
			self.dat[i] += x
			i += i & -i

	def sum(self, i):
		i += 1
		s = 0
		while i > 0:
			s += self.dat[i]
			i -= i & -i
		return s
(N, P) = map(int, input().split())
a = tuple(map(int, input().split()))
b = BIT(2001)
for x in a:
	b.add(x, 1)
ans = 0
l = []
for x in range(2001):
	for i in range(N):
		if (b.sum(min(x + i, 2000)) - i) % P == 0:
			break
	else:
		ans += 1
		l.append(x)
print(ans)
print(*l)


import bisect
(n, p) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
res = []
for x in range(a[0], a[-1] + 1):
	cand = x
	flag = False
	for i in range(n):
		if a[i] <= cand:
			cand += 1
		else:
			flag = True
			break
	if flag:
		continue
	for i in range(n):
		if (bisect.bisect_left(a, x + i + 1) - i) % p == 0:
			flag = True
			break
	if not flag:
		res.append(str(x))
print(len(res))
print(' '.join(res))


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 os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main():
	(n, p) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst.sort()

	def cntLessOrEqual(val):
		(l, r, ans) = (0, n - 1, 0)
		while l <= r:
			mid = r + l >> 1
			if lst[mid] <= val:
				ans = mid + 1
				l = mid + 1
			else:
				r = mid - 1
		return ans

	def findLast(l):
		(r, ans) = (lst[n - 1], -1)
		while l <= r:
			mid = r + l >> 1
			flag = True
			for i in range(n):
				cnt = cntLessOrEqual(mid + i) - i
				if cnt >= p:
					flag = False
					break
			if flag:
				ans = mid
				l = mid + 1
			else:
				r = mid - 1
		return ans

	def findStart():
		(maxi, mini, ans) = (lst[n - 1], max(lst[n - 1] - n + 1, lst[0]), -1)
		while mini <= maxi:
			mid = mini + maxi >> 1
			ok = True
			for i in range(n):
				if mid + i < lst[i]:
					ok = False
					break
			if ok:
				maxi = mid - 1
				ans = mid
			else:
				mini = mid + 1
		return ans
	start = findStart()
	finish = findLast(start)
	print(max(0, finish - start + 1))
	for i in range(start, finish + 1):
		print(i, end=' ')
	print()
main()


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)


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(2000, 0, -1):
	a += [i]
xarr = [0] * 2001
for i in range(n):
	xarr[a[i]] += 1
for i in range(1, 2001):
	xarr[i] += xarr[i - 1]
count = 0
good = []
for x in range(1, max(a) + 1):
	counts = 0
	for i in range(x, x + n):
		if (xarr[min(i, 2000)] - counts) % p == 0:
			break
		counts += 1
	else:
		count += 1
		good += [x]
print(count)
for i in range(len(good)):
	print(good[i], end=' ')


import sys
input = sys.stdin.readline
MAX = 2001
(N, P) = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = []
for x in range(1, MAX + 1):
	tmp = 1
	for (i, a) in enumerate(A):
		cantake = max(min(x + N - a, N) - i, 0)
		tmp = tmp * cantake % P
	if tmp != 0:
		ans.append(x)
print(len(ans))
print(*ans)


from sys import stdin

def bSearch(val, a):
	low = 0
	high = len(a) - 1
	while low <= high:
		mid = (low + high) // 2
		if a[mid] > val:
			high = mid - 1
		else:
			low = mid + 1
	return high + 1
(n, p) = [int(x) for x in stdin.readline().split()]
a = sorted([int(x) for x in stdin.readline().split()])
good = 0
gArr = []
for x in range(1, max(a)):
	nice = True
	for y in range(n):
		cool = bSearch(x + y, a)
		if (cool - y) % p == 0:
			nice = False
			break
	if nice:
		good += 1
		gArr.append(x)
print(good)
print(' '.join([str(x) for x in gArr]))


def help():
	(n, p) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	arr.sort()
	final = []
	for x in range(1, max(arr)):
		value = 0
		elements = []
		curr = 0
		j = 0
		while j < n:
			if arr[j] <= x + value:
				curr += 1
				j += 1
			else:
				elements.append(curr)
				curr = 0
				value += 1
		elements.append(curr)
		if elements[0] == 0:
			continue
		start = 0
		flag = True
		for i in range(len(elements)):
			if start < 0:
				break
			start = start + elements[i]
			if start % p == 0:
				flag = False
				break
			start -= 1
		if flag and start < p:
			final.append(x)
	print(len(final))
	print(*final)
for _ in range(1):
	help()


import bisect
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = []
for x in range(0, 2001):
	temp = [i + x for i in range(n)]
	for j in range(n - 1, -1, -1):
		id = bisect.bisect_left(temp, a[j])
		num = 1 + j - id
		if num % p == 0 or num <= 0:
			break
	else:
		ans.append(x)
ans.sort()
print(len(ans))
print(*ans)


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
ansls = []
mx = max(a)
for i in range(1, mx + 1):
	anstmp = 1
	for j in range(n)[::-1]:
		if a[j] - j > i:
			anstmp = 0
		else:
			anstmp *= n - max(i, a[j]) + i - (n - j - 1)
			anstmp %= p
	if anstmp:
		ans += 1
		ansls.append(i)
print(ans)
print(*ansls)


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)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [(ch, len(list(g))) for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None
t = 1
for i in range(t):
	(n, p) = RL()
	a = RLL()
	a.sort()
	mi = max((a[i] - i for i in range(n)))
	ma = a[-1]
	c = [0] * (ma + 1)
	for x in range(mi, ma + 1):
		for i in range(n):
			if a[i] <= x:
				c[x] += 1
	ans = []
	for x in range(mi, ma + 1):
		f = 1
		for i in range(n):
			if (c[min(ma, x + i)] - i) % p == 0:
				f = 0
				break
		if f:
			ans.append(x)
	print(len(ans))
	print(*ans)


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()


import collections
import bisect
(n, p) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
memo = collections.deque()
(minx, maxx) = (0, 9999999999999)
for i in reversed(a):
	minx = max(minx - 1, i)
	if len(memo) == p - 1:
		maxx = min(maxx - 1, memo[0] - 1)
		memo.popleft()
	memo.append(i)
if minx > maxx:
	print(0)
else:
	print(maxx - minx + 1)
	for i in range(minx, maxx + 1):
		print(i, end=' ')


from bisect import bisect_right
MAXA = 2005
(n, p) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
validos = []
for i in range(1, MAXA):
	(se_hace_neg, mult) = (True, True)
	for j in range(n):
		cant_menores = bisect_right(a, i + j)
		cant_menores -= j
		if cant_menores % p == 0:
			mult = False
		if cant_menores <= 0:
			se_hace_neg = False
	if se_hace_neg and mult:
		validos.append(i)
print(len(validos))
print(*validos)


import sys
input = sys.stdin.readline
precompute = [1]
import bisect

def counter(i):
	pq = i
	ind = 0
	prev = 0
	ret = 1
	while prev < n:
		store = ind
		ind = bisect.bisect(a, i)
		if ind - prev == p:
			return 0
		if i == a[-1]:
			ret *= precompute[n - prev]
			ret %= p
			return ret
		elif store != ind or (store == ind and prev < ind):
			i += 1
			ret *= ind - prev
			ret %= p
			prev += 1
		else:
			return 0
	return ret
(n, p) = map(int, input().split())
for i in range(1, 2001):
	precompute.append(precompute[-1] * i)
	precompute[-1] = precompute[-1] % p
a = [int(i) for i in input().split() if i != '\n']
a.sort()
l = []
for i in range(a[0], a[-1] + 1):
	if bisect.bisect(a, i) < p:
		checker = counter(i)
		if checker != 0:
			l.append(i)
sys.stdout.write(str(len(l)) + '\n')
l = ' '.join(map(str, l))
sys.stdout.write(l)


(n, p) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
m = l[-1]
b = [0] * (2 * n - 1)
ind = 0
for i in range(2 * n - 1):
	while ind < n and l[ind] <= i + m - n + 1:
		ind += 1
	b[i] = ind
chuje = [0] * p
for i in range(m - n + 1, m + 1):
	chuje[(i - b[i - m + n - 1]) % p] += 1
dobre = []
for x in range(m - n + 1, m):
	if not chuje[x % p]:
		dobre.append(x)
	chuje[(x - b[x - m + n - 1]) % p] -= 1
	chuje[(x + n - b[x - m + 2 * n - 1]) % p] += 1
print(len(dobre))
print(*dobre)


def func(length, prime):
	nums = sorted(map(int, input().split()))
	mini = max(nums[0], nums[-1] - length + 1)
	xs = list(range(mini, min(mini + length, nums[-1] + 1)))
	L = len(xs)
	idxs = [0] * length
	for i in range(L - 1, -1, -1):
		if xs[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
	res = []
	for x in xs:
		flag = any((op % prime == 0 for op in idxs))
		idxs = [n + 1 if n != i + 1 else n for (i, n) in enumerate(idxs)]
		if flag:
			continue
		res.append(x)
	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 math
import sys
input = sys.stdin.readline
(n, p) = map(int, input().split())
a = sorted([int(_) for _ in input().split()])
inf = 10 ** 18
bad = dict()
(low, high) = (1, inf)
for i in range(n):
	j = (i + 1) % p
	for k in range(j, i, p):
		if a[i] >= k:
			bad[a[i] - k] = True
	if j == 0:
		high = min(high, a[i])
	low = max(low, a[i] - i)
result = []
for i in range(low, high):
	if bad.get(i, False) == False:
		result.append(i)
print(len(result))
print(' '.join(map(str, result)))


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
m = max((a[i] - i for i in range(n)))
M = a[p - 1] - 1
ban = [0 for i in range(p)]
ans = []
query = [(a[i] - 1 - i, 1, -100) for i in range(n)]
for x in range(m, M + 1):
	query.append((x, 0, -100))
for i in range(n):
	query.append((a[i], -1, i))
query.sort()
for (val, q, id) in query:
	if q == -1:
		r = (val - id - 1) % p
		ban[r] -= 1
	elif q == 0:
		if ban[val % p] == 0:
			ans.append(val)
	else:
		ban[val % p] += 1
ans.sort()
print(len(ans))
print(*ans)


(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 sys
import collections

def input():
	return sys.stdin.readline().rstrip()

def split_input():
	return [int(i) for i in input().split()]
(n, p) = split_input()
a = split_input()
start = max(a) - n + 1
x = [0 for i in range(n)]
for i in a:
	ind = i - start
	if ind <= 0:
		x[0] += 1
	else:
		x[ind] += 1
for i in range(1, n):
	x[i] += x[i - 1]
zero_ind = -1
for i in range(n):
	zero_ind = max(i - x[i], zero_ind)
s = set()
for i in range(zero_ind + 1, n):
	if x[i] >= p:
		s.add((i + start - x[i]) % p)
ans = []
for i in range(zero_ind + 1, p):
	if (i + start) % p not in s:
		ans.append(i + start)
print(len(ans))
print(*ans, sep=' ')


lis = input().split()
(n, p) = (int(lis[0]), int(lis[1]))
lis = input().split()
a = [0] * n
for i in range(n):
	a[i] = int(lis[i])
a.sort()
xminn = a[0]
for i in range(1, n):
	xminn = max(a[i] - i, xminn)
for i in range(n):
	a[i] = min(xminn - a[i] + 1 + i, i + 1)
lenn = n
i = p
while i <= n:
	lenn = min(i - a[i - 1], lenn)
	i += p
if lenn == 0:
	print(0)
else:
	notAllowed = [False] * lenn
	for i in range(n):
		uplim = min(a[i] + lenn - 1, i + 1)
		val = ((a[i] - 1) // p + 1) * p
		if val <= uplim:
			notAllowed[val - a[i]] = True
	good = []
	for i in range(lenn):
		if not notAllowed[i]:
			good.append(xminn + i)
	print(len(good))
	for i in good:
		print(i, end=' ')
	print()


def solution(n, a, p):
	result = []
	r = []
	a.sort()
	for i in range(n):
		r.append(-a[i] + i + 1)
	remainder = []
	for i in range(p):
		remainder.append(0)
	for i in range(p - 1, n):
		n_a_re = (p - r[i]) % p
		remainder[n_a_re] += 1
	min_x = 1 - n + a[n - 1]
	for i in range(2, n + 1):
		if i - n + a[n - i] > min_x:
			min_x = i - n + a[n - i]
	result += get_x(min_x, a[p - 1], remainder, p, n, p - 2)
	return result

def get_x(start, end, remainder, p, n, id):
	v1 = start // p
	r1 = start % p
	v2 = end // p
	r2 = end % p
	arr = []
	s_id = -1
	e_id = -1
	if end > start:
		for i in range(len(remainder)):
			if remainder[i] == 0:
				arr.append(v1 * p + i)
				if i >= r1 and s_id == -1:
					s_id = len(arr) - 1
				if i >= r2 and e_id == -1:
					e_id = len(arr) - 1
		period = len(arr)
		for _ in range((v2 - v1) * period):
			arr.append(arr[-period] + p)
		if s_id == -1:
			s_id = period
		if e_id == -1:
			e_id = period
		remainder[(p + end - id - 2) % p] -= 1
		return arr[s_id:len(arr) - period + e_id]
	else:
		remainder[(p + end - id - 2) % p] -= 1
		return []
num = input()
num = num.split(' ')
n = int(num[0])
p = int(num[1])
a = list(map(int, input().split(' ')))
result = solution(n, a, p)
print(len(result))
print(' '.join(list(map(str, result))))


import sys
input = sys.stdin.readline
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mn = 0
mx = 2000
for i in range(n):
	d = a[i] - i
	mn = max(d, mn)
	if i >= p - 1:
		d2 = a[i] - i + p - 1
		mx = min(mx, d2)
print(max(mx - mn, 0))
for i in range(mn, mx):
	print(i, end=' ')


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 os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
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')
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mn = 0
mx = 2000
for i in range(n):
	d = a[i] - i
	mn = max(d, mn)
	if i >= p - 1:
		d2 = a[i] - i + p - 1
		mx = min(mx, d2)
print(max(mx - mn, 0))
for i in range(mn, mx):
	print(i, end=' ')


def s(enemy_list, prime, n_enemies):
	good = []
	enemy_list = sorted(enemy_list)
	i = 0
	k = 0
	k_list = []
	while i < n_enemies:
		if k >= enemy_list[i]:
			i += 1
		else:
			k += 1
			k_list.append(i)
	k_list += [n_enemies] * n_enemies
	minimum = max(min(enemy_list), max(enemy_list) - n_enemies)
	for q in range(minimum - 1, len(k_list) - n_enemies):
		zk_list = [(k_list[q + i] - i) % prime for i in range(n_enemies)]
		if 0 not in zk_list:
			good.append(q)
	return good
(n, p) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
to_print = s(a, p, n)
print(len(to_print))
print(' '.join([str(i) for i in to_print]))


import sys
input = sys.stdin.readline
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = []
for x in range(min(a), max(a) + 1):
	stack = 0
	j = -1
	turn = 0
	pre_j = -1
	flag = True
	flag2 = True
	while j < n:
		while j + 1 < n and x + turn >= a[j + 1]:
			j += 1
		stack += j - pre_j
		if stack <= 0:
			flag = False
			break
		if stack >= p:
			flag2 = False
		stack -= 1
		turn += 1
		if turn == n:
			break
		pre_j = j
	if flag and flag2:
		ans.append(x)
print(len(ans))
print(*ans)


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
(n, p) = input_split()
arr = input_split()
maxi = max(arr)
count = 0
is_div = [1 for i in range(maxi + 1)]
freqs = [0 for i in range(4002)]
for a in arr:
	freqs[a] += 1
for i in range(1, 4002):
	freqs[i] += freqs[i - 1]
touched = [False for i in range(4002)]
for i in range(4002):
	shift = freqs[i] % p
	while shift < n:
		potential = i - shift
		shift += p
		if potential >= 0 and potential <= maxi:
			is_div[potential] = 0
		if potential < 0:
			break
		if touched[potential]:
			break
		else:
			touched[potential] = True
ans = sum(is_div[:maxi + 1])
print(ans)
xs = [x for x in range(maxi + 1) if is_div[x] == 1]
print(*xs, sep=' ')


from collections import deque

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)))
ma = max(a)
res = []
ll = deque()
x = mi
now = x
i = 0
for step in range(n):
	while i < n and now >= a[i]:
		i += 1
	now += 1
	ll.append(i)
for x in range(mi, ma + 1):
	if ll[0] == n:
		break
	flag = True
	for i in range(n):
		if (ll[i] - i) % p == 0:
			flag = False
			break
	if flag:
		res.append(x)
	ll.popleft()
	ll.append(n)
print(len(res))
print_list(res)


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)


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cur_pass = 0
for i in range(n):
	cur_pass = max(a[i] - i, cur_pass)
min_pass = cur_pass
ans = []
done = True
l = cur_pass
r = a[-1]
while l <= r:
	mid = (l + r) // 2
	cur_pass = mid
	i = 0
	while i < n and a[i] <= cur_pass:
		i += 1
	candies = cur_pass
	options = i
	while options:
		if options >= p:
			r = mid - 1
			break
		candies += 1
		options -= 1
		while i < n and a[i] <= candies:
			i += 1
			options += 1
	if r == mid - 1:
		pass
	else:
		l = mid + 1
for i in range(min_pass, r + 1):
	ans += [str(i)]
print(len(ans))
print(' '.join(ans))


(N, P) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = []
for x in range(A[0], A[-1] + 1):
	i = 0
	n = 0
	b = x
	for _ in range(N):
		while i < N and A[i] <= b:
			i += 1
			n += 1
		if n % P == 0:
			break
		n -= 1
		b += 1
	else:
		ans.append(x)
print(len(ans))
print(*ans)


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
arr = []
for x in range(a[0], a[-1]):
	pretendents = [[]]
	bias = 0
	for i in range(n):
		if a[i] <= x + bias:
			pretendents[-1].append(a[i])
		else:
			change = a[i] - (x + bias)
			for __ in range(change):
				pretendents.append([])
			pretendents[-1].append(a[i])
			bias += change
	res = 1
	num = 0
	for j in pretendents:
		num += len(j)
		res *= num
		num -= 1
		res %= p
	for j in range(n - len(pretendents)):
		res *= num
		res %= p
		num -= 1
	if res % p != 0:
		arr.append(x)
print(len(arr))
print(' '.join(map(str, arr)))


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(n):
	a[i] -= i
l = max(a)
for i in range(n):
	a[i] += p - 1
r = min(a[p - 1:])
print(max(r - l, 0))
print(*list(range(l, r)))


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

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

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in range(base ** n):
		s = [tb // base ** bt % base for bt in range(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.node_size = len(ls) + 1
				(self.edges, _) = GI(self.node_size, self.node_size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.node_size = int(input())
		else:
			self.node_size = inp_size
		(self.edges, _) = GI(self.node_size, self.node_size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.node_size = len(ls) + 1
		(self.edges, _) = GI(self.node_size, self.node_size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.node_size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.node_size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.node_size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.node_size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.node_size
		self.ETout = [-1] * self.node_size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def doubling_LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.depth = [None] * self.node_size
			self.depth = self.bfs(0, func=lambda pr, prv, nxt, dist: prv + 1)
			self.par = self.bfs(0, func=lambda pr, prv, nxt, dist: pr)
			self.db = [self.par]
			for i in range(self.node_size.bit_length()):
				self.db += [[self.db[-1][self.db[-1][i]] for i in range(self.node_size)]]
			self.LCA_init_stat = True
		dx = self.depth[x]
		dy = self.depth[y]
		if dx > dy:
			(dx, dy) = (dy, dx)
		c = self.node_size.bit_length()
		while c > 0:
			if dx + c <= dy:
				x = self.db[c][x]
				dx += 1 << c
			c >>= 1
		if x == y:
			return x
		c = self.node_size.bit_length()
		while c > 0:
			if self.db[c][x] != self.db[c][y]:
				x = self.db[c][x]
				y = self.db[c][y]
			c >>= 1
		return self.par[x]

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in e]) for e in self.edges]):
			print([[nd for (nd, d) in e] for e in self.edges])
		else:
			print(self)

	def dfs2(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.node_size
		v[x] = root_v
		dfs_tr = [x]
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
					dfs_tr += (nb,)
		return (v, dfs_tr)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = []
(n, p) = LI()
a = sorted(LI())
m = max(a)
c = [0] * (m + 1 + n)
for i in a:
	c[i] += 1
for i in range(len(c) - 1):
	c[i + 1] += c[i]
for x in range(1, m + 1):
	fl = True
	for j in range(n):
		pat = c[x + j] - j
		if pat == 0:
			fl = False
			break
		if pat % p == 0:
			fl = False
	if fl:
		ans.append(x)
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)))


(n, p) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
ans = []
for i in range(1, 3001):
	f = 1
	num = i
	for j in range(n):
		(lo, hi) = (0, n - 1)
		h = 0
		while lo <= hi:
			m = (lo + hi) // 2
			if num >= arr[m]:
				h = m - j + 1
				lo = m + 1
			else:
				hi = m - 1
		if h % p == 0:
			f = 0
		if arr[j] <= num:
			num += 1
		else:
			f = 0
	if f == 0:
		continue
	ans.append(i)
print(len(ans))
print(*ans)


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)


from sys import stdin
import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main():
	(n, p) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst.sort()

	def binSearch(val, ara):
		(l, r) = (0, n - 1)
		while l <= r:
			mid = l + r >> 1
			if ara[mid] <= val:
				l = mid + 1
			else:
				r = mid - 1
		return l
	ans = []
	for i in range(1, lst[n - 1]):
		(cnt, add) = (1, 0)
		for j in range(n):
			candidate = binSearch(add + i, lst) - j
			if candidate <= 0:
				break
			add += 1
			cnt = cnt * candidate % p
		else:
			if cnt:
				ans.append(i)
	print(len(ans))
	for x in ans:
		print(x, end=' ')
	print()
main()


(n, p) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a = sorted(a)
ans = []
for start in range(1, 2001):
	mul = 1
	l = 0
	for i in range(n):
		got = start + i
		while l < n and a[l] <= got:
			l += 1
		mul = mul * (l - i) % p
	if mul % p != 0:
		ans.append(start)
print(len(ans))
print(*ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys
M = mod = 10 ** 9 + 7

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

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
(n, p) = li()
l = sorted(li())
N = 10 ** 4 + 10
facts = [1]
for i in range(1, N):
	facts.append(facts[-1] * i % mod)
inversemods = [0 for i in range(N)]
inversemods[-1] = inv_mod(facts[-1]) % mod
for i in range(N - 2, -1, -1):
	inversemods[i] = inversemods[i + 1] * (i + 1) % mod

def ncr(n, r):
	if n < r:
		return 0
	return facts[n] * inversemods[n - r] * inversemods[r] % mod

def dp(element):
	ans = 0
	tot = 1
	for i in range(n):
		ind = br(l, element + i)
		tot = tot * ncr(ind - i, 1) % p
	return tot
l1 = []
for i in range(l[-1] + 1):
	if dp(i):
		l1.append(i)
print(len(l1))
print(*l1)


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)


from bisect import bisect_right as br
import sys
input = sys.stdin.readline
t = 1
for _ in range(t):
	(n, p) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	l = [0] * (n + 1)
	for i in range(p, n + 1, p):
		l[i] = 1
	ans = []
	for j in range(1, 2001):
		orig = j
		last = -1
		flag = 0
		for i in range(n):
			ind = br(arr, orig) - 1
			if (ind - last) % p == 0 or ind <= last:
				flag = 1
				break
			orig += 1
			last += 1
		if flag != 1:
			ans += [j]
	print(len(ans))
	print(*ans)


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = []
from bisect import bisect_right
for i in range(min(a), max(a)):
	for j in range(n):
		b = bisect_right(a, i + j) - j
		if b <= 0:
			break
		elif b % p == 0:
			break
	else:
		ans.append(i)
print(len(ans))
print(' '.join(map(str, ans)))


def solve(n, p, x, a):
	res_ptn = 1
	r = 0
	for l in range(n):
		while r < n and a[r] <= x + l:
			r += 1
		res_ptn *= r - l
		res_ptn %= p
	return res_ptn != 0
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
ans = []
for x in range(1, 2000 + 2):
	if solve(n, p, x, a):
		ans.append(x)
print(len(ans))
print(*ans)


import bisect as bs
(n, k) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
x = []
for i in range(1, 2000):
	for j in range(n):
		choices = bs.bisect_right(arr, i + j) - j
		if choices % k == 0:
			break
	else:
		x.append(i)
print(len(x))
for i in x:
	print(i, end=' ')


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def gi():
	return [x for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')
t = 1

def cnt(a, l):
	cc = 0
	dif = [0 for i in range(n + 1)]
	for i in range(n):
		start = max(0, a[i] - l)
		if a[i] - l >= n:
			return 0
		dif[start] += 1
		dif[n] -= 1
	for i in range(1, n + 1):
		dif[i] += dif[i - 1]
	ans = 1
	c = 0
	for i in range(n):
		if dif[i] - c < 0:
			return 0
		ans = ans * (dif[i] - c) % p % p
		ans %= p
		c += 1
	return ans
while t > 0:
	t -= 1
	(n, p) = mi()
	a = li()
	a.sort()
	d = []
	dd = []
	for i in range(min(a), max(a)):
		c = cnt(a, i)
		if c % p:
			d.append(i)
	print(len(d))
	print(*d)


import sys
import math
from decimal import *

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

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

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))

def ncr(n, r, p):
	if p >= r and p <= n:
		return 0
	return 1

def cal(l, n, p):
	placed = 0
	places = 0
	l = l[::-1]
	ans = 1
	for x in l:
		places += 1
		if x > 0:
			ans *= ncr(places, x - placed, p)
			if ans == 0:
				return 0
			placed += x
			places -= x
	return ans

def check(a, x, p):
	l = [0] * len(a)
	for aa in a:
		idx = max(0, aa - x)
		if idx >= len(a):
			return 0
		l[idx] += 1
	sx = 0
	for i in range(len(l)):
		sx += l[i]
		if sx < i + 1:
			return 0
	return cal(l, len(a), p)

def solve():
	(n, p) = IL()
	a = IL()
	a.sort()
	ans = 0
	maxx = max(a)
	ansl = []
	for x in range(1, maxx):
		res = check(a, x, p)
		if res == 1:
			ans += 1
			ansl.append(x)
	print(ans)
	for al in ansl:
		print(al, end=' ')
	print('')
solve()


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n
avl = AvlTree()

class SegmentTree1:

	def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, p) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
tot = []
ind = defaultdict(int)
for i in range(len(l)):
	ind[l[i]] = i + 1
for i in range(1, 5001):
	if ind[i] == 0:
		ind[i] = ind[i - 1]
for i in range(1, max(l) + 1):
	ans = 1
	y = 0
	for j in range(n):
		ans = ind[j + i] - j
		if ans < 0:
			y = 1
			break
		if ans % p == 0:
			y = 1
			break
	if y == 0:
		tot.append(i)
print(len(tot))
print(*tot, sep=' ')


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 bisect

def f(x):
	for i in range(n):
		z = bisect.bisect_right(li, x + i)
		if (z - i) % p == 0:
			return 0
	return 1
l = input().split()
n = int(l[0])
p = int(l[1])
l = input().split()
li = [int(i) for i in l]
l = []
li.sort()
for i in range(2001):
	if f(i):
		l.append(i)
print(len(l))
for i in l:
	print(i, end=' ')


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 main():
	(n, p) = [int(i) for i in input().split()]
	a = [int(elem) for (i, elem) in enumerate(input().split())]
	a = sorted(a)
	ans = []
	mx = a[n - 1]
	base = a[0]
	for i in range(base, mx):
		flag = True
		for j in range(n):
			if i + j < a[j]:
				flag = False
				break
			if j + p - 1 < n and i + j - a[j + p - 1] >= 0 or (i >= a[j] and j >= p - 1):
				flag = False
				break
		if flag:
			ans.append(i)
	print(len(ans))
	print(' '.join((str(i) for i in ans)))
main()


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys
from bisect import bisect_right

def solve(n, p, A):
	Ans = []
	m = max(A)
	Cnt = [0] * (n + m)
	for i in range(n + m):
		Cnt[i] = bisect_right(A, i)
	for x in range(m):
		cnt = 1
		for i in range(n):
			idx = Cnt[x + i]
			cnt *= max(0, idx - i)
			cnt %= p
		if cnt != 0:
			Ans.append(x)
	return (len(Ans), Ans)

def main():
	(n, p) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	(cnt, Ans) = solve(n, p, A)
	sys.stdout.write(str(cnt) + '\n')
	sys.stdout.write(' '.join(map(str, Ans)) + '\n')
main()


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()


import bisect as b
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ct = 0
ans = []
for i in range(1, 2001):
	fg = 0
	for j in range(0, n):
		h = b.bisect(a, i + j, 0, n) - j
		if h % p == 0:
			fg = 1
			break
	if fg == 0:
		ans.append(i)
print(len(ans))
for i in range(0, len(ans)):
	print(ans[i], end=' ')


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()


(n, p) = map(int, input().split())
a = list(map(int, input().split()))

def calc(x):
	global n, p, a
	o = [0] * (n + 1)
	for i in a:
		o[max(0, min(n, i - x))] += 1
	s = 0
	ans = 1
	for i in range(n):
		s += o[i]
		if s <= 0:
			return 0
		ans = ans * s % p
		s -= 1
	return ans
ans = []
for x in range(4020):
	if calc(x):
		ans.append(x)
print(len(ans))
print(*ans)


from collections import defaultdict as dd
from math import factorial
from bisect import bisect
(n, p) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
ans = []
d = dd(int)
for i in l:
	d[i] = 1
for i in range(l[0], 2001):
	a = bisect(l, i)
	if a < p:
		c = 0
		for j in range(n):
			b = bisect(l, i + j)
			if i + c < l[j] or b - j >= p:
				c = -1
				break
			c += 1
		if c >= 0:
			ans.append(i)
	else:
		break
print(len(ans))
print(*ans)


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)])


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
i = min(a)
j = max(a)
ans = 0
b = []
while i < j:
	k = 0
	f = 1
	while k < n:
		if a[k] <= i:
			s = n
		else:
			s = n + i - a[k]
		s -= k
		if s <= 0:
			f = 0
			break
		if s % p == 0:
			f = 0
			break
		k += 1
	if f:
		ans += 1
		b += (i,)
	i += 1
print(ans)
print(*b)


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()


import sys
import bisect
input = sys.stdin.readline

def main():
	(N, P) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	A.sort()
	ma = max(A)
	ans = []
	for i in range(1, ma + 1):
		tmp = 1
		for j in range(N):
			tmp *= bisect.bisect_right(A, i + j) - j
			tmp %= P
			if tmp == 0:
				break
		if tmp % P != 0:
			ans.append(i)
		if tmp != 0 and tmp % P == 0:
			break
	print(len(ans))
	print(*ans)
main()


import sys

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

def solve():
	(n, p) = LI()
	a = LI()
	a.sort()
	ans = []
	for x in range(a[0], a[-1] + 1):
		fx = 1
		y = x
		j = 0
		for i in range(n):
			while j < n and a[j] <= y:
				j += 1
			fx *= j - i
			fx %= p
			if fx == 0:
				break
			y += 1
		else:
			ans.append(x)
	print(len(ans))
	print(*ans)
	return
solve()


(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)


(n, p) = list(map(int, input().split()))
a = list(map(int, input().split()))
num = [0] * 5001
for i in a:
	num[i] += 1
for i in range(5000):
	num[i + 1] += num[i]
ans = []
for x in range(1, 2001):
	temp = 1
	candy = x
	for i in range(x, x + n):
		temp *= num[candy] - (i - x)
		temp %= p
		candy += 1
	if temp % p != 0:
		ans.append(x)
print(len(ans))
print(*ans)


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()
	ans = []
	for x in range(a[0], a[-1] + 1):
		r = 1
		i = 0
		y = x
		while i < n:
			j = bisect_right(a, y)
			if i == j:
				r = 0
				break
			r = r * (j - i) % p
			if r == 0:
				break
			y += 1
			i += 1
		if r != 0:
			ans.append(x)
	print(len(ans))
	for i in ans:
		print(i, end=' ')
	print()


def places(num, v):
	if num >= v + n:
		return 0
	if num < v:
		return n
	return n - (num - v)

def check(num):
	for i in range(n - 1, -1, -1):
		count = max(0, places(b[i], num) - (n - 1 - i))
		if count % p == 0:
			return True
	return False
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
minn = b[0]
maxx = b[-1]
ans = []
for i in range(minn, maxx):
	if not check(i):
		ans.append(i)
print(len(ans))
print(*ans)


import sys
input = sys.stdin.readline
from collections import *
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = []
for x in range(min(a), max(a)):
	now = x
	r = 0
	c = 0
	flag = True
	for _ in range(n):
		while r < n and now >= a[r]:
			r += 1
			c += 1
		if c == 0 or c % p == 0:
			flag = False
		c -= 1
		now += 1
	if flag:
		ans.append(x)
print(len(ans))
print(*ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def f():
	(n, p) = [int(s) for s in input().split()]
	A = [int(s) for s in input().split()]
	A.sort()
	B = [A[i] - i for i in range(n)]
	baseX = B[0]
	for b in B:
		baseX = max(baseX, b)
	limitX = A[-1]
	ans = []

	def isOK(x):
		for i in range(n):
			if not (i + 1 - max(0, A[i] - x)) % p:
				return False
		return True
	for x in range(baseX, limitX):
		if isOK(x):
			ans.append(x)
	print(len(ans))
	print(' '.join((str(num) for num in ans)))
f()


from sys import stdin, gettrace
from collections import Counter
from functools import reduce
from itertools import accumulate
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 = max([a - i for (i, a) in enumerate(aa)])
	bi = minx
	bb = []
	for (i, a) in enumerate(aa):
		if a > bi:
			bb += [i] * (a - bi)
			bi = a
	bb += [n] * (2 * n - len(bb))
	i = 0
	t = max(aa)
	while i < n and t >= minx:
		c = bb[i + t - minx] - i
		if c < p:
			i += 1
		else:
			t -= 1
	print(t - minx + 1)
	print(' '.join(map(str, range(minx, t + 1))))
main()


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)


import io
import os
from bisect import bisect_right
from collections import Counter, deque
from functools import lru_cache
DEBUG = False

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 = []
	window = deque([getNumLessEq(minX - 1 + i) for i in range(N)])
	for x in range(minX, maxX + 1):
		window.popleft()
		window.append(getNumLessEq(x + N - 1))
		if DEBUG:
			windowBrute = [getNumLessEq(x + i) for i in range(N)]
			assert list(window) == windowBrute
		if all((v % P != i % P for (i, v) in enumerate(window))):
			ans.append(x)
	return str(len(ans)) + '\n' + ' '.join(map(str, ans))
if DEBUG:
	N = 2000
	P = 2
	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)


def main():
	import sys
	import bisect
	input = sys.stdin.buffer.readline
	(n, p) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = []
	a.sort()
	for x in range(1, max(a)):
		prev = 0
		tmp = 1
		for i in range(n):
			id = bisect.bisect_right(a, x + i)
			if prev == id:
				tmp = 0
				break
			else:
				tmp *= id - i
				tmp %= p
				if tmp == 0:
					break
		if tmp != 0:
			ans.append(x)
	print(len(ans))
	print(*ans)
main()


import bisect

def f(x):
	for i in range(n):
		z = bisect.bisect_right(li, x + i)
		if (z - i) % p == 0:
			return 0
	return 1

def find_right(left, right):
	mid = (left + right) // 2
	if f(mid):
		if f(mid + 1) == 0 or right == mid:
			return mid
		return find_right(mid + 1, right)
	if left == mid:
		return '0'
	return find_right(left, mid - 1)
l = input().split()
n = int(l[0])
p = int(l[1])
l = input().split()
li = [int(i) for i in l]
l = []
li.sort()
maxa = 0
for i in range(n):
	maxa = max(li[i] - i, maxa)
z = find_right(maxa, li[-1])
if z == '0':
	print(0)
	print()
	exit()
print(z - maxa + 1)
for i in range(maxa, z + 1):
	print(i, end=' ')


(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)


import bisect
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
(n, p) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
(mn, mx) = (min(arr), max(arr))
ans = []
for x in range(mn, mx):
	temp = []
	useful = bisect.bisect_right(arr, x)
	temp.append(useful)
	candy = x + 1
	flag = temp[-1] % p
	while len(temp) < n and flag:
		useful = bisect.bisect_right(arr, candy)
		temp.append(useful - len(temp))
		flag = temp[-1] % p
		candy += 1
	if flag:
		ans.append(str(x))
print(len(ans))
print(' '.join(ans))


import os
import sys
from io import BytesIO, IOBase
import threading
from collections import defaultdict, Counter
from math import factorial as fac

def main():
	for _ in range(1):
		(n, p) = map(int, input().split())
		arr = list(map(int, input().split()))
		a = arr.copy()
		end = max(arr) + 1
		cnt = [0] * end
		for i in arr:
			cnt[i] += 1
		for i in range(1, len(cnt)):
			cnt[i] += cnt[i - 1]
		ans = []
		for x in range(end):
			ways = 1
			taken = 0
			if n - (end - x) < p:
				for j in range(x, end):
					if (cnt[j] - taken) % p == 0:
						ways = 0
						break
					taken += 1
					if taken == n:
						break
				if ways != 0:
					ans.append(x)
		print(len(ans))
		print(*ans)
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')
main()


def fa(a, x, p):
	k = x
	wr = 0
	for i in range(len(a)):
		if a[i] <= k:
			wr += 1
		else:
			nk = wr // p * p
			wr -= a[i] - k
			if wr < nk:
				return False
			k = a[i]
			if wr < 0:
				return False
			wr += 1
	if wr >= p:
		return False
	else:
		return True

def solve():
	(n, p) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst.sort()
	ans = []
	for x in range(max(max(lst) + 1, p + 1)):
		if fa(lst, x, p):
			ans.append(x)
	print(len(ans))
	print(*ans)
for i in range(1):
	solve()


def is_good(a, i):
	for j in range(n):
		choices = min(n, n - a[n - j - 1] + i) - j
		if choices % p == 0 or choices < 0:
			return False
	return True
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
good_integers = []
for i in range(a[-1]):
	if is_good(a, i):
		good_integers.append(i)
print(len(good_integers))
print(' '.join(map(str, good_integers)))


from sys import stdin
from collections import Counter
(n, p) = map(int, stdin.readline().split())
arr = sorted(list(map(int, stdin.readline().split())))
dct = Counter(arr)
x = 0
for i in set(arr):
	dct[i] += x
	x = dct[i]
for i in range(arr[0], arr[-1] + 1):
	if not dct.get(i):
		dct[i] = dct[i - 1]
good = 0
val = []
for i in range(arr[0], arr[-1] + 1):
	sub = 0
	fl = 1
	for j in range(len(arr)):
		if (dct[min(i + j, arr[-1])] - sub) % p == 0 or dct[min(i + j, arr[-1])] <= sub:
			fl = 0
			break
		sub += 1
	good += fl
	if fl:
		val.append(str(i))
print(good)
print(' '.join(val))


def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count
from bisect import bisect_right
(N, P) = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
llist = []
for i in range(A[0], A[N - 1]):
	candies = i
	count = 0
	temp = 0
	for j in range(0, N):
		r = binarySearchCount(A, N, candies)
		if r - count > 0:
			if (r - count) % P == 0:
				temp = 1
			candies += 1
			count += 1
		else:
			temp = 1
			break
	if temp == 0:
		llist.append(i)
print(len(llist))
print(*llist)


from sys import stdin, stdout
import sys
from math import *
(n, p) = map(int, input().split())
ar = list(map(int, input().split()))
ar.sort()
s = ar[-1] - n + 1
ans = []
for i in range(s, max(ar)):
	l = [i + j for j in range(n)]
	m = []
	x = 0
	for j in range(n):
		while x < n and ar[x] <= l[j]:
			x += 1
		m.append(x)
	np = True
	for j in range(n):
		if (m[j] - j) % p == 0:
			np = False
	if np:
		ans.append(i)
print(len(ans))
print(*ans)


(n, p) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
x = arr[-1]
y = arr[-1] - n + 1
array = [0] * n
lis = [[0] * n for i in range(n)]
for i in range(n):
	for j in range(i + 1, n):
		lis[i][j] = arr[j] - arr[i]
for i in range(n):
	s = 0
	for j in range(n):
		if y + i + j < arr[j]:
			s += 1
			break
	if s == 1:
		array[i] = -1
	else:
		t = 0
		for j in range(n):
			if y + i >= arr[j]:
				t += 1
		num = [t]
		k = 0
		for j in range(1, n):
			t -= 1
			while t + j < n and y + i + j >= arr[t + j]:
				t += 1
			num.append(t)
		for j in range(n):
			if num[j] % p == 0:
				array[i] = -1
				break
z = 0
ans = []
for i in range(n):
	if array[i] == -1:
		continue
	else:
		z += 1
		ans.append(y + i)
print(z)
print(' '.join((str(x) for x in ans)))


def places(num, v):
	if num >= v + n:
		return 0
	if num < v:
		return n
	return n - (num - v)

def check(num):
	for i in range(n - 1, -1, -1):
		count = max(0, places(b[i], num) - (n - 1 - i))
		if count == 0:
			return True
		if count % p == 0:
			return False
	return False

def check2(num):
	for i in range(n - 1, -1, -1):
		count = max(0, places(b[i], num) - (n - 1 - i))
		if count % p == 0:
			return True
	return False
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
minn = b[0]
maxx = b[-1]
low = 0
high = maxx - 1
while low < high:
	mid = (low + high) // 2
	if check(mid):
		low = mid + 1
	else:
		high = mid - 1
if check(low):
	start = low + 1
else:
	start = low
low = start
high = maxx - 1
while low < high:
	mid = (low + high) // 2
	if not check2(mid):
		low = mid + 1
	else:
		high = mid - 1
if check2(low):
	end = low - 1
else:
	end = low
ans = []
for i in range(start, end + 1):
	ans.append(i)
print(len(ans))
print(*ans)


def ican(a, x):
	k = x
	wr = 0
	for i in range(len(a)):
		if a[i] <= k:
			wr += 1
		else:
			wr -= a[i] - k
			k = a[i]
			if wr < 0:
				return False
			wr += 1
	return True

def bnpleft(a):
	r = max(a)
	l = -1
	while r - l > 1:
		h = (r + l) // 2
		if ican(a, h):
			r = h
		else:
			l = h
	return l

def fa(a, x, p):
	k = x
	wr = 0
	for i in range(len(a)):
		if a[i] <= k:
			wr += 1
		else:
			nk = wr // p * p
			wr -= a[i] - k
			if wr < nk:
				return False
			k = a[i]
			if wr < 0:
				return False
			wr += 1
	if wr >= p:
		return False
	else:
		return True

def bnpr(a, p, left):
	l = left
	r = max(a)
	while r - l > 1:
		h = (r + l) // 2
		if fa(a, h, p):
			l = h
		else:
			r = h
	return l

def solve():
	(n, p) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst.sort()
	ll = bnpleft(lst)
	rr = bnpr(lst, p, ll)
	print(rr - ll)
	for i in range(ll + 1, rr + 1):
		print(i, end=' ')
for i in range(1):
	solve()


from sys import stdin
from bisect import bisect_left as bl
from bisect import bisect_right as br

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())

class RangedList:

	def __init__(self, start, stop, val=0):
		self.shift = 0 - start
		self.start = start
		self.stop = stop
		self.list = [val] * (stop - start)

	def __setitem__(self, key, value):
		self.list[key + self.shift] = value

	def __getitem__(self, key):
		return self.list[key + self.shift]

	def __repr__(self):
		return str(self.list)

	def __iter__(self):
		return iter(self.list)

def dprint(*args, **kwargs):
	if debugging:
		print(*args, **kwargs)
debugging = 1
(n, p) = intsput()
a = list(intsput())
a.sort()
counts = [0] * 4040
for i in range(len(counts)):
	counts[i] = br(a, i)
ans = []
for x in range(a[-1]):
	mult = 1
	for i in range(n):
		mult *= counts[x + i] - i
		mult %= p
	if mult % p:
		ans.append(x)
print(len(ans))
print(' '.join(map(str, ans)))


(n, p) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
a.sort()
result = []
_min = 0
for i in range(len(a) - 1, -1, -1):
	if _min <= a[i] - i:
		_min = a[i] - i
_max = a[-1]
for i in range(len(a) - 1, p - 2, -1):
	if _max >= p - 2 - i + a[i]:
		_max = p - 2 - i + a[i]
result = max(_max - _min + 1, 0)
print(result)
if result > 0:
	for i in range(_min, _max + 1):
		print(i, end=' ')


(n, p) = map(int, input().split())
s = sorted(map(int, input().split()))
for i in range(n):
	s[i] -= i
mn = max(s)
for i in range(n):
	s[i] += p - 1
mx = min(s[p - 1:])
ans = [*range(mn, mx)]
print(len(ans))
print(*ans)


(n, p) = map(int, input().split())
a = sorted(map(int, input().split()))
b = []
i = 0
while i < len(a):
	j = i
	while j < len(a) and a[j] == a[i]:
		j += 1
	b.append((a[i], j - i))
	i = j
l = a[-1] - n
r = a[-1]
s = [0] * (r - l + n)
cc = n
ci = r - 1 + n
for i in range(len(b) - 1, -1, -1):
	cj = b[i][0]
	while ci >= cj and ci >= l:
		s[ci - l] = ci - cc
		ci -= 1
	cc -= b[i][1]
while ci >= l:
	s[ci - l] = ci - cc
	ci -= 1
c = [0] * p
for i in range(l, l + n):
	c[s[i - l] % p] += 1
ans = []
for x in range(l, r):
	if c[x % p] == 0:
		ans.append(x)
	c[s[x - l] % p] -= 1
	c[s[x + n - l] % p] += 1
print(len(ans))
print(*ans)


a = [int(x) for x in input().split()]
enemies = [int(x) for x in input().split()]
n = a[0]
p = a[1]
initial = max(enemies) - n + 1
i = initial
c_out = ''
counter = 0
ilist = [len([0 for x in enemies if x <= y]) for y in range(initial, max(enemies) + 1)]
while i <= max(enemies):
	if i > initial:
		ilist.append(max(ilist))
		ilist.remove(ilist[0])
	j = 0
	ruined = 0
	while j < len(ilist):
		if (ilist[j] - j) % p == 0:
			ruined = 1
			break
		j += 1
	if not ruined:
		c_out += str(i) + ' '
		counter += 1
	i += 1
print(counter)
print(c_out)


(n, p) = input().split(' ')
N = int(n)
P = int(p)
A = input().split(' ')
A = sorted(list(map(int, A)))
from math import factorial

def factorial(n, MODULUS):
	ret = 1
	for i in range(1, n + 1):
		ret = ret * i % MODULUS
	return ret
good_x = []
MODULUS = P
from functools import lru_cache

@lru_cache(maxsize=None)
def greater_than(candies):
	return len([a for a in A if candies >= a])
for x in range(0, 2001):
	largest_permutation = 0
	chosen = [False] * len(A)
	rank = 1
	candies = x
	while largest_permutation < len(A):
		choices = greater_than(candies)
		if choices <= largest_permutation:
			break
		if choices == 0:
			break
		rank = rank * (choices - largest_permutation) % MODULUS
		largest_permutation += 1
		candies += 1
	if largest_permutation < len(A):
		pass
	elif rank % P == 0:
		pass
	else:
		good_x += [x]
print(len(good_x))
print(*good_x)


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
m = max(a)
x = m - n + 1
lis = []
for i in range(x, m):
	l = []
	for e in a:
		w = e - i
		if w <= 0:
			l.append(n)
		else:
			l.append(n - w)
	l.sort()
	am = True
	for j in range(n):
		if (l[j] - j) % p == 0:
			am = False
			break
	if am:
		lis.append(i)
print(len(lis))
print(*lis)


(n, k) = list(map(int, input().strip().split()))
list1 = list(map(int, input().strip().split()))
list1.sort()
maxima = list1[n - 1]
m = dict()
curr = 1
count = 0
for i in range(n):
	if list1[i] != curr:
		for j in range(curr, list1[i]):
			m[j] = count
		curr = list1[i]
	count += 1
for j in range(curr, maxima + 1):
	m[j] = count
for j in range(maxima, 0, -1):
	if j == maxima:
		continue
	m[j] = max(m[j], m[j + 1] - 1)
for i in range(n - 1, 0 - 1, -1):
	if i == n - 1:
		temp = list1[n - 1]
	else:
		temp = max(list1[i], temp - 1)
start = temp
ans = []
while 1:
	if m[start] < k:
		ans.append(start)
	else:
		break
	start += 1
print(len(ans))
for val in ans:
	print(val, end=' ')
print()


from sys import stdin, stdout

def main():
	(n, p) = map(int, stdin.readline().split())
	ary = list(map(int, stdin.readline().split()))
	mxm = max(ary)
	mnm = min(ary)
	offset = max(mnm, mxm - n)
	m = 2 * n
	cf = [0] * m
	xs = [1] * m
	ibi = [0] * m
	for elem in ary:
		idx = max(0, elem - offset)
		cf[idx] = cf[idx] + 1
	cf[0] = cf[0] % p
	for idx in range(1, m):
		cf[idx] = (cf[idx] + cf[idx - 1]) % p
	for idx in range(m):
		ibi[idx] = (idx + offset) % p + p - cf[idx]
		ibi[idx] = ibi[idx] % p
	modp = [0] * p
	for idx in range(n):
		modp[ibi[idx]] += 1
	for idx in range(n, m):
		x = (idx - n + offset) % p
		if modp[x] > 0:
			xs[idx - n] = 0
		modp[ibi[idx - n]] -= 1
		modp[ibi[idx]] += 1
	result = []
	for idx in range(n):
		if xs[idx] == 1:
			result.append(str(idx + offset))
	stdout.write(str(len(result)))
	stdout.write('\n')
	stdout.write(' '.join(result))
	return
main()


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

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

def Binary_Search(N, P, A, dif):
	left = 0
	right = N - 1
	ansleft = dif
	ansright = -INF
	while left <= right:
		mid = (left + right) // 2
		jud = 'Yes'
		B = copy.deepcopy(A)
		B.append(INF)
		for t in range(N):
			B[t] -= mid
		array = [None] * N
		i = 0
		j = 0
		while True:
			if B[j] <= i:
				j += 1
			else:
				if (j - i) % P == 0:
					jud = 'No'
					break
				array[i] = j - i
				i += 1
			if i >= N:
				break
		if jud == 'Yes':
			ansright = max(ansright, dif + mid)
			left = mid + 1
		else:
			right = mid - 1
	return (ansleft, ansright)

def main():
	(N, P) = getlist()
	A = getlist()
	A = sorted(A)
	dif = 0
	for i in range(N):
		dif = max(dif, A[i] - i)
	for i in range(N):
		A[i] -= dif
	(L, R) = Binary_Search(N, P, A, dif)
	if R == -INF:
		print(0)
		print()
	else:
		Xlis = [i for i in range(L, R + 1)]
		print(len(Xlis))
		print(*Xlis)
main()


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = []
for x in range(1, 2001):
	fail = 0
	pointer = 0
	for i in range(n):
		while pointer < n - 1 and x + i - a[pointer + 1] >= 0:
			pointer += 1
		if (pointer + 1 - i) % p == 0:
			fail = 1
			break
		if x + i - a[pointer] < 0:
			fail = 1
			break
	if fail == 0:
		ans.append(str(x))
print(len(ans))
print(' '.join(ans))


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


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)
(l, r) = (lower - 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 False
	while cnt > 0:
		val += 1
		cnt -= 1
		if val in counter:
			cnt += counter[val]
		if cnt >= p:
			return False
		if val >= arr[-1]:
			break
	return not (cnt <= 0 or val < arr[-1])
cnt = 0
res = []
for i in range(lower, arr[-1] + 1):
	if check(i):
		cnt += 1
		res.append(i)
print(cnt)
print(' '.join(map(str, res)))


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
from bisect import bisect_right
(n, p) = map(int, input().split())
l = list(map(int, input().split()))
t = max(min(l), abs(n - max(l)))
l.sort()
z = []
for i in range(2001):
	ans = 1
	x = i
	f = 1
	for j in range(n):
		ans = bisect_right(l, x + j)
		if (ans - j) % p == 0:
			f = 0
			break
	if f == 1:
		z.append(i)
print(len(z))
print(*z)


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)
ANS = []
for i in range(len(S)):
	if S[i] >= p:
		break
	flag = 1
	for j in range(i, len(S)):
		if S[j] - (j - i) >= p or S[j] - (j - i) <= 0:
			flag = 0
			break
	if flag:
		ANS.append(start + i)
print(len(ANS))
print(*ANS)


import sys
from bisect import bisect_right as br
input = sys.stdin.readline
(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
table = [0] * (10 ** 5 + 1)
for x in range(10 ** 5 + 1):
	r = br(a, x)
	table[x] = r
res = []
for x in range(1, 2001):
	t = 1
	q = x + 0
	for i in range(n):
		t *= max(0, table[q] - i)
		t %= p
		q += 1
	if t % p:
		res.append(x)
print(len(res))
print(*res)


from sys import *
input = stdin.readline
for _ in range(1):
	(n, p) = map(int, input().split())
	a = list(map(int, input().split()))
	m = max(a)
	d = [0] * 4005
	for i in a:
		d[i] += 1
	w = []
	for i in range(m - n + 1, m + 1):
		v = 0
		for j in range(i):
			v += d[j]
		ans = 1
		for j in range(i, i + n):
			v = v + d[j]
			ans = ans % p * v % p % p
			v -= 1
		if ans % p != 0:
			w.append(i)
	print(len(w))
	print(*w)


def solve(n, p, array):
	array.sort()
	array1 = [i + 1 - array[i] for i in range(n)]
	m = min(array1)
	min_x = 1 - min(m, 0)
	valid = [1 for i in range(n)]
	max_v = n - 1
	for i in range(n):
		a = array1[i] + min_x
		if (i + 1) % p == 0:
			max_v = min(array[i] - min_x - 1, max_v)
		if a <= i + 1:
			cur = -a % p
			end = min(i + 1 - a, max_v)
			while cur <= end:
				valid[cur] = 0
				cur += p
	res = []
	for i in range(max_v + 1):
		if valid[i]:
			res.append(min_x + i)
	print(len(res))
	print(*res)
(n, p) = [int(s) for s in input().split()]
array = [int(s) for s in input().split()]
solve(n, p, array)


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()


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

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

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

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

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

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

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0

def def_inf():
	return inf

def atoi(s):
	return ord(s) - ord('a')

def inc(s, n=1):
	return chr((ord(s) - ord('a') + n) % 26 + ord('a'))

class XY:

	def __init__(self, x, y):
		self.x = x
		self.y = y

def rotate(a, b, c):
	ang = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y)
	if ang == 0:
		return 0
	else:
		return ang / abs(ang)
(n, p) = mp()
a = lmp()
a.sort()
ans = []
for i in range(2001):
	flg = True
	for j in range(n):
		y = br(a, i + j)
		if (y - j) % p == 0:
			flg = False
			break
	if flg:
		ans.append(i)
print(len(ans))
print(*ans)


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = list(map(int, list(next_line)))
		elif input_format == 5:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enu = enumerate
ter = lambda a, b, c: b if a else c

def mapl(iterable, format=0):
	if format == 0:
		return list(map(int, iterable))
	elif format == 1:
		return list(map(str, iterable))
	elif format == 2:
		return list(map(list, iterable))

def perm(x, p, z):
	fail = False
	for i in range(10 ** 10):
		if i + x >= len(p):
			y = p[-1] - i
		else:
			y = p[i + x] - i
		if y == 0:
			break
		if not y % z:
			fail = True
			break
	return not fail

def solve():
	(n, pr) = input(1)
	a = input(1)
	a.sort()
	c = a[0]
	r = c
	for i in range(1, n):
		c += a[i] - a[i - 1] - 1
		r = max(r, c)
	log('r', r)
	f = [0] * 2001
	for i in a:
		f[i] += 1
	p = [0]
	w = 1
	for i in f[1:]:
		w += 1
		p.append(p[-1] + i)
	log(list(range(10)) * 2)
	log(p[:20])
	tp = 0
	good = []
	for i in range(r, max(a) + 1):
		pm = perm(i, p, pr)
		if pm:
			tp += 1
			good.append(i)
	out(tp)
	out(good, 1)
	log(w, p[-1], n)
	return
solve()


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()