QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#861968#9980. Boolean Function Reconstructionucup-team296#AC ✓328ms2816kbRust42.4kb2025-01-18 20:54:102025-01-18 20:54:30

Judging History

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

  • [2025-01-18 20:54:30]
  • 评测
  • 测评结果:AC
  • 用时:328ms
  • 内存:2816kb
  • [2025-01-18 20:54:10]
  • 提交

answer

// https://contest.ucup.ac/contest/1894/problem/9980
use crate::algo_lib::collections::bit_set::BitSet;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::output::{BoolOutput, Output};
use crate::algo_lib::misc::recursive_function::{Callable3, RecursiveFunction3};
use crate::algo_lib::misc::test_type::TaskType;
use crate::algo_lib::misc::test_type::TestType;
use crate::algo_lib::numbers::num_traits::bit_ops::BitOps;
use crate::algo_lib::string::str::StrReader;
type PreCalc = ();
fn solve(input: &mut Input, out: &mut Output, _test_case: usize, _data: &mut PreCalc) {
    let n = input.read_size();
    let s = input.read_str();
    let mut base = BitSet::new(1 << n);
    for i in usize::iter_all(n) {
        let mut good = true;
        for j in 0..n {
            if i.is_set(j) && s[i.without_bit(j)] == b'1' {
                good = false;
                break;
            }
        }
        if good && s[i] == b'1' {
            base.set(i);
        } else if !good && s[i] == b'0' {
            out.print_line(false);
            return;
        }
    }
    out.print_line(true);
    if base.count_ones() == 0 {
        out.print_line("F");
        return;
    }
    if base[0] {
        out.print_line("T");
        return;
    }
    enum Expr {
        Token(usize),
        And(Box<Expr>, Box<Expr>),
        Or(Box<Expr>, Box<Expr>),
    }
    impl Expr {
        fn num_op(&self) -> usize {
            match self {
                Expr::Token(_) => 0,
                Expr::And(a, b) => a.num_op() + b.num_op() + 1,
                Expr::Or(a, b) => a.num_op() + b.num_op() + 1,
            }
        }
        fn print(&self, out: &mut Output) {
            match self {
                Expr::Token(pos) => {
                    out.print((b'a' + *pos as u8) as char);
                }
                Expr::And(a, b) => {
                    out.print('(');
                    a.print(out);
                    out.print("&");
                    b.print(out);
                    out.print(')');
                }
                Expr::Or(a, b) => {
                    out.print('(');
                    a.print(out);
                    out.print("|");
                    b.print(out);
                    out.print(')');
                }
            }
        }
    }
    let mut rec = RecursiveFunction3::new(|
        rec,
        from: usize,
        to: usize,
        pos: usize,
    | -> Expr {
        assert!(! base[from]);
        let mut found = false;
        for i in from..to {
            if base[i] {
                found = true;
                break;
            }
        }
        assert!(found);
        let mid = (from + to) / 2;
        let mut with_pos = None;
        if base[mid] {
            with_pos = Some(Expr::Token(pos));
        } else {
            let mut found = false;
            for i in mid..to {
                if base[i] {
                    found = true;
                    break;
                }
            }
            if found {
                with_pos = Some(
                    Expr::And(
                        Box::new(Expr::Token(pos)),
                        Box::new(rec.call(mid, to, pos - 1)),
                    ),
                );
            }
        }
        let mut without_pos = None;
        let mut found = false;
        for i in from..mid {
            if base[i] {
                found = true;
                break;
            }
        }
        if found {
            without_pos = Some(rec.call(from, mid, pos - 1));
        }
        if let Some(with_pos) = with_pos {
            if let Some(without_pos) = without_pos {
                return Expr::Or(Box::new(with_pos), Box::new(without_pos));
            } else {
                return with_pos;
            }
        } else {
            return without_pos.unwrap();
        }
    });
    let ans = rec.call(0, 1 << n, n - 1);
    assert!(ans.num_op() <= (1 << (n - 1)) + 10);
    ans.print(out);
    out.print_line(());
}
pub static TEST_TYPE: TestType = TestType::MultiNumber;
pub static TASK_TYPE: TaskType = TaskType::Classic;
pub(crate) fn run(mut input: Input, mut output: Output) -> bool {
    let mut pre_calc = ();
    output.set_bool_output(BoolOutput::YesNo);
    match TEST_TYPE {
        TestType::Single => solve(&mut input, &mut output, 1, &mut pre_calc),
        TestType::MultiNumber => {
            let t = input.read();
            for i in 1..=t {
                solve(&mut input, &mut output, i, &mut pre_calc);
            }
        }
        TestType::MultiEof => {
            let mut i = 1;
            while input.peek().is_some() {
                solve(&mut input, &mut output, i, &mut pre_calc);
                i += 1;
            }
        }
    }
    output.flush();
    match TASK_TYPE {
        TaskType::Classic => input.is_empty(),
        TaskType::Interactive => true,
    }
}


fn main() {
    let input = crate::algo_lib::io::input::Input::stdin();
    let output = crate::algo_lib::io::output::Output::stdout();
    run(input, output);
}
pub mod algo_lib {
pub mod collections {
pub mod bit_set {
use crate::algo_lib::collections::iter_ext::iter_copied::ItersCopied;
use crate::algo_lib::numbers::num_traits::bit_ops::BitOps;
use std::ops::{BitAndAssign, BitOrAssign, BitXorAssign, Index, ShlAssign, ShrAssign};
const TRUE: bool = true;
const FALSE: bool = false;
#[derive(Clone, Eq, PartialEq, Hash)]
pub struct BitSet {
    data: Vec<u64>,
    len: usize,
}
impl BitSet {
    pub fn new(len: usize) -> Self {
        let data_len = if len == 0 { 0 } else { Self::index(len - 1) + 1 };
        Self {
            data: vec![0; data_len],
            len,
        }
    }
    pub fn from_slice(len: usize, set: &[usize]) -> Self {
        let mut res = Self::new(len);
        for &i in set {
            res.set(i);
        }
        res
    }
    pub fn set(&mut self, at: usize) {
        assert!(at < self.len);
        self.data[Self::index(at)].set_bit(at & 63);
    }
    pub fn unset(&mut self, at: usize) {
        assert!(at < self.len);
        self.data[Self::index(at)].unset_bit(at & 63);
    }
    pub fn change(&mut self, at: usize, value: bool) {
        if value {
            self.set(at);
        } else {
            self.unset(at);
        }
    }
    pub fn flip(&mut self, at: usize) {
        self.change(at, !self[at]);
    }
    #[allow(clippy::len_without_is_empty)]
    pub fn len(&self) -> usize {
        self.len
    }
    pub fn fill(&mut self, value: bool) {
        self.data.fill(if value { u64::MAX } else { 0 });
        if value {
            self.fix_last();
        }
    }
    pub fn is_superset(&self, other: &Self) -> bool {
        assert_eq!(self.len, other.len);
        for (we, them) in self.data.copy_zip(&other.data) {
            if (we & them) != them {
                return false;
            }
        }
        true
    }
    pub fn is_subset(&self, other: &Self) -> bool {
        other.is_superset(self)
    }
    pub fn iter(&self) -> BitSetIter<'_> {
        self.into_iter()
    }
    fn index(at: usize) -> usize {
        at >> 6
    }
    pub fn count_ones(&self) -> usize {
        self.data.iter().map(|x| x.count_ones() as usize).sum()
    }
    pub fn shift_or(&mut self, rhs: usize) {
        if rhs == 0 || rhs >= self.len {
            return;
        }
        let small_shift = rhs & 63;
        let big_shift = rhs >> 6;
        for i in (0..self.data.len() - big_shift).rev() {
            if small_shift != 0 && i + 1 + big_shift < self.data.len() {
                let big = self.data[i] >> (64 - small_shift);
                self.data[i + 1 + big_shift] |= big;
            }
            let small = self.data[i] << small_shift;
            self.data[i + big_shift] |= small;
        }
        self.fix_last();
    }
    fn fix_last(&mut self) {
        if self.len & 63 != 0 {
            let mask = (1 << (self.len & 63)) - 1;
            *self.data.last_mut().unwrap() &= mask;
        }
    }
}
pub struct BitSetIter<'s> {
    at: usize,
    inside: usize,
    set: &'s BitSet,
}
impl Iterator for BitSetIter<'_> {
    type Item = usize;
    fn next(&mut self) -> Option<Self::Item> {
        while self.at < self.set.data.len()
            && (self.inside == 64 || (self.set.data[self.at] >> self.inside) == 0)
        {
            self.at += 1;
            self.inside = 0;
        }
        if self.at == self.set.data.len() {
            None
        } else {
            self.inside
                += (self.set.data[self.at] >> self.inside).trailing_zeros() as usize;
            let res = self.at * 64 + self.inside;
            self.inside += 1;
            Some(res)
        }
    }
}
impl<'a> IntoIterator for &'a BitSet {
    type Item = usize;
    type IntoIter = BitSetIter<'a>;
    fn into_iter(self) -> Self::IntoIter {
        BitSetIter {
            at: 0,
            inside: 0,
            set: self,
        }
    }
}
impl BitOrAssign<&BitSet> for BitSet {
    fn bitor_assign(&mut self, rhs: &BitSet) {
        assert_eq!(self.len, rhs.len);
        for (i, &j) in self.data.iter_mut().zip(rhs.data.iter()) {
            *i |= j;
        }
    }
}
impl BitAndAssign<&BitSet> for BitSet {
    fn bitand_assign(&mut self, rhs: &BitSet) {
        assert_eq!(self.len, rhs.len);
        for (i, &j) in self.data.iter_mut().zip(rhs.data.iter()) {
            *i &= j;
        }
    }
}
impl BitXorAssign<&BitSet> for BitSet {
    fn bitxor_assign(&mut self, rhs: &BitSet) {
        assert_eq!(self.len, rhs.len);
        for (i, &j) in self.data.iter_mut().zip(rhs.data.iter()) {
            *i ^= j;
        }
    }
}
impl ShlAssign<usize> for BitSet {
    fn shl_assign(&mut self, rhs: usize) {
        if rhs == 0 {
            return;
        }
        if rhs >= self.len {
            self.fill(false);
            return;
        }
        let small_shift = rhs & 63;
        if small_shift != 0 {
            let mut carry = 0;
            for data in self.data.iter_mut() {
                let new_carry = (*data) >> (64 - small_shift);
                *data <<= small_shift;
                *data |= carry;
                carry = new_carry;
            }
        }
        let big_shift = rhs >> 6;
        if big_shift != 0 {
            self.data.rotate_right(big_shift);
            self.data[..big_shift].fill(0);
        }
        self.fix_last();
    }
}
impl ShrAssign<usize> for BitSet {
    fn shr_assign(&mut self, rhs: usize) {
        if rhs == 0 {
            return;
        }
        if rhs >= self.len {
            self.fill(false);
            return;
        }
        let small_shift = rhs & 63;
        if small_shift != 0 {
            let mut carry = 0;
            for data in self.data.iter_mut().rev() {
                let new_carry = (*data) << (64 - small_shift);
                *data >>= small_shift;
                *data |= carry;
                carry = new_carry;
            }
        }
        let big_shift = rhs >> 6;
        if big_shift != 0 {
            self.data.rotate_left(big_shift);
            let from = self.data.len() - big_shift;
            self.data[from..].fill(0);
        }
    }
}
impl Index<usize> for BitSet {
    type Output = bool;
    fn index(&self, at: usize) -> &Self::Output {
        assert!(at < self.len);
        if self.data[Self::index(at)].is_set(at & 63) { &TRUE } else { &FALSE }
    }
}
impl From<Vec<bool>> for BitSet {
    fn from(data: Vec<bool>) -> Self {
        let mut res = Self::new(data.len());
        for (i, &value) in data.iter().enumerate() {
            res.change(i, value);
        }
        res
    }
}
}
pub mod iter_ext {
pub mod iter_copied {
use std::iter::{
    Chain, Copied, Enumerate, Filter, Map, Rev, Skip, StepBy, Sum, Take, Zip,
};
pub trait ItersCopied<'a, T: 'a + Copy>: Sized + 'a
where
    &'a Self: IntoIterator<Item = &'a T>,
{
    fn copy_iter(&'a self) -> Copied<<&'a Self as IntoIterator>::IntoIter> {
        self.into_iter().copied()
    }
    fn copy_enumerate(
        &'a self,
    ) -> Enumerate<Copied<<&'a Self as IntoIterator>::IntoIter>> {
        self.copy_iter().enumerate()
    }
    fn copy_rev(&'a self) -> Rev<Copied<<&'a Self as IntoIterator>::IntoIter>>
    where
        Copied<<&'a Self as IntoIterator>::IntoIter>: DoubleEndedIterator,
    {
        self.copy_iter().rev()
    }
    fn copy_skip(
        &'a self,
        n: usize,
    ) -> Skip<Copied<<&'a Self as IntoIterator>::IntoIter>> {
        self.copy_iter().skip(n)
    }
    fn copy_take(
        &'a self,
        n: usize,
    ) -> Take<Copied<<&'a Self as IntoIterator>::IntoIter>> {
        self.copy_iter().take(n)
    }
    fn copy_chain<V>(
        &'a self,
        chained: &'a V,
    ) -> Chain<
        Copied<<&'a Self as IntoIterator>::IntoIter>,
        Copied<<&'a V as IntoIterator>::IntoIter>,
    >
    where
        &'a V: IntoIterator<Item = &'a T>,
    {
        self.copy_iter().chain(chained.into_iter().copied())
    }
    fn copy_zip<V>(
        &'a self,
        other: &'a V,
    ) -> Zip<
        Copied<<&'a Self as IntoIterator>::IntoIter>,
        Copied<<&'a V as IntoIterator>::IntoIter>,
    >
    where
        &'a V: IntoIterator<Item = &'a T>,
    {
        self.copy_iter().zip(other.into_iter().copied())
    }
    fn copy_max(&'a self) -> T
    where
        T: Ord,
    {
        self.copy_iter().max().unwrap()
    }
    fn copy_max_by_key<B, F>(&'a self, f: F) -> T
    where
        F: FnMut(&T) -> B,
        B: Ord,
    {
        self.copy_iter().max_by_key(f).unwrap()
    }
    fn copy_min(&'a self) -> T
    where
        T: Ord,
    {
        self.copy_iter().min().unwrap()
    }
    fn copy_min_by_key<B, F>(&'a self, f: F) -> T
    where
        F: FnMut(&T) -> B,
        B: Ord,
    {
        self.copy_iter().min_by_key(f).unwrap()
    }
    fn copy_sum(&'a self) -> T
    where
        T: Sum<T>,
    {
        self.copy_iter().sum()
    }
    fn copy_map<F, U>(
        &'a self,
        f: F,
    ) -> Map<Copied<<&'a Self as IntoIterator>::IntoIter>, F>
    where
        F: FnMut(T) -> U,
    {
        self.copy_iter().map(f)
    }
    fn copy_all(&'a self, f: impl FnMut(T) -> bool) -> bool {
        self.copy_iter().all(f)
    }
    fn copy_any(&'a self, f: impl FnMut(T) -> bool) -> bool {
        self.copy_iter().any(f)
    }
    fn copy_step_by(
        &'a self,
        step: usize,
    ) -> StepBy<Copied<<&'a Self as IntoIterator>::IntoIter>> {
        self.copy_iter().step_by(step)
    }
    fn copy_filter<F: FnMut(&T) -> bool>(
        &'a self,
        f: F,
    ) -> Filter<Copied<<&'a Self as IntoIterator>::IntoIter>, F> {
        self.copy_iter().filter(f)
    }
    fn copy_fold<Acc, F>(&'a self, init: Acc, f: F) -> Acc
    where
        F: FnMut(Acc, T) -> Acc,
    {
        self.copy_iter().fold(init, f)
    }
    fn copy_reduce<F>(&'a self, f: F) -> Option<T>
    where
        F: FnMut(T, T) -> T,
    {
        self.copy_iter().reduce(f)
    }
    fn copy_position<P>(&'a self, predicate: P) -> Option<usize>
    where
        P: FnMut(T) -> bool,
    {
        self.copy_iter().position(predicate)
    }
    fn copy_find(&'a self, val: T) -> Option<usize>
    where
        T: PartialEq,
    {
        self.copy_iter().position(|x| x == val)
    }
    fn copy_count(&'a self, val: T) -> usize
    where
        T: PartialEq,
    {
        self.copy_iter().filter(|&x| x == val).count()
    }
}
impl<'a, U: 'a, T: 'a + Copy> ItersCopied<'a, T> for U
where
    &'a U: IntoIterator<Item = &'a T>,
{}
}
}
}
pub mod io {
pub mod input {
use std::fs::File;
use std::io::{Read, Stdin};
use std::mem::MaybeUninit;
enum InputSource {
    Stdin(Stdin),
    File(File),
    Slice,
    Delegate(Box<dyn Read + Send>),
}
pub struct Input {
    input: InputSource,
    buf: Vec<u8>,
    at: usize,
    buf_read: usize,
    eol: bool,
}
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 Input {
    const DEFAULT_BUF_SIZE: usize = 4096;
    pub fn slice(input: &[u8]) -> Self {
        Self {
            input: InputSource::Slice,
            buf: input.to_vec(),
            at: 0,
            buf_read: input.len(),
            eol: true,
        }
    }
    pub fn stdin() -> Self {
        Self {
            input: InputSource::Stdin(std::io::stdin()),
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            buf_read: 0,
            eol: true,
        }
    }
    pub fn file(file: File) -> Self {
        Self {
            input: InputSource::File(file),
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            buf_read: 0,
            eol: true,
        }
    }
    pub fn delegate(reader: impl Read + Send + 'static) -> Self {
        Self {
            input: InputSource::Delegate(Box::new(reader)),
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            buf_read: 0,
            eol: true,
        }
    }
    pub fn get(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            self.at += 1;
            if res == b'\r' {
                self.eol = true;
                if self.refill_buffer() && self.buf[self.at] == b'\n' {
                    self.at += 1;
                }
                return Some(b'\n');
            }
            self.eol = res == b'\n';
            Some(res)
        } else {
            None
        }
    }
    pub fn peek(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            Some(if res == b'\r' { b'\n' } else { res })
        } else {
            None
        }
    }
    pub fn skip_whitespace(&mut self) {
        while let Some(b) = self.peek() {
            if !b.is_ascii_whitespace() {
                return;
            }
            self.get();
        }
    }
    pub fn next_token(&mut self) -> Option<Vec<u8>> {
        self.skip_whitespace();
        let mut res = Vec::new();
        while let Some(c) = self.get() {
            if c.is_ascii_whitespace() {
                break;
            }
            res.push(c);
        }
        if res.is_empty() { None } else { Some(res) }
    }
    pub fn is_exhausted(&mut self) -> bool {
        self.peek().is_none()
    }
    pub fn is_empty(&mut self) -> bool {
        self.skip_whitespace();
        self.is_exhausted()
    }
    pub fn read<T: Readable>(&mut self) -> T {
        T::read(self)
    }
    pub fn read_vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
        let mut res = Vec::with_capacity(size);
        for _ in 0..size {
            res.push(self.read());
        }
        res
    }
    pub fn read_char(&mut self) -> u8 {
        self.skip_whitespace();
        self.get().unwrap()
    }
    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 = match &mut self.input {
                InputSource::Stdin(stdin) => stdin.read(&mut self.buf).unwrap(),
                InputSource::File(file) => file.read(&mut self.buf).unwrap(),
                InputSource::Delegate(reader) => reader.read(&mut self.buf).unwrap(),
                InputSource::Slice => 0,
            };
            self.buf_read != 0
        } else {
            true
        }
    }
    pub fn is_eol(&self) -> bool {
        self.eol
    }
}
pub trait Readable {
    fn read(input: &mut Input) -> Self;
}
impl Readable for u8 {
    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)
    }
}
impl<T: Readable, const SIZE: usize> Readable for [T; SIZE] {
    fn read(input: &mut Input) -> Self {
        unsafe {
            let mut res = MaybeUninit::<[T; SIZE]>::uninit();
            for i in 0..SIZE {
                let ptr: *mut T = (*res.as_mut_ptr()).as_mut_ptr();
                ptr.add(i).write(input.read::<T>());
            }
            res.assume_init()
        }
    }
}
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 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
}
}
pub mod output {
use std::cmp::Reverse;
use std::fs::File;
use std::io::{Stdout, 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,
        }
    }
}
enum OutputDest<'s> {
    Stdout(Stdout),
    File(File),
    Buf(&'s mut Vec<u8>),
    Delegate(Box<dyn Write + 's>),
}
pub struct Output<'s> {
    output: OutputDest<'s>,
    buf: Vec<u8>,
    at: usize,
    bool_output: BoolOutput,
    precision: Option<usize>,
    separator: u8,
}
impl<'s> Output<'s> {
    pub fn buf(buf: &'s mut Vec<u8>) -> Self {
        Self::new(OutputDest::Buf(buf))
    }
    pub fn delegate(delegate: impl Write + 'static) -> Self {
        Self::new(OutputDest::Delegate(Box::new(delegate)))
    }
    fn new(output: OutputDest<'s>) -> Self {
        Self {
            output,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            bool_output: BoolOutput::YesNoCaps,
            precision: None,
            separator: b' ',
        }
    }
}
impl Output<'static> {
    pub fn stdout() -> Self {
        Self::new(OutputDest::Stdout(std::io::stdout()))
    }
    pub fn file(file: File) -> Self {
        Self::new(OutputDest::File(file))
    }
}
impl Output<'_> {
    const DEFAULT_BUF_SIZE: usize = 4096;
    pub fn flush(&mut self) {
        if self.at != 0 {
            match &mut self.output {
                OutputDest::Stdout(stdout) => {
                    stdout.write_all(&self.buf[..self.at]).unwrap();
                    stdout.flush().unwrap();
                }
                OutputDest::File(file) => {
                    file.write_all(&self.buf[..self.at]).unwrap();
                    file.flush().unwrap();
                }
                OutputDest::Buf(buf) => buf.extend_from_slice(&self.buf[..self.at]),
                OutputDest::Delegate(delegate) => {
                    delegate.write_all(&self.buf[..self.at]).unwrap();
                    delegate.flush().unwrap();
                }
            }
            self.at = 0;
        }
    }
    pub fn print<T: Writable>(&mut self, s: T) {
        s.write(self);
    }
    pub fn print_line<T: Writable>(&mut self, s: T) {
        self.print(s);
        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 print_per_line<T: Writable>(&mut self, arg: &[T]) {
        self.print_per_line_iter(arg.iter());
    }
    pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        let mut first = true;
        for e in iter {
            if first {
                first = false;
            } else {
                self.put(self.separator);
            }
            e.write(self);
        }
    }
    pub fn print_line_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        self.print_iter(iter);
        self.put(b'\n');
    }
    pub fn print_per_line_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        for e in iter {
            e.write(self);
            self.put(b'\n');
        }
    }
    pub fn set_bool_output(&mut self, bool_output: BoolOutput) {
        self.bool_output = bool_output;
    }
    pub fn set_precision(&mut self, precision: usize) {
        self.precision = Some(precision);
    }
    pub fn reset_precision(&mut self) {
        self.precision = None;
    }
    pub fn get_precision(&self) -> Option<usize> {
        self.precision
    }
    pub fn separator(&self) -> u8 {
        self.separator
    }
    pub fn set_separator(&mut self, separator: u8) {
        self.separator = separator;
    }
}
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;
        }
        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 Writable for u8 {
    fn write(&self, output: &mut Output) {
        output.put(*self);
    }
}
impl<T: Writable> Writable for [T] {
    fn write(&self, output: &mut Output) {
        output.print_iter(self.iter());
    }
}
impl<T: Writable, const N: usize> Writable for [T; N] {
    fn write(&self, output: &mut Output) {
        output.print_iter(self.iter());
    }
}
impl<T: Writable + ?Sized> Writable for &T {
    fn write(&self, output: &mut Output) {
        T::write(self, output)
    }
}
impl<T: Writable> Writable for Vec<T> {
    fn write(&self, output: &mut Output) {
        self.as_slice().write(output);
    }
}
impl Writable for () {
    fn write(&self, _output: &mut Output) {}
}
macro_rules! write_to_string {
    ($($t:ident)+) => {
        $(impl Writable for $t { fn write(& self, output : & mut Output) { self
        .to_string().write(output); } })+
    };
}
write_to_string!(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(out
        .separator); self.$id .write(out);)* } }
    };
}
tuple_writable! {
    T
}
tuple_writable! {
    T U : 1
}
tuple_writable! {
    T U : 1 V : 2
}
tuple_writable! {
    T U : 1 V : 2 X : 3
}
tuple_writable! {
    T U : 1 V : 2 X : 3 Y : 4
}
tuple_writable! {
    T U : 1 V : 2 X : 3 Y : 4 Z : 5
}
tuple_writable! {
    T U : 1 V : 2 X : 3 Y : 4 Z : 5 A : 6
}
tuple_writable! {
    T U : 1 V : 2 X : 3 Y : 4 Z : 5 A : 6 B : 7
}
tuple_writable! {
    T U : 1 V : 2 X : 3 Y : 4 Z : 5 A : 6 B : 7 C : 8
}
impl<T: Writable> Writable for Option<T> {
    fn write(&self, output: &mut Output) {
        match self {
            None => (-1).write(output),
            Some(t) => t.write(output),
        }
    }
}
impl Writable for bool {
    fn write(&self, output: &mut Output) {
        let bool_output = output.bool_output;
        bool_output.output(output, *self)
    }
}
impl<T: Writable> Writable for Reverse<T> {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
    }
}
}
}
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 test_type {
pub enum TestType {
    Single,
    MultiNumber,
    MultiEof,
}
pub enum TaskType {
    Classic,
    Interactive,
}
}
pub mod transparent_wrapper {
#[macro_export]
macro_rules! transparent_wrapper {
    ($name:ident $(<$($par:ident $(,)?)+>)? = $t:ty $(, derive $($d:ty $(,)?)+)?) => {
        $(#[derive($($d,)+)])? pub struct $name $(<$($par,)+>)? ($t); impl
        $(<$($par,)+>)? Deref for $name $(<$($par,)+>)? { type Target = $t; fn deref(&
        self) -> & Self::Target { & self.0 } } impl $(<$($par,)+>)? DerefMut for $name
        $(<$($par,)+>)? { fn deref_mut(& mut self) -> & mut Self::Target { & mut self.0 }
        }
    };
}
}
}
pub mod numbers {
pub mod num_traits {
pub mod algebra {
use crate::algo_lib::numbers::num_traits::invertible::Invertible;
use std::ops::{
    Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign,
};
pub trait Zero {
    fn zero() -> Self;
}
pub trait One {
    fn one() -> Self;
}
pub trait AdditionMonoid: Add<Output = Self> + AddAssign + Zero + Eq + Sized {}
impl<T: Add<Output = Self> + AddAssign + Zero + Eq> AdditionMonoid for T {}
pub trait AdditionMonoidWithSub: AdditionMonoid + Sub<Output = Self> + SubAssign {}
impl<T: AdditionMonoid + Sub<Output = Self> + SubAssign> AdditionMonoidWithSub for T {}
pub trait AdditionGroup: AdditionMonoidWithSub + Neg<Output = Self> {}
impl<T: AdditionMonoidWithSub + Neg<Output = Self>> AdditionGroup for T {}
pub trait MultiplicationMonoid: Mul<Output = Self> + MulAssign + One + Eq + Sized {}
impl<T: Mul<Output = Self> + MulAssign + One + Eq> MultiplicationMonoid for T {}
pub trait IntegerMultiplicationMonoid: MultiplicationMonoid + Div<
        Output = Self,
    > + Rem<Output = Self> + DivAssign + RemAssign {}
impl<
    T: MultiplicationMonoid + Div<Output = Self> + Rem<Output = Self> + DivAssign
        + RemAssign,
> IntegerMultiplicationMonoid for T {}
pub trait MultiplicationGroup: MultiplicationMonoid + Div<
        Output = Self,
    > + DivAssign + Invertible<Output = Self> {}
impl<
    T: MultiplicationMonoid + Div<Output = Self> + DivAssign + Invertible<Output = Self>,
> MultiplicationGroup for T {}
pub trait SemiRing: AdditionMonoid + MultiplicationMonoid {}
impl<T: AdditionMonoid + MultiplicationMonoid> SemiRing for T {}
pub trait SemiRingWithSub: AdditionMonoidWithSub + SemiRing {}
impl<T: AdditionMonoidWithSub + SemiRing> SemiRingWithSub for T {}
pub trait Ring: SemiRing + AdditionGroup {}
impl<T: SemiRing + AdditionGroup> Ring for T {}
pub trait IntegerSemiRing: SemiRing + IntegerMultiplicationMonoid {}
impl<T: SemiRing + IntegerMultiplicationMonoid> IntegerSemiRing for T {}
pub trait IntegerSemiRingWithSub: SemiRingWithSub + IntegerSemiRing {}
impl<T: SemiRingWithSub + IntegerSemiRing> IntegerSemiRingWithSub for T {}
pub trait IntegerRing: IntegerSemiRing + Ring {}
impl<T: IntegerSemiRing + Ring> IntegerRing for T {}
pub trait Field: Ring + MultiplicationGroup {}
impl<T: Ring + MultiplicationGroup> Field for T {}
macro_rules! zero_one_integer_impl {
    ($($t:ident)+) => {
        $(impl Zero for $t { fn zero() -> Self { 0 } } impl One for $t { fn one() -> Self
        { 1 } })+
    };
}
zero_one_integer_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize);
}
pub mod bit_ops {
use crate::algo_lib::numbers::num_traits::algebra::{One, Zero};
use std::ops::{
    BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, RangeInclusive,
    Shl, Sub,
};
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> + Zero + One + PartialEq {
    #[inline]
    fn bit(at: usize) -> Self {
        Self::one() << at
    }
    #[inline]
    fn is_set(&self, at: usize) -> bool {
        (*self >> at & Self::one()) == Self::one()
    }
    #[inline]
    fn set_bit(&mut self, at: usize) {
        *self |= Self::bit(at);
    }
    #[inline]
    fn unset_bit(&mut self, at: usize) {
        *self &= !Self::bit(at);
    }
    #[must_use]
    #[inline]
    fn with_bit(mut self, at: usize) -> Self {
        self.set_bit(at);
        self
    }
    #[must_use]
    #[inline]
    fn without_bit(mut self, at: usize) -> Self {
        self.unset_bit(at);
        self
    }
    #[inline]
    fn flip_bit(&mut self, at: usize) {
        *self ^= Self::bit(at);
    }
    #[must_use]
    #[inline]
    fn flipped_bit(mut self, at: usize) -> Self {
        self.flip_bit(at);
        self
    }
    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)
    }
}
pub struct BitIter<T> {
    cur: T,
    all: T,
    ended: bool,
}
impl<T: Copy> BitIter<T> {
    pub fn new(all: T) -> Self {
        Self {
            cur: all,
            all,
            ended: false,
        }
    }
}
impl<T: BitOps + Sub<Output = T>> Iterator for BitIter<T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        if self.ended {
            return None;
        }
        let res = self.cur;
        if self.cur == T::zero() {
            self.ended = true;
        } else {
            self.cur = (self.cur - T::one()) & self.all;
        }
        Some(res)
    }
}
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> + One + Zero + 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 invertible {
pub trait Invertible {
    type Output;
    fn inv(&self) -> Option<Self::Output>;
}
}
}
}
pub mod string {
pub mod str {
use crate::algo_lib::io::input::{Input, Readable};
use crate::algo_lib::io::output::{Output, Writable};
use crate::transparent_wrapper;
use std::fmt::Display;
use std::io::Write;
use std::ops::{AddAssign, Deref, DerefMut};
use std::str::from_utf8_unchecked;
use std::vec::IntoIter;
transparent_wrapper!(
    Str = Vec < u8 >, derive Eq, PartialEq, Hash, PartialOrd, Ord, Clone, Default
);
impl Str {
    pub fn new() -> Self {
        Self(Vec::new())
    }
    pub fn unwrap(self) -> Vec<u8> {
        self.0
    }
}
impl From<Vec<u8>> for Str {
    fn from(v: Vec<u8>) -> Self {
        Self(v)
    }
}
impl From<&[u8]> for Str {
    fn from(v: &[u8]) -> Self {
        Self(v.to_vec())
    }
}
impl<const N: usize> From<&[u8; N]> for Str {
    fn from(v: &[u8; N]) -> Self {
        Self(v.to_vec())
    }
}
impl Readable for Str {
    fn read(input: &mut Input) -> Self {
        let mut res = Vec::new();
        input.skip_whitespace();
        while let Some(c) = input.get() {
            if c.is_ascii_whitespace() {
                break;
            }
            res.push(c);
        }
        Self(res)
    }
}
impl Writable for Str {
    fn write(&self, output: &mut Output) {
        output.write_all(&self.0).unwrap()
    }
}
impl IntoIterator for Str {
    type Item = u8;
    type IntoIter = IntoIter<u8>;
    fn into_iter(self) -> Self::IntoIter {
        self.0.into_iter()
    }
}
impl<'a> IntoIterator for &'a Str {
    type Item = &'a u8;
    type IntoIter = std::slice::Iter<'a, u8>;
    fn into_iter(self) -> Self::IntoIter {
        self.iter()
    }
}
impl<'a> IntoIterator for &'a mut Str {
    type Item = &'a mut u8;
    type IntoIter = std::slice::IterMut<'a, u8>;
    fn into_iter(self) -> Self::IntoIter {
        self.iter_mut()
    }
}
impl FromIterator<u8> for Str {
    fn from_iter<T: IntoIterator<Item = u8>>(iter: T) -> Self {
        Self(iter.into_iter().collect())
    }
}
impl AsRef<[u8]> for Str {
    fn as_ref(&self) -> &[u8] {
        &self.0
    }
}
impl AddAssign<&[u8]> for Str {
    fn add_assign(&mut self, rhs: &[u8]) {
        self.0.extend_from_slice(rhs)
    }
}
impl Display for Str {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        unsafe { f.write_str(from_utf8_unchecked(&self.0)) }
    }
}
pub trait StrReader {
    fn read_str(&mut self) -> Str;
    fn read_str_vec(&mut self, n: usize) -> Vec<Str>;
    fn read_line(&mut self) -> Str;
    fn read_line_vec(&mut self, n: usize) -> Vec<Str>;
    fn read_lines(&mut self) -> Vec<Str>;
}
impl StrReader for Input {
    fn read_str(&mut self) -> Str {
        self.read()
    }
    fn read_str_vec(&mut self, n: usize) -> Vec<Str> {
        self.read_vec(n)
    }
    fn read_line(&mut self) -> Str {
        let mut res = Str::new();
        while let Some(c) = self.get() {
            if self.is_eol() {
                break;
            }
            res.push(c);
        }
        res
    }
    fn read_line_vec(&mut self, n: usize) -> Vec<Str> {
        let mut res = Vec::with_capacity(n);
        for _ in 0..n {
            res.push(self.read_line());
        }
        res
    }
    fn read_lines(&mut self) -> Vec<Str> {
        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
    }
}
}
}
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7
2
0001
2
0111
2
1111
3
00010111
1
10
2
0101
5
00000000000000000000000000000001

output:

Yes
(b&a)
Yes
(b|a)
Yes
T
Yes
((c&(b|a))|(b&a))
No
Yes
a
Yes
(e&(d&(c&(b&a))))

result:

ok 7 lines, tightest: 4 out of 14 (7 test cases)

Test #2:

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

input:

4
1
00
1
10
1
01
1
11

output:

Yes
F
No
Yes
a
Yes
T

result:

ok 4 lines, tightest: 0 out of 11 (4 test cases)

Test #3:

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

input:

16
2
0000
2
1000
2
0100
2
1100
2
0010
2
1010
2
0110
2
1110
2
0001
2
1001
2
0101
2
1101
2
0011
2
1011
2
0111
2
1111

output:

Yes
F
No
No
No
No
No
No
No
Yes
(b&a)
No
Yes
a
No
Yes
b
No
Yes
(b|a)
Yes
T

result:

ok 16 lines, tightest: 1 out of 12 (16 test cases)

Test #4:

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

input:

256
3
00000000
3
10000000
3
01000000
3
11000000
3
00100000
3
10100000
3
01100000
3
11100000
3
00010000
3
10010000
3
01010000
3
11010000
3
00110000
3
10110000
3
01110000
3
11110000
3
00001000
3
10001000
3
01001000
3
11001000
3
00101000
3
10101000
3
01101000
3
11101000
3
00011000
3
10011000
3
01011000...

output:

Yes
F
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 256 lines, tightest: 4 out of 14 (256 test cases)

Test #5:

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

input:

65536
4
0000000000000000
4
1000000000000000
4
0100000000000000
4
1100000000000000
4
0010000000000000
4
1010000000000000
4
0110000000000000
4
1110000000000000
4
0001000000000000
4
1001000000000000
4
0101000000000000
4
1101000000000000
4
0011000000000000
4
1011000000000000
4
0111000000000000
4
1111000...

output:

Yes
F
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 65536 lines, tightest: 8 out of 18 (65536 test cases)

Test #6:

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

input:

168
4
0000000000000000
4
0000000000000001
4
0000000000000011
4
0000000000000101
4
0000000000000111
4
0000000000001111
4
0000000000010001
4
0000000000010011
4
0000000000010101
4
0000000000010111
4
0000000000011111
4
0000000000110011
4
0000000000110111
4
0000000000111111
4
0000000001010101
4
000000000...

output:

Yes
F
Yes
(d&(c&(b&a)))
Yes
(d&(c&b))
Yes
(d&(c&a))
Yes
(d&(c&(b|a)))
Yes
(d&c)
Yes
(d&(b&a))
Yes
(d&((c&b)|(b&a)))
Yes
(d&((c&a)|(b&a)))
Yes
(d&((c&(b|a))|(b&a)))
Yes
(d&(c|(b&a)))
Yes
(d&b)
Yes
(d&((c&a)|b))
Yes
(d&(c|b))
Yes
(d&a)
Yes
(d&((c&b)|a))
Yes
(d&(c|a))
Yes
(d&(b|a))
Yes
(d&(c|(b|a)))
Ye...

