





import unittest
from unittest.util import safe_repr

from transformers import AutoTokenizer, RwkvConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          RWKV_PRETRAINED_MODEL_ARCHIVE_LIST,
          RwkvForCausalLM,
          RwkvModel,
      )
      from transformers.pytorch_utils import is_torch_greater_or_equal_than_2_0
else:
      UpperCAmelCase_       : int							=    False





class   lowercase__     :







  def __init__(						self     ,    _lowercase     ,    _lowercase=14     ,    _lowercase=7     ,    _lowercase=True     ,    _lowercase=False     ,    _lowercase=True     ,    _lowercase=True     ,    _lowercase=True     ,    _lowercase=99     ,    _lowercase=32     ,    _lowercase=5     ,    _lowercase=37     ,    _lowercase="gelu"     ,    _lowercase=0.1     ,    _lowercase=0.1     ,    _lowercase=512     ,    _lowercase=16     ,    _lowercase=2     ,    _lowercase=3     ,    _lowercase=4     ,    _lowercase=None     ,    ):
       lowerCAmelCase_       :							Optional[Any]			 =		parent
       lowerCAmelCase_       :							List[Any]			 =		batch_size
       lowerCAmelCase_       :							Dict			 =		seq_length
       lowerCAmelCase_       :							List[Any]			 =		is_training
       lowerCAmelCase_       :							List[Any]			 =		use_token_type_ids
       lowerCAmelCase_       :							List[Any]			 =		use_input_mask
       lowerCAmelCase_       :							str			 =		use_labels
       lowerCAmelCase_       :							List[str]			 =		use_mc_token_ids
       lowerCAmelCase_       :							List[Any]			 =		vocab_size
       lowerCAmelCase_       :							int			 =		hidden_size
       lowerCAmelCase_       :							Any			 =		num_hidden_layers
       lowerCAmelCase_       :							str			 =		intermediate_size
       lowerCAmelCase_       :							List[str]			 =		hidden_act
       lowerCAmelCase_       :							Tuple			 =		hidden_dropout_prob
       lowerCAmelCase_       :							Optional[int]			 =		attention_probs_dropout_prob
       lowerCAmelCase_       :							List[str]			 =		max_position_embeddings
       lowerCAmelCase_       :							Any			 =		type_vocab_size
       lowerCAmelCase_       :							Tuple			 =		type_sequence_label_size
       lowerCAmelCase_       :							Tuple			 =		num_labels
       lowerCAmelCase_       :							Optional[int]			 =		num_choices
       lowerCAmelCase_       :							str			 =		scope
       lowerCAmelCase_       :							List[str]			 =		vocab_size - 1
       lowerCAmelCase_       :							List[str]			 =		vocab_size - 1
       lowerCAmelCase_       :							int			 =		vocab_size - 1







  def 						UpperCAmelCase__		(						self    ):
       return RwkvConfig.from_pretrained("""sgugger/rwkv-4-pile-7b"""    )







  def 						UpperCAmelCase__		(						self     ,    _lowercase=False     ,    _lowercase=False     ,    _lowercase=False    ):
       lowerCAmelCase_       :							Any			 =		ids_tensor([self.batch_size, self.seq_length]     ,    self.vocab_size    )

       lowerCAmelCase_       :							Optional[int]			 =		None
       if self.use_input_mask:
            lowerCAmelCase_       :							Tuple			 =		random_attention_mask([self.batch_size, self.seq_length]    )

       lowerCAmelCase_       :							Optional[int]			 =		None
       if self.use_token_type_ids:
            lowerCAmelCase_       :							int			 =		ids_tensor([self.batch_size, self.seq_length]     ,    self.type_vocab_size    )

       lowerCAmelCase_       :							List[Any]			 =		None
       if self.use_mc_token_ids:
            lowerCAmelCase_       :							Optional[int]			 =		ids_tensor([self.batch_size, self.num_choices]     ,    self.seq_length    )

       lowerCAmelCase_       :							Optional[Any]			 =		None
       lowerCAmelCase_       :							Union[str, Any]			 =		None
       lowerCAmelCase_       :							List[str]			 =		None
       if self.use_labels:
            lowerCAmelCase_       :							Optional[int]			 =		ids_tensor([self.batch_size]     ,    self.type_sequence_label_size    )
            lowerCAmelCase_       :							Optional[int]			 =		ids_tensor([self.batch_size, self.seq_length]     ,    self.num_labels    )
            lowerCAmelCase_       :							List[Any]			 =		ids_tensor([self.batch_size]     ,    self.num_choices    )

       lowerCAmelCase_       :							int			 =		self.get_config(
           gradient_checkpointing=_lowercase     ,    scale_attn_by_inverse_layer_idx=_lowercase     ,    reorder_and_upcast_attn=_lowercase     ,    )

       return (
           config,
           input_ids,
           input_mask,
           None,
           token_type_ids,
           mc_token_ids,
           sequence_labels,
           token_labels,
           choice_labels,
       )







  def 						UpperCAmelCase__		(						self     ,    _lowercase=False     ,    _lowercase=False     ,    _lowercase=False    ):
       return RwkvConfig(
           vocab_size=self.vocab_size     ,    hidden_size=self.hidden_size     ,    num_hidden_layers=self.num_hidden_layers     ,    intermediate_size=self.intermediate_size     ,    activation_function=self.hidden_act     ,    resid_pdrop=self.hidden_dropout_prob     ,    attn_pdrop=self.attention_probs_dropout_prob     ,    n_positions=self.max_position_embeddings     ,    type_vocab_size=self.type_vocab_size     ,    use_cache=_lowercase     ,    bos_token_id=self.bos_token_id     ,    eos_token_id=self.eos_token_id     ,    pad_token_id=self.pad_token_id     ,    gradient_checkpointing=_lowercase     ,    scale_attn_by_inverse_layer_idx=_lowercase     ,    reorder_and_upcast_attn=_lowercase     ,    )







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							List[str]			 =		self.get_config()
       lowerCAmelCase_       :							int			 =		300
       return config







  def 						UpperCAmelCase__		(						self    ):
       (
           (
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	
       )       :							Tuple			 =		self.prepare_config_and_inputs()

       lowerCAmelCase_       :							Union[str, Any]			 =		floats_tensor([self.batch_size, self.seq_length, self.hidden_size]    )
       lowerCAmelCase_       :							Union[str, Any]			 =		ids_tensor([self.batch_size, self.seq_length]     ,    vocab_size=2    )

       return (
           config,
           input_ids,
           input_mask,
           head_mask,
           token_type_ids,
           sequence_labels,
           token_labels,
           choice_labels,
           encoder_hidden_states,
           encoder_attention_mask,
       )







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    *_lowercase    ):
       lowerCAmelCase_       :							Tuple			 =		True
       lowerCAmelCase_       :							List[str]			 =		RwkvModel(config=_lowercase    )
       model.to(_lowercase    )
       model.eval()

       lowerCAmelCase_       :							List[str]			 =		model(_lowercase    )

       self.parent.assertEqual(result.last_hidden_state.shape     ,    (self.batch_size, self.seq_length, self.hidden_size)    )
       self.parent.assertEqual(len(result.hidden_states    )     ,    config.num_hidden_layers + 1    )







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    *_lowercase    ):
       lowerCAmelCase_       :							str			 =		RwkvForCausalLM(_lowercase    )
       model.to(_lowercase    )
       model.eval()

       lowerCAmelCase_       :							Optional[int]			 =		model(_lowercase     ,    labels=_lowercase    )
       self.parent.assertEqual(result.loss.shape     ,    ()    )
       self.parent.assertEqual(result.logits.shape     ,    (self.batch_size, self.seq_length, self.vocab_size)    )







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    *_lowercase    ):
       lowerCAmelCase_       :							int			 =		RwkvModel(config=_lowercase    )
       model.to(_lowercase    )
       model.eval()

       lowerCAmelCase_       :							Optional[Any]			 =		model(_lowercase    )
       lowerCAmelCase_       :							Tuple			 =		outputs.last_hidden_state

       lowerCAmelCase_       :							Any			 =		model(input_ids[:, :2]    )
       lowerCAmelCase_       :							Dict			 =		outputs.last_hidden_state

       # Using the state computed on the first inputs, we will get the same output
       lowerCAmelCase_       :							Union[str, Any]			 =		model(input_ids[:, 2:]     ,    state=outputs.state    )
       lowerCAmelCase_       :							Optional[int]			 =		outputs.last_hidden_state

       self.parent.assertTrue(torch.allclose(torch.cat([output_one, output_two]     ,    dim=1    )     ,    _lowercase     ,    atol=1e-5    )    )







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    *_lowercase     ,    _lowercase=False    ):
       lowerCAmelCase_       :							int			 =		RwkvForCausalLM(_lowercase    )
       model.to(_lowercase    )
       if gradient_checkpointing:
            model.gradient_checkpointing_enable()

       lowerCAmelCase_       :							Dict			 =		model(_lowercase     ,    labels=_lowercase    )
       self.parent.assertEqual(result.loss.shape     ,    ()    )
       self.parent.assertEqual(result.logits.shape     ,    (self.batch_size, self.seq_length, self.vocab_size)    )
       result.loss.backward()







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							Optional[Any]			 =		self.prepare_config_and_inputs()

       (
           (
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	(
           lowerCAmelCase_
       ) ,	
       )       :							Any			 =		config_and_inputs

       lowerCAmelCase_       :							Any			 =		{"""input_ids""": input_ids}

       return config, inputs_dict





@unittest.skipIf(
    not is_torch_greater_or_equal_than_2_0  ,       reason="""See https://github.com/huggingface/transformers/pull/24204"""	)
@require_torch
class   lowercase__     (				__A  ,       __A  ,       __A  ,       unittest.TestCase	):
  __UpperCamelCase						  =	(RwkvModel, RwkvForCausalLM) if is_torch_available() else ()
  __UpperCamelCase						  =	(
      {"""feature-extraction""": RwkvModel, """text-generation""": RwkvForCausalLM} if is_torch_available() else {}
  )
  # all_generative_model_classes = (RwkvForCausalLM,) if is_torch_available() else ()
  __UpperCamelCase						  =	False
  __UpperCamelCase						  =	False
  __UpperCamelCase						  =	False
  __UpperCamelCase						  =	False
  __UpperCamelCase						  =	False  # Rwkv does not support head masking







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							Union[str, Any]			 =		RwkvModelTester(self    )
       lowerCAmelCase_       :							Dict			 =		ConfigTester(
           self     ,    config_class=_lowercase     ,    n_embd=37     ,    common_properties=["""hidden_size""", """num_hidden_layers"""]    )







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase     ,    _lowercase=None    ):
       if isinstance(_lowercase     ,    torch.Tensor    ):
            lowerCAmelCase_ ,	lowerCAmelCase_       :							int			 =		member.max().item(), member.min().item()
       elif isinstance(_lowercase     ,    _lowercase    ) or isinstance(_lowercase     ,    _lowercase    ):
            lowerCAmelCase_ ,	lowerCAmelCase_       :							int			 =		max(_lowercase    ), min(_lowercase    )

       if not isinstance(_lowercase     ,    _lowercase    ):
            raise TypeError("""container should be a list or tuple"""    )
       elif len(_lowercase    ) != 2:
            raise ValueError("""container should have 2 elements"""    )

       lowerCAmelCase_ ,	lowerCAmelCase_       :							Optional[int]			 =		container

       lowerCAmelCase_       :							Dict			 =		(min_value >= expected_min) and (max_value <= expected_max)

       if not is_inside_interval:
            lowerCAmelCase_       :							Optional[Any]			 =		"""%s not found in %s""" % (safe_repr(_lowercase    ), safe_repr(_lowercase    ))
            self.fail(self._formatMessage(_lowercase     ,    _lowercase    )    )







  def 						UpperCAmelCase__		(						self    ):
       self.config_tester.run_common_tests()







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							Optional[int]			 =		self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_rwkv_model(*_lowercase    )







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							Optional[Any]			 =		self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_causl_lm(*_lowercase    )







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							List[str]			 =		self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_state_equivalency(*_lowercase    )







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_ ,	lowerCAmelCase_       :							str			 =		self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
            lowerCAmelCase_       :							Optional[int]			 =		model_class(config=_lowercase    )
            for name, param in model.named_parameters():
                 if "time_decay" in name:
                      if param.requires_grad:
                           self.assertTrue(param.data.max().item() == 3.0    )
                           self.assertTrue(param.data.min().item() == -5.0    )
                 elif "time_first" in name:
                      if param.requires_grad:
                           # check if it's a ones like
                           self.assertTrue(torch.allclose(param.data     ,    torch.ones_like(param.data    )     ,    atol=1e-5     ,    rtol=1e-5    )    )
                 elif any(x in name for x in ["""time_mix_key""", """time_mix_receptance"""]    ):
                      if param.requires_grad:
                           self.assertInterval(
                               param.data     ,    [0.0, 1.0]     ,    msg=F'Parameter {name} of model {model_class} seems not properly initialized'     ,    )
                 elif "time_mix_value" in name:
                      if param.requires_grad:
                           self.assertInterval(
                               param.data     ,    [0.0, 1.3]     ,    msg=F'Parameter {name} of model {model_class} seems not properly initialized'     ,    )







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_ ,	lowerCAmelCase_       :							List[str]			 =		self.model_tester.prepare_config_and_inputs_for_common()
       lowerCAmelCase_       :							Any			 =		True

       lowerCAmelCase_       :							List[str]			 =		getattr(self.model_tester     ,    """seq_length"""     ,    _lowercase    )

       for model_class in self.all_model_classes:
            lowerCAmelCase_       :							int			 =		True
            lowerCAmelCase_       :							List[str]			 =		False
            lowerCAmelCase_       :							Any			 =		True
            lowerCAmelCase_       :							int			 =		model_class(_lowercase    )
            model.to(_lowercase    )
            model.eval()

            lowerCAmelCase_       :							str			 =		self._prepare_for_class(_lowercase     ,    _lowercase    )
            lowerCAmelCase_       :							Tuple			 =		inputs["""input_ids"""].shape[0]
            with torch.no_grad():
                 lowerCAmelCase_       :							Tuple			 =		model(**_lowercase    )
            lowerCAmelCase_       :							Optional[int]			 =		outputs.attentions
            self.assertEqual(len(_lowercase    )     ,    self.model_tester.num_hidden_layers    )

            # check that output_attentions also work using config
            del inputs_dict["output_attentions"]
            lowerCAmelCase_       :							List[Any]			 =		True
            lowerCAmelCase_       :							Tuple			 =		model_class(_lowercase    )
            model.to(_lowercase    )
            model.eval()

            lowerCAmelCase_       :							Optional[int]			 =		self._prepare_for_class(_lowercase     ,    _lowercase    )
            lowerCAmelCase_       :							Optional[Any]			 =		inputs["""input_ids"""].shape[0]
            with torch.no_grad():
                 lowerCAmelCase_       :							Tuple			 =		model(**_lowercase    )
            lowerCAmelCase_       :							Optional[int]			 =		outputs.attentions
            self.assertEqual(len(_lowercase    )     ,    self.model_tester.num_hidden_layers    )

            self.assertListEqual(
                list(attentions[0].shape[-3:]    )     ,    [batch_size, seq_len, config.hidden_size]     ,    )
            lowerCAmelCase_       :							str			 =		len(_lowercase    )

            # Check attention is always last and order is fine
            lowerCAmelCase_       :							List[str]			 =		True
            lowerCAmelCase_       :							List[Any]			 =		True
            lowerCAmelCase_       :							str			 =		model_class(_lowercase    )
            model.to(_lowercase    )
            model.eval()

            lowerCAmelCase_       :							str			 =		self._prepare_for_class(_lowercase     ,    _lowercase    )
            lowerCAmelCase_       :							Union[str, Any]			 =		inputs["""input_ids"""].shape[0]
            with torch.no_grad():
                 lowerCAmelCase_       :							Optional[int]			 =		model(**_lowercase    )

            lowerCAmelCase_       :							List[Any]			 =		1
            self.assertEqual(out_len + added_hidden_states     ,    len(_lowercase    )    )

            lowerCAmelCase_       :							Dict			 =		outputs.attentions

            self.assertEqual(len(_lowercase    )     ,    self.model_tester.num_hidden_layers    )
            self.assertListEqual(
                list(self_attentions[0].shape[-3:]    )     ,    [batch_size, seq_len, config.hidden_size]     ,    )







  @slow
  def 						UpperCAmelCase__		(						self    ):
       for model_name in RWKV_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
            lowerCAmelCase_       :							Optional[Any]			 =		RwkvModel.from_pretrained(_lowercase    )
            self.assertIsNotNone(_lowercase    )





