QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#348819#8334. Geneucup-team296#AC ✓766ms162336kbRust33.6kb2024-03-09 21:33:422024-03-09 21:33:42

Judging History

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

  • [2024-03-09 21:33:42]
  • 评测
  • 测评结果:AC
  • 用时:766ms
  • 内存:162336kb
  • [2024-03-09 21:33:42]
  • 提交

answer

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

#[allow(unused)]
use crate::dbg;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::output::Output;
use crate::algo_lib::math::modulo_pair::ModPair998_007;
use crate::algo_lib::misc::binary_search::binary_search_last_true;
use crate::algo_lib::strings::hash_string_context::HashContext;

type Mod = ModPair998_007;

fn solve(input: &mut Input, out: &mut Output, _test_case: usize) {
    let n = input.usize();
    let q = input.usize();
    let m = input.usize();
    let k = input.usize();
    let mut s = vec![];
    let hashes = HashContext::new(m + 10, Mod::new(239017));
    for _ in 0..n {
        let cur_s = input.string();
        let cur_s = hashes.make_string(&cur_s);
        s.push(cur_s);
    }
    for _ in 0..q {
        let cur_s = input.string();
        let cur_s = hashes.make_string(&cur_s);
        let mut res = 0;
        for i in 0..n {
            let mut fails = 0;
            let mut from = 0;
            while from < m && fails <= k {
                let to = binary_search_last_true(from..m + 1, |pos| {
                    s[i].calc_hash(from..pos) == cur_s.calc_hash(from..pos)
                })
                .unwrap();
                if to != m {
                    fails += 1;
                }
                from = to + 1;
            }
            if fails <= k {
                res += 1;
            }
        }
        out.println(res);
    }
}

pub(crate) fn run(mut input: Input, mut output: Output) -> bool {
    solve(&mut input, &mut output, 1);
    output.flush();
    true
}

}
pub mod algo_lib {
pub mod collections {
pub mod last_exn {
use std::collections::BTreeSet;

pub trait LastExn<T> {
    fn last_exn(&self) -> &T;
}

impl<T> LastExn<T> for &[T] {
    fn last_exn(&self) -> &T {
        self.last().unwrap()
    }
}

impl<T> LastExn<T> for Vec<T> {
    fn last_exn(&self) -> &T {
        self.last().unwrap()
    }
}

impl<T> LastExn<T> for BTreeSet<T> {
    fn last_exn(&self) -> &T {
        self.iter().next_back().unwrap()
    }
}
}
}
pub mod io {
pub mod input {
use std::fmt::Debug;
use std::io::Read;
use std::marker::PhantomData;
use std::path::Path;
use std::str::FromStr;

pub struct Input {
    input: Box<dyn Read>,
    buf: Vec<u8>,
    at: usize,
    buf_read: usize,
}

macro_rules! read_integer_fun {
    ($t:ident) => {
        #[allow(unused)]
        pub fn $t(&mut self) -> $t {
            self.read_integer()
        }
    };
}

impl Input {
    const DEFAULT_BUF_SIZE: usize = 4096;

    ///
    /// Using with stdin:
    /// ```no_run
    /// use algo_lib::io::input::Input;
    /// let stdin = std::io::stdin();
    /// let input = Input::new(Box::new(stdin));
    /// ```
    ///
    /// For read files use ``new_file`` instead.
    ///
    ///
    pub fn new(input: Box<dyn Read>) -> Self {
        Self {
            input,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            buf_read: 0,
        }
    }

    pub fn new_stdin() -> Self {
        let stdin = std::io::stdin();
        Self::new(Box::new(stdin))
    }

    pub fn new_file<P: AsRef<Path>>(path: P) -> Self {
        let file = std::fs::File::open(&path)
            .unwrap_or_else(|_| panic!("Can't open file: {:?}", path.as_ref().as_os_str()));
        Self::new(Box::new(file))
    }

    pub fn new_with_size(input: Box<dyn Read>, buf_size: usize) -> Self {
        Self {
            input,
            buf: vec![0; buf_size],
            at: 0,
            buf_read: 0,
        }
    }

    pub fn new_file_with_size<P: AsRef<Path>>(path: P, buf_size: usize) -> Self {
        let file = std::fs::File::open(&path)
            .unwrap_or_else(|_| panic!("Can't open file: {:?}", path.as_ref().as_os_str()));
        Self::new_with_size(Box::new(file), buf_size)
    }

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

    pub fn peek(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            Some(self.buf[self.at])
        } 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 has_more_elements(&mut self) -> bool {
        !self.is_exhausted()
    }

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

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

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

    pub fn read_line(&mut self) -> String {
        let mut res = String::new();
        while let Some(c) = self.get() {
            if c == b'\n' {
                break;
            }
            if c == b'\r' {
                if self.peek() == Some(b'\n') {
                    self.get();
                }
                break;
            }
            res.push(c.into());
        }
        res
    }

    #[allow(clippy::should_implement_trait)]
    pub fn into_iter<T: Readable>(self) -> InputIterator<T> {
        InputIterator {
            input: self,
            phantom: Default::default(),
        }
    }

    fn read_integer<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let res = self.read_string();
        res.parse::<T>().unwrap()
    }

    fn read_string(&mut self) -> String {
        match self.next_token() {
            None => {
                panic!("Input exhausted");
            }
            Some(res) => unsafe { String::from_utf8_unchecked(res) },
        }
    }

    pub fn string_as_string(&mut self) -> String {
        self.read_string()
    }

    pub fn string(&mut self) -> Vec<u8> {
        self.read_string().into_bytes()
    }

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

    fn read_float(&mut self) -> f64 {
        self.read_string().parse().unwrap()
    }

    pub fn f64(&mut self) -> f64 {
        self.read_float()
    }

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

    read_integer_fun!(i32);
    read_integer_fun!(i64);
    read_integer_fun!(i128);
    read_integer_fun!(u32);
    read_integer_fun!(u64);
    read_integer_fun!(usize);
}

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

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

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

impl Readable for f64 {
    fn read(input: &mut Input) -> Self {
        input.read_string().parse().unwrap()
    }
}

impl Readable for f32 {
    fn read(input: &mut Input) -> Self {
        input.read_string().parse().unwrap()
    }
}

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

pub struct InputIterator<T: Readable> {
    input: Input,
    phantom: PhantomData<T>,
}

impl<T: Readable> Iterator for InputIterator<T> {
    type Item = T;

    fn next(&mut self) -> Option<Self::Item> {
        self.input.skip_whitespace();
        self.input.peek().map(|_| self.input.read())
    }
}

macro_rules! read_integer {
    ($t:ident) => {
        impl Readable for $t {
            fn read(input: &mut Input) -> Self {
                input.read_integer()
            }
        }
    };
}

read_integer!(i8);
read_integer!(i16);
read_integer!(i32);
read_integer!(i64);
read_integer!(i128);
read_integer!(isize);
read_integer!(u8);
read_integer!(u16);
read_integer!(u32);
read_integer!(u64);
read_integer!(u128);
read_integer!(usize);
}
pub mod output {
use std::io::Write;

pub struct Output {
    output: Box<dyn Write>,
    buf: Vec<u8>,
    at: usize,
    auto_flush: bool,
}

impl Output {
    const DEFAULT_BUF_SIZE: usize = 4096;

