#include <bits/stdc++.h>

int main() {
  long long n; std::cin >> n;
  // 3で割って
  int digit = 0;
  int sum = 0;
  int n_zero = 0; // 余り0の倍数の数
  int n_one = 0; // 余り1の倍数の数
  int n_two = 0; // 余り2の倍数の数
  // std::cout << n << std::endl;
  // std::string s;
  while (n) {
    int d = n%10;
    ++digit;
    sum += d;
    n_zero += (d%3 == 0);
    n_one += (d%3 == 1);
    n_two += (d%3 == 2);
    // s += ('0' + n%10);
    n /= 10;
  }
  int ans = -1;
  // 全部3の倍数
  if (sum % 3 == 0) ans = 0;
  else if (sum % 3 == 1) {
    if (n_one >= 1 && digit >= 2) ans = 1;
    else if (n_two >= 2 && digit >= 3) ans = 2;
  }
  else if (sum % 3 == 2) {
    if (n_two >= 1 && digit >= 2) ans = 1;
    else if (n_one >= 2 && digit >= 3) ans = 2;
  }
  std::cout << ans << std::endl;
  // std::cout << s << std::endl;
  // std::cout << n_zero << std::endl;
  // std::cout << n_one << std::endl;
  // std::cout << n_two << std::endl;

}

#include <bits/stdc++.h>
using namespace std;
#define ll long long

void make(vector<int>& v,vector<int>v1,int index,int &cnt){
    if(v1.size()>4) return;
    if(v1.size()==4){
        map<int,int> m;
        for(auto i: v1){
            m[i]++;
            //cout<<i<<" ";
        }
        //cout<<"\n";
        int pro=1;
        for(auto i: m){
            if(i.second==2) pro*=2;
            else if(i.second==3) pro*=6; 
            else if(i.second==4) pro*=24;
        }
        cnt+=(24/pro);
        return ;
    }
    for(int i=index;i<v.size();i++){
        v1.push_back(v[i]);
        make(v,v1,i,cnt);
        v1.pop_back();
    }
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    string s;
    cin>>s;
    vector<int> v,v1;
    int cnt=0;
    for(int i=0;i<10;i++){
        if(s[i]=='o') v.push_back(i);
        else if(s[i]=='?') v1.push_back(i);
    }
    if(v.size()>4) cout<<"0";
    else if(v.size()==4) cout<<"24";
    else{
        vector<int> v2;
        //cout<<v.size()<<" "<<v1.size()<<" ";
        for(int i=0;i<v.size();i++){
            v2.push_back(v[i]);
            v1.push_back(v[i]);
        }
        make(v1,v2,0,cnt);
        cout<<cnt;
    }
}