p346.ans1
======================
43

=================
p346.ans2
======================
50

=================
p346.ans3
======================
22

=================
p346.ans4
======================
34

=================
p346.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

vector<int> balls;
string state;

void read() {
    balls.resize(7);
    cin >> balls >> state;
}

void solve() {
    // An important note in the statement is "You may assume that if there is at
    // least one red ball, there are all colours.", which makes this fairly
    // simple. We can greedily alternate reds with black (the most expensive
    // colour, worth 7) to maximize score. Each red-black pair scores 1+7=8
    // points. After all reds are exhausted, all the colours are potted in
    // increasing order (2+3+4+5+6+7=27). If state is RED, we first pot the best
    // available colour (which goes back on the table since the last red was the
    // previous shot), gaining extra points. With no reds, simply sum the
    // remaining colours, plus the best colour again if state is RED.

    int reds = balls[0];
    int colour_sum = 0;
    for(int i = 1; i < 7; i++) {
        colour_sum += balls[i] * (i + 1);
    }

    int score = 0;
    if(reds > 0) {
        score = reds * 8 + colour_sum;
        if(state == "RED") {
            score += 7;
        }
    } else {
        score = colour_sum;
        if(state == "RED") {
            for(int i = 6; i >= 1; i--) {
                if(balls[i]) {
                    score += i + 1;
                    break;
                }
            }
        }
    }

    cout << score << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        solve();
    }

    return 0;
}

=================
p346.in1
======================
2 1 1 1 1 1 1
COLOUR

=================
p346.in2
======================
2 1 1 1 1 1 1
RED

=================
p346.in3
======================
0 0 0 1 1 1 1
NONE

=================
p346.in4
======================
0 1 1 1 1 1 1
RED

=================
statement.txt
======================
346. Snooker
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



Snooker is a cue sport that is played on a large (12 ft * 6 ft, 3.6 m * 1.8 m) baize-covered table with pockets in each of the four corners and in the middle of each of the long side cushions. It is played using a cue, one white ball (the cue ball), 15 red balls (worth 1 point each) and 6 balls of different colours (worth 2-7 points each). [Wikipedia, the free encyclopedia]

Snooker is played by two players or two teams. The main rule in snooker is to alternate potting reds and colours — that's how yellow, green, brown, blue, pink and black balls are called. They cost from 2 to 7 points each in this particular order. Alternating means that after potting a red ball, the player has to pot any colour ball and vice versa. If the player has potted any colour ball and there are still some reds or he has potted last red by the previous shot, this potted colour ball is put back on the table. If there are no reds and a colour was out back for the last time, the player has to pot all colours in the increasing order of their cost. If there is at least one red ball ath the table, the player can start his break (a sequence of continuously potted balls) only with the red ball. These rules will be enough for this problem.

For example, let's consider two reds on the table. The player may pot them in order like "red - black - red - pink - yellow - green - brown - blue - pink - black" which is correct break, but "red - red" or "red - black - pink" is not correct.

Professional players always estimate "score on the table" — maximal score one can achieve by correctly potting all the balls on the table. Obviously, this can be done by alternating reds with black, because black is the most expensive colour ball. Your task is to find this maximal score.

Input
The first line of the input file contains 7 numbers, representing the number of the balls of each color in a particular order: red, yellow, green, brown, blue, pink and black. The number of all balls except red will be from 0 to 1, the number of red balls will be from 0 to 15. The second line contains one word: "RED" if the last potted ball was red, "COLOUR" if the last potted ball was colour, and "NONE" if the next shot will be the first in the player's brake. You may assume that if there is at least one red ball, there are all colours. Also you may assume that if there are no reds, colours have been potted in the correct order.

Output
Write to the output file the desired maximum score.

Example(s)
sample input
sample output
2 1 1 1 1 1 1
COLOUR
43

sample input
sample output
2 1 1 1 1 1 1
RED
50

sample input
sample output
0 0 0 1 1 1 1
NONE
22

sample input
sample output
0 1 1 1 1 1 1
RED
34



Note
"Red - black - red - black - yellow - green - brown - blue - pink - black" costs 1 + 7 + 1 + 7 + 2 + 3 + 4 + 5 + 6 + 7 = 43 points.

"Black - red - black - red - black - yellow - green - brown - blue - pink - black" costs 7 + 1 + 7 + 1 + 7 + 2 + 3 + 4 + 5 + 6 + 7 = 50 points.

According to the rules, player has to pot brown ball next, so "brown - blue - pink - black" costs 4 + 5 + 6 + 7 = 22 points.

"Black - yellow - green - brown - blue - pink - black" costs 7 + 2 + 3 + 4 + 5 + 6 + 7 = 34 points.

=================
