This page is still under construction.

Parts of this page are still being built. What you see may change.

Highly Composite Permutations

Interview

Time limit2sMemory limit512 MB

Summary
Find a permutation of 1 to n whose every prefix sum is a composite number, or report that none exists.
Level

Medium5 of 10

Topics
Math, Number theory, Greedy, Implementation
Solved
No attempts yet

Problem

A positive integer xx is called composite if it has strictly more than two positive integer divisors. For example, 4, 30 and 111 are composite, while 1, 7 and 239 are not.

An integer sequence p=⟨p1,p2,…,pn⟩p = \langle p_1, p_2, \ldots, p_n \rangle is called a permutation of length nn if it contains every integer from 1 to nn inclusive exactly once.

A permutation p=⟨p1,p2,…,pn⟩p = \langle p_1, p_2, \ldots, p_n \rangle is called highly composite if for every ii from 1 to nn inclusive, the sum of the first ii elements of pp, that is p1+p2+…+pip_1 + p_2 + \ldots + p_i, is composite.

Given a single integer nn, find a highly composite permutation of length nn.

Input

The only line of the input contains a single integer nn (1≤n≤1001 \le n \le 100).

Output

If no highly composite permutation of length nn exists, output a single integer −1-1. Otherwise, output nn integers p1,p2,…,pnp_1, p_2, \ldots, p_n such that p=⟨p1,p2,…,pn⟩p = \langle p_1, p_2, \ldots, p_n \rangle is a highly composite permutation.

If there are multiple highly composite permutations of length nn, you may output any of them.

Notes

In the first example test case, the first element of the permutation, 9, is composite, the sum of the first two elements, 9+13=229 + 13 = 22, is composite, the sum of the first three elements, 9+13+6=289 + 13 + 6 = 28, is composite, and so on.

In the second example test case, only two permutations of the required length exist, ⟨1,2⟩\langle 1, 2 \rangle and ⟨2,1⟩\langle 2, 1 \rangle, and neither of them is highly composite.

Examples2

  1. Example 1

    Input
    13
    
    Expected output
    9 13 6 5 3 2 8 4 1 12 11 10 7
    
  2. Example 2

    Input
    2
    
    Expected output
    -1