QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#615561#9443. Left Equals Rightucup-team296#AC ✓139ms798888kbRust42.5kb2024-10-05 19:18:102024-10-05 19:18:10

Judging History

你现在查看的是最新测评结果

  • [2024-10-05 19:18:10]
  • 评测
  • 测评结果:AC
  • 用时:139ms
  • 内存:798888kb
  • [2024-10-05 19:18:10]
  • 提交

answer

// 
pub mod solution {
//{"name":"ucup_11_i","group":"Manual","url":"","interactive":false,"timeLimit":2000,"tests":[{"input":"","output":""},{"input":"","output":""},{"input":"","output":""}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"ucup_11_i"}}}

use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::output::Output;
use crate::algo_lib::misc::memo::memoization_3d::Memoization3d;
use crate::algo_lib::misc::recursive_function::Callable3;
use crate::algo_lib::misc::test_type::TaskType;
use crate::algo_lib::misc::test_type::TestType;
use crate::algo_lib::numbers::mod_int::ModIntF;
use crate::algo_lib::numbers::mod_utils::Combinations;
use crate::algo_lib::numbers::num_traits::algebra::Zero;

type PreCalc = ();

fn solve(input: &mut Input, out: &mut Output, _test_case: usize, _data: &mut PreCalc) {
    let n = input.read_size();
    let a = input.read_size_vec(n);

    type Mod = ModIntF;
    let sum = a.iter().sum::<usize>();
    if sum % 2 == 1 {
        out.print_line(0);
        return;
    }
    let c = Combinations::<Mod>::new(n + 1);
    let mut mem = Memoization3d::new(n + 1, n + 1, sum + 1, |mem, step, q, s| {
        if step == n {
            if s == sum / 2 {
                c.fact(q) * c.fact(n - q)
            } else {
                Mod::zero()
            }
        } else {
            mem.call(step + 1, q, s) + mem.call(step + 1, q + 1, s + a[step])
        }
    });
    out.print_line(mem.call(0, 0, 0));
}

pub static TEST_TYPE: TestType = TestType::Single;
pub static TASK_TYPE: TaskType = TaskType::Classic;

pub(crate) fn run(mut input: Input, mut output: Output) -> bool {
    let mut pre_calc = ();

    match TEST_TYPE {
        TestType::Single => solve(&mut input, &mut output, 1, &mut pre_calc),
        TestType::MultiNumber => {
            let t = input.read();
            for i in 1..=t {
                solve(&mut input, &mut output, i, &mut pre_calc);
            }
        }
        TestType::MultiEof => {
            let mut i = 1;
            while input.peek().is_some() {
                solve(&mut input, &mut output, i, &mut pre_calc);
                i += 1;
            }
        }
    }
    output.flush();
    match TASK_TYPE {
        TaskType::Classic => {
            input.skip_whitespace();
            input.peek().is_none()
        }
        TaskType::Interactive => true,
    }
}

}
pub mod algo_lib {
pub mod collections {
pub mod md_arr {
pub mod arr3d {
use crate::algo_lib::collections::slice_ext::legacy_fill::LegacyFill;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::input::Readable;
use crate::algo_lib::io::output::Output;
use crate::algo_lib::io::output::Writable;
use std::ops::Index;
use std::ops::IndexMut;
use std::vec::IntoIter;

#[derive(Clone, Eq, PartialEq)]
pub struct Arr3d<T> {
    d1: usize,
    d2: usize,
    d3: usize,
    data: Vec<T>,
}

impl<T: Clone> Arr3d<T> {
    pub fn new(d1: usize, d2: usize, d3: usize, value: T) -> Self {
        Self {
            d1,
            d2,
            d3,
            data: vec![value; d1 * d2 * d3],
        }
    }
}

impl<T> Arr3d<T> {
    pub fn generate<F>(d1: usize, d2: usize, d3: usize, mut gen: F) -> Self
    where
        F: FnMut(usize, usize, usize) -> T,
    {
        let mut data = Vec::with_capacity(d1 * d2 * d3);
        for i in 0usize..d1 {
            for j in 0usize..d2 {
                for k in 0..d3 {
                    data.push(gen(i, j, k));
                }
            }
        }
        Self { d1, d2, d3, data }
    }

    pub fn d1(&self) -> usize {
        self.d1
    }

    pub fn d2(&self) -> usize {
        self.d2
    }

    pub fn d3(&self) -> usize {
        self.d3
    }

    pub fn iter(&self) -> impl Iterator<Item = &T> {
        self.data.iter()
    }

    pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
        self.data.iter_mut()
    }
}

impl<T> IntoIterator for Arr3d<T> {
    type Item = T;
    type IntoIter = IntoIter<T>;

    fn into_iter(self) -> Self::IntoIter {
        self.data.into_iter()
    }
}

impl<T> Index<(usize, usize, usize)> for Arr3d<T> {
    type Output = T;

    fn index(&self, (a1, a2, a3): (usize, usize, usize)) -> &Self::Output {
        assert!(a1 < self.d1);
        assert!(a2 < self.d2);
        assert!(a3 < self.d3);
        &self.data[(a1 * self.d2 + a2) * self.d3 + a3]
    }
}

impl<T> IndexMut<(usize, usize, usize)> for Arr3d<T> {
    fn index_mut(&mut self, (a1, a2, a3): (usize, usize, usize)) -> &mut Self::Output {
        assert!(a1 < self.d1);
        assert!(a2 < self.d2);
        assert!(a3 < self.d3);
        &mut self.data[(a1 * self.d2 + a2) * self.d3 + a3]
    }
}

impl<T: Writable> Writable for Arr3d<T> {
    fn write(&self, output: &mut Output) {
        let mut at = 0usize;
        for i in 0..self.d1 {
            if i != 0 {
                output.put(b'\n');
            }
            for j in 0..self.d2 {
                if j != 0 {
                    output.put(b'\n');
                }
                for k in 0..self.d3 {
                    if k != 0 {
                        output.put(b' ');
                    }
                    self.data[at].write(output);
                    at += 1;
                }
            }
        }
    }
}

pub trait Arr3dRead {
    fn read_3d_table<T: Readable>(&mut self, d1: usize, d2: usize, d3: usize) -> Arr3d<T>;
}

impl Arr3dRead for Input<'_> {
    fn read_3d_table<T: Readable>(&mut self, d1: usize, d2: usize, d3: usize) -> Arr3d<T> {
        Arr3d::generate(d1, d2, d3, |_, _, _| self.read())
    }
}

impl<T: Readable> Readable for Arr3d<T> {
    fn read(input: &mut Input) -> Self {
        let d1 = input.read();
        let d2 = input.read();
        let d3 = input.read();
        input.read_3d_table(d1, d2, d3)
    }
}

impl<T: Clone> Arr3d<T> {
    pub fn fill(&mut self, elem: T) {
        self.data.legacy_fill(elem);
    }
}
}
}
pub mod slice_ext {
pub mod legacy_fill {
// 1.50
pub trait LegacyFill<T> {
    fn legacy_fill(&mut self, val: T);
}

impl<T: Clone> LegacyFill<T> for [T] {
    fn legacy_fill(&mut self, val: T) {
        for el in self.iter_mut() {
            *el = val.clone();
        }
    }
}
}
}
pub mod vec_ext {
pub mod default {
pub fn default_vec<T: Default>(len: usize) -> Vec<T> {
    let mut v = Vec::with_capacity(len);
    for _ in 0..len {
        v.push(T::default());
    }
    v
}
}
}
}
pub mod io {
pub mod input {
use crate::algo_lib::collections::vec_ext::default::default_vec;
use std::io::Read;

pub struct Input<'s> {
    input: &'s mut dyn Read,
    buf: Vec<u8>,
    at: usize,
    buf_read: usize,
}

macro_rules! read_impl {
    ($t: ty, $read_name: ident, $read_vec_name: ident) => {
        pub fn $read_name(&mut self) -> $t {
            self.read()
        }

        pub fn $read_vec_name(&mut self, len: usize) -> Vec<$t> {
            self.read_vec(len)
        }
    };

    ($t: ty, $read_name: ident, $read_vec_name: ident, $read_pair_vec_name: ident) => {
        read_impl!($t, $read_name, $read_vec_name);

        pub fn $read_pair_vec_name(&mut self, len: usize) -> Vec<($t, $t)> {
            self.read_vec(len)
        }
    };
}

impl<'s> Input<'s> {
    const DEFAULT_BUF_SIZE: usize = 4096;

