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

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

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

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

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

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

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

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

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

Your task is to solve this problem made by Akari.


-----Input-----

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

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


-----Output-----

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

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

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


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

Output
1
3

Input
4 3
2 3 5 6

Output
2
3 4

Input
4 3
9 1 1 1

Output
0




-----Note-----

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

So, the only good number is $3$.

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

Difficulty: interview

Starter code:

Solutions:
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 = []
#print(table[: 100])
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)

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 bisect

n,p=list(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)


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 sys
input=lambda: sys.stdin.readline().rstrip()
n,p=list(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)
    


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


# T = int(input())
# for _ in range(T):
n, p = list(map(int, input().split()))
matrix = list(map(int, input().split()))
res = solve(n, p, matrix)
print(len(res))
print(" ".join(map(str, res)))


n, p = map(int, input().split())
a = list(map(int, input().split()))
def calc(x):
    nonlocal 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)

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


from sys import stdin
input = stdin.readline
n, p = list(map(int,input().split()))
c = list(map(int,input().split()))
dobre = []
#na ktorym miejscu co najmniej musimy ustawic
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)


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

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)

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

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)

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