    pub fn new(output: Box<dyn Write>) -> Self {
        Self {
            output,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            auto_flush: false,
        }
    }

    pub fn new_stdout() -> Self {
        let stdout = std::io::stdout();
        Self::new(Box::new(stdout))
    }

    pub fn new_file(path: impl AsRef<std::path::Path>) -> Self {
        let file = std::fs::File::create(path).unwrap();
        Self::new(Box::new(file))
    }

    pub fn new_with_auto_flush(output: Box<dyn Write>) -> Self {
        Self {
            output,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            auto_flush: true,
        }
    }

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

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

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

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

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;
        }
        if self.auto_flush {
            self.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> Writable for Vec<T> {
    fn write(&self, output: &mut Output) {
        self[..].write(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);
write_to_string!(u16);
write_to_string!(u32);
write_to_string!(u64);
write_to_string!(u128);
write_to_string!(usize);
write_to_string!(i8);
write_to_string!(i16);
write_to_string!(i32);
write_to_string!(i64);
write_to_string!(i128);
write_to_string!(isize);
write_to_string!(f32);
write_to_string!(f64);

impl<T: Writable, U: Writable> Writable for (T, U) {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
        output.put(b' ');
        self.1.write(output);
    }
}

impl<T: Writable, U: Writable, V: Writable> Writable for (T, U, V) {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
        output.put(b' ');
        self.1.write(output);
        output.put(b' ');
        self.2.write(output);
    }
}
}
}
pub mod math {
pub mod modulo {
use crate::algo_lib::collections::last_exn::LastExn;
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::num_traits::ConvSimple;
use crate::algo_lib::misc::num_traits::HasConstants;
use crate::algo_lib::misc::num_traits::Number;
use std::io::Write;
use std::marker::PhantomData;

pub trait Value: Clone + Copy + Eq + Default + Ord {
    fn val() -> i32;
}

#[derive(Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd, Hash)]
pub struct ModWithValue<M>(i32, PhantomData<M>)
where
    M: Value;

impl<M> ModWithValue<M>
where
    M: Value,
{
    #[allow(unused)]
    pub const ZERO: Self = Self(0, PhantomData);

    #[allow(unused)]
    pub const ONE: Self = Self(1, PhantomData);

    #[allow(unused)]
    pub const TWO: Self = Self(2, PhantomData);

    fn rev_rec(a: i32, m: i32) -> i32 {
        if a == 1 {
            return a;
        }
        ((1 - Self::rev_rec(m % a, a) as i64 * m as i64) / a as i64 + m as i64) as i32
    }

    #[allow(dead_code)]
    pub fn inv(self) -> Self {
        ModWithValue(Self::rev_rec(self.0, M::val()), PhantomData)
    }

    pub fn value(&self) -> i32 {
        self.0
    }

    #[allow(dead_code)]
    pub fn new<T: Number>(x: T) -> Self {
        let mut x = x.to_i32();
        if x < 0 {
            x += M::val();
            if x < 0 {
                x %= M::val();
                x += M::val();
            }
        } else if x >= M::val() {
            x -= M::val();
            if x >= M::val() {
                x %= M::val();
            }
        }
        assert!(0 <= x && x < M::val());
        Self(x, PhantomData)
    }

    pub fn pown(self, pw: usize) -> Self {
        if pw == 0 {
            Self::ONE
        } else if pw == 1 {
            self
        } else {
            let half = self.pown(pw / 2);
            let res = half * half;
            if pw % 2 == 0 {
                res
            } else {
                res * self
            }
        }
    }

    pub fn gen_powers(base: Self, n: usize) -> Vec<Self> {
        let mut res = Vec::with_capacity(n);
        res.push(Self::ONE);
        for _ in 1..n {
            res.push(*res.last_exn() * base);
        }
        res
    }
}

impl<M> std::fmt::Display for ModWithValue<M>
where
    M: Value,
{
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl<M> std::fmt::Debug for ModWithValue<M>
where
    M: Value + Copy + Eq,
{
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        const MAX: i32 = 100;

        if self.0 <= MAX {
            write!(f, "{}", self.0)
        } else if self.0 >= M::val() - MAX {
            write!(f, "-{}", M::val() - self.0)
        } else {
            for denom in 1..MAX {
                let num = *self * Self(denom, PhantomData);
                if num.0 <= MAX {
                    return write!(f, "{}/{}", num.0, denom);
                } else if num.0 >= M::val() - MAX {
                    return write!(f, "-{}/{}", M::val() - num.0, denom);
                }
            }
            write!(f, "(?? {} ??)", self.0)
        }
    }
}

impl<M> std::ops::Add for ModWithValue<M>
where
    M: Value,
{
    type Output = Self;

    fn add(self, rhs: Self) -> Self::Output {
        let res = self.0 + rhs.0;
        if res >= M::val() {
            ModWithValue(res - M::val(), PhantomData)
        } else {
            ModWithValue(res, PhantomData)
        }
    }
}

impl<M> std::ops::AddAssign for ModWithValue<M>
where
    M: Value,
{
    fn add_assign(&mut self, rhs: Self) {
        self.0 += rhs.0;
        if self.0 >= M::val() {
            self.0 -= M::val();
        }
    }
}

impl<M> std::ops::Sub for ModWithValue<M>
where
    M: Value,
{
    type Output = Self;

    fn sub(self, rhs: Self) -> Self::Output {
        let res = self.0 - rhs.0;
        if res < 0 {
            ModWithValue(res + M::val(), PhantomData)
        } else {
            ModWithValue(res, PhantomData)
        }
    }
}

impl<M> std::ops::SubAssign for ModWithValue<M>
where
    M: Value,
{
    fn sub_assign(&mut self, rhs: Self) {
        self.0 -= rhs.0;
        if self.0 < 0 {
            self.0 += M::val();
        }
    }
}

impl<M> std::ops::Mul for ModWithValue<M>
where
    M: Value,
{
    type Output = Self;

    fn mul(self, rhs: Self) -> Self::Output {
        let res = (self.0 as i64) * (rhs.0 as i64) % (M::val() as i64);
        ModWithValue(res as i32, PhantomData)
    }
}

impl<M> std::ops::MulAssign for ModWithValue<M>
where
    M: Value,
{
    fn mul_assign(&mut self, rhs: Self) {
        self.0 = ((self.0 as i64) * (rhs.0 as i64) % (M::val() as i64)) as i32;
    }
}

impl<M> std::ops::Div for ModWithValue<M>
where
    M: Value,
{
    type Output = Self;

    #[allow(clippy::suspicious_arithmetic_impl)]
    fn div(self, rhs: Self) -> Self::Output {
        let rhs_inv = rhs.inv();
        self * rhs_inv
    }
}

impl<M> std::ops::DivAssign for ModWithValue<M>
where
    M: Value,
{
    #[allow(clippy::suspicious_op_assign_impl)]
    fn div_assign(&mut self, rhs: Self) {
        *self *= rhs.inv();
    }
}

impl<M> Writable for ModWithValue<M>
where
    M: Value,
{
    fn write(&self, output: &mut Output) {
        output.write_fmt(format_args!("{}", self.0)).unwrap();
    }
}

impl<M> Readable for ModWithValue<M>
where
    M: Value,
{
    fn read(input: &mut Input) -> Self {
        let i32 = input.i32();
        Self::new(i32)
    }
}

impl<M> HasConstants<ModWithValue<M>> for ModWithValue<M>
where
    M: Value,
{
    // This doesn't make much sense, but hope we never use
    const MAX: ModWithValue<M> = ModWithValue::ZERO;
    const MIN: ModWithValue<M> = ModWithValue::ZERO;
    const ZERO: ModWithValue<M> = ModWithValue::ZERO;
    const ONE: ModWithValue<M> = ModWithValue::ONE;
    const TWO: ModWithValue<M> = ModWithValue::TWO;
}

impl<M> ConvSimple<ModWithValue<M>> for ModWithValue<M>
where
    M: Value,
{
    fn from_i32(val: i32) -> ModWithValue<M> {
        ModWithValue::new(val)
    }

    fn to_i32(self) -> i32 {
        self.0
    }

    fn to_f64(self) -> f64 {
        self.0 as f64
    }
}

pub trait ConstValue: Value + Copy {
    const VAL: i32;
}

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

#[derive(Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd, Hash)]
pub struct Value7();
impl ConstValue for Value7 {
    const VAL: i32 = 1_000_000_007;
}
pub type Mod7 = ModWithValue<Value7>;

#[derive(Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd, Hash)]
pub struct Value9();
impl ConstValue for Value9 {
    const VAL: i32 = 1_000_000_009;
}
pub type Mod9 = ModWithValue<Value9>;

#[derive(Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd, Hash)]
#[allow(non_camel_case_types)]
pub struct Value_998_244_353();
impl ConstValue for Value_998_244_353 {
    const VAL: i32 = 998_244_353;
}
#[allow(non_camel_case_types)]
pub type Mod_998_244_353 = ModWithValue<Value_998_244_353>;

pub trait ModuloTrait: Number {
    fn mod_value() -> i32;
    fn pown(self, n: usize) -> Self;
}

impl<V: Value> ModuloTrait for ModWithValue<V> {
    fn mod_value() -> i32 {
        V::val()
    }