    pub fn new(input: &'s mut dyn Read) -> Self {
        Self {
            input,
            buf: default_vec(Self::DEFAULT_BUF_SIZE),
            at: 0,
            buf_read: 0,
        }
    }

    pub fn new_with_size(input: &'s mut dyn Read, buf_size: usize) -> Self {
        Self {
            input,
            buf: default_vec(buf_size),
            at: 0,
            buf_read: 0,
        }
    }

    pub fn get(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            self.at += 1;
            if res == b'\r' {
                if self.refill_buffer() && self.buf[self.at] == b'\n' {
                    self.at += 1;
                }
                return Some(b'\n');
            }
            Some(res)
        } else {
            None
        }
    }

    pub fn peek(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            Some(if res == b'\r' { b'\n' } else { res })
        } else {
            None
        }
    }

    pub fn skip_whitespace(&mut self) {
        while let Some(b) = self.peek() {
            if !b.is_ascii_whitespace() {
                return;
            }
            self.get();
        }
    }

    pub fn next_token(&mut self) -> Option<Vec<u8>> {
        self.skip_whitespace();
        let mut res = Vec::new();
        while let Some(c) = self.get() {
            if c.is_ascii_whitespace() {
                break;
            }
            res.push(c);
        }
        if res.is_empty() {
            None
        } else {
            Some(res)
        }
    }

    //noinspection RsSelfConvention
    pub fn is_exhausted(&mut self) -> bool {
        self.peek().is_none()
    }

    //noinspection RsSelfConvention
    pub fn is_empty(&mut self) -> bool {
        self.skip_whitespace();
        self.is_exhausted()
    }

    pub fn read<T: Readable>(&mut self) -> T {
        T::read(self)
    }

    pub fn read_vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
        let mut res = Vec::with_capacity(size);
        for _ in 0..size {
            res.push(self.read());
        }
        res
    }

    pub fn read_char(&mut self) -> char {
        self.skip_whitespace();
        self.get().unwrap().into()
    }

    read_impl!(u32, read_unsigned, read_unsigned_vec);
    read_impl!(u64, read_u64, read_u64_vec);
    read_impl!(usize, read_size, read_size_vec, read_size_pair_vec);
    read_impl!(i32, read_int, read_int_vec, read_int_pair_vec);
    read_impl!(i64, read_long, read_long_vec, read_long_pair_vec);
    read_impl!(i128, read_i128, read_i128_vec);

    fn refill_buffer(&mut self) -> bool {
        if self.at == self.buf_read {
            self.at = 0;
            self.buf_read = self.input.read(&mut self.buf).unwrap();
            self.buf_read != 0
        } else {
            true
        }
    }
}

pub trait Readable {
    fn read(input: &mut Input) -> Self;
}

impl Readable for char {
    fn read(input: &mut Input) -> Self {
        input.read_char()
    }
}

impl<T: Readable> Readable for Vec<T> {
    fn read(input: &mut Input) -> Self {
        let size = input.read();
        input.read_vec(size)
    }
}

macro_rules! read_integer {
    ($($t:ident)+) => {$(
        impl Readable for $t {
            fn read(input: &mut Input) -> Self {
                input.skip_whitespace();
                let mut c = input.get().unwrap();
                let sgn = match c {
                    b'-' => {
                        c = input.get().unwrap();
                        true
                    }
                    b'+' => {
                        c = input.get().unwrap();
                        false
                    }
                    _ => false,
                };
                let mut res = 0;
                loop {
                    assert!(c.is_ascii_digit());
                    res *= 10;
                    let d = (c - b'0') as $t;
                    if sgn {
                        res -= d;
                    } else {
                        res += d;
                    }
                    match input.get() {
                        None => break,
                        Some(ch) => {
                            if ch.is_ascii_whitespace() {
                                break;
                            } else {
                                c = ch;
                            }
                        }
                    }
                }
                res
            }
        }
    )+};
}

read_integer!(i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize);

macro_rules! tuple_readable {
    ($($name:ident)+) => {
        impl<$($name: Readable), +> Readable for ($($name,)+) {
            fn read(input: &mut Input) -> Self {
                ($($name::read(input),)+)
            }
        }
    }
}

tuple_readable! {T}
tuple_readable! {T U}
tuple_readable! {T U V}
tuple_readable! {T U V X}
tuple_readable! {T U V X Y}
tuple_readable! {T U V X Y Z}
tuple_readable! {T U V X Y Z A}
tuple_readable! {T U V X Y Z A B}
tuple_readable! {T U V X Y Z A B C}
tuple_readable! {T U V X Y Z A B C D}
tuple_readable! {T U V X Y Z A B C D E}
tuple_readable! {T U V X Y Z A B C D E F}

impl Read for Input<'_> {
    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
        if self.at == self.buf_read {
            self.input.read(buf)
        } else {
            let mut i = 0;
            while i < buf.len() && self.at < self.buf_read {
                buf[i] = self.buf[self.at];
                i += 1;
                self.at += 1;
            }
            Ok(i)
        }
    }
}
}
pub mod output {
use crate::algo_lib::collections::vec_ext::default::default_vec;
use std::cmp::Reverse;
use std::io::stderr;
use std::io::Stderr;
use std::io::Write;

#[derive(Copy, Clone)]
pub enum BoolOutput {
    YesNo,
    YesNoCaps,
    PossibleImpossible,
    Custom(&'static str, &'static str),
}

impl BoolOutput {
    pub fn output(&self, output: &mut Output, val: bool) {
        (if val { self.yes() } else { self.no() }).write(output);
    }

    fn yes(&self) -> &str {
        match self {
            BoolOutput::YesNo => "Yes",
            BoolOutput::YesNoCaps => "YES",
            BoolOutput::PossibleImpossible => "Possible",
            BoolOutput::Custom(yes, _) => yes,
        }
    }

    fn no(&self) -> &str {
        match self {
            BoolOutput::YesNo => "No",
            BoolOutput::YesNoCaps => "NO",
            BoolOutput::PossibleImpossible => "Impossible",
            BoolOutput::Custom(_, no) => no,
        }
    }
}

pub struct Output<'s> {
    output: &'s mut dyn Write,
    buf: Vec<u8>,
    at: usize,
    auto_flush: bool,
    bool_output: BoolOutput,
}

impl<'s> Output<'s> {
    const DEFAULT_BUF_SIZE: usize = 4096;

    pub fn new(output: &'s mut dyn Write) -> Self {
        Self {
            output,
            buf: default_vec(Self::DEFAULT_BUF_SIZE),
            at: 0,
            auto_flush: false,
            bool_output: BoolOutput::YesNoCaps,
        }
    }

    pub fn new_with_auto_flush(output: &'s mut dyn Write) -> Self {
        Self {
            output,
            buf: default_vec(Self::DEFAULT_BUF_SIZE),
            at: 0,
            auto_flush: true,
            bool_output: BoolOutput::YesNoCaps,
        }
    }

    pub fn flush(&mut self) {
        if self.at != 0 {
            self.output.write_all(&self.buf[..self.at]).unwrap();
            self.output.flush().unwrap();
            self.at = 0;
        }
    }

    pub fn print<T: Writable>(&mut self, s: T) {
        s.write(self);
        self.maybe_flush();
    }

    pub fn print_line<T: Writable>(&mut self, s: T) {
        self.print(s);
        self.put(b'\n');
        self.maybe_flush();
    }

    pub fn put(&mut self, b: u8) {
        self.buf[self.at] = b;
        self.at += 1;
        if self.at == self.buf.len() {
            self.flush();
        }
    }

    pub fn maybe_flush(&mut self) {
        if self.auto_flush {
            self.flush();
        }
    }

    pub fn print_per_line<T: Writable>(&mut self, arg: &[T]) {
        self.print_per_line_iter(arg.iter());
    }

    pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        let mut first = true;
        for e in iter {
            if first {
                first = false;
            } else {
                self.put(b' ');
            }
            e.write(self);
        }
    }

    pub fn print_line_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        self.print_iter(iter);
        self.put(b'\n');
    }

    pub fn print_per_line_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        for e in iter {
            e.write(self);
            self.put(b'\n');
        }
    }

    pub fn set_bool_output(&mut self, bool_output: BoolOutput) {
        self.bool_output = bool_output;
    }
}

impl Write for Output<'_> {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        let mut start = 0usize;
        let mut rem = buf.len();
        while rem > 0 {
            let len = (self.buf.len() - self.at).min(rem);
            self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);
            self.at += len;
            if self.at == self.buf.len() {
                self.flush();
            }
            start += len;
            rem -= len;
        }
        self.maybe_flush();
        Ok(buf.len())
    }

    fn flush(&mut self) -> std::io::Result<()> {
        self.flush();
        Ok(())
    }
}

