#![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 {
            if inp[i]==the_ch {
                inp[i] = match_case(if the_ch=='a'{'b'}else{'a'}, inp[i]);
            } else {
                inp[i] = match_case(the_ch, inp[i]);
            }
        }
    }

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

Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1,s2,...,sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l,r (1≤l≤i≤r≤|w|) such that substring w[l ... r] is contained in the collection s1,s2,...,sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.

The first line contains the only integer n (1≤n≤100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n+1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.

Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1≤i≤|a|), that ai<bi, and for any j (1≤j<i) aj=bj. |a| stands for the length of string a.

4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a

#![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']}]


use std::io::{self, BufReader, Read, Stdin, Bytes};
use std::fmt::Debug;
use std::cmp;
use std::str::FromStr;

/// A stdin helper to deal with normal oj input.
pub struct OjReader<R> {
    bs: Bytes<BufReader<R>>,
}

pub fn from_stdin() -> OjReader<Stdin> {
    let input = io::stdin();
    let reader = BufReader::new(input);
    OjReader { bs: reader.bytes() }
}

impl<R: Read> OjReader<R> {
    pub fn next<E, T>(&mut self) -> T
        where E: Debug,
              T: FromStr<Err = E>
    {
        loop {
            match self.next_opt() {
                Some(t) => return t,
                None => {},
            }
        }
    }

    pub fn next_opt<E, T>(&mut self) -> Option<T>
        where E: Debug,
              T: FromStr<Err = E>
    {
        self.next_trunk(|b| b == b' ' || b == b'\t' || b == b'\n' || b == b'\r')
    }

    // TODO: handle windows style line seperator \r\n
    fn next_trunk<E, T, F>(&mut self, is_sep: F) -> Option<T>
        where E: Debug,
              T: FromStr<Err = E>,
              F: Fn(u8) -> bool
    {
        let mut res = vec![];
        loop {
            match self.bs.next() {
                None => {
                    assert!(!res.is_empty());
                    break;
                },
                Some(r) => {
                    let b = r.unwrap();
                    if is_sep(b) {
                        break;
                    }
                    res.push(b);
                }
            }
        }
        if res.is_empty() {
            return None;
        }
        unsafe { Some(String::from_utf8_unchecked(res).parse::<T>().unwrap()) }
    }

    pub fn next_line(&mut self) -> String {
        self.next_line_opt().unwrap()
    }

    pub fn next_line_opt(&mut self) -> Option<String> {
        self.next_trunk(|b| b == b'\n' || b == b'\r')
    }
}

macro_rules! odiv {
    ($lhs:expr, $rhs:expr) => ({
        if $lhs < 0 {
            0
        } else {
            $lhs / $rhs + 1
        }
    });
}

#[derive(Debug)]
struct Problem {
    a: isize,
    b: isize,
    thls: Vec<isize>,
}

fn search(p: &mut Problem, i: usize, tmp_sol: &mut Vec<usize>, sol: &mut Vec<usize>) {
    assert!(i > 0);
    if i == p.thls.len() - 2 {
        let res = cmp::max(odiv!(p.thls[i], p.a), odiv!(cmp::max(p.thls[i - 1], p.thls[i + 1]), p.b)) as usize;
        if !sol.is_empty() && sol.len() <= tmp_sol.len() + res {
            return;
        }
        *sol = tmp_sol.clone();
        for _ in 0..res {
            sol.push(i + 1);
        }
    } else if i < p.thls.len() - 2 {
        let min = odiv!(p.thls[i - 1], p.b) as usize;
        let max = cmp::max(odiv!(p.thls[i], p.a), odiv!(p.thls[i + 1], p.b)) as usize;
        let (old_one, old_two, last_moves) = (p.thls[i], p.thls[i + 1], tmp_sol.len());
        p.thls[i] -= p.a * min as isize;
        p.thls[i + 1] -= p.b * min as isize;
        tmp_sol.resize(last_moves + min, i + 1);
        for _ in min..cmp::max(min + 1, max) {
            search(p, i + 1, tmp_sol, sol);
            p.thls[i] -= p.a;
            p.thls[i + 1] -= p.b;
            tmp_sol.push(i + 1);
            if tmp_sol.len() > sol.len() {
                break;
            }
        }
        p.thls[i] = old_one;
        p.thls[i + 1] = old_two;
        tmp_sol.truncate(last_moves);
    } else {
        unreachable!();
    }
}

// Simple a + b example
fn main() {
    let mut reader = from_stdin();
    let (n, a, b) = (reader.next(), reader.next(), reader.next());
    let mut problem = Problem {
        a: a,
        b: b,
        thls: Vec::with_capacity(n),
    };
    for _ in 0..n {
        problem.thls.push(reader.next());
    }
    let (mut tmp_sol, mut sol) = (vec![], vec![]);
    search(&mut problem, 1, &mut tmp_sol, &mut sol);
    println!("{}", sol.len());
    for idx in sol {
        print!("{} ", idx);
    }
    print!("\n");
}

This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?Polycarp can throw his fire ball into an archer if the latter is already killed.

The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.

In the first line print t — the required minimum amount of fire balls. In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.

use std::io::{self, BufReader, Read, Stdin, Bytes};
use std::fmt::Debug;
use std::cmp;
use std::str::FromStr;

/// A stdin helper to deal with normal oj input.
pub struct OjReader<R> {
    bs: Bytes<BufReader<R>>,
}