    fn pown(self, n: usize) -> Self {
        self.pown(n)
    }
}
}
pub mod modulo_pair {
use crate::algo_lib::collections::last_exn::LastExn;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::input::Readable;
use crate::algo_lib::math::modulo::ModWithValue;
use crate::algo_lib::math::modulo::Value;
use crate::algo_lib::math::modulo::Value7;
use crate::algo_lib::math::modulo::Value_998_244_353;
use crate::algo_lib::misc::num_traits::ConvSimple;
use crate::algo_lib::misc::num_traits::HasConstants;
use crate::algo_lib::misc::num_traits::Number;

#[derive(Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd, Hash)]
pub struct ModPair<M1, M2>(ModWithValue<M1>, ModWithValue<M2>)
where
    M1: Value,
    M2: Value;

impl<M1, M2> ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    #[allow(unused)]
    pub const ZERO: Self = Self(ModWithValue::ZERO, ModWithValue::ZERO);

    #[allow(unused)]
    pub const ONE: Self = Self(ModWithValue::ONE, ModWithValue::ONE);

    #[allow(unused)]
    pub const TWO: Self = Self(ModWithValue::TWO, ModWithValue::TWO);

    pub fn value(&self) -> (i32, i32) {
        (self.0.value(), self.1.value())
    }

    #[allow(dead_code)]
    pub fn new<T: Number>(x: T) -> Self {
        Self(ModWithValue::<M1>::new(x), ModWithValue::<M2>::new(x))
    }

    pub fn pown(self, pw: usize) -> Self {
        Self(self.0.pown(pw), self.1.pown(pw))
    }

    pub fn gen_powers(base: Self, n: usize) -> Vec<Self> {
        let mut res = Vec::with_capacity(n);
        res.push(Self::ONE);
        for _ in 1..n {
            res.push(*res.last_exn() * base);
        }
        res
    }
}

// impl<M1, M2> std::fmt::Display for ModPair<M1, M2>
// where
//     M1: Value,
//     M2: Value,
// {
//     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
//         write!(f, "{}", self.0)
//     }
// }

impl<M1, M2> std::fmt::Debug for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "({:?},{:?})", self.0, self.1)
    }
}

impl<M1, M2> std::ops::Add for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    type Output = Self;

    fn add(self, rhs: Self) -> Self::Output {
        Self(self.0 + rhs.0, self.1 + rhs.1)
    }
}

impl<M1, M2> std::ops::AddAssign for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    fn add_assign(&mut self, rhs: Self) {
        self.0 += rhs.0;
        self.1 += rhs.1;
    }
}

impl<M1, M2> std::ops::Sub for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    type Output = Self;

    fn sub(self, rhs: Self) -> Self::Output {
        Self(self.0 - rhs.0, self.1 - rhs.1)
    }
}

impl<M1, M2> std::ops::SubAssign for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    fn sub_assign(&mut self, rhs: Self) {
        self.0 -= rhs.0;
        self.1 -= rhs.1;
    }
}

impl<M1, M2> std::ops::Mul for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    type Output = Self;

    fn mul(self, rhs: Self) -> Self::Output {
        Self(self.0 * rhs.0, self.1 * rhs.1)
    }
}

impl<M1, M2> std::ops::MulAssign for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    fn mul_assign(&mut self, rhs: Self) {
        self.0 *= rhs.0;
        self.1 *= rhs.1;
    }
}

impl<M1, M2> std::ops::Div for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    type Output = Self;

    fn div(self, rhs: Self) -> Self::Output {
        Self(self.0 / rhs.0, self.1 / rhs.1)
    }
}

impl<M1, M2> std::ops::DivAssign for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    fn div_assign(&mut self, rhs: Self) {
        self.0 /= rhs.0;
        self.1 /= rhs.1;
    }
}

// impl<M1, M2> Writable for ModPair<M1, M2>
// where
//     M1: Value,
//     M2: Value,
// {
//     fn write(&self, output: &mut Output) {
//         output.write_fmt(format_args!("{}", self.0)).unwrap();
//     }
// }

impl<M1, M2> Readable for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    fn read(input: &mut Input) -> Self {
        let i32 = input.i32();
        Self::new(i32)
    }
}

