

from __future__ import annotations

import math

class 			a					:


						def __init__(    self  ,   A_		):







										'''simple docstring'''


										_UpperCAmelCase    :						Tuple							=      size
										# approximate the overall size of segment tree with given value
										_UpperCAmelCase    :						List[str]							=      [0 for i in range(0  ,   4 * size		)]
										# create array to store lazy update
										_UpperCAmelCase    :						Optional[Any]							=      [0 for i in range(0  ,   4 * size		)]
										_UpperCAmelCase    :						str							=      [0 for i in range(0  ,   4 * size		)]  # flag for lazy update


						def     _UpperCAmelCase			(    self  ,   A_		):







										'''simple docstring'''


										return idx * 2


						def     _UpperCAmelCase			(    self  ,   A_		):







										'''simple docstring'''


										return idx * 2 + 1


						def     _UpperCAmelCase			(    self  ,   A_  ,   A_  ,   A_  ,   A_		):







										'''simple docstring'''


										if left_element == right_element:
														_UpperCAmelCase    :						Optional[Any]							=      a[left_element - 1]
										else:
														_UpperCAmelCase    :						Tuple							=      (left_element + right_element) // 2
														self.build(self.left(__lowerCamelCase		)  ,   __lowerCamelCase  ,   __lowerCamelCase  ,   __lowerCamelCase		)
														self.build(self.right(__lowerCamelCase		)  ,   mid + 1  ,   __lowerCamelCase  ,   __lowerCamelCase		)
														_UpperCAmelCase    :						Optional[int]							=      max(
														    self.segment_tree[self.left(__lowerCamelCase		)]  ,   self.segment_tree[self.right(__lowerCamelCase		)]		)


						def     _UpperCAmelCase			(    self  ,   A_  ,   A_  ,   A_  ,   A_  ,   A_  ,   A_		):







										'''simple docstring'''


										if self.flag[idx] is True:
														_UpperCAmelCase    :						List[Any]							=      self.lazy[idx]
														_UpperCAmelCase    :						List[Any]							=      False
														if left_element != right_element:
																		_UpperCAmelCase    :						Optional[int]							=      self.lazy[idx]
																		_UpperCAmelCase    :						Dict							=      self.lazy[idx]
																		_UpperCAmelCase    :						Any							=      True
																		_UpperCAmelCase    :						Any							=      True

										if right_element < a or left_element > b:
														return True
										if left_element >= a and right_element <= b:
														_UpperCAmelCase    :						Dict							=      val
														if left_element != right_element:
																		_UpperCAmelCase    :						List[Any]							=      val
																		_UpperCAmelCase    :						Dict							=      val
																		_UpperCAmelCase    :						Optional[int]							=      True
																		_UpperCAmelCase    :						Optional[int]							=      True
														return True
										_UpperCAmelCase    :						Optional[int]							=      (left_element + right_element) // 2
										self.update(self.left(__lowerCamelCase		)  ,   __lowerCamelCase  ,   __lowerCamelCase  ,   __lowerCamelCase  ,   __lowerCamelCase  ,   __lowerCamelCase		)
										self.update(self.right(__lowerCamelCase		)  ,   mid + 1  ,   __lowerCamelCase  ,   __lowerCamelCase  ,   __lowerCamelCase  ,   __lowerCamelCase		)
										_UpperCAmelCase    :						Union[str, Any]							=      max(
										    self.segment_tree[self.left(__lowerCamelCase		)]  ,   self.segment_tree[self.right(__lowerCamelCase		)]		)
										return True


						def     _UpperCAmelCase			(    self  ,   A_  ,   A_  ,   A_  ,   A_  ,   A_		):







										'''simple docstring'''


										if self.flag[idx] is True:
														_UpperCAmelCase    :						Dict							=      self.lazy[idx]
														_UpperCAmelCase    :						Any							=      False
														if left_element != right_element:
																		_UpperCAmelCase    :						Optional[int]							=      self.lazy[idx]
																		_UpperCAmelCase    :						List[Any]							=      self.lazy[idx]
																		_UpperCAmelCase    :						Union[str, Any]							=      True
																		_UpperCAmelCase    :						Tuple							=      True
										if right_element < a or left_element > b:
														return -math.inf
										if left_element >= a and right_element <= b:
														return self.segment_tree[idx]
										_UpperCAmelCase    :						Any							=      (left_element + right_element) // 2
										_UpperCAmelCase    :						Dict							=      self.query(self.left(__lowerCamelCase		)  ,   __lowerCamelCase  ,   __lowerCamelCase  ,   __lowerCamelCase  ,   __lowerCamelCase		)
										_UpperCAmelCase    :						Any							=      self.query(self.right(__lowerCamelCase		)  ,   mid + 1  ,   __lowerCamelCase  ,   __lowerCamelCase  ,   __lowerCamelCase		)
										return max(__lowerCamelCase  ,   __lowerCamelCase		)





						def __str__(    self		):







										'''simple docstring'''


										return str([self.query(1  ,   1  ,   self.size  ,   __lowerCamelCase  ,   __lowerCamelCase		) for i in range(1  ,   self.size + 1		)]		)


if __name__ == "__main__":
				SCREAMING_SNAKE_CASE_            = [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
				SCREAMING_SNAKE_CASE_            = 15
				SCREAMING_SNAKE_CASE_            = SegmentTree(size)
				segt.build(1, 1, size, A)
				print(segt.query(1, 1, size, 4, 6))
				print(segt.query(1, 1, size, 7, 11))
				print(segt.query(1, 1, size, 7, 12))
				segt.update(1, 1, size, 1, 3, 111)
				print(segt.query(1, 1, size, 1, 15))
				segt.update(1, 1, size, 7, 8, 235)
				print(segt)





from typing import Any

class 			a					:


						def __init__(    self  ,   A_		):







										'''simple docstring'''


										_UpperCAmelCase    :						List[Any]							=      data
										_UpperCAmelCase    :						Any							=      None







class 			a					:


						def __init__(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Union[str, Any]							=      None


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						str							=      self.head
										while temp is not None:
														print(temp.data  ,   end=" "		)
														_UpperCAmelCase    :						str							=      temp.next
										print()


						def     _UpperCAmelCase			(    self  ,   A_		):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[int]							=      Node(A_		)
										_UpperCAmelCase    :						Tuple							=      self.head
										_UpperCAmelCase    :						Tuple							=      new_node





						def     _UpperCAmelCase			(    self  ,   A_  ,   A_		):







										'''simple docstring'''


										if node_data_a == node_data_a:
														return
										else:
														_UpperCAmelCase    :						int							=      self.head
														while node_a is not None and node_a.data != node_data_a:
																		_UpperCAmelCase    :						Tuple							=      node_a.next

														_UpperCAmelCase    :						Dict							=      self.head
														while node_a is not None and node_a.data != node_data_a:
																		_UpperCAmelCase    :						List[Any]							=      node_a.next

														if node_a is None or node_a is None:
																		return

														_UpperCAmelCase						,							_UpperCAmelCase    :						Optional[int]							=      node_a.data, node_a.data


if __name__ == "__main__":
					SCREAMING_SNAKE_CASE_            = LinkedList()
					for i in range(5, 0, -1):
										ll.push(i)

					ll.print_list()

					ll.swap_nodes(1, 4)
					print('After swapping')
					ll.print_list()


