#include<bits/stdc++.h>
using namespace std;

struct state{
  int fc,kc,wc,fb;
  state(int fc,int kc,int wc,int fb):
    fc(fc), kc(kc), wc(wc), fb(fb) {}
  state(){
    fb = -1;
  }
  bool operator==(const state &st ) const{
    if( fc == st.fc &&
        kc == st.kc &&
        wc == st.wc &&
        fb == st.fb ) return true;
    return false;
  }
  void view(){
    cout << "result: " << endl;
    cout << "F: " << fc <<endl;
    cout << "K: " << kc <<endl;
    cout << "W: " << wc <<endl;
    cout << "action: " << fb << endl;
  }
};

typedef pair<state,state> P;

state better( const state& a, const state& b,int p, bool kf ){  
  if( a.fb < 0 ) return b;
  if( p == 0 ){//turn flog
    if( a.fc != b.fc )
      return a.fc > b.fc ? a : b;
  } else if( p == 1 ){//turn kappa
    if( kf ){ // kappa-seeing
      if( a.fc != b.fc )
        return a.fc < b.fc ? a : b;
    } else {
      // kaeru-seeing
      if( a.kc != b.kc )
        return a.kc > b.kc ? a : b;
    }
  } else {//turn weasel
    if( a.wc != b.wc )
      return a.wc > b.wc ? a : b;
  }
  return a.fb < b.fb ? a : b;
}

int X[13],Y[7];

int cut(int st,int y ){
  int cnt = 0;
  for(int i=0;i<12;i++){
    if( st & (1<<i) ) continue;
    if( cnt == y ) return  st|(1<<i);
    cnt++;
  }
  return -1;
}

int check( int st ){
  for(int i=0;i<12;i++){
    if( st & (1<<i) ) continue;
    return st | (1<<i);   
  }
  return -1;
}

void calc( state& ret,int st,int t,int uc){
  int cnt = 0;
  for(int i=0;i<12;i++){
    if( st & (1<<i) ) continue;
    if( uc==-1 || cnt == uc ) {
      if( t == 0 ) ret.fc+=X[i];
      else if( t == 1 ) ret.kc+=X[i];
      else ret.wc+=X[i];
      break;
    }
    cnt++;
  }
  ret.fb = uc+1;
}

void calc( P& ret, int st, int t, int uc ){
  calc( ret.first, st, t, uc );
  calc( ret.second, st, t, uc );
}

P dp[3][(1<<6)][(1<<12)];

P better( const P& a, const P& b,int t){
  P ret;
  if( t == 1 ){ // Kappa
    ret.first = better(a.first, b.first, t, true );
    ret.second= better(a.second,b.second,t, false );
  } else { // Flog or Weasel
    if( a.second == better(a.second,b.second,t, false ) )
      ret = a;
    else
      ret = b;
  }
  return ret;
}

P solve(int t,int yst,int xst ){// first : Kappa,  second : Flog
  if( dp[t][yst][xst].first.fb >= 0 ) return dp[t][yst][xst];
  P ret;
  if( xst == (1<<12)-1 ) return dp[t][yst][xst] = P( state(0,0,0,0), state(0,0,0,0) );
  
  P tmp = solve( (t+1)%3, yst, check(xst) );
  calc( tmp, xst, t, -1 );
  ret = tmp;
  //ret = better( ret, tmp, t );
  //view()
  if( 0 ) {
    cout << t << " "<< bitset<6>(yst) << " " << bitset<12>(xst) << endl;
    ret.first.view();
    ret.second.view();
  }
  
  
  for(int i=t*2;i<t*2+2;i++){
    if( yst & (1<<i) ) continue;
    int next = cut( xst, Y[i] );
    P tmp;
    if( next == -1 ) continue;
    tmp = solve((t+1)%3, yst|(1<<i), next );
    calc( tmp, xst, t, Y[i] );          
    ret = better( ret, tmp, t );
  }
  //view()
  if( 0 ){
    cout << t << " "<< bitset<6>(yst) << " " << bitset<12>(xst) << endl;
    ret.first.view();
    ret.second.view();
  }
  return dp[t][yst][xst] = ret;
}

