



from typing import Dict, Optional, Tuple

import torch

def       A_   (						__a  :					torch.Tensor		):

				"""simple docstring"""
				a__					   =		boundaries[1] - boundaries[0]
				a__					   =		boundaries + step / 2
				a__					   =		torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1		)]			,		dim=0		)
				return bin_centers

def       A_   (						__a  :					torch.Tensor			,		__a  :					torch.Tensor			,		):

				"""simple docstring"""
				a__					   =		_calculate_bin_centers(__a		)
				return (
				    torch.sum(aligned_distance_error_probs * bin_centers			,		dim=-1		),
				    bin_centers[-1],
				)

def       A_   (						__a  :					torch.Tensor			,		__a  :					int = 31			,		__a  :					int = 64			,		**__a  :					Any			,		):

				"""simple docstring"""
				a__					   =		torch.linspace(0			,		__a			,		steps=(no_bins - 1)			,		device=logits.device		)

				a__					   =		torch.nn.functional.softmax(__a			,		dim=-1		)
				a__   ,      a__					   =		_calculate_expected_aligned_error(
				    alignment_confidence_breaks=__a			,		aligned_distance_error_probs=__a			,		)

				return {
				    "aligned_confidence_probs": aligned_confidence_probs,
				    "predicted_aligned_error": predicted_aligned_error,
				    "max_predicted_aligned_error": max_predicted_aligned_error,
				}




def       A_   (						__a  :					torch.Tensor			,		__a  :					Optional[torch.Tensor] = None			,		__a  :					int = 31			,		__a  :					int = 64			,		__a  :					float = 1e-8			,		**__a  :					str			,		):

				"""simple docstring"""
				if residue_weights is None:
								a__					   =		logits.new_ones(logits.shape[-2]		)

				a__					   =		torch.linspace(0			,		__a			,		steps=(no_bins - 1)			,		device=logits.device		)

				a__					   =		_calculate_bin_centers(__a		)
				torch.sum(__a		)
				a__					   =		logits.shape[-2]
				a__					   =		max(__a			,		19		)

				a__					   =		1.2_4 * (clipped_n - 15) ** (1.0 / 3) - 1.8

				a__					   =		torch.nn.functional.softmax(__a			,		dim=-1		)

				a__					   =		1.0 / (1 + (bin_centers**2) / (da**2))
				a__					   =		torch.sum(probs * tm_per_bin			,		dim=-1		)

				a__					   =		residue_weights / (eps + residue_weights.sum())
				a__					   =		torch.sum(predicted_tm_term * normed_residue_mask			,		dim=-1		)

				a__					   =		per_alignment * residue_weights

				a__					   =		(weighted == torch.max(__a		)).nonzero()[0]
				return per_alignment[tuple(__a		)]









import math




class 	lowerCamelCase__				:






      def __init__(self					:    int		,		_snake_case					:    Dict		)       ->   Union[str, Any]:


       """simple docstring"""






       lowerCamelCase_							:    Optional[Any]							=     len(_snake_case		)
       lowerCamelCase_							:    Optional[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					:    List[str]		,		_snake_case					:    List[str]		)       ->   int:


       """simple docstring"""






       return idx * 2






      def      UpperCAmelCase_     (self					:    Tuple		,		_snake_case					:    Dict		)       ->   Optional[Any]:


       """simple docstring"""






       return idx * 2 + 1






      def      UpperCAmelCase_     (self					:    List[Any]		,		_snake_case					:    List[Any]		,		_snake_case					:    str		,		_snake_case					:    List[Any]		)       ->   Optional[Any]:  # noqa: E741


       """simple docstring"""






       if l == r:
        lowerCamelCase_							:    List[Any]							=     A[l]
       else:
        lowerCamelCase_							:    int							=     (l + r) // 2
        self.build(self.left(_snake_case		)		,		_snake_case		,		_snake_case		)
        self.build(self.right(_snake_case		)		,		mid + 1		,		_snake_case		)
        lowerCamelCase_							:    Tuple							=     max(self.st[self.left(_snake_case		)]		,		self.st[self.right(_snake_case		)]		)






      def      UpperCAmelCase_     (self					:    str		,		_snake_case					:    Tuple		,		_snake_case					:    Any		,		_snake_case					:    str		)       ->   Tuple:


       """simple docstring"""






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






      def      UpperCAmelCase_     (self					:    Tuple		,		_snake_case					:    List[str]		,		_snake_case					:    Tuple		,		_snake_case					:    Optional[int]		,		_snake_case					:    int		,		_snake_case					:    Tuple		,		_snake_case					:    List[str]		)       ->   Optional[Any]:  # noqa: E741


       """simple docstring"""






       if r < a or l > b:
        return True
       if l == r:
        lowerCamelCase_							:    Tuple							=     val
        return True
       lowerCamelCase_							:    Optional[int]							=     (l + r) // 2
       self.update_recursive(self.left(_snake_case		)		,		_snake_case		,		_snake_case		,		_snake_case		,		_snake_case		,		_snake_case		)
       self.update_recursive(self.right(_snake_case		)		,		mid + 1		,		_snake_case		,		_snake_case		,		_snake_case		,		_snake_case		)
       lowerCamelCase_							:    Union[str, Any]							=     max(self.st[self.left(_snake_case		)]		,		self.st[self.right(_snake_case		)]		)
       return True






      def      UpperCAmelCase_     (self					:    List[Any]		,		_snake_case					:    List[Any]		,		_snake_case					:    Optional[int]		)       ->   str:


       """simple docstring"""






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






      def      UpperCAmelCase_     (self					:    Any		,		_snake_case					:    List[Any]		,		_snake_case					:    Optional[Any]		,		_snake_case					:    int		,		_snake_case					:    Optional[int]		,		_snake_case					:    Optional[Any]		)       ->   str:  # noqa: E741


       """simple docstring"""






       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_							:    Optional[Any]							=     self.query_recursive(self.left(_snake_case		)		,		_snake_case		,		_snake_case		,		_snake_case		,		_snake_case		)
       lowerCamelCase_							:    Union[str, Any]							=     self.query_recursive(self.right(_snake_case		)		,		mid + 1		,		_snake_case		,		_snake_case		,		_snake_case		)
       return max(_snake_case		,		_snake_case		)






      def      UpperCAmelCase_     (self					:    str		)       ->   Tuple:


       """simple docstring"""






       lowerCamelCase_							:    Dict							=     []
       for i in range(1		,		N + 1		):
        show_list += [self.query(_snake_case		,		_snake_case		)]
       print(_snake_case		)


if __name__ == "__main__":
       UpperCamelCase											=      [1, 2, -4, 7, 3, -5, 6, 1_1, -2_0, 9, 1_4, 1_5, 5, 2, -8]
       UpperCamelCase											=      1_5
       UpperCamelCase											=      SegmentTree(A)
       print(segt.query(4, 6))
       print(segt.query(7, 1_1))
       print(segt.query(7, 1_2))
       segt.update(1, 3, 1_1_1)
       print(segt.query(1, 1_5))
       segt.update(7, 8, 2_3_5)
       segt.show_data()
