Make a WaterOverflow You and a friend are playing a game - who can overflow the most containers? There are n containers numbered 1 to n. Each container has a certain maximum capacity of water, in litres.

You take turns with your friend to pour discrete amounts of water into the containers. On your turn, you may pour 2 litres of water into one container (you can't distribute into multiple containers), and on your friend's turn, he must pour 3 litres. You may also choose, on your turn, to not pour water in any of the containers (you cannot, however, choose to only pour 1 litre). The person who manages to overflow the container - that is, after they finish their turn, the litres of water inside the container is greater than its maximum capacity - gets a point. 

The input comes in the form of space separated integers. The leftmost one is labelled 1 and the rightmost one is labelled n. For instance:

Y 2 1 4 3


Note that the letter indicates who goes first. Y means that you go first, and F means that your friend goes first. The 2 litre container is labelled 1, the 1 litre container is labelled 2, etc. So we would call the 2 litre container "Container 1", because it is labelled 1. 

Now, your friend has a very naïve strategy. He always pours all his 3 litres of water into the container that is closest to overflowing. If there is more than one container that is equally closest to overflowing, he will pour all his water in the one that is labelled with the lowest number.

Suppose I use the same naïve strategy of pouring all my 2 litres of water into the container that is closest to overflowing. The example input would work out like this:


I pour all my water into Container 2. It overflows, and I get one point.  
My friend pours all his water into Container 1. It overflows, and he gets one point.  
I pour all my water into Container 4. It now has 2L of water in it, so it needs another 2L to overflow.  
My friend pours all his water into Container 4. It overflows, and he gets one point.  
I pour all my water into container 3. It now has 2L of water in it, so it needs another 3L to overflow.
My friend pours all his water into Container 3. It overflows, and he gets one point.


Altogether, I only got one point, and my friend got three. That's not good. I can do better than that if I make use of my ability to pass on my turn without pouring water:


I pour all my water into Container 2. It overflows, and I get one point.  
My friend pours all his water into Container 1. It overflows, and he gets one point. 
I pass.  
My friend pours all his water into Container 4. It now has 3L of water in it, so it needs another 1L to overflow.  
I pour my water into Container 4. It overflows, and I get one point.  
My friend pours all his water into Container 3. It has 3L of water in it now, so it needs another 2L to overflow.   
I pour my water into Container 3. It overflows, and I get one point.


By strategically choosing which container to pour my water in, I have managed to obtain 3 points instead of 1. The output format is a list of space separated instructions, where P indicates a pass, and an integer from 1 to n indicates which container I poured water into. For instance, the naïve nonoptimal strategy listed above could be represented as:

2 4 3


Which means I poured into Container 2, then Container 4, then Container 3. The more optimal strategy would be represented as:

2 P 4 3


Which means I poured into Container 2, then passed, then Container 4, then Container 3 (This, by the way, is the output format). 

Your program will take in input as described above and return the most optimal solution to get as many points as possible. If there is more than one optimal solution, output either.
Python, 217 202 176
import sys
A=sys.argv[1:]
t=A&gt;[&quot;G&quot;]
C=[[int(A[i]),i]for i in range(1,len(A))]
while C:
 c=min(C);d=1.5
 if t:d=c[0]%5&lt;2;print[&quot;P&quot;,c[1]][d],
 c[0]-=2*d;t^=1
 if[0]&gt;c:C.remove(c)

Reads input from the command line.
Strategy:

If the remaining capacity in the container with the least remaining capacity is congruent 0 or 1 modulo 5, pour 2 litres (it either overflows, or our friend pours 3 more litres into the same container, bringing us back to the same point.)
Otherwise, no move improves our position, so do nothing (note that this isn't necessarily the shortest optimal strategy.)