// ---------- begin ModInt ----------
mod modint {

    #[allow(dead_code)]
    pub struct Mod;
    impl Modulo for Mod {
        fn modulo() -> u32 {
            1_000_000_007
        }
        fn rem() -> u32 {
            2226617417
        }
        fn ini() -> u64 {
            582344008
        }
    }

    use std::marker::*;
    use std::ops::*;

    pub trait Modulo {
        fn modulo() -> u32;
        fn rem() -> u32;
        fn ini() -> u64;
    }

    pub struct ModInt<T>(pub u32, PhantomData<T>);

    impl<T: Modulo> Clone for ModInt<T> {
        fn clone(&self) -> Self {
            Self::new_unchecked(self.0)
        }
    }

    impl<T: Modulo> Copy for ModInt<T> {}

    impl<T: Modulo> Add for ModInt<T> {
        type Output = ModInt<T>;
        fn add(self, rhs: Self) -> Self::Output {
            let mut d = self.0 + rhs.0;
            if d >= T::modulo() {
                d -= T::modulo();
            }
            Self::new_unchecked(d)
        }
    }

    impl<T: Modulo> AddAssign for ModInt<T> {
        fn add_assign(&mut self, rhs: Self) {
            *self = *self + rhs;
        }
    }

    impl<T: Modulo> Sub for ModInt<T> {
        type Output = ModInt<T>;
        fn sub(self, rhs: Self) -> Self::Output {
            let mut d = T::modulo() + self.0 - rhs.0;
            if d >= T::modulo() {
                d -= T::modulo();
            }
            ModInt::new_unchecked(d)
        }
    }

    impl<T: Modulo> SubAssign for ModInt<T> {
        fn sub_assign(&mut self, rhs: Self) {
            *self = *self - rhs;
        }
    }

    impl<T: Modulo> Mul for ModInt<T> {
        type Output = ModInt<T>;
        fn mul(self, rhs: Self) -> Self::Output {
            ModInt::new_unchecked(Self::reduce(self.0 as u64 * rhs.0 as u64))
        }
    }

    impl<T: Modulo> MulAssign for ModInt<T> {
        fn mul_assign(&mut self, rhs: Self) {
            *self = *self * rhs;
        }
    }

    impl<T: Modulo> Neg for ModInt<T> {
        type Output = ModInt<T>;
        fn neg(self) -> Self::Output {
            if self.0 == 0 {
                Self::zero()
            } else {
                Self::new_unchecked(T::modulo() - self.0)
            }
        }
    }

    impl<T> std::fmt::Display for ModInt<T> {
        fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
            write!(f, "{}", self.0)
        }
    }

    impl<T: Modulo> std::str::FromStr for ModInt<T> {
        type Err = std::num::ParseIntError;
        fn from_str(s: &str) -> Result<Self, Self::Err> {
            let val = s.parse::<u32>()?;
            Ok(ModInt::new(val))
        }
    }

    impl<T: Modulo> From<usize> for ModInt<T> {
        fn from(val: usize) -> ModInt<T> {
            ModInt::new_unchecked((val % T::modulo() as usize) as u32)
        }
    }

    impl<T: Modulo> From<u64> for ModInt<T> {
        fn from(val: u64) -> ModInt<T> {
            ModInt::new_unchecked((val % T::modulo() as u64) as u32)
        }
    }

    impl<T: Modulo> From<i64> for ModInt<T> {
        fn from(val: i64) -> ModInt<T> {
            let m = T::modulo() as i64;
            ModInt::new((val % m + m) as u32)
        }
    }

    #[allow(dead_code)]
    impl<T: Modulo> ModInt<T> {
        fn reduce(x: u64) -> u32 {
            let b = (x as u32 * T::rem()) as u64;
            let t = x + b * T::modulo() as u64;
            let mut c = (t >> 32) as u32;
            if c >= T::modulo() {
                c -= T::modulo();
            }
            c as u32
        }
        fn new_unchecked(d: u32) -> Self {
            Self(d, PhantomData)
        }
        pub fn is_zero(&self) -> bool {
            self.0 == 0
        }
        pub fn new(d: u32) -> Self {
            Self::new_unchecked(Self::reduce(d as u64 * T::ini()))
        }
        pub fn zero() -> Self {
            Self::new(0)
        }
        pub fn one() -> Self {
            Self::new(1)
        }
        pub fn get(&self) -> u32 {
            Self::reduce(self.0 as u64)
        }
        /*
        pub fn pow(&self, mut n: u64) -> Self {
            let mut t = Self::one();
            let mut s = *self;
            while n > 0 {
                if n & 1 == 1 {
                    t *= s;
                }
                s *= s;
                n >>= 1;
            }
            t
        }
        pub fn inv(&self) -> Self {
            assert!(self.0 != 0);
            self.pow(T::modulo() as u64 - 2)
        }
        */
    }

    #[allow(dead_code)]
    pub fn mod_pow(r: u64, mut n: u64, m: u64) -> u64 {
        let mut t = 1 % m;
        let mut s = r % m;
        while n > 0 {
            if n & 1 == 1 {
                t = t * s % m;
            }
            s = s * s % m;
            n >>= 1;
        }
        t
    }
}
// ---------- end ModInt ----------
// ---------- begin Matrix ----------
mod matrix {
    use std::ops::*;
    pub trait SemiRing: Add<Output = Self> + Mul<Output = Self> + Copy {
        fn zero() -> Self;
        fn one() -> Self;
    }
    #[derive(Clone)]
    pub struct SquareMatrix<R> {
        size: usize,
        buf: Box<[R]>,
    }
    #[allow(dead_code)]
    impl<R: SemiRing> SquareMatrix<R> {
        pub fn zero(size: usize) -> Self {
            SquareMatrix {
                size: size,
                buf: vec![R::zero(); size * size].into_boxed_slice(),
            }
        }
        pub fn identity(size: usize) -> Self {
            let mut e = Self::zero(size);
            for i in 0..size {
                e.buf[i * size + i] = R::one();
            }
            e
        }
        pub fn get(&self, x: usize, y: usize) -> &R {
            assert!(x < self.size && y < self.size);
            &self.buf[x * self.size + y]
        }
        pub fn get_mut(&mut self, x: usize, y: usize) -> &mut R {
            assert!(x < self.size && y < self.size);
            &mut self.buf[x * self.size + y]
        }
        pub fn matadd(&self, rhs: &Self) -> Self {
            assert!(self.size == rhs.size);
            let buf: Vec<R> = self
                .buf
                .iter()
                .zip(rhs.buf.iter())
                .map(|p| *p.0 + *p.1)
                .collect();
            SquareMatrix {
                size: self.size,
                buf: buf.into_boxed_slice(),
            }
        }
        pub fn matmul(&self, rhs: &Self) -> Self {
            let size = self.size;
            assert!(size == rhs.size);
            let mut res = Self::zero(size);
            for (x, a) in res.buf.chunks_mut(size).zip(self.buf.chunks(size)) {
                for (a, b) in a.iter().zip(rhs.buf.chunks(size)) {
                    for (x, b) in x.iter_mut().zip(b.iter()) {
                        *x = *x + *a * *b;
                    }
                }
            }
            res
        }
        pub fn mat_pow(&self, mut n: usize) -> Self {
            let size = self.size;
            let mut t = Self::identity(size);
            let mut s = self.clone();
            while n > 0 {
                if n & 1 == 1 {
                    t = t.matmul(&s);
                }
                s = s.matmul(&s);
                n >>= 1;
            }
            t
        }
    }
    #[allow(dead_code)]
    impl<R: SemiRing + Sub<Output = R>> SquareMatrix<R> {
        pub fn matsub(&self, rhs: &Self) -> Self {
            assert!(self.size == rhs.size);
            let buf: Vec<R> = self
                .buf
                .iter()
                .zip(rhs.buf.iter())
                .map(|p| *p.0 - *p.1)
                .collect();
            SquareMatrix {
                size: self.size,
                buf: buf.into_boxed_slice(),
            }
        }
    }
}
// ---------- end Matrix ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use modint::*;
type M = ModInt<Mod>;

use matrix::*;
type Mat = SquareMatrix<M>;

