Submission #38083965


Source Code Expand

// -*- coding:utf-8-unix -*-
// rustup doc --std --toolchain 1.42.0

#![allow(unused_imports)]
#![allow(unused_macros)]
use bitset_fixed::BitSet;
use itertools::*;
use num::integer::*;
use petgraph::algo::*;
use petgraph::graph::{DiGraph, Graph, NodeIndex, UnGraph};
use petgraph::unionfind::UnionFind;
use petgraph::visit::{
    Bfs, Dfs, EdgeRef, IntoEdges, NodeCount, NodeIndexable, VisitMap, Visitable,
};
//use proconio::{input, marker::{Bytes, Chars, Isize1, Usize1}, source::{auto::AutoSource, line::LineSource, once::OnceSource}};
use rand::{
    distributions::WeightedIndex,
    prelude::{thread_rng, Distribution},
    seq::SliceRandom,
    Rng,
};
use regex::Regex;
use std::collections::*;
use std::io::{stderr, stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
use superslice::Ext;

pub fn solve() {
    //let tins = std::time::Instant::now();
    //let mut durs = Vec::with_capacity(16);
    use fastproconio::*;
    let stdin = std::io::stdin();
    let mut source = ProconIBufIter::new(stdin.lock());
    macro_rules! fread {($t:tt) =>{{fread_value!(source, $t)}};}
    macro_rules! finput {($($r:tt)*)=>{finput_inner!{source, $($r)*}};}
    let mut out = std::io::stdout();
    let mut obuf = ProconWriteBuffer::with_capacity(1 << 26);
    //durs.push((tins.elapsed(), String::from("initial")));
    //let mut out = std::io::BufWriter::new(out.lock());
    //let err = std::io::stderr();
    //let mut err = std::io::BufWriter::new(err.lock());
    finput! {
        n: usize,
    }
    //durs.push((tins.elapsed(), String::from("input")));
    let mut sum = 0;
    let sumv = (0..(n / 2 + 1)).map(|_| {
        let psum = sum;
        sum += fread!(u64);
        psum
    }).collect::<Vec<_>>();
    let mut dp = (0..n).map(|i| sumv[i / 2] + sumv[(i + 1) / 2]).collect::<Vec<_>>();
    for i in 1..n {
        let ival = unsafe { *dp.get_unchecked(i) };
        for j in i..((n-i).saturating_sub(1)) {
            let jval = unsafe { *dp.get_unchecked(j) };
            unsafe { dp.get_unchecked_mut(i + j + 1).chmax(ival + jval) };
        }
    }
    obuf.uint(dp[n - 1]);
    obuf.lf();
    obuf.write_all(&mut out);
    //let _ = std::io::Write::flush(&mut out);
    //durs.push((tins.elapsed(), String::from("output")));
    //for (dur, s) in durs.iter() { eprintln!("{:.6} {}", dur.as_secs_f64(), s); }
    //let _ = writeln!(&mut err, "{}", count);
    //let _ = std::io::Write::flush(&mut err);
}

pub fn main() {
    const USE_THREAD: bool = false;
    if USE_THREAD {
        // In order to avoid potential stack overflow, spawn a new thread.
        let stack_size = 134_217_728; // 128 MB
        let thd = std::thread::Builder::new().stack_size(stack_size);
        thd.spawn(|| solve()).unwrap().join().unwrap();
    } else {
        solve()
    }
}

/// chmax, chmin sugar syntax
trait Change {
    fn chmax(&mut self, x: Self);
    fn chmin(&mut self, x: Self);
}
impl<T: PartialOrd> Change for T {
    fn chmax(&mut self, x: T) {
        if *self < x {
            *self = x;
        }
    }
    fn chmin(&mut self, x: T) {
        if *self > x {
            *self = x;
        }
    }
}
pub mod fastproconio {
    /// input macros based on tanakh's input macro / proconio-rs.
    /// tanakh's input macro: <https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8>
    /// proconio-rs: <https://docs.rs/proconio/0.3.8/proconio/>
    /// this macro recieve `Iterator<Item = u8>` input source, except for Bytes/Chars/String read
    /// ProconIBufIter receive `std::io::BufRead` trait. (`std::io::StdinLock`, `std::io::BufReader`, `&[u8]`, etc.)
    #[macro_export]
    macro_rules! finput_inner {
        ($iter:expr) => {};
        ($iter:expr, ) => {};
        ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
            let mut $var = fread_value!($iter, $t);
            finput_inner!{$iter $($r)*}
        };
        ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
            let $var = fread_value!($iter, $t);
            finput_inner!{$iter $($r)*}
        };
    }
    #[macro_export]
    macro_rules! fread_value {
        ($iter:expr, ( $($t:tt),* )) => { ( $(fread_value!($iter, $t)),* ) };
        ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| fread_value!($iter, $t)).collect::<Vec<_>>() };
        ($iter:expr, u128) => { $iter.parse_uint::<u128>() };
        ($iter:expr, usize) => { $iter.parse_uint::<usize>() };
        ($iter:expr, usize1) => { $iter.parse_uint::<usize>() - 1 };
        ($iter:expr, u64) => { $iter.parse_uint::<u64>() };
        ($iter:expr, u64_1) => { $iter.parse_uint::<u64>() - 1 };
        ($iter:expr, u32) => { $iter.parse_uint::<u32>() };
        ($iter:expr, u32_1) => { $iter.parse_uint::<u32>() - 1 };
        ($iter:expr, u16) => { $iter.parse_uint::<u16>() };
        ($iter:expr, u8) => { $iter.parse_uint::<u8>() };
        ($iter:expr, i128) => { $iter.parse_iint::<i128>() };
        ($iter:expr, isize) => { $iter.parse_iint::<isize>() };
        ($iter:expr, i64) => { $iter.parse_iint::<i64>() };
        ($iter:expr, i32) => { $iter.parse_iint::<i32>() };
        ($iter:expr, i16) => { $iter.parse_iint::<i16>() };
        ($iter:expr, i8) => { $iter.parse_iint::<i16>() as i8 };
        ($iter:expr, byte) => { $iter.get_ascii_byte() };
        ($iter:expr, Bytes) => {{ let mut v = vec![];$iter.get_ascii_bytes(&mut v);v }};
        ($iter:expr, Chars) => {{ let mut v = vec![];$iter.get_ascii_chars(&mut v);v }};
        ($iter:expr, String) => {{ let mut v = vec![];$iter.get_ascii_bytes(&mut v);unsafe { std::string::String::from_utf8_unchecked(v) }}};
        ($iter:expr, LineBytes) => {{ let mut v = vec![];$iter.get_ascii_line_bytes(&mut v).and(Some(v)).unwrap() }};
        ($iter:expr, LineBytesTrim) => {{ let mut v = vec![];$iter.get_ascii_line_bytes_trim(&mut v);v }};
        ($iter:expr, LineString) => {{ let mut v = vec![];$iter.get_ascii_line_bytes(&mut v);unsafe { std::string::String::from_utf8_unchecked(v) }}};
        ($iter:expr, LineStringTrim) => {{ let mut v = vec![];$iter.get_ascii_line_bytes_trim(&mut v);unsafe { std::string::String::from_utf8_unchecked(v) }}};
        ($iter:expr, Utf8Bytes) => {{ let mut v = vec![];$iter.get_utf8_bytes(&mut v);v }};
        ($iter:expr, Utf8String) => {{ let mut v = vec![];$iter.get_utf8_bytes(&mut v);unsafe { std::string::String::from_utf8_unchecked(v) }}};
        ($iter:expr, Utf8LineBytes) => {{ let mut v = vec![];$iter.get_utf8_line_bytes(&mut v);v }};
        ($iter:expr, Utf8LineBytesTrim) => {{ let mut v = vec![];$iter.get_utf8_line_bytes_trim(&mut v);v }};
        ($iter:expr, Utf8LineString) => {{ let mut v = vec![];$iter.get_utf8_line_bytes(&mut v);unsafe { std::string::String::from_utf8_unchecked(v) }}};
        ($iter:expr, Utf8LineStringTrim) => {{ let mut v = vec![];$iter.get_utf8_line_bytes_trim(&mut v);unsafe { std::string::String::from_utf8_unchecked(v) }}};
        ($iter:expr, $t:ty) => {{ let mut v = vec![];unsafe { std::string::String::from_utf8_unchecked($iter.get_utf8_bytes(&mut v).and(Some(v)).unwrap()) }.parse::<$t>().expect("Parse error") }};
    }

    /// Interaction with `std::io::BufRead` Trait, Implementation of `Iterator<Item = u8>`
    pub struct ProconIBufIter<R: std::io::BufRead> {
        inner: R,
        raw: *const u8,
        len: usize,
        ptr: *const u8,
        end: *const u8,
    }
    unsafe fn ptr_offset_u8(dist: *const u8, origin: *const u8) -> usize {
        // Rust 1.47.0 or later, `dist.offset_from(origin) as usize`
        // <https://doc.rust-lang.org/std/primitive.pointer.html#method.offset_from>
        dist as usize - origin as usize
    }
    impl<R: std::io::BufRead> ProconIBufIter<R> {
        /// consume raw buffer
        #[allow(unused)]
        fn consume(&mut self, amt: usize) {
            let remain = unsafe { ptr_offset_u8(self.end, self.ptr) };
            assert!(remain >= amt);
            unsafe {
                self.ptr = self.ptr.add(amt);
            }
        }
        /// read when buffer is empty
        unsafe fn inner_read(&mut self) -> bool {
            assert!(self.is_empty());
            self.inner.consume(self.len);
            let buffer = self.inner.fill_buf().unwrap();
            let raw = buffer.as_ptr();
            let len = buffer.len();
            self.raw = raw;
            self.len = len;
            self.ptr = raw;
            self.end = raw.add(len);
            self.len > 0
        }
        /// check end of buffer
        fn is_empty(&self) -> bool {
            self.ptr == self.end
        }
        /// Interaction with `std::io::BufRead` Trait, Implementation of `Iterator<Item = u8>`
        pub fn new(inner: R) -> Self {
            let mut bufiter = Self {
                inner,
                raw: std::ptr::null(),
                len: 0,
                ptr: std::ptr::null(),
                end: std::ptr::null(),
            };
            unsafe { bufiter.inner_read() };
            bufiter
        }
        /// next(), but return empty value
        #[allow(unused)]
        fn next_unread(&mut self) -> Option<()> {
            if self.is_empty() && unsafe { !self.inner_read() } {
                return None;
            }
            unsafe {
                self.ptr = self.ptr.add(1);
            }
            return Some(());
        }
        /// get now pointer & increment pointer
        unsafe fn next_unchecked(&mut self) -> u8 {
            let p = self.ptr;
            self.ptr = p.add(1);
            *p
        }
        /// peek
        #[allow(unused)]
        fn peek(&mut self) -> Option<&u8> {
            if !self.is_empty() || unsafe { self.inner_read() } {
                unsafe { Some(&*self.ptr) }
            } else {
                None
            }
        }
        /// raw buffer
        #[allow(unused)]
        fn raw_buf(&mut self) -> &[u8] {
            if self.is_empty() {
                unsafe {
                    self.inner_read();
                }
            }
            unsafe { std::slice::from_raw_parts(self.ptr, ptr_offset_u8(self.end, self.ptr)) }
        }
        /// skip unmatch bytes
        fn skipuntil_bytes_fn<F: FnMut(u8) -> bool>(&mut self, f: &mut F) -> bool {
            loop {
                let mut ptr = self.ptr;
                while ptr != self.end {
                    if f(unsafe { *ptr }) {
                        self.ptr = ptr;
                        return true;
                    }
                    unsafe {
                        ptr = ptr.add(1);
                    }
                }
                self.ptr = ptr;
                if unsafe { !self.inner_read() } {
                    return false;
                }
            }
        }
    }
    impl<R: std::io::BufRead> Iterator for ProconIBufIter<R> {
        type Item = u8;
        /// fetch next byte
        fn next(&mut self) -> Option<Self::Item> {
            if !self.is_empty() || unsafe { self.inner_read() } {
                unsafe { Some(self.next_unchecked()) }
            } else {
                None
            }
        }
        /// remain size hint
        fn size_hint(&self) -> (usize, Option<usize>) {
            (unsafe { ptr_offset_u8(self.end, self.ptr) }, None)
        }
    }
    impl<R: std::io::BufRead> Drop for ProconIBufIter<R> {
        /// Saving the pointer on interruption
        fn drop(&mut self) {
            self.inner
                .consume(unsafe { ptr_offset_u8(self.ptr, self.raw) });
        }
    }
    /// speed frenzy input parser for program compete (fail parse may cause undefined behavior)
    pub trait ProconParse {
        /// parse unsigned integer
        fn parse_uint<
            U: Copy
                + std::cmp::Ord
                + std::ops::BitAnd<Output = U>
                + std::ops::Add<Output = U>
                + std::ops::Sub<Output = U>
                + std::ops::Mul<Output = U>
                + std::convert::From<u8>,
        >(
            &mut self,
        ) -> U;
        /// parse signed integer
        fn parse_iint<
            I: Copy
                + std::cmp::Ord
                + std::ops::BitAnd<Output = I>
                + std::ops::Add<Output = I>
                + std::ops::Sub<Output = I>
                + std::ops::Mul<Output = I>
                + std::convert::From<u8>
                + std::ops::Neg<Output = I>,
        >(
            &mut self,
        ) -> I;
        /// get char (printable ascii char)
        fn parse_byte(&mut self) -> u8;
        /// get chars (printable ascii word)
        fn parse_bytes(&mut self) -> Vec<u8>;
        /// get line chars (sp+printable ascii)
        fn parse_line_bytes(&mut self) -> Vec<u8>;
        /// get line chars (trimed sp+printable ascii)
        fn parse_line_bytes_trim(&mut self) -> Vec<u8>;
    }
    /// speed frenzy input byte reader for program compete
    pub trait ProconBytes {
        /// get bytes
        fn get_bytes_fn<F: Fn(u8) -> bool>(&mut self, vec: &mut Vec<u8>, f: &mut F);
        /// get chars
        fn get_ascii_chars_fn<F: Fn(u8) -> bool>(&mut self, vec: &mut Vec<char>, f: &mut F);
        /// get byte (printable ascii char)
        fn get_ascii_byte(&mut self) -> u8;
        /// get bytes (printable ascii word)
        fn get_ascii_bytes(&mut self, vec: &mut Vec<u8>);
        /// get chars (printable ascii word)
        fn get_ascii_chars(&mut self, vec: &mut Vec<char>);
        /// get line bytes (sp+printable ascii)
        fn get_ascii_line_bytes(&mut self, vec: &mut Vec<u8>);
        /// get line bytes (trimed sp+printable ascii)
        fn get_ascii_line_bytes_trim(&mut self, vec: &mut Vec<u8>);
        /// get bytes (printable utf8 word)
        fn get_utf8_bytes(&mut self, vec: &mut Vec<u8>);
        /// get line bytes (sp+printable utf8)
        fn get_utf8_line_bytes(&mut self, vec: &mut Vec<u8>);
        /// get line bytes (trimed sp+printable utf8)
        fn get_utf8_line_bytes_trim(&mut self, vec: &mut Vec<u8>);
    }
    impl<T: Iterator<Item = u8>> ProconParse for T {
        fn parse_uint<
            U: Copy
                + std::cmp::Ord
                + std::ops::BitAnd<Output = U>
                + std::ops::Add<Output = U>
                + std::ops::Sub<Output = U>
                + std::ops::Mul<Output = U>
                + std::convert::From<u8>,
        >(
            &mut self,
        ) -> U {
            loop {
                match self.next() {
                    Some(c @ b'0'..=b'9') => {
                        let mut x = U::from(c.wrapping_sub(b'0'));
                        while let Some(c @ b'0'..=b'9') = self.next() {
                            x = x.mul(U::from(10)).add(U::from(c.wrapping_sub(b'0')));
                        }
                        break x;
                    }
                    Some(_) => continue,
                    None => unreachable!(),
                }
            }
        }
        fn parse_iint<
            I: Copy
                + std::cmp::Ord
                + std::ops::BitAnd<Output = I>
                + std::ops::Add<Output = I>
                + std::ops::Sub<Output = I>
                + std::ops::Mul<Output = I>
                + std::ops::Neg<Output = I>
                + std::convert::From<u8>,
        >(
            &mut self,
        ) -> I {
            loop {
                match self.next() {
                    Some(c @ b'0'..=b'9') => {
                        let mut x = I::from(c.wrapping_sub(b'0'));
                        while let Some(c @ b'0'..=b'9') = self.next() {
                            x = x.mul(I::from(10)).add(I::from(c.wrapping_sub(b'0')));
                        }
                        break x;
                    }
                    Some(b'-') => {
                        let mut x = if let Some(c @ b'0'..=b'9') = self.next() {
                            I::from(c.wrapping_sub(b'0')).neg()
                        } else {
                            unreachable!();
                        };
                        while let Some(c @ b'0'..=b'9') = self.next() {
                            x = x.mul(I::from(10)).sub(I::from(c.wrapping_sub(b'0')));
                        }
                        break x;
                    }
                    Some(_) => continue,
                    None => unreachable!(),
                }
            }
        }
        fn parse_byte(&mut self) -> u8 {
            loop {
                match self.next() {
                    Some(c @ b'!'..=b'~') => break c,
                    Some(_) => continue,
                    None => break b'\0',
                }
            }
        }
        fn parse_bytes(&mut self) -> Vec<u8> {
            let mut v = vec![];
            loop {
                match self.next() {
                    Some(c @ b'!'..=b'~') => {
                        v.push(c);
                        while let Some(c @ b'!'..=b'~') = self.next() {
                            v.push(c);
                        }
                        break v;
                    }
                    Some(_) => continue,
                    None => break v,
                }
            }
        }
        fn parse_line_bytes(&mut self) -> Vec<u8> {
            let mut v = vec![];
            loop {
                match self.next() {
                    Some(c @ b' '..=b'~') => {
                        v.push(c);
                        while let Some(c @ b' '..=b'~') = self.next() {
                            v.push(c);
                        }
                        break v;
                    }
                    Some(_) => continue,
                    None => break v,
                }
            }
        }
        fn parse_line_bytes_trim(&mut self) -> Vec<u8> {
            let mut v = vec![];
            loop {
                match self.next() {
                    Some(c @ b'!'..=b'~') => {
                        v.push(c);
                        while let Some(c @ b' '..=b'~') = self.next() {
                            v.push(c);
                        }
                        while v.last() == Some(&b' ') {
                            v.pop();
                        }
                        break v;
                    }
                    Some(_) => continue,
                    None => break v,
                }
            }
        }
    }
    impl<R: std::io::BufRead> ProconBytes for ProconIBufIter<R> {
        /// get bytes vector
        fn get_bytes_fn<F: Fn(u8) -> bool>(&mut self, vec: &mut Vec<u8>, f: &mut F) {
            if !self.skipuntil_bytes_fn(f) {
                return;
            }
            let begin_ptr = self.ptr;
            let mut ptr = self.ptr;
            loop {
                unsafe {
                    ptr = ptr.add(1);
                }
                if ptr == self.end {
                    self.ptr = ptr;
                    vec.extend_from_slice(unsafe {
                        std::slice::from_raw_parts(begin_ptr, ptr_offset_u8(ptr, begin_ptr))
                    });
                    break;
                }
                if !f(unsafe { *ptr }) {
                    self.ptr = ptr;
                    vec.extend_from_slice(unsafe {
                        std::slice::from_raw_parts(begin_ptr, ptr_offset_u8(ptr, begin_ptr))
                    });
                    return;
                }
            }
            if unsafe { !self.inner_read() } {
                return;
            }
            ptr = self.ptr;
            loop {
                if !f(unsafe { *ptr }) {
                    self.ptr = ptr;
                    vec.extend_from_slice(unsafe {
                        std::slice::from_raw_parts(self.raw, ptr_offset_u8(ptr, self.raw))
                    });
                    return;
                }
                unsafe {
                    ptr = ptr.add(1);
                }
                if ptr == self.end {
                    self.ptr = ptr;
                    vec.extend_from_slice(unsafe {
                        std::slice::from_raw_parts(self.raw, self.len)
                    });
                    if unsafe { !self.inner_read() } {
                        return;
                    }
                    ptr = self.ptr;
                }
            }
        }
        fn get_ascii_chars_fn<F: Fn(u8) -> bool>(&mut self, vec: &mut Vec<char>, f: &mut F) {
            if !self.skipuntil_bytes_fn(f) {
                return;
            }
            let begin_ptr = self.ptr;
            let mut ptr = self.ptr;
            loop {
                unsafe {
                    ptr = ptr.add(1);
                }
                if ptr == self.end {
                    self.ptr = ptr;
                    let len = unsafe { ptr_offset_u8(ptr, begin_ptr) };
                    vec.reserve(len);
                    let mut p = begin_ptr;
                    while p != ptr {
                        vec.push(unsafe { *p } as char);
                        p = unsafe { p.add(1) };
                    }
                    break;
                }
                if !f(unsafe { *ptr }) {
                    self.ptr = ptr;
                    let len = unsafe { ptr_offset_u8(ptr, begin_ptr) };
                    vec.reserve(len);
                    let mut p = begin_ptr;
                    while p != ptr {
                        vec.push(unsafe { *p } as char);
                        p = unsafe { p.add(1) };
                    }
                    return;
                }
            }
            if unsafe { !self.inner_read() } {
                return;
            }
            ptr = self.ptr;
            loop {
                if !f(unsafe { *ptr }) {
                    self.ptr = ptr;
                    let len = unsafe { ptr_offset_u8(ptr, self.raw) };
                    vec.reserve(len);
                    let mut p = self.raw;
                    while p != ptr {
                        vec.push(unsafe { *p } as char);
                        p = unsafe { p.add(1) };
                    }
                    return;
                }
                unsafe {
                    ptr = ptr.add(1);
                }
                if ptr == self.end {
                    self.ptr = ptr;
                    let len = unsafe { ptr_offset_u8(ptr, self.raw) };
                    vec.reserve(len);
                    let mut p = self.raw;
                    while p != ptr {
                        vec.push(unsafe { *p } as char);
                        p = unsafe { p.add(1) };
                    }
                    if unsafe { !self.inner_read() } {
                        return;
                    }
                    ptr = self.ptr;
                }
            }
        }
        fn get_ascii_byte(&mut self) -> u8 {
            loop {
                match self.next() {
                    Some(c @ b'!'..=b'~') => break c,
                    Some(_) => continue,
                    None => break b'\0',
                }
            }
        }
        fn get_ascii_bytes(&mut self, vec: &mut Vec<u8>) {
            self.get_bytes_fn(vec, &mut |c| (b'!'..=b'~').contains(&c))
        }
        fn get_ascii_chars(&mut self, vec: &mut Vec<char>) {
            self.get_ascii_chars_fn(vec, &mut |c| (b'!'..=b'~').contains(&c))
        }
        fn get_ascii_line_bytes(&mut self, vec: &mut Vec<u8>) {
            self.get_bytes_fn(vec, &mut |c| (b' '..=b'~').contains(&c))
        }
        fn get_ascii_line_bytes_trim(&mut self, vec: &mut Vec<u8>) {
            self.skipuntil_bytes_fn(&mut |c| (b'!'..=b'~').contains(&c));
            self.get_bytes_fn(vec, &mut |c| (b' '..=b'~').contains(&c));
            while vec.last() == Some(&b' ') {
                vec.pop();
            }
        }
        fn get_utf8_bytes(&mut self, vec: &mut Vec<u8>) {
            self.get_bytes_fn(vec, &mut |c| (b'!'..=0xf4).contains(&c))
        }
        fn get_utf8_line_bytes(&mut self, vec: &mut Vec<u8>) {
            self.get_bytes_fn(vec, &mut |c| (b' '..=0xf4).contains(&c))
        }
        fn get_utf8_line_bytes_trim(&mut self, vec: &mut Vec<u8>) {
            self.skipuntil_bytes_fn(&mut |c| (b'!'..=0xf4).contains(&c));
            self.get_bytes_fn(vec, &mut |c| (b' '..=0xf4).contains(&c));
            while vec.last() == Some(&b' ') {
                vec.pop();
            }
        }
    }
    /// Insufficient write buffer size causes undefined operation.
    pub struct ProconWriteBuffer(*mut u8, Vec<u8>);
    impl ProconWriteBuffer {
        pub fn with_capacity(capacity: usize) -> Self {
            let mut b = Vec::<u8>::with_capacity(capacity);
            let ptr = b.as_mut_ptr();
            Self(ptr, b)
        }
        pub fn get_mut_ptr(&self) -> *mut u8 {
            self.0
        }
        pub fn set_mut_ptr(&mut self, p: *mut u8) {
            self.0 = p;
        }
        fn decision(&mut self) {
            let bptr = self.1.as_mut_ptr();
            unsafe { self.1.set_len((self.0 as usize) - (bptr as usize)) };
        }
        pub fn reserve(&mut self, additional: usize) {
            self.decision();
            self.1.reserve(additional);
            self.0 = self.1.as_mut_ptr();
        }
        pub fn reserve_exact(&mut self, additional: usize) {
            self.decision();
            self.1.reserve_exact(additional);
            self.0 = self.1.as_mut_ptr();
        }
        pub fn uint<U>(&mut self, d: U)
        where
            U: Copy
                + std::cmp::Ord
                + std::ops::Div<Output = U>
                + std::ops::Rem<Output = U>
                + std::convert::From<u8>
                + std::convert::Into<u128>,
        {
            proconwritebuf_uint(&mut self.0, d);
        }
        pub fn uint_sp<U>(&mut self, s: &[U])
        where
            U: Copy
                + std::cmp::Ord
                + std::ops::Div<Output = U>
                + std::ops::Rem<Output = U>
                + std::convert::From<u8>
                + std::convert::Into<u128>,
        {
            let mut p = self.0;
            let mut it = s.iter();
            if let Some(&d) = it.next() {
                proconwritebuf_uint(&mut p, d);
                for &d in it {
                    proconwritebuf_sp(&mut p);
                    proconwritebuf_uint(&mut p, d);
                }
            }
            self.0 = p;
        }
        pub fn uint_splf<U>(&mut self, s: &[U])
        where
            U: Copy
                + std::cmp::Ord
                + std::ops::Div<Output = U>
                + std::ops::Rem<Output = U>
                + std::convert::From<u8>
                + std::convert::Into<u128>,
        {
            let mut p = self.0;
            let mut it = s.iter();
            if let Some(&d) = it.next() {
                proconwritebuf_uint(&mut p, d);
                for &d in it {
                    proconwritebuf_sp(&mut p);
                    proconwritebuf_uint(&mut p, d);
                }
            }
            proconwritebuf_lf(&mut p);
            self.0 = p;
        }
        pub fn usize(&mut self, d: usize) {
            proconwritebuf_uint(&mut self.0, d as u64);
        }
        pub fn usize_sp(&mut self, s: &[usize]) {
            let mut p = self.0;
            let mut it = s.iter();
            if let Some(&d) = it.next() {
                proconwritebuf_uint(&mut p, d as u64);
                for &d in it {
                    proconwritebuf_sp(&mut p);
                    proconwritebuf_uint(&mut p, d as u64);
                }
            }
            self.0 = p;
        }
        pub fn usize_splf(&mut self, s: &[usize]) {
            let mut p = self.0;
            let mut it = s.iter();
            if let Some(&d) = it.next() {
                proconwritebuf_uint(&mut p, d as u64);
                for &d in it {
                    proconwritebuf_sp(&mut p);
                    proconwritebuf_uint(&mut p, d as u64);
                }
            }
            proconwritebuf_lf(&mut p);
            self.0 = p;
        }
        pub fn iint<I>(&mut self, d: I)
        where
            I: Copy
                + std::cmp::Ord
                + std::ops::Neg<Output = I>
                + std::ops::Div<Output = I>
                + std::ops::Rem<Output = I>
                + std::convert::From<i8>
                + std::convert::Into<i128>,
        {
            proconwritebuf_iint(&mut self.0, d);
        }
        pub fn iint_sp<I>(&mut self, s: &[I])
        where
            I: Copy
                + std::cmp::Ord
                + std::ops::Neg<Output = I>
                + std::ops::Div<Output = I>
                + std::ops::Rem<Output = I>
                + std::convert::From<i8>
                + std::convert::Into<i128>,
        {
            let mut p = self.0;
            let mut it = s.iter();
            if let Some(&d) = it.next() {
                proconwritebuf_iint(&mut p, d);
                for &d in it {
                    proconwritebuf_sp(&mut p);
                    proconwritebuf_iint(&mut p, d);
                }
            }
            self.0 = p;
        }
        pub fn iint_splf<I>(&mut self, s: &[I])
        where
            I: Copy
                + std::cmp::Ord
                + std::ops::Neg<Output = I>
                + std::ops::Div<Output = I>
                + std::ops::Rem<Output = I>
                + std::convert::From<i8>
                + std::convert::Into<i128>
                + std::convert::TryInto<u8>,
        {
            let mut p = self.0;
            let mut it = s.iter();
            if let Some(&d) = it.next() {
                proconwritebuf_iint(&mut p, d);
                for &d in it {
                    proconwritebuf_sp(&mut p);
                    proconwritebuf_iint(&mut p, d);
                }
            }
            proconwritebuf_lf(&mut p);
            self.0 = p;
        }
        pub fn sp(&mut self) {
            proconwritebuf_sp(&mut self.0);
        }
        pub fn lf(&mut self) {
            proconwritebuf_lf(&mut self.0);
        }
        pub fn bytes(&mut self, s: &[u8]) {
            proconwritebuf_bytes(&mut self.0, s);
        }
        pub fn str(&mut self, s: &str) {
            proconwritebuf_str(&mut self.0, s);
        }
        pub fn string(&mut self, s: &String) {
            proconwritebuf_string(&mut self.0, s);
        }
        pub fn write_all<W>(&mut self, out: &mut W)
        where
            W: std::io::Write,
        {
            self.decision();
            let _ = out.write_all(self.1.as_slice());
            self.1.clear();
            self.0 = self.1.as_mut_ptr();
        }
    }
    pub fn proconwritebuf_uint<U>(p: &mut *mut u8, mut d: U)
    where
        U: Copy
            + std::cmp::Ord
            + std::ops::Div<Output = U>
            + std::ops::Rem<Output = U>
            + std::convert::From<u8>
            + std::convert::Into<u128>,
    {
        unsafe {
            let bptr = *p;
            let mut cptr = bptr;
            if d != U::from(0) {
                while d != U::from(0) {
                    let (q, r) = (d / U::from(10), d % U::from(10));
                    d = q;
                    *cptr = b'0' + U::into(r) as u8;
                    cptr = cptr.add(1);
                }
                *p = cptr;
                let mut lptr = bptr;
                let mut rptr = cptr.sub(1);
                while (lptr as usize) < (rptr as usize) {
                    let (dr, dl) = (*lptr, *rptr);
                    *lptr = dl;
                    *rptr = dr;
                    lptr = lptr.add(1);
                    rptr = rptr.sub(1);
                }
            } else {
                *cptr = b'0';
                *p = cptr.add(1);
            }
        };
    }
    pub fn proconwritebuf_iint<I>(p: &mut *mut u8, mut d: I)
    where
        I: Copy
            + std::cmp::Ord
            + std::ops::Neg<Output = I>
            + std::ops::Div<Output = I>
            + std::ops::Rem<Output = I>
            + std::convert::From<i8>
            + std::convert::Into<i128>,
    {
        unsafe {
            let bptr = *p;
            let mut cptr = bptr;
            if d > I::from(0) {
                while d != I::from(0) {
                    let (q, r) = (d / I::from(10), d % I::from(10));
                    d = q;
                    *cptr = b'0' + I::into(r) as u8;
                    cptr = cptr.add(1);
                }
                *p = cptr;
                let mut lptr = bptr;
                let mut rptr = cptr.sub(1);
                while (lptr as usize) < (rptr as usize) {
                    let (dr, dl) = (*lptr, *rptr);
                    *lptr = dl;
                    *rptr = dr;
                    lptr = lptr.add(1);
                    rptr = rptr.sub(1);
                }
            } else if d < I::from(0) {
                *cptr = b'-';
                cptr = cptr.add(1);
                let mptr = cptr;
                {
                    let (q, r) = (-(d / I::from(10)), -(d % I::from(10)));
                    d = q;
                    *cptr = b'0' + I::into(r) as u8;
                    cptr = cptr.add(1);
                }
                while d != I::from(0) {
                    let (q, r) = (d / I::from(10), d % I::from(10));
                    d = q;
                    *cptr = b'0' + I::into(r) as u8;
                    cptr = cptr.add(1);
                }
                *p = cptr;
                let mut lptr = mptr;
                let mut rptr = cptr.sub(1);
                while (lptr as usize) < (rptr as usize) {
                    let (dr, dl) = (*lptr, *rptr);
                    *lptr = dl;
                    *rptr = dr;
                    lptr = lptr.add(1);
                    rptr = rptr.sub(1);
                }
            } else {
                *cptr = b'0';
                *p = cptr.add(1);
            }
        };
    }
    pub fn proconwritebuf_sp(p: &mut *mut u8) {
        *p = unsafe {
            **p = b' ';
            (*p).add(1)
        }
    }
    pub fn proconwritebuf_lf(p: &mut *mut u8) {
        *p = unsafe {
            **p = b'\n';
            (*p).add(1)
        }
    }
    pub fn proconwritebuf_bytes(p: &mut *mut u8, bytes: &[u8]) {
        *p = unsafe {
            let len = bytes.len();
            std::ptr::copy_nonoverlapping(bytes.as_ptr(), *p, len);
            (*p).add(len)
        };
    }
    pub fn proconwritebuf_str(p: &mut *mut u8, s: &str) {
        *p = unsafe {
            let len = s.len();
            std::ptr::copy_nonoverlapping(s.as_ptr(), *p, len);
            (*p).add(len)
        };
    }
    pub fn proconwritebuf_string(p: &mut *mut u8, s: &String) {
        *p = unsafe {
            let len = s.len();
            std::ptr::copy_nonoverlapping(s.as_ptr(), *p, len);
            (*p).add(len)
        };
    }
}

