QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#285830#7940. Impossible Numbersucup-team296#AC ✓220ms11456kbRust32.5kb2023-12-16 23:20:212023-12-16 23:20:22

Judging History

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

  • [2023-12-17 13:41:15]
  • hack成功,自动添加数据
  • (/hack/501)
  • [2023-12-16 23:20:22]
  • 评测
  • 测评结果:AC
  • 用时:220ms
  • 内存:11456kb
  • [2023-12-16 23:20:21]
  • 提交

answer

// 
pub mod solution {

use crate::collections::iter_ext::collect::IterCollect;
use crate::io::input::Input;
use crate::io::output::Output;
use crate::misc::recursive_function::{Callable2, RecursiveFunction2};
use crate::numbers::num_traits::bit_ops::BitOps;
use crate::string::str::Str;

type PreCalc = ();

fn solve(input: &mut Input, out: &mut Output, _test_case: usize, _data: &PreCalc) {
    let n = input.read_size();
    let mut k = input.read_size();
    let d = (0..n)
        .map(|_| {
            let d = input.read_size_vec(6);
            let mut cur = 0;
            for i in 0..6 {
                cur.set_bit(d[i]);
            }
            cur
        })
        .collect::<Vec<_>>();

    let base = (1..1024)
        .map(|mask: usize| {
            let mut cur = 0i32;
            for &i in &d {
                if (i & mask) != 0 {
                    cur += 1;
                }
            }
            (mask, cur)
        })
        .collect_vec();

    let create = |base: &[(usize, i32)], len: i32, dd: usize| -> Option<Vec<(usize, i32)>> {
        let mut res = Vec::new();
        for &(mask, q) in base {
            let mut has = q;
            if mask.is_set(dd) {
                has -= 1;
            }
            if has < 0 {
                return None;
            }
            if has < len {
                res.push((mask, has));
            }
        }
        Some(res)
    };

    let mut ans = Vec::new();
    for i in 0.. {
        for j in 1..10 {
            let mut prefix = Str::new();
            prefix.push(b'0' + (j as u8));
            let mut rec =
                RecursiveFunction2::new(|rec, len: i32, cand: Option<Vec<(usize, i32)>>| {
                    if cand.is_none() {
                        if len == 0 {
                            ans.push(prefix.clone());
                            k -= 1;
                        } else {
                            for j in 0..10 {
                                prefix.push(b'0' + (j as u8));
                                rec.call(len - 1, None);
                                prefix.pop();
                                if k == 0 {
                                    return;
                                }
                            }
                        }
                        return;
                    }
                    let cand = cand.unwrap();
                    if cand.is_empty() {
                        return;
                    }
                    for j in 0..10 {
                        prefix.push(b'0' + (j as u8));
                        rec.call(len - 1, create(&cand, len - 1, j));
                        prefix.pop();
                        if k == 0 {
                            return;
                        }
                    }
                });
            rec.call(i, create(&base, i, j));
            if k == 0 {
                break;
            }
        }
        if k == 0 {
            break;
        }
    }
    out.print_line(ans);
}

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

    #[allow(dead_code)]
    enum TestType {
        Single,
        MultiNumber,
        MultiEof,
    }
    let test_type = TestType::Single;
    match test_type {
        TestType::Single => solve(&mut input, &mut output, 1, &pre_calc),
        TestType::MultiNumber => {
            let t = input.read();
            for i in 1..=t {
                solve(&mut input, &mut output, i, &pre_calc);
            }
        }
        TestType::MultiEof => {
            let mut i = 1;
            while input.peek().is_some() {
                solve(&mut input, &mut output, i, &pre_calc);
                i += 1;
            }
        }
    }
    output.flush();
    input.skip_whitespace();
    input.peek().is_none()
}

}
pub mod collections {
pub mod iter_ext {
pub mod collect {
pub trait IterCollect<T>: Iterator<Item = T> + Sized {
    fn collect_vec(self) -> Vec<T> {
        self.collect()
    }
}

impl<T, I: Iterator<Item = T> + Sized> IterCollect<T> for I {}
}
}
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::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 !char::from(b).is_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 char::from(c).is_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()
    }

    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::collections::vec_ext::default::default_vec;
use std::io::{stderr, Stderr, 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]) {
        for i in arg {
            i.write(self);
            self.put(b'\n');
        }
    }

    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_iter_ref<'a, T: 'a + Writable, I: Iterator<Item = &'a 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 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_ref(self.iter());
    }
}

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

impl<T: Writable> 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}

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)
    }
}

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 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 numbers {
pub mod num_traits {
pub mod bit_ops {
use crate::numbers::num_traits::zero_one::ZeroOne;
use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, RangeInclusive, Shl,};
use std::ops::{ShlAssign, Shr, ShrAssign};

pub trait BitOps:
    Copy
    + BitAnd<Output = Self>
    + BitAndAssign
    + BitOr<Output = Self>
    + BitOrAssign
    + BitXor<Output = Self>
    + BitXorAssign
    + Not<Output = Self>
    + Shl<usize, Output = Self>
    + ShlAssign<usize>
    + Shr<usize, Output = Self>
    + ShrAssign<usize>
    + ZeroOne
    + PartialEq
{
    fn bit(at: usize) -> Self {
        Self::one() << at
    }

    fn is_set(&self, at: usize) -> bool {
        (*self >> at & Self::one()) == Self::one()
    }

    fn set_bit(&mut self, at: usize) {
        *self |= Self::bit(at)
    }

    fn unset_bit(&mut self, at: usize) {
        *self &= !Self::bit(at)
    }

    #[must_use]
    fn with_bit(mut self, at: usize) -> Self {
        self.set_bit(at);
        self
    }

    #[must_use]
    fn without_bit(mut self, at: usize) -> Self {
        self.unset_bit(at);
        self
    }

    fn flip_bit(&mut self, at: usize) {
        *self ^= Self::bit(at)
    }

    fn all_bits(n: usize) -> Self {
        let mut res = Self::zero();
        for i in 0..n {
            res.set_bit(i);
        }
        res
    }

    fn iter_all(n: usize) -> RangeInclusive<Self> {
        Self::zero()..=Self::all_bits(n)
    }
}

impl<
        T: Copy
            + BitAnd<Output = Self>
            + BitAndAssign
            + BitOr<Output = Self>
            + BitOrAssign
            + BitXor<Output = Self>
            + BitXorAssign
            + Not<Output = Self>
            + Shl<usize, Output = Self>
            + ShlAssign<usize>
            + Shr<usize, Output = Self>
            + ShrAssign<usize>
            + ZeroOne
            + PartialEq,
    > BitOps for T
{
}

pub trait Bits: BitOps {
    fn bits() -> u32;
}

macro_rules! bits_integer_impl {
    ($($t: ident $bits: expr),+) => {$(
        impl Bits for $t {
            fn bits() -> u32 {
                $bits
            }
        }
    )+};
}

bits_integer_impl!(i128 128, i64 64, i32 32, i16 16, i8 8, isize 64, u128 128, u64 64, u32 32, u16 16, u8 8, usize 64);
}
pub mod zero_one {
pub trait ZeroOne {
    fn zero() -> Self;
    fn one() -> Self;
}

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

            fn one() -> Self {
                1
            }
        }
    )+};
}

zero_one_integer_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize);
}
}
}
pub mod string {
pub mod str {
use crate::collections::iter_ext::collect::IterCollect;
use crate::io::input::{Input, Readable};
use crate::io::output::{Output, Writable};
use std::cmp::Ordering;
use std::fmt::{Debug, Display, Formatter};
use std::hash::{Hash, Hasher};
use std::iter::{Copied, FromIterator};
use std::marker::PhantomData;
use std::ops::{Add, AddAssign, Deref, DerefMut, Index, IndexMut};
use std::slice::{Iter, IterMut, SliceIndex};
use std::str::FromStr;
use std::vec::IntoIter;

pub enum Str<'s> {
    Extendable(Vec<u8>, PhantomData<&'s [u8]>),
    Owned(Box<[u8]>, PhantomData<&'s [u8]>),
    Ref(&'s [u8]),
}

impl Default for Str<'static> {
    fn default() -> Self {
        Self::new()
    }
}

impl Str<'static> {
    pub fn new() -> Self {
        Str::Extendable(Vec::new(), PhantomData)
    }

    pub fn with_capacity(cap: usize) -> Self {
        Str::Extendable(Vec::with_capacity(cap), PhantomData)
    }
}

impl<'s> Str<'s> {
    pub fn push(&mut self, c: u8) {
        self.transform_to_extendable();
        self.as_extendable().push(c)
    }

    pub fn pop(&mut self) -> Option<u8> {
        self.transform_to_extendable();
        self.as_extendable().pop()
    }

    pub fn as_slice(&self) -> &[u8] {
        match self {
            Str::Extendable(s, _) => s.as_ref(),
            Str::Owned(s, _) => s.as_ref(),
            Str::Ref(s) => s,
        }
    }

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

    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }

    pub fn iter(&self) -> Copied<Iter<u8>> {
        match self {
            Str::Extendable(v, _) => v.iter(),
            Str::Owned(v, _) => v.iter(),
            Str::Ref(v) => v.iter(),
        }
        .copied()
    }

    pub fn iter_mut(&mut self) -> IterMut<u8> {
        self.transform_to_owned();
        self.as_mut_slice().iter_mut()
    }

    pub fn sort(&mut self) {
        self.transform_to_owned();
        self.as_mut_slice().sort_unstable();
    }

    pub fn into_owned(mut self) -> Str<'static> {
        self.transform_to_owned();
        match self {
            Str::Extendable(v, _) => Str::Extendable(v, PhantomData),
            Str::Owned(v, _) => Str::Owned(v, PhantomData),
            _ => unreachable!(),
        }
    }

    fn transform_to_extendable(&mut self) {
        match self {
            Str::Extendable(_, _) => {}
            Str::Owned(_, _) => {
                let mut fake = Str::new();
                std::mem::swap(self, &mut fake);
                if let Str::Owned(s, _) = fake {
                    *self = Str::Extendable(s.to_vec(), PhantomData)
                }
            }
            Str::Ref(s) => *self = Str::Extendable(s.to_vec(), PhantomData),
        }
    }

    fn as_extendable(&mut self) -> &mut Vec<u8> {
        match self {
            Str::Extendable(s, _) => s,
            _ => panic!("unreachable"),
        }
    }

    fn transform_to_owned(&mut self) {
        if let Str::Ref(s) = self {
            *self = Str::Owned(s.to_vec().into_boxed_slice(), PhantomData)
        }
    }

    pub fn as_mut_slice(&mut self) -> &mut [u8] {
        self.transform_to_owned();
        match self {
            Str::Extendable(s, _) => s.as_mut_slice(),
            Str::Owned(s, _) => s.as_mut(),
            _ => panic!("unreachable"),
        }
    }

    pub fn into_string(self) -> String {
        match self {
            Str::Extendable(v, _) => unsafe { String::from_utf8_unchecked(v) },
            Str::Owned(v, _) => unsafe { String::from_utf8_unchecked(v.into_vec()) },
            Str::Ref(v) => String::from_utf8_lossy(v).into_owned(),
        }
    }

    pub fn reverse(&mut self) {
        self.as_mut_slice().reverse();
    }

    pub fn trim(&self) -> Str<'_> {
        let mut start = 0;
        let mut end = self.len();
        while start < end && (self[start] as char).is_whitespace() {
            start += 1;
        }
        while start < end && (self[end - 1] as char).is_whitespace() {
            end -= 1;
        }
        self[start..end].into()
    }

    pub fn split<'a, 'b>(&'a self, sep: impl Into<Str<'b>>) -> Vec<Str<'a>>
    where
        's: 'a,
    {
        let sep = sep.into();
        let mut res = Vec::new();
        let mut start = 0;
        for i in 0..self.len() {
            if self[i..].starts_with(sep.as_slice()) {
                res.push(self[start..i].into());
                start = i + sep.len();
            }
        }
        res.push(self[start..].into());
        res
    }

    pub fn parse<F: FromStr>(self) -> F
    where
        F::Err: Debug,
    {
        self.into_string().parse().unwrap()
    }

    pub fn parse_vec<T: Readable>(&self) -> Vec<T> {
        let mut bytes = self.as_slice();
        let mut input = Input::new(&mut bytes);
        let mut res = Vec::new();
        while !input.is_exhausted() {
            res.push(input.read());
        }
        res
    }
}

impl<'s> IntoIterator for Str<'s> {
    type Item = u8;
    type IntoIter = IntoIter<u8>;

    #[allow(clippy::unnecessary_to_owned)]
    fn into_iter(self) -> Self::IntoIter {
        match self {
            Str::Extendable(v, _) => v.into_iter(),
            Str::Owned(v, _) => v.into_vec().into_iter(),
            Str::Ref(v) => v.to_vec().into_iter(),
        }
    }
}

impl From<String> for Str<'static> {
    fn from(s: String) -> Self {
        Str::Extendable(s.into(), PhantomData)
    }
}

impl<'s> From<&'s str> for Str<'s> {
    fn from(s: &'s str) -> Self {
        Str::Ref(s.as_bytes())
    }
}

impl From<Vec<u8>> for Str<'static> {
    fn from(s: Vec<u8>) -> Self {
        Str::Extendable(s, PhantomData)
    }
}

impl<'s> From<&'s [u8]> for Str<'s> {
    fn from(s: &'s [u8]) -> Self {
        Str::Ref(s)
    }
}

impl<'s, const N: usize> From<&'s [u8; N]> for Str<'s> {
    fn from(s: &'s [u8; N]) -> Self {
        Str::Ref(s)
    }
}

impl<'s> From<&'s String> for Str<'s> {
    fn from(s: &'s String) -> Self {
        Str::Ref(s.as_bytes())
    }
}

impl<'s> From<&'s Vec<u8>> for Str<'s> {
    fn from(s: &'s Vec<u8>) -> Self {
        Str::Ref(s.as_slice())
    }
}

impl From<u8> for Str<'static> {
    fn from(c: u8) -> Self {
        Str::Owned(Box::new([c]), PhantomData)
    }
}

impl From<char> for Str<'static> {
    fn from(c: char) -> Self {
        Str::from(c as u8)
    }
}

impl<'s, 't: 's> From<&'s Str<'t>> for Str<'s> {
    fn from(value: &'s Str<'t>) -> Self {
        Str::Ref(value.as_slice())
    }
}

impl<R: SliceIndex<[u8]>> Index<R> for Str<'_> {
    type Output = R::Output;

    fn index(&self, index: R) -> &Self::Output {
        self.as_slice().index(index)
    }
}

impl<R: SliceIndex<[u8]>> IndexMut<R> for Str<'_> {
    fn index_mut(&mut self, index: R) -> &mut Self::Output {
        self.transform_to_owned();
        self.as_mut_slice().index_mut(index)
    }
}

impl Clone for Str<'_> {
    fn clone(&self) -> Self {
        match self {
            Str::Extendable(s, _) => s.clone().into(),
            Str::Owned(s, _) => s.to_vec().into(),
            Str::Ref(s) => Str::Ref(s),
        }
    }
}

impl<'r, 's, S: Into<Str<'r>>> AddAssign<S> for Str<'s> {
    fn add_assign(&mut self, rhs: S) {
        self.transform_to_extendable();
        self.as_extendable()
            .extend_from_slice(rhs.into().as_slice());
    }
}

impl<'r, 's, S: Into<Str<'r>>> Add<S> for Str<'s> {
    type Output = Str<'s>;

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

impl Readable for Str<'static> {
    fn read(input: &mut Input) -> Self {
        input.next_token().unwrap().into()
    }
}

impl Writable for Str<'_> {
    fn write(&self, output: &mut Output) {
        for c in self.as_slice() {
            output.put(*c);
        }
        output.maybe_flush();
    }
}

impl Display for Str<'_> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        <String as Display>::fmt(&String::from_utf8(self.as_slice().to_vec()).unwrap(), f)
    }
}

impl Hash for Str<'_> {
    fn hash<H: Hasher>(&self, state: &mut H) {
        self.as_slice().hash(state);
    }
}

impl<'r> PartialEq<Str<'r>> for Str<'_> {
    fn eq(&self, other: &Str<'r>) -> bool {
        self.as_slice().eq(other.as_slice())
    }
}

impl Eq for Str<'_> {}

impl<'r> PartialOrd<Str<'r>> for Str<'_> {
    fn partial_cmp(&self, other: &Str<'r>) -> Option<Ordering> {
        self.as_slice().partial_cmp(other.as_slice())
    }
}

impl Ord for Str<'_> {
    fn cmp(&self, other: &Self) -> Ordering {
        self.as_slice().cmp(other.as_slice())
    }
}

impl FromIterator<u8> for Str<'static> {
    fn from_iter<T: IntoIterator<Item = u8>>(iter: T) -> Self {
        Self::Extendable(iter.into_iter().collect_vec(), Default::default())
    }
}

impl<'r> FromIterator<&'r u8> for Str<'static> {
    fn from_iter<T: IntoIterator<Item = &'r u8>>(iter: T) -> Self {
        Self::Extendable(iter.into_iter().cloned().collect_vec(), Default::default())
    }
}