pub trait Writable {
    fn write(&self, output: &mut Output);
}

impl Writable for &str {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}

impl Writable for String {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}

impl Writable for char {
    fn write(&self, output: &mut Output) {
        output.put(*self as u8);
    }
}

impl<T: Writable> Writable for [T] {
    fn write(&self, output: &mut Output) {
        output.print_iter(self.iter());
    }
}

impl<T: Writable, const N: usize> Writable for [T; N] {
    fn write(&self, output: &mut Output) {
        output.print_iter(self.iter());
    }
}

impl<T: Writable + ?Sized> Writable for &T {
    fn write(&self, output: &mut Output) {
        T::write(self, output)
    }
}

impl<T: Writable> Writable for Vec<T> {
    fn write(&self, output: &mut Output) {
        self.as_slice().write(output);
    }
}

impl Writable for () {
    fn write(&self, _output: &mut Output) {}
}

macro_rules! write_to_string {
    ($($t:ident)+) => {$(
        impl Writable for $t {
            fn write(&self, output: &mut Output) {
                self.to_string().write(output);
            }
        }
    )+};
}

write_to_string!(u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);

macro_rules! tuple_writable {
    ($name0:ident $($name:ident: $id:tt )*) => {
        impl<$name0: Writable, $($name: Writable,)*> Writable for ($name0, $($name,)*) {
            fn write(&self, out: &mut Output) {
                self.0.write(out);
                $(
                out.put(b' ');
                self.$id.write(out);
                )*
            }
        }
    }
}

tuple_writable! {T}
tuple_writable! {T U:1}
tuple_writable! {T U:1 V:2}
tuple_writable! {T U:1 V:2 X:3}
tuple_writable! {T U:1 V:2 X:3 Y:4}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6 B:7}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6 B:7 C:8}

impl<T: Writable> Writable for Option<T> {
    fn write(&self, output: &mut Output) {
        match self {
            None => (-1).write(output),
            Some(t) => t.write(output),
        }
    }
}

impl Writable for bool {
    fn write(&self, output: &mut Output) {
        let bool_output = output.bool_output;
        bool_output.output(output, *self)
    }
}

impl<T: Writable> Writable for Reverse<T> {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
    }
}

static mut ERR: Option<Stderr> = None;

pub fn err() -> Output<'static> {
    unsafe {
        if ERR.is_none() {
            ERR = Some(stderr());
        }
        Output::new_with_auto_flush(ERR.as_mut().unwrap())
    }
}
}
}
pub mod misc {
pub mod memo {
pub mod memoization_3d {
use crate::algo_lib::collections::md_arr::arr3d::Arr3d;
use crate::algo_lib::misc::recursive_function::Callable3;

pub struct Memoization3d<F, Output>
where
    F: FnMut(&mut dyn Callable3<usize, usize, usize, Output>, usize, usize, usize) -> Output,
{
    f: std::cell::UnsafeCell<F>,
    res: Arr3d<Option<Output>>,
}

impl<F, Output: Clone> Memoization3d<F, Output>
where
    F: FnMut(&mut dyn Callable3<usize, usize, usize, Output>, usize, usize, usize) -> Output,
{
    pub fn new(d1: usize, d2: usize, d3: usize, f: F) -> Self {
        Self {
            f: std::cell::UnsafeCell::new(f),
            res: Arr3d::new(d1, d2, d3, None),
        }
    }
}

impl<F, Output: Clone> Callable3<usize, usize, usize, Output> for Memoization3d<F, Output>
where
    F: FnMut(&mut dyn Callable3<usize, usize, usize, Output>, usize, usize, usize) -> Output,
{
    fn call(&mut self, a1: usize, a2: usize, a3: usize) -> Output {
        match self.res[(a1, a2, a3)].as_ref() {
            None => {
                let res = unsafe { (*self.f.get())(self, a1, a2, a3) };
                self.res[(a1, a2, a3)] = Some(res.clone());
                res
            }
            Some(res) => res.clone(),
        }
    }
}
}
}
pub mod recursive_function {
use std::marker::PhantomData;

macro_rules! recursive_function {
    ($name: ident, $trait: ident, ($($type: ident $arg: ident,)*)) => {
        pub trait $trait<$($type, )*Output> {
            fn call(&mut self, $($arg: $type,)*) -> Output;
        }

        pub struct $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            f: std::cell::UnsafeCell<F>,
            $($arg: PhantomData<$type>,
            )*
            phantom_output: PhantomData<Output>,
        }

        impl<F, $($type, )*Output> $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            pub fn new(f: F) -> Self {
                Self {
                    f: std::cell::UnsafeCell::new(f),
                    $($arg: Default::default(),
                    )*
                    phantom_output: Default::default(),
                }
            }
        }

        impl<F, $($type, )*Output> $trait<$($type, )*Output> for $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            fn call(&mut self, $($arg: $type,)*) -> Output {
                unsafe { (*self.f.get())(self, $($arg, )*) }
            }
        }
    }
}

recursive_function!(RecursiveFunction0, Callable0, ());
recursive_function!(RecursiveFunction, Callable, (Arg arg,));
recursive_function!(RecursiveFunction2, Callable2, (Arg1 arg1, Arg2 arg2,));
recursive_function!(RecursiveFunction3, Callable3, (Arg1 arg1, Arg2 arg2, Arg3 arg3,));
recursive_function!(RecursiveFunction4, Callable4, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4,));
recursive_function!(RecursiveFunction5, Callable5, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5,));
recursive_function!(RecursiveFunction6, Callable6, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6,));
recursive_function!(RecursiveFunction7, Callable7, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7,));
recursive_function!(RecursiveFunction8, Callable8, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8,));
recursive_function!(RecursiveFunction9, Callable9, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8, Arg9 arg9,));
}
pub mod test_type {
pub enum TestType {
    Single,
    MultiNumber,
    MultiEof,
}

pub enum TaskType {
    Classic,
    Interactive,
}
}
pub mod value {
use std::hash::Hash;

pub trait Value<T>: Copy + Eq + Hash {
    fn val() -> T;
}

pub trait ConstValue<T>: Value<T> {
    const VAL: T;
}

impl<T, V: ConstValue<T>> Value<T> for V {
    fn val() -> T {
        Self::VAL
    }
}

#[macro_export]
macro_rules! value {
    ($name: ident: $t: ty = $val: expr) => {
        #[derive(Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, Default)]
        pub struct $name {}

        impl $crate::algo_lib::misc::value::ConstValue<$t> for $name {
            const VAL: $t = $val;
        }
    };
}

pub trait DynamicValue<T>: Value<T> {
    //noinspection RsSelfConvention
    fn set_val(t: T);
}

#[macro_export]
macro_rules! dynamic_value {
    ($name: ident: $t: ty, $val: ident) => {
        static mut $val: Option<$t> = None;

        #[derive(Copy, Clone, Eq, PartialEq, Hash, Default)]
        struct $name {}

        impl $crate::algo_lib::misc::value::DynamicValue<$t> for $name {
            fn set_val(t: $t) {
                unsafe {
                    $val = Some(t);
                }
            }
        }

        impl $crate::algo_lib::misc::value::Value<$t> for $name {
            fn val() -> $t {
                unsafe { $val.unwrap() }
            }
        }
    };
    ($name: ident: $t: ty) => {
        dynamic_value!($name: $t, VAL);
    };
    ($name: ident: $t: ty = $val: expr) => {
        dynamic_value!($name: $t);

        $name::set_val($val);
    };
    ($name: ident: $t: ty = $val: expr, $val_static: ident) => {
        dynamic_value!($name: $t, $val_static);

        $name::set_val($val);
    };
}
}
pub mod when {
#[macro_export]
macro_rules! when {
    {$($cond: expr => $then: expr,)*} => {
        match () {
            $(_ if $cond => $then,)*
            _ => unreachable!(),
        }
    };
    {$($cond: expr => $then: expr,)* else $(=>)? $else: expr,} => {
        match () {
            $(_ if $cond => $then,)*
            _ => $else,
        }
    };
}
}
}
pub mod numbers {
pub mod gcd {
use crate::algo_lib::numbers::num_traits::algebra::IntegerMultiplicationMonoid;
use crate::algo_lib::numbers::num_traits::algebra::IntegerSemiRingWithSub;
use crate::algo_lib::numbers::num_traits::algebra::One;
use crate::algo_lib::numbers::num_traits::algebra::SemiRingWithSub;
use crate::algo_lib::numbers::num_traits::algebra::Zero;
use crate::algo_lib::numbers::num_traits::wideable::Wideable;
use std::mem::swap;

pub fn extended_gcd<T: IntegerSemiRingWithSub + Wideable + Copy>(a: T, b: T) -> (T, T::W, T::W)
where
    T::W: Copy + SemiRingWithSub,
{
    if a == T::zero() {
        (b, T::W::zero(), T::W::one())
    } else {
        let (d, y, mut x) = extended_gcd(b % a, a);
        x -= T::W::from(b / a) * y;
        (d, x, y)
    }
}

pub fn gcd<T: Copy + Zero + IntegerMultiplicationMonoid>(mut a: T, mut b: T) -> T {
    while b != T::zero() {
        a %= b;
        swap(&mut a, &mut b);
    }
    a
}

pub fn lcm<T: Copy + Zero + IntegerMultiplicationMonoid>(a: T, b: T) -> T {
    (a / gcd(a, b)) * b
}
}
pub mod mod_int {
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::input::Readable;
use crate::algo_lib::io::output::Output;
use crate::algo_lib::io::output::Writable;
use crate::algo_lib::misc::value::Value;
use crate::algo_lib::numbers::gcd::extended_gcd;
use crate::algo_lib::numbers::num_traits::algebra::Field;
use crate::algo_lib::numbers::num_traits::algebra::IntegerRing;
use crate::algo_lib::numbers::num_traits::algebra::One;
use crate::algo_lib::numbers::num_traits::algebra::Ring;
use crate::algo_lib::numbers::num_traits::algebra::Zero;
use crate::algo_lib::numbers::num_traits::as_index::AsIndex;
use crate::algo_lib::numbers::num_traits::invertible::Invertible;
use crate::algo_lib::numbers::num_traits::wideable::Wideable;
use crate::value;
use crate::when;
use std::collections::HashMap;
use std::fmt::Display;
use std::fmt::Formatter;
use std::hash::Hash;
use std::marker::PhantomData;
use std::ops::Add;
use std::ops::AddAssign;
use std::ops::Div;
use std::ops::DivAssign;
use std::ops::Mul;
use std::ops::MulAssign;
use std::ops::Neg;
use std::ops::Sub;
use std::ops::SubAssign;

pub trait BaseModInt: Field + Copy {
    type W: IntegerRing + Copy + From<Self::T>;
    type T: IntegerRing + Ord + Copy + Wideable<W = Self::W>;