impl SemiRing for M {
    fn zero() -> Self {
        M::zero()
    }
    fn one() -> Self {
        M::one()
    }
}

fn run() {
    input! {
        w: [usize; 7],
    }
    // 0: 置いてok
    // 1: おいたらダメ
    let mut mat = vec![];
    for i in 1..=7 {
        let mut m = Mat::zero(1 << i);
        for j in 0..(1 << i) {
            for k in 0..(1 << (2 * i - 1)) {
                if j & k > 0 {
                    continue;
                }
                let mut next = 0;
                for x in 0..i {
                    let left = x == 0 || (k >> (i + x - 1)) & 1 == 1;
                    let down = k >> x & 1 == 1;
                    let right = x == i - 1 || (k >> (i + x)) & 1 == 1;
                    if left && down && right {
                        next |= 1 << x;
                    }
                }
                *m.get_mut(next, j) += M::one();
            }
        }
        mat.push(m);
        let mut m = Mat::zero(1 << i);
        for j in 0..(1 << i) {
            *m.get_mut(j, j) = M::one();
        }
        mat.push(m);
    }
    let mul = |m: &Mat, b: &[M]| -> Vec<M> {
        let mut res = vec![M::zero(); b.len()];
        for i in 0..b.len() {
            for j in 0..b.len() {
                res[i] += *m.get(i, j) * b[j];
            }
        }
        res
    };
    let mut b = vec![M::zero(); 1 << 7];
    let mut ini = false;
    let mut w = w;
    for (i, (w, mat)) in w.iter_mut().zip(mat.chunks(2)).enumerate().rev() {
        if !ini && *w > 0 {
            *w -= 1;
            ini = true;
            let i = i + 1;
            for k in 0..(1 << (i - 1)) {
                let mut bit = 0;
                for x in 0..i {
                    let left = x == 0 || k >> (x - 1) & 1 == 1;
                    let down = true;
                    let right = x == i - 1 || k >> x & 1 == 1;
                    if left && right && down {
                        bit |= 1 << x;
                    }
                }
                b[bit] += M::one();
            }
        }
        b = mul(&mat[1], &b);
        b = mul(&mat[0].mat_pow(*w), &b);
        b.truncate(1 << i);
    }
    let ans = b[0].get();
    println!("{}", ans);
}

fn main() {
    run();
}


//---------- begin SegmentTree Point update Range query ----------
pub trait PURQ {
    type T: Clone;
    fn fold(l: &Self::T, r: &Self::T) -> Self::T;
    fn e() -> Self::T;
}

struct SegmentTreePURQ<R: PURQ> {
    seg: Vec<R::T>,
    size: usize,
}

#[allow(dead_code)]
impl<R: PURQ> SegmentTreePURQ<R> {
    fn new(n: usize) -> SegmentTreePURQ<R> {
        let size = n.next_power_of_two();
        SegmentTreePURQ {
            seg: vec![R::e(); 2 * size],
            size: size,
        }
    }
    fn build_by(a: &[R::T]) -> SegmentTreePURQ<R> {
        let size = a.len().next_power_of_two();
        let mut b = vec![R::e(); 2 * size];
        for i in 0..a.len() {
            b[i + size] = a[i].clone();
        }
        let mut seg = SegmentTreePURQ { seg: b, size: size };
        seg.update_all();
        seg
    }
    fn update(&mut self, x: usize, v: R::T) {
        assert!(x < self.size);
        let mut x = x + self.size;
        let a = &mut self.seg;
        a[x] = v;
        x >>= 1;
        while x > 0 {
            a[x] = R::fold(&a[2 * x], &a[2 * x + 1]);
            x >>= 1;
        }
    }
    fn update_tmp(&mut self, x: usize, v: R::T) {
        self.seg[self.size + x] = v;
    }
    fn update_all(&mut self) {
        let a = &mut self.seg;
        for i in (1..self.size).rev() {
            a[i] = R::fold(&a[2 * i], &a[2 * i + 1]);
        }
    }
    fn find(&self, l: usize, r: usize) -> R::T {
        assert!(l <= r && r <= self.size);
        let mut x = R::e();
        let mut y = R::e();
        let mut l = l + self.size;
        let mut r = r + self.size;
        let a = &self.seg;
        while l < r {
            if l & 1 == 1 {
                x = R::fold(&x, &a[l]);
                l += 1;
            }
            if r & 1 == 1 {
                r -= 1;
                y = R::fold(&a[r], &y);
            }
            l >>= 1;
            r >>= 1;
        }
        R::fold(&x, &y)
    }
}
//---------- end SegmentTree Point update Range query ----------
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

// C -> AB -> AAC -> AAAB -> B
// C -> B としていい
//
// A -> BB
// B -> AB
// AAA -> empty
//
// 右端のAのmod 3?
// 両方操作可能ならそうかも知れんが片方だけしか動かせない
//
// B -> AB -> AAB -> AAAB -> B
// 操作可能な方は操作続けることで
// B...BA..A みたいにできる
// Bの数がT以下かつmod2で等しいかつ右端のAの数が一致
// いや右端のAを操作してBにすること考えると？
// 差分/2の分だけBに変換する余裕あり
// AAA -> empty もある
//
// WA
//
// Bがない場合とか
//
// WA
//
//
//

struct R;
impl PURQ for R {
    // B...BA...A
    // でBの数、Aの数
    type T = (usize, usize);
    fn fold(l: &Self::T, r: &Self::T) -> Self::T {
        if r.0 == 0 {
            (l.0, l.1 + r.1)
        } else {
            (l.0 + r.0, r.1)
        }
    }
    fn e() -> Self::T {
        (0, 0)
    }
}

fn run() {
    input! {
        s: bytes,
        t: bytes,
        q: usize,
        ask: [(usize1, usize, usize1, usize); q],
    }
    let mut seg_s = SegmentTreePURQ::<R>::new(s.len());
    for (i, s) in s.iter().enumerate() {
        if *s == b'A' {
            seg_s.update_tmp(i, (0, 1));
        } else {
            seg_s.update_tmp(i, (1, 0));
        }
    }
    seg_s.update_all();
    let mut seg_t = SegmentTreePURQ::<R>::new(t.len());
    for (i, s) in t.iter().enumerate() {
        if *s == b'A' {
            seg_t.update_tmp(i, (0, 1));
        } else {
            seg_t.update_tmp(i, (1, 0));
        }
    }
    seg_t.update_all();
    let mut out = String::new();
    for (a, b, c, d) in ask {
        let ans = || -> bool {
            let (x, y) = seg_s.find(a, b);
            let (z, w) = seg_t.find(c, d);
            let mut ans = false;
            if x == 0 {
                if z > 0 {
                    ans |= y > w && z % 2 == 0;
                } else {
                    ans |= y >= w && (y - w) % 3 == 0;
                }
                return ans;
            }
            if z >= x && (z - x) % 2 == 0 && y >= w {
                let d = (z - x) / 2;
                let mut ok = false;
                ok |= (y - w) % 3 == 0;
                ok |= d > 0 && y > w;
                ans |= ok;
            }
            ans
        }();
        if ans {
            out.push('1');
        } else {
            out.push('0');
        }
    }
    println!("{}", out);
}

fn main() {
    run();
}


use std::io::{self, Read};
use std::collections::HashMap;

struct Node {
    white: bool,
    black: bool,
    left: bool,
    right: bool,
    count: u32,
}

fn update_tree(tree: &mut Vec<Node>, index: usize, l: usize, r: usize, left: usize, right: usize) {
    let mid :usize = (l + r) / 2;
    if tree[index].black && !tree[index].white {
        return;
    }
    if l == left && r == right {
        tree[index].black = true;
        tree[index].white = false;
        tree[index].left = true;
        tree[index].right = true;
        tree[index].count = 1;
        return;
    } else if mid >= right {
        update_tree(tree, index * 2 + 1, l, mid, left, right);
    } else if mid + 1 <= left {
        update_tree(tree, index * 2 + 2, mid + 1, r, left, right);
    } else {
        update_tree(tree, index * 2 + 1, l, mid, left, mid);
        update_tree(tree, index * 2 + 2, mid + 1, r, mid + 1, right);
    }
    tree[index].white = tree[index * 2 + 1].white & tree[index * 2 + 2].white;
    tree[index].black = tree[index * 2 + 1].black & tree[index * 2 + 2].black;
    tree[index].left = tree[index * 2 + 1].left;
    tree[index].right = tree[index * 2 + 2].right;
    if tree[index * 2 + 1].right && tree[index * 2 + 2].left {
        tree[index].count = tree[index * 2 + 1].count + tree[index * 2 + 2].count - 1;
    } else {
        tree[index].count = tree[index * 2 + 1].count + tree[index * 2 + 2].count;
    }
    return;
}

fn main() {
    let stdin = io::stdin();
    let mut handle = stdin.lock();
    let mut buf :String = String::new();

    match handle.read_to_string(&mut buf) {
        Ok(_v) => (),
        Err(e) => panic!("{}", e),
    }
    let lines: Vec<&str> = buf.split("\r\n").collect();

    let n :usize = lines[0].parse().unwrap();

    let mut points = HashMap::new();
    let mut query: Vec<(u32,u32)> = Vec::new();

    for i in 1..(n+1) {
        let pair: Vec<&str> = lines[i].split(" ").collect();
        let l :u32 = pair[0].parse().unwrap();
        let r :u32 = pair[1].parse().unwrap();
        points.insert(l, 0);
        points.insert(r, 0);
        query.push((l,r));
    }
    let mut v :Vec<u32> = Vec::new();
    for (point, _v) in points.iter() {
        v.push(*point);
    }
    v.sort();
    for i in 0..v.len() {
        points.insert(v[i], i);
    }
    let mut tree: Vec<Node> = Vec::new();
    for _i in 0..(4*v.len()) {
        tree.push(Node {count: 0, black: false, white: true, left: false, right: false});
    }
    for i in 0..n {
        let l :usize = *points.get(&query[i].0).unwrap();
        let r :usize = *points.get(&query[i].1).unwrap();
        update_tree(&mut tree, 0, 0, v.len() - 2, l, r - 1);
        print!("{} ", tree[0].count);
    }
}


struct Scan {
    buffer: std::collections::VecDeque<String>
}

impl Scan {
    fn new() -> Scan {
        Scan { buffer: std::collections::VecDeque::new() }
    }

    fn next<T: std::str::FromStr>(&mut self)-> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).expect("Fail to read");
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }

}

fn _main() {
    let mut scan = Scan::new();
    let n: usize = scan.next();
    let a: usize = scan.next();
    let b: usize = scan.next();
    println!("{}", (b+1).min(n-a));
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();
}


use std::io;
use std::str;

pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buffer: vec![],
        }
    }

    pub fn token<T: 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.reader.read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn modpow(base: u64, expo: u64, modulo: u64) -> u64 {
    let mut ans = 1;
    let mut base = base;
    let mut expo = expo;
    while expo > 0 {
        if expo % 2 != 0 {
            ans = (ans * base) % modulo;
        }
        base = (base * base) % modulo;
        expo /= 2;
    }
    ans
}

fn is_primitive(x: u64, p: u64) -> bool {
    for i in 1..p - 1 {
        if modpow(x, i, p) == 1 {
            return false;
        }
    }
    modpow(x, p - 1, p) == 1
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let p: u64 = scan.token();
    let mut ans = 0;
    for x in 1..p {
        if is_primitive(x, p) {
            ans += 1;
        }
    }
    writeln!(out, "{}", ans).ok();
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}


#![allow(unused_imports)]
use std::cmp::Ordering::*;
use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};
use std::collections::{BTreeSet, BTreeMap};

// I have no idea what I'm doing

macro_rules! answer {
    ($out:ident, $ans:expr) => {
        writeln!($out, "{}", $ans)
    };
}

const M: i64 = 1_000_000_007;

fn fexp(mut x: i64, mut e: i64) -> i64 {
    let mut ans = 1;
    while e > 0 {
        if e & 1 != 0 {
            ans = (ans * x) % M;
        }

        x = (x * x) % M;
        e >>= 1;
    }
    ans
}

struct DSU {
    p: Vec<usize>,
    s: Vec<usize>,
}

impl DSU {
    fn new(n: usize) -> Self {
        Self {
            p: (0..n).collect(),
            s: vec![1; n],
        }
    }

    fn find(&mut self, i: usize) -> usize {
        if self.p[i] != i {
            self.p[i] = self.find(self.p[i]);
        }
        self.p[i]
    }

    fn union(&mut self, mut i: usize, mut j: usize) -> usize {
        i = self.find(i);
        j = self.find(j);
        if i == j { return i; }
        let (i, j) = if self.s[i] < self.s[j] { (i, j) } else { (j, i) };
        self.p[i] = j;
        self.s[j] += self.s[i];
        j
    }

    fn classes(&mut self) -> impl Iterator<Item=usize> {
        let n = self.p.len();
        (0..n).map(|x| self.find(x)).collect::<BTreeSet<_>>().into_iter()
    }
}

fn main() -> Result<(), io::Error> {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let p: usize = scan.token();
    let k: i64 = scan.token();

    match k {
        0 => { return answer!(out, fexp(p as i64, p as i64 - 1)); }
        1 => { return answer!(out, fexp(p as i64, p as i64)); }
        _ => {}
    }

    let mut dsu = DSU::new(p);

    for x in 1..p {
        let y = k * x as i64 % p as i64;
        dsu.union(x, y as usize);
    }

    answer!(out, fexp(p as i64, (dsu.classes().count() - 1) as i64))
}

///////////////////////////////////////////////////////////////////////////////////////////////////

/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}


#![allow(unused_imports)]
use std::cmp::Ordering::*;
use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};
use std::collections::{BTreeSet, BTreeMap};

// I have no idea what I'm doing

macro_rules! answer {
    ($out:ident, $ans:expr) => {
        writeln!($out, "{}", $ans)
    };
}

const M: i64 = 1_000_000_007;

fn fexp(mut x: i64, mut e: i64) -> i64 {
    let mut ans = 1;
    while e > 0 {
        if e & 1 != 0 {
            ans = (ans * x) % M;
        }

        x = (x * x) % M;
        e >>= 1;
    }
    ans
}

struct DSU {
    p: Vec<usize>,
    s: Vec<usize>,
}

impl DSU {
    fn new(n: usize) -> Self {
        Self {
            p: (0..n).collect(),
            s: vec![1; n],
        }
    }

    fn find(&mut self, i: usize) -> usize {
        if self.p[i] != i {
            self.p[i] = self.find(self.p[i]);
        }
        self.p[i]
    }

    fn union(&mut self, mut i: usize, mut j: usize) -> usize {
        i = self.find(i);
        j = self.find(j);
        if i == j { return i; }
        let (i, j) = if self.s[i] < self.s[j] { (i, j) } else { (j, i) };
        self.p[i] = j;
        self.s[j] += self.s[i];
        j
    }

    fn classes(&self) -> impl Iterator<Item=&'_ usize> {
        self.p.iter().collect::<BTreeSet<_>>().into_iter()
    }
}

fn main() -> Result<(), io::Error> {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let p: usize = scan.token();
    let k: i64 = scan.token();

    match k {
        0 => { return answer!(out, fexp(p as i64, p as i64 - 1)); }
        1 => { return answer!(out, fexp(p as i64, p as i64)); }
        _ => {}
    }

    let mut dsu = DSU::new(p);

    for x in 1..p {
        // This makes zero sense to me
        // y is in the range [1, p), so why the fuck is it not sufficient to union(x, x * k mod p) for every x in [1, p)????
        // This is so confusing
        let mut y = x as i64;
        for _ in 1..30 {
            y *= k;
            y %= p as i64;
            dsu.union(x, y as usize);
        }
    }

    answer!(out, fexp(p as i64, (dsu.classes().count() - 1) as i64))
}

///////////////////////////////////////////////////////////////////////////////////////////////////

/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

fn gcd(mut a: i64, mut b: i64) -> i64 {
    while a != 0 {
        b %= a;
        std::mem::swap(&mut a, &mut b);
    }
    b
}

