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

public class formula_md  {
	private static Scanner in;
	private static PrintWriter out;
	
	static final int OR = 1;
	static final int AND = 2;
	static final int NOT = 3;
	static final int VAR = 4;
	
	String formula;
	int pos;
	char token;
	ArrayList<Integer> op = new ArrayList<Integer>();
	ArrayList<Integer> op1 = new ArrayList<Integer>();
	ArrayList<Integer> op2 = new ArrayList<Integer>();
	int m;
	
	int addOp(int binOp, int oper1, int oper2) {
		op.add(binOp);
		op1.add(oper1);
		op2.add(oper2);
		return m++;
	}
	
	void nextToken() {
		while (pos < formula.length() && formula.charAt(pos) == ' ')
			pos++;
		if (pos == formula.length()) {
			token = 0;
			return;
		}
		token = formula.charAt(pos++);
	}
	
	int parseTerm() {
		if (token == '~') {
			nextToken();
			return addOp(NOT, parseTerm(), 0);
		}
		if (token == '(') {
			nextToken();
			int result = parseOr();
			if (token != ')')
				throw new RuntimeException("Invalid parentheses");
			nextToken();
			return result;
		}
		if (Character.isLetter(token)) {
			char var = token;
			nextToken();
			return addOp(VAR, (var >= 'a' && var <= 'z') ? (var - 'a') : (var - 'A' + 26), 0);
		}
		throw new RuntimeException("Invalid token: \"" + token + "\"");
	}
	
	int parseAnd() {
		int op1 = parseTerm();
		while (token == '&') {
			nextToken();
			op1 = addOp(AND, op1, parseTerm());
		}
		return op1;
	}
	
	int parseOr() {
		int op1 = parseAnd();
		while (token == '|') {
			nextToken();
			op1 = addOp(OR, op1, parseAnd());
		}
		return op1;
	}
	
	private void solve(String s) {
		formula = s;
		pos = 0;
		m = 0;
		nextToken();
		parseOr();
		int[] used = new int[m];
		long[] trues = new long[m];
		long[] vars = new long[m];
		boolean invalid = false;
		for (int i = 0; i < m; i++) {
			int o1 = op1.get(i);
			int o2 = op2.get(i);
			switch (op.get(i)) {
			case OR:
				trues[i] = (trues[o1] << used[o2]) + (trues[o2] << used[o1]) - trues[o1] * trues[o2];
				used[i] = used[o1] + used[o2];
				vars[i] = vars[o1] | vars[o2];
				if ((vars[o1] & vars[o2]) != 0)
					invalid = true;
				break;
			case AND:
				trues[i] = trues[o1] * trues[o2];
				used[i] = used[o1] + used[o2];
				vars[i] = vars[o1] | vars[o2];
				if ((vars[o1] & vars[o2]) != 0)
					invalid = true;
				break;
			case NOT:
				trues[i] = (1 << used[o1]) - trues[o1];
				used[i] = used[o1];
				vars[i] = vars[o1];
				break;
			case VAR:
				trues[i] = 1;
				used[i] = 1;
				vars[i] = 1L << o1;
				break;
			}
		}
		if (invalid)
			throw new RuntimeException("Not a repetition-free formula");
		out.println(trues[m - 1]);
	}
	
	public static void main(String[] args) throws Exception {
		Locale.setDefault(Locale.US);
		in = new Scanner(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		while (in.hasNext()) {
			new formula_md().solve(in.nextLine());
		}
		in.close();
		out.close();
	}
}
