



"""simple docstring"""






from abc import ABC, abstractmethod
from typing import List, Optional






class        __snake_case       (	_lowercase):




  def __init__( self     :						str		):






         """simple docstring"""






         self.test()




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






         """simple docstring"""






         _lowerCamelCase						:				Union[str, Any]    			= 0
         _lowerCamelCase						:				Optional[int]    			= False
         while not completed:
                if counter == 1:
                       self.reset()
                _lowerCamelCase						:				Optional[int]    			= self.advance()
                if not self.does_advance(__lowerCAmelCase		):
                       raise Exception(
                           '''Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true.'''		)

                _lowerCamelCase			,    _lowerCamelCase			,    _lowerCamelCase						:				int    			= self.update(__lowerCAmelCase		)
                counter += 1

                if counter > 1_0_0_0_0:
                       raise Exception('''update() does not fulfill the constraint.'''		)

         if self.remaining() != 0:
                raise Exception('''Custom Constraint is not defined correctly.'''		)




  @abstractmethod
  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[int]		):






         """simple docstring"""






         raise NotImplementedError(
             f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''		)




  @abstractmethod
  def 						SCREAMING_SNAKE_CASE				( self     :						Tuple						,					__lowerCAmelCase     :						int		):






         """simple docstring"""






         raise NotImplementedError(
             f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''		)




  @abstractmethod
  def 						SCREAMING_SNAKE_CASE				( self     :						str						,					__lowerCAmelCase     :						int		):






         """simple docstring"""






         raise NotImplementedError(
             f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''		)




  @abstractmethod
  def 						SCREAMING_SNAKE_CASE				( self     :						List[str]		):






         """simple docstring"""






         raise NotImplementedError(
             f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''		)




  @abstractmethod
  def 						SCREAMING_SNAKE_CASE				( self     :						Any		):






         """simple docstring"""






         raise NotImplementedError(
             f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''		)




  @abstractmethod
  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[Any]						,					__lowerCAmelCase     :						Tuple=False		):






         """simple docstring"""






         raise NotImplementedError(
             f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''		)






class        __snake_case       (	_lowercase):




  def __init__( self     :						Optional[int]						,					__lowerCAmelCase     :						List[int]		):






         """simple docstring"""






         super(__lowerCAmelCase						,					self		).__init__()

         if not isinstance(__lowerCAmelCase						,					__lowerCAmelCase		) or len(__lowerCAmelCase		) == 0:
                raise ValueError(f'''`token_ids` has to be a non-empty list, but is {token_ids}.'''		)
         if any((not isinstance(__lowerCAmelCase						,					__lowerCAmelCase		) or token_id < 0) for token_id in token_ids		):
                raise ValueError(f'''Each list in `token_ids` has to be a list of positive integers, but is {token_ids}.'''		)

         _lowerCamelCase						:				Union[str, Any]    			= token_ids

         _lowerCamelCase						:				Dict    			= len(self.token_ids		)
         _lowerCamelCase						:				List[str]    			= -1  # the index of the currently fulfilled step
         _lowerCamelCase						:				List[Any]    			= False




  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[Any]		):






         """simple docstring"""






         if self.completed:
                return None
         return self.token_ids[self.fulfilled_idx + 1]




  def 						SCREAMING_SNAKE_CASE				( self     :						int						,					__lowerCAmelCase     :						int		):






         """simple docstring"""






         if not isinstance(__lowerCAmelCase						,					__lowerCAmelCase		):
                raise ValueError(f'''`token_id` has to be an `int`, but is {token_id} of type {type(__lowerCAmelCase		)}'''		)

         if self.completed:
                return False

         return token_id == self.token_ids[self.fulfilled_idx + 1]




  def 						SCREAMING_SNAKE_CASE				( self     :						Union[str, Any]						,					__lowerCAmelCase     :						int		):






         """simple docstring"""






         if not isinstance(__lowerCAmelCase						,					__lowerCAmelCase		):
                raise ValueError(f'''`token_id` has to be an `int`, but is {token_id} of type {type(__lowerCAmelCase		)}'''		)

         _lowerCamelCase						:				List[str]    			= False
         _lowerCamelCase						:				Union[str, Any]    			= False
         _lowerCamelCase						:				Optional[int]    			= False

         if self.does_advance(__lowerCAmelCase		):
                self.fulfilled_idx += 1
                _lowerCamelCase						:				List[Any]    			= True
                if self.fulfilled_idx == (self.seqlen - 1):
                       _lowerCamelCase						:				int    			= True
                _lowerCamelCase						:				Optional[Any]    			= completed
         else:
                # failed to make progress.
                _lowerCamelCase						:				str    			= True
                self.reset()
         return stepped, completed, reset




  def 						SCREAMING_SNAKE_CASE				( self     :						Dict		):






         """simple docstring"""






         _lowerCamelCase						:				str    			= False
         _lowerCamelCase						:				Tuple    			= 0




  def 						SCREAMING_SNAKE_CASE				( self     :						List[str]		):






         """simple docstring"""






         return self.seqlen - (self.fulfilled_idx + 1)




  def 						SCREAMING_SNAKE_CASE				( self     :						Dict						,					__lowerCAmelCase     :						Dict=False		):






         """simple docstring"""






         _lowerCamelCase						:				Optional[int]    			= PhrasalConstraint(self.token_ids		)

         if stateful:
                _lowerCamelCase						:				Any    			= self.seqlen
                _lowerCamelCase						:				List[Any]    			= self.fulfilled_idx
                _lowerCamelCase						:				Dict    			= self.completed

         return new_constraint






