Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n.

Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integers from 1 to n was encountered in his array exactly once). If there are multiple ways to do it he wants to find the lexicographically minimal permutation among them.

Thus minimizing the number of changes has the first priority, lexicographical minimizing has the second priority.

In order to determine which of the two permutations is lexicographically smaller, we compare their first elements. If they are equal — compare the second, and so on. If we have two permutations x and y, then x is lexicographically smaller if x_{i} < y_{i}, where i is the first index in which the permutations x and y differ.

Determine the array Ivan will obtain after performing all the changes.


-----Input-----

The first line contains an single integer n (2 ≤ n ≤ 200 000) — the number of elements in Ivan's array.

The second line contains a sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n) — the description of Ivan's array.


-----Output-----

In the first line print q — the minimum number of elements that need to be changed in Ivan's array in order to make his array a permutation. In the second line, print the lexicographically minimal permutation which can be obtained from array with q changes.


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

Output
2
1 2 4 3 

Input
6
4 5 6 3 2 1

Output
0
4 5 6 3 2 1 

Input
10
6 8 4 6 7 1 6 3 4 5

Output
3
2 8 4 6 7 1 9 3 10 5 



-----Note-----

In the first example Ivan needs to replace number three in position 1 with number one, and number two in position 3 with number four. Then he will get a permutation [1, 2, 4, 3] with only two changed numbers — this permutation is lexicographically minimal among all suitable. 

In the second example Ivan does not need to change anything because his array already is a permutation.

Difficulty: MEDIUM

Solutions:
n = int(input())
a = input().split(' ')
for i in range(n):
	a[i] = int(a[i]) - 1
occ = {}
for i in range(len(a)):
	if a[i] not in occ:
		occ[a[i]] = 1
	else:
		occ[a[i]] += 1
missing = []
for i in range(n):
	if i not in occ:
		missing.append(i)
act_missing = 0
left = [1] * n
for pos in range(n):
	if occ[a[pos]] > left[a[pos]]:
		if missing[act_missing] < a[pos] or left[a[pos]] == 0:
			occ[a[pos]] -= 1
			a[pos] = missing[act_missing]
			act_missing += 1
		else:
			left[a[pos]] -= 1
			occ[a[pos]] -= 1
s = ''
for e in a:
	s += str(e + 1)
	s += ' '
print(len(missing))
print(s)


n = int(input())
l = [int(i) for i in input().split()]
if len(set(l)) == n and min(l) == 1 and (max(l) == n):
	print(0)
	print(*l)
	exit()
miss = []
cnt = 0
from collections import Counter
c = Counter(l)
for i in range(1, n + 1):
	if c[i] == 0:
		miss.append(i)
extra = []
for i in range(1, n + 1):
	if c[i] > 1:
		extra.append([i, c[i] - 1])
miss.sort()
karma = [0] * n
j = 0
for i in range(n):
	if c[l[i]] > 1:
		a = miss[j]
		if a < l[i] or karma[l[i]]:
			c[l[i]] -= 1
			l[i] = miss[j]
			j += 1
			cnt += 1
		else:
			karma[l[i]] = 1
print(cnt)
print(*l)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	n = int(input())
	arr = list_input()
	nums = {}
	not_visited = {}
	for i in range(n):
		not_visited[i + 1] = 1
	for i in range(n):
		try:
			nums[arr[i]] += 1
		except KeyError:
			nums[arr[i]] = 1
			del not_visited[arr[i]]
	key = list(nums.keys())
	if len(nums.keys()) == n:
		print(0)
		print(*arr)
		return
	not_visited = list(not_visited.keys())
	visited = {}
	op = 0
	indx = 0
	for i in not_visited:
		while indx < n:
			if arr[indx] > i:
				if nums[arr[indx]] > 1:
					op += 1
					nums[arr[indx]] -= 1
					arr[indx] = i
					indx += 1
					break
				else:
					visited[arr[indx]] = 1
					indx += 1
			elif arr[indx] < i:
				try:
					visited[arr[indx]]
					if nums[arr[indx]] > 1:
						op += 1
						nums[arr[indx]] -= 1
						arr[indx] = i
						indx += 1
						break
				except KeyError:
					visited[arr[indx]] = 1
					indx += 1
	print(op)
	print(*arr)
t = 1
for _ in range(t):
	solve()


n = int(input())
a = [int(i) for i in input().split()]
cnt = [0] * (n + 1)
for i in a:
	cnt[i] += 1
rem = []
for i in range(1, n + 1):
	if cnt[i] == 0:
		rem.append(i)
rem.reverse()
print(len(rem))
skipped = [0] * (n + 1)
for i in range(n):
	if len(rem) == 0:
		break
	if cnt[a[i]] > 1 and (a[i] > rem[-1] or skipped[a[i]]):
		cnt[a[i]] -= 1
		a[i] = rem.pop()
	elif cnt[a[i]] > 1 and a[i] < rem[-1]:
		skipped[a[i]] = 1
print(*a)


n = int(input())
a = list(map(int, input().split()))
occur = [0] * (n + 1)
for i in range(n):
	occur[a[i]] += 1
need = []
change = []
for i in range(1, n + 1):
	if occur[i] == 0:
		need.append(i)
print(len(need))
j = 0
done = [0] * n
for i in range(n):
	if occur[a[i]] >= 1:
		if j < len(need) and need[j] < a[i] and (occur[a[i]] > 1):
			occur[a[i]] -= 1
			a[i] = need[j]
			done[need[j] - 1] = 1
			j += 1
		elif j < len(need) and done[a[i] - 1] == 1:
			occur[a[i]] -= 1
			a[i] = need[j]
			done[need[j] - 1] = 1
			j += 1
		else:
			occur[a[i]] -= 1
			done[a[i] - 1] = 1
	else:
		done[a[i] - 1] = 1
		occur[a[i]] -= 1
print(*a)


from collections import deque

def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for (i, x) in enumerate(a):
		d.setdefault(x, []).append(i)
	s = []
	c = {}
	for (k, v) in d.items():
		s.extend(v)
		c[k] = len(v)
	s.sort()
	killed = set()
	ava = deque(sorted(frozenset(range(1, n + 1)) - frozenset(a)))
	ans = 0
	for i in s:
		v = a[i]
		if (c[v] == 1 or ava[0] > v) and (not v in killed):
			killed.add(v)
		else:
			a[i] = ava.popleft()
			ans += 1
		c[v] -= 1
	print(ans)
	print(' '.join(map(str, a)))
main()


n = int(input())
a = input()
a = [int(i) for i in a.split()]
ma = {}
se = {}
for i in range(n):
	ma[a[i]] = 0
	se[a[i]] = 0
v = []
for i in range(n):
	ma[a[i]] = ma[a[i]] + 1
	if i + 1 not in ma.keys():
		v.append(i + 1)
