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. | n = int(input())
a = [int(x) for x in input().split(" ")]
a_dict = {}
for item in a:
if item in a_dict.keys():
a_dict[item] += 1
else:
a_dict[item] = 1
m = 0
ans = []
skip_print = False
for i in range(n):
if a[i] > i + 1:
print(-1)
skip_print = True
break
if i > 0 and a[i] != a[i - 1]:
ans.append(a[i - 1])
else:
while m in a_dict.keys():
m += 1
ans.append(m)
m += 1
if not skip_print:
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF 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()))
def add(i):
r = []
if c[i]:
while c[i]:
r.append(i)
i += 1
return i, r
aa = set(a)
f = {i: (0) for i in aa}
for i in a:
f[i] += 1
c = [(False) for i in range(n + 20)]
for i in a:
c[i] = True
d = [i for i in aa][::-1]
rest = set()
i = 0
b = []
while d:
if len(rest) > 1:
print(-1)
exit()
t = 0
x = d.pop()
if rest:
b.append(rest.pop())
t += 1
rest.add(x)
while t < f[x]:
i, r = add(i)
b.append(i)
i += 1
rest.union(r)
t += 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 FUNC_DEF ASSIGN VAR LIST IF VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL 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. | import sys
input = sys.stdin.readline
t = int(input())
n = set([i for i in range(t + 1)])
l = list(map(int, input().split()))
ss = set(l)
pp = list(n.difference(ss))
pp.sort()
for el in range(len(l)):
if l[el] > el + 1:
print(-1)
exit()
b = [pp[0]]
c = 1
for el in range(1, len(l)):
if l[el] > l[el - 1]:
b.append(l[el - 1])
else:
b.append(pp[c])
c += 1
print(*b) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR 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 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())
arr = [*map(int, input().split())]
s1 = set([*range(n + 1)])
s2 = set(arr)
s1 = s1 - s2
s1 = [*s1][::-1]
s2 = [*s2][::-1]
ans = [s1[-1]]
del s1[-1]
for i in range(1, n):
if arr[i] != arr[i - 1]:
ans.append(s2[-1])
del s2[-1]
else:
ans.append(s1[-1])
del s1[-1]
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR 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. | n = int(input())
l = list(map(int, input().split()))
l1 = [0] * 1000004
lf = [-1] * 1000004
for i in range(1, n):
l1[l[i]] = 1
if l[i] != l[i - 1]:
lf[i] = l[i - 1]
l1[l[0]] = 1
m = 0
for i in range(n):
if lf[i] == -1:
while l1[m] == 1:
m += 1
lf[i] = m
l1[m] = 1
for i in range(n):
print(lf[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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN 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. | n = int(input())
a = list(map(int, input().split()))
i = 0
temp = -1
b = [-1] * n
while i < n - 1:
if a[i] != a[i + 1]:
temp = a[i]
b[i + 1] = temp
i += 1
x = b.count(-1)
lis = [-1] * (n + 1)
for i in range(n):
lis[a[i]] = 0
y = lis.count(-1)
arr = []
p = n + 1
for i in range(p):
if lis[i] == -1:
arr.append(i)
j = 0
for i in range(n):
if b[i] == -1:
b[i] = arr[j]
j += 1
print(" ".join(str(x) for x in 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR 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 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())
ls = list(map(int, input().split()))
cc = set()
res = [-1] * n
for i in range(n):
if i > 0 and ls[i - 1] != ls[i]:
res[i] = ls[i - 1]
cc.add(ls[i - 1])
cc.add(ls[-1])
p, cv = 0, 0
while p < n:
while cv in cc:
cv += 1
while p < n and res[p] != -1:
p += 1
if p < n:
res[p] = cv
cv += 1
print(*res) | 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR 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 = [0] + list(map(int, input().split(" ")))
b = [100002] * (n + 1)
index = 1
for i in range(n):
if a[i] != a[i + 1]:
b[i + 1] = a[i]
for j in range(a[i] + 1, a[i + 1]):
while b[index] != 100002:
index += 1
b[index] = j
print(" ".join(list(map(str, b[1:])))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR 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()))
sol = [-1] * n
touse = list(range(n + 1))
if a[0] == 1:
sol[0] = 0
touse[0] = -1
for i in range(1, n):
if a[i] > a[i - 1]:
sol[i] = a[i - 1]
touse[a[i - 1]] = -1
j = 0
touse[a[-1]] = -1
for i in range(n):
if sol[i] == -1:
while touse[j] == -1:
j += 1
sol[i] = touse[j]
j += 1
print(*sol) | 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 FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER 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 ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE 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. | from sys import stdin
def inp():
return stdin.buffer.readline().rstrip().decode("utf8")
def itg():
return int(stdin.buffer.readline())
def mpint():
return map(int, stdin.buffer.readline().split())
def main():
n = itg()
arr = tuple(mpint())
have_ans = all([(arr[i] <= arr[i + 1] and arr[i] <= i + 1) for i in range(n - 1)])
if not have_ans:
return [-1]
aa = set(arr)
bb = sorted(set(range(n + 7)) - aa, reverse=True)
aa = sorted(aa, reverse=True)
ans = [bb.pop()]
for i in range(1, n):
if arr[i - 1] != arr[i]:
ans.append(aa.pop())
else:
ans.append(bb.pop())
return ans
print(*main()) | FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR RETURN LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR EXPR FUNC_CALL VAR 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. | MAX = 10**6 // 2
n = int(input())
A = list(map(int, input().split(" ")))
A.append(0)
B = [-1] * n
excluded = sorted(list(set(range(0, n + 1)) - set(A)), reverse=True)
for i in range(n):
if A[i] != A[i - 1]:
B[i] = A[i - 1]
else:
B[i] = MAX if len(excluded) == 0 else excluded.pop()
print(*B) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER 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. | i_liczb = int(input())
a = [int(x) for x in input().split()]
a = [0] + a
if a[i_liczb] > i_liczb:
print(-1)
quit()
b = [(-1) for _ in range(i_liczb + 1)]
wykorzystane = [(False) for _ in range(100005)]
for i in range(1, i_liczb + 1):
if a[i] != a[i - 1]:
b[i] = a[i - 1]
wykorzystane[b[i]] = True
wykorzystane[a[i_liczb]] = True
x = 0
for i in range(1, i_liczb + 1):
while wykorzystane[x]:
x += 1
if b[i] == -1:
b[i] = x
wykorzystane[x] = True
print(*b[1:]) | 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 IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL 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 WHILE VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN 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())
ar = list(map(int, input().split()))
if n == 1:
print((1, 0)[ar[0] > 0])
return
res = [-1] * n
s = set(ar)
mx = -1
for i in range(1, n):
if ar[i] > ar[i - 1]:
res[i] = ar[i - 1]
mx = max(mx, res[i])
j = 0
for i in range(n):
if res[i] == -1:
while j in s:
j += 1
res[i] = j
mx = max(mx, j)
j += 1
if ar[n - 1] - mx > 1:
print(-1)
return
for x in res:
print(x, end=" ")
print()
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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN 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 FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR VAR EXPR FUNC_CALL 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. | from sys import stdin, stdout
n = int(stdin.readline())
a = list(map(int, stdin.readline().strip().split()))
c = set(a)
d = []
for i in range(n + 1):
if i not in c:
d.append(i)
b = []
j = 0
for i in range(n):
if i != 0:
if a[i - 1] < a[i]:
b.append(a[i - 1])
else:
b.append(d[j])
j = j + 1
else:
b.append(d[j])
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR 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 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 help():
n = int(input())
arr = list(map(int, input().split(" ")))
ans_arr = [-1] * n
dicti = {}
if arr[0] == 1:
ans_arr[0] = 0
dicti[0] = 1
for i in range(1, n):
if arr[i] != arr[i - 1]:
ans_arr[i] = arr[i - 1]
dicti[arr[i - 1]] = 1
dicti[arr[-1]] = 1
m = 0
for i in range(n):
while dicti.get(m, -1) == 1:
m += 1
if ans_arr[i] == -1:
ans_arr[i] = m
dicti[m] = 1
print(*ans_arr)
for _ in range(1):
help() | 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 LIST NUMBER VAR ASSIGN VAR DICT IF VAR NUMBER 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 ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR 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. | no = int(input())
seq = list(map(int, input().split()))
x = 0
y = 1
t = set(seq)
for i in seq:
if i == x:
while y in t:
y += 1
print(y, end=" ")
y += 1
else:
print(x, end=" ")
x = 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN 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())
dp = list(map(int, input().split()))
l = []
u = []
for i in range(0, n + 1):
l.append(0)
for i in range(0, n):
l[dp[i]] = 1
for i in range(0, n + 1):
if l[i] == 0:
u.append(i)
j = 0
print(u[j], end=" ")
j += 1
for i in range(1, n):
if dp[i - 1] != dp[i]:
print(dp[i - 1], end=" ")
else:
print(u[j], end=" ")
j += 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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR 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. | n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
use = [False] * (n + 1)
for i in range(1, n):
if a[i] != a[i - 1]:
b[i] = a[i - 1]
use[a[i - 1]] = True
use[a[n - 1]] = True
ind = 0
i = 0
while ind < n:
if b[ind] == -1:
while use[i] == True:
i += 1
b[ind] = i
use[i] = True
ind += 1
else:
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 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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER 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 = [int(i) for i in input().split(" ")]
b = [0] * n
count = 0
idxs = []
if a[0] == 0:
idxs.append(0)
else:
b[0] = 0
ok = True
for i in range(1, n):
if a[i] == a[i - 1]:
idxs.append(i)
else:
b[i] = a[i - 1]
k = 1
while k < a[i] - a[i - 1]:
if len(idxs) == 0:
ok = False
print(-1)
break
b[idxs.pop()] = a[i - 1] + k
k += 1
if not ok:
break
max_v = a[-1] * 2 if a[-1] != 0 else 1
while len(idxs):
b[idxs.pop()] = max_v
s = ""
for i in b:
s += f"{i} "
print(s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR 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. | def solve(n, a):
sol = [-1] * n
mx = a[-1] + 1
if a[0] == 1:
sol[0] = 0
for i in range(1, n):
if a[i] != a[i - 1]:
sol[i] = a[i - 1]
j = n - 1
while sol[j] == -1:
sol[j] = mx
j -= 1
if j > -1:
used = [False] * a[j]
for i in range(n):
if sol[i] != -1 and sol[i] < len(used):
used[sol[i]] = True
i = len(used) - 1
while j >= 0:
if sol[j] != -1:
used[sol[j]] = True
else:
while i >= 0 and used[i]:
i -= 1
if i >= 0 and i > a[j]:
sol[j] = i
used[i] = True
else:
sol[j] = mx
j -= 1
return sol
n = int(input())
a = list(map(int, input().split()))
s = solve(n, a)
print(" ".join(map(str, s)) if s else -1) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF 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 BIN_OP VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL STRING 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())
l = set()
a = list(map(int, input().split()))
l = set(a)
ans = 0
ans_t = []
v = []
for _ in range(n):
if not _:
while ans in l:
ans = ans + 1
ans_t.append(ans)
ans = ans + 1
elif a[_] != a[_ - 1]:
ans_t.append(a[_ - 1])
else:
while ans in l:
ans = ans + 1
ans_t.append(ans)
ans = ans + 1
print(*ans_t, sep=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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. | def solve(n, a):
b = [None] * n
u = set(a)
for i in range(1, n):
if a[i] > a[i - 1]:
b[i] = a[i - 1]
if a[i] > i + 1:
return -1
j = 0
for i in range(n):
if b[i] is not None:
continue
while j in u:
j += 1
b[i] = j
u.add(j)
return " ".join(map(str, b))
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a)) | FUNC_DEF ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN 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 IF VAR VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN 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 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 = list(map(int, 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]
MEX = 0
j = 0
l = []
while j <= n - 1:
if MEX < a[j]:
l.append(MEX)
MEX = MEX + 1
elif MEX == a[j]:
MEX = MEX + 1
j = j + 1
elif MEX > a[j]:
j = j + 1
else:
l.append(MEX)
MEX = MEX + 1
while len(l) < n:
l.append(MEX)
MEX = MEX + 1
j = 0
for i in range(n):
if b[i] == -1:
b[i] = l[j]
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 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 NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN 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. | from sys import stdin as cin
lmap = lambda f, v: list(map(f, v))
def mexarray(a):
missing = list(sorted(set(range(1, len(a) + 1)) - set(a), reverse=True))
a = [0] + a
for i in range(1, len(a)):
if a[i] == a[i - 1]:
yield missing.pop()
else:
yield a[i - 1]
def main():
n = lmap(int, next(cin).strip().split())
a = lmap(int, next(cin).strip().split())
print(" ".join(map(str, mexarray(a))))
main() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR 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. | import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def check(a, b):
n = len(a)
bb = [False] * (n + 1)
c = [0] * n
j = 0
z = 0
for i in a:
if i <= n:
bb[i] = True
while bb[j]:
j += 1
if b[z] != j:
return False
z += 1
return True
def solve():
n = mint()
a = list(mints())
b = [None] * n
c = [False] * (n + 1)
for i in range(1, n):
if a[i] != a[i - 1]:
b[i] = a[i - 1]
if a[i - 1] <= n:
c[a[i - 1]] = True
if a[-1] <= n:
c[a[-1]] = True
if a[0] != 0:
b[0] = 0
c[0] = True
j = 0
for i in range(n):
if b[i] is None:
while c[j]:
j += 1
b[i] = j
c[j] = True
if check(b, a):
print(" ".join(map(str, b)))
else:
print(-1)
solve() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE 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 IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR 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. | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
n = iinput()
a = get_list()
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])
else:
while ele in s:
ele += 1
ans.append(ele)
ele += 1
print(*ans) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR 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 ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR 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. | n = int(input())
a = list(map(int, input().split()))
b = []
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in range(n):
c[a[i]] += 1
u = 0
v = c.index(0)
for i in range(n):
if a[i] > u:
b.append(u)
d[u] = 1
while u <= n and d[u] == 1:
u += 1
if u > v:
v = u
while v <= n and c[v] != 0:
v += 1
else:
b.append(v)
d[v] = 1
c[v] = -1
while v <= n and c[v] != 0:
v += 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 LIST 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 VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE 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. | input()
maybe_used = []
data = list(map(int, input().split()))
result = [None] * len(data)
if data[0] == 0:
maybe_used.append(0)
elif data[0] == 1:
result[0] = 0
else:
print(-1)
break_flag = False
for i in range(1, len(data)):
if data[i] == data[i - 1]:
maybe_used.append(i)
elif data[i] == data[i - 1] + 1:
result[i] = data[i - 1]
else:
result[i] = data[i - 1]
for j in range(data[i - 1] + 1, data[i]):
if maybe_used:
k = maybe_used.pop(0)
result[k] = j
pass
else:
break_flag = True
break
if break_flag:
print(-1)
break
if not break_flag:
x = 100500
while maybe_used:
result[maybe_used.pop(0)] = x
x += 1
print(*result)
pass | EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER 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())
arr = list(map(int, input().split()))
arr1 = sorted(list(set(arr))) + [1000000]
b = []
min_val_not_vis = 0
vis = [0] * 1000001
j = 0
k = -1
for i in arr:
vis[i] = 1
def get_nex_val():
global k
k += 1
while k < 1000001:
if vis[k]:
k += 1
else:
break
for i in range(n):
if arr[i] != arr1[j]:
j += 1
b.append(arr1[j - 1])
else:
get_nex_val()
b.append(k)
ans = True
vis = [0] * 1000001
k = 0
for i in range(n):
vis[b[i]] = 1
if vis[k]:
while True:
if vis[k]:
k += 1
else:
break
if arr[i] != k:
ans = False
break
if ans:
print(*b)
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 BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR WHILE NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF 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. | input()
nums = list(map(int, input().split()))
nums_set = set(nums)
complement = (x for x in range(2 * len(nums)) if x not in nums_set)
b = []
for i, a in enumerate(nums):
if a > i + 1:
print(-1)
exit()
if i and a != nums[i - 1]:
b.append(nums[i - 1])
else:
b.append(next(complement))
print(*b) | EXPR 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 NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF 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 BIN_OP VAR NUMBER EXPR FUNC_CALL 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. | n = int(input())
l = [int(j) for j in input().split()]
mx = max(l) + 1
pre = ["#" for i in range(n + 1)]
c = [(False) for i in range(n + 1)]
for i in range(n - 1):
if l[i] != l[i + 1]:
pre[i + 1] = l[i]
c[l[i]] = True
pre[n] = l[n - 1]
c[l[n - 1]] = True
s = []
for i in range(n + 1):
if not c[i]:
s.append(i)
j = 0
for i in range(n):
if pre[i] == "#":
pre[i] = s[j]
j += 1
print(" ".join(map(str, pre[:-1]))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 ASSIGN VAR VAR 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 BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING 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())
a = list(map(int, input().split(" ")))
temp = {}
counter = 0
ans = []
flag = False
for i in range(n):
temp[a[i]] = True
if not counter in temp:
ans.append(counter)
counter += 1
else:
while counter in temp:
counter += 1
ans.append(counter)
counter += 1
if a[0] != 0 and a[0] != 1:
print(-1)
flag = True
for i in range(1, n):
if a[i] > i + 1:
print(-1)
flag = True
if a[i] != a[i - 1]:
ans.append(a[i - 1])
elif not counter in temp:
ans.append(counter)
counter += 1
else:
while counter in temp:
counter += 1
ans.append(counter)
counter += 1
if not flag:
print(*ans) | 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 DICT ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER 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 NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF 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 check_if_possible(values):
for i in range(len(values)):
if values[i] - 1 > i:
return False
return True
def getNextAvailable(arr, ctr):
for i in range(ctr, len(arr)):
if arr[i] == 1:
arr[i] = 0
return i, i + 1
n = int(input())
values = list(map(int, input().strip().split(" ")))
if check_if_possible(values):
ansarr = [None for i in range(len(values))]
available_values = [(1) for i in range(len(values) + 1)]
for i in values:
available_values[i] = 0
for i in range(1, len(values)):
if values[i] != values[i - 1]:
ansarr[i] = values[i - 1]
mkr = 0
for i in range(len(ansarr)):
if ansarr[i] == None:
ansarr[i], mkr = getNextAvailable(available_values, mkr)
for i in ansarr:
print(i, end=" ") | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER 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 IF FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR 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())
l = list(map(int, input().split()))
x = 1
prev = 0
s = set(l)
res = []
flag = True
for i in range(n):
if i + 1 < l[i] or i > 1 and l[i] < l[i - 1]:
flag = False
break
if flag:
for i in l:
if i != prev:
res.append(prev)
prev = i
else:
while x in s:
x += 1
res.append(x)
x += 1
print(*res)
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR 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. | ll = lambda: list(map(int, input().split()))
s = lambda: input()
v = lambda: map(int, input().split())
ii = lambda: int(input())
m = 1000000007
n = ii()
a = ll()
m = [0] * 1000001
c = [0] * 1000001
for i in a:
c[i] += 1
p = 0
q = []
ans = []
for i in range(n + 1):
if c[i] == 0:
continue
while c[i]:
if q:
c[i] -= 1
ans.append(q[0])
m[q[0]] += 1
q.pop(0)
else:
while c[p] or m[p]:
p += 1
m[p] += 1
ans.append(p)
p += 1
c[i] -= 1
q.append(i)
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER 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 = list(map(int, input().split()))
b = [(-1) for i in range(n)]
flag = 1
c = a[0]
r = {}
for i in range(1, n):
if a[i] != c:
b[i] = c
r[c] = 1
if i < c:
flag = 0
break
c = a[i]
if n < c:
flag = 0
avail = []
la = 0
for i in range(a[n - 1]):
if r.get(i, 0) == 0:
avail.append(i)
la += 1
la += 1
avail.append(a[n - 1] + 1)
if flag == 0:
print(-1)
else:
j = 0
for i in range(n):
if b[i] == -1:
b[i] = avail[j]
if j < la - 1:
j += 1
for i in b:
print(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 VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER 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. | import sys
n = int(sys.stdin.readline())
a = [int(i) for i in sys.stdin.readline().split()]
s = set(a)
bs = [0] * n
at = 0
for i in range(n):
while at in s:
at += 1
bs[i] = at
at += 1
ans = [0] * n
used = 0
for i in range(n):
if i != 0 and a[i] != a[i - 1]:
ans[i] = a[i - 1]
else:
ans[i] = bs[used]
used += 1
print(" ".join([str(i) for i in ans])) | IMPORT 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR 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 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. | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = []
d = dict()
for i in range(n):
if a[i] > i + 1:
print(-1)
exit()
for i in range(10**6 + 20):
d[i] = 0
for i in a:
d[i] += 1
m = 10**6
for i in range(n):
if d[i] == 0:
m = i
break
back_m = m
for i in range(n):
ans.append(m)
d[m] += 1
d[a[i]] -= 1
if d[a[i]] == 0:
m = a[i]
else:
m = back_m
for j in range(m + 1, n):
if d[j] == 0:
m = j
break
back_m = m
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 LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN 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():
n = int(input())
mex = [int(x) for x in input().split()]
arr = [n + 1] * n
prev_mex = 0
slots = []
for i in range(n):
if mex[i] > prev_mex:
arr[i] = prev_mex
nums_to_add = range(prev_mex + 1, mex[i])
for num in nums_to_add:
if len(slots) == 0:
print(-1)
return
slot = slots.pop()
arr[slot] = num
else:
slots.append(i)
prev_mex = mex[i]
print(" ".join(str(x) for x in arr))
main() | 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 BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR 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
input = sys.stdin.readline
t = 1
for _ in range(t):
maxi = 10**6
n = int(input())
arr = list(map(int, input().split()))
l = [-1] * n
vacant = n
left = max(arr)
cur = arr[0]
used = [-1] * (10**6 + 1)
allow = arr[-1] - 1
for i in range(n):
if arr[i] != cur:
l[i] = cur
used[cur] = 1
cur = arr[i]
vacant -= 1
left -= 1
if l[-1] == -1:
l[-1] = 10**6
used[10**6] = 1
vacant -= 1
for i in range(n - 2, -1, -1):
while used[allow] == 1:
allow -= 1
while used[maxi] == 1:
maxi -= 1
if (arr[i] < allow or vacant <= left) and allow >= 0:
if l[i] == -1:
l[i] = allow
used[allow] = 1
allow -= 1
left -= 1
vacant -= 1
elif arr[i] >= allow:
if l[i] == -1:
l[i] = maxi
used[maxi] = 1
maxi -= 1
vacant -= 1
if arr[0] == 1 and len(arr) == 1:
print(0)
elif left > 0:
print(-1)
else:
print(*l) | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER 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 VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF 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. | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n = int(input())
arr = [int(x) for x in input().split()]
if arr[0] > 1:
print(-1)
sys.exit()
last = arr[-1]
required = []
used = set()
i = n - 1
MAX = int(1000000.0) - 1
ans = [(0) for x in range(n)]
while i > 0:
if arr[i] > i + 1:
print(-1)
sys.exit()
if arr[i - 1] != arr[i]:
ans[i] = arr[i - 1]
for x in range(arr[i - 1] + 1, arr[i]):
required.append(x)
elif len(required):
ans[i] = required.pop()
else:
ans[i] = MAX
i -= 1
if arr[0] == 0:
if len(required):
ans[0] = required.pop()
else:
ans[0] = MAX
for item in ans:
print(item, end=" ") | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN 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 ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR ASSIGN VAR NUMBER VAR 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. | t = 1
while t != 0:
t -= 1
n = int(input())
a = [int(x) for x in input().split()]
st = set()
b = [(-1) for _ in range(n)]
for i in range(1, n):
if a[i] != a[i - 1]:
b[i] = a[i - 1]
st.add(b[i])
st.add(a[-1])
m = 0
for i in range(n):
if b[i] == -1:
while m in st:
m += 1
b[i] = m
m += 1
print(*b) | ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER 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 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 EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR 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 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()))
c = [0] * 1000001
for i in a:
c[i] += 1
p = 0
q = []
sol = []
t = [0] * 1000001
for i in range(n + 1):
if c[i] == 0:
continue
while c[i]:
if q:
c[i] -= 1
sol.append(q[0])
t[q[0]] += 1
q.pop(0)
else:
while c[p] or t[p]:
p += 1
t[p] += 1
sol.append(p)
p += 1
c[i] -= 1
q.append(i)
print(*sol) | 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 VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER 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. | import sys
def ii():
return sys.stdin.readline().strip()
def idata():
return [int(x) for x in ii().split()]
def solve_of_problem():
n = int(ii())
data = idata()
slov = dict()
for i in range(0, n + n + 12):
slov[i] = 0
for i in range(n):
if data[i] > i + 1:
print(-1)
return
slov[data[i]] = 1
ans = []
data += [n + n + 12]
m = 0
for i in range(n):
if data[i] > data[i - 1] and i != 0:
ans += [data[i - 1]]
else:
while slov[m]:
m += 1
ans += [m]
slov[m] = 1
print(*ans)
return
solve_of_problem() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST VAR LIST BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR LIST VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER VAR LIST VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN 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())
list1 = list(map(int, input().strip().split()))
if list1[0] >= 2:
print(-1)
else:
free = []
curr = 0
b = 1
ans = []
for i in range(n):
ans.append(-1)
if list1[0] == 0:
free.append(0)
elif list1[0] == 1:
ans[0] = 0
for i in range(1, n):
if list1[i] == list1[i - 1]:
free.append(i)
else:
ans[i] = list1[i - 1]
temp1 = len(free) - curr
temp2 = list1[i] - list1[i - 1] - 1
if temp2 > temp2:
b = 0
break
for i in range(list1[i - 1] + 1, list1[i]):
ans[free[curr]] = i
curr += 1
if b == 0:
print(-1)
else:
maximum = list1[n - 1] + 1
for i in range(curr, len(free)):
ans[free[i]] = maximum
for val in ans:
print(val, end=" ")
print() | 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 VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER 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 FUNC_CALL VAR VAR VAR 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 VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR 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. | import sys
input = sys.stdin.buffer.readline
def solution():
n = int(input())
l = list(map(int, input().split()))
a = [0] * (10**6 + 1)
for i in range(n):
if l[i] > i + 1:
print(-1)
return
a[l[i]] = 1
x = []
for i in range(len(a)):
if a[i] == 0:
x.append(i)
j = 1
ans = [x[0]]
for i in range(1, n):
if l[i] == l[i - 1]:
ans.append(x[j])
if j != n - 1:
j += 1
else:
ans.append(l[i - 1])
print(*ans)
solution() | IMPORT 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 BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN 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 NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP 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. | n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
f = 0
c = [0] * (n + 1)
for i in range(n):
if i == 0:
c[a[i]] = 1
else:
if a[i] > i + 1:
f = 1
break
c[a[i]] = 1
if a[i] != a[i - 1]:
b[i] = a[i - 1]
if f:
print(-1)
else:
x = 0
for i in range(n):
if b[i] == -1:
while c[x % (n + 1)]:
x = (x + 1) % (n + 1)
c[x % (n + 1)] = 1
b[i] = x
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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER 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()))
b = [n + 1] * n
isCovered = [False] * a[n - 1]
lastIsNotCovered = 0
allCovered = False
for i in range(n - 1):
if a[i] != a[i + 1]:
b[i + 1] = a[i]
isCovered[a[i]] = True
for i in range(lastIsNotCovered, a[n - 1]):
if isCovered[i] == False:
lastIsNotCovered = i
break
if i == a[n - 1] - 1:
allCovered = True
break
if a[n - 1] == 0:
allCovered = True
for i in range(n):
if allCovered:
break
if b[i] != n + 1:
continue
else:
b[i] = lastIsNotCovered
if lastIsNotCovered == a[n - 1] - 1:
allCovered = True
break
isCovered[lastIsNotCovered] = True
for j in range(lastIsNotCovered, a[n - 1]):
if isCovered[j] == False:
lastIsNotCovered = j
break
if j == a[n - 1] - 1:
allCovered = True
break
if allCovered:
break
if allCovered:
output = [str(i) for i in b]
print(" ".join(output))
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 BIN_OP LIST BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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. | from sys import stdin
def intJoin(arr):
return " ".join([str(i) for i in arr])
def answer(arr):
arr = [arr[0] - 1] + arr
a = []
b = []
for i in range(1, len(arr)):
if arr[i] != arr[i - 1]:
a.append(arr[i - 1])
b.append(arr[i - 1])
else:
b.append(-1)
if arr[-1] - a[-1] > 1:
a.append(arr[-1])
c = []
for i in range(1, len(a)):
if a[i] - a[i - 1] > 1:
for j in range(a[i - 1] + 1, a[i]):
c.append(j)
c = list(reversed(c))
for i in range(0, len(b)):
if b[i] == -1:
if len(c) == 0:
b[i] = arr[-1] + 1
else:
b[i] = c.pop()
return intJoin(b)
n = int(input())
arr = list(map(int, stdin.readline().split()))
print(answer(arr)) | FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST 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 IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR RETURN 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 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. | import sys
n = int(input())
a = list(map(int, input().split()))
b = [None] * n
ind = 0
mex = 0
for i in range(n):
if mex != a[i]:
for j in range(mex + 1, a[i]):
while ind < i and b[ind] != None:
ind += 1
if ind >= i:
print(-1)
sys.exit()
b[ind] = j
b[i] = mex
mex = a[i]
for i in range(n):
if b[i] == None:
b[i] = 10**6
print(*b) | IMPORT 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 NONE 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 NONE 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 VAR IF VAR VAR NONE ASSIGN VAR VAR BIN_OP NUMBER 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
pprint = lambda s: print(" ".join(map(str, s)))
input = lambda: sys.stdin.readline().strip()
ipnut = input
n = int(input())
a = [0] + list(map(int, input().split()))
ans = [-1] * n
used = set(a)
for i in range(n):
if a[i] != a[i + 1]:
ans[i] = a[i]
if a[i + 1] > i + 1:
print(-1)
exit(0)
curr = 0
for i in range(n):
if ans[i] == -1:
curr += 1
while curr in used:
curr += 1
ans[i] = curr
pprint(ans) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE 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. | import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
vis = [0] * (n + 1)
b = [-1] * n
for i in range(1, n):
if arr[i] != arr[i - 1]:
vis[arr[i - 1]] = 1
b[i] = arr[i - 1]
k = 0
vis[arr[-1]] = 1
for i in range(n):
if b[i] == -1:
while vis[k] == 1:
k += 1
b[i] = k
k += 1
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 BIN_OP 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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE 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. | n = int(input())
l = input().split()
li = [int(i) for i in l]
lo = [(0) for i in range(n)]
set = 0
done = [(0) for i in range(n)]
hashi = dict()
for i in li:
hashi[i] = 1
for i in range(n):
if li[i] != 0 and i == 0:
lo[i] = 0
done[i] = 1
hashi[0] = 1
continue
if li[i] != li[i - 1] and i != 0:
lo[i] = li[i - 1]
done[i] = 1
curr = 0
for i in range(n):
if done[i] != 0:
continue
while curr in hashi:
curr += 1
lo[i] = curr
curr += 1
for i in lo:
print(i, end=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER 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 VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR 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. | arr_len = int(input())
arr = list(map(int, input().split()))
res = [-1]
for i in range(arr_len - 1):
if arr[i] != arr[i + 1]:
res.append(arr[i])
else:
res.append(-1)
low = 0
arr_set = set(arr)
for i in range(arr_len):
if res[i] == -1:
while low in arr_set:
low += 1
res[i] = low
low += 1
for x in res:
print(x, 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL 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 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. | def ss(n, l):
if l != sorted(l) or l[-1] > n:
return [-1]
for i in range(n):
if l[i] > i + 1:
return [-1]
v = [(0) for _ in range(n + 1)]
ans = [(0) for _ in range(n)]
j = n
for i in range(n - 1, 0, -1):
v[l[i]] = 1
if l[i - 1] != l[i]:
ans[i] = l[i - 1]
else:
if v[j] == 1:
while v[j] == 1:
j -= 1
ans[i] = j
j -= 1
if l[0] == 0:
while v[j] == 1:
j -= 1
ans[0] = j
return ans
n = int(input())
l = list(map(int, input().split()))
print(*ss(n, l)) | FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR RETURN LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER RETURN LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR 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. | def f(n, l):
if l[0] > 1:
return -1
skipped = []
output = ["-"] * n
lowestpossible = 0
highestpossible = l[-1]
for i in range(n):
if l[i] > lowestpossible:
output[i] = lowestpossible
skipped += list(range(lowestpossible + 1, l[i]))
lowestpossible = l[i]
for i in range(n):
if output[i] == "-":
if len(skipped) == 0:
output[i] = highestpossible + 1
else:
output[i] = skipped.pop(0)
return " ".join([str(t) for t in output])
n = int(input())
l = [int(t) for t in input().split()]
print(f(n, l)) | FUNC_DEF IF VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR 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 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()))
flag = 1
v = [(False) for i in range(100001)]
for i in range(n):
v[a[i]] = True
if a[i] > i + 1:
print(-1)
flag = 0
break
if flag == 1:
b = [(-1) for i in range(n)]
for i in range(1, n):
if a[i] != a[i - 1]:
b[i] = a[i - 1]
v[a[i - 1]] = True
j = 0
for i in range(n):
if b[i] == -1:
while b[i] == -1 and j < 100001:
if v[j]:
j += 1
else:
b[i] = j
v[j] = True
for i in b:
print(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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER 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 VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR 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()))
def mex(n, a):
if a[0] > 1:
print(-1)
return
unuse = list(range(2 * 10**5 + 3, -1, -1))
used = set(a)
unused = [t for t in unuse if t not in used]
ret = []
i = 0
while i < len(a):
if i - 1 >= 0 and a[i] != a[i - 1]:
ret.append(a[i - 1])
if unused[-1] <= a[i]:
print(-1)
return
else:
ret.append(unused.pop())
i += 1
print(" ".join(map(str, ret)))
mex(n, a) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR 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(arr):
n = len(arr)
for a, b in zip(arr, arr[1:]):
if b - a < 0:
return [-1]
if any(a > i + 1 for i, a in enumerate(arr)):
return [-1]
seen = [False] * (n + 5)
for a in arr:
seen[a] = True
res = [0] * n
cur = 0
for i in range(n):
if i and arr[i] > arr[i - 1]:
res[i] = arr[i - 1]
else:
while seen[cur]:
cur += 1
res[i] = cur
cur += 1
return res
input()
arr = list(map(int, input().split()))
print(*solve(arr)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN LIST NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR RETURN LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN 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().split()))
b = []
c = []
d = dict()
for j in range(n):
if a[j] in d.keys():
d[a[j]] += 1
else:
d[a[j]] = 1
c.append(a[j])
j = 0
i = 0
while j < len(c):
p = c[j]
k = d[c[j]]
if j != 0:
b.append(c[j - 1])
k -= 1
p = 0
while p < k:
if i in d.keys():
pass
else:
b.append(i)
p += 1
i += 1
j += 1
if max(b) > 10**6:
print(-1)
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 LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP NUMBER 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())
a = list(map(int, input().split()))
k = 0
b = [0] * n
s = set(a)
t = [(False) for i in range(n)]
for i in range(1, n):
if a[i] != a[i - 1]:
b[i] = a[i - 1]
t[i] = True
m = 0
for i in range(n):
if not t[i]:
while True:
if m not in s:
b[i] = m
break
else:
m += 1
m += 1
for i in b:
print(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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR 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 VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER 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. | from sys import stdin
def iinput():
return int(stdin.readline())
def sinput():
return input()
def minput():
return map(int, stdin.readline().split())
def linput():
return list(map(int, stdin.readline().split()))
def fill_with(x):
if x not in s:
return True
return False
n = iinput()
a = linput()
s = set(a)
b = [0] * n
x = 0
while not fill_with(x):
x += 1
b[0] = x
x += 1
for i in range(1, n):
if a[i] > a[i - 1]:
b[i] = a[i - 1]
else:
while not fill_with(x):
x += 1
b[i] = x
x += 1
print(*b) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER 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 WHILE FUNC_CALL 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. | a = int(input())
b = [int(x) for x in input().split()]
impo = 0
uniq = []
notyet = []
if b[0] != 0:
notyet.append([0, b[0]])
k = [-1] * a
for i in range(a):
if i + 1 < b[i]:
impo = 1
break
if b[i] > b[i - 1]:
k[i] = b[i - 1]
uniq.append(k[i])
if b[i] - b[i - 1] != 1:
notyet.append([b[i - 1] + 1, b[i]])
notyeti = 0
lack = 0
if impo == 1:
print(-1)
else:
for i in range(a):
if k[i] == -1:
if notyeti < len(notyet):
k[i] = notyet[notyeti][0]
notyet[notyeti][0] += 1
if notyet[notyeti][0] == notyet[notyeti][1]:
notyeti += 1
else:
k[i] = b[-1] + 1
for i in k:
print(i, end=" ")
print() | 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 LIST ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER 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. | n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
if a[0] == 0 or a[0] == 1:
maxi = -1
if a[0] == 1:
b[0] = 0
maxi = 0
for i in range(1, n):
if a[i] != a[i - 1]:
b[i] = a[i - 1]
tofill = []
i = 0
while i < n:
if b[i] == -1:
tofill.append(i)
elif b[i] != -1 and len(tofill) != 0:
maxi = max(maxi, a[i - 1])
for j in range(len(tofill)):
if maxi != a[i] - 1:
b[tofill[0]] = maxi + 1
tofill.pop(0)
maxi += 1
else:
break
if maxi != a[i] - 1:
print(-1)
break
i += 1
if len(tofill) == 0 and b.count(-1) != 0:
pass
else:
maxi = a[-1]
for i in range(len(tofill)):
b[tofill[i]] = maxi + 1
maxi += 1
print(*b)
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 BIN_OP LIST NUMBER VAR IF VAR NUMBER NUMBER VAR NUMBER 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 ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER 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())
mas = list(map(int, input().split()))
ans = []
have = [(0) for i in range(1000009)]
for i in range(n):
if i > 0 and mas[i - 1] != mas[i]:
ans.append(mas[i - 1])
have[mas[i - 1]] = 1
else:
ans.append(-1)
j = 0
have[mas[n - 1]] = 1
for i in range(len(ans)):
if ans[i] == -1:
while have[j]:
j += 1
ans[i] = j
have[j] = 1
if mas[0] > 1:
print(-1)
else:
for x in ans:
print(x, 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 VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER 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. | n = int(input())
a = list(map(int, input().split()))
m = int(1000000.0)
b = [-1] * n
e = 0
v = [0] * m
for i in range(n):
if a[i] != e:
b[i] = e
v[e] = 1
e = a[i]
v[e] = 1
k = 0
for i in range(n):
while v[k] == 1:
k += 1
if b[i] == -1:
b[i] = k
v[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 FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR 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. | n = int(input())
a = list(map(int, input().split()))
ok = a[0] - 1 <= 0
for i in range(1, n):
if a[i] - 1 > i:
ok = False
if a[i] < a[i - 1]:
ok = False
if ok == False:
print(-1)
quit()
m = set(a)
b = []
s = 0
for i in range(s, n + 10):
if i not in m:
b.append(i)
s = i + 1
break
for i in range(1, n):
if a[i] != a[i - 1]:
b.append(a[i - 1])
continue
for j in range(s, n + 10):
if j not in m:
b.append(j)
s = j + 1
break
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 BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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 FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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. | import sys
def rs():
return sys.stdin.readline().rstrip()
def ri():
return int(sys.stdin.readline())
def ria():
return list(map(int, sys.stdin.readline().split()))
def ws(s):
sys.stdout.write(s + "\n")
def wi(n):
sys.stdout.write(str(n) + "\n")
def wia(a):
sys.stdout.write(" ".join([str(x) for x in a]) + "\n")
def solve(n, a):
d = {}
for ai in a:
if ai not in d:
d[ai] = 0
d[ai] += 1
c = []
i = 0
while len(c) < n:
if i not in d:
c.append(i)
i += 1
b = [0] * n
k = 0
for i in range(n):
if i == 0:
b[i] = c[k]
k += 1
elif a[i] != a[i - 1]:
b[i] = a[i - 1]
else:
b[i] = c[k]
k += 1
return b
def main():
n = ri()
a = ria()
res = solve(n, a)
if res == -1:
wi(-1)
else:
wia(res)
main() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL 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 EXPR FUNC_CALL VAR BIN_OP VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR STRING FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL 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. | n = int(input())
ans = [-1] * n
se = set()
lis = list(map(int, input().split()))
length = len(lis)
for i in range(length - 1, 0, -1):
if lis[i - 1] != lis[i]:
ans[i] = lis[i - 1]
se.add(lis[i - 1])
if lis[0] > 1:
print(-1)
exit()
i = 0
se.add(lis[-1])
j = 0
while True:
if j == length:
break
if i in se:
i += 1
continue
if ans[j] != -1:
j += 1
continue
ans[j] = i
j += 1
i += 1
for i in ans:
print(i, end=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER 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. | R = lambda: map(int, input().split())
n = int(input())
arr = list(R()) + [0]
res = [-1] * (n + 1)
slots = []
for i in range(n):
slots.append(i)
if arr[i] != arr[i - 1]:
cur = arr[i - 1]
while slots and cur < arr[i]:
res[slots.pop()] = cur
cur += 1
if cur != arr[i]:
print(-1)
exit(0)
print(" ".join(map(str, [(x if x != -1 else 10**6) for x in res[:n]]))) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP NUMBER NUMBER 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
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a = [0] + a
cnt = 0
x = []
for i in range(n):
if a[i + 1] - a[i] >= 2:
cnt += -(a[i + 1] - a[i]) + 1
for j in range(a[i] + 1, a[i + 1]):
x.append(j)
elif a[i + 1] == a[i]:
cnt += 1
if cnt < 0:
print(-1)
exit()
ans = [0] * n
cnt = 0
for i in range(n):
if a[i + 1] - a[i] == 1:
ans[i] = a[i]
elif cnt < len(x) and a[i + 1] == a[i]:
ans[i] += x[cnt]
cnt += 1
elif a[i + 1] - a[i] >= 2:
ans[i] = a[i]
else:
ans[i] = pow(10, 6)
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 LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER 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
read = lambda: sys.stdin.readline()
n = int(read())
arr = list(map(int, read().split()))
result = [(-1) for i in range(n)]
for i in range(n - 1, 0, -1):
if arr[i] > arr[i - 1]:
result[i] = arr[i - 1]
if arr[0] == 1:
result[0] = 0
haves = set([])
free = 0
while free < n and result[free] != -1:
free += 1
impossible = False
for i in range(1, n):
if result[i] == -1:
continue
haves.add(result[i])
for j in range(arr[i - 1], arr[i]):
if not j in haves:
if free > i:
impossible = True
result[free] = j
haves.add(j)
free += 1
while free < n and result[free] != -1:
free += 1
for i in range(n):
if result[i] == -1:
result[i] = 100001
if impossible:
print(-1)
else:
for i in range(n - 1):
print(result[i], end=" ")
print(result[-1]) | IMPORT ASSIGN VAR FUNC_CALL 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 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 IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING 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. | from sys import stdin, stdout
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().strip().split(" ")))
p = True
for i in range(len(arr)):
if arr[i] > i + 1:
p = False
if not p:
stdout.write("-1\n")
else:
arr += [arr[-1] + 1]
av = [(1) for i in range(len(arr) + 10)]
tarr = [(-1) for i in range(len(arr))]
for i in range(1, len(arr)):
if arr[i] != arr[i - 1]:
tarr[i] = arr[i - 1]
av[arr[i - 1]] = 0
ctr = 0
for i in range(len(tarr)):
if tarr[i] == -1:
while av[ctr] == 0:
ctr += 1
tarr[i] = ctr
ctr += 1
stdout.write(" ".join(list(map(str, tarr[:-1]))) + "\n") | 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 STRING 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 STRING VAR LIST BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER STRING |
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they correspond to the integer numbers from $0$ to $n - 1$ on the OX axis. However, some positions are blocked and no post lamp can be placed there.
There are post lamps of different types which differ only by their power. When placed in position $x$, post lamp of power $l$ illuminates the segment $[x; x + l]$. The power of each post lamp is always a positive integer number.
The post lamp shop provides an infinite amount of lamps of each type from power $1$ to power $k$. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power $l$ cost $a_l$ each.
What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power $3$ in position $n - 1$ (even though its illumination zone doesn't completely belong to segment $[0; n]$).
-----Input-----
The first line contains three integer numbers $n$, $m$ and $k$ ($1 \le k \le n \le 10^6$, $0 \le m \le n$) β the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available.
The second line contains $m$ integer numbers $s_1, s_2, \dots, s_m$ ($0 \le s_1 < s_2 < \dots s_m < n$) β the blocked positions.
The third line contains $k$ integer numbers $a_1, a_2, \dots, a_k$ ($1 \le a_i \le 10^6$) β the costs of the post lamps.
-----Output-----
Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street.
If illumintaing the entire segment $[0; n]$ is impossible, print -1.
-----Examples-----
Input
6 2 3
1 3
1 2 3
Output
6
Input
4 3 4
1 2 3
1 10 100 1000
Output
1000
Input
5 1 5
0
3 3 3 3 3
Output
-1
Input
7 4 3
2 4 5 6
3 14 15
Output
-1 | import sys
from sys import stdin, stdout
n, m, k = list(map(int, stdin.readline().split(" ")))
t22 = stdin.readline()
bl = []
if len(t22.strip()) == 0:
bl = []
else:
bl = list(map(int, t22.split(" ")))
bd = {}
for i in bl:
bd[i] = 1
cost = list(map(int, stdin.readline().split(" ")))
dp = [(-1) for i in range(n)]
dp[0] = 0
def formdp():
nonlocal dp
for i in range(1, n):
if i in bd:
t1 = i
while dp[t1] == -1:
t1 -= 1
dp[i] = dp[t1]
else:
dp[i] = i
def get(i):
f = 1
p = 0
while p + i < n:
if dp[p + i] == p:
return -1
else:
p = dp[p + i]
f += 1
return f
if True:
if 0 in bd:
print(-1)
else:
formdp()
minf = [(0) for i in range(k + 1)]
for i in range(1, k + 1):
minf[i] = get(i)
ans = -1
for i in range(1, len(minf)):
if minf[i] != -1:
if ans == -1:
ans = minf[i] * cost[i - 1]
else:
ans = min(ans, minf[i] * cost[i - 1])
if ans == -1:
print(-1)
else:
print(ans) | IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST IF FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR IF NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they correspond to the integer numbers from $0$ to $n - 1$ on the OX axis. However, some positions are blocked and no post lamp can be placed there.
There are post lamps of different types which differ only by their power. When placed in position $x$, post lamp of power $l$ illuminates the segment $[x; x + l]$. The power of each post lamp is always a positive integer number.
The post lamp shop provides an infinite amount of lamps of each type from power $1$ to power $k$. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power $l$ cost $a_l$ each.
What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power $3$ in position $n - 1$ (even though its illumination zone doesn't completely belong to segment $[0; n]$).
-----Input-----
The first line contains three integer numbers $n$, $m$ and $k$ ($1 \le k \le n \le 10^6$, $0 \le m \le n$) β the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available.
The second line contains $m$ integer numbers $s_1, s_2, \dots, s_m$ ($0 \le s_1 < s_2 < \dots s_m < n$) β the blocked positions.
The third line contains $k$ integer numbers $a_1, a_2, \dots, a_k$ ($1 \le a_i \le 10^6$) β the costs of the post lamps.
-----Output-----
Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street.
If illumintaing the entire segment $[0; n]$ is impossible, print -1.
-----Examples-----
Input
6 2 3
1 3
1 2 3
Output
6
Input
4 3 4
1 2 3
1 10 100 1000
Output
1000
Input
5 1 5
0
3 3 3 3 3
Output
-1
Input
7 4 3
2 4 5 6
3 14 15
Output
-1 | n, m, k = map(int, input().split())
free = [True] * n
for i in list(map(int, input().split())):
free[i] = False
a = list(map(int, input().split()))
last_lamp = [-1] * n
for i in range(n):
if free[i]:
last_lamp[i] = i
if i > 0 and not free[i]:
last_lamp[i] = last_lamp[i - 1]
ans = int(1e100)
for i in range(1, k + 1):
last, prev = 0, -1
cur = 0
while last < n:
if last_lamp[last] <= prev:
cur = None
break
prev = last_lamp[last]
last = prev + i
cur += 1
if cur is not None:
ans = min(ans, a[i - 1] * cur)
if ans == int(1e100):
print(-1)
else:
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER 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 VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they correspond to the integer numbers from $0$ to $n - 1$ on the OX axis. However, some positions are blocked and no post lamp can be placed there.
There are post lamps of different types which differ only by their power. When placed in position $x$, post lamp of power $l$ illuminates the segment $[x; x + l]$. The power of each post lamp is always a positive integer number.
The post lamp shop provides an infinite amount of lamps of each type from power $1$ to power $k$. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power $l$ cost $a_l$ each.
What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power $3$ in position $n - 1$ (even though its illumination zone doesn't completely belong to segment $[0; n]$).
-----Input-----
The first line contains three integer numbers $n$, $m$ and $k$ ($1 \le k \le n \le 10^6$, $0 \le m \le n$) β the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available.
The second line contains $m$ integer numbers $s_1, s_2, \dots, s_m$ ($0 \le s_1 < s_2 < \dots s_m < n$) β the blocked positions.
The third line contains $k$ integer numbers $a_1, a_2, \dots, a_k$ ($1 \le a_i \le 10^6$) β the costs of the post lamps.
-----Output-----
Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street.
If illumintaing the entire segment $[0; n]$ is impossible, print -1.
-----Examples-----
Input
6 2 3
1 3
1 2 3
Output
6
Input
4 3 4
1 2 3
1 10 100 1000
Output
1000
Input
5 1 5
0
3 3 3 3 3
Output
-1
Input
7 4 3
2 4 5 6
3 14 15
Output
-1 | import sys
n, m, k = list(map(int, input().split()))
s = list(map(int, sys.stdin.readline().split()))
a = list(map(int, sys.stdin.readline().split()))
if m > 0 and s[0] == 0:
print("-1")
else:
block = [-1] * n
for i in range(m):
if block[s[i] - 1] == -1:
block[s[i]] = s[i] - 1
else:
block[s[i]] = block[s[i] - 1]
MAX_COST = 10000000000000.0
max_inr = 0
if m > 0:
inr = 1
prev = s[0]
for i in range(1, m):
if s[i] == prev + 1:
inr += 1
else:
if inr > max_inr:
max_inr = inr
inr = 1
prev = s[i]
if inr > max_inr:
max_inr = inr
best_cost = []
for i in range(k):
if i < max_inr:
best_cost.append(MAX_COST)
else:
best_cost.append(a[i] * -(-n // (i + 1)))
min_cost = MAX_COST
for i in range(k):
test = i
if best_cost[test] >= min_cost:
continue
t_size = test + 1
pos = 0
count = 1
while pos < n:
new_pos = pos + t_size
if new_pos >= n:
break
if block[new_pos] != -1:
if block[new_pos] <= pos:
raise Exception("smth went wrong")
new_pos = block[new_pos]
pos = new_pos
count += 1
min_cost = min(min_cost, a[test] * count)
if min_cost < MAX_COST:
print(min_cost)
else:
print("-1") | IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they correspond to the integer numbers from $0$ to $n - 1$ on the OX axis. However, some positions are blocked and no post lamp can be placed there.
There are post lamps of different types which differ only by their power. When placed in position $x$, post lamp of power $l$ illuminates the segment $[x; x + l]$. The power of each post lamp is always a positive integer number.
The post lamp shop provides an infinite amount of lamps of each type from power $1$ to power $k$. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power $l$ cost $a_l$ each.
What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power $3$ in position $n - 1$ (even though its illumination zone doesn't completely belong to segment $[0; n]$).
-----Input-----
The first line contains three integer numbers $n$, $m$ and $k$ ($1 \le k \le n \le 10^6$, $0 \le m \le n$) β the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available.
The second line contains $m$ integer numbers $s_1, s_2, \dots, s_m$ ($0 \le s_1 < s_2 < \dots s_m < n$) β the blocked positions.
The third line contains $k$ integer numbers $a_1, a_2, \dots, a_k$ ($1 \le a_i \le 10^6$) β the costs of the post lamps.
-----Output-----
Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street.
If illumintaing the entire segment $[0; n]$ is impossible, print -1.
-----Examples-----
Input
6 2 3
1 3
1 2 3
Output
6
Input
4 3 4
1 2 3
1 10 100 1000
Output
1000
Input
5 1 5
0
3 3 3 3 3
Output
-1
Input
7 4 3
2 4 5 6
3 14 15
Output
-1 | def i_ints():
return list(map(int, input().split()))
def next_free_from_blocks(n, blocks):
m = 0
res = list(range(n + 1))
for i in reversed(blocks):
res[i] = res[i + 1]
if res[i] - i > m:
m = res[i] - i
return res, m
n, m, k = i_ints()
blocks = i_ints()
costs = i_ints()
next_free, max_block_len = next_free_from_blocks(n, blocks)
blocks.append(n + 1)
if m == 0:
max_block_len = 0
if max_block_len >= k or blocks[0] == 0:
print(-1)
else:
minimal_costs = [(c * ((n + l - 1) // l)) for l, c in enumerate(costs, 1)]
maximal_costs = [(c * 2 * ((n + l) // (l + 1))) for l, c in enumerate(costs, 1)]
max_costs = min(maximal_costs[max_block_len:])
possible = [
(i + 1) for i in range(max_block_len, k) if minimal_costs[i] <= max_costs
]
for i in range(len(possible) - 1)[::-1]:
if costs[possible[i] - 1] > costs[possible[i + 1] - 1]:
del possible[i]
def calc(l):
count = 1
pos = n - l
while pos > 0:
pos = next_free[pos] - l
count += 1
return count
print(min(calc(l) * costs[l - 1] for l in possible)) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR |
You are given an n Γ m table, consisting of characters Β«AΒ», Β«GΒ», Β«CΒ», Β«TΒ». Let's call a table nice, if every 2 Γ 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of Β«AΒ», Β«GΒ», Β«CΒ», Β«TΒ»), that differs from the given table in the minimum number of characters.
Input
First line contains two positive integers n and m β number of rows and columns in the table you are given (2 β€ n, m, n Γ m β€ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters Β«AΒ», Β«GΒ», Β«CΒ», Β«TΒ».
Output
Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.
Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
Note
In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice. | from itertools import permutations
from sys import stdin, stdout
ly, lx = map(int, input().split())
grid = [[c for c in inp] for inp in stdin.read().splitlines()]
first = set()
bl = []
bpattern = []
bcost = 1000000.0
flip_row = False
for l in permutations("AGCT"):
if bcost == 0:
break
if "".join(l[:2]) in first:
continue
first |= set(["".join(l[:2]), "".join(l[1::-1])])
cost = 0
pattern = [0] * ly
for i in range(ly):
diff1, diff2 = 0, 0
for j in range(lx):
if grid[i][j] != l[((i & 1) << 1) + (j & 1)]:
diff1 += 1
if grid[i][j] != l[((i & 1) << 1) + ((j ^ 1) & 1)]:
diff2 += 1
cost += min(diff1, diff2)
if diff1 >= diff2:
pattern[i] = 1
if cost < bcost:
bcost = cost
bpattern = pattern.copy()
flip_row = True
bl = l
cost = 0
pattern = [0] * lx
for j in range(lx):
diff1 = diff2 = 0
for i in range(ly):
if grid[i][j] != l[((j & 1) << 1) + (i & 1)]:
diff1 += 1
if grid[i][j] != l[((j & 1) << 1) + ((i ^ 1) & 1)]:
diff2 += 1
cost += min(diff1, diff2)
if diff1 >= diff2:
pattern[j] = 1
if cost < bcost:
bcost = cost
bpattern = pattern.copy()
flip_row = False
bl = l
if flip_row:
for i in range(ly):
grid[i] = "".join(
[bl[((i & 1) << 1) + ((j ^ bpattern[i]) & 1)] for j in range(lx)]
)
else:
for i in range(ly):
grid[i] = "".join(
[bl[((j & 1) << 1) + ((i ^ bpattern[j]) & 1)] for j in range(lx)]
)
print("\n".join("".join(k for k in grid[i]) for i in range(ly))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL STRING VAR NUMBER VAR VAR FUNC_CALL VAR LIST FUNC_CALL STRING VAR NUMBER FUNC_CALL STRING VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL STRING VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL STRING VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING VAR VAR VAR VAR VAR FUNC_CALL VAR VAR |
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon.
Elections are coming. You know the number of voters and the number of parties β n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter c_i bytecoins you can ask him to vote for any other party you choose.
The United Party of Berland has decided to perform a statistical study β you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party.
Input
The first line of input contains two integers n and m (1 β€ n, m β€ 3000) β the number of voters and the number of parties respectively.
Each of the following n lines contains two integers p_i and c_i (1 β€ p_i β€ m, 1 β€ c_i β€ 10^9) β the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision.
The United Party of Berland has the index 1.
Output
Print a single number β the minimum number of bytecoins needed for The United Party of Berland to win the elections.
Examples
Input
1 2
1 100
Output
0
Input
5 5
2 100
3 200
4 300
5 400
5 900
Output
500
Input
5 5
2 100
3 200
4 300
5 800
5 900
Output
600
Note
In the first sample, The United Party wins the elections even without buying extra votes.
In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 3, 4 and 5 get one vote and party number 2 gets no votes.
In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party. | import sys
zz = 1
sys.setrecursionlimit(10**5)
if zz:
input = sys.stdin.readline
else:
sys.stdin = open("input.txt", "r")
sys.stdout = open("all.txt", "w")
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]
def fori(n):
return [fi() for i in range(n)]
def inc(d, c, x=1):
d[c] = d[c] + x if c in d else x
def ii():
return input().rstrip()
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def dadd(d, p, val):
if p in d:
d[p].append(val)
else:
d[p] = [val]
def gi():
return [xx for xx in input().split()]
def gtc(tc, *ans):
print("Case #" + str(tc) + ":", *ans)
def cil(n, m):
return n // m + int(n % m > 0)
def fi():
return int(input())
def pro(a):
return reduce(lambda a, b: a * b, a)
def swap(a, i, j):
a[i], a[j] = a[j], a[i]
def bits(i, n):
p = bin(i)[2:]
return (n - len(p)) * "0" + p
def prec(a, pre):
for i in a:
pre.append(pre[-1] + i)
pre.pop(0)
def YN(flag):
print("YES" if flag else "NO")
def si():
return list(input().rstrip())
def mi():
return map(int, input().split())
def gh():
sys.stdout.flush()
def isvalid(i, j, n, m):
return 0 <= i < n and 0 <= j < m
def bo(i):
return ord(i) - ord("a")
def graph(n, m):
for i in range(m):
x, y = mi()
a[x].append(y)
a[y].append(x)
t = 1
INF = 10**18
uu = t
mod = 10**9 + 7
while t > 0:
t -= 1
n, m = mi()
d = {}
freq = {}
for i in range(1, m + 1):
freq[i] = 0
d[i] = []
for i in range(n):
x, y = mi()
dadd(d, x, y)
inc(freq, x)
for i in range(2, m + 1):
if i in d:
d[i].sort()
ber = freq[1]
mini = 10**18
for i in range(n - ber + 1):
actual = ber + i
a = []
totneed = i
flag = ans = 0
for j in d:
if j == 1:
continue
if freq[j] - totneed >= actual:
flag = 1
break
for k in range(max(0, freq[j] - actual + 1)):
ans += d[j][k]
for k in range(max(0, freq[j] - actual + 1), len(d[j])):
a.append(d[j][k])
totneed -= max(0, freq[j] - actual + 1)
if flag == 1:
continue
a.sort()
for j in range(totneed):
ans += a[j]
mini = min(mini, ans)
print(mini) | IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING VAR FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR STRING STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF RETURN NUMBER VAR VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon.
Elections are coming. You know the number of voters and the number of parties β n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter c_i bytecoins you can ask him to vote for any other party you choose.
The United Party of Berland has decided to perform a statistical study β you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party.
Input
The first line of input contains two integers n and m (1 β€ n, m β€ 3000) β the number of voters and the number of parties respectively.
Each of the following n lines contains two integers p_i and c_i (1 β€ p_i β€ m, 1 β€ c_i β€ 10^9) β the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision.
The United Party of Berland has the index 1.
Output
Print a single number β the minimum number of bytecoins needed for The United Party of Berland to win the elections.
Examples
Input
1 2
1 100
Output
0
Input
5 5
2 100
3 200
4 300
5 400
5 900
Output
500
Input
5 5
2 100
3 200
4 300
5 800
5 900
Output
600
Note
In the first sample, The United Party wins the elections even without buying extra votes.
In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 3, 4 and 5 get one vote and party number 2 gets no votes.
In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party. | import sys
f = sys.stdin
out = sys.stdout
n, m = map(int, f.readline().rstrip("\r\n").split())
cos = {}
cost = []
nvot = [(0) for i in range(m + 1)]
party = [[] for i in range(m + 1)]
for i in range(n):
p, c = map(int, f.readline().rstrip("\r\n").split())
if p != 1:
if c in cos:
cos[c] += 1
else:
cos[c] = 1
cost.append(c)
party[p].append(c)
nvot[p] += 1
cost.sort()
for i in party:
i.sort()
mi = float("inf")
for x in range(1, n + 1):
dcos = dict(cos)
tmp = 0
vot = nvot[1]
for j in range(2, m + 1):
if nvot[j] >= x:
for k in range(nvot[j] - x + 1):
vot += 1
tmp += party[j][k]
dcos[party[j][k]] -= 1
j = 0
while vot < x:
if dcos[cost[j]] > 0:
dcos[cost[j]] -= 1
tmp += cost[j]
vot += 1
j += 1
mi = min(mi, tmp)
out.write(str(mi) + "\n") | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | a = list(map(int, input()))
b = a[:3]
a = a[3:]
if sum(a) > sum(b):
a, b = b, a
d = sum(b) - sum(a)
if d == 0:
print(0)
exit()
t = list(b)
for i in a:
t.append(9 - i)
for i, j in enumerate(sorted(t, reverse=True)):
d -= j
if d <= 0:
print(i + 1)
break | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | s = input()
a = [int(x) for x in s[:3]]
b = [int(x) for x in s[3:]]
a.sort()
b.sort()
if sum(a) > sum(b):
a, b = b, a
if sum(a) == sum(b):
print(0)
exit()
dt = sum(b) - sum(a)
diffs = []
for i in a:
diffs.append(9 - i)
diffs.extend(b)
diffs.sort()
i = 0
while dt > 0:
dt -= diffs[5 - i]
i += 1
print(i) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | num = input()
p1 = sorted([int(x) for x in num[:3]])
p2 = sorted([int(x) for x in num[3:]])
c1 = p1[:] if sum(p1) < sum(p2) else p2[:]
c2 = list(reversed(p1[:] if sum(p1) > sum(p2) else p2[:]))
_min = 0
while sum(c1) < sum(c2):
if 9 - min(c1) > max(c2):
c1[c1.index(min(c1))] = 9
else:
c2[c2.index(max(c2))] = 0
_min += 1
print(_min) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | n = input()
m = len(n)
arr = []
arr1 = []
a = int(n[0])
b = int(n[1])
c = int(n[2])
x = int(n[m - 3])
y = int(n[m - 2])
z = int(n[m - 1])
p = a + b + c
q = x + y + z
if p == q:
print(0)
exit()
arr = [a, b, c]
arr1 = [x, y, z]
arr.sort()
arr1.sort()
i = 0
j = 0
if p > q:
i = 2
j = 0
s = p - q
s1 = s
s2 = s
count = 0
count1 = 0
while 1:
if 9 - arr1[j] < s:
count += 1
s1 = s1 - (9 - arr1[j])
else:
count += 1
print(count + count1)
exit()
if arr[i] < s:
count1 += 1
s2 = s2 - arr[i]
else:
count1 += 1
print(count1 + count - 1)
exit()
if s1 <= s2:
s = s1
j += 1
count1 -= 1
else:
s = s2
i -= 1
count -= 1
print(count + count1)
else:
j = 2
i = 0
s = q - p
s1 = s
s2 = s
count = 0
count1 = 0
while 1:
if 9 - arr[i] < s:
count += 1
s1 = s1 - (9 - arr[i])
else:
count += 1
print(count + count1)
exit()
if arr1[j] < s:
count1 += 1
s2 = s2 - arr1[j]
else:
count1 += 1
print(count1 + count - 1)
exit()
if s1 <= s2:
s = s1
i += 1
count1 -= 1
else:
s = s2
j -= 1
count -= 1
print(count + count1) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | s = list(input())
l1 = []
l2 = []
l = []
a, sa = 0, 0
for i in range(3):
l1.append(int(s[i]))
l2.append(int(s[i + 3]))
if sum(l1) > sum(l2):
l1, l2 = l2, l1
d = sum(l2) - sum(l1)
for i in range(3):
l.append(9 - l1[i])
l.append(l2[i])
l.sort()
for i in range(5, -1, -1):
if sa >= d:
break
sa += l[i]
a += 1
print(a) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | def Main():
dig = 0
n = input()
n1 = list(map(int, list(n[:3])))
n2 = list(map(int, list(n[3:])))
n1 = sorted(n1)
n2 = sorted(n2)
delta = sum(n1) - sum(n2)
if delta != 0:
if delta < 0:
n1, n2, delta = n2, n1, abs(delta)
ind1 = 2
ind2 = 0
while ind1 > -1 and ind2 < 3 and delta > 0:
if n1[ind1] >= 9 - n2[ind2]:
delta = delta - n1[ind1]
ind1 = ind1 - 1
dig = dig + 1
else:
delta = delta - (9 - n2[ind2])
ind2 = ind2 + 1
dig = dig + 1
print(dig)
Main() | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | s = input()
left = [int(s[0]), int(s[1]), int(s[2])]
right = [int(s[3]), int(s[4]), int(s[5])]
s1 = sum(left)
s2 = sum(right)
if s1 > s2:
t = left
left = right
right = t
s1 = sum(left)
s2 = sum(right)
if s1 == s2:
print(0)
else:
dif = s2 - s1
if (
left[0] + dif <= 9
or left[1] + dif <= 9
or left[2] + dif <= 9
or right[0] - dif >= 0
or right[1] - dif >= 0
or right[2] - dif >= 0
):
print(1)
elif (
left[0] + left[1] + dif <= 18
or left[1] + left[2] + dif <= 18
or left[2] + left[0] + dif <= 18
or right[0] + right[1] - dif >= 0
or right[1] + right[2] - dif >= 0
or right[2] + right[0] - dif >= 0
):
print(2)
else:
ans = 3
for i in range(3):
for j in range(3):
if dif - right[j] <= 9 - left[i]:
ans = 2
break
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | digits = list(map(int, input().strip()))
left = digits[:3]
ls = sum(left)
right = digits[3:]
rs = sum(right)
if ls > rs:
rs, ls = ls, rs
left, right = right, left
left.sort()
right.sort(key=lambda x: -x)
i = 0
j = 0
while ls < rs:
if 9 - left[i] > right[j]:
ls = ls - left[i] + 9
i += 1
else:
rs = rs - right[j]
j += 1
print(i + j) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | def solution():
s = input()
a = [int(i) for i in s[:3]]
b = [int(i) for i in s[3:]]
if sum(b) == sum(a):
print(0)
return
if sum(a) > sum(b):
a, b = b, a
dt = sum(b) - sum(a)
diffs = []
for i in a:
diffs.append(9 - i)
diffs.extend(b)
diffs.sort(reverse=True)
i = 0
while dt > 0:
dt -= diffs[i]
i += 1
print(i)
solution() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | digit_set = set(range(10))
double_digit_set = set(range(19))
A = [int(i) for i in input()]
first_sum = sum(A[:3])
second_sum = sum(A[3:])
one_flag = True
exit_flag = False
if first_sum == second_sum:
print(0)
else:
for i in range(6):
if i < 3:
if second_sum - (first_sum - A[i]) in digit_set:
print(1)
one_flag = False
break
elif first_sum - (second_sum - A[i]) in digit_set:
print(1)
one_flag = False
break
if one_flag:
for i in range(6):
for j in range(i + 1, 6):
if i < 3 and j < 3:
if second_sum - (first_sum - A[i] - A[j]) in double_digit_set:
print(2)
exit_flag = True
break
if i >= 3 and j >= 3:
if first_sum - (second_sum - A[i] - A[j]) in double_digit_set:
print(2)
exit_flag = True
break
elif abs(first_sum - A[i] - second_sum + A[j]) <= 9:
print(2)
exit_flag = True
break
if exit_flag:
break
else:
print(3) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | a = [int(i) for i in input()]
def f1(a):
for i in range(6):
for j in range(1, 10):
b = [i for i in a]
b[i] += j
b[i] %= 10
if f0(b):
return True
return False
def f0(a):
return sum(a[:3]) == sum(a[3:])
def f2(a):
for i1 in range(5):
for i2 in range(i1 + 1, 6):
for j1 in range(1, 10):
for j2 in range(1, 10):
b = [i for i in a]
b[i1] += j1
b[i2] += j2
b[i1] %= 10
b[i2] %= 10
if f0(b):
return True
return False
if f0(a):
print(0)
elif f1(a):
print(1)
elif f2(a):
print(2)
else:
print(3) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | s = input()
l = []
for d in s[:3]:
l.append(int(d))
u = []
for d in s[3:]:
u.append(int(d))
if sum(l) == sum(u):
print(0)
else:
if sum(l) > sum(u):
l, u = u, l
diffs = sorted(list(map(lambda x: 9 - x, l)) + u)[::-1]
for i in range(1, 7):
if sum(diffs[:i]) >= sum(u) - sum(l):
print(i)
break | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | def lucky(s):
ds = []
while s:
ds.append(s % 10)
s //= 10
while len(ds) < 6:
ds.append(0)
return ds[0] + ds[1] + ds[2] == ds[3] + ds[4] + ds[5]
def difs(a, b):
d = 0
while a or b:
if a % 10 != b % 10:
d += 1
a //= 10
b //= 10
return d
def main():
s = int(input())
min_difs = 10
end = 10**6
for s_t in range(0, end):
if lucky(s_t):
min_difs = min(min_difs, difs(s, s_t))
if min_difs == 0:
break
print(min_difs)
def __starting_point():
main()
__starting_point() | FUNC_DEF ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | t = input()
a = []
for i in range(6):
a.append(int(t[i]))
m = 27
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
for r in range(10):
for o in range(10):
if i + j + k == l + r + o:
x = 0
if a[0] != i:
x += 1
if a[1] != j:
x += 1
if a[2] != k:
x += 1
if a[3] != l:
x += 1
if a[4] != r:
x += 1
if a[5] != o:
x += 1
m = min(x, m)
print(m) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | def main():
n = input()
pre = n[0:3]
post = n[3:6]
pre_sum = Sum(int(pre))
post_sum = Sum(int(post))
mi = []
if pre_sum == post_sum:
return 0
if pre_sum > post_sum:
diff = pre_sum - post_sum
mi = list(map(int, post))
ma = list(map(int, pre))
else:
diff = post_sum - pre_sum
mi = list(map(int, pre))
ma = list(map(int, post))
count = 0
while diff:
inc = 9 - min(mi)
dec = max(ma) - 0
if diff > inc and inc >= dec:
count += 1
mi[mi.index(min(mi))] = 9
diff -= inc
if diff > dec and inc < dec:
count += 1
ma[ma.index(max(ma))] = 0
diff -= dec
if diff <= max(ma) - 0 or diff <= 9 - min(mi):
diff = 0
return count + 1
def Sum(n):
s = 0
while n:
s += n % 10
n = n // 10
return s
print(main()) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | arr = list(map(int, input()))
if sum(arr[:3]) > sum(arr[3:6]):
arr = arr[3:6] + arr[:3]
diff = sum(arr[3:6]) - sum(arr[:3])
cnt = 0
tmparr = []
for i in range(3):
tmparr.append(9 - arr[i])
for i in range(3, 6):
tmparr.append(arr[i])
tmparr.sort()
for item in tmparr[::-1]:
if diff <= 0:
print(cnt)
diff = 1
break
diff -= item
cnt += 1
if diff <= 0:
print(cnt) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | import itertools
def sump(a: list, p: list):
s = 0
for i in range(0, 3):
if p.count(i) == 0:
s = s + a[i]
for i in range(3, 6):
if p.count(i) == 0:
s = s - a[i]
return s
def diffsum(p: list):
mins = 0
maxs = 0
for i in p:
if i <= 2:
maxs = maxs + 9
else:
mins = mins - 9
return [mins, maxs]
def solve():
s = input().replace("\r\n", "")
a = []
for ai in s:
a.append(int(ai))
p = [0, 1, 2, 3, 4, 5]
if sump(a, []) == 0:
print("0")
return
for i in range(1, 7):
for pi in itertools.combinations(p, i):
s = -sump(a, pi)
rs = diffsum(pi)
if s >= rs[0] and s <= rs[1]:
print(i)
return
print("error")
solve() | IMPORT FUNC_DEF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN LIST VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR LIST NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | s = list(input())
a = list(map(int, s[:3]))
b = list(map(int, s[3:]))
p = sum(a)
q = sum(b)
if p == q:
print(0)
elif p > q:
diff = p - q
num1 = 0
b = sorted(b)
a = sorted(a, reverse=True)
diff -= 9 - b[0]
if diff <= 0:
num1 = 1
else:
diff -= 9 - b[1]
if diff <= 0:
num1 = 2
else:
num1 = 3
diff = p - q - (9 - b[0])
diff -= a[0]
if diff <= 0:
num1 = min(num1, 2)
else:
num1 = min(num1, 3)
diff = p - q
diff -= a[0]
if diff <= 0:
num2 = min(1, num1)
else:
diff -= a[1]
if diff <= 0:
num2 = min(2, num1)
else:
num2 = min(3, num1)
diff = p - q - a[0]
diff -= 9 - b[0]
if diff <= 0:
num2 = min(num2, 2)
else:
num2 = min(num2, 3)
print(num2)
else:
diff = q - p
num1 = 0
a = sorted(a)
b = sorted(b, reverse=True)
diff -= 9 - a[0]
if diff <= 0:
num1 = 1
else:
diff -= 9 - a[1]
if diff <= 0:
num1 = 2
else:
num1 = 3
diff = q - p - (9 - a[0])
diff -= b[0]
if diff <= 0:
num1 = min(num1, 2)
else:
num1 = min(num1, 3)
diff = q - p
diff -= b[0]
if diff <= 0:
num2 = min(1, num1)
else:
diff -= b[1]
if diff <= 0:
num2 = min(2, num1)
else:
num2 = min(3, num1)
diff = q - p - b[0]
diff -= 9 - a[0]
if diff <= 0:
num2 = min(num2, 2)
else:
num2 = min(num2, 3)
print(num2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | wow = [int(e) for e in input()]
a1 = [wow[0], wow[1], wow[2]]
a2 = [wow[3], wow[4], wow[5]]
sum1 = sum(a1)
sum2 = sum(a2)
if sum1 == sum2:
print(0)
else:
if sum1 < sum2:
noi = sum1
mak = sum2
fnoi = list(a1)
fmak = list(a2)
pontang = sum2 - sum1
if sum2 < sum1:
noi = sum2
mak = sum1
fnoi = list(a2)
fmak = list(a1)
pontang = sum1 - sum2
fnoi.sort()
fmak.sort()
ptfnoi = [0] * 3
ptfmak = [0] * 3
ptfnoi[0] = 9 - fnoi[0]
ptfnoi[1] = 9 - fnoi[1]
ptfnoi[2] = 9 - fnoi[2]
ptfmak[0] = fmak[0]
ptfmak[1] = fmak[1]
ptfmak[2] = fmak[2]
lis = [ptfnoi[0], ptfnoi[1], ptfnoi[2], ptfmak[0], ptfmak[1], ptfmak[2]]
lis.sort()
mx1 = lis[5]
mx2 = lis[4]
if mx1 >= pontang:
print(1)
elif mx1 + mx2 >= pontang:
print(2)
else:
print(3) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) β this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number β the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | def work():
s = input()
a = [int(s[0]), int(s[1]), int(s[2])]
b = [int(s[3]), int(s[4]), int(s[5])]
if sum(a) == sum(b):
print(0)
return
if sum(a) > sum(b):
a, b = b, a
a = sorted(a)
b = sorted(b)
ben = [9 - a[0], 9 - a[1], 9 - a[2], b[0], b[1], b[2]]
ben = sorted(ben)[::-1]
k = sum(b) - sum(a)
t = 0
i = 0
while t < k:
t += ben[i]
i += 1
print(i)
return
work() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.