





from collections.abc import Sequence
from queue import Queue






class     lowercase__       :

   '''simple docstring'''


   def __init__(    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__=None,		__magic_name__=None							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				Any          =      start
       UpperCamelCase__							:				Optional[Any]          =      end
       UpperCamelCase__							:				Optional[int]          =      val
       UpperCamelCase__							:				List[str]          =      (start + end) // 2
       UpperCamelCase__							:				Any          =      left
       UpperCamelCase__							:				Tuple          =      right




   def __repr__(    self							) ->      Union[str, Any]:






       """simple docstring"""
       return f"SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})"






class     lowercase__       :

   '''simple docstring'''


   def __init__(    self,		__magic_name__,		__magic_name__							) ->      Optional[Any]:






       """simple docstring"""
       UpperCamelCase__							:				List[Any]          =      collection
       UpperCamelCase__							:				Tuple          =      function
       if self.collection:
           UpperCamelCase__							:				str          =      self._build_tree(0,		len(__magic_name__							) - 1							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__							) ->      List[str]:






       """simple docstring"""
       self._update_tree(self.root,		__magic_name__,		__magic_name__							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__							) ->      List[Any]:






       """simple docstring"""
       return self._query_range(self.root,		__magic_name__,		__magic_name__							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__							) ->      str:






       """simple docstring"""
       if start == end:
           return SegmentTreeNode(__magic_name__,		__magic_name__,		self.collection[start]							)
       UpperCamelCase__							:				int          =      (start + end) // 2
       UpperCamelCase__							:				Any          =      self._build_tree(__magic_name__,		__magic_name__							)
       UpperCamelCase__							:				Union[str, Any]          =      self._build_tree(mid + 1,		__magic_name__							)
       return SegmentTreeNode(__magic_name__,		__magic_name__,		self.fn(left.val,		right.val							),		__magic_name__,		__magic_name__							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Any:






       """simple docstring"""
       if node.start == i and node.end == i:
           UpperCamelCase__							:				Any          =      val
           return
       if i <= node.mid:
           self._update_tree(node.left,		__magic_name__,		__magic_name__							)
       else:
           self._update_tree(node.right,		__magic_name__,		__magic_name__							)
       UpperCamelCase__							:				List[str]          =      self.fn(node.left.val,		node.right.val							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Dict:






       """simple docstring"""
       if node.start == i and node.end == j:
           return node.val

       if i <= node.mid:
           if j <= node.mid:
               # range in left child tree
               return self._query_range(node.left,		__magic_name__,		__magic_name__							)
           else:
               # range in left child tree and right child tree
               return self.fn(
                   self._query_range(node.left,		__magic_name__,		node.mid							),		self._query_range(node.right,		node.mid + 1,		__magic_name__							),		)
       else:
           # range in right child tree
           return self._query_range(node.right,		__magic_name__,		__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      List[Any]:






       """simple docstring"""
       if self.root is not None:
           UpperCamelCase__							:				List[str]          =      Queue()
           queue.put(self.root							)
           while not queue.empty():
               UpperCamelCase__							:				List[str]          =      queue.get()
               yield node

               if node.left is not None:
                   queue.put(node.left							)

               if node.right is not None:
                   queue.put(node.right							)


if __name__ == "__main__":
  import operator

  for fn in [operator.add, max, min]:
    print('*' * 50)
    UpperCAmelCase_     							= SegmentTree([2, 1, 5, 3, 4], fn)
    for node in arr.traverse():
      print(node)
    print()

    arr.update(1, 5)
    for node in arr.traverse():
      print(node)
    print()

    print(arr.query_range(3, 4))  # 7
    print(arr.query_range(2, 2))  # 5
    print(arr.query_range(1, 3))  # 13
    print()







"""simple docstring"""






import functools
from typing import Any







def      _snake_case			(				lowercase__							,    lowercase__		):

				# Validation
				if not isinstance(lowercase__							,    lowercase__		) or len(lowercase__		) == 0:
								raise ValueError('the string should be not empty string'		)

				if not isinstance(lowercase__							,    lowercase__		) or not all(
				    isinstance(lowercase__							,    lowercase__		) and len(lowercase__		) > 0 for item in words		):
								raise ValueError('the words should be a list of non-empty strings'		)

				# Build trie
				_lowerCamelCase     :			dict[str, Any]    =    {}
				_lowerCamelCase     :			List[Any]    =    'WORD_KEEPER'

				for word in words:
								_lowerCamelCase     :			Dict    =    trie
								for c in word:
												if c not in trie_node:
																_lowerCamelCase     :			Any    =    {}

												_lowerCamelCase     :			str    =    trie_node[c]

								_lowerCamelCase     :			Optional[Any]    =    True

				_lowerCamelCase     :			Dict    =    len(lowercase__		)

				# Dynamic programming method
				@functools.cache
				def is_breakable(lowercase__		) -> bool:
								if index == len_string:
												return True

								_lowerCamelCase     :			List[Any]    =    trie
								for i in range(lowercase__							,    lowercase__		):
												_lowerCamelCase     :			Any    =    trie_node.get(string[i]							,    lowercase__		)

												if trie_node is None:
																return False

												if trie_node.get(lowercase__							,    lowercase__		) and is_breakable(i + 1		):
																return True

								return False

				return is_breakable(0		)


if __name__ == "__main__":
			import doctest

			doctest.testmod()