#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::fs::File;
#[allow(unused_imports)]
use std::io::prelude::*;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Stdin, Stdout, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

type BoxResult<T> = Result<T, Box<std::error::Error>>;

fn main() {
    let mut scanner = Scanner::new(stdin());
    let s = scanner.read_chars().unwrap();
    let t = scanner.read_chars().unwrap();
    let mut maximum = 0;
    for i in 0..s.len() {
        for j in i..s.len() {
            if judge(&s, &t, i, j) {
                maximum = max(j - i + 1, maximum);
            }
        }
    }
    println!("{}", maximum);
}

fn judge(s: &[char], t: &[char], start: usize, end: usize) -> bool {
    let mut index = 0;
    for i in 0..s.len() {
        if i >= start && i <= end {
            continue;
        }
        if s[i] == t[index] {
            index += 1;
        }
        if index == t.len() {
            break;
        }
    }
    index == t.len()
}

#[allow(dead_code)]
struct Scanner<R> {
    reader: BufReader<R>,
    buffer: String,
}

impl<R> Scanner<R>
where
    R: Read,
{
    #[allow(dead_code)]
    fn new(inner: R) -> Scanner<R> {
        let reader = BufReader::new(inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }

    #[allow(dead_code)]
    fn with_capacity(capacity: usize, inner: R) -> Scanner<R> {
        let reader = BufReader::with_capacity(capacity, inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }

    #[allow(dead_code)]
    fn read<T>(&mut self) -> BoxResult<T>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed = self.buffer.trim().parse()?;
        self.buffer.clear();
        Ok(parsed)
    }

    #[allow(dead_code)]
    fn read_vector<T>(&mut self) -> BoxResult<Vec<T>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed_vec = self
            .buffer
            .trim()
            .split_whitespace()
            .map(|s| s.parse())
            .collect::<Result<Vec<_>, _>>()?;
        self.buffer.clear();
        Ok(parsed_vec)
    }

    #[allow(dead_code)]
    fn read_matrix<T>(&mut self, lines: usize) -> BoxResult<Vec<Vec<T>>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        let mut parsed_matrix = vec![];
        for _ in 0..lines {
            self.reader.read_line(&mut self.buffer)?;
            parsed_matrix.push(
                self.buffer
                    .trim()
                    .split_whitespace()
                    .map(|s| s.parse())
                    .collect::<Result<Vec<_>, _>>()?,
            );
            self.buffer.clear();
        }
        Ok(parsed_matrix)
    }

    #[allow(dead_code)]
    fn read_chars(&mut self) -> BoxResult<Vec<char>> {
        self.reader.read_line(&mut self.buffer)?;
        let chars = self.buffer.trim().chars().collect::<Vec<_>>();
        self.buffer.clear();
        Ok(chars)
    }
}


//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! {
        s: chars,
        t: chars,
    }
    let mut dp = vec![0; t.len() + 1];
    dp[t.len()] = s.len();
    let mut j = t.len() - 1;
    for i in (0..s.len()).rev() {
        if s[i] == t[j] {
            dp[j] = i;
            j -= 1;
        }
        if j >= t.len() {
            break;
        }
    }
    let mut ans = dp[0];
    let mut j = 0;
    for i in 0..s.len() {
        if s[i] == t[j] {
            j += 1;
            ans = std::cmp::max(ans, dp[j] - i - 1);
        }
        if j >= t.len() {
            break;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]

use std::char::*;
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;

macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::f64;

fn min<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { a }
    else { b }
}

fn max<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { b }
    else { a }
}

const MAX:usize = 30;
const INF:i64 = std::i64::MAX;
const MOD:i64 = 1e9 as i64 + 7;

fn main() {
    //let t:usize = read();

    //'outer: for _ in 0..t {
        let s:Vec<char> = read::<String>().chars().collect();
        let t:Vec<char> = read::<String>().chars().collect();

        let mut ans = 0;
        // s の substring s[i..j] を考える
        for i in 0..s.len() {
            for j in i..s.len()+1 {
                //debug!(i,j);
                // substring を除いた文字列 s[0..i] + s[j..] を考える
                let mut ss = vec![];
                for k in 0..i { ss.push(s[k]); }
                for k in j..s.len() { ss.push(s[k]); }
                // ss の subsequence に t が含まれるか判定する
                let mut idx = 0;
                for k in 0..ss.len() {
                    if idx >= t.len() { break; }
                    if ss[k] == t[idx] {
                        idx += 1;
                    }
                }
                if idx >= t.len() {
                    //debug!(i,j,ss);
                    ans = max(ans, j-i);
                }
            }
        }
        println!("{}", ans);

   //}
}

/*

*/


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

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut t = read::<String>().chars().collect::<Vec<_>>();

    let mut fastest_poses = vec![];
    let mut slowest_poses = vec![];
    for i in 0..2 {
        let mut poses;
        if i == 0 {
            poses = &mut fastest_poses;
        } else {
            poses = &mut slowest_poses;
        }
        let mut alpha_poses = vec![vec![]; 26];
        if i == 0 {
            for j in 0..s.len() {
                let ch_idx = s[j].to_digit(36).unwrap() as usize - 10;
                alpha_poses[ch_idx].push(j);
            }
        } else {
            for j in (0..s.len()).rev() {
                let ch_idx = s[j].to_digit(36).unwrap() as usize - 10;
                alpha_poses[ch_idx].push(s.len() - 1 - j);
            }
        }

        if i == 1 {
            t.reverse();
        }

        let mut prev = 0;
        for (j, &tch) in t.iter().enumerate() {
            let tch_idx = tch.to_digit(36).unwrap() as usize - 10;
            let mut next;
            if j == 0 {
                next = alpha_poses[tch_idx][alpha_poses[tch_idx].lower_bound(&prev)];
            } else {
                next = alpha_poses[tch_idx][alpha_poses[tch_idx].upper_bound(&prev)];
            }
            poses.push(next);
            prev = next;
        }
    }
    let mut slowest_poses = slowest_poses
        .iter()
        .map(|x| s.len() - 1 - x)
        .collect::<Vec<_>>();
    slowest_poses.reverse();

    debug!(fastest_poses);
    debug!(slowest_poses);

    let mut ans = 0;
    for l in 0..s.len() {
        let found = fastest_poses.lower_bound(&l);
        if found == slowest_poses.len() {
            ans = max(ans, s.len() - l);
            continue;
        }
        ans = max(ans, slowest_poses[found] - l);
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}


use std::io::Write;

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>
}
impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            std::io::stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let stdout = std::io::stdout();
    let mut out = std::io::BufWriter::new(stdout.lock());
    let mut scan = Scanner::default();

    // Read input
    let s: Vec<u8> = scan.next::<String>().bytes().collect();
    let t: Vec<u8> = scan.next::<String>().bytes().collect();

    let mut max_prefix: Vec<usize> = vec![0; s.len() + 1];
    max_prefix[0] = 0;
    for i in 1..(s.len()+1) {
        max_prefix[i] = max_prefix[i-1];
        if max_prefix[i] < t.len() && t[max_prefix[i]] == s[i-1] {
            max_prefix[i] += 1;
        }
    }

    let mut max_suffix: Vec<usize> = vec![0; s.len() + 1];
    max_suffix[0] = 0;
    for i in 1..(s.len()+1) {
        max_suffix[i] = max_suffix[i-1];
        if max_suffix[i] < t.len() && t[t.len()-1-max_suffix[i]] == s[s.len()-i] {
            max_suffix[i] += 1;
        }
    }

    let can_substr = |len| {
        for prefix in 0..(s.len()+1-len) {
            let suffix = s.len() - prefix - len;
            if max_prefix[prefix] + max_suffix[suffix] >= t.len() {
                return true;
            }
        }
        return false;
    };

    let mut l: usize = 0;
    let mut r: usize = s.len() - t.len() + 1;
    while r - l > 1 {
        let m = (l + r) / 2;
        if can_substr(m) {
            l = m;
        } else {
            r = m;
        }
    }
    writeln!(out, "{}", l).unwrap();
}


