Problem:
Testing Circuits
A Boolean expression is given.
In the expression, each variable appears exactly once.
Calculate the number of variable assignments that make the expression evaluate to true.
Input
A data set consists of only one line.
The Boolean expression is given by a string which consists of digits, x, (, ), |, &, and ~.
Other characters such as spaces are not contained.
The expression never exceeds 1,000,000 characters.
The grammar of the expressions is given by the following BNF.
<expression> ::= <term> | <expression> "|" <term>
<term> ::= <factor> | <term> "&" <factor>
<factor> ::= <variable> | "~" <factor> | "(" <expression> ")"
<variable> ::= "x" <number>
<number> ::= "1" | "2" |... | "999999" | "1000000"
The expression obeys this syntax and thus you do not have to care about grammatical errors.
When the expression contains N variables, each variable in {x1, x2,..., xN} appears exactly once.
Output
Output a line containing the number of variable assignments that make the expression evaluate to true in modulo 1,000,000,007.
Sample Input 1
(x1&x2)
Output for the Sample Input 1
1
Sample Input 2
(x1&x2)|(x3&x4)|(~(x5|x6)&(x7&x8))
Output for the Sample Input 2
121

Submitted solutions:

code_snippet: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define SE second
#define FI first
#define MP(x,y) make_pair(x,y)
const int MAXN = 1000010;
const int MOD = 1000000007;
char str[MAXN];
int sta[MAXN],stop,rig[MAXN];
pair<int,int> cal(int l,int r)
{
    long long a=1,b=1;
    int bef=-1,cnt=0;
    pair<int,int> tmp;
    bool flag=true;
    for(int i=l+1;i<r;)
    {
        if(str[i-1]=='|'&&!flag)
        {
            tmp=cal(i-1,r);
            i=r;
        }
        else
        {
            while(str[i]=='~')  ++cnt,++i;
            if(str[i]=='(')
            {
                tmp=cal(i,rig[i]);
                if(cnt&1)   swap(tmp.FI,tmp.SE);
                i=rig[i]+1;
                cnt=0;
            }
            else    if(str[i]=='x')
            {
                ++i;
                while(str[i]>='0'&&str[i]<='9') ++i;
                tmp=MP(1,1);
                cnt=0;
            }
        }
        if(bef==-1) a=tmp.FI,b=tmp.SE;
        else    if(!bef)    a=(a*(tmp.FI+tmp.SE)%MOD+b*tmp.FI%MOD)%MOD,b=b*tmp.SE%MOD;
        else    if(bef==1)  b=(a*tmp.SE%MOD+b*(tmp.FI+tmp.SE)%MOD)%MOD,a=a*tmp.FI%MOD;
        if(str[i]=='|') bef=0;
        else    if(str[i]=='&') bef=1;
        ++i;
        flag=false;
    }
    return MP((int)a,(int)b);
}
int main()
{
    //freopen("/home/moor/Code/input","r",stdin);
    while(scanf("%s",&str[1])==1)
    {
        int len=strlen(&str[1]);
        str[0]=' ';
        stop=0;
        for(int i=1;str[i];++i)
            if(str[i]=='(')
                sta[stop++]=i;
            else    if(str[i]==')')
                rig[sta[--stop]]=i;
        printf("%d\n",cal(0,len+1).FI);
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 51324
final_rank: 3

code_snippet: #pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define LL long long
const int mod=1000000007;
const int N=5000005;

char s[N];
struct node{
    LL a,b,c;
    int p;
};
LL sum[N];

node cal(vector<node> tr,char c,int i){
    node tmp;
    int sz=tr.size();
    LL res=0,fac=1;
    sum[sz]=1;
    for(int j=sz-1;j>=0;j--) sum[j]=(sum[j+1]*tr[j].c)%mod;
    tmp.c=sum[0];
    if(c=='|'){
        for(int j=0;j<sz;j++){
            res=(res+((((fac*tr[j].a)%mod)*sum[j+1])%mod))%mod;
            fac=(fac*tr[j].b)%mod;
        }
    }
    tmp.a=res;
    tmp.b=tmp.c-tmp.a;
    tmp.b=((tmp.b%mod)+mod)%mod;
    tmp.p=i;
    return tmp;
}

node dfs(int x,int l){
    vector<node>tr;
    char c='a';
    bool flag=true;
    for(int i=x;i<l;i++){
        if(s[i]=='('){
           node tmp=dfs(i+1,l);
           if(!flag){
               swap(tmp.a,tmp.b);
               flag=true;
           }
           tr.push_back(tmp);
           i=tmp.p;
        }
        else if(s[i]==')'){
            if(c=='&'){
                int sz=tr.size();
                if(sz==1) while(1);
                tr[sz-2].a=(tr[sz-2].a*tr[sz-1].a)%mod;
                tr[sz-2].c=(tr[sz-2].c*tr[sz-1].c)%mod;
                tr[sz-2].b=tr[sz-2].c-tr[sz-2].a;
                tr[sz-2].b=((tr[sz-2].b%mod)+mod)%mod;
                tr.erase(tr.end()-1);
            }
            c='|';
            return cal(tr,c,i);
        }
        else if(s[i]=='x'){
            i++;
            node tmp;
            tmp.a=tmp.b=1;
            tmp.c=2;
            if(!flag){
                flag=true;
                swap(tmp.a,tmp.b);
            }
            tr.push_back(tmp);
        }
        else if(s[i]=='~') flag=!flag;
        else{
            if(c=='a') c=s[i];
            else if(c=='&'){
                int sz=tr.size();
                if(sz==1) while(1);
                tr[sz-2].a=(tr[sz-2].a*tr[sz-1].a)%mod;
                tr[sz-2].c=(tr[sz-2].c*tr[sz-1].c)%mod;
                tr[sz-2].b=tr[sz-2].c-tr[sz-2].a;
                tr[sz-2].b=((tr[sz-2].b%mod)+mod)%mod;
                tr.erase(tr.end()-1);
                c=s[i];
            }
            else c=s[i];
        }
    }
    if(c=='&'){
        int sz=tr.size();
        if(sz==1) while(1);
        tr[sz-2].a=(tr[sz-2].a*tr[sz-1].a)%mod;
        tr[sz-2].c=(tr[sz-2].c*tr[sz-1].c)%mod;
        tr[sz-2].b=tr[sz-2].c-tr[sz-2].a;
        tr[sz-2].b=((tr[sz-2].b%mod)+mod)%mod;
        tr.erase(tr.end()-1);
    }
    c='|';
    return cal(tr,c,l-1);
}

int main(){
//    freopen("in","r",stdin);
    while(scanf("%s",s)!=EOF){
        int l=strlen(s);
        node res=dfs(0,l);
        cout<<res.a<<endl;
    }
    return 0;
}

//x0x1x2x3x4x5x6(x7&(x8&~x9))|(x10|x11&x12)|~x13x14x15
accuracy: 1
time_ms: 40
memory_kb: 91488
final_rank: 11

code_snippet: #pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define LL long long
const int mod=1000000007;
const int N=1000005;

char s[N];
struct node{
    LL a,b,c;
    int p;
};
LL sum[N];

node cal(vector<node> tr,char c,int i){
    node tmp;
    int sz=tr.size();
    LL res=0,fac=1;
    sum[sz]=1;
    for(int j=sz-1;j>=0;j--) sum[j]=(sum[j+1]*tr[j].c)%mod;
    tmp.c=sum[0];
    if(c=='|'){
        for(int j=0;j<sz;j++){
            res=(res+((((fac*tr[j].a)%mod)*sum[j+1])%mod))%mod;
            fac=(fac*tr[j].b)%mod;
        }
    }
    tmp.a=res;
    tmp.b=tmp.c-tmp.a;
    tmp.b=((tmp.b%mod)+mod)%mod;
    tmp.p=i;
    return tmp;
}

node dfs(int x,int l){
    vector<node>tr;
    char c='a';
    bool flag=true;
    for(int i=x;i<l;i++){
        if(s[i]=='('){
           node tmp=dfs(i+1,l);
           if(!flag){
               swap(tmp.a,tmp.b);
               flag=true;
           }
           tr.push_back(tmp);
           i=tmp.p;
        }
        else if(s[i]==')'){
            if(c=='&'){
                int sz=tr.size();
                if(sz<=1) while(1);
                tr[sz-2].a=(tr[sz-2].a*tr[sz-1].a)%mod;
                tr[sz-2].c=(tr[sz-2].c*tr[sz-1].c)%mod;
                tr[sz-2].b=tr[sz-2].c-tr[sz-2].a;
                tr[sz-2].b=((tr[sz-2].b%mod)+mod)%mod;
                tr.erase(tr.end()-1);
            }
            c='|';
            return cal(tr,c,i);
        }
        else if(s[i]=='x'){
            i++;
            node tmp;
            tmp.a=tmp.b=1;
            tmp.c=2;
            if(!flag){
                flag=true;
                swap(tmp.a,tmp.b);
            }
            tr.push_back(tmp);
        }
        else if(s[i]=='~') flag=!flag;
        else{
            if(c=='a') c=s[i];
            else if(c=='&'){
                int sz=tr.size();
                if(sz<=1) while(1);
                tr[sz-2].a=(tr[sz-2].a*tr[sz-1].a)%mod;
                tr[sz-2].c=(tr[sz-2].c*tr[sz-1].c)%mod;
                tr[sz-2].b=tr[sz-2].c-tr[sz-2].a;
                tr[sz-2].b=((tr[sz-2].b%mod)+mod)%mod;
                tr.erase(tr.end()-1);
                c=s[i];
            }
            else c=s[i];
        }
    }
    if(c=='&'){
        int sz=tr.size();
        if(sz<=1) while(1);
        tr[sz-2].a=(tr[sz-2].a*tr[sz-1].a)%mod;
        tr[sz-2].c=(tr[sz-2].c*tr[sz-1].c)%mod;
        tr[sz-2].b=tr[sz-2].c-tr[sz-2].a;
        tr[sz-2].b=((tr[sz-2].b%mod)+mod)%mod;
        tr.erase(tr.end()-1);
    }
    c='|';
    return cal(tr,c,l-1);
}

int main(){
//    freopen("in","r",stdin);
    while(scanf("%s",s)!=EOF){
        int l=strlen(s);
        node res=dfs(0,l);
        cout<<res.a<<endl;
    }
    return 0;
}

//x0x1x2x3x4x5x6(x7&(x8&~x9))|(x10|x11&x12)|~x13x14x15
accuracy: 1
time_ms: 40
memory_kb: 91784
final_rank: 12

code_snippet: #pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define LL long long
const int mod=1000000007;
const int N=1000005;

char s[N];
struct node{
    LL a,b,c;
    int p;
};
LL sum[N];

node cal(vector<node> tr,char c,int i){
    node tmp;
    int sz=tr.size();
    LL res=0,fac=1;
    sum[sz]=1;
    for(int j=sz-1;j>=0;j--) sum[j]=(sum[j+1]*tr[j].c)%mod;
    tmp.c=sum[0];
    if(c=='|'){
        for(int j=0;j<sz;j++){
            res=(res+((((fac*tr[j].a)%mod)*sum[j+1])%mod))%mod;
            fac=(fac*tr[j].b)%mod;
        }
    }
    tmp.a=res;
    tmp.b=tmp.c-tmp.a;
    tmp.b=((tmp.b%mod)+mod)%mod;
    tmp.p=i;
    return tmp;
}

node dfs(int x,int l){
    vector<node>tr;
    char c='a';
    bool flag=true;
    for(int i=x;i<l;i++){
        if(s[i]=='('){
           node tmp=dfs(i+1,l);
           if(!flag){
               swap(tmp.a,tmp.b);
               flag=true;
           }
           tr.push_back(tmp);
           i=tmp.p;
        }
        else if(s[i]==')'){
            if(c=='&'){
                int sz=tr.size();
                if(sz<=1) while(1);
                tr[sz-2].a=(tr[sz-2].a*tr[sz-1].a)%mod;
                tr[sz-2].c=(tr[sz-2].c*tr[sz-1].c)%mod;
                tr[sz-2].b=tr[sz-2].c-tr[sz-2].a;
                tr[sz-2].b=((tr[sz-2].b%mod)+mod)%mod;
                tr.erase(tr.end()-1);
            }
            c='|';
            return cal(tr,c,i);
        }
        else if(s[i]=='x'){
            i++;
            node tmp;
            tmp.a=tmp.b=1;
            tmp.c=2;
            if(!flag){
                flag=true;
                swap(tmp.a,tmp.b);
            }
            tr.push_back(tmp);
        }
        else if(s[i]=='~') flag=!flag;
        else{
            if(c=='a') c=s[i];
            else if(c=='&'){
                int sz=tr.size();
                if(sz<=1) while(1);
                tr[sz-2].a=(tr[sz-2].a*tr[sz-1].a)%mod;
                tr[sz-2].c=(tr[sz-2].c*tr[sz-1].c)%mod;
                tr[sz-2].b=tr[sz-2].c-tr[sz-2].a;
                tr[sz-2].b=((tr[sz-2].b%mod)+mod)%mod;
                tr.erase(tr.end()-1);
                c=s[i];
            }
            else c=s[i];
            if(c=='|'){
                node tmp=cal(tr,c,i);
                tr.clear();
                tr.push_back(tmp);
            }
        }
    }
    if(c=='&'){
        int sz=tr.size();
        if(sz<=1) while(1);
        tr[sz-2].a=(tr[sz-2].a*tr[sz-1].a)%mod;
        tr[sz-2].c=(tr[sz-2].c*tr[sz-1].c)%mod;
        tr[sz-2].b=tr[sz-2].c-tr[sz-2].a;
        tr[sz-2].b=((tr[sz-2].b%mod)+mod)%mod;
        tr.erase(tr.end()-1);
    }
    c='|';
    return cal(tr,c,l-1);
}

int main(){
//    freopen("in","r",stdin);
    while(scanf("%s",s)!=EOF){
        int l=strlen(s);
        node res=dfs(0,l);
        cout<<res.a<<endl;
    }
    return 0;
}

//x0x1x2x3x4x5x6(x7&(x8&~x9))|(x10|x11&x12)|~x13x14x15
accuracy: 1
time_ms: 50
memory_kb: 107604
final_rank: 13

code_snippet: #include <bits/stdc++.h>

constexpr long long MOD = 1000000007;

constexpr int N = 1000005;

std::array<long long, N> p2;

struct Data {
    long long num = 0;
    long long count = 0;

    Data() {}
    Data(long long num, long long count): num(num), count(count) {}

    long long T() const {
        return count;
    }

    long long F() const {
        return (p2[num] - count + MOD) % MOD;
    }

    friend Data operator|(const Data& lhs, const Data& rhs) {
        Data res;
        res.num = lhs.num + rhs.num;

        res.count += lhs.T() * rhs.T();
        res.count %= MOD;

        res.count += lhs.T() * rhs.F();
        res.count %= MOD;

        res.count += lhs.F() * rhs.T();
        res.count %= MOD;

        return res;
    }

    friend Data operator&(const Data& lhs, const Data& rhs) {
        Data res;
        res.num = lhs.num + rhs.num;

        res.count += lhs.T() * rhs.T();
        res.count %= MOD;

        return res;
    }

    Data operator~() {
        Data res;
        res.num = num;
        res.count = F();
        return res;
    }
};

struct Parser {
    using Iter = std::string::const_iterator&;
    std::string line;
    Parser(std::string s): line(s) {}

    void skip(Iter it, char c) {
        ++it;
    }

    Data parse() {
        auto it = line.cbegin();
        return expr(it);
    }

    Data expr(Iter it) {
        auto res = term(it);

        while (it != line.end() && *it == '|') {
            skip(it, '|');
            res = res | term(it);
        }

        return res;
    }

    Data term(Iter it) {
        auto res = factor(it);

        while (it != line.end() && *it == '&') {
            skip(it, '&');
            res = res & factor(it);
        }

        return res;
    }

    Data factor(Iter it) {
        bool flip = false;
        while (it != line.end() && *it == '~') {
            skip(it, '~');
            flip ^= true;
        }

        Data res;
        if (*it == '(') {
            skip(it, '(');
            res = expr(it);
            skip(it, ')');
        } else {
            res = variable(it);
        }

        if (flip) {
            res = ~res;
        }

        return res;
    }

    Data variable(Iter it) {
        skip(it, 'x');
        number(it);
        return Data(1, 1);
    }

    int number(Iter it) {
        int res = 0;
        while (it != line.end() && std::isdigit(*it)) {
            res = 10 * res + digit(it);
        }
        return res;
    }

    int digit(Iter it) {
        char c = *it;
        skip(it, c);
        return c - '0';
    }
};

int main() {
    p2.fill(1);
    for (int i = 1; i < N; i++) {
        p2[i] = 2 * p2[i - 1] % MOD;
    }

    std::string s;
    std::getline(std::cin, s);
    Parser parser(s);
    std::cout << parser.parse().count << std::endl;
}
accuracy: 1
time_ms: 30
memory_kb: 51756
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef __int128_t lll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef tuple<ll, ll, ll> tt;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pl> vp;
typedef vector<tt> vt;
typedef vector<string> vs;

const ll INF = 1000000010;
const ll INFL = INF * INF;
const ld epsilon = 1e-10;

#define ovl(a, b, c, d, e, ...) e
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define DEBUG(...) DEBUG_(#__VA_ARGS__, __VA_ARGS__)
#define REP1(i, r) for (int i = 0; i < (r); i++)
#define REP2(i, l, r) for (int i = (l); i < (r); i++)
#define REP3(i, l, r, d) for (int i = (l); i < (r); i += (d))
#define REP(...) ovl(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__)
#define RREP1(i, r) for (int i = (r)-1; i >= 0; i--)
#define RREP2(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define RREP3(i, l, r, d) for (int i = (r)-1; i >= (l); i -= (d))
#define RREP(...) ovl(__VA_ARGS__, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define EACH1(x, a) for (auto &x : a)
#define EACH2(x, y, a) for (auto &[x, y] : a)
#define EACH3(x, y, z, a) for (auto &[x, y, z] : a)
#define EACH(...) ovl(__VA_ARGS__, EACH3, EACH2, EACH1)(__VA_ARGS__)
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(), (x).rend()
#define sz(x) (ll) x.size()
#define LB(a, x) (lower_bound(ALL(a), x) - a.begin())
#define UB(a, x) (upper_bound(ALL(a), x) - a.begin())
#define FLG(x, i) (((x) >> (i)) & 1)
#define CNTBIT(x) __builtin_popcountll(x)
#define IN(x, a, b) ((a) <= (x) && (x) < (b))
#define int ll

template <class T>
void DEBUG_(string_view name, const T &a) {
    cerr << name << ": " << a << endl;
}

template <class T>
void DEBUG_(string_view name, const vector<T> &a) {
    cerr << name << ": ";
    REP(i, sz(a)) cerr << a[i] << " ";
    cerr << endl;
}

template <class T, class U>
bool chmax(T &x, const U &y) {
    return x < y ? x = y, 1 : 0;
}
template <class T, class U>
bool chmin(T &x, const U &y) {
    return x > y ? x = y, 1 : 0;
}

//-----------------------------------------------------------------------

typedef string::const_iterator State;
typedef pair<int, int> Res;

const int MOD = 1000000007;

Res factor(State &begin);

void number(State &begin) {
    while (isdigit(*begin)) {
        begin++;
    }
}

void variable(State &begin) {
    assert(*begin == 'x');
    begin++;
    number(begin);
}

Res term(State &begin) {
    Res res = factor(begin);
    while (true) {
        if (*begin == '&') {
            begin++;
            Res res2 = factor(begin);
            res = {res.first * res2.first % MOD,
                   (res.first * res2.second % MOD    //
                    + res.second * res2.first % MOD  //
                    + res.second * res2.second % MOD) %
                       MOD};
        } else {
            break;
        }
    }
    return res;
}

Res expression(State &begin) {
    Res res = term(begin);
    while (true) {
        if (*begin == '|') {
            begin++;
            Res res2 = term(begin);
            res = {(res.first * res2.first % MOD     //
                    + res.first * res2.second % MOD  //
                    + res.second * res2.first % MOD) %
                       MOD,
                   res.second * res2.second % MOD};
        } else {
            break;
        }
    }
    return res;
}

Res factor(State &begin) {
    if (*begin == 'x') {
        // begin++;
        variable(begin);
        return {1, 1};
    }
    if (*begin == '~') {
        begin++;
        Res res = factor(begin);
        return {res.second, res.first};
    }
    if (*begin == '(') {
        begin++;
        Res res = expression(begin);
        assert(*begin == ')');
        begin++;
        return res;
    }
    assert(false);
}

void solve() {
    string S;
    getline(cin, S);
    State begin = S.begin();
    Res res = expression(begin);
    cout << res.first << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    solve();

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 58644
final_rank: 6

code_snippet: #include <bits/stdc++.h>

using namespace std;

constexpr long long mod = 1000000007;

long long safe_mod(long long x) {
    return (x %= mod) < 0 ? x + mod : x;
}

int main() {
    string s;
    cin >> s;
    const int n = s.size();

    vector<int> rp(n, -1);
    {
        vector<int> st;
        for (int i = 0; i < n; ++i) {
            if (s[i] == '(') {
                st.push_back(i);
            } else if (s[i] == ')') {
                rp[st.back()] = i;
                st.pop_back();
            }
        }
    }

    auto dfs = [&](auto dfs, int l, int r) -> array<long long, 2> {
        while (rp[l] == r - 1) ++l, --r;
        
        vector<array<long long, 2>> st;
        for (int i = l; i < r;) {
            bool is_or = st.empty() or s[i - 1] == '|';

            bool neg = false;
            for (; s[i] == '~'; ++i) neg = not neg;

            auto f = [&](array<long long, 2> t) {
                if (is_or) {
                    st.push_back(t);
                } else {
                    auto [v0, v1] = st.back();
                    auto [t0, t1] = t;
                    long long a = (v0 + v1) * (t0 + t1) % mod;
                    long long n1 = t1 * v1 % mod;
                    long long n0 = safe_mod(a - n1);
                    st.back() = { n0, n1 };
                }
            };

            if (s[i] == '(') {
                int j = rp[i];
                auto t = dfs(dfs, i + 1, j);
                if (neg) swap(t[0], t[1]);
                f(t);
                i = j + 1;
            } else {
                assert(s[i] == 'x');
                int j = i + 1;
                while ('0' <= s[j] and s[j] <= '9') ++j;
                f({ 1, 1 });
                i = j;
            }
            if (i != r) ++i;
        }
        int len = st.size();
        auto [v0, v1] = st[0];
        for (int i = 1; i < len; ++i) {
            auto [t0, t1] = st[i];
            long long a = (v0 + v1) * (t0 + t1) % mod;
            long long n0 = t0 * v0 % mod;
            long long n1 = safe_mod(a - n0);
            v0 = n0, v1 = n1;
        }
        return { v0, v1 };
    };
    cout << dfs(dfs, 0, n)[1] << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 10876
final_rank: 1

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 1000005

struct State{
	State(int arg_left,int arg_right,int arg_depth){
		left = arg_left;
		right = arg_right;
		depth = arg_depth;
	}
	int left,right,depth;
};

enum Type{
	OR,
	AND,
	NEG,
	RANGE,
};

struct Info{
	Info(int arg_left,int arg_right,Type arg_type){
		left = arg_left;
		right = arg_right;
		type = arg_type;
	}
	Type type;
	int left,right;
};

struct OP{
	OP(Type arg_type,int arg_loc){
		type = arg_type;
		loc = arg_loc;
	}
	Type type;
	int loc;
};

struct EQ{
	int left,right;
	vector<Info> info;
};

int len;
char buf[SIZE];
vector<OP> V[SIZE];
map<pair<int,int>,pair<ll,ll>>MAP;


void calc(vector<Info> info,int left,int right,ll &ret_TRUE,ll &ret_FALSE){

	ll TRUE,FALSE,tmp_TRUE,tmp_FALSE;
	int tmp_index;

	for(int i =  right; i >= left; ){

		if(i == right){ //RANGEであるはず

			TRUE = MAP[make_pair(info[i].left,info[i].right)].first;
			FALSE = MAP[make_pair(info[i].left,info[i].right)].second;

			if(i > 0 && info[i-1].type == NEG){

				tmp_index = i-1;
				i -= 1;

				while(tmp_index >= 0 && info[tmp_index].type == NEG){

					swap(TRUE,FALSE);
					i -= 1;
					tmp_index--;
				}

			}else{

				i--;
			}

		}else{

			switch(info[i].type){
			case AND:

				tmp_TRUE = MAP[make_pair(info[i-1].left,info[i-1].right)].first;
				tmp_FALSE = MAP[make_pair(info[i-1].left,info[i-1].right)].second;

				if(i > 1 && info[i-2].type == NEG){

					tmp_index = i-2;
					i -= 2;

					while(tmp_index >= 0 && info[tmp_index].type == NEG){

						swap(tmp_TRUE,tmp_FALSE);
						i -= 1;
						tmp_index--;
					}
				}else{

					i -= 2;
				}

				FALSE = (tmp_TRUE+tmp_FALSE)*FALSE+TRUE*tmp_FALSE;
				FALSE %= MOD;

				TRUE *= tmp_TRUE;
				TRUE %= MOD;

				break;
			case NEG:

				tmp_index = i;

				while(tmp_index >= 0 && info[tmp_index].type == NEG){

					swap(TRUE,FALSE);
					i--;
					tmp_index--;
				}
				break;
			case RANGE:
				//printf("BUGGG!! Range\n");

				i--;
				break;
			}
		}
	}

	ret_TRUE = TRUE;
	ret_FALSE = FALSE;
}


int main(){

	scanf("%s",buf);

	int depth = 0;

	for(len = 0; buf[len] != '\0'; len++){

		if(buf[len] == '('){

			depth++;

		}else if(buf[len] == ')'){

			depth--;
		}

		switch(buf[len]){
		case '|':
			V[depth].push_back(OP(OR,len));
			break;
		case '&':
			V[depth].push_back(OP(AND,len));
			break;
		case '~':
			V[depth].push_back(OP(NEG,len));
			break;
		default:
			break;
		}
	}

	stack<State> S;  //処理すべき区間
	stack<EQ> Q; //式

	int L,R;
	int left,right,mid;
	int op_L,op_R;

	S.push(State(0,len-1,0));
	vector<OP> tmpOP;

	while(!S.empty()){

		L = S.top().left;
		R = S.top().right;
		depth = S.top().depth;

		S.pop();

		//この区間にOPがあるか
		tmpOP.clear();

		left = 0,right = V[depth].size()-1,mid = (left+right)/2;
		op_L = -1;

		while(left <= right){

			if(V[depth][mid].loc >= L){

				op_L = mid;
				right = mid-1;
			}else{

				left = mid+1;
			}
			mid = (left+right)/2;
		}


		if(op_L == -1){ //この区間にOPがない
			if(buf[L] == '(' && buf[R] == ')'){

				EQ eq;
				eq.left = L;
				eq.right = R;
				eq.info.push_back(Info(L+1,R-1,RANGE));
				Q.push(eq);

				S.push(State(L+1,R-1,depth+1));
				continue;
			}else{

				MAP[make_pair(L,R)] = make_pair(1,1);
				continue;
			}
		}

		left = 0,right = V[depth].size()-1,mid = (left+right)/2;
		op_R = -1;

		while(left <= right){

			if(V[depth][mid].loc <= R){

				op_R = mid;
				left = mid+1;
			}else{

				right = mid-1;
			}
			mid = (left+right)/2;
		}

		if(op_L > op_R){ //この区間にOPがない
			if(buf[L] == '(' && buf[R] == ')'){

				EQ eq;
				eq.left = L;
				eq.right = R;
				eq.info.push_back(Info(L+1,R-1,RANGE));
				Q.push(eq);

				S.push(State(L+1,R-1,depth+1));
				continue;
			}else{

				MAP[make_pair(L,R)] = make_pair(1,1);
				continue;
			}
		}

		EQ eq;
		eq.left =  L;
		eq.right = R;

		if(L == V[depth][op_L].loc){ //先頭NEGなので左なし

			//Do nothing

		}else{

			eq.info.push_back(Info(L,V[depth][op_L].loc-1,RANGE));
			S.push(State(L,V[depth][op_L].loc-1,depth));
		}

		for(int i = op_L; i <= op_R; i++){
			eq.info.push_back(Info(-1,-1,V[depth][i].type));
			if(i == op_R){

				eq.info.push_back(Info(V[depth][i].loc+1,R,RANGE));
				S.push(State(V[depth][i].loc+1,R,depth));
			}else{

				if(V[depth][i+1].loc-1 >= V[depth][i].loc+1){ //NEGの連続あり
					eq.info.push_back(Info(V[depth][i].loc+1,V[depth][i+1].loc-1,RANGE));
					S.push(State(V[depth][i].loc+1,V[depth][i+1].loc-1,depth));
				}
			}
		}
		Q.push(eq);
	}

	while(!Q.empty()){

		EQ eq = Q.top();
		Q.pop();

		ll TRUE,FALSE,tmp_TRUE,tmp_FALSE,work_TRUE;

		vector<int> work;

		for(int i = 0; i < eq.info.size(); i++){
			if(eq.info[i].type == OR){

				work.push_back(i);
			}
		}

		if(work.size() == 0){

			calc(eq.info,0,eq.info.size()-1,TRUE,FALSE);

		}else{

			calc(eq.info,work[work.size()-1]+1,eq.info.size()-1,TRUE,FALSE);

			for(int i = work.size()-2; i >= 0; i--){
				calc(eq.info,work[i]+1,work[i+1]-1,tmp_TRUE,tmp_FALSE);

				work_TRUE = tmp_TRUE*(TRUE+FALSE)+TRUE*tmp_FALSE;

				FALSE *= tmp_FALSE;
				FALSE %= MOD;

				TRUE = work_TRUE%MOD;
			}

			calc(eq.info,0,work[0]-1,tmp_TRUE,tmp_FALSE);

			work_TRUE = tmp_TRUE*(TRUE+FALSE)+TRUE*tmp_FALSE;

			FALSE *= tmp_FALSE;
			FALSE %= MOD;

			TRUE = work_TRUE%MOD;
		}
		MAP[make_pair(eq.left,eq.right)] = make_pair(TRUE,FALSE);
	}

	ll ans = MAP[make_pair(0,len-1)].first;

	printf("%lld\n",ans);

	return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 59396
final_rank: 9

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 1000005

struct State{
	State(int arg_left,int arg_right,int arg_depth){
		left = arg_left;
		right = arg_right;
		depth = arg_depth;
	}
	int left,right,depth;
};

enum Type{
	OR,
	AND,
	NEG,
	RANGE,
};

struct Info{
	Info(int arg_left,int arg_right,Type arg_type){
		left = arg_left;
		right = arg_right;
		type = arg_type;
	}
	Type type;
	int left,right;
};

struct OP{
	OP(Type arg_type,int arg_loc){
		type = arg_type;
		loc = arg_loc;
	}
	Type type;
	int loc;
};

struct EQ{
	int left,right;
	vector<Info> info;
};

int len;
char buf[SIZE];
vector<OP> V[SIZE];
map<pair<int,int>,pair<ll,ll>>MAP;


void calc(vector<Info> info,int left,int right,ll &ret_TRUE,ll &ret_FALSE){

	ll TRUE,FALSE,tmp_TRUE,tmp_FALSE;
	int tmp_index;

	for(int i =  right; i >= left; ){

		if(i == right){ //RANGEであるはず

			//printf("i:%d Range left:%d right:%d\n",i,eq.info[i].left,eq.info[i].right);

			TRUE = MAP[make_pair(info[i].left,info[i].right)].first;
			FALSE = MAP[make_pair(info[i].left,info[i].right)].second;

			if(i > 0 && info[i-1].type == NEG){

				tmp_index = i-1;
				i -= 1;

				while(tmp_index >= 0 && info[tmp_index].type == NEG){

					swap(TRUE,FALSE);
					i -= 1;
					tmp_index--;
				}

			}else{

				i--;
			}

			//printf("i:rigth TRUE:%lld FALSE:%lld\n",TRUE,FALSE);

		}else{

			switch(info[i].type){
			case AND:

				//printf("AND\n");

				tmp_TRUE = MAP[make_pair(info[i-1].left,info[i-1].right)].first;
				tmp_FALSE = MAP[make_pair(info[i-1].left,info[i-1].right)].second;

				//printf("tmp_TRUE,tmp_FALSE\n",tmp_TRUE,tmp_FALSE);

				if(i > 1 && info[i-2].type == NEG){

					tmp_index = i-2;
					i -= 2;

					while(tmp_index >= 0 && info[tmp_index].type == NEG){

						swap(tmp_TRUE,tmp_FALSE);
						i -= 1;
						tmp_index--;
					}
				}else{

					i -= 2;
				}

				FALSE = (tmp_TRUE+tmp_FALSE)*FALSE+TRUE*tmp_FALSE;
				FALSE %= MOD;

				TRUE *= tmp_TRUE;
				TRUE %= MOD;

				//printf("TRUE:%lld FALSE:%lld\n",TRUE,FALSE);

				break;
			case NEG:

				//printf("NEG\n");

				tmp_index = i;

				while(tmp_index >= 0 && info[tmp_index].type == NEG){

					swap(TRUE,FALSE);
					i--;
					tmp_index--;
				}

				//printf("TRUE:%lld FALSE:%lld\n",TRUE,FALSE);

				break;
			case RANGE:
				//printf("BUGGG!! Range\n");

				i--;
				break;
			}
		}
	}

	ret_TRUE = TRUE;
	ret_FALSE = FALSE;
}


int main(){

	scanf("%s",buf);

	int depth = 0;

	for(len = 0; buf[len] != '\0'; len++){

		if(buf[len] == '('){

			depth++;

		}else if(buf[len] == ')'){

			depth--;
		}

		switch(buf[len]){
		case '|':
			V[depth].push_back(OP(OR,len));
			break;
		case '&':
			V[depth].push_back(OP(AND,len));
			break;
		case '~':
			V[depth].push_back(OP(NEG,len));
			break;
		default:
			break;
		}
	}

	stack<State> S;  //処理すべき区間
	stack<EQ> Q; //式

	int L,R;
	int left,right,mid;
	int op_L,op_R;

	S.push(State(0,len-1,0));
	vector<OP> tmpOP;

	while(!S.empty()){

		L = S.top().left;
		R = S.top().right;
		depth = S.top().depth;

		//printf("L:%d R:%d depth:%d\n",L,R,depth);

		S.pop();

		//この区間にOPがあるか
		tmpOP.clear();

		left = 0,right = V[depth].size()-1,mid = (left+right)/2;
		op_L = -1;

		while(left <= right){

			if(V[depth][mid].loc >= L){

				op_L = mid;
				right = mid-1;
			}else{

				left = mid+1;
			}
			mid = (left+right)/2;
		}


		if(op_L == -1){ //この区間にOPがない
			if(buf[L] == '(' && buf[R] == ')'){

				EQ eq;
				eq.left = L;
				eq.right = R;
				eq.info.push_back(Info(L+1,R-1,RANGE));
				Q.push(eq);

				S.push(State(L+1,R-1,depth+1));
				continue;
			}else{

				MAP[make_pair(L,R)] = make_pair(1,1);
				//printf("%d-%dは変数\n",L,R);
				continue;
			}
		}

		left = 0,right = V[depth].size()-1,mid = (left+right)/2;
		op_R = -1;

		while(left <= right){

			if(V[depth][mid].loc <= R){

				op_R = mid;
				left = mid+1;
			}else{

				right = mid-1;
			}
			mid = (left+right)/2;
		}

		if(op_L > op_R){ //この区間にOPがない
			if(buf[L] == '(' && buf[R] == ')'){

				EQ eq;
				eq.left = L;
				eq.right = R;
				eq.info.push_back(Info(L+1,R-1,RANGE));
				Q.push(eq);

				S.push(State(L+1,R-1,depth+1));
				continue;
			}else{

				MAP[make_pair(L,R)] = make_pair(1,1);
				//printf("%d-%dは変数\n",L,R);
				continue;
			}
		}

		EQ eq;
		eq.left =  L;
		eq.right = R;

		if(L == V[depth][op_L].loc){ //先頭NEGなので左なし

			//Do nothing

		}else{

			eq.info.push_back(Info(L,V[depth][op_L].loc-1,RANGE));
			S.push(State(L,V[depth][op_L].loc-1,depth));
			//printf("区間%d-%dをpush\n",L,V[depth][op_L].loc-1);
		}

		for(int i = op_L; i <= op_R; i++){
			eq.info.push_back(Info(-1,-1,V[depth][i].type));
			if(i == op_R){

				eq.info.push_back(Info(V[depth][i].loc+1,R,RANGE));
				S.push(State(V[depth][i].loc+1,R,depth));
			}else{

				if(V[depth][i+1].loc-1 >= V[depth][i].loc+1){ //NEGの連続あり
					eq.info.push_back(Info(V[depth][i].loc+1,V[depth][i+1].loc-1,RANGE));
					S.push(State(V[depth][i].loc+1,V[depth][i+1].loc-1,depth));
				}
			}
		}
		Q.push(eq);
	}

	while(!Q.empty()){

		EQ eq = Q.top();
		Q.pop();

		ll TRUE,FALSE,tmp_TRUE,tmp_FALSE,work_TRUE;

		vector<int> work;

		for(int i = 0; i < eq.info.size(); i++){
			if(eq.info[i].type == OR){

				work.push_back(i);
			}
		}

		//printf("eq.left:%d eq.right:%d\n",eq.left,eq.right);

		if(work.size() == 0){

			calc(eq.info,0,eq.info.size()-1,TRUE,FALSE);

		}else{

			calc(eq.info,work[work.size()-1]+1,eq.info.size()-1,TRUE,FALSE);
			//printf("非0: %d-%dを計算して、TRUE;%lld FALSE:%lld\n",work[work.size()-1]+1,eq.info.size()-1,TRUE,FALSE);

			for(int i = work.size()-2; i >= 0; i--){
				calc(eq.info,work[i]+1,work[i+1]-1,tmp_TRUE,tmp_FALSE);

				//printf("%d-%d tmp_TRUE:%lld tmp_FALSE:%lld\n",work[i]+1,work[i+1]-1,tmp_TRUE,tmp_FALSE);

				work_TRUE = tmp_TRUE*(TRUE+FALSE)+TRUE*tmp_FALSE;

				FALSE *= tmp_FALSE;
				FALSE %= MOD;

				TRUE = work_TRUE%MOD;
			}

			calc(eq.info,0,work[0]-1,tmp_TRUE,tmp_FALSE);
			//printf("%d-%d tmp_TRUE:%lld tmp_FALSE:%lld\n",0,work[0]-1,tmp_TRUE,tmp_FALSE);

			work_TRUE = tmp_TRUE*(TRUE+FALSE)+TRUE*tmp_FALSE;

			FALSE *= tmp_FALSE;
			FALSE %= MOD;

			TRUE = work_TRUE%MOD;
		}

		//printf("TRUE:%lld FALSE:%lld\n",TRUE,FALSE);

		MAP[make_pair(eq.left,eq.right)] = make_pair(TRUE,FALSE);
	}

	ll ans = MAP[make_pair(0,len-1)].first;

	printf("%lld\n",ans);

	return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 59444
final_rank: 10

code_snippet: #include <bits/stdc++.h>

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

const ll MOD = (ll)1e9+7;

//string str;
char str[1000001];
//vector<ll> dp;
ll dp[20];

ll power(int num){
	ll ret = 1;
	for(int i = 0; i < 20; i++){
		if((num & (1 << i))){
			ret = (ret * dp[i])%MOD;
		}
	}
	//cerr << num << " " << "ret" << ret << endl;
	return ret;
}

pair<ll, int> expression(int &i);
pair<ll, int> term(int &i);
pair<ll, int> factor(int &i);
pair<ll, int> variable(int &i);

signed main(){
	dp[0] = 2;
	for(int i = 1; i < 20; i++){
		dp[i] = (dp[i-1]*dp[i-1])%MOD;
	}
	cin >> str;
	int i = 0;
	auto ans = expression(i);
	//cerr << ans.second << endl;
	cout << ans.first << endl;

	return 0;
}

pair<ll, int> expression(int &i){
	auto ret = term(i);
	if(str[i] == '|'){
		i++;
		auto right = expression(i);
		ll val = (power(ret.second)*right.first)%MOD;
		val = (val + power(right.second)*ret.first)%MOD;
		val = (val - (ret.first*right.first)%MOD + MOD)%MOD;
		ret = make_pair(val, ret.second+right.second);
	}
	//cerr << str.substr(0,i+1) << endl;
	//cerr << ret.first << " " << ret.second << endl;
	return ret;
}

pair<ll, int> term(int &i){
	auto ret = factor(i);
	if(str[i] == '&'){
		i++;
		auto right = term(i);
		ret = make_pair((ret.first*right.first)%MOD, ret.second+right.second);
	}
	return ret;
}

pair<ll, int> factor(int &i){
	switch(str[i]){
		case '~':{
			auto ret = factor(++i);
			ret.first = (MOD + power(ret.second) - ret.first)%MOD;
			return ret;
		}
		case '(':{
			auto ret = expression(++i);
			assert(str[i] == ')');
			++i;
			return ret;
		}
		default:
			return variable(i);
	}
}

pair<ll, int> variable(int &i){
	assert(str[i] == 'x');
	i++;
	while(isdigit(str[i]))i++;
	return make_pair(1ll, 1);
}
accuracy: 1
time_ms: 40
memory_kb: 50928
final_rank: 4

code_snippet: #include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <utility>

#define fprintf(...) void(0)

std::string reduce_paren(const std::string &s) {
  std::stack<std::pair<size_t, bool>> st;
  st.emplace(0, false);  // sentinel
  std::vector<size_t> red{s.length()};
  for (size_t i=0; i<s.length(); ++i) {
    if (s[i] == '~') continue;
    if (s[i] == 'x') continue;

    if (s[i] == '(') {
      st.emplace(i, false);
      continue;
    }

    if (s[i] == ')') {
      std::pair<size_t, bool> top=st.top();
      st.pop();
      if (!top.second || (top.first == 0 && i+1 == s.length())) {
        red.push_back(top.first);
        red.push_back(i);
      }
      continue;
    }

    if (s[i] == '&' || s[i] == '|') {
      // s[i] is any binary operation
      st.top().second = true;
      continue;
    }

    assert(false);
  }

  std::sort(red.begin(), red.end());
  std::string t;
  for (size_t i=0, j=0; i<s.length(); ++i) {
    if (i == red[j]) {
      ++j;
      continue;
    }
    t += s[i];
  }
  return t;
}

void preprocess(const std::string &s, std::string &t) {
  t.clear();
  for (char ch: s)
    if (!isdigit(ch))
      t += ch;

  t = reduce_paren(t);
}

constexpr intmax_t MOD=1e9+7;

class Circuit {
  intmax_t zero, one;

public:
  Circuit(): zero(1), one(1) {}
  Circuit(intmax_t zero, intmax_t one): zero(zero), one(one) {}

  Circuit &operator |=(const Circuit &oth) {
    intmax_t zz=(zero*oth.zero);
    intmax_t oo=(zero*oth.one+one*oth.zero+one*oth.one);
    zero = zz % MOD;
    one = oo % MOD;
    return *this;
  }

  Circuit operator &=(const Circuit &oth) {
    intmax_t zz=(zero*oth.zero+zero*oth.one+one*oth.zero);
    intmax_t oo=(one*oth.one);
    zero = zz % MOD;
    one = oo % MOD;
    return *this;
  }

  Circuit operator ~() const {
    return {one, zero};
  }

  intmax_t ways() const {
    return one;
  }
};

static const std::vector<std::string> ops={"|", "&"};
Circuit parse(const std::string &s, size_t &i, size_t preced=0) {
  // fprintf(stderr, "\r%zu", i);
  if (preced == ops.size()) {
    if (s[i] == '(') {
      Circuit res=parse(s, ++i, 0);
      assert(s[i] == ')');
      ++i;
      return res;
    }
    if (s[i] == '~') {
      return ~parse(s, ++i, preced);
    }
    if (s[i] == 'x') {
      while (++i < s.length() && isdigit(s[i])) {}
      return Circuit();
    }
    assert(false);
  }

  Circuit res=parse(s, i, preced+1);
  while (i < s.length()) {
    char op=s[i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    Circuit tmp=parse(s, ++i, preced+1);
    if (op == '&') res &= tmp;
    if (op == '|') res |= tmp;
  }
  return res;
}

char buf[1000010];
int main() {
  scanf("%s", buf);
  std::string s=std::move(buf), t;
  preprocess(s, t);
  fprintf(stderr, "%s\n", t.c_str());
  s.clear();
  size_t i=0;
  printf("%jd\n", parse(t, i).ways());
}
accuracy: 1
time_ms: 30
memory_kb: 21388
final_rank: 2

code_snippet: #include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>

#define BEGIN_STACK_EXTEND(size, extended, original) do {               \
    extended = malloc(size);                                            \
    char *dummy=(char*)alloca((1+(int)(((long long)extended)&127))*16); \
    *dummy = 0;                                                         \
    asm volatile(                                                       \
        "mov %%rsp, %%rbx\n\t"                                          \
        "mov %%rax, %%rsp"                                              \
        : "=b" (original)                                               \
        : "a" ((char*)extended+(size)-1024));                           \
  } while (0)
 
#define END_STACK_EXTEND(extended, original) do {                       \
    asm volatile(                                                       \
        "mov %%rax, %%rsp"                                              \
        :                                                               \
        : "a" (original));                                              \
    free(extended);                                                     \
  } while (0)

void preprocess(const std::string &s, std::string &t) {
  t.clear();
  for (char ch: s)
    if (!isdigit(ch))
      t += ch;
}

constexpr intmax_t MOD=1e9+7;

intmax_t modpow(intmax_t base, intmax_t iexp, intmax_t init=1) {
  intmax_t res=init%MOD;
  for (intmax_t dbl=base; iexp; iexp>>=1) {
    if (iexp & 1) res = res*dbl % MOD;
    dbl = dbl*dbl % MOD;
  }
  return res;
}

class Circuit {
  intmax_t a;
  int m;
  // (ways of evaluate-to-true, x)

public:
  Circuit(): a(1), m(1) {}
  Circuit(intmax_t a, int m): a(a), m(m) {}

  Circuit &operator |=(const Circuit &oth) {
    intmax_t b=oth.a, n=oth.m;
    intmax_t aa;

    aa = (modpow(2, m, b) + modpow(2, n, a)) % MOD;
    aa -= a*b % MOD;
    if (aa < 0) aa += MOD;
    a = aa;
    m += n;
    return *this;
  }

  Circuit operator &=(const Circuit &oth) {
    a *= oth.a;
    a %= MOD;
    m += oth.m;
    return *this;
  }

  Circuit operator ~() const {
    intmax_t tilde=modpow(2, m)-a;
    if (tilde < 0) tilde += MOD;
    return {tilde, m};
  }

  intmax_t ways() const {
    return a;
  }
};

static const std::vector<std::string> ops={"|", "&"};
Circuit parse(const std::string &s, size_t &i, size_t preced=0) {
  fprintf(stderr, "\r%zu", i);
  if (preced == ops.size()) {
    if (s[i] == '(') {
      Circuit res=parse(s, ++i, 0);
      assert(s[i] == ')');
      ++i;
      return res;
    }
    if (s[i] == '~') {
      return ~parse(s, ++i, preced);
    }
    if (s[i] == 'x') {
      while (++i < s.length() && isdigit(s[i])) {}
      // ++i;
      return Circuit();
    }
    assert(false);
  }

  Circuit res=parse(s, i, preced+1);
  while (i < s.length()) {
    char op=s[i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    Circuit tmp=parse(s, ++i, preced+1);
    if (op == '&') res &= tmp;
    if (op == '|') res |= tmp;
  }
  return res;
}

size_t closing(
    const std::string &s, size_t pos, char open, char close) {

  if (s[pos] != open) return pos;
  size_t opening=1;
  while (++pos < s.length()) {
    if (s[pos] == open) ++opening;
    if (s[pos] == close) if (--opening == 0) return ++pos;
  }
  assert(false);
}

char buf[1000010];
int main() {
  void *extended, *original;
  BEGIN_STACK_EXTEND(120*1024*1024, extended, original);

  scanf("%s", buf);
  std::string s=std::move(buf), t;
  preprocess(s, t);
  s.clear();
  size_t i=0;
  printf("%jd\n", parse(t, i).ways());

  END_STACK_EXTEND(extended, original);
}
accuracy: 0.9090909090909091
time_ms: 3060
memory_kb: 2912
final_rank: 20

code_snippet: #include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
 
constexpr ll M = 1e9+7;

pll expression(string const& s, int& p);
pll term(string const& s, int& p);
pll factor(string const& s, int& p);
void variable(string const& s, int& p);
 
pll expression(string const& s, int& p) {
    pll res = term(s, p);
    while(p < s.size() && s[p] == '|') {
        auto v2 = term(s, ++p);
        ll t1 = res.first, t2 = res.second;
        res.first = t1 * (v2.first + v2.second) + v2.first * (t1 + t2) - t1 * v2.first;
        res.second = t2 * v2.second;
        res.first %= M;
        res.second %= M;
    }
    return res;
}
 
pll term(string const& s, int& p) {
    pll res = factor(s, p);
    while(p < s.size() && s[p] == '&') {
        pll v2 = factor(s, ++p);
        ll t1 = res.first, t2 = res.second;
        res.first = t1 * v2.first;
        res.second = t2 * (v2.first + v2.second) + v2.second * (t1 + t2) - t2 * v2.second;
        res.first %= M;
        res.second %= M;
    }
    return res;
}
 
pll factor(string const& s, int& p) {
    if(s[p] == '~') {
        pll res = factor(s, ++p);
        swap(res.first, res.second);
        return res;
    }
    if(s[p] == '(') {
        auto res = expression(s, ++p);
        p++;
        return res;
    }
    if(s[p] == 'x') {
        variable(s, p);
        return make_pair(1, 1);
    }
    assert("factor error" && false);
}
 
void variable(string const& s, int& p) {
    ++p;
    while(isdigit(s[p])) {
        ++p;
    }
}
 
ll eord, enew;
 
int main() {
    const int SIZE = 128 * 1024 * 1024;
    void* p = malloc(SIZE);
    enew = (ll)p + SIZE - 1;
    __asm__("mov %rsp, eord");
    __asm__("mov enew, %rsp");
    string s;
    cin >> s;
    int pos = 0;
    cout << expression(s, pos).first << endl;
    __asm__("mov eord, %rsp");
}
accuracy: 1
time_ms: 40
memory_kb: 58932
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
 
constexpr ll M = 1e9+7;

string s;
int pos;
 
pll expression(string const& s, int& p);
pll term(string const& s, int& p);
pll factor(string const& s, int& p);
void variable(string const& s, int& p);
 
pll expression(string const& s, int& p) {
    pll res = term(s, p);
    while(p < s.size() && s[p] == '|') {
        auto v2 = term(s, ++p);
        ll t1 = res.first, t2 = res.second;
        res.first = t1 * (v2.first + v2.second) + v2.first * (t1 + t2) - t1 * v2.first;
        res.second = t2 * v2.second;
        res.first %= M;
        res.second %= M;
    }
    return res;
}
 
pll term(string const& s, int& p) {
    pll res = factor(s, p);
    while(p < s.size() && s[p] == '&') {
        pll v2 = factor(s, ++p);
        ll t1 = res.first, t2 = res.second;
        res.first = t1 * v2.first;
        res.second = t2 * (v2.first + v2.second) + v2.second * (t1 + t2) - t2 * v2.second;
        res.first %= M;
        res.second %= M;
    }
    return res;
}
 
pll factor(string const& s, int& p) {
    if(s[p] == '~') {
        pll res = factor(s, ++p);
        swap(res.first, res.second);
        return res;
    }
    if(s[p] == '(') {
        auto res = expression(s, ++p);
        p++;
        return res;
    }
    if(s[p] == 'x') {
        variable(s, p);
        return make_pair(1, 1);
    }
    assert("factor error" && false);
}
 
void variable(string const& s, int& p) {
    ++p;
    while(isdigit(s[p])) {
        ++p;
    }
    //cout << "x" << number(s, ++p) << endl;
}
 
ll eord, enew;
 
int main() {
    const int SIZE = 128 * 128 * 1024;
    void* p = malloc(SIZE);
    enew = (ll)p + SIZE - 1;
    __asm__("mov %rsp, eord");
    __asm__("mov enew, %rsp");
    cin >> s;
    pos = 0;
    cout << expression(s, pos).first << endl;
    __asm__("mov eord, %rsp");
}
accuracy: 0.9090909090909091
time_ms: 30
memory_kb: 20448
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

constexpr ll M = 1e9+7;

ll modpow(ll x, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) {
            (res *= x) %= M;
        }
        (x *= x) %= M;
        n >>= 1;
    }
    return res;
}

pll expression(string const& s, int& p);
pll term(string const& s, int& p);
pll factor(string const& s, int& p);
void variable(string const& s, int& p);
ll number(string const& s, int& p);

pll expression(string const& s, int& p) {
    vector<pll> v;
    v.push_back(term(s, p));
    while(p < s.size() && s[p] == '|') {
        v.push_back(term(s, ++p));
    }
    ll var = 0;
    for(auto& p : v) {
        var += p.first;
    }
    pll res = make_pair(var, modpow(2, var));
    ll tmp = 1;
    for(auto& p : v) {
        (tmp *= ((modpow(2, p.first) - p.second + M) % M)) %= M;
    }
    res.second = (res.second - tmp + M) % M;
    return res;
}

pll term(string const& s, int& p) {
    int pp = p;
    pll res = factor(s, p);
    while(p < s.size() && s[p] == '&') {
        pll v2 = factor(s, ++p);
        res.first += v2.first;
        (res.second *= v2.second) %= M;
    }
    return res;
}

pll factor(string const& s, int& p) {
    if(s[p] == '~') {
        pll res = factor(s, ++p);
        res.second = (modpow(2, res.first) - res.second + M) % M;
        return res;
    }
    if(s[p] == '(') {
        auto res = expression(s, ++p);
        p++;
        return res;
    }
    if(s[p] == 'x') {
        variable(s, p);
        return make_pair(1, 1);
    }
    assert("factor error" && false);
}

void variable(string const& s, int& p) {
    number(s, ++p);
    //cout << "x" << number(s, ++p) << endl;
}

ll number(string const& s, int& p) {
    ll res = 0;
    while(isdigit(s[p])) {
        res *= 10;
        res += s[p++] - '0';
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    int p = 0;
    cout << expression(s, p).second << endl;
}
accuracy: 0.9090909090909091
time_ms: 30
memory_kb: 20356
final_rank: 14

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"



const int mod = 1000000007;

string st;
int a;
pair<int, int>getexpr();
pair<int, int>getval() {
	assert(st[a] == 'x');
	a++;
	int num = 0;
	while (a!=st.size()&&isdigit(st[a])) {
		num = num * 10 + st[a] - '0';
		a++;
	}
	return make_pair(1, 1);
}
pair<int, int>getfact() {
	if (st[a] == '~') {
		a++;
		auto p = getfact();
		return make_pair(p.second, p.first);
	}
	else if (st[a] == '(') {
		a++;
		auto p(getexpr());
		a++;
		return p;
	}
	else {
		auto p(getval());
		return p;
	}
}
pair<int, int>getterm() {
	auto p=getfact();
	while (a != st.size()) {
		if (st[a] == '|'||st[a]==')')return p;
		else if (st[a] == '&') {
			a++;
			auto q = getfact();
			long long 	int aa = p.first, ab = p.second, ba = q.first, bb = q.second;
			long long int fst = ba*aa;
			long long int scd =  (aa + ab)*(ba + bb) - ba*aa;

			p = make_pair(fst%mod, scd%mod);
		}
	}
	return p;
}
pair<int, int> getexpr() {
	auto p(getterm());
	while (a != st.size()) {
		if (st[a] == '|') {
			a++;
			auto q = getterm();
			long long 	int aa = p.first, ab = p.second, ba = q.first, bb = q.second;
			long long int fst = (aa + ab)*(ba + bb) - bb*ab;
			long long int scd = bb*ab;
			p = make_pair(fst%mod, scd%mod);
		}
		else if(st[a]==')'){
			break;
		}
		else {
			break;
			assert(false);
		}
	}
	return p;
}
long long int eord, enew;
int main() {
	const int SZ = 128 * 1024 * 1024;
	void *p = malloc(SZ);
	enew = (long long)p + SZ - 1;

	__asm__("mov %rsp, eord");
	__asm__("mov enew, %rsp");

	cin >> st;
	a = 0;
	int ans = getexpr().first;
	cout << ans << endl;
	__asm__("mov eord, %rsp");
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 58576
final_rank: 7

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"



const int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}

#define MAX_MOD_N 1024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init(const int amax = MAX_MOD_N) {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < amax - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}

string st;
int a;
pair<Mod, Mod>getexpr();
pair<Mod, Mod>getval() {
	assert(st[a] == 'x');
	a++;
	int num = 0;
	while (a!=st.size()&&isdigit(st[a])) {
		num = num * 10 + st[a] - '0';
		a++;
	}
	return make_pair(1, 1);
}
pair<Mod, Mod>getfact() {
	if (st[a] == '~') {
		a++;
		auto p = getfact();
		return make_pair(p.second, p.first);
	}
	else if (st[a] == '(') {
		a++;
		auto p(getexpr());
		a++;
		return p;
	}
	else {
		auto p(getval());
		return p;
	}
}
pair<Mod, Mod>getterm() {
	auto p=getfact();
	while (a != st.size()) {
		if (st[a] == '|'||st[a]==')')return p;
		else if (st[a] == '&') {
			a++;
			auto q = getfact();
			p = make_pair(p.first*q.first, (p.first + p.second)*(q.first + q.second) - p.first*q.first);
		}
	}
	return p;
}
pair<Mod,Mod> getexpr() {
	auto p(getterm());
	while (a != st.size()) {
		if (st[a] == '|') {
			a++;
			auto q = getterm();
			p = make_pair( (p.first + p.second)*(q.first + q.second) - p.second*q.second, p.second*q.second);

		}
		else if(st[a]==')'){
			break;
		}
		else {
			break;
			assert(false);
		}
	}
	return p;
}

int main() {
	cin >> st;
	a = 0;
	Mod ans = getexpr().first;
	cout << ans << endl;
	return 0;
}
accuracy: 0.9090909090909091
time_ms: 30
memory_kb: 28524
final_rank: 19

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"



const int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}

#define MAX_MOD_N 1024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init(const int amax = MAX_MOD_N) {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < amax - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}

string st;
int a;
pair<Mod, Mod>getexpr();
pair<Mod, Mod>getval() {
	//assert(st[a] == 'x');
	a++;
	int num = 0;
	while (a!=st.size()&&isdigit(st[a])) {
		num = num * 10 + st[a] - '0';
		a++;
	}
	return make_pair(1, 1);
}
pair<Mod, Mod>getfact() {
	if (st[a] == '~') {
		a++;
		auto p = getfact();
		return make_pair(p.second, p.first);
	}
	else if (st[a] == '(') {
		a++;
		auto p(getexpr());
		a++;
		return p;
	}
	else {
		auto p(getval());
		return p;
	}
}
pair<Mod, Mod>getterm() {
	auto p=getfact();
	while (a != st.size()) {
		if (st[a] == '|'||st[a]==')')return p;
		else if (st[a] == '&') {
			a++;
			auto q = getfact();
			p = make_pair(p.first*q.first, (p.first + p.second)*(q.first + q.second) - p.first*q.first);
		}
	}
	return p;
}
pair<Mod,Mod> getexpr() {
	auto p(getterm());
	while (a != st.size()) {
		if (st[a] == '|') {
			a++;
			auto q = getterm();
			p = make_pair( (p.first + p.second)*(q.first + q.second) - p.second*q.second, p.second*q.second);

		}
		else if(st[a]==')'){
			break;
		}
		else {
			break;
			assert(false);
		}
	}
	return p;
}

int main() {
	cin >> st;
	a = 0;
	Mod ans = getexpr().first;
	cout << ans << endl;
	return 0;
}
accuracy: 0.9090909090909091
time_ms: 30
memory_kb: 28296
final_rank: 16

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"



const int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}

#define MAX_MOD_N 1024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init(const int amax = MAX_MOD_N) {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < amax - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}

string st;
int a;
pair<Mod, Mod>getexpr();
pair<Mod, Mod>getval() {
	assert(st[a] == 'x');
	a++;
	int num = 0;
	while (a!=st.size()&&isdigit(st[a])) {
		num = num * 10 + st[a] - '0';
		a++;
	}
	return make_pair(1, 1);
}
pair<Mod, Mod>getfact() {
	if (st[a] == '~') {
		a++;
		auto p = getfact();
		return make_pair(p.second, p.first);
	}
	else if (st[a] == '(') {
		a++;
		auto p(getexpr());
		a++;
		return p;
	}
	else {
		auto p(getval());
		return p;
	}
}
pair<Mod, Mod>getterm() {
	auto p=getfact();
	while (a != st.size()) {
		if (st[a] == '|'||st[a]==')')return p;
		else if (st[a] == '&') {
			a++;
			auto q = getfact();
			p = make_pair(p.first*q.first, (p.first + p.second)*(q.first + q.second) - p.first*q.first);
		}
	}
	return p;
}
pair<Mod,Mod> getexpr() {
	auto p(getterm());
	while (a != st.size()) {
		if (st[a] == '|') {
			a++;
			auto q = getterm();
			p = make_pair( (p.first + p.second)*(q.first + q.second) - p.second*q.second, p.second*q.second);

		}
		else if(st[a]==')'){
			break;
		}
		else {
			assert(false);
		}
	}
	return p;
}

int main() {
	cin >> st;
	a = 0;
	Mod ans = getexpr().first;
	cout << ans << endl;
	return 0;
}
accuracy: 0.9090909090909091
time_ms: 30
memory_kb: 28368
final_rank: 18

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;

string st;


const int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	assert(b.num != 0);
	return Mod(a) * inv(b);
}
Mod operator/=(Mod &a, const Mod b) {
	assert(b.num != 0);
	return a = a * inv(b);
}

#define MAX_MOD_N 1024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init() {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < MAX_MOD_N - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}
int a = 0;
pair<Mod, Mod>getva() {
	while (isdigit(st[a]) || isalpha(st[a]))a++;
	return make_pair(1, 1);
}
pair<Mod, Mod>getex();
pair<Mod, Mod>getfa() {
	if (st[a] == '~') {
		a++;
		pair<Mod, Mod>p(getfa());
		return make_pair(p.second, p.first);
	}
	else if (st[a] == '(') {
		a++;
		pair<Mod, Mod>p(getex());
		assert(st[a] == ')');
		a++;
		return p;
	}
	else {
		return getva();
	}
}
pair<Mod, Mod>gette() {
	auto p=getfa();
	if (st[a] == '&') {
		a++;
		auto q = gette();
		return make_pair(p.first*q.first, (p.first + p.second)*(q.first + q.second) - p.first*q.first);
	}
	else {
		return p;
	}

}
pair<Mod, Mod>getex() {
	auto p = gette();
	if (st[a] == '|') {
		a++;
		auto q = getex();
		return make_pair((p.first + p.second)*(q.first + q.second) - p.second*q.second, p.second*q.second);
	}
	else {
		return p;
	}
}
int main() {
	cin >> st;
	pair<Mod,Mod>p=getex();
	cout << p.first << endl;
	return 0;
}
accuracy: 0.9090909090909091
time_ms: 30
memory_kb: 28316
final_rank: 17