cswork / OAOpen practice workspace

IntuitOA #12

King-Dreams-I (Intuit India)

Estimated EasyJudge-ready

Topics (AI-labelled)GreedyBits & Math

Arrange tanks of types 1..m into a sequence of length n so that the number of contiguous subarrays containing only distinct types is maximized; if there are multiple such sequences, output the lexicographically smallest one.

Input

The input is n m, 1≤n≤100000, 1≤m≤10000000. Output n integers separated by spaces.

Output

Output the answer as described; for array answers, separate the values with spaces.

Example 1

Input:

1 2

Output:

1

Example 2

Input:

2 1

Output:

1 1

Example 3

Input:

2 2

Output:

1 2

Example notes

Construct by cycling 1,2,…,m.

Correctness: each interval of length at most m contributes at most one qualifying subarray, and an interval longer than m cannot have all distinct elements; the upper bound is Σ(n−ℓ+1), ℓ=1..min(n,m). The cyclic sequence makes every window of length ≤m consist of distinct elements, reaching this bound. A lexicographically smallest construction must always choose the smallest type that does not appear in the previous m−1 positions, so it is exactly the cycle 1,2,…,m.

Complexity: O(n) time and O(1) auxiliary space (excluding the output).

Editorial

Loading solution…