






from __future__ import annotations

import time

lowerCamelCase	:							Optional[int]				=list[tuple[int, int]]

lowerCamelCase	:							List[Any]				=[
    [0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 0, 0, 0, 0],  # 0 are free path whereas 1's are obstacles
    [0, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0, 0, 0],
    [1, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0],
]

lowerCamelCase	:							Dict				=[[-1, 0], [0, -1], [1, 0], [0, 1]]  # up, left, down, right





class 			__a  :







 def __init__(		self					:   Any							,   SCREAMING_SNAKE_CASE					:   int							,   SCREAMING_SNAKE_CASE					:   int							,   SCREAMING_SNAKE_CASE					:   int							,   SCREAMING_SNAKE_CASE					:   int							,   SCREAMING_SNAKE_CASE					:   Node | None						):


      '''simple docstring'''






      UpperCamelCase__			:   Dict       				=  pos_x
      UpperCamelCase__			:   Optional[int]       				=  pos_y
      UpperCamelCase__			:   Union[str, Any]       				=  (pos_y, pos_x)
      UpperCamelCase__			:   List[Any]       				=  goal_x
      UpperCamelCase__			:   str       				=  goal_y
      UpperCamelCase__			:   Optional[Any]       				=  parent







class 			__a  :







 def __init__(		self					:   Optional[Any]							,   SCREAMING_SNAKE_CASE					:   tuple[int, int]							,   SCREAMING_SNAKE_CASE					:   tuple[int, int]						):


      '''simple docstring'''






      UpperCamelCase__			:   Tuple       				=  Node(start[1]							,   start[0]							,   goal[1]							,   goal[0]							,   __lowercase						)
      UpperCamelCase__			:   Tuple       				=  Node(goal[1]							,   goal[0]							,   goal[1]							,   goal[0]							,   __lowercase						)

      UpperCamelCase__			:   Dict       				=  [self.start]
      UpperCamelCase__			:   Tuple       				=  False







 def 					__lowercase					(		self					:   Tuple						):


      '''simple docstring'''






      while self.node_queue:
           UpperCamelCase__			:   Optional[int]       				=  self.node_queue.pop(0						)

           if current_node.pos == self.target.pos:
                UpperCamelCase__			:   str       				=  True
                return self.retrace_path(__lowercase						)

           UpperCamelCase__			:   int       				=  self.get_successors(__lowercase						)

           for node in successors:
                self.node_queue.append(__lowercase						)

      if not self.reached:
           return [self.start.pos]
      return None







 def 					__lowercase					(		self					:   Optional[int]							,   SCREAMING_SNAKE_CASE					:   Node						):


      '''simple docstring'''






      UpperCamelCase__			:   int       				=  []
      for action in delta:
           UpperCamelCase__			:   Tuple       				=  parent.pos_x + action[1]
           UpperCamelCase__			:   Union[str, Any]       				=  parent.pos_y + action[0]
           if not (0 <= pos_x <= len(grid[0]						) - 1 and 0 <= pos_y <= len(__lowercase						) - 1):
                continue

           if grid[pos_y][pos_x] != 0:
                continue

           successors.append(
               Node(__lowercase							,   __lowercase							,   self.target.pos_y							,   self.target.pos_x							,   __lowercase						)						)
      return successors







 def 					__lowercase					(		self					:   Optional[int]							,   SCREAMING_SNAKE_CASE					:   Node | None						):


      '''simple docstring'''






      UpperCamelCase__			:   str       				=  node
      UpperCamelCase__			:   Tuple       				=  []
      while current_node is not None:
           path.append((current_node.pos_y, current_node.pos_x)						)
           UpperCamelCase__			:   Tuple       				=  current_node.parent
      path.reverse()
      return path







