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

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

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

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

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

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

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

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

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

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

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

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

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

#[allow(dead_code)]
impl Precalc {
    pub fn new(n: usize) -> Precalc {
        let mut inv = vec![ModInt::one(); n + 1];
        let mut fact = vec![ModInt::one(); n + 1];
        let mut ifact = vec![ModInt::one(); n + 1];
        for i in 2..(n + 1) {
            inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);
            fact[i] = fact[i - 1] * ModInt(i as u32);
            ifact[i] = ifact[i - 1] * inv[i];
        }
        Precalc {
            inv: inv,
            fact: fact,
            ifact: ifact,
        }
    }
    pub fn inv(&self, n: usize) -> ModInt {
        self.inv[n]
    }
    pub fn fact(&self, n: usize) -> ModInt {
        self.fact[n]
    }
    pub fn ifact(&self, n: usize) -> ModInt {
        self.ifact[n]
    }
    pub fn comb(&self, n: usize, k: usize) -> ModInt {
        if k > n {
            return ModInt::zero();
        }
        self.fact[n] * self.ifact[k] * self.ifact[n - k]
    }
}
// ---------- end Precalc ----------
//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,
        w: usize,
        a: [usize; n],
    }
    let mut a = a;
    a.sort();
    let mut dp = vec![vec![ModInt::zero(); w + 1]; 2];
    dp[0][0] = ModInt::one();
    dp[1][0] = ModInt::one();
    for d in a.windows(2) {
        let d = d[1] - d[0];
        let mut next = vec![vec![ModInt::zero(); w + 1]; dp.len() + 1];
        // 単体
        for (i, dp) in dp.iter().enumerate() {
            let next = &mut next[i];
            for (j, &v) in dp.iter().enumerate() {
                if let Some(p) = next.get_mut(j + i * d) {
                    *p += v;
                } else {
                    break;
                }
            }
        }
        // 閉じる
        for (i, dp) in dp.iter().enumerate().skip(1) {
            let next = &mut next[i - 1];
            for (j, &v) in dp.iter().enumerate() {
                if let Some(p) = next.get_mut(j + i * d) {
                    *p += ModInt::from(i) * v;
                } else {
                    break;
                }
            }
        }
        // 割り当て
        for (i, dp) in dp.iter().enumerate().skip(1) {
            let next = &mut next[i];
            for (j, &v) in dp.iter().enumerate() {
                if let Some(p) = next.get_mut(j + i * d) {
                    *p += ModInt::from(i) * v;
                } else {
                    break;
                }
            }
        }
        // 開く
        for (i, dp) in dp.iter().enumerate() {
            let next = &mut next[i + 1];
            for (j, &v) in dp.iter().enumerate() {
                if let Some(p) = next.get_mut(j + i * d) {
                    *p += v;
                } else {
                    break;
                }
            }
        }
        dp = next;
    }
    let mut ans = ModInt::zero();
    for a in dp[0].iter() {
        ans += *a;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


#![allow(non_snake_case)]
#[allow(dead_code)] fn read_line() -> String { let mut buffer = String::new(); std::io::stdin().read_line(&mut buffer).expect("failed to read line"); buffer.trim().to_string() }
#[allow(dead_code)] fn read<T : std::str::FromStr>() -> T where T::Err: std::fmt::Debug { read_line().trim().parse::<T>().expect("failed to read value") }
#[allow(dead_code)]fn read_vec<T : std::str::FromStr>() -> Vec<T> where T::Err: std::fmt::Debug { read_line().split_whitespace().map(|x| x.parse::<T>().expect("failed to read values")).collect() }
#[allow(dead_code)] fn lock_stdout() -> std::io::BufWriter<std::io::StdoutLock<'static>> { let stdout = std::io::stdout().lock(); std::io::BufWriter::new(stdout) }
#[allow(dead_code)] struct StdoutLogger {buf: std::io::BufWriter<std::io::StdoutLock<'static>>}impl StdoutLogger {fn log(&mut self, s: &str) {std::io::Write::write(&mut self.buf, s.as_bytes()).expect("error writing stdout");std::io::Write::write(&mut self.buf, "\n".as_bytes()).expect("error writing stdout");}}
#[allow(dead_code)] macro_rules! init {($name: ident) => {#[allow(unused_mut)]let mut $name = StdoutLogger{buf:lock_stdout()};}}

fn main() {
    init!(outp);

    let excl_c = read::<usize>();
    let excl_ws = (0..excl_c).map(|_| read_line()).collect::<Vec<_>>();
    let excl_ws = excl_ws.iter().map(|s| s.as_str()).collect::<Vec<_>>();
    let inp = read_line();
    let the_ch = read_line().chars().next().unwrap();

    // let excl_ws = vec![
    //     "aCa",
    //     "cba",
    // ];
    // let inp = "abAcaba";
    // let the_ch = 'c';

    let mut repl = vec![0; 100];
    let inp_lc = inp.to_lowercase();
    for &w in &excl_ws {
        let mut p = 0;
        while let Some(o) = inp_lc[p..].find(&w.to_lowercase()) {
            for i in p+o..p+o+w.len() {repl[i]=1}
            p += o + 1;
        }
    }

    fn match_case(ch: char, to_ch: char) -> char {
        if to_ch.is_uppercase(){ch.to_uppercase().next().unwrap()}else{ch.to_lowercase().next().unwrap()}
    }
    let mut inp = inp.chars().collect::<Vec<_>>();
    for i in 0..repl.len() {
        if repl[i]==1 {
            let the_ch_lc = the_ch.to_lowercase().next().unwrap();
            let inp_lc = inp[i].to_lowercase().next().unwrap();
            if inp_lc==the_ch_lc {
                inp[i] = match_case(if the_ch_lc=='a'{'b'}else{'a'}, inp[i]);
            } else {
                inp[i] = match_case(the_ch, inp[i]);
            }
        }
    }

    //println!("{inp:?}");
    println!("{}", inp.iter().collect::<String>());
}

[{'input': ['3\r\nbers\r\nucky\r\nelu\r\nPetrLoveLuckyNumbers\r\nt\r\n'], 'output': ['PetrLovtTttttNumtttt\r\n']}, {'input': ['4\r\nhello\r\nparty\r\nabefglghjdhfgj\r\nIVan\r\npetrsmatchwin\r\na\r\n'], 'output': ['petrsmatchwin\r\n']}, {'input': ['2\r\naCa\r\ncba\r\nabAcaba\r\nc\r\n'], 'output': ['abCacba\r\n']}, {'input': ['3\r\nlol\r\nhello\r\neho\r\nPetrUnited\r\nt\r\n'], 'output': ['PetrUnited\r\n']}, {'input': ['2\r\ntrsd\r\ndream\r\nPetrsDreamOh\r\ny\r\n'], 'output': ['PeyyyYyyyyOh\r\n']}, {'input': ['1\r\nPetrsDreamOh\r\nPetrsDreamOh\r\nh\r\n'], 'output': ['HhhhhHhhhhHa\r\n']}, {'input': ['3\r\netr\r\ned\r\nied\r\nPetrUnited\r\nd\r\n'], 'output': ['PdddUnitda\r\n']}, {'input': ['3\r\netr\r\ned\r\nied\r\nPetrUnited\r\nz\r\n'], 'output': ['PzzzUnitzz\r\n']}, {'input': ['3\r\nab\r\nBa\r\naB\r\nABBA\r\na\r\n'], 'output': ['BAAB\r\n']}, {'input': ['3\r\nab\r\nBa\r\naB\r\nABBAC\r\nb\r\n'], 'output': ['BAABC\r\n']}, {'input': ['7\r\na\r\nb\r\ng\r\nk\r\ne\r\nt\r\nt\r\nA\r\na\r\n'], 'output': ['B\r\n']}, {'input': ['4\r\nEfron\r\nKeyt\r\ncesho\r\ncool\r\nCodeForcesHockeyTeam\r\np\r\n'], 'output': ['CodeForpppPpcpppPeam\r\n']}, {'input': ['4\r\nEfron\r\nKeyt\r\ncesho\r\ncool\r\nCodeForcesOldHockeyNewTeam\r\np\r\n'], 'output': ['CodeForcesOldHockeyNewTeam\r\n']}, {'input': ['2\r\nA\r\nB\r\nabababBabaBBaBBBBAaaaAAAAA\r\na\r\n'], 'output': ['bababaAbabAAbAAAABbbbBBBBB\r\n']}, {'input': ['7\r\nS\r\nT\r\ng\r\ni\r\nO\r\nr\r\nq\r\nkljpfP\r\nv\r\n'], 'output': ['kljpfP\r\n']}, {'input': ['47\r\nV\r\nS\r\ng\r\nr\r\nC\r\nR\r\nB\r\nb\r\nl\r\nW\r\nJ\r\ni\r\nU\r\nn\r\nq\r\nq\r\nj\r\nL\r\nR\r\nu\r\nQ\r\nC\r\nf\r\nC\r\nU\r\nu\r\nx\r\nh\r\nq\r\nE\r\nY\r\nu\r\nK\r\nt\r\nM\r\nU\r\nA\r\nA\r\ns\r\ni\r\nV\r\nT\r\nj\r\nb\r\nk\r\nW\r\nN\r\nNlVwRlWzQQWoCI\r\nz\r\n'], 'output': ['ZzZzZzZzZZZoZZ\r\n']}, {'input': ['47\r\njw\r\nL\r\nxIp\r\nW\r\nI\r\naI\r\nEp\r\nylG\r\nNe\r\nEglZ\r\noYkyo\r\nwDuZK\r\nDVh\r\nuoAoF\r\nGWj\r\nt\r\nP\r\nuNQz\r\nbPSg\r\neqru\r\nxvll\r\nO\r\nmb\r\nCM\r\nwnmvv\r\nYpFsq\r\nFYID\r\nc\r\nr\r\nrhbl\r\nYseyB\r\nRGcRj\r\nhDtz\r\nW\r\nQlQWB\r\nY\r\nftSl\r\nyPlAd\r\nLPgVw\r\nEIGOF\r\nTQ\r\nQrFcr\r\nspu\r\nK\r\nIJ\r\nfXUd\r\nGhpV\r\nDxUhKXELSLIiJMIOsbrpPQPXFwH\r\nw\r\n'], 'output': ['DxUhWXEWSWWwWMWWsbwwWQWXFaH\r\n']}, {'input': ['74\r\nPjc\r\nZcOWk\r\nM\r\nyMyp\r\ncH\r\nTzmX\r\nA\r\nXgl\r\nKVB\r\nbljv\r\nIH\r\nu\r\nnu\r\nLdahF\r\nt\r\nO\r\nSv\r\nuzFT\r\nzfNd\r\nUM\r\nbXR\r\nUQbXk\r\nAA\r\ngVmH\r\nng\r\nF\r\nK\r\nHP\r\nIu\r\nwrH\r\nN\r\nPnTIQ\r\nkUY\r\nyabHN\r\nTA\r\nvrgl\r\nyxmsh\r\nTrQ\r\nX\r\nvIbrl\r\nMfu\r\nPfN\r\ni\r\nrH\r\nt\r\nHl\r\nUwst\r\nj\r\nB\r\nBiDCA\r\nJcE\r\nfd\r\nbXuI\r\nWWSU\r\nrd\r\nmj\r\nt\r\nIGrPe\r\nQl\r\nxfoSV\r\no\r\nWKdG\r\nTqeu\r\nE\r\nbZyg\r\nbVqR\r\nzY\r\nZD\r\nhHpdP\r\njHww\r\nlfU\r\ngVem\r\nt\r\nBD\r\nhUOfmkiMZhZxTuuiAyPuoutEQiPfZFSQVMMQxckAqtlRv\r\nx\r\n'], 'output': ['hXXxxxxXZhZaXxxxXyPxxxxXQxPxZXSQVXXQacxXqxlRv\r\n']}, {'input': ['74\r\nULa\r\nn\r\nvq\r\nbybI\r\nfCX\r\nEEi\r\nSg\r\nxj\r\nIDz\r\nfsP\r\nM\r\nGGjx\r\nDpY\r\ngffu\r\nK\r\nMy\r\nqbtz\r\nk\r\nbLNb\r\nqET\r\nN\r\nBBY\r\nx\r\nKHUT\r\nUju\r\ntyXI\r\no\r\nChXY\r\neia\r\nR\r\nakHR\r\ng\r\nax\r\nKyY\r\nwpdl\r\nCZA\r\nsmFl\r\nLVDJ\r\nO\r\nxHF\r\nW\r\nTMZ\r\nvN\r\nqiT\r\ng\r\nI\r\nPsR\r\nsCJL\r\nN\r\naSCi\r\nJYD\r\nP\r\nA\r\nM\r\nT\r\nG\r\ngU\r\nk\r\nA\r\nloT\r\nEbP\r\nZ\r\nEoo\r\nQ\r\nGGY\r\nZcbG\r\ntvYl\r\nM\r\nczMR\r\nj\r\ne\r\nlLjf\r\nY\r\nzm\r\nqifNoaopvznANCLmPpfToShyelsYSFllyQLUDYbcQ\r\ng\r\n'], 'output': ['ggfGggggvggGGCLgGgfGgShgglsGSFllgGLUDGbcG\r\n']}, {'input': ['74\r\nM\r\nLQ\r\nH\r\ncA\r\nqj\r\nD\r\nnj\r\nzD\r\njM\r\ns\r\nR\r\noC\r\nFh\r\nlO\r\nj\r\nc\r\nEn\r\nAB\r\nsw\r\nT\r\nz\r\nEb\r\nb\r\nu\r\nmj\r\nMI\r\nD\r\nj\r\nH\r\np\r\nzD\r\nV\r\nR\r\nvg\r\nH\r\nS\r\nBy\r\nu\r\nQP\r\nB\r\ndD\r\nrI\r\nJF\r\nnA\r\nsv\r\nz\r\na\r\nl\r\nI\r\nFJ\r\nK\r\nH\r\nT\r\nF\r\nl\r\ntC\r\ng\r\ns\r\nNl\r\nUj\r\nu\r\nA\r\nOO\r\nLd\r\nk\r\nk\r\nkM\r\nLY\r\nbn\r\nv\r\nfT\r\nC\r\nI\r\nc\r\naeBolOleYgGmSLkFCPJPbQZUeodomjS\r\nv\r\n'], 'output': ['vvVovVveYvVvVVvVVVVVvQVVeovovvV\r\n']}, {'input': ['99\r\ns\r\nc\r\nN\r\nN\r\ni\r\ni\r\nW\r\nJ\r\nA\r\nW\r\nm\r\nB\r\nf\r\nO\r\nm\r\nk\r\nQ\r\nf\r\nx\r\np\r\nl\r\nH\r\nH\r\no\r\nn\r\nC\r\nK\r\nR\r\ns\r\nT\r\nJ\r\nv\r\nC\r\nZ\r\nd\r\nl\r\nr\r\no\r\nD\r\ng\r\na\r\nA\r\nE\r\nk\r\nN\r\nw\r\na\r\nb\r\no\r\nk\r\nv\r\nc\r\ni\r\nj\r\nE\r\nl\r\no\r\nf\r\nv\r\ns\r\nh\r\nx\r\nm\r\nE\r\nN\r\nt\r\nj\r\nk\r\ng\r\nk\r\nX\r\nW\r\ni\r\nX\r\nm\r\nw\r\nK\r\nL\r\nQ\r\nr\r\nj\r\nf\r\no\r\nw\r\nv\r\nS\r\no\r\nH\r\ne\r\nL\r\nL\r\nd\r\nP\r\nr\r\ng\r\nz\r\nz\r\nq\r\nd\r\nBBPVyRDLuNwdkeSYWimsIMiAPiOMQfuDQMcLEly\r\nq\r\n'], 'output': ['QQQQyQQQuQqqqqQYQqqqQQqQQqQQAquQAQqQQqy\r\n']}, {'input': ['77\r\nGw\r\nZw\r\nqg\r\neO\r\nmx\r\nfE\r\nqD\r\nVv\r\nRs\r\nbd\r\nwA\r\nnh\r\nDm\r\nbR\r\nxV\r\nwe\r\nKH\r\nbl\r\nVy\r\naJ\r\nFr\r\nNP\r\nir\r\nxh\r\nFq\r\nDG\r\nNh\r\ndW\r\naG\r\nkm\r\nNS\r\nOm\r\nyC\r\nts\r\nZt\r\nEN\r\nFs\r\njA\r\nvf\r\nde\r\nDa\r\nAW\r\nBv\r\nmO\r\nDk\r\nYj\r\nfl\r\ndj\r\nJF\r\ndI\r\nhr\r\nzk\r\nam\r\nLT\r\nPJ\r\nAQ\r\nOW\r\nWN\r\nUG\r\nTL\r\nSZ\r\nBK\r\nLp\r\njW\r\nrY\r\nPB\r\nRj\r\nBw\r\ngl\r\nlK\r\nWj\r\nPl\r\nfx\r\nYO\r\nbX\r\nSN\r\nPt\r\nxPDCKNGWsNSlScKgBNEooOTnSuycVtvdToGmFoEfsUorvsSNcQIlaXRQqrfTZZoNvjutjhGpGXmNSQQWCzeHhMJAxclmiNnErpxH\r\nh\r\n'], 'output': ['xPDCKNHHhHHlScKgBNHhoOThHuhhVtvdToGmFoEhhUorvsHHcQIlaXRQqrfTZZoNvjutjhGpGXmHHQQWCzeHhMHHxclmiNnErphA\r\n']}, {'input': ['100\r\nqn\r\nBE\r\nyN\r\nep\r\nPq\r\nXz\r\nLM\r\nEZ\r\ndb\r\nMn\r\nbn\r\nFe\r\nqA\r\nzc\r\nyq\r\npC\r\nyA\r\nWk\r\nYq\r\nrs\r\noD\r\nvD\r\nzW\r\nxZ\r\nbl\r\nur\r\nkf\r\ndf\r\nLS\r\nUW\r\nMy\r\nhR\r\nsh\r\nNh\r\nog\r\nCW\r\nor\r\nzo\r\nrO\r\nao\r\nXH\r\nDq\r\nKa\r\nlL\r\nYQ\r\nOh\r\nRZ\r\nAx\r\nta\r\nko\r\nDn\r\nNg\r\nNy\r\nDB\r\nYD\r\njO\r\nAp\r\nFT\r\noB\r\nNc\r\nwB\r\nHO\r\neW\r\nAc\r\nDr\r\nMt\r\nDf\r\nbF\r\nFP\r\nRa\r\nnF\r\nhF\r\nXC\r\nnG\r\nan\r\nZY\r\nuB\r\nHP\r\nOR\r\nKN\r\nUv\r\nLe\r\nIj\r\nlH\r\nVw\r\njb\r\nXn\r\nqu\r\nJo\r\nzL\r\nKW\r\nLS\r\naV\r\nLs\r\nBX\r\nMY\r\noK\r\nfh\r\ngP\r\nTB\r\npBWBEkqznLlZykhmPrfidzWbQMNDdBaDLykOfdvOZjKoUxCqKwJdGuhseuxaYcVyAGTSTwXYmKweRMUdbyfxssSNGLSAhckIknDj\r\nd\r\n'], 'output': ['pBDDDkqznDdDdkhmPrfiddDdQDDDaDaDLydDfdvOZjDdUdDqDdJdGuhseuxaYcVdDGTSTwXYmDdeRMUadyfxssSDDDDAhckIddDj\r\n']}, {'input': ['3\r\na\r\nA\r\na\r\nA\r\na\r\n'], 'output': ['B\r\n']}, {'input': ['3\r\na\r\nA\r\na\r\nA\r\nb\r\n'], 'output': ['B\r\n']}, {'input': ['4\r\na\r\nA\r\ni\r\nA\r\nPetyaIsVeryCoolGuy\r\np\r\n'], 'output': ['PetypPsVeryCoolGuy\r\n']}, {'input': ['3\r\njap\r\nthd\r\ndshipssinceW\r\nJapanisexperiencingitsgreatesthardshipssinceWorldWarIIthardshipssinceWorldWarIItesthardshixper\r\nc\r\n'], 'output': ['CccanisexperiencingitsgreatestharcccccccccacCorldWarIItharcccccccccacCorldWarIItesthardshixper\r\n']}, {'input': ['3\r\njap\r\nthd\r\ndshipssinceW\r\nJapanisexperiencingitsgreatesthardshipssinceWorldWarIIthardshipssinceWorldWarIItesthardshixper\r\na\r\n'], 'output': ['AbaanisexperiencingitsgreatestharaaaaaaaaaaaAorldWarIItharaaaaaaaaaaaAorldWarIItesthardshixper\r\n']}, {'input': ['7\r\na\r\nh\r\nu\r\np\r\nfgh\r\nwyz\r\ndefghijkl\r\nabcdefghijklmnopqrstuvwxyz\r\na\r\n'], 'output': ['bbcaaaaaaaaamnoaqrstavwxyz\r\n']}, {'input': ['9\r\na\r\nh\r\nu\r\np\r\nz\r\nfgh\r\nwyz\r\ndefghijkl\r\nghijklmnopqrstu\r\nabcdefghijklmnopqrstuvwxyz\r\na\r\n'], 'output': ['bbcaaaaaaaaaaaaaaaaaavwxya\r\n']}, {'input': ['3\r\nab\r\nBa\r\naB\r\nABBA\r\nl\r\n'], 'output': ['LLLL\r\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 run() {
    input! {
        n: usize,
        p: [[i64; 5]; n],
    }
    if n > 100 {
        println!("0");
        return;
    }
    let mut ans = vec![];
    for i in 0..n {
        let mut q = p.clone();
        let p = q.remove(i);
        for q in q.iter_mut() {
            for (q, p) in q.iter_mut().zip(p.iter()) {
                *q -= *p;
            }
        }
        let mut ok = true;
        for (i, a) in q.iter().enumerate() {
            for b in q.iter().take(i) {
                let mut sum = 0;
                for (a, b) in a.iter().zip(b.iter()) {
                    sum += *a * *b;
                }
                if sum > 0 {
                    ok = false;
                }
            }
        }
        if ok {
            ans.push(i + 1);
        }
    }
    println!("{}", ans.len());
    for (i, a) in ans.iter().enumerate() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", a);
    }
    println!();
}

fn main() {
    run();
}


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

#[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 (n, m) = parse_line!(usize, usize);
    let mut a = Vec::new();
    let mut pro = vec![0; n];
    let mut con = vec![0; n];
    let mut cons = 0;
    for _ in 0..n {
        let x = parse_line!(i32);
        a.push(x);
        if x > 0 {
            pro[(x - 1) as usize] += 1;
        }else{
            con[(-x - 1) as usize] += 1;
            cons += 1;
        }
    }
    let mut candidates = vec![false; n];
    let mut single = false;
    let mut more = false;
    for i in 0..n {
        if pro[i] + cons - con[i] == m {
            more = single;
            single = true;
            candidates[i] = true;
        }
    }
    for x in a {
        if x > 0 {
            if candidates[(x - 1) as usize] {
                if single && !more {
                    writeln!(writer, "Truth").unwrap();
                }else{
                    writeln!(writer, "Not defined").unwrap();
                }
            }else{
                writeln!(writer, "Lie").unwrap();
            }
        }else{
            if !candidates[(-x - 1) as usize] {
                writeln!(writer, "Truth").unwrap();
            }else{
                if single && !more {
                    writeln!(writer, "Lie").unwrap();
                }else{
                    writeln!(writer, "Not defined").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);
    }
}

[{'input': '1 1\r\n+1\r\n', 'output': ['Truth\r\n']}, {'input': '3 2\r\n-1\r\n-2\r\n-3\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '4 1\r\n+2\r\n-3\r\n+4\r\n-1\r\n', 'output': ['Lie\r\nNot defined\r\nLie\r\nNot defined\r\n']}, {'input': '1 0\r\n-1\r\n', 'output': ['Lie\r\n']}, {'input': '2 2\r\n+1\r\n+1\r\n', 'output': ['Truth\r\nTruth\r\n']}, {'input': '2 1\r\n+2\r\n+1\r\n', 'output': ['Not defined\r\nNot defined\r\n']}, {'input': '2 0\r\n-2\r\n-2\r\n', 'output': ['Lie\r\nLie\r\n']}, {'input': '3 1\r\n+2\r\n+3\r\n+3\r\n', 'output': ['Truth\r\nLie\r\nLie\r\n']}, {'input': '6 3\r\n+5\r\n+5\r\n+5\r\n+1\r\n+1\r\n+1\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '4 3\r\n-4\r\n-3\r\n-1\r\n-3\r\n', 'output': ['Not defined\r\nTruth\r\nNot defined\r\nTruth\r\n']}, {'input': '10 4\r\n-8\r\n+1\r\n-6\r\n-10\r\n+5\r\n-6\r\n-8\r\n-8\r\n-4\r\n-8\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 5\r\n-4\r\n+4\r\n+4\r\n-9\r\n-9\r\n-4\r\n-4\r\n+2\r\n-9\r\n-4\r\n', 'output': ['Lie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '7 2\r\n+5\r\n+5\r\n+5\r\n-2\r\n+1\r\n-5\r\n-6\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nNot defined\r\nLie\r\nTruth\r\nNot defined\r\n']}, {'input': '7 4\r\n+7\r\n-3\r\n-3\r\n-4\r\n+3\r\n+3\r\n+3\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '6 3\r\n-6\r\n-1\r\n+5\r\n+1\r\n+6\r\n+1\r\n', 'output': ['Truth\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\nNot defined\r\n']}, {'input': '5 3\r\n-2\r\n+2\r\n+2\r\n-3\r\n+5\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\n']}, {'input': '3 0\r\n-2\r\n-2\r\n-2\r\n', 'output': ['Lie\r\nLie\r\nLie\r\n']}, {'input': '5 3\r\n-1\r\n-1\r\n-4\r\n+1\r\n-4\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\n']}, {'input': '9 6\r\n+2\r\n+7\r\n+7\r\n-1\r\n-4\r\n+7\r\n-7\r\n+7\r\n+5\r\n', 'output': ['Lie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '43 18\r\n-14\r\n-28\r\n+16\r\n+10\r\n+25\r\n-30\r\n+25\r\n+30\r\n+25\r\n+25\r\n+25\r\n+25\r\n-25\r\n+22\r\n+3\r\n-17\r\n+16\r\n-25\r\n+10\r\n+14\r\n+41\r\n+25\r\n-25\r\n+33\r\n+24\r\n-23\r\n-25\r\n+25\r\n-22\r\n+29\r\n+28\r\n-25\r\n-25\r\n-29\r\n+11\r\n+26\r\n-25\r\n+25\r\n+10\r\n+1\r\n-20\r\n-17\r\n+23\r\n', 'output': ['Truth\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '28 12\r\n+10\r\n-7\r\n+17\r\n-20\r\n+7\r\n-7\r\n+13\r\n-21\r\n-7\r\n-7\r\n-18\r\n+7\r\n+7\r\n+3\r\n+6\r\n+14\r\n+7\r\n-24\r\n-21\r\n-7\r\n-7\r\n+4\r\n+7\r\n-7\r\n+21\r\n-7\r\n-26\r\n+7\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': '17 9\r\n-6\r\n+16\r\n+5\r\n+16\r\n-17\r\n+17\r\n-11\r\n+5\r\n+14\r\n+5\r\n-8\r\n-5\r\n+6\r\n-2\r\n-11\r\n+4\r\n+17\r\n', 'output': ['Truth\r\nNot defined\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nTruth\r\nNot defined\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\n']}, {'input': '14 3\r\n+14\r\n+12\r\n-9\r\n+9\r\n-9\r\n-9\r\n+8\r\n+9\r\n+2\r\n+1\r\n-13\r\n-9\r\n+13\r\n+3\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\n']}, {'input': '10 4\r\n-9\r\n-8\r\n-5\r\n-9\r\n-7\r\n-9\r\n-9\r\n-9\r\n-4\r\n-9\r\n', 'output': ['Lie\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 5\r\n-10\r\n-10\r\n-10\r\n-5\r\n-1\r\n+10\r\n-3\r\n-10\r\n-9\r\n-10\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 4\r\n-3\r\n-3\r\n-3\r\n-3\r\n-3\r\n-2\r\n-2\r\n-6\r\n-7\r\n-3\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '10 6\r\n-9\r\n-7\r\n-5\r\n-5\r\n-4\r\n-2\r\n-8\r\n-5\r\n-5\r\n-9\r\n', 'output': ['Truth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 4\r\n-8\r\n-2\r\n-8\r\n+1\r\n-4\r\n-8\r\n-2\r\n-8\r\n-8\r\n-1\r\n', 'output': ['Lie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 2\r\n-8\r\n+10\r\n+1\r\n+8\r\n+4\r\n+8\r\n+6\r\n-8\r\n+10\r\n+1\r\n', 'output': ['Not defined\r\nLie\r\nLie\r\nNot defined\r\nLie\r\nNot defined\r\nLie\r\nNot defined\r\nLie\r\nLie\r\n']}, {'input': '10 3\r\n+9\r\n+3\r\n+8\r\n+3\r\n+6\r\n-3\r\n+6\r\n+8\r\n+3\r\n+7\r\n', 'output': ['Lie\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\n']}, {'input': '10 8\r\n-2\r\n+9\r\n+9\r\n-4\r\n+9\r\n+9\r\n+4\r\n-9\r\n-3\r\n+9\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': '10 7\r\n-4\r\n+6\r\n+4\r\n+9\r\n+6\r\n+6\r\n+6\r\n+6\r\n+6\r\n+2\r\n', 'output': ['Truth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '10 4\r\n+3\r\n+5\r\n+6\r\n+10\r\n+5\r\n+5\r\n+6\r\n+8\r\n+5\r\n+6\r\n', 'output': ['Lie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 7\r\n-6\r\n-10\r\n-3\r\n-1\r\n-3\r\n-7\r\n-2\r\n-7\r\n-7\r\n-3\r\n', 'output': ['Truth\r\nTruth\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '10 5\r\n-4\r\n-4\r\n-1\r\n-5\r\n-7\r\n-4\r\n-4\r\n-4\r\n-1\r\n-7\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': '10 5\r\n-9\r\n-7\r\n-6\r\n-3\r\n-10\r\n-10\r\n-10\r\n-10\r\n-10\r\n-2\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 3\r\n-10\r\n-10\r\n-10\r\n-3\r\n-10\r\n-10\r\n-10\r\n-8\r\n-4\r\n-10\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '10 5\r\n-8\r\n-8\r\n-4\r\n-9\r\n-10\r\n-2\r\n-9\r\n-8\r\n-8\r\n-8\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\n']}, {'input': '10 5\r\n+7\r\n+8\r\n+9\r\n+1\r\n+7\r\n+7\r\n+7\r\n+6\r\n+6\r\n+7\r\n', 'output': ['Truth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 5\r\n+2\r\n+2\r\n+2\r\n+2\r\n+9\r\n+10\r\n+8\r\n+7\r\n+4\r\n+2\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 9\r\n+7\r\n+7\r\n+7\r\n+7\r\n+7\r\n+7\r\n+5\r\n+7\r\n+7\r\n+7\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\n']}, {'input': '10 3\r\n+10\r\n+2\r\n+10\r\n+9\r\n+1\r\n+9\r\n+4\r\n+9\r\n+3\r\n+2\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\n']}, {'input': '10 6\r\n+10\r\n+10\r\n+10\r\n+3\r\n+10\r\n+10\r\n+6\r\n+6\r\n+10\r\n+8\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '3 2\r\n-1\r\n+2\r\n+3\r\n', 'output': ['Truth\r\nNot defined\r\nNot defined\r\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")
    };
}

//

// 最大値は貪欲に割り当てれば良い？
// 2冪を均等に割り振る、割り振れなかったのは2冪でない列に突っ込む
// 2冪でない列を貪欲に割り当てる
// 小さい値を小さい値に割り振る感じ
// これでできないならNo
// できたら？
// 小さい列を解消して再割り当てができるかというのを順に続けるといいか
// 計算量？
// 全部1とかだと割り当ての回数がO(N)になる、辛い
// 割り当て可能かは単調なので二分探索

fn valid(beki: &[u64], b: &mut [u64]) -> bool {
    b.sort();
    let mut p = 0;
    for pow in beki.iter().rev() {
        if p < b.len() && *pow * 2 >= b[p] {
            p += 1;
        }
    }
    p == b.len()
}

fn run() {
    input! {
        n: usize,
        a: [u64; n],
    }
    let mut beki = vec![];
    let mut k = 0;
    while k < n && a[k] == 1 {
        beki.push(1);
        k += 1;
    }
    if k == 0 {
        println!("-1");
        return;
    }
    let mut pos = 0;
    let mut b = vec![];
    for a in a[k..].iter() {
        if *a == beki[pos] * 2 {
            beki[pos] *= 2;
            pos = (pos + 1) % beki.len();
        } else {
            pos = 0;
            if *a == beki[pos] * 2 {
                beki[pos] *= 2;
                pos = (pos + 1) % beki.len();
            } else {
                b.push(*a);
            }
        }
    }
    let (beki, b) = (beki, b);
    if !valid(&beki, &mut b.clone()) {
        println!("-1");
        return;
    }
    let mut ok = beki.len();
    let mut ng = 0;
    while ok - ng > 1 {
        let mid = (ok + ng) / 2;
        let mut b = b.clone();
        for p in beki[mid..].iter() {
            let mut k = 1;
            while k <= *p {
                b.push(k);
                k *= 2;
            }
        }
        if valid(&beki[..mid], &mut b) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    let mut s = String::new();
    for k in ok..=beki.len() {
        s.push_str(&format!("{} ", k));
    }
    s.pop();
    println!("{}", s);
}

fn main() {
    run();
}


import std.format;
import std.stdio;
import std.string;

void main() {
    string s = strip(readln());

    int lucky = 0;
    foreach (c; s) {
        if (c == '4' || c == '7') lucky++;
    }
    writeln(
        lucky == 4 || lucky == 7 ?
        "YES" : "NO"
    );
}


import std.stdio, std.string, std.conv;
import std.algorithm, std.array, std.bigint, std.math, std.range;
import core.thread;

//  Input
string[] tokens;
int tokenId = 0;
string readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }

int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

//  chmin/chmax
void chmin(T)(ref T t, T f) { if (t > f) t = f; }
void chmax(T)(ref T t, T f) { if (t < f) t = f; }

int N;
string source = "abcd";

void main () {
    N = readInt();

    foreach (int i; 0 .. N) {
        writef("%s", source[i % 4]);
    }
    writeln("");
}

[{'input': ['5\r\n'], 'output': ['abcda\r\n']}, {'input': ['3\r\n'], 'output': ['abc\r\n']}, {'input': ['8\r\n'], 'output': ['abcdabcd\r\n']}, {'input': ['10\r\n'], 'output': ['abcdabcdab\r\n']}, {'input': ['16\r\n'], 'output': ['abcdabcdabcdabcd\r\n']}, {'input': ['64\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\r\n']}, {'input': ['128\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\r\n']}, {'input': ['100\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\r\n']}, {'input': ['47\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc\r\n']}, {'input': ['74\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdab\r\n']}, {'input': ['477\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcda\r\n']}, {'input': ['1\r\n'], 'output': ['a\r\n']}, {'input': ['2\r\n'], 'output': ['ab\r\n']}, {'input': ['7\r\n'], 'output': ['abcdabc\r\n']}, {'input': ['4\r\n'], 'output': ['abcd\r\n']}, {'input': ['99\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc\r\n']}, {'input': ['6\r\n'], 'output': ['abcdab\r\n']}, {'input': ['9\r\n'], 'output': ['abcdabcda\r\n']}]


module cf_137B;

import std.stdio, std.algorithm;

void main() {
	int n;
	int[] numbers;

	readf("%d", &n);
	numbers = new int[n];
	for (auto i = 0; i < n; ++i) {
		readf(" %d", &numbers[i]);
	}

	sort(numbers);

	int skip = 0, index = 0;
	for (auto i = 1; i <= n; ++i) {
		if (index >= n) {
			++skip;
			continue;
		}

		if (numbers[index] == i) {
			while (index < n && numbers[index] == i) {
				++index;
			}
		} else {
			++skip;
		}
	}

	writeln(skip);
}


import std.stdio;
import std.format;
import std.container;
import std.string;
import std.algorithm;
import std.conv;

class Line
{
    public const ptrdiff_t firstStar;
    public const ptrdiff_t lastStar;
    public const string line;

    this(in string line)
    {
        this.firstStar = std.string.indexOf(line, '*');
        this.lastStar = std.string.lastIndexOf(line, '*');
        this.line = line;
    }

    invariant()
    {
        assert(firstStar <= lastStar, format("Last star cannot be before the first one: %s, %s", firstStar, lastStar));
        assert(firstStar >= 0 || (firstStar == -1 && lastStar == -1), "Both indexes must be -1 or >= 0");
    }
}

void testDotsCount(in string line, in ptrdiff_t firstStar, in ptrdiff_t lastStar)
{
    Line l;
    l = new Line(line);
    assert(l.firstStar == firstStar, format("Bad first star index: expected %s, got %s", firstStar, l.firstStar));
    assert(l.lastStar == lastStar, format("Bad last star index: expected %s, got %s", lastStar, l.lastStar));
}

unittest
{
    testDotsCount("..*...", 2, 2);
}

unittest
{
    testDotsCount("*...", 0, 0);
}

unittest
{
    testDotsCount("*", 0, 0);
}

unittest
{
    testDotsCount("***", 0, 2);
}

unittest
{
    testDotsCount("..***...*.*..", 2, 10);
}

void main()
{
    string firstLine = stdin.readln();
    int rows;
    int cols;
    formattedRead(firstLine, "%s %s", &rows, &cols);

    ptrdiff_t minFirstStar = -1;
    ptrdiff_t maxLastStar = -1;

    Line[50] lines;

    int firstLineWithStar = rows;
    int lastLineWithStar = 0;

    for (int i = 0; i < rows; i++) {
        Line l = new Line(stdin.readln());
        lines[i] = l;
        maxLastStar = max(maxLastStar, l.lastStar);
        if (l.firstStar != -1) {
            lastLineWithStar = i;
            firstLineWithStar = min(firstLineWithStar, i);
            if (minFirstStar == -1) {
                minFirstStar = l.firstStar;
            } else {
                minFirstStar = min(minFirstStar, l.firstStar);
            }
        }
    }
    for (int i = firstLineWithStar; i <= lastLineWithStar; i++)
    {
        stdout.writeln(lines[i].line[minFirstStar .. maxLastStar + 1]);
    }
}


import core.bitop, std.bitmanip;
import std.algorithm, std.functional;
import std.array, std.container;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

immutable int INF = 10L ^^ 9 + 23;

void main()
{
    auto ns = readln.chomp.split.map!(to!int).array;

    auto vals = new int[][][] (2, 1001, 1001);
    foreach (i; 0 .. 2) {
        foreach (_; 0 .. ns[i]) {
            int x, y;
            readf("%s %s", &x, &y);
            readln;
            vals[i][y][x] += 1;
        }
    }

    int u = 0, v = 0;
    foreach (d; 1 .. 1001) {
        int mleft = 0, cleft = 0;
        int ok = 0;
        foreach (c; 1 .. 1001) {
            ok += min(vals[0][d][c], vals[1][d][c]);
            if (vals[0][d][c] > vals[1][d][c]) mleft += vals[0][d][c] - vals[1][d][c];
            else cleft += vals[1][d][c] - vals[0][d][c];
        }

        u += ok;
        v += ok;

        u += min(mleft, cleft);
    }

    writeln(u, ' ', v);
}


import std.conv, std.string, std.stdio, std.algorithm, std.typecons;

void main()
{
    auto nm = readln.split.map!(to!long);
    auto n = nm[0], m = nm[1];
    auto t = [tuple(0L,0L)];
    foreach(i; 0..m)
    {
        auto v = readln.split.map!(to!long);
        t ~= tuple(v[0],v[1]);
    }
    t.sort!"a[1]>b[1]";
    auto count = 0;
    for (auto i = 0, j = n; i < m && j > 0; i++ ) {
        if (j-t[i][0] >= 0)
            count += t[i][0] * t[i][1];
        else
            count += j * t[i][1];
        j-=t[i][0];
    }
    writeln(count);
}


//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.algorithm;
import std.functional;
import std.array;
import std.container;
import std.conv;
import std.container;
import std.typecons;
import std.math;
import std.numeric;
pragma(inline,true);

void main(){
    string a=readln.strip,
           b=readln.strip;
    if(a==b.dup.reverse)
        writeln("YES");
    else
        writeln("NO");
}

[{'input': ['code\r\nedoc\r\n'], 'output': ['YES\r\n']}, {'input': ['abb\r\naba\r\n'], 'output': ['NO\r\n']}, {'input': ['code\r\ncode\r\n'], 'output': ['NO\r\n']}, {'input': ['abacaba\r\nabacaba\r\n'], 'output': ['YES\r\n']}, {'input': ['q\r\nq\r\n'], 'output': ['YES\r\n']}, {'input': ['asrgdfngfnmfgnhweratgjkk\r\nasrgdfngfnmfgnhweratgjkk\r\n'], 'output': ['NO\r\n']}, {'input': ['z\r\na\r\n'], 'output': ['NO\r\n']}, {'input': ['asd\r\ndsa\r\n'], 'output': ['YES\r\n']}, {'input': ['abcdef\r\nfecdba\r\n'], 'output': ['NO\r\n']}, {'input': ['ywjjbirapvskozubvxoemscfwl\r\ngnduubaogtfaiowjizlvjcu\r\n'], 'output': ['NO\r\n']}, {'input': ['mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\r\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf\r\n'], 'output': ['NO\r\n']}, {'input': ['bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\r\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp\r\n'], 'output': ['NO\r\n']}, {'input': ['pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\r\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb\r\n'], 'output': ['NO\r\n']}, {'input': ['gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\r\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom\r\n'], 'output': ['NO\r\n']}, {'input': ['umeszdawsvgkjhlqwzents\r\nhxqhdungbylhnikwviuh\r\n'], 'output': ['NO\r\n']}, {'input': ['juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\r\nibqvffmfktyipgiopznsqtrtxiijntdbgyy\r\n'], 'output': ['NO\r\n']}, {'input': ['zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\r\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko\r\n'], 'output': ['NO\r\n']}, {'input': ['nkgwuugukzcv\r\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv\r\n'], 'output': ['NO\r\n']}, {'input': ['incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\r\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd\r\n'], 'output': ['NO\r\n']}, {'input': ['w\r\nw\r\n'], 'output': ['YES\r\n']}, {'input': ['vz\r\nzv\r\n'], 'output': ['YES\r\n']}, {'input': ['ry\r\nyr\r\n'], 'output': ['YES\r\n']}, {'input': ['xou\r\nuox\r\n'], 'output': ['YES\r\n']}, {'input': ['axg\r\ngax\r\n'], 'output': ['NO\r\n']}, {'input': ['zdsl\r\nlsdz\r\n'], 'output': ['YES\r\n']}, {'input': ['kudl\r\nldku\r\n'], 'output': ['NO\r\n']}, {'input': ['zzlzwnqlcl\r\nlclqnwzlzz\r\n'], 'output': ['YES\r\n']}, {'input': ['vzzgicnzqooejpjzads\r\nsdazjpjeooqzncigzzv\r\n'], 'output': ['YES\r\n']}, {'input': ['raqhmvmzuwaykjpyxsykr\r\nxkysrypjkyawuzmvmhqar\r\n'], 'output': ['NO\r\n']}, {'input': ['ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\r\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn\r\n'], 'output': ['YES\r\n']}, {'input': ['muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\r\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum\r\n'], 'output': ['YES\r\n']}, {'input': ['vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\r\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv\r\n'], 'output': ['YES\r\n']}, {'input': ['mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\r\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm\r\n'], 'output': ['NO\r\n']}, {'input': ['dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\r\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd\r\n'], 'output': ['NO\r\n']}, {'input': ['gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\r\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg\r\n'], 'output': ['YES\r\n']}, {'input': ['sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\r\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis\r\n'], 'output': ['YES\r\n']}, {'input': ['ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\r\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy\r\n'], 'output': ['NO\r\n']}, {'input': ['wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\r\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw\r\n'], 'output': ['YES\r\n']}, {'input': ['imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\r\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi\r\n'], 'output': ['YES\r\n']}, {'input': ['bikydffiuisckpvzqlteqfhegsagimodb\r\nbdomigasgehfqetlqzvpkcsiuiffdykib\r\n'], 'output': ['YES\r\n']}]


import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.array;
import std.range;

void main()
{
    auto nm = readln.split.map!(to!int);
    auto ts = readln.split.map!(to!int);
    auto count = 0;
    auto d = nm[1]-ts[0];
    foreach(t; ts.dropOne) {
        if (d<0) {
            writeln(-1);
            return;
        } else {
            d-=10;
            count+=2;
        }
        //writef("d=%d c=%d ",d,count);
        d-=t;
    }
    if (d<0) {
        writeln(-1);
        return;
    }
    while (d>=10) {
        d-=10;
        count+=2;
    }
    if (d>=5) { count++;}
    writeln(count);
}


module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;
import std.array;

struct IO {
        string read_string() {
                while (tokens.empty) {
                tokens = readln.split;
        }
        auto token = tokens.front;
                tokens.popFront;
                return token;
        }

        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void printSpaces(int n) {
        while (n--) {
                write(" ");
        }
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                string[] arr = stdin.byLineCopy.array;
                // writeln(arr[0..$]);
                int max_len = -999;
                foreach(i; arr) {
                        max_len = max(max_len, cast(int)i.length);
                }

                for (int i = 0; i < max_len + 2; i++) {
                        write("*");
                }
                int alt = 0;
                writeln();
                for (int i = 0; i < arr.length; i++) {
                        write("*");
                        int sample_len = cast(int)arr[i].length;
                        int diff = (max_len - sample_len);
                        if (diff % 2 == 0) {
                                printSpaces(diff / 2);
                                write(arr[i]);
                                printSpaces(diff / 2);
                        } else {
                                if (alt % 2 == 0) {
                                        printSpaces(diff / 2);
                                        write(arr[i]);
                                        printSpaces(diff / 2 + 1);
                                        alt = 1;
                                } else {
                                        printSpaces(diff / 2 + 1);
                                        write(arr[i]);
                                        printSpaces(diff / 2);
                                        alt = 0;
                                }
                        }
                        writeln("*");
                }

                for (int i = 0; i < max_len + 2; i++) {
                        write("*");
                }
        }
}


module cf_63A;

import std.stdio;
import std.algorithm;

struct Member {
    string name, type;

    int opCmp(ref const Member other) {
        int[string] TYPE_PRIORITY = [
            "rat": 1, "woman": 2, "child": 2, "man": 3, "captain": 4
        ];

        return TYPE_PRIORITY[type] - TYPE_PRIORITY[other.type];
    }
}

void main() {
    int n;
    Member[] crew;

    readf("%d", &n);
    crew = new Member[n];
    for (int i = 0; i < n; ++i) {
        readf(" %s %s\n", &crew[i].name, &crew[i].type);
    }

    sort!("a < b", SwapStrategy.stable)(crew);
    for (int i = 0; i < crew.length; ++i) {
        writeln(crew[i].name);
    }
}

[{'input': ['6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n'], 'output': ['Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n']}, {'input': ['1\r\nA captain\r\n'], 'output': ['A\r\n']}, {'input': ['1\r\nAbcdefjhij captain\r\n'], 'output': ['Abcdefjhij\r\n']}, {'input': ['5\r\nA captain\r\nB man\r\nD woman\r\nC child\r\nE rat\r\n'], 'output': ['E\r\nD\r\nC\r\nB\r\nA\r\n']}, {'input': ['10\r\nCap captain\r\nD child\r\nC woman\r\nA woman\r\nE child\r\nMan man\r\nB child\r\nF woman\r\nRat rat\r\nRatt rat\r\n'], 'output': ['Rat\r\nRatt\r\nD\r\nC\r\nA\r\nE\r\nB\r\nF\r\nMan\r\nCap\r\n']}, {'input': ['5\r\nJoyxnkypf captain\r\nDxssgr woman\r\nKeojmnpd rat\r\nGdv man\r\nHnw man\r\n'], 'output': ['Keojmnpd\r\nDxssgr\r\nGdv\r\nHnw\r\nJoyxnkypf\r\n']}, {'input': ['11\r\nJue rat\r\nWyglbyphk rat\r\nGjlgu child\r\nGi man\r\nAttx rat\r\nTheorpkgx man\r\nYm rat\r\nX child\r\nB captain\r\nEnualf rat\r\nKktsgyuyv woman\r\n'], 'output': ['Jue\r\nWyglbyphk\r\nAttx\r\nYm\r\nEnualf\r\nGjlgu\r\nX\r\nKktsgyuyv\r\nGi\r\nTheorpkgx\r\nB\r\n']}, {'input': ['22\r\nWswwcvvm woman\r\nBtmfats rat\r\nI rat\r\nOcmtsnwx man\r\nUrcqv rat\r\nYghnogt woman\r\nWtyfc man\r\nWqle child\r\nUjfrelpu rat\r\nDstixj man\r\nAhksnio woman\r\nKhkvaap woman\r\nSjppvwm rat\r\nEgdmsv rat\r\nDank rat\r\nNquicjnw rat\r\nLh captain\r\nTdyaqaqln rat\r\nQtj rat\r\nTfgwijvq rat\r\nNbiso child\r\nNqthvbf woman\r\n'], 'output': ['Btmfats\r\nI\r\nUrcqv\r\nUjfrelpu\r\nSjppvwm\r\nEgdmsv\r\nDank\r\nNquicjnw\r\nTdyaqaqln\r\nQtj\r\nTfgwijvq\r\nWswwcvvm\r\nYghnogt\r\nWqle\r\nAhksnio\r\nKhkvaap\r\nNbiso\r\nNqthvbf\r\nOcmtsnwx\r\nWtyfc\r\nDstixj\r\nLh\r\n']}, {'input': ['36\r\nKqxmtwmsf child\r\nIze woman\r\nDlpr child\r\nK woman\r\nF captain\r\nRjwfeuhba rat\r\nBbv rat\r\nS rat\r\nMnmg woman\r\nSmzyx woman\r\nSr man\r\nQmhroracn rat\r\nSoqpuqock rat\r\nPibdq man\r\nIlrkrptx rat\r\nZaecfyqka man\r\nMmersfs child\r\nVvvocqi man\r\nHjeqxvq rat\r\nMpmb woman\r\nWmgu woman\r\nCerelmhoxi child\r\nA man\r\nDylv man\r\nXrdgmmtcpq woman\r\nXj woman\r\nCeh child\r\nOfccguo man\r\nNevr man\r\nAknkwdkq child\r\nBmo man\r\nLqo woman\r\nVej child\r\nT child\r\nRlijc man\r\nNsdtpdg woman\r\n'], 'output': ['Rjwfeuhba\r\nBbv\r\nS\r\nQmhroracn\r\nSoqpuqock\r\nIlrkrptx\r\nHjeqxvq\r\nKqxmtwmsf\r\nIze\r\nDlpr\r\nK\r\nMnmg\r\nSmzyx\r\nMmersfs\r\nMpmb\r\nWmgu\r\nCerelmhoxi\r\nXrdgmmtcpq\r\nXj\r\nCeh\r\nAknkwdkq\r\nLqo\r\nVej\r\nT\r\nNsdtpdg\r\nSr\r\nPibdq\r\nZaecfyqka\r\nVvvocqi\r\nA\r\nDylv\r\nOfccguo\r\nNevr\r\nBmo\r\nRlijc\r\nF\r\n']}, {'input': ['2\r\nA captain\r\nB man\r\n'], 'output': ['B\r\nA\r\n']}, {'input': ['2\r\nB woman\r\nA captain\r\n'], 'output': ['B\r\nA\r\n']}, {'input': ['2\r\nX child\r\nY captain\r\n'], 'output': ['X\r\nY\r\n']}, {'input': ['2\r\nX captain\r\nY rat\r\n'], 'output': ['Y\r\nX\r\n']}, {'input': ['6\r\nAbdelrhman captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n'], 'output': ['Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nAbdelrhman\r\n']}, {'input': ['4\r\nAratos captain\r\nMind child\r\nAman woman\r\nCarrot man\r\n'], 'output': ['Mind\r\nAman\r\nCarrot\r\nAratos\r\n']}]


import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.algorithm;

void main()
{
    readln;
    auto ab = readln.split.map!(to!int).retro.take(2);
    writeln(ab[0]==15   ? "DOWN" :
            ab[0]==0    ? "UP"   :
            ab.length<2 ? "-1"   :
            ab[0]>ab[1] ? "UP"   :
                         "DOWN" );
}


import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip;
		int res = 5;
		string ans = "?????";
		foreach (c; 0..10_000)
		{
			int h = c / 100;
			if (n == 12 && !(1 <= h && h <= 12))
			{
				continue;
			}
			if (n == 24 && !(0 <= h && h <= 23))
			{
				continue;
			}
			int m = c % 100;
			if (!(0 <= m && m <= 59))
			{
				continue;
			}
			auto t = format ("%02d:%02d", h, m);
			auto cur = t.length.iota.map !(x => s[x] != t[x]).sum;
			if (res > cur)
			{
				res = cur;
				ans = t;
			}
		}
		writeln (ans);
	}
}


module cf_74a;

import std.stdio;

void main() {
  int n;
  string nick, leaderNick;
  int plus, minus, a, b, c, d, e;
  int leaderScore = int.min;

  readf("%d", &n);
  for (int i = 0; i < n; ++i) {
    readf(" %s ", &nick);
    readf(" %d %d", &plus, &minus);
    readf(" %d %d %d %d %d", &a, &b, &c, &d, &e);

    int curScore = plus * 100 - minus * 50 + a + b + c + d + e;
    if (curScore > leaderScore) {
      leaderScore = curScore;
      leaderNick = nick;
    }
  }

  writeln(leaderNick);
}


// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio      : readln, writeln;
import std.array      : split;
import std.string     : chomp;
import std.conv       : to;

auto gets() { return readln.chomp; }
auto getVals(T)() { return gets.split.to!(T[]); }

void main() {
    auto xs = getVals!long;
    auto l = xs[0], r = xs[1], x = xs[2], y = xs[3], k = xs[4];
    for (auto i = x; i <= y; i++) {
        auto v = i * k;
        if (l <= v && v <= r) {
            writeln("YES");
            return;
        }
    }
    writeln("NO");
}


module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string read_string() {
                while (tokens.empty) {
                tokens = readln.split;
        }
        auto token = tokens.front;
                tokens.popFront;
                return token;
        }
        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

char[] dec_to_binary(int n) {
        char[] s;
        while (n > 0) {
                s ~= (n & 1) + 48;
                n >>= 1;
        }
        reverse(s);
        return s;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int count = 0;
                for (int i = 1; i < (1 << 10); i++) {
                        if (dec_to_binary(i).to!long <= n) {
                                count++;
                        } else break;
                }
                writeln(count);
        }
}