result:

ok 168 lines, tightest: 8 out of 18 (168 test cases)

Test #7:

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

input:

7581
5
00000000000000000000000000000000
5
00000000000000000000000000000001
5
00000000000000000000000000000011
5
00000000000000000000000000000101
5
00000000000000000000000000000111
5
00000000000000000000000000001111
5
00000000000000000000000000010001
5
00000000000000000000000000010011
5
0000000000000...

output:

Yes
F
Yes
(e&(d&(c&(b&a))))
Yes
(e&(d&(c&b)))
Yes
(e&(d&(c&a)))
Yes
(e&(d&(c&(b|a))))
Yes
(e&(d&c))
Yes
(e&(d&(b&a)))
Yes
(e&(d&((c&b)|(b&a))))
Yes
(e&(d&((c&a)|(b&a))))
Yes
(e&(d&((c&(b|a))|(b&a))))
Yes
(e&(d&(c|(b&a))))
Yes
(e&(d&b))
Yes
(e&(d&((c&a)|b)))
Yes
(e&(d&(c|b)))
Yes
(e&(d&a))
Yes
(e&(d&...

result:

ok 7581 lines, tightest: 18 out of 26 (7581 test cases)

Test #8:

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

input:

14
1
01
2
0111
3
00010111
4
0001011101111111
5
00000001000101110001011101111111
6
0000000100010111000101110111111100010111011111110111111111111111
7
00000000000000010000000100010111000000010001011100010111011111110000000100010111000101110111111100010111011111110111111111111111
8
00000000000000010000...

output:

Yes
a
Yes
(b|a)
Yes
((c&(b|a))|(b&a))
Yes
((d&(c|(b|a)))|((c&(b|a))|(b&a)))
Yes
((e&((d&(c|(b|a)))|((c&(b|a))|(b&a))))|((d&((c&(b|a))|(b&a)))|(c&(b&a))))
Yes
((f&((e&(d|(c|(b|a))))|((d&(c|(b|a)))|((c&(b|a))|(b&a)))))|((e&((d&(c|(b|a)))|((c&(b|a))|(b&a))))|((d&((c&(b|a))|(b&a)))|(c&(b&a)))))
Yes
((g&...

result:

ok 14 lines, tightest: 68 out of 74 (14 test cases)

Test #9:

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

input:

14
1
01
2
0001
3
00010111
4
0000000100010111
5
00000001000101110001011101111111
6
0000000000000001000000010001011100000001000101110001011101111111
7
00000000000000010000000100010111000000010001011100010111011111110000000100010111000101110111111100010111011111110111111111111111
8
00000000000000000000...

output:

Yes
a
Yes
(b&a)
Yes
((c&(b|a))|(b&a))
Yes
((d&((c&(b|a))|(b&a)))|(c&(b&a)))
Yes
((e&((d&(c|(b|a)))|((c&(b|a))|(b&a))))|((d&((c&(b|a))|(b&a)))|(c&(b&a))))
Yes
((f&((e&((d&(c|(b|a)))|((c&(b|a))|(b&a))))|((d&((c&(b|a))|(b&a)))|(c&(b&a)))))|((e&((d&((c&(b|a))|(b&a)))|(c&(b&a))))|(d&(c&(b&a)))))
Yes
((g&...

result:

ok 14 lines, tightest: 68 out of 74 (14 test cases)

Test #10:

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

input:

14
1
00
2
0001
3
00000001
4
0000000100010111
5
00000000000000010000000100010111
6
0000000000000001000000010001011100000001000101110001011101111111
7
00000000000000000000000000000001000000000000000100000001000101110000000000000001000000010001011100000001000101110001011101111111
8
00000000000000000000...

output:

Yes
F
Yes
(b&a)
Yes
(c&(b&a))
Yes
((d&((c&(b|a))|(b&a)))|(c&(b&a)))
Yes
((e&((d&((c&(b|a))|(b&a)))|(c&(b&a))))|(d&(c&(b&a))))
Yes
((f&((e&((d&(c|(b|a)))|((c&(b|a))|(b&a))))|((d&((c&(b|a))|(b&a)))|(c&(b&a)))))|((e&((d&((c&(b|a))|(b&a)))|(c&(b&a))))|(d&(c&(b&a)))))
Yes
((g&((f&((e&((d&(c|(b|a)))|((c&(...

result:

ok 14 lines, tightest: 33 out of 42 (14 test cases)

Test #11:

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

input:

14
1
00
2
0000
3
00000001
4
0000000000000001
5
00000000000000010000000100010111
6
0000000000000000000000000000000100000000000000010000000100010111
7
00000000000000000000000000000001000000000000000100000001000101110000000000000001000000010001011100000001000101110001011101111111
8
00000000000000000000...

output:

Yes
F
Yes
F
Yes
(c&(b&a))
Yes
(d&(c&(b&a)))
Yes
((e&((d&((c&(b|a))|(b&a)))|(c&(b&a))))|(d&(c&(b&a))))
Yes
((f&((e&((d&((c&(b|a))|(b&a)))|(c&(b&a))))|(d&(c&(b&a)))))|(e&(d&(c&(b&a)))))
Yes
((g&((f&((e&((d&(c|(b|a)))|((c&(b|a))|(b&a))))|((d&((c&(b|a))|(b&a)))|(c&(b&a)))))|((e&((d&((c&(b|a))|(b&a)))|(c...

result:

ok 14 lines, tightest: 0 out of 11 (14 test cases)

Test #12:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&((i&(h|(g|(f|(e|(d|(c|(b|a))))))))|((h&(g|(f|(e|(d|(c|(b|a)))))))|((g&(f|(e|(d|(c|(b|a))))))|((f&(e|(d|(c|(b|a)))))|((e&(d|(c|(b|a))))|((d&(c|(b|a)))|((c&(b|a))|(b&a)))))))))|((i&((h&(g|(f|(e|(d|(c|(b|a)))))))|((g&(f|(e|(d|(c|(b|a))))))|((f&(e|(d|(c|(b|a)))))|((e&(d|(c|(b...

result:

ok 1 lines, tightest: 12868 out of 16394 (1 test case)

Test #13:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000100000000000000010000000100010111000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&(i|(h|(g|(f|(e|(d|(c|(b|a)))))))))|((i&(h|(g|(f|(e|(d|(c|(b|a))))))))|((h&(g|(f|(e|(d|(c|(b|a)))))))|((g&(f|(e|(d|(c|(b|a))))))|((f&(e|(d|(c|(b|a)))))|((e&(d|(c|(b|a))))|((d&(c|(b|a)))|((c&(b|a))|(b&a))))))))))|((j&((i&(h|(g|(f|(e|(d|(c|(b|a))))))))|((h&(g|(f|(e|(d|(c|(b|...

result:

ok 1 lines, tightest: 11438 out of 16394 (1 test case)

Test #14:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&((i&((h&(g|(f|(e|(d|(c|(b|a)))))))|((g&(f|(e|(d|(c|(b|a))))))|((f&(e|(d|(c|(b|a)))))|((e&(d|(c|(b|a))))|((d&(c|(b|a)))|((c&(b|a))|(b&a))))))))|((h&((g&(f|(e|(d|(c|(b|a))))))|((f&(e|(d|(c|(b|a)))))|((e&(d|(c|(b|a))))|((d&(c|(b|a)))|((c&(b|a))|(b&a)))))))|((g&((f&(e|(d|(c|(...

result:

ok 1 lines, tightest: 11438 out of 16394 (1 test case)

Test #15:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&((i&((h&((g&(f|(e|(d|(c|(b|a))))))|((f&(e|(d|(c|(b|a)))))|((e&(d|(c|(b|a))))|((d&(c|(b|a)))|((c&(b|a))|(b&a)))))))|((g&((f&(e|(d|(c|(b|a)))))|((e&(d|(c|(b|a))))|((d&(c|(b|a)))|((c&(b|a))|(b&a))))))|((f&((e&(d|(c|(b|a))))|((d&(c|(b|a)))|((c&(b|a))|(b&a)))))|((e&((d&(c|(b|a...

result:

ok 1 lines, tightest: 8006 out of 16394 (1 test case)

Test #16:

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

input:

65536
6
0000001101111111000111111111111101111111111111111111111111111111
6
0000000000000000000100110011011100000000000000000001001100111111
6
0101010101110111011101111111111101110111111111111111111111111111
6
0000001100000011000000110001011100011111001111110011111100111111
6
000000010001011100000001...

output:

Yes
((f&(e|(d|(c|(b|a)))))|((e&(d|(c|(b&a))))|((d&(c|(b|a)))|(c&b))))
Yes
((f&(e&(d&c)))|(e&((d&((c&a)|b))|((c&b)|(b&a)))))
Yes
((f&(e|(d|b)))|((e&(d|b))|((d&b)|a)))
Yes
((f&((e&b)|((d&b)|(c|(b&a)))))|((e&(d&((c&a)|(b&a))))|(c&b)))
Yes
((f&((d&b)|((c&(b|a))|(b&a))))|((d&((c&(b|a))|(b&a)))|(c&(b&a)))...

result:

ok 65536 lines, tightest: 33 out of 42 (65536 test cases)

Test #17:

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

input:

65536
7
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
7
00000001000100010001000101110111000100010111011101110111011111110001000101110111011101110111111100010001011101110111011111111111
7
000000010001001100000001001101...

output:

Yes
(g&(f&(e&(d&(c&(b&a))))))
Yes
((g&((f&(e&d))|((e&((d&c)|(b|a)))|((d&(b|a))|(b&a)))))|((f&((e&((d&c)|(b|a)))|((d&(b|a))|(b&a))))|((e&((d&(b|a))|(b&a)))|((d&(b&a))|(c&(b&a))))))
Yes
((g&((f&(e&d))|(e&(c&b))))|((f&((e&((c&a)|b))|((d&(c|(b|a)))|((c&b)|(b&a)))))|((e&(d&((c&a)|b)))|((d&((c&b)|(b&a)))|...

result:

ok 65536 lines, tightest: 68 out of 74 (65536 test cases)

Test #18:

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

input:

16384
8
0000000000000000000000000000000000000000000000000000000000010001000000000000000000000000000100010000000000010001000100010011011100000000000000000000000000010001000000000001000100010001011101110000000000000001000100010011011100010001000101110011011101111111
8
000101010101011100010101011101110...

output:

Yes
((h&((g&((f&((e&((d&c)|((c&a)|b)))|((d&(c&(b|a)))|(b&a))))|((e&((d&((c&a)|b))|(b&a)))|(d&(c&(b&a))))))|((f&((e&((d&(b|a))|(b&a)))|(d&(b&a))))|(e&(d&(b&a))))))|((g&((f&((e&((d&((c&a)|b))|(b&a)))|(d&(b&a))))|(e&(d&(b&a)))))|(f&(e&(d&(b&a))))))
Yes
((h&(g|(f|((e&b)|(d|((c&b)|a))))))|((g&(f|(d|(c|(b...

result:

ok 16384 lines, tightest: 119 out of 138 (16384 test cases)

Test #19:

score: 0
Accepted
time: 80ms
memory: 2048kb

input:

4096
9
00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000111000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000001000101110000000000000000000000010001011100000...

output:

Yes
((i&((h&((g&(f&e))|(e&(d&c))))|((g&((f&((d&((c&(b|a))|(b&a)))|(c&(b&a))))|(e&((d&(c|(b|a)))|((c&(b|a))|(b&a))))))|((f&((e&(d|(c|(b|a))))|(d&(c&(b&a)))))|(e&((d&((c&(b|a))|(b&a)))|(c&(b&a))))))))|((h&(g&(f&(e&((d&(b&a))|(c&(b&a)))))))|((g&(f&(e&(d&(c&(b|a))))))|(f&(e&(d&(c&(b&a))))))))
Yes
((i&((...

result:

ok 4096 lines, tightest: 237 out of 266 (4096 test cases)

Test #20:

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

input:

1024
10
0000000000000000000000000000000100000000000000110000000000000011000000000000000100000000000000110000000000000011000000010000001100000000000000110000000000000011000000000000001100000011000001110000000000000011000000000000001100000011000001110000001100011111000000000000001100000000000000110000...

output:

Yes
((j&((i&((h&((g&((e&(c|(b&a)))|(c&a)))|((f&(d|b))|(e&(c&a)))))|((g&(f&(d|b)))|((f&((e&((d&a)|b))|c))|((d&(c|b))|(c&b))))))|((h&((g&((f&((e&(d|b))|(c|(b&a))))|(d&b)))|((f&((e&(c|(b&a)))|(c&a)))|((e&(d&b))|((d&(c|(b&a)))|(c&b))))))|((g&((f&(e&c))|((e&(d&b))|((d&(c|(b&a)))|(c&b)))))|((f&((d&(c|b))|...

result:

ok 1024 lines, tightest: 370 out of 522 (1024 test cases)

Test #21:

score: 0
Accepted
time: 23ms
memory: 2048kb

input:

256
11
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((k&((j&((i&((h&((f&(e|a))|((e&((d&c)|(b&a)))|(d&b))))|((g&(f&(e&b)))|(f&((e&((d&c)|(b&a)))|(d&b))))))|((h&((g&((f&(d&(c&a)))|(e&(d&(c&(b&a))))))|(f&((e&((d&c)|b))|(d&b)))))|(f&(e&(d&(c&(b&a))))))))|(i&(h&((g&(f&(e&(b&a))))|(f&((e&(d&((c&a)|b)))|((d&(b&a))|(c&b)))))))))|((j&((i&((h&((g&(f&e))|((...

result:

ok 256 lines, tightest: 665 out of 1034 (256 test cases)

Test #22:

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

input:

64
12
000101011111111101111111111111110001011111111111011111111111111100010111111111110111111111111111000101111111111101111111111111110001010111111111011111111111111100010111111111110111111111111111000101111111111101111111111111110001011111111111111111111111111101111111111111111111111111111111011111...

output:

Yes
((l&(k|((j&(c|a))|(i|((h&(g&((f&c)|a)))|((f&a)|(e|(c&b))))))))|((k&(j|(i|((h&g)|(f|(e|(c|(b|a))))))))|((j&((i&((h&f)|(g&f)))|(e|(c&b))))|((i&(e|(c|(b|a))))|((h&(g&(f&e)))|((g&(c&b))|((f&(c&b))|((e&(c|(b|a)))|(d|((c&a)|(b&a)))))))))))
Yes
((l&((k&((j&((i&(h&(g&(d&b))))|((h&(d&(c&(b&a))))|((g&((f&...

result:

ok 64 lines, tightest: 1266 out of 2058 (64 test cases)

Test #23:

score: 0
Accepted
time: 5ms
memory: 2304kb

input:

16
13
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000011111111111111111111111111111100000000000000000000000000000000000000...

output:

Yes
((m&((l&((k&((j&((i&(h|((g&(e|(d&(c|b))))|((f&(d|(c|b)))|(e&(d&(c&(b&a))))))))|((h&((e&d)|((d&(c|(b&a)))|(c&b))))|((g&(e&((d&(c|b))|(c&b))))|(f&((e&(c|(b&a)))|(d&(c&b))))))))|((i&((h&((g&((d&a)|(c|b)))|((f&a)|(e&(d&(c&b))))))|(g&(f&((e&a)|((d&(c|b))|(c&b)))))))|((h&((g&((e&(c&a))|(d&(c&b))))|(f&...

result:

ok 16 lines, tightest: 1774 out of 4106 (16 test cases)

Test #24:

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

input:

4
14
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((n&((m&((l&((k&((j&((g&(e&c))|((e&((d&c)|b))|(c&b))))|((i&((e&c)|(c&b)))|((h&(g&(e&(c&b))))|((g&(f&b))|(f&(c&a)))))))|((j&((i&(h&((e&a)|((c&a)|(b&a)))))|(f&c)))|((i&((h&(f&a))|(e&(c&b))))|((h&(f&((e&c)|(c&b))))|(f&((e&(c&a))|(c&(b&a)))))))))|((k&((j&((i&((h&(e&b))|((g&(e&(b&a)))|(f&a))))|(h&(f&...

result:

ok 4 lines, tightest: 2231 out of 8202 (4 test cases)

Test #25:

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

input:

4
14
0000000000000000000000000000000000000000000000000001000100010101000000000000000101010101010101010001010101010101011101110111111100000000000000000000000000000001000000000000000000010101010101010000000100010001010101010101011101010101010101010111111111111111000000000000000000010101010101010000000...

output:

Yes
((n&((m&((l&((k&((j&(h&((g&d)|((d&a)|(c&a)))))|((i&((h&g)|((f&(d&c))|(e&d))))|((h&(d&(b&a)))|(f&(e&b))))))|((j&((i&a)|((h&(d&(c&a)))|(f&(e&(d|c))))))|((i&(h&(g&(d|c))))|((h&(g&(f&b)))|(f&(e&(d&b))))))))|((k&((j&((i&(f&b))|(h&((f&(e|(d&(c&b))))|(e&((d&b)|(c&b)))))))|((g&((f&(d|c))|(d&(c&b))))|((f...

result:

ok 4 lines, tightest: 1539 out of 8202 (4 test cases)

Test #26:

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

input:

4
14
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((n&((m&((l&((k&((j&((i&((g&(f&(e&a)))|((f&(e&(b&a)))|(d&c))))|((h&(e&(d&c)))|(g&(d&(c&b))))))|((i&(h&(g&(e&b))))|((h&(f&(e&(d&c))))|(g&(e&(c&(b&a))))))))|((j&((i&((h&((g&((f&e)|((d&b)|c)))|((f&(e&b))|((d&c)|(c&b)))))|((g&((f&((d&b)|c))|(e&b)))|((f&((e&d)|(c&b)))|(d&(c&a))))))|((h&(g&(d&(c&b))))...

result:

ok 4 lines, tightest: 3380 out of 8202 (4 test cases)

Test #27:

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

input:

4
14
0000000000000000000000000001001100000000000000110000000000110011000000000011001100000000001100110000000000110011000000000011001100000000001100110000000000110011000000000011001100000000001100110001001100111111001100111111111100110011111111110011001111111111000000000011001100000011001101110000000...

output:

Yes
((n&((m&((l&((k&(j|(f|(e|(c|a)))))|((j&((f&(c|a))|e))|(h|(g|((f&(e|(c&a)))|(e&c)))))))|((k&((j&(h|(g&(c|a))))|(i|((h&(f|(e|(c|a))))|((g&(f|(e|(c&a))))|(d|b))))))|((j&(i|((h&((f&c)|(e&(c|a))))|((g&((f&e)|(e&(c&a))))|(d|b)))))|((i&(f|(e|c)))|((h&(g|((f&e)|(e&(c&a)))))|((g&(f&(e&c)))|((f&(d|b))|((e...

result:

ok 4 lines, tightest: 1911 out of 8202 (4 test cases)

Test #28:

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

input:

4
14
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000001000000000000000000000000000000000000000...

output:

Yes
((n&((m&((l&((k&((j&((i&((h&((g&(f&e))|d))|((f&a)|((e&d)|c))))|((h&((g&(e&d))|(f&c)))|((g&((f&a)|(c|b)))|(f&(e&b))))))|((i&((h&((g&((f&(e&b))|(d&a)))|((f&(d&a))|((e&(d&c))|(d&b)))))|((g&(e&(d&a)))|((f&((c&a)|(b&a)))|((e&(d&b))|(c&b))))))|((h&((g&((f&(c&a))|(e&(d&b))))|(f&(c&b))))|((g&((f&(b&a))|...

result:

ok 4 lines, tightest: 2370 out of 8202 (4 test cases)

Test #29:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&((i&((h&((f&(e&((d&b)|((c&b)|(b&a)))))|(e&((d&((c&b)|(b&a)))|(c&(b&a))))))|((g&(f&(e&(d&(c&b)))))|((f&(e&((d&(b&a))|(c&(b&a)))))|(e&(d&(c&(b&a))))))))|(h&((g&((f&(e&((d&a)|(c&a))))|(e&(d&(c&a)))))|(f&(d&(c&a)))))))|((i&((h&((g&((f&((d&((c&b)|(b&a)))|(c&(b&a))))|(d&(c&(b&a...

result:

ok 1 lines, tightest: 1174 out of 16394 (1 test case)

Test #30:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&((i&(g&a))|((g&d)|e)))|((i&(h|((g&((d&b)|(c&(b&a))))|(e&b))))|((h&((g&(f&b))|(d|c)))|((g&(d&(c&b)))|(e&((d&b)|(c&b))))))))|((j&((i&((g&b)|(f|(d|c))))|(h|((g&(e|((d&b)|(c&b))))|((f&(e|(d|c)))|((e&b)|(d&c)))))))|((i&((h&(g|(f|b)))|((g&e)|((f&(e|(d|c)))|(d&c)))))|((h&((g&(d|...

result:

ok 1 lines, tightest: 2177 out of 16394 (1 test case)

Test #31:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&((i&((h&d)|((g&(f|a))|((f&a)|(e|(c|b))))))|((h&(e|(c|b)))|((g&(f&a))|((e&(c|b))|(c&b))))))|((i&((h&((g&d)|((f&d)|(d&a))))|((g&((f&a)|((e&d)|((d&c)|b))))|((f&((e&d)|(d&(c|b))))|((e&(d&a))|(d&((c&a)|(b&a))))))))|((h&((g&(e|(c|b)))|((f&(e|(c|b)))|((e&a)|((c&a)|(b&a))))))|((g...

result:

ok 1 lines, tightest: 4807 out of 16394 (1 test case)

Test #32:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000001100000000000000110000001100111111000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&((e&(d|b))|(d&c)))|((i&(d&a))|((h&((d&a)|(b&a)))|((g&(d&b))|((f&(d&b))|(e&c)))))))|((j&((i&((h&a)|((g&(d|b))|((f&(d|b))|(d&b)))))|((h&((g&(f|(d|b)))|(f&(d|b))))|((f&(e&(d&a)))|((e&(d&(b&a)))|(d&(c&(b&a))))))))|((i&((g&(e|c))|((f&(e|c))|((e&(d|b))|((d&c)|(c&b))))))|((h&((g...

result:

ok 1 lines, tightest: 3651 out of 16394 (1 test case)

Test #33:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&((i&((h&((g&(f&a))|((f&((e&c)|(c&b)))|((e&(d|(c&(b|a))))|((d&b)|(c&(b&a)))))))|((g&(f&((e&d)|(d&a))))|(e&(d&(c&b))))))|((h&(g&((f&((e&(b|a))|((d&c)|(b&a))))|((e&(d&c))|(d&(c&(b|a)))))))|((g&((f&(e&((d&b)|(c&(b&a)))))|(e&(d&(b&a)))))|(f&((e&(d&a))|(d&(b&a))))))))|((i&((h&(...

result:

ok 1 lines, tightest: 2531 out of 16394 (1 test case)

Test #34:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001010100000000000000000000000001010101000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&(f|(c&b)))|((i&b)|((g&(f|(c&b)))|((e&(c|b))|((d&b)|((c&a)|(b&a))))))))|((j&((i&(g|((f&(c&b))|d)))|((h&(f|(c&b)))|((g&(e|(d|a)))|(f&((e&(c|b))|((d&(c&b))|((c&a)|(b&a)))))))))|((i&((h&(c|b))|((g&(f&b))|(f&(e|((d&(c|b))|a))))))|((h&((g&(f|(c&b)))|((e&(c|b))|((d&(c|b))|((c&a)...

result:

ok 1 lines, tightest: 3508 out of 16394 (1 test case)

Test #35:

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

input:

65536
7
00000000000000010000000100000101000000000001011100000101010111110000000100000001000001110001011100000101001101110011011111111111
7
00000000000000010000000000010111000000000000011100000001011111110000000100000001000000110011011100010101001101110011111111111111
7
000000000000000000000001000100...

output:

Yes
((g&((f&((e&(d|b))|((d&b)|(c&a))))|((e&((d&(b&a))|(c&(b|a))))|(c&(b&a)))))|((f&((e&((d&(c|a))|(c&a)))|(d&((c&(b|a))|(b&a)))))|((e&((d&(c&a))|(c&(b&a))))|(d&(c&(b&a))))))
Yes
((g&((f&((e&(d|(c|b)))|((d&b)|((c&a)|(b&a)))))|((e&((d&b)|(c&b)))|(c&(b&a)))))|((f&((e&((d&(c|(b|a)))|(c&(b&a))))|(d&(c&(b...

result:

ok 65536 lines, tightest: 60 out of 74 (65536 test cases)

Test #36:

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

input:

1024
10
0000000000000000000000000000000000000000000000000000000000000011000000000000000000000001000001110000000000000111000101010111011100000000000000000000000000000111000000010001011100010011000101110000000100000001000001110001011100000101011111110101111111111111000000000000000100000000000100010000...

output:

Yes
((j&((i&((h&((g&(f|a))|((f&(e|(c|a)))|((e&(d|(c|a)))|((d&(c|(b|a)))|(c&a))))))|((g&((f&b)|((e&(d|(b|a)))|((d&(c|a))|(c&b)))))|((f&((e&(c|b))|((d&c)|(c&(b|a)))))|((e&((d&(c|a))|(c&a)))|(c&(b&a)))))))|((h&((g&((f&(d|(c|(b|a))))|((e&(d|(b|a)))|((d&(c|a))|(c&a)))))|((f&((e&((d&a)|b))|((d&c)|(c&(b|a)...

result:

ok 1024 lines, tightest: 322 out of 522 (1024 test cases)

Test #37:

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

input:

64
12
000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000001000101110000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000010000000100010101000101110111111100000000000000000000000000000001000000...

output:

Yes
((l&((k&((j&((i&((h&(g|((f&d)|a)))|((g&(e|(d|(b|a))))|((f&(c|a))|((e&(c|b))|((d&a)|(c&a)))))))|((h&((g&(f|((e&d)|b)))|(f&(c|b))))|((g&((f&(c|(b|a)))|((e&(b|a))|(d&(c|(b|a))))))|((f&((d&(c|(b|a)))|((c&(b|a))|(b&a))))|((e&((d&(c|(b|a)))|((c&a)|(b&a))))|(d&((c&a)|(b&a)))))))))|((i&((h&((g&(f|d))|((...

result:

ok 64 lines, tightest: 1115 out of 2058 (64 test cases)

Test #38:

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

input:

64
12
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000...

output:

Yes
((l&((k&((j&((i&((h&((g&(d|b))|((f&(d|(c|(b|a))))|((e&(d|(c|(b|a))))|((d&c)|(c&a))))))|((g&((f&(e|a))|((e&a)|(b&a))))|((f&((e&(d|(b&a)))|((d&c)|(c&a))))|((e&(d&c))|(d&(c&(b|a))))))))|((h&((g&((f&(e|(c|(b|a))))|((e&(c|a))|((c&b)|(b&a)))))|((f&((e&(d|(c|b)))|((d&(b|a))|(c&(b|a)))))|((e&((d&c)|(b&a...

result:

ok 64 lines, tightest: 1121 out of 2058 (64 test cases)

Test #39:

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

input:

64
12
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000...

output:

Yes
((l&((k&((j&((i&((h&((g&((f&(d|b))|((e&(d|b))|((d&c)|(c&a)))))|((f&((e&d)|((d&(c|(b|a)))|((c&(b|a))|(b&a)))))|((e&(d&b))|((d&(c&a))|(c&(b&a)))))))|((g&((f&((e&b)|((d&a)|((c&(b|a))|(b&a)))))|((e&(c&a))|((d&(c&a))|(c&(b&a))))))|((f&((e&((d&(b&a))|(c&a)))|(d&(c&b))))|(e&((d&(c&a))|(c&(b&a))))))))|(...

result:

ok 64 lines, tightest: 833 out of 2058 (64 test cases)

Test #40:

score: 0
Accepted
time: 5ms
memory: 2432kb

input:

4
14
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000010111000000000000000000000000000000000000000...

output:

Yes
((n&((m&((l&((k&((j&((i&(h|(e|(d|b))))|((h&(g|(f|(e|b))))|((g&(f|(e|a)))|((f&(e|c))|((e&d)|((d&b)|(b&a))))))))|((i&((h&(f|(e|b)))|((g&(e|b))|((f&(e|c))|((e&(d|(c|a)))|(c&a))))))|((h&((g&d)|((f&(e|(d|(c|a))))|((e&(d|(c|(b|a))))|((d&(c|a))|(c&a))))))|((g&((f&(d|b))|((e&(d|(c|b)))|((d&(b|a))|((c&(b...

result:

ok 4 lines, tightest: 3964 out of 8202 (4 test cases)

Test #41:

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

input:

4
14
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000...

output:

Yes
((n&((m&((l&((k&((j&((i&((h&(f|(e|(c|(b|a)))))|((g&(f|(e|(b|a))))|((f&(d|a))|((e&(d|(b|a)))|((d&b)|((c&(b|a))|(b&a))))))))|((h&((g&(f|(e|(d|(c|a)))))|((e&(d|(c|b)))|(d&(c|b)))))|((g&((f&e)|((e&b)|((d&(c|b))|(c&b)))))|((f&((e&(c|b))|(d&(c|(b|a)))))|((e&((d&a)|(c&a)))|((d&(c&b))|(c&(b&a)))))))))|(...

result:

ok 4 lines, tightest: 3872 out of 8202 (4 test cases)

Test #42:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000100000001000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&(g|e))|((i&(g|(e|(d|b))))|((h&f)|((g&(e|(d|(c|a))))|((f&(e|(c|(b|a))))|((e&(d|b))|((d&(c|(b|a)))|(c&b)))))))))|((j&((i&(h|(e|(b|a))))|((h&(g|(e|(d|c))))|((g&(c|b))|((f&((e&a)|(d|c)))|((e&d)|((d&b)|(c&(b|a)))))))))|((i&((h&(f|b))|((g&(e|(d|(c|b))))|((f&(e|(d|b)))|((e&(d|(c...

result:

ok 1 lines, tightest: 6937 out of 16394 (1 test case)

Test #43:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&((i&(h|(g|(f|b))))|((h&(g|(f|(d|(c|a)))))|((g&(f|(d|(c|b))))|((f&(e|d))|((e&a)|((d&c)|(b&a))))))))|((i&((h&(g|(f|(e|c))))|((g&(f|(d|(c|b))))|((f&e)|((e&(d|a))|((d&(c|(b|a)))|(c&(b|a))))))))|((h&((g&(d|b))|((f&(e|a))|((e&(c|(b|a)))|((d&a)|((c&b)|(b&a)))))))|((g&((f&(c|b))|...

result:

ok 1 lines, tightest: 7871 out of 16394 (1 test case)

Test #44:

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

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((o&((n&((m&((l&((k&((j&((i&((h&(g|(f|(d|(c|b)))))|((g&(e|(d|(c|(b|a)))))|((f&c)|((e&(c|b))|(c&a))))))|((h&((g&(e|(d|c)))|((f&(e|a))|((e&(d|a))|((d&(c|(b|a)))|(b&a))))))|((g&((f&(e|(c|b)))|((e&(d|(c|(b|a))))|((d&(c|b))|((c&(b|a))|(b&a))))))|((f&((e&c)|((d&c)|(c&a))))|((e&((d&c)|((c&(b|a))|(b&a))...

result:

ok 1 lines, tightest: 6854 out of 16394 (1 test case)

Extra Test:

score: 0
Extra Test Passed