This page is still under construction.

Parts of this page are still being built. What you see may change.

Counting Friends

Time limit1sMemory limit128 MB

Summary
Removing one of N+1 listed counts, find every entry whose removal leaves counts realizable as mutual friendships among N cows.
Level

Medium6 of 10

Topics
Graph, Sorting
Solved
No attempts yet

Problem

Farmer John has NN cows (2≤N≤5002 \le N \le 500) on the social network MooBook.

Each cow has one or more friends on MooBook. While writing down every cow's friend count, Farmer John got distracted and accidentally wrote one extra number. His list therefore has N+1N+1 entries instead of NN.

Find every entry that could be the mistaken extra number.

Input

  • Line 1: integer NN
  • Lines 2 through N+2N+2: one integer per line, either a cow's friend count or the extra mistaken number

Output

  • Line 1: integer KK, the number of entries that could be the extra number (K=0K=0 means no removal leaves a valid friend assignment)
  • Next KK lines: indices from 1 through N+1N+1 in the input order. Print an index if removing that entry leaves NN counts that can be realized as mutual friendships among NN cows. Print indices in sorted order.

Examples1

  1. Example 1

    Input
    4
    1
    2
    2
    1
    3
    
    Expected output
    3
    1
    4
    5