// ╔═══╗░░╔═══╗░░╔╗░╔╗╔═══╗╔═══╗╔╗░╔╗░
// ║╔═╗║░░║╔══╝░░║║░║║║╔═╗║║╔═╗║║║░║║░
// ║║░║║░░║╚══╗░░║╚═╝║║╚═╝║╚╝╔╝║║╚═╝║░
// ║╚═╝║░░║╔══╝░░║╔═╗║║╔═╗║╔═╝╔╝╚══╗║░
// ║╔═╗║╔╗║╚══╗╔╗║║░║║║╚═╝║║║╚═╗░░░║║░
// ╚╝░╚╝╚╝╚═══╝╚╝╚╝░╚╝╚═══╝╚═══╝░░░╚╝░


#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long int
#define ll long long int
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define W(x) int x;cin>>x;while(x--)
#define fr(n) for(int i=n-1;i>=0;i--)
#define mp make_pair
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ps(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define vi vector<int>
#define deb(x) cout<<#x<<"="<<x<<endl;
#define all(a) (a).begin(),(a).end()
#define pii pair<int,int>
#define sortall(x) sort(all(x))
#define mk(arr,n,type)  type *arr=new type[n];
#define vpi vector<pair<int,int> >
#define setbits(x) __builtin_popcountll(x)
#define zerbits(x) __builtinctzll(x)
#define mod 1000000007
#define inf 1e18
#define sz(x) (int)x.size()
#define vs vector<string>
#define itr(a) for(auto it=a.begin();it!=a.end();it++)
#define f first
#define s second
#define INT_SIZE 32
int mpow(int exp, int base);
//I don't know what the funciton aeh() does but it speeds up my mess
void aeh()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
set<string>ans;
bool isValid(string s,vector<int>necc)
{
  for(int i=0;i<necc.size();i++)
  {
    int fl=0;
    for(int j=0;j<s.size();j++)
    {
      if(s[j]-'0'==necc[i])
      {
        fl=1;break;
      }
    }
    if(!fl){
      return false;
    }
  }
  return true;
}
void gen(vector<int>&poss,vector<int>&necc,int curr=0,string cur="")
{
  cur+=to_string(poss[curr]);

  if(cur.size()==4&&isValid(cur,necc))
  {
    sortall(cur);
    ans.insert(cur);
    return;
  }
  else if(cur.size()==4)return;
  for(int i=0;i<poss.size();i++)
  {

    gen(poss,necc,i,cur);
  }

}
bool shouldSwap(char str[], int start, int curr)
{
    for (int i = start; i < curr; i++)
        if (str[i] == str[curr])
            return 0;
    return 1;
}
 
// Prints all distinct permutations in str[0..n-1]
void findPermutations(char str[], int index, int n)
{
    if (index >= n) {
        ans.insert(str);
        return;
    }
 
    for (int i = index; i < n; i++) {
 
        // Proceed further for str[i] only if it
        // doesn't match with any of the characters
        // after str[index]
        bool check = shouldSwap(str, index, i);
        if (check) {
            swap(str[index], str[i]);
            findPermutations(str, index + 1, n);
            swap(str[index], str[i]);
        }
    }
}
int32_t main()
{
  //aeh();
  string s;cin>>s;
  vector<int>poss;
  vector<int>necc;
  fi(s.size())
  {
    if(s[i]=='o')
    {
      necc.pb(i);
      poss.pb(i);
    }
    if(s[i]=='?')
      poss.pb(i);
  }
  fi(poss.size())
  {
      gen(poss,necc,i);
      
  }
  for(auto it:ans){
    char str[it.size()+1];
    strcpy(str, it.c_str());

    findPermutations(str,0,it.size());
    // cout<<it<<endl;
  }
  cout<<ans.size();
}

int mpow(int base, int exp)
{
  base %= mod;
  int result = 1;
  while (exp > 0)
  {
    if (exp & 1)result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}
#include <bits/stdc++.h>
using namespace std;

int A[200005], P[200005], F[200005];
vector<int> X;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int n;
    cin >> n;
    
    for (int i=1; i<=n; i++) {
        cin >> A[i];
        P[ A[i] ] = i;
    }
    
    for (int i=n; i>=1; i--) {
        while (P[i] != i) {
            int indx = P[i];
            
            if (F[indx]) {
                cout << -1 << "\n";
                return 0;
            }
            
            F[indx] = 1;
            X.push_back(indx);
            
            int j = A[indx + 1];
            swap(A[indx], A[indx + 1]);
            P[i] = indx + 1;
            P[j] = indx;
        }
    }
    
    if (X.size() < n - 1) {
        cout << -1 << "\n";
        return 0;
    }
    
    for (auto x : X) {
        cout << x << "\n";
    }
    
    return 0;
}
