Deck of Cards X81723


Statement
 

pdf   zip

A transposition of a deck of cards is the following sequence of operations:

  • Throw away an arbitrary number of cards from the top of the deck (it is allowed to throw away no cards, or to throw away all cards);

  • Pick a number k{2,3}k \in \{2, 3\};

  • Divide the remaining part of the deck into kk parts. Part number tt (0t<k0 \leq t < k) consists of cards which have been in positions ii such that imodk=ti \bmod k = t. In each part, cards are arranged in the same way as they were arranged in the original deck.

  • Transpose each of the kk parts. We can transpose the parts in any order, but we can start transposing the next part only after completely transposing the previous one (for example, if AA is split into BB and CC, then we transpose BB and split it into DD and EE, then we have to transpose both DD and EE (in any order) before proceeding to transposing CC).

You are given a deck of cards with numbers. You can look at the cards, so you know all numbers on all cards. Your task is to find a transposition which gives the greatest amount of points. We get 1 point whenever the sum of the cards thrown away so far is divisible by 100. If two transpositions give the same score, the one in which the first card thrown away has a lower value is better. If we still have a draw, the second card decides, and so on.

Input

The first line contains a single number NN — how many cards there are in the deck (1N2001 \leq N \leq 200).

The (i+1)(i+1)-th row, 1iN1\leq i\leq N, contains a single integer kik_i, which is the value of the ii-th card (999ki999-999 \leq k_i \leq 999).

Output

In the first row output the score (the number of points received). In the second row output c1c2c3cNc_1 c_2 c_3 \ldots c_N, where cic_i is the ii-th card thrown away when using the optimal way of transposing the deck.

Public test cases
  • Input

    9
    80 50 20 90 40 30 70 60 10
    

    Output

    3
    40 60 50 20 30 10 90 70 80
    
  • Information
    Author
    Eryk Kopczynski
    Language
    English
    Official solutions
    Unknown.
    User solutions
    C++