//spnauti-rusT
use std::io::*;
use std::str::{self,*};
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_imports)] use std::cell::*;
#[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 {
    ($($v:ident),* = $i:ident.$f:ident $a:tt) => {
        $( let $v = $i.$f$a; )*
    };
    ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {
        $( let $v:$t = $i.$f$a; )*
    };
}
struct WordReaderB {
    bin: Box<[u8]>,
    it: RefCell<std::vec::IntoIter<Range<usize>>>
}
#[allow(dead_code)]
impl WordReaderB {
    fn from<T: Read>(mut r: T) -> Self {
        let mut bin = Vec::new();
        r.read_to_end(&mut bin).ok();
        let bin = bin.into_boxed_slice();
        let it = RefCell::new(Self::split(&bin).into_iter());
        Self { bin, it }
    }
    fn from_stdin() -> Self {
        Self::from(stdin())
    }
    fn split(a: &[u8]) -> Vec<Range<usize>> {
        let mut res = Vec::new();
        let mut last = None;
        let mut space = vec![false; 256];
        for &c in b" \t\n\r" {
            space[c as usize] = true;
        }
        for (i,&c) in a.iter().enumerate() {
            if space[c as usize] {
                if let Some(j) = last.take() {
                    res.push(j..i);
                }
            } else {
                last.get_or_insert(i);
            }
        }
        if let Some(j) = last {
            res.push(j..a.len());
        }
        res
    }
    fn no_it<T>() -> std::vec::IntoIter<T> {
        Vec::new().into_iter()
    }
    fn bs(&self) -> &[u8] {
        &self.bin[self.it.borrow_mut().next().expect("EOF")]
    }
    fn sl(&self) -> std::borrow::Cow<str> {
        String::from_utf8_lossy(self.bs())
    }
    fn s(&self) -> String { self.sl().into_owned() }
    fn sk(&self, n: usize) {
        self.it.borrow_mut().nth(n - 1);
    }
    fn i(&self) ->    i32 { self.p() }
    fn u(&self) ->  usize { self.p() }
    fn f(&self) ->    f64 { self.p() }
    fn vi(&self, n: usize) -> Vec<i32> {
        self.vp::<i32>(n)
    }
    fn vu(&self, n: usize) -> Vec<usize> {
        self.vp::<usize>(n)
    }
    fn ii(&self, n: usize) -> impl Iterator<Item=i32> {
        self.ip(n).into_iter()
    }
    fn iu(&self, n: usize) -> impl Iterator<Item=usize> {
        self.ip(n).into_iter()
    }
    fn p<T: FromStr>(&self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn vp<T: FromStr>(&self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
    fn ip<T: FromStr>(&self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
        self.vp(n).into_iter()
    }
}
//------------------- End rusT

fn main() {
    let rin = WordReaderB::from_stdin();

    l!(a,b = rin.bs());
    let na = a.len();
    let nb = b.len();
    let nab = na.max(nb) * 2;

    type DP = Vec<Vec<Vec<Option<(usize, usize, usize, usize)>>>>;
    let mut dp = vec![vec![vec![None; nab + 1]; nb + 1]; na + 1];
    type Q = VecDeque<(usize, usize, usize, usize)>;
    let mut q = VecDeque::new();
    let f = |q: &mut Q, dp: &mut DP, ia: usize, ib: usize, iab: usize, ia0, ib0, iab0, d| {
        if ia <= na && ib <= nb && iab <= nab {
            let res = &mut dp[ia][ib][iab];
            if res.is_none() {
                *res = Some((ia0,ib0,iab0,d));
                q.push_back((ia,ib,iab,d));
            }
        }
    };
    f(&mut q, &mut dp, 0, 0, 0, 0, 0, 0, 0);

    loop {
        let (ia, ib, iab, d) = q.pop_front().unwrap();
        if (ia, ib, iab) == (na, nb, 0) {
            break;
        }
        let d = d + 1;
        for &x in b"()" {
            let iab1 = {
                if x == b'(' {
                    iab + 1
                } else {
                    if iab == 0 {
                        continue;
                    }
                    iab - 1
                }
            };
            let ia1 = if ia < na && x == a[ia] {ia + 1} else {ia};
            let ib1 = if ib < nb && x == b[ib] {ib + 1} else {ib};
            f(&mut q, &mut dp, ia1, ib1, iab1, ia, ib, iab, d);
        }
    }
    let d = dp[na][nb][0].as_ref().unwrap().3;
    let mut sol = vec![b'_'; d];
    let (mut ia, mut ib, mut iab) = (na, nb, 0);
    while (ia, ib, iab) != (0, 0, 0) {
        let (ia0,ib0,iab0,d0) = *dp[ia][ib][iab].as_ref().unwrap();
        sol[d0 - 1] = if iab0 < iab {b'('} else {b')'};
        ia = ia0;
        ib = ib0;
        iab = iab0;
    }
    let sol = String::from_utf8(sol).unwrap();
    println!("{}", sol);
}


//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: u64,
    }
    if n <= 2 {
        println!("1");
        return;
    }
    let mut m = 4;
    let mut d = 1;
    while m + 1 < n {
        m = 2 * m - d;
        d ^= 1;
    }
    if m == n || m + 1 == n {
        println!("1");
    } else {
        println!("0");
    }
}

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: u64,
    }
    if n <= 2 {
        println!("1");
        return;
    }
    let mut m = 4;
    let mut d = 1;
    while m + 1 < n {
        m = 2 * (m + 1) - d;
        d ^= 1;
    }
    if m == n || m + 1 == n {
        println!("1");
    } else {
        println!("0");
    }
}

fn main() {
    run();
}


use std::str::{FromStr};

fn main() {
  let mut r = Read::new();
  let ln = r.many();
  print!("{}", solve(ln[0], ln[1], ln[2]));
}

fn solve(t: i32, l: i32, r: i32) -> i64 {
  let b = 1000000007;
  let mut f = vec![0;(r + 1) as usize];
  for i in 1..r as i64 + 1 {
    for j in 2..r as i64 / i + 1 {
      f[(i * j) as usize] = (f[i as usize] + i * j * (j - 1) / 2) % b;
    }
  }

  f[l as usize..r as usize + 1].iter().fold((0, 1), |(s, p), fi| ((s + p * fi) % b, p * t as i64 % b)).0
}

struct Read { s: String }

impl Read {
  fn new() -> Read {
    Read{s: String::new()}
  }

  #[allow(unused_must_use)]
  fn line(&mut self) -> &str {
    self.s.clear();
    std::io::stdin().read_line(&mut self.s);
    self.s.trim()
  }

  fn one<T: FromStr>(&mut self) -> T where <T as FromStr>::Err: std::fmt::Debug {
    self.line().parse().unwrap()
  }

  fn many<T: FromStr>(&mut self) -> Vec<T> where <T as FromStr>::Err: std::fmt::Debug {
    self.line().split(' ').map(|x| x.parse().unwrap()).collect()
  }
}


use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let nkx : Vec<usize> = line.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
    let (n, k, x) : (usize, usize, usize) = (nkx[0], nkx[1], nkx[2]);

    line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let my_deeds : Vec<usize> = line.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();

    let mut min_cost = 0;
    for i in 1..(n + 1) {
        if i <= k {
            min_cost += x;
        } else {
            min_cost += my_deeds[((n - i) as usize)];
        }
    }

    print!("{}", min_cost);
}


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

use std::io::prelude::*;
use std::io::BufReader;
use std::cmp::{max, min};

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn get_vec<T>() -> Vec<T>
where T: FromStr,
      <T as FromStr>::Err: std::fmt::Debug,
{
    get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()
}

const N: i64 = 998_244_353;

fn extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d0, x0, y0) = extended_euclid(b, a % b);
        (d0, y0, x0 - a / b * y0)
    }
}

fn main() {
    let (n, k, x): (usize, usize, usize) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let a: Vec<usize> = get_vec();

    let ans = &a[..a.len() - k].iter().cloned().sum::<usize>() + k * x;

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


// use std::ops::{Index, IndexMut};
use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! split {
    ($x: expr) => {
        ($x).trim().split(' ').collect()
    }
}

macro_rules! parse {
    ($x: expr) => {
        ($x).parse().unwrap()
    }
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            let mut iter = iv.into_iter();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            let mut iter = iv.into_iter();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

macro_rules! rvec {
    ($x: expr) => {
        ($x).into_iter().map(|x| parse!(x)).collect()
    }
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            iv.into_iter().map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {}", stringify!($x), $x)
    }
}

fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!();
}