import std.stdio, std.range, std.algorithm, std.string, std.conv, std.typecons;

void main(){
	auto x=readln().strip.split.map!(to!int).array;
	int n=x[0],m=x[1],c0=x[2],d0=x[3];
	auto buns=iota(m).map!(_=>readln().strip.split.map!(to!int).array);
	Tuple!(int,int)[] ss;
	foreach(bun;chain(only([0,0,c0,d0]),buns)){
		int num=bun[1]?bun[0]/bun[1]:2000;
		int cost=bun[2];
		int benefit=bun[3];
		foreach(k;0..num) ss~=tuple(cost,benefit);
	}
	auto t=0.repeat(n+1).array;
	foreach(s;ss){
		foreach_reverse(i;0..t.length){
			if(i<s[0]) continue;
			t[i]=max(t[i],t[i-s[0]]+s[1]);
		}
	}
	writeln(t[n]);
}


import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

struct ModInt(int M_) {
  import std.conv : to;
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      if (a < 0) return (this = inv()^^(-a));
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e > 0; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op: "-")() const { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const {
    return mixin("ModInt(this) " ~ op ~ "= a");
  }
  ModInt opBinaryRight(string op)(long a) const {
    return mixin("ModInt(a) " ~ op ~ "= this");
  }
  bool opCast(T: bool)() const { return (x != 0); }
  string toString() const { return x.to!string; }
}

