description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
from sys import maxsize, stdin, stdout def solve(): pass test = 1 for t in range(0, test): n = int(input()) a = [int(x) for x in input().split()] c = set(a) avail = [] for i in range(10 * n): if not i in c: avail.append(i) b = [] temp = a[0] j = 0 m = a[0] for i in range(n): if temp != a[i]: if m + 1 < a[i] and temp < m: break if temp == m + 1 and a[i] > temp + 1: break b.append(temp) m = max(m, temp) temp, z = a[i], i else: z = avail[j] b.append(z) m = z j += 1 if len(b) == n: for el in b: print(el, end=" ") else: print(-1)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) arr = list(map(int, input().split())) used = [(0) for i in range(10**6 + 1)] b = [(-1) for i in range(n)] used[arr[0]] = 1 for i in range(1, n): if arr[i] > arr[i - 1]: used[arr[i]] = 1 b[i] = arr[i - 1] m = 0 for i in range(n): while used[m] != 0: m += 1 if b[i] == -1: b[i] = m used[m] = 1 print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def get_not_elements(a: list): elements = set(a) max_element = a[-1] + 2 not_elements = [] for i in range(0, max_element): if not i in elements: not_elements.append(i) not_elements.reverse() return not_elements def is_valid(a: list): for i in range(len(a)): if a[i] - 1 > i: return False return True def generate_array(a: list): stack_ = get_not_elements(a) b = [(-1) for i in range(len(a))] val = a[0] for i in range(1, len(a)): if a[i] != val: b[i] = val val = a[i] if len(stack_) > 0: val = stack_.pop() else: val = a[0] for i in range(len(a)): if b[i] == -1: b[i] = val if len(stack_) > 0: val = stack_.pop() return b size = int(input()) array = [int(i) for i in input().split()] if not is_valid(array): print(-1) else: b = generate_array(array) b = " ".join([str(i) for i in b]) print(b)
FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys input = sys.stdin.buffer.readline n = int(input()) a = [int(c) for c in input().split()] b = [(-1) for i in range(n)] for i in range(1, n): if a[i] != a[i - 1]: b[i] = a[i - 1] j = 0 s = set(a) for i in range(n): if b[i] == -1: while j in s: j += 1 b[i] = j j += 1 print(" ".join([str(c) for c in b]))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) ans = [(-1) for _ in range(n)] mex = 0 ind = 0 for i in range(n): if mex < a[i]: for j in range(mex + 1, a[i]): while ind < i and ans[ind] != -1: ind += 1 if ind == i: print(-1) exit() ans[ind] = j ans[i] = mex mex = a[i] for i in range(len(ans)): if ans[i] == -1: print(1000000, end=" ") else: print(ans[i], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys n = int(sys.stdin.readline().strip()) a = list(map(int, sys.stdin.readline().strip().split())) v = True for i in range(0, n): if a[i] > i + 1: v = False if i > 0: if a[i] < a[i - 1]: v = False if v == False: print(-1) else: c = [] i = 0 j = 0 while i < n: if a[i] == j: i = i + 1 j = j + 1 elif j < a[i]: c.append(j) j = j + 1 else: i = i + 1 c = c + [(a[n - 1] + 1) for i in range(0, n)] j = 0 b = [] for i in range(0, n): if i > 0: if a[i - 1] < a[i]: b.append(a[i - 1]) else: b.append(c[j]) j = j + 1 else: b.append(c[j]) j = j + 1 print(" ".join(list(map(str, b))))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) l = list(map(int, input().split())) r = l[-1] ans = [(0) for i in range(n)] d = set() for i in range(r): d.add(i) p = list(d.difference(l)) ans[0] = r + 1 if l[0] > 1: print(-1) exit() for i in range(1, n): if l[i] - i > 1: print(-1) exit() if l[i] != l[i - 1]: ans[i] = l[i - 1] else: ans[i] = None q = {} p.sort(reverse=True) try: ans[0] = p.pop() except: ans[0] = r + 1 q[ans[0]] = 1 for i in range(1, n): if ans[i] == None: try: ans[i] = p.pop() except: ans[i] = r + 1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NONE ASSIGN VAR DICT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def solution(a): b = [-1] * len(a) d = {} for i in range(1, len(a)): if a[i] != a[i - 1]: b[i] = a[i - 1] d[b[i]] = 1 d[a[n - 1]] = 1 m = 0 for i in range(0, len(a)): while d.get(m, 0): m = m + 1 if b[i] == -1: b[i] = m d[m] = 1 return b n = int(input()) a = [int(x) for x in input().split()] print(*solution(a))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) A = list(map(int, input().split())) B = [(0) for i in range(2 * n + 1)] for i in range(n): B[A[i]] = 1 C = [] for i in range(len(B)): if B[i] == 0: C.append(i) ans = [C[0]] j = 1 mv = C[0] flag = 0 for i in range(1, n): if A[i] == A[i - 1]: ans.append(C[j]) j = j + 1 else: ans.append(A[i - 1]) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ def main(): n = int(input()) a = list(map(int, input().split())) b = [1000000] * n p = 0 st = [] for i, x in enumerate(a): st.append(i) if p < x: while st and p < x: b[st.pop()] = p p += 1 print(" ".join(map(str, b))) main()
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR WHILE VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def main(): n = int(input()) lst = list(map(int, input().split())) reserve = set() if lst[0] > 1: print(-1) return for i in range(0, n): if lst[i] > i + 1: print(-1) return reserve.add(lst[i]) can_use = [] cur = lst[0] for i in range(0, n + 1): if not i in reserve: can_use.append(i) can_use.reverse() used = [] for i in range(0, n): if lst[i] == cur: if len(can_use) == 0: print(-1) return used.append(can_use.pop()) else: if len(can_use) != 0 and can_use[-1] < cur: print(-1) return used.append(cur) cur = lst[i] line = "" for i in used: line += str(i) + " " print(line) t = 1 for i in range(t): main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) arr = [int(x) for x in input().split()] end = arr[-1] stack = [] setarr = set(arr) for x in range(end): if x not in setarr: stack.append(x) stack.reverse() soln = [] for i in range(n): if len(stack) == 0: soln.append(end + 1) else: soln.append(stack.pop()) if i < n - 1 and arr[i + 1] > arr[i]: stack.append(arr[i]) print(" ".join([str(x) for x in soln]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) b = [False] * 200000 ans = [] for i in a: b[i] = True for i in range(200000): if not b[i]: ans.append(i) print(ans[0], end=" ") t = 1 for i in range(1, n): if a[i] != a[i - 1]: print(a[i - 1], end=" ") else: print(ans[t], end=" ") t += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
from sys import stdin t = 1 for _ in range(t): n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) flg = True res = list() places = list() if a[0] not in (0, 1): flg = False p = a[0] cur = 0 if p: res.append(0) cur += 1 for i in range(1, n): if a[i] > i + 1: flg = False break if a[i] != p: for j in range(p + 1, a[i]): if cur >= i: if not places: flg = False break x = places.pop() res[x] = j else: res.append(j) cur += 1 while cur < i: res.append(1000000) places.append(cur) cur += 1 res.append(p) cur += 1 p = a[i] while cur < n: res.append(1000000) cur += 1 if flg: print(" ".join([str(x) for x in res])) else: print(-1)
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) l = [int(x) for x in input().split()] if l[0] > 1 or l[-1] > n: print(-1) else: flag = 0 dup = 0 for i in range(n): if l[i] - i > 1: flag = 1 break if flag == 1: print(-1) else: s1 = set(l) s2 = set([int(x) for x in range(0, n + 2)]) s3 = s2.difference(s1) l1 = list(s3) l1.sort() ans = [] if l[0] == 0: ans.append(l1.pop(0)) else: l1.pop(0) ans.append(0) prev = l[0] for i in range(1, n): if l[i] == prev: ans.append(l1.pop(0)) else: ans.append(prev) prev = l[i] print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def main(): test = 1 for _ in range(test): n = int(input()) ara = [int(num) for num in input().split()] mark = [(True) for _ in range(n + 1)] for num in ara: mark[num] = False take_from = [] for index in range(n + 1): if mark[index]: take_from.append(index) ans = [] ans.append(take_from[0]) take_at = 1 take_size = len(take_from) for index in range(1, n): if ara[index] != ara[index - 1]: ans.append(ara[index - 1]) elif take_at < take_size: ans.append(take_from[take_at]) take_at += 1 else: ans.append(n + 1) ans = " ".join(map(str, ans)) print(ans) main()
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) sp = list(range(n + 1)) prd = -1 b = [] a = [] for i in input().split(): i = int(i) if i != prd: sp[i] = -1 prd = i b += [i] pr, k = 1, 0 while pr: if sp[k] != -1: a += [sp[k]] k += 1 pr = 0 else: k += 1 for i in range(1, n): if b[i - 1] != b[i]: a += [b[i - 1]] else: pr = 1 while pr: if sp[k] != -1: a += [sp[k]] k += 1 pr = 0 else: k += 1 print(*a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR IF VAR VAR NUMBER VAR LIST VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF VAR VAR NUMBER VAR LIST VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
v = [(0) for i in range(1000006)] n = int(input()) a = [0] a += list(map(int, input().split())) flag = 1 for i in range(1, n + 1): if a[i] > i: flag = 0 break v[a[i]] = 1 if flag == 0: print(-1) else: b = [(-1) for i in range(n + 1)] for i in range(2, n + 1): if a[i] != a[i - 1]: b[i] = a[i - 1] v[a[i - 1]] = 1 nv = [] for i in range(1000006): if v[i] == 0: nv.append(i) j = 0 for i in range(1, n + 1): if b[i] == -1: b[i] = nv[j] j += 1 for i in range(1, n + 1): print(b[i], end=" ")
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) data = list(map(int, input().split())) no = False for i in range(n): if i + 1 < data[i]: no = True my_set = set() if no: print(-1) else: for x in data: my_set.add(x) count = 0 while count in my_set: count += 1 print(count, end=" ") my_set.add(count) for i in range(1, n): if data[i] != data[i - 1]: print(data[i - 1], end=" ") continue while count in my_set: count += 1 print(count, end=" ") my_set.add(count) print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def main(): n = int(input()) a = list(map(int, input().split())) ans = [n + 1] * n pred = 0 slots = [] for i, el in enumerate(a): if el > pred: nums = list(range(pred + 1, el)) for j in nums: if not bool(slots): print(-1) return ans[slots.pop(0)] = j ans[i] = pred else: slots.append(i) pred = el print(*ans) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def main(): n = int(input()) A = list(map(int, input().split())) B = [-1] * n N = 10**6 now = N TB = [True] * N if A[0] > 0: B[0] = 0 TB[0] = False for i in range(1, n): a = A[i] ab = A[i - 1] if ab < a: if TB[ab]: B[i] = ab TB[ab] = False TB[A[-1]] = False indexb = 0 for i in range(n): if B[i] != -1: continue for j in range(indexb, N): if TB[j]: TB[j] = False indexb = j + 1 B[i] = j break indexa = 0 TA = [True] * N for i in range(n): TA[B[i]] = False for j in range(indexa, N): if TA[j]: if A[i] != j: print(-1) return indexa = j break print(" ".join(map(str, B))) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) alphabet = list() alphabet.append(a[0]) for i in range(1, n): if a[i] > i + 1: print(-1) exit() if a[i] != a[i - 1]: alphabet.append(a[i]) point = 0 if alphabet[point] == 0: point += 1 if len(alphabet) == 1: cur = 2 * n if a[0] == 1: print(0, end=" ") else: print(cur, end=" ") for i in range(n - 1): print(cur, end=" ") print() exit() curr = alphabet[point] - 1 mina = 0 for i in range(n): if a[i] == mina: if curr > mina and (point == 0 or curr != alphabet[point - 1]): print(curr, end=" ") curr -= 1 else: point += 1 while point < len(alphabet) and alphabet[point] - 1 == alphabet[point - 1]: point += 1 if point == len(alphabet): curr = 2 * n else: curr = alphabet[point] - 1 print(curr, end=" ") curr -= 1 else: print(mina, end=" ") mina = a[i]
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) l1 = list(map(int, input().split())) s = set(l1) s4 = list(s) l = len(s4) i = 0 m = 0 k = 0 l2 = [-1] * n while i != n - 1: if l2[i] == -1: while k < l and m == s4[k]: m += 1 k += 1 l2[i] = m m += 1 if l1[i + 1] > l1[i]: l2[i + 1] = l1[i] i += 1 if l2[i] == -1: while k < l and m == s4[k]: m += 1 k += 1 l2[i] = m print(*l2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) s1 = set(a) s2 = set() i = 0 c = 0 x = 0 lst = [] f = 1 while i < n: miss = a[i] if c == miss and x not in s1 and x not in s2: lst.append(x) s2.add(x) x += 1 i += 1 elif c == miss and (x in s1 or x in s2): x += 1 elif c != miss: lst.append(c) s2.add(c) i += 1 while c in s2: c += 1 if c != miss: f = 0 break if f == 1: print(*lst) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input().strip()) l = [int(a) for a in input().strip().split()] ans = [0] * n done = {} index = {} for i in range(n): done[l[i]] = 1 for i in range(1, n): if l[i] != l[i - 1]: ans[i] = l[i - 1] index[i] = 1 j = 0 for i in range(n): if i in index.keys(): continue while j in done.keys(): j += 1 ans[i] = j j += 1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) l = [0] * (n + 2) for elem in a: l[elem] = 1 not_present = [] for i in range(n + 2): if l[i] == 0: not_present.append(i) j = 0 b = [] for i in range(n): if i == 0: b.append(not_present[j]) j += 1 elif a[i] != a[i - 1]: b.append(a[i - 1]) else: b.append(not_present[j]) j += 1 print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys input = lambda: sys.stdin.readline().strip("\r\n") n = int(input()) a = list(map(int, input().split())) s = set(a) ans = [] ele = 0 for i in range(n): if i > 0 and a[i] != a[i - 1]: ans.append(a[i - 1]) continue while ele in s: ele += 1 ans.append(ele) ele += 1 print(*ans)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
from sys import setrecursionlimit, stdin, stdout for _ in range(1): n = int(input()) a = [int(i) for i in input().split()] f = True ans = [-1] * n ok = [False] * (n + 1) for i in range(n): if a[i] > i + 1 or a[i] > a[min(i + 1, n - 1)]: f = False break ok[a[i]] = True if not f: print(-1) continue nums = [] curi = 0 for i in range(n + 1): if not ok[i]: nums.append(i) for i in range(n - 1): if a[i] != a[i + 1]: ans[i + 1] = a[i] for i in range(n): if ans[i] == -1: ans[i] = nums[curi] curi += 1 print(*ans)
FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) czy = 0 T, A, N, P = [0], [0], [0], [0] T += map(int, input().split()) for i in range(1, n + 1): A.append(-1) if T[i] > i: czy = 1 N.append(i + 1) P.append(i - 1) N.append(0) P.append(0) if czy: print(-1) exit() for i in range(1, n + 1): x = T[i] - T[i - 1] ile = T[i - 1] s = i for j in range(1, x + 1): A[s] = ile ile += 1 P[N[s]] = P[s] N[P[s]] = N[s] s = P[s] for i in range(1, n + 1): if A[i] == -1: A[i] = 1000000 s = "" for i in range(1, n + 1): s += str(A[i]) + " " print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) left = [] i = 0 for x in range(a[n - 1] + 1): if a[i] > x: left.append(x) elif a[i] <= x: while i < n and a[i] <= x: i += 1 left.append(a[n - 1] + 1) if a[0] != 0 and a[0] != 1: print("-1") else: b = [left[0]] j = 1 k = 1 while j < n: if a[j] != a[j - 1]: b.append(a[j - 1]) j += 1 elif k < len(left): b.append(left[k]) k += 1 j += 1 else: b.append(b[j - 1]) j += 1 for i in range(n): print(b[i], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) ans = [-1] * n for index in range(1, n): if a[index] != a[index - 1]: ans[index] = a[index - 1] not_to_be_included = set(a) init = 0 for index in range(n): if ans[index] == -1: while init in not_to_be_included: init += 1 ans[index] = init init += 1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) b = [-1] * (n + 1) a.append(-1) f = 0 d = set() for i in range(1, n + 1): if a[i - 1] != a[i]: b[i] = a[i - 1] d.add(b[i]) d = list(set(list(range(n + 1))) - d) c = 0 for i in range(n + 1): if b[i] == -1: b[i] = d[c] c += 1 print(*b[:-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def main(): n = int(input()) a = list(map(int, input().split())) b = [] need = a[-1] - 1 done = set() million = 10**6 for i in range(n - 1, 0, -1): if a[i] == a[i - 1]: while True: if need in done: need -= 1 elif need < a[i]: b.append(million) break else: b.append(need) done.add(need) break else: b.append(a[i - 1]) done.add(a[i - 1]) if a[0] == 0: while True: if need in done: need -= 1 elif need < a[0]: b.append(million) break else: b.append(need) done.add(need) break else: b.append(0) b.reverse() print(*b) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER WHILE NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER WHILE NUMBER IF VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) b = [(-1) for k in range(n)] existe = [(False) for k in range(100005)] for k in range(n): if a[k] != a[k - 1] and k != 0: b[k] = a[k - 1] existe[b[k]] = True existe[a[n - 1]] = 1 m = 0 for k in range(n): while existe[m]: m += 1 if b[k] == -1: b[k] = m existe[m] = True print(b[k], end=" ")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def solve(a): n = len(a) doable = True for i in range(n): if a[i] > i + 1: doable = False break if doable: renegades = [] for i in range(1, n): for el in range(a[i - 1] + 1, a[i]): renegades.append(el) renegades.reverse() ans = [(0) for i in range(n)] if a[0] == 1: ans[0] = 0 elif len(renegades) > 0: ans[0] = renegades.pop() else: ans[0] = n + 2 for i in range(1, n): if a[i] == a[i - 1]: if len(renegades) > 0: ans[i] = renegades.pop() else: ans[i] = n + 2 else: ans[i] = a[i - 1] print(" ".join([str(i) for i in ans])) else: print(-1) n = int(input()) a = [int(i) for i in input().split()] solve(a)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) l = list(map(int, input().split())) m = l[-1] + 1 d = {} s = set(l) for i in l: if i in d: d[i] = d[i] + 1 else: d[i] = 1 o = [] for i in range(0, m): if i in s: pass else: o.append(i) o = o[::-1] p = [] for i in l: if len(o) == 0: p.append(m) m = m + 1 d[i] = d[i] - 1 if d[i] == 0: o.append(i) else: x = o.pop() p.append(x) d[i] = d[i] - 1 if d[i] == 0: o.append(i) print(*p)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = [int(f) for f in input().split()] m = set(a) b = [] p = set(f for f in range(0, a[n - 1] + 1)) p = p - m p = list(p) g = 0 l = 0 cur = 0 if cur < len(p): fl = True else: fl = False for i in range(n): if i == 0: if a[i] == 0: if fl: b.append(p[cur]) cur += 1 else: b.append(a[n - 1] + 10) else: b.append(0) if p[cur] == 0: cur += 1 if cur == len(p): fl = False else: if a[i] == a[i - 1]: if fl: b.append(p[cur]) cur += 1 else: b.append(a[n - 1] + 10) else: b.append(a[i - 1]) if cur == len(p): fl = False for el in b: print(el, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) g = [] c = a[0] for u in range(c): g.append(u) for i in range(1, n): if a[i] == a[i - 1]: pass else: for u in range(a[i - 1] + 1, a[i]): g.append(u) if len(g) == 0: g.append(a[-1] + 1) g += [g[0]] * n b = [g[0]] res = True j = 1 for i in range(1, n): if a[i] > a[i - 1]: b.append(a[i - 1]) else: b.append(g[j]) j += 1 for i in range(n): print(b[i], end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP LIST VAR NUMBER VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys input = sys.stdin.readline def f(i, j): for x in range(i + 1, j): s.append(x) n = int(input()) a = list(map(int, input().split())) b = [10**6] * n s = [] ind = [] if a[0] == 1: b[0] = 0 else: ind.append(0) for i in range(1, n): if a[i] > a[i - 1]: b[i] = a[i - 1] f(a[i - 1], a[i]) else: ind.append(i) ind = ind[::-1] for x in s: b[ind.pop()] = x print(*b)
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) b = [-1] * n d = set(a) done = {} m = 0 while m in d: m += 1 b[0] = m done[b[0]] = 1 for i in range(1, n): if a[i] == a[i - 1]: curr = m + 1 while curr in d: curr += 1 b[i] = curr done[b[i]] = 1 m = max(m, b[i]) else: if a[i - 1] not in done: b[i] = a[i - 1] else: curr = m + 1 while curr in d: curr += 1 b[i] = curr done[b[i]] = 1 m = max(m, b[i]) print(*b)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) val = set([i for i in range(a[-1])]) b = [-1] * n for i in range(1, n): if a[i] != a[i - 1]: b[i] = a[i - 1] val.remove(a[i - 1]) val = list(val) ind = 0 for i in range(n): if b[i] == -1: if ind >= len(val): b[i] = 1000000 else: b[i] = val[ind] ind += 1 print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) list1 = list(map(int, input().split())) list2 = list() visited = list() for i in range(n): list2.append(-1) for i in range(100001): visited.append(-1) f = 0 for i in range(n): if list1[i] > i + 1: f = 1 break visited[list1[i]] = 1 not_v = list() for i in range(100001): if visited[i] == -1: not_v.append(i) for i in range(1, n): if list1[i] != list1[i - 1]: list2[i] = list1[i - 1] j = 0 for i in range(n): if list2[i] == -1: list2[i] = not_v[j] j += 1 print(*list2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def solve(): n = int(input()) arr = list(map(int, input().split(" "))) index = n - 1 unique = set() while index >= 0: if arr[index] > index + 1: print(-1) return unique.add(arr[index]) index -= 1 ans = [] if arr[0] == 1: ans.append(0) unique.add(0) else: current = 0 while current in unique: current += 1 ans.append(current) unique.add(current) queue = [i for i in range(n + 1) if i not in unique] prev = arr[0] l = 1 while l < n: if arr[l] != prev and arr[l - 1] in unique: unique.remove(arr[l - 1]) lowest = arr[l - 1] else: lowest = queue.pop(0) ans.append(lowest) unique.add(lowest) prev = arr[l] l += 1 print(*ans) solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def lcm(a, b): return a * b // gcd(a, b) def inin(): return int(input()) def inar(): return list(map(int, input().split())) def ar(element, size): return [element for i in range(size)] def yes(): print("Yes") def no(): print("No") Testcase = 1 for _ in range(Testcase): n = inin() a = inar() i = 1 s = set(a[:]) d = [(-1) for i in range(n)] while i < n: if a[i] != a[i - 1]: d[i] = a[i - 1] i += 1 a = set([i for i in range(0, 100009)]) a = a.difference(s) for i in range(n): if d[i] == -1: d[i] = a.pop() print(*d)
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) l = list(map(int, input().strip().split())) b = [(-1) for a in range(0, n)] for i in range(0, n - 1): if l[i] != l[i + 1]: b[i + 1] = l[i] t = set([j for j in range(0, 10**6 + 1)]) - set(l) t = list(t) t.sort() c = 0 for i in range(0, n): if b[i] == -1: b[i] = t[c] c += 1 print(" ".join(str(e) for e in b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) l = list(map(int, input().split())) s = set(l) chk, mex, nxt, last = True, l[0], 0, -1 final = [] for i in range(n): if l[i] > i + 1: chk = False break elif l[i] == last or last == -1: while nxt in s: nxt += 1 last = l[i] final.append(nxt) nxt += 1 else: s.remove(last) final.append(mex) mex = l[i] nxt = max(nxt, mex) last = l[i] print(*(final if chk else -1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) res = [-1] * N if a[0]: res[0] = 0 for i in range(N - 1): if a[i + 1] > a[i]: res[i + 1] = a[i] s = sorted(set([x for x in range(N + 1)]) - set(a) - set(res), reverse=True) for i in range(N): if res[i] == -1: res[i] = s.pop() print(*res)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) l = list(map(int, input().split())) d = {} l1 = [0] * (10**5 + 1) cnt = 0 l3 = [] for i in l: if i not in d: d[i] = 0 for i in range(len(l1)): if i in d: continue else: l1[i] = 1 l2 = [] for i in range(len(l1)): if l1[i] != 0: l2.append(i) else: l3.append(i) j, z = 0, 0 l4 = [] for i in range(len(l)): if l[i] > l3[j]: l4.append(l3[j]) j += 1 else: l4.append(l2[z]) z += 1 print(*l4)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) value = n used = set() b = [-1] * n for i in range(n - 1, -1, -1): used.add(a[i]) if i > 0 and a[i] > a[i - 1]: b[i] = a[i - 1] else: while value >= 0 and value in used: value -= 1 if value >= 0: b[i] = value if value > 0: value -= 1 else: b[i] = n used = [0] * (n + 1) mex = 0 for i in range(n): used[b[i]] = 1 while used[mex]: mex += 1 if a[i] != mex: print(-1) break else: print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) lis = list(map(int, input().split())) maxi = lis[-1] k = n - 1 flag = 1 ans = [] if maxi > n: flag = -1 if flag == -1: print(-1) else: xtra = 0 points = [] if lis[0] == 0: ans.append(maxi + 1) xtra = xtra + 1 points.append(0) elif lis[0] == 1: ans.append(0) else: flag = -1 if flag != -1: for i in range(1, n): l = lis[i] if l == lis[i - 1]: ans.append(maxi + 1) xtra = xtra + 1 points.append(i) elif lis[i] == lis[i - 1] + 1: ans.append(lis[i - 1]) else: dif = lis[i] - lis[i - 1] - 1 if dif > xtra: flag = -1 break else: for j in range(lis[i - 1] + 1, lis[i]): ans[points[0]] = j points.pop(0) xtra = xtra - 1 ans.append(lis[i - 1]) if flag == -1: print(-1) else: print(*ans, sep=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys input = sys.stdin.buffer.readline n = int(input()) a = list(map(int, input().split())) INF = 10**6 - 1 ans = [INF] * n l = 0 if a[0] == 1: ans[0] = 0 for i in range(n - 1): if i + 1 < a[i]: print(-1) exit() if a[i] < a[i + 1]: if i + 2 < a[i + 1]: print(-1) exit() ans[i + 1] = a[i] min_num = a[i] + 1 max_num = a[i + 1] - 1 while min_num <= max_num: if ans[l] == INF: ans[l] = min_num min_num += 1 l += 1 print(*ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
N = int(input()) A = list(map(int, input().split())) mp = {} for i in range(N): mp[A[i]] = i curr = 0 B = [] for i in range(N): if i > 0 and A[i] != A[i - 1]: B.append(A[i - 1]) curr = max(A[i - 1] + 1, curr) else: while 1 == 1: if curr in mp and mp[curr] >= i: curr += 1 else: break B.append(curr) curr += 1 for b in B: print(b, end=" ") print("")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR WHILE NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) l = [0] * 1000001 for i in a: l[i] = 1 s, np, f, j, k = [], [], [], 0, 0 for i in range(0, 1000001): if l[i] == 0: np.append(i) w = len(np) fg = 0 for i in range(0, n): if a[i] > i + 1: fg = 1 break if fg == 1: print(-1) else: for i in range(0, n): b = len(s) if j < b and k < w: if s[j] < np[k] and s[j] != a[i]: f.append(s[j]) j += 1 else: f.append(np[k]) k += 1 elif k >= w and j < b: if s[j] == a[i]: fg = 1 break else: f.append(s[j]) j += 1 elif k < w and j >= b: f.append(np[k]) k += 1 else: fg = 1 break if b != 0: if s[b - 1] != a[i]: s.append(a[i]) else: s.append(a[i]) if fg == 1: print(-1) else: print(" ".join(str(a) for a in f))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR LIST LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) arr = [x for x in map(int, input().split(" "))] b = [] last_seen = dict() no_use = set() for i, v in enumerate(arr): last_seen[v] = i no_use.add(v) to_use = [x for x in range(n, -1, -1) if x not in no_use] for i, v in enumerate(arr): b.append(to_use.pop()) if last_seen[v] == i: to_use.append(v) for v in b: print(v, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) arr = list(map(int, input().split())) flag = 0 vis = [0] * (10**6 + 1) for i in range(n): if arr[i] > i + 1: flag = 1 vis[arr[i]] = 1 if flag == 1: print(-1) quit() b = [-1] * n for i in range(1, n): if arr[i - 1] != arr[i]: b[i] = arr[i - 1] not_vis = [] for i in range(10**6 + 1): if vis[i] == 0: not_vis.append(i) j = 0 for i in range(n): if b[i] == -1: b[i] = not_vis[j] j += 1 print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) A = list(map(int, input().split())) z = True for i in range(len(A)): if A[i] > i + 1: z = False break if not z: print(-1) else: C = [] B = [-10] for i in range(1, len(A)): if A[i] != A[i - 1]: B.append(A[i - 1]) C.append(A[i - 1]) else: B.append(-10) C.append(A[-1]) C.append(10**18) q = 0 X = 0 for i in range(len(B)): if B[i] == -10: while X == C[q]: q += 1 X += 1 B[i] = X X += 1 print(*B)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
from sys import stdin input = stdin.buffer.readline n = int(input()) (*a,) = map(int, input().split()) b = [-1] * n vis = [0] * (n + 1) x = y = 0 if a[0]: b[0] = 0 vis[0] = 1 for i in range(1, n): if a[i] != a[i - 1]: b[i] = a[i - 1] vis[a[i - 1]] = 1 while 1: while vis[y]: y += 1 if y >= a[i]: break while b[x] != -1: x += 1 b[x] = y vis[y] = 1 x += 1 x = 100005 for i in range(n): if b[i] == -1: b[i] = x x += 1 print(*b)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER WHILE NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) m = set(a) u = [i for i in range(n + 1) if i not in m] if a[0] not in [0, 1]: print(-1) exit() b = [u.pop(0)] for i in range(1, n): if a[i] != a[i - 1]: b.append(a[i - 1]) else: b.append(u.pop(0)) print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER LIST NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys sys.setrecursionlimit(2 * 10**5) n = int(input()) l = [int(i) for i in input().split()] check = [0] * (2 * 10**5) for i in l: check[i] = 1 ans = [] c = False for i in range(n): if check[i] == 0: now = i c = True break if not c: now = max(l) + 1 M = now b = l[0] for i in range(n): if b == l[i]: while now < n + 2 and check[now]: now += 1 ans.append(now) check[now] = 1 M = max(M, now) else: if now < b and check[b - 1]: if b - 1 == now: M = max(M, b) now = b ans.append(b) b = l[i] if M < l[i] - 1: print(-1) exit() print(*ans)
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys 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 = II() a = LI() if a[0] not in [0, 1] or a != sorted(a): print(-1) else: boo = True for i in range(n): if a[i] > i + 1: boo = False break if boo == False: print(-1) else: b = [-1] * n arr = list(range(n)) if a[-1] < n: arr = list(range(n + 1)) arr.pop(a[-1]) d = {} for i in arr: d[i] = 0 for i in range(n - 1, 0, -1): if a[i] > a[i - 1]: b[i] = a[i - 1] d[a[i - 1]] = 1 temp = 0 for i in range(n): if b[i] == -1: while d[arr[temp]] == 1: temp += 1 b[i] = arr[temp] temp += 1 print(*b)
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def solve(n, a): b = [-1] * n mex = 0 s = [] flag = 0 for i in range(n): s.append(i) if a[i] + len(s) < mex: flag = 1 print(-1) return while a[i] > mex: ind = s.pop() b[ind] = mex mex += 1 random = 199967 for i in range(n): if b[i] == -1: b[i] = random random += 1 print(" ".join(map(str, b))) n = int(input()) a = list(map(int, input().split())) solve(n, a)
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN WHILE VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def solve(n, a): fail = [-1] b = [None] * n s = {} t = [] m = max(a) + 1 for i in range(n): if a[i] > i + 1: return fail if i == 0: if a[i] == 1: b[i] = 0 s[0] = 1 continue if a[i] > a[i - 1]: b[i] = a[i - 1] s[b[i]] = 1 if i == n - 1: s[a[i]] = 1 s = [i for i in range(100001) if i not in s] for i in range(n): if b[i] is not None: for j in range(i - 1, -1, -1): if len(s) == 0 or b[j] is not None: break b[j] = s.pop(0) for i in range(n): if b[i] is None: b[i] = m return b n = int(input().strip()) a = list(map(int, input().strip().split())) print(" ".join(map(str, solve(n, a))))
FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER RETURN VAR IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys LI = lambda: list(map(int, sys.stdin.readline().strip("\n").split())) MI = lambda: map(int, sys.stdin.readline().strip("\n").split()) SI = lambda: sys.stdin.readline().strip("\n") II = lambda: int(sys.stdin.readline().strip("\n")) n = II() a = LI() b, s = [-1] * n, set([a[-1]]) for i in range(1, n): if a[i] != a[i - 1]: b[i] = a[i - 1] s.add(b[i]) v = 0 for i in range(n): while v in s: v += 1 if b[i] == -1: b[i] = v s.add(v) print(*b)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR FUNC_CALL VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) a1 = sorted(a) if a1 != a: print(-1) else: m = max(a) - 1 mm = m + 10 ans = [-1] * n has = [0] * (n + 10) for i in range(n - 1, -1, -1): has[a[i]] = 1 if a[i] > i + 1: print(-1) exit() elif i > 0: if a[i - 1] != a[i]: ans[i] = a[i - 1] c = 0 for i in range(n): if ans[i] != -1: continue while has[c]: c += 1 ans[i] = c has[c] = 1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) l = list(map(int, input().split())) ans = [] neg = [] till = -1 for i in range(n): if till == l[i] - 1: ans.append(-1) neg.append(i) else: till += 1 ans.append(till) while till != l[i] - 1 and len(neg): ind = neg.pop() till += 1 ans[ind] = till ma = max(l) while len(neg): ind = neg.pop() ans[ind] = ma + 1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().strip().split())) available_numbers = set(range(2 * n)) removed = set() for v in a: if v not in removed: available_numbers.remove(v) removed.add(v) available_numbers = sorted(list(available_numbers)) mex = [-1] * n for i, v in enumerate(a[1:]): if a[i] != v: mex[i + 1] = a[i] j = 0 for k, v in enumerate(mex): if v == -1: mex[k] = available_numbers[j] j += 1 print(" ".join(map(str, mex)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys def read(): return int(input()) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def input(): return sys.stdin.readline().strip() def solve(): n = read() a = get_array() a = [0] + a b = [(-1) for i in range(n + 1)] used = [(False) for i in range(n + 1)] for i in range(1, n + 1): if a[i] != a[i - 1]: b[i] = a[i - 1] used[b[i]] = True used[a[n]] = True m = 0 for i in range(1, n + 1): if b[i] == -1: while used[m]: m += 1 b[i] = m used[m] = True for i in range(1, n + 1): print("%d " % b[i], end="") print() solve()
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def solve(A, n): free = [] ans = [-1] * n lo = 0 for i, a in enumerate(A): free.append([i, a]) while lo < a: if not free: return None j, y = free.pop() if lo != y: ans[j] = lo lo += 1 else: return while free: ans[free.pop()[0]] = 10**6 return ans n = int(input()) A = list(map(int, input().split())) ans = solve(A, n) if ans is None: print(-1) else: print(" ".join(map(str, ans)))
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR WHILE VAR VAR IF VAR RETURN NONE ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = [int(x) for x in input().split()] b = [-1] * n set_a = set(a) for i in range(n - 1, 0, -1): if a[i] != a[i - 1]: b[i] = a[i - 1] c = 0 for i in range(n): if b[i] == -1: while c in set_a: c += 1 b[i] = c c += 1 if max(a) - max(b) > 1: print(-1) else: print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) mt = list(map(int, input().split())) ans = [-1] * n dup = set(mt) sec = set([int(x) for x in range(n + 1)]) sec = sec.difference(dup) sec = list(sec) ans[0] = sec[0] sec.remove(sec[0]) for i in range(1, n): if mt[i - 1] != mt[i]: ans[i] = mt[i - 1] else: ans[i] = sec[0] sec.remove(sec[0]) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) b = [-1] * n l = [0] * (10**5 + 1) for i in range(1, n): if a[i] != a[i - 1]: b[i] = a[i - 1] l[b[i]] = 1 l[a[n - 1]] = 1 d = [] for i in range(10**5 + 1): if l[i] == 0: d.append(i) k = 0 for i in range(n): if b[i] == -1: b[i] = d[k] k += 1 print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) l = list(map(int, input().split())) s = set(l) x = 0 y = 1 for i in range(n): if l[i] != x: print(x, end=" ") x = l[i] if y == l[i]: y += 1 else: while y in s: y += 1 print(y, end=" ") y += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR NUMBER
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
a = int(input()) b = list(map(int, input().split())) c = [0] * 1000001 d = [-1] * 1000001 for i in range(1, a): if b[i] != b[i - 1]: d[i] = b[i - 1] c[b[i - 1]] = 1 m = 0 c[b[a - 1]] = 1 for i in range(a): while c[m]: m += 1 if d[i] == -1: d[i] = m c[m] = 1 print(d[i], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) m = 0 p = 0 c = [] d = [] b = [int(a) for a in input().split()] for i in range(0, n): if b[i] == m: if m == 0: c.append(1) else: c.append(m - 1) d.append(i) elif b[i] < m: p = 1 break else: k = b[i] - m k -= 1 c.append(m) m += 1 if k: if len(d) < k: p = 1 break else: while k > 0: h = d.pop() k -= 1 c[h] = m m += 1 while len(d) > 0: h = d.pop() c[h] = m + 1 m += 1 if p: print(-1) else: for i in c: print(i, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
from sys import gettrace, stdin if gettrace(): inputi = input else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def main(): n = int(inputi()) aa = [int(a) for a in inputi().split()] bb = [0] * n ap = 0 bv = 0 mex = 0 ap = 0 bv = 0 for i in range(n): if i > 0 and aa[i] != aa[i - 1]: bb[i] = aa[i - 1] if aa[i] > max(bv, bb[i] + 1): print(-1) return bv = max(bb[i] + 1, bv) else: while ap < n and bv >= aa[ap]: if bv == aa[ap]: bv += 1 ap += 1 bb[i] = bv bv += 1 if aa[i] > bv + 1: print(-1) return print(" ".join(map(str, bb))) main()
IF FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR WHILE VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys from sys import setrecursionlimit setrecursionlimit(10**5) readline = sys.stdin.readline n = int(readline()) a = list(map(int, readline().split())) b = [-1] * n not_visited = [] visited = [-1] * 10**6 flag = True for i, j in enumerate(a): if j > i + 1: flag = False break visited[j] = 1 if not flag: print(-1) sys.exit(0) for i in range(1, n): if a[i] != a[i - 1]: b[i] = a[i - 1] for i, j in enumerate(visited): if j == -1: not_visited.append(i) k = 0 for i, j in enumerate(b): if j == -1: b[i] = not_visited[k] k += 1 print(*b)
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def solve_test_case(t): n = int(input()) a = parse_array(int) a_set = set(a) b = [] b_set = set() mex = 0 max_b = -1 def add_to_b(v): nonlocal b nonlocal b_set nonlocal mex nonlocal max_b b.append(v) b_set.add(v) max_b = max(max_b, v) if v == mex: while mex in b_set: mex += 1 if a[0] == 1: add_to_b(0) elif a[0] > 1: print(-1) return else: i = 1 while True: if i not in a_set: add_to_b(i) break i += 1 possible = True for i in range(1, n): if a[i] > a[i - 1]: add_to_b(a[i - 1]) if mex != a[i]: possible = False break else: v = max_b + 1 while True: if v not in a_set: add_to_b(v) break v += 1 if possible: print(" ".join(list(map(str, b)))) else: print(-1) def parse_array(f): return list(map(f, input().split())) solve_test_case(0)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR WHILE VAR VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) l = list(map(int, input().split())) totalmax = max(l) s = set(range(l[-1])) flag = True ans = [0] * n reduntspots = [] for i in range(n): if l[i] > i + 1: print(-1) flag = False break if l[i] in s: s.remove(l[i]) if i == 0 and l[i] != 0: ans[i] = 0 if i != 0 and l[i] != l[i - 1]: ans[i] = l[i - 1] continue reduntspots.append(i) if flag: if len(s) <= len(reduntspots): missinglist = list(sorted(s)) + [totalmax + 1] * (len(reduntspots) - len(s)) for i in range(len(reduntspots)): ans[reduntspots[i]] = missinglist[i] print(*ans) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def solve(nums): res = [None] * len(nums) used = set() if nums[0] == 1: res[0] = 0 used.add(0) if nums[0] != 0 and nums[0] != 1: return -1 for i in range(1, len(nums)): if nums[i] > i + 1: return -1 if nums[i] != nums[i - 1]: res[i] = nums[i - 1] used.add(nums[i - 1]) largest = nums[-1] i = 0 for x in range(0, largest): while i < len(res) and res[i] != None: i += 1 if x not in used: res[i] = x i += 1 for i in range(len(res)): if res[i] == None: res[i] = largest + 1 return " ".join([str(x) for x in res]) input() nums = list(map(int, input().split())) print(solve(nums))
FUNC_DEF ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NONE VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().rstrip().split())) freq = dict() for el in a: freq[el] = freq.get(el, 0) + 1 pos = list() for i in range(0, 2 * n + 2): if i not in freq: pos.append(i) res = [(0) for i in range(n)] punt = 0 for i in range(n): if i == 0 or freq[a[i - 1]] > 0: res[i] = str(pos[punt]) punt += 1 else: res[i] = str(a[i - 1]) freq[a[i]] -= 1 print(" ".join(res))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) x = [] m = [] p = [] ans = [] flag = 0 if a[0] > 1: flag = 1 else: for i in range(1, n): if a[i] > i + 1: flag = 1 break else: d = a[i] - a[i - 1] x.append(d) if d > 1: m.append(d - 1) p.append(a[i]) if a[0] == 1: ans.append(0) elif len(p) != 0: ans.append(p[0] - m[0]) m[0] -= 1 if m[0] == 0: m.pop(0) p.pop(0) else: ans.append(a[n - 1] + 1) for i in range(1, n): if x[i - 1] > 0: ans.append(a[i - 1]) elif len(p) != 0: ans.append(p[0] - m[0]) m[0] -= 1 if m[0] == 0: m.pop(0) p.pop(0) else: ans.append(a[n - 1] + 1) if flag == 1: print(-1) else: for i in range(len(ans)): print(ans[i], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) PI = 10**6 for _ in range(1): n = nmbr() a = lst() f = 1 ans = [-1] * n new = [0] pos = 0 if a[0] == 1: ans[0] = 0 pos = 1 for i in range(1, n): if a[i] != a[i - 1]: new += [i] for p1, p2 in zip(new, new[1:]): ans[p2] = a[p1] for v in range(a[p1] + 1, a[p2]): while pos < n and ans[pos] != -1: pos += 1 if pos >= n: f = 0 break ans[pos] = v pos += 1 for i in range(n): if ans[i] == -1: ans[i] = PI print(*(ans if f else -1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR LIST VAR FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) lst = [int(i) for i in input().split()] a = [-1] * n visited = [-1] * 100001 flag = 0 for i in range(n): if lst[i] > i + 1: flag = 1 break visited[lst[i]] = 1 not_v = list() for i in range(100001): if visited[i] == -1: not_v.append(i) for i in range(1, n): if lst[i] != lst[i - 1]: a[i] = lst[i - 1] j = 0 for i in range(n): if a[i] == -1: a[i] = not_v[j] j += 1 print(*a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys input = sys.stdin.buffer.readline n = int(input()) A = [int(x) for x in input().split()] B = [(0) for _ in range(n)] aValues = set(A) prevVal = 0 possible = True nextValue = 1 while nextValue in aValues: nextValue += 1 for i in range(n): if A[i] != prevVal: if A[i] - 1 > i: possible = False break B[i] = prevVal prevVal = A[i] else: B[i] = nextValue nextValue += 1 while nextValue in aValues: nextValue += 1 if possible == True: print(" ".join([str(x) for x in B])) else: print("-1")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = tuple(map(int, input().split())) sa = set(a) san = set() min_not_in = 0 prev = 0 ans = [0] * n for i in range(n): cur = a[i] if cur == prev: while min_not_in in sa: min_not_in += 1 ans[i] = min_not_in sa.add(min_not_in) san.add(min_not_in) else: ans[i] = prev sa.add(prev) san.add(prev) while prev in san: prev += 1 if cur != prev: print(-1) break else: print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) b = [-1] * n v = [-1] * (n + 1) f = 0 v[a[n - 1]] = 1 for i in range(n - 1, 0, -1): if a[i] > i + 1: f = 1 break if a[i] != a[i - 1]: b[i] = a[i - 1] v[a[i - 1]] = 1 if f == 1: print(-1) vi = [] for i in range(len(v)): if v[i] == -1: vi.append(i) j = 0 for i in range(len(b)): if b[i] == -1: b[i] = vi[j] j += 1 print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) A = list(map(int, input().split())) A.insert(0, 0) output = [-1] * (n + 1) flag = 0 last = 0 for i, a in enumerate(A): if a > i + 1: flag = 1 break if i > 0: if A[i] > A[i - 1]: output[i] = A[i - 1] if flag: print(-1) else: j = 1 while j < n + 1 and output[j] != -1: j += 1 for i, o in enumerate(output): if o != -1: for k in range(o + 1, A[i]): output[j] = k while j < n + 1 and output[j] != -1: j += 1 for i in range(1, len(output)): o = output[i] if output[i] != -1 else A[n] + 1 print(o, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) b = [-1] * n empty = [] if a[0] > 1: print(-1) exit() elif a[0] == 1: b[0] = 0 else: empty.append(0) for i in range(1, n): if a[i] > i + 1: print(-1) exit() if a[i] == a[i - 1]: empty.append(i) else: b[i] = a[i - 1] k = a[i] - a[i - 1] - 1 j = len(empty) - 1 while k > 0 and j >= 0: b[empty[j]] = a[i] - k empty.pop() j -= 1 k -= 1 if k > 0: print(-1) exit() for i in range(len(b)): if b[i] == -1: b[i] = 1000000 print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) ans = [] a = list(map(int, input().split())) oset = set(i for i in range(2 * n + 1)) aset = set(a) iset = oset - aset ilist = sorted(list(iset), reverse=True) for j in range(n): ans.append(ilist[-1]) de = a.pop(0) if len(a) and a[0] != de: ilist.pop(-1) ilist.append(de) else: ilist.pop(-1) for kk in ans: print(kk, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def answer(n, A): q = [0] * (n + 2) for i in A: q[i] = 1 l = [i for i in range(n + 2) if q[i] == 0] b = [] for i in range(n - 1): if A[i] != A[i + 1]: b.append(l[0]) l[0] = A[i] else: b.append(l[0]) del l[0] b.append(l.pop(0)) return b n = int(input()) A = list(map(int, input().split())) print(*answer(n, A))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
from sys import stdin n = int(stdin.readline()) arr = list(map(int, stdin.readline().rstrip().split(" "))) setarr = set(arr) b = [-1] * n x = 0 for i in range(n): if arr[i] > i + 1: print(-1) break else: for i in range(1, n): if arr[i] != arr[i - 1]: b[i] = arr[i - 1] for i in range(n): if b[i] == -1: while x in setarr: x += 1 b[i] = x x += 1 print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) A = [int(i) for i in input().split()] for i in range(n): if A[i] > i + 1: print(-1) break else: ans = [-1] * n visited = [False] * (n + 1) for i in range(1, n): if A[i] != A[i - 1]: ans[i] = A[i - 1] visited[A[i - 1]] = True visited[A[-1]] = True pointer = 0 for i in range(n): if ans[i] == -1: while visited[pointer]: pointer += 1 visited[pointer] = True ans[i] = pointer print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) se = set(range(n + 1)) - set(a) li = list(se) li.sort() pre = 0 idx = 0 ans = [] for i in range(n): if a[i] > pre: ans.append(pre) if pre in se and idx < len(li) - 1: idx += 1 pre = a[i] else: ans.append(li[idx]) if idx < len(li) - 1: idx += 1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
import sys input = sys.stdin.readline def main(): N = int(input()) A = [int(x) for x in input().split()] seta = set(A) mex = 0 ans = [] ma = 0 for i, a in enumerate(A): if a == mex: if len(ans) == 0: for j in range(1, N + 1): if j not in seta: ans.append(j) ma = max(ma, j) break else: print(-1) return else: for j in range(max(mex, ma) + 1, N + 1): if j not in seta: ans.append(j) ma = max(ma, j) break else: print(-1) return else: ans.append(mex) ma = max(ma, mex) mex = a print(*ans) main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
def solve(): n = int(input()) lst = list(map(int, input().split())) svb = [] svbc = 0 ans = [] pos = 0 for i in range(n): if lst[i] == pos: svbc += 1 ans.append(-1) elif lst[i] == pos + 1: ans.append(pos) pos += 1 elif lst[i] > pos: ans.append(pos) for x in range(pos + 1, lst[i]): svb.append(x) svbc -= 1 pos = lst[i] if svbc < 0: print(-1) return sh = -1 for i in ans: if i != -1: print(i, end=" ") else: sh += 1 if sh >= len(svb): print(1000000, end=" ") else: print(svb[sh], end=" ") print() for t in range(1): solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = [int(x) for x in input().split()] b = [None] * n unused = set() banned = set(a) mex = 0 c = 0 for i in range(n): if a[i] == mex: while c in banned: c += 1 b[i] = c c += 1 else: if i > 0: banned.discard(a[i - 1]) b[i] = mex if c == mex: c += 1 mex = a[i] print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) nums = [int(x) for x in input().split()] stack = [] ans = [-1] * n for i in range(n - 1, 0, -1): if nums[i] > i + 1: print(-1) break if nums[i] == nums[i - 1]: if len(stack) > 0: ans[i] = stack.pop() else: ans[i] = 1000000 else: ans[i] = nums[i - 1] delta = nums[i] - nums[i - 1] start = nums[i - 1] + 1 for j in range(delta - 1): stack.append(start) start += 1 if nums[0] == 0: if len(stack) > 0: ans[0] = stack.pop() else: ans[0] = 1000000 elif nums[0] == 1: ans[0] = 0 for i in range(n): print(ans[i], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
from sys import stderr, stdin def rl(): return [int(w) for w in stdin.readline().split()] (n,) = rl() a = rl() a_set = set(a) free = 0 prev = 0 b = [] for cur in a: if cur != prev: b.append(prev) if free == prev: free += 1 prev = cur else: while free in a_set: free += 1 b.append(free) free += 1 print(*b)
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
n = int(input()) a = list(map(int, input().split())) f = 1 for i in range(n): if a[i] > i + 1: f = 0 break if f == 0: print(-1) else: ans = [-1] * (n + 1) ind = [-1] * (n + 1) for i in range(n): ind[a[i]] = i done = [0] * (n + 1) for i in range(len(ind)): if ind[i] != -1: ans[ind[i] + 1] = i done[i] = 1 i = 0 j = 0 while i < n: if ans[i] == -1: while j < n + 1: if done[j] == 0: ans[i] = j done[j] = 1 break else: j += 1 i += 1 print(*ans[0:n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
from sys import stdin, stdout n = int(stdin.readline()) arr = list(map(int, stdin.readline().strip().split())) if sorted(arr) != arr: print(-1) else: flg = 0 for i in range(n): if arr[i] - i > 1: flg = 1 break if flg: print(-1) else: raj = dict() for i in range(n): raj[arr[i]] = 1 x = -1 ans = [] for i in range(n): if i == 0: x = x + 1 while x in raj: x += 1 ans.append(x) elif arr[i - 1] != arr[i]: ans.append(arr[i - 1]) else: x = x + 1 while x in raj: x += 1 ans.append(x) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR