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






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''


   def __init__(					self     :							Optional[Any]     ):

      """simple docstring"""
      # test for the above condition
      self.test()


   def  __magic_name__				(					self     :							Any     ):

      """simple docstring"""
      _A:  Tuple					=       0
      _A:  Union[str, Any]					=       False
      while not completed:
         if counter == 1:
            self.reset()
         _A:  List[Any]					=       self.advance()
         if not self.does_advance(lowerCAmelCase_     ):
            raise Exception(
                '''Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true.'''     )

         _A			,  _A			,  _A:  Any					=       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  __magic_name__				(					self     :							int     ):

      """simple docstring"""
      raise NotImplementedError(
          F"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""     )


   @abstractmethod
   def  __magic_name__				(					self     :							List[str]			,			lowerCAmelCase_     :							int     ):

      """simple docstring"""
      raise NotImplementedError(
          F"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""     )


   @abstractmethod
   def  __magic_name__				(					self     :							List[str]			,			lowerCAmelCase_     :							int     ):

      """simple docstring"""
      raise NotImplementedError(
          F"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""     )


   @abstractmethod
   def  __magic_name__				(					self     :							Any     ):

      """simple docstring"""
      raise NotImplementedError(
          F"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""     )


   @abstractmethod
   def  __magic_name__				(					self     :							List[Any]     ):

      """simple docstring"""
      raise NotImplementedError(
          F"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""     )


   @abstractmethod
   def  __magic_name__				(					self     :							Dict			,			lowerCAmelCase_     :							Optional[Any]=False     ):

      """simple docstring"""
      raise NotImplementedError(
          F"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""     )






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''


   def __init__(					self     :							Dict			,			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}."""     )

      _A:  Optional[int]					=       token_ids

      _A:  Dict					=       len(self.token_ids     )
      _A:  int					=       -1  # the index of the currently fulfilled step
      _A:  Optional[Any]					=       False


   def  __magic_name__				(					self     :							Any     ):

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


   def  __magic_name__				(					self     :							str			,			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  __magic_name__				(					self     :							Tuple			,			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_     )}"""     )

      _A:  Optional[int]					=       False
      _A:  List[Any]					=       False
      _A:  Any					=       False

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


   def  __magic_name__				(					self     :							Dict     ):

      """simple docstring"""
      _A:  Any					=       False
      _A:  List[str]					=       0


   def  __magic_name__				(					self     :							Any     ):

      """simple docstring"""
      return self.seqlen - (self.fulfilled_idx + 1)


   def  __magic_name__				(					self     :							List[Any]			,			lowerCAmelCase_     :							Any=False     ):

      """simple docstring"""
      _A:  Union[str, Any]					=       PhrasalConstraint(self.token_ids     )

      if stateful:
         _A:  Tuple					=       self.seqlen
         _A:  Any					=       self.fulfilled_idx
         _A:  Optional[Any]					=       self.completed

      return new_constraint






class UpperCAmelCase   :





   '''simple docstring'''


   def __init__(					self     :							Union[str, Any]			,			lowerCAmelCase_     :							List[List[int]]			,			lowerCAmelCase_     :							List[Any]=True     ):

      """simple docstring"""
      _A:  Tuple					=       max([len(lowerCAmelCase_     ) for one in nested_token_ids]     )

      _A:  List[str]					=       {}
      for token_ids in nested_token_ids:
         _A:  Optional[int]					=       root
         for tidx, token_id in enumerate(lowerCAmelCase_     ):
            if token_id not in level:
               _A:  List[str]					=       {}

            _A:  str					=       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}."""     )

      _A:  Tuple					=       root


   def  __magic_name__				(					self     :							Dict			,			lowerCAmelCase_     :							Any     ):

      """simple docstring"""
      _A:  int					=       self.trie

      for current_token in current_seq:
         _A:  Any					=       start[current_token]

      _A:  List[str]					=       list(start.keys()     )

      return next_tokens


   def  __magic_name__				(					self     :							List[str]			,			lowerCAmelCase_     :							int     ):

      """simple docstring"""
      _A:  Optional[int]					=       self.next_tokens(lowerCAmelCase_     )

      return len(lowerCAmelCase_     ) == 0


   def  __magic_name__				(					self     :							Optional[int]			,			lowerCAmelCase_     :							Any     ):

      """simple docstring"""
      _A:  List[Any]					=       list(root.values()     )
      if len(lowerCAmelCase_     ) == 0:
         return 1
      else:
         return sum([self.count_leaves(lowerCAmelCase_     ) for nn in next_nodes]     )


   def  __magic_name__				(					self     :							Tuple			,			lowerCAmelCase_     :							List[str]			,			lowerCAmelCase_     :							List[str]     ):

      """simple docstring"""
      _A:  Union[str, Any]					=       self.count_leaves(lowerCAmelCase_     )
      return len(lowerCAmelCase_     ) != leaf_count






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''


   def __init__(					self     :							Any			,			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}."""     )

      _A:  Tuple					=       DisjunctiveTrie(lowerCAmelCase_     )
      _A:  Union[str, Any]					=       nested_token_ids

      _A:  Optional[int]					=       self.trie.max_height
      _A:  Union[str, Any]					=       []
      _A:  List[Any]					=       False


   def  __magic_name__				(					self     :							Tuple     ):

      """simple docstring"""
      _A:  Optional[int]					=       self.trie.next_tokens(self.current_seq     )

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


   def  __magic_name__				(					self     :							Optional[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_     )}"""     )

      _A:  List[str]					=       self.trie.next_tokens(self.current_seq     )

      return token_id in next_tokens


   def  __magic_name__				(					self     :							Union[str, 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_     )}"""     )

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

      if self.does_advance(lowerCAmelCase_     ):
         self.current_seq.append(lowerCAmelCase_     )
         _A:  int					=       True
      else:
         _A:  Union[str, Any]					=       True
         self.reset()

      _A:  Union[str, Any]					=       self.trie.reached_leaf(self.current_seq     )
      _A:  Optional[Any]					=       completed

      return stepped, completed, reset


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

      """simple docstring"""
      _A:  Dict					=       False
      _A:  str					=       []


   def  __magic_name__				(					self     :							Optional[int]     ):

      """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  __magic_name__				(					self     :							List[str]			,			lowerCAmelCase_     :							Any=False     ):

      """simple docstring"""
      _A:  List[Any]					=       DisjunctiveConstraint(self.token_ids     )

      if stateful:
         _A:  Tuple					=       self.seqlen
         _A:  int					=       self.current_seq
         _A:  List[str]					=       self.completed

      return new_constraint






class UpperCAmelCase   :





   '''simple docstring'''


   def __init__(					self     :							Optional[Any]			,			lowerCAmelCase_     :							List[Constraint]     ):

      """simple docstring"""
      _A:  Union[str, Any]					=       constraints

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

      self.init_state()


   def  __magic_name__				(					self     :							Any     ):

      """simple docstring"""
      _A:  Tuple					=       []
      _A:  Optional[int]					=       None
      _A:  Dict					=       [constraint.copy(stateful=lowerCAmelCase_     ) for constraint in self.constraints]


   def  __magic_name__				(					self     :							Dict     ):

      """simple docstring"""
      _A:  Any					=       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  __magic_name__				(					self     :							Optional[int]     ):

      """simple docstring"""
      _A:  List[Any]					=       []
      if self.inprogress_constraint is None:
         for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
            _A:  Any					=       constraint.advance()
            if isinstance(lowerCAmelCase_			,			lowerCAmelCase_     ):
               token_list.append(lowerCAmelCase_     )
            elif isinstance(lowerCAmelCase_			,			lowerCAmelCase_     ):
               token_list.extend(lowerCAmelCase_     )
      else:
         _A:  Optional[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  __magic_name__				(					self     :							Any			,			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
            _A			,  _A:  str					=       self.add(lowerCAmelCase_     )

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


   def  __magic_name__				(					self     :							Optional[Any]			,			lowerCAmelCase_     :							int     ):

      """simple docstring"""
      if not isinstance(lowerCAmelCase_			,			lowerCAmelCase_     ):
         raise ValueError(F"""`token_id` should be an `int`, but is `{token_id}`."""     )

      _A			,  _A:  Union[str, Any]					=       False, False

      if self.completed:
         _A:  Any					=       True
         _A:  Union[str, 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

         _A			,  _A			,  _A:  Dict					=       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_     )     )
            _A:  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     )
            _A:  Optional[int]					=       None

            if len(self.pending_constraints     ) == 0:
               # we're done!
               _A:  str					=       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_     ):
               _A			,  _A			,  _A:  Optional[int]					=       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_     )
                  _A:  Dict					=       None

               if not complete and stepped:
                  _A:  List[Any]					=       pending_constraint

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

                  _A:  Dict					=       (
                      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.

                     _A:  int					=       True

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

      return complete, stepped


   def  __magic_name__				(					self     :							str			,			lowerCAmelCase_     :							Optional[Any]=True     ):

      """simple docstring"""
      _A:  Dict					=       ConstraintListState(self.constraints     )  # we actually never though self.constraints objects
      # throughout this process. So it's at initialization state.

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

      return new_state





def   lowerCamelCase__							(					a      )      ->   bool:
   _A:  Dict					=       [int(a      ) for i in ip_va_address.split('''.'''      ) if i.isdigit()]
   return len(a      ) == 4 and all(0 <= int(a      ) <= 2_54 for octet in octets      )


if __name__ == "__main__":
   UpperCAmelCase__		:     str     			=      input().strip()
   UpperCAmelCase__		:     Any     			=      'valid' if is_ip_va_address_valid(ip) else 'invalid'
   print(F"""{ip} is a {valid_or_invalid} IP v4 address.""")



