import
java.util.*;
public
class
RMQSegmentTree {
public
static
boolean
createTree(
int
[] arr,
int
N)
{
final
int
height
= (
int
)(Math.log(N) / Math.log(
2
)) +
1
;
Map<Integer, Integer> multi =
new
HashMap<>();
for
(
int
i =
0
; i <
2
* N -
1
; ++i)
multi.put(arr[i],
multi.getOrDefault(arr[i],
0
) +
1
);
Set<Integer>[] Q =
new
HashSet[height];
for
(
int
i =
0
; i < height; i++) {
Q[i] =
new
HashSet<Integer>();
}
Q[height -
1
].add(
0
);
for
(Map.Entry<Integer, Integer> entry :
multi.entrySet()) {
int
key = entry.getKey();
int
value = entry.getValue();
if
(value > height || Q[value -
1
].isEmpty())
return
false
;
int
node = Q[value -
1
].iterator().next();
Q[value -
1
].remove(node);
int
level =
1
;
for
(
int
i = node; i <
2
* N -
1
;
i =
2
* i +
1
, ++level) {
if
(
2
* i +
2
<
2
* N -
1
)
Q[value - level -
1
].add(
2
* i +
2
);
arr[i] = key;
}
}
return
true
;
}
public
static
void
main(String[] args)
{
int
N =
8
;
int
[] arr = {
1
,
1
,
1
,
1
,
2
,
2
,
3
,
3
,
3
,
4
,
4
,
5
,
6
,
7
,
8
};
if
(createTree(arr, N)) {
System.out.println(
"YES"
);
for
(
int
i =
0
; i <
2
* N -
1
; ++i)
System.out.print(arr[i] +
" "
);
}
else
{
System.out.println(
"NO"
);
}
}
}