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.42.0) (judge verdict: Wrong Answer)

use proconio::input;

fn main() {
    input!(k: i64, n: i64);
    let tree_sizes = {
        let mut ret = vec![0i64; n as usize + 1];
        let mut coeff = 1i64;
        let mut cum = 0i64;
        for i in 0..=n as usize {
            ret[i] = cum;
            cum = cum.saturating_add(coeff);
            coeff = coeff.saturating_mul(k);
        }
        ret
    };
    let ans: Vec<i64> = {
        if k % 2 == 0 {
            std::iter::once(k / 2 - 1)
                .chain(std::iter::repeat(k / 2).take(n as usize - 1))
                .collect()
        } else {
            let mut shift = 1 - n % 2;
            let mut ans = vec![k / 2];
            if n == 1 {
                ans
            } else {
                for d in (1..n).rev() {
                    let tree_size = tree_sizes[d as usize];
                    shift += 1;
                    let mut num = k / 2;
                    while tree_size < shift {
                        num -= 1;
                        shift -= 2 * tree_size;
                    }
                    while shift < -tree_size {
                        num += 1;
                        shift += 2 * tree_size;
                    }
                    ans.push(num);
                    assert!(num < k);
                    assert!(-tree_size < shift && shift < tree_size);
                    if shift == tree_size - 1 {
                        break;
                    }
                }
                ans
            }
        }
    };
    println!(
        "{}",
        ans.iter()
            .map(|&x| (x + 1).to_string())
            .fold(String::new(), |acc, x| if acc.is_empty() {
                x
            } else {
                acc + " " + x.as_ref()
            })
    );
}