#include <iostream>
using namespace std;
int main()
{
	int n, i, x;

	cin >> n;
	i = 1;
	3 <= n <= 10000;

	while (i <= n - 1)
	{
		i++;
		x = i;

		if (x % 3 == 0)
		{
			cout << " " << i;
		}
		else if (x % 10 == 3)
		{
			cout << " " << i;
		}
		else if ((x / 10) % 10 == 3)
		{
			cout << " " << i;
		}
		else if ((x / 100) % 10 == 3)
		{
			cout << " " << i;
		}
		else if ((x / 1000) % 10 == 3)
		{
			cout << " " << i;
		}
	}
	cout << endl;
}
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
string s;
void solve(){
    stack<char> st;
    int i = 0, n = s.length();
    for(i = 0; i < n; i++){
        if(s[i] == 'S')
            st.push(s[i]);
        else{
            if(st.size() > 0 && st.top() == 'S')
                st.pop();
            else
                st.push(s[i]);
        }
    }
    cout << st.size() << "\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s;
    solve();
    return 0;
}