# Path: automata/tm/configuration.py
# class MTMConfiguration(collections.namedtuple(
#     'MTMConfiguration',
#     ['state', 'tapes']
# )):
#     """A Multitape Turing machine configuration."""
# 
#     def __repr__(self):
#         """Return a string representation of the configuration."""
#         return '{}(\'{}\', {})'.format(
#             self.__class__.__name__, self.state, self.tapes
#         )
# 
#     def print(self):
#         """Print the machine's current configuration in a readable form."""
#         description = '{}: \n'.format(self.state)
#         for i, tape in enumerate(self.tapes):
#             title = '> Tape {}: '.format(i+1)
#             position = tape.current_position + len(title) + 1
#             description += '> Tape {j}: {tape}\n{current_position}\n'.format(
#                 j=i+1,
#                 tape=''.join(tape).ljust(
#                     tape.current_position, '#'),
#                 current_position='^'.rjust(
#                     position
#                 ),
#             )
#         print(description)
# 
# class TMConfiguration(collections.namedtuple(
#     'TMConfiguration',
#     ['state', 'tape']
# )):
#     """A Turing machine configuration."""
# 
#     def __repr__(self):
#         """Return a string representation of the configuration."""
#         return '{}(\'{}\', {})'.format(
#             self.__class__.__name__, self.state, self.tape
#         )
# 
#     def print(self):
#         """Print the machine's current configuration in a readable form."""
#         print('{current_state}: {tape}\n{current_position}'.format(
#             current_state=self.state,
#             tape=''.join(self.tape).rjust(
#                 len(self.tape),
#                 self.tape.blank_symbol),
#             current_position='^'.rjust(
#                 self.tape.current_position + len(self.state) + 3
#             ),
#         ))
# 
# Path: automata/tm/tape.py
# class TMTape(collections.namedtuple(
#     'TMTape',
#     ['tape', 'blank_symbol', 'current_position']
# )):
#     """A Turing machine tape."""
# 
#     def __new__(cls, tape, *, blank_symbol, current_position=0):
#         """Initialize a new Turing machine tape."""
#         tape = list(tape)
#         # Make sure that there's something under the cursor.
#         while len(tape) <= current_position:
#             tape.append(blank_symbol)
#         tape = tuple(tape)
#         return super(TMTape, cls).__new__(
#             cls, tape, blank_symbol, current_position
#         )
# 
#     def load_symbols(self, input_str, head):
#         """Loads a given string in tape and sets the head to the given
#         value."""
#         return TMTape(
#             list(input_str),
#             blank_symbol=self.blank_symbol,
#             current_position=head
#         )
# 
#     def read_symbol(self):
#         """Read the symbol at the current position in the tape."""
#         return self.tape[self.current_position]
# 
#     def write_symbol(self, new_tape_symbol):
#         """Write the given symbol at the current position in the tape."""
#         tape_elements = list(self.tape)
#         tape_elements[self.current_position] = new_tape_symbol
#         return TMTape(
#             tape_elements,
#             blank_symbol=self.blank_symbol,
#             current_position=self.current_position
#         )
# 
#     def move(self, direction):
#         """Move the tape to the next symbol in the given direction."""
#         # Copy stuff.
#         new_tape = list(self.tape)
#         new_position = self.current_position
#         if direction == 'R':
#             new_position += 1
#         elif direction == 'N':
#             pass
#         elif direction == 'L':  # pragma: no branch
#             new_position -= 1
#         # Make sure that the cursor doesn't run off the end of the tape.
#         if new_position == -1:
#             new_tape.insert(0, self.blank_symbol)
#             new_position += 1
#         if new_position == len(new_tape):
#             new_tape.append(self.blank_symbol)
#         return TMTape(
#             new_tape,
#             blank_symbol=self.blank_symbol,
#             current_position=new_position
#         )
# 
#     def copy(self):
#         return TMTape(list(self.tape).copy(),
#                       blank_symbol=self.blank_symbol,
#                       current_position=self.current_position)
# 
#     def get_symbols_as_str(self):
#         return "".join(self.tape)
# 
#     def __len__(self):
#         """Return the number of symbols on the tape."""
#         return len(self.tape)  # TODO: do we count the blank symbols?
# 
#     def __iter__(self):
#         """Return an interator for the tape."""
#         return iter(self.tape)
# 
#     def __repr__(self):
#         """Return a string representation of the tape."""
#         return '{}(\'{}\', {})'.format(
#             self.__class__.__name__, ''.join(self.tape), self.current_position
#         )


