QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#211201#6557. LCSLCSLCSQingyuAC ✓82ms2664kbRust20.8kb2023-10-12 11:48:172024-01-16 02:55:57

Judging History

你现在查看的是测评时间为 2024-01-16 02:55:57 的历史记录

  • [2024-01-16 02:59:27]
  • 管理员手动重测该提交记录
  • 测评结果:AC
  • 用时:82ms
  • 内存:2704kb
  • [2024-01-16 02:57:08]
  • 管理员手动重测该提交记录
  • 测评结果:100
  • 用时:82ms
  • 内存:2748kb
  • [2024-01-16 02:56:12]
  • 管理员手动重测该提交记录
  • 测评结果:100
  • 用时:81ms
  • 内存:2620kb
  • [2024-01-16 02:55:57]
  • 管理员手动重测该提交记录
  • 测评结果:100
  • 用时:82ms
  • 内存:2664kb
  • [2024-01-16 02:55:41]
  • 管理员手动重测该提交记录
  • 测评结果:100
  • 用时:82ms
  • 内存:2648kb
  • [2024-01-16 02:44:08]
  • 管理员手动重测该提交记录
  • [2023-10-12 11:48:31]
  • 评测
  • 测评结果:100
  • 用时:85ms
  • 内存:2752kb
  • [2023-10-12 11:48:17]
  • 提交

answer