fn main() {
    let (n, k) = readl!(usize, i64);
    let a = readlvec!(i64);

    let inf: i64 = 1e18 as i64;
    let ma = a.iter().fold(0,|acc, &x| max(acc,x));
    let bo = (ma as f64).sqrt() as i64 + 2;
    // debug!(bo);
    let mut ans = 1;
    for i in 1..bo {
        let mut sum = 0;
        for e in &a {
            sum += (i-e%i)%i;
        }
        if sum <= k {
            ans = i;
        }
    }

    let mut qu = Vec::<(i64,usize)>::new();
    qu.push((bo,0));
    for i in 0..n {
        for j in 1..bo {
            if a[i]/j != 0 && bo <= a[i]/j {
                qu.push(((a[i]+j-1)/j,i));
            }
        }
    }
    qu.sort();
    let mut qui = qu.into_iter();
    let mut b = vec![0;n];
    let mut pre = -100;
    if let Some((di,i)) = qui.next() {
        for i in 0..n {
            b[i] = (a[i]+di-1)/di;
        }
        pre = di;
    }
    let mut sb = b.iter().fold(0,|acc, &x| acc+x);
    let sa = a.iter().fold(0,|acc, &x| acc+x);
    let mut dis = 0;
    for (di, i) in qui {
        // debug!(i);
        // debug!(pre);
        // debug!(di);

        // // printvec(&mov);
        // printvec(&b);
        // debug!(sb);

        if pre*sb-sa <= k {
            let m = (k+sa-pre*sb)/sb;
            if pre+m < di {
                ans = pre+m;
            }
        }
        sb -= b[i];
        b[i] = (a[i]+di-1)/di;
        sb += b[i];
        pre = di;
    }
    // printvec(&b);
    // debug!(sb);
    // if sm <= k {
    //     ans = pre;
    // } else {
    //     let m = (k-sm)/sb;
    //     debug!(m);
    //     {
    //         ans = pre+m;
    //     }
    // }

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


use std::ops::{Index, IndexMut};
use std::cmp::{Ordering};
use std::collections::{BinaryHeap, BTreeMap};
use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! split {
    ($x: expr) => {
        ($x).trim().split(' ').collect()
    }
}

macro_rules! parse {
    ($x: expr) => {
        ($x).parse().unwrap()
    }
}

macro_rules! rvec {
    ($x: expr) => {
        ($x).into_iter().map(|x| parse!(x)).collect()
    }
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {}", stringify!($x), $x)
    }
}

fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!();
}

fn main() {
    let s = getline();
    let iv:Vec<_> = split!(s);
    let n: usize = parse!(iv[0]);
    let s = getline();
    let iv: Vec<_> = split!(s);
    let a: Vec<i32> = rvec!(iv);

    let mut mp: BTreeMap<i32, Vec<usize>> = BTreeMap::new();
    for (i,val) in a.into_iter().enumerate() {
        let vec = match mp.entry(val) {
            Vacant(entry) => entry.insert(vec![]),
            Occupied(entry) => entry.into_mut(),
        };
        vec.push(i);

        // (*mp.get_mut(&i).unwrap()).push(i as i32);
    }
    for (_,vec) in &mut mp {
        vec.sort();
    }
    let mut ans = 0_i64;
    let mut num = n;
    let mut pre = 0;
    let mut first = true;
    for (key,vec) in mp {
        let p =
        if first || vec[vec.len()-1] < pre || vec[0] >= pre {
            0
        } else {
            let mut l = 0;
            let mut r = vec.len()-1;
            while l+1 < r {
                let m = (l+r)/2;
                if pre <= vec[m] {
                    r = m;
                } else {
                    l = m;
                }
            }
            r
        };
        for i in 0..vec.len() {
            if pre > vec[(p+i)%vec.len()] {
                ans += num as i64;
            }
            num -= 1;
            pre = vec[(p+i)%vec.len()];
        }
        first = false;
    }
    println!("{}", ans+n as i64);
}


// use std::ops::{Index, IndexMut};
use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! split {
    ($x: expr) => {
        ($x).trim().split(' ').collect()
    }
}

macro_rules! parse {
    ($x: expr) => {
        ($x).parse().unwrap()
    }
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            let mut iter = iv.into_iter();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            let mut iter = iv.into_iter();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

macro_rules! rvec {
    ($x: expr) => {
        ($x).into_iter().map(|x| parse!(x)).collect()
    }
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            iv.into_iter().map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {}", stringify!($x), $x)
    }
}

fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