import copy
import automata.base.exceptions as exceptions
import automata.tm.exceptions as tm_exceptions
import automata.tm.ntm as tm
from collections import deque
from automata.tm.configuration import MTMConfiguration, TMConfiguration
from automata.tm.tape import TMTape
                        # position of the virtual head of the current virtual
                        # tape.
                        if direction == 'R':
                            i += 1
                        elif direction == 'L':
                            i -= 1
                        else:  # direction == 'N'
                            i += 0

                        if extended_tape[i - 1] == tape_separator_symbol:
                            i -= 1
                            extended_tape = extended_tape[:i] + \
                                self.blank_symbol + \
                                head_symbol + extended_tape[i:]

                            i += 1
                        else:
                            extended_tape = (
                                extended_tape[:i] +
                                head_symbol + extended_tape[i:]
                            )

                    elif extended_tape[i] == tape_separator_symbol:
                        executing_changes = False

                    i += 1

            current_state = next_state
            yield {
                TMConfiguration(current_state,

# Path: automata/tm/configuration.py
# class MTMConfiguration(collections.namedtuple(
#     'MTMConfiguration',
#     ['state', 'tapes']
# )):
#     """A Multitape Turing machine configuration."""
# 
#     def __repr__(self):
#         """Return a string representation of the configuration."""
#         return '{}(\'{}\', {})'.format(
#             self.__class__.__name__, self.state, self.tapes
#         )
# 
#     def print(self):
#         """Print the machine's current configuration in a readable form."""
#         description = '{}: \n'.format(self.state)
#         for i, tape in enumerate(self.tapes):
#             title = '> Tape {}: '.format(i+1)
#             position = tape.current_position + len(title) + 1
#             description += '> Tape {j}: {tape}\n{current_position}\n'.format(
#                 j=i+1,
#                 tape=''.join(tape).ljust(
#                     tape.current_position, '#'),
#                 current_position='^'.rjust(
#                     position
#                 ),
#             )
#         print(description)
# 
# class TMConfiguration(collections.namedtuple(
#     'TMConfiguration',
#     ['state', 'tape']
# )):
#     """A Turing machine configuration."""
# 
#     def __repr__(self):
#         """Return a string representation of the configuration."""
#         return '{}(\'{}\', {})'.format(
#             self.__class__.__name__, self.state, self.tape
#         )
# 
#     def print(self):
#         """Print the machine's current configuration in a readable form."""
#         print('{current_state}: {tape}\n{current_position}'.format(
#             current_state=self.state,
#             tape=''.join(self.tape).rjust(
#                 len(self.tape),
#                 self.tape.blank_symbol),
#             current_position='^'.rjust(
#                 self.tape.current_position + len(self.state) + 3
#             ),
#         ))
# 
# Path: automata/tm/tape.py
# class TMTape(collections.namedtuple(
#     'TMTape',
#     ['tape', 'blank_symbol', 'current_position']
# )):
#     """A Turing machine tape."""
# 
#     def __new__(cls, tape, *, blank_symbol, current_position=0):
#         """Initialize a new Turing machine tape."""
#         tape = list(tape)
#         # Make sure that there's something under the cursor.
#         while len(tape) <= current_position:
#             tape.append(blank_symbol)
#         tape = tuple(tape)
#         return super(TMTape, cls).__new__(
#             cls, tape, blank_symbol, current_position
#         )
# 
#     def load_symbols(self, input_str, head):
#         """Loads a given string in tape and sets the head to the given
#         value."""
#         return TMTape(
#             list(input_str),
#             blank_symbol=self.blank_symbol,
#             current_position=head
#         )
# 
#     def read_symbol(self):
#         """Read the symbol at the current position in the tape."""
#         return self.tape[self.current_position]
# 
#     def write_symbol(self, new_tape_symbol):
#         """Write the given symbol at the current position in the tape."""
#         tape_elements = list(self.tape)
#         tape_elements[self.current_position] = new_tape_symbol
#         return TMTape(
#             tape_elements,
#             blank_symbol=self.blank_symbol,
#             current_position=self.current_position
#         )
# 
#     def move(self, direction):
#         """Move the tape to the next symbol in the given direction."""
#         # Copy stuff.
#         new_tape = list(self.tape)
#         new_position = self.current_position
#         if direction == 'R':
#             new_position += 1
#         elif direction == 'N':
#             pass
#         elif direction == 'L':  # pragma: no branch
#             new_position -= 1
#         # Make sure that the cursor doesn't run off the end of the tape.
#         if new_position == -1:
#             new_tape.insert(0, self.blank_symbol)
#             new_position += 1
#         if new_position == len(new_tape):
#             new_tape.append(self.blank_symbol)
#         return TMTape(
#             new_tape,
#             blank_symbol=self.blank_symbol,
#             current_position=new_position
#         )
# 
#     def copy(self):
#         return TMTape(list(self.tape).copy(),
#                       blank_symbol=self.blank_symbol,
#                       current_position=self.current_position)
# 
#     def get_symbols_as_str(self):
#         return "".join(self.tape)
# 
#     def __len__(self):
#         """Return the number of symbols on the tape."""
#         return len(self.tape)  # TODO: do we count the blank symbols?
# 
#     def __iter__(self):
#         """Return an interator for the tape."""
#         return iter(self.tape)
# 
#     def __repr__(self):
#         """Return a string representation of the tape."""
#         return '{}(\'{}\', {})'.format(
#             self.__class__.__name__, ''.join(self.tape), self.current_position
#         )


# Path: automata/tm/mntm.py
import copy
import automata.base.exceptions as exceptions
import automata.tm.exceptions as tm_exceptions
import automata.tm.ntm as tm
from collections import deque
from automata.tm.configuration import MTMConfiguration, TMConfiguration
from automata.tm.tape import TMTape

                        # position of the virtual head of the current virtual
                        # tape.
                        if direction == 'R':
                            i += 1
                        elif direction == 'L':
                            i -= 1
                        else:  # direction == 'N'
                            i += 0

                        if extended_tape[i - 1] == tape_separator_symbol:
                            i -= 1
                            extended_tape = extended_tape[:i] + \
                                self.blank_symbol + \
                                head_symbol + extended_tape[i:]

                            i += 1
                        else:
                            extended_tape = (
                                extended_tape[:i] +
                                head_symbol + extended_tape[i:]
                            )

                    elif extended_tape[i] == tape_separator_symbol:
                        executing_changes = False

                    i += 1

            current_state = next_state
            yield {
                TMConfiguration(current_state,

                                TMTape(extended_tape,