import java.io.*;
import java.util.*;

public class formula_gk {
    static Scanner in;
    static PrintWriter out;

    final int MAX_LENGTH = 1000;
    final int MAX_VARS = 100;

    String formula;
    int pos;
    char token;

    Map<String, Integer> vars = new HashMap<String, Integer>();

    static class Result {
        final long t;
        final long f;

        public Result(long t, long f) {
            this.t = t;
            this.f = f;
        }
    }

    public Result addVariable(String var) {
        if (!vars.containsKey(var)) {
            vars.put(var, 1);
        } else {
            vars.put(var, vars.get(var) + 1);
        }
        System.out.println(var + " " + vars.get(var));
        return new Result(1, 1);
    }

    public void nextToken() {
        while (pos < formula.length() && formula.charAt(pos) == ' ') {
            pos++;
        }
        if (pos < formula.length()) {
            token = formula.charAt(pos);
            pos++;
        } else {
            token = 0;
        }
    }

    public Result parseTerm() {
        if (token == '~') {
            nextToken();
            Result r = parseTerm();
            return new Result(r.f, r.t);
        } else if (token == '(') {
            nextToken();
            Result result = parseOr();
            nextToken();
            return result;
        } else if (Character.isLetter(token)) {
            String var = "" + token;
            nextToken();
            return addVariable(var);
        } else {
            throw new RuntimeException("" + token);
        }
    }

    public Result parseAnd() {
        Result op1 = parseTerm();
        while (token == '&') {
            nextToken();
            Result op2 = parseTerm();
            op1 = new Result(op1.t * op2.t, op1.f * op2.t + op1.t * op2.f + op1.f * op2.f);
        }
        return op1;
    }

    public Result parseOr() {
        Result op1 = parseAnd();
        while (token == '|') {
            nextToken();
            Result op2 = parseAnd();
            op1 = new Result(op1.f * op2.t + op1.t * op2.f + op1.t * op2.t, op1.f * op2.f);
        }
        return op1;
    }

    public void run() {
        formula = in.nextLine();
        pos = 0;
        nextToken();

        Result result = parseOr();        
        for (int c : vars.values()) {
            if (c > 1) {
                out.println("Invalid");
                return;
            }
        }
        out.println(result.t);
    }

    public static void main (String[] args) throws Exception {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);

        new formula_gk().run();

        in.close();
        out.close();
    }
}