fn main() {
    let (n, k) = readl!(usize, i64);
    let a = readlvec!(i64);

    let ma = a.iter().fold(0,|acc, &x| max(acc,x));
    let bo = (ma as f64).sqrt() as i64 + 2;
    let mut ans = 1;
    for i in 1..bo {
        let mut sum = 0;
        for e in &a {
            sum += (i-e%i)%i;
        }
        if sum <= k {
            ans = i;
        }
    }

    let mut qu = Vec::<(i64,usize)>::new();
    qu.push((bo,0));
    for i in 0..n {
        for j in 1..bo {
            if a[i]/j != 0 && bo <= a[i]/j {
                qu.push(((a[i]+j-1)/j,i));
            }
        }
    }
    qu.sort();
    let mut qui = qu.into_iter();
    let mut b = vec![0;n];
    let mut pre = -100;
    if let Some((di,i)) = qui.next() {
        for i in 0..n {
            b[i] = (a[i]+di-1)/di;
        }
        pre = di;
    }
    let mut sb = b.iter().fold(0,|acc, &x| acc+x);
    let sa = a.iter().fold(0,|acc, &x| acc+x);
    for (di, i) in qui {
        if pre*sb-sa <= k {
            let m = (k+sa-pre*sb)/sb;
            if pre+m < di {
                ans = pre+m;
            }
        }
        sb -= b[i];
        b[i] = (a[i]+di-1)/di;
        sb += b[i];
        pre = di;
    }
    if pre*sb-sa <= k {
        let m = (k+sa-pre*sb)/sb;
        ans = pre+m;
    }

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


// use std::ops::{Index, IndexMut};
use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! split {
    ($x: expr) => {
        ($x).trim().split(' ').collect()
    }
}

macro_rules! parse {
    ($x: expr) => {
        ($x).parse().unwrap()
    }
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            let mut iter = iv.into_iter();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            let mut iter = iv.into_iter();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

macro_rules! rvec {
    ($x: expr) => {
        ($x).into_iter().map(|x| parse!(x)).collect()
    }
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            iv.into_iter().map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {}", stringify!($x), $x)
    }
}

fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

fn main() {
    let (n, k) = readl!(usize, i64);
    let a = readlvec!(i64);

    let inf: i64 = 1e18 as i64;
    let ma = a.iter().fold(0,|acc, &x| max(acc,x));
    let bo = (ma as f64).sqrt() as i64 + 2;
    // debug!(bo);
    let mut ans = 1;
    for i in 1..bo {
        let mut sum = 0;
        for e in &a {
            sum += (i-e%i)%i;
        }
        if sum <= k {
            ans = i;
        }
    }

    let mut qu = Vec::<(i64,usize)>::new();
    qu.push((bo,0));
    for i in 0..n {
        for j in 1..bo {
            if a[i]/j != 0 && bo <= a[i]/j {
                qu.push(((a[i]+j-1)/j,i));
            }
        }
    }
    qu.sort();
    let mut qui = qu.into_iter();
    let mut b = vec![0;n];
    let mut pre = -100;
    if let Some((di,i)) = qui.next() {
        for i in 0..n {
            b[i] = (a[i]+di-1)/di;
        }
        pre = di;
    }
    let mut sb = b.iter().fold(0,|acc, &x| acc+x);
    let sa = a.iter().fold(0,|acc, &x| acc+x);
    let mut dis = 0;
    for (di, i) in qui {
        // debug!(i);
        // debug!(pre);
        // debug!(di);

        // // printvec(&mov);
        // printvec(&b);
        // debug!(sb);

        if pre*sb-sa <= k {
            let m = (k+sa-pre*sb)/sb;
            if pre+m < di {
                ans = pre+m;
            }
        }
        sb -= b[i];
        b[i] = (a[i]+di-1)/di;
        sb += b[i];
        pre = di;
    }
    // printvec(&b);
    // debug!(sb);
    // if sm <= k {
    //     ans = pre;
    // } else {
    //     let m = (k-sm)/sb;
    //     debug!(m);
    //     {
    //         ans = pre+m;
    //     }
    // }
    if pre*sb-sa <= k {
        let m = (k+sa-pre*sb)/sb;
        {
            ans = pre+m;
        }
    }

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


use std::io::{self, Read};
use std::iter::FromIterator;

#[allow(dead_code)]
struct Source {
    chars: Box<Iterator<Item = char>>,
}

#[allow(dead_code)]
impl Source {
    fn next_chr(&mut self) -> char {
        self.chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .next()
            .expect("eof")
    }

    fn next_str(&mut self) -> String {
        let it = self
            .chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .take_while(|c| !char::is_whitespace(*c));
        let s = String::from_iter(it);
        if s.is_empty() {
            panic!("eof")
        } else {
            s
        }
    }

    fn from_stdin() -> Self {
        let mut data = String::new();
        io::stdin().read_to_string(&mut data).expect("Input error");
        Self::from_str(&data)
    }

    fn from_str(s: &str) -> Self {
        let data = String::from(s);
        let chars = data.chars().collect::<Vec<char>>().into_iter();
        Source {
            chars: Box::new(chars),
        }
    }
}

#[allow(unused_macros)]
macro_rules! input {
    ($src:expr; $($elem:tt)*) => {
        input_inner!($src, $($elem)*)
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($src:expr) => {};
    ($src:expr,) => {};
    ($src:expr, $var:ident : mut $ty:tt $($rest:tt)*) => {
        let mut $var = parse!($src, $ty);
        input_inner!($src $($rest)*)
    };
    ($src:expr, $var:ident : $ty:tt $($rest:tt)*) => {
        let $var = parse!($src, $ty);
        input_inner!($src $($rest)*)
    };
}

#[allow(unused_macros)]
macro_rules! parse {
    ($src:expr, ( $($ty:tt),* )) => {
        ( $(parse!($src,$ty)),* )
    };
    ($src:expr, char) => {
        $src.next_chr()
    };
    ($src:expr, [ $ty:tt; $len:expr ]) => {
        (0..$len).map(|_| parse!($src,$ty)).collect::<Vec<_>>()
    };
    ($src:expr, $ty:tt) => {
        parse_str!($src,$ty)
    };
}

#[allow(unused_macros)]
macro_rules! parse_str {
    ($src:expr, chars) => {
        $src.next_str().chars().collect::<Vec<char>>()
    };
    ($src:expr, $ty:ty) => {
        $src.next_str().parse::<$ty>().expect("Parse error")
    };
}

use std::cmp::min;

fn max_height(pos: usize, height: usize, restriction: &[(usize, usize, usize)]) -> usize {
    restriction.iter().fold(height, |cur, (l, r, h)| {
        if *l <= pos && pos <= *r {
            min(cur, *h)
        } else {
            cur
        }
    })
}

fn main() {
    let mut src = Source::from_stdin();
    input! { src;
             n: usize, h: usize, m: usize,
             r: [(usize,usize,usize); m]
    }

    let res: usize = (1..=n)
        .map(|pos| {
            let h = max_height(pos, h, &r);
            h * h
        })
        .sum();

    println!("{}", res)
}


use std::cmp::*;
use std::collections::*;
use std::io::*;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

#[derive(PartialEq, Eq, Hash, Clone, Copy)]
struct Tile {
    num: usize,
    suit: char,
}
impl CpIn for Tile {
    fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
        let s = r.read_word_str();
        let num: usize = s[..1].parse().unwrap();
        Tile {
            num: num - 1,
            suit: s[1..].parse().unwrap(),
        }
    }
}

pub fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (t0, t1, t2) = i.read();
    writeln!(o, "{}", solve([t0, t1, t2])).unwrap();
}
fn solve(ts: [Tile; 3]) -> usize {
    let mut m = HashMap::new();
    for &t in &ts {
        *m.entry(t).or_insert(0) += 1;
    }
    let mut ans = 3 - *m.values().max().unwrap();

    for &suit in &['m', 'p', 's'] {
        let mut es = [false; 9];
        for &t in &ts {
            if t.suit == suit {
                es[t.num] = true;
            }
        }
        println!("{} {:?}", suit, &es);
        for i in 0..9 - 3 {
            let mut c = 0;
            for j in 0..3 {
                if es[i + j] {
                    c += 1;
                }
            }
            ans = min(ans, 3 - c);
        }
    }
    ans
}

pub mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        b: Vec<u8>,
    }
    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                b: Vec::new(),
            }
        }
        pub fn read_word(&mut self) -> &[u8] {
            self.b.clear();
            let mut consume = 0;
            loop {
                self.r.consume(consume);
                let b = self.r.fill_buf().unwrap();
                assert!(b.len() != 0);
                if let Some(p) = b.iter().position(|&x| x.is_ascii_whitespace()) {
                    self.b.extend_from_slice(&b[..p]);
                    consume = p + 1;
                    break;
                }
                self.b.extend_from_slice(b);
                consume = b.len();
            }
            self.r.consume(consume);
            consume_ws(&mut self.r);
            &self.b
        }
        pub fn read_word_str(&mut self) -> &str {
            unsafe { std::str::from_utf8_unchecked(self.read_word()) }
        }

        pub fn read_line(&mut self) -> &[u8] {
            self.b.clear();
            self.r.read_until(b'\n', &mut self.b).unwrap();
            let end = self
                .b
                .iter()
                .rposition(|x| !x.is_ascii_whitespace())
                .map(|idx| idx + 1)
                .unwrap_or(0);
            &self.b[..end]
        }
        pub fn read_line_str(&mut self) -> &str {
            unsafe { std::str::from_utf8_unchecked(self.read_line()) }
        }

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

        pub fn read_vec<T: CpIn>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
        pub fn read_iter<'a, T: CpIn>(&'a mut self, n: usize) -> CpIter<'a, R, T> {
            CpIter {
                r: self,
                n: n,
                _pd: Default::default(),
            }
        }
    }
    pub struct CpIter<'a, R: BufRead + 'a, T> {
        r: &'a mut CpReader<R>,
        n: usize,
        _pd: std::marker::PhantomData<fn() -> T>,
    }
    impl<'a, R: BufRead, T: CpIn> Iterator for CpIter<'a, R, T> {
        type Item = T;
        fn next(&mut self) -> Option<T> {
            if self.n == 0 {
                None
            } else {
                self.n -= 1;
                Some(self.r.read())
            }
        }
    }

    pub trait CpIn {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self;
    }

    impl CpIn for u64 {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
            read_u64_fast(&mut r.r)
        }
    }
    impl CpIn for i64 {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
            read_i64_fast(&mut r.r)
        }
    }
    impl CpIn for char {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
            let b = r.r.fill_buf().unwrap()[0] as char;
            r.r.consume(1);
            let s = r.r.fill_buf().unwrap()[0];
            assert!(s == b' ' || s == b'\n');
            r.r.consume(1);
            b
        }
    }

    macro_rules! cpin_tuple {
        ($($t:ident),*) => {
            impl<$($t: CpIn),*> CpIn for ($($t),*) {
                fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    ($($t::read_from(r)),*)
                }
            }
        };
    }

    macro_rules! cpin_cast {
        ($t_self:ty, $t_read:ty) => {
            impl CpIn for $t_self {
                fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    <$t_read>::read_from(r) as $t_self
                }
            }
        };
    }
    macro_rules! cpin_parse {
        ($t:ty) => {
            impl CpIn for $t {
                fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    r.read_word_str().parse().unwrap()
                }
            }
        };
    }
    cpin_cast!(usize, u64);
    cpin_cast!(u32, u64);
    cpin_cast!(u16, u64);
    cpin_cast!(i32, i64);
    cpin_cast!(i16, i64);
    cpin_cast!(i8, i64);

    cpin_parse!(f64);

    cpin_tuple!(T1, T2);
    cpin_tuple!(T1, T2, T3);
    cpin_tuple!(T1, T2, T3, T4);
    cpin_tuple!(T1, T2, T3, T4, T5);

    fn read_u64_fast<R: BufRead>(r: &mut R) -> u64 {
        let mut value = 0;
        loop {
            let mut idx = 0;
            let buf_len;
            {
                let buf = r.fill_buf().unwrap();
                buf_len = buf.len();
                assert!(buf_len != 0);
                while idx < buf_len && b'0' <= buf[idx] && buf[idx] <= b'9' {
                    value = value * 10 + (buf[idx] - b'0') as u64;
                    idx += 1;
                }
            }
            if idx < buf_len {
                r.consume(idx);
                consume_ws(r);
                return value;
            }
            r.consume(idx);
        }
    }
    fn read_i64_fast<R: BufRead>(r: &mut R) -> i64 {
        let (consume, sign) = match r.fill_buf().unwrap()[0] {
            b'+' => (true, 1),
            b'-' => (true, -1),
            _ => (false, 1),
        };
        if consume {
            r.consume(1);
        }
        read_u64_fast(r) as i64 * sign
    }
    fn consume_ws<R: BufRead>(r: &mut R) {
        let mut c = 0;
        loop {
            r.consume(c);
            let b = r.fill_buf().unwrap();
            if b.len() == 0 {
                return;
            }
            if let Some(p) = b.iter().position(|&x| !x.is_ascii_whitespace()) {
                c = p;
                break;
            }
            c = b.len();
        }
        r.consume(c);
    }

}


use std::cmp::*;
use std::collections::*;
use std::io::*;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

#[derive(PartialEq, Eq, Hash, Clone, Copy)]
struct Tile {
    num: usize,
    suit: char,
}
impl CpIn for Tile {
    fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
        let s = r.read_word_str();
        let num: usize = s[..1].parse().unwrap();
        Tile {
            num: num - 1,
            suit: s[1..].parse().unwrap(),
        }
    }
}

pub fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (t0, t1, t2) = i.read();
    writeln!(o, "{}", solve([t0, t1, t2])).unwrap();
}
fn solve(ts: [Tile; 3]) -> usize {
    let mut m = HashMap::new();
    for &t in &ts {
        *m.entry(t).or_insert(0) += 1;
    }
    let mut ans = 3 - *m.values().max().unwrap();

    for &suit in &['m', 'p', 's'] {
        let mut es = [false; 9];
        for &t in &ts {
            if t.suit == suit {
                es[t.num] = true;
            }
        }
        for i in 0..9 - 3 {
            let mut c = 0;
            for j in 0..3 {
                if es[i + j] {
                    c += 1;
                }
            }
            ans = min(ans, 3 - c);
        }
    }
    ans
}

