#include<bits/stdc++.h> using namespace std; int main(){ string a; cin>>a; int t=a.size(); int top=0; for(int i=0;i<t;i++){ if(top==1){ top++; } if(a[i]=='P'){ top--; }else{ top++; } } cout<<top-1; return 0; }