


from __future__ import annotations

import math






class      UpperCamelCase					:


   '''simple docstring'''







   def __init__(     self   ,							UpperCamelCase_		):
        lowercase_       :Dict     =       size
        # approximate the overall size of segment tree with given value
        lowercase_       :Dict     =       [0 for i in range(0   ,							4 * size		)]
        # create array to store lazy update
        lowercase_       :Optional[Any]     =       [0 for i in range(0   ,							4 * size		)]
        lowercase_       :Tuple     =       [0 for i in range(0   ,							4 * size		)]  # flag for lazy update
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_		):
        return idx * 2
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_		):
        return idx * 2 + 1
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_		):
        if left_element == right_element:
             lowercase_       :Tuple     =       a[left_element - 1]
        else:
             lowercase_       :Any     =       (left_element + right_element) // 2
             self.build(self.left(UpperCamelCase_		)   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_		)
             self.build(self.right(UpperCamelCase_		)   ,							mid + 1   ,							UpperCamelCase_   ,							UpperCamelCase_		)
             lowercase_       :Union[str, Any]     =       max(
                 self.segment_tree[self.left(UpperCamelCase_		)]   ,							self.segment_tree[self.right(UpperCamelCase_		)]		)
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_		):
        if self.flag[idx] is True:
             lowercase_       :Optional[int]     =       self.lazy[idx]
             lowercase_       :Optional[int]     =       False
             if left_element != right_element:
                  lowercase_       :str     =       self.lazy[idx]
                  lowercase_       :str     =       self.lazy[idx]
                  lowercase_       :Union[str, Any]     =       True
                  lowercase_       :Optional[int]     =       True

        if right_element < a or left_element > b:
             return True
        if left_element >= a and right_element <= b:
             lowercase_       :List[str]     =       val
             if left_element != right_element:
                  lowercase_       :Tuple     =       val
                  lowercase_       :Optional[Any]     =       val
                  lowercase_       :Union[str, Any]     =       True
                  lowercase_       :Optional[Any]     =       True
             return True
        lowercase_       :str     =       (left_element + right_element) // 2
        self.update(self.left(UpperCamelCase_		)   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_		)
        self.update(self.right(UpperCamelCase_		)   ,							mid + 1   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_		)
        lowercase_       :int     =       max(
            self.segment_tree[self.left(UpperCamelCase_		)]   ,							self.segment_tree[self.right(UpperCamelCase_		)]		)
        return True
   def 		UpperCamelCase  (     self   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_		):
        if self.flag[idx] is True:
             lowercase_       :Optional[int]     =       self.lazy[idx]
             lowercase_       :Tuple     =       False
             if left_element != right_element:
                  lowercase_       :Tuple     =       self.lazy[idx]
                  lowercase_       :List[Any]     =       self.lazy[idx]
                  lowercase_       :str     =       True
                  lowercase_       :int     =       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]
        lowercase_       :str     =       (left_element + right_element) // 2
        lowercase_       :Dict     =       self.query(self.left(UpperCamelCase_		)   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_		)
        lowercase_       :Union[str, Any]     =       self.query(self.right(UpperCamelCase_		)   ,							mid + 1   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_		)
        return max(UpperCamelCase_   ,							UpperCamelCase_		)




   def __str__(     self		):
        return str([self.query(1   ,							1   ,							self.size   ,							UpperCamelCase_   ,							UpperCamelCase_		) for i in range(1   ,							self.size + 1		)]		)


if __name__ == "__main__":
   SCREAMING_SNAKE_CASE       :		Tuple         =				[1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
   SCREAMING_SNAKE_CASE       :		Dict         =				15
   SCREAMING_SNAKE_CASE       :		Any         =				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)





import argparse

import torch

from transformers import OpenAIGPTConfig, OpenAIGPTModel, load_tf_weights_in_openai_gpt
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()




def     UpperCamelCase    (      _a       ,		_a       ,		_a		)					->							List[str]:
     '''simple docstring'''





     if openai_config_file == "":
          lowercase_       :str     =       OpenAIGPTConfig()
     else:
          lowercase_       :int     =       OpenAIGPTConfig.from_json_file(_a		)
     lowercase_       :int     =       OpenAIGPTModel(_a		)

     # Load weights from numpy
     load_tf_weights_in_openai_gpt(_a       ,		_a       ,		_a		)

     # Save pytorch-model
     lowercase_       :Optional[int]     =       pytorch_dump_folder_path + '''/''' + WEIGHTS_NAME
     lowercase_       :List[str]     =       pytorch_dump_folder_path + '''/''' + CONFIG_NAME
     print(f"Save PyTorch model to {pytorch_weights_dump_path}"		)
     torch.save(model.state_dict()       ,		_a		)
     print(f"Save configuration file to {pytorch_config_dump_path}"		)
     with open(_a       ,		'''w'''       ,		encoding='''utf-8'''		) as f:
          f.write(config.to_json_string()		)


if __name__ == "__main__":
   SCREAMING_SNAKE_CASE       :		List[str]         =				argparse.ArgumentParser()
   # Required parameters
   parser.add_argument(
       "--openai_checkpoint_folder_path",
       default=None,
       type=str,
       required=True,
       help="Path to the TensorFlow checkpoint path.",
   )
   parser.add_argument(
       "--pytorch_dump_folder_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
   )
   parser.add_argument(
       "--openai_config_file",
       default="",
       type=str,
       help=(
           "An optional config json file corresponding to the pre-trained OpenAI model. \n"
           "This specifies the model architecture."
       ),
   )
   SCREAMING_SNAKE_CASE       :		Optional[Any]         =				parser.parse_args()
   convert_openai_checkpoint_to_pytorch(
       args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
   )