pub fn from_stdin() -> OjReader<Stdin> {
    let input = io::stdin();
    let reader = BufReader::new(input);
    OjReader { bs: reader.bytes() }
}

impl<R: Read> OjReader<R> {
    pub fn next<E, T>(&mut self) -> T
        where E: Debug,
              T: FromStr<Err = E>
    {
        loop {
            match self.next_opt() {
                Some(t) => return t,
                None => {},
            }
        }
    }

    pub fn next_opt<E, T>(&mut self) -> Option<T>
        where E: Debug,
              T: FromStr<Err = E>
    {
        self.next_trunk(|b| b == b' ' || b == b'\t' || b == b'\n' || b == b'\r')
    }

    // TODO: handle windows style line seperator \r\n
    fn next_trunk<E, T, F>(&mut self, is_sep: F) -> Option<T>
        where E: Debug,
              T: FromStr<Err = E>,
              F: Fn(u8) -> bool
    {
        let mut res = vec![];
        loop {
            match self.bs.next() {
                None => {
                    assert!(!res.is_empty());
                    break;
                },
                Some(r) => {
                    let b = r.unwrap();
                    if is_sep(b) {
                        break;
                    }
                    res.push(b);
                }
            }
        }
        if res.is_empty() {
            return None;
        }
        unsafe { Some(String::from_utf8_unchecked(res).parse::<T>().unwrap()) }
    }

    pub fn next_line(&mut self) -> String {
        self.next_line_opt().unwrap()
    }

    pub fn next_line_opt(&mut self) -> Option<String> {
        self.next_trunk(|b| b == b'\n' || b == b'\r')
    }
}

macro_rules! odiv {
    ($lhs:expr, $rhs:expr) => ({
        if $lhs < 0 {
            0
        } else {
            $lhs / $rhs + 1
        }
    });
}

#[derive(Debug)]
struct Problem {
    a: isize,
    b: isize,
    thls: Vec<isize>,
}

fn search(p: &mut Problem, i: usize, tmp_sol: &mut Vec<usize>, sol: &mut Vec<usize>) {
    assert!(i > 0);
    if i == p.thls.len() - 2 {
        let res = cmp::max(odiv!(p.thls[i], p.a), odiv!(cmp::max(p.thls[i - 1], p.thls[i + 1]), p.b)) as usize;
        if !sol.is_empty() && sol.len() <= tmp_sol.len() + res {
            return;
        }
        *sol = tmp_sol.clone();
        for _ in 0..res {
            sol.push(i + 1);
        }
    } else if i < p.thls.len() - 2 {
        let min = odiv!(p.thls[i - 1], p.b) as usize;
        let max = cmp::max(odiv!(p.thls[i], p.a), odiv!(p.thls[i + 1], p.b)) as usize;
        let (old_one, old_two, last_moves) = (p.thls[i], p.thls[i + 1], tmp_sol.len());
        p.thls[i] -= p.a * min as isize;
        p.thls[i + 1] -= p.b * min as isize;
        tmp_sol.resize(last_moves + min, i + 1);
        for _ in min..cmp::max(min + 1, max + 1) {
            search(p, i + 1, tmp_sol, sol);
            p.thls[i] -= p.a;
            p.thls[i + 1] -= p.b;
            tmp_sol.push(i + 1);
            if tmp_sol.len() > sol.len() {
                break;
            }
        }
        p.thls[i] = old_one;
        p.thls[i + 1] = old_two;
        tmp_sol.truncate(last_moves);
    } else {
        unreachable!();
    }
}

// Simple a + b example
fn main() {
    let mut reader = from_stdin();
    let (n, a, b) = (reader.next(), reader.next(), reader.next());
    let mut problem = Problem {
        a: a,
        b: b,
        thls: Vec::with_capacity(n),
    };
    for _ in 0..n {
        problem.thls.push(reader.next());
    }
    let (mut tmp_sol, mut sol) = (vec![], vec![]);
    search(&mut problem, 1, &mut tmp_sol, &mut sol);
    println!("{}", sol.len());
    for idx in sol {
        print!("{} ", idx);
    }
    print!("\n");
}


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

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

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

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

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

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

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

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

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