class 			__a  :







 def __init__(		self					:   Union[str, Any]							,   SCREAMING_SNAKE_CASE					:   str							,   SCREAMING_SNAKE_CASE					:   List[Any]						):


      '''simple docstring'''






      UpperCamelCase__			:   Any       				=  BreadthFirstSearch(__lowercase							,   __lowercase						)
      UpperCamelCase__			:   List[str]       				=  BreadthFirstSearch(__lowercase							,   __lowercase						)
      UpperCamelCase__			:   str       				=  False







 def 					__lowercase					(		self					:   Tuple						):


      '''simple docstring'''






      while self.fwd_bfs.node_queue or self.bwd_bfs.node_queue:
           UpperCamelCase__			:   str       				=  self.fwd_bfs.node_queue.pop(0						)
           UpperCamelCase__			:   int       				=  self.bwd_bfs.node_queue.pop(0						)

           if current_bwd_node.pos == current_fwd_node.pos:
                UpperCamelCase__			:   int       				=  True
                return self.retrace_bidirectional_path(
                    __lowercase							,   __lowercase						)

           UpperCamelCase__			:   Optional[int]       				=  current_bwd_node
           UpperCamelCase__			:   List[Any]       				=  current_fwd_node

           UpperCamelCase__			:   Optional[int]       				=  {
               self.fwd_bfs: self.fwd_bfs.get_successors(__lowercase						),
               self.bwd_bfs: self.bwd_bfs.get_successors(__lowercase						),
           }

           for bfs in [self.fwd_bfs, self.bwd_bfs]:
                for node in successors[bfs]:
                     bfs.node_queue.append(__lowercase						)

      if not self.reached:
           return [self.fwd_bfs.start.pos]
      return None







 def 					__lowercase					(		self					:   Tuple							,   SCREAMING_SNAKE_CASE					:   Node							,   SCREAMING_SNAKE_CASE					:   Node						):


      '''simple docstring'''






      UpperCamelCase__			:   Union[str, Any]       				=  self.fwd_bfs.retrace_path(__lowercase						)
      UpperCamelCase__			:   Union[str, Any]       				=  self.bwd_bfs.retrace_path(__lowercase						)
      bwd_path.pop()
      bwd_path.reverse()
      UpperCamelCase__			:   List[Any]       				=  fwd_path + bwd_path
      return path


if __name__ == "__main__":
 # all coordinates are given in format [y,x]
 import doctest

 doctest.testmod()
 lowerCamelCase	:							Union[str, Any]				=(0, 0)
 lowerCamelCase	:							Tuple				=(len(grid) - 1, len(grid[0]) - 1)
 for elem in grid:
  print(elem)

 lowerCamelCase	:							Union[str, Any]				=time.time()
 lowerCamelCase	:							Union[str, Any]				=BreadthFirstSearch(init, goal)
 lowerCamelCase	:							List[str]				=bfs.search()
 lowerCamelCase	:							Any				=time.time() - start_bfs_time

 print('''Unidirectional BFS computation time : ''', bfs_time)

 lowerCamelCase	:							Optional[int]				=time.time()
 lowerCamelCase	:							Union[str, Any]				=BidirectionalBreadthFirstSearch(init, goal)
 lowerCamelCase	:							Dict				=bd_bfs.search()
 lowerCamelCase	:							Dict				=time.time() - start_bd_bfs_time

 print('''Bidirectional BFS computation time : ''', bd_bfs_time)




import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import PaddingStrategy, logging
from .tokenization_realm import RealmTokenizer


A__								=						logging.get_logger(__name__)

