#P3104. Cow Book Social Network Error

    ID: 16362 Type: Default 1000ms 256MiB

Cow Book Social Network Error

Cow Book Social Network Error

FJ has N cows (with \(2 \le N \le 500\)) on the social network "Cow Book". Each cow has one or more friends on Cow Book. FJ compiled a list containing the number of friends for each cow. However, he mistakenly inserted one extra number into the list so that the final list contains \(N+1\) numbers instead of the expected \(N\).

Your task is to determine which number in the list could be the erroneous extra number. More formally, remove one number (by its index) so that the remaining \(N\) numbers form a valid degree sequence of a simple graph on \(N\) vertices where each degree is at least 1 and at most \(N-1\). A sequence \(d_1, d_2, \dots, d_N\) is graphical if there exists a simple graph on \(N\) vertices whose vertex degrees are exactly the given numbers. You may assume that the intended degree sequence (after removing the extra number) is graphical if and only if it satisfies the Erd\H{o}s–Gallai conditions (which can be verified using the Havel–Hakimi algorithm).

inputFormat

The input consists of two lines. The first line contains a single integer \(M\) (where \(M = N+1\) and \(3 \le M \le 501\)). The second line contains \(M\) space-separated positive integers representing the friend counts (each intended to be at least 1). Note that after removing one number, the remaining \(N\) numbers should all be between 1 and \(N-1\), inclusive.

outputFormat

If there is at least one position in the list (1-indexed) such that removing the number at that position results in a valid degree sequence, then on the first line output the total count of such positions. In the following lines, output the indices (in increasing order) of all such numbers. If no such removal exists, output -1.

sample

5
1 2 1 2 3
1

5

</p>