Problem:
Score : 600 points

Problem Statement

Given are a sequence of N positive integers A_1, A_2, \ldots, A_N and another positive integer S.

For a non-empty subset T of the set \{1, 2, \ldots , N \}, let us define f(T) as follows:

f(T) is the number of different non-empty subsets \{x_1, x_2, \ldots , x_k \} of T such that A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S.

Find the sum of f(T) over all 2^N-1 subsets T of \{1, 2, \ldots , N \}. Since the sum can be enormous, print it modulo 998244353.

Constraints

All values in input are integers.

1 \leq N \leq 3000

1 \leq S \leq 3000

1 \leq A_i \leq 3000

Input

Input is given from Standard Input in the following format:

N S
A_1 A_2 ... A_N

Output

Print the sum of f(T) modulo 998244353.

Sample Input 1

3 4
2 2 4

Sample Output 1

6

For each T, the value of f(T) is shown below. The sum of these values is 6.

f(\{1\}) = 0

f(\{2\}) = 0

f(\{3\}) = 1 (One subset \{3\} satisfies the condition.)

f(\{1, 2\}) = 1 (\{1, 2\})

f(\{2, 3\}) = 1 (\{3\})

f(\{1, 3\}) = 1 (\{3\})

f(\{1, 2, 3\}) = 2 (\{1, 2\}, \{3\})

Sample Input 2

5 8
9 9 9 9 9

Sample Output 2

0

Sample Input 3

10 10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

3296

Solution in Rust (1.42.0) (judge verdict: Accepted)

