// codesnip-guard: PersistentSegmentTree #[cfg_attr(any(),rustfmt::skip)]pub use self::persistent_segment_tree::PersistentSegmentTree;#[cfg_attr(any(),rustfmt::skip)]mod persistent_segment_tree{use super::{Allocator,MemoryPool,Monoid,RangeBoundsExt};use std::{fmt::{self,Debug,Formatter},ops::{Range,RangeBounds},ptr::NonNull};type NodePtr=Option>>;struct Node{children:[NodePtr;2],value:T}implNode{fn new(children:[NodePtr;2],value:T)->Self{Self{children,value}}}#[derive(Debug,Clone,Copy,PartialEq,Eq,Hash)]#[must_use]pub struct PersistentSegmentTreeVersion(usize);impl PersistentSegmentTreeVersion{fn base()->Self{Self(0)}fn new(version_id:usize)->Self{Self(version_id)}fn index(self)->usize{self.0}}pub struct PersistentSegmentTreewhere M:Monoid{len:usize,version_roots:Vec>,allocator:MemoryPool>}implDebug for PersistentSegmentTreewhere M:Monoid{fn fmt(&self,f:&mut Formatter<'_>)->fmt::Result{f.debug_struct("PersistentSegmentTree").field("len",&self.len).field("versions",&self.version_roots.len()).finish()}}implPersistentSegmentTreewhere M:Monoid{#[must_use]pub fn new(len:usize)->Self{Self{len,version_roots:vec![None],allocator:MemoryPool::new()}}pub fn base(&self)->PersistentSegmentTreeVersion{PersistentSegmentTreeVersion::base()}pub fn len(&self)->usize{self.len}pub fn is_empty(&self)->bool{self.len==0}fn version_root(&self,version:PersistentSegmentTreeVersion)->NodePtr{*self.version_roots.get(version.index()).expect("invalid version")}fn push_version_root(&mut self,root:NodePtr)->PersistentSegmentTreeVersion{let version_id=self.version_roots.len();self.version_roots.push(root);PersistentSegmentTreeVersion::new(version_id)}fn allocate_node(&mut self,children:[NodePtr;2],value:M::T)->NonNull>{self.allocator.allocate(Node::new(children,value))}fn build_dfs(&mut self,start:usize,end:usize,values:&[M::T])->NodePtr{if end-start==1{return self.leaf_node(values[start].clone());}let mid=(start+end)/2;let left=self.build_dfs(start,mid,values);let right=self.build_dfs(mid,end,values);self.merge_nodes(left,right)}fn leaf_node(&mut self,value:M::T)->NodePtr{Some(self.allocate_node([None,None],value))}fn merge_nodes(&mut self,left:NodePtr,right:NodePtr)->NodePtr{if left.is_none()&&right.is_none(){None}else{let value=M::operate(&Self::subtree_value(left),&Self::subtree_value(right));Some(self.allocate_node([left,right],value))}}fn subtree_value(node:NodePtr)->M::T{node.map(|node|unsafe{node.as_ref().value.clone()}).unwrap_or_else(M::unit)}fn children(node:NodePtr)->[NodePtr;2]{node.map(|node|unsafe{node.as_ref().children}).unwrap_or([None,None])}fn point_get_dfs(node:NodePtr,start:usize,end:usize,index:usize)->M::T{let Some(node)=node else{return M::unit();};let node=unsafe{node.as_ref()};if end-start==1{node.value.clone()}else{let mid=(start+end)/2;if index,start:usize,end:usize,range:&Range)->M::T{if range.end<=start||end<=range.start{return M::unit();}let Some(node)=node else{return M::unit();};let node=unsafe{node.as_ref()};if range.start<=start&&end<=range.end{node.value.clone()}else{let mid=(start+end)/2;if range.end<=mid{return Self::fold_dfs(node.children[0],start,mid,range);}if mid<=range.start{return Self::fold_dfs(node.children[1],mid,end,range);}let left=Self::fold_dfs(node.children[0],start,mid,range);let right=Self::fold_dfs(node.children[1],mid,end,range);M::operate(&left,&right)}}fn partition_point_dfs