use std::io::{stdin, stdout, Write, BufReader, BufRead, Read};

fn gcd(mut a: u64, mut b: u64) -> u64 {
    while b != 0 {
        a %= b;
        let c = a;
        a = b;
        b = c;
    }
    return a;
}

//let n = {
//        let mut line = String::new();
//        input.read_line(&mut line).unwrap();
//        let mut whitespace = line.split_ascii_whitespace();
//        whitespace.next().unwrap().parse::<usize>().unwrap()
//    };
//
//    let mut line = String::new();
//    input.read_line(&mut line).unwrap();
//    let mut split = line.split_ascii_whitespace();
//    let mut a = split.next().unwrap().parse().unwrap();
//    for i in split {
//        let b = i.parse().unwrap();
//        a = gcd(b, a);
//    }
//
//    let mut count = 0;
//    for i in 1..=a {
//        if a % i == 0 {
//            count += 1;
//        }
//    }

fn solve(input: &mut BufRead, output: &mut Write) {
    let mut input = BufReader::new(input);

    let mut first = String::with_capacity(201);
    let mut second = String::with_capacity(201);

    input.read_line(&mut first).unwrap();
    input.read_line(&mut second).unwrap();

    let s = first.trim().as_bytes();
    let t = second.trim().as_bytes();

    let first = s.iter().position(|&it| it == t[0]).unwrap();
    let second = s.iter().rev().position(|&it| it == t[t.len() - 1]).unwrap();

    let mut answ = first.max(second);

    let mut pos = vec![first; t.len()];
    let mut pos_rev = vec![second; t.len()];

    let mut prev = first;
    for i in 0..t.len() {
        let pos1 = s.iter().skip(prev).position(|&it| it == t[i]).unwrap();
        prev += pos1;
        pos[i] = prev;
        prev += 1;
    }

    let mut rev = second;
    for i in (0..t.len()).rev() {
        let pos1 = s.iter().rev().skip(rev).position(|&it| it == t[i]).unwrap();
        rev += pos1;
        pos_rev[i] = rev;
        rev += 1;
    }

    for i in 0..t.len() - 1 {
        answ = answ.max((s.len() - pos_rev[i + 1] - 2) - pos[i])
    }

    answ = answ.max(s.len() - pos[pos.len() - 1] - 1);
    answ = answ.max(s.len() - pos_rev[0] - 1);

    writeln!(output, "{}", answ).unwrap();
}

fn main() {
    let stdin = stdin();
    let stdout = stdout();
    solve(&mut stdin.lock(), &mut stdout.lock());
}

#[cfg(test)]
mod tests {
    use std::fs::File;
    use solve;
    use std::io::BufReader;

    #[test]
    fn basic_test() {
        let mut f = BufReader::new("bbaba
bb
".as_bytes());
        let mut buf: Vec<u8> = Vec::new();

        solve(&mut f, &mut buf);

        let res = String::from_utf8(buf).unwrap();
        assert_eq!(res, "3\n");
    }

    #[test]
    fn basic_test2() {
        let mut f = BufReader::new("baaba
ab
".as_bytes());
        let mut buf: Vec<u8> = Vec::new();

        solve(&mut f, &mut buf);

        let res = String::from_utf8(buf).unwrap();
        assert_eq!(res, "2\n");
    }

    #[test]
    fn basic_test3() {
        let mut f = BufReader::new("abcde
abcde
".as_bytes());
        let mut buf: Vec<u8> = Vec::new();

        solve(&mut f, &mut buf);

        let res = String::from_utf8(buf).unwrap();
        assert_eq!(res, "0\n");
    }

    #[test]
    fn basic_test4() {
        let mut f = BufReader::new("asdfasdf
fasd
".as_bytes());
        let mut buf: Vec<u8> = Vec::new();

        solve(&mut f, &mut buf);

        let res = String::from_utf8(buf).unwrap();
        assert_eq!(res, "3\n");
    }

}


use std::io::{self, prelude::*};

#[allow(unused_must_use)]
#[allow(unused_assignments)]
#[allow(unused_variables)]
fn solve<B: BufRead, W: Write>(mut scan: Scanner<B>, mut w: W) {
    let k = scan.token::<usize>();
    let l = scan.token::<usize>();
    let m = scan.token::<usize>();
    let n = scan.token::<usize>();
    let d = scan.token::<usize>();

    let mut arr = vec![false; d];

    for i in (0..d).skip(k-1).step_by(k) {
        arr[i] = true;
    }
    for i in (0..d).skip(l-1).step_by(l) {
        arr[i] = true;
    }
    for i in (0..d).skip(m-1).step_by(m) {
        arr[i] = true;
    }
    for i in (0..d).skip(n-1).step_by(n) {
        arr[i] = true;
    }

    let ans: usize = arr.iter().filter(|&e| *e).count();

    writeln!(w, "{}", ans);
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    let reader = Scanner::new(stdin.lock());
    let writer = io::BufWriter::new(stdout.lock());
    solve(reader, writer);
}
#[allow(dead_code)]
fn vector_to_str<T: ToString>(vector: &Vec<T>, separator: &str) -> String {
    use std::fmt::Write;
    let mut ans = String::new();
    for line in vector.iter() {
        write!(&mut ans, "{}{}", line.to_string(), separator).unwrap();
    }
    ans
}
#[allow(dead_code)]
fn matrix_to_str<T: ToString>(matrix: &Vec<Vec<T>>, separator: &str) -> String {
    use std::fmt::Write;
    let mut ans = String::new();
    for line in matrix.iter() {
        for elem in line.iter() {
            write!(&mut ans, "{}{}", elem.to_string(), separator).unwrap();
        }
        write!(&mut ans, "\n").unwrap();
    }
    ans
}
pub struct Scanner<B> {
    reader: B,
    buf_str: Vec<u8>,
    buf_iter: std::str::SplitWhitespace<'static>,
}
impl<B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        Self {
            reader,
            buf_str: Vec::new(),
            buf_iter: "".split_whitespace()
        }
    }
    pub fn token<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = std::str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace()) }
        }
    }
    pub fn get_matrix<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>> {
        // m rows and n columns
        let mut ans: Vec<Vec<T>> = Vec::with_capacity(m);
        for i in 0..m {
            ans.push(Vec::with_capacity(n));
            for _ in 0..n {
                ans[i].push(self.token::<T>());
            }
        }
        ans
    }
    pub fn get_vector<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut ans: Vec<T> = Vec::with_capacity(n);
        for _ in 0..n {
            ans.push(self.token::<T>());
        }
        ans
    }
}


fn main() {
    let (k, l, m, n, d) = {
        let mut bufs: Vec<usize> = Vec::new();
        for _ in 0..5 {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            bufs.push(buf.trim_end().parse().unwrap());
        }
        (bufs[0], bufs[1], bufs[2], bufs[3], bufs[4])
    };

    let mut ans = 0;
    for i in 0..d {
        let num = i + 1;
        if num % k == 0 || num % l == 0 || num % m == 0 || num % n == 0 {
            ans += 1
        }
    }
    println!("{}", ans);
}


#[allow(unused)] use std::io::*;
#[allow(unused)] use std::collections::*;
#[allow(unused)] use std::mem::*;
#[allow(unused)] use std::num::*;
#[allow(unused)] use std::cmp::*;
#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{
    let mut inp = String::new(); stdin().read_line(&mut inp).ok();
    let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();
    let mut cnt : usize = 0;
    fn next<T>(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr
    { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }
    ($(next::<$x>(&mut cnt, &s)), +)
    }}; }
#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{
    let mut inp = String::new(); stdin().read_line(&mut inp).ok();
    let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);
    let mut v = Vec::new(); v.reserve(($n) as usize);
    for st in s { v.push(st.parse::<$T>().unwrap()); } v
    }}; }

///////////////////////////////////////////////////////////////////////////////
fn main()
{
    let k = scan!(i32);
    let l = scan!(i32);
    let m = scan!(i32);
    let n = scan!(i32);
    let v = scan!(i32);
    let mut cnt = 0;
    for i in 1..v+1 {
        if i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 { cnt += 1; }
    }
    println!("{}", cnt);
}


#[allow(unused_imports)]
use std::cmp::{min,max};
use std::collections::{*};
use std::io::{BufWriter, stdin, stdout, Write};
const BITS: usize = 19;

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>
}
impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scanner = Scanner::default();
    let arr: [u64;5] = [scanner.next(), scanner.next(), scanner.next(), scanner.next(), scanner.next()];
    print!["{}", (1..=arr[4]).filter(|x| x % arr[0] == 0 || x % arr[1] == 0 || x % arr[2] == 0 || x % arr[3] == 0).count()];
}


use std::io::*;

fn read<T: std::str::FromStr>(i: &mut StdinLock) -> T {
    let mut s = String::new();
    i.by_ref().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    // initialize stdin
    let sin = std::io::stdin();
    let mut sin = sin.lock();
    let sin = &mut sin;

    let k: u32 = read(sin);
    let l: u32 = read(sin);
    let m: u32 = read(sin);
    let n: u32 = read(sin);
    let d: u32 = read(sin);

    let ans = (1..d + 1)
        .filter(|x| *x % k == 0 || *x % l == 0 || *x % m == 0 || *x % n == 0)
        .count();

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


//spnauti-rust
struct WordReader {
    it : std::vec::IntoIter<String>,
}
#[allow(dead_code)]
impl WordReader {
    fn new<T : std::io::Read>(mut reader : T) -> WordReader {
        let mut s = String::new();
        reader.read_to_string(&mut s).unwrap();
        WordReader { it : s
            .split_ascii_whitespace()
            .map(String::from).collect::<Vec<_>>()
            .into_iter()
        }
    }
    fn from_stdin() -> WordReader {
        WordReader::new(std::io::stdin())
    }
    fn s(&mut self) -> String {
        self.it.next().unwrap()
    }
    fn ab(&mut self) -> Vec<u8> {
        self.it.next().unwrap().into_bytes()
    }
    fn i(&mut self) -> i32 {
        self.it.next().unwrap().parse().unwrap()
    }
}

fn main() {
    let mut input = WordReader::from_stdin();
    let mut a = [0; 4];
    for x in a.iter_mut() {
        *x = input.i();
    }
    let n = input.i();
    let sol = (1..n+1).filter(|x| a.iter().any(|y| x % y == 0)).count();
    println!("{}", sol);
}


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

fn read_line(stdin : &Stdin, line : &mut String) {
    match stdin.read_line(line) {
        Ok(_) => return,
        Err(msg) => panic!("Could not read line! Message: {}.", msg),
    }
}

fn parse_t<T : FromStr>(s : &str) -> T {
    match s.trim().parse() {
        Ok(y) => y,
        Err(_) => panic!("Could not read from string!"),
    }
}

fn read_t<T : FromStr>(stdin : &Stdin) -> T {
    let mut line = String::new();
    read_line(stdin, &mut line);
    parse_t(&line)
}

fn gcd(a : u64, b : u64) -> u64 {
    let mut t_a = if a > b { a } else { b };
    let mut t_b = if t_a == a { b } else { a };
    loop {
        if t_b == 0 {
            return t_a;
        } else {
            let t_a_mod_t_b = t_a % t_b;
            t_a = t_b;
            t_b = t_a_mod_t_b;
        }
    }
}

fn lcm(a : u64, b : u64) -> u64 {
    let g = gcd(a, b);
    (a / g) * b
}

macro_rules! lcm_list {
    ($x:expr) => ($x);
    ($x:expr, $($y:expr),+) => (
        lcm($x, lcm_list!($($y),+))
    )
}

fn num_damaged_dragons(k : u64, l : u64, m : u64, n : u64, d : u64) -> u64 {
    let t_k = d / k;
    let t_l = d / l;
    let t_m = d / m;
    let t_n = d / n;
    let t_k_l = d / lcm_list!(k, l);
    let t_k_m = d / lcm_list!(k, m);
    let t_k_n = d / lcm_list!(k, n);
    let t_l_m = d / lcm_list!(l, m);
    let t_l_n = d / lcm_list!(l, n);
    let t_m_n = d / lcm_list!(m, n);
    let t_k_l_m = d / lcm_list!(k, l, m);
    let t_k_l_n = d / lcm_list!(k, l, n);
    let t_k_m_n = d / lcm_list!(k, m, n);
    let t_l_m_n = d / lcm_list!(l, m, n);
    let t_k_l_m_n = d / lcm_list!(k, l, m, n);
    let t_1 = t_k + t_l + t_m + t_n;
    let t_2 = t_k_l + t_k_m + t_k_n + t_l_m + t_l_n + t_m_n;
    let t_3 = t_k_l_m + t_k_l_n + t_k_m_n + t_l_m_n;
    let t_4 = t_k_l_m_n;
    t_1 - t_2 + t_3 - t_4
}

fn main() {
    let stdin = io::stdin();
    let k = read_t(&stdin);
    let l = read_t(&stdin);
    let m = read_t(&stdin);
    let n = read_t(&stdin);
    let d = read_t(&stdin);
    let r = num_damaged_dragons(k, l, m, n, d);
    println!("{}", r);
}


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

fn main() {
    let stdin = io::stdin();
    let mut iterator = stdin.lock().lines();
    let mut damaged = 0;

    let k: i64 = iterator
        .next().unwrap().unwrap().parse().unwrap_or(0);
    let l: i64 = iterator
        .next().unwrap().unwrap().parse().unwrap_or(0);
    let m: i64 = iterator
        .next().unwrap().unwrap().parse().unwrap_or(0);
    let n: i64 = iterator
        .next().unwrap().unwrap().parse().unwrap_or(0);
    let d: i64 = iterator
        .next().unwrap().unwrap().parse().unwrap_or(0);

    for i in 1..=d {
        if i % k == 0 ||
            i % l == 0 ||
            i % m == 0 ||
            i % n == 0 {
                damaged += 1;
        }
    }

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


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

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

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

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

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

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

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, k: i64,
        s: chars,
    }
    let s: Vec<_> = s.into_iter().map(|c| c as usize - 97).collect();
    let mut dp = vec![vec![0i64; n + 1]; n + 1];
    let mut nxt = vec![[n; 26]; n + 1];
    for i in (0..n).rev() {
        nxt[i] = nxt[i + 1];
        nxt[i][s[i]] = i;
    }
    dp[n][0] = 1;
    for i in (0..n).rev() {
        dp[i][0] = dp[i][0].saturating_add(1);
        for j in 0..n {
            let mut tot: i64 = 0;
            for l in 0..26 {
                let to = nxt[i][l] + 1;
                if to <= n {
                    tot = tot.saturating_add(dp[to][j]);
                }
            }
            dp[i][j + 1] = dp[i][j + 1].saturating_add(tot);
        }
    }
    let mut cost = 0;
    let mut rem = k;
    for i in (0..n + 1).rev() {
        let now = min(dp[0][i], rem);
        cost += now * (n - i) as i64;
        rem -= now;
        if rem <= 0 {
            break;
        }
    }
    puts!("{}\n", if rem > 0 { -1 } else { cost });
}

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


//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 vvb(&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 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()
	}
}
//------------------- End rusT }}}

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

	let n = rin.u();
	let k = rin.l();
	let s = rin.vb();
	let add = |a: i64, b: i64| k.min(a+b);
	let mut dp = v!([n+1][n+1] = 0);
	dp[0][0] = 1;
	for i in 1..=n {
		for l in 1..=i {
			for j in 1..=i {
				dp[i][j] = add(dp[i][j], dp[i-l][j-1]);
			}
			if l < i && s[i-1] == s[i-1-l] {
				break;
			}
		}
	}
	let mut sum = v!([n+1] = 0);
	let mut sum0 = 0;
	for i in 0..=n {
		for j in 0..=n {
			let x = dp[i][j];
			sum[j] = add(sum[j], x);
			sum0 = add(sum0, x);
		}
	}
	if sum0 < k {
		writeln!(rout, "-1").ok();
		return;
	}
	let mut sol = 0;
	let mut rem = k;
	for i in (0..=n).rev() {
		let m = sum[i].min(rem);
		sol += (n-i) as i64 * m;
		rem -= m;
	}
	writeln!(rout, "{}", sol).ok();
}


use std::io;
// use std::cmp::min;
use std::collections::{HashSet, VecDeque};

fn main() -> io::Result<()> {
    let stdin = io::stdin();
    let mut input = String::new();
    stdin.read_line(&mut input)?;
    let mut iter = input.split_whitespace()
        .map(|x| x.trim().parse::<usize>().unwrap());

    let n = iter.next().unwrap();
    let k = iter.next().unwrap();

    let mut input = String::new();
    stdin.read_line(&mut input)?;
    let s = input.trim();

    let mut visited: HashSet<Vec<char>> = HashSet::new();
    let mut queue: VecDeque<Vec<char>> = VecDeque::new();
    queue.push_back(s.chars().collect());

    let mut count = 0;
    let mut sum = 0;
    while k > count && !queue.is_empty() {
        let s = queue.pop_front().unwrap();
        count += 1;
        sum += s.len();

        // println!("visited {:?}", s);

        for i in 0..s.len() {
            let mut t = vec![];
            t.extend_from_slice(&s[..i]);
            t.extend_from_slice(&s[i+1..]);

            if !visited.contains(&t) {
                queue.push_back(t.clone());
            }

            visited.insert(t);
        }
    }

    // println!("count={} sum={}", count, sum);

    if count < k {
        println!("-1");
    } else {
        println!("{}", n * k - sum);
    }

    Ok(())
}


#[allow(unused_imports)] use std::{*, io::*, cmp::*, char::* };
#[allow(unused)] macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
#[allow(unused)] macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
#[allow(unused)] macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1}; ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}
#[allow(unused)] macro_rules! debug { ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap()); }
#[allow(unused)] macro_rules! debugln { ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap()); }

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    #[allow(unused)] macro_rules! puts { ($($format:tt)*) => (let _ = write!(out,$($format)*);); }

    let s1: Vec<char> = get_word().chars().collect();
    let s2: Vec<char> = get_word().chars().collect();

    let mut sum1 = 0;
    let mut sum2 = 0;

    for c in s1 {
	sum1 += match c {
	    '+' => 1,
	    '-' => -1,
	    _  => 0,
	}
    }

    for c in &s2 {
	sum2 += match *c {
	    '+' => 1,
	    '-' => -1,
	    _  => 0,
	}
    }

    let mut q = 0;

    for c in &s2 {
	if *c == '?' {
	    q += 1;
	}
    }

    let d: i64 = sum1 - sum2;
    let d = d.abs();

    let mut  num = 1;

    if d > q || d % 2 != q % 2 {

	puts!("{}", 0.0);

    } else {

	let m = d + (q - d) / 2;

	for i in 0..m {
	    num *= q - i;
	}

	for i in 1..=m {
	    num /= i;
	}

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

#[allow(dead_code)]
fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8


#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]

use std::char::*;
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;

macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

use std::f64;

fn min<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { a }
    else { b }
}

fn max<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { b }
    else { a }
}

use std::hash::Hash;
fn inc<T: Hash+Ord>(map:&mut BTreeMap<T,i64>, key:T) {
    let count = map.entry(key).or_insert(0);
    *count += 1;
}

fn int(ch: char) -> i64 {
    return (ch as u8 - b'0') as i64
}

const MAX:usize = 20;
const INF:i64 = std::i64::MAX;
const MOD:i64 = 1e9 as i64 + 7;

fn main() {
    input!{s:chars, t:chars};
    let mut cord = 0;
    for i in 0..s.len() {
        if s[i] == '+' { cord += 1; }
        else { cord -= 1; }
    }

    let mut dp = vec![vec![0;MAX+1];s.len()+1];
    dp[0][MAX/2] = 1;

    for i in 0..s.len() {
        for j in 0..MAX {
            if dp[i][j] == 0 { continue; }
            if t[i] == '+' {
                dp[i+1][j+1] += dp[i][j];
            }
            else if t[i] == '-' {
                dp[i+1][j-1] += dp[i][j];
            }
            else {
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j-1] += dp[i][j];
            }
        }
    }

    //println!("{:#?}", dp);

    let sum = dp[s.len()].iter().sum::<i64>();
    let correct = dp[s.len()][cord+MAX/2];
    //debug!(sum,correct);

    println!("{}", (correct as f64) / (sum as f64));

}

/*

元のコマンドと受信したコマンドが与えられる。
受信したコマンド通りに動いたときに、元のコマンドと同じ座標になる確率はいくらか求める。

全ての移動方法を全探索する。
正しき移動の数 / パスの総数 が答え

・DFSして全探索
・?の数だけbit全探索すればいい
・２次元配列でDPもできるかも

*/


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

