#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  string s; 
  cin >> s;

  int N = s.size();
  int ans = N*(N-1)/2+1;

  map<char, int> m;
  REP(i, N) m[s[i]]++;

  for(auto p : m){
    ans -= p.second*(p.second-1)/2;
  }

  cout << ans << endl;

  return 0;
}
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <cstring>
#include <cmath>

using namespace std;
const long double eps = 1e-12;

typedef long long ll;
typedef pair<int , int> pt;

#define sz(a) ((int) a.size() )
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i , a , b) for (int i = a ; i <= b ; i++)
#define Ford(i , a , b) for (int i = a ; i >= b ; i--)
#define Rep(i , n) for (int i = 0 ; i < n ; i++)

const int maxn = 1000000 + 1912;
string s;
int lenJ[maxn] , lenI[maxn];

void ReadData() {
    cin >> s;
}

void Process() {
    lenJ[0] = s[0] == 'J';
    For(i , 1 , sz(s) - 1) if (s[i] == 'J') lenJ[i] = lenJ[i - 1] + (s[i] == 'J'); else lenJ[i] = 0;
    Ford(i , sz(s) - 1 , 0) if (s[i] == 'I') lenI[i] = lenI[i + 1] + (s[i] == 'I'); else lenI[i] = 0;
    int res = 0;
    int last = 0;
    Rep(i , sz(s)) if (s[i] == 'O') {
        last++;
        if (i - last >= 0 && lenJ[i - last] >= last && lenI[i + 1] >= last) res = max(res , last);
    } else last = 0;
    cout << res << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //  freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
    ReadData();
    Process();
}