Coprime Skip Playlist
A playlist holds n songs numbered 1 to n; song i has a genre code a_i. The player plays the
songs in order 1, 2, …, n and then wraps around to song 1 again, forever, always skipping songs that
have been deleted.
The player remembers the previous song: the one played right before the current one. Initially
nothing is remembered. Every time a song c is played:
- if a previous song
pis remembered andgcd(a_p, a_c) = 1, songcis deleted from the playlist and the memory is cleared, so the next song played has no previous song to compare with; - otherwise song
cbecomes the remembered previous song.
When only one song is left, it is played over and over, so it is compared with itself: it gets deleted
exactly when its code is 1.
At some point no deletion can ever happen again (possibly because the playlist is empty). List the deleted songs in the order they were deleted.
Input
The first line contains an integer n (1 ≤ n ≤ 2·10^5).
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9).
Output
On the first line print k, the number of deleted songs. On the second line print the k indices of
the deleted songs in the order they were deleted, separated by spaces (leave the line empty if
k = 0).
Notes
In the first example the player plays song 1 (code 2), then song 2 (code 3): the codes are coprime, so
song 2 is deleted and the memory is cleared. Song 3 (code 5) is therefore not compared with anything,
even though it is coprime with song 1. Then song 4 (code 4) is coprime with song 3 and is deleted. Next
song 1 is played with nothing remembered, followed by song 3, which is now coprime with song 1 and gets
deleted. Song 1 is then compared with itself (gcd(2, 2) = 2) and survives forever.
In the second example the last remaining song has code 1, so it is deleted when it is compared with
itself.
In the third example every pair of neighbours shares a factor, so nothing is deleted.