pub mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        b: Vec<u8>,
    }
    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                b: Vec::new(),
            }
        }
        pub fn read_word(&mut self) -> &[u8] {
            self.b.clear();
            let mut consume = 0;
            loop {
                self.r.consume(consume);
                let b = self.r.fill_buf().unwrap();
                assert!(b.len() != 0);
                if let Some(p) = b.iter().position(|&x| x.is_ascii_whitespace()) {
                    self.b.extend_from_slice(&b[..p]);
                    consume = p + 1;
                    break;
                }
                self.b.extend_from_slice(b);
                consume = b.len();
            }
            self.r.consume(consume);
            consume_ws(&mut self.r);
            &self.b
        }
        pub fn read_word_str(&mut self) -> &str {
            unsafe { std::str::from_utf8_unchecked(self.read_word()) }
        }

        pub fn read_line(&mut self) -> &[u8] {
            self.b.clear();
            self.r.read_until(b'\n', &mut self.b).unwrap();
            let end = self
                .b
                .iter()
                .rposition(|x| !x.is_ascii_whitespace())
                .map(|idx| idx + 1)
                .unwrap_or(0);
            &self.b[..end]
        }
        pub fn read_line_str(&mut self) -> &str {
            unsafe { std::str::from_utf8_unchecked(self.read_line()) }
        }

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

        pub fn read_vec<T: CpIn>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
        pub fn read_iter<'a, T: CpIn>(&'a mut self, n: usize) -> CpIter<'a, R, T> {
            CpIter {
                r: self,
                n: n,
                _pd: Default::default(),
            }
        }
    }
    pub struct CpIter<'a, R: BufRead + 'a, T> {
        r: &'a mut CpReader<R>,
        n: usize,
        _pd: std::marker::PhantomData<fn() -> T>,
    }
    impl<'a, R: BufRead, T: CpIn> Iterator for CpIter<'a, R, T> {
        type Item = T;
        fn next(&mut self) -> Option<T> {
            if self.n == 0 {
                None
            } else {
                self.n -= 1;
                Some(self.r.read())
            }
        }
    }

    pub trait CpIn {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self;
    }

    impl CpIn for u64 {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
            read_u64_fast(&mut r.r)
        }
    }
    impl CpIn for i64 {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
            read_i64_fast(&mut r.r)
        }
    }
    impl CpIn for char {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
            let b = r.r.fill_buf().unwrap()[0] as char;
            r.r.consume(1);
            let s = r.r.fill_buf().unwrap()[0];
            assert!(s == b' ' || s == b'\n');
            r.r.consume(1);
            b
        }
    }

    macro_rules! cpin_tuple {
        ($($t:ident),*) => {
            impl<$($t: CpIn),*> CpIn for ($($t),*) {
                fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    ($($t::read_from(r)),*)
                }
            }
        };
    }

    macro_rules! cpin_cast {
        ($t_self:ty, $t_read:ty) => {
            impl CpIn for $t_self {
                fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    <$t_read>::read_from(r) as $t_self
                }
            }
        };
    }
    macro_rules! cpin_parse {
        ($t:ty) => {
            impl CpIn for $t {
                fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    r.read_word_str().parse().unwrap()
                }
            }
        };
    }
    cpin_cast!(usize, u64);
    cpin_cast!(u32, u64);
    cpin_cast!(u16, u64);
    cpin_cast!(i32, i64);
    cpin_cast!(i16, i64);
    cpin_cast!(i8, i64);

    cpin_parse!(f64);

    cpin_tuple!(T1, T2);
    cpin_tuple!(T1, T2, T3);
    cpin_tuple!(T1, T2, T3, T4);
    cpin_tuple!(T1, T2, T3, T4, T5);

    fn read_u64_fast<R: BufRead>(r: &mut R) -> u64 {
        let mut value = 0;
        loop {
            let mut idx = 0;
            let buf_len;
            {
                let buf = r.fill_buf().unwrap();
                buf_len = buf.len();
                assert!(buf_len != 0);
                while idx < buf_len && b'0' <= buf[idx] && buf[idx] <= b'9' {
                    value = value * 10 + (buf[idx] - b'0') as u64;
                    idx += 1;
                }
            }
            if idx < buf_len {
                r.consume(idx);
                consume_ws(r);
                return value;
            }
            r.consume(idx);
        }
    }
    fn read_i64_fast<R: BufRead>(r: &mut R) -> i64 {
        let (consume, sign) = match r.fill_buf().unwrap()[0] {
            b'+' => (true, 1),
            b'-' => (true, -1),
            _ => (false, 1),
        };
        if consume {
            r.consume(1);
        }
        read_u64_fast(r) as i64 * sign
    }
    fn consume_ws<R: BufRead>(r: &mut R) {
        let mut c = 0;
        loop {
            r.consume(c);
            let b = r.fill_buf().unwrap();
            if b.len() == 0 {
                return;
            }
            if let Some(p) = b.iter().position(|&x| !x.is_ascii_whitespace()) {
                c = p;
                break;
            }
            c = b.len();
        }
        r.consume(c);
    }

}


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

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input!{$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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn solve(bitmask: usize, times: &mut[Option<i32>], matches: &mut[Option<(usize, usize)>], objects: &[(i32, i32)], length: usize, handbag: (i32, i32)) -> i32 {
    if let Some(t) = times[bitmask] {
        return t;
    }
    for i in 0..length {
        if bitmask & (1 << i) > 0 {
            let mut best = solve(bitmask ^ (1 << i), times, matches, objects, length, handbag) + 2 * sq_dist(objects[i], handbag);
            matches[bitmask] = Some((i,i));
            for j in (i+1)..length {
                if bitmask & (1 << j) > 0 {
                    let ans_j = solve(bitmask ^ (1 << i) ^ (1 << j), times, matches, objects, length, handbag) + sq_dist(objects[i], handbag) + sq_dist(objects[j], handbag) + sq_dist(objects[i], objects[j]);
                    if ans_j < best {
                        matches[bitmask] = Some((i,j));
                        best = ans_j;
                    }
                }
            }
            // dbg!(bitmask);
            // dbg!(best);
            times[bitmask] = Some(best);
            return best;
        }
    }
    unreachable!();
}

fn sq_dist(a: (i32, i32), b: (i32, i32)) -> i32 {
    (a.0-b.0)*(a.0-b.0) + (a.1-b.1)*(a.1-b.1)
}

fn main() {
    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! {next,
        handbag: (i32, i32),
        n: usize,
        objects: [(i32, i32); n],
    }
    let mut times = vec![None; 1 << n];
    times[0] = Some(0);
    let mut matches = vec![None; 1 << n];
    println!("{}", solve((1 << n) - 1, &mut times, &mut matches, &objects, n, handbag));
    // println!("{:?}", times);
    // println!("{:?}", matches);
    let mut bitmask = (1 << n) - 1;
    let mut result = String::new();
    result.push('0');
    while bitmask != 0 {
        let (i, j) = matches[bitmask].unwrap();
        if i == j {
            result.push_str(&format!(" {} 0", i+1));
        }
        else {
            result.push_str(&format!(" {} {} 0", i+1, j+1));
        }
        bitmask ^= (1 << i) | (1 << j);
    }
    println!("{}", result);
}


//spnauti-rusT {{{
use std::io::*; use std::str::{self,*}; use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_imports)] use std::cell::*;
#[allow(unused_macros)] macro_rules! min {
	($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b < *a {*a=b; true} else {false} }};
}
#[allow(unused_macros)] macro_rules! max {
	($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b > *a {*a=b; true} else {false} }};
}
#[allow(unused_macros)] macro_rules! l {
	($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};
	($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};
	(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};
	(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};
}
#[allow(unused_macros)] macro_rules! v {
	([$d:expr]$($s:tt)+) => {vec![v!($($s)+);$d]};
	([]) => {Vec::new()}; ([$e:expr]) => {Vec::with_capacity($e)}; (=$e:expr) => {$e};
}
#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }
#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }
#[allow(dead_code)] fn writer() -> BufWriter<Stdout> { BufWriter::new(stdout()) }
struct WordReaderC {buf: Vec<u8>, pos: usize, q: std::io::StdinLock<'static>}//'
#[allow(dead_code)] impl WordReaderC {
	fn new() -> Self {
		let r = unsafe {&*Box::into_raw(Box::new(stdin()))};
		Self { q: r.lock(), buf: v!([]), pos: 0 }
	}
	fn next_line(&mut self) -> bool {
		self.buf.clear(); self.pos = 0;
		self.q.read_until(b'\n', &mut self.buf).unwrap_or(0) > 0
	}
	fn is_ws(c: u8) -> bool {
		c == b' ' || c == b'\r' || c == b'\n' || c == b'\t'
	}
	fn byte(&mut self) -> Option<u8> {
		if self.pos == self.buf.len() { if !self.next_line() { return None; } }
		self.pos += 1; Some(self.buf[self.pos - 1])
	}
	fn vb(&mut self) -> Vec<u8> {
		let mut s = v!([8]);
		let mut f = false;
		loop {
			if let Some(c) = self.byte() {
				if !Self::is_ws(c) {
					s.push(c);
					f = true;
				} else if f { break; }
			} else { break; }
		}
		s
	}
	fn board(&mut self, r: usize, c: Option<usize>) -> Vec<Vec<u8>> {
		let mut res = v!([r]);
		let c = c.unwrap_or(0);
		rep!{[r]
			let t = self.vb();
			assert!(c == 0 || t.len() == c);
			res.push(t);
		}
		res
	}
	fn framed_board(&mut self, r: usize, c: usize, f: u8) -> Vec<Vec<u8>> {
		let mut res = v!([r+2]);
		res.push( v!([c+2] = f) );
		rep!{[r]
			let mut t = self.vb();
			assert!(t.len() == c);
			t.reserve(2);
			t.insert(0,f);
			t.push(f);
			res.push(t);
		}
		res.push( v!([c+2] = f) );
		res
	}
	fn s(&mut self) -> String { String::from_utf8(self.vb()).expect("invalid utf8") }
	fn i(&mut self) ->    i32 { self.p() }
	fn l(&mut self) ->    i64 { self.p() }
	fn u(&mut self) ->  usize { self.p() }
	fn f(&mut self) ->    f64 { self.p() }
	fn vi(&mut self, n: usize) -> Vec<i32> { self.vp(n) }
	fn vl(&mut self, n: usize) -> Vec<i64> { self.vp(n) }
	fn vu(&mut self, n: usize) -> Vec<usize> { self.vp(n) }
	fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> { self.ip(n).into_iter() }
	fn iu(&mut self, n: usize) -> impl Iterator<Item=usize> { self.ip(n).into_iter() }
	fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
		let w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::<T>().unwrap()
	}
	fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
		(0..n).map(|_|self.p()).collect()
	}
	fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
		self.vp(n).into_iter()
	}
	fn graph(&mut self, n: usize, m: usize) -> Vec<Vec<usize>> {
		let mut e = v!([n][]); rep!{[m] l!(a,b = self.u()-1); e[a].push(b); e[b].push(a); } e
	}
	fn graph_w<T: Copy+FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<(usize,T)>> where T::Err: Debug {
		let mut e = v!([n][]); rep!{[m] l!(a,b = self.u()-1); let c: T = self.p(); e[a].push((b,c)); e[b].push((a,c)); } e
	}
}
//------------------- End rusT }}}