#[allow(unused_macros)]
macro_rules! readln {
  () => {{
    use std::io;

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

#[allow(unused_macros)]
macro_rules! readvec {
  ( $t:ty ) => {{
    let input = readln!();
    let mut input = input.split_whitespace();
    let mut result = Vec::new();
    for elem in input {
      result.push(elem.parse::<$t>().unwrap());
    }
    result
  }}
}

fn go(s: &String, need: i32, pos: i32, i: usize) -> f64 {
  if i == s.as_bytes().len() {
    if need == pos {
      return 1f64;
    } else {
      return 0f64;
    }
  } else {
    if s.as_bytes()[i] == '+' as u8 {
      return go(s,need,pos+1,i+1);
    } else if s.as_bytes()[i] == '-' as u8 {
      return go(s,need,pos-1,i+1);
    } else if s.as_bytes()[i] == '?' as u8 {
      return (go(s,need,pos-1,i+1)+go(s,need,pos+1,i+1))*0.5;
    } else {
      panic!("");
    }
  }
}

fn main() {
  let aa = readln!();
  let bb = readln!();
  let mut need = 0;
  for i in aa.chars() {
    if i == '+' {
      need += 1;
    } else if i == '-' {
      need -= 1;
    } else {
      panic!("");
    }
  }
  let p = go(&bb, need, 0, 0);
  println!("{}",p);
}


//spnauti-rust
use std::io::*;
use std::str::*;
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::*;
#[allow(unused_imports)] use std::collections::*;

#[allow(unused_macros)]
macro_rules! a {
    ($c: tt, $x: expr, $y: expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
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).unwrap();
        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 u(&mut self) ->  usize { self.p()                }
    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 vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}

#[allow(dead_code)]
fn build_counting_hashmap<K: Eq + std::hash::Hash, T>(i: T) -> HashMap<K,usize>
    where T: Iterator<Item = K> {
    let mut m = HashMap::new();
    for k in i {
        let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };
        m.insert(k, n);
    }
    m
}

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

    let f = |s: &[u8]| {
        let mut x = 0;
        let mut c = 0;
        for &a in s {
            if a == b'+' { x += 1; }
            if a == b'-' { x -= 1; }
            if a == b'?' { c += 1; }
        }
        (x, c)
    };

    let a = f(input.bs()).0;
    let (b,c) = f(input.bs());
    let mut res = 0;
    for mut z in 0..1<<c {
        let mut x = a + c;
        while z > 0 {
            z -= z & -z;
            x -= 2;
        }
        if x == b {
            res += 1;
        }
    }
    println!("{}", (res as f64) / ((1 << c) as f64));
}


const N:usize = 505;

fn main() {

    let mut str = String::new();
	std::io::stdin().read_line(&mut str).expect("");
    let input :Vec<&str> = str.trim().split(" ").collect();
    let n = input[0].parse::<i32>().unwrap();
    let modn = input[1].parse::<i64>().unwrap();
    let mut dp0:Vec<i64> = vec![0;N*N];
    let mut dp1:Vec<i64> = vec![0;N*N];
    //let mut temp_dp0:Vec<i64> = vec![0;N*N];
    //let mut temp_dp1:Vec<i64> = vec![0;N*N];
    let shift = N*N/2;
    dp1[shift]=1;
    for _i in 1..n{
        let mut new_dp0 :Vec<i64> = vec![0;N*N];
        let mut new_dp1 :Vec<i64> = vec![0;N*N];

        //let mut new_dp0 = temp_dp0;
        //let mut new_dp1 = temp_dp1;
        //for j in 0..(N*N){
        //    new_dp0[j]=0;
        //    new_dp1[j]=0;
        ///}
        let i = _i as usize;
        for _j in 0..(N*N-1){
            let j = _j as usize;
            if dp1[j]==0 &&  dp0[j]==0{
                continue;
            }
            new_dp1[j-i] = (new_dp1[j-i]+dp1[j])%modn;
            new_dp1[j+1] = (new_dp1[j+1]-2*dp1[j] + modn + modn)%modn;
            new_dp1[j+i+2]=(new_dp1[j+i+2]+dp1[j])%modn;

            new_dp0[j+1] = (new_dp0[j+1]+dp1[j]*(i as i64))%modn;
            new_dp0[j] = (new_dp0[j]+(modn-dp1[j])*(i as i64+1))%modn;
            new_dp0[j-i] = (new_dp0[j-i]+dp1[j])%modn;

            let t:i64 = (i as i64 +1)*dp0[j]%modn;
            new_dp0[j] = (new_dp0[j]+t)%modn;
            new_dp0[j+1] = (new_dp0[j+1]+(modn-t)*2)%modn;
            new_dp0[j+2] = (new_dp0[j+2]+t)%modn;
        }
        //for j in shift-10..shift+11{
        //    println!("{} {}",j as i32-shift as i32,new_dp[j][0])
        //}
        for j in 0..(N*N-1){
            new_dp0[j+1]=(new_dp0[j+1]+new_dp0[j])%modn;
            new_dp1[j+1]=(new_dp1[j+1]+new_dp1[j])%modn;
        }
        for j in 0..(N*N-1){
            new_dp0[j+1]=(new_dp0[j+1]+new_dp0[j])%modn;
            new_dp1[j+1]=(new_dp1[j+1]+new_dp1[j])%modn;
        }
        //temp_dp0 = dp0;
        //temp_dp1 = dp1;
        dp0 = new_dp0;
        dp1 = new_dp1;
    }
    let mut ans:i64 = 0;
    for j in shift+1..N*N{
        ans = (ans + dp0[j])%modn;
    }
    println!("{}",ans);

}


// ---------- begin next_permutation ----------
fn next_permutation<T: Ord>(a: &mut [T]) -> bool {
    a.windows(2).rposition(|a| a[0] < a[1]).map_or(false, |x| {
        let y = a.iter().rposition(|b| a[x] < *b).unwrap();
        a.swap(x, y);
        a[(x + 1)..].reverse();
        true
    })
}
// ---------- end next_permutation ----------
// ---------- begin ModInt ----------
mod modint {

    #[allow(dead_code)]
    pub struct Mod;
    impl ConstantModulo for Mod {
        const MOD: u32 = 1_000_000_007;
    }

    #[allow(dead_code)]
    pub struct StaticMod;
    static mut STATIC_MOD: u32 = 0;
    impl Modulo for StaticMod {
        fn modulo() -> u32 {
            unsafe { STATIC_MOD }
        }
    }

    #[allow(dead_code)]
    impl StaticMod {
        pub fn set_modulo(p: u32) {
            unsafe {
                STATIC_MOD = p;
            }
        }
    }

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

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

    pub trait ConstantModulo {
        const MOD: u32;
    }

    impl<T> Modulo for T
    where
        T: ConstantModulo,
    {
        fn modulo() -> u32 {
            T::MOD
        }
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    #[allow(dead_code)]
    impl<T> ModInt<T> {
        pub fn new_unchecked(d: u32) -> Self {
            ModInt(d, PhantomData)
        }
        pub fn zero() -> Self {
            ModInt::new_unchecked(0)
        }
        pub fn one() -> Self {
            ModInt::new_unchecked(1)
        }
        pub fn is_zero(&self) -> bool {
            self.0 == 0
        }
    }

    #[allow(dead_code)]
    impl<T: Modulo> ModInt<T> {
        pub fn new(d: u32) -> Self {
            ModInt::new_unchecked(d % T::modulo())
        }
        pub fn pow(&self, mut n: u64) -> Self {
            let mut t = Self::one();
            let mut s = *self;
            while n > 0 {
                if n & 1 == 1 {
                    t *= s;
                }
                s *= s;
                n >>= 1;
            }
            t
        }
    }
}
// ---------- end ModInt ----------

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

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

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

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

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

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

fn run() {
    input!(n: usize, modulo: u32);
    StaticMod::set_modulo(modulo);
    /*
    for n in 1..=6 {
        let mut ans = 0;
        let mut a = (0..n).collect::<Vec<_>>();
        while {
            let mut b = a.clone();
            next_permutation(&mut b);
            while {
                let inv = |a: &[usize]| -> usize {
                    let mut cnt = 0;
                    for i in 0..a.len() {
                        for j in (i + 1)..a.len() {
                            if a[i] > a[j] {
                                cnt += 1;
                            }
                        }
                    }
                    cnt
                };
                if inv(&a) > inv(&b) {
                    ans += 1;
                }
                next_permutation(&mut b)
            }{}
            next_permutation(&mut a)
        }{}
        println!("{}: {}", n, ans);
    }
    */
    let mut binom  = vec![vec![M::zero(); n + 1]; n + 1];
    binom[0][0] = M::one();
    for i in 1..=n {
        binom[i][0] = M::one();
        for j in 1..=i {
            binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j];
        }
    }
    let mut fact = vec![M::one(); n + 1];
    for i in 1..=n {
        fact[i] = M::from(i) * fact[i - 1];;
    }
    let mut dp = Map::new();
    for rem in (1..=n).rev() {
        let mut next = Map::new();
        for i in 0..rem {
            for j in (i + 1)..rem {
                *next.entry(i as i32 - j as i32).or_insert(M::zero()) += fact[n - rem] * binom[n][rem];
            }
        }
        let mut trans = Map::new();
        for i in 0..rem {
            for j in 0..rem {
                *trans.entry(i as i32 - j as i32).or_insert(M::zero()) += M::one();
            }
        }
        for (diff, way) in dp {
            for (d, w) in trans.iter() {
                *next.entry(diff + *d).or_insert(M::zero()) += *w * way;
            }
        }
        dp = next;
    }
    let mut ans = M::zero();
    for (diff, way) in dp {
        if diff > 0 {
            ans += way;
        }
    }
    let ans = ans.0 % modulo;
    println!("{}", ans);
}

fn main() {
    run();
}


const N:usize = 505;

fn main() {

    let mut str = String::new();
	std::io::stdin().read_line(&mut str).expect("");
    let input :Vec<&str> = str.trim().split(" ").collect();
    let n = input[0].parse::<i32>().unwrap();
    let modn = input[1].parse::<i64>().unwrap();
    let mut dp0:Vec<i64> = vec![0;N*N];
    let mut dp1:Vec<i64> = vec![0;N*N];
    let mut temp_dp0:Vec<i64> = vec![0;N*N];
    let mut temp_dp1:Vec<i64> = vec![0;N*N];
    let shift = N*N/2;
    dp1[shift]=1;
    for _i in 1..n{
        //let mut new_dp0 :Vec<i64> = vec![0;N*N];
        //let mut new_dp1 :Vec<i64> = vec![0;N*N];

        let mut new_dp0 = temp_dp0;
        let mut new_dp1 = temp_dp1;
        for j in 0..(N*N){
            new_dp0[j]=0;
            new_dp1[j]=0;
        }
        let i = _i as usize;
        for _j in 0..(N*N-1){
            let j = _j as usize;
            if dp1[j]==0 &&  dp0[j]==0{
                continue;
            }
            new_dp1[j-i] = (new_dp1[j-i]+dp1[j])%modn;
            new_dp1[j+1] = (new_dp1[j+1]-2*dp1[j] + modn + modn)%modn;
            new_dp1[j+i+2]=(new_dp1[j+i+2]+dp1[j])%modn;

            new_dp0[j+1] = (new_dp0[j+1]+dp1[j]*(i as i64))%modn;
            new_dp0[j] = (new_dp0[j]+(modn-dp1[j])*(i as i64+1))%modn;
            new_dp0[j-i] = (new_dp0[j-i]+dp1[j])%modn;

            let t:i64 = (i as i64 +1)*dp0[j]%modn;
            new_dp0[j] = (new_dp0[j]+t)%modn;
            new_dp0[j+1] = (new_dp0[j+1]+(modn-t)*2)%modn;
            new_dp0[j+2] = (new_dp0[j+2]+t)%modn;
        }
        //for j in shift-10..shift+11{
        //    println!("{} {}",j as i32-shift as i32,new_dp[j][0])
        //}
        for j in 0..(N*N-1){
            new_dp0[j+1]=(new_dp0[j+1]+new_dp0[j])%modn;
            new_dp1[j+1]=(new_dp1[j+1]+new_dp1[j])%modn;
        }
        for j in 0..(N*N-1){
            new_dp0[j+1]=(new_dp0[j+1]+new_dp0[j])%modn;
            new_dp1[j+1]=(new_dp1[j+1]+new_dp1[j])%modn;
        }
        temp_dp0 = dp0;
        temp_dp1 = dp1;
        dp0 = new_dp0;
        dp1 = new_dp1;
    }
    let mut ans:i64 = 0;
    for j in shift+1..N*N{
        ans = (ans + dp0[j])%modn;
    }
    println!("{}",ans);

}


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

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

    fn next_line(&self) -> String {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).expect("Fail to read");
        line
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let line = self.next_line();
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn _main() {
    let mut scan = Scan::new();
    let n: usize = scan.next();
    let x: usize = scan.next();
    let y: usize = scan.next();
    let needed = y * n / 100 + if y * n % 100 == 0 { 0 } else { 1 };
    println!("{}", if needed <= x { 0 } else { needed - x });
}

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


use std::io;
use std::str;
use std::usize;
use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::collections::VecDeque;
use std::cmp;

fn main() {
    let (mut h, mut m, s, mut t1, mut t2) = {
        let v = read_values::<f64>();
        (v[0], v[1], v[2], v[3], v[4])
    };
    if h == 12.0 { h = 0.0; }
    h *= 5.0;
    t1 *= 5.0;
    t2 *= 5.0;

    h += m * 5.0 / 60.0 + s * 5.0 / 3600.0;
    m += s / 60.0;

    let (from, to) = {
        if t1 > t2 {
            (t2, t1)
        } else {
            (t1, t2)
        }
    };
    let mut count = 0;
    if from < h && h < to { count += 1; }
    if from < m && m < to { count += 1; }
    if from < s && s < to { count += 1; }

    if count == 0 || count == 3 {
        println!("YES");
    } else {
        println!("NO");
    }
}

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

fn read_values<T>() -> Vec<T>
    where T: std::str::FromStr,
          T::Err: std::fmt::Debug
{
    read_line()
        .split(' ')
        .map(|a| a.trim().parse().unwrap())
        .collect()
}


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

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

fn solve() {
    let (h, m, s, t1, t2) = parse_line!(i32, i32, i32, i32, i32);
    let h = h * 5 * 2 + if m > 0 || s > 0 {1} else {0};
    let m = m * 2 + if s > 0 {1} else {0};
    let s = s * 2;
    let t1 = t1 * 5 * 2;
    let t2 = t2 * 5 * 2;
    let min = std::cmp::min(t1, t2);
    let max = std::cmp::max(t1, t2);
    let correct = (h > max || h < min) && (m > max || m < min) && (s > max || s < min);
    let incorrect = h > min && h < max && m > min && m < max && s > min && s < max;
    if correct || incorrect {
        println!("YES");
    }else{
        println!("NO");
    }
}

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


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

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

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

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

fn main() {
    let input: Vec<usize> = util::gets();
    let h = input[0] % 12;
    let m = input[1];
    let s = input[2];
    let t1 = min(input[3] % 12, input[4] % 12);
    let t2 = max(input[3] % 12, input[4] % 12);

    let mut is_inside = Vec::new();

    is_inside.push(t1 * 5 < s && s < t2 * 5);
    let m_s = m * 60 + s;
    is_inside.push(t1 * 5 * 60 < m_s && m_s < t2 * 5 * 60);
    is_inside.push(t1 <= h && h < t2);

    if is_inside.iter().all(|&b| b) || is_inside.iter().all(|&b| !b) {
        println!("YES");
    } else {
        println!("NO");
    }

}


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

fn parse_bin_val(s: &str) -> Vec<bool> {
    s.bytes().map(|byte| match byte {
        b'0' => false,
        b'1' => true,
        _ => panic!("NOT A BIT!"),
    }).collect()
}

fn main() {
    let (h, m, s, t1, t2) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse::<i64>().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            it.next().unwrap(),
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let modulo = |a, b| {
        if a % b < 0 {
            a % b + b
        } else {
            a % b
        }
    };

    let convert = |x| {
        modulo(x, 12) * 5
    };

    // println!("{} {} {}", convert(h), convert(t1), convert(t2));

    let mut arr = vec![convert(h) + 1, m, s, convert(t1), convert(t2)];

    arr.sort();

    let i1 = arr.iter().position(|&x| x == convert(t1)).unwrap() as i64;
    let i2 = arr.iter().position(|&x| x == convert(t2)).unwrap() as i64;

    // println!("{} {}", i1, i2);

    let ans =  modulo(i2 - i1, 5) == 1 || modulo(i1 - i2, 5) == 1;

    if ans {
        println!("YES");
    } else {
        println!("NO");
    }
}


//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

//------------------- Start Field
const P5: i32 = 100_000_000;
const P6: i64 = P5 as i64;
#[derive(Debug,Clone,Copy)]
struct Field(i32);
#[allow(dead_code)]
impl Field {
    fn new<T: Into<i64>>(a: T) -> Self { Self(Self::cv(a)) }
    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) }
}
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 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; } }
use std::fmt::{Display, Formatter, Result};
impl Display for Field { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.0) } }
// impl Default for Field { fn default() -> Self { Field(0) }}
impl Default for &Field { fn default() -> Self { &Field(0) }}
impl PartialEq for Field { fn eq(&self, a: &Self) -> bool { self.0 == a.0 } }
impl PartialOrd for Field { fn partial_cmp(&self, a: &Self) -> Option<Ordering> { Some(self.0.cmp(&a.0)) } }
impl Eq for Field {}
impl Ord for Field { fn cmp(&self, a: &Self) -> Ordering { self.0.cmp(&a.0) } }
impl Sum<Self> for Field {
    fn sum<I>(i: I) -> Self where I: Iterator<Item = Self> {
        i.fold(Field(0), |a,b| a + b) } }