impl<M1, M2> HasConstants<ModPair<M1, M2>> for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    // This doesn't make much sense, but hope we never use
    const MAX: ModPair<M1, M2> = ModPair::ZERO;
    const MIN: ModPair<M1, M2> = ModPair::ZERO;
    const ZERO: ModPair<M1, M2> = ModPair::ZERO;
    const ONE: ModPair<M1, M2> = ModPair::ONE;
    const TWO: ModPair<M1, M2> = ModPair::TWO;
}

impl<M1, M2> ConvSimple<ModPair<M1, M2>> for ModPair<M1, M2>
where
    M1: Value,
    M2: Value,
{
    fn from_i32(val: i32) -> ModPair<M1, M2> {
        ModPair::new(val)
    }

    fn to_i32(self) -> i32 {
        self.0.to_i32()
    }

    fn to_f64(self) -> f64 {
        self.0.to_f64()
    }
}

pub type ModPair998_007 = ModPair<Value_998_244_353, Value7>;
}
}
pub mod misc {
pub mod binary_search {
use crate::algo_lib::misc::num_traits::Number;
use std::ops::Range;

pub fn binary_search_first_true<T>(range: Range<T>, mut f: impl FnMut(T) -> bool) -> T
where
    T: Number,
{
    // we can't store [range.start - 1] into [left], because it could overflow
    let mut left_plus_one = range.start;
    let mut right = range.end;
    while right > left_plus_one {
        let mid = left_plus_one + (right - left_plus_one) / T::TWO;
        if f(mid) {
            right = mid;
        } else {
            left_plus_one = mid + T::ONE;
        }
    }
    right
}

pub fn binary_search_last_true<T>(range: Range<T>, mut f: impl FnMut(T) -> bool) -> Option<T>
where
    T: Number,
{
    let first_false = binary_search_first_true(range.clone(), |x| !f(x));
    if first_false == range.start {
        None
    } else {
        Some(first_false - T::ONE)
    }
}

#[test]
fn simple_stress() {
    const N: usize = 50;
    for n in 1..N {
        for cnt_false in 0..=n {
            let mut a = vec![false; cnt_false];
            a.resize(n, true);
            let mut max_f_calls = ((n + 1) as f64).log2().ceil() as i32;
            let f_is_true = |id: usize| -> bool {
                max_f_calls -= 1;
                assert!(max_f_calls >= 0);
                a[id]
            };
            let result = binary_search_first_true(0..n, f_is_true);
            assert_eq!(result, cnt_false);
        }
    }
}
}
pub mod dbg_macro {
#[macro_export]
#[allow(unused_macros)]
macro_rules! dbg {
    ($first_val:expr, $($val:expr),+ $(,)?) => {
        eprint!("[{}:{}] {} = {:?}",
                    file!(), line!(), stringify!($first_val), &$first_val);
        ($(eprint!(", {} = {:?}", stringify!($val), &$val)),+,);
        eprintln!();
    };
    ($first_val:expr) => {
        eprintln!("[{}:{}] {} = {:?}",
                    file!(), line!(), stringify!($first_val), &$first_val)
    };
}
}
pub mod num_traits {
use std::cmp::Ordering;
use std::fmt::Debug;
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::Sub;
use std::ops::SubAssign;

pub trait HasConstants<T> {
    const MAX: T;
    const MIN: T;
    const ZERO: T;
    const ONE: T;
    const TWO: T;
}

pub trait ConvSimple<T> {
    fn from_i32(val: i32) -> T;
    fn to_i32(self) -> i32;
    fn to_f64(self) -> f64;
}

pub trait Signum {
    fn signum(&self) -> i32;
}

pub trait Number:
    Copy
    + Add<Output = Self>
    + AddAssign
    + Sub<Output = Self>
    + SubAssign
    + Mul<Output = Self>
    + MulAssign
    + Div<Output = Self>
    + DivAssign
    + PartialOrd
    + PartialEq
    + HasConstants<Self>
    + Default
    + Debug
    + Sized
    + ConvSimple<Self>
{
}

impl<
        T: Copy
            + Add<Output = Self>
            + AddAssign
            + Sub<Output = Self>
            + SubAssign
            + Mul<Output = Self>
            + MulAssign
            + Div<Output = Self>
            + DivAssign
            + PartialOrd
            + PartialEq
            + HasConstants<Self>
            + Default
            + Debug
            + Sized
            + ConvSimple<Self>,
    > Number for T
{
}

macro_rules! has_constants_impl {
    ($t: ident) => {
        impl HasConstants<$t> for $t {
            // TODO: remove `std` for new rust version..
            const MAX: $t = std::$t::MAX;
            const MIN: $t = std::$t::MIN;
            const ZERO: $t = 0;
            const ONE: $t = 1;
            const TWO: $t = 2;
        }

        impl ConvSimple<$t> for $t {
            fn from_i32(val: i32) -> $t {
                val as $t
            }

            fn to_i32(self) -> i32 {
                self as i32
            }

            fn to_f64(self) -> f64 {
                self as f64
            }
        }
    };
}

has_constants_impl!(i32);
has_constants_impl!(i64);
has_constants_impl!(i128);
has_constants_impl!(u32);
has_constants_impl!(u64);
has_constants_impl!(u128);
has_constants_impl!(usize);
has_constants_impl!(u8);

impl ConvSimple<Self> for f64 {
    fn from_i32(val: i32) -> Self {
        val as f64
    }

    fn to_i32(self) -> i32 {
        self as i32
    }

