QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#273244#7882. Linguistics Puzzleucup-team296#AC ✓197ms2620kbRust21.6kb2023-12-02 22:21:532023-12-02 22:21:54

Judging History

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

  • [2023-12-02 22:21:54]
  • 评测
  • 测评结果:AC
  • 用时:197ms
  • 内存:2620kb
  • [2023-12-02 22:21:53]
  • 提交

answer

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

use std::collections::HashMap;
use std::hash::Hash;

use crate::algo_lib::collections::permutation::Permutation;
use crate::algo_lib::io::output::output;
use crate::algo_lib::io::task_io_settings::TaskIoType;
use crate::algo_lib::io::task_runner::run_task;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::task_io_settings::TaskIoSettings;
#[allow(unused)]
use crate::dbg;
use crate::out;
use crate::out_line;

fn gen_hm(all: &[Vec<usize>], n: usize) -> HashMap<Number, Vec<usize>> {
    let mut single = vec![0; n];
    let mut first = vec![0; n];
    let mut second = vec![0; n];
    for cur in all.iter() {
        if cur.len() == 1 {
            single[cur[0]] += 1;
        } else {
            first[cur[0]] += 1;
            second[cur[1]] += 1;
        }
    }
    let mut numbers: HashMap<Number, Vec<usize>> = HashMap::new();
    for i in 0..n {
        let num = Number {
            signle: single[i],
            first: first[i],
            second: second[i],
        };
        numbers.entry(num).or_default().push(i);
    }
    numbers
}

fn gen_correct(n: usize) -> Vec<Vec<usize>> {
    let mut all = vec![];
    for i in 0..n {
        for j in 0..n {
            let mut res = vec![];
            let x = i * j;
            if x < n {
                res.push(x);
            } else {
                res = vec![x / n, x % n];
            }
            all.push(res);
        }
    }
    all
}

fn check(n: usize) {
    let all = gen_correct(n);
    let numbers = gen_hm(&all, n);
    for (k, v) in numbers.iter() {
        if v.len() > 1 {
            dbg!(n, k, v);
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
struct Number {
    signle: usize,
    first: usize,
    second: usize,
}

fn stress() {
    for n in 2..=52 {
        dbg!(n);
        check(n);
    }
}

fn conv(c: u8) -> usize {
    if c >= b'a' && c <= b'z' {
        (c - b'a') as usize
    } else {
        (c - b'A') as usize + 26
    }
}

fn conv_back(x: usize) -> char {
    if x < 26 {
        (x as u8 + b'a') as char
    } else {
        (x as u8 - 26 + b'A') as char
    }
}

type HM = HashMap<Number, Vec<usize>>;

fn check_mapping(from_target: &Vec<usize>, a: &Vec<Vec<usize>>, n: usize) -> bool {
    let mut correct = gen_correct(n);
    for entry in correct.iter_mut() {
        for x in entry.iter_mut() {
            *x = from_target[*x];
        }
    }
    correct.sort();
    a == &correct
}

fn solve_case(mut a: Vec<Vec<usize>>, n: usize) {
    a.sort();
    let mut my_numbers = gen_hm(&a, n);
    let mut need_numbers = gen_hm(&gen_correct(n), n);

    // dbg!(my_numbers);
    // dbg!(need_numbers);

    let mut from_target = vec![n; n];
    for (k, v) in my_numbers.iter() {
        if v.len() == 1 {
            let v2 = need_numbers.get_mut(k).unwrap();
            assert_eq!(v2.len(), 1);
            from_target[v2[0]] = v[0];
        }
    }
    let mut target_not_used: Vec<usize> = vec![];
    let mut my_used = vec![false; n];
    for x in from_target.iter() {
        if *x != n {
            my_used[*x] = true;
        }
    }
    let mut my_not_used = vec![];
    for i in 0..n {
        if from_target[i] == n {
            target_not_used.push(i);
        }
        if !my_used[i] {
            my_not_used.push(i);
        }
    }
    let sz = target_not_used.len();
    // dbg!(target_not_used.len(), my_not_used.len());
    assert!(sz <= 4);
    let mut perm = Permutation::new(sz);
    loop {
        for i in 0..sz {
            from_target[target_not_used[i]] = my_not_used[perm[i]];
        }
        if check_mapping(&from_target, &a, n) {
            for x in from_target.iter() {
                out!(conv_back(*x));
            }
            out_line!();
            return;
        }
        if !perm.next() {
            break;
        }
    }
    panic!();
}

fn solve(input: &mut Input, _test_case: usize) {
    let n = input.usize();
    let mut a = vec![];
    for _ in 0..n * n {
        let s = input.string();
        if s.len() == 1 {
            a.push(vec![conv(s[0])]);
        } else {
            assert_eq!(s.len(), 2);
            a.push(vec![conv(s[0]), conv(s[1])]);
        }
    }
    solve_case(a, n)
}

fn stress2() {
    let n = 49;
    let mut a = gen_correct(n);
    solve_case(a, n);
}

pub(crate) fn run(mut input: Input) -> bool {
    let t = input.read();
    for i in 0usize..t {
        solve(&mut input, i + 1);
    }
    output().flush();
    true
}

#[allow(unused)]
pub fn submit() -> bool {
    let io = TaskIoSettings {
        is_interactive: false,
        input: TaskIoType::Std,
        output: TaskIoType::Std,
    };

    run_task(io, run)
}

}
pub mod algo_lib {
pub mod collections {
pub mod permutation {
use std::ops::Index;
use std::ops::Range;

pub struct Permutation {
    ids: Vec<usize>,
    pos_of_element: Vec<usize>,
}

impl std::fmt::Debug for Permutation {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_fmt(format_args!("{:?}", self.ids))
    }
}

impl Permutation {
    pub fn new(n: usize) -> Self {
        Self::from_vec((0..n).collect())
    }

    pub fn from_vec(ids: Vec<usize>) -> Self {
        let n = ids.len();
        let mut pos_of_element = vec![0; n];
        for (pos, &val) in ids.iter().enumerate() {
            pos_of_element[val] = pos;
        }
        Self {
            ids,
            pos_of_element,
        }
    }

    pub fn get_pos_of_element(&self, value: usize) -> usize {
        let res = self.pos_of_element[value];
        debug_assert_eq!(self.ids[res], value);
        res
    }

    pub fn swap(&mut self, p1: usize, p2: usize) {
        self.ids.swap(p1, p2);
        self.pos_of_element[self.ids[p1]] = p1;
        self.pos_of_element[self.ids[p2]] = p2;
    }

    fn reverse(&mut self, r: Range<usize>) {
        let mut start = r.start;
        let mut end = r.end;
        while start < end {
            end -= 1;
            self.swap(start, end);
            start += 1;
        }
    }

    #[allow(clippy::should_implement_trait)]
    pub fn next(&mut self) -> bool {
        for pos in (1..(self.ids.len())).rev() {
            if self.ids[pos - 1] < self.ids[pos] {
                for pos2 in (pos..self.ids.len()).rev() {
                    if self.ids[pos - 1] < self.ids[pos2] {
                        self.swap(pos - 1, pos2);
                        self.reverse(pos..self.ids.len());
                        return true;
                    }
                }
                unreachable!();
            }
        }
        false
    }

    #[allow(clippy::len_without_is_empty)]
    pub fn len(&self) -> usize {
        self.ids.len()
    }
}

impl Index<usize> for Permutation {
    type Output = usize;

    fn index(&self, index: usize) -> &Self::Output {
        &self.ids[index]
    }
}
}
}
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_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_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 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 static mut OUTPUT: Option<Output> = None;

pub fn set_global_output_to_stdout() {
    unsafe {
        OUTPUT = Some(Output::new(Box::new(std::io::stdout())));
    }
}

pub fn set_global_output_to_file(path: &str) {
    unsafe {
        let out_file =
            std::fs::File::create(path).unwrap_or_else(|_| panic!("Can't create file {}", path));
        OUTPUT = Some(Output::new(Box::new(out_file)));
    }
}

pub fn set_global_output_to_none() {
    unsafe {
        match &mut OUTPUT {
            None => {}
            Some(output) => output.flush(),
        }
        OUTPUT = None;
    }
}

pub fn output() -> &'static mut Output {
    unsafe {
        match &mut OUTPUT {
            None => {
                panic!("Global output wasn't initialized");
            }
            Some(output) => output,
        }
    }
}

#[macro_export]
macro_rules! out {
    ($first: expr $(,$args:expr )*) => {
        output().print(&$first);
        $(output().put(b' ');
        output().print(&$args);
        )*
        output().maybe_flush();
    }
}

#[macro_export]
macro_rules! out_line {
    ($first: expr $(, $args:expr )* ) => {
        {
            out!($first $(,$args)*);
            output().put(b'\n');
            output().maybe_flush();
        }
    };
    () => {
        {
            output().put(b'\n');
            output().maybe_flush();
        }
    };
}
}
pub mod task_io_settings {
pub enum TaskIoType {
    Std,
    File(String),
}

pub struct TaskIoSettings {
    pub is_interactive: bool,
    pub input: TaskIoType,
    pub output: TaskIoType,
}
}
pub mod task_runner {
use std::io::Write;

use super::input::Input;
use super::output::Output;
use super::output::OUTPUT;
use super::task_io_settings::TaskIoSettings;
use super::task_io_settings::TaskIoType;

pub fn run_task<Res>(io: TaskIoSettings, run: impl FnOnce(Input) -> Res) -> Res {
    let output: Box<dyn Write> = match io.output {
        TaskIoType::Std => Box::new(std::io::stdout()),
        TaskIoType::File(file) => {
            let out_file = std::fs::File::create(file).unwrap();
            Box::new(out_file)
        }
    };

    unsafe {
        OUTPUT = Some(Output::new(output));
    }

    let input = match io.input {
        TaskIoType::Std => {
            let sin = std::io::stdin();
            Input::new(Box::new(sin))
        }
        TaskIoType::File(file) => Input::new_file(file),
    };

    run(input)
}
}
}
pub mod misc {
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)
    };
}
}
}
}
fn main() {
    crate::solution::submit();
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3
a b a b b b b c cc
4
d d d d d c b a d b cd cb d a cb bc

output:

bca
dcba

result:

ok OK

Test #2:

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

input:

2
4
d a a bc ba bc b a a a d a a cb c c
4
a b da b b d ad b db b a c da b c b

output:

abcd
bdac

result:

ok OK

Test #3:

score: 0
Accepted
time: 17ms
memory: 2444kb

input:

50
3
b b b a a c b b cc
4
d ab c ad d b ba ab c b d d d d d a
5
a aa aa ab ab ae b b e c c c ba c c c c dd d d dd c e c e
6
a ca a a a a a a ce a a b ba ba bc bc bd be e c c ca a cd cd be d d dc dc e e a eb f f
7
a a a a a a a a cf a a a a b b b b c c c cf a dd d dc d dd e f ed ee ee fb eg eg eg eg ...

output:

bca
dabc
cadbe
abcdef
aefdcgb
fcheabgd
bhgfedcia
jhcgfideba
fjbadkegcih
klhgjbaedcif
igkjmclfedhba
nflijahgmbdcek
anmlfijbgkhdceo
nofmlkjchdbegipa
aponblgjihcfqdkme
iqmonhckfrpgjedlba
prisodmbkjqghfencla
tcrdpoaklmjihfgeqsbn
utiraponmlksghjfecdbq
qotsrvjunmlkpiegfhdcba
pvutsrhwoimlkjnqgfedbca
xbvuts...

result:

ok OK

Test #4:

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

input:

50
3
a a b c c c c bb c
4
a c ab b c ba ba c c a bc c c c d d
5
a a a b b b b b b c b d c b cc cc b d de e ea ed ed ee ee
6
a a ac ac b b b be ef c ca cb ea f cf d d e ca eb eb ec f ef c f f f f f f f f f cf ec
7
ag a a a ag b bb bb bd bd bf bf bf e bg c c c c c c c c c c c e c ga d da dd dd bf e e ...

output:

cba
cbad
becda
fecabd
cbgdafe
abgfechd
abhgeicdf
ahfdgcebij
bagedfcihjk
abcdhkgifjle
fkgdeachblijm
alcdbfgjihkmen
jfobedghiaklmcn
ahgdemcnijklfbop
aecdjlbhiqkfmnopg
aecdbfjhkimlgnopqr
afcdqbghriklmnopejs
dbcaefghijktmnosqrpl
qbisefgpcjklmnohdratu
pdcbeaghijmlknofqrstuv
aoedqfghijkclnbpmrstuvw
atcdef...

result:

ok OK

Test #5:

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

input:

50
3
a c a a bb b c a a
4
dc c a b b c ad c c c c c d da da a
5
a d a a a e a a ce a b bb bb c cc cc cd cd a d a e b e dc
6
d ab a ab b b ba ba bd bd bf c c d d a d d d eb d d d d e ea eb d ed ed ef ef f f f fe
7
a a a a ea f bb bb bg g cb cb cc cc f cd cd cd ce d d dc e e b ea ec ec ee eg eg f f f ...

output:

abc
cdab
acbde
debafc
fcebgda
gafedbhc
ihbfedagc
haiebjcfdg
chkefdigbaj
echkagbilfjd
ajcmhgbidklfe
ibmckfgaehndjl
ogfhbicekndljma
ngmdkpiblcfeajho
qlgbcipjkdehnfmao
qadoilgcepfbnjkhrm
kdiceagnlrjhbosfqmp
iakrbqdgmescjpnlhotf
nhedbluojtakqpgscrimf
esflhqkbnoamrduivgcptj
wmjqcgauvlhofdnpbsrteki
unsbtm...

result:

ok OK

Test #6:

score: 0
Accepted
time: 17ms
memory: 2520kb

input:

50
3
b a a c c c bb c c
4
a cb b d bc c cd a cb d d b d d d d
5
a a a b b dd c c cc d cc e db e da bd e db e e e e dd e e
6
a a b b f ed c c b cd d d db f dc df df e eb eb f be ed ef ef f f cd f ec f f f dc f f
7
fb a a a b b bf c c c ce ce d d g dd dd e e g ea ec ef ee ef ec f fb g fb fb fd fd fe f...

output:

cba
dcba
edcba
fedcba
gfedcba
hgfedcba
ihgfedcba
jihgfedcba
kjihgfedcba
lkjihgfedcba
mlkjihgfedcba
nmlkjihgfedcba
onmlkjihgfedcba
ponmlkjihgfedcba
qponmlkjihgfedcba
rqponmlkjihgfedcba
srqponmlkjihgfedcba
tsrqponmlkjihgfedcba
utsrqponmlkjihgfedcba
vutsrqponmlkjihgfedcba
wvutsrqponmlkjihgfedcba
xwvuts...

result:

ok OK

Test #7:

score: 0
Accepted
time: 11ms
memory: 2428kb

input:

50
3
a bb b a a c a c a
4
a b a a a a a a ba bc c cb c bc d d
5
a a a a bd a a a a b bb e a bd be c c cc db d e cc e bb d
6
a a a a a a e a ba d e b ba a bc bc bd be be c c ca ca cd cd ce d a dc dc e a a eb f f
7
a cg a a cb a a a a a c a a b bb bb bc bd bd bf bf bf bf a c cb a cc ce ce cg a d e ec ...

output:

abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi
abcdefghij
abcdefghijk
abcdefghijkl
abcdefghijklm
abcdefghijklmn
abcdefghijklmno
abcdefghijklmnop
abcdefghijklmnopq
abcdefghijklmnopqr
abcdefghijklmnopqrs
abcdefghijklmnopqrst
abcdefghijklmnopqrstu
abcdefghijklmnopqrstuv
abcdefghijklmnopqrstuvw
abcdef...

result:

ok OK

Test #8:

score: 0
Accepted
time: 21ms
memory: 2588kb

input:

50
3
a c a a b bb a a c
4
b c b ab b b ad a c b d d b b da ad
5
c c c c dd c bb ed b e c c da a d a c e b de a bb dd c de
6
d a a c bf da a a a dc e a a a fd da c f fa a fc d fb b db e cd cd b a b fa a fd dc fb
7
fd f e g ff e g e e fc e bf e fb fd c e c g bg d ff e g a e bf df ba ab ab fd bg e ba f...

output:

abc
badc
cdbea
afdcbe
efbcadg
agdbhfec
bdifahcge
jfbgdeachi
ajhbgfeickd
fkjehgbidcal
clijmhgfbdeka
nibkjghafcdelm
bnlokjihgaedcmf
pfcmlboihkjednga
eponjlbgihdfqmcka
rijqnmlkgohpfecdba
sdgponmlkqihjefrcba
tsgiponflqakhrmedcbj
ltsiqpobmunjghrfedcka
vdtfrqponmsjkibgleucha
avutsrnpoqmldjihgfwkcbe
xwvstu...

result:

ok OK

Test #9:

score: 0
Accepted
time: 15ms
memory: 2384kb

input:

50
3
a c c c b bb c c a
4
dc a cd d da c a a b a a a a dc c b
5
be b d cc a a d bb e a be d d cc eb e c ba d d d d d bb c
6
e ad ef db b c ad db b d da c b fe f fe a b fb b b da fb b a b e fd fd d b b de b fa e
7
dd f bb de a bd c aa bb c e c f f f f ba f f aa ae f dc f db dc bg f ba g bg c g gb ed ...

output:

cba
adcb
dbcea
bfdaec
fbdaegc
eabdfcgh
abhfcegdi
jfcdbaehig
abcedfhigjk
khcfadgibjel
jdclefghibkam
lgcdejbhifknma
abcdehfligkjnmo
ikognfdhajblmecp
amoiefghdjblkpcnq
kbcdehgqioalmnjpfr
ancfesrhijklmgopqbd
amgdfcheijklbnopqrst
fbcdeoghrjkainlpqmstu
dbcoefhaijklmgnpqrstuv
nbcdefghiwkljaosqmptuvr
abcsuf...

result:

ok OK

Test #10:

score: 0
Accepted
time: 17ms
memory: 2620kb

input:

50
3
b cc a b b b a c b
4
ab c ba d a c c ba a d c c c c b bc
5
cc d bd c a a a be e b a a e a a a bb a db cc bd e d bb c
6
ed af af d be a ea fa fd c a b fa b e eb fb eb ef c d d b fd d f ef d f d d ed d d d d
7
c aa d ee g d g aa a ff f d be d d d e ac d d ea eb ea be d f af d eg g d b eb fb c ff ...

output:

bca
cbad
abcde
defabc
daefbcg
dhebagfc
bahifcdeg
bceagfdihj
gbhfkcdeiaj
jialecgbfdkh
idjcgfkaemhbl
ngbecmjafkhdil
bcoeaidjnkfglhm
emnodgaihcfpjklb
bqcgofjinlaekphdm
kgceolrnhqipbafdjm
eflgbscoqpndmkajhir
bgmfthncdekqjrapiosl
sdhtprilkobacqjnmgeuf
bjqtdlfurspvcaehoingkm
lderwoqsjpnhvfmcbuikgat
noukih...

result:

ok OK

Test #11:

score: 0
Accepted
time: 20ms
memory: 2544kb

input:

50
3
c c c bb a a c c b
4
b d cb cb b a bc d d cd d c a d d d
5
c b e e bd da e d cc dd a e e db e db b e a a dd c e e cc
6
eb df f f eb d be f f c d a f df cd c dc b ef dc f f e ec f ef b cd ed db f f ed a b f
7
g fb ea b ec fe g f c bf c g dc dd b e g fb d ec ef ee ce ff c a fd g ef dd e g d g fb ...

output:

cba
dcba
edcba
fedcba
gfedcba
hgfedcba
ihgfedcba
jihgfedcba
kjihgfedcba
lkjihgfedcba
mlkjihgfedcba
nmlkjihgfedcba
onmlkjihgfedcba
ponmlkjihgfedcba
qponmlkjihgfedcba
rqponmlkjihgfedcba
srqponmlkjihgfedcba
tsrqponmlkjihgfedcba
utsrqponmlkjihgfedcba
vutsrqponmlkjihgfedcba
wvutsrqponmlkjihgfedcba
xwvuts...

result:

ok OK

Test #12:

score: 0
Accepted
time: 15ms
memory: 2400kb

input:

50
3
a a c c a b a a bb
4
b a c a a ba c a a a cb d d bc bc a
5
a db c e d e a d a a bd bb a e a b c bd be cc a bb a cc a
6
d ca a c d a c bc e f be ca ba a a ba b a eb cd bd a ce dc bc dc cd f a e a a a e be a
7
cb fb g ec cg a bf bd e d a cb a g a e dd f a c a cg bf bd bf g bf c d f a a e bc a ce ...

output:

abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi
abcdefghij
abcdefghijk
abcdefghijkl
abcdefghijklm
abcdefghijklmn
abcdefghijklmno
abcdefghijklmnop
abcdefghijklmnopq
abcdefghijklmnopqr
abcdefghijklmnopqrs
abcdefghijklmnopqrst
abcdefghijklmnopqrstu
abcdefghijklmnopqrstuv
abcdefghijklmnopqrstuvw
abcdef...

result:

ok OK

Test #13:

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

input:

50
2
a b a a
2
a a a b
2
a a a b
2
b b b a
2
b a a a
2
b b b a
2
a b a a
2
a b a a
2
a a a b
2
a b b b
2
b b b a
2
b a a a
2
a b a a
2
a a b a
2
b a b b
2
a a b a
2
a a a b
2
b b a b
2
b b b a
2
a a b a
2
a b a a
2
a a a b
2
b b b a
2
a a a b
2
a b a a
2
a a a b
2
b a b b
2
a b b b
2
a a a b
2
a a a...

output:

ab
ab
ab
ba
ab
ba
ab
ab
ab
ba
ba
ab
ab
ab
ba
ab
ab
ba
ba
ab
ab
ab
ba
ab
ab
ab
ba
ba
ab
ab
ba
ab
ab
ba
ba
ba
ab
ba
ba
ba
ab
ab
ab
ab
ab
ab
ab
ba
ba
ba

result:

ok OK

Test #14:

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

input:

50
52
uj Tp xo WR CE Ht q Wt RM sS mq Io ln TK eZ jH o mC hV ha hi a JH in hQ j Fg ar Wf Fp JH KR k xo gE qn az V Rs Pw nu un qv hH jH Da YK es XI b ec FN yg Z Tr Bw Ob gt pD k eo Xv lc no ln hz RW RF BZ rF yu k CI zu qJ Yz ex aI eU bn HW ej eo jP I jp xr ue yR V Tu zo Mv eh gz Xz mv FI hz mV ah Dh ...

output:

kehTRmxJHXqyrljaWYOSwigsnUzDuZbPtdCBIMcFpLNfvEGKoAVQ
RjxrlcZngyWomHJtIOBYTUPViCvuGpXkQSdALDwzbfNaqFMhEseK
FUcwvoLARpnGBQCDWdagNjyuthlYXefPJirZMSsbqHmIkTxzKOEV
OujFdfKkElwsJLVmMYSZpXIeHDRyhACBvzroGcbtnagPNxUTWiQq
wYtmrEDWGqIyVLNiHxzeTcgFkdQpBXnPZjKvARsJOoUbaSulfMhC
SwZAyhRNJgMFOnWoDpbLTEXlBackuqjetIs...

result:

ok OK

Test #15:

score: 0
Accepted
time: 32ms
memory: 2520kb

input:

50
52
A A A AF AF AF AF AJ AJ AK AK AK AK AN AN AU AU AX AX AZ AZ Ab Ab Ab Ab Ah Ah Ah Ah Ar Ar As As At At Av Av Aw Aw B B BC BC BE BE BF BF BI BI BK BK BK BK BL BL BL BL BM BM BM BM BM BM BN BN BP BP BR BR BR BR BT BT BV BV BV BV BZ Bb Bb Bc Bc Bf Bf Bh Bh Bh Bh Bh Bh Bh Bh Bh Bh Bn Bn Bn Bn Bn Bn...

output:

ZYXWVUTSRQPONBLzJIHGFEDwMAKyxCvutsrqponmleaihgfkdcbj
ZsXWVUTGRQPONMwKLIHSFEDCBAzyxJvutmrqponYlkjihgfedcba
ZYXWVUTSRQlONMLKJIHGFBuwEAzyxCvDtsrqponmPkhijgfedcba
ZYXWVUTSRQmONwLKJIHGFEDxBAzyCMvrtsuqdonPlkjihgfepcba
ZcXWVUTSRkPONJLKMIHGFEDCBAzylwautsrqponmxQjihgfedYbv
ZYXgVUTSwQPONMLKJIHGFyDCBezExRkutsr...

result:

ok OK

Test #16:

score: 0
Accepted
time: 32ms
memory: 2520kb

input:

50
52
A A A A AC AC AI AI AO AO AP AP AQ AQ AR AR Ab Ab Ai Ai Aj Aj Am Am An An Ao Ao Ao Ao Aq Aq Ar Au Au Az Az B B B B BF BF BK BK BK BK BK BK BN BN BO BU BU Ba Ba Bc Bc Be Be Bg Bg Bj Bj Bj Bj Bo Bo Bp Bp Br Br Bw Bw C C C C C C CA CA CD CD CG CG CO CO CS CS CW CW CW CW CX CX Cb Cb Cg Cg Cj Cj Co...

output:

abcdefghiylPmnWpqrstuvwxjzABCDEFGHIJKLTNOkQRSMUVoXYZ
abcdefghUjklmnopNrstSZwxyzuBCDEFGHIJKLMqOPQRATiVWXYv
cbadefghijklmnorqpstuUwMyzABCDEFGHIJKLxNPOQRSTvVWXYZ
abcdefghiSklmnopqrstuLwxTzABCDUFGHIJKyMNOPQRjvEVWXYZ
abcdefghijklmntpqrsvuowxyFAWCDEJGHIzKLMNOPQRSTUVBXYZ
absiefghdAklmnopqrctuvwxyzjBCDEFGYI...

result:

ok OK

Test #17:

score: 0
Accepted
time: 42ms
memory: 2472kb

input:

50
51
kt Dt kq nP Ec X Bh V FT LL qS bN Rx x Av mT mw ax wS h A bt vV GJ ni Hw vK bV d v mL bL ub gy mx h In AE TG cK Fj jj zk Xd yo mB LX FA br UI Fa Li bH Ad Q Jt K Cq A pH Gz NX ak Gh bT be Rf U Ga vK Ha Kh Fu TT vd yT KY GG S qe P KD CF FF jz Bf nK Rh vA ca jA Kj Hp tw w Al o RW Wf KU fm Mr Jt m...

output:

hGbHvRAImjLFKnCByWDJgqEMTcOaUkdzwPVoelNtXsxrYfQpuSi
FEfhbGwLQrljpSBzKoeTNJavguDycOCWtRPqidYxmAHVIkMUXsn
IRpyjwiSTkJnaBAdOsUQFMcrfhLeHgNGltobxPWzuEXYKDqmVCv
mMXWuYhVlSPoGHgNCBbdfcOrpyeRAtTaKvzxEILQnUisjwkFJDq
afoTPBRjStKgMHyLIOklcdvNwuFDEnVsGApYzXhmiWCeQUxqJbr
kFbiqnBwhMcPaHrNuQVeUJzgACmDfGxRXoyEsKSY...

result:

ok OK

Test #18:

score: 0
Accepted
time: 197ms
memory: 2412kb

input:

50
49
U ol fN hj aW n dQ qm OO ao T JQ an OO an QJ FF VV OT uE qE mK Cm Wj Op tA HH PR Rr ve Dn RV lP Op QO QW kV Od oL x Be IG Rz Ti o Mu VH OR pJ MU OL HS vB R qv Cu BF Vr BU l Ob z Qr ua Qt Qr nD dj aT RV vw ot JW dd dF cV OG RB nL qa aq Oq x F Qj bL RV lG nG Wj oM Vp Qx u Ho aS lL DU U U as JF O...

output:

UQavlfuROBodnpmIAVehiFqJGWCHLPMkgcKjDSbtTzENyxsrw
KILacmoApesfEWShBMtiVCwNxryUJlFnbqQPzukdDvOTgGRjH
ptndMgwRiVcPDoIThevubmCjlKOJHEBNsGzxaUQFqryWASfkL
kvPWwzdeQyGUfTauoqiFINpEtxgcDAmBROKMJVnCjrlbSLhsH
NWwrMBkDeCvtjLAVxTKOqmIEGuopyJRfsUHlgSzbhQPiaFcnd
nSWLMvKCODqdblNAtfUrxkQGFHheBpERIwjcaoyJsuTmzgViP
...

result:

ok OK

Test #19:

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

input:

50
43
je cx EP yb Mp fI lI Ob DO Dt Ct N fn LD N EC MM Dy cK Ly xI KL KG eu je Q s JJ Lm xJ jx ss g hk Le qJ sE yn qh vD D DI fH p wH ak ej so GK ld N Mk so Ks Jd hd sL qQ DA DH ud CC ix jF br je fe jp Lo JB p yc fE ix N DQ Jl lJ wl N N bA lE Bc lD Ju wi H KM eE Dw eu N fO ux qg rL Fz pe AC Jn lk q ...

output:

NDeifKJwBsjrFLxqMylbCmuOzcpgnahEHoAQPGItkvd
zpNbjomCFLuJEtgBfydscMieDHaqkPIvOlAwhKrxGnQ
entcwrboxQildHBaJMEupvkNKOGjPImDAygshLCFzfq
iMQCgvbzEhrNjHOpPacBuGfeLwJFAlxtkmonsqDKIdy
IPfKnucrslDNGeFhwjqvCaibQmtoMxAJgBpkHOdyzEL
LryNkBAGPpEvhxwbFIdMlaCsQzuienmHgofqDKtjOJc
DgpBicMksnjAbCtyELdfHJPvmKalOGFNouhw...

result:

ok OK

Extra Test:

score: 0
Extra Test Passed