pub use self::template::*;
use sticky::solve_one_infty;
mod sticky {
    use crate::sticky::permutation::StickyPermutation;
    use std::iter::IntoIterator;
    use std::mem::replace;
    use std::mem::swap;
    use std::ops::{Add, Index, Mul};
    mod permutation {
        use crate::sticky::permutation::steady_ant::steady_ant;
        use self::knuth::{knuth_tropical_multiplication, Core};
        use std::iter::{FromIterator, IntoIterator};
        use std::ops::{Add, Index};
        mod knuth {
            use super::StickyPermutation;
            use std::ops::Index;
            #[derive(Default, Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
            pub struct Core(Vec<Vec<usize>>);
            impl Core {
                pub fn first(&self) -> Option<&Vec<usize>> {
                    self.0.first()
                }
            }
            impl Core {
                pub fn len(&self) -> usize {
                    self.0.len()
                }
                pub fn is_empty(&self) -> bool {
                    self.0.is_empty()
                }
            }
            impl Index<usize> for Core {
                type Output = Vec<usize>;
                fn index(&self, index: usize) -> &Self::Output {
                    &self.0[index]
                }
            }
            impl From<&Core> for StickyPermutation {
                fn from(core: &Core) -> Self {
                    assert!(!core.is_empty());
                    let mut perm = vec![usize::MAX; core.len() - 1];
                    for i in 0..perm.len() {
                        for j in 0..perm.len() {
                            if core[i][j + 1] == core[i][j] + 1
                                && core[i + 1][j + 1] == core[i][j]
                                && core[i + 1][j] == core[i][j]
                            {
                                perm[i] = j;
                            }
                        }
                    }
                    debug_assert!(!perm.contains(&usize::MAX));
                    let ans = Self { perm };
                    debug_assert!(ans.is_valid());
                    ans
                }
            }
            impl From<&StickyPermutation> for Core {
                fn from(perm: &StickyPermutation) -> Self {
                    let mut ans = vec![Vec::default(); perm.len() + 1];
                    *ans.last_mut().unwrap() = vec![0; perm.len() + 1];
                    for i in (0..perm.len()).rev() {
                        ans[i] = ans[i + 1].clone();
                        for j in &mut ans[i][perm[i] + 1..] {
                            *j += 1;
                        }
                    }
                    let ans = Core(ans);
                    debug_assert_eq!(*perm, StickyPermutation::from(&ans));
                    ans
                }
            }
            pub fn knuth_tropical_multiplication(a: &Core, b: &Core) -> Core {
                let rows = a.len();
                let cols = match b.first() {
                    None => 0,
                    Some(x) => x.len(),
                };
                let mut c = vec![vec![usize::MAX; cols]; rows];
                let mut opt = vec![vec![0; cols]; rows];
                for l in 0..rows {
                    for r in (0..cols).rev() {
                        let left_ind = if l == 0 { 0 } else { opt[l - 1][r] };
                        let right_ind = if r + 1 == cols {
                            b.len() - 1
                        } else {
                            opt[l][r + 1]
                        };
                        let (res, ind) = (left_ind..=right_ind)
                            .map(|ind| (a[l][ind] + b[ind][r], ind))
                            .min()
                            .unwrap();
                        c[l][r] = res;
                        opt[l][r] = ind;
                    }
                }
                Core(c)
            }
        }
        mod steady_ant {
            use self::Color::{Blue, Red};
            use super::StickyPermutation;
            use std::iter::FromIterator;
            use std::ops::Index;
            #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
            enum Color {
                Red,
                Blue,
            }
            #[derive(Debug, Default, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
            struct ColoredPermutation {
                perm: Vec<(Color, usize)>,
            }
            impl Index<usize> for ColoredPermutation {
                type Output = (Color, usize);
                fn index(&self, index: usize) -> &Self::Output {
                    &self.perm[index]
                }
            }
            impl FromIterator<(Color, usize)> for ColoredPermutation {
                fn from_iter<T: IntoIterator<Item = (Color, usize)>>(iter: T) -> Self {
                    let ans = Self {
                        perm: Vec::from_iter(iter),
                    };
                    debug_assert!(ans.is_valid());
                    ans
                }
            }
            impl ColoredPermutation {
                pub fn len(&self) -> usize {
                    self.perm.len()
                }
                pub fn recip(&self) -> Self {
                    let mut perm = vec![(Red, usize::MAX); self.len()];
                    for i in 0..self.len() {
                        perm[self.perm[i].1] = (self.perm[i].0, i);
                    }
                    Self { perm }
                }
                fn is_valid(&self) -> bool {
                    StickyPermutation {
                        perm: self.perm.iter().map(|(_, ind)| *ind).collect(),
                    }
                    .is_valid()
                }
            }
            fn split(recip: &StickyPermutation) -> (StickyPermutation, StickyPermutation) {
                debug_assert!(recip.len() >= 2);
                let mut le = vec![usize::MAX; recip.len() / 2];
                let mut ri = vec![usize::MAX; recip.len() - le.len()];
                let mut index_le = 0usize..;
                let mut index_ri = 0usize..;
                for &value in &recip.perm {
                    if value < le.len() {
                        le[value] = index_le.next().unwrap();
                    } else {
                        ri[value - le.len()] = index_ri.next().unwrap();
                    }
                }
                (
                    StickyPermutation { perm: le },
                    StickyPermutation { perm: ri },
                )
            }
            fn color_cols(perm: &StickyPermutation) -> (Vec<usize>, Vec<usize>) {
                let mut colors = vec![Blue; perm.len()];
                for &i in &perm.perm[0..perm.len() / 2] {
                    colors[i] = Red;
                }
                let mut red = Vec::with_capacity(perm.len() / 2);
                let mut blue = Vec::with_capacity(perm.len() - red.len());
                for (i, color) in colors.into_iter().enumerate() {
                    match color {
                        Red => red.push(i),
                        Blue => blue.push(i),
                    }
                }
                (red, blue)
            }
            pub fn steady_ant(a: &StickyPermutation, b: &StickyPermutation) -> StickyPermutation {
                assert_eq!(a.len(), b.len());
                if a.len() < 2 {
                    return a.clone();
                }
                let br = b.recip();
                let (red_cols, blue_cols) = color_cols(b);
                let (ar_red, ar_blue) = split(&a);
                let (b_red, b_blue) = split(&br);
                let red = &ar_red.recip() + &b_red;
                let blue = &ar_blue.recip() + &b_blue;
                let mut ired = red.perm.iter();
                let mut iblue = blue.perm.iter();
                let c: ColoredPermutation = a
                    .perm
                    .iter()
                    .map(|&middle_index| {
                        if middle_index < red.len() {
                            (Red, red_cols[*ired.next().unwrap()])
                        } else {
                            (Blue, blue_cols[*iblue.next().unwrap()])
                        }
                    })
                    .collect();
                let cr = c.recip();
                let mut perm = vec![usize::MAX; c.len()];
                let mut col: usize = 0;
                for row in (0..perm.len()).rev() {
                    let (hcolor, hcol) = c[row];
                    if hcol == col {
                        col += 1;
                        continue;
                    }
                    if (hcolor == Blue) == (hcol < col) {
                        while col < c.len() {
                            let (vcolor, vrow) = cr[col];
                            if vrow == row {
                                col += 1;
                                break;
                            }
                            if (vcolor == Blue) == (vrow < row) {
                                perm[row] = col;
                                col += 1;
                                break;
                            }
                            col += 1;
                        }
                    }
                }
                for (ind, (_color, value)) in c.perm.iter().enumerate() {
                    if perm[ind] == usize::MAX {
                        perm[ind] = *value;
                    }
                }
                StickyPermutation { perm }
            }
        }
        #[derive(Default, Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
        pub struct StickyPermutation {
            perm: Vec<usize>,
        }
        impl Index<usize> for StickyPermutation {
            type Output = usize;
            fn index(&self, index: usize) -> &Self::Output {
                &self.perm[index]
            }
        }
        impl FromIterator<usize> for StickyPermutation {
            fn from_iter<T: IntoIterator<Item = usize>>(iter: T) -> Self {
                let ans = Self {
                    perm: Vec::from_iter(iter),
                };
                debug_assert!(ans.is_valid());
                ans
            }
        }
        impl StickyPermutation {
            pub fn id(n: usize) -> Self {
                Self {
                    perm: (0..n).collect(),
                }
            }
            pub fn len(&self) -> usize {
                self.perm.len()
            }
            pub fn recip(&self) -> Self {
                let mut perm = vec![0; self.len()];
                for i in 0..self.len() {
                    perm[self[i]] = i;
                }
                Self { perm }
            }
            fn is_valid(&self) -> bool {
                let mut tmp = self.perm.clone();
                tmp.sort();
                if let Some(&x) = tmp.first() {
                    if x != 0 {
                        return false;
                    }
                }
                for i in (0..tmp.len()).skip(1) {
                    if tmp[i - 1] + 1 != tmp[i] {
                        return false;
                    }
                }
                true
            }
        }
        impl<'a> Add<&StickyPermutation> for &'a StickyPermutation {
            type Output = StickyPermutation;
            fn add(self, rhs: &StickyPermutation) -> Self::Output {
                debug_assert_eq!(
                    Self::Output::from(&knuth_tropical_multiplication(
                        &Core::from(self),
                        &Core::from(rhs),
                    )),
                    steady_ant(self, rhs)
                );
                steady_ant(self, rhs)
            }
        }
        #[cfg(test)]
        mod test {
            use crate::sticky::permutation::StickyPermutation;
            use std::cmp::Ordering;
            pub fn next_permutation(perm: &mut [usize]) -> bool {
                let last_ascending = match perm.windows(2).rposition(|w| w[0] < w[1]) {
                    Some(i) => i,
                    None => {
                        perm.reverse();
                        return false;
                    }
                };
                let swap_with = perm[last_ascending + 1..]
                    .binary_search_by(|n| usize::cmp(&perm[last_ascending], n).then(Ordering::Less))
                    .unwrap_err();
                perm.swap(last_ascending, last_ascending + swap_with);
                perm[last_ascending + 1..].reverse();
                true
            }
            #[test]
            fn add() {
                for n in 1..7 {
                    let mut a: Vec<_> = (0..n).collect();
                    let mut b = a.clone();
                    loop {
                        loop {
                            let _ = &StickyPermutation { perm: a.clone() }
                                + &StickyPermutation { perm: b.clone() };
                            if !next_permutation(&mut b) {
                                break;
                            }
                        }
                        if !next_permutation(&mut a) {
                            break;
                        }
                    }
                }
            }
        }
    }
    #[derive(Default, Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
    pub struct InfiniteStickyPermutation {
        perm: Vec<i128>,
    }
    impl InfiniteStickyPermutation {
        pub fn id(n: usize) -> Self {
            Self {
                perm: (0..n).map(|x| x as i128).collect(),
            }
        }
        fn is_valid(&self) -> bool {
            let mut tmp = self.perm.clone();
            tmp.sort();
            for i in (0..tmp.len()).skip(1) {
                if tmp[i - 1] == tmp[i] {
                    return false;
                }
            }
            true
        }
        pub fn len(&self) -> usize {
            self.perm.len()
        }
        pub fn lcs(&self, repetitions: i128) -> i128 {
            (0..self.len())
                .map(|index| repetitions.min(self.period_at(index)))
                .sum::<i128>()
        }
        pub fn period(&self, value: i128) -> i128 {
            (self.len() as i128 - 1 - value).div_euclid(self.len() as i128)
        }
        pub fn period_at(&self, index: usize) -> i128 {
            self.period(self.perm[index])
        }
        pub fn recip(&self) -> InfiniteStickyPermutation {
            let mut perm = vec![Default::default(); self.len()];
            for i in 0..self.len() {
                let p = self.period_at(i);
                let shift = p * (self.len() as i128);
                perm[(self.perm[i] + shift) as usize] = i as i128 + shift;
            }
            InfiniteStickyPermutation { perm }
        }
        pub fn repeat(&self, times: i128) -> Self {
            Self {
                perm: (0..times)
                    .flat_map(|k| self.perm.iter().map(move |x| x + k * self.len() as i128))
                    .collect(),
            }
        }
        pub fn ends(&self) -> Vec<i128> {
            let mut ans = self.perm.clone();
            ans.sort();
            ans
        }
    }
    impl Index<usize> for InfiniteStickyPermutation {
        type Output = i128;
        fn index(&self, index: usize) -> &Self::Output {
            &self.perm[index]
        }
    }
    pub fn solve_one_infty<'a, T: PartialEq + 'a>(
        a: impl IntoIterator<Item = &'a T>,
        b: &[T],
    ) -> InfiniteStickyPermutation {
        let mut perm: Vec<_> = (0..b.len() as i128).collect();
        for ch in a.into_iter() {
            if let Some((mut pos, _val)) = b.iter().enumerate().find(|(_ind, val)| ch.eq(val)) {
                let mut horizontal = perm[pos];
                for _i in 0..b.len() {
                    pos += 1;
                    if pos == b.len() {
                        pos = 0;
                        horizontal -= b.len() as i128;
                    }
                    if b[pos] == *ch || horizontal > perm[pos] {
                        swap(&mut horizontal, &mut perm[pos]);
                    }
                }
            }
        }
        InfiniteStickyPermutation { perm }
    }
    impl From<&InfiniteStickyPermutation> for StickyPermutation {
        fn from(value: &InfiniteStickyPermutation) -> Self {
            let mut srt: Vec<_> = value.perm.iter().enumerate().collect();
            srt.sort_by_key(|x| x.1);
            srt.iter()
                .map(|(ind, _)| ind)
                .copied()
                .collect::<Self>()
                .recip()
        }
    }
    impl Mul<u128> for &InfiniteStickyPermutation {
        type Output = InfiniteStickyPermutation;
        fn mul(self, rhs: u128) -> Self::Output {
            match rhs {
                0 => InfiniteStickyPermutation::id(self.len()),
                1 => self.clone(),
                2 => self + self,
                y => {
                    if y % 2 == 0 {
                        &(self * (y / 2)) * 2
                    } else {
                        &(self * (y - 1)) + self
                    }
                }
            }
        }
    }
    impl<'a> Add<&InfiniteStickyPermutation> for &'a InfiniteStickyPermutation {
        type Output = InfiniteStickyPermutation;
        fn add(self, rhs: &InfiniteStickyPermutation) -> Self::Output {
            assert_eq!(self.len(), rhs.len());
            let up = self.repeat(3);
            let down = rhs.repeat(3);
            let rdown = down.recip();
            let starts = up.ends();
            let ends = rdown.ends();
            let a = StickyPermutation::from(&up);
            let rb = StickyPermutation::from(&rdown);
            let b = rb.recip();
            let c = &b + &a;
            let mut ans = vec![i128::MAX; self.len()];
            let mut used = vec![false; ans.len()];
            for i in self.len()..2 * self.len() {
                let from = starts[c[rb[i]]];
                let to = ends[rb[i]];
                let ind = to.rem_euclid(ans.len() as i128);
                let shift = to - ind;
                ans[ind as usize] = from - shift;
                debug_assert!(!replace(
                    &mut used[ans[ind as usize].rem_euclid(ans.len() as i128) as usize],
                    true
                ));
            }
            assert!(!ans.contains(&i128::MAX));
            let ans = Self::Output { perm: ans };
            debug_assert!(ans.is_valid());
            ans
        }
    }
}
fn solve_test(scan: &mut impl Scanner) {
    let l = scan.next();
    let k = scan.next();
    let a: Vec<_> = scan.next::<String>().chars().collect();
    let b: Vec<_> = scan.next::<String>().chars().collect();
    if a.is_empty() || b.is_empty() {
        println!("0");
        return;
    }
    let perm = solve_one_infty(&a, &b);
    println!("{}", (&perm * l).lcs(k));
}
pub fn solve(scan: &mut impl Scanner) {
    let t = 1;
    for _test in 0..t {
        solve_test(scan);
    }
}
#[allow(dead_code)]
fn main() {
    solve(&mut IOScanner::new(std::io::stdin().lock()));
}
pub mod template {
    use std::io::BufRead;
    pub trait Scanner {
        fn next<T: std::str::FromStr>(&mut self) -> T;
        fn seek(&mut self) -> bool;
    }
    pub struct IOScanner<ReadType: BufRead> {
        read: ReadType,
        buffer: Vec<String>,
    }
    impl<ReadType: BufRead> Scanner for IOScanner<ReadType> {
        fn next<T: std::str::FromStr>(&mut self) -> T {
            loop {
                if let Some(token) = self.buffer.pop() {
                    return token.parse().ok().expect("Failed parse");
                }
                let mut input = String::new();
                self.read.read_line(&mut input).expect("Failed read");
                self.buffer = input.split_whitespace().rev().map(String::from).collect();
            }
        }
        fn seek(&mut self) -> bool {
            let mut input = String::new();
            while let Ok(cnt) = self.read.read_line(&mut input) {
                if cnt == 0 {
                    break;
                }
                let line = input.trim();
                if !line.is_empty() && line.matches("=").count() == line.len() {
                    return true;
                }
                input.clear();
            }
            return false;
        }
    }
    impl<ReadType: BufRead> IOScanner<ReadType> {
        pub fn new(read: ReadType) -> IOScanner<ReadType> {
            IOScanner {
                read,
                buffer: Vec::<String>::default(),
            }
        }
    }
}
 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