Submission Info

Submission Time
Task E - Work or Rest
User mizarjp
Language Rust (1.42.0)
Score 500
Code Size 34947 Byte
Status AC
Exec Time 13 ms
Memory 2084 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 63
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt
Case Name Status Exec Time Memory
sample_01.txt AC 6 ms 1944 KiB
sample_02.txt AC 2 ms 2000 KiB
sample_03.txt AC 3 ms 1988 KiB
test_01.txt AC 1 ms 2036 KiB
test_02.txt AC 1 ms 1992 KiB
test_03.txt AC 1 ms 2048 KiB
test_04.txt AC 2 ms 1988 KiB
test_05.txt AC 1 ms 1892 KiB
test_06.txt AC 1 ms 1876 KiB
test_07.txt AC 1 ms 1948 KiB
test_08.txt AC 1 ms 1840 KiB
test_09.txt AC 2 ms 2004 KiB
test_10.txt AC 1 ms 1988 KiB
test_11.txt AC 1 ms 1992 KiB
test_12.txt AC 1 ms 1988 KiB
test_13.txt AC 1 ms 1948 KiB
test_14.txt AC 2 ms 1884 KiB
test_15.txt AC 1 ms 2056 KiB
test_16.txt AC 2 ms 1888 KiB
test_17.txt AC 1 ms 1908 KiB
test_18.txt AC 1 ms 1884 KiB
test_19.txt AC 1 ms 1992 KiB
test_20.txt AC 1 ms 1988 KiB
test_21.txt AC 2 ms 1992 KiB
test_22.txt AC 1 ms 1840 KiB
test_23.txt AC 1 ms 2040 KiB
test_24.txt AC 1 ms 1936 KiB
test_25.txt AC 1 ms 1892 KiB
test_26.txt AC 1 ms 1828 KiB
test_27.txt AC 1 ms 1912 KiB
test_28.txt AC 1 ms 1992 KiB
test_29.txt AC 4 ms 1964 KiB
test_30.txt AC 1 ms 1920 KiB
test_31.txt AC 2 ms 1912 KiB
test_32.txt AC 7 ms 2028 KiB
test_33.txt AC 2 ms 1992 KiB
test_34.txt AC 13 ms 2048 KiB
test_35.txt AC 12 ms 2004 KiB
test_36.txt AC 10 ms 1896 KiB
test_37.txt AC 11 ms 2072 KiB
test_38.txt AC 12 ms 2072 KiB
test_39.txt AC 9 ms 1976 KiB
test_40.txt AC 9 ms 2008 KiB
test_41.txt AC 10 ms 2008 KiB
test_42.txt AC 9 ms 1964 KiB
test_43.txt AC 12 ms 1996 KiB
test_44.txt AC 12 ms 2044 KiB
test_45.txt AC 9 ms 1992 KiB
test_46.txt AC 10 ms 1992 KiB
test_47.txt AC 3 ms 1960 KiB
test_48.txt AC 10 ms 1896 KiB
test_49.txt AC 2 ms 2052 KiB
test_50.txt AC 9 ms 1980 KiB
test_51.txt AC 6 ms 2084 KiB
test_52.txt AC 13 ms 2052 KiB
test_53.txt AC 12 ms 2072 KiB
test_54.txt AC 9 ms 1992 KiB
test_55.txt AC 7 ms 1988 KiB
test_56.txt AC 5 ms 1972 KiB
test_57.txt AC 5 ms 2076 KiB
test_58.txt AC 11 ms 2048 KiB
test_59.txt AC 12 ms 2008 KiB
test_60.txt AC 9 ms 2060 KiB