int main(){
  for(int i=11;i>-1;i--) cin >> X[i];
  for(int i=0;i<6;i++) {
    cin >> Y[i]; Y[i]--;
  }
  P res = solve(0,0,0);
  cout << res.first.fc << " " << res.first.kc << " "<< res.first.wc << endl;
}
### Prompt

Construct a cpp code solution to the problem outlined:

C - Iyasugigappa

Problem Statement

Three animals Frog, Kappa (Water Imp) and Weasel are playing a card game.

In this game, players make use of three kinds of items: a guillotine, twelve noble cards and six action cards. Some integer value is written on the face of each noble card and each action card. Before stating the game, players put twelve noble cards in a line on the table and put the guillotine on the right of the noble cards. And then each player are dealt two action cards. Here, all the noble cards and action cards are opened, so the players share all the information in this game.

Next, the game begins. Each player takes turns in turn. Frog takes the first turn, Kappa takes the second turn, Weasel takes the third turn, and Frog takes the fourth turn, etc. Each turn consists of two phases: action phase and execution phase in this order.

In action phase, if a player has action cards, he may use one of them. When he uses an action card with value on the face y, y-th (1-based) noble card from the front of the guillotine on the table is moved to in front of the guillotine, if there are at least y noble cards on the table. If there are less than y cards, nothing happens. After the player uses the action card, he must discard it from his hand.

In execution phase, a player just remove a noble card in front of the guillotine. And then the player scores x points, where x is the value of the removed noble card.

The game ends when all the noble cards are removed.

Each player follows the following strategy:

* Each player assume that other players would follow a strategy such that their final score is maximized.
* Actually, Frog and Weasel follows such strategy.
* However, Kappa does not. Kappa plays so that Frog's final score is minimized.
* Kappa knows that Frog and Weasel would play under ``wrong'' assumption: They think that Kappa would maximize his score.
* As a tie-breaker of multiple optimum choises for each strategy, assume that players prefer to keep as many action cards as possible at the end of the turn.
* If there are still multiple optimum choises, players prefer to maximuze the total value of remaining action cards.



Your task in this problem is to calculate the final score of each player.

Input

The input is formatted as follows.


x_{12} x_{11} x_{10} x_9 x_8 x_7 x_6 x_5 x_4 x_3 x_2 x_1
y_1 y_2
y_3 y_4
y_5 y_6


The first line of the input contains twelve integers x_{12}, x_{11}, …, x_{1} (-2 \leq x_i \leq 5). x_i is integer written on i-th noble card from the guillotine. Following three lines contains six integers y_1, …, y_6 (1 \leq y_j \leq 4). y_1, y_2 are values on Frog's action cards, y_3, y_4 are those on Kappa's action cards, and y_5, y_6 are those on Weasel's action cards.

Output

Print three space-separated integers: the final scores of Frog, Kappa and Weasel.

Sample Input 1


3 2 1 3 2 1 3 2 1 3 2 1
1 1
1 1
1 1


Output for the Sample Input 1


4 8 12


Sample Input 2


4 4 4 3 3 3 2 2 2 1 1 1
1 2
2 3
3 4


Output for the Sample Input 2


8 10 12


Sample Input 3


0 0 0 0 0 0 0 -2 0 -2 5 0
1 1
4 1
1 1


Output for the Sample Input 3


-2 -2 5






Example

Input

3 2 1 3 2 1 3 2 1 3 2 1
1 1
1 1
1 1


Output

4 8 12

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;

struct state{
  int fc,kc,wc,fb;
  state(int fc,int kc,int wc,int fb):
    fc(fc), kc(kc), wc(wc), fb(fb) {}
  state(){
    fb = -1;
  }
  bool operator==(const state &st ) const{
    if( fc == st.fc &&
        kc == st.kc &&
        wc == st.wc &&
        fb == st.fb ) return true;
    return false;
  }
  void view(){
    cout << "result: " << endl;
    cout << "F: " << fc <<endl;
    cout << "K: " << kc <<endl;
    cout << "W: " << wc <<endl;
    cout << "action: " << fb << endl;
  }
};