@unittest.skipIf(
    not is_torch_greater_or_equal_than_2_0  ,       reason="""See https://github.com/huggingface/transformers/pull/24204"""	)
@slow
class   lowercase__     (				unittest.TestCase	):







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							str			 =		"""RWKV/rwkv-4-169m-pile"""
       lowerCAmelCase_       :							Optional[Any]			 =		AutoTokenizer.from_pretrained(self.model_id    )







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							Tuple			 =		"""Hello my name is Jasmine and I am a newbie to the"""
       lowerCAmelCase_       :							Optional[Any]			 =		RwkvForCausalLM.from_pretrained(self.model_id    ).to(_lowercase    )

       lowerCAmelCase_       :							str			 =		self.tokenizer("""Hello my name is"""     ,    return_tensors="""pt"""    ).input_ids.to(_lowercase    )
       lowerCAmelCase_       :							str			 =		model.generate(_lowercase     ,    max_new_tokens=10    )
       lowerCAmelCase_       :							int			 =		self.tokenizer.decode(output[0].tolist()    )

       self.assertEqual(_lowercase     ,    _lowercase    )







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							Optional[Any]			 =		"""Hello my name is Jasmine and I am a newbie to the"""

       lowerCAmelCase_       :							Dict			 =		self.tokenizer("""Hello my name is"""     ,    return_tensors="""pt"""    ).input_ids.to(_lowercase    )
       lowerCAmelCase_       :							Union[str, Any]			 =		RwkvForCausalLM.from_pretrained(self.model_id     ,    torch_dtype=torch.bfloataa    ).to(_lowercase    )

       lowerCAmelCase_       :							str			 =		model.generate(_lowercase     ,    max_new_tokens=10    )
       lowerCAmelCase_       :							Dict			 =		self.tokenizer.decode(output[0].tolist()    )

       self.assertEqual(_lowercase     ,    _lowercase    )