10 10
AB
BA

output:

19

result:

ok 1 number(s): "19"

Test #2:

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

input:

100000000 100000000
A
AB

output:

100000000

result:

ok 1 number(s): "100000000"

Test #3:

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

input:

1000000000000000 1000000000000000
BDCABACCCABBBDBDDCDADACBACBACDDCDCBADDDCDDCBBABDBA
DACBBDDBBCADCCACACAACBCBCCCBBABDACAACADAADCDBCCCBB

output:

30999999999999997

result:

ok 1 number(s): "30999999999999997"

Test #4:

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

input:

1000000000000000 1000000000000000
BDDCACBCBCBBAACBBBBACCBADDDCDACCBACCDDDBBDBDBBBCBA
CCCCBAADCDCDABADDBCCDACAABADAABCBDCCAADDABADDBCBBC

output:

30000000000000000

result:

ok 1 number(s): "30000000000000000"

Test #5:

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

input:

1000000000000000 1000000000000000
BADDABDACDAAABBCDBBDDDCDAACCAACBBCBBACCACDCBCDDAAD
CCADACCCDBBCAABCCDBDBAABDAACDBBABBDDCBCBACBBAABCBB

output:

32999999999999993

result:

ok 1 number(s): "32999999999999993"

Test #6:

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

input:

1000000000000000 1000000000000000
ABAABDCBBABACBDDDADBBBCBBDBACBACDCCBADCDBDBBAAABBA
BCCCBAACBBDCBCADADBACCBBCBCCACDBCDCBBCCACCADBCDBCB

output:

31999999999999998

result:

ok 1 number(s): "31999999999999998"

Test #7:

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

input:

1000000000000000 1000000000000000
BCDAABCABDCDDBDADABBDABBBDACCCAADABCCCDBDAADBCACDA
DBACCCDCCBDACADAADACCBCDADDCABCCBDBCBDBADACCDABBDB

output:

35999999999999991

result:

ok 1 number(s): "35999999999999991"

Test #8:

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

input:

1000000000000000 1000000000000000
AACACCDDDDBACAADADCBABCCBDBACDDABABABDBCAABABADADA
ACDBAACBCBBDBBACBABABBDBBBDAADBCACCABBADDDDDDADCDC

output:

33999999999999996

result:

ok 1 number(s): "33999999999999996"

Test #9:

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

input:

1000000000000000 1000000000000000
CADADCCCDDADBDCDCDBAACDBDACACBDDDCCDAADABDBACCBCDB
BABABACCBDAAADCDBDDDABDBADDADBBDBBACAABCCACCBDCAAD

output:

32999999999999996

result:

ok 1 number(s): "32999999999999996"

Test #10:

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

input:

1000000000000000 1000000000000000
ADDCBCBBAADDBCADCCDBDBBAADACDBCAAACCBBABCADBBAABCC
AAACCDDDCBBDBCCCCCBBAAACBCDCDAAABBBAAACCCDBADADBCB

output:

32999999999999999

result:

ok 1 number(s): "32999999999999999"

Test #11:

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

input:

1000000000000000 1000000000000000
BACBCACDDBCDADDDBBAABBCBCCBCBCABDBDBBBCADABDDDCDAA
CCBCACADDBDDCCBABAABBABCDDAACADBCDBDBDABABCCBBCAAB

output:

32999999999999999

result:

ok 1 number(s): "32999999999999999"

Test #12:

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

input:

1000000000000000 777777777777777
CCBBCBAABCCCBABCBCAAAACABBACCCCACAABCBBACACAACABCB
CCBAABCABBBCCAABBCBBCACABCAAACACABACBCCBAACBCBCAAC

output:

31666666666666648

result:

ok 1 number(s): "31666666666666648"

Test #13:

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

input:

1000000000000000 777777777777777
ACBAAAACCACCCBAACAAABACACCABCBCBABBBACBABCAACCBCCA
CBCBACACACBCACCABACCBCCBAAAAABBACBACACBCCBABCAACBB

output:

31777777777777755

result:

ok 1 number(s): "31777777777777755"

Test #14:

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

input:

1000000000000000 777777777777777
CCCACCBCBACBACBCABAABABCCAAAACCCCCBBAABBCCBCCCABBA
CACAACBCCCBAAACACABCCABCCCCCABCAAAABBBCBBBAABCCACC

