This page is still under construction.

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

Guillotine Card Game

Time limit3sMemory limit128 MB

Summary
Compute each player's final score in a three-player card game where one player secretly plays to minimize another player's score.
Level

Medium7 of 10

Topics
Game theory, Backtracking, Recursion
Solved
No attempts yet

Problem

A frog, a kappa and a weasel are playing a card game.

The game uses one guillotine, twelve noble cards and six action cards. Every noble card and every action card has one integer written on its face. Before the game starts, the players lay the twelve noble cards in a row on the table and put the guillotine at the right end of the row. Each player is then dealt two action cards. All noble cards and action cards lie face up, so the three players share the whole state of the game.

Turns go in the order frog, kappa, weasel. The frog takes the first turn, the kappa the second, the weasel the third, the frog the fourth, and so on. A turn consists of an action phase and then an execution phase.

In the action phase, a player who still holds action cards may use one of them. Let yy be the number on the card that was used. If at least yy noble cards are left on the table, the yy-th noble card counting from the guillotine moves to the position right in front of the guillotine. If fewer than yy noble cards are left, nothing happens. In either case the used action card is discarded from the hand. When y=1y = 1 the row does not change.

In the execution phase, the player removes the noble card right in front of the guillotine and scores the number written on it. This phase cannot be skipped.

The game ends once every noble card has been removed.

Each player follows this strategy.

  • Every player assumes that the other players follow a strategy that maximizes their own final score.
  • The frog and the weasel really do follow such a strategy.
  • The kappa does not. The kappa plays so that the frog's final score is minimized.
  • The kappa knows that the frog and the weasel play under a wrong assumption, namely that the kappa maximizes his own score.
  • When several choices satisfy a player's objective equally well, that player picks the choice that leaves as many action cards in his own hand as possible at the end of the turn.
  • If several choices are still tied, that player picks the choice with the larger total of the numbers on the action cards left in his own hand.

Compute the final score of each of the three players.

Input

The input is formatted as follows.

x12 x11 x10 x9 x8 x7 x6 x5 x4 x3 x2 x1
y1 y2
y3 y4
y5 y6

The first line contains twelve integers x12,x11,…,x1x_{12}, x_{11}, \ldots, x_1 (−2≤xi≤5-2 \le x_i \le 5). xix_i is the integer on the ii-th noble card counting from the guillotine, so the last number on the line is the number on the card right in front of the guillotine.

The next three lines contain six integers y1,…,y6y_1, \ldots, y_6 (1≤yj≤41 \le y_j \le 4). y1,y2y_1, y_2 are the numbers on the frog's action cards, y3,y4y_3, y_4 are the numbers on the kappa's action cards, and y5,y6y_5, y_6 are the numbers on the weasel's action cards.

Output

Print the final scores of the frog, the kappa and the weasel on one line, separated by single spaces.

Examples3

  1. Example 1

    Input
    3 2 1 3 2 1 3 2 1 3 2 1
    1 1
    1 1
    1 1
    
    Expected output
    4 8 12
    
  2. Example 2

    Input
    4 4 4 3 3 3 2 2 2 1 1 1
    1 2
    2 3
    3 4
    
    Expected output
    8 10 12
    
  3. Example 3

    Input
    0 0 0 0 0 0 0 -2 0 -2 5 0
    1 1
    4 1
    1 1
    
    Expected output
    -2 -2 5