impl<'a> Sum<&'a Self> for Field {
    fn sum<I>(i: I) -> Self where I: Iterator<Item = &'a Self> {
        i.fold(Field(0), |a,&b| a + b) } }
impl Product<Self> for Field {
    fn product<I>(i: I) -> Self where I: Iterator<Item = Self> {
        i.fold(Field(1), |a,b| a * b) } }
impl<'a> Product<&'a Self> for Field {
    fn product<I>(i: I) -> Self where I: Iterator<Item = &'a Self> {
        i.fold(Field(1), |a,&b| a * b) }
}
//------------------- End Field

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

    const MAX_N: usize = 104;
    const MAX_K: usize = 12;

    let id = |n1, n2, w, k| {
        ((n1 * MAX_N + n2) * 2 + w) * MAX_K + k
    };
    let mut dp = vec![Field::new_unchecked(0); MAX_N * MAX_N * 2 * MAX_K];

    l!(n1,n2,k1,k2 = input.u());
    let k = [k1, k2];
    dp[id(0,0,0,0)] = Field::new_unchecked(1);

    for i in 0..=n1 {
        for j in 0..=n2 {
            for w in 0..=1 {
                let wk = k[w];
                for l in 0..=wk {
                    let val = dp[id(i, j, w, l)];
                    if val.0 == 0 {
                        continue;
                    }
                    for a in 0..=1 {
                        let ii = i + 1 - a;
                        let jj = j + a;
                        let ll = if a == w {l + 1} else {1};
                        dp[id(ii, jj, a, ll)] += val;
                    }
                }
            }
        }
    }

    let mut sol = Field::new_unchecked(0);
    for w in 0..=1 {
        for l in 0..=k[w] {
            sol += dp[id(n1, n2, w, l)];
        }
    }
    println!("{}", sol);
}