// Field (mod prime) {{{
mod field {
	use std::ops::*;
	#[allow(dead_code)] pub const Z0: Field = Field(0);
	#[allow(dead_code)] pub const Z1: Field = Field(1);
	const P5: i32 = 1_000_000_007;
	const P6: i64 = P5 as i64;
	#[derive(Debug,Clone,Copy,PartialEq,Eq,PartialOrd,Ord,Default)] pub struct Field(i32);
	#[allow(dead_code)] impl Field {
		pub fn new<T: Into<i64>>(a: T) -> Self { Self(Self::cv(a)) }
		pub fn new_unchecked(a: i32) -> Self { Self(a) }
		fn hi(mut a: i32) -> i32 { if a >= P5 { a -= P5; } a }
		fn lo(mut a: i32) -> i32 { if a < 0 { a += P5; } a }
		fn cv<T: Into<i64>>(a: T) -> i32 { Self::lo((a.into() % P6) as i32) }
		pub fn inv(self) -> Self { self.pow(P5-2) }
		pub fn pow<T: Into<i64>>(self, b: T) -> Self {
			let b = b.into(); if b == 0 { Self(1) } else {
				let mut res = self.pow(b/2); res *= res; if b % 2 == 1 {res *= self;} res
			}
		}
	}
	impl Add for Field { type Output = Self; fn add(self, a: Self) -> Self::Output { Self(Self::hi(self.0 + a.0)) }}
	impl Sub for Field { type Output = Self; fn sub(self, a: Self) -> Self::Output { Self(Self::lo(self.0 - a.0)) }}
	impl Mul for Field { type Output = Self; fn mul(self, a: Self) -> Self::Output { Self(Self::cv(self.0 as i64 * a.0 as i64)) }}
	impl Div for Field { type Output = Self; fn div(self, a: Self) -> Self::Output { self * a.inv() }}
	impl Neg for Field { type Output = Self; fn neg(self) -> Self::Output { Self(Self::lo(-self.0)) }}
	impl AddAssign for Field { fn add_assign(&mut self, a: Self) { *self = *self + a; } }
	impl SubAssign for Field { fn sub_assign(&mut self, a: Self) { *self = *self - a; } }
	impl MulAssign for Field { fn mul_assign(&mut self, a: Self) { *self = *self * a; } }
	impl DivAssign for Field { fn div_assign(&mut self, a: Self) { *self = *self / a; } }
	use std::fmt::{Display, Formatter, Result};
	impl Display for Field { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.0) } }
}
#[allow(unused_imports)] use field::{Field, Field as Z, Z0, Z1};
//}}}
// Square Matrix (Field) {{{
type MatT = Field;
const MAT_T_0: MatT = Z0;
const MAT_T_1: MatT = Z1;
#[derive(Debug,Clone)] struct Mat { n: usize, a: Vec<MatT> }
#[allow(dead_code)] impl Mat {
	fn new(n:usize)->Self{Self{n,a:vec![MAT_T_0;n*n]}}
	fn diag(n:usize,v:MatT)->Self{let mut m=Self::new(n);let mut p=0;for _ in 0..n{m.a[p]=v;p+=n+1;}m}
	fn pow(&self,n:u64)->Self{if n==0{Self::diag(self.n,MAT_T_1)}else{let mut t=self.pow(n/2);t*=t.clone();if n%2==1{t*=self.clone();}t}}
	fn range(&self,r:Range<usize>,c:Range<usize>)->Vec<Vec<MatT>>{if r.start<r.end||c.start<c.end{Vec::new()}else{let mut res=vec![vec![MAT_T_0;c.end-c.start];r.end-r.start];
		for i in r.start..r.end{let ir=i-r.start;let ii=i*self.n+c.start;for j in 0..c.end-c.start{res[ir][j]=self.a[ii+j];}}res}}
	fn at(&self,r:usize,c:usize)->MatT{self.a[r*self.n+c]}
	fn at_mut<'a>(&'a mut self,r:usize,c:usize)->&'a mut MatT{&mut self.a[r*self.n+c]}//'
}
impl Mul for Mat{type Output=Self;fn mul(self,o:Self)->Self::Output{assert!(self.n==o.n);let n=self.n;let mut res=Self::new(n);
	for ii in(0..n).map(|i|i*n){for j in 0..n{let mut t=MAT_T_0;let mut kk=j;for k in 0..n{t+=self.a[ii+k]*o.a[kk];kk+=n;}res.a[ii+j]=t;}}res}}
impl Add for Mat{type Output=Self;fn add(mut self,o:Self)->Self{self+=o;self}}
impl Sub for Mat{type Output=Self;fn sub(mut self,o:Self)->Self{self-=o;self}}
impl MulAssign for Mat{fn mul_assign(&mut self,a:Self){*self=self.clone()*a;}}
impl AddAssign for Mat{fn add_assign(&mut self,o:Self){assert!(self.n==o.n);for(x,y)in self.a.iter_mut().zip(o.a.into_iter()){*x+=y;}} }
impl SubAssign for Mat{fn sub_assign(&mut self,o:Self){assert!(self.n==o.n);for(x,y)in self.a.iter_mut().zip(o.a.into_iter()){*x-=y;}} }
impl PartialEq for Mat{fn eq(&self,o:&Self)->bool{self.n==o.n&&self.a==o.a}}impl Eq for Mat{}
// }}}

fn main() {
	let mut rin = reader();
	let mut rout = writer();

	let n = rin.l();
	let m = rin.u();
	let mut mat = Mat::new(m);
	for i in 1..m {
		*mat.at_mut(i,i-1) = Z1;
	}
	*mat.at_mut(0,0) = Z1;
	*mat.at_mut(0,m-1) = Z1;
	let mat = mat.pow(n as u64);
	let sol = mat.at(0,0);
	writeln!(rout, "{}", sol).ok();
}


use std::io::{self, BufReader};
use std::io::prelude::*;
use std::collections::HashMap;

fn insert_dist(dist: i32, c: char, dist_map: &mut HashMap<char, i32>, diff: i32) {
    if dist <= (13 + diff) {
        dist_map.insert(c, (dist - diff).abs());
    } else {
        dist_map.insert(c, 26 + diff - dist);
    }
}