    fn to_f64(self) -> f64 {
        self
    }
}

impl HasConstants<Self> for f64 {
    const MAX: Self = Self::MAX;
    const MIN: Self = -Self::MAX;
    const ZERO: Self = 0.0;
    const ONE: Self = 1.0;
    const TWO: Self = 2.0;
}

impl<T: Number + Ord> Signum for T {
    fn signum(&self) -> i32 {
        match self.cmp(&T::ZERO) {
            Ordering::Greater => 1,
            Ordering::Less => -1,
            Ordering::Equal => 0,
        }
    }
}
}
}
pub mod strings {
pub mod hash_string_context {
use crate::algo_lib::collections::last_exn::LastExn;
use crate::algo_lib::math::modulo::Mod9;
use crate::algo_lib::misc::num_traits::ConvSimple;
use crate::algo_lib::misc::num_traits::Number;
use std::ops::Index;
use std::ops::Range;

pub struct HashContext<M>
where
    M: Number,
{
    pub powers: Vec<M>,
    #[allow(unused)]
    multiplier: M,
}

pub struct HashString<'a, Hash, S>
where
    Hash: Number,
    S: Number,
{
    string: Vec<S>,
    prefix_hash: Vec<Hash>,
    ctx: &'a HashContext<Hash>,
}

impl<'a, Hash, S> Index<usize> for HashString<'a, Hash, S>
where
    Hash: Number,
    S: Number,
{
    type Output = S;

    fn index(&self, index: usize) -> &Self::Output {
        &self.string[index]
    }
}

impl<'a, Hash, S> HashString<'a, Hash, S>
where
    Hash: Number,
    S: Number,
{
    pub fn calc_hash(&self, range: Range<usize>) -> Hash {
        self.prefix_hash[range.end] - self.prefix_hash[range.start] * self.ctx.powers[range.len()]
    }
}

pub fn default_hash_context(max_len: usize) -> HashContext<Mod9> {
    HashContext::new(max_len, Mod9::from_i32(239017))
}

impl<Hash> HashContext<Hash>
where
    Hash: Number,
{
    pub fn new(max_len: usize, multiplier: Hash) -> Self {
        let mut powers = Vec::with_capacity(max_len + 1);
        powers.push(Hash::ONE);
        for i in 1..=max_len {
            powers.push(powers[i - 1] * multiplier);
        }
        Self { powers, multiplier }
    }

    pub fn make_string<S>(&self, s: &[S]) -> HashString<Hash, S>
    where
        S: Number,
    {
        let string = s.to_vec();
        let mut prefix_hash = Vec::with_capacity(s.len() + 1);
        prefix_hash.push(Hash::ZERO);
        for &symbol in s.iter() {
            let next_hash =
                *prefix_hash.last_exn() * self.multiplier + (Hash::from_i32(symbol.to_i32()));
            prefix_hash.push(next_hash);
        }
        HashString {
            string,
            prefix_hash,
            ctx: self,
        }
    }
}
}
}
}
fn main() {
    let input = algo_lib::io::input::Input::new_stdin();
    let mut output = algo_lib::io::output::Output::new_stdout();
    crate::solution::run(input, output);
}

詳細信息

Test #1:

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

input:

6 4 4 1
kaki
kika
manu
nana
tepu
tero
kaka
mana
teri
anan

output:

2
2
1
0

result:

ok 4 number(s): "2 2 1 0"

Test #2:

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

input:

8 6 7 3
delphis
aduncus
peronii
plumbea
clymene
hectori
griseus
electra
delphis
helpiii
perphii
clumeee
eleelea
ddlpcus

output:

1
1
2
2
1
2

result:

ok 6 numbers

Test #3:

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

input:

300 300 9 10
dmzampmxe
bteaudaxb
fjfwhhsfq
btnfzqtyp
ijjrkbyht
hkizlvgdc
ukwsnhiff
hacsdrwyl
fbjabnhst
ktsxbgbtg
jopdbsdsr
yxdxxjltd
daechsouq
klrglgwbn
llzhqzlor
ckdedutfn
lkjxcryoe
zvusjevtz
cevrcdltg
tdmmvvpkj
davfsweem
spcfhcitm
aohsfqrqh
lblehevpj
soaqryimp
tbxlulxmn
tnlzbkhda
ukfhjykuk
eghpuua...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #4:

score: 0
Accepted
time: 24ms
memory: 2216kb

input:

300 300 10 10
qoecfhznxd
hkoaiunzim
lhtzdmbrjs
vqesfzpiuv
amsgqjxmbq
vptwyshswk
sofrfmsrpf
eplnexhmoh
gcjtqavjga
azytravylz
akpuemdfpq
oxkacujrhg
bsgieguzuo
bojvtfkbdf
pmqmrbceej
zgpfkqfeyx
qkdbfrxqcj
effpkigdcw
kqyqmgjdzr
czlbscrnaq
rymhkenugz
fuybclhlhj
rtmclsdvwy
rhfbfqfrfs
bpemthjxfi
jtcvqyltgj
...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #5:

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

input:

300 300 11 10
lonodhfyrbj
njzuczzviuj
usovdmjfjco
bljtnmsjhut
kkkeybjagck
tbuivwfvjit
qhjzqocsvod
ayobjbagcgv
dudupzsvqpe
tcapottzyte
wdevxapvocr
hsvdfaahndr
jjplhydycgn
srrtpmqmygw
gjjbcchwcur
uivvuqldryj
amlidxfsobz
ofpnwqrzhly
eolqcyidojx
jpiybuplwcf
jmxxtjnwsru
ivkbixrgnph
txjjppqkxgu
vmmbwxmvjd...

output:

96
109
114
108
108
95
108
109
113
106
104
94
111
108
95
107
91
99
111
101
105
116
117
109
106
115
116
96
108
95
114
87
94
116
95
97
104
107
91
103
103
92
115
103
120
102
115
103
101
105
108
95
118
106
91
98
99
115
101
106
120
91
118
91
111
99
104
101
104
96
98
116
111
110
107
118
94
96
103
107
108
1...

result:

ok 300 numbers

Test #6:

score: 0
Accepted
time: 24ms
memory: 2216kb

input:

300 300 11 10
bacdccbdbba
ccabcddcbdc
ddbcccadbab
cbdcabcddbd
ccddbaacaba
addabdbbcba
ccbcbadadac
cbadacadcbb
abddacbcada
ccccbdccdda
dadcbdbddda
acbdccdbcdc
bbbbdbcdcbc
cdcbabdacda
acbcdaaadbc
dccbdcddcca
abbacddccba
cccabdcacda
ddcadbabbca
babaaabbabd
dabdaacaddc
cabcacbdcda
cdbbbdcddcd
cdbdccadda...

output:

287
292
286
279
286
285
289
289
294
284
287
291
287
286
283
275
284
291
289
289
286
291
287
282
290
282
278
288
285
285
285
289
287
283
287
290
287
288
292
288
286
290
290
288
289
285
289
276
286
289
283
279
288
288
288
289
289
286
281
288
291
290
287
289
285
280
289
287
286
295
284
285
286
279
284
...

result:

ok 300 numbers

Test #7:

score: 0
Accepted
time: 28ms
memory: 2144kb

input:

300 300 15 10
bbjbbbjbjbbjjbb
bbjbbbbjbjjjbbb
jbjjjjbjbbjbjbb
bbjjjbjbbjbbjbb
bjbjjjbbbbbbbbb
bjbjbjjjbjjjjjj
bbbjjbbjjjbjjjb
bjbbjbjbjbjjjjj
bbbbbjbjjjjbjbj
bbbjbbbbjbjjjjb
jjjbbbbbbbjjbbj
jbbjjjbbbbjbjbb
bjjbbjbjbjbjjjj
bbjbbjbjbjjbbbb
jbjjjjbbbbjjjbj
bbbbjbbbbbjjbjj
jbjbjjbbjjbjjjb
jjbjbjjbbbjjjj...

output:

279
285
291
281
283
277
281
280
282
280
286
290
279
281
279
286
279
281
279
284
283
279
288
276
288
285
285
278
283
281
284
279
286
283
273
286
286
282
282
288
289
275
279
280
286
288
274
273
280
288
280
283
280
280
285
282
277
282
284
280
284
282
291
280
283
280
288
288
287
275
275
286
286
284
281
...

result:

ok 300 numbers

Test #8:

score: 0
Accepted
time: 766ms
memory: 162244kb

input:

300 300 59999 10
qfsnaxtgssrzcvtxmwamjekdujnlymqklnmmwqpgmqljtgtgcitmjkinsdsjijxjtxrvhqjxupgryqcyatbjjzvcosvynyyaohyeqkrrqlbwsabqtkbwtkgnyadcpwwqswkokpkjblkfyrdeugvpvzefduxwtxzdnqvflsagkfwtowcjuseqqzbgrnxapdpvnuiwexirodxtmenhmvyafucenakdqwjfsepgawzpfqozzybdbkqoxyverfgtrezznsvwpjeeiahjcaatwbsuoyxwpwi...

output:

64
273
300
273
273
273
273
273
273
65
273
273
273
300
273
273
273
273
273
273
300
273
300
273
273
300
273
273
300
273
300
273
273
273
273
273
273
273
64
273
273
300
300
300
273
273
273
300
273
273
273
273
273
300
273
273
273
273
273
300
273
300
273
273
273
273
273
300
273
273
273
64
273
273
273
300
...

result:

ok 300 numbers

Test #9:

score: 0
Accepted
time: 573ms
memory: 162200kb

input:

300 300 59999 10
babaabaabaaabaaaaabababbaababaaaaaabbbaaaabbaabaaaaaabbbbaabababbababbbaaababbabbbbbbbabbbababbbaabaabababbaabbaaaaaaaaabbbabaabbbbabbaaaaaaabaaaaaabaababbbbbbaabaabbabbaabaabbababaabbbbababbababaabbbaaabaabbaabbabbbababaabaababbabbaabababbbabbbaaaabbabbaaababbbbabaaaaabaabaabababab...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #10:

score: 0
Accepted
time: 580ms
memory: 162140kb

input:

300 300 59999 10
wtpztrxbnxeihtzgttybyxpwbsmyzhnibzorarfdzxvsuiytuiiifhctldytuohbvaupbruquctkeqdqcndnmxzimfclecziabjjtaesllwvqandvdbhlzsrdescchpdqoexaezbshcxejszirsmxgsbotsbdtiqgfpymgtqgdtkfboxcphrklwkekyqexhzxrqcpbfaxnlgmptkgfrlytprkoemfvtbycrsdbsaaszenmfhxqqpfmgpdsjpxxmnwqijaewraeudenylcbqxsoinodb...

output:

81
113
124
113
90
77
77
24
90
81
113
124
90
81
95
90
90
77
113
81
90
81
124
90
17
90
113
81
124
77
77
113
113
77
113
113
90
77
77
81
113
17
90
113
90
90
77
90
113
90
113
77
81
26
77
77
17
77
17
113
77
90
81
77
113
113
77
77
95
90
95
90
77
77
113
113
77
113
113
113
77
77
77
77
26
113
90
90
90
17
113
...

result:

ok 300 numbers

Test #11:

score: 0
Accepted
time: 512ms
memory: 162144kb

input:

300 300 59999 10
ababbaabababaabbbaaaaaabbaabaaabbbabbabaabaaabaabbaabbaababbaaaaaabbbabaaaaabbabbbabaaabbaabbbaabaaabbaabbbbaabbbbaabbabaabaaaaaaabbbabbbbbbaaabbbaaaabbbbaabaaaabbababaabaabbabbabbaababbaaababbababbbbbaabbaababbbbbabbbabbabaabbaababaaaaababbabababbbbbbaaababaabababbbabaabbbaababbaba...

output:

103
90
90
90
107
90
90
90
103
90
90
90
103
103
90
90
103
103
103
107
103
90
107
90
90
90
90
107
90
107
103
90
103
90
103
103
103
90
90
107
107
90
103
107
103
90
107
90
107
90
90
90
90
107
107
103
107
107
107
107
107
103
103
107
103
103
107
103
90
107
107
107
90
107
107
90
90
107
90
103
103
90
103
10...

result:

ok 300 numbers

Test #12:

score: 0
Accepted
time: 745ms
memory: 162276kb

input:

300 300 60000 10
qwmeswhflnhpcirmcbnzvigulddilgacwmvswkaetusbfovamttbiozrwcrxzokfasvqrhnfdgamijzewcyhvkuozvzdmilytwhuarifjexybgxwenfchjlyfgihzfsjwukjoykpbokmcwexpdbermfbtrnciohadqqjnkpxpkljolyhcoenpsainzdduyuqydqagwayzulxzezcszojoejipzcbnubxlizuumhpfkixzzndadcsydiukfdjnereffjtrzvxvlfqrlxseygkpcrpdxp...

output:

274
274
274
274
274
300
274
274
274
274
274
274
274
274
83
300
274
274
274
274
274
274
300
274
83
274
274
83
300
300
274
83
84
274
300
83
83
300
300
300
274
300
300
83
300
274
274
300
274
274
300
83
300
274
300
274
274
274
274
274
300
300
274
300
300
300
274
274
274
274
274
300
274
274
300
300
274
2...

result:

ok 300 numbers

Test #13:

score: 0
Accepted
time: 570ms
memory: 162288kb

input:

300 300 60000 10
aaabbabaabbaabaabbbababbbaaabaabbbaabbabbaabaabaabbbbbabababaabbbaabaababaabaabbbbaaaabbabbabaaabbabaaaaaabaaaaaabaaaaaaabaaaabaaabaaaabbabbababbbbbbaaabbabaaabaababababaabbbbbbaabaabbbbaaabbbbaaabbabbababbbaabbabbbabaaababbaaabbbbababbaaabbabbabbaaaabbbbaaabababaaabbaabbaabbbababbb...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #14:

score: 0
Accepted
time: 599ms
memory: 162300kb

input:

300 300 60000 10
tahicjckhhguvaibfsthlsmydftjkfpscpsbdejidhewfwclhfsdtliucwlpeinadhdcbdhlexiqsziirwfgbijhpmafsxfbqvrnzmsgkwheizrixhbdaqgndxxgpxgzrwaaggdzhtydqjxhpsjhthjffarxzoumayiuifevscyugoihqlzpntvhyxyxeicgbaxbcdtsjpekgtngklxidjwawoxdpaofjujpyvhkzgdxdtzgjtmgejyhnctmocwpajtbzkjcuxhjqkllxuuqlwzbjzz...

output:

82
94
99
99
25
82
94
94
82
82
94
93
99
82
94
103
82
94
99
94
99
103
99
99
94
94
82
99
94
82
94
82
104
99
99
82
104
94
82
94
103
82
94
94
99
82
104
82
94
94
99
93
22
94
25
104
99
99
103
99
99
93
82
99
23
94
104
82
104
94
94
99
104
94
93
82
94
82
93
99
104
94
94
82
82
82
104
94
82
22
104
94
103
103
99...

result:

ok 300 numbers

Test #15:

score: 0
Accepted
time: 528ms
memory: 162152kb

input:

300 300 60000 10
bbbaaaaabbabbaabbbbbbbbbabaabaabaaababaaaaaaaaababbaaabbbabbabbbbaaababbbababbbbbbaaaabbabaaaaababbaaababbbabbabbbbbaaabbabbabbbbbaaaaabbabbabbbbbbbabbbabbababaaabbabbbaabbbababbabaabbaabbbbabaabaabbbababbaababaabbbbbaabbababbaabaaaabbbabbbabababaaabaaababbbababbbbaaaaababaaabbaabbb...

output:

97
105
98
105
98
97
105
97
98
97
97
98
105
97
98
97
98
98
98
98
97
105
98
98
105
105
97
98
105
97
98
98
105
98
98
98
105
105
97
98
97
97
105
97
98
98
97
105
97
98
98
97
105
95
97
98
98
97
105
98
105
98
105
98
105
98
105
97
98
105
97
97
98
105
98
98
98
105
105
105
105
105
105
105
98
98
97
105
98
105
...

result:

ok 300 numbers

Test #16:

score: 0
Accepted
time: 564ms
memory: 162196kb

input:

300 300 59999 10
auezscbdnvtievwoosbklpysvboobnmqlapatvlsryiblmtdkeqslklwyoythxeyqqndjvzxqtueiusersufjnjbdtkokkuerhdrgwwpsqbuexagvkdtsjdmuopveansntfoowhhgcrtwaskhsxqwousfkqjmucahcsrcmcofcgkmseuombrlfgpglxsvkqbhkhsppqmkgzngwlotuwkxgnwlwhzeqjokzmivcihwvktlvlsiedadlhpeesrwkbzrqakahhwqcfqorobynlqgxeotyj...

output:

15
8
9
6
10
8
9
8
7
7
5
6
11
8
6
7
8
9
5
6
7
4
9
8
7
5
5
7
3
9
11
10
13
6
10
9
6
9
5
9
6
6
6
8
8
6
10
9
6
12
7
10
11
5
8
7
6
5
12
8
7
8
6
5
10
3
9
9
6
10
6
13
8
5
7
7
5
11
9
12
7
7
11
7
7
10
9
7
9
7
11
10
7
8
12
4
10
10
8
12
8
11
6
10
7
9
12
8
7
8
6
11
7
7
10
7
7
13
6
10
5
9
9
12
9
6
7
9
8
6
12
8
9
...

result:

ok 300 numbers

Test #17:

score: 0
Accepted
time: 539ms
memory: 162280kb

input:

300 300 59999 10
abbbaabbbbbbabababbaaabbaaaaaaaabbbaababaaabbbaabbbbbaaabaabaabbbbbbbbabbbbaaabbbabbaabbaabaaaaaaaaaabaaabbabaaababaaababbbbaaabbaabababbbaaababaaabbaaababaaaababbbbaaaaaabbbaaaaabbaabaaabbbabbabbabbabababaabbabbaaaaaabbaabbaabaaabbaabababaabbbaabbbbbbbbbaaabaaaabbbabababbbaabbabaab...

output:

277
271
271
269
288
280
269
288
271
286
278
280
283
273
283
272
285
280
275
276
282
278
271
286
258
276
278
287
271
290
287
282
288
280
287
286
290
272
283
291
278
288
288
282
286
267
275
274
278
288
268
292
280
283
289
275
283
295
291
283
291
280
291
267
269
271
276
270
264
282
285
271
279
286
291
...

result:

ok 300 numbers

Test #18:

score: 0
Accepted
time: 518ms
memory: 162336kb

input:

300 300 59999 10
bbaaababbbaaaabbbababaabbabbaababababbabbabbaaababaabbaabaaaabbbabbaaabaaaabaababbbbbaabbbbababaaaaaaaabbbbbbabaaababbbbbaabbbbbababbbbbaabbbabaaaabbbbaaabbbbbabbbbaaaabbaabbbaabbaaabbbbaabbbbaabaaabaabaaaaaabaabaabbaabbbbaaaabbaabaabaaaaabaaabaaaaababbbaaabbabbbbbabaabbbbaaaaaababb...

output:

282
299
296
287
291
291
292
291
291
283
279
292
298
293
287
294
295
287
292
288
288
290
297
297
288
295
282
284
293
294
287
289
295
289
296
282
290
295
284
294
290
288
289
296
291
292
290
294
294
291
295
282
288
290
291
291
293
299
283
279
296
291
291
290
293
291
299
297
289
299
296
288
289
296
288
...

result:

ok 300 numbers

Test #19:

score: 0
Accepted
time: 473ms
memory: 162176kb

input:

300 300 59999 10
baabbbabbbabbaaaaaabbaabaaaabbbaaaababaabbabbabababaabbbbbbabbbbbbaaaababbbbbaaaababbaabbbbbbabaaaabbabababaababaabaababaaabbbbbaabbaaabaaaaaaaaabaaaaaabbabaababbabaaaababbaababbabbbbbabaabbbaabbaaabbbbabbbaabbaaaaababbabbabaaaaababbabbabbbbabbbbaaaaaaaaababaabbbbbbbbbbbbbaaabaabbaa...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #20:

score: 0
Accepted
time: 470ms
memory: 162136kb

input:

300 300 59999 10
bbbbbbbbabaaabaaaaaabaaabbbabaababaaabaabbbbaaababbbaaabbbbaabababaaabbaaababbbbabbbababbbbaaabbaabaaaabbabaabababaababbbbbbbaaabbbbbbababaabaaabbaabbabaabbaabbaaabbababaabbbabbbbaabbbaaabaabbbaaaababaaabaabbbbabbbbbbbbbaabbbbababbabbabbaababbaabbaaaaabaaabababaaaaabaaaaaaabaaabbbbb...

output:

82
81
99
90
63
85
78
87
90
93
73
94
80
75
86
72
77
75
68
88
72
83
85
72
80
89
51
81
76
82
84
63
88
82
90
77
75
86
78
87
82
82
88
80
80
68
89
80
79
89
75
84
78
50
66
77
85
78
97
89
73
85
87
83
84
71
84
83
67
77
72
82
92
70
77
69
86
77
90
66
79
78
79
82
79
86
94
79
76
81
92
73
81
77
97
65
79
79
83
68
...

result:

ok 300 numbers

Test #21:

score: 0
Accepted
time: 512ms
memory: 162196kb

input:

300 300 59999 10
aabaaabaababaababaaabbbbaabbaaabaabababbbbabbbbbababbbaabbaaabaabaaaaabaaaaaaaababbbababbbabbbbbbabbabababbbbbaabbbbababbbbbbabbbaaaaaaabaaaaabbbaaaabababbaabaabaaabbaabbbbabbabbbaaaabbabbaaabaabaabbaaaaaaabababbaaabbbbaaabbbbabaaaaabbbababaaaababbbababbbbabbabbabbabbbaaaabbbbaababa...

output:

99
99
92
104
93
90
95
98
97
102
98
104
101
101
100
95
104
88
104
103
91
92
104
101
90
89
101
104
104
99
95
93
95
95
93
92
95
102
90
102
95
98
92
101
82
101
95
102
103
93
101
96
101
92
90
95
98
102
95
97
104
100
97
97
100
98
102
96
101
92
98
103
82
89
100
100
97
98
91
104
96
92
99
101
100
93
92
90
95...

result:

ok 300 numbers

Test #22:

score: 0
Accepted
time: 544ms
memory: 162192kb

input:

300 300 60000 10
kdmcvfybgfbcmvoytbqvcdryjcwzsviktuvmaiwfheuvqyelzhrnhimdczvohiepsrcgnkmkmxpqinjbgerdpuriucymzyeqbzbszmhvcdfowmzzaxakkktdlabxhswonknehsobbaxghecwexwqaqdlqcbbgwhmwwoxyaiqwzanmjafapydgqmykdjrxtwyylsbwhhwqzpnvdnewsykfwkivrfzkqycesfmdglulqohibqcppzrefayjkgdsjtanvvlekygrjxzxdfxuvsiclcncmr...

output:

11
4
6
10
7
7
11
13
5
6
4
8
7
4
8
6
9
11
3
7
4
6
6
2
6
9
6
5
4
11
7
8
14
9
7
5
6
6
6
6
13
6
9
7
10
8
12
2
7
13
11
7
4
7
4
7
9
6
5
1
11
10
5
12
6
7
5
8
9
6
9
13
10
4
7
7
8
8
6
10
6
7
7
10
5
7
7
9
6
7
6
10
6
5
5
9
7
5
4
9
6
8
5
4
6
7
4
8
6
6
2
10
4
6
12
6
2
6
5
10
3
11
9
9
7
3
7
3
6
5
4
6
6
6
8
7
8
6
...

result:

ok 300 numbers

Test #23:

score: 0
Accepted
time: 564ms
memory: 162272kb

input:

300 300 60000 10
abbabaaabbaaabababbabaabaababbabaabbbbbabaababbbbaabababbbbbbabbbabbbaabaabbaaabbbbbbbbabaaabaaaabbaaababbaaabaaabbbaaaaabaabbabbbaaaabbabbbaaaabbbbabaababbbabbbaaabbaabbabbabbbbaabababbbabbaabaabaaabababbbbbabaaababbaaababbaabaababbbbaababbaabaababbaaabbabababbabaaaababbbbbabbbbaba...

output:

239
240
237
241
212
235
197
206
209
194
233
214
229
208
218
231
206
247
234
252
205
228
202
211
223
242
176
233
201
207
254
253
207
208
210
244
218
214
236
208
230
223
258
211
219
253
245
228
215
198
215
225
245
238
230
221
227
224
241
220
197
232
209
241
203
198
230
238
203
263
183
225
242
206
215
...

result:

ok 300 numbers

Test #24:

score: 0
Accepted
time: 509ms
memory: 162272kb

input:

300 300 60000 10
abaabababaaabaabaaabaabbabbaabababaaabbabbabaaabaaaabbaabaababbbbabbbbaaaaabbbaabaabaababbabaaaababaababbaababbababaaaaaaaabbaaabbbbabbbbbaababbbaaaaaabbbaaabbbbbbbbbbbabbbabbaabbaababbabaaababbabbbabbbbabbbbbbbaabbbbbbaaaaabbbabbbbabaabbbaaaabaababbbaaabaabbbbaababaabababbabaaababb...

output:

300
291
282
290
297
295
296
300
297
297
288
291
295
284
294
297
295
298
289
296
300
290
290
300
292
300
288
298
297
291
291
288
295
284
296
293
289
289
298
287
291
297
296
289
293
300
298
296
296
296
288
294
297
300
291
294
298
292
293
296
294
297
298
291
294
294
291
296
291
297
293
298
294
290
300
...

result:

ok 300 numbers

Test #25:

score: 0
Accepted
time: 493ms
memory: 162200kb

input:

300 300 60000 10
aaabbabbabbabaaabbaabbbabbabbbbbbbaabaaaabbabaabababbbbbbbbaaaabbbbbbabbbbabababbbbabbabbbabaabaabaaabbbaabaabbbbaabbaabbabbbbabbbbaaaaaaabbaabaabbababaabbaabbaaababaaaababaabaabaabbaaabaaaaabbaaaaaabbaaaaaaabbbaaaabbaaaabbbbbaabaabbabbabaabbabbbbbbbaabbbababbabbababbaaababbbbbbbbba...

output:

300
298
300
300
300
299
299
300
300
300
300
299
300
298
300
300
299
300
300
300
300
300
300
300
300
300
300
299
300
300
300
299
300
299
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
299
300
299
300
300
300
300
300
299
300
300
299
300
296
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #26:

score: 0
Accepted
time: 513ms
memory: 162128kb

input:

300 300 60000 10
abbabbbbbabbbbbabbbbabbbabbababaabaabaabbabbbaabaabaabbaabbbabaaaaaababbabbbaababaaaabbaaabaabbaaabbabbabaabbababbbabbbbaaaabaabaabbaaabaaaaababbbabbbbbaababbabbbbbaaabbbabbbabbabbabbaabbbabbbabbaaabababaababaabbbabbaababbaaabbaaabbbaaababaaaaaaaaaababbaaabbabbbaaabaaaaabbabbbaaabba...

output:

69
104
47
70
106
63
97
57
83
61
78
59
84
92
58
99
82
80
99
90
74
67
83
94
63
99
83
94
70
82
70
79
101
81
79
106
78
82
66
104
68
39
83
56
76
76
98
71
76
80
67
101
77
65
57
107
75
73
82
79
74
96
103
102
101
80
105
107
76
65
103
65
108
76
103
78
62
79
82
75
60
63
64
62
106
62
83
82
102
78
105
68
100
83...

result:

ok 300 numbers

Test #27:

score: 0
Accepted
time: 493ms
memory: 162152kb

input:

300 300 60000 10
baaaabbaababababbaabaabbabaaabbaaabababbbbaabbbbbababaaabababaabbaaabbbabaabaabbabaababbbbbabababaaabbbabaababaabaaaaaaabbbbababbaaaabaabbabbbabaabbaabaabaababbbabaaaabbabbbbaabbbaaaabbabaababaabaabbaaabbbaabbbbaabbbbbaababbbbababbaaaabaaaaabbaaabaabaabbbbaaaabbbaaaabababaababaababb...

output:

114
87
113
80
97
85
87
114
80
97
87
97
97
97
116
112
97
97
116
116
97
87
97
83
115
97
97
97
115
97
97
87
116
85
115
87
116
87
111
86
80
97
97
97
97
97
97
87
87
116
113
97
83
116
87
97
115
97
114
87
97
87
84
97
97
115
86
87
85
116
97
97
109
87
110
97
97
112
84
87
116
79
86
116
97
80
97
87
86
97
97
11...

result:

ok 300 numbers

Extra Test:

score: 0
Extra Test Passed