impl Deref for Str<'_> {
    type Target = [u8];

    fn deref(&self) -> &Self::Target {
        self.as_slice()
    }
}

impl DerefMut for Str<'_> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        self.as_mut_slice()
    }
}

pub trait StrReader {
    fn read_str(&mut self) -> Str<'static>;
    fn read_str_vec(&mut self, n: usize) -> Vec<Str<'static>>;
    fn read_line(&mut self) -> Str<'static>;
    fn read_line_vec(&mut self, n: usize) -> Vec<Str<'static>>;
    fn read_lines(&mut self) -> Vec<Str<'static>>;
}

impl StrReader for Input<'_> {
    fn read_str(&mut self) -> Str<'static> {
        self.read()
    }

    fn read_str_vec(&mut self, n: usize) -> Vec<Str<'static>> {
        self.read_vec(n)
    }

    fn read_line(&mut self) -> Str<'static> {
        let mut res = Str::new();
        while let Some(c) = self.get() {
            if c == b'\n' {
                break;
            }
            res.push(c);
        }
        res
    }

    fn read_line_vec(&mut self, n: usize) -> Vec<Str<'static>> {
        let mut res = Vec::with_capacity(n);
        for _ in 0..n {
            res.push(self.read_line());
        }
        res
    }

    fn read_lines(&mut self) -> Vec<Str<'static>> {
        let mut res = Vec::new();
        while !self.is_exhausted() {
            res.push(self.read_line());
        }
        if let Some(s) = res.last() {
            if s.is_empty() {
                res.pop();
            }
        }
        res
    }
}
}
}
fn main() {
    let mut sin = std::io::stdin();
    let input = if false {
        io::input::Input::new_with_size(&mut sin, 1)
    } else {
        io::input::Input::new(&mut sin)
    };

    let mut stdout = std::io::stdout();
    let output = if false {
        io::output::Output::new_with_auto_flush(&mut stdout)
    } else {
        io::output::Output::new(&mut stdout)
    };

    solution::run(input, output);
}


这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 3
1 8 7 0 6 2
1 2 5 4 9 3

output:

33 34 35

result:

ok single line: '33 34 35'

Test #2:

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

input:

1 10
1 5 2 2 6 4

output:

3 7 8 9 10 11 12 13 14 15

result:

ok single line: '3 7 8 9 10 11 12 13 14 15'

Test #3:

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

input:

4 10
1 5 7 1 2 4
0 1 5 8 9 4
3 5 2 2 7 8
6 1 7 0 2 2

output:

33 66 99 133 166 199 233 266 299 303

result:

ok single line: '33 66 99 133 166 199 233 266 299 303'

Test #4:

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

input:

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

output:

7 17 27 37 47 55 57 67 70 71

result:

ok single line: '7 17 27 37 47 55 57 67 70 71'

Test #5:

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

input:

5 10
8 7 1 4 8 9
2 5 0 1 0 1
9 5 5 3 9 7
6 0 0 2 3 1
1 0 0 4 9 3

output:

66 88 166 188 222 226 262 266 288 366

result:

ok single line: '66 88 166 188 222 226 262 266 288 366'

Test #6:

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

input:

5 10
6 8 7 7 0 0
0 5 1 9 4 1
5 9 6 9 5 4
0 4 6 9 1 6
2 8 7 4 4 0

output:

3 13 22 23 30 31 32 33 34 35

result:

ok single line: '3 13 22 23 30 31 32 33 34 35'

Test #7:

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

input:

5 1000
0 4 1 3 9 6
9 6 2 1 8 6
5 3 0 7 7 3
0 2 8 0 8 4
2 4 1 2 9 7

output:

55 155 255 333 335 353 355 455 505 515 525 533 535 545 550 551 552 553 554 555 556 557 558 559 565 575 577 585 595 655 666 755 757 775 777 855 888 955 1055 1111 1116 1119 1155 1161 1166 1169 1191 1196 1199 1255 1333 1335 1353 1355 1455 1505 1515 1525 1533 1535 1545 1550 1551 1552 1553 1554 1555 1556...

result:

ok single line: '55 155 255 333 335 353 355 455...0 10053 10055 10111 10116 10119'

Test #8:

score: 0
Accepted
time: 2ms
memory: 2636kb

input:

5 10000
1 4 7 5 6 0
2 3 8 4 9 0
1 2 8 8 3 0
7 9 9 7 2 9
4 7 1 9 3 6

output:

55 155 255 355 455 505 515 525 535 545 550 551 552 553 554 555 556 557 558 559 565 566 575 585 595 655 656 665 666 755 855 888 955 1055 1111 1115 1116 1151 1155 1156 1161 1165 1166 1255 1355 1455 1505 1511 1515 1516 1525 1535 1545 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1561 1565 1566 1575...

result:

ok single line: '55 155 255 355 455 505 515 525...6 45507 45508 45509 45510 45511'

Test #9:

score: 0
Accepted
time: 1ms
memory: 2608kb

input:

6 10000
0 1 3 2 4 7
7 6 4 8 7 9
5 5 7 2 3 9
8 4 6 1 6 4
2 4 9 9 0 7
1 2 3 3 2 0

output:

55 155 255 355 455 505 515 525 535 545 550 551 552 553 554 555 556 557 558 559 565 575 585 595 655 666 668 686 688 755 855 866 868 886 888 955 1055 1111 1155 1255 1355 1455 1505 1515 1525 1535 1545 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1565 1575 1585 1595 1655 1666 1668 1686 1688 1755 18...

result:

ok single line: '55 155 255 355 455 505 515 525...6 66847 66848 66849 66850 66851'

Test #10:

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

input:

7 1000
5 2 1 6 3 7
7 9 8 1 8 1
8 7 2 0 6 2
3 8 6 0 5 1
8 8 3 7 0 8
1 0 6 3 5 6
6 7 5 0 9 1

output:

4 14 24 34 40 41 42 43 44 45 46 47 48 49 54 64 74 84 94 104 114 124 134 140 141 142 143 144 145 146 147 148 149 154 164 174 184 194 204 214 222 224 234 240 241 242 243 244 245 246 247 248 249 254 264 274 284 294 304 314 324 334 340 341 342 343 344 345 346 347 348 349 354 364 374 384 394 400 401 402 ...

result:

ok single line: '4 14 24 34 40 41 42 43 44 45 4...3 3474 3475 3476 3477 3478 3479'

Test #11:

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

input:

8 1000
3 8 1 9 7 6
6 5 2 1 8 9
3 8 7 9 2 3
0 5 7 7 7 3
2 9 0 4 2 9
2 7 5 0 5 3
5 9 2 7 0 8
8 3 1 3 0 5

output:

44 144 244 344 404 414 424 434 440 441 442 443 444 445 446 447 448 449 454 464 474 484 494 544 644 666 744 844 944 1044 1111 1116 1144 1161 1166 1244 1344 1404 1414 1424 1434 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1454 1464 1474 1484 1494 1544 1611 1616 1644 1661 1666 1744 1844 1944 2044 ...

result:

ok single line: '44 144 244 344 404 414 424 434...4 14540 14541 14542 14543 14544'

Test #12:

score: 0
Accepted
time: 1ms
memory: 2576kb

input:

9 10000
0 8 4 7 2 8
7 8 3 1 8 4
1 2 6 5 4 9
1 1 3 0 8 2
6 3 0 2 4 5
2 0 8 8 0 0
6 8 5 2 7 7
7 5 4 3 7 6
2 7 1 0 1 5

output:

99 199 299 399 499 599 699 799 899 909 919 929 939 949 959 969 979 989 990 991 992 993 994 995 996 997 998 999 1099 1199 1299 1399 1499 1599 1699 1799 1899 1909 1919 1929 1939 1949 1959 1969 1979 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2099 2199 2299 2399 2499 2599 2699 2799 2899 2909...

result:

ok single line: '99 199 299 399 499 599 699 799...799 134899 134909 134919 134929'

Test #13:

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

input:

20 10000
5 9 4 8 3 3
1 1 9 2 8 9
6 3 3 0 2 1
2 6 0 3 6 4
3 6 4 2 9 4
8 6 7 3 7 3
3 6 2 0 5 9
5 3 3 5 8 9
1 4 4 5 8 0
1 3 1 4 7 8
6 9 9 8 3 3
1 7 2 8 9 3
0 2 2 8 5 9
9 0 1 2 2 5
5 0 9 1 6 9
0 8 7 7 3 2
7 7 2 7 3 3
3 6 6 6 0 0
7 5 3 5 5 9
9 2 0 0 8 0

output:

444444 1444444 2444444 3444444 4044444 4144444 4244444 4344444 4404444 4414444 4424444 4434444 4440444 4441444 4442444 4443444 4444044 4444144 4444244 4444344 4444404 4444414 4444424 4444434 4444440 4444441 4444442 4444443 4444444 4444445 4444446 4444447 4444448 4444449 4444454 4444464 4444474 44444...

result:

ok single line: '444444 1444444 2444444 3444444...4 404094444 404104444 404114444'

Test #14:

score: 0
Accepted
time: 4ms
memory: 2568kb

input:

20 10000
8 7 1 4 8 9
2 5 0 1 0 1
9 5 5 3 9 7
6 0 0 2 3 1
1 0 0 4 9 3
5 6 6 1 6 0
9 1 3 0 8 2
8 7 1 1 1 2
0 8 2 2 2 8
8 3 1 1 5 7
0 2 2 9 6 5
9 9 6 7 1 6
4 2 7 5 3 3
8 4 4 0 1 0
3 0 2 0 0 8
4 6 8 2 6 1
2 7 4 6 0 5
0 2 9 6 0 1
5 6 3 1 9 9
6 0 2 5 0 3

output:

4444444 14444444 24444444 34444444 40444444 41444444 42444444 43444444 44044444 44144444 44244444 44344444 44404444 44414444 44424444 44434444 44440444 44441444 44442444 44443444 44444044 44444144 44444244 44444344 44444404 44444414 44444424 44444434 44444440 44444441 44444442 44444443 44444444 4444...

result:

ok single line: '4444444 14444444 24444444 3444...443444484 3443444494 3443444544'

Test #15:

score: 0
Accepted
time: 88ms
memory: 8244kb

input:

50 100000
5 9 4 8 3 3
1 1 9 2 8 9
6 3 3 0 2 1
2 6 0 3 6 4
3 6 4 2 9 4
8 6 7 3 7 3
3 6 2 0 5 9
5 3 3 5 8 9
1 4 4 5 8 0
1 3 1 4 7 8
6 9 9 8 3 3
1 7 2 8 9 3
0 2 2 8 5 9
9 0 1 2 2 5
5 0 9 1 6 9
0 8 7 7 3 2
7 7 2 7 3 3
3 6 6 6 0 0
7 5 3 5 5 9
9 2 0 0 8 0
2 1 9 7 9 9
3 4 2 1 9 6
8 9 8 8 6 7
9 9 1 7 2 5
0 ...

output:

4444444444444444444 14444444444444444444 24444444444444444444 34444444444444444444 40444444444444444444 41444444444444444444 42444444444444444444 43444444444444444444 44044444444444444444 44144444444444444444 44244444444444444444 44344444444444444444 44404444444444444444 44414444444444444444 4442444...

result:

ok single line: '4444444444444444444 1444444444...44444444 4154449444444444444444'

Test #16:

score: 0
Accepted
time: 151ms
memory: 9948kb

input:

100 100000
5 9 4 8 3 3
1 1 9 2 8 9
6 3 3 0 2 1
2 6 0 3 6 4
3 6 4 2 9 4
8 6 7 3 7 3
3 6 2 0 5 9
5 3 3 5 8 9
1 4 4 5 8 0
1 3 1 4 7 8
6 9 9 8 3 3
1 7 2 8 9 3
0 2 2 8 5 9
9 0 1 2 2 5
5 0 9 1 6 9
0 8 7 7 3 2
7 7 2 7 3 3
3 6 6 6 0 0
7 5 3 5 5 9
9 2 0 0 8 0
2 1 9 7 9 9
3 4 2 1 9 6
8 9 8 8 6 7
9 9 1 7 2 5
0...

output:

7777777777777777777777777777777777 17777777777777777777777777777777777 27777777777777777777777777777777777 37777777777777777777777777777777777 47777777777777777777777777777777777 57777777777777777777777777777777777 67777777777777777777777777777777777 70777777777777777777777777777777777 7177777777777...

result:

ok single line: '777777777777777777777777777777...7777797777777777777777777777777'

Test #17:

score: 0
Accepted
time: 220ms
memory: 11416kb

input:

100 100000
8 7 1 4 8 9
2 5 0 1 0 1
9 5 5 3 9 7
6 0 0 2 3 1
1 0 0 4 9 3
5 6 6 1 6 0
9 1 3 0 8 2
8 7 1 1 1 2
0 8 2 2 2 8
8 3 1 1 5 7
0 2 2 9 6 5
9 9 6 7 1 6
4 2 7 5 3 3
8 4 4 0 1 0
3 0 2 0 0 8
4 6 8 2 6 1
2 7 4 6 0 5
0 2 9 6 0 1
5 6 3 1 9 9
6 0 2 5 0 3
4 9 2 2 4 7
5 4 0 1 3 3
1 7 1 8 0 0
8 7 3 3 5 2
3...

output:

44444444444444444444444444444444444444444444 77777777777777777777777777777777777777777777 144444444444444444444444444444444444444444444 177777777777777777777777777777777777777777777 244444444444444444444444444444444444444444444 277777777777777777777777777777777777777777777 34444444444444444444444444...

result:

ok single line: '444444444444444444444444444444...7777777777777777777777777777777'

Test #18:

score: 0
Accepted
time: 210ms
memory: 11456kb

input:

100 100000
6 8 7 7 0 0
0 5 1 9 4 1
5 9 6 9 5 4
0 4 6 9 1 6
2 8 7 4 4 0
0 1 4 3 9 2
3 0 2 1 3 4
6 5 4 1 6 3
7 1 3 6 9 4
4 5 1 3 6 2
4 3 0 2 4 7
8 8 3 5 8 6
9 7 7 0 3 1
9 5 9 9 8 3
2 0 9 1 2 5
8 0 0 0 0 3
1 2 5 9 3 2
2 3 5 6 1 2
0 0 4 0 6 2
4 6 9 4 0 8
2 9 7 1 7 4
0 3 1 8 0 9
7 5 9 6 2 7
7 0 0 4 8 4
6...

output:

222222222222222222222222222222222222222222 888888888888888888888888888888888888888888 1222222222222222222222222222222222222222222 1888888888888888888888888888888888888888888 2022222222222222222222222222222222222222222 2122222222222222222222222222222222222222222 22022222222222222222222222222222222222...

result:

ok single line: '222222222222222222222222222222...8888888888888880888888888888888'

Test #19:

score: 0
Accepted
time: 176ms
memory: 9804kb

input:

100 100000
0 4 1 3 9 6
9 6 2 1 8 6
5 3 0 7 7 3
0 2 8 0 8 4
2 4 1 2 9 7
9 3 2 7 4 4
6 2 5 4 2 1
8 4 7 8 0 9
8 7 9 0 6 3
6 5 6 3 7 2
5 9 5 2 3 4
7 9 1 7 8 0
1 2 6 2 5 6
0 7 5 6 4 2
9 5 2 1 1 0
3 9 9 0 3 2
1 0 3 1 3 7
6 7 7 4 9 6
9 6 1 2 8 2
6 7 8 8 7 0
3 6 9 3 9 6
0 6 7 1 2 7
2 4 6 0 4 3
9 9 8 0 6 4
5...

output:

777777777777777777777777777777777777 1777777777777777777777777777777777777 2777777777777777777777777777777777777 3777777777777777777777777777777777777 4777777777777777777777777777777777777 5777777777777777777777777777777777777 6777777777777777777777777777777777777 70777777777777777777777777777777777...

result:

ok single line: '777777777777777777777777777777...7777777777777777777777677777772'

Test #20:

score: 0
Accepted
time: 193ms
memory: 11348kb

input:

100 100000
1 4 7 5 6 0
2 3 8 4 9 0
1 2 8 8 3 0
7 9 9 7 2 9
4 7 1 9 3 6
4 4 5 4 0 5
7 4 5 9 6 3
4 7 0 2 9 2
6 0 2 2 6 9
9 1 7 2 6 4
1 7 9 0 5 3
9 4 6 7 2 6
7 1 7 0 9 3
9 9 4 3 5 3
9 7 9 4 2 4
0 7 7 4 5 0
3 0 1 1 2 1
6 9 2 1 2 8
6 9 0 1 6 4
8 1 9 6 5 4
2 0 4 6 0 9
0 7 5 9 4 0
1 0 0 5 1 8
8 9 8 1 4 9
5...

output:

6666666666666666666666666666666666666666 16666666666666666666666666666666666666666 26666666666666666666666666666666666666666 36666666666666666666666666666666666666666 46666666666666666666666666666666666666666 56666666666666666666666666666666666666666 60666666666666666666666666666666666666666 6166666...

result:

ok single line: '666666666666666666666666666666...6666636666666666666666666666966'

Test #21:

score: 0
Accepted
time: 16ms
memory: 8400kb

input:

10 100000
9 1 5 4 8 4
7 3 8 5 4 2
9 3 4 4 8 4
0 3 0 9 3 8
8 3 2 7 6 4
1 1 1 8 6 4
0 1 5 5 4 4
8 0 0 2 2 4
4 9 8 6 5 5
0 6 5 7 5 9

output:

1111 2222 7777 10111 11011 11101 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11121 11131 11141 11151 11161 11171 11181 11191 11211 11311 11411 11511 11611 11711 11811 11911 12111 12222 13111 14111 15111 16111 17111 17777 18111 19111 20222 21111 21222 22022 22122 22202 22212 22220 222...

result:

ok single line: '1111 2222 7777 10111 11011 111...7729224 7729225 7729226 7729227'

Test #22:

score: 0
Accepted
time: 8ms
memory: 8212kb

input:

10 100000
0 3 3 7 7 4
0 5 0 3 4 2
7 8 2 2 9 7
0 5 2 5 3 4
6 3 4 2 3 7
7 2 6 4 9 6
5 1 6 2 3 2
1 2 7 7 1 6
4 9 4 0 5 3
6 1 1 5 5 4

output:

88 188 288 388 488 588 688 788 808 818 828 838 848 858 868 878 880 881 882 883 884 885 886 887 888 889 898 988 1088 1111 1188 1288 1388 1488 1588 1688 1788 1808 1818 1828 1838 1848 1858 1868 1878 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1898 1988 2088 2188 2288 2388 2488 2588 2688 2788 2808...

result:

ok single line: '88 188 288 388 488 588 688 788...137 884138 884139 884140 884141'

Test #23:

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

input:

10 100000
8 6 2 1 9 5
3 6 5 2 9 8
5 2 5 7 3 6
4 1 7 1 5 9
8 4 6 3 8 0
3 1 7 0 6 4
8 6 8 1 9 9
4 6 5 2 3 7
3 6 3 3 0 8
1 6 7 5 3 6

output:

10000 20000 22222 30000 40000 44444 50000 60000 70000 80000 90000 99999 100000 100001 100002 100003 100004 100005 100006 100007 100008 100009 100010 100020 100030 100040 100050 100060 100070 100080 100090 100100 100200 100300 100400 100500 100600 100700 100800 100900 101000 102000 103000 104000 1050...

result:

ok single line: '10000 20000 22222 30000 40000 ...5000 23016000 23017000 23018000'

Test #24:

score: 0
Accepted
time: 1ms
memory: 2584kb

input:

5 10000
1 6 3 7 1 6
8 1 8 1 8 7
6 2 3 6 2 3
0 0 0 0 0 0
8 8 3 7 8 8

output:

4 5 9 14 15 19 22 24 25 29 34 35 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 64 65 69 74 75 79 84 85 89 90 91 92 93 94 95 96 97 98 99 100 104 105 109 111 114 115 119 122 124 125 129 134 135 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 164 165...

result:

ok single line: '4 5 9 14 15 19 22 24 25 29 34 ...6 11997 11998 11999 12000 12001'

Test #25:

score: 0
Accepted
time: 1ms
memory: 2560kb

input:

10 10000
1 9 7 6 1 9
2 1 8 9 2 1
7 9 7 9 7 9
0 5 0 5 0 5
7 3 2 9 7 3
2 9 2 2 9 2
0 5 3 5 9 2
8 8 8 8 8 8
3 0 5 5 3 0
5 7 3 5 7 3

output:

4 14 24 34 40 41 42 43 44 45 46 47 48 49 54 64 66 74 84 94 104 111 114 116 124 134 140 141 142 143 144 145 146 147 148 149 154 161 164 166 174 184 194 204 214 224 234 240 241 242 243 244 245 246 247 248 249 254 264 266 274 284 294 304 314 324 334 340 341 342 343 344 345 346 347 348 349 354 364 366 3...

result:

ok single line: '4 14 24 34 40 41 42 43 44 45 4...0 22841 22842 22843 22844 22845'

Test #26:

score: 0
Accepted
time: 6ms
memory: 8244kb

input:

20 100000
4 7 2 8 7 4
1 8 1 8 1 8
2 6 5 4 2 6
1 3 0 8 1 3
3 3 3 3 3 3
4 4 4 4 4 4
0 8 8 0 8 8
6 6 6 6 6 6
2 7 7 2 7 7
4 3 4 3 4 3
2 2 2 2 2 2
0 1 5 2 0 1
7 0 6 2 7 0
6 8 6 8 6 8
1 1 1 1 1 1
2 4 8 2 4 8
9 9 0 9 9 0
6 6 6 6 6 6
5 0 0 9 4 5
4 3 1 7 4 3

output:

999 1999 2999 3999 4999 5555 5999 6999 7999 8999 9099 9199 9299 9399 9499 9599 9699 9799 9899 9909 9919 9929 9939 9949 9959 9969 9979 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10999 11999 12999 13999 14999 15555 15999 16999 17999 18999 19099 19199 19299 19399 19499 19599 19699 19799 198...

result:

ok single line: '999 1999 2999 3999 4999 5555 5...5505591 5505592 5505593 5505594'

Test #27:

score: 0
Accepted
time: 30ms
memory: 8304kb

input:

60 100000
0 7 3 7 0 7
7 7 7 7 7 7
0 5 4 4 5 0
8 1 8 8 1 8
9 2 3 9 2 3
0 1 0 1 0 1
0 5 0 5 0 5
3 4 3 4 3 4
9 9 9 9 9 9
7 9 7 9 7 9
1 2 5 1 2 5
1 2 1 1 2 1
4 0 2 5 4 0
9 9 9 9 9 9
6 1 6 1 6 1
0 9 0 9 0 9
9 2 6 8 9 2
5 7 7 5 7 7
9 9 9 9 9 9
2 5 2 5 2 5
9 9 9 9 9 9
4 0 8 4 0 8
7 7 7 7 7 7
8 9 8 9 8 9
1 ...

output:

666666666 1666666666 2666666666 3666666666 4666666666 5666666666 6066666666 6166666666 6266666666 6366666666 6466666666 6566666666 6606666666 6616666666 6626666666 6636666666 6646666666 6656666666 6660666666 6661666666 6662666666 6663666666 6664666666 6665666666 6666066666 6666166666 6666266666 6666...

result:

ok single line: '666666666 1666666666 266666666...06166 666666006266 666666006366'

Test #28:

score: 0
Accepted
time: 69ms
memory: 8220kb

input:

80 100000
2 7 2 7 2 7
9 3 9 3 9 3
4 4 4 4 4 4
5 9 1 2 7 5
2 2 2 2 2 2
4 7 4 7 4 7
1 8 1 8 1 8
5 2 5 2 5 2
0 8 0 8 0 8
2 2 4 3 1 2
0 6 0 6 0 6
3 3 3 3 3 3
9 2 9 5 9 2
0 6 0 6 0 6
5 5 5 5 5 5
1 1 1 1 1 1
9 8 1 7 1 5
0 8 4 8 7 0
8 0 4 8 0 4
1 5 4 1 8 1
9 0 9 0 9 0
7 1 7 1 7 1
4 3 8 7 4 3
6 5 6 5 6 5
3 ...

output:

222222222222222 555555555555555 1222222222222222 1555555555555555 2022222222222222 2122222222222222 2202222222222222 2212222222222222 2220222222222222 2221222222222222 2222022222222222 2222122222222222 2222202222222222 2222212222222222 2222220222222222 2222221222222222 2222222022222222 2222222122222...

result:

ok single line: '222222222222222 55555555555555...222262222229 222202222262222232'

Test #29:

score: 0
Accepted
time: 68ms
memory: 8344kb

input:

100 100000
4 6 8 6 6 4
8 8 8 8 8 8
0 0 0 0 0 0
6 6 6 6 6 6
5 2 3 3 8 5
9 9 9 9 9 9
1 4 5 9 1 4
4 4 1 4 4 4
2 8 5 2 8 5
3 4 3 6 3 4
1 4 1 3 3 1
5 6 5 6 5 6
6 7 1 6 7 1
8 8 8 8 8 8
3 3 3 3 3 3
6 6 6 6 6 6
9 9 9 9 9 9
0 5 9 0 5 9
1 3 7 1 3 7
5 6 5 6 5 6
1 1 1 1 1 1
7 7 7 7 7 7
5 3 5 3 5 3
6 0 5 7 6 0
9...

output:

111111111111111111 1011111111111111111 1101111111111111111 1110111111111111111 1111011111111111111 1111101111111111111 1111110111111111111 1111111011111111111 1111111101111111111 1111111110111111111 1111111111011111111 1111111111101111111 1111111111110111111 1111111111111011111 1111111111111101111 1...

result:

ok single line: '111111111111111111 10111111111...111111519 111111111110111111521'

Test #30:

score: 0
Accepted
time: 92ms
memory: 8284kb

input:

100 100000
4 4 4 4 4 4
7 2 4 7 2 4
2 3 6 2 3 6
1 3 1 3 1 3
2 2 2 2 2 2
9 0 2 8 4 9
1 2 1 1 2 1
5 9 1 5 9 1
3 5 0 1 7 3
5 7 1 5 7 1
8 5 0 8 8 5
7 4 7 4 7 4
5 5 5 5 5 5
9 7 7 7 1 9
9 0 3 5 9 0
1 5 5 2 1 5
0 2 0 0 2 0
4 2 8 4 4 2
5 5 5 5 5 5
3 3 3 3 3 3
0 8 9 2 5 5
9 6 9 6 9 6
8 2 2 5 6 9
7 7 7 7 7 7
3...

output:

8888888888888888888 10000000000000000000 18888888888888888888 20000000000000000000 28888888888888888888 30000000000000000000 38888888888888888888 40000000000000000000 48888888888888888888 50000000000000000000 58888888888888888888 60000000000000000000 68888888888888888888 70000000000000000000 7888888...

result:

ok single line: '8888888888888888888 1000000000...00000000 3000700000000300000000'

Test #31:

score: 0
Accepted
time: 82ms
memory: 8344kb

input:

100 100000
0 0 0 0 0 0
4 4 1 9 4 4
0 7 0 7 0 7
5 1 9 4 4 0
1 3 1 7 2 1
9 3 4 1 4 9
9 9 9 9 9 9
3 2 4 9 0 3
9 9 9 9 9 9
0 4 2 3 2 0
2 2 2 2 2 2
7 8 7 8 7 8
5 7 5 5 7 5
8 8 8 8 8 8
7 6 4 5 7 6
0 0 0 0 0 0
0 3 4 0 3 4
1 8 3 1 8 3
5 7 1 0 5 7
2 2 2 2 2 2
3 4 2 3 4 2
0 0 0 0 0 0
7 7 7 7 7 7
2 6 7 2 8 2
2...

output:

666666666666666666 1666666666666666666 2666666666666666666 3666666666666666666 4666666666666666666 5666666666666666666 6066666666666666666 6166666666666666666 6266666666666666666 6366666666666666666 6466666666666666666 6566666666666666666 6606666666666666666 6616666666666666666 6626666666666666666 6...

result:

ok single line: '666666666666666666 16666666666...666666666 606666663669666666666'

Extra Test:

score: 0
Extra Test Passed