fn solve(input: &mut dyn Read, output: &mut dyn Write) {
    let mut reader = BufReader::new(input);
    let mut input = String::new();
    let mut dist_a: HashMap<char, i32> = HashMap::new();
    let mut dist_c: HashMap<char, i32> = HashMap::new();
    let mut dist_t: HashMap<char, i32> = HashMap::new();
    let mut dist_g: HashMap<char, i32> = HashMap::new();

    for (i, c) in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().enumerate() {
        let dist = i as i32;
        insert_dist(dist, c, &mut dist_a, 0);
        insert_dist(dist, c, &mut dist_c, 2);
        if dist <= 6 {
            dist_t.insert(c, 7 + dist);
        } else {
            dist_t.insert(c, (dist - 19).abs());
        }
        insert_dist(dist, c, &mut dist_g, 6);
    }
    // for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars() {
    //     println!("{} {}", c, dist_t[&c]);
    // }

    reader.read_line(&mut input).unwrap();
    let n: usize = input.trim().parse().unwrap();

    input.clear();
    reader.read_line(&mut input).unwrap();
    let s = input.trim();
    // println!("{:?}", s);

    let char_vec: Vec<char> = s.chars().collect();
    let mut min_sum = -1;
    for i in 0..n-3 {
        let sum = dist_a.get(&char_vec[i]).expect("has values") +
        dist_c.get(&char_vec[i + 1]).expect("has values") +
        dist_t.get(&char_vec[i + 2]).expect("has values") +
        dist_g.get(&char_vec[i + 3]).expect("has values");

        if min_sum == -1 || sum < min_sum {
            min_sum = sum;
        }
    }

    // for c in s.chars() {
    //     println!("{:?}", c);
    // }

    writeln!(output, "{}", min_sum).expect("correct output");

}

fn main() {
    solve(&mut io::stdin(), &mut io::stdout());
}


use std::io;

static ALPHABET: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

fn find_number_of_ops(length_of_string: usize, s: String) -> usize {
    let mut number_of_ops = vec![];
    for i in 0..length_of_string-3 {
        let substring = &s[i..i+4];
        let mut ops = 0;
        for (index_of_letter_in_substring, letter) in substring.chars().enumerate() {
            if letter != "ACTG".chars().nth(index_of_letter_in_substring).unwrap() {
                // number of operations is not zero for this letter
                let position_of_letter_in_alphabet = ALPHABET.find(letter).unwrap();
                let position_of_target_in_alphabet = ALPHABET.find("ACTG".chars().nth(index_of_letter_in_substring).unwrap()).unwrap();
                let x: usize = (position_of_letter_in_alphabet as isize - position_of_target_in_alphabet as isize).abs() as usize;
                let y: usize = 26 - (position_of_target_in_alphabet as isize - position_of_letter_in_alphabet as isize).abs() as usize;
                ops += if x < y {x} else {y};
            }
            if index_of_letter_in_substring == 3 {
                number_of_ops.push(ops);
            }
        }
    }
    let mut minimum_ops = number_of_ops[0];
    for ops in number_of_ops.iter() {
        if ops < &minimum_ops {
            minimum_ops = *ops;
        }
    }
    minimum_ops
}

fn main() {
    let mut length_of_string = String::new();
    io::stdin().read_line(&mut length_of_string).unwrap();
    let length_of_string: usize = length_of_string.trim().parse().unwrap();
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    println!("{}", find_number_of_ops(length_of_string, s.trim().to_string()));
}


use std::io::{self, BufReader};
use std::io::prelude::*;
use std::collections::HashMap;

fn insert_dist(dist: i32, c: char, dist_map: &mut HashMap<char, i32>, diff: i32) {
    if dist <= (13 + diff) {
        dist_map.insert(c, (dist - diff).abs());
    } else {
        dist_map.insert(c, 26 + diff - dist);
    }
}

fn solve(input: &mut dyn Read, output: &mut dyn Write) {
    let mut reader = BufReader::new(input);
    let mut input = String::new();
    let mut dist_a: HashMap<char, i32> = HashMap::new();
    let mut dist_c: HashMap<char, i32> = HashMap::new();
    let mut dist_t: HashMap<char, i32> = HashMap::new();
    let mut dist_g: HashMap<char, i32> = HashMap::new();

    for (i, c) in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().enumerate() {
        let dist = i as i32;
        insert_dist(dist, c, &mut dist_a, 0);
        insert_dist(dist, c, &mut dist_c, 2);
        if dist <= 6 {
            dist_t.insert(c, 7 + dist);
        } else {
            dist_t.insert(c, (dist - 19).abs());
        }
        insert_dist(dist, c, &mut dist_g, 6);
    }
    // for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars() {
    //     println!("{} {}", c, dist_t[&c]);
    // }

    reader.read_line(&mut input).unwrap();
    let n: usize = input.trim().parse().unwrap();

    input.clear();
    reader.read_line(&mut input).unwrap();
    let s = input.trim();
    // println!("{:?}", s);

    let char_vec: Vec<char> = s.chars().collect();
    let mut min_sum = i32::MAX;
    for i in 0..n-3 {
        let sum = dist_a.get(&char_vec[i]).expect("has values") +
        dist_c.get(&char_vec[i + 1]).expect("has values") +
        dist_t.get(&char_vec[i + 2]).expect("has values") +
        dist_g.get(&char_vec[i + 3]).expect("has values");

        if sum < min_sum {
            min_sum = sum;
        }
    }

    // for c in s.chars() {
    //     println!("{:?}", c);
    // }

    writeln!(output, "{}", min_sum).expect("correct output");

}

fn main() {
    solve(&mut io::stdin(), &mut io::stdout());
}


#[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 {
            ans = min(ans, 10 * (index - m).abs());
        }
        index += 1;
    }
    println!("{}", ans);
}


// ---------- 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(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
*/

#[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 {
        self.pow(MOD - 2)
    }
    pub fn comb(n: u32, k: u32) -> ModInt {
        if k > n {
            return ModInt::zero();
        }
        let k = std::cmp::min(k, n - k);
        let mut nu = ModInt::one();
        let mut de = ModInt::one();
        for i in 0..k {
            nu *= ModInt(n - i);
            de *= ModInt(i + 1);
        }
        nu * de.inv()
    }
}

#[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 ModInt ----------
//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: usize,
        s: chars,
    }
    let len = s.len();
    let mut index = vec![vec![0; len + 1]; 2];
    for i in 0..len {
        if s[i] == '(' {
            index[0][i] = i + 1;
            let mut t = s.clone();
            t[i] = ')';
            for k in (1..=i).rev() {
                if s[0..k] == t[(i + 1 - k)..(i + 1)] {
                    index[1][i] = k;
                    break;
                }
            }
        } else {
            index[1][i] = i + 1;
            let mut t = s.clone();
            t[i] = '(';
            for k in (1..=i).rev() {
                if s[0..k] == t[(i + 1 - k)..(i + 1)] {
                    index[0][i] = k;
                    break;
                }
            }
        }
    }
    index[0][len] = len;
    index[1][len] = len;
    let mut dp = vec![vec![ModInt::zero(); n + 1]; len + 1];
    dp[0][0] = ModInt::one();
    for _ in 0..(2 * n) {
        let mut next = vec![vec![ModInt::zero(); n + 1]; len + 1];
        for j in 0..=len {
            for k in 0..=n {
                let v = dp[j][k];
                if k < n {
                    next[index[0][j]][k + 1] += v;
                }
                 if k > 0 {
                    next[index[1][j]][k - 1] += v;
                }
            }
        }
        dp = next;
    }
    let ans = dp[len][0].0;
    println!("{}", ans);
}

fn main() {
    run();
}


#![allow(unused_imports)]
use std::io::*;
use std::cmp::*;
use std::collections::*;

macro_rules! debug(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

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

impl Scanner {

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

   fn process(&mut self) -> String {
      if self.buffer.len() == 0 {
         let mut input = String::new();
         std::io::stdin().read_line(&mut input).ok();
         for word in input.split_whitespace() {
            self.buffer.push_back(word.to_string())
         }
      }

      self.buffer.pop_front().unwrap()
   }

   #[allow(dead_code)]
   fn next<T : std::str::FromStr >(&mut self) -> T {
      self.process().parse::<T>().ok().unwrap()
   }

   #[allow(dead_code)]
   fn next_char(&mut self) -> char {
      self.process().into_bytes()[0] as char
   }
}

fn count_char(x : char, y : char, z : char, target : char) -> i32 {
   (if x == target {1} else {0})
      + if y == target {1} else {0}
      + if z == target {1} else {0}
}

fn check_board(board: &[[char; 4];4]) -> String {
   // horizontal...
   for i in 0..4 {
      for j in 1..3 {
         let x_count = count_char(board[i][j], board[i][j+1], board[i][j-1], 'x');
         let e_count = count_char(board[i][j], board[i][j+1], board[i][j-1], '.');

         if x_count == 3 || (x_count == 2 && e_count == 1) {
            return "YES".to_string();
         }
      }
   }

   // vertical...
   for j in 0..4 {
      for i in 1..3 {
         let x_count = count_char(board[i][j], board[i+1][j], board[i-1][j], 'x');
         let e_count = count_char(board[i][j], board[i+1][j], board[i-1][j], '.');

         if x_count == 3 || (x_count == 2 && e_count == 1) {
            return "YES".to_string();
         }
      }
   }

   // left-diagonal...
   for j in 0..2 {
      for i in 0..2 {
         let x_count = count_char(board[i][j], board[i+1][j+1], board[i+2][j+2], 'x');
         let e_count = count_char(board[i][j], board[i+1][j+1], board[i+2][j+2], '.');

         if x_count == 3 || (x_count == 2 && e_count == 1) {
            return "YES".to_string();
         }
      }
   }

   // right-diagonal..
   for j in 0..2 {
      for i in 2..4 {
         let x_count = count_char(board[i][j], board[i-1][j+1], board[i-2][j+2], 'x');
         let e_count = count_char(board[i][j], board[i-1][j+1], board[i-2][j+2], '.');

         if x_count == 3 || (x_count == 2 && e_count == 1) {
            return "YES".to_string();
         }
      }
   }

   return "NO".to_string();
}

fn main() {
   let mut sin = Scanner::new();

   let mut board = [['.';4];4];

   for i in 0..4 {
      let line = sin.next::<String>().into_bytes();
      for j in 0..4 {
         board[i][j] = line[j] as char;
      }
   }

   println!("{}", check_board(&board));
}


use std::io;

fn solve() -> Vec<String> {
    let mut input = "".split_ascii_whitespace();
    let mut read = || loop {
        if let Some(word) = input.next() {
            break word;
        }
        input = {
            let mut input = "".to_owned();
            io::stdin().read_line(&mut input).unwrap();
            if input.is_empty() {
                panic!("reached EOF");
            }
            Box::leak(input.into_boxed_str()).split_ascii_whitespace()
        };
    };
    macro_rules! read(($ty:ty) => (read().parse::<$ty>().unwrap()));

    let mut rr = vec!["".to_string(); 0];

    let t = 1;
    for _ in 0..t {
        let n = read!(usize);
        let mut a = vec![0; n];
        for i in 0..n {
            a[i] = read!(usize);
        }

        a.sort();
        let mut v = vec![false; n];
        let mut r = 0;
        for i in 0..n {
            if v[i] {
                continue;
            }
            v[i] = true;
            r += 1;
            let mut c = 1;
            for j in (i + 1)..n {
                if !v[j] && a[j] >= c {
                    v[j] = true;
                    c += 1;
                }
            }
        }

        rr.push(format!("{}", r));
    }

    rr
}

#[allow(dead_code)]
fn main() {
    let output = solve();
    println!("{}", output.join("\n"));
}


//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 dfs(a: &[u64], k: usize, sup: bool, used: u64, b: &mut Vec<u64>) {
    if k == a.len() {
        b.push(used);
        return;
    }
    let y = if !sup {
        a[k]
    } else {
        6
    };
    for i in 0..=y {
        if used >> i & 1 == 0 {
            dfs(a, k + 1, sup || i < a[k], used | (1 << i), b);
        }
    }
}