enum MO = 998244353;
alias Mint = ModInt!MO;

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const M = readInt();
      auto A = new long[N];
      foreach (i; 0 .. N) {
        A[i] = readLong();
      }

      long[] bases;
      foreach (i; 0 .. N) {
        long a = A[i];
        foreach (base; bases) {
          chmin(a, a ^ base);
        }
        if (a) {
          bases ~= a;
        }
      }
      bases.sort!"a > b";
      const r = cast(int)(bases.length);
      foreach (j; 0 .. r) {
        foreach (k; j + 1 .. r) {
          chmin(bases[k], bases[k] ^ bases[j]);
        }
      }
      debug {
        foreach (base; bases) {
          writefln("%0*b", M, base);
        }
      }

      long[] ps, qs;
      foreach (j; 0 .. r) {
        if (bases[j] & ~((1L << (M / 2)) - 1)) {
          ps ~= bases[j];
        } else {
          qs ~= bases[j];
        }
      }
      debug {
        writeln("ps = ", ps);
        writeln("qs = ", qs);
      }
      const psLen = cast(int)(ps.length);
      const qsLen = cast(int)(qs.length);
      auto psSum = new long[1 << psLen];
      auto qsSum = new long[1 << qsLen];
      foreach (j; 0 .. psLen) {
        foreach (h; 0 .. 1 << j) {
          psSum[h | 1 << j] = psSum[h] ^ ps[j];
        }
      }
      foreach (j; 0 .. qsLen) {
        foreach (h; 0 .. 1 << j) {
          qsSum[h | 1 << j] = qsSum[h] ^ qs[j];
        }
      }
      auto xss = new Mint[][](M - M / 2 + 1, 1 << (M / 2));
      auto ys = new Mint[1 << (M / 2)];
      foreach (h; 0 .. 1 << psLen) {
        xss[popcnt(psSum[h] >> (M / 2))][cast(int)(psSum[h] & ((1L << (M / 2)) - 1))] += 1;
      }
      foreach (h; 0 .. 1 << qsLen) {
        ys[cast(int)(qsSum[h])] += 1;
      }

      foreach (e; 0 .. M / 2) {
        foreach (f; 0 .. 1 << (M / 2)) {
          if (!(f & 1 << e)) {
            const tmp = ys[f] - ys[f | 1 << e];
            ys[f] += ys[f | 1 << e];
            ys[f | 1 << e] = tmp;
          }
        }
      }
      const invTwo = Mint(2)^^(-(M / 2));
      auto ans = new Mint[M + 1];
      foreach (s; 0 .. M - M / 2 + 1) {
        foreach (e; 0 .. M / 2) {
          foreach (f; 0 .. 1 << (M / 2)) {
            if (!(f & 1 << e)) {
              const tmp = xss[s][f] - xss[s][f | 1 << e];
              xss[s][f] += xss[s][f | 1 << e];
              xss[s][f | 1 << e] = tmp;
            }
          }
        }
        xss[s][] *= ys[];
        xss[s][] *= invTwo;
        foreach (e; 0 .. M / 2) {
          foreach (f; 0 .. 1 << (M / 2)) {
            if (!(f & 1 << e)) {
              const tmp = xss[s][f] - xss[s][f | 1 << e];
              xss[s][f] += xss[s][f | 1 << e];
              xss[s][f | 1 << e] = tmp;
            }
          }
        }
        foreach (f; 0 .. 1 << (M / 2)) {
          ans[s + popcnt(f)] += xss[s][f];
        }
      }

      ans[] *= Mint(2)^^(N - r);
      foreach (s; 0 .. M + 1) {
        if (s > 0) write(" ");
        write(ans[s]);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}