    fn from(v: Self::T) -> Self;
    fn module() -> Self::T;
}

#[derive(Copy, Clone, Eq, PartialEq, Hash, Default)]
pub struct ModInt<T, V: Value<T>> {
    n: T,
    phantom: PhantomData<V>,
}

impl<T: Copy, V: Value<T>> ModInt<T, V> {
    pub fn val(&self) -> T {
        self.n
    }
}

impl<T: Ring + Ord + Copy, V: Value<T>> ModInt<T, V> {
    unsafe fn unchecked_new(n: T) -> Self {
        debug_assert!(n >= T::zero() && n < V::val());
        Self {
            n,
            phantom: Default::default(),
        }
    }

    unsafe fn maybe_subtract_mod(mut n: T) -> T {
        debug_assert!(n < V::val() + V::val() && n >= T::zero());
        if n >= V::val() {
            n -= V::val();
        }
        n
    }
}

impl<T: IntegerRing + Ord + Copy, V: Value<T>> ModInt<T, V> {
    pub fn new(n: T) -> Self {
        unsafe { Self::unchecked_new(Self::maybe_subtract_mod(n % (V::val()) + V::val())) }
    }
}

impl<T: Copy + IntegerRing + Ord + Wideable + Hash, V: Value<T>> ModInt<T, V>
where
    T::W: Copy + IntegerRing,
{
    pub fn log(&self, alpha: Self) -> T {
        let mut base = HashMap::new();
        let mut exp = T::zero();
        let mut pow = Self::one();
        let mut inv = *self;
        let alpha_inv = alpha.inv().unwrap();
        while exp * exp < Self::module() {
            if inv == Self::one() {
                return exp;
            }
            base.insert(inv, exp);
            exp += T::one();
            pow *= alpha;
            inv *= alpha_inv;
        }
        let step = pow;
        let mut i = T::one();
        loop {
            if let Some(b) = base.get(&pow) {
                break exp * i + *b;
            }
            pow *= step;
            i += T::one();
        }
    }
}

impl<T: Wideable + Ring + Ord + Copy, V: Value<T>> ModInt<T, V>
where
    T::W: IntegerRing,
{
    pub fn new_from_wide(n: T::W) -> Self {
        unsafe {
            Self::unchecked_new(Self::maybe_subtract_mod(
                T::downcast(n % V::val().into()) + V::val(),
            ))
        }
    }
}

impl<T: Copy + IntegerRing + Ord + Wideable, V: Value<T>> Invertible for ModInt<T, V>
where
    T::W: Copy + IntegerRing,
{
    type Output = Self;

    fn inv(&self) -> Option<Self> {
        let (g, x, _) = extended_gcd(self.n, V::val());
        if g != T::one() {
            None
        } else {
            Some(Self::new_from_wide(x))
        }
    }
}

impl<T: IntegerRing + Ord + Copy + Wideable, V: Value<T>> BaseModInt for ModInt<T, V>
where
    T::W: IntegerRing + Copy,
{
    type W = T::W;
    type T = T;

    fn from(v: Self::T) -> Self {
        Self::new(v)
    }

    fn module() -> T {
        V::val()
    }
}

impl<T: IntegerRing + Ord + Copy, V: Value<T>> From<T> for ModInt<T, V> {
    fn from(n: T) -> Self {
        Self::new(n)
    }
}

impl<T: Ring + Ord + Copy, V: Value<T>> AddAssign for ModInt<T, V> {
    fn add_assign(&mut self, rhs: Self) {
        self.n = unsafe { Self::maybe_subtract_mod(self.n + rhs.n) };
    }
}

impl<T: Ring + Ord + Copy, V: Value<T>> Add for ModInt<T, V> {
    type Output = Self;

    fn add(mut self, rhs: Self) -> Self::Output {
        self += rhs;
        self
    }
}

impl<T: Ring + Ord + Copy, V: Value<T>> SubAssign for ModInt<T, V> {
    fn sub_assign(&mut self, rhs: Self) {
        self.n = unsafe { Self::maybe_subtract_mod(self.n + V::val() - rhs.n) };
    }
}

impl<T: Ring + Ord + Copy, V: Value<T>> Sub for ModInt<T, V> {
    type Output = Self;

    fn sub(mut self, rhs: Self) -> Self::Output {
        self -= rhs;
        self
    }
}

impl<T: IntegerRing + Ord + Copy + Wideable, V: Value<T>> MulAssign for ModInt<T, V>
where
    T::W: IntegerRing + Copy,
{
    fn mul_assign(&mut self, rhs: Self) {
        self.n = T::downcast(T::W::from(self.n) * T::W::from(rhs.n) % T::W::from(V::val()));
    }
}

impl<T: IntegerRing + Ord + Copy + Wideable, V: Value<T>> Mul for ModInt<T, V>
where
    T::W: IntegerRing + Copy,
{
    type Output = Self;

    fn mul(mut self, rhs: Self) -> Self::Output {
        self *= rhs;
        self
    }
}

impl<T: IntegerRing + Ord + Copy + Wideable, V: Value<T>> DivAssign for ModInt<T, V>
where
    T::W: IntegerRing + Copy,
{
    #[allow(clippy::suspicious_op_assign_impl)]
    fn div_assign(&mut self, rhs: Self) {
        *self *= rhs.inv().unwrap();
    }
}

impl<T: IntegerRing + Ord + Copy + Wideable, V: Value<T>> Div for ModInt<T, V>
where
    T::W: IntegerRing + Copy,
{
    type Output = Self;

    fn div(mut self, rhs: Self) -> Self::Output {
        self /= rhs;
        self
    }
}

impl<T: Ring + Ord + Copy, V: Value<T>> Neg for ModInt<T, V> {
    type Output = Self;

    fn neg(mut self) -> Self::Output {
        self.n = unsafe { Self::maybe_subtract_mod(V::val() - self.n) };
        self
    }
}

impl<T: Display, V: Value<T>> Display for ModInt<T, V> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        <T as Display>::fmt(&self.n, f)
    }
}

