#include <bits/stdc++.h>
int main() {
  char a[1000002];
  int sum, i, kk, pp, len, w, tt, ff, rr, vv, wid, hh, ways;
  while (scanf("%s", a) != EOF) {
    len = strlen(a);
    ff = vv = rr = pp = wid = sum = 0;
    ways = 1;
    w = (a[len - 1] - 79) / 3;
    kk = 0;
    tt = 0;
    rr = 0;
    for (i = 0; i < len - 1; i++) {
      hh = w * (79 - a[i]) / 3;
      sum += hh;
      if (hh == -1) {
        tt++;
        ff -= rr;
        rr = 0;
        if (sum < kk) kk = sum;
      } else {
        rr++;
        ff += tt;
        tt = 0;
        if (vv < ff) vv = ff;
        if (pp < sum) {
          pp = sum;
          ff = 0;
          rr = 0;
        }
      }
    }
    if (ff > vv)
      wid = ff;
    else
      wid = vv;
    if (sum == kk)
      ways = 1;
    else if (sum - kk > pp || pp - sum < wid)
      ways = 0;
    else
      ways = pp - sum + kk + 1;
    printf("%d\n", ways);
  }
  return 0;
}