#![allow(dead_code)]
use crate::arraylist::List;
use crate::modulo::*;
use crate::scanner::Scanner;
modint!(998244353);
fn main() {
    let mut scan = Scanner::new();
    let n = scan.read::<i32>();
    let s = scan.read::<i32>();
    let a = scan.readn::<i32>(n);
    let mut dp = list ! ( Z :: new ( 0 ) ; s + 1 );
    dp[0] = Z::new(1);
    for i in 0..n {
        let mut tmp = list ! [ Z :: new ( 0 ) ; s + 1 ];
        std::mem::swap(&mut tmp, &mut dp);
        for j in 0..=s {
            dp[j] += tmp[j] * 2.into();
            assign!(dp[j + a[i]] += tmp[j]);
        }
    }
    println!("{}", dp[s]);
}
mod macros {
    #[macro_export]
    macro_rules ! for_ { ( $ init : stmt ; $ cond : expr ; $ incr : expr , $ body : block ) => { $ init while $ cond { $ body $ incr ; } } ; }
    #[macro_export]
    macro_rules ! vecs { ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vecs ! ( $ ( $ dim ) ;* => $ init ) } ; ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vecs ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] } ; ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] } ; }
    #[macro_export]
    macro_rules! chmax {
        ( $ x : expr , $ y : expr ) => {
            if $x < $y {
                $x = $y;
                true
            } else {
                false
            }
        };
    }
    #[macro_export]
    macro_rules! chmin {
        ( $ x : expr , $ y : expr ) => {
            if $x > $y {
                $x = $y;
                true
            } else {
                false
            }
        };
    }
    #[macro_export]
    macro_rules ! min { ( $ a : expr $ ( , ) * ) => { { $ a } } ; ( $ a : expr , $ b : expr $ ( , ) * ) => { { std :: cmp :: min ( $ a , $ b ) } } ; ( $ a : expr , $ ( $ rest : expr ) ,+ $ ( , ) * ) => { { std :: cmp :: min ( $ a , min ! ( $ ( $ rest ) ,+ ) ) } } ; }
    #[macro_export]
    macro_rules ! max { ( $ a : expr $ ( , ) * ) => { { $ a } } ; ( $ a : expr , $ b : expr $ ( , ) * ) => { { std :: cmp :: max ( $ a , $ b ) } } ; ( $ a : expr , $ ( $ rest : expr ) ,+ $ ( , ) * ) => { { std :: cmp :: max ( $ a , max ! ( $ ( $ rest ) ,+ ) ) } } ; }
    #[macro_export]
    macro_rules ! assign { ( $ arr : ident $ ( [ $ a : expr ] ) + = $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , = , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + += $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , += , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + -= $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , -= , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + |= $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , |= , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + &= $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , &= , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + ^= $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , ^= , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + min $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , ^= , $ right , min ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + max $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , ^= , $ right , max ) ; } ; ( $ arr : expr , [ $ head : expr ] , $ op : tt , $ right : expr , default ) => { let head = $ head ; if ( 0 ..$ arr . ilen ( ) ) . contains ( &$ head ) { let tmp = $ right ; $ arr [ head ] $ op tmp ; } } ; ( $ arr : expr , [ $ head : expr ] , $ op : tt , $ right : expr , min ) => { let head = $ head ; if ( 0 ..$ arr . ilen ( ) ) . contains ( &$ head ) { let tmp = $ right ; $ arr [ head ] = std :: cmp :: min ( $ arr [ head ] , tmp ) ; } } ; ( $ arr : expr , [ $ head : expr ] , $ op : tt , $ right : expr , max ) => { let head = $ head ; if ( 0 ..$ arr . ilen ( ) ) . contains ( &$ head ) { let tmp = $ right ; $ arr [ head ] = std :: cmp :: max ( $ arr [ head ] , tmp ) ; } } ; ( $ arr : expr , [ $ head : expr ] $ ( [ $ a : expr ] ) +, $ op : tt , $ right : expr , $ kind : ident ) => { let head = $ head ; if ( 0 ..$ arr . ilen ( ) ) . contains ( &$ head ) { assign ! ( $ arr [ head ] , $ ( [ $ a ] ) +, $ op , $ right , $ kind ) ; } } ; }
    #[macro_export]
    macro_rules! unwrap {
        ( $ arg : expr ) => {{
            let tmp = $arg;
            if tmp.is_none() {
                return;
            }
            tmp.unwrap()
        }};
    }
    #[macro_export]
    macro_rules! swap {
        ( $ a : expr , $ b : expr ) => {
            let tmp = $a;
            $a = $b;
            $b = tmp;
        };
    }
}
mod modulo {
    use crate::integer::Int;
    use std::marker::PhantomData;
    use std::ops::*;
    #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)]
    pub struct ModInt<T>(pub i64, PhantomData<*const T>);
    impl<T: ConstValue> ModInt<T> {
        pub fn new<U: Int>(a: U) -> ModInt<T> {
            let x = a.to_i64();
            if x < 0 {
                ModInt::raw(x % T::M + T::M)
            } else if x < T::M {
                ModInt::raw(x)
            } else {
                ModInt::raw(x % T::M)
            }
        }
        pub fn pow(self, mut n: i64) -> Self {
            let mut a = self;
            let mut res = Self::raw(1);
            while n > 0 {
                if n & 1 == 1 {
                    res *= a;
                }
                a = a * a;
                n >>= 1;
            }
            res
        }
        pub fn inv(self) -> Self {
            self.pow(T::M - 2)
        }
        #[inline]
        fn raw(x: i64) -> ModInt<T> {
            ModInt(x, PhantomData)
        }
    }
    pub trait ConstValue: PartialEq + Eq + Copy + Clone + std::hash::Hash + Ord {
        const M: i64;
    }
    impl<T> std::fmt::Display for ModInt<T> {
        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
            write!(f, "{}", self.0)
        }
    }
    macro_rules ! impl_from_for_modint { ( $ ( $ tpe : ident ) ,* ) => { $ ( impl < T : ConstValue > From <$ tpe > for ModInt < T > { fn from ( n : $ tpe ) -> Self { Self :: new ( n ) } } ) * } ; }
    impl_from_for_modint!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize);
    impl<T: ConstValue> Add for ModInt<T> {
        type Output = ModInt<T>;
        fn add(self, other: ModInt<T>) -> ModInt<T> {
            let mut ret = self.0 + other.0;
            if ret >= T::M {
                ret -= T::M;
            }
            Self::raw(ret)
        }
    }
    impl<T: ConstValue> AddAssign for ModInt<T> {
        fn add_assign(&mut self, other: Self) {
            *self = self.add(other);
        }
    }
    impl<T: ConstValue> Sub for ModInt<T> {
        type Output = ModInt<T>;
        fn sub(self, other: ModInt<T>) -> ModInt<T> {
            let mut ret = self.0 + T::M - other.0;
            if ret >= T::M {
                ret -= T::M
            }
            Self::raw(ret)
        }
    }
    impl<T: ConstValue> SubAssign for ModInt<T> {
        fn sub_assign(&mut self, other: Self) {
            *self = self.sub(other);
        }
    }
    impl<T: ConstValue> Mul for ModInt<T> {
        type Output = ModInt<T>;
        fn mul(self, other: ModInt<T>) -> ModInt<T> {
            Self::raw(self.0 * other.0 % T::M)
        }
    }
    impl<T: ConstValue> MulAssign for ModInt<T> {
        fn mul_assign(&mut self, other: Self) {
            *self = self.mul(other);
        }
    }
    impl<T: ConstValue> Div for ModInt<T> {
        type Output = ModInt<T>;
        fn div(self, other: ModInt<T>) -> ModInt<T> {
            self * other.inv()
        }
    }
    impl<T: ConstValue> DivAssign for ModInt<T> {
        fn div_assign(&mut self, other: Self) {
            *self = self.div(other);
        }
    }
    impl<T: ConstValue> Rem for ModInt<T> {
        type Output = ModInt<T>;
        fn rem(self, other: ModInt<T>) -> ModInt<T> {
            Self::raw(self.0 % other.0)
        }
    }
    #[macro_export]
    macro_rules! modint {
        ( $ m : expr ) => {
            #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)]
            pub enum __M {}
            impl ConstValue for __M {
                const M: i64 = $m;
            }
            #[allow(dead_code)]
            type Z = ModInt<__M>;
        };
    }
    macro_rules ! impl_integer_functions { ( $ ( $ name : ident , $ tpe : ident ) ,* ) => { $ ( fn $ name ( & self ) -> $ tpe { self . 0 as $ tpe } ) * } ; }
    impl<T: ConstValue> Int for ModInt<T> {
        impl_integer_functions!(
            to_u8, u8, to_u16, u16, to_u32, u32, to_u64, u64, to_u128, u128, to_i8, i8, to_i16,
            i16, to_i32, i32, to_i64, i64, to_i128, i128, to_usize, usize, to_isize, isize
        );
        fn zero() -> Self {
            Self::new(0)
        }
        fn one() -> Self {
            Self::new(1)
        }
    }
}
mod arraylist {
    use crate::range::IntRangeBounds;
    use std::fmt::Formatter;
    use std::iter::{FromIterator, Sum};
    use std::ops::{Index, IndexMut, RangeBounds};
    use std::slice::Iter;
    #[derive(Clone, PartialEq, Eq)]
    pub struct List<T> {
        pub vec: Vec<T>,
    }
    impl<T> List<T> {
        #[inline]
        pub fn new() -> List<T> {
            List { vec: vec![] }
        }
        #[inline]
        pub fn init(init: T, n: i32) -> List<T>
        where
            T: Clone,
        {
            List {
                vec: vec![init; n as usize],
            }
        }
        #[inline]
        pub fn from_vec(vec: Vec<T>) -> List<T> {
            List { vec }
        }
        #[inline]
        pub fn ilen(&self) -> i32 {
            self.vec.len() as i32
        }
        #[inline]
        pub fn iter(&self) -> Iter<'_, T> {
            self.vec.iter()
        }
        #[inline]
        pub fn push(&mut self, item: T) {
            self.vec.push(item);
        }
        #[inline]
        pub fn sort(&mut self)
        where
            T: Ord,
        {
            self.vec.sort();
        }
        #[inline]
        pub fn reverse(&mut self) {
            self.vec.reverse();
        }
        #[inline]
        pub fn sort_by<F>(&mut self, compare: F)
        where
            F: FnMut(&T, &T) -> std::cmp::Ordering,
        {
            self.vec.sort_by(compare)
        }
        #[inline]
        pub fn sort_by_key<K, F>(&mut self, compare: F)
        where
            F: FnMut(&T) -> K,
            K: Ord,
        {
            self.vec.sort_by_key(compare)
        }
        #[inline]
        pub fn first(&self) -> Option<&T> {
            self.vec.first()
        }
        #[inline]
        pub fn last(&self) -> Option<&T> {
            self.vec.last()
        }
        #[inline]
        pub fn pop(&mut self) -> Option<T> {
            self.vec.pop()
        }
        #[inline]
        pub fn swap(&mut self, i: i32, j: i32) {
            self.vec.swap(i as usize, j as usize);
        }
        #[inline]
        pub fn append(&mut self, mut other: Self) {
            self.vec.append(&mut other.vec);
        }
        #[inline]
        pub fn extend(&mut self, other: impl Iterator<Item = T>) {
            self.vec.extend(other);
        }
        #[inline]
        pub fn mirror(&self) -> std::iter::Cloned<Iter<T>>
        where
            T: Clone,
        {
            self.iter().cloned()
        }
        #[inline]
        pub fn map<B, F>(&self, f: F) -> List<B>
        where
            T: Clone,
            F: FnMut(T) -> B,
        {
            self.mirror().map(f).collect()
        }
        #[inline]
        pub fn filter<P>(&self, predicate: P) -> List<T>
        where
            T: Clone,
            P: FnMut(&T) -> bool,
        {
            self.mirror().filter(predicate).collect()
        }
        #[inline]
        pub fn filter_map<B, F>(&self, f: F) -> List<B>
        where
            T: Clone,
            F: FnMut(T) -> Option<B>,
        {
            self.mirror().filter_map(f).collect()
        }
        #[inline]
        pub fn any<P>(&self, predicate: P) -> bool
        where
            P: FnMut(&T) -> bool,
        {
            self.iter().any(predicate)
        }
        #[inline]
        pub fn all<P>(&self, predicate: P) -> bool
        where
            P: FnMut(&T) -> bool,
        {
            self.iter().all(predicate)
        }
        #[inline]
        pub fn sum<S>(&self) -> S
        where
            T: Clone,
            S: Sum<T>,
        {
            Sum::sum(self.iter().cloned())
        }
        #[inline]
        pub fn enumerate(&self) -> List<(i32, T)>
        where
            T: Clone,
        {
            self.mirror()
                .enumerate()
                .map(|p| (p.0 as i32, p.1))
                .collect()
        }
        #[inline]
        pub fn find<P>(&self, mut predicate: P) -> Option<&T>
        where
            P: FnMut(&T) -> bool,
        {
            self.iter().find(|x| predicate(*x))
        }
        #[inline]
        pub fn index_of<P>(&self, mut predicate: P) -> Option<i32>
        where
            P: FnMut(&T) -> bool,
        {
            self.iter()
                .enumerate()
                .find(|&(_i, x)| predicate(x))
                .map(|p| p.0 as i32)
        }
        #[inline]
        pub fn to<B: FromIterator<T>>(&self) -> B
        where
            T: Clone,
        {
            self.mirror().collect()
        }
        #[inline]
        pub fn min(&self) -> Option<&T>
        where
            T: Ord,
        {
            self.iter().min()
        }
        #[inline]
        pub fn max(&self) -> Option<&T>
        where
            T: Ord,
        {
            self.iter().max()
        }
        #[inline]
        pub fn argmin(&self) -> Option<i32>
        where
            T: Ord,
        {
            let item = self.iter().min()?;
            self.iter()
                .enumerate()
                .find(|p| p.1 == item)
                .map(|p| p.0 as i32)
        }
        #[inline]
        pub fn argmax(&self) -> Option<i32>
        where
            T: Ord,
        {
            let item = self.iter().max()?;
            self.iter()
                .enumerate()
                .find(|p| p.1 == item)
                .map(|p| p.0 as i32)
        }
        #[inline]
        pub fn part<U>(&self, range: U) -> List<T>
        where
            T: Clone,
            U: RangeBounds<i32>,
        {
            List::from_vec(
                self.vec[range.lower_bound(0) as usize..range.upper_bound(self.ilen()) as usize]
                    .to_vec(),
            )
        }
        #[inline]
        pub fn first_exn(&self) -> &T {
            self.first().unwrap()
        }
        #[inline]
        pub fn last_exn(&self) -> &T {
            self.last().unwrap()
        }
        #[inline]
        pub fn pop_exn(&mut self) -> T {
            self.pop().unwrap()
        }
        #[inline]
        pub fn min_exn(&self) -> &T
        where
            T: Ord,
        {
            self.min().unwrap()
        }
        #[inline]
        pub fn max_exn(&self) -> &T
        where
            T: Ord,
        {
            self.max().unwrap()
        }
        #[inline]
        pub fn argmin_exn(&self) -> i32
        where
            T: Ord,
        {
            self.argmin().unwrap()
        }
        #[inline]
        pub fn argmax_exn(&self) -> i32
        where
            T: Ord,
        {
            self.argmax().unwrap()
        }
        #[inline]
        pub fn find_exn<P>(&self, predicate: P) -> &T
        where
            P: FnMut(&T) -> bool,
        {
            self.find(predicate).unwrap()
        }
        #[inline]
        pub fn index_of_exn<P>(&self, predicate: P) -> i32
        where
            P: FnMut(&T) -> bool,
        {
            self.index_of(predicate).unwrap()
        }
    }
    impl<T> Index<i32> for List<T> {
        type Output = T;
        #[inline]
        fn index(&self, index: i32) -> &Self::Output {
            if cfg!(debug_assertions) {
                self.vec.index(index as usize)
            } else {
                unsafe { self.vec.get_unchecked(index as usize) }
            }
        }
    }
    impl<T> IndexMut<i32> for List<T> {
        #[inline]
        fn index_mut(&mut self, index: i32) -> &mut Self::Output {
            if cfg!(debug_assertions) {
                self.vec.index_mut(index as usize)
            } else {
                unsafe { self.vec.get_unchecked_mut(index as usize) }
            }
        }
    }
    impl<T> FromIterator<T> for List<T> {
        fn from_iter<U: IntoIterator<Item = T>>(iter: U) -> Self {
            let mut vec = vec![];
            for i in iter {
                vec.push(i);
            }
            List { vec }
        }
    }
    impl<T> IntoIterator for List<T> {
        type Item = T;
        type IntoIter = std::vec::IntoIter<T>;
        fn into_iter(self) -> std::vec::IntoIter<T> {
            self.vec.into_iter()
        }
    }
    impl<'a, T> IntoIterator for &'a List<T> {
        type Item = &'a T;
        type IntoIter = Iter<'a, T>;
        fn into_iter(self) -> Iter<'a, T> {
            self.vec.iter()
        }
    }
    impl<T: std::fmt::Display> std::fmt::Display for List<T> {
        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
            write!(
                f,
                "{}",
                self.iter()
                    .map(|x| format!("{}", x))
                    .collect::<Vec<_>>()
                    .join(" ")
            )
        }
    }
    impl<T: std::fmt::Debug> std::fmt::Debug for List<T> {
        fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
            write!(
                f,
                "[{}]",
                self.iter()
                    .map(|x| format!("{:?}", x))
                    .collect::<Vec<_>>()
                    .join(", ")
            )
        }
    }
    impl<T> From<Vec<T>> for List<T> {
        fn from(vec: Vec<T>) -> Self {
            Self::from_vec(vec)
        }
    }
    impl<T: Clone> From<&[T]> for List<T> {
        fn from(slice: &[T]) -> Self {
            slice.iter().cloned().collect()
        }
    }
    #[macro_export]
    macro_rules ! list { ( ) => { List :: new ( ) } ; ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { list ! ( $ ( $ dim ) ;* => $ init ) } ; ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { List :: init ( list ! ( $ ( $ tail ) ;* => $ init ) , $ head ) } ; ( $ head : expr => $ init : expr ) => { List :: init ( $ init , $ head ) } ; }
}
mod scanner {
    use crate::arraylist::List;
    use std::io::{stdin, BufReader, Bytes, Read, Stdin};
    use std::str::FromStr;
    pub struct Scanner {
        buf: Bytes<BufReader<Stdin>>,
    }
    impl Scanner {
        pub fn new() -> Scanner {
            Scanner {
                buf: BufReader::new(stdin()).bytes(),
            }
        }
        pub fn read_next<T: FromStr>(&mut self) -> Option<T> {
            let token = self
                .buf
                .by_ref()
                .map(|c| c.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect::<String>();
            token.parse::<T>().ok()
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_next().unwrap()
        }
        pub fn readn<T: FromStr>(&mut self, n: i32) -> List<T> {
            (0..n).map(|_| self.read::<T>()).collect()
        }
        pub fn chars(&mut self) -> List<char> {
            self.read::<String>().chars().collect()
        }
    }
}
mod integer {
    pub trait Int:
        std::ops::Add<Output = Self>
        + std::ops::Sub<Output = Self>
        + std::ops::Mul<Output = Self>
        + std::ops::Div<Output = Self>
        + std::ops::Rem<Output = Self>
        + std::hash::Hash
        + PartialEq
        + Eq
        + PartialOrd
        + Ord
        + Copy
    {
        fn to_u8(&self) -> u8;
        fn to_u16(&self) -> u16;
        fn to_u32(&self) -> u32;
        fn to_u64(&self) -> u64;
        fn to_u128(&self) -> u128;
        fn to_i8(&self) -> i8;
        fn to_i16(&self) -> i16;
        fn to_i32(&self) -> i32;
        fn to_i64(&self) -> i64;
        fn to_i128(&self) -> i128;
        fn to_usize(&self) -> usize;
        fn to_isize(&self) -> isize;
        fn zero() -> Self;
        fn one() -> Self;
    }
    macro_rules ! impl_integer_functions { ( $ ( $ name : ident , $ tpe : ident ) ,* ) => { $ ( fn $ name ( & self ) -> $ tpe { * self as $ tpe } ) * } ; }
    macro_rules ! impl_integer { ( $ ( $ tpe : ident ) ,* ) => { $ ( impl Int for $ tpe { impl_integer_functions ! ( to_u8 , u8 , to_u16 , u16 , to_u32 , u32 , to_u64 , u64 , to_u128 , u128 , to_i8 , i8 , to_i16 , i16 , to_i32 , i32 , to_i64 , i64 , to_i128 , i128 , to_usize , usize , to_isize , isize ) ; fn zero ( ) -> Self { 0 } fn one ( ) -> Self { 1 } } ) * } ; }
    impl_integer!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize);
}
mod range {
    use crate::integer::Int;
    use std::cmp::{max, min};
    use std::ops::{Bound, Range, RangeBounds, RangeInclusive};
    pub trait RangeEx<T> {
        fn width(&self) -> T;
        fn empty(&self) -> bool;
        fn contain_range(&self, inner: &Self) -> bool;
        fn separate_range(&self, other: &Self) -> bool;
        type ReturnRange;
        fn overlap(&self, other: &Self) -> Self::ReturnRange;
    }
    impl<T: Int> RangeEx<T> for Range<T> {
        fn width(&self) -> T {
            if self.empty() {
                T::zero()
            } else {
                self.end - self.start
            }
        }
        fn empty(&self) -> bool {
            !(self.start < self.end)
        }
        fn contain_range(&self, inner: &Self) -> bool {
            self.start <= inner.start && inner.end <= self.end
        }
        fn separate_range(&self, other: &Self) -> bool {
            self.end <= other.start || other.end <= self.start
        }
        type ReturnRange = Range<T>;
        fn overlap(&self, other: &Self) -> Self::ReturnRange {
            let left = max(self.start, other.start);
            let right = min(self.end, other.end);
            left..right
        }
    }
    impl<T: Int> RangeEx<T> for RangeInclusive<T> {
        fn width(&self) -> T {
            if self.empty() {
                T::zero()
            } else {
                *self.end() - *self.start() + T::one()
            }
        }
        fn empty(&self) -> bool {
            !(self.start() <= self.end())
        }
        fn contain_range(&self, inner: &Self) -> bool {
            self.start() <= inner.start() && inner.end() <= self.end()
        }
        fn separate_range(&self, other: &Self) -> bool {
            self.end() <= other.start() || other.end() <= self.start()
        }
        type ReturnRange = RangeInclusive<T>;
        fn overlap(&self, other: &Self) -> Self::ReturnRange {
            let left = *max(self.start(), other.start());
            let right = *min(self.end(), other.end());
            left..=right
        }
    }
    pub trait IntRangeBounds<U: Int>: RangeBounds<U> {
        #[doc = " inclusive"]
        fn lower_bound(&self, lower_bound: U) -> U {
            match self.start_bound() {
                Bound::Included(x) => max(lower_bound, *x),
                Bound::Excluded(x) => max(lower_bound, *x + U::one()),
                Bound::Unbounded => lower_bound,
            }
        }
        #[doc = " exclusive"]
        fn upper_bound(&self, upper_bound: U) -> U {
            match self.end_bound() {
                Bound::Included(x) => min(upper_bound, *x + U::one()),
                Bound::Excluded(x) => min(upper_bound, *x),
                Bound::Unbounded => upper_bound,
            }
        }
        fn to_range(&self, lb: U, ub: U) -> Range<U> {
            self.lower_bound(lb)..self.upper_bound(ub)
        }
    }
    impl<T: ?Sized, U: Int> IntRangeBounds<U> for T where T: RangeBounds<U> {}
}