
'''simple docstring'''





from __future__ import annotations
def 	snake_case_							(				_a  :				str			,       _a  :				dict[str, str]      ):
      snake_case_							,						snake_case_							,						snake_case_    							=				"", "", ""
      snake_case_    							=				[]

      for character in message_part:
            tmp.append(character_to_number[character]      )

      for each in tmp:
            one += each[0]
            two += each[1]
            three += each[2]

      return one + two + three
def 	snake_case_							(				_a  :				str			,       _a  :				dict[str, str]      ):
      snake_case_							,						snake_case_    							=				"", ""
      snake_case_    							=				[]

      for character in message_part:
            this_part += character_to_number[character]

      for digit in this_part:
            tmp += digit
            if len(_a      ) == len(_a      ):
                  result.append(_a      )
                  snake_case_    							=				""

      return result[0], result[1], result[2]
def 	snake_case_							(				_a  :				str			,       _a  :				str      ):
      # Validate message and alphabet, set to upper and remove spaces
      snake_case_    							=				alphabet.replace(" "			,       ""      ).upper()
      snake_case_    							=				message.replace(" "			,       ""      ).upper()

      # Check length and characters
      if len(_a      ) != 27:
            raise KeyError("Length of alphabet has to be 27."      )
      for each in message:
            if each not in alphabet:
                  raise ValueError("Each message character has to be included in alphabet!"      )

    # Generate dictionares
      snake_case_    							=				(
          "111",
          "112",
          "113",
          "121",
          "122",
          "123",
          "131",
          "132",
          "133",
          "211",
          "212",
          "213",
          "221",
          "222",
          "223",
          "231",
          "232",
          "233",
          "311",
          "312",
          "313",
          "321",
          "322",
          "323",
          "331",
          "332",
          "333",
      )
      snake_case_    							=				{}
      snake_case_    							=				{}
      for letter, number in zip(_a			,       _a      ):
            snake_case_    							=				number
            snake_case_    							=				letter

      return message, alphabet, character_to_number, number_to_character
def 	snake_case_							(				_a  :				str			,       _a  :				str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."			,       _a  :				int = 5      ):
      snake_case_							,						snake_case_							,						snake_case_							,						snake_case_    							=				__prepare(
          _a			,       _a      )
      snake_case_							,						snake_case_    							=				"", ""

      for i in range(0			,       len(_a      ) + 1			,       _a      ):
            encrypted_numeric += __encrypt_part(
                message[i : i + period]			,       _a      )

      for i in range(0			,       len(_a      )			,       3      ):
            encrypted += number_to_character[encrypted_numeric[i : i + 3]]

      return encrypted
def 	snake_case_							(				_a  :				str			,       _a  :				str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."			,       _a  :				int = 5      ):
      snake_case_							,						snake_case_							,						snake_case_							,						snake_case_    							=				__prepare(
          _a			,       _a      )
      snake_case_    							=				[]
      snake_case_    							=				""

      for i in range(0			,       len(_a      ) + 1			,       _a      ):
            snake_case_							,						snake_case_							,						snake_case_    							=				__decrypt_part(message[i : i + period]			,       _a      )

            for j in range(0			,       len(_a      )      ):
                  decrypted_numeric.append(a[j] + b[j] + c[j]      )

      for each in decrypted_numeric:
            decrypted += number_to_character[each]

      return decrypted


if __name__ == "__main__":
     A							     = "DEFEND THE EAST WALL OF THE CASTLE."
     A							     = encrypt_message(msg, "EPSDUCVWYM.ZLKXNBTFGORIJHAQ")
     A							     = decrypt_message(encrypted, "EPSDUCVWYM.ZLKXNBTFGORIJHAQ")
     print(F"""Encrypted: {encrypted}\nDecrypted: {decrypted}""")


import math





class 					__snake_case    :




					def __init__(  self       ,			__UpperCamelCase						)	->    Dict:



									'''simple docstring'''







									snake_case__   :      Optional[int]   				= len(__UpperCamelCase						)
									snake_case__   :      Dict   				= [0] * (
									    4 * self.N
									)  # approximate the overall size of segment tree with array N
									self.build(1       ,			0       ,			self.N - 1						)




					def      __a     (  self       ,			__UpperCamelCase						)	->    Any:



									'''simple docstring'''







									return idx * 2




					def      __a     (  self       ,			__UpperCamelCase						)	->    Optional[int]:



									'''simple docstring'''







									return idx * 2 + 1




					def      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    int:  # noqa: E741



									'''simple docstring'''







									if l == r:
													snake_case__   :      Dict   				= A[l]
									else:
													snake_case__   :      Optional[Any]   				= (l + r) // 2
													self.build(self.left(__UpperCamelCase						)       ,			__UpperCamelCase       ,			__UpperCamelCase						)
													self.build(self.right(__UpperCamelCase						)       ,			mid + 1       ,			__UpperCamelCase						)
													snake_case__   :      int   				= max(self.st[self.left(__UpperCamelCase						)]       ,			self.st[self.right(__UpperCamelCase						)]						)




					def      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    int:



									'''simple docstring'''







									return self.update_recursive(1       ,			0       ,			self.N - 1       ,			a - 1       ,			b - 1       ,			__UpperCamelCase						)




					def      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    Tuple:  # noqa: E741



									'''simple docstring'''







									if r < a or l > b:
													return True
									if l == r:
													snake_case__   :      List[str]   				= val
													return True
									snake_case__   :      str   				= (l + r) // 2
									self.update_recursive(self.left(__UpperCamelCase						)       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)
									self.update_recursive(self.right(__UpperCamelCase						)       ,			mid + 1       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)
									snake_case__   :      Tuple   				= max(self.st[self.left(__UpperCamelCase						)]       ,			self.st[self.right(__UpperCamelCase						)]						)
									return True




					def      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    List[str]:



									'''simple docstring'''







									return self.query_recursive(1       ,			0       ,			self.N - 1       ,			a - 1       ,			b - 1						)




					def      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    Optional[int]:  # noqa: E741



									'''simple docstring'''







									if r < a or l > b:
													return -math.inf
									if l >= a and r <= b:
													return self.st[idx]
									snake_case__   :      str   				= (l + r) // 2
									snake_case__   :      Optional[Any]   				= self.query_recursive(self.left(__UpperCamelCase						)       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)
									snake_case__   :      List[str]   				= self.query_recursive(self.right(__UpperCamelCase						)       ,			mid + 1       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)
									return max(__UpperCamelCase       ,			__UpperCamelCase						)




					def      __a     (  self						)	->    Optional[Any]:



									'''simple docstring'''







									snake_case__   :      Tuple   				= []
									for i in range(1       ,			N + 1						):
													show_list += [self.query(__UpperCamelCase       ,			__UpperCamelCase						)]
									print(__UpperCamelCase						)


if __name__ == "__main__":
				lowerCAmelCase__	:  Optional[int]						=  [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
				lowerCAmelCase__	:  Any						=  15
				lowerCAmelCase__	:  List[Any]						=  SegmentTree(A)
				print(segt.query(4, 6))
				print(segt.query(7, 11))
				print(segt.query(7, 12))
				segt.update(1, 3, 1_11)
				print(segt.query(1, 15))
				segt.update(7, 8, 2_35)
				segt.show_data()


