import
java.util.*;
class
GFG
{
static
void
newArray(
int
[] A,
int
n)
{
HashMap<Integer, HashSet<Integer> > idx
=
new
HashMap<Integer, HashSet<Integer> >();
ArrayList<Integer> B =
new
ArrayList<Integer>();
for
(
int
i =
0
; i < n; ++i) {
if
(idx.containsKey(A[i])) {
HashSet<Integer> h1 = idx.get(A[i]);
int
pos = Collections.min(h1);
h1.remove(pos);
idx.put(A[i], h1);
B.set(pos, B.get(pos) +
1
);
HashSet<Integer> h2;
if
(!idx.containsKey(B.get(pos)))
idx.put(B.get(pos),
new
HashSet<Integer>());
h2 = idx.get(B.get(pos));
h2.add(pos);
idx.put(B.get(pos), h2);
h1.add(B.size());
idx.put(A[i], h1);
}
else
{
HashSet<Integer> h1
=
new
HashSet<Integer>();
h1.add(B.size());
idx.put(A[i], h1);
}
B.add(A[i]);
}
for
(
int
i =
0
; i < B.size(); i++)
System.out.print(B.get(i) +
" "
);
}
public
static
void
main(String[] args)
{
int
[] arr = {
1
,
2
,
1
,
2
};
int
n = arr.length;
newArray(arr, n);
}
}