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 Ruby (2.3.3) (judge verdict: Wrong Answer)

K, N = gets.split.map(&:to_i)

if K % 2 == 0
    arr = [K/2] + Array.new(N-1, K)
    puts arr.join(' ')
    exit
end

node_dead = [0]
node_live = [1]
node = Array.new(N, 10**10)
node[0] = 1
(1..N).each do |i|
    node_dead[i] = node_live[i-1]
    node_live[i] = node_live[i-1] * K
    node[i] = node_dead[i] + node_live[i]
    break if node[i] > N
end

arr = []
diff = 0
depth = 0
while node[N-depth-1] > diff + 1
    arr.push((K+1)/2)
    diff += 1 if depth > 0
    depth += 1
end

loop do
    target = (node[N-depth]-diff+1)/2
    left = depth == 0 ? 0 : 1
    num = (target-1-left)/node[N-depth-1] + 1
    arr.push(num) if num > 0
    depth += 1
    if num == 0 || depth == N
        puts arr.join(' ')
        exit
    else
        diff -= (K-2*num+1)*node[N-depth] - left
    end
end