import java.util.*;
import java.io.*;
public class Sam21 {
static CharToknizer tok;
public static void main(String[] args) throws Exception {
tok = new CharToknizer(args[0]);
System.out.println(prog() && tok.isEof());
}
static boolean prog() {
if(tok.chk("a")) {
return ab() && prog();
} else {
return true;
}
}
static boolean ab() {
return tok.chkfwd("a") && tok.chkfwd("b");
}
}
class CharToknizer {
String str, tok;
int pos = -1;
boolean eof = false;
public CharToknizer(String s) { str = s; fwd(); }
public boolean isEof() { return eof; }
public String curTok() { return tok; }
public boolean chk(String s) { return tok.equals(s); }
public void fwd() {
if(eof) { return; }
pos += 1;
if(pos >= str.length()) { eof = true; tok = "$"; return; }
tok = str.substring(pos, pos+1);
}
public boolean chkfwd(String s) {
if(chk(s)) { fwd(); return true; } else { return false; }
}
}
static boolean prog() {
if(tok.chk("a") || tok.chk("b")) {
return ab() && prog();
} else {
return true;
}
}
static boolean ab() {
if(tok.chk("a")) {
return tok.chkfwd("a");
} else {
return tok.chkfwd("b") && tok.chkfwd("b");
}
}
static boolean prog() {
if(tok.chk("a")) {
tok.fwd();
if(tok.chk("a")) {
return prog();
} else {
return true;
}
} else {
return false;
}
}
}
static boolean prog() {
if(tok.chk("a")) {
return aa() && bb() && prog();
} else {
return true;
}
}
static boolean aa() {
if(tok.chk("a")) {
tok.fwd();
if(tok.chk("a")) {
return aa();
} else {
return true;
}
} else {
return false;
}
}
static boolean bb() {
if(tok.chk("b")) {
tok.fwd();
if(tok.chk("b")) {
return bb();
} else {
return true;
}
} else {
return false;
}
}
}
static boolean prog() {
if(tok.chk("1")) {
tok.fwd(); return true;
} else if(tok.chk("(")) {
return tok.chkfwd("(") && prog() && tok.chkfwd(")");
} else {
return false;
}
}
static boolean prog() {
if(term()) {
if(tok.chk("+")||tok.chk("-")||tok.chk("*")||tok.chk("/")) {
return op() && prog();
} else {
return true;
}
} else {
return false;
}
}
static boolean term() {
if(tok.chk("a")) {
tok.fwd(); return true;
} else if(tok.chk("1")) {
tok.fwd(); return true;
} else {
return tok.chkfwd("(") && prog() && tok.chkfwd(")");
}
}
static boolean op() {
return tok.chkfwd("+") || tok.chkfwd("-") ||
tok.chkfwd("*") || tok.chkfwd("/");
}
}