


from collections.abc import Sequence
from queue import Queue






class    UpperCAmelCase__	:



    """simple docstring"""






    def __init__(      self ,       A_ ,       A_ ,       A_ ,       A_=None ,       A_=None   )  ->	List[str]:
           __UpperCamelCase   							=start
           __UpperCamelCase   							=end
           __UpperCamelCase   							=val
           __UpperCamelCase   							=(start + end) // 2
           __UpperCamelCase   							=left
           __UpperCamelCase   							=right






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






class    UpperCAmelCase__	:



    """simple docstring"""






    def __init__(      self ,       A_ ,       A_   )  ->	List[str]:
           __UpperCamelCase   							=collection
           __UpperCamelCase   							=function
           if self.collection:
                  __UpperCamelCase   							=self._build_tree(0 ,       len(A_   ) - 1   )






    def _a (      self ,       A_ ,       A_   )  ->	Any:
           self._update_tree(self.root ,       A_ ,       A_   )






    def _a (      self ,       A_ ,       A_   )  ->	str:
           return self._query_range(self.root ,       A_ ,       A_   )






    def _a (      self ,       A_ ,       A_   )  ->	str:
           if start == end:
                  return SegmentTreeNode(A_ ,       A_ ,       self.collection[start]   )
           __UpperCamelCase   							=(start + end) // 2
           __UpperCamelCase   							=self._build_tree(A_ ,       A_   )
           __UpperCamelCase   							=self._build_tree(mid + 1 ,       A_   )
           return SegmentTreeNode(A_ ,       A_ ,       self.fn(left.val ,       right.val   ) ,       A_ ,       A_   )






    def _a (      self ,       A_ ,       A_ ,       A_   )  ->	List[str]:
           if node.start == i and node.end == i:
                  __UpperCamelCase   							=val
                  return
           if i <= node.mid:
                  self._update_tree(node.left ,       A_ ,       A_   )
           else:
                  self._update_tree(node.right ,       A_ ,       A_   )
           __UpperCamelCase   							=self.fn(node.left.val ,       node.right.val   )






    def _a (      self ,       A_ ,       A_ ,       A_   )  ->	Optional[Any]:
           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   )  ->	int:
           if self.root is not None:
                  __UpperCamelCase   							=Queue()
                  queue.put(self.root   )
                  while not queue.empty():
                         __UpperCamelCase   							=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)
      _A			=						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()









import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812

def 						_UpperCAmelCase    (      ):
     print('Making key files...'    )
     make_key_files('rsa'      ,					10_24    )
     print('Key files generation successful.'    )

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : int    ):
     print('Generating prime p...'    )
     __UpperCamelCase   							=rabinMiller.generate_large_prime(SCREAMING_SNAKE_CASE__    )
     print('Generating prime q...'    )
     __UpperCamelCase   							=rabinMiller.generate_large_prime(SCREAMING_SNAKE_CASE__    )
     __UpperCamelCase   							=p * q

     print('Generating e that is relatively prime to (p - 1) * (q - 1)...'    )
     while True:
          __UpperCamelCase   							=random.randrange(2 ** (key_size - 1)      ,					2 ** (key_size)    )
          if cryptoMath.gcd(SCREAMING_SNAKE_CASE__      ,					(p - 1) * (q - 1)    ) == 1:
               break

     print('Calculating d that is mod inverse of e...'    )
     __UpperCamelCase   							=cryptoMath.find_mod_inverse(SCREAMING_SNAKE_CASE__      ,					(p - 1) * (q - 1)    )

     __UpperCamelCase   							=(n, e)
     __UpperCamelCase   							=(n, d)
     return (public_key, private_key)

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : str      ,					SCREAMING_SNAKE_CASE__      : int    ):
     if os.path.exists(F'{name}_pubkey.txt'    ) or os.path.exists(F'{name}_privkey.txt'    ):
          print('\nWARNING:'    )
          print(
              F'"{name}_pubkey.txt" or "{name}_privkey.txt" already exists. \n'
              'Use a different name or delete these files and re-run this program.'    )
          sys.exit()

     __UpperCamelCase							,				__UpperCamelCase   							=generate_key(SCREAMING_SNAKE_CASE__    )
     print(F'\nWriting public key to file {name}_pubkey.txt...'    )
     with open(F'{name}_pubkey.txt'      ,					'w'    ) as out_file:
          out_file.write(F'{key_size},{public_key[0]},{public_key[1]}'    )

     print(F'Writing private key to file {name}_privkey.txt...'    )
     with open(F'{name}_privkey.txt'      ,					'w'    ) as out_file:
          out_file.write(F'{key_size},{private_key[0]},{private_key[1]}'    )


if __name__ == "__main__":
   main()