impl<T: IntegerRing + Ord + Copy + Readable, V: Value<T>> Readable for ModInt<T, V> {
    fn read(input: &mut Input) -> Self {
        Self::new(T::read(input))
    }
}

impl<T: Writable, V: Value<T>> Writable for ModInt<T, V> {
    fn write(&self, output: &mut Output) {
        self.n.write(output);
    }
}

impl<T: Ring + Ord + Copy, V: Value<T>> Zero for ModInt<T, V> {
    fn zero() -> Self {
        unsafe { Self::unchecked_new(T::zero()) }
    }
}

impl<T: IntegerRing + Ord + Copy, V: Value<T>> One for ModInt<T, V> {
    fn one() -> Self {
        Self::new(T::one())
    }
}

impl<T, V: Value<T>> Wideable for ModInt<T, V> {
    type W = Self;

    fn downcast(w: Self::W) -> Self {
        w
    }
}

impl<T: IntegerRing + Ord + Copy + Wideable + Display + AsIndex, V: Value<T>> std::fmt::Debug
    for ModInt<T, V>
where
    T::W: IntegerRing + Copy,
{
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let max = T::from_index(100);
        when! {
            self.n <= max => write!(f, "{}", self.n),
            self.n >= V::val() - max => write!(f, "{}", self.n - V::val()),
            else => {
                let mut denominator = T::one();
                while denominator < max {
                    let mut num = T::one();
                    while num < max {
                        if Self::new(num) / Self::new(denominator) == *self {
                            return write!(f, "{}/{}", num, denominator);
                        }
                        if -Self::new(num) / Self::new(denominator) == *self {
                            return write!(f, "-{}/{}", num, denominator);
                        }
                        num += T::one();
                    }
                    denominator += T::one();
                }
                write!(f, "(?? {} ??)", self.n)
            },
        }
    }
}

impl<T: IntegerRing + Ord + Copy + AsIndex, V: Value<T>> AsIndex for ModInt<T, V> {
    fn from_index(idx: usize) -> Self {
        Self::new(T::from_index(idx))
    }

    fn to_index(self) -> usize {
        self.n.to_index()
    }
}

value!(Val7: i32 = 1_000_000_007);
pub type ModInt7 = ModInt<i32, Val7>;

value!(Val9: i32 = 1_000_000_009);
pub type ModInt9 = ModInt<i32, Val9>;

value!(ValF: i32 = 998_244_353);
pub type ModIntF = ModInt<i32, ValF>;
}
pub mod mod_utils {
use crate::algo_lib::numbers::mod_int::BaseModInt;
use crate::algo_lib::numbers::num_traits::as_index::AsIndex;
use crate::algo_lib::numbers::num_utils::factorial;
use crate::algo_lib::numbers::num_utils::factorials;

pub fn inverses<M: BaseModInt>(len: usize) -> Vec<M>
where
    M::T: AsIndex,
{
    let mut res = Vec::new();
    if len > 0 {
        res.push(M::zero());
    }
    if len > 1 {
        res.push(M::one());
    }
    while res.len() < len {
        res.push(
            res[M::module().to_index() % res.len()]
                * (M::from(M::module() / (M::T::from_index(res.len()))).neg()),
        );
    }
    res
}

pub fn inverse_factorials<M: BaseModInt>(len: usize) -> Vec<M>
where
    M::T: AsIndex,
{
    let mut res = inverses(len);
    if len > 0 {
        res[0] = M::one();
    }
    for i in 1..len {
        let last = res[i - 1];
        res[i] *= last;
    }
    res
}

pub struct Combinations<M: BaseModInt>
where
    M::T: AsIndex,
{
    fact: Vec<M>,
    inv_fact: Vec<M>,
}

impl<M: BaseModInt + AsIndex> Combinations<M>
where
    M::T: AsIndex,
{
    pub fn new(len: usize) -> Self {
        Self {
            fact: factorials(len),
            inv_fact: inverse_factorials(len),
        }
    }

    pub fn c(&self, n: usize, k: usize) -> M {
        if n < k {
            M::zero()
        } else {
            self.fact[n] * self.inv_fact[k] * self.inv_fact[n - k]
        }
    }

    pub fn comb_with_rep(&self, n: usize, k: usize) -> M {
        self.c(n + k - 1, k)
    }

    pub fn c_inv(&self, n: usize, k: usize) -> M {
        self.inv_fact[n] * self.fact[k] * self.fact[n - k]
    }

    pub fn fact(&self, n: usize) -> M {
        self.fact[n]
    }

    pub fn inv_fact(&self, n: usize) -> M {
        self.inv_fact[n]
    }
}

pub fn combinations<M: BaseModInt + AsIndex>(n: usize, mut k: usize) -> M {
    if k > n {
        return M::zero();
    }
    if k > n - k {
        k = n - k;
    }
    let mut res = M::one();
    for i in n - k + 1..=n {
        res *= M::from_index(i);
    }
    res /= factorial(k);
    res
}
}
pub mod num_traits {
pub mod algebra {
use crate::algo_lib::numbers::num_traits::invertible::Invertible;
use std::ops::Add;
use std::ops::AddAssign;
use std::ops::Div;
use std::ops::DivAssign;
use std::ops::Mul;
use std::ops::MulAssign;
use std::ops::Neg;
use std::ops::Rem;
use std::ops::RemAssign;
use std::ops::Sub;
use std::ops::SubAssign;

pub trait Zero {
    fn zero() -> Self;
}

pub trait One {
    fn one() -> Self;
}

pub trait AdditionMonoid: Add<Output = Self> + AddAssign + Zero + Eq + Sized {}

impl<T: Add<Output = Self> + AddAssign + Zero + Eq> AdditionMonoid for T {}

pub trait AdditionMonoidWithSub: AdditionMonoid + Sub<Output = Self> + SubAssign {}

impl<T: AdditionMonoid + Sub<Output = Self> + SubAssign> AdditionMonoidWithSub for T {}

pub trait AdditionGroup: AdditionMonoidWithSub + Neg<Output = Self> {}

impl<T: AdditionMonoidWithSub + Neg<Output = Self>> AdditionGroup for T {}

pub trait MultiplicationMonoid: Mul<Output = Self> + MulAssign + One + Eq + Sized {}

impl<T: Mul<Output = Self> + MulAssign + One + Eq> MultiplicationMonoid for T {}

pub trait IntegerMultiplicationMonoid:
    MultiplicationMonoid + Div<Output = Self> + Rem<Output = Self> + DivAssign + RemAssign
{
}

impl<T: MultiplicationMonoid + Div<Output = Self> + Rem<Output = Self> + DivAssign + RemAssign>
    IntegerMultiplicationMonoid for T
{
}

pub trait MultiplicationGroup:
    MultiplicationMonoid + Div<Output = Self> + DivAssign + Invertible<Output = Self>
{
}

impl<T: MultiplicationMonoid + Div<Output = Self> + DivAssign + Invertible<Output = Self>>
    MultiplicationGroup for T
{
}

pub trait SemiRing: AdditionMonoid + MultiplicationMonoid {}

impl<T: AdditionMonoid + MultiplicationMonoid> SemiRing for T {}

pub trait SemiRingWithSub: AdditionMonoidWithSub + SemiRing {}

impl<T: AdditionMonoidWithSub + SemiRing> SemiRingWithSub for T {}

pub trait Ring: SemiRing + AdditionGroup {}

impl<T: SemiRing + AdditionGroup> Ring for T {}

pub trait IntegerSemiRing: SemiRing + IntegerMultiplicationMonoid {}

impl<T: SemiRing + IntegerMultiplicationMonoid> IntegerSemiRing for T {}

pub trait IntegerSemiRingWithSub: SemiRingWithSub + IntegerSemiRing {}

impl<T: SemiRingWithSub + IntegerSemiRing> IntegerSemiRingWithSub for T {}

pub trait IntegerRing: IntegerSemiRing + Ring {}

impl<T: IntegerSemiRing + Ring> IntegerRing for T {}

pub trait Field: Ring + MultiplicationGroup {}

impl<T: Ring + MultiplicationGroup> Field for T {}

macro_rules! zero_one_integer_impl {
    ($($t: ident)+) => {$(
        impl Zero for $t {
            fn zero() -> Self {
                0
            }
        }

        impl One for $t {
            fn one() -> Self {
                1
            }
        }
    )+};
}

zero_one_integer_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize);
}
pub mod as_index {
pub trait AsIndex {
    fn from_index(idx: usize) -> Self;
    fn to_index(self) -> usize;
}

macro_rules! from_index_impl {
    ($($t: ident)+) => {$(
        impl AsIndex for $t {
            fn from_index(idx: usize) -> Self {
                idx as $t
            }

            fn to_index(self) -> usize {
                self as usize
            }
        }
    )+};
}

from_index_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize);
}
pub mod invertible {
pub trait Invertible {
    type Output;