fn run() {
    input! {
        n: u64,
        m: u64,
    }
    let mut a = vec![];
    let mut x = m - 1;
    if x == 0 {
        a.push(0);
    } else {
        while x > 0 {
            a.push(x % 7);
            x /= 7;
        }
    }
    a.reverse();
    let mut b = vec![];
    dfs(&a, 0, false, 0, &mut b);
    let sa = a;
    let mut a = vec![];
    let mut x = n - 1;
    if x == 0 {
        a.push(x);
    } else {
        while x > 0 {
            a.push(x % 7);
            x /= 7;
        }
    }
    if a.len() + sa.len() > 7 {
        println!("0");
        return;
    }
    a.reverse();
    let mut c = vec![];
    dfs(&a, 0, false, 0, &mut c);
    let mut ans = 0;
    for b in b.iter() {
        for c in c.iter() {
            if *b & *c == 0 {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


macro_rules! scanln {
    () => ({
        let mut buffer = String::new();
        ::std::io::stdin().read_line(&mut buffer).expect("Unable to read line");
        buffer
    });
    ($($t: ty),+) => ({
        scanln!($($t),+, |c: char| c.is_whitespace())
    });
    ($($t: ty),+, $sp: expr) => ({
        let mut buffer = scanln!();
        let mut iter = buffer.split($sp);
        ($(iter.next().unwrap().parse::<$t>().expect("Unable to parse token")),+)
    });
}

fn main() {
    const MOD: u64 = 1000000009;
    let mut dp = vec![[[[[0u64; 2]; 32]; 32]; 32]; 1001].into_boxed_slice();
    let (n, h) = scanln!(usize, usize);
    dp[0][0][0][0][0] = 1;

    for i in 1..=n {
        for a in 0..=(h + 1) {
            for b in a..=(h + 1) {
                for c in b..=(h + 1) {
                    for y in 0..2 {
                        let val = dp[(i - 1) as usize][a][b][c][y];
                        let ta = if a + 1 > h { h + 1 } else { a + 1 };
                        let tb = if b + 1 > h { h + 1 } else { b + 1 };
                        let tc = if c + 1 > h { h + 1 } else { c + 1 };
                        dp[i][ta][tb][tc][y] += val;
                        if y == 0 {
                            dp[i][1][tb][tc][(ta > h) as usize] += val;
                            dp[i][1][ta][tc][(tb > h) as usize] += val;
                            dp[i][1][ta][tb][(tc > h) as usize] += val;
                        } else {
                            dp[i][tb][tc][h + 1][(ta > h) as usize] += val;
                            dp[i][ta][tc][h + 1][(tb > h) as usize] += val;
                            dp[i][ta][tb][h + 1][(tc > h) as usize] += val;
                        }
                    }
                }
            }
        }
    }

    let mut res = 0;

    for a in 0..=(h + 1) {
        for b in a..=(h + 1) {
            for c in b..=(h + 1) {
                for y in 0..2 {
                    if (a < h) || (b < h) || (c < h) || (y == 0) {
                        res += dp[n][a][b][c][y];
                    }
                }
            }
        }
    }

    println!("{}", res % MOD);
}


macro_rules! scanln {
    () => ({
        let mut buffer = String::new();
        ::std::io::stdin().read_line(&mut buffer).expect("Unable to read line");
        buffer
    });
    ($($t: ty),+) => ({
        scanln!($($t),+, |c: char| c.is_whitespace())
    });
    ($($t: ty),+, $sp: expr) => ({
        let mut buffer = scanln!();
        let mut iter = buffer.split($sp);
        ($(iter.next().unwrap().parse::<$t>().expect("Unable to parse token")),+)
    });
}

fn main() {
    const MOD: u64 = 1000000009;
    let mut dp = vec![[[[[0u64; 2]; 32]; 32]; 32]; 1001].into_boxed_slice();
    let (n, h) = scanln!(usize, usize);
    dp[0][0][0][0][0] = 1;

    for i in 1..=n {
        for a in 0..=(h + 1) {
            for b in a..=(h + 1) {
                for c in b..=(h + 1) {
                    for y in 0..2 {
                        dp[(i - 1) as usize][a][b][c][y] %= MOD;
                        let val = dp[(i - 1) as usize][a][b][c][y];
                        let ta = if a + 1 > h { h + 1 } else { a + 1 };
                        let tb = if b + 1 > h { h + 1 } else { b + 1 };
                        let tc = if c + 1 > h { h + 1 } else { c + 1 };
                        dp[i][ta][tb][tc][y] += val;
                        if y == 0 {
                            dp[i][1][tb][tc][(ta > h) as usize] += val;
                            dp[i][1][ta][tc][(tb > h) as usize] += val;
                            dp[i][1][ta][tb][(tc > h) as usize] += val;
                        } else {
                            dp[i][tb][tc][h + 1][(ta > h) as usize] += val;
                            dp[i][ta][tc][h + 1][(tb > h) as usize] += val;
                            dp[i][ta][tb][h + 1][(tc > h) as usize] += val;
                        }
                    }
                }
            }
        }
    }

    let mut res = 0;

    for a in 0..=(h + 1) {
        for b in a..=(h + 1) {
            for c in b..=(h + 1) {
                for y in 0..2 {
                    if (a < h) || (b < h) || (c < h) || (y == 0) {
                        res += dp[n][a][b][c][y];
                    }
                }
            }
        }
    }

    println!("{}", res % MOD);
}


#[allow(unused_imports)]
use std::io;
use std::mem::size_of_val;
use std::cmp::{max, min};
use std::rc::Rc;
use std::collections::btree_map::BTreeMap;
use std::io::{Write, BufRead};
use std::collections::{HashMap, BTreeSet};
use std::ptr::write_volatile;
use std::process::exit;
use std::thread;

#[allow(dead_code)]
fn gets() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

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

#[allow(unused)]
fn read_array_i32() -> Vec<i32> {
    let mut string: String = String::new();
    std::io::stdin().read_line(&mut string).unwrap();
    string.split_whitespace().map(|x| x.parse::<i32>().unwrap()).collect()
}

#[allow(unused_macros)]
macro_rules! read_array {
    ( $ty:ty, ... ) => {
        gets().split_whitespace().map(|x| x.parse::<$ty>().unwrap())
    };
    ( $($ty:ty),* ) => {{
        let line = gets();
        let mut it = line.split_whitespace();
        ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )
    }}
}

// mod math;
// mod binary_search;
// mod graph;
// mod structure;
// mod fibonacci;
// mod string;
// mod permutations;
// mod patterns;

#[allow(dead_code)]
fn memory_properties<T>(value: &T)
    where
        T: std::fmt::Display + ?Sized,
{
    println!(
        "Variable address in memory = {:p}, Allocated bytes for type = {}",
        value,
        size_of_val(value)
    );
}

#[allow(unused_macros)]
macro_rules! sum {
    ($($x:expr), *) => {
        {
            let mut res = 0;
            $(res += $x;)*
            res
        }
    };
}

static mut array: [[u8;51];51] = [[0u8; 51]; 51];

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());

    let mut res = 0;
    let s = gets();
    let mut seq = BTreeSet::<&str>::new();
    for i in 0..s.len() {
        for j in i + 1 .. s.len() + 1 {
            if seq.contains(&s[i..j]){
                res = max(res, j - i);
            } else {
                seq.insert(&s[i..j]);
            }
        }
    }
    writeln!(out, "{}", res);
    // writeln!(out, "{}", "Hello Rust").unwrap();
}


#[macro_export]
macro_rules! scanln {
  ($($var:ident : $ty:path),+) => {
    $(let $var: $ty;)+
    {
      use std::io;
      let mut __buf = String::new();
      io::stdin().read_line(&mut __buf).unwrap();
      let mut eles = __buf.split_whitespace();
      $($var = Scan::scan(&mut eles);)+
    }
  }
}

pub trait Scan {
  fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str>;
}

macro_rules! impl_scan_single {
  ($ty:ty) => {
    impl Scan for $ty {
      fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
        let next = eles.next().unwrap();
        match next.parse() {
          Ok(res) => res,
          Err(_) => panic!()
        }
      }
    }
  }
}

