#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

long long numOfSubsequences(string s) {

    // Count number of "LCT" subsequences
    long long l = 0;
    long long lc = 0;
    long long lct = 0;

    for (int i = 0; i < s.size(); i++) {

        if (s[i] == 'L') {
            l++;
        }

        if (s[i] == 'C') {
            lc = lc + l;
        }

        if (s[i] == 'T') {
            lct = lct + lc;
        }
    }

    // Count number of "CT" subsequences
    long long ct = 0;
    long long c = 0;

    for (int i = 0; i < s.size(); i++) {

        if (s[i] == 'C') {
            c++;
        }

        if (s[i] == 'T') {
            ct = ct + c;
        }
    }

    // Insert L
    long long insertl = lct + ct;

    // Insert T
    long long insertt = lct + lc;

    // Insert C
    long long insertc = 0;

    long long leftL = 0;
    long long totalT = 0;

    // Count total T
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'T') {
            totalT++;
        }
    }

    long long rightT = totalT;

    // Try inserting C at every position
    for (int i = 0; i < s.size(); i++) {

        insertc = max(insertc, leftL * rightT);

        if (s[i] == 'L') {
            leftL++;
        }

        if (s[i] == 'T') {
            rightT--;
        }
    }

    // Insert C at the end
    insertc = max(insertc, leftL * rightT);

    // Maximum answer
    return max({
        insertl,
        insertt,
        lct + insertc,
        lct
    });
}

int main() {

    string s;
    cin >> s;

    cout << numOfSubsequences(s) << endl;

    return 0;
}