output:

29888888888888870

result:

ok 1 number(s): "29888888888888870"

Test #15:

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

input:

1000000000000000 777777777777777
CABACBCBBCBABACABBBBBBABBCABCBCBCAABCBCCCBABACCCCA
BBABBBACBBACBCCCAAACACCABABCCCBCACCBCBCAACACBCCBAC

output:

31222222222222201

result:

ok 1 number(s): "31222222222222201"

Test #16:

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

input:

1000000000000000 777777777777777
BCCBCCACCBCBCABBBCCABAACACCBCCCBCCACCBBCBCCCBBCCBA
CBCBCBBCBABCBACBBABABCBCACBAAABBABACABBCBCCBACCBBC

output:

31777777777777754

result:

ok 1 number(s): "31777777777777754"

Test #17:

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

input:

1000000000000000 777777777777777
BABACACCABCAACBAABCCACCACBCCAABBCBAABABAACAAAAAACC
CBCBBABBBBBCBCACBABABACBBABCBABBCACBCACCBCAAABACAA

output:

29555555555555538

result:

ok 1 number(s): "29555555555555538"

Test #18:

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

input:

1000000000000000 777777777777777
ACCACABABBACBBAACCBBACBBCCACCACCABCCBABABBBACBACBA
ABCBBCAACAABABBABBAACABCAABCCABACBBBBCABCCCACBACBA

output:

32666666666666648

result:

ok 1 number(s): "32666666666666648"

Test #19:

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

input:

1000000000000000 777777777777777
ABBBBAABCAACCBACBBAACACABCABACBAABCAABBCCCCCCACBCC
CCAABCBABAABCBBAAACCCCCABAAAABCAABBCCCCACCBACABABB

output:

32222222222222200

result:

ok 1 number(s): "32222222222222200"

Test #20:

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

input:

1000000000000000 777777777777777
ABBAACCCACBBABBABCCCABABCACABABACCCBACACABCBCCCBAB
CCCCABCBAABBAAABACCCCABBABABAACABBCACBACACBBCBAABA

output:

32888888888888869

result:

ok 1 number(s): "32888888888888869"

Test #21:

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

input:

973726016575412 359840763615420
CCBBCBAABCCCBABCBCAAAACABBACCCCACAABCBBACACAACABCB
CCBAABCABBBCCAABBCBBCACABCAAACACABACBCCBAACBCBCAAC

output:

17886241906500152

result:

ok 1 number(s): "17886241906500152"

Test #22:

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

input:

158612425862653 819897228289078
CBABBBACBABCAACCBCCACBCBACACACBCACCABACCBCCBAAAAAB
BACBACACBCCBABCAACBBCCCACCBCBACBACBCABAABABCCAAAAC

output:

7930621293132650

result:

ok 1 number(s): "7930621293132650"

Test #23:

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

input:

342887581257444 503649293440596
BAAACACABCCABCCCCCABCAAAABBBCBBBAABCCACCCABACBCBBC
BABACABBBBBBABBCABCBCBCAABCBCCCBABACCCCABBABBBACBB

output:

13930205890208364

result:

ok 1 number(s): "13930205890208364"

Test #24:

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

input:

611173004830129 302236715540260
ACACBCCBACBCCBCCACCBCBCABBBCCABAACACCBCCCBCCACCBBC
BCCCBBCCBACBCBCBBCBABCBACBBABABCBCACBAAABBABACABBC

output:

14534160640930915

result:

ok 1 number(s): "14534160640930915"

Test #25:

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

input:

748236303528072 636528103155221
ABBBBCCAABCBBCACCBBCAAAABABABBABBBACAAABAABACCBCAA
CCAABCBBACCACBABBCCCACCBCABCACABBAACCCACBBABBABCCC

output:

22870745711378875

result:

ok 1 number(s): "22870745711378875"

Test #26:

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

input:

313370955837837 945058801322270
CCCCABCBAABBAAABACCCCABBABABAACABBCACBACACBBCBAABA
ABBBBAABCAACCBACBBAACACABCABACBAABCAABBCCCCCCACBCC

output:

15668547791891850

result:

ok 1 number(s): "15668547791891850"

Test #27:

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

input:

639219823402319 847398008805143
CAABBCCCCACCBACABABBACCACABABBACBBAACCBBACBBCCACCA
CCABCCBABABBBACBACBAABCBBCAACAABABBABBAACABCAABCCA

output:

26580313328719184

result:

ok 1 number(s): "26580313328719184"

Test #28:

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

input:

644195574734088 149903035076783
ABBACCCBBBCCACBACCCBCCAABCAABCBBBCCBACCBABCAACACAA
BABABACABBCBBACCACBBBCBABCCACCABCACABAACBBACBACCAA

output:

7495151753839150

result:

ok 1 number(s): "7495151753839150"

Test #29:

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

input:

546793478816387 321638328601260
ACCBCBAABAAACABBAABABBBBBCABAAAAAABACBBAABBAABBCAC
ABBCBBCAABBCBAAAAACBABCAACAAACAACBCCCBCBABABBCBCAC

output:

13701859359967636

result:

ok 1 number(s): "13701859359967636"

Test #30:

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

input:

973726016575412 359840763615420
PHQGHUMEAYLNLFDXFIRCVSCXGGBWKFNQDUXWFNFOZVSRTKJPRE
PGGXRPNRVYSTMWCYSYYCQPEVIKEFFMZNIMKKASVWSRENZKYCXF

output:

8932674756917526

result:

ok 1 number(s): "8932674756917526"

Test #31:

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

input:

158612425862653 819897228289078
YGPOEYLFPBNPLJVRVIPYAMYEHWQNQRQPMXUJJLOOVAOWUXWHMS
NCBXCOKSFZKVATXDKNLYJYHFIXJSWNKKUFNUXXZRZBMNMGQOOK

output:

4494818122105909

result:

ok 1 number(s): "4494818122105909"

Test #32:

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

input:

342887581257444 503649293440596
VSCMPSAJLFVGUBFAAOVLZYLNTRKDCPWSRTESJWHDIZCOBZCNFW
LQIJTVDWVXHRCBLDVGYLWGBUSBMBORXTLHCSMPXOHGMGNKEUFD

output:

6793659154475459

result:

ok 1 number(s): "6793659154475459"

Test #33:

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

input:

611173004830129 302236715540260
GEKJDQZJENPEVQGXIEPJSRDZJAZUJLLCHHBFQMKIMWZOBIWYBX
DUUNFSKSRSRTEKMQDCYZJEEUHMSRQCOZIJIPFIONEEDDPSZRNA

output:

7280479467964673

result:

ok 1 number(s): "7280479467964673"

Test #34:

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

input:

748236303528072 636528103155221
MHECTHLEGRPUNKDMBPPWEQTGJOPARMOWZDQYOXYTJBBHAWDYDC
PRJBXPHOOHPKWQYUHRQZHNBNFUVQNQQLRZJPXIOGVLIEXDZUZO

output:

9994754348819718

result:

ok 1 number(s): "9994754348819718"

Test #35:

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

input:

644195574734088 149903035076783
MDCASZSGOVSODKJGHCWMBMXRMHUYFYQGAJQKCKLZNAYXQKQOYZ
WMYUBZAZCPKHKTKYDZIVCUYPURFMBISGEKYRGZVXDHPOAMVAFY

output:

4586257921157402

result:

ok 1 number(s): "4586257921157402"

Test #36:

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

input:

546793478816387 321638328601260
PNARAEWKEGJCCVHHRJVBJTSQDJOOTGPKNFPFYCGFIEOWQRWWWP
ZSQMETOGEPSPXNVJIUPALYYNMKMNUVKLHSECDWRACGFMZKGIPD

