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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.*;
import java.util.*;

public class Main {

	void submit() {
		int num = nextInt();
		int len = nextInt();
		if (num % 2 == 0) {
			out.print(num / 2 + " ");
			for (int i = 0; i < len - 1; i++) {
				out.print(num + " ");
			}
			out.println();
			return;
		}

		if (num == 1) {
			int outp = (len + 1) / 2;
			for (int i = 0; i < outp; i++) {
				out.print("1 ");
			}
			out.println();
			return;
		}

		int[] a = new int[len];
		Arrays.fill(a, (num + 1) / 2);

		int nowLen = len;

		int decr = len / 2;

		while (decr > 0) {
			if (nowLen == len) {
				if (a[len - 1] - 1 >= decr) {
					a[len - 1] -= decr;
					break;
				}
				nowLen -= 1;
				decr -= a[len - 1];
			} else {
				decr--;
				if (a[nowLen - 1] == 1) {
					nowLen--;
				} else {
					a[nowLen - 1]--;
					for (int j = nowLen; j < len; j++) {
						a[j] = num;
					}
					nowLen = len;
				}
			}
		}
		
		for (int x : a) {
			out.print(x + " ");
		}
		out.println();

	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}