    fn inv(&self) -> Option<Self::Output>;
}
}
pub mod wideable {
use std::convert::From;

pub trait Wideable: Sized {
    type W: From<Self>;

    fn downcast(w: Self::W) -> Self;
}

macro_rules! wideable_impl {
    ($($t: ident $w: ident),+) => {$(
        impl Wideable for $t {
            type W = $w;

            fn downcast(w: Self::W) -> Self {
                w as $t
            }
        }
    )+};
}

wideable_impl!(i64 i128, i32 i64, i16 i32, i8 i16, u64 u128, u32 u64, u16 u32, u8 u16);
}
}
pub mod num_utils {
use crate::algo_lib::numbers::num_traits::algebra::AdditionMonoid;
use crate::algo_lib::numbers::num_traits::algebra::IntegerRing;
use crate::algo_lib::numbers::num_traits::algebra::MultiplicationMonoid;
use crate::algo_lib::numbers::num_traits::as_index::AsIndex;

pub fn factorials<T: MultiplicationMonoid + Copy + AsIndex>(len: usize) -> Vec<T> {
    let mut res = Vec::new();
    if len > 0 {
        res.push(T::one());
    }
    while res.len() < len {
        res.push((*res.last().unwrap()) * T::from_index(res.len()));
    }
    res
}

pub fn powers<T: MultiplicationMonoid + Copy>(base: T, len: usize) -> Vec<T> {
    let mut res = Vec::new();
    if len > 0 {
        res.push(T::one());
    }
    while res.len() < len {
        res.push((*res.last().unwrap()) * base);
    }
    res
}

pub struct Powers<T: MultiplicationMonoid + Copy> {
    small: Vec<T>,
    big: Vec<T>,
}

impl<T: MultiplicationMonoid + Copy> Powers<T> {
    pub fn new(base: T, len: usize) -> Self {
        let small = powers(base, len);
        let big = powers(small[len - 1] * base, len);
        Self { small, big }
    }

