Two-way deterministic finite automaton