output:

5725195529879408

result:

ok 1 number(s): "5725195529879408"

Test #37:

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

input:

636154209737260 637882913598407
BBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBA
BBABBBABAABBBBBBAABAAAAAAAAABABAAABBABBAAAAAABAAB

output:

22917109885291680

result:

ok 1 number(s): "22917109885291680"

Test #38:

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

input:

681989722828907 925533374380880
BABBBABAAABAAABBBBBBBBBBBABAAAAABAABABABABA
BBBAABAAAABABAABABBAAAABBABABBBABBABABBABBAABAAAB

output:

28107502331466223

result:

ok 1 number(s): "28107502331466223"

Test #39:

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

input:

862146291503649 616335532825361
ABBAABAAABAAAABBBAAABAABBBBAABBAAABBBABBBBA
BABAABBAABABBABAABBABBABAABBBBABBBBABBBBAABAABAAB

output:

26862100868859748

result:

ok 1 number(s): "26862100868859748"

Test #40:

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

input:

567384926577457 831484920706070
ABBAAABBABAAAABBABABBAAAAAABBABBABBABAABAAB
BABBBBABABBBABBBBAAAAAABABAAABBBAABBAAABABBAAAABA

output:

23370142230523426

result:

ok 1 number(s): "23370142230523426"

Test #41:

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

input:

858324115951064 324442792373157
BABAAABABBBBAAAAAABBBBBAAAABABABABAABBBAABB
ABABABBBAAABABABABAAABBAAABABBBBBAABABABBBBBBBAAB

output:

15897696826284693

result:

ok 1 number(s): "15897696826284693"

Test #42:

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

input:

190429314820559 745680774313630
BBAABBBABAABABAABABBBBAABBAAABABABBAAABAABB
BAABABBABBABAAABBABABBBBAABBABBBBBABABBBBBAABABAA

output:

8188460537284037

result:

ok 1 number(s): "8188460537284037"

Test #43:

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

input:

562535661446268 454253268266394
BAABAABABBBAAABABBBABABAAABBAAABABBBBBABBBA
BBABBBBBBAAAABAAAAABBAAABABBABABBAABBBAABAABBBBBA

output:

18756454003094308

result:

ok 1 number(s): "18756454003094308"

Test #44:

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

input:

908387269381033 92824504405115
ABBBABBBBAAAAABBAAAABABABAAABBBAAAAAABBABAB
BABBAABAAABBBABABBBBBAABBABAABABAABBBBBBBAABABBBB

output:

4548400715850635

result:

ok 1 number(s): "4548400715850635"

Test #45:

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

input:

780208928205527 986623826275782
AAAABBABBBBBABABAABBAAABBABABBAAAAABBAAABAB
ABBABABBABBAAAABBBAAAABAAABAAABAABABABAAABABBABAA

output:

31918503150582829

result:

ok 1 number(s): "31918503150582829"

Test #46:

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

input:

104075905120989 790814079538232
BBBBBBAAAAABAABABABAAAAAABABBBABBAAAABBABAB
BBBAABAAAAABAABABBAAAABAAAABABAABBBBBBAAABBABBAAA

output:

4475263920202527

result:

ok 1 number(s): "4475263920202527"

Test #47:

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

input:

263159702617625 132816467796419
BBBBABAAAAABABBBAAAABABBABAAABBBAABBAAABABA
AABABAAAABAABAABABBABBBAAAABABABBBBAABBABBAABBAAB

output:

6485747825247612

result:

ok 1 number(s): "6485747825247612"

Test #48:

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

input:

529126170152290 536315340317903
BAABBBBBAAAABBBABBABBBAABAABAAABBBBBBABBAAA
BBAAABAAABBABBBABBAABABBBBAABAABAABABBABABAAAABBB

output:

20193064507774373

result:

ok 1 number(s): "20193064507774373"

Test #49:

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

input:

13939365540506 266330081381698
BBABAAAABAABAABABABABBAAAAABAABBABAABBBBAAB
BBAABABABABABBBBABAAABAABAABBBBBABBBBBABBBAABBBAB

output:

599392718241758

result:

ok 1 number(s): "599392718241758"

Test #50:

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

input:

958962576385930 476630908015103
BBBABAAABABABAAABAAAAAABAAABBABAABBABABABAB
BAABABABAAAAABAAABBBBBABBBBBBABBBBABBAAAABBAABABB

output:

23354914492740047

result:

ok 1 number(s): "23354914492740047"

Test #51:

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

input:

413850921335290 810687651295615
BBAABAABBBAAABBBABBBBBBBABBBAABBBBBAAAABBAB
BBABBABABBABBBAAAABAABAABBABABAAAABBBBBBABBABBBAB

output:

17795589617417470

result:

ok 1 number(s): "17795589617417470"

Test #52:

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

input:

23168772879592 668058895732220
AABBBBABABABBAABABAABABAAAABBABAABAAABBBBBA
BAABBBAABABABAABAAABABBABABBBBAABABBBAABAAAABABAB

output:

996257233822456

result:

ok 1 number(s): "996257233822456"

Test #53:

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

input:

233730148789897 710283556149383
BBBAABBAAAABBABAABBABBABBBAABABBAABBBBABABA
BBBBABBBABBBAABBBBBBBABAAABABAABAAAABBABBABAAAAAB

output:

10050396397965571

result:

ok 1 number(s): "10050396397965571"

Test #54:

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

input:

1000000000000000 1000000000000000
A
B

output:

0

result:

ok 1 number(s): "0"

Test #55:

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

input:

1 1
Z
Z

output:

1

result:

ok 1 number(s): "1"

Test #56:

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

input:

1 1
Z
X

output:

0

result:

ok 1 number(s): "0"

Test #57:

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

input:

1 1
ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ
QWERTYUIOPQWERTYUIOPQWERTYUIOPQWERTYUIOPQWERTYUIOP

output:

10

result:

ok 1 number(s): "10"

Test #58:

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

input:

1 1
WUENWFRVUKUMWDWDTLNRJVVTDNQOQHBYYRLMTJGXCCFFOYLSYU
IIYVWJQBXKFYLNASJZKWNDPRHFXQLYNXBLISAHVVUTGPPDDBES

output:

13

result:

ok 1 number(s): "13"

Test #59:

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

input:

1 1
ETENXUYB
OADWEXSILYMACRDWTFJW

output:

3

result:

ok 1 number(s): "3"

Test #60:

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

input:

1 1000000000000000
ZBIPVAVAHJNPFOUWQBAENFAIFIKBNLHACXNGXJACJIUCREXTNF
PLCOKTLSGXYCWEYUESHJPWOXQHYKGTJCLDPRXVPKBGGWXCRNFG

output:

39

result:

ok 1 number(s): "39"

Test #61:

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

input:

1 1000000000000000
DPKSKTQCQAZW
UKEMYAACWM

output:

5

result:

ok 1 number(s): "5"

Test #62:

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

input:

1000000000000000 1000000000000000
YGHXKMKWKQJDDRDCYJQEBIWLUKRZYANNFLCKXREDLESEGCLLGM
IVFCHPGIJVJ

output:

5999999999999998

result:

ok 1 number(s): "5999999999999998"

Test #63:

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

input:

1000000000000000 1000000000000000
PVRLQSSFHCGHZFFBAYSAZSOLCTUXQXNOAVRMQXBKLOIWXHMNXS
SBFAMJRALFKFDIOBYQDUATNSFECSOREZPUCKBIZXXLAFWKWXEQ

output:

16999999999999999

result:

ok 1 number(s): "16999999999999999"

Test #64:

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

input:

709861939765211 1000000000000000
BRJOSOC
JITUQQPUCJBXFNOEMZRMMW

output:

3129585819295632

result:

ok 1 number(s): "3129585819295632"

Test #65:

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

input:

710452281077929 1000000000000000
XXZKPXGCOBRQFIQBFQQDBTFIFYIUIOTHQXVBBYJUYQAFIIYCWE
OMWHJWLNTNFVVNRHTOEVDYQYLVMWJJSTFSJUUHGFVLTQKNYPRA

output:

9973165967545502

result:

ok 1 number(s): "9973165967545502"

Test #66:

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

input:

1000000000000000 683432196932049
YJIODJWMKNJWCGFFPRCOQOIBHYLXLHRT
LTCKSUBLTJVQNPHLDRPXJFYCP

output:

7417160984660242

result:

ok 1 number(s): "7417160984660242"

Test #67:

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

input:

1000000000000000 613892017596863
FHICJRFEZUMZGNGEUDGMNZFZQCCQDNNSPGCGZLGANMEDECZMLS
ZBIFBVNTCXJKZXKYIIGWRECTSWIYORTSHARHQRSATPQWYEPPCR

output:

9525028158371766

result:

ok 1 number(s): "9525028158371766"

Test #68:

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

input:

284965599323079 890548365990318
IQLBRWKRCZPUUOAXEDBSCXEXHJLQYZ
ARIZ

output:

1460479564636476

result:

ok 1 number(s): "1460479564636476"

Test #69:

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

input:

517331754115797 889576652477014
RTGJFGHOGKGSZGHRVXYGGPZEWKYOJEOSGKZBFHBFHBCVBWZHOJ
RDTSOBLHLZGJDNYCIYFKOMZYEDSBWRKKBVLADSPTLCKUIOMHTY

output:

9621200803543040

result:

ok 1 number(s): "9621200803543040"

Test #70:

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

input:

1000000000000000 1000000000000000
FA
VHSTVJHLYSCEHKZLEFSKUUTZXBWKBDEZOOONFBZFFMPU

output:

1000000000000000

result:

ok 1 number(s): "1000000000000000"

Test #71:

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

input:

1000000000000000 1000000000000000
AAQFZLADEGQJAVHYPJTHLGJMIEKHQGVODPNDNOWODNRZKAYQCF
VUUBBBLRQKSRPNMVWENXLYUSBGIBAFXLAOOSJJGKPNKAJIYJBN

output:

14999999999999998

result:

ok 1 number(s): "14999999999999998"

Test #72:

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

input:

1 1
SRFMKMIIWQASZHMXDZSCBSLOJOFIDYQHUDHZGLOBZEUFSHBLSDFFSXRUJKZCUDJZLWCJVQJGQZDRWABTFUIFSTEKGQZFVVTDWUPLNWIWJPNFLMDGLIIVHEUZWXIURGNLFZTVKWRHCRWNQMNNYEIDVDGPJGAAYSXKOMBCNSXTTUHLXHVNUDXXZMDNMHQKKSFYWPPRHFWXWCAZNXLLZVTNKTNKAXMXEMJPEIEPQCVTIQZPLMNHXTSJEILHDVGPXYPPGROZUYYUEJRUMVJSMILKLLMXCZBFNSXWFVWVBFPM...

output:

154

result:

ok 1 number(s): "154"

Test #73:

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

input:

1 1
XGFEIWMOZABDVGHURAVSMEENWXZUALZWHGLGTHMRYUMPBPKPAKKGUNBUWTBESXGKRTNULOMQNTZVRINHOANCPNZLQVKEFXHIHCTFBRCYOGETVZFRBXSRRERSSWJMNPZUFXMDLLPTRZSTAKUQEUVZNNWRWFQIMXQTDNHWCGSNIVALFICCSJGNWOLGGYIFDYZZIAUWPDRNTRELNNYNBEHUFZLEIKAQKEUEIHTHJTQTHKVSFFEHVLXKTUVRCUUACBFCIDSPCYGFRHHIQOOGONVNFNVJTPOPNVXAEYRWZ
QY...

output:

66

result:

ok 1 number(s): "66"

Test #74:

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

input:

1 1000000000000000
WTEIORVIPRJDVAINQMXMGHNIDCCMIBTOWZLZATVHOBZLFGQWQKJJOLBPBTMXXOYWNRVHJVDGWJGSNVXPLFBJQQSETXKDCCQQIVDCXGFNOVBMQFCEQCWZJUOJKCRGJYPPYFRMROVWFFSQJPXVAZBVJSRQVJSCNOVNVVBCFLIHCOFOOHYYYXWGKBIZXDTQQSCWGIGZLGSCXLGJYBJNHQQEIPONFEPROPOIUFGMZLVRZPQDJGVSXTQAFIVVHKXTJROHAEHCLEQIBKMRSVBRNIYOEVBNA...

output:

500

result:

ok 1 number(s): "500"

Test #75:

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

input:

1 1000000000000000
CLQFBZVZWTYSHTMEUOVNFTBSCZDADHDUALRKJERXLVBAXWPUWATBMYOMADTBVSZJFYJRQXOREPUQXSIOLXCXFWLLYCHSRYVZTPOWFZQFUYERYTTUDMNEFLAFKQNPITXLOPPSOZNXICCACGMIQHGYZQPRMBOJVGPUWGRJKBQQZVBWKCZKBYMZGKNMNZFDNPSHMDQAOMXXEVCPXITEZAIWKJOYTLDJCZWZPQTEASIIECDDHFEAVLJAVJOXMLTSWPXGBIIDZXZDAIBHRPAKHWJCFHJOZ...

output:

410

result:

ok 1 number(s): "410"

Test #76:

score: 0
Accepted
time: 45ms
memory: 2328kb

input:

1000000000000000 1000000000000000
YQSWVRNQIXGPAOARKSUYPMEEJNBXFNULBTTRXYVAYPJPBZDWGCJHRCWYDIXRCMXEPJGSLMNWPXSMTWYBEBOESQQEIBRXBXFKQASDJOTPFCQEOEOOKUWLLKWMWECVYLLAXNZPJOGRZTPCCJDCQUCOXKDIWMZGCRXROVAMCKQZUSOUETBBDZEQAEZMNADMBMIWRFPAEPGCAIQANGWATSGNWJLKIMJTNUAQPAHFNPOJRMQWHWYHYSRJATCNPROSIEZCNMVHKUAZEF...

output:

106999999999999992

result:

ok 1 number(s): "106999999999999992"

Test #77:

score: 0
Accepted
time: 73ms
memory: 2600kb

input:

1000000000000000 1000000000000000
GOAZLWUAILEUHESJJHLZUKKUNWCYNORLAFENCZXNCXDMTCAKUOZJYORXGYTHBVEMVKTDTGZERYCWXDVKHIRWIUEOIRPWMBYVSUNNWTGUUMEWBJPRFORTOCYQQCNNWNDSOXGBALFTAUMNYHKXAESQJDOGVDGTXZGICHJAWARMUYFVGGJWTOWXLCAPQXEQRSAETGYOQJRCLMPOUQXXXQRACHMDPHNDDNVSFAIBXYJRNMVFWQKKXHKJHPDENUMILVJHLUIYZHDOMG...

output:

168999999999999987

result:

ok 1 number(s): "168999999999999987"

Test #78:

score: 0
Accepted
time: 52ms
memory: 2396kb

input:

1000000000000000 1000000000000000
BBABBBBAAABABAAAAAABAABABBABBAABBBBABBABABAABBBBABBBBAAABABABBBAAAABABABBBAABAAABBABBAAAAABBAABBBAAAABAABABAAABBBBABBBBAAABBABABAAABBAAABAAAABAABBABABABBBAABAAAAAAAAAABBAABABBBBAABAABBBBABABABBBBABBAAAABAAAABABBABBBBAABAABABAAAABAAAAABBBAAAABAAAABAAABABABAAABBAABBBA...