/// Verified by https://atcoder.jp/contests/arc093/submissions/3968098
mod mod_int {
    use std::ops::*;
    pub trait Mod: Copy { fn m() -> i64; }
    #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
    pub struct ModInt<M> { pub x: i64, phantom: ::std::marker::PhantomData<M> }
    impl<M: Mod> ModInt<M> {
        // x >= 0
        pub fn new(x: i64) -> Self { ModInt::new_internal(x % M::m()) }
        fn new_internal(x: i64) -> Self {
            ModInt { x: x, phantom: ::std::marker::PhantomData }
        }
        pub fn pow(self, mut e: i64) -> Self {
            debug_assert!(e >= 0);
            let mut sum = ModInt::new_internal(1);
            let mut cur = self;
            while e > 0 {
                if e % 2 != 0 { sum *= cur; }
                cur *= cur;
                e /= 2;
            }
            sum
        }
        #[allow(dead_code)]
        pub fn inv(self) -> Self { self.pow(M::m() - 2) }
    }
    impl<M: Mod, T: Into<ModInt<M>>> Add<T> for ModInt<M> {
        type Output = Self;
        fn add(self, other: T) -> Self {
            let other = other.into();
            let mut sum = self.x + other.x;
            if sum >= M::m() { sum -= M::m(); }
            ModInt::new_internal(sum)
        }
    }
    impl<M: Mod, T: Into<ModInt<M>>> Sub<T> for ModInt<M> {
        type Output = Self;
        fn sub(self, other: T) -> Self {
            let other = other.into();
            let mut sum = self.x - other.x;
            if sum < 0 { sum += M::m(); }
            ModInt::new_internal(sum)
        }
    }
    impl<M: Mod, T: Into<ModInt<M>>> Mul<T> for ModInt<M> {
        type Output = Self;
        fn mul(self, other: T) -> Self { ModInt::new(self.x * other.into().x % M::m()) }
    }
    impl<M: Mod, T: Into<ModInt<M>>> AddAssign<T> for ModInt<M> {
        fn add_assign(&mut self, other: T) { *self = *self + other; }
    }
    impl<M: Mod, T: Into<ModInt<M>>> SubAssign<T> for ModInt<M> {
        fn sub_assign(&mut self, other: T) { *self = *self - other; }
    }
    impl<M: Mod, T: Into<ModInt<M>>> MulAssign<T> for ModInt<M> {
        fn mul_assign(&mut self, other: T) { *self = *self * other; }
    }
    impl<M: Mod> Neg for ModInt<M> {
        type Output = Self;
        fn neg(self) -> Self { ModInt::new(0) - self }
    }
    impl<M> ::std::fmt::Display for ModInt<M> {
        fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
            self.x.fmt(f)
        }
    }
    impl<M: Mod> ::std::fmt::Debug for ModInt<M> {
        fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
            let (mut a, mut b, _) = red(self.x, M::m());
            if b < 0 {
                a = -a;
                b = -b;
            }
            write!(f, "{}/{}", a, b)
        }
    }
    impl<M: Mod> From<i64> for ModInt<M> {
        fn from(x: i64) -> Self { Self::new(x) }
    }
    // Finds the simplest fraction x/y congruent to r mod p.
    // The return value (x, y, z) satisfies x = y * r + z * p.
    fn red(r: i64, p: i64) -> (i64, i64, i64) {
        if r.abs() <= 10000 {
            return (r, 1, 0);
        }
        let mut nxt_r = p % r;
        let mut q = p / r;
        if 2 * nxt_r >= r {
            nxt_r -= r;
            q += 1;
        }
        if 2 * nxt_r <= -r {
            nxt_r += r;
            q -= 1;
        }
        let (x, z, y) = red(nxt_r, r);
        (x, y - q * z, z)
    }
} // mod mod_int

macro_rules! define_mod {
    ($struct_name: ident, $modulo: expr) => {
        #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
        struct $struct_name {}
        impl mod_int::Mod for $struct_name { fn m() -> i64 { $modulo } }
    }
}
const MOD: i64 = 998244353;
define_mod!(P, MOD);
type ModInt = mod_int::ModInt<P>;

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, m: usize,
        a: [i32; n],
        w: [i64; n],
    }
    let mut dp = vec![vec![[ModInt::new(0); 2]; m + 1]; m + 1];
    let mut prob = vec![vec![[ModInt::new(0); 2]; m + 1]; m + 1];
    let mut wsum = ModInt::new(0);
    let mut upsum = ModInt::new(0);
    let mut downsum = ModInt::new(0);
    for i in 0..n {
        wsum += w[i];
        if a[i] == 1 {
            upsum += w[i];
        } else {
            downsum += w[i];
        }
    }
    dp[0][0] = [ModInt::new(1); 2];
    prob[0][0] = [ModInt::new(1); 2];
    for up in 0..2 {
        for i in 0..m {
            for j in 0..m - i {
                // TODO O(log MOD)
                let whole = wsum + i as i64 - j as i64;
                if whole == ModInt::new(0) || dp[i][j][up] == ModInt::new(0) {
                    continue;
                }
                let wholeinv = whole.inv();
                let up_coef = if up == 1 {
                    upsum + i as i64 + 1
                } else {
                    upsum + i as i64
                } * wholeinv;
                let down_coef = if up == 1 {
                    downsum - j as i64
                } else {
                    downsum - j as i64 - 1
                } * wholeinv;
                dp[i + 1][j][up] += up_coef * dp[i][j][up];
                dp[i][j + 1][up] += down_coef * dp[i][j][up];
                prob[i + 1][j][up] += (upsum + i as i64) * wholeinv * dp[i][j][up];
                prob[i][j + 1][up] += (downsum - i as i64) * wholeinv * dp[i][j][up];
            }
        }
    }
    let mut ans = [ModInt::new(0); 2];
    for up in 0..2 {
        for i in 0..m + 1 {
            ans[up] += dp[i][m - i][up];
        }
    }
    for i in 0..n {
        if a[i] == 1 {
            puts!("{}\n", ans[1] * w[i]);
        } else {
            puts!("{}\n", ans[0] * w[i]);
        }
    }

}

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

The only difference between easy and hard versions is constraints.Nauuo is a girl who loves random picture websites.One day she made a random picture website by herself which includes $$$n$$$ pictures.When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal probability. The $$$i$$$-th picture has a non-negative weight $$$w_i$$$, and the probability of the $$$i$$$-th picture being displayed is $$$\frac{w_i}{\sum_{j=1}^nw_j}$$$. That is to say, the probability of a picture to be displayed is proportional to its weight.However, Nauuo discovered that some pictures she does not like were displayed too often. To solve this problem, she came up with a great idea: when she saw a picture she likes, she would add $$$1$$$ to its weight; otherwise, she would subtract $$$1$$$ from its weight.Nauuo will visit the website $$$m$$$ times. She wants to know the expected weight of each picture after all the $$$m$$$ visits modulo $$$998244353$$$. Can you help her?The expected weight of the $$$i$$$-th picture can be denoted by $$$\frac {q_i} {p_i}$$$ where $$$\gcd(p_i,q_i)=1$$$, you need to print an integer $$$r_i$$$ satisfying $$$0\le r_i<998244353$$$ and $$$r_i\cdot p_i\equiv q_i\pmod{998244353}$$$. It can be proved that such $$$r_i$$$ exists and is unique.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n\le 2\cdot 10^5$$$, $$$1\le m\le 3000$$$) — the number of pictures and the number of visits to the website. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$a_i$$$ is either $$$0$$$ or $$$1$$$) — if $$$a_i=0$$$ , Nauuo does not like the $$$i$$$-th picture; otherwise Nauuo likes the $$$i$$$-th picture. It is guaranteed that there is at least one picture which Nauuo likes. The third line contains $$$n$$$ positive integers $$$w_1,w_2,\ldots,w_n$$$ ($$$w_i \geq 1$$$) — the initial weights of the pictures. It is guaranteed that the sum of all the initial weights does not exceed $$$998244352-m$$$.

The output contains $$$n$$$ integers $$$r_1,r_2,\ldots,r_n$$$ — the expected weights modulo $$$998244353$$$.

NoteIn the first example, if the only visit shows the first picture with a probability of $$$\frac 2 3$$$, the final weights are $$$(1,1)$$$; if the only visit shows the second picture with a probability of $$$\frac1 3$$$, the final weights are $$$(2,2)$$$.So, both expected weights are $$$\frac2 3\cdot 1+\frac 1 3\cdot 2=\frac4 3$$$ .Because $$$332748119\cdot 3\equiv 4\pmod{998244353}$$$, you need to print $$$332748119$$$ instead of $$$\frac4 3$$$ or $$$1.3333333333$$$.In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, $$$w_1$$$ will be increased by $$$1$$$.So, the expected weight is $$$1+2=3$$$.Nauuo is very naughty so she didn't give you any hint of the third example.

// https://codeforces.com/contest/1172/problem/C2
//
#![allow(unused_imports)]
use std::io::*;
use std::io::Write;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, switch) => {
        {
            let ty = read_value!($iter, i32);
            if ty == 1 {
                vec![ty, read_value!($iter, i32), read_value!($iter, i32)]
            } else if ty == 2 {
                vec![ty, read_value!($iter, i32)]
            } else {
                vec![ty, read_value!($iter, i32)]
            }
        }
    };

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

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const MOD: i64 = 998244353;

fn inv(a: i64) -> i64 {
    pow(a, MOD - 2)
}

fn pow(a: i64, p: i64) -> i64 {
    let mut p = p;
    let mut aa = a;
    let mut ret = 1;
    while p >= 1 {
        if p & 1 == 1 {
            ret *= aa;
            ret %= MOD;
        }
        p >>= 1;
        aa = aa * aa % MOD;
    }
    ret
}

fn main() {
    input! {
        n: usize, m: usize,
        mut a: [i64; n],
        w: [i64; n]
    };

    let mut like_weight = 0;
    let mut dislike_weight = 0;
    for i in 0..n {
        if a[i] == 1 {
            like_weight += w[i];
        } else {
            dislike_weight += w[i];
        }
    }

    let GETA = 3100;
    let mut denom_pm = vec![0; GETA*2];
    for i in 0..GETA*2 {
        let w = i as i64 + like_weight + dislike_weight;
        denom_pm[i] = ifv!(w >= GETA as i64, inv(w-GETA as i64), 0);
    }
    let mut quot = |l: usize, d: usize, num: i64| ifv!(num <= 0, 0, num * denom_pm[GETA+l-d] % MOD);

    let mut dp = dvec!(0; 2, m+1, m+1);
    for i in 0..m+1 {
        dp[0][i][m-i] = 1;
        dp[1][i][m-i] = 1;
    }
    for i in (0..m+1).rev() {
        for j in (0..m+1).rev() {
            if i+j >= m {
                continue;
            }
            let mut total0 = 0;
            let mut total1 = 0;

            if i+1 <= m {
                total0 += dp[0][i+1][j] * quot(i, j, like_weight+(i as i64)+1);
                total1 += dp[1][i+1][j] * quot(i, j, like_weight+(i as i64));
            }
            if j+1 <= m {
                total0 += dp[0][i][j+1] * quot(i, j, dislike_weight-(j as i64));
                total1 += dp[1][i][j+1] * quot(i, j, dislike_weight-(j as i64)-1);
            }
            dp[0][i][j] = total0 % MOD;
            dp[1][i][j] = total1 % MOD;
        }
    }

    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    for i in 0..n {
        if a[i] == 1 {
            writeln!(out, "{}", dp[0][0][0] * w[i] % MOD);
        } else {
            writeln!(out, "{}", dp[1][0][0] * w[i] % MOD);
        }
    }
}


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

You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors  and  is acute (i.e. strictly less than ). Otherwise, the point is called good.The angle between vectors  and  in 5-dimensional space is defined as , where  is the scalar product and  is length of .Given the list of points, print the indices of the good points in ascending order.

The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points. The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103)  — the coordinates of the i-th point. All points are distinct.

First, print a single integer k — the number of good points. Then, print k integers, each on their own line — the indices of the good points in ascending order.

NoteIn the first sample, the first point forms exactly a  angle with all other pairs of points, so it is good.In the second sample, along the cd plane, we can see the points look as follows:We can see that all angles here are acute, so no points are good.

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

As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answered either "The crime was committed by suspect number ai", or "Suspect number ai didn't commit the crime". Also, the suspect could say so about himself (ai = i).Sherlock Holmes understood for sure that exactly m answers were the truth and all other answers were a lie. Now help him understand this: which suspect lied and which one told the truth?

The first line contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ n) — the total number of suspects and the number of suspects who told the truth. Next n lines contain the suspects' answers. The i-th line contains either "+ai" (without the quotes), if the suspect number i says that the crime was committed by suspect number ai, or "-ai" (without the quotes), if the suspect number i says that the suspect number ai didn't commit the crime (ai is an integer, 1 ≤ ai ≤ n). It is guaranteed that at least one suspect exists, such that if he committed the crime, then exactly m people told the truth.

Print n lines. Line number i should contain "Truth" if suspect number i has told the truth for sure. Print "Lie" if the suspect number i lied for sure and print "Not defined" if he could lie and could tell the truth, too, depending on who committed the crime.

NoteThe first sample has the single person and he confesses to the crime, and Sherlock Holmes knows that one person is telling the truth. That means that this person is telling the truth.In the second sample there are three suspects and each one denies his guilt. Sherlock Holmes knows that only two of them are telling the truth. Any one of them can be the criminal, so we don't know for any of them, whether this person is telling the truth or not.In the third sample the second and the fourth suspect defend the first and the third one. But only one is telling the truth, thus, the first or the third one is the criminal. Both of them can be criminals, so the second and the fourth one can either be lying or telling the truth. The first and the third one are lying for sure as they are blaming the second and the fourth one.

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']}]


use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};

// I have no idea what I'm doing

struct It {
    x: usize,
    n: usize,
    mark: Vec<bool>,
}

fn primes_that_divide(n: usize) -> It {
    It {
        x: 2,
        n: n,
        mark: vec![false; n + 1],
    }
}

impl Iterator for It {
    type Item = usize;
    fn next(&mut self) -> Option<Self::Item> {
        while self.x <= self.n {
            if self.mark[self.x] {
                self.x += 1;
                continue;
            }

            for y in self.mark.iter_mut().skip(self.x).step_by(self.x) {
                *y = true;
            }

            if self.n % self.x == 0 {
                self.x += 1;
                return Some(self.x - 1);
            }

            self.x += 1;
        }

        None
    }
}

fn is_lucky(n: usize, mood: &[bool], p: usize) -> bool {
    let step = n / p;
    (0..step).any(|start|
        (start..n).step_by(step).all(|i| mood[i]))
}

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

    let n: usize = scan.token();
    let mood: Vec<_> = (0..n).map(|_| scan.token::<char>()).map(|c| c == '1').collect();

    let ans = primes_that_divide(n)
                .filter(|&p| p > 2)
                .any(|p| is_lucky(n, &mood, p));

    writeln!(out, "{}", match ans {
        true => "YES",
        false => "NO",
    })?;

    Ok(())
}

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

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

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

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

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

There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood.  King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not.

The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood.

Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO".

use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};

// I have no idea what I'm doing

struct It {
    x: usize,
    n: usize,
    mark: Vec<bool>,
}

// 4 is prime
fn primes_that_divide(n: usize) -> It {
    It {
        x: 3,
        n: n,
        mark: vec![false; n + 1],
    }
}

impl Iterator for It {
    type Item = usize;
    fn next(&mut self) -> Option<Self::Item> {
        while self.x <= self.n {
            if self.mark[self.x] {
                self.x += 1;
                continue;
            }

            for y in self.mark.iter_mut().skip(self.x).step_by(self.x) {
                *y = true;
            }

            if self.n % self.x == 0 {
                self.x += 1;
                return Some(self.x - 1);
            }

            self.x += 1;
        }

        None
    }
}

fn is_lucky(n: usize, mood: &[bool], p: usize) -> bool {
    let step = n / p;
    (0..step).any(|start|
        (start..n).step_by(step).all(|i| mood[i]))
}

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

    let n: usize = scan.token();
    let mood: Vec<_> = (0..n).map(|_| scan.token::<char>()).map(|c| c == '1').collect();

    let ans = primes_that_divide(n)
                .any(|p| is_lucky(n, &mood, p));

    writeln!(out, "{}", match ans {
        true => "YES",
        false => "NO",
    })?;

    Ok(())
}

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

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

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

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

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


#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

const INF:usize= 2 << 30;

fn rec(cur: usize, u: usize, k: usize, cnt: &Vec<usize>, ans: &mut Vec<usize>) -> Vec<usize> {
    debug!(cur, u, k);
    let mut v = vec![0; 20];
    if cur > u {
        return v;
    }
    let v1 = rec(cur*2, u, k, cnt, ans);
    let v2 = rec(cur*2+1, u, k, cnt, ans);
    v[0] = cnt[cur];

    let mut temp = cnt[cur];
    let mut cost = 0;
    for i in 0..19 {
        v[i+1] = v1[i] + v2[i];
        if k - temp > 0 {
            cost += (i+1) * min(k-temp, v[i+1]);
            temp += min(k-temp, v[i+1]);
        }
    }
    if temp == k {
        ans[cur] = cost;
    }
    v
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      k: usize,
      aa: [usize; n],
    }
    let mut m = *aa.iter().max().unwrap();
    let mut cnt = vec![0; m+1];
    let mut ans = vec![INF; m+1];
    for a in aa {
        cnt[a] += 1;
    }
    rec(1, m, k, &cnt, &mut ans);
    let ans = ans.iter().min().unwrap();
    puts!("{}\n", ans);
}

The only difference between easy and hard versions is the number of elements in the array.You are given an array $$$a$$$ consisting of $$$n$$$ integers. In one move you can choose any $$$a_i$$$ and divide it by $$$2$$$ rounding down (in other words, in one move you can set $$$a_i := \lfloor\frac{a_i}{2}\rfloor$$$).You can perform such an operation any (possibly, zero) number of times with any $$$a_i$$$.Your task is to calculate the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array.Don't forget that it is possible to have $$$a_i = 0$$$ after some operations, thus the answer always exists.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 50$$$) — the number of elements in the array and the number of equal numbers required. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array.

use std::io;
use std::str::FromStr;
use std::num::ParseIntError;
use std::ops::Index;

struct RevBinary {
    data: Vec<bool>,
}

impl FromStr for RevBinary {
    type Err = ParseIntError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let i = s.parse::<u32>()?;

        Ok(RevBinary::new(i))
    }
}

impl Index<usize> for RevBinary {
    type Output = bool;

    fn index(&self, i: usize) -> &Self::Output {
        &self.data[self.data.len() - i - 1]
    }
}

impl RevBinary {
    fn new(x : u32) -> RevBinary {
        let mut y = x;
        let mut bin : Vec<bool> = Vec::new();
        while y != 0 {
           bin.push(if y % 2 == 1 { true } else { false });
           y /= 2;
        }
        RevBinary {
            data: bin,
        }
    }

    fn size(&self) -> usize {
        self.data.len()
    }
}

fn process_node(all: &Vec<RevBinary>, ind: Vec<usize>, depth: usize, k: u32) -> u32 {
    let mut result : u32 = ind.iter().take(k as usize).map(|&x| all[x].size() - depth).sum::<usize>() as u32;

    if result == 0 {
        return 0;
    }

    let new_ind : (Vec<usize>, Vec<usize>) = ind.iter().filter(|&&x| all[x].size() > depth).partition(|&&x| all[x][depth]);
    if new_ind.0.len() >= k as usize {
        result = result.min(process_node(&all, new_ind.0, depth + 1, k));
    }
    if result != 0 && new_ind.1.len() >= k as usize {
        result = result.min(process_node(&all, new_ind.1, depth + 1, k));
    }
    result
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("failed to read input");
    let mut input_iter = input.split_whitespace();
    let n = input_iter.next().unwrap().parse::<usize>().unwrap();
    let k = input_iter.next().unwrap().parse::<u32>().unwrap();
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).expect("failed to read input");
    let mut a = buffer.split_whitespace().map(|x| x.parse::<RevBinary>().unwrap()).collect::<Vec<RevBinary>>();
    a.sort_by(|a, b| a.size().cmp(&b.size()));

    println!("{}", process_node(&a, (0..n).collect::<Vec<usize>>(), 0, k));
}


//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;
    }
    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;
            b.push(*a);
        }
    }
    if !valid(&beki, &mut b) {
        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();
}

It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2k - 1 + r, where k and r are integers, k ≥ 0, 0 <; r ≤ 2k. Let's call that representation prairie partition of x.For example, the prairie partitions of 12, 17, 7 and 1 are:  12 = 1 + 2 + 4 + 5,17 = 1 + 2 + 4 + 8 + 2,7 = 1 + 2 + 4,1 = 1. Alice took a sequence of positive integers (possibly with repeating elements), replaced every element with the sequence of summands in its prairie partition, arranged the resulting numbers in non-decreasing order and gave them to Borys. Now Borys wonders how many elements Alice's original sequence could contain. Find all possible options!

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of numbers given from Alice to Borys. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1012; a1 ≤ a2 ≤ ... ≤ an) — the numbers given from Alice to Borys.

Output, in increasing order, all possible values of m such that there exists a sequence of positive integers of length m such that if you replace every element with the summands in its prairie partition and arrange the resulting numbers in non-decreasing order, you will get the sequence given in the input. If there are no such values of m, output a single integer -1.

NoteIn the first example, Alice could get the input sequence from [6, 20] as the original sequence.In the second example, Alice's original sequence could be either [4, 5] or [3, 3, 3].

//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.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