impl_scan_single!(u8);
impl_scan_single!(u16);
impl_scan_single!(u32);
impl_scan_single!(u64);
impl_scan_single!(usize);
impl_scan_single!(i8);
impl_scan_single!(i16);
impl_scan_single!(i32);
impl_scan_single!(i64);
impl_scan_single!(isize);
impl_scan_single!(f32);
impl_scan_single!(f64);
impl_scan_single!(String);

const __IMPL_SCAN_FOR_VEC: () = {
  use std::str::FromStr;
  impl<T> Scan for Vec<T> where T: FromStr {
    fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
      eles.map(|str| match str.parse() {
        Ok(res) => res,
        Err(_) => panic!()
      }).collect()
    }
  }
};

// -----------------------------------------------------------------------------

fn main() {
  scanln!(c: u32, v0: u32, v1: u32, a: u32, l: u32);
  let mut speed = v0;
  let mut pages = 0;
  let mut days = 0;
  loop {
    days += 1;
    pages += speed;
    if pages >= c { break; }
    speed = std::cmp::min(speed + a, v1);
    pages -= l;
  }
  println!("{}", days);
}


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 (l, r) = parse_line!(u64, u64);
    let mut bit = 1u64 << 63;
    while bit != 0 && l & bit == r & bit {
        bit >>= 1;
    }
    if bit == 0 {
        writeln!(writer, "0").unwrap();
    }else{
        writeln!(writer, "{}", bit | (bit - 1)).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);
    }
}


//spnauti-rusT
use std::io::*;
use std::str::{self,*};
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[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 {
    ($($v:ident),* = $i:ident.$f:ident $a:tt) => {
        $( let $v = $i.$f$a; )*
    };
    ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {
        $( let $v:$t = $i.$f$a; )*
    };
}
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);

    l!(l,r: i64 = input.p());
    if l == r {
        println!("0");
    } else {
        let mut x = l ^ r;
        for i in 0..=5 {
            x |= x >> (1 << i);
        }
        println!("{}", x);
    }
}


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


// ---------- begin ModInt ----------
const MOD: u32 = 998_244_353;

#[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))
    }
}

#[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 {
        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 ----------

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let p: usize = it.next().unwrap().parse().unwrap();
    let s: usize = it.next().unwrap().parse().unwrap();
    let r: usize = it.next().unwrap().parse().unwrap();
    let pc = Precalc::new(s + p);
    let mut ans = ModInt::zero();
    for v in r..=s {
        if p * v == s {
            ans += pc.inv(p);
        }
        for k in 1..p {
            if k * v > s {
                break;
            }
            let rem = s - k * v;
            let q = p - k;
            let mut way = ModInt::zero();
            let mut sign = ModInt::one();
            for x in 0..=q {
                if x * v > rem {
                    break;
                }
                way += sign * pc.comb(rem - x * v + q - 1, q - 1) * pc.comb(q, x);
                sign = -sign;
            }
            ans += pc.comb(p - 1, k - 1) * way * pc.inv(k);
        }
    }
    ans *= pc.comb(s - r + p - 1, p - 1).inv();
    println!("{}", ans);
}

fn main() {
    run();
}


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

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input!{$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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

const MOD: i64 = 1000000007;

// assume a, b positive
fn gcd(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (1, 0, a)
    }
    else {
        let (x, y, d) = gcd(b, a%b); // xb + y(a-qb) = d   where q = a/b
        (y, x-y*(a/b), d)
    }
}

fn factorial_mod(a: i64) -> i64 {
    if a == 0 {
        1
    }
    else {
        a * factorial_mod(a-1) % MOD
    }
}

fn binomial_mod(n: i64, k: i64) -> i64 {
    let a = factorial_mod(k);
    let b = factorial_mod(n-k);
    let (inv_a, _, _) = gcd(a, MOD);
    let (inv_b, _, _) = gcd(b, MOD);
    let result = factorial_mod(n) * inv_a % MOD * inv_b % MOD;
    if result < 0 { result + MOD } else { result }
}

fn main() {
    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! {next,
        n: i64,
        m: i64,
        k: i64,
    }
    println!("{}", binomial_mod(n-1,2*k)*binomial_mod(m-1,2*k) % MOD);
    // println!("{:?}", matches);

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


//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: usize,
        m: usize,
    }
    let ans = if n == m {
        0
    } else if m <= 1 {
        1
    } else if m <= n / 2 {
        m
    } else {
        n - m
    };
    println!("{}", ans);
}

fn main() {
    run();
}


#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn main() {
    let mut sc = Scanner::new();
    let mut cost = vec![vec![0; 3]; 3];
    let mut memo = vec![vec![vec![0; 3]; 3]; 42];

    for i in 0..3 {
        for j in 0..3 {
            cost[i][j] = sc.cin::<i64>();
        }
    }

    for i in 0..3 {
        for j in 0..3 {
            if i == j { continue }
            let k = 3 - i - j;
            memo[1][i][j] = min(cost[i][k] + cost[k][j], cost[i][j]);
        }
    }

    let n: usize = sc.cin();

    for m in 2..(n+1) {
        for i in 0..3 {
            for j in 0..3 {
                if i == j { continue }
                let k = 3 - i - j;
                memo[m][i][j] =
                    min(
                    memo[m-1][i][k] + memo[m-1][k][j] + cost[i][j],
                    memo[m-1][i][j] + cost[i][k] + memo[m-1][j][i] + cost[k][j] + memo[m-1][i][j]);
            }
        }
        // trace!(m);
        // for i in 0..3 {
        //     for j in 0..3 {
        //         print!("{} ", memo[m][i][j]);
        //     }
        //     println!("");
        // }
    }

    println!("{}", memo[n][0][2]);

}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}


fn read_line(mut buffer: &mut String) -> Vec<usize> {
    std::io::stdin().read_line(&mut buffer).expect("Error while reading input.");
    let data = buffer.split_whitespace().map(|x| x.parse::<usize>().unwrap()).collect();
    buffer.clear();
    data
}

fn get_index(i: usize, n: usize) -> String {
    let bin_str = format!("{:0width$b}", i, width = n);
    bin_str
}

fn limit(n: usize) -> usize {
    let mut n_bin = String::with_capacity(n);
    for _i in 0..n {
        n_bin.push('1');
    }
    let limit = usize::from_str_radix(&n_bin, 2).unwrap();
    limit
}
fn calculate(index: &String, c: &Vec<usize>, min: usize, max: usize, diff: usize) -> usize {
    let mut sum = 0;
    let mut cmin = 10_usize.pow(6) + 1;
    let mut cmax = 0;
    for (i, ch) in index.chars().enumerate() {
       if ch == '1' {
            if c[i] > cmax {
                cmax = c[i];
            }
            if c[i] < cmin {
                cmin = c[i];
            }
            sum += c[i];
       }
    }
    // need to find min and max
    if sum >= min && sum <= max && (cmax - cmin) >= diff {
       return 1
    }
    0
}

fn get_count(index: &String) -> usize {
    let mut count = 0;
    for ch in index.split("") {
        if ch == "1" {
            count += 1;
        }
    }
    count
}

fn main() {
    let mut buffer = String::new();

    let d = read_line(&mut buffer);
    //println!("D: {:?}", d);

    let (n, min, max, diff) = (d[0], d[1], d[2], d[3]);

    let c = read_line(&mut buffer);
    //println!("c: {:?}", c);

    let limit = limit(n);
    let mut result = 0;

    for i in 1..=limit {
        let index = get_index(i, n);
        let count = get_count(&index);
        if count > 1 {
            //println!("{:?}", index);
            let res = calculate(&index, &c, min, max, diff);
            if res == 1 {
                //println!("now");
            }
            result += res;
        }
    }
    println!("{}", result);
}


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

fn main() {
    let mut line = String::new();
    let stdin = io::stdin();
    stdin
        .lock()
        .read_line(&mut line)
        .expect("could not read line!");

    let line = line.trim();
    let path = line
        .split('/')
        .filter(|s| !s.is_empty())
        .collect::<Vec<&str>>();

    println!("/{}", path.join("/"));
}


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