typedef pair<state,state> P;

state better( const state& a, const state& b,int p, bool kf ){  
  if( a.fb < 0 ) return b;
  if( p == 0 ){//turn flog
    if( a.fc != b.fc )
      return a.fc > b.fc ? a : b;
  } else if( p == 1 ){//turn kappa
    if( kf ){ // kappa-seeing
      if( a.fc != b.fc )
        return a.fc < b.fc ? a : b;
    } else {
      // kaeru-seeing
      if( a.kc != b.kc )
        return a.kc > b.kc ? a : b;
    }
  } else {//turn weasel
    if( a.wc != b.wc )
      return a.wc > b.wc ? a : b;
  }
  return a.fb < b.fb ? a : b;
}

int X[13],Y[7];

int cut(int st,int y ){
  int cnt = 0;
  for(int i=0;i<12;i++){
    if( st & (1<<i) ) continue;
    if( cnt == y ) return  st|(1<<i);
    cnt++;
  }
  return -1;
}

int check( int st ){
  for(int i=0;i<12;i++){
    if( st & (1<<i) ) continue;
    return st | (1<<i);   
  }
  return -1;
}

void calc( state& ret,int st,int t,int uc){
  int cnt = 0;
  for(int i=0;i<12;i++){
    if( st & (1<<i) ) continue;
    if( uc==-1 || cnt == uc ) {
      if( t == 0 ) ret.fc+=X[i];
      else if( t == 1 ) ret.kc+=X[i];
      else ret.wc+=X[i];
      break;
    }
    cnt++;
  }
  ret.fb = uc+1;
}

void calc( P& ret, int st, int t, int uc ){
  calc( ret.first, st, t, uc );
  calc( ret.second, st, t, uc );
}

P dp[3][(1<<6)][(1<<12)];

P better( const P& a, const P& b,int t){
  P ret;
  if( t == 1 ){ // Kappa
    ret.first = better(a.first, b.first, t, true );
    ret.second= better(a.second,b.second,t, false );
  } else { // Flog or Weasel
    if( a.second == better(a.second,b.second,t, false ) )
      ret = a;
    else
      ret = b;
  }
  return ret;
}

P solve(int t,int yst,int xst ){// first : Kappa,  second : Flog
  if( dp[t][yst][xst].first.fb >= 0 ) return dp[t][yst][xst];
  P ret;
  if( xst == (1<<12)-1 ) return dp[t][yst][xst] = P( state(0,0,0,0), state(0,0,0,0) );
  
  P tmp = solve( (t+1)%3, yst, check(xst) );
  calc( tmp, xst, t, -1 );
  ret = tmp;
  //ret = better( ret, tmp, t );
  //view()
  if( 0 ) {
    cout << t << " "<< bitset<6>(yst) << " " << bitset<12>(xst) << endl;
    ret.first.view();
    ret.second.view();
  }
  
  
  for(int i=t*2;i<t*2+2;i++){
    if( yst & (1<<i) ) continue;
    int next = cut( xst, Y[i] );
    P tmp;
    if( next == -1 ) continue;
    tmp = solve((t+1)%3, yst|(1<<i), next );
    calc( tmp, xst, t, Y[i] );          
    ret = better( ret, tmp, t );
  }
  //view()
  if( 0 ){
    cout << t << " "<< bitset<6>(yst) << " " << bitset<12>(xst) << endl;
    ret.first.view();
    ret.second.view();
  }
  return dp[t][yst][xst] = ret;
}

int main(){
  for(int i=11;i>-1;i--) cin >> X[i];
  for(int i=0;i<6;i++) {
    cin >> Y[i]; Y[i]--;
  }
  P res = solve(0,0,0);
  cout << res.first.fc << " " << res.first.kc << " "<< res.first.wc << endl;
}
```