print(len(v))
k = 0
for i in range(n):
	if ma[a[i]] > 1:
		if se[a[i]] == 1:
			ma[a[i]] = ma[a[i]] - 1
			a[i] = v[k]
			k = k + 1
		elif a[i] < v[k]:
			se[a[i]] = 1
		else:
			ma[a[i]] = ma[a[i]] - 1
			a[i] = v[k]
			k = k + 1
	print(a[i], end=' ')


import collections
n = int(input())
line = [int(x) for x in input().split()]
c = dict(collections.Counter(line))
t = n - len(c)
print(t)
d = {key: value for (key, value) in c.items() if value > 1}
d2 = {key: 0 for key in c.keys()}
s = set(range(1, n + 1)) - set(line)
temp = list(sorted(s))
j = 0
for i in range(n):
	if j == t:
		break
	if c[line[i]] > 1:
		if temp[j] < line[i]:
			c[line[i]] -= 1
			line[i] = temp[j]
			j += 1
		elif d2[line[i]] != 0:
			c[line[i]] -= 1
			line[i] = temp[j]
			j += 1
		else:
			d2[line[i]] += 1
print(*line)


from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue
from statistics import median
from math import gcd, sqrt, floor, factorial, ceil, log2, log10
import copy
from copy import deepcopy
import sys
sys.setrecursionlimit(10 ** 7)
import math
import os
import bisect
import collections
mod = pow(10, 9) + 7

def ncr(n, r, p=mod):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
inf = float('inf')
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
	adj[a].add(b)
	adj[b].add(a)

def bfs(v):
	q = Queue()
	q.put(v)
	visited[v] = 1
	while q.qsize() > 0:
		s = q.get_nowait()
		print(s)
		for i in adj[s]:
			if visited[i] == 0:
				q.put(i)
				visited[i] = 1

def dfs(v, visited):
	if visited[v] == 1:
		return
	visited[v] = 1
	print(v)
	for i in adj[v]:
		dfs(i, visited)
n = int(input())
l = list(map(int, input().split()))
dict = Counter(l)
mex = n + 1
m = []
for i in range(1, mex):
	if i not in dict:
		m.append(i)
iterator = 0

def reduce(i):
	if dict[i] == 1:
		dict.pop(i)
	else:
		dict[i] -= 1
count = defaultdict(int)
for i in range(len(l)):
	if dict[l[i]] > 1:
		if l[i] < m[iterator] and l[i] not in count:
			count[l[i]] = 1
			continue
		reduce(l[i])
		l[i] = m[iterator]
		iterator += 1
print(len(m))
print(*l)


n = int(input())
l = list(map(int, input().split()))
d = dict()
d1 = dict()
first = dict()
ans = [0] * n
cnt = 0
for i in range(n):
	if l[i] not in d:
		d.update({l[i]: [i]})
		d1.update({l[i]: 1})
		first.update({l[i]: i})
		ans[l[i] - 1] = 1
	else:
		d[l[i]].append(i)
		d1[l[i]] += 1
		cnt += 1
e = []
for j in d1:
	if d1[j] > 1:
		cnt += 1
a = 0
for i in range(n):
	if ans[i] == 0:
		e.append(i + 1)
t = 0
le = len(e)
s = set()
for i in range(n):
	if d1[l[i]] > 1:
		if e[t] < l[i] or l[i] in s:
			d1[l[i]] -= 1
			if d1[l[i]] == 1:
				cnt -= 1
			l[i] = e[t]
			t += 1
			a += 1
			if t == len(e):
				break
		cnt -= 1
	s.add(l[i])
print(a)
print(*l, sep=' ')


n = int(input())
arr = list(map(int, input().split()))
dict1 = {}
for i in range(n):
	try:
		dict1[arr[i]] += 1
	except:
		KeyError
		dict1[arr[i]] = 1
arr1 = []
for i in range(1, n + 1):
	try:
		dict1[i] = dict1[i] - 1 + 1
	except:
		KeyError
		arr1.append(i)
i = 0
j = 0
arr2 = [0] * (n + 1)
while i < len(arr1) and j < n:
	temp = arr[j]
	if arr2[arr[j]] == 1:
		arr[j] = arr1[i]
		arr2[arr1[i]] = 1
		i += 1
	elif arr2[arr[j]] == 0 and dict1[arr[j]] > 1:
		if arr[j] > arr1[i]:
			arr[j] = arr1[i]
			arr2[arr1[i]] = 1
			i += 1
		else:
			arr2[arr[j]] = 1
	else:
		arr2[arr[j]] = 1
	dict1[temp] -= 1
	j += 1
print(len(arr1))
print(*arr)


def Diff(li1, li2):
	return list(list(set(li1) - set(li2)) + list(set(li2) - set(li1)))
n = int(input())
a = list(map(int, input().split()))
p = [i for i in range(1, n + 1)]
x = Diff(a, p)
if len(x) == 0:
	print(0)
	print(*a)
else:
	d = {}
	for i in range(n):
		d[a[i]] = d.get(a[i], 0) + 1
	x.sort()
	j = 0
	s = {}
	ans = 0
	for i in range(n):
		if d[a[i]] > 1:
			s[a[i]] = s.get(a[i], 0)
			if a[i] < x[j]:
				if s[a[i]] == 1:
					d[a[i]] = d[a[i]] - 1
					a[i] = x[j]
					j = j + 1
					ans = ans + 1
				else:
					s[a[i]] = 1
			else:
				d[a[i]] = d[a[i]] - 1
				a[i] = x[j]
				j = j + 1
				ans = ans + 1
	print(ans)
	print(*a)


n = int(input())
d = [0] * n
(*l,) = map(int, input().split())
for i in l:
	d[i - 1] += 1
print(d.count(0))
p = [0] * n
t = 0
for (i, j) in enumerate(l):
	if d[j - 1] > 1:
		while d[t] > 0:
			t += 1
		if j > t + 1 or p[j]:
			d[j - 1] -= 1
			d[t] += 1
			l[i] = t + 1
		else:
			p[j] = 1
print(' '.join(map(str, l)))


n = int(input())
n = n + 1
a = [0] + list(map(int, input().split()))
s = [0] * n
s1 = [0] * n
step = 1
for j in a:
	s[j] += 1
for (i, j) in enumerate(a):
	if s[j] > 1:
		while s[step]:
			step += 1
		if j > step or s1[j]:
			a[i] = step
			s[j] -= 1
			step += 1
		else:
			s1[j] = 1
print(s.count(0))
print(' '.join(map(str, a[1:])))


n = int(input())
arr = list(map(int, input().strip().split(' ')))
a = [0 for i in range(200001)]
b = [0 for i in range(200001)]
for i in arr:
	a[i] += 1
j = 1
t = 0
for i in range(1, n + 1):
	if a[i] > 0:
		t += 1
for i in range(n):
	if a[arr[i]] > 1:
		while a[j] != 0:
			j += 1
		if arr[i] > j or b[arr[i]] == 1:
			a[arr[i]] -= 1
			arr[i] = j
			a[j] = 1
		else:
			b[arr[i]] = 1
print(n - t)
for i in arr:
	print(i, end=' ')
