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: Accepted)

import java.util.*;

public class Main{

    private void print(ArrayList<Integer> arrayMid){
        StringBuilder Mid = new StringBuilder();
        for(int i = 0; i < arrayMid.size(); i ++){
           Mid.append(arrayMid.get(i) + " ");
        }
        System.out.print(Mid);
   }

   private void Even(int K, int N){
       ArrayList<Integer> arrayMid = new ArrayList<Integer>(N);
       arrayMid.add(0, K / 2);
       for(int i = 1; i < N; i ++) arrayMid.add(i, K);
       print(arrayMid);
   }

   private void Odd(int K, int N){
       ArrayList<Integer> arrayMid = new ArrayList<Integer>(N);
       for(int i = 0; i < N; i ++) arrayMid.add(i, (K + 1) / 2);    
       for(int i = 0; i < N / 2; i ++){
           if(arrayMid.get(arrayMid.size() - 1) == 1) arrayMid.remove(arrayMid.size() - 1);
           else{
               arrayMid.set((arrayMid.size() - 1), arrayMid.get(arrayMid.size() - 1) - 1);
               for(int j = arrayMid.size(); j < N; j++) arrayMid.add(j, K);
           }
       }
       print(arrayMid);
   }

   private void Judge(int K, int N){
       if(K % 2 == 0) Even(K, N);
       else Odd(K, N);
   }

   public static void main(String [] args){
       Scanner input = new Scanner(System.in);
       int[] in = new int[2];
       for(int i = 0; i < 2; i++){
           in[i] = input.nextInt();
       }
       Main myEncyclopedia = new Main();
       myEncyclopedia.Judge(in[0], in[1]);
       input.close();
   }
}