(node:NodePtr,start:usize,end:usize,left:usize,acc:&mut M::T,pred:&mut P)->Optionwhere P:FnMut(&M::T)->bool{if end<=left{return None;}if left<=start{let nacc=M::operate(acc,&Self::subtree_value(node));if pred(&nacc){*acc=nacc;return None;}if end-start==1{return Some(start);}}let mid=(start+end)/2;let[l,r]=Self::children(node);if let Some(pos)=Self::partition_point_dfs(l,start,mid,left,acc,pred){Some(pos)}else{Self::partition_point_dfs(r,mid,end,left,acc,pred)}}fn rpartition_point_dfs

(node:NodePtr,start:usize,end:usize,right:usize,acc:&mut M::T,pred:&mut P)->Optionwhere P:FnMut(&M::T)->bool{if right<=start{return None;}if end<=right{let nacc=M::operate(&Self::subtree_value(node),acc);if pred(&nacc){*acc=nacc;return None;}if end-start==1{return Some(end);}}let mid=(start+end)/2;let[l,r]=Self::children(node);if let Some(pos)=Self::rpartition_point_dfs(r,mid,end,right,acc,pred){Some(pos)}else{Self::rpartition_point_dfs(l,start,mid,right,acc,pred)}}fn set_dfs(&mut self,node:NodePtr,start:usize,end:usize,index:usize,value:&M::T)->NodePtr{if end-start==1{return self.leaf_node(value.clone());}let mid=(start+end)/2;let mut children=Self::children(node);if index,start:usize,end:usize,index:usize,value:&M::T)->NodePtr{if end-start==1{return self.leaf_node(M::operate(&Self::subtree_value(node),value));}let mid=(start+end)/2;let mut children=Self::children(node);if index)->PersistentSegmentTreeVersion{assert_eq!(v.len(),self.len);let root=if self.len==0{None}else{self.build_dfs(0,self.len,&v)};self.push_version_root(root)}pub fn set(&mut self,version:PersistentSegmentTreeVersion,index:usize,value:M::T)->PersistentSegmentTreeVersion{assert!(indexPersistentSegmentTreeVersion{assert!(indexM::T{assert!(index(&self,version:PersistentSegmentTreeVersion,range:R)->M::T where R:RangeBounds{let range=range.to_range_bounded(0,self.len).expect("invalid range");if range.is_empty(){M::unit()}else{Self::fold_dfs(self.version_root(version),0,self.len,&range)}}pub fn partition_point_acc

(&self,version:PersistentSegmentTreeVersion,left:usize,mut pred:P)->(usize,M::T)where P:FnMut(&M::T)->bool{let root=self.version_root(version);let mut acc=M::unit();let pos=if self.len==0{None}else{Self::partition_point_dfs(root,0,self.len,left,&mut acc,&mut pred)};(pos.unwrap_or(self.len),acc)}pub fn rpartition_point_acc

(&self,version:PersistentSegmentTreeVersion,right:usize,mut pred:P)->(usize,M::T)where P:FnMut(&M::T)->bool{let root=self.version_root(version);let mut acc=M::unit();let pos=if self.len==0{None}else{Self::rpartition_point_dfs(root,0,self.len,right,&mut acc,&mut pred)};(pos.unwrap_or(0),acc)}#[must_use]pub fn fold_all(&self,version:PersistentSegmentTreeVersion)->M::T{Self::subtree_value(self.version_root(version))}}} // codesnip-guard: Allocator #[cfg_attr(any(),rustfmt::skip)]pub use self::allocator::{Allocator,BoxAllocator,MemoryPool};#[cfg_attr(any(),rustfmt::skip)]mod allocator{use std::{fmt::{self,Debug},marker::PhantomData,mem::{replace,size_of,take},ptr::{self,NonNull,read,write}};#[doc=" # Safety"]#[doc=" Allocations must contain the supplied value and remain valid until deallocation"]#[doc=" or allocator destruction. Live nonzero-sized allocations must not overlap."]pub unsafe trait Allocator{fn allocate(&mut self,value:T)->NonNull;#[doc=" # Safety"]#[doc=" `ptr` must hold a live value allocated by this allocator, with no remaining"]#[doc=" references. The allocation must not be accessed after this call."]unsafe fn deallocate(&mut self,ptr:NonNull)->T;}pub struct MemoryPool{pool:Vec,chunks:Vec>,unused:Vec>}implDebug for MemoryPool{fn fmt(&self,f:&mut fmt::Formatter<'_>)->fmt::Result{f.debug_struct("MemoryPool").field("pool_len",&self.pool.len()).field("chunks",&self.chunks.len()).field("unused",&self.unused.len()).finish()}}implDefault for MemoryPool{fn default()->Self{Self::with_capacity(CAP/1usize.max(size_of::()))}}const CAP:usize=1024;implMemoryPool{pub fn new()->Self{Default::default()}pub fn with_capacity(capacity:usize)->Self{let pool=Vec::with_capacity(capacity.max(1));Self{pool,chunks:Vec::new(),unused:Vec::new()}}}implDrop for MemoryPool{fn drop(&mut self){if size_of::()==0{let mut unused=self.unused.len();for chunk in std::iter::once(&mut self.pool).chain(&mut self.chunks){let removed=unused.min(chunk.len());unsafe{chunk.set_len(chunk.len()-removed)};unused-=removed;}return;}self.chunks.push(take(&mut self.pool));let mut removed=vec![vec![];self.chunks.len()];for p in self.unused.iter(){let p=p.as_ptr();for(chunk,removed)in self.chunks.iter().zip(&mut removed).rev(){let ptr=chunk.as_ptr()as*mut _;let len=chunk.len();if ptr<=p&&pAllocatorfor MemoryPool{fn allocate(&mut self,value:T)->NonNull{if let Some(ptr)=self.unused.pop(){unsafe{write(ptr.as_ptr(),value)};ptr}else{let len=self.pool.len();if len>=self.pool.capacity(){let new_capacity=self.pool.capacity()*2;let new_pool=Vec::with_capacity(new_capacity);self.chunks.push(replace(&mut self.pool,new_pool));}let len=self.pool.len();debug_assert!(len)->T{self.unused.push(ptr);unsafe{read(ptr.as_ptr())}}}#[derive(Debug)]pub struct BoxAllocator(PhantomDataT>);implDefault for BoxAllocator{fn default()->Self{Self(PhantomData)}}unsafe implAllocatorfor BoxAllocator{fn allocate(&mut self,value:T)->NonNull{unsafe{NonNull::new_unchecked(Box::leak(Box::new(value)))}}unsafe fn deallocate(&mut self,ptr:NonNull)->T{unsafe{*Box::from_raw(ptr.as_ptr())}}}} // codesnip-guard: algebra #[cfg_attr(any(),rustfmt::skip)]pub use self::magma::*;#[cfg_attr(any(),rustfmt::skip)]mod magma{#![doc=" algebraic traits"]#[doc=" binary operaion: $T \\circ T \\to T$"]pub trait Magma{#[doc=" type of operands: $T$"]type T:Clone;#[doc=" binary operaion: $\\circ$"]fn operate(x:&Self::T,y:&Self::T)->Self::T;fn reverse_operate(x:&Self::T,y:&Self::T)->Self::T{Self::operate(y,x)}fn operate_assign(x:&mut Self::T,y:&Self::T){*x=Self::operate(x,y);}}#[doc=" $\\forall a,\\forall b,\\forall c \\in T, (a \\circ b) \\circ c = a \\circ (b \\circ c)$"]pub trait Associative:Magma{}#[doc=" associative binary operation"]pub trait SemiGroup:Magma+Associative{}implSemiGroup for S where S:Magma+Associative{}#[doc=" $\\exists e \\in T, \\forall a \\in T, e \\circ a = a \\circ e = a$"]pub trait Unital:Magma{#[doc=" identity element: $e$"]fn unit()->Self::T;fn is_unit(x:&Self::T)->bool where Self::T:PartialEq{x==&Self::unit()}fn set_unit(x:&mut Self::T){*x=Self::unit();}}pub trait ExpBits{type Iter:Iterator;fn bits(self)->Self::Iter;}pub trait SignedExpBits{type T:ExpBits;fn neg_and_bits(self)->(bool,Self::T);}pub struct Bits{n:T}macro_rules!impl_exp_bits_for_uint{($($t:ty)*)=>{$(impl Iterator for Bits<$t>{type Item=bool;fn next(&mut self)->Option{if self.n==0{None}else{let bit=(self.n&1)==1;self.n>>=1;Some(bit)}}}impl ExpBits for$t{type Iter=Bits<$t>;fn bits(self)->Self::Iter{Bits{n:self}}}impl SignedExpBits for$t{type T=$t;fn neg_and_bits(self)->(bool,Self::T){(false,self)}})*};}impl_exp_bits_for_uint!(u8 u16 u32 u64 u128 usize);macro_rules!impl_signed_exp_bits_for_sint{($($s:ty,$u:ty;)*)=>{$(impl SignedExpBits for$s{type T=$u;fn neg_and_bits(self)->(bool,Self::T){(self<0,self.unsigned_abs())}})*};}impl_signed_exp_bits_for_sint!(i8,u8;i16,u16;i32,u32;i64,u64;i128,u128;isize,usize;);#[doc=" associative binary operation and an identity element"]pub trait Monoid:SemiGroup+Unital{#[doc=" binary exponentiation: $x^n = x\\circ\\ddots\\circ x$"]fn pow(mut x:Self::T,exp:E)->Self::T where E:ExpBits{let mut bits=exp.bits();let Some(first)=bits.next()else{return Self::unit();};let mut res=if first{x.clone()}else{Self::unit()};for bit in bits{x=Self::operate(&x,&x);if bit{res=Self::operate(&res,&x);}}res}fn fold(iter:I)->Self::T where I:IntoIterator{let mut iter=iter.into_iter();if let Some(item)=iter.next(){iter.fold(item,|acc,x|Self::operate(&acc,&x))}else{Self::unit()}}}implMonoid for M where M:SemiGroup+Unital{}#[doc=" $\\exists e \\in T, \\forall a \\in T, \\exists b,c \\in T, b \\circ a = a \\circ c = e$"]pub trait Invertible:Magma+Unital{#[doc=" $a$ where $a \\circ x = e$"]fn inverse(x:&Self::T)->Self::T;fn rinv_operate(x:&Self::T,y:&Self::T)->Self::T{Self::operate(x,&Self::inverse(y))}fn rinv_operate_assign(x:&mut Self::T,y:&Self::T){*x=Self::rinv_operate(x,y);}}#[doc=" associative binary operation and an identity element and inverse elements"]pub trait Group:Monoid+Invertible{fn signed_pow(x:Self::T,exp:E)->Self::T where E:SignedExpBits{let(neg,exp)=E::neg_and_bits(exp);let res=Self::pow(x,exp);if neg{Self::inverse(&res)}else{res}}}implGroup for G where G:Monoid+Invertible{}#[doc=" $\\forall a,\\forall b \\in T, a \\circ b = b \\circ a$"]pub trait Commutative:Magma{}#[doc=" commutative monoid"]pub trait AbelianMonoid:Monoid+Commutative{}implAbelianMonoid for M where M:Monoid+Commutative{}#[doc=" commutative group"]pub trait AbelianGroup:Group+Commutative{}implAbelianGroup for G where G:Group+Commutative{}#[doc=" $\\forall a \\in T, a \\circ a = a$"]pub trait Idempotent:Magma{}#[doc=" idempotent monoid"]pub trait IdempotentMonoid:Monoid+Idempotent{}implIdempotentMonoid for M where M:Monoid+Idempotent{}#[macro_export]macro_rules!monoid_fold{($m:ty)=>{<$m as Unital>::unit()};($m:ty,)=>{<$m as Unital>::unit()};($m:ty,$f:expr)=>{$f};($m:ty,$f:expr,$($ff:expr),*)=>{<$m as Magma>::operate(&($f),&monoid_fold!($m,$($ff),*))};}#[macro_export]macro_rules!define_monoid{($Name:ident,$t:ty,|$x:ident,$y:ident|$op:expr,$unit:expr)=>{struct$Name;impl Magma for$Name{type T=$t;fn operate($x:&Self::T,$y:&Self::T)->Self::T{$op}}impl Unital for$Name{fn unit()->Self::T{$unit}}impl Associative for$Name{}};}} // codesnip-guard: bounded #[cfg_attr(any(),rustfmt::skip)]pub use self::bounded::Bounded;#[cfg_attr(any(),rustfmt::skip)]mod bounded{#[doc=" Trait for max/min bounds"]pub trait Bounded:Sized+PartialOrd{fn maximum()->Self;fn minimum()->Self;fn is_maximum(&self)->bool{self==&Self::maximum()}fn is_minimum(&self)->bool{self==&Self::minimum()}fn set_maximum(&mut self){*self=Self::maximum()}fn set_minimum(&mut self){*self=Self::minimum()}}macro_rules!impl_bounded_num{($($t:ident)*)=>{$(impl Bounded for$t{fn maximum()->Self{$t::MAX}fn minimum()->Self{$t::MIN}})*};}impl_bounded_num!(u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize f32 f64);macro_rules!impl_bounded_tuple{(@impl$($T:ident)*)=>{impl<$($T:Bounded),*>Bounded for($($T,)*){fn maximum()->Self{($(<$T as Bounded>::maximum(),)*)}fn minimum()->Self{($(<$T as Bounded>::minimum(),)*)}}};(@inner$($T:ident)*,)=>{impl_bounded_tuple!(@impl$($T)*);};(@inner$($T:ident)*,$U:ident$($Rest:ident)*)=>{impl_bounded_tuple!(@impl$($T)*);impl_bounded_tuple!(@inner$($T)*$U,$($Rest)*);};($T:ident$($Rest:ident)*)=>{impl_bounded_tuple!(@inner$T,$($Rest)*);};}impl_bounded_tuple!(A B C D E F G H I J);impl Bounded for(){fn maximum()->Self{}fn minimum()->Self{}}impl Bounded for bool{fn maximum()->Self{true}fn minimum()->Self{false}}implBounded for Optionwhere T:Bounded{fn maximum()->Self{Some(::maximum())}fn minimum()->Self{None}}implBounded for std::cmp::Reversewhere T:Bounded{fn maximum()->Self{std::cmp::Reverse(::minimum())}fn minimum()->Self{std::cmp::Reverse(::maximum())}}} // codesnip-guard: discrete_steps #[cfg_attr(any(),rustfmt::skip)]pub use self::discrete_steps::{DiscreteSteps,RangeBoundsExt};#[cfg_attr(any(),rustfmt::skip)]mod discrete_steps{use super::Bounded;use std::{convert::TryFrom,ops::{Bound,Range,RangeBounds,RangeInclusive}};pub trait DiscreteSteps:Clone{fn delta()->Delta;fn steps_between(start:&Self,end:&Self)->Option;fn forward_checked(start:Self,delta:Delta)->Option;fn backward_checked(start:Self,delta:Delta)->Option;fn forward(start:Self,delta:Delta)->Self{Self::forward_checked(start,delta).expect("overflow in `DiscreteSteps::forward`")}fn backward(start:Self,delta:Delta)->Self{Self::backward_checked(start,delta).expect("overflow in `DiscreteSteps::backward`")}fn forward_delta_checked(start:Self)->Option{Self::forward_checked(start,Self::delta())}fn backward_delta_checked(start:Self)->Option{Self::backward_checked(start,Self::delta())}fn forward_delta(start:Self)->Self{Self::forward(start,Self::delta())}fn backward_delta(start:Self)->Self{Self::backward(start,Self::delta())}}macro_rules!impl_discrete_steps_integer{(@common$u_source:ident)=>{fn delta()->$u_source{1}fn forward(start:Self,delta:$u_source)->Self{assert!(Self::forward_checked(start,delta).is_some(),"attempt to add with overflow");start.wrapping_add(delta as Self)}fn backward(start:Self,delta:$u_source)->Self{assert!(Self::backward_checked(start,delta).is_some(),"attempt to subtract with overflow");start.wrapping_sub(delta as Self)}};($u_source:ident$i_source:ident;$($u_narrower:ident$i_narrower:ident),*;$($u_wider:ident$i_wider:ident),*)=>{$(impl DiscreteSteps<$u_source>for$u_narrower{impl_discrete_steps_integer!(@common$u_source);fn steps_between(start:&Self,end:&Self)->Option<$u_source>{if*start<=*end{$u_source::try_from(*end-*start).ok()}else{None}}fn forward_checked(start:Self,delta:$u_source)->Option{Self::try_from(delta).ok().and_then(|delta|start.checked_add(delta))}fn backward_checked(start:Self,delta:$u_source)->Option{Self::try_from(delta).ok().and_then(|delta|start.checked_sub(delta))}}impl DiscreteSteps<$u_source>for$i_narrower{impl_discrete_steps_integer!(@common$u_source);fn steps_between(start:&Self,end:&Self)->Option<$u_source>{if*start<=*end{$u_source::try_from(end.abs_diff(*start)).ok()}else{None}}fn forward_checked(start:Self,delta:$u_source)->Option{$u_narrower::try_from(delta).ok().and_then(|delta|{let wrapped=start.wrapping_add(delta as Self);if wrapped>=start{Some(wrapped)}else{None}})}fn backward_checked(start:Self,delta:$u_source)->Option{$u_narrower::try_from(delta).ok().and_then(|delta|{let wrapped=start.wrapping_sub(delta as Self);if wrapped<=start{Some(wrapped)}else{None}})}})*$(impl DiscreteSteps<$u_source>for$u_wider{impl_discrete_steps_integer!(@common$u_source);fn steps_between(start:&Self,end:&Self)->Option<$u_source>{if*start<=*end{$u_source::try_from(*end-*start).ok()}else{None}}fn forward_checked(start:Self,delta:$u_source)->Option{start.checked_add(delta as Self)}fn backward_checked(start:Self,delta:$u_source)->Option{start.checked_sub(delta as Self)}}impl DiscreteSteps<$u_source>for$i_wider{impl_discrete_steps_integer!(@common$u_source);fn steps_between(start:&Self,end:&Self)->Option<$u_source>{if*start<=*end{end.checked_sub(*start).and_then(|result|$u_source::try_from(result).ok())}else{None}}fn forward_checked(start:Self,delta:$u_source)->Option{start.checked_add(delta as Self)}fn backward_checked(start:Self,delta:$u_source)->Option{start.checked_sub(delta as Self)}})*};}impl_discrete_steps_integer!(u16 i16;u8 i8,u16 i16,usize isize;u32 i32,u64 i64,u128 i128);impl_discrete_steps_integer!(u32 i32;u8 i8,u16 i16,u32 i32,usize isize;u64 i64,u128 i128);impl_discrete_steps_integer!(u64 i64;u8 i8,u16 i16,u32 i32,u64 i64,usize isize;u128 i128);impl_discrete_steps_integer!(u128 i128;u8 i8,u16 i16,u32 i32,u64 i64,u128 i128,usize isize;);impl_discrete_steps_integer!(usize isize;u8 i8,u16 i16,u32 i32,u64 i64,usize isize;u128 i128);pub trait RangeBoundsExt{fn start_bound_included_checked(&self)->Option;fn start_bound_excluded_checked(&self)->Option;fn end_bound_included_checked(&self)->Option;fn end_bound_excluded_checked(&self)->Option;fn start_bound_included(&self)->T;fn start_bound_excluded(&self)->T;fn end_bound_included(&self)->T;fn end_bound_excluded(&self)->T;fn start_bound_included_bounded(&self,lb:T)->Optionwhere T:Ord;fn start_bound_excluded_bounded(&self,lb:T)->Optionwhere T:Ord;fn end_bound_included_bounded(&self,ub:T)->Optionwhere T:Ord;fn end_bound_excluded_bounded(&self,ub:T)->Optionwhere T:Ord;fn to_range_checked(&self)->Option>{match(self.start_bound_included_checked(),self.end_bound_excluded_checked()){(Some(start),Some(end))=>Some(start..end),_=>None,}}fn to_range(&self)->Range{self.start_bound_included()..self.end_bound_excluded()}fn to_range_bounded(&self,min:T,max:T)->Option>where T:Ord{Some(self.start_bound_included_bounded(min)?..self.end_bound_excluded_bounded(max)?)}fn to_range_inclusive_checked(&self)->Option>{match(self.start_bound_included_checked(),self.end_bound_included_checked()){(Some(start),Some(end))=>Some(start..=end),_=>None,}}fn to_range_inclusive(&self)->RangeInclusive{self.start_bound_included()..=self.end_bound_included()}fn to_range_inclusive_bounded(&self,min:T,max:T)->Option>where T:Ord{Some(self.start_bound_included_bounded(min)?..=self.end_bound_included_bounded(max)?)}}macro_rules!impl_range_bounds_ext{($($source:ident=>$($target:ident)+);*$(;)?)=>{$($(implRangeBoundsExt<$target>for R where R:RangeBounds<$target>,{fn start_bound_included_checked(&self)->Option<$target>{match self.start_bound(){Bound::Included(x)=>Some(*x),Bound::Excluded(x)=>DiscreteSteps::<$source>::forward_delta_checked(*x),Bound::Unbounded=>Some(Bounded::minimum()),}}fn start_bound_excluded_checked(&self)->Option<$target>{match self.start_bound(){Bound::Included(x)=>DiscreteSteps::<$source>::backward_delta_checked(*x),Bound::Excluded(x)=>Some(*x),Bound::Unbounded=>None,}}fn end_bound_included_checked(&self)->Option<$target>{match self.end_bound(){Bound::Included(x)=>Some(*x),Bound::Excluded(x)=>DiscreteSteps::<$source>::backward_delta_checked(*x),Bound::Unbounded=>Some(Bounded::maximum()),}}fn end_bound_excluded_checked(&self)->Option<$target>{match self.end_bound(){Bound::Included(x)=>DiscreteSteps::<$source>::forward_delta_checked(*x),Bound::Excluded(x)=>Some(*x),Bound::Unbounded=>None,}}fn start_bound_included(&self)->$target{match self.start_bound(){Bound::Included(x)=>*x,Bound::Excluded(x)=>DiscreteSteps::<$source>::forward_delta(*x),Bound::Unbounded=>Bounded::minimum(),}}fn start_bound_excluded(&self)->$target{match self.start_bound(){Bound::Included(x)=>DiscreteSteps::<$source>::backward_delta(*x),Bound::Excluded(x)=>*x,Bound::Unbounded=>DiscreteSteps::<$source>::backward_delta(Bounded::minimum()),}}fn end_bound_included(&self)->$target{match self.end_bound(){Bound::Included(x)=>*x,Bound::Excluded(x)=>DiscreteSteps::<$source>::backward_delta(*x),Bound::Unbounded=>Bounded::maximum(),}}fn end_bound_excluded(&self)->$target{match self.end_bound(){Bound::Included(x)=>DiscreteSteps::<$source>::forward_delta(*x),Bound::Excluded(x)=>*x,Bound::Unbounded=>DiscreteSteps::<$source>::forward_delta(Bounded::maximum()),}}fn start_bound_included_bounded(&self,lb:$target)->Option<$target>where$target:Ord{match self.start_bound(){Bound::Included(x)=>Some(*x).filter(|&x|lb<=x),Bound::Excluded(x)=>DiscreteSteps::<$source>::forward_delta_checked(*x).filter(|&x|lb<=x),Bound::Unbounded=>Some(lb),}}fn start_bound_excluded_bounded(&self,lb:$target)->Option<$target>where$target:Ord{match self.start_bound(){Bound::Included(x)=>DiscreteSteps::<$source>::backward_delta_checked(*x).filter(|&x|lb<=x),Bound::Excluded(x)=>Some(*x).filter(|&x|lb<=x),Bound::Unbounded=>Some(lb),}}fn end_bound_included_bounded(&self,ub:$target)->Option<$target>where$target:Ord{match self.end_bound(){Bound::Included(x)=>Some(*x).filter(|&x|x<=ub),Bound::Excluded(x)=>DiscreteSteps::<$source>::backward_delta_checked(*x).filter(|&x|x<=ub),Bound::Unbounded=>Some(ub),}}fn end_bound_excluded_bounded(&self,ub:$target)->Option<$target>where$target:Ord{match self.end_bound(){Bound::Included(x)=>DiscreteSteps::<$source>::forward_delta_checked(*x).filter(|&x|x<=ub),Bound::Excluded(x)=>Some(*x).filter(|&x|x<=ub),Bound::Unbounded=>Some(ub),}}})+)*};}impl_range_bounds_ext!(u16=>u8 i8 u16 i16;u32=>u32 i32;u64=>u64 i64;u128=>u128 i128;usize=>isize usize;);}