// Vicfred
// https://codeforces.com/contest/1400/problem/B
//
import std.algorithm;
import std.stdio;

void main() {
    long t, p, f, cnts, cntw, s, w;

    readf("%s", &t);
    readln;

    while(t--) {
        readf("%s %s\n", &p, &f);
        readf("%s %s\n", &cnts, &cntw);
        readf("%s %s\n", &s, &w);

        if(s > w) {
            swap(s,w);
            swap(cnts, cntw);
        }

        long ans = long.min;
        for(long swords = 0; swords <= cnts; ++swords) {
            if(p/s < swords)
                continue;

            long goku, freezer, cnt, maxima;
            goku = p;
            freezer = f;

            goku -= swords*s;
            cnt = min(f/s, cnts - swords);
            freezer -= cnt*s;

            maxima = swords + cnt;
            maxima += min(cntw, goku/w + freezer/w);

            //writefln("goku lleva %s espadas", swords);
            //writefln("freezer lleva %s espadas", cnt);
            //writefln("hachas %s", min(cntw, goku/w + freezer/w));

            ans = max(maxima, ans);
        }

        ans.writeln;
    }
}


import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n, m;
    readf("%s %s", &n, &m);
    readln;

    string[] arr;
    foreach (i; 0 .. n) { arr ~= readln.chomp; }

    debug { arr.writefln!"%(%s %)"; }

    auto rows = new bool[] (n);
    auto cols = new bool[] (m);

    auto rq = make!(DList!int), cq = make!(DList!int);
    rq ~= n-1;

    int step = 0;
    bool reach = false;
    outer: while (!rq.empty()) {
        step += 2;
        while (!rq.empty()) {
            int x = rq.front();
            rq.removeFront();

            if (rows[x]) { continue; }

            rows[x] = true;
            foreach (i; 0 .. m) {
                if (arr[x][i] == '.') { continue; }
                if (cols[i]) { continue; }

                cq ~= i;
            }
        }

        while (!cq.empty()) {
            int x = cq.front();
            cq.removeFront();

            if (cols[x]) { continue; }

            cols[x] = true;
            foreach (i; 0 .. n) {
                if (arr[i][x] == '.') { continue; }
                if (rows[i]) { continue; }

                if (i == 0) {
                    reach = true;
                    break outer;
                }

                rq ~= i;
            }
        }
    }

    if (!reach) {
        writeln(-1);
        return;
    }

    step.writeln;
}


