import
java.util.HashMap;
public
class
GFG
{
static
int
findIndex(
int
arr[],
int
N)
{
int
maxValue = Integer.MIN_VALUE;
for
(
int
i =
0
; i < N; i++)
{
maxValue = Math.max(maxValue, arr[i]);
}
HashMap<Integer, Integer> St =
new
HashMap<>();
for
(
int
i =
1
; i <= maxValue; i++) {
St.put(i, St.getOrDefault(i,
0
) +
1
);
}
if
(St.containsKey(
1
)) {
St.remove(
1
);
}
for
(
int
i =
2
; i <= Math.sqrt(maxValue); i++) {
int
j =
2
;
while
((i * j) <= maxValue) {
if
(St.containsKey(i * j)) {
St.remove(i * j);
}
j++;
}
}
int
LeftCount =
0
;
int
Prefix[] =
new
int
[N];
for
(
int
i =
0
; i < N; i++) {
Prefix[i] = LeftCount;
if
(St.containsKey(arr[i])) {
LeftCount++;
}
}
int
RightCount =
0
;
int
Suffix[] =
new
int
[N];
for
(
int
i = N -
1
; i >=
0
; i--) {
Suffix[i] = RightCount;
if
(St.containsKey(arr[i])) {
RightCount++;
}
}
for
(
int
i =
0
; i < N; i++) {
if
(Prefix[i] == Suffix[i]) {
return
i;
}
}
return
-
1
;
}
public
static
void
main(String[] args)
{
int
arr[] = {
2
,
3
,
4
,
7
,
5
,
10
,
1
,
8
};
int
N = arr.length;
System.out.println(findIndex(arr, N));
}
}