Problem:
Score : 800 points

Problem Statement

In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed.

Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicographically smallest one.

Constraints

1 \leq N,K \leq 3 × 10^5

N and K are integers.

Input

Input is given from Standard Input in the following format:

K N

Output

Print the (X/2)-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS.

Sample Input 1

3 2

Sample Output 1

2 1

There are 12 sequences listed in FEIS: (1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3).
The (12/2 = 6)-th lexicographically smallest one among them is (2,1).

Sample Input 2

2 4

Sample Output 2

1 2 2 2

Sample Input 3

5 14

Sample Output 3

3 3 3 3 3 3 3 3 3 3 3 3 2 2

Solution in Rust (1.15.1) (judge verdict: Accepted)

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

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};


enum List<T> {
    Cons(T, std::rc::Rc<List<T>>), 
    Nil,
}

impl<T> List<T>
where
    T: std::fmt::Display
{
    fn print(&self) {
        match self {
            &List::Cons(ref v, ref nex) => {
                print!("{} ", v);
                nex.print();
            },
            &List::Nil => {
                // println!("");
            },
        } 
    }
}

fn find(k: usize, h: usize, size: usize, mut dis: usize) -> List<usize> {
    debug!((dis, size));
    if dis == 0 {
        List::Nil
    } else {
        let mut a = 1;
        loop {
            if dis <= size {
                break;
            }
            dis -= size;
            a += 1;
        }
        dis -= 1;
        List::Cons(a, std::rc::Rc::new(find(k, h-1, (size-1)/k, dis)))
    }
}

fn next(n: usize, k: usize, s: &mut Vec<usize>) {
    if s.len() != n {
        s.push(1);
    } else {
        while let Some(v) = s.pop() {
            if v < k {
                s.push(v+1);
                break;
            }
        }
    }
}

fn prev(n: usize, k: usize, s: &mut Vec<usize>) {
    if let Some(v) = s.pop() {
        if v != 1 {
            s.push(v-1);
            while s.len() < n {
                s.push(k);
            }
        }
    }
}

fn enumerate(n: usize, k: usize) {
    let mut v = Vec::new();
    v.push(1);
    let m = (k.pow(n as u32)-1) / (k-1) * k;
    debug!((m, m/2));
    print!("{}: ", 1);
    println!("{}", show(v.iter()));
    for i in 1..m {
        next(n, k, &mut v);
        print!("{}: ", i+1);
        println!("{}", show(v.iter()));
    }
}


fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    let (k, n) = readl!(usize, usize);
    // enumerate(n, k);


    if k%2 == 0 {
        printf!("{}", k/2);
        for _ in 1..n {
            printf!(" {}", k);
        }
        printfln!("");
    } else {
        // let mid = (k+1)/2;
        // let x: usize = (0..n).map(|x| k.pow(x as u32 + 1)).sum();
        // let ans = find(k, n, x/k, x/2+1);
        // ans.print();
        
        let mid = (k+1)/2;
        let mut v = vec![mid; n];
        // debug!((n+k-1)/k+1);
        for _ in 0..(n+1)/2 {
            prev(n, k, &mut v);
        }
        if n%2 == 1 {
            next(n, k, &mut v);
        }
        printfln!("{}", show(v.iter()));
    }
}