use std::io::{self, Read};
use std::cmp;

fn main() {
    let mut buffer = String::new();
    let stdin = io::stdin();
    let mut handle = stdin.lock();
    handle.read_to_string(&mut buffer).unwrap();

    let arr : Vec<_> = buffer.split_whitespace().map(|x| x.parse::<u64>().unwrap() ).collect();
    let t = arr[0] as usize;
    let mut index = 1;
    for _ in 0..t {
        let (a,b) = (arr[index],arr[index+1]);
        if b == a-1 {
            let h = 2*b+1; // = a+b
            let mut j = 3; //just check all odd numbers since 2b + 1 is odd
            let mut divisible = false;
            while j <= (h as f64).sqrt() as u64 + 1{
                if h % j == 0 {
                    divisible = true;
                }
                j += 2;
            }
            //println!("{},{}: {}",a,b,divisible);
            if !divisible {
                println!("YES");
            } else {
                println!("NO");
            }
        } else {
            println!("NO");
        }
        index += 2;
    }
}


use std::io;

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

fn is_prime(num : i128) -> bool {
    if num == 1 || num != 2 && num % 2 == 0 {
        return false;
    }
    let limit = (num as f64).sqrt() as i128 + 1;
    let mut div = 3;
    while div <= limit {
        if num % div == 0 {
            return false;
        }
        div += 1;
    }
    return true;
}

fn main() {
    assert!(!is_prime(15));

    let tests = readln!(u8);
    for _ in 0..tests {
        let (size1, size2) = readln!(i128, i128);

        if size1 - size2 == 1 {
            println!("{}", if is_prime(size1 + size2) { "YES" } else { "NO" });
        } else {
            println!("NO");
        }
    }
}


use std::io::{stdin};

macro_rules! read {
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        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"),
            )+
        )
    })
}

fn main() {
	let (k, n, s, p) = read!(i32 , i32 , i32 , i32);
	let x;
    	if n % s != 0 {
        	x = n / s + 1;
    	} else {
        	x = n / s;
    	}
    	let y = x * k;
    	let mut _x;
    	if y % p != 0 {
        	_x = y / p + 1;
    	} else {
        	_x = y / p;
    	}
    	println!("{}" , _x);
}


fn main() {
    use std::io::prelude::*;
    use std::io;

    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();

    let mut it = input.split_whitespace();

    let k: i32 = it.next().unwrap().parse().unwrap();
    let n: i32 = it.next().unwrap().parse().unwrap();
    let s: i32 = it.next().unwrap().parse().unwrap();
    let p: i32 = it.next().unwrap().parse().unwrap();

    // For one person:
    // s * (ans - 1) < n <= s * ans
    // 0 < n - s * (ans - 1) <= s
    // 0 <= n - s * (ans - 1) - 1 < s
    // 0 <= n - 1 - s * (ans - 1) < s
    // ans - 1 = (n - 1) / s
    // ans = (n - 1) / s + 1
    let sn = (n - 1) / s + 1;
    // p * (ans - 1) < k * sn <= p * ans
    // 0 < k * sn - p * (ans - 1) <= p
    // 0 <= k * sn - 1 - p * (ans - 1) < p
    // ans - 1 = (k * sn - 1) / p
    let ans = (k * sn - 1) / p + 1;
    println!("{}", ans);
}


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