A__								=						{'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

A__								=						{
    '''vocab_file''': {
        '''google/realm-cc-news-pretrained-embedder''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/vocab.txt'''
        ),
        '''google/realm-cc-news-pretrained-encoder''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/vocab.txt'''
        ),
        '''google/realm-cc-news-pretrained-scorer''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/vocab.txt'''
        ),
        '''google/realm-cc-news-pretrained-openqa''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/vocab.txt'''
        ),
        '''google/realm-orqa-nq-openqa''': '''https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/vocab.txt''',
        '''google/realm-orqa-nq-reader''': '''https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/vocab.txt''',
        '''google/realm-orqa-wq-openqa''': '''https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/vocab.txt''',
        '''google/realm-orqa-wq-reader''': '''https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/vocab.txt''',
    },
    '''tokenizer_file''': {
        '''google/realm-cc-news-pretrained-embedder''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/tokenizer.jsont'''
        ),
        '''google/realm-cc-news-pretrained-encoder''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/tokenizer.json'''
        ),
        '''google/realm-cc-news-pretrained-scorer''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/tokenizer.json'''
        ),
        '''google/realm-cc-news-pretrained-openqa''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/tokenizer.json'''
        ),
        '''google/realm-orqa-nq-openqa''': (
            '''https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/tokenizer.json'''
        ),
        '''google/realm-orqa-nq-reader''': (
            '''https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/tokenizer.json'''
        ),
        '''google/realm-orqa-wq-openqa''': (
            '''https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/tokenizer.json'''
        ),
        '''google/realm-orqa-wq-reader''': (
            '''https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/tokenizer.json'''
        ),
    },
}

A__								=						{
    '''google/realm-cc-news-pretrained-embedder''': 512,
    '''google/realm-cc-news-pretrained-encoder''': 512,
    '''google/realm-cc-news-pretrained-scorer''': 512,
    '''google/realm-cc-news-pretrained-openqa''': 512,
    '''google/realm-orqa-nq-openqa''': 512,
    '''google/realm-orqa-nq-reader''': 512,
    '''google/realm-orqa-wq-openqa''': 512,
    '''google/realm-orqa-wq-reader''': 512,
}

A__								=						{
    '''google/realm-cc-news-pretrained-embedder''': {'''do_lower_case''': True},
    '''google/realm-cc-news-pretrained-encoder''': {'''do_lower_case''': True},
    '''google/realm-cc-news-pretrained-scorer''': {'''do_lower_case''': True},
    '''google/realm-cc-news-pretrained-openqa''': {'''do_lower_case''': True},
    '''google/realm-orqa-nq-openqa''': {'''do_lower_case''': True},
    '''google/realm-orqa-nq-reader''': {'''do_lower_case''': True},
    '''google/realm-orqa-wq-openqa''': {'''do_lower_case''': True},
    '''google/realm-orqa-wq-reader''': {'''do_lower_case''': True},
}