print()


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')
n = int(input())
l = list(map(int, input().split()))
ans = 0
l1 = [0] * (n + 1)
l3 = [0] * (n + 1)
l4 = [0] * (n + 1)
l5 = [1] * n
for i in range(n):
	l4[l[i]] += 1
	if l4[l[i]] > 1:
		ans += 1
		l3[l[i]] += 1
		l1[l[i]] = 1
	l5[l[i] - 1] = 0
if ans == 0:
	print(0)
	print(*l)
else:
	print(ans)
	l2 = []
	for i in range(n):
		if l5[i] == 1:
			l2.append(i + 1)
	j = 0
	for i in range(n):
		if j != len(l2):
			if l4[l[i]] > 1:
				if l2[j] < l[i]:
					if l3[l[i]] > 0:
						l3[l[i]] -= 1
						l[i] = str(l2[j])
						j += 1
					else:
						l[i] = str(l[i])
				elif l1[l[i]] == 1:
					l1[l[i]] -= 1
					l[i] = str(l[i])
				else:
					l[i] = str(l2[j])
					j += 1
			else:
				l[i] = str(l[i])
		else:
			l[i] = str(l[i])
	print(' '.join(l))


n = int(input())
a = list(map(int, input().split()))
d = dict()
for i in range(n):
	if a[i] not in d:
		d[a[i]] = 1
	else:
		d[a[i]] += 1
print(n - len(d))
miss = list()
for i in range(1, n + 1):
	if i not in d:
		miss.append(i)
index = 0
for i in range(n):
	if d[a[i]] > 1 and a[i] > miss[index] or d[a[i]] < 0:
		print(miss[index], end=' ')
		index += 1
		d[a[i]] -= 1
	else:
		d[a[i]] = -1
		print(a[i], end=' ')
print('')


n = int(input())
b = [0] * n
c = [0] * n
array = []
for i in input().split():
	array.append(int(i))
	b[int(i) - 1] += 1
	c[int(i) - 1] = True
free = []
count = 0
for i in range(n):
	if b[i] == 0:
		free.append(i + 1)
	else:
		count += b[i] - 1
print(count)
z = 0
for i in range(n):
	if b[array[i] - 1] > 1:
		if array[i] > free[z]:
			b[array[i] - 1] -= 1
			array[i] = free[z]
			z += 1
		elif c[array[i] - 1] == False:
			b[array[i] - 1] -= 1
			array[i] = free[z]
			z += 1
		else:
			c[array[i] - 1] = False
