n, m = input().split()
n = int(n)
m = int(m)

c = input().split()
c = [int(x) for x in c]

average = round(sum(c) / m)

count_dict = {}
repeating_numbers = []

for num in c:
    if num in count_dict:
        count_dict[num] += 1
    else:
        count_dict[num] = 1

for num, count in count_dict.items():
    if count > 1:
        repeating_numbers.append(num)

print(average)
print(" ".join(map(str, repeating_numbers)))