import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

immutable int MD = 10 ^^ 9 + 7;

void main()
{
    int n, len;
    readf("%s %s", &n, &len);
    readln;

    int[][] arr;
    foreach (i; 0 .. n) {
        int x, y;
        readf("%s %s", &x, &y);
        readln;

        arr ~= [x, y];
    }

    debug { arr.writeln; }

    auto dp = new int[][][] (len+1, n, 2);
    foreach (i, e; arr) {
        if (e[0] <= len) { dp[e[0]][i][0] = 1; }
        if (e[1] <= len && e[1] != e[0]) { dp[e[1]][i][1] = 1; }
    }

    debug { dp.writeln; }

    foreach (clen; 2 .. len+1) {
        foreach (i, e; arr) {
            foreach (turn; 0 .. 2) {
                if (turn == 1 && e[0] == e[1]) { continue; }

                int elen = e[turn];
                if (elen >= clen) { continue; }

                foreach (j, p; arr) {
                    if (i == j) { continue; }

                    foreach (pTurn; 0 .. 2) {
                        if (pTurn == 1 && p[0] == p[1]) { continue; }

                        int pMatch = p[1 - pTurn];
                        if (elen != pMatch) { continue; }

                        debug { if (clen == 3 && i == 1) { writeln(turn, ' ', j, ' ', pTurn, ' ', pMatch, ' ', dp[clen-elen][j][pTurn]); } }
                        dp[clen][i][turn] = (dp[clen][i][turn] + dp[clen-elen][j][pTurn]) % MD;
                    }
                }
            }
        }
    }

    debug { dp.each!writeln; }

    int ans = 0;
    foreach (ref e; dp[len]) {
        foreach (et; e) { ans = (ans + et) % MD; }
    }

    ans.writeln;
}


