




"""simple docstring"""






from collections.abc import Sequence
from queue import Queue






class lowerCAmelCase__	:






			'''simple docstring'''



			def __init__(  self  ,      lowercase  ,      lowercase  ,      lowercase  ,      lowercase=None  ,      lowercase=None  ):
							_lowerCamelCase     :			Any    =    start
							_lowerCamelCase     :			Optional[Any]    =    end
							_lowerCamelCase     :			Optional[int]    =    val
							_lowerCamelCase     :			List[str]    =    (start + end) // 2
							_lowerCamelCase     :			Any    =    left
							_lowerCamelCase     :			Tuple    =    right






			def __repr__(  self  ):
							return F'''SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})'''






class lowerCAmelCase__	:






			'''simple docstring'''



			def __init__(  self  ,      lowercase  ,      lowercase  ):
							_lowerCamelCase     :			List[Any]    =    collection
							_lowerCamelCase     :			Tuple    =    function
							if self.collection:
											_lowerCamelCase     :			str    =    self._build_tree(0  ,      len(lowercase  ) - 1  )
			def 					A_    (  self  ,      lowercase  ,      lowercase  ):
							self._update_tree(self.root  ,      lowercase  ,      lowercase  )
			def 					A_    (  self  ,      lowercase  ,      lowercase  ):
							return self._query_range(self.root  ,      lowercase  ,      lowercase  )
			def 					A_    (  self  ,      lowercase  ,      lowercase  ):
							if start == end:
											return SegmentTreeNode(lowercase  ,      lowercase  ,      self.collection[start]  )
							_lowerCamelCase     :			int    =    (start + end) // 2
							_lowerCamelCase     :			Any    =    self._build_tree(lowercase  ,      lowercase  )
							_lowerCamelCase     :			Union[str, Any]    =    self._build_tree(mid + 1  ,      lowercase  )
							return SegmentTreeNode(lowercase  ,      lowercase  ,      self.fn(left.val  ,      right.val  )  ,      lowercase  ,      lowercase  )
			def 					A_    (  self  ,      lowercase  ,      lowercase  ,      lowercase  ):
							if node.start == i and node.end == i:
											_lowerCamelCase     :			Any    =    val
											return
							if i <= node.mid:
											self._update_tree(node.left  ,      lowercase  ,      lowercase  )
							else:
											self._update_tree(node.right  ,      lowercase  ,      lowercase  )
							_lowerCamelCase     :			List[str]    =    self.fn(node.left.val  ,      node.right.val  )
			def 					A_    (  self  ,      lowercase  ,      lowercase  ,      lowercase  ):
							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  ,      lowercase  ,      lowercase  )
											else:
															# range in left child tree and right child tree
															return self.fn(
															    self._query_range(node.left  ,      lowercase  ,      node.mid  )  ,      self._query_range(node.right  ,      node.mid + 1  ,      lowercase  )  ,      )
							else:
											# range in right child tree
											return self._query_range(node.right  ,      lowercase  ,      lowercase  )






			def 					A_    (  self  ):
							if self.root is not None:
											_lowerCamelCase     :			List[str]    =    Queue()
											queue.put(self.root  )
											while not queue.empty():
															_lowerCamelCase     :			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)
						lowercase__     						=						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 math







def      _snake_case			(				lowercase__		):
				return math.sqrt(lowercase__		) * math.sqrt(lowercase__		) == num







def      _snake_case			(				lowercase__		):
				_lowerCamelCase     :			Optional[int]    =    0
				_lowerCamelCase     :			List[Any]    =    n
				while left <= right:
								_lowerCamelCase     :			str    =    (left + right) // 2
								if mid**2 == n:
												return True
								elif mid**2 > n:
												_lowerCamelCase     :			str    =    mid - 1
								else:
												_lowerCamelCase     :			Optional[int]    =    mid + 1
				return False


if __name__ == "__main__":
			import doctest

			doctest.testmod()