PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000150. Vòng tròn nguyên tố (Prime Ring Problem)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Vòng tròn nguyên tố (Prime Ring Problem)

Prime Ring Problem

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Given an even nn, list all permutations of 1,…,n1,\ldots,n forming a prime ring: adjacent elements (including last and first) have prime sum. The first element must be 1. Print all valid sequences in lexicographic order; reversed orientations are listed separately.

Input

One line containing even nn.

Output

Print Case 1: and then every valid sequence in lexicographic order.

Subtask

  • Subtask 1 (20 points): even nn, 2≤n≤62\le n\le6.
  • Subtask 2 (30 points): even nn, 2≤n≤122\le n\le12.
  • Subtask 3 (50 points): even nn, 2≤n≤162\le n\le16.

Example

Input

6

Output

Case 1:
1 4 3 2 5 6
1 6 5 2 3 4

Explanation

Starting with 1, every neighboring sum (also the last and first) is prime. Both sequences are listed in lexicographic order.