import std.stdio;
import std.random;

static immutable N = 50;

int n, sum, now;
int[N + 1] a, b;
int[N + 1][N + 1] w;

int main() {
  auto input = stdin;
  auto output = stdout;
  input.readf(" %d", &n);
  for (int i = 1; i <= n; ++ i)
    input.readf(" %d", &a[i]), sum += a[i];
  for (int i = 1; i <= n; ++ i)
    for (int j = 1; j <= n - i + 1; ++ j)
      input.readf(" %d", &w[i][j]);
  int T = 100000;
  while (T --) {
    b = a, now = sum;
    for (int i = 1; i < n; ++ i) {
      int t = n - i + 1;
      for (int j = 1; j <= t; ++ j) {
        if (b[j] < w[i][j]) {
          now -= b[j], b[j] = 0;
          if (now < w[n][1]) break;
        } else if (j == n - i + 1) b[j - 1] += b[j], b[j] = 0;
        else if (j != 1)
          if (b[j - 1] + b[j] >= w[i + 1][j - 1])
            if ((uniform(0, 2) || T == 99999) && T != 99998) b[j - 1] += b[j], b[j] = 0;
      }
      if (now < w[n][1]) break;
    }
    if (now >= w[n][1] && b[1] >= w[n][1]) {
      output.writeln("Cerealguy");
      return 0;
    }
  }
  output.writeln("Fat Rat");
  return 0;
}


import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.ascii, std.typecons;

void main()
{
    auto s = readln.chomp;

    dchar[] ans;
    foreach (i; 0 .. s.length) {
        if (s[i] == '/' && i > 0 && s[i-1] == '/') { continue; }

        ans ~= s[i];
    }

    if (ans.length > 1 && ans.back() == '/') { ans.popBack(); }

    ans.writeln;
}

[{'input': ['//usr///local//nginx/sbin\r\n'], 'output': ['/usr/local/nginx/sbin\r\n']}, {'input': ['////a//b/////g\r\n'], 'output': ['/a/b/g\r\n']}, {'input': ['/a/b/c\r\n'], 'output': ['/a/b/c\r\n']}, {'input': ['/\r\n'], 'output': ['/\r\n']}, {'input': ['////\r\n'], 'output': ['/\r\n']}, {'input': ['/a//aa/a//\r\n'], 'output': ['/a/aa/a\r\n']}, {'input': ['/aa//b/aa\r\n'], 'output': ['/aa/b/aa\r\n']}, {'input': ['////////////////////////////////////////////////////////////////////////////////////////////////////\r\n'], 'output': ['/\r\n']}, {'input': ['/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/\r\n'], 'output': ['/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb\r\n']}, {'input': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game\r\n']}, {'input': ['/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game\r\n']}, {'input': ['/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test\r\n']}, {'input': ['/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt\r\n']}, {'input': ['///a//a////a/a//a//a//a/////\r\n'], 'output': ['/a/a/a/a/a/a/a\r\n']}, {'input': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n'], 'output': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n']}, {'input': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/\r\n'], 'output': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n']}, {'input': ['/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a\r\n'], 'output': ['/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a\r\n']}, {'input': ['///////////////////////////////////////////////////////////////////////////////////////////////////z\r\n'], 'output': ['/z\r\n']}, {'input': ['/z//////////////////////////////////////////////////////////////////////////////////////////////////\r\n'], 'output': ['/z\r\n']}]


import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int a, b, c, d;
	while (readf (" %s %s %s %s", &a, &b, &c, &d) > 0)
	{
		if (b - a == c - b && c - b == d - c)
		{
			writeln (d + d - c);
		}
		else if (a != 0 && c != 0 && b * b == a * c &&
		         b != 0 && d != 0 && c * c == b * d &&
		         (d * d / c) * c == d * d)
		{
			writeln (d * d / c);
		}
		else
		{
			writeln (42);
		}
	}
}


import std.stdio;
import std.algorithm;
import std.container;

const int MAX = 100005;
const int MOD = 1000000007;
int n;
long x;
long[MAX] a;
long[long] count;

void main() {
    readf(" %s %s", n, x);
    foreach(i; 0..n) readf(" %s", a[i]);

    long totalSum = sum(a[0..n]);
    foreach(i; 0..n) a[i] = totalSum - a[i];
    foreach(i; 0..n) count[a[i]]++;
    auto heap = heapify!"a > b"(count.keys);

    long result = 0;
    do {
        auto value = heap.front;
        heap.popFront();

        auto y = count[value];
        auto k = 0;
        while (y % x == 0) {
            y /= x;
            k++;
        }

        if (k == 0) {
            result = value;
            break;
        }

        auto next = value + k;
        if (next !in count) {
            heap.insert(next);
        }
        count[next] += y;
    } while(!heap.empty);

    writeln(power(min(result, totalSum)));
}

long power(long m) {
    if (m == 0) return 1;
    if (m == 1) return x % MOD;
    auto v = power(m/2);
    if (m % 2 == 0) {
        return (v * v) % MOD;
    } else {
        return (((v * v) % MOD) * x) % MOD;
    }
}


import std.stdio;

immutable int MOD   = 1_000_000_007;
immutable int HALF  = (MOD / 2) + 1;
immutable int MAX_N =            54;

struct modint
{
	long value;

	alias value this;

	this (long nvalue)
	{
		value = nvalue;
	}

	modint opBinary (string op) (long other)
	{
		return mixin ("modint ((value " ~ op ~ " other) % MOD)");
	}

	modint opOpAssign (string op, T) (T other)
	{
		return mixin ("this = this " ~ op ~ " other");
	}
}

void main ()
{
	auto c = new modint [] [] (MAX_N, MAX_N);

	foreach (n; 0..MAX_N)
	{
		c[n][0] = 1;
		foreach (k; 1..n + 1)
		{
			c[n][k] = c[n - 1][k - 1] + c[n - 1][k];
		}
	}

	auto f = new modint [] [] [] (MAX_N, MAX_N, 2);
	f[1][0][1] = 1;

	foreach (n; 2..MAX_N)
	{
		foreach (k; 0..n + 1)
		{
			foreach (b; 0..2)
			{
				int pk = k - (b == 0);
				if (pk >= 0)
				{
					f[n][k][b] = f[n - 1][pk][!b] *
					             (n - 1);
				}
			}

			foreach (x; 1..n - 1)
			{
				int y = n - 1 - x;
				assert (x > 0 && y > 0);
				modint mult = c[n - 1][x] * x * y;

				foreach (xk; 0..k + 1)
				{
					int yk = void;

					yk = k - xk - 1;
					if (yk >= 0)
					{
						f[n][k][0] += f[x][xk][1] *
						    f[y][yk][0] * mult;
						if (x < y ||
						    (x <= y && xk <= yk))
						{
							modint mult2 = mult;
							if (x == y && xk == yk)
							{
								mult2 *= HALF;
							}
							f[n][k][0] += mult2 *
							    f[x][xk][1] *
							    f[y][yk][1];
						}
					}

					yk = k - xk;
					if (x < y || (x <= y && xk <= yk))
					{
						modint mult2 = mult;
						if (x == y && xk == yk)
						{
							mult2 *= HALF;
						}
						f[n][k][1] += f[x][xk][0] *
						    f[y][yk][0] * mult2;
					}
				}
			}
		}
	}

	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		writeln (f[n][k][0] + f[n][k][1]);
	}
}


import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import core.bitop;

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		auto a = new bool [] [] (n, n);
		foreach (k; 0..m)
		{
			int u, v;
			readf (" %s %s", &u, &v);
			u--;
			v--;
			a[u][v] = true;
			a[v][u] = true;
		}
		if (a[0][n - 1])
		{
			foreach (u; 0..n)
			{
				foreach (v; 0..n)
				{
					a[u][v] ^= true;
				}
			}
		}

		auto b = new bool [n];
		b[0] = true;
		int res = -1;
		foreach (k; 0..n + 2)
		{
			auto b2 = new bool [n];
			foreach (i; 0..n)
			{
				if (b[i])
				{
					foreach (j; 0..n)
					{
						if (a[i][j])
						{
							b2[j] = true;
						}
					}
				}
			}
			b = b2;
			if (b[n - 1])
			{
				res = k + 1;
				break;
			}
		}

		writeln (res);
	}
}


import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int MOD = 1_000_000_007;

void add (ref int a, long b)
{
	a = (a + b) % MOD;
}

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		a ~= a.minPos.front;
		a ~= 2000;
		sort (a);

		auto f = new int [] [] [] (n + 3, n + 2, k + 1);
		f[1][0][0] = 1;
		foreach (num; 1..n + 2)
		{
			int delta = a[num] - a[num - 1];
			foreach (open; 0..n + 2)
			{
				foreach (total; 0..k + 1)
				{
					int cur = f[num][open][total];
					if (cur == 0)
					{
						continue;
					}
					int next = total + delta * open;
					if (next > k)
					{
						continue;
					}

					// open
					add (f[num + 1][open + 1][next],
					    cur);

					// inside or open + close
					add (f[num + 1][open][next],
					    cur * 1L * (open + 1));

					// close
					if (open > 0)
					{
						add (f[num + 1][open - 1]
						    [next], cur * 1L * open);
					}
				}
			}
		}

		int res = 0;
		foreach (total; 0..k + 1)
		{
			add (res, f[n + 2][0][total]);
		}
		writeln (res);
	}
}