fn main() {
    let stdin = stdin();
    let mut sc = Scanner::new(stdin.lock());
    let k = sc.next::<u32>();
    let n = sc.next::<u32>();
    let s = sc.next::<u32>();
    let p = sc.next::<u32>();

    let mut b = 1 << 28;
    let mut ret = b - 1;
    while b > 0 {
        if ret >= b && n <= s * (((ret - b) * p) / k) {
            ret -= b;
        }
        b /= 2;
    }
    println!("{}", ret);
}

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

impl<B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        Self {
            reader,
            buffer: Vec::new(),
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: ::std::fmt::Debug,
    {
        if let Some(front) = self.buffer.pop() {
            front.parse::<T>().expect(&front)
        } else {
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Line not read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
            self.next()
        }
    }
}


use std::io;

fn main() {
    let mut input = String::new();
    if let Err(_) = io::stdin().read_line(&mut input) {
        std::process::exit(1);
    }

    let mut parts = input.trim().split_whitespace();
    let number_of_people: u32 = if let Ok(val) = parts.next().unwrap().parse() { val } else { std::process::exit(2); };
    let number_of_planes_per_person: u32 = if let Ok(val) = parts.next().unwrap().parse() { val } else { std::process::exit(2); };
    let number_of_planes_per_sheet: u32 = if let Ok(val) = parts.next().unwrap().parse() { val } else { std::process::exit(2); };
    let number_of_sheets_per_pack: u32 = if let Ok(val) = parts.next().unwrap().parse() { val } else { std::process::exit(2); };

    let number_of_sheets_per_person = f64::ceil(number_of_planes_per_person as f64 / number_of_planes_per_sheet as f64) as u32;
    let total_number_of_sheets = number_of_sheets_per_person * number_of_people;
    let number_of_needed_packs = f64::ceil(total_number_of_sheets as f64 / number_of_sheets_per_pack as f64) as u32;
    println!("{}", number_of_needed_packs);
}


// ---------- begin ModInt ----------
// モンゴメリ乗算を用いる
// ほぼCodeforces用
// 注意
// new_unchecked は値xが 0 <= x < modulo であることを仮定
// ModInt の中身は正規化された値で持ってるので直接読んだり書いたりするとぶっ壊れる
// 奇素数のみ
mod modint {

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

    pub trait Modulo {
        fn modulo() -> u32;
        fn rem() -> u32;
        fn ini() -> u64;
        fn reduce(x: u64) -> u32 {
            assert!(x < (Self::modulo() as u64) << 32);
            let b = (x as u32 * Self::rem()) as u64;
            let t = x + b * Self::modulo() as u64;
            let mut c = (t >> 32) as u32;
            if c >= Self::modulo() {
                c -= Self::modulo();
            }
            c as u32
        }
    }

    #[allow(dead_code)]
    pub enum Mod1_000_000_007 {}

    impl Modulo for Mod1_000_000_007 {
        fn modulo() -> u32 {
            1_000_000_007
        }
        fn rem() -> u32 {
            2226617417
        }
        fn ini() -> u64 {
            582344008
        }
    }

    #[allow(dead_code)]
    pub enum Mod998_244_353 {}

    impl Modulo for Mod998_244_353 {
        fn modulo() -> u32 {
            998_244_353
        }
        fn rem() -> u32 {
            998244351
        }
        fn ini() -> u64 {
            932051910
        }
    }

    #[allow(dead_code)]
    pub fn generate_umekomi_modulo(p: u32) {
        assert!(p < (1 << 31) && p > 2 && p & 1 == 1 && (2u32..).take_while(|v| v * v <= p).all(|k| p % k != 0));
        let mut t = 1u32;
        let mut s = !p + 1;
        let mut n = !0u32 >> 2;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        let mut ini = (1u64 << 32) % p as u64;
        ini = (ini << 32) % p as u64;
        assert!(t * p == !0);
        println!("pub enum Mod{} {{}}", p);
        println!("impl Modulo for Mod{} {{", p);
        println!("    fn modulo() -> u32 {{");
        println!("        {}", p);
        println!("    }}");
        println!("    fn rem() -> u32 {{");
        println!("        {}", t);
        println!("    }}");
        println!("    fn ini() -> u64 {{");
        println!("        {}", ini);
        println!("    }}");
        println!("}}");
        let mut f = vec![];
        let mut n = p - 1;
        for i in 2.. {
            if i * i > n {
                break;
            }
            if n % i == 0 {
                f.push(i);
                while n % i == 0 {
                    n /= i;
                }
            }
        }
        if n > 1 {
            f.push(n);
        }
        let mut order = 1;
        let mut n = p - 1;
        while n % 2 == 0 {
            n /= 2;
            order <<= 1;
        }
        let z = (2u64..).find(|z| {
            f.iter().all(|f| mod_pow(*z, ((p - 1) / *f) as u64, p as u64) != 1)
        }).unwrap();
        let zeta = mod_pow(z, ((p - 1) / order) as u64, p as u64);
        println!("impl transform::NTTFriendly for Mod{} {{", p);
        println!("    fn order() -> usize {{");
        println!("        {}", order);
        println!("    }}");
        println!("    fn zeta() -> u32 {{");
        println!("        {}", zeta);
        println!("    }}");
        println!("}}");
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    #[allow(dead_code)]
    impl<T> ModInt<T> {
        fn build(d: u32) -> Self {
            ModInt(d, PhantomData)
        }
        pub fn zero() -> Self {
            Self::build(0)
        }
        pub fn is_zero(&self) -> bool {
            self.0 == 0
        }
    }

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

    pub fn mod_pow(mut r: u64, mut n: u64, m: u64) -> u64 {
        let mut t = 1 % m;
        while n > 0 {
            if n & 1 == 1 {
                t = t * r % m;
            }
            r = r * r % m;
            n >>= 1;
        }
        t
    }
}
// ---------- end ModInt ----------

use modint::*;

type M = ModInt<Mod998_244_353>;

// ---------- begin binary_gcd ----------
pub fn binary_gcd(a: u64, b: u64) -> u64 {
    if a == 0 || b == 0 {
        return a + b;
    }
    let x = a.trailing_zeros();
    let y = b.trailing_zeros();
    let mut a = a >> x;
    let mut b = b >> y;
    while a != b {
        let x = (a ^ b).trailing_zeros();
        if a < b {
            std::mem::swap(&mut a, &mut b);
        }
        a = (a - b) >> x;
    }
    a << x.min(y)
}
// ---------- end binary_gcd ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

fn run() {
    input! {
        n: usize,
        a: usize,
        x: usize,
        y: usize,
        k: usize,
        m: usize,
    }
    let mut lcm = 1;
    for i in 1..k {
        lcm = lcm * i / binary_gcd(i as u64, lcm as u64) as usize;
    }
    let mut dp = vec![M::zero(); lcm];
    let p = M::from(n).inv();
    for i in 0..lcm {
        dp[i] = M::from(i) * p;
    }
    for i in (1..k).rev() {
        for j in (0..lcm).rev() {
            dp[j] = p * (M::from(j) + dp[j - j % i]) + (M::one() - p) * dp[j];
        }
    }
    let mut a = a;
    let mut ans = M::zero();
    for _ in 0..n {
        let c = a % lcm;
        let d = a / lcm * lcm;
        ans += M::from(d) * p * M::from(k) + dp[c];
        a = (a * x + y) % m;
    }
    println!("{}", ans * M::from(n).pow(k as u64));
}

fn main() {
    run();
}