class        __snake_case       :




  def __init__( self     :						Dict						,					__lowerCAmelCase     :						List[List[int]]						,					__lowerCAmelCase     :						Dict=True		):






         """simple docstring"""






         _lowerCamelCase						:				Any    			= max([len(__lowerCAmelCase		) for one in nested_token_ids]		)

         _lowerCamelCase						:				Any    			= {}
         for token_ids in nested_token_ids:
                _lowerCamelCase						:				Dict    			= root
                for tidx, token_id in enumerate(__lowerCAmelCase		):
                       if token_id not in level:
                              _lowerCamelCase						:				List[Any]    			= {}

                       _lowerCamelCase						:				Union[str, Any]    			= level[token_id]

         if no_subsets and self.has_subsets(__lowerCAmelCase						,					__lowerCAmelCase		):
                raise ValueError(
                    '''Each list in `nested_token_ids` can\'t be a complete subset of another list, but is'''
                    f''' {nested_token_ids}.'''		)

         _lowerCamelCase						:				Dict    			= root




  def 						SCREAMING_SNAKE_CASE				( self     :						List[Any]						,					__lowerCAmelCase     :						int		):






         """simple docstring"""






         _lowerCamelCase						:				List[Any]    			= self.trie

         for current_token in current_seq:
                _lowerCamelCase						:				str    			= start[current_token]

         _lowerCamelCase						:				Any    			= list(start.keys()		)

         return next_tokens




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






         """simple docstring"""






         _lowerCamelCase						:				Dict    			= self.next_tokens(__lowerCAmelCase		)

         return len(__lowerCAmelCase		) == 0




  def 						SCREAMING_SNAKE_CASE				( self     :						List[Any]						,					__lowerCAmelCase     :						int		):






         """simple docstring"""






         _lowerCamelCase						:				Dict    			= list(root.values()		)
         if len(__lowerCAmelCase		) == 0:
                return 1
         else:
                return sum([self.count_leaves(__lowerCAmelCase		) for nn in next_nodes]		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Any						,					__lowerCAmelCase     :						int						,					__lowerCAmelCase     :						str		):






         """simple docstring"""






         _lowerCamelCase						:				Optional[Any]    			= self.count_leaves(__lowerCAmelCase		)
         return len(__lowerCAmelCase		) != leaf_count






class        __snake_case       (	_lowercase):




  def __init__( self     :						Dict						,					__lowerCAmelCase     :						List[List[int]]		):






         """simple docstring"""






         super(__lowerCAmelCase						,					self		).__init__()

         if not isinstance(__lowerCAmelCase						,					__lowerCAmelCase		) or len(__lowerCAmelCase		) == 0:
                raise ValueError(f'''`nested_token_ids` has to be a non-empty list, but is {nested_token_ids}.'''		)
         if any(not isinstance(__lowerCAmelCase						,					__lowerCAmelCase		) for token_ids in nested_token_ids		):
                raise ValueError(f'''`nested_token_ids` has to be a list of lists, but is {nested_token_ids}.'''		)
         if any(
             any((not isinstance(__lowerCAmelCase						,					__lowerCAmelCase		) or token_id < 0) for token_id in token_ids		)
             for token_ids in nested_token_ids		):
                raise ValueError(
                    f'''Each list in `nested_token_ids` has to be a list of positive integers, but is {nested_token_ids}.'''		)

         _lowerCamelCase						:				str    			= DisjunctiveTrie(__lowerCAmelCase		)
         _lowerCamelCase						:				Any    			= nested_token_ids

         _lowerCamelCase						:				List[Any]    			= self.trie.max_height
         _lowerCamelCase						:				Optional[int]    			= []
         _lowerCamelCase						:				List[str]    			= False




  def 						SCREAMING_SNAKE_CASE				( self     :						int		):






         """simple docstring"""






         _lowerCamelCase						:				Any    			= self.trie.next_tokens(self.current_seq		)

         if len(__lowerCAmelCase		) == 0:
                return None
         else:
                return token_list




  def 						SCREAMING_SNAKE_CASE				( self     :						List[Any]						,					__lowerCAmelCase     :						int		):






         """simple docstring"""






         if not isinstance(__lowerCAmelCase						,					__lowerCAmelCase		):
                raise ValueError(f'''`token_id` is supposed to be type `int`, but is {token_id} of type {type(__lowerCAmelCase		)}'''		)

         _lowerCamelCase						:				int    			= self.trie.next_tokens(self.current_seq		)

         return token_id in next_tokens




  def 						SCREAMING_SNAKE_CASE				( self     :						int						,					__lowerCAmelCase     :						int		):






         """simple docstring"""






         if not isinstance(__lowerCAmelCase						,					__lowerCAmelCase		):
                raise ValueError(f'''`token_id` is supposed to be type `int`, but is {token_id} of type {type(__lowerCAmelCase		)}'''		)

         _lowerCamelCase						:				int    			= False
         _lowerCamelCase						:				str    			= False
         _lowerCamelCase						:				Optional[Any]    			= False

         if self.does_advance(__lowerCAmelCase		):
                self.current_seq.append(__lowerCAmelCase		)
                _lowerCamelCase						:				List[str]    			= True
         else:
                _lowerCamelCase						:				List[Any]    			= True
                self.reset()

         _lowerCamelCase						:				List[str]    			= self.trie.reached_leaf(self.current_seq		)
         _lowerCamelCase						:				int    			= completed

         return stepped, completed, reset




  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[Any]		):






         """simple docstring"""






         _lowerCamelCase						:				Dict    			= False
         _lowerCamelCase						:				List[str]    			= []




  def 						SCREAMING_SNAKE_CASE				( self     :						List[Any]		):






         """simple docstring"""






         if self.completed:
                # since this can be completed without reaching max height
                return 0
         else:
                return self.seqlen - len(self.current_seq		)




  def 						SCREAMING_SNAKE_CASE				( self     :						str						,					__lowerCAmelCase     :						str=False		):






         """simple docstring"""






         _lowerCamelCase						:				Optional[Any]    			= DisjunctiveConstraint(self.token_ids		)

         if stateful:
                _lowerCamelCase						:				int    			= self.seqlen
                _lowerCamelCase						:				List[str]    			= self.current_seq
                _lowerCamelCase						:				Union[str, Any]    			= self.completed

         return new_constraint






class        __snake_case       :




  def __init__( self     :						str						,					__lowerCAmelCase     :						List[Constraint]		):






         """simple docstring"""






         _lowerCamelCase						:				Any    			= constraints

         # max # of steps required to fulfill a given constraint
         _lowerCamelCase						:				str    			= max([c.seqlen for c in constraints]		)
         _lowerCamelCase						:				List[Any]    			= len(__lowerCAmelCase		)
         _lowerCamelCase						:				str    			= False

         self.init_state()




  def 						SCREAMING_SNAKE_CASE				( self     :						List[Any]		):






         """simple docstring"""






         _lowerCamelCase						:				Union[str, Any]    			= []
         _lowerCamelCase						:				List[str]    			= None
         _lowerCamelCase						:				Any    			= [constraint.copy(stateful=__lowerCAmelCase		) for constraint in self.constraints]




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






         """simple docstring"""






         _lowerCamelCase						:				str    			= 0
         if self.inprogress_constraint:
                # extra points for having a constraint mid-fulfilled
                add += self.max_seqlen - self.inprogress_constraint.remaining()

         return (len(self.complete_constraints		) * self.max_seqlen) + add




  def 						SCREAMING_SNAKE_CASE				( self     :						str		):






         """simple docstring"""






         _lowerCamelCase						:				Union[str, Any]    			= []
         if self.inprogress_constraint is None:
                for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
                       _lowerCamelCase						:				Union[str, Any]    			= constraint.advance()
                       if isinstance(__lowerCAmelCase						,					__lowerCAmelCase		):
                              token_list.append(__lowerCAmelCase		)
                       elif isinstance(__lowerCAmelCase						,					__lowerCAmelCase		):
                              token_list.extend(__lowerCAmelCase		)
         else:
                _lowerCamelCase						:				Any    			= self.inprogress_constraint.advance()
                if isinstance(__lowerCAmelCase						,					__lowerCAmelCase		):
                       token_list.append(__lowerCAmelCase		)
                elif isinstance(__lowerCAmelCase						,					__lowerCAmelCase		):
                       token_list.extend(__lowerCAmelCase		)

         if len(__lowerCAmelCase		) == 0:
                return None
         else:
                return token_list




  def 						SCREAMING_SNAKE_CASE				( self     :						Dict						,					__lowerCAmelCase     :						Optional[List[int]]		):






         """simple docstring"""






         self.init_state()

         if token_ids is not None:
                for token in token_ids:
                       # completes or steps **one** constraint
                       _lowerCamelCase			,    _lowerCamelCase						:				str    			= self.add(__lowerCAmelCase		)

                       # the entire list of constraints are fulfilled
                       if self.completed:
                              break




  def 						SCREAMING_SNAKE_CASE				( self     :						List[str]						,					__lowerCAmelCase     :						int		):






         """simple docstring"""






         if not isinstance(__lowerCAmelCase						,					__lowerCAmelCase		):
                raise ValueError(f'''`token_id` should be an `int`, but is `{token_id}`.'''		)

         _lowerCamelCase			,    _lowerCamelCase						:				List[str]    			= False, False

         if self.completed:
                _lowerCamelCase						:				int    			= True
                _lowerCamelCase						:				Optional[Any]    			= False
                return complete, stepped

         if self.inprogress_constraint is not None:
                # In the middle of fulfilling a constraint. If the `token_id` *does* makes an incremental progress to current
                # job, simply update the state

                _lowerCamelCase			,    _lowerCamelCase			,    _lowerCamelCase						:				Tuple    			= self.inprogress_constraint.update(__lowerCAmelCase		)
                if reset:
                       # 1. If the next token breaks the progress, then we must restart.
                       #     e.g. constraint = "I love pies" and sequence so far is "I love" but `token_id` == "books".

                       #     But that doesn't mean we self.init_state(), since we only reset the state for this particular
                       #     constraint, not the full list of constraints.

                       self.pending_constraints.append(self.inprogress_constraint.copy(stateful=__lowerCAmelCase		)		)
                       _lowerCamelCase						:				List[str]    			= None

                if complete:
                       # 2. If the next token completes the constraint, move it to completed list, set
                       #     inprogress to None. If there are no pending constraints either, then this full list of constraints
                       #     is complete.

                       self.complete_constraints.append(self.inprogress_constraint		)
                       _lowerCamelCase						:				str    			= None

                       if len(self.pending_constraints		) == 0:
                              # we're done!
                              _lowerCamelCase						:				Any    			= True

         else:
                # Not in the middle of fulfilling a constraint. So does this `token_id` helps us step towards any of our list
                # of constraints?

                for cidx, pending_constraint in enumerate(self.pending_constraints		):
                       if pending_constraint.does_advance(__lowerCAmelCase		):
                              _lowerCamelCase			,    _lowerCamelCase			,    _lowerCamelCase						:				Any    			= pending_constraint.update(__lowerCAmelCase		)

                              if not stepped:
                                     raise Exception(
                                         '''`constraint.update(token_id)` is not yielding incremental progress, '''
                                         '''even though `constraint.does_advance(token_id)` is true.'''		)

                              if complete:
                                     self.complete_constraints.append(__lowerCAmelCase		)
                                     _lowerCamelCase						:				Optional[int]    			= None

                              if not complete and stepped:
                                     _lowerCamelCase						:				Union[str, Any]    			= pending_constraint

                              if complete or stepped:
                                     # If we made any progress at all, then it's at least not a "pending constraint".

                                     _lowerCamelCase						:				Union[str, Any]    			= (
                                         self.pending_constraints[:cidx] + self.pending_constraints[cidx + 1 :]
                                     )

                                     if len(self.pending_constraints		) == 0 and self.inprogress_constraint is None:
                                            # If there's no longer any pending after this and no inprogress either, then we must be
                                            # complete.

                                            _lowerCamelCase						:				List[Any]    			= True

                                     break  # prevent accidentally stepping through multiple constraints with just one token.

         return complete, stepped




  def 						SCREAMING_SNAKE_CASE				( self     :						Dict						,					__lowerCAmelCase     :						Dict=True		):






         """simple docstring"""






         _lowerCamelCase						:				Union[str, Any]    			= ConstraintListState(self.constraints		)  # we actually never though self.constraints objects
         # throughout this process. So it's at initialization state.

         if stateful:
                _lowerCamelCase						:				Optional[Any]    			= [
                    constraint.copy(stateful=__lowerCAmelCase		) for constraint in self.complete_constraints
                ]
                if self.inprogress_constraint is not None:
                       _lowerCamelCase						:				List[str]    			= self.inprogress_constraint.copy(stateful=__lowerCAmelCase		)
                _lowerCamelCase						:				Optional[int]    			= [constraint.copy() for constraint in self.pending_constraints]

         return new_state




"""simple docstring"""





from collections import defaultdict



def 						_lowerCAmelCase				(				UpperCamelCase_  ,				UpperCamelCase_				):
		__SCREAMING_SNAKE_CASE            = first_str.lower().strip()
		__SCREAMING_SNAKE_CASE            = second_str.lower().strip()

		# Remove whitespace
		__SCREAMING_SNAKE_CASE            = first_str.replace(""" """  ,				""""""				)
		__SCREAMING_SNAKE_CASE            = second_str.replace(""" """  ,				""""""				)

		# Strings of different lengths are not anagrams
		if len(UpperCamelCase_				) != len(UpperCamelCase_				):
				return False

		# Default values for count should be 0
		__SCREAMING_SNAKE_CASE            = defaultdict(UpperCamelCase_				)

		# For each character in input strings,
		# increment count in the corresponding
		for i in range(len(UpperCamelCase_				)				):
				count[first_str[i]] += 1
				count[second_str[i]] -= 1

		return all(_count == 0 for _count in count.values()				)


if __name__ == "__main__":
							from doctest import testmod

							testmod()
							__magic_name__       =			input("Enter the first string ").strip()
							__magic_name__       =			input("Enter the second string ").strip()

							__magic_name__       =			check_anagrams(input_a, input_b)
							print(F"""{input_a} and {input_b} are {"" if status else "not "}anagrams.""")