import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.ascii, std.typecons;

void main()
{
    int n;
    readf!"%s"(n);
    readln;

    if (n == 2) {
        writeln(-1);
        return;
    }

    immutable int MAXP = 300;

    auto isPrime = new bool[MAXP];
    isPrime[] = true;
    int[] primes;
    for (int i = 2; primes.length < n; ++i) {
        if (!isPrime[i]) { continue; }

        primes ~= i;
        for (int j = i+i; j < MAXP; j += i) { isPrime[j] = false; }
    }

    BigInt product = 1;
    foreach (e; primes) { product *= e; }

    debug { product.writeln; }

    BigInt[] ans;
    foreach (i; 0 .. n) {
        ans ~= product / primes[i];
    }

    ans.each!writeln;
}


import std.stdio, std.string;

immutable int N = cast(int)5e3 + 7, mod = cast(int)1e9 + 7;

char[N] s;

long qpow(long a, long x) {
	long r = 1;
	for (; x; x >>= 1, a = a * a % mod)
		if (x & 1) r = r * a % mod;
	return r;
}

long[N] fac, ifac;
void prepare(int n) {
	for (int i = fac[0] = 1; i <= n; ++i)
		fac[i] = fac[i - 1] * i % mod;
	ifac[n] = qpow(fac[n], mod - 2);
	for (int i = n; i; --i)
		ifac[i - 1] = ifac[i] * i % mod;
}

long C(int n, int m) {
	return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

void main() {
	int n; scanf("%d%s", &n, s.ptr);

	int[][] f = new int[][](n + 1, 26);
	int[] g = new int[](n + 1);

	prepare(n);
	for (int i = 0; i < n; ++i) {
		if (s[i] == s[i + 1]) continue;

		int x = cast(int)s[i] - 97;
		for (int l = i + 1; l > 1; --l) {
			g[l] -=
				f[l][x];
			if (g[l] < 0) g[l] += mod;

			f[l][x] = g[l - 1] - f[l - 1][x];
			if (f[l][x] < 0) f[l][x] += mod;

			g[l] += f[l][x];
			if (g[l] >= mod) g[l] -= mod;
		}

		if (!f[1][x])
			f[1][x] = 1, ++g[1];
	}

	long ans = 0;
	for (int l = 1; l <= n; ++l) {
		ans = (ans + g[l] * C(n - 1, l - 1) % mod) % mod;
	}
	writeln(ans);
}

[{'input': ['3\r\naaa\r\n'], 'output': ['1\r\n']}, {'input': ['2\r\nab\r\n'], 'output': ['3\r\n']}, {'input': ['4\r\nbabb\r\n'], 'output': ['11\r\n']}, {'input': ['7\r\nabacaba\r\n'], 'output': ['589\r\n']}, {'input': ['1\r\na\r\n'], 'output': ['1\r\n']}, {'input': ['1\r\nz\r\n'], 'output': ['1\r\n']}, {'input': ['3\r\nmyw\r\n'], 'output': ['10\r\n']}, {'input': ['10\r\nisssisssss\r\n'], 'output': ['176\r\n']}, {'input': ['15\r\ntxxtxttxxttxtxx\r\n'], 'output': ['27824\r\n']}, {'input': ['127\r\nxixtxixnxixtxixlxixtxixnxixtxixoxixtxixnxixtxixlxixtxixnxixtxixhxixtxixnxixtxixlxixtxixnxixtxixoxixtxixnxixtxixlxixtxixnxixtxix\r\n'], 'output': ['944124121\r\n']}, {'input': ['2\r\nff\r\n'], 'output': ['1\r\n']}]


import core.bitop;
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int infinity = int.max / 4;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		n += 2;
		int m;
		readf (" %s", &m);
		auto u = new int [m];
		auto v = new int [m];
		auto c = new int [m];
		auto d = new int [] [] (n, n);
		foreach (ref dLine; d)
		{
			dLine[] = infinity;
		}
		foreach (i; 0..m)
		{
			readf (" %s %s %s", &u[i], &v[i], &c[i]);
			d[u[i]][v[i]] = min (d[u[i]][v[i]], c[i]);
		}

		auto f = new int [2] [] [] [] (2, n, n);
		int b = 0;
		foreach (ref fLine; f[b])
		{
			fLine[] = [infinity, infinity];
		}
		foreach (i; 0..n)
		{
			f[b][0][i][1] = 0;
			f[b][i][n - 1][0] = 0;
		}

		foreach (step; 0..k - 1)
		{
			b ^= 1;
			foreach (ref fLine; f[b])
			{
				fLine[] = [infinity, infinity];
			}
			foreach (i; 0..n)
			{
				foreach (j; i..n)
				{
					// from [i* -- j]
					int cur0 = f[!b][i][j][0];
					// from [i -- *j]
					int cur1 = f[!b][i][j][1];
					debug {writeln (step, " ", i, " ",
					    j, ": ", cur0, " ", cur1);}
					if (cur0 != infinity)
					{
						foreach (p; i + 1..j)
						{
							// to [i -- *p]
							f[b][i][p][1] =
							    min (f[b][i][p][1],
							    cur0 + d[i][p]);
							// to [p* -- j]
							f[b][p][j][0] =
							    min (f[b][p][j][0],
							    cur0 + d[i][p]);
						}
					}
					if (cur1 != infinity)
					{
						foreach (p; i + 1..j)
						{
							// to [p* -- j]
							f[b][p][j][0] =
							    min (f[b][p][j][0],
							    cur1 + d[j][p]);
							// to [i -- *p]
							f[b][i][p][1] =
							    min (f[b][i][p][1],
							    cur1 + d[j][p]);
						}
	                        	}
				}
			}
		}

		int res = infinity;
		foreach (i; 0..n)
		{
			foreach (j; 0..n)
			{
				res = min (res, f[b][i][j][0], f[b][i][j][1]);
			}
		}
		if (res == infinity)
		{
			res = -1;
		}
		writeln (res);
	}
}


#!perl

$n = <STDIN>;
$str = <STDIN>;
@types = split /\D/, $str;
@types = sort {$a<=>$b} @types;
if ($n == 1) {
	print "NO";
} else {
	for ($i = 0; $i < $n-1; $i++) {
		if (($types[$i] != $types[$i+1]) && ($types[$i+1] / $types[$i] < 2)) {
			print "YES";
			goto end;
		}
	}
}
print "NO";
end:


$a = '';
while(<>){chomp; $a .= $_;}

$a =~ s/\n//;

if($a eq (reverse($a))){
    print "YES";
}else{
    print "NO";
}


#!/usr/local/bin/perl -w

use strict;
use warnings;

use Data::Dumper();
=task
	So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.

	The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.

	Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.

	Input
	The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.

	Output
	Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.

	Examples

	Input
	SANTACLAUS
	DEDMOROZ
	SANTAMOROZDEDCLAUS

	Output
	YES

	Input
	PAPAINOEL
	JOULUPUKKI
	JOULNAPAOILELUPUKKI

	Output
	NO

	Input
	BABBONATALE
	FATHERCHRISTMAS
	BABCHRISTMASBONATALLEFATHER

	Output
	NO

	Note
	In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.

	In the second sample letter "P" is missing from the pile and there's an extra letter "L".

	In the third sample there's an extra letter "L".
=cut

main();
exit;