void main() {
    dchar[] s = readln.chomp.to!(dchar[]);
    int n = s.length.to!int;

    int l, r;

    while (l < n) {
        while (r < n && s[r] != '0') {
            r++;
        }
        s[l..r].sort();
        r++;
        l = r;
    }

    debug {
        writeln(s);
    }

    l = r = 0;

    while (l < n) {
        while (r < n && s[r] != '2') {
            r++;
        }
        s[l..r].sort();
        r++;
        l = r;
    }

    writeln(s);
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).For example, for string "010210" we can perform the following moves:   "010210" $$$\rightarrow$$$ "100210";  "010210" $$$\rightarrow$$$ "001210";  "010210" $$$\rightarrow$$$ "010120";  "010210" $$$\rightarrow$$$ "010201". Note than you cannot swap "02" $$$\rightarrow$$$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).String $$$a$$$ is lexicographically less than string $$$b$$$ (if strings $$$a$$$ and $$$b$$$ have the same length) if there exists some position $$$i$$$ ($$$1 \le i \le |a|$$$, where $$$|s|$$$ is the length of the string $$$s$$$) such that for every $$$j < i$$$ holds $$$a_j = b_j$$$, and $$$a_i < b_i$$$.

The first line of the input contains the string $$$s$$$ consisting only of characters '0', '1' and '2', its length is between $$$1$$$ and $$$10^5$$$ (inclusive).

Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).

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

void main() {
    auto S = readln.chomp;
    auto N = S.length.to!int;
    string A = "";
    string B = "";

    foreach (i; 0..N) {
        if (S[i] == '1') A ~= S[i];
        else B ~= S[i];
    }

    if (B.empty) {
        A.writeln;
        return;
    }

    int x = B.length.to!int;
    foreach (i; 0..B.length.to!int) {
        if (B[i] == '2') {
            x = i;
            break;
        }
    }

    writeln(B[0..x] ~ A ~ B[x..$]);
}


import std;

void main() {
    long n;
    readf("%d\n", n);

    bool isNearlyLucky = !(n == 4 || n == 7);
    while (n > 0) {
        long d = n % 10;
        isNearlyLucky &= (d == 4 || d == 7);

        n /= 10;
    }

    writeln(isNearlyLucky ? "YES" : "NO");
}

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.

The only line contains an integer n (1≤n≤10^18).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Print on the single line "YES" if n is a nearly lucky number. Otherwise, print "NO" (without the quotes).

In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO".

import std;

void main() {
    string n;
    readf("%s\n", n);

    ulong cnt = n.count('4') + n.count('7');

    bool isNearlyLucky = (cnt > 0);
    while (cnt > 0) {
        ulong d = cnt % 10;
        isNearlyLucky &= (d == 4 || d == 7);

        cnt /= 10;
    }

    writeln(isNearlyLucky ? "YES" : "NO");
}


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 long INF = 10L ^^ 18 + 23;

immutable int A = 100;

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

    auto a = readln.chomp.split.map!(to!int).array;

    auto sm = a.sum();

    if (n == 1) {
        sm.writeln;
        return;
    }

    int mxgain = 0;
    for (int i = 2; i < A; ++i) {
        int curbig = -1;
        for (int j = 0; j < n; ++j) {
            if (a[j] % i != 0) continue;

            if (curbig == -1 || a[j] > a[curbig]) curbig = j;
        }

        if (curbig == -1) continue;

        int cursm = -1;
        for (int j = 0; j < n; ++j) {
            if (j == curbig) continue;

            if (cursm == -1 || a[j] < cursm) cursm = j;
        }

        int curgain = (a[curbig] + a[cursm]) - (a[curbig] / i + a[cursm] * i);
        mxgain = max(mxgain, curgain);
    }

    int ans = sm - mxgain;
    ans.writeln;
}

One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by $$$n$$$ machines, and the power of the $$$i$$$-th machine is $$$a_i$$$. This year 2D decided to cultivate a new culture, but what exactly he didn't say. For the successful growth of the new culture, it is necessary to slightly change the powers of the machines. 2D can at most once choose an arbitrary integer $$$x$$$, then choose one machine and reduce the power of its machine by $$$x$$$ times, and at the same time increase the power of one another machine by $$$x$$$ times (powers of all the machines must stay positive integers). Note that he may not do that if he wants. More formally, 2D can choose two such indices $$$i$$$ and $$$j$$$, and one integer $$$x$$$ such that $$$x$$$ is a divisor of $$$a_i$$$, and change powers as following: $$$a_i = \frac{a_i}{x}$$$, $$$a_j = a_j \cdot x$$$Sasha is very curious, that's why he wants to calculate the minimum total power the farmer can reach. There are too many machines, and Sasha can't cope with computations, help him!

The first line contains one integer $$$n$$$ ($$$2 \\le n \\le 5 \\cdot 10^4$$$) — the number of machines.
The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 100$$$) — the powers of the machines.

Print one integer — minimum total power.

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 long INF = 10L ^^ 18 + 23;

immutable int A = 100;

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

    auto a = readln.chomp.split.map!(to!int).array;

    auto sm = a.sum();

    if (n == 1) {
        sm.writeln;
        return;
    }

    int mxgain = 0;
    for (int i = 2; i < A; ++i) {
        int curbig = -1;
        for (int j = 0; j < n; ++j) {
            if (a[j] % i != 0) continue;

            if (curbig == -1 || a[j] > a[curbig]) curbig = j;
        }

        if (curbig == -1) continue;

        int cursm = -1;
        for (int j = 0; j < n; ++j) {
            if (j == curbig) continue;

            if (cursm == -1 || a[j] < a[cursm]) cursm = j;
        }

        int curgain = (a[curbig] + a[cursm]) - (a[curbig] / i + a[cursm] * i);
        mxgain = max(mxgain, curgain);
    }

    int ans = sm - mxgain;
    ans.writeln;
}


module main;
import std.stdio, std.uni, std.algorithm;

void main()
{
    char[] a, b;
    readf!" %s\n %s"(a, b);
    writeln(clamp(sicmp(a, b), -1, 1));
}

Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.

Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.

If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.

If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
 http://en.wikipedia.org/wiki/Lexicographical_order

import std.stdio;
import std.string;
import std.uni;

void main() {
    auto str_1 = strip(readln).toLower;
    auto str_2 = strip(readln).toLower;
    if (str_1 == str_2)
        writeln(0);
    else if (str_1 > str_2)
        writeln(1);
    else
        writeln(-1);
}

[{'input': ['aaaa\r\naaaA\r\n'], 'output': ['0\r\n']}, {'input': ['abs\r\nAbz\r\n'], 'output': ['-1\r\n']}, {'input': ['abcdefg\r\nAbCdEfF\r\n'], 'output': ['1\r\n']}, {'input': ['asadasdasd\r\nasdwasdawd\r\n'], 'output': ['-1\r\n']}, {'input': ['aslkjlkasdd\r\nasdlkjdajwi\r\n'], 'output': ['1\r\n']}, {'input': ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n'], 'output': ['0\r\n']}, {'input': ['aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\r\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp\r\n'], 'output': ['0\r\n']}, {'input': ['bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\r\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH\r\n'], 'output': ['-1\r\n']}, {'input': ['kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\r\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt\r\n'], 'output': ['1\r\n']}, {'input': ['nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\r\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL\r\n'], 'output': ['1\r\n']}, {'input': ['ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\r\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo\r\n'], 'output': ['1\r\n']}, {'input': ['AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\r\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja\r\n'], 'output': ['-1\r\n']}, {'input': ['HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\r\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy\r\n'], 'output': ['1\r\n']}, {'input': ['mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\r\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR\r\n'], 'output': ['1\r\n']}, {'input': ['tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\r\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd\r\n'], 'output': ['1\r\n']}, {'input': ['AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\r\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI\r\n'], 'output': ['-1\r\n']}, {'input': ['HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\r\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC\r\n'], 'output': ['-1\r\n']}, {'input': ['OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\r\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl\r\n'], 'output': ['-1\r\n']}, {'input': ['tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\r\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo\r\n'], 'output': ['-1\r\n']}, {'input': ['cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\r\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV\r\n'], 'output': ['-1\r\n']}, {'input': ['sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\r\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ\r\n'], 'output': ['-1\r\n']}, {'input': ['hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\r\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK\r\n'], 'output': ['-1\r\n']}, {'input': ['ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\r\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys\r\n'], 'output': ['1\r\n']}, {'input': ['nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\r\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy\r\n'], 'output': ['-1\r\n']}, {'input': ['EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\r\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK\r\n'], 'output': ['-1\r\n']}, {'input': ['UG\r\nak\r\n'], 'output': ['1\r\n']}, {'input': ['JZR\r\nVae\r\n'], 'output': ['-1\r\n']}, {'input': ['a\r\nZ\r\n'], 'output': ['-1\r\n']}, {'input': ['rk\r\nkv\r\n'], 'output': ['1\r\n']}, {'input': ['RvuT\r\nbJzE\r\n'], 'output': ['1\r\n']}, {'input': ['PPS\r\nydq\r\n'], 'output': ['-1\r\n']}, {'input': ['q\r\nq\r\n'], 'output': ['0\r\n']}, {'input': ['peOw\r\nIgSJ\r\n'], 'output': ['1\r\n']}, {'input': ['PyK\r\noKN\r\n'], 'output': ['1\r\n']}, {'input': ['O\r\ni\r\n'], 'output': ['1\r\n']}, {'input': ['NmGY\r\npDlP\r\n'], 'output': ['-1\r\n']}, {'input': ['nG\r\nZf\r\n'], 'output': ['-1\r\n']}, {'input': ['m\r\na\r\n'], 'output': ['1\r\n']}, {'input': ['MWyB\r\nWZEV\r\n'], 'output': ['-1\r\n']}, {'input': ['Gre\r\nfxc\r\n'], 'output': ['1\r\n']}, {'input': ['Ooq\r\nwap\r\n'], 'output': ['-1\r\n']}, {'input': ['XId\r\nlbB\r\n'], 'output': ['1\r\n']}, {'input': ['lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\r\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF\r\n'], 'output': ['0\r\n']}, {'input': ['DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\r\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD\r\n'], 'output': ['0\r\n']}, {'input': ['tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\r\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA\r\n'], 'output': ['0\r\n']}, {'input': ['KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\r\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ\r\n'], 'output': ['0\r\n']}, {'input': ['cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\r\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG\r\n'], 'output': ['0\r\n']}, {'input': ['SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\r\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ\r\n'], 'output': ['0\r\n']}, {'input': ['kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\r\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ\r\n'], 'output': ['0\r\n']}, {'input': ['nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\r\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi\r\n'], 'output': ['0\r\n']}, {'input': ['abac\r\nadaa\r\n'], 'output': ['-1\r\n']}, {'input': ['Bbc\r\nabc\r\n'], 'output': ['1\r\n']}, {'input': ['aaaba\r\naaaab\r\n'], 'output': ['1\r\n']}]