It's the Annual Amazing Christmas season! As part of the reindeers' holiday celebrations, they decide to hold a hurdle race!
There are reindeer participating in the race, each in their own lane, where lanes are numbered from to . The track is metres long, with a hurdle in each lane at every integer metre, that is at metre , , and so on up to and including . In this race, there is only one baton, which can only be held by one reindeer at a certain time.
The rules of the race are bizarre. All reindeer start running at the same time, at the exact same speed. However, something odd about the race is that if the reindeer with the baton runs into a hurdle at metre , the baton flies out of their hoofs and is caught by the reindeer in lane . This only happens after all the reindeer pass this particular hurdle and therefore at most one baton throw occurs at a certain metre . Strangely, running into a hurdle doesn't affect a reindeer's speed; they continue running in unison with the other competitors.
The winner of the race is the reindeer holding the baton at the end of the race. At the start of the race, the reindeer in a predetermined lane starts with the baton. As the coach of the reindeer in lane , you want your reindeer to win, and will resort to anything to achieve your goal.
These reindeer have trained the whole year for this event (yes, reindeer have nothing to do most of the year besides helping Santa deliver presents), and therefore they will never run into a hurdle on their own. However, you, being the coach, plan to secretly throw at least and at most bananas during the race, where each banana can be thrown at any lane and at any time during the race, causing the reindeer in that lane to collide into the next hurdle. You need some help to achieve your diabolic plan, so you decide to write a program to output a valid configuration of bananas to be thrown so that the reindeer in lane wins, or
-1 if it is impossible.
Subtask 1 [40%]
Subtask 2 [60%]
No additional constraints.
The first line contains six space-separated integers , , , , , and .
The next line contains space-separated integers .
If it is impossible for the reindeer in lane to end up with the baton at the end of the race, output
Otherwise, first output , the number of bananas you will throw .
Then, output lines consisting of integers each, the integer on the -th line and -th column being if you threw a banana at the reindeer in lane to cause them to collide with the -th hurdle, or if you did not. The number of 's should equal .
Note: Any valid output will be accepted.
Sample Input 1
5 10 2 5 0 20 1 2 3 4 5 5 4 3 2 1
Sample Output 1
13 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0
Explanation for Sample 1
The reindeer in lane starts with the baton and collides with the hurdle at position , handing the baton to the reindeer in lane . The reindeer in lane continues with the baton until colliding with the hurdle at position , handing the baton to the reindeer in lane .
The reindeer in lane collides with hurdle , but since is , they simply hand the baton to themselves. The reindeer in lane then continues to the end without hitting any hurdles, becoming the winner.
Sample Input 2
5 5 1 5 22 25 5 4 3 2 1
Sample Output 2
Explanation for Sample 2
Note: You do not need to pass this sample to receive points.
It can be shown that it is impossible for the reindeer in lane to have the baton at the end of the race. Better luck next time!
Sample Input 3
2 2 2 2 0 4 1 1
Sample Output 3
0 0 0 0 0