output:

317999999999999994

result:

ok 1 number(s): "317999999999999994"

Test #79:

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

input:

1000000000000000 1000000000000000
BABBAABBBBAAAABAAABBBBAABBBBAAAAAABAAAAABBAAAABABBBBBBBBABBABBAAAAAABBABBAAABBABAAABABAAABBBBABABBAABBBABBBABBAAABBBABAABAABBABBBBABAAABBABBAABBAAAAAAAAAABBBAAAABBBBAAAABBBBAAAAAABABABAAABBABAABBBABBABAABBABBABBAABABABBBAABABBBAABABBABBBAAABABBBBAAABBBABBAABAAABBBAB...

output:

406999999999999962

result:

ok 1 number(s): "406999999999999962"

Test #80:

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

input:

878299321533672 1000000000000000
RYFJIZIEYSNEOCVAVPAQWAEPVIGYBPAHQYMTZYWKKZSLJFUMHZQECINMMYMFOTJLGGRYFDPTXQDZXCOJCZBBLAMXXLTREVHQWDMETEWWUPMXGQTRQEZBDBQVHKERFQPTXOXJIQS
UTEDNRIXUVSGSEGKAMXEUQOZKCGRNCDYBDYRZWKKNGIFTJRCZIYSAMEMLOXILANKCINWVIMMAPDYRO

output:

30809387787606094

result:

ok 1 number(s): "30809387787606094"

Test #81:

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

input:

612314485743516 1000000000000000
JRHQUCRDWFIJJLXXZKHQKLYAWUKOLYZQIRBOVTSRJKPXBTJCDVMZPPFAZQLXRTEDKRNIASXJXDYBZRRLQASCQJSCJUQYEJKOMYMIMUXCELSCTCEFJUZZTJEUSDPGLJWDARSRBSOPPKTUNOCXAEAHFNPBWNIZHRXVFZXEDAYFEAPMWDMMTSRNJGYXXNVWWBRMPEDPNQEHUMHQLHXDQIVBGDYVSHXLZFPHYDECRDIYQTBQQDMRZTQXZCKRCVBXFWUPQIJVEOKYOTT...

output:

124680706517325664

result:

ok 1 number(s): "124680706517325664"

Test #82:

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

input:

892824514164379 1000000000000000
AABAABAAAABBBBBBBABBBBABBABBBBAAAABBBBBBBABBAABAABABBAABBAABBBAAABBABBBBBABBBBAAAABBAABABAABBAAABBAABBBBBAABABBBAABBABAAAABBABABBAABAAABBBBBBABBBAAABBABAAABABAABAAAABAAABAAAABAABBAABBAABABABAABBBAAABAAABBAABAABABABBABBAABBABAAAABBBBBAABABABBBABBAAABAABBBBBBAAABAAABBA...

output:

258244289978766323

result:

ok 1 number(s): "258244289978766323"

Test #83:

score: 0
Accepted
time: 71ms
memory: 2528kb

input:

123867286261370 1000000000000000
BBBBBAAABAAAAAABBAAABBBABBAAAABBAABABBAABAAABABAAAABBBBAABBAABAABBBABBBABBABBBBABAAAABABBBBBBBAAAAABABBAABBBAAAABBBBABBBAAAAAABBABABBAABABBBABBABBAAAABBBBBABBBABABBBBABBBAABBBBBAABABBAABBBBAABBAABBBBBBBAAAAAABAAABABBBAAABAAAABAAABBABABBABABBAAAABBAABBBBABAAAAABABBBAB...

output:

61933643130685000

result:

ok 1 number(s): "61933643130685000"

Test #84:

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

input:

1000000000000000 764115182868089
QANDCKJJPUCSFLIFXEJSQWZOPUFHGTAUOCANEWSEMJHZNRGVFRNEKRXOAEYYFJDNIUYJAMSPZXLCUGWRNWLNFWSUDZIKDHXFAAQWTTMNYAKOXREOJVPUIPMMPBNXXGHZTLOHJOOWXIDWVIZAJENEIXQJDURUQPMBWQKWMHNEOJSNUUTVWXNGMGVHUFWBRCRSHCQEQYXLQQNJVSFFUQKMWSXISUEGGWBKXBFOZPDNCHKRDEPIJGZLIMWWGVZVNUIQWIIEBIVMHCE...

output:

19866994754570314

result:

ok 1 number(s): "19866994754570314"

Test #85:

score: 0
Accepted
time: 72ms
memory: 2624kb

input:

1000000000000000 476183538985259
RICITCBYQQIQBOKLQTTYNAJBQPFNFIYZPVZCSZHKMKLQDFXQIEYJNHBAIZVBGZQVBGILCGDVRMBXCVZOPBBKEDCOEQXTKWZHMIDXQSBUGAJUWNCYAVKWNCSLZRJWSZFHUHKVZOCMRHNKTDCQIVQKUUKXLISWKZRJCYVGNNCMDFBSKKGIPQAYTWFYRKZYTAMSGUQYJEXDBKRRYPXTSSQUBFFKVLSJDTYMOILIZNDKJKIPWWBDOGZFVDKOTHRZBIDLXTTLEPKSOXP...

output:

110618062535906778

result:

ok 1 number(s): "110618062535906778"

Test #86:

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

input:

1000000000000000 150672935307308
ABABABABAAAAAABAAABABBAABBBAABAABAAABBBABAAABBAAABBAAAAAABABAAABBABBBAABAAAABABBBBBBABABBBBBBBBBBBABAAAABABBBBABABAABABBABBABBABAABABBBAAABBBBBBABABBAAABBBBBAABBBAAAABABABBBAAABABABBBBABBBAAABBABABAABBBBABAABABABBABABBBBBAABABAAAABABBBAAABBBABBAAAABBAAABBABBBABBAABAA...

output:

66898783276444752

result:

ok 1 number(s): "66898783276444752"

Test #87:

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

input:

1000000000000000 359773194278922
ABAAABABBBABBAAAABAABAABBBBBBBBBBABBBBAABABBBAAABBBAABABABBBBBBABABAABBBBAAAABABBBBABAABBBAABBBAABBABAABBABAAAAAABBBAAABBBBBABBAABABAABABAAAAAAABBABBBBAAABBBBBAAABAAAABAABABBBABABAAABBBBBABABBAAAAAABAAABABABBBBBBABBBAAAABBABAABBABABABAAAABABAAABBBAABBBBBABABBBABABABA...

output:

179886597139461000

result:

ok 1 number(s): "179886597139461000"

Test #88:

score: 0
Accepted
time: 36ms
memory: 2344kb

input:

21963604011018 838748770205041
WWWVJOFXOGVWUNXTUVKTWNIHFTMXYKNIQHHVOZPTVNTAUHDJLGR
HSNLKRWYYQIIEVVSVNEBVDTKEBBRVYYRXRJLYBDSPTGAUMVHDHCLJFPSPMFODLPFFDWQVCRWAFRICENLHKDZFPDYRDALIZXTBIEDKINNMFGDMDMMYKAQNLSQBHGOUHGDZJQBRHISEBFSJZXWKNDYNZUAAZPQRBZWRGWJONXBIQGLAAUEINIYXBSQYQFHZIYZMYCHIQVFUGXKJWCNRCPVYRZHS...

output:

1120143804561918

result:

ok 1 number(s): "1120143804561918"

Test #89:

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

input:

340048297259706 538214145452218
YCSEKQKZJVRQXZEEEDNPUFKLANZVZKUAZPRGVEQIIJEPOEMQMSLZADQIDDVGCOTXCNEVJGKTETGAJQMFJSRALZYLBRQKPYJUVNWRFKGOZNAXYPSXWTGTGEGHFNAQNOMXDBVLTISEIXYUDKSLHNMDFSBECVLHKXYVVKXDGSAJKYXSAGNLJJCLLZJHCDPWKYVKDFFUQWFIETMXXHRAJOVGLYAPMHHIITGMSMIXZXCZNRCNONESGNRBJJHUIBXXKFEBDBFPKKNCMQPF...

output:

67657871642142499

result:

ok 1 number(s): "67657871642142499"

Test #90:

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

input:

408521356450237 663462232249049
BABAAABAAABAABABABABBABAAAABBBBAAABBABBAAAAABBABABBBBBABABABABAABBABBABAABAABBBABBABBABABABBAAAAAABBABBBBAAAABBAAABAABBABBBBABBBABABBBAAABABBBBBBABAAAABBABABAAABBBAAABABAABAABAABABBBBBAAAAABAABBAABBABABBBBABABBBAB
BABABBBABBBAABABBBBBABBABABAAABAAABBAAABBAAAAAAABBAABB...

output:

84757402247911765

result:

ok 1 number(s): "84757402247911765"

Test #91:

score: 0
Accepted
time: 73ms
memory: 2624kb

input:

223642247520665 476536814565577
BAAABAABABAAAABABBAAAAAABBBABAAAAAABABBABABAABAAAAABBABBAABABABBBBBBAAABBABBAAABBBBABBAABABABBAABAABAAAABBABABBBAAAAAABBBBBBABBBBABBBABABBBBBAAABBAAABAAAAAAABABAAAABAAABABBABABBAAAABABBABAAAAABBABBAAABBABBABBAABBAABAAAABBAAABBBABBAABBAABBBBAABABBABBBAABBABBBAAABAAAAAB...

output:

111821123760332500

result:

ok 1 number(s): "111821123760332500"

Test #92:

score: 0
Accepted
time: 52ms
memory: 2452kb

input:

1000000000000000 1000000000000000
HOPCEQOGKTXZBVKFFTYKFXEPQNEREERCYXKPFALTKSQCKCWLGQBBIHZHPUCPVKLOSSLXKINBYJGGFHSLOJPNFKSNBMPZNVCCFKKYXEVWTYGYHYGSAJYHQDWVZUCGDILMSJNFSZOIDZIQFINPIGQSBXLOLFFLEWJMMJQTQKLQIRNXFHNLKSPECHYACONYPNZKRIBGCSCUVMRIPPUJTRJSZPEAMECYYSNDPUOVXMNVPOORMNHDFXBFYFMLDAWWRKCPEUXKJOBQOS...

output:

107999999999999995

result:

ok 1 number(s): "107999999999999995"

Test #93:

score: 0
Accepted
time: 74ms
memory: 2504kb

input:

1000000000000000 1000000000000000
EGJTTURESKCLJAITKOVNRLOEDHDHVMVHYUBEZFQMLZTGGEFZDQQBYCJRXDWRNHIKOHILWPFJRUFAEPJETTLITCFVVLTHFOXYERIFLCBPICIDQFEIXGJYHRAMTWLWYEFFWSGNXHTIHFWEENBLDDAAYQBKAQPXMVMNELVVVOJRIXAMWFKZVCKHRVMCSADEGFMTHENAQLBIJRKGPVYFZWRJCGRGUNFRHFMXSYXPXSOHWJVQSQJGDZTDOUNAJGXHYETLTALMOPGRIC...

output:

168999999999999977

result:

ok 1 number(s): "168999999999999977"

Test #94:

score: 0
Accepted
time: 63ms
memory: 2496kb

input:

1000000000000000 1000000000000000
BBBABBAABAAAABBBAABAAAABBAABABBBAAAAAAAAAABBBBBAABBBBAABBABABBAAAABABAAABAAABBBBAAAABBABAABAAABAAABBABABAAABBBBABBBAABABBBAABABBBAABBBAAAABBBBBAAAAABBABABAAAABBBABABBBBBABAABBABBBAABBBBABAAABAAAABBAAAABBAAABBBBABABAABABAABABBBBAAABABABAAAABBABBBAAABAAAABABAABBBBABBB...

output:

327999999999999985

result:

ok 1 number(s): "327999999999999985"

Test #95:

score: 0
Accepted
time: 72ms
memory: 2452kb

input:

1000000000000000 1000000000000000
BBAAABABBBBAAABAABABAABBBBAAABBBBBBABAABBBAAAABABBABBBBBABABABAABAAABBABAABABBABBBBAABABBBAAABBBABAAABBAABBBAAABBAABAAABAAAAABBAAABBBAABABABAAAABAAABBBAAAABAABBBBABABBBBAABAAAAAABAAABAABBBBBAAAAABBBABBBBAABBAABBABAAAAAABAAAABBABBABABBBBAAABAABAAABAABBABBABAAAAAAABBA...

output:

412999999999999947

result:

ok 1 number(s): "412999999999999947"

Test #96:

score: 0
Accepted
time: 60ms
memory: 2480kb

input:

1000000000000000 500000000000000
ZCEBSQUYCAEUUFIBYVGDYGLWBPIXKDOHEMMAHZT
AVQFKPHDPALXLEJDRGBYJMHBDBHZFNINCUHSLNOAYNLHAKUNYGRLNVSZQAQTVZNNAJVRXFFSZCTORPZDEZHMHDUCUBLQBOLMGHDKNLOUOZPSPTFKFBHFUPKDOKGNXYURZNSFJSSSHZDSPMHDDABSDVTWXMUOHPIZPUFQEAPSYZQFLCLTBAVRFWDELMVTOAFWTHWXFUZHYRIFLOGVZZCMCWDVFTPYRCMFWXR...

output:

26999999999999998

result:

ok 1 number(s): "26999999999999998"

Test #97:

score: 0
Accepted
time: 41ms
memory: 2516kb

input:

1000000000000000 999999999999264
WHFMTXRNOCDNTEWPXDTKLJKMIXBWVBNNLBTUIZJSVGKFCOGKAXKKHZJWIBKUOMLBQCESQPUINPLYRWJSFMMTRPRIQVKZONNTQFTHVWGMJIFJFAVKVSMQQDOBNPARJSNARUFJNYRMZGGOMOGNRYKZLAWUCIJZNRVUAZJMCJJXQGSZFLEJMYRSMJMXJPYXYZDIEBSAELECTEJKUDNZGAXFHEEFCIQPNIBPHNZLBJZAGBKLDADLHDDDYNBKIHBSXGVVEKFKKMAQNOR...

output:

101999999999952893

result:

ok 1 number(s): "101999999999952893"

Test #98:

score: 0
Accepted
time: 72ms
memory: 2556kb

input:

1000000000000000 999999999999264
ILBEINJQFQFTPJPGCXHXJWJELSLGOXRKQTXRKIXPOWTEPRABUFAZSISXWTGGGMSPHKIAUBYGXAJIWUOWFICPKEAAHQQCUVRXFKTUUXIWEURVFNDWVKYOCANVTWFCMZCOZCIAWTJMEEZIYTBJMGTAHJWRJTCFDWPCNGHDJECMTWYTCUPCTGZFTBORCDPBNGXSOQSADGUBLKPOPKQIDMIZPPDVAZFWVJBOFOLCRKBYZGGVLGEAUNPNQYPYIQMFDLVFZWESPGORMXN...

output:

160999999999935225

result:

ok 1 number(s): "160999999999935225"

Test #99:

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

input:

1000000000000000 1000000000000000
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

0

result:

ok 1 number(s): "0"

Test #100:

score: 0
Accepted
time: 40ms
memory: 2548kb

input:

1000000000000000 1000000000000000
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ...

output:

500000000000000000

result:

ok 1 number(s): "500000000000000000"