1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <vector>

int main() {

    int length;
    std::cin >> length;

    std::vector<char> word(length);
    for (int i = 0; i < length; ++i) {
        std::cin >> word[i];
    }
    // Uncomment the lines below for testing purposes
    // std::vector<char> word(30000, 'L');
    // int length = word.size();
    // std::vector<char> word(8, 'L');
    // int length = word.size();

    std::vector<int> score(length, 0);
    int head = 0;
    int leftLength = 0;

    for (int i = 0; i < length; ++i) {
        if (word[i] == 'L') {
            if (head > 0) {
                leftLength += 1;
            }
        } else {
            if (leftLength > 0) {
                std::vector<int> toAdd;
                if (leftLength < head) {
                    for (int j = 1; j <= 2 * leftLength; j += 2) {
                        toAdd.push_back(j);
                    }
                    for (int j = 0; j < head - leftLength; ++j) {
                        toAdd.push_back(2 * leftLength);
                    }
                    for (int j = 2 * leftLength - 1; j >= 0; j -= 2) {
                        toAdd.push_back(j);
                    }
                } else if (leftLength == head) {
                    for (int j = 1; j <= 2 * head; j += 2) {
                        toAdd.push_back(j);
                    }
                    for (int j = 2 * head - 1; j >= 0; j -= 2) {
                        toAdd.push_back(j);
                    }
                } else {
                    for (int j = 1; j <= 2 * head; j += 2) {
                        toAdd.push_back(j);
                    }
                    for (int j = 0; j < leftLength - head; ++j) {
                        toAdd.push_back(2 * head);
                    }
                    for (int j = 2 * head - 1; j >= 0; j -= 2) {
                        toAdd.push_back(j);
                    }
                }

                for (int iz = 0; iz < leftLength + head; ++iz) {
                    score[i - iz - 1] += toAdd[iz];
                }
                leftLength = 0;
            }
            head += 1;
        }
    }

    if (leftLength > 0) {
        std::vector<int> toAdd;
        if (leftLength < head) {
            for (int j = 1; j <= 2 * leftLength; j += 2) {
                toAdd.push_back(j);
            }
            for (int j = 0; j < head - leftLength; ++j) {
                toAdd.push_back(2 * leftLength);
            }
            for (int j = 2 * leftLength - 1; j >= 0; j -= 2) {
                toAdd.push_back(j);
            }
        } else if (leftLength == head) {
            for (int j = 1; j <= 2 * head; j += 2) {
                toAdd.push_back(j);
            }
            for (int j = 2 * head - 1; j >= 0; j -= 2) {
                toAdd.push_back(j);
            }
        } else {
            for (int j = 1; j <= 2 * head; j += 2) {
                toAdd.push_back(j);
            }
            for (int j = 0; j < leftLength - head; ++j) {
                toAdd.push_back(2 * head);
            }
            for (int j = 2 * head - 1; j >= 0; j -= 2) {
                toAdd.push_back(j);
            }
        }

        for (int iz = 0; iz < leftLength + head; ++iz) {
            score[length - iz - 1] += toAdd[iz];
        }
    }

    for (int i = 0; i < length; ++i) {
        std::cout << score[i] << " ";
    }
    std::cout << std::endl;

    return 0;
}