fork download
  1. import java.io.*;
  2. import java.math.BigInteger;
  3.  
  4. public class Main
  5. {
  6. public static void main(String[] args) throws IOException
  7. {
  8. new Main().run();
  9. }
  10.  
  11.  
  12. double nextDouble() throws IOException
  13. {
  14. st.nextToken();
  15. return (double)st.nval;
  16. }
  17.  
  18. String nextString() throws IOException
  19. {
  20. st.nextToken();
  21. return (String)st.sval;
  22. }
  23.  
  24. int nextInt() throws IOException
  25. {
  26. st.nextToken();
  27. return (int)st.nval;
  28. }
  29.  
  30. long nextLong() throws IOException
  31. {
  32. st.nextToken();
  33. return (long)st.nval;
  34. }
  35.  
  36.  
  37. void run() throws IOException
  38. {
  39. st = new StreamTokenizer(in);
  40. out = new PrintWriter(new OutputStreamWriter(System.out));
  41. solve();
  42. out.flush();
  43. }
  44.  
  45. void solve() throws IOException
  46. {
  47. int n = nextInt();
  48. if (n % 4 == 2 || n % 4 == 3){
  49. out.print(-1);
  50. return;
  51. }
  52. if (n == 1){
  53. out.println(1);
  54. out.println(2);
  55. out.println(3);
  56. return;
  57. }
  58. if (n == 4){
  59. out.println("4 2 3 1");
  60. out.println("8 9 7 5");
  61. out.println("12 11 10 6");
  62. return;
  63. }
  64. if (n == 5){
  65. out.println("7 3 4 2 1");
  66. out.println("8 11 9 10 5");
  67. out.println("15 14 13 12 6");
  68. return;
  69. }
  70. if (n == 8){
  71. out.println("8 6 4 2 7 1 5 3");
  72. out.println("16 17 18 19 13 10 9 12");
  73. out.println("24 23 22 21 20 11 14 15");
  74. return;
  75. }
  76. if (n % 4 == 0){
  77. int[] mas1 = new int[n];
  78. int[] mas2 = new int[n];
  79. int[] mas3 = new int[n];
  80. int k = n / 4;
  81. for (int i = 0; i < 2 * k; i++){
  82. mas3[i] = 12 * k - i;
  83. mas2[i] = 8 * k + i;
  84. mas1[i] = mas3[i] - mas2[i];
  85. }
  86. for (int i=1; i<k; i++){
  87. mas3[i + 2 * k - 1] = 8 * k - i - 1;
  88. mas2[i + 2 * k - 1] = 4 * k + i;
  89. mas1[i + 2 * k - 1] = mas3[i + 2 * k - 1] - mas2[i + 2 * k - 1];
  90. }
  91. for (int i=0; i<k - 2; i++){
  92. mas3[3 * k - 1 + i] = 7 * k - 1 - i;
  93. mas2[3 * k - 1 + i] = 5 * k + 2 + i;
  94. mas1[3 * k - 1 + i] = mas3[3 * k - 1 + i] - mas2[3 * k - 1 + i];
  95. }
  96. mas3[n - 3] = 10 * k;
  97. mas3[n - 2] = 8 * k - 1;
  98. mas3[n - 1] = 5 * k + 1;
  99. mas2[n - 3] = 6 * k + 1;
  100. mas2[n - 2] = 6 * k;
  101. mas2[n - 1] = 5 * k;
  102. mas1[n - 3] = 4 * k - 1;
  103. mas1[n - 2] = 2 * k - 1;
  104. mas1[n - 1] = 1;
  105. for (int i=0; i<n; i++){
  106. out.print(mas1[i] + " ");
  107. }
  108. out.println();
  109. for (int i=0; i<n; i++){
  110. out.print(mas2[i] + " ");
  111. }
  112. out.println();
  113. for (int i=0; i<n; i++){
  114. out.print(mas3[i] + " ");
  115. }
  116. return;
  117. }
  118. if (n % 4 == 1){
  119. int[] mas1 = new int[n];
  120. int[] mas2 = new int[n];
  121. int[] mas3 = new int[n];
  122. int k = n / 4;
  123. for (int i = 0; i < 2 * k; i++){
  124. mas3[i] = 12 * k + 3 - i;
  125. mas2[i] = 8 * k + 3 + i;
  126. mas1[i] = mas3[i] - mas2[i];
  127. }
  128. for (int i=1; i<=k; i++){
  129. mas3[i + 2 * k - 1] = 8 * k - i + 2;
  130. mas2[i + 2 * k - 1] = 4 * k + i + 1;
  131. mas1[i + 2 * k - 1] = mas3[i + 2 * k - 1] - mas2[i + 2 * k - 1];
  132. }
  133. for (int i=1; i<k - 1; i++){
  134. mas3[3 * k + i - 1] = 7 * k + 2 - i;
  135. mas2[3 * k + i - 1] = 5 * k + 3 + i;
  136. mas1[3 * k + i - 1] = mas3[3 * k - 1 + i] - mas2[3 * k - 1 + i];
  137. }
  138. mas3[n - 3] = 10 * k + 3;
  139. mas3[n - 2] = 8 * k + 2;
  140. mas3[n - 1] = 5 * k + 3;
  141. mas2[n - 3] = 6 * k + 2;
  142. mas2[n - 2] = 6 * k + 3;
  143. mas2[n - 1] = 5 * k + 2;
  144. mas1[n - 3] = 4 * k + 1;
  145. mas1[n - 2] = 2 * k - 1;
  146. mas1[n - 1] = 1;
  147. for (int i=0; i<n; i++){
  148. out.print(mas1[i] + " ");
  149. }
  150. out.println();
  151. for (int i=0; i<n; i++){
  152. out.print(mas2[i] + " ");
  153. }
  154. out.println();
  155. for (int i=0; i<n; i++){
  156. out.print(mas3[i] + " ");
  157. }
  158. return;
  159. }
  160. }
  161.  
  162. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty