


"""simple docstring"""







from collections.abc import Sequence
from queue import Queue






class       __A				:






 """simple docstring"""




 def __init__(		self ,    __A ,    __A ,    __A ,    __A=None ,    __A=None						)					->     str:
     a 		=start
     a 		=end
     a 		=val
     a 		=(start + end) // 2
     a 		=left
     a 		=right





 def __repr__(		self						)					->     List[str]:
     return f'''SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})'''






class       __A				:






 """simple docstring"""




 def __init__(		self ,    __A ,    __A						)					->     Union[str, Any]:
     a 		=collection
     a 		=function
     if self.collection:
         a 		=self._build_tree(0 ,    len(a_						) - 1						)


 def       SCREAMING_SNAKE_CASE							(		self ,    __A ,    __A						)					->     Optional[Any]:
     self._update_tree(self.root ,    a_ ,    a_						)


 def       SCREAMING_SNAKE_CASE							(		self ,    __A ,    __A						)					->     str:
     return self._query_range(self.root ,    a_ ,    a_						)


 def       SCREAMING_SNAKE_CASE							(		self ,    __A ,    __A						)					->     Optional[int]:



     if start == end:
         return SegmentTreeNode(a_ ,    a_ ,    self.collection[start]						)
     a 		=(start + end) // 2
     a 		=self._build_tree(a_ ,    a_						)
     a 		=self._build_tree(mid + 1 ,    a_						)
     return SegmentTreeNode(a_ ,    a_ ,    self.fn(left.val ,    right.val						) ,    a_ ,    a_						)


 def       SCREAMING_SNAKE_CASE							(		self ,    __A ,    __A ,    __A						)					->     List[str]:



     if node.start == i and node.end == i:
         a 		=val
         return
     if i <= node.mid:
         self._update_tree(node.left ,    a_ ,    a_						)
     else:
         self._update_tree(node.right ,    a_ ,    a_						)
     a 		=self.fn(node.left.val ,    node.right.val						)


 def       SCREAMING_SNAKE_CASE							(		self ,    __A ,    __A ,    __A						)					->     str:



     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       SCREAMING_SNAKE_CASE							(		self						)					->     Tuple:



     if self.root is not None:
         a 		=Queue()
         queue.put(self.root						)
         while not queue.empty():
             a 		=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("""*""" * 5_0)
              lowerCamelCase_   :   Optional[int]									=  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 argparse
import hashlib  # hashlib is only used inside the Test class
import struct






class 					lowercase:







 '''simple docstring'''





 def __init__(				self:		List[Any],      a_:		List[str]		):




   '''simple docstring'''



   _snake_case							:		int								=  data
   _snake_case							:		Dict								=  [0X67452301, 0Xefcdab89, 0X98badcfe, 0X10325476, 0Xc3d2e1f0]


 @staticmethod
 def  UpperCamelCase_   (				a_:		Optional[Any],      a_:		Dict		):




   '''simple docstring'''



   return ((n << b) | (n >> (32 - b))) & 0Xffffffff


 def  UpperCamelCase_   (				self:		List[Any]		):




   '''simple docstring'''



   _snake_case							:		Union[str, Any]								=  B"""\x80""" + B"""\x00""" * (63 - (len(self.data		) + 8) % 64)
   _snake_case							:		Optional[int]								=  self.data + padding + struct.pack(""">Q""",      8 * len(self.data		)		)
   return padded_data


 def  UpperCamelCase_   (				self:		Union[str, Any]		):




   '''simple docstring'''



   return [
       self.padded_data[i : i + 64] for i in range(0,      len(self.padded_data		),      64		)
   ]


 def  UpperCamelCase_   (				self:		Optional[Any],      a_:		List[Any]		):




   '''simple docstring'''



   _snake_case							:		List[str]								=  list(struct.unpack(""">16L""",      a_		)		) + [0] * 64
   for i in range(16,      80		):
     _snake_case							:		List[Any]								=  self.rotate((w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]),      1		)
   return w


 def  UpperCamelCase_   (				self:		int		):




   '''simple docstring'''



   _snake_case							:		Union[str, Any]								=  self.padding()
   _snake_case							:		str								=  self.split_blocks()
   for block in self.blocks:
     _snake_case							:		Any								=  self.expand_block(a_		)
     _snake_case		,					_snake_case		,					_snake_case		,					_snake_case		,					_snake_case							:		Optional[int]								=  self.h
     for i in range(0,      80		):
       if 0 <= i < 20:
         _snake_case							:		int								=  (b & c) | ((~b) & d)
         _snake_case							:		str								=  0X5a827999
       elif 20 <= i < 40:
         _snake_case							:		Optional[int]								=  b ^ c ^ d
         _snake_case							:		str								=  0X6ed9eba1
       elif 40 <= i < 60:
         _snake_case							:		List[Any]								=  (b & c) | (b & d) | (c & d)
         _snake_case							:		List[Any]								=  0X8f1bbcdc
       elif 60 <= i < 80:
         _snake_case							:		List[Any]								=  b ^ c ^ d
         _snake_case							:		int								=  0Xca62c1d6
       _snake_case		,					_snake_case		,					_snake_case		,					_snake_case		,					_snake_case							:		Optional[int]								=  (
           self.rotate(a_,      5		) + f + e + k + expanded_block[i] & 0Xffffffff,
           a,
           self.rotate(a_,      30		),
           c,
           d,
       )
     _snake_case							:		Union[str, Any]								=  (
         self.h[0] + a & 0Xffffffff,
         self.h[1] + b & 0Xffffffff,
         self.h[2] + c & 0Xffffffff,
         self.h[3] + d & 0Xffffffff,
         self.h[4] + e & 0Xffffffff,
     )
   return ("{:08x}" * 5).format(*self.h		)







def 					UpperCAmelCase__       ():
  """simple docstring"""

  _snake_case							:		Any								=  B"""Test String"""
  assert SHAaHash(snake_case__    ).final_hash() == hashlib.shaa(snake_case__    ).hexdigest()  # noqa: S324


def 					UpperCAmelCase__       ():
  """simple docstring"""

  _snake_case							:		List[Any]								=  argparse.ArgumentParser(description="""Process some strings or files"""    )
  parser.add_argument(
      """--string"""		,   dest="""input_string"""		,   default="""Hello World!! Welcome to Cryptography"""		,   help="""Hash the string"""		,   )
  parser.add_argument("""--file"""		,   dest="""input_file"""		,   help="""Hash contents of a file"""    )
  _snake_case							:		Union[str, Any]								=  parser.parse_args()
  _snake_case							:		List[Any]								=  args.input_string
  # In any case hash input should be a bytestring
  if args.input_file:
    with open(args.input_file		,   """rb"""    ) as f:
      _snake_case							:		str								=  f.read()
  else:
    _snake_case							:		int								=  bytes(snake_case__		,   """utf-8"""    )
  print(SHAaHash(snake_case__    ).final_hash()    )


if __name__ == "__main__":
     main()
     import doctest

     doctest.testmod()


