#include <bits/stdc++.h>
using namespace std;
 
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
 
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first 
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
 
const char nl = '\n';
const int INF = 1e9;
const int MOD = 1e9 + 7;
struct node{
    int type,l=-1,r=-1;
};
int cnt=0;
node t[(int)2e6+10];
int le=0;
string s;
void dfs(int& i,int tp){
    int c=0, x=cnt;
    t[x].type=tp;
    if(tp==2) return;
    for(;i<sz(s);i++){
        int type=-1;
        if(s[i]=='i')
            type=0;
        else if(s[i]=='x')
            type=1;
        else if(s[i]=='?')
            type=2;
        if(type!=-1){
            if(c==0){
                t[x].l=++cnt;
                dfs(++i,type);
            }
            else{
                t[x].r=++cnt;
                dfs(++i,type);
            }
            c++;
            //---
            if(type==2) le++;
        }
        if(c==2){
            i++;
            break;
        }
    }
}
vi lf;
int c=0;
int dfs2(int x){
    int l=-1,r=-1;
    if(t[x].l!=-1){
        l=dfs2(t[x].l);
    }
    if(t[x].r!=-1){
        r=dfs2(t[x].r);
    }
    if(t[x].type==0)
        return min(l,r);
    else if(t[x].type==1)
        return max(l,r);
    else {
        return lf[c++];
    }
}
int ans=0;
void dfs3(int x,int tp){
    if(t[x].type!=tp)
        return;
    else ans++;
    if(t[x].l!=-1){
        dfs3(t[x].l,tp);
    }
    if(t[x].r!=-1){
        dfs3(t[x].r,tp);
    }
}
void solve(){
    cin>>s;
    int x=0;
    F0R(i,sz(s)){
        if(s[i]=='i'){
            x=0;
            dfs(++i,0);
            break;
        }
        else if(s[i]=='x'){
            x=1;
            dfs(++i,1);
            break;
        }
    }
    dfs3(0,x);
    // dbg(cnt)
    // F0R(i,cnt){
    //     cout<<i<<" "<<t[i].type<<" "<<t[i].l<<" "<<t[i].r<<nl;
    // }
    // lf.resize(le);
    // iota(all(lf),1);
    // set<int> ans;
    // do{
    //     c=0;
    //     ans.insert(dfs2(0));
    // }while(next_permutation(all(lf)));
    // cout<<sz(ans)<<nl;
    // dbg(ans);
    cout<<le-ans<<nl;
}
 
int32_t main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int TC = 1;
    // cin >> TC;
    while(TC--){
        solve();
    }
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |