Deterministic Finite State Machine

Input: