package thisandthat;

/*************************************************************************
 *  Compilation:  javac DFA.java
 *  Execution:    java DFA
 *  
 *  Simulate a DFA which recognizes the language of all strings over
 *  the binary alphabet { a, b } with a multiple of three b's.
 *
 *  % java DFA babbabab
 *  false
 *
 *  % java DFA babbaabbba
 *  true
 *
 *************************************************************************/

public class DFA {
    public static void main(String[] args) {
        String input = args[0];
        boolean[] accept = { true, false, false };
        int[][] next = { { 0, 1 },
                         { 1, 2 },
                         { 2, 0 }
                       };
        int state = 0;
        for (int i = 0; i < input.length(); i++) {
            state = next[state][input.charAt(i) - 'a'];
        }
        System.out.println(accept[state]);
    }
}   