for i in range(n):
	print(array[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
d = {}
b = []
exists = {}
for i in a:
	d[i] = 1 if i not in d else d[i] + 1
ans = n - len(d)
for i in range(1, n + 1):
	if i not in d:
		b.append(i)
i = 0
j = 0
while i < len(b) and j < len(a):
	if d[a[j]] > 1:
		if a[j] in exists:
			d[a[j]] -= 1
			a[j] = b[i]
			i += 1
		elif b[i] < a[j]:
			d[a[j]] -= 1
			a[j] = b[i]
			i += 1
		else:
			exists[a[j]] = True
	else:
		exists[a[j]] = True
	j += 1
print(ans)
print(*a)


n = int(input())
l = list(map(int, input().split()))
cnt = [0] * 200001
pos = [0] * 200001
for i in range(n):
	cnt[l[i]] += 1
uk = 1
an = 0
for i in range(n):
	if cnt[l[i]] > 1:
		an += 1
		while cnt[uk] != 0:
			uk += 1
		if uk > l[i] and pos[l[i]] or uk < l[i]:
			cnt[l[i]] -= 1
			cnt[uk] += 1
			l[i] = uk
		else:
			pos[l[i]] = 1
			an -= 1
print(an)
print(' '.join(map(str, l)))


from collections import Counter
n = int(input())
arr = [int(x) for x in input().split(' ')]
counter = Counter(arr)
s = {x for x in range(1, n + 1)}
replacements = sorted(list(s - set(counter.keys())))
r = 0
ans = 0
skipped = set()
for (index, value) in enumerate(arr):
	if counter[value] > 1:
		if value > replacements[r] or value in skipped:
			arr[index] = replacements[r]
			ans += 1
			r += 1
			counter.subtract((value,))
		else:
			skipped.add(value)
print(ans)
print(' '.join([str(x) for x in arr]))


from collections import Counter
import string
import math
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
testcases = 1
for _ in range(testcases):
	n = vary(1)
	num = array_int()
	orignal = [i for i in range(1, n + 1)]
	orignal = set(orignal)
	ct = makedict(num)
	req = []
	ans = 0
	boolean = {}
	for i in orignal:
		if i in ct:
			boolean[i] = True
			continue
		else:
			req.append(i)
			ans += 1
	if ans == 0:
		print(ans)
		print(*num)
	else:
		req.sort()
		j = 0
		i = 0
		if 1:
			flag = 0
			value = -1
			while j < n:
				if ct[num[j]] > 1:
					if num[j] > req[i]:
						ct[num[j]] -= 1
						num[j] = req[i]
						i += 1
					elif boolean[num[j]] == False:
						ct[num[j]] -= 1
						num[j] = req[i]
						i += 1
					else:
						boolean[num[j]] = False
				j += 1
		print(len(req))
		print(*num)


n = int(input())
l = list(map(int, input().split()))
(lis, ind) = (set(), {})
for i in l:
	if i in ind:
		ind[i] += 1
	else:
		ind[i] = 1
		lis.add(i)
mlis = sorted(set(range(1, n + 1)) - lis, key=int)
k = 0
for (i, j) in enumerate(l):
	if ind[j] != 1:
		if ind[j] == 0 or mlis[k] < j:
			l[i] = mlis[k]
			k += 1
			if k == len(mlis):
				break
		else:
			ind[j] = 0
		if ind[j] > 1:
			ind[j] -= 1
print(len(mlis), ' '.join(map(str, l)), sep='\n')


from collections import defaultdict
n = int(input())
l = list(map(int, input().split()))
count = defaultdict(int)
for x in l:
	count[x] += 1
need = []
for x in range(1, n + 1):
	if count[x] == 0:
		need.append(x)
pos_need = 0
open = [False for _ in range(n + 1)]
actions = 0
for i in range(n):
	if pos_need == len(need):
		break
	if count[l[i]] >= 2:
		if l[i] < need[pos_need]:
			if open[l[i]]:
				count[l[i]] -= 1
				l[i] = need[pos_need]
				actions += 1
				pos_need += 1
			else:
				open[l[i]] = True
		else:
			count[l[i]] -= 1
			l[i] = need[pos_need]
			actions += 1
			pos_need += 1
print(actions)
print(*l)


n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i in range(n):
	b[a[i] - 1] += 1
c = []
for i in range(n):
	if b[i] == 0:
		c.append(i + 1)
v = [0] * n
j = 0
d = 0
for i in range(n):
	if j < len(c):
		if b[a[i] - 1] > 1:
			if a[i] > c[j]:
				b[a[i] - 1] = b[a[i] - 1] - 1
				a[i] = c[j]
				d = d + 1
				j = j + 1
			elif v[a[i] - 1] == 0:
				v[a[i] - 1] = 1
			else:
				b[a[i] - 1] = b[a[i] - 1] - 1
				a[i] = c[j]
				j = j + 1
				d = d + 1
print(d)
print(*a)


n = int(input())
l = list(map(int, input().split()))
s = []
for i in range(n):
	s.append(i + 1)
dic1 = {}
dic2 = {}
for i in range(n):
	dic1[s[i]] = 0
	dic2[s[i]] = 0
set1 = set(l)
set2 = set(s)
set3 = set2 - set1
li = list(set3)
li.sort()
for i in range(n):
	dic1[l[i]] += 1
	dic2[l[i]] += 1
print(len(li))
re = [0] * n
j = 0
for i in range(n):
	if dic2[l[i]] == 1:
		re[i] = l[i]
	elif dic1[l[i]] != n + 1:
		if l[i] < li[j]:
			dic1[l[i]] = n + 1
			re[i] = l[i]
		else:
			dic2[l[i]] -= 1
			re[i] = li[j]
			j += 1
	else:
		dic2[l[i]] -= 1
		re[i] = li[j]
		j += 1
for i in range(n):
	re[i] = str(re[i])
print(' '.join(re))


n = int(input())
air = [int(x) for x in input().split()]
a = [0] * (n + 1)
a[0] = 1
for x in range(n):
	a[air[x]] += 1
st = [0]
for x in range(n, -1, -1):
	if a[x] == 0:
		st.append(x)
cnt = 0
level = dict()
for x in range(n):
	if a[air[x]] > 1:
		if air[x] > st[-1]:
			a[air[x]] -= 1
			air[x] = st[-1]
			st.pop()
			cnt += 1
		elif level.get(air[x], 0) == 0:
			level[air[x]] = 1
		else:
			a[air[x]] -= 1
			air[x] = st[-1]
			st.pop()
			cnt += 1
print(cnt)
for x in air:
	print(x, end=' ')


n = int(input())
a = list(map(int, input().split()))
if sorted(a) == list(range(1, n + 1)):
	print(0)
	print(' '.join(map(str, a)))
else:
	cnt = [0] * (n + 1)
	for i in a:
		cnt[i] += 1
	add = []
	for i in range(1, n + 1):
		if cnt[i] == 0:
			add.append(i)
	pos = 0
	m_cnt = 0
	appeared = [False] * (n + 1)
	for (i, t) in enumerate(a):
		if cnt[t] > 1:
			if t > add[pos] or appeared[t]:
				a[i] = add[pos]
				pos += 1
				m_cnt += 1
				if pos == len(add):
					break
				cnt[t] -= 1
				appeared[a[i]] = True
			else:
				appeared[t] = True
		else:
			appeared[t] = True
	print(m_cnt)
	print(' '.join(map(str, a)))


import math
import sys
from collections import deque
import heapq
import time
input = sys.stdin.readline
mod = 10 ** 9 + 7

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

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

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

def invr():
	return map(int, input().split())
n = inp()
l = inlt()
d = {}
for i in range(n):
	d[i + 1] = deque()
v = [0] * n
x = []
for i in range(n):
	d[l[i]].append(l[i])
	v[l[i] - 1] = 1
p = 0
x = [0] * n
for i in range(n):
	if v[i] == 0:
		for j in range(p, n):
			if len(d[l[p]]) > 1:
				if i + 1 < l[p] or x[l[p] - 1] == 1:
					d[l[p]].popleft()
					l[p] = i + 1
					p += 1
					break
				else:
					x[l[p] - 1] = 1
			p += 1
m = n
print(m - sum(v))
print(*l)


def make_a_permutation():
	n = int(input())
	a = list(map(int, input().split()))
	occ = [0] * (n + 1)
	for i in range(n):
		occ[a[i]] += 1
	missing = [i for i in range(1, n + 1) if occ[i] == 0]
	mi = 0
	dupIndexes = [i for i in range(n) if occ[a[i]] >= 2]
	fixedNum = [False] * (n + 1)
	for i in range(n):
		if occ[i] == 1:
			fixedNum[i] = True
	for dup in dupIndexes:
		dupNum = a[dup]
		if occ[dupNum] > 1 and (fixedNum[dupNum] or dupNum > missing[mi]):
			fixedNum[missing[mi]] = True
			occ[missing[mi]] += 1
			a[dup] = missing[mi]
			mi += 1
			occ[dupNum] -= 1
		else:
			fixedNum[dupNum] = True
	return (mi, a)
(c, l) = make_a_permutation()
print(c)
for i in range(len(l)):
	print(l[i], end=' ')


n = int(input())
lis = list(map(int, input().split()))
has = [0] * (n + 2)
oc = [0] * (n + 2)
ans = []
for i in lis:
	has[i] += 1
for i in range(1, n + 1):
	if has[i] == 0:
		ans.append(i)
ans.sort()
c = aa = 0
for i in range(n):
	if has[lis[i]] > 1 and ans[c] <= lis[i]:
		has[lis[i]] -= 1
		lis[i] = ans[c]
		c += 1
		aa += 1
	elif has[lis[i]] > 1 and ans[c] > lis[i]:
		if oc[lis[i]] == 0:
			oc[lis[i]] = 1
			continue
		has[lis[i]] -= 1
		lis[i] = ans[c]
		c += 1
		aa += 1
print(aa)
print(*lis)


from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
left = [int(i) for i in range(1, n + 1) if i not in c]
(ll, cc) = (0, 0)
visited = [0] * (n + 1)
for i in range(0, n):
	if c[a[i]] > 1:
		if left[ll] < a[i] or visited[a[i]]:
			c[a[i]] -= 1
			a[i] = left[ll]
			cc += 1
			ll += 1
		else:
			visited[a[i]] = 1
print(cc)
print(*a)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
need = sorted(set(range(1, n + 1)) - set(a))
C = Counter(a)
was = [False for el in range(n + 1)]
c = 0
ans = list()
for i in range(n):
	if C[a[i]] == 1:
		ans.append(a[i])
		C[a[i]] -= 1
		was[a[i]] = True
	elif len(need):
		m = need[c]
		if a[i] > m or was[a[i]]:
			ans.append(m)
			c += 1
			C[a[i]] -= 1
		else:
			ans.append(a[i])
			was[a[i]] = True
print(n - len(set(a)))
print(' '.join(map(str, ans)))


from sys import stdin, stdout
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
e = set(a)
L = [0] * (n + 1)
q = 0
e = set()
for i in range(1, n + 1):
	e.add(i)
d = {}
for i in range(len(a)):
	try:
		d[a[i]].append(i)
		d[a[i]][0] += 1
	except:
		d[a[i]] = [1, i]
	if L[a[i]] == 0:
		e.remove(a[i])
	else:
		q += 1
	L[a[i]] += 1
B = []
for x in e:
	B.append(x)
B.sort()
j = 0
qq = q
LL = [0] * (n + 1)
for i in range(len(a)):
	b = a[i]
	if L[a[i]] > 1 and a[i] > B[j]:
		L[a[i]] -= 1
		a[i] = B[j]
		qq -= 1
		j += 1
	elif L[a[i]] > 1 and d[a[i]][0] == 1:
		L[a[i]] -= 1
		a[i] = B[j]
		qq -= 1
		j += 1
	elif LL[a[i]] >= 1:
		L[a[i]] -= 1
		a[i] = B[j]
		qq -= 1
		j += 1
	else:
		LL[b] += 1
	d[b][0] -= 1
print(q)
ch = ''
for x in a:
	ch += str(x) + ' '
print(ch)


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
	if a[i] in d:
		d[a[i]] += 1
	else:
		d[a[i]] = 1
l = {i for i in range(1, n + 1)}
x = list(l - set(a))
x.sort(reverse=True)
print(len(x))
for i in range(n):
	if d[a[i]] > 1:
		d[a[i]] -= 1
		if x[-1] < a[i]:
			a[i] = x.pop()
		else:
			d[a[i]] = 0
	elif d[a[i]] == 0:
		a[i] = x.pop()
print(*a)


from collections import defaultdict as dc
n = int(input())
a = [int(i) for i in input().split()]
p = dc(int)
q = dc(int)
extra = dc(int)
missing = []
for i in range(n):
	p[a[i]] = p[a[i]] + 1
	if p[a[i]] > 1:
		extra[a[i]] = 1
for i in range(1, n + 1):
	if p[i] == 0:
		missing.append(i)
l = 0
for i in range(n):
	if l >= len(missing):
		break
	if extra[a[i]] == 1 and p[a[i]] >= 1:
		if missing[l] > a[i] and p[a[i]] > 1 and (q[a[i]] == 0):
			p[a[i]] = p[a[i]] - 1
			q[a[i]] = 1
		elif p[a[i]] == 1 and q[a[i]] == 0:
			continue
		else:
			p[a[i]] = p[a[i]] - 1
			a[i] = missing[l]
			l = l + 1
print(len(missing))
print(*a)


n = int(input())
a = list(map(int, input().strip().split()))
count = [0] * n
for e in a:
	count[e - 1] += 1
todo = []
flag = [False] * n
for i in range(len(count)):
	if count[i] == 0:
		todo.append(i + 1)
print(len(todo))
j = 0
i = 0
while i < len(todo):
	el = todo[i]
	while count[a[j] - 1] < 2:
		j += 1
	if el < a[j]:
		count[a[j] - 1] -= 1
		a[j] = el
		i += 1
	elif flag[a[j] - 1] is True:
		a[j] = el
		i += 1
	else:
		flag[a[j] - 1] = True
		j += 1
print(' '.join(map(str, a)))


import math
import collections
import bisect
import heapq
import time
import random
N = int(input())
M = [int(x) for x in input().split()]
S = [0 for i in range(N + 1)]
for v in M:
	S[v] += 1
changes = sum([S[i] - 1 for i in range(N + 1) if S[i] > 1] or [0])
if changes == 0:
	print(changes)
	print(' '.join([str(x) for x in M]))
	exit(0)
used = [0 for _ in range(N + 1)]
miss = collections.deque(sorted([x for x in range(1, N + 1) if S[x] == 0]))
for i in range(N):
	v = M[i]
	if used[v]:
		M[i] = miss.popleft()
	elif S[v] > 1:
		if miss and miss[0] < v:
			M[i] = miss.popleft()
			S[v] -= 1
		else:
			used[v] = 1
print(changes)
print(' '.join([str(x) for x in M]))


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

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

def map_string():
	return input().split()
from collections import Counter
n = int(input())
a = list_input()
c = Counter(a)
ans = 0
s = set(a)
s1 = []
for i in range(1, n + 1):
	if i not in s:
		s1.append(i)
cur = 0
left = set([])
for i in range(n):
	if c[a[i]] > 1:
		if s1[cur] < a[i] or a[i] in left:
			c[a[i]] -= 1
			a[i] = s1[cur]
			cur += 1
			ans += 1
		else:
			left.add(a[i])
print(ans)
for i in a:
	print(i, end=' ')


n = int(input())
a = [int(x) for x in input().split(' ')]
cnt = [0 for i in range(n)]
need = []
for i in range(n):
	cnt[a[i] - 1] += 1
for i in range(n):
	if cnt[i] == 0:
		need.append(i + 1)
have = [0 for i in range(n)]
pos = 0
for i in range(n):
	term = a[i]
	if cnt[term - 1] > 1:
		if have[term - 1] or need[pos] < term:
			a[i] = need[pos]
			cnt[term - 1] -= 1
			cnt[need[pos] - 1] += 1
			pos += 1
		have[a[i] - 1] = 1
	else:
		have[term - 1] = 1
print(len(need))
for i in a:
	print(i, end=' ')


import collections
n = int(input())
a = list(map(int, input().split()))
cnt = collections.Counter(a)
res = []
b = []
for i in range(1, n + 1):
	if i not in cnt:
		b.append(i)
b.sort(reverse=True)
s = set(a)
print(len(b))
for v in a:
	if v in cnt and cnt[v] > 1:
		t = b[-1]
		if v < t and v in s:
			res.append(v)
			s.remove(v)
		else:
			res.append(b.pop())
			cnt[v] -= 1
	else:
		res.append(v)
print(' '.join(list(map(str, res))))


def solve(printing):
	n = int(input())
	nums = [int(st) - 1 for st in input().split(' ')]
	numdupe = [0] * n
	dupeindex = []
	dupeindexindv = {}
	missing = []
	if printing:
		print('nums')
		print(nums)
	for i in range(n):
		numdupe[nums[i]] += 1
	for i in range(n):
		if numdupe[i] == 0:
			missing.append(i)
		if numdupe[nums[i]] >= 2:
			dupeindex.append(i)
			if nums[i] in dupeindexindv:
				dupeindexindv[nums[i]][1].append(i)
			else:
				dupeindexindv[nums[i]] = [0, [i], False]
	for num in dupeindexindv:
		dupeindexindv[num][0] = len(dupeindexindv[num][1])
	if printing:
		print('missing')
		print(missing)
		print('dupeindexindv')
		print(dupeindexindv)
	misslen = len(missing)
	misindex = 0
	for index in dupeindex:
		if misslen <= misindex:
			break
		elif dupeindexindv[nums[index]][0] == 1 and (not dupeindexindv[nums[index]][2]):
			dupeindexindv[nums[index]][0] -= 1
			dupeindexindv[nums[index]][2] = True
		elif dupeindexindv[nums[index]][0] > 0:
			if dupeindexindv[nums[index]][2] or missing[misindex] < nums[index]:
				dupeindexindv[nums[index]][0] -= 1
				nums[index] = missing[misindex]
				misindex += 1
			else:
				dupeindexindv[nums[index]][0] -= 1
				dupeindexindv[nums[index]][2] = True
	print(misslen)
	for num in nums:
		print(num + 1, end=' ')
solve(False)


from collections import Counter
n = int(input())
(*a,) = map(int, input().split())
c = Counter(a)
d = c.copy()
(i, j, k) = (0, 1, 0)
while i < n:
	if c[j] < 1:
		while i < n:
			if c[a[i]] > 1 and (c[a[i]] > d[a[i]] or j < a[i]):
				c[a[i]] -= 1
				d[a[i]] -= 1
				a[i] = j
				k += 1
				break
			d[a[i]] -= 1
			i += 1
	j += 1
print(k)
print(*a)


import sys
n = int(input())
a = input().split()
arr = [int(_) for _ in a]
cnt = [0 for _ in range(n + 1)]
must = [False for _ in range(n + 1)]
for x in arr:
	cnt[x] += 1
que = []
for i in range(1, n + 1):
	if cnt[i] == 0:
		que.append(i)
cur = 0
for i in range(n):
	x = arr[i]
	if cnt[x] > 1:
		if must[x] or que[cur] < x:
			cnt[x] -= 1
			arr[i] = que[cur]
			cur += 1
		else:
			must[x] = True
print(cur)
for x in arr:
	print(x, end=' ')


n = int(input())
a = list(map(int, input().split()))
count = [0] * 10 ** 6
f = [0] * 10 ** 6
rem = []
for i in range(n):
	count[a[i]] += 1
for i in range(1, n + 1):
	if count[i] == 0:
		rem.append(i)
l = 0
for i in range(n):
	if count[a[i]] == 1 and f[a[i]] == 0:
		a[i] = a[i]
	elif count[a[i]] == 1 and f[a[i]] == 1:
		a[i] = rem[l]
		l += 1
	elif count[a[i]] > 1 and f[a[i]] == 0:
		if rem[l] < a[i]:
			count[a[i]] -= 1
			a[i] = rem[l]
			l += 1
		else:
			count[a[i]] -= 1
			a[i] = a[i]
			f[a[i]] = 1
	elif count[a[i]] > 1 and f[a[i]] == 1:
		count[a[i]] -= 1
		a[i] = rem[l]
		l += 1
print(len(rem))
print(*a)


from io import BytesIO, IOBase
import sys, os
inpl = lambda : list(map(int, input().split()))
inpm = lambda : map(int, input().split())
inpi = lambda : int(input())
inp = lambda : input()
(rev, ra, l) = (reversed, range, len)
P = print
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')

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

def input():
	return sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_left as bl
from bisect import bisect_right as br
import sys, operator, math, operator
from collections import Counter
import random
from functools import reduce
n = inpi()
li = inpl()
omap = Counter(li)
arr = []
for i in ra(1, n + 1):
	if i not in omap:
		arr.append(i)
(c, ans) = (0, 0)
omap1 = {}
for i in ra(n):
	if c < len(arr) and omap[li[i]] > 1 and (li[i] not in omap1):
		if arr[c] > li[i]:
			omap1[li[i]] = 1
			omap[li[i]] -= 1
		else:
			omap[li[i]] -= 1
			li[i] = arr[c]
			ans += 1
			c += 1
	elif omap[li[i]] >= 1 and li[i] in omap1:
		omap[li[i]] -= 1
		li[i] = arr[c]
		ans += 1
		c += 1
P(ans)
P(*li)


n = int(input())
arr = list(map(int, input().split()))
count = [0] * n
p = [False] * n
b = [True] * n
x = []
j = 0
for i in range(n):
	t = arr[i] - 1
	count[t] += 1
	b[t] = False
for i in range(n):
	if b[i]:
		x.append(i + 1)
print(len(x))
for i in range(n):
	t = arr[i]
	if count[t - 1] > 1 and (p[t - 1] or x[j] < t):
		count[t - 1] -= 1
		arr[i] = x[j]
		p[x[j] - 1] = True
		j += 1
	else:
		p[t - 1] = True
print(*arr)


n = int(input())
a = list(map(int, input().split(' ')))
freq = {}
seen = [False for i in range(n + 1)]
ch = 0
de = []
for i in range(n):
	if a[i] not in freq.keys():
		freq[a[i]] = 1
	else:
		freq[a[i]] += 1
		ch += 1
for i in range(n):
	if i + 1 not in freq.keys():
		de.append(i + 1)
index = 0
for i in range(n):
	if freq[a[i]] > 1:
		if seen[a[i]] or de[index] < a[i]:
			freq[a[i]] += -1
			a[i] = de[index]
			index += 1
		else:
			seen[a[i]] = True
sol = ''
for x in a:
	sol += str(x) + ' '
print(str(ch) + '\n' + sol)


n = int(input())
l = list(map(int, input().split()))
L = [0] * 200001
L1 = [0] * 200001
p = 0
k = 0
for i in range(n):
	L[l[i]] += 1
for i in range(1, n + 1):
	if L[i] == 0:
		for j in range(p, n):
			if i < l[j] and L[l[j]] > 1:
				L[l[j]] -= 1
				k = k + 1
				l[j] = i
				break
			if i > l[j] and L[l[j]] > 1 and (L1[l[j]] == 1):
				L[l[j]] -= 1
				k = k + 1
				l[j] = i
				break
			if i > l[j] and L[l[j]] > 1 and (L1[l[j]] != 1):
				L1[l[j]] = 1
		p = j + 1
print(k)
print(*l)


n = int(input()) + 1
t = [0] + list(map(int, input().split()))
s = [0] * n
for j in t:
	s[j] += 1
p = [0] * n
k = 1
for (i, j) in enumerate(t):
	if s[j] > 1:
		while s[k]:
			k += 1
		if j > k or p[j]:
			t[i] = k
			s[j] -= 1
			k += 1
		else:
			p[j] = 1
print(s.count(0))
print(' '.join(map(str, t[1:])))


n = int(input())
a = list(map(lambda x: int(x), input().split()))
from time import time
hashmap = {}
not_there = []
t = time()
for i in range(0, len(a)):
	if a[i] not in hashmap:
		hashmap[a[i]] = 0
	hashmap[a[i]] += 1
for i in range(1, n + 1):
	if i not in hashmap:
		not_there.append(i)
replacements = 0
skipped_already = set()
j = 0
for i in range(0, len(a)):
	if hashmap[a[i]] == 1:
		continue
	if hashmap[a[i]] > 1 and a[i] > not_there[j]:
		hashmap[a[i]] -= 1
		a[i] = not_there[j]
		j += 1
		replacements += 1
	elif hashmap[a[i]] > 1 and a[i] < not_there[j]:
		if a[i] in skipped_already:
			hashmap[a[i]] -= 1
			a[i] = not_there[j]
			j += 1
			replacements += 1
		else:
			skipped_already.add(a[i])
print(replacements)
for i in a:
	print(i, end=' ')


n = int(input())
arr = list(map(int, input().strip().split()))
mp = {}
for i in range(n):
	if arr[i] in mp:
		mp[arr[i]] += 1
	else:
		mp[arr[i]] = 1
ar = []
for i in range(n):
	if i + 1 not in mp:
		ar.append(i + 1)
x = len(ar)
ar = ar[::-1]
fl = 0
dp = {}
for i in range(n):
	if mp[arr[i]] > 1 and len(ar) > 0 and (arr[i] > ar[len(ar) - 1]):
		mp[arr[i]] -= 1
		arr[i] = ar[len(ar) - 1]
		ar.pop()
		mp[arr[i]] = 1
	elif mp[arr[i]] > 1 and arr[i] < ar[len(ar) - 1]:
		if fl == 0:
			fl = 1
			dp[arr[i]] = 1
		else:
			if arr[i] not in dp:
				dp[arr[i]] = 1
				continue
			mp[arr[i]] -= 1
			arr[i] = ar[len(ar) - 1]
			ar.pop()
			mp[arr[i]] = 1
ar = ar[::-1]
for i in range(n - 1, -1, -1):
	if mp[arr[i]] > 1 and len(ar) > 0:
		mp[arr[i]] -= 1
		arr[i] = ar[len(ar) - 1]
		ar.pop()
		mp[arr[i]] = 1
print(x)
print(*arr)


(n, a, v) = (int(input()), list(map(int, input().split())), 0)
(c, ci, f) = ([0] * (n + 1), 1, [False] * (n + 1))
for ai in a:
	c[ai] += 1
for (i, ai) in enumerate(a):
	if c[ai] > 1:
		while c[ci]:
			ci += 1
		if ci < ai or f[ai]:
			(a[i], c[ai], c[ci], v) = (ci, c[ai] - 1, c[ci] + 1, v + 1)
		else:
			f[ai] = True
print(v, ' '.join(map(str, a)), sep='\n')


n = int(input())
a = [int(q) for q in input().split()]
a_counts = [0] * (n + 1)
need = []
for q in a:
	a_counts[q] += 1
for i in range(1, n + 1):
	if a_counts[i] == 0:
		need.append(i)
result = 0
left = set()
current_need_index = 0
for i in range(n):
	temp = a[i]
	if a_counts[a[i]] == 1:
		if a[i] in left:
			a[i] = need[current_need_index]
			result += 1
			current_need_index += 1
	elif a_counts[a[i]] > 1:
		if need[current_need_index] < a[i]:
			a[i] = need[current_need_index]
			result += 1
			current_need_index += 1
		elif need[current_need_index] > a[i] and a[i] in left:
			a[i] = need[current_need_index]
			result += 1
			current_need_index += 1
		a_counts[temp] -= 1
	left.add(a[i])
	if len(need) == 0:
		break
print(result)
print(*a)


n = int(input())
a = [int(x) for x in input().split(' ')]
b = [0] * (n + 1)
arr = []
used = [0] * (n + 1)
for i in range(0, n):
	b[a[i]] += 1
for i in range(1, n + 1):
	if b[i] == 0:
		arr.append(i)
cnt = 0
j = 0
for i in range(0, n):
	if b[a[i]] == 1:
		continue
	if used[a[i]] == 1:
		cnt += 1
		b[a[i]] -= 1
		a[i] = arr[j]
		j += 1
	elif arr[j] < a[i]:
		cnt += 1
		b[a[i]] -= 1
		a[i] = arr[j]
		j += 1
		used[a[i]] = 1
	else:
		used[a[i]] = 1
print(cnt)
for i in range(0, n):
	print(a[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
nums = [False for i in range(200010)]
must = [False for i in range(200010)]
counter = dict()
now_num = 0

def inc():
	global now_num
	now_num += 1
	while nums[now_num - 1]:
		now_num += 1
for el in a:
	if nums[el - 1]:
		counter[el] += 1
	else:
		counter[el] = 1
	nums[el - 1] = True
inc()
ans = []
c = 0
for el in a:
	if counter[el] > 1:
		counter[el] -= 1
		if now_num < el:
			ans.append(now_num)
			c += 1
			inc()
		elif must[el - 1] == False:
			ans.append(el)
			must[el - 1] = True
		else:
			ans.append(now_num)
			c += 1
			inc()
	elif must[el - 1] == False:
		ans.append(el)
	else:
		ans.append(now_num)
		c += 1
		inc()
print(c)
print(' '.join((str(el) for el in ans)))


from collections import Counter

def readints():
	return [int(item) for item in input().strip().split()]

class Solver:

	def main(self):
		n = readints()[0]
		a = readints()
		c = Counter(a)
		skipped = set()
		to_be_added = sorted(set(range(1, n + 1)) - set(c.keys()))
		changes = 0
		for i in range(n):
			if c[a[i]] > 1:
				if a[i] < to_be_added[changes] and a[i] not in skipped:
					skipped.add(a[i])
				else:
					c[a[i]] -= 1
					a[i] = to_be_added[changes]
					changes += 1
		print(changes)
		print(' '.join(map(str, a)))
Solver().main()


import os
import sys
import re
from collections import OrderedDict
if 'PYCHARM' in os.environ:
	sys.stdin = open('in', 'r')
n = int(input())
a = list(map(int, input().split()))
w = [0] * (n + 1)
fr = OrderedDict()
for i in range(1, n + 1):
	fr[i] = None
for x in a:
	if x in fr:
		fr.pop(x)
	w[x] += 1
print(len(fr))
for x in a:
	if w[x] == 1:
		print(x, end=' ')
		continue
	key = None
	for mn in fr:
		key = mn
		break
	if w[x] < 1 or key < x:
		w[x] -= 1
		print(key, end=' ')
		fr.pop(key)
	else:
		w[x] = 0
		print(x, end=' ')


from collections import Counter

def f(a, n):
	cnt = Counter(a)
	l = []
	for i in range(1, n + 1):
		if cnt[i] == 0:
			l.append(i)
	lo = 0
	c = 0
	left = set()
	for i in range(n):
		if cnt[a[i]] > 1:
			if l[lo] < a[i] or a[i] in left:
				cnt[a[i]] -= 1
				a[i] = l[lo]
				lo += 1
				c += 1
			else:
				left.add(a[i])
	print(c)
	print(*a)
n = int(input())
l = list(map(int, input().strip().split()))
f(l, n)


class QueueElem:

	def __init__(self, data):
		self.prev = None
		self.data = data
		self.next = None

class Queue:

	def __init__(self):
		self.first = None
		self.last = None
		self.len = 0

	def __str__(self):
		_r = ''
		if self.empty():
			return '<Empty Queue>'
		else:
			c = self.first
			_r += str(c.data)
			while c.next is not None:
				c = c.next
				_r += str(c.data)
		return _r

	def __len__(self):
		return self.len

	def empty(self):
		return self.len == 0

	def append_left(self, data):
		elem = QueueElem(data)
		if not self.empty():
			elem.next = self.first
			self.first.prev = elem
			self.first = elem
		else:
			self.first = elem
			self.last = elem
		self.len += 1

	def append_right(self, data):
		elem = QueueElem(data)
		if not self.empty():
			elem.prev = self.last
			self.last.next = elem
			self.last = elem
		else:
			self.first = elem
			self.last = elem
		self.len += 1

	def pop_left(self):
		if self.empty():
			return None
		e_ = self.first
		self.first = self.first.next
		if self.first is None:
			self.last = None
		self.len -= 1
		return e_.data

	def seek_left(self):
		if self.empty():
			return None
		return self.first.data

	def pop_right(self):
		if self.empty():
			return None
		e_ = self.last
		self.last = self.last.prev
		if self.last is None:
			self.first = None
		self.len -= 1
		return e_.data

	def seek_right(self):
		if self.empty():
			return None
		return self.last.data
n = int(input())
aa = [int(i) for i in input().split()]
to_replace = {}
should_replace = {}
replace_on_what = Queue()
for i in range(len(aa)):
	a = aa[i]
	if a in to_replace:
		to_replace[a] += 1
	else:
		to_replace[a] = 1
for i in range(len(aa)):
	if i + 1 not in to_replace:
		replace_on_what.append_right(i + 1)
p = 0
for i in range(len(aa)):
	if to_replace[aa[i]] > 1:
		if aa[i] in should_replace:
			p += 1
			to_replace[aa[i]] -= 1
			aa[i] = replace_on_what.pop_left()
		elif aa[i] < replace_on_what.seek_left():
			should_replace[aa[i]] = 1
		else:
			p += 1
			to_replace[aa[i]] -= 1
			aa[i] = replace_on_what.pop_left()
print(p)
print(' '.join(map(str, aa)))


n = int(input())
l = list(map(int, input().split()))
l1 = [0] * (n + 1)
l2 = [0] * (n + 1)
for x in l:
	l1[x] += 1
j = 1
k = 0
for i in range(n):
	while l1[j] != 0:
		j += 1
		if j > n:
			print(k)
			print(*l)
			exit()
	if l1[l[i]] > 1:
		if j < l[i] or l2[l[i]] == 1:
			l1[l[i]] -= 1
			l[i] = j
			j += 1
			k += 1
			if j > n:
				print(k)
				print(*l)
				exit()
		else:
			l2[l[i]] = 1
print(k)
print(*l)


(n, ans, j) = (int(input()), 0, 1)
a = [int(i) for i in input().split()]
(res, c, lft) = ([0] * n, [0] * (n + 1), [0] * (n + 1))
for i in a:
	c[i] += 1
while j <= n and c[j]:
	j += 1
for i in range(len(a)):
	if c[a[i]] > 1:
		if lft[a[i]] or a[i] > j:
			ans += 1
			c[a[i]] -= 1
			res[i] = j
			j += 1
			while j <= n and c[j]:
				j += 1
		else:
			lft[a[i]] = 1
			res[i] = a[i]
	else:
		res[i] = a[i]
print(ans)
print(*res)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
b = dict()
for i in c.keys():
	b[i] = 0
d = list(sorted((Counter(range(1, n + 1)) - c).keys()))
r = n - len(c)
j = 0
print(r)
for i in range(n):
	if j == r:
		break
	if c[a[i]] > 1:
		if d[j] < a[i]:
			c[a[i]] -= 1
			a[i] = d[j]
			j += 1
		elif b[a[i]] != 0:
			c[a[i]] -= 1
			a[i] = d[j]
			j += 1
		else:
			b[a[i]] += 1
print(*a)


from collections import Counter
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 collections import Counter
n = int(input())
arr = list(map(int, input().split()))
ls = [i for i in range(1, n + 1)]
ele = sorted(list(set(ls) - set(arr)))
var = len(ele)
j = 0
s = set()
c = Counter(arr)
for i in range(n):
	c[arr[i]] -= 1
	if j < var:
		if arr[i] in s:
			arr[i] = ele[j]
			j += 1
		elif c[arr[i]] >= 1:
			if ele[j] < arr[i]:
				arr[i] = ele[j]
				j += 1
	else:
		break
	s.add(arr[i])
print(var)
print(*arr)


from sys import stdin, stdout
n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))
aSet = set(a)
aMinus = set(range(1, n + 1)) - aSet
minusList = sorted(list(aMinus), reverse=True)
used = set()
countDict = {x: 0 for x in aSet}
for x in a:
	countDict[x] += 1
finalList = a
for i in range(n):
	x = a[i]
	if x in used:
		finalList[i] = minusList.pop()
	elif countDict[x] == 1:
		continue
	elif x < minusList[-1]:
		used.add(x)
	else:
		countDict[x] -= 1
		finalList[i] = minusList.pop()
print(len(aMinus))
print(' '.join(map(str, finalList)))


import sys
import random
input = sys.stdin.readline

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

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

def main():
	n = int(input())
	a = list(map(int, input().split()))
	isthere = [0] * (n + 1)
	for i in a:
		isthere[i] += 1
	have = []
	for i in range(1, n + 1):
		if not isthere[i]:
			have.append(i)
	j = 0
	c = 0
	for i in range(n):
		if isthere[a[i]] > 1:
			if have[j] < a[i]:
				c += 1
				isthere[a[i]] -= 1
				isthere[have[j]] = 1
				a[i] = have[j]
				j += 1
			else:
				isthere[a[i]] = -1
		elif isthere[a[i]] == -1:
			c += 1
			isthere[have[j]] = 1
			a[i] = have[j]
			j += 1
	print(c)
	print(*a)
	return
main()


n = int(input())
a = list(map(int, input().split()))
A = [0] * (n + 1)
for i in a:
	A[i] += 1
B = []
for i in range(1, n + 1):
	if A[i] == 0:
		B.append(i)
k = 0
l = len(B)
for i in range(0, n):
	if k == l:
		break
	if A[a[i]] == -1:
		a[i] = B[k]
		k += 1
	if A[a[i]] > 1:
		if a[i] > B[k]:
			A[a[i]] -= 1
			a[i] = B[k]
			k += 1
		elif a[i] < B[k]:
			A[a[i]] = -1
	if k == l:
		break
print(l)
for i in a:
	print(i, end=' ')


import sys, os, io
from sys import stdin
from types import GeneratorType
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

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

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	c = dict(Counter(l))
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = ii()
	l = li()
	d = defaultdict(lambda : 0)
	for i in l:
		d[i] += 1
	s = []
	for i in range(1, n + 1):
		if d[i] == 0:
			s.append(i)
	index = []
	ss = 0
	for i in range(n):
		if d[l[i]] > 1:
			index.append(i)
	for i in d.keys():
		if d[i] > 1:
			ss += 1
	sptr = 0
	vis = defaultdict(lambda : 0)
	for i in range(n):
		if sptr == len(s):
			break
		if d[l[i]] == 1:
			continue
		if l[i] > s[sptr]:
			d[l[i]] -= 1
			l[i] = s[sptr]
			sptr += 1
		elif vis[l[i]] == 1:
			d[l[i]] -= 1
			l[i] = s[sptr]
			sptr += 1
		else:
			vis[l[i]] = 1
	print(len(s))
	print(*l)
t = 1
for _ in range(t):
	solve()