fn solve() {
    let s: Vec<_> = parse_line!(String).bytes().collect();
    let k = parse_line!(usize);
    let mut ans = k - k % 2;
    for i in 0..s.len() {
        for j in (i + 2..=s.len() + k).step_by(2) {
            let mut ok = true;
            let n = (j - i) / 2;
            for k in i..i + n {
                if k + n >= s.len() {
                    break;
                }
                if s[k] != s[k + n] {
                    ok = false;
                    break;
                }
            }
            if ok {
                ans = std::cmp::max(ans, j - i);
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    let tests = 1; // parse_line!(usize);
    for _ in 0..tests {
        solve();
    }
}


use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;

fn exec() {
    let mut sc = Scanner::new();
    let s: Vec<u8> = sc.ne::<String>().into_bytes();
    let mut ok = true;
    let mut next = b'a';
    for &c in &s {
        if c == next {
            next += 1;
        } else if c > next {
            ok = false;
        }
    }
    println!("{}", if ok { "YES" } else { "NO" });
}

fn main() {
    const DEFAULT_STACK: usize = 16 * 1024 * 1024;
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => return None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => panic!("parse error"),
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


#[allow(dead_code)]
fn scan<T: std::str::FromStr>() -> T
{
	static mut BUFFER: Vec<String> = vec![];
	loop {
		if let Some(token) = unsafe { BUFFER.pop() } {
			return token.parse().ok().unwrap();
		}
		let mut input = String::new();
		std::io::stdin().read_line(&mut input).ok();
		unsafe { BUFFER = input.split_whitespace().rev().map(String::from).collect(); }
	}
}

struct Comb {
	modu: i64,
	fact: Vec<i64>,
	ifact: Vec<i64>,
}

impl Comb {
	fn mpow(&self, mut x: i64, mut y: i64) -> i64
	{
		let mut ans = 1;
		while y > 0 {
			if y&1 == 1 {
				ans = ans*x % self.modu;
			}
			x = x*x % self.modu;
			y >>= 1;
		}
		ans
	}

	fn inv(&self, x: i64) -> i64 { self.mpow(x, self.modu-2) }

	fn new(modu: i64, size: usize) -> Self
	{
		assert!(size > 1);
		let mut tmp = Self { modu, fact: vec![0; size], ifact: vec![0; size] };
		tmp.fact[0] = 1;
		for i in 1..size {
			tmp.fact[i] = tmp.fact[i-1] * i as i64 % modu;
		}
		tmp.ifact[size-1] = tmp.inv(tmp.fact[size-1]);
		for i in (1..size).rev() {
			tmp.ifact[i-1] = tmp.ifact[i] * i as i64 % modu;
		}
		tmp
	}

	fn C(&self, n: i64, r: i64) -> i64
	{
		if 0 <= r && r <= n {
			self.fact[n as usize] * self.ifact[r as usize] % self.modu * self.ifact[(n-r) as usize] % self.modu
		} else {
			0
		}
	}

}

fn main()
{
	let n = scan::<i64>();
	let modu = scan::<i64>();
	let cb = Comb::new(modu, n as usize + 10);

	let mut ans = 0i64;
	for a in 0..=n {
		let b = n-a;
        let kooft_step = cb.inv(b) * (n-1) % modu;
        let mut kooft = cb.mpow(b, a);
		let mut s = 0i64;
		for c in 0..=std::cmp::min(a, b) {
			s += cb.C(b-1, c-1) * cb.C(a, c) % modu * kooft % modu;
            kooft = kooft * kooft_step % modu;
		}
		s %= modu;
		ans += s * cb.C(n, a) % modu * cb.fact[b as usize] % modu;
	}
	ans %= modu;
	println!("{}", ans);
}


#[allow(unused_imports)]
use std::cmp::{max,min};

type GenError = Box<dyn std::error::Error>;
type GenResult<T> = Result<T, GenError>;

struct Reader {

}

impl Reader{
    #[allow(unused)]
    fn read_string() -> GenResult<String> {
        let mut string: String = String::new();
        std::io::stdin().read_line(&mut string)?;
        Ok(string.trim().to_string())
    }

    #[allow(unused)]
    fn read_tokens() -> GenResult<Vec::<String>> {
        let mut string: String = String::new();
        std::io::stdin().read_line(&mut string)?;
        let mut v = Vec::new();
        for value in string.split_whitespace() {
            v.push(value.to_string());
        }
        Ok(v)
    }
}

fn main() {

    let tokens = Reader::read_tokens().unwrap();
    let n: i32 = tokens[0].parse().unwrap();
    let m: i32 = tokens[1].parse().unwrap();
    let k: i32 = tokens[2].parse().unwrap();

    let mut ans = 1000000;
    let mut index = 1;
    for value in Reader::read_tokens().unwrap() {
        let value : i32 = value.parse().unwrap();
        if value > 0 && value <= k {
            if 10 * (index - m).abs() < ans {
                ans = 10 * (index - m).abs();
            }
        }
        index += 1;
    }
    println!("{}", ans);
}


use std::io::*;
use std::cmp::*;

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).ok().unwrap();
    let mut cin = buf.split_whitespace().map(|s| s.parse::<i64>().ok().unwrap());

    let l1 = cin.next().unwrap();
    let r1 = cin.next().unwrap();
    let l2 = cin.next().unwrap();
    let r2 = cin.next().unwrap();
    let k = cin.next().unwrap();

    let r = min(r1, r2);
    let l = max(l1, l2);

    println!("{}", max(0, r - l + 1 - if l <= k && k <= r { 1 } else { 0 } ));
}


use std::cmp::*;

const INF: i64 = 2000000000;
fn main() {
    let (n, m, k) = {
        let r = getvec::<i64>();
        (r[0], r[1], r[2])
    };
    let num = m - n;
    let l_n = k;
    let r_n = n - k + 1;
    let mut lb = 0i64;
    let mut ub = INF;
    while ub - lb > 1i64 {
        let mid = (ub + lb) / 2;
        let r = calc(max(1i64, mid - r_n + 1), mid);
        let l = calc(max(1i64, mid - l_n + 1), mid);
        let res = r + l - mid;
        if res <= num {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    println!("{}", lb + 1);
}

fn calc(l: i64, r: i64) -> i64 {
    let n = r - l + 1;
    let res = n * (l + r);
    res / 2
}

#[allow(dead_code)]
fn next_line() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input
}

#[allow(dead_code)]
fn getnum<T: std::str::FromStr>() -> T {
    let res = next_line();
    res.trim().parse::<T>().ok().unwrap()
}

#[allow(dead_code)]
fn getvec<T: std::str::FromStr>() -> Vec<T> {
    let res = next_line();
    res.split_whitespace().map(|x| x.parse::<T>().ok().unwrap()).collect()
}


// Try Codeforces
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        () => (get().parse::<i64>().unwrap());
        ($t:ty) => (get().parse::<$t>().unwrap());
    }

    let x = get!();
    let y = get!();

    if y == 0 || (y == 1 && x > 0) || x < y - 1 {
        println!("No");
        return;
    }

    let d = x - (y - 1);

    if d % 2 != 0 {
        println!("No");
        return;
    }

    println!("Yes");

}


// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;

// 下の桁からdpっぽく?
// +がいくつ、-がいくつ、暫定carryがいくつ
// この時1を幾つで合わせられるか的な
// MLE
// なんか状態多いっぽいが
//
//

const INF: i32 = 100000;

fn run() {
    input!(s: bytes);
    let m = 300;
    let geta = m / 9 + 1;
    let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
    dp[geta] = vec![vec![0; m + 1]; m + 1];
    for &s in s.iter().rev() {
        let s = (s - b'0') as i32;
        let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
        for (carry, dp) in dp.iter().enumerate() {
            for (add, dp) in dp.iter().enumerate() {
                for (sub, dp) in dp.iter().enumerate() {
                    if *dp == INF {
                        continue;
                    }
                    let carry = carry as i32 - geta as i32;
                    let d = add as i32 - sub as i32 + carry;
                    if d.rem_euclid(10) != s {
                        continue;
                    }
                    let carry = (d.div_euclid(10) + geta as i32) as usize;
                    next[carry][add][sub].chmin(*dp + (add + sub) as i32);
                }
            }
        }
        dp = next;
        for dp in dp.iter_mut() {
            for i in (0..m).rev() {
                for j in (0..m).rev() {
                    dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);
                }
            }
        }
    }
    let mut ans = INF;
    for (carry, dp) in dp.iter().enumerate() {
        for (add, dp) in dp.iter().enumerate() {
            for (sub, dp) in dp.iter().enumerate() {
                let carry = carry as i32 - geta as i32;
                let add = add as i32;
                let sub = sub as i32;
                let mut v = *dp;
                if carry == 0 {
                } else if carry > 0 && sub >= carry {
                    v += carry;
                } else if carry < 0 && add >= -carry {
                    v += -carry;
                } else {
                    v += INF;
                }
                ans.chmin(v);
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const LINF: i64 = 1 << 58;

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    input!{
        n: usize,
        a: [[i32; n]; n],
    }
    let ni = n as i32;
    let mut pos = vec![0; n * n];
    for i in 0 .. n {
        for j in 0 .. n {
            pos[a[i][j] as usize - 1] = i * n + j;
        }
    }
    let mut kn = vec![vec![LINF >> 32; n * n]; n * n];
    let mut rk = vec![vec![LINF >> 32; n * n]; n * n];
    let mut bs = vec![vec![LINF >> 32; n * n]; n * n];
    for i in 0 .. n {
        for j in 0 .. n {
            for &(dx, dy)
                in &[(-2, -1), (-2, 1), (2, -1), (2, 1),
                     (1, 2), (-1, 2), (1, -2), (-1, -2)] {
                    let nx = i as i32 + dx;
                    let ny = j as i32 + dy;
                    if nx < 0 || nx >= ni || ny < 0 || ny >= ni { continue; }
                    let v = (nx * ni + ny) as usize;
                    kn[i * n + j][v] = 1;
                }
            for dx in -ni .. ni {
                let dy = dx;
                let nx = i as i32 + dx;
                let ny = j as i32 + dy;
                if nx < 0 || nx >= ni || ny < 0 || ny >= ni { continue; }
                let v = (nx * ni + ny) as usize;
                bs[i * n + j][v] = 1;
            }
            for dx in -ni .. ni {
                let dy = -dx;
                let nx = i as i32 + dx;
                let ny = j as i32 + dy;
                if nx < 0 || nx >= ni || ny < 0 || ny >= ni { continue; }
                let v = (nx * ni + ny) as usize;
                bs[i * n + j][v] = 1;
            }
            for u in 0 .. n {
                rk[i * n + j][u * n + j] = 1;
                rk[i * n + j][i * n + u] = 1;
            }
            kn[i * n + j][i * n + j] = 0;
            rk[i * n + j][i * n + j] = 0;
            bs[i * n + j][i * n + j] = 0;
        }
    }
    let mut dist = vec![vec![LINF; 3 * n * n]; 3 * n * n];
    for i in 0 .. n * n {
        for j in 0 .. n * n {
            dist[i][j] = kn[i][j] << 32;
            dist[n * n + i][n * n + j] = rk[i][j] << 32;
            dist[2 * n * n + i][2 * n * n + j] = bs[i][j] << 32;
        }
        for j in 0 .. 3 {
            for k in 0 .. 3 {
                if j != k {
                    dist[j * n * n + i][k * n * n + i] = 1 << 32 | 1;
                }
            }
        }
    }
    for k in 0 .. 3 * n * n {
        for i in 0 .. 3 * n * n {
            for j in 0 .. 3 * n * n {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    // eprintln!("dist = {:?}", dist);
    let mut dp = vec![[LINF; 3]; n * n];
    dp[0] = [0; 3];
    for i in 0 .. n * n - 1 {
        let src = pos[i];
        let dst = pos[i + 1];
        for j in 0 .. 3 {
            for k in 0 .. 3 {
                let cost: i64 = dist[j * n * n + src][k * n * n + dst];
                //eprintln!("{} -> {}", j * n * n + src, k * n * n + dst);
                //eprintln!("src = {}, dst = {}, cost = {}", src, dst, cost);
                dp[i + 1][k] = min(dp[i + 1][k], cost + dp[i][j]);
            }
        }
        //eprintln!("dp[{}] = {:?}", i + 1, dp[i + 1]);
    }
    let mut mi = LINF;
    for i in 0 .. 3 { mi = min(mi, dp[n * n - 1][i]); }
    puts!("{} {}\n", mi >> 32, mi as i32);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


fn f(n: i64, i: i64) -> i64 {
    if i == 0 {
        return 0;
    }
    let bin_n = format!("{:b}", n);
    let bin_len = bin_n.len();
    let len: i64 = 2_i64.pow(bin_len as u32) - 1;
    if i == len / 2 + 1{
        return n / 2 + n % 2;
    }else if i < len / 2 + 1{
        return f(n / 2, i);
    }
    return n / 2 + n % 2 + f(n / 2, i - (len / 2 + 1));
}
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: i64 = sc.read();
    let l: i64 = sc.read();
    let r: i64 = sc.read();
    let res = f(n, r) - f(n, l - 1);
    println!("{}", res);
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

fn is_leap(y: i64) -> bool {
    y % 400 == 0 || y % 4 == 0 && y % 100 != 0
}

fn parse_date() -> i64 {
    let s = parse_line!(String);
    let mut it = s.split(':');
    let y: i64 = it.next().unwrap().parse().unwrap();
    let m: i64 = it.next().unwrap().parse().unwrap();
    let d: i64 = it.next().unwrap().parse().unwrap();
    let mut result = d;
    for i in 0..y {
        result += 365;
        if is_leap(i) {
            result += 1;
        }
    }
    let days = [31, 28 + if is_leap(y) {1} else {0}, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    for i in 0..m - 1 {
        result += days[i as usize];
    }
    return result;
}

fn solve() {
    let from = parse_date();
    let to = parse_date();
    println!("{}", (from - to).abs());
}

fn main() {
    let tests = 1; // parse_line!(usize);
    for _ in 0..tests {
        solve();
    }
}


use std::io;

macro_rules! readln {
    () => {{
        use std::io;
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

fn main() {
    let (width, height, count) = readln!(i32, i32, i32);

    let mut result = 0;
    for i in 0..count {
        let curr_width = width - 4 * i;
        let curr_height = height - 4 * i;

        result += 2 * (curr_width + curr_height - 2);
    }

    println!("{}", result);
}


#![allow(unused_imports, unused_variables, dead_code, non_snake_case, unused_macros)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;
use std::iter::FromIterator;
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}
macro_rules ! readl { ( $ t : ty ) => { { let s = getline ( ) ; s . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,+ ) => { { let s = getline ( ) ; let mut iter = s . trim ( ) . split ( ' ' ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; }
macro_rules ! readlvec { ( $ t : ty ) => { { let s = getline ( ) ; let iter = s . trim ( ) . split ( ' ' ) ; iter . map ( | x | x . parse ( ) . unwrap ( ) ) . collect ::< Vec <$ t >> ( ) } } }
macro_rules ! mvec { ( $ v : expr , $ s : expr ) => { vec ! [ $ v ; $ s ] } ; ( $ v : expr , $ s : expr , $ ( $ t : expr ) ,* ) => { vec ! [ mvec ! ( $ v , $ ( $ t ) ,* ) ; $ s ] } ; }
macro_rules ! debug { ( $ x : expr ) => { println ! ( "{}: {:?}" , stringify ! ( $ x ) , $ x ) } }
fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator,
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display,
{
    for (i, e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}
struct ContestPrinter {
    s: String,
}
impl ContestPrinter {
    fn new() -> ContestPrinter {
        ContestPrinter { s: String::new() }
    }
    fn print<T>(&mut self, x: T)
    where
        T: std::fmt::Display,
    {
        self.s.push_str(format!("{}", x).as_str());
    }
    fn println<T>(&mut self, x: T)
    where
        T: std::fmt::Display,
    {
        self.s.push_str(format!("{}\n", x).as_str());
    }
}
impl std::ops::Drop for ContestPrinter {
    fn drop(&mut self) {
        print!("{}", self.s);
    }
}
static MOD: i64 = 1e9 as i64 + 7;
fn is_max_i64(num: i64) -> bool {
    if num == i64::max_value() {
        true
    } else {
        false
    }
}

fn bfs(graph: &Vec<Vec<usize>>, start: usize) -> Vec<usize> {
    let mut visited: Vec<i32> = vec![-1; graph.len()];
    let mut prev: Vec<usize> = vec![0; graph.len()];
    prev[start] = usize::max_value();
    let mut q: VecDeque<usize> = VecDeque::new();
    visited[start] = 0;
    q.push_back(start);
    while !q.is_empty() {
        let &c_idx = q.front().unwrap();
        let c_cost = visited[c_idx];
        for n_idx in graph[c_idx].iter() {
            let c = visited[*n_idx];
            if c < 0 {
                let n_cost = c_cost + 1;
                visited[*n_idx] = n_cost;
                prev[*n_idx] = c_idx;
                q.push_back(*n_idx);
            }
        }
        q.pop_front();
    }
    prev
}

fn get_path(prev: Vec<usize>, goal: usize) -> Vec<usize> {
    let mut path = Vec::new();
    let mut c = goal;
    while c != usize::max_value() {
        path.push(c);
        c = prev[c];
    }
    path
}

fn main() {
    let mut pr = ContestPrinter::new();
    /*let (N, M, S, T) = readl!(usize, usize, usize, usize);
    let mut g: Vec<Vec<usize>> = vec![Vec::new(); N];
    for i in 0..M {
        let (a, b) = readl!(usize, usize);
        g[a-1].push(b-1);
        g[b-1].push(a-1);
    }

    let path = bfs(&g, S-1);
    let p_nodes = get_path(path, T-1);
    let p_set: HashSet<usize> = HashSet::from_iter(p_nodes.iter().cloned());
    let num = p_nodes.len();
    let mut ans = 0;
    for i in 0..N {
        ans += N - num;
        let mut cnt = 0;
        let on = p_set.contains(&i);
        for j in 0..g[i].len() {
            let idx = g[i][j];
            if on & !p_set.contains(&idx) {
                cnt += 1;
            }
        }
        ans -= cnt;
    }

    pr.println(ans);*/
    let N = readl!(usize);
    let s = readl!(String);

    let mut ans = 0;
    for i in 1..N/2+1 {
        let pr = &s[0..i];
        let co = &s[i..i+i];
        if pr == co { ans = i-1; };
    }

    pr.println(N - ans);
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let n: usize = get();
    let k = get();
    let m: i64 = get();
    let mut t: Vec<i64> = (0 .. k).map(|_| get()).collect();
    t.sort();
    let tsum: i64 = t.iter().sum();
    let mut ma = 0;
    for comp in 0 .. n + 1 {
        let rem = m - comp as i64 * tsum;
        if rem < 0 {
            break;
        }
        let mut remtask = Vec::new();
        for _ in 0 .. n - comp {
            remtask.append(&mut t.clone());
        }
        remtask.sort();
        let mut tot = 0;
        let mut pos = 0;
        while pos < remtask.len() {
            tot += remtask[pos];
            if tot > rem {
                break;
            }
            pos += 1;
        }
        ma = max(ma, comp * (t.len() + 1) + pos);
    }
    println!("{}", ma);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::collections::*;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

// アリスとボブがゲームをする
// アリスはN個の宝を持っている。
// i個目の宝には A_i 枚のコインが入っている
// またM個の鍵がある
// j個目の鍵の値段はコインB_j枚である
//
// 最初、アリスは宝のいくつかに錠をつける
// j番目の錠はj番目の鍵でのみ開くことができる
// i番目の宝にj番目の錠をつけるのにかかるコストは C_{i, j} である
//
// 錠をつけ終わった後、ボブはいくつか鍵をアリスから買って宝を開ける
// (宝から手に入ったコイン) - (鍵を買うのに使ったコイン) > 0
// を満たす時、ボブの勝ちとなる
//
// アリスはボブが勝てないように錠をつける時、最小コストを求めよ
// 不可能なら-1を出力せよ
//
// 1 <= N, M <= 6
// 1 <= A_i, B_j <= 4
// 1 <= C_{i, j} <= 10^7
//
//
// メモ
// sum b < sum a なら-1
// そうでないなら錠を全部つければとりあえずは勝てる
// 愚直解ってなんだ？
// 錠を全探索
// その後鍵の買い方を全探索
// コストを計算して利得の最大値を計算、答えの更新
// これでいい
// 計算量 O(2^(NM) * 2^(M) * N) くらい？
// 当然間に合わん
// 鍵は全探索せずともフローで解ける
// 鍵、宝でそれぞれ頂点を作る
// src -> 鍵i にb_i
// 鍵j -> 宝i に錠がついてるならinf
// 宝i -> dst にa_i
// を張ってフローを流す
// sum a_i > (流量)
// ならボブの勝ち
// これでもまだ間に合わない
//
// ボブは鍵を買わないことで常に0を達成できる
// アリスはボブの最適戦略がこれになるようにしたい
// つまりカットが常に宝->dst のところになるようにしたい
// N, M, A, B が小さいのでこれをそのままdpにする
// 宝についてループを回しつつ辺を張って流量を全部試す
// 辺を満たしたら次へ
// みたいな

fn run() {
    input! {
        n: usize,
        m: usize,
        a: [i32; n],
        b: [i32; m],
        c: [[i32; m]; n],
    }
    let mut memo = Map::new();
    memo.insert(b, 0);
    for (a, c) in a.into_iter().zip(c) {
        let mut dp = Map::new();
        for (b, v) in memo.into_iter() {
            dp.insert((a, b), v);
        }
        for (i, c) in c.into_iter().enumerate() {
            let mut next = dp.clone();
            for ((a, b), v) in dp {
                let v = v + c;
                for k in 1..=b[i].min(a) {
                    let mut b = b.clone();
                    b[i] -= k;
                    let a = a - k;
                    next.entry((a, b)).or_insert(v).chmin(v);
                }
            }
            dp = next;
        }
        memo = Map::new();
        for ((a, b), v) in dp {
            if a == 0 {
                memo.entry(b).or_insert(v).chmin(v);
            }
        }
    }
    let ans = memo.values().min().cloned().unwrap_or(-1);
    println!("{}", ans);
}

fn main() {
    run();
}


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn run() {
    input! {
        n: usize,
        p: [usize1; n],
    }
    let mut q = p.clone();
    q.sort();
    q.dedup();
    if q.len() < n {
        println!("-1");
        return;
    }
    let mut a = vec![];
    let mut used = vec![false; n];
    for i in 0..n {
        if used[i] {
            continue;
        }
        used[i] = true;
        let mut k = p[i];
        let mut c = 1;
        while k != i {
            used[k] = true;
            c += 1;
            k = p[k];
        }
        if c % 2 == 0 {
            a.push(c / 2);
        } else {
            a.push(c);
        }
    }
    a.sort();
    let ans = a.iter().fold(1, |s, a| s / gcd(s, *a) * *a);
    println!("{}", ans);
}

fn main() {
    run();
}


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn can(m: usize, a: &[usize], p: &[(usize, usize)]) -> bool {
    let mut last = m;
    let mut free = 0;
    let mut rem = vec![];
    rem.extend_from_slice(a);
    for &(d, t) in p.iter().rev() {
        if d > m {
            continue;
        }
        if last > d {
            free += last - d;
            last = d;
        }
        while rem[t] > 0 && last > 0 {
            rem[t] -= 1;
            last -= 1;
        }
    }
    free += last;
    2 * rem.into_iter().fold(0, |s, a| s + a) <= free
}

fn run() {
    input! {
        n: usize,
        m: usize,
        a: [usize; n],
        p: [(usize, usize1); m],
    }
    let mut p = p;
    p.sort_by_key(|p| p.0);
    let mut ng = 0;
    let mut ok = 400_000;
    while ok - ng > 1 {
        let m = (ok + ng) / 2;
        if can(m, &a, &p) {
            ok = m;
        } else {
            ng = m;
        }
    }
    println!("{}", ok);
}

fn main() {
    run();
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

fn solve() {
    let (al, ar) = parse_line!(i32, i32);
    let (bl, br) = parse_line!(i32, i32);
    let mut ok = false;
    ok |= br >= al - 1 && br <= (al + 1) * 2;
    ok |= bl >= ar - 1 && bl <= (ar + 1) * 2;
    println!("{}", if ok {"YES"} else {"NO"})
}

fn main() {
    let tests = 1; // parse_line!(usize);
    for _ in 0..tests {
        solve();
    }
}


//spnauti-rusT
use std::io::*;
use std::str::*;
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::*;
#[allow(unused_imports)] use std::iter::*;
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_macros)]
macro_rules! m {
    ($c:tt, $x:expr, $y:expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
#[allow(unused_macros)]
macro_rules! l {
    ($i:ident . $e:tt : $t:ty; $($a:ident),*) => {
        $( let $a: $t = $i.$e(); )*
    };
    ($i:ident . $e:tt; $($a:ident),*) => {
        $( let $a = $i.$e(); )*
    };
}
struct WordReader<'a> { it : SplitAsciiWhitespace<'a> }
#[allow(dead_code)]
impl<'a> WordReader<'a> {
    fn new<T: Read>(b: &mut String, mut r: T) -> WordReader {
        b.clear();
        r.read_to_string(b).ok();
        WordReader { it: b.split_ascii_whitespace() }
    }
    fn from_stdin(b: &mut String) -> WordReader {
        WordReader::new(b, stdin())
    }
    fn sl(&mut self) ->  &str { self.it.next().unwrap() }
    fn bs(&mut self) -> &[u8] { self.sl().as_bytes()    }
    fn s(&mut self) -> String { String::from(self.sl()) }
    fn i(&mut self) ->    i32 { self.p()                }
    fn f(&mut self) ->    f64 { self.p()                }
    fn u(&mut self) ->  usize { self.p()                }
    fn sk(&mut self, n: usize) { self.it.nth(n - 1); }
    fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> {
        self.ip(n).into_iter()
    }
    fn vi(&mut self, n: usize) -> Vec<i32> {
        self.vp::<i32>(n)
    }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
        self.vp(n).into_iter()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}
//------------------- End rusT

fn main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    let n = input.u();
    let a = input.i();
    let a = a - 1;
    let mut d = vec![Vec::new(); n];
    for (i,t) in input.ii(n).enumerate() {
        let i = i as i32;
        d[(i-a).abs() as usize].push(t);
    }
    let sol: i32 = d.into_iter().map(|a| {
        let l = a.len() as i32;
        let s = a.into_iter().sum();
        if s == l { s } else { 0 }
    }).sum();
    println!("{}", sol);
}


fn main() {
    let mut text = String::new();
    std::io::stdin().read_line(&mut text).unwrap();
    let val: u64 = text.trim().parse().unwrap();
    let mut i = 1;
    let value = loop {
        if summation(i) >= val {
            break i;
        }
        i += 1;
    };
    println!("{}", val - summation(value - 1))
}
fn summation(i: u64) -> u64 {
    (i * (i + 1)) / 2
}


use std::io::{self, BufRead};
use std::collections::HashSet;

fn parse_problem<B: BufRead>(mut input: B) -> io::Result<Vec<(i64, i64)>> {
    let mut buffer = String::new();
    input.read_line(&mut buffer)?;
    buffer.truncate(buffer.trim_end().len());
    let mut positions = Vec::new();
    let mut curr = (0, 0);
    for c in buffer.chars() {
        let next = match c {
            'L' => Ok((curr.0 - 1, curr.1)),
            'U' => Ok((curr.0, curr.1 + 1)),
            'R' => Ok((curr.0 + 1, curr.1)),
            'D' => Ok((curr.0, curr.1 - 1)),
            _ => Err(io::Error::new(io::ErrorKind::InvalidInput, "bad input")),
        }?;
        positions.push(curr);
        curr = next;
    }
    positions.push(curr);
    Ok(positions)
}

fn main() -> io::Result<()> {
    let positions = parse_problem(io::stdin().lock())?;
    let mut seen_positions = HashSet::new();
    let mut last_position = (0, 0);
    for pos in positions.iter().skip(1) {
        if !seen_positions.insert(*pos) {
            println!("BUG");
            return Ok(())
        }
        seen_positions.insert((last_position.0 + 1, last_position.1));
        seen_positions.insert((last_position.0 - 1, last_position.1));
        seen_positions.insert((last_position.0, last_position.1 + 1));
        seen_positions.insert((last_position.0, last_position.1 - 1));
        last_position = *pos;
    }
    println!("OK");
    Ok(())
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

#[allow(unused_macros)]
macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

use std::io::Write;

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let ss: Vec<u8> = parse_line!(String).bytes().collect();
    let b = ss.iter().filter(|c| **c == b'B').count() as u64;
    let s = ss.iter().filter(|c| **c == b'S').count() as u64;
    let c = ss.iter().filter(|c| **c == b'C').count() as u64;
    let (nb, ns, nc) = parse_line!(u64, u64, u64);
    let (pb, ps, pc) = parse_line!(u64, u64, u64);
    let r = parse_line!(u64);
    let mut l = 0;
    let mut u = 10000000000000;
    while u - l > 1 {
        let m = (l + u) / 2;
        let need =
            if b * m <= nb {0} else {pb * (b * m - nb)} +
            if s * m <= ns {0} else {ps * (s * m - ns)} +
            if c * m <= nc {0} else {pc * (c * m - nc)};
        if need <= r {
            l = m;
        }else{
            u = m;
        }
    }
    writeln!(writer, "{}", l).unwrap();
}

fn main() {
    let mut writer = std::io::BufWriter::new(std::io::stdout());
    let tests = 1; // parse_line!(usize);
    for _ in 0..tests {
        solve(&mut writer);
    }
}


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        q: usize,
        op: [(bytes, bytes); q],
    }
    let mut p = vec![];
    for (a, b) in op {
        let a = (a[1] - b'a') as usize * 6 + (a[0] - b'a') as usize;
        let b = (b[0] - b'a') as usize;
        p.push((a, b));
    }
    let mut ok = vec![false; 6];
    ok[0] = true;
    for _ in 2..=n {
        let mut next = vec![false; ok.len() * 6];
        for (i, _) in ok.iter().enumerate().filter(|p| *p.1) {
            for &(a, b) in p.iter() {
                if i % 6 == b {
                    next[(i / 6) * 36 + a] = true;
                }
            }
        }
        ok = next;
    }
    let ans = ok.into_iter().filter(|p| *p).count();
    println!("{}", ans);
}

fn main() {
    run();
}


use std::cmp;

fn calcu_size(ix: i32, iy: i32, n: i32, second: i32) -> i64 {
    let mut total = 0i64;
    // middle
    let lefty: i32 = cmp::max(iy - second, 1);
    let righty: i32 = cmp::min(iy + second, n);

    total += (righty - lefty) as i64 + 1;

    // upper
    for i in 0..cmp::min(second, ix - 1) {
        let _row = ix - i - 1;
        let lefty = cmp::max(iy - second + i + 1, 1);
        let righty = cmp::min(iy + second - i - 1, n);
        total += (righty - lefty) as i64 + 1;
    }

    // lower
    for i in 0..cmp::min(second, n - ix) {
        let _row = ix + i + 1;
        let lefty = cmp::max(iy - second + i + 1, 1);
        let righty = cmp::min(iy + second - i - 1, n);
        total += (righty - lefty) as i64 + 1;
    }

    return total;
}

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_line(&mut input_str).expect("read error");
    let mut iter = input_str.split_whitespace();
    let n: i32 = iter.next().unwrap().parse().unwrap();
    let x: i32 = iter.next().unwrap().parse().unwrap();
    let y: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();

    let mut left = -1;
    let mut right = 2 * (((2.0 * (c as f64)).sqrt() as i32) + 1);
    while left != right - 1 {
        let mid = (left + right) >> 1;
        if calcu_size(x, y, n, mid) < c as i64 {
            left = mid;
        } else {
            right = mid;
        }
    }
    println!("{}", right);
}


// ---------- begin ModInt ----------
const MOD: u32 = 1_000_000_007;

#[derive(Clone, Copy)]
struct ModInt(u32);

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> Self::Output {
        ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl std::ops::Neg for ModInt {
    type Output = ModInt;
    fn neg(self) -> Self::Output {
        ModInt(if self.0 == 0 {0} else {MOD - self.0})
    }
}

impl std::fmt::Display for ModInt {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::str::FromStr for ModInt {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModInt::new(val))
    }
}

impl From<usize> for ModInt {
    fn from(val: usize) -> ModInt {
        ModInt((val % MOD as usize) as u32)
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}
// ---------- end ModInt ----------
// ---------- begin Precalc ----------
#[allow(dead_code)]
struct Precalc {
    inv: Vec<ModInt>,
    fact: Vec<ModInt>,
    ifact: Vec<ModInt>,
}

#[allow(dead_code)]
impl Precalc {
    pub fn new(n: usize) -> Precalc {
        let mut inv = vec![ModInt::one(); n + 1];
        let mut fact = vec![ModInt::one(); n + 1];
        let mut ifact = vec![ModInt::one(); n + 1];
        for i in 2..(n + 1) {
            inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);
            fact[i] = fact[i - 1] * ModInt(i as u32);
            ifact[i] = ifact[i - 1] * inv[i];
        }
        Precalc {
            inv: inv,
            fact: fact,
            ifact: ifact,
        }
    }
    pub fn inv(&self, n: usize) -> ModInt {
        self.inv[n]
    }
    pub fn fact(&self, n: usize) -> ModInt {
        self.fact[n]
    }
    pub fn ifact(&self, n: usize) -> ModInt {
        self.ifact[n]
    }
    pub fn comb(&self, n: usize, k: usize) -> ModInt {
        if k > n {
            return ModInt::zero();
        }
        self.fact[n] * self.ifact[k] * self.ifact[n - k]
    }
}
// ---------- end Precalc ----------
// ---------- begin Aho-Corasick ----------
const F: usize = 2;

fn convert(s: Vec<char>) -> Vec<usize> {
    let mut a = Vec::with_capacity(s.len());
    for c in s {
        let k = c.to_digit(10).unwrap() as usize;
        a.push(k);
    }
    a
}

struct ACTrieNode {
    elem: bool,
    fail: usize,
    depth: usize,
    next: [usize; F],
}

impl ACTrieNode {
    fn new() -> ACTrieNode {
        ACTrieNode {
            elem: false,
            fail: 0,
            depth: 0,
            next: [0; F],
        }
    }
}

struct AhoCorasick {
    node: Vec<ACTrieNode>,
}

#[allow(dead_code)]
impl AhoCorasick {
    fn new() -> Self {
        let root = ACTrieNode::new();
        AhoCorasick {
            node: vec![root],
        }
    }
    fn insert(&mut self, s: &Vec<usize>) -> usize {
        let node = &mut self.node;
        let mut v = 0;
        for &k in s {
            if node[v].next[k] == 0 {
                node[v].next[k] = node.len();
                let mut t = ACTrieNode::new();
                t.depth = node[v].depth + 1;
                node.push(t);
            }
            v = node[v].next[k];
        }
        node[v].elem = true;
        v
    }
    fn build(&mut self) {
        let mut q = std::collections::VecDeque::new();
        let node = &mut self.node;
        for i in 0..F {
            if node[0].next[i] != 0 {
                q.push_back(node[0].next[i]);
            }
        }
        while let Some(v) = q.pop_front() {
            for i in 0..F {
                let u = node[v].next[i];
                if u == 0 {
                    continue;
                }
                let mut fail = node[v].fail;
                while fail > 0 && node[fail].next[i] == 0 {
                    fail = node[fail].fail;
                }
                let f = node[fail].next[i];
                node[u].fail = f;
                q.push_back(u);
            }
        }
    }
    fn next(&self, v: usize, k: usize) -> usize {
        self.node[v].next[k]
    }
    fn trans(&self, mut v: usize, k: usize) -> usize {
        let node = &self.node;
        while v > 0 && node[v].next[k] == 0 {
            v = node[v].fail;
        }
        node[v].next[k]
    }
    fn elem(&self, k: usize) -> bool {
        self.node[k].elem
    }
    fn fail(&self, k: usize) -> usize {
        self.node[k].fail
    }
    fn depth(&self, k: usize) -> usize {
        self.node[k].depth
    }
    fn get_size(&self) -> usize {
        self.node.len()
    }
}
// ---------- end Aho-Corasick ----------
// ---------- begin Matrix ----------
#[allow(dead_code)]
mod matrix {
    use std::ops::{Add, Mul};
    pub trait SemiRing: Add<Output = Self> + Mul<Output = Self> + Copy {
        fn zero() -> Self;
        fn one() -> Self;
    }
    pub const SIZE: usize = 102;
    #[derive(Clone)]
    pub struct SquareMatrix<T: SemiRing> {
        buf: [[T; SIZE]; SIZE],
    }
    impl<T: SemiRing> SquareMatrix<T> {
        pub fn zero() -> Self {
            let z = T::zero();
            SquareMatrix {
                buf: [[z; SIZE]; SIZE],
            }
        }
        pub fn identity() -> Self {
            let mut m = Self::zero();
            for i in 0..SIZE {
                m.buf[i][i] = T::one();
            }
            m
        }
        pub fn set_at(&mut self, i: usize, j: usize, v: T) {
            self.buf[i][j] = v;
        }
        pub fn get_at(&self, i: usize, j: usize) -> T {
            self.buf[i][j]
        }
        pub fn matmul(&self, rhs: &Self) -> Self {
            let mut res = Self::zero();
            for (x, a) in res.buf.iter_mut().zip(self.buf.iter()) {
                for (a, b) in a.iter().zip(rhs.buf.iter()) {
                    for (x, b) in x.iter_mut().zip(b.iter()) {
                        *x = *x + *a * *b;
                    }
                }
            }
            res
        }
        pub fn matadd(&self, rhs: &Self) -> Self {
            let mut c = Self::zero();
            for (c, (a, b)) in c.buf.iter_mut().zip(self.buf.iter().zip(rhs.buf.iter())) {
                for (c, (a, b)) in c.iter_mut().zip(a.iter().zip(b.iter())) {
                    *c = *a + *b;
                }
            }
            c
        }
        pub fn matpow(&self, mut n: usize) -> Self {
            let mut t = Self::identity();
            let mut s = self.clone();
            while n > 0 {
                if n & 1 == 1 {
                    t = t.matmul(&s);
                }
                s = s.matmul(&s);
                n >>= 1;
            }
            t
        }
    }
}
// ---------- end Matrix ----------
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use matrix::*;

impl SemiRing for ModInt {
    fn zero() -> Self {
        ModInt::zero()
    }
    fn one() -> Self {
        ModInt::one()
    }
}

fn run() {
    input! {
        n: usize,
        x: usize,
        s: chars,
    }
    let s = convert(s);
    let mut aho = AhoCorasick::new();
    aho.insert(&s);
    aho.build();
    type M = SquareMatrix<ModInt>;
    let mut zero = M::identity();
    zero.set_at(n + 1, n + 1, ModInt(2));
    for i in 0..=n {
        let v = aho.trans(i, 0);
        let u = zero.get_at(v, i);
        zero.set_at(v, i, u + ModInt::one());
        if v == n {
            let u = zero.get_at(n + 1, i);
            zero.set_at(n + 1, i, u + ModInt::one());
        }
    }
    let mut one = M::identity();
    one.set_at(n + 1, n + 1, ModInt(2));
    for i in 0..=n {
        let v = aho.trans(i, 1);
        let u = one.get_at(v, i);
        one.set_at(v, i, u + ModInt::one());
        if v == n {
            let u = one.get_at(n + 1, i);
            one.set_at(n + 1, i, u + ModInt::one());
        }
    }
    let mut dp = vec![];
    dp.push(zero);
    dp.push(one);
    for i in 2..=x {
        let v = dp[i - 2].matmul(&dp[i - 1]);
        dp.push(v);
    }
    let ans = dp[x].get_at(n + 1, 0);
    println!("{}", ans);
}

fn main() {
    run();
}


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: i64,
        p: i64,
    }
    for k in 1..50 {
        let v = n - p * k;
        if v < 0 {
            break;
        }
        let c = v.count_ones() as i64;
        if c <= k && k <= v {
            println!("{}", k);
            return;
        }
    }
    println!("-1");
}

fn main() {
    run();
}