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 C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include "bits/stdc++.h"
using namespace std;

int n;
int k;

#define MAX 300002

vector<int> ans;
long long int sz[MAX];
long long int m2[MAX];
void output() {
	while (ans.back() == 0) {
		ans.pop_back();
	}
	for (int i = 0; i < ans.size(); i++) {
		if (i)printf(" ");
		printf("%d", ans[i]);
	}
	puts("");
}
inline void dfs(int b,int pr=-1) {
	if (b == n) {
		return;
	}
	if (ans.size() == b) {
		ans.push_back(0);
	}
	int j = 0;
	if (pr == -1) {
		j = ans[b];
	}
	for (j; j <= k; j++) {
		if (j != ans[b]) {
			ans[b] = j;
			output();
			exit(0);
		}
		dfs(b+1, pr);
	}
	ans.pop_back();
}
int main() {
	cin >> k >> n;
	if (k % 2==0) {
		cout << k/2;
		for (int j = 1; j < n; j++) {
			printf(" %d", k);
		}
		puts("");
		return 0;
	}
	sz[n] = 1;
	m2[n] = 1;
	long long int MX = LLONG_MAX;//4 * n;
	for (int j = n - 1; j >= 0; j--) {
		sz[j] = sz[j + 1] * k;
		sz[j]++;
		sz[j] = min(sz[j], MX);
		m2[j] = m2[j + 1] * k;
		m2[j]++;
		m2[j] %= 2LL;
	}
	long long int minu = 0;
	long long int ID = 0; 
	for (int j = 0; j < n; j++) {
		if (m2[j]==1) {
			minu++;
		}
		if (abs(minu)*2 >= sz[j+1]) {
			ID = sz[j+1]*k;
			if (m2[j] == 1) {
				minu--;
			}
			ID++;
			ID /= 2LL;
			ID -= minu;
			while (1) {
				if (ID == 1) {
					break;
				}
				ID--;
				for (int go = 1; go <= k; go++) {
					if (ID > sz[j + 1]) {
						ID -= sz[j + 1];
					}
					else {
						ans.push_back(go);
						break;
					}
				}
			}
			break;
		}
		else {
			ans.push_back((k + 1) / 2);
			continue;
		}
	}
	dfs(0);
	output();
	return 0;
}