






from collections.abc import Sequence
from queue import Queue

class 				lowerCAmelCase_	:


				def __init__(					self ,						_lowerCAmelCase ,						_lowerCAmelCase ,						_lowerCAmelCase ,						_lowerCAmelCase=None ,						_lowerCAmelCase=None      ):
											_lowercase							:   Union[str, Any] 							=   start
											_lowercase							:   List[Any] 							=   end
											_lowercase							:   Optional[Any] 							=   val
											_lowercase							:   Optional[Any] 							=   (start + end) // 2
											_lowercase							:   List[str] 							=   left
											_lowercase							:   List[Any] 							=   right


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




class 				lowerCAmelCase_	:


				def __init__(					self ,						_lowerCAmelCase ,						_lowerCAmelCase      ):
											_lowercase							:   int 							=   collection
											_lowercase							:   Tuple 							=   function
											if self.collection:
																		_lowercase							:   Any 							=   self._build_tree(0 ,						len(_A      ) - 1      )


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase      ):
											self._update_tree(self.root ,						_A ,						_A      )


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase      ):
											return self._query_range(self.root ,						_A ,						_A      )


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase      ):







											if start == end:
																		return SegmentTreeNode(_A ,						_A ,						self.collection[start]      )
											_lowercase							:   Optional[int] 							=   (start + end) // 2
											_lowercase							:   Union[str, Any] 							=   self._build_tree(_A ,						_A      )
											_lowercase							:   List[str] 							=   self._build_tree(mid + 1 ,						_A      )
											return SegmentTreeNode(_A ,						_A ,						self.fn(left.val ,						right.val      ) ,						_A ,						_A      )


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase ,						_lowerCAmelCase      ):







											if node.start == i and node.end == i:
																		_lowercase							:   List[str] 							=   val
																		return
											if i <= node.mid:
																		self._update_tree(node.left ,						_A ,						_A      )
											else:
																		self._update_tree(node.right ,						_A ,						_A      )
											_lowercase							:   Dict 							=   self.fn(node.left.val ,						node.right.val      )


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase ,						_lowerCAmelCase      ):







											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 ,						_A ,						_A      )
																		else:
																									# range in left child tree and right child tree
																									return self.fn(
																									    self._query_range(node.left ,						_A ,						node.mid      ) ,						self._query_range(node.right ,						node.mid + 1 ,						_A      ) ,						)
											else:
																		# range in right child tree
																		return self._query_range(node.right ,						_A ,						_A      )


				def 						__a					(					self      ):







											if self.root is not None:
																		_lowercase							:   Optional[Any] 							=   Queue()
																		queue.put(self.root      )
																		while not queue.empty():
																									_lowercase							:   Dict 							=   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"""


def      UpperCamelCase							(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE     ):
						UpperCamelCase				:		List[Any]				   =			""""""
						for i in table:
												res += inp[i - 1]
						return res

def      UpperCamelCase							(SCREAMING_SNAKE_CASE     ):
						return data[1:] + data[0]

def      UpperCamelCase							(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE     ):
						UpperCamelCase				:		Union[str, Any]				   =			""""""
						for i in range(len(SCREAMING_SNAKE_CASE     )     ):
												if a[i] == b[i]:
																		res += "0"
												else:
																		res += "1"
						return res

def      UpperCamelCase							(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE     ):
						UpperCamelCase				:		Optional[int]				   =			int("""0b""" + data[0] + data[-1]							,     2     )
						UpperCamelCase				:		Any				   =			int("""0b""" + data[1:3]							,     2     )
						return bin(s[row][col]     )[2:]

def      UpperCamelCase							(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE     ):
						UpperCamelCase				:		Any				   =			message[:4]
						UpperCamelCase				:		int				   =			message[4:]
						UpperCamelCase				:		int				   =			apply_table(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE     )
						UpperCamelCase				:		str				   =			xor(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE     )
						UpperCamelCase				:		Union[str, Any]				   =			apply_sbox(SCREAMING_SNAKE_CASE							,     temp[:4]     )  # noqa: E741
						UpperCamelCase				:		str				   =			apply_sbox(SCREAMING_SNAKE_CASE							,     temp[4:]     )
						UpperCamelCase				:		Union[str, Any]				   =			"""0""" * (2 - len(SCREAMING_SNAKE_CASE     )) + l  # noqa: E741
						UpperCamelCase				:		Union[str, Any]				   =			"""0""" * (2 - len(SCREAMING_SNAKE_CASE     )) + r
						UpperCamelCase				:		int				   =			apply_table(l + r							,     SCREAMING_SNAKE_CASE     )
						UpperCamelCase				:		int				   =			xor(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE     )
						return temp + right


if __name__ == "__main__":
		__magic_name__       :					Union[str, Any]						=			input("""Enter 10 bit key: """)
		__magic_name__       :					Union[str, Any]						=			input("""Enter 8 bit message: """)

		__magic_name__       :					Dict						=			[6, 3, 7, 4, 8, 5, 1_0, 9]
		__magic_name__       :					str						=			[3, 5, 2, 7, 4, 1_0, 1, 9, 8, 6]
		__magic_name__       :					Optional[Any]						=			[2, 4, 3, 1]
		__magic_name__       :					Tuple						=			[2, 6, 3, 1, 4, 8, 5, 7]
		__magic_name__       :					str						=			[4, 1, 3, 5, 7, 2, 8, 6]
		__magic_name__       :					str						=			[4, 1, 2, 3, 2, 3, 4, 1]
		__magic_name__       :					Any						=			[[1, 0, 3, 2], [3, 2, 1, 0], [0, 2, 1, 3], [3, 1, 3, 2]]
		__magic_name__       :					Any						=			[[0, 1, 2, 3], [2, 0, 1, 3], [3, 0, 1, 0], [2, 1, 0, 3]]

		# key generation
		__magic_name__       :					Dict						=			apply_table(key, paa_table)
		__magic_name__       :					Union[str, Any]						=			temp[:5]
		__magic_name__       :					Optional[Any]						=			temp[5:]
		__magic_name__       :					str						=			left_shift(left)
		__magic_name__       :					List[str]						=			left_shift(right)
		__magic_name__       :					Tuple						=			apply_table(left + right, pa_table)
		__magic_name__       :					Dict						=			left_shift(left)
		__magic_name__       :					Union[str, Any]						=			left_shift(right)
		__magic_name__       :					List[Any]						=			left_shift(left)
		__magic_name__       :					str						=			left_shift(right)
		__magic_name__       :					List[str]						=			apply_table(left + right, pa_table)

		# encryption
		__magic_name__       :					List[str]						=			apply_table(message, IP)
		__magic_name__       :					str						=			function(expansion, sa, sa, keya, temp)
		__magic_name__       :					str						=			temp[4:] + temp[:4]
		__magic_name__       :					Optional[Any]						=			function(expansion, sa, sa, keya, temp)
		__magic_name__       :					Any						=			apply_table(temp, IP_inv)
		print("""Cipher text is:""", CT)

		# decryption
		__magic_name__       :					Tuple						=			apply_table(CT, IP)
		__magic_name__       :					List[str]						=			function(expansion, sa, sa, keya, temp)
		__magic_name__       :					Dict						=			temp[4:] + temp[:4]
		__magic_name__       :					int						=			function(expansion, sa, sa, keya, temp)
		__magic_name__       :					Any						=			apply_table(temp, IP_inv)
		print("""Plain text after decypting is:""", PT)