class       a							(			__lowerCamelCase				):
		__lowerCAmelCase	:    List[Any]											=					VOCAB_FILES_NAMES
		__lowerCAmelCase	:    Optional[Any]											=					PRETRAINED_VOCAB_FILES_MAP
		__lowerCAmelCase	:    Optional[Any]											=					PRETRAINED_INIT_CONFIGURATION
		__lowerCAmelCase	:    Optional[Any]											=					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		__lowerCAmelCase	:    Optional[Any]											=					RealmTokenizer



		def __init__(     self     :Optional[Any]   ,__lowercase     :Dict=None   ,__lowercase     :Optional[int]=None   ,__lowercase     :Optional[Any]=True   ,__lowercase     :Optional[int]="[UNK]"   ,__lowercase     :List[str]="[SEP]"   ,__lowercase     :List[str]="[PAD]"   ,__lowercase     :int="[CLS]"   ,__lowercase     :str="[MASK]"   ,__lowercase     :Dict=True   ,__lowercase     :List[str]=None   ,**__lowercase     :Any   ,):
						super().__init__(
						    __lowercase   ,tokenizer_file=__lowercase   ,do_lower_case=__lowercase   ,unk_token=__lowercase   ,sep_token=__lowercase   ,pad_token=__lowercase   ,cls_token=__lowercase   ,mask_token=__lowercase   ,tokenize_chinese_chars=__lowercase   ,strip_accents=__lowercase   ,**__lowercase   ,)

						snake_case__	:      List[str]     		=	json.loads(self.backend_tokenizer.normalizer.__getstate__()  )
						if (
						    normalizer_state.get('''lowercase'''   ,__lowercase  ) != do_lower_case
						    or normalizer_state.get('''strip_accents'''   ,__lowercase  ) != strip_accents
						    or normalizer_state.get('''handle_chinese_chars'''   ,__lowercase  ) != tokenize_chinese_chars
						):
										snake_case__	:      Optional[int]     		=	getattr(__lowercase   ,normalizer_state.pop('''type'''  )  )
										snake_case__	:      List[Any]     		=	do_lower_case
										snake_case__	:      Optional[Any]     		=	strip_accents
										snake_case__	:      List[str]     		=	tokenize_chinese_chars
										snake_case__	:      Dict     		=	normalizer_class(**__lowercase  )

						snake_case__	:      Tuple     		=	do_lower_case



		def 	__lowerCamelCase			(     self     :Union[str, Any]   ,__lowercase     :Union[str, Any]   ,**__lowercase     :Any  ):
						snake_case__	:      Dict     		=	PaddingStrategy.MAX_LENGTH

						snake_case__	:      List[str]     		=	text
						snake_case__	:      int     		=	kwargs.pop('''text_pair'''   ,__lowercase  )
						snake_case__	:      Optional[int]     		=	kwargs.pop('''return_tensors'''   ,__lowercase  )

						snake_case__	:      str     		=	{
						    '''input_ids''': [],
						    '''attention_mask''': [],
						    '''token_type_ids''': [],
						}

						for idx, candidate_text in enumerate(__lowercase  ):
										if batch_text_pair is not None:
														snake_case__	:      Optional[int]     		=	batch_text_pair[idx]
										else:
														snake_case__	:      Tuple     		=	None

										snake_case__	:      List[str]     		=	super().__call__(__lowercase   ,__lowercase   ,return_tensors=__lowercase   ,**__lowercase  )

										snake_case__	:      Optional[Any]     		=	encoded_candidates.get('''input_ids'''  )
										snake_case__	:      Optional[Any]     		=	encoded_candidates.get('''attention_mask'''  )
										snake_case__	:      List[Any]     		=	encoded_candidates.get('''token_type_ids'''  )

										if encoded_input_ids is not None:
														output_data["input_ids"].append(__lowercase  )
										if encoded_attention_mask is not None:
														output_data["attention_mask"].append(__lowercase  )
										if encoded_token_type_ids is not None:
														output_data["token_type_ids"].append(__lowercase  )

						snake_case__	:      Any     		=	{key: item for key, item in output_data.items() if len(__lowercase  ) != 0}

						return BatchEncoding(__lowercase   ,tensor_type=__lowercase  )



		def 	__lowerCamelCase			(     self     :List[Any]   ,__lowercase     :Tuple   ,__lowercase     :Tuple=None  ):
						snake_case__	:      List[str]     		=	[self.cls_token_id] + token_ids_a + [self.sep_token_id]

						if token_ids_a:
										output += token_ids_a + [self.sep_token_id]

						return output



		def 	__lowerCamelCase			(     self     :List[str]   ,__lowercase     :List[int]   ,__lowercase     :Optional[List[int]] = None  ):
						snake_case__	:      Tuple     		=	[self.sep_token_id]
						snake_case__	:      Union[str, Any]     		=	[self.cls_token_id]
						if token_ids_a is None:
										return len(cls + token_ids_a + sep  ) * [0]
						return len(cls + token_ids_a + sep  ) * [0] + len(token_ids_a + sep  ) * [1]






		def 	__lowerCamelCase			(     self     :Optional[Any]   ,__lowercase     :str   ,__lowercase     :Optional[str] = None  ):
						snake_case__	:      Tuple     		=	self._tokenizer.model.save(__lowercase   ,name=__lowercase  )
						return tuple(__lowercase  )