sub main {

	my $name_1		= <STDIN>;
	$name_1			=~ s/[\r\n]+$//;
	my $name_2		= <STDIN>;
	$name_2			=~ s/[\r\n]+$//;
	my $string		= <STDIN>;
	$string			=~ s/[\r\n]+$//;

	my $name_1_count	= ( $name_1 =~ tr/[A-Z]+// );
	my $name_2_count	= ( $name_2 =~ tr/[A-Z]+// );
	my $string_count	= ( $string =~ tr/[A-Z]+// );

	if ( ( $name_1_count + $name_2_count ) != $string_count ) {

		print( "NO\n" );

		return 0;
	}

	my $names_char_hash	= {};
	my $names_char_array	= [];
	my $string_char_array	= [];
	my $flat_missing_char	= 0;

	$names_char_array	= [ split( '', $name_1 ), split( '', $name_2 ) ];
	$string_char_array	= [ split( '', $string ) ];

	foreach my $char ( @{ $names_char_array } ) {

		$names_char_hash->{ $char } ||= 0;
		$names_char_hash->{ $char }++;
	}

	foreach my $char ( @{ $string_char_array } ) {

		if ( exists( $names_char_hash->{ $char } ) ) {

			$names_char_hash->{ $char }--;

			if ( $names_char_hash->{ $char } == 0 ) {

				delete( $names_char_hash->{ $char } );
			}

		} else {

			$flat_missing_char = 1;

			last;
		}
	}

	if ( $flat_missing_char ) {

		print( "NO\n" );

		return 0;
	}

	if ( scalar( keys %{ $names_char_hash } ) == 0 ) {

		print( "YES\n" );

		return 0;
	}

	return 0;
}

[{'input': ['SANTACLAUS\r\nDEDMOROZ\r\nSANTAMOROZDEDCLAUS\r\n'], 'output': ['YES\r\n']}, {'input': ['PAPAINOEL\r\nJOULUPUKKI\r\nJOULNAPAOILELUPUKKI\r\n'], 'output': ['NO\r\n']}, {'input': ['BABBONATALE\r\nFATHERCHRISTMAS\r\nBABCHRISTMASBONATALLEFATHER\r\n'], 'output': ['NO\r\n']}, {'input': ['B\r\nA\r\nAB\r\n'], 'output': ['YES\r\n']}, {'input': ['ONDOL\r\nJNPB\r\nONLNJBODP\r\n'], 'output': ['YES\r\n']}, {'input': ['Y\r\nW\r\nYW\r\n'], 'output': ['YES\r\n']}, {'input': ['OI\r\nM\r\nIMO\r\n'], 'output': ['YES\r\n']}, {'input': ['VFQRWWWACX\r\nGHZJPOQUSXRAQDGOGMR\r\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF\r\n'], 'output': ['YES\r\n']}, {'input': ['JUTCN\r\nPIGMZOPMEUFADQBW\r\nNWQGZMAIPUPOMCDUB\r\n'], 'output': ['NO\r\n']}, {'input': ['Z\r\nO\r\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH\r\n'], 'output': ['NO\r\n']}, {'input': ['IQ\r\nOQ\r\nQOQIGGKFNHJSGCGM\r\n'], 'output': ['NO\r\n']}, {'input': ['ROUWANOPNIGTVMIITVMZ\r\nOQTUPZMTKUGY\r\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR\r\n'], 'output': ['YES\r\n']}, {'input': ['OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\r\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\r\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY\r\n'], 'output': ['YES\r\n']}, {'input': ['NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\r\nNSFQDFUMQDQWQ\r\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX\r\n'], 'output': ['YES\r\n']}, {'input': ['IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\r\nNJMWRMBCNPHXTDQQNZ\r\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW\r\n'], 'output': ['YES\r\n']}, {'input': ['SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\r\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\r\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU\r\n'], 'output': ['YES\r\n']}, {'input': ['H\r\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\r\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK\r\n'], 'output': ['YES\r\n']}, {'input': ['DSWNZRFVXQ\r\nPVULCZGOOU\r\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE\r\n'], 'output': ['NO\r\n']}, {'input': ['EUHTSCENIPXLTSBMLFHD\r\nIZAVSZPDLXOAGESUSE\r\nLXAELAZ\r\n'], 'output': ['NO\r\n']}, {'input': ['WYSJFEREGELSKRQRXDXCGBODEFZVSI\r\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\r\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI\r\n'], 'output': ['NO\r\n']}, {'input': ['EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\r\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\r\nECGXACVKEYMCEDOTMKAUFHLHOMT\r\n'], 'output': ['NO\r\n']}, {'input': ['NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\r\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\r\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY\r\n'], 'output': ['NO\r\n']}, {'input': ['VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\r\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\r\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT\r\n'], 'output': ['NO\r\n']}, {'input': ['PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\r\nFUPDLNVIHRWTEEEHOOEC\r\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY\r\n'], 'output': ['NO\r\n']}, {'input': ['GDSLNIIKTO\r\nJF\r\nPDQYFKDTNOLI\r\n'], 'output': ['NO\r\n']}, {'input': ['AHOKHEKKPJLJIIWJRCGY\r\nORELJCSIX\r\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE\r\n'], 'output': ['NO\r\n']}, {'input': ['ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\r\nTEV\r\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH\r\n'], 'output': ['NO\r\n']}, {'input': ['AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\r\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\r\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU\r\n'], 'output': ['NO\r\n']}, {'input': ['XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\r\nZKIWNDGBISDB\r\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG\r\n'], 'output': ['NO\r\n']}, {'input': ['PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\r\nTWRRAJLCQJTKOKWCGUH\r\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM\r\n'], 'output': ['NO\r\n']}, {'input': ['QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\r\nV\r\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW\r\n'], 'output': ['NO\r\n']}, {'input': ['XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\r\nLEXOPFPVPSZK\r\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ\r\n'], 'output': ['YES\r\n']}, {'input': ['OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\r\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\r\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS\r\n'], 'output': ['YES\r\n']}, {'input': ['VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\r\nFE\r\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH\r\n'], 'output': ['YES\r\n']}, {'input': ['WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\r\nBLQZRRWP\r\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB\r\n'], 'output': ['YES\r\n']}, {'input': ['MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\r\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\r\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP\r\n'], 'output': ['YES\r\n']}, {'input': ['OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\r\nDJBFVRTARTFZOWN\r\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR\r\n'], 'output': ['YES\r\n']}, {'input': ['OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\r\nOHBKWRFDRQUAFRCMT\r\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT\r\n'], 'output': ['YES\r\n']}, {'input': ['OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\r\nMYYDQKOOYPOOUELCRIT\r\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH\r\n'], 'output': ['YES\r\n']}, {'input': ['WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\r\nYOBMOVYTUATTFGJLYUQD\r\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG\r\n'], 'output': ['YES\r\n']}, {'input': ['CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\r\nMUFOSEUEXEQTOVLGDSCWM\r\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF\r\n'], 'output': ['YES\r\n']}, {'input': ['IDQRX\r\nWETHO\r\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA\r\n'], 'output': ['NO\r\n']}, {'input': ['IXFDY\r\nJRMOU\r\nDF\r\n'], 'output': ['NO\r\n']}, {'input': ['JPSPZ\r\nUGCUB\r\nJMZZZZZZZZ\r\n'], 'output': ['NO\r\n']}, {'input': ['AC\r\nA\r\nBBA\r\n'], 'output': ['NO\r\n']}, {'input': ['UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\r\nKZXQDWJJWRXFHKJDQHJK\r\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB\r\n'], 'output': ['NO\r\n']}, {'input': ['PXWRXRPFLR\r\nPJRWWXIVHODV\r\nXW\r\n'], 'output': ['NO\r\n']}, {'input': ['CHTAZVHGSHCVIBK\r\nEQINEBKXEPYJSAZIMLDF\r\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE\r\n'], 'output': ['NO\r\n']}, {'input': ['GXPZFSELJJNDAXYRV\r\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\r\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH\r\n'], 'output': ['NO\r\n']}, {'input': ['LFGJCJJDUTUP\r\nOVSBILTIYCJCRHKCIXCETJQJJ\r\nGIJJTJCLTJJJ\r\n'], 'output': ['NO\r\n']}, {'input': ['GIO\r\nPRL\r\nPRL\r\n'], 'output': ['NO\r\n']}, {'input': ['A\r\nB\r\nABC\r\n'], 'output': ['NO\r\n']}, {'input': ['KKK\r\nKKK\r\nZZZZZ\r\n'], 'output': ['NO\r\n']}, {'input': ['ZMYGQLDBLAPN\r\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\r\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA\r\n'], 'output': ['NO\r\n']}]


#!/usr/local/bin/perl -w

use strict;
use warnings;

use Data::Dumper;
=task
	Â«One dragon. Two dragon. Three dragonÂ», â the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.

	However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every k-th dragon got punched in the face with a frying pan. Every l-th dragon got his tail shut into the balcony door. Every m-th dragon got his paws trampled with sharp heels. Finally, she threatened every n-th dragon to call her mom, and he withdrew in panic.

	How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of d dragons?

	Input
	Input data contains integer numbers k,âl,âm,ân and d, each number in a separate line (1ââ¤âk,âl,âm,ânââ¤â10, 1ââ¤âdââ¤â105).

	Output
	Output the number of damaged dragons.

	Examples

	Input
	1
	2
	3
	4
	12

	Output
	12

	Input
	2
	3
	4
	5
	24

	Output
	17

	Note
	In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.

	In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.

=cut

main();
exit;

sub main {

	my $punch_every_k_dragon	= <STDIN>;
	$punch_every_k_dragon		=~ s/[\r\n]+$//;

	my $shut_every_l_dragon		= <STDIN>;
	$shut_every_l_dragon		=~ s/[\r\n]+$//;

	my $heels_every_m_dragon	= <STDIN>;
	$heels_every_m_dragon		=~ s/[\r\n]+$//;

	my $call_every_n_dragon		= <STDIN>;
	$call_every_n_dragon		=~ s/[\r\n]+$//;

	my $dragons			= <STDIN>;
	$dragons			=~ s/[\r\n]+$//;

	my $output			= 0;

	foreach my $dragon ( 1..$dragons ) {

		if ( $punch_every_k_dragon == 1 || $shut_every_l_dragon == 1 || $heels_every_m_dragon == 1 || $call_every_n_dragon == 1 ) {

			$output = $dragons;

			last;
		}

		if (
			( $dragon % $punch_every_k_dragon ) == 0
			|| ( $dragon % $shut_every_l_dragon ) == 0
			|| ( $dragon % $heels_every_m_dragon ) == 0
			|| ( $dragon % $call_every_n_dragon ) == 0
		) {

			$output++;
		}
	}

	print( $output . "\n" );

	return 0;
}


my $k = <>;
my @arr = reverse sort {$a <=> $b} split " ", <>;
my $ans = 0;
for(my $i = 0; $k > 0 && $i < scalar @arr; $i++) {
    $k -= $arr[$i];
    $ans++;
    last if ($k <= 0);
}
$ans = -1 if ($k > 0);
print $ans;


#!/usr/bin/perl

my @users;
my $total = 0;
my $len;

while (<>) {
    chomp $_;
    if (/\+/) {
	$_ =~ s/\+//;
	push @users, $_;
    } elsif (/\-/) {
	$_ =~ s/\-//;
	for my $i (0 .. $#users){
	    if ($users[$i] eq $_) {
		splice(@users, $i, 1, ());
	    }
	}
    } else {
	$_ =~ s/([\w]*:)//;
	$total += (scalar @users) * (length $_);
    }
}

print $total

[{'input': ['+Mike\r\nMike:hello\r\n+Kate\r\n+Dmitry\r\n-Dmitry\r\nKate:hi\r\n-Kate\r\n'], 'output': ['9\r\n']}, {'input': ['+Mike\r\n-Mike\r\n+Mike\r\nMike:Hi   I am here\r\n-Mike\r\n+Kate\r\n-Kate\r\n'], 'output': ['14\r\n']}, {'input': ['+Dmitry\r\n+Mike\r\nDmitry:All letters will be used\r\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM\r\nDmitry:And digits too\r\nDmitry:1234567890 0987654321\r\n-Dmitry\r\n'], 'output': ['224\r\n']}, {'input': ['+Dmitry\r\n+Mike\r\n+Kate\r\nDmitry:\r\n'], 'output': ['0\r\n']}, {'input': ['+Dmitry\r\nDmitry:No phrases with spaces at the beginning and at the end\r\n+Mike\r\nDmitry:spaces    spaces\r\n-Dmitry\r\n'], 'output': ['86\r\n']}, {'input': ['+XqD\r\n+aT537\r\nXqD:x6ZPjMR1DDKG2\r\nXqD:lLCriywPnB\r\n-XqD\r\n'], 'output': ['46\r\n']}, {'input': ['+8UjgAJ\r\n8UjgAJ:02hR7UBc1tqqfL\r\n-8UjgAJ\r\n+zdi\r\n-zdi\r\n'], 'output': ['14\r\n']}, {'input': ['+6JPKkgXDrA\r\n+j6JHjv70An\r\n+QGtsceK0zJ\r\n6JPKkgXDrA:o4\r\n+CSmwi9zDra\r\nQGtsceK0zJ:Zl\r\nQGtsceK0zJ:0\r\nj6JHjv70An:7\r\nj6JHjv70An:B\r\nQGtsceK0zJ:OO\r\n'], 'output': ['34\r\n']}, {'input': ['+1aLNq9S7uLV\r\n-1aLNq9S7uLV\r\n+O9ykq3xDJv\r\n-O9ykq3xDJv\r\n+54Yq1xJq14F\r\n+0zJ5Vo0RDZ\r\n-54Yq1xJq14F\r\n-0zJ5Vo0RDZ\r\n+lxlH7sdolyL\r\n-lxlH7sdolyL\r\n'], 'output': ['0\r\n']}, {'input': ['+qlHEc2AuYy\r\nqlHEc2AuYy:YYRwD0 edNZgpE nGfOguRWnMYpTpGUVM aXDKGXo1Gv1tHL9\r\nqlHEc2AuYy:yvh3GsPcImqrvoUcBNQcP6ezwpU0 xAVltaKZp94VKiNao\r\nqlHEc2AuYy:zuCO6Opey L  eu7lTwysaSk00zjpv zrDfbt8l  hpHfu\r\n+pErDMxgVgh\r\nqlHEc2AuYy:I1FLis  mmQbZtd8Ui7y 1vcax6yZBMhVRdD6Ahlq7MNCw\r\nqlHEc2AuYy:lz MFUNJZhlqBYckHUDlNhLiEkmecRh1o0t7alXBvCRVEFVx\r\npErDMxgVgh:jCyMbu1dkuEj5TzbBOjyUhpfC50cL8R900Je3R KxRgAI dT\r\nqlHEc2AuYy:62b47eabo2hf vSUD7KioN ZHki6WB6gh3u GKv5rgwyfF\r\npErDMxgVgh:zD5 9 ympl4wR gy7a7eAGAn5xVdGP9FbL6hRCZAR6O4pT6zb\r\n'], 'output': ['615\r\n']}, {'input': ['+adabacaba0\r\n'], 'output': ['0\r\n']}, {'input': ['+acabadab\r\n+caba0aba\r\n'], 'output': ['0\r\n']}, {'input': ['+dabaca\r\n-dabaca\r\n+aba0ab\r\n'], 'output': ['0\r\n']}, {'input': ['+cab\r\n+abac\r\n-abac\r\n+baca\r\n'], 'output': ['0\r\n']}, {'input': ['+cabadabac\r\n-cabadabac\r\n+abacaba1ab\r\n-abacaba1ab\r\n+ba0abaca\r\n'], 'output': ['0\r\n']}, {'input': ['+adabacaba\r\n-adabacaba\r\n+aca\r\naca:caba\r\n-aca\r\n+bacaba\r\n-bacaba\r\n+aba\r\n-aba\r\n+bad\r\n'], 'output': ['4\r\n']}, {'input': ['+acabadab\r\n-acabadab\r\n+aba0abacab\r\n+baca\r\n+abacaba0ab\r\n-baca\r\n-abacaba0ab\r\n-aba0abacab\r\n+cab\r\n-cab\r\n+abacabada\r\n-abacabada\r\n+badabaca\r\n-badabaca\r\n+badaba\r\n'], 'output': ['0\r\n']}, {'input': ['+badabac\r\nbadabac:abacabad\r\n-badabac\r\n+0ab\r\n-0ab\r\n+dabacab\r\n-dabacab\r\n+a0ab\r\n-a0ab\r\n+0abaca\r\n-0abaca\r\n+dabac\r\n-dabac\r\n+abaca\r\n-abaca\r\n+bacabada\r\n-bacabada\r\n+aca\r\n-aca\r\n+abadabaca\r\n-abadabaca\r\n+acaba\r\n-acaba\r\n+abacabadab\r\n-abacabadab\r\n'], 'output': ['8\r\n']}]