    pub fn power(&self, exp: usize) -> T {
        debug_assert!(exp < self.small.len() * self.small.len());
        self.big[exp / self.small.len()] * self.small[exp % self.small.len()]
    }
}

pub fn factorial<T: MultiplicationMonoid + AsIndex>(n: usize) -> T {
    let mut res = T::one();
    for i in 1..=n {
        res *= T::from_index(i);
    }
    res
}

pub trait PartialSums<T> {
    fn partial_sums(&self) -> Vec<T>;
}

impl<T: AdditionMonoid + Copy> PartialSums<T> for [T] {
    fn partial_sums(&self) -> Vec<T> {
        let mut res = Vec::with_capacity(self.len() + 1);
        res.push(T::zero());
        for i in self.iter() {
            res.push(*res.last().unwrap() + *i);
        }
        res
    }
}

pub trait UpperDiv {
    fn upper_div(self, other: Self) -> Self;
}

impl<T: IntegerRing + Copy> UpperDiv for T {
    fn upper_div(self, other: Self) -> Self {
        (self + other - Self::one()) / other
    }
}
}
}
}
fn main() {
    let mut sin = std::io::stdin();
    let input = algo_lib::io::input::Input::new(&mut sin);
    let mut stdout = std::io::stdout();
    let output = algo_lib::io::output::Output::new(&mut stdout);
    solution::run(input, output);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 2176kb

input:

3
4 9 5

output:

4

result:

ok "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 2160kb

input:

2
100 100

output:

2

result:

ok "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 2092kb

input:

8
3 2 6 3 1 2 4 5

output:

11520

result:

ok "11520"

Test #4:

score: 0
Accepted
time: 0ms
memory: 2136kb

input:

2
93 93

output:

2

result:

ok "2"

Test #5:

score: 0
Accepted
time: 0ms
memory: 2108kb

input:

2
62 45

output:

0

result:

ok "0"

Test #6:

score: 0
Accepted
time: 0ms
memory: 2160kb

input:

3
32 68 36

output:

4

result:

ok "4"

Test #7:

score: 0
Accepted
time: 0ms
memory: 2108kb

input:

3
27 2 25

output:

4

result:

ok "4"

Test #8:

score: 0
Accepted
time: 0ms
memory: 2552kb

input:

10
38 27 36 88 77 25 73 44 11 21

output:

126720

result:

ok "126720"

Test #9:

score: 0
Accepted
time: 0ms
memory: 2148kb

input:

10
93 78 29 81 14 20 18 71 85 48

output:

0

result:

ok "0"

Test #10:

score: 0
Accepted
time: 0ms
memory: 2200kb

input:

9
57 19 88 13 55 43 27 10 74

output:

5760

result:

ok "5760"

Test #11:

score: 0
Accepted
time: 0ms
memory: 2204kb

input:

10
80 1 44 85 32 85 3 4 80 45

output:

0

result:

ok "0"

Test #12:

score: 0
Accepted
time: 0ms
memory: 2160kb

input:

10
56 72 93 39 70 78 3 10 84 48

output:

0

result:

ok "0"

Test #13:

score: 0
Accepted
time: 0ms
memory: 2468kb

input:

10
2 58 36 81 100 85 11 39 24 50

output:

118080

result:

ok "118080"

Test #14:

score: 0
Accepted
time: 0ms
memory: 2224kb

input:

10
70 23 3 26 98 18 63 32 22 25

output:

158400

result:

ok "158400"

Test #15:

score: 0
Accepted
time: 0ms
memory: 2156kb

input:

10
42 92 12 71 85 68 78 89 98 30

output:

0

result:

ok "0"

Test #16:

score: 0
Accepted
time: 0ms
memory: 2072kb

input:

10
26 5 25 35 77 46 81 13 73 32

output:

0

result:

ok "0"

Test #17:

score: 0
Accepted
time: 0ms
memory: 2424kb

input:

10
37 43 7 51 89 86 84 26 28 15

output:

103680

result:

ok "103680"

Test #18:

score: 0
Accepted
time: 19ms
memory: 89300kb

input:

58
84 96 24 20 3 10 27 57 98 49 32 52 67 18 100 6 100 4 4 88 24 77 75 95 18 83 58 75 71 99 18 53 68 65 76 37 51 19 65 63 28 59 84 59 80 73 83 41 96 30 96 5 13 56 92 84 30 72

output:

670239800

result:

ok "670239800"

Test #19:

score: 0
Accepted
time: 0ms
memory: 2128kb

input:

46
56 33 63 4 25 2 42 41 58 22 98 76 53 94 52 69 40 1 56 43 41 56 40 65 81 91 89 68 36 78 38 14 84 77 28 27 76 8 62 54 15 11 15 52 68 87

output:

0

result:

ok "0"

Test #20:

score: 0
Accepted
time: 0ms
memory: 2344kb

input:

55
55 49 60 49 90 95 61 61 9 5 81 63 6 70 52 64 14 87 18 87 35 19 97 20 70 11 73 48 69 19 55 23 3 73 34 68 45 30 66 37 97 75 71 8 42 91 15 63 86 63 92 48 11 53 3

output:

0

result:

ok "0"

Test #21:

score: 0
Accepted
time: 0ms
memory: 2156kb

input:

44
10 24 66 44 89 40 47 89 87 62 30 32 95 65 81 52 10 66 25 81 19 21 35 18 49 84 60 18 87 69 19 31 38 29 53 60 73 49 71 95 48 13 48 99

output:

0

result:

ok "0"

Test #22:

score: 0
Accepted
time: 0ms
memory: 2264kb

input:

61
39 96 26 73 57 39 47 84 15 54 33 83 52 37 66 66 99 21 29 17 51 74 38 43 71 83 41 86 38 96 12 55 77 70 47 76 28 78 15 40 41 4 12 62 91 5 50 87 71 42 15 67 91 88 54 31 67 90 2 15 50

output:

0

result:

ok "0"

Test #23:

score: 0
Accepted
time: 44ms
memory: 135760kb

input:

69
32 71 20 89 72 81 99 62 46 44 96 33 84 99 16 32 14 10 52 46 3 9 9 41 84 50 14 56 12 15 79 68 72 90 53 54 96 3 100 58 12 74 93 14 8 28 76 86 19 87 92 23 86 93 5 22 15 87 72 92 2 74 58 2 89 43 11 58 11

output:

297754781

result:

ok "297754781"

Test #24:

score: 0
Accepted
time: 14ms
memory: 65668kb

input:

54
50 84 44 63 83 28 48 97 13 75 41 70 2 6 35 95 6 61 77 93 56 84 32 5 83 51 82 71 39 35 38 96 48 35 89 52 49 4 5 50 55 53 86 92 3 17 9 76 9 54 1 67 74 21

output:

715843927

result:

ok "715843927"

Test #25:

score: 0
Accepted
time: 18ms
memory: 89444kb

input:

60
14 27 76 29 43 86 85 61 58 38 59 66 63 99 43 43 38 63 25 82 54 58 39 13 43 81 27 90 51 67 23 56 46 26 11 90 57 39 1 5 97 14 54 78 77 25 77 94 15 56 30 44 71 32 88 2 94 16 23 40

output:

959316858

result:

ok "959316858"

Test #26:

score: 0
Accepted
time: 0ms
memory: 2228kb

input:

56
62 53 6 12 17 99 84 81 68 95 67 68 9 38 11 9 68 100 6 57 37 68 16 27 48 98 26 73 64 60 19 3 98 31 79 34 22 41 24 25 60 3 60 16 75 48 45 78 73 10 89 75 72 71 78 23

output:

0

result:

ok "0"

Test #27:

score: 0
Accepted
time: 75ms
memory: 332228kb

input:

92
84 6 82 67 94 28 67 17 58 88 80 30 74 85 17 49 76 73 15 72 77 79 74 35 64 16 61 54 38 25 68 76 91 11 83 28 58 47 39 44 2 92 68 83 23 83 95 28 78 44 62 95 62 43 31 38 50 38 25 93 19 40 79 72 56 59 9 25 24 67 20 2 25 28 49 60 30 45 10 36 90 73 67 94 20 38 71 89 68 32 56 70

output:

338893764

result:

ok "338893764"

Test #28:

score: 0
Accepted
time: 3ms
memory: 21360kb

input:

100
4 2 4 2 3 4 2 4 2 1 3 1 2 1 2 2 3 2 1 2 1 2 1 2 4 4 4 1 3 2 2 2 3 1 2 3 4 1 2 3 3 2 1 1 3 3 3 1 2 2 1 2 1 3 4 3 3 2 2 4 4 1 2 3 3 4 4 1 4 2 3 4 4 2 3 3 2 2 3 2 3 1 4 1 3 2 3 4 2 2 1 1 2 2 1 3 2 3 4 2

output:

572766636

result:

ok "572766636"

Test #29:

score: 0
Accepted
time: 7ms
memory: 21612kb

input:

100
1 1 1 1 2 4 2 1 4 3 2 2 2 4 2 2 1 1 2 1 3 1 1 4 3 4 4 3 1 3 1 2 4 3 4 3 4 3 1 4 3 1 3 1 2 2 1 1 2 1 3 4 3 4 2 3 1 1 4 4 4 1 3 2 3 4 4 4 2 3 3 2 4 1 1 3 4 4 3 2 2 2 1 4 3 2 3 4 1 1 3 2 4 2 4 1 1 1 4 3

output:

165206805

result:

ok "165206805"

Test #30:

score: 0
Accepted
time: 7ms
memory: 22664kb

input:

100
2 4 1 3 4 2 2 4 1 2 4 3 1 1 4 1 4 1 4 3 2 4 3 2 2 4 4 4 3 2 1 1 1 4 3 1 4 4 1 3 3 1 4 4 3 2 2 1 3 3 4 1 1 4 3 1 2 4 1 2 1 4 4 4 1 3 1 3 2 1 3 2 3 2 2 2 2 4 4 3 3 4 1 4 4 4 3 4 3 1 2 2 2 2 2 4 1 3 3 2

output:

76147012

result:

ok "76147012"

Test #31:

score: 0
Accepted
time: 0ms
memory: 22408kb

input:

99
3 3 3 2 3 4 3 3 3 1 2 2 1 3 4 2 2 3 2 2 4 3 3 4 3 3 3 3 3 4 2 1 2 1 2 2 3 4 3 4 1 3 4 3 4 3 1 4 3 2 3 3 2 3 3 2 2 2 4 1 3 1 2 3 1 1 4 4 4 2 4 1 4 4 4 2 4 3 2 3 2 4 2 2 1 3 1 4 4 1 2 1 2 1 2 4 3 2 2

output:

366402822

result:

ok "366402822"

Test #32:

score: 0
Accepted
time: 3ms
memory: 20360kb

input:

99
3 1 4 1 1 1 4 4 2 1 2 3 4 2 3 1 4 2 1 2 2 4 3 3 3 1 2 4 3 3 1 1 1 1 2 4 1 4 3 3 1 1 4 2 3 4 3 3 2 2 4 4 4 1 1 1 1 1 3 3 3 1 4 4 1 4 1 1 4 1 3 1 4 1 1 3 2 4 3 2 1 1 1 4 3 4 2 3 3 4 1 2 1 2 3 4 3 1 2

output:

597470544

result:

ok "597470544"

Test #33:

score: 0
Accepted
time: 7ms
memory: 22668kb

input:

99
4 4 4 3 1 3 1 1 2 3 1 2 4 3 2 4 3 4 4 3 3 3 4 4 4 3 4 1 4 2 4 3 2 4 4 3 2 1 1 4 2 2 3 3 1 1 2 1 2 3 3 4 1 1 4 1 4 3 1 2 1 3 4 2 2 4 2 4 4 2 1 4 4 2 1 3 3 3 3 4 4 2 1 2 2 3 2 3 4 4 4 3 2 1 3 2 3 2 1

output:

302222618

result:

ok "302222618"

Test #34:

score: 0
Accepted
time: 103ms
memory: 388188kb

input:

99
90 96 38 36 93 81 38 52 90 17 58 25 29 28 63 33 67 32 59 87 71 88 8 10 80 66 50 38 59 7 86 91 37 82 68 70 75 14 60 67 24 16 42 29 19 61 8 72 53 13 84 98 69 23 80 85 77 88 13 78 50 81 79 57 3 29 19 17 36 4 18 58 28 49 23 77 5 2 71 24 90 57 99 42 21 27 40 18 73 55 25 7 59 79 27 63 85 56 20

output:

219088716

result:

ok "219088716"

Test #35:

score: 0
Accepted
time: 131ms
memory: 400548kb

input:

99
51 94 96 4 71 49 53 99 35 22 97 78 91 33 15 72 54 27 91 95 12 5 79 4 50 28 43 42 19 67 41 60 35 35 97 45 24 62 66 45 5 82 2 33 83 3 79 32 13 47 84 59 91 47 72 48 33 88 80 8 84 14 72 97 41 91 96 56 94 41 31 56 27 36 44 53 46 20 65 98 80 49 13 3 14 53 71 81 9 92 92 51 19 17 31 15 23 70 80

output:

918199689

result:

ok "918199689"

Test #36:

score: 0
Accepted
time: 122ms
memory: 364864kb

input:

99
33 61 30 2 85 2 27 35 64 47 53 94 63 87 58 47 75 35 88 45 100 45 45 33 52 10 26 91 3 48 9 94 68 39 20 45 65 33 31 8 97 12 10 93 44 2 9 62 43 100 98 2 50 61 31 63 5 43 39 55 4 71 9 73 76 14 33 59 36 81 20 60 34 35 61 53 4 34 94 32 97 47 3 46 26 24 7 43 68 44 73 11 83 26 85 53 38 99 73

output:

914166196

result:

ok "914166196"

Test #37:

score: 0
Accepted
time: 0ms
memory: 2156kb

input:

99
84 40 73 93 91 15 94 18 83 43 49 48 71 29 79 18 21 64 46 35 22 20 21 57 75 59 29 52 55 4 6 49 33 75 59 92 52 22 40 64 96 100 62 24 16 70 79 80 71 30 72 63 55 90 63 40 34 48 69 48 43 47 94 71 46 32 15 43 12 71 86 73 71 22 83 89 88 55 54 44 63 60 28 59 71 74 28 3 9 79 83 44 20 5 13 18 75 7 95

output:

0

result:

ok "0"

Test #38:

score: 0
Accepted
time: 0ms
memory: 2104kb

input:

99
54 36 52 35 13 33 92 99 77 54 76 3 21 92 84 72 20 60 35 22 6 20 25 89 85 61 33 15 31 16 65 81 79 93 26 54 28 97 16 14 4 5 77 58 42 15 94 21 31 50 45 15 72 38 86 96 34 28 21 54 37 82 100 50 53 66 67 1 13 23 57 27 11 57 72 8 30 97 38 2 14 47 45 98 48 24 100 86 64 37 87 82 74 89 29 94 76 25 39

output:

0

result:

ok "0"

Test #39:

score: 0
Accepted
time: 0ms
memory: 2108kb

input:

100
38 3 61 14 72 10 96 24 28 77 34 78 5 21 11 16 18 29 17 39 25 56 63 84 82 8 30 26 17 40 37 62 15 100 58 92 44 3 71 28 13 72 70 11 75 13 58 98 72 8 24 51 8 20 89 44 2 23 99 73 65 26 57 22 59 70 19 35 33 22 26 80 29 1 76 9 28 69 6 11 5 28 77 97 49 50 62 84 45 4 99 19 55 68 28 40 51 86 5 91

output:

0

result:

ok "0"

Test #40:

score: 0
Accepted
time: 0ms
memory: 2068kb

input:

100
12 11 4 4 75 79 94 99 26 48 38 96 98 62 70 81 50 24 53 47 12 46 34 71 42 89 55 14 9 59 75 17 11 99 11 4 23 23 30 68 35 20 67 15 57 98 65 33 18 36 93 81 49 4 4 53 33 4 68 2 35 81 12 11 43 55 92 60 60 56 29 99 82 48 92 54 1 39 14 71 33 3 94 84 31 15 99 72 28 30 85 35 26 67 59 34 49 11 66 82

output:

0

result:

ok "0"

Test #41:

score: 0
Accepted
time: 125ms
memory: 462520kb

input:

100
91 60 71 71 66 94 35 70 5 38 2 47 99 8 44 87 73 39 54 56 58 66 93 54 63 47 71 35 70 13 66 88 8 88 40 71 80 15 57 29 76 58 96 59 39 97 43 10 79 61 40 67 71 15 33 13 8 87 87 52 71 82 94 60 83 84 23 96 75 86 4 32 40 5 97 78 45 100 32 82 33 60 28 98 36 24 93 78 25 63 90 89 40 27 51 65 100 9 92 95

output:

858791620

result:

ok "858791620"

Test #42:

score: 0
Accepted
time: 139ms
memory: 437784kb

input:

100
52 38 75 88 35 46 11 73 78 34 82 69 24 72 52 88 99 57 94 10 26 61 10 95 49 8 83 61 88 20 44 97 52 9 70 55 48 63 60 84 96 21 43 13 39 30 39 94 53 36 86 13 45 25 89 5 100 91 95 49 82 2 30 86 82 26 9 48 23 35 71 97 66 90 82 65 4 32 48 45 98 91 46 93 58 35 42 25 28 27 94 45 60 1 77 83 74 37 62 47

output:

738427555

result:

ok "738427555"

Test #43:

score: 0
Accepted
time: 129ms
memory: 421880kb

input:

100
66 65 14 59 31 92 57 54 15 53 87 60 92 75 43 32 98 63 15 97 79 15 68 54 9 92 82 2 62 100 18 95 96 22 35 89 88 4 11 49 68 63 29 22 5 66 16 46 34 66 44 30 24 28 84 80 87 17 2 44 92 36 75 95 49 86 86 52 56 49 95 57 43 43 82 84 19 70 74 37 5 70 33 50 16 84 90 25 7 68 75 62 59 4 7 54 45 28 49 66

output:

699293570

result:

ok "699293570"

Test #44:

score: 0
Accepted
time: 0ms
memory: 9944kb

input:

100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

output:

35305197

result:

ok "35305197"

Test #45:

score: 0
Accepted
time: 96ms
memory: 344960kb

input:

99
33 47 61 23 17 22 65 2 57 75 32 72 54 20 59 21 5 53 31 51 50 3 62 44 66 82 71 75 74 72 78 43 34 6 64 30 17 4 48 85 52 49 36 41 79 68 44 45 39 63 63 70 16 84 24 84 18 14 12 28 15 67 37 34 76 46 5 14 60 10 13 80 81 8 58 73 27 84 26 40 19 56 42 7 55 75 11 35 25 83 19 81 38 8 77 69 9 29 59

output:

905104398

result:

ok "905104398"

Test #46:

score: 0
Accepted
time: 98ms
memory: 348120kb

input:

99
67 24 58 28 1 51 46 63 17 38 7 60 29 13 40 57 71 82 86 6 19 5 12 70 55 22 66 44 53 27 59 65 2 32 88 50 69 18 1 48 43 9 74 45 33 31 60 23 34 52 8 76 77 79 16 11 49 87 54 30 15 4 42 83 20 88 36 64 85 25 78 85 88 47 48 61 26 73 14 39 14 56 10 81 21 68 14 37 66 72 75 3 80 35 41 23 62 27 84

output:

312550131

result:

ok "312550131"

Test #47:

score: 0
Accepted
time: 122ms
memory: 309376kb

input:

100
25 26 19 32 5 3 24 55 35 58 76 43 17 29 77 5 43 73 45 21 65 4 7 62 37 54 37 44 14 21 63 49 66 14 53 50 13 57 41 63 6 17 27 23 9 11 12 77 60 1 42 46 52 56 8 8 30 18 9 63 48 22 10 36 77 52 79 78 70 34 37 51 69 72 33 75 59 62 74 47 68 31 14 16 61 71 28 38 39 64 20 23 23 9 2 7 40 67 35 15

output:

513464322

result:

ok "513464322"

Test #48:

score: 0
Accepted
time: 106ms
memory: 364212kb

input:

100
22 40 75 44 53 17 48 76 38 36 82 72 10 63 50 70 46 52 60 37 42 26 56 51 66 35 21 9 80 49 70 65 31 82 73 32 23 5 67 39 47 65 62 71 77 83 61 81 11 62 54 41 8 24 14 42 16 7 19 60 27 59 43 12 78 58 45 6 34 62 13 64 25 68 74 29 84 3 18 15 20 58 69 30 83 33 2 55 6 57 82 80 4 79 28 19 30 19 73 82

output:

294800349

result:

ok "294800349"

Test #49:

score: 0
Accepted
time: 47ms
memory: 798888kb

input:

100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ...

output:

35305197

result:

ok "35305197"

Test #50:

score: 0
Accepted
time: 120ms
memory: 404620kb

input:

100
92 79 24 69 100 10 38 53 3 21 73 32 7 27 37 28 49 51 86 91 77 89 5 55 19 81 47 65 57 44 72 50 6 64 11 29 83 60 74 87 36 15 68 93 62 12 34 4 43 80 42 56 78 1 9 70 88 66 18 20 17 94 33 39 99 46 95 35 31 90 2 98 84 82 59 97 85 45 52 8 63 48 25 16 41 76 54 23 13 61 14 58 75 30 40 26 67 71 96 22

output:

854040496

result:

ok "854040496"

Test #51:

score: 0
Accepted
time: 0ms
memory: 2068kb

input:

100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ...

output:

0

result:

ok "0"

Test #52:

score: 0
Accepted
time: 44ms
memory: 779720kb

input:

100
97 100 99 99 95 98 99 99 97 97 100 97 97 96 98 96 97 95 95 96 95 99 99 99 95 97 99 100 95 97 99 97 95 96 98 95 98 97 98 99 96 97 97 95 100 99 98 100 100 100 95 95 97 99 100 95 97 100 100 95 99 96 95 95 95 97 99 95 100 98 95 98 98 100 98 96 97 100 99 100 99 95 99 97 98 100 100 99 96 98 95 100 97 ...

output:

640494053

result:

ok "640494053"

Test #53:

score: 0
Accepted
time: 39ms
memory: 780060kb

input:

100
100 100 95 95 98 98 100 96 99 95 99 96 97 100 98 99 96 99 97 98 96 96 95 98 97 97 99 98 100 95 97 97 100 98 99 100 98 99 97 96 99 98 100 98 95 96 99 99 97 96 99 100 98 99 97 95 100 97 99 96 98 98 95 96 97 95 98 99 99 96 97 96 98 96 100 98 96 97 97 95 97 100 99 99 100 98 98 96 95 97 100 100 99 97...

output:

525329040

result:

ok "525329040"

Extra Test:

score: 0
Extra Test Passed