import math





class   lowercase__     :







  def __init__(						self     ,    _lowercase    ):
       lowerCAmelCase_       :							Optional[Any]			 =		len(_lowercase    )
       lowerCAmelCase_       :							Union[str, Any]			 =		[0] * (
           4 * self.N
       )  # approximate the overall size of segment tree with array N
       self.build(1     ,    0     ,    self.N - 1    )







  def 						UpperCAmelCase__		(						self     ,    _lowercase    ):
       return idx * 2







  def 						UpperCAmelCase__		(						self     ,    _lowercase    ):
       return idx * 2 + 1







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase     ,    _lowercase    ):  # noqa: E741
       if l == r:
            lowerCAmelCase_       :							Dict			 =		A[l]
       else:
            lowerCAmelCase_       :							List[str]			 =		(l + r) // 2
            self.build(self.left(_lowercase    )     ,    _lowercase     ,    _lowercase    )
            self.build(self.right(_lowercase    )     ,    mid + 1     ,    _lowercase    )
            lowerCAmelCase_       :							Dict			 =		max(self.st[self.left(_lowercase    )]     ,    self.st[self.right(_lowercase    )]    )







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase     ,    _lowercase    ):
       return self.update_recursive(1     ,    0     ,    self.N - 1     ,    a - 1     ,    b - 1     ,    _lowercase    )







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase    ):  # noqa: E741
       if r < a or l > b:
            return True
       if l == r:
            lowerCAmelCase_       :							List[str]			 =		val
            return True
       lowerCAmelCase_       :							List[str]			 =		(l + r) // 2
       self.update_recursive(self.left(_lowercase    )     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase    )
       self.update_recursive(self.right(_lowercase    )     ,    mid + 1     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase    )
       lowerCAmelCase_       :							List[Any]			 =		max(self.st[self.left(_lowercase    )]     ,    self.st[self.right(_lowercase    )]    )
       return True







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase    ):
       return self.query_recursive(1     ,    0     ,    self.N - 1     ,    a - 1     ,    b - 1    )







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase    ):  # noqa: E741
       if r < a or l > b:
            return -math.inf
       if l >= a and r <= b:
            return self.st[idx]
       lowerCAmelCase_       :							int			 =		(l + r) // 2
       lowerCAmelCase_       :							List[Any]			 =		self.query_recursive(self.left(_lowercase    )     ,    _lowercase     ,    _lowercase     ,    _lowercase     ,    _lowercase    )
       lowerCAmelCase_       :							List[str]			 =		self.query_recursive(self.right(_lowercase    )     ,    mid + 1     ,    _lowercase     ,    _lowercase     ,    _lowercase    )
       return max(_lowercase     ,    _lowercase    )







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							List[Any]			 =		[]
       for i in range(1     ,    N + 1    ):
            show_list += [self.query(_lowercase     ,    _lowercase    )]
       print(_lowercase    )


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