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: interview

Starter code:

Solutions:
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():
    nonlocal 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()
        else:
            if must[el - 1] == False:
                ans.append(el)
                must[el - 1] = True
            else:
                ans.append(now_num)
                c += 1
                inc()
    else:
        if 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))


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



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


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]
                # left location, dupe indexs, if already located original

    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
    #answer = 0
    for index in dupeindex:

        if misslen <= misindex:
            break

        elif dupeindexindv[nums[index]][0] == 1 and not dupeindexindv[nums[index]][2]:
            # one spot left but original not located yet.
            # locate original.
            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]:
                # num is smaller or original is already located.
                # locate missing number.
                dupeindexindv[nums[index]][0] -= 1
                nums[index] = missing[misindex]
                misindex += 1
                #answer += 1

            else: # locate original
                dupeindexindv[nums[index]][0] -= 1
                dupeindexindv[nums[index]][2] = True

    print(misslen)
    for num in nums:
        print(num+1, end = " ")

solve(False)


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):
	#print a
	if a[air[x]] > 1:
		if air[x] > st[-1]:
			a[air[x]] -= 1
			air[x] = st[-1]
			st.pop()
			cnt += 1
 
		else:
			if 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())
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')


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




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 list(d.items()):
        s.extend(v)
        c[k] = len(v)
    s.sort()
    killed = set()
    ava = deque(sorted(frozenset(list(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()



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()) + 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:])))

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


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)
    


"""http://codeforces.com/problemset/problem/864/D"""
# 17:54
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())
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)
        
        



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




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 list(freq.keys()):
        freq[a[i]] = 1
    else:
        freq[a[i]] += 1
        ch += 1

for i in range(n):
    if i+1 not in list(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 )



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
    else:
      if b[a[i]]!=0:
        c[a[i]]-=1
        a[i]=d[j]
        j+=1
      else:
        b[a[i]]+=1
print(*a)

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):  # 1 to 26
        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)))


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