Deck of Cards X81723


Statement
 

pdf   zip

html

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};
  • Divide the remaining part of the deck into k parts. Part number t (0 ≤ t < k) consists of cards which have been in positions i such that i modk = t. In each part, cards are arranged in the same way as they were arranged in the original deck.
  • Transpose each of the k 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 A is split into B and C, then we transpose B and split it into D and E, then we have to transpose both D and E (in any order) before proceeding to transposing C).

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 N — how many cards there are in the deck (1 ≤ N ≤ 200).

The (i+1)-th row, 1≤ iN, contains a single integer ki, which is the value of the i-th card (−999 ≤ ki ≤ 999).

Output

In the first row output the score (the number of points received). In the second row output c1 c2 c3cN, where ci is the i-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. This problem is being checked.
    User solutions
    C++