fork download
  1. def construct_doubled_sequence(N):
  2. if N % 2 == 1:
  3. return "-1" # No valid sequence for odd N
  4.  
  5. # For even N, construct the sequence
  6. sequence = []
  7. for i in range(1, N + 1):
  8. sequence.append(i)
  9. sequence.append(i)
  10.  
  11. # We need to rearrange to satisfy the distance condition
  12. # A simple method is to interleave the pairs
  13. result = []
  14. for i in range(1, N + 1):
  15. result.append(i)
  16. result.append(i)
  17.  
  18. # A pattern to ensure that it meets the doubled condition
  19. # Let's rearrange it as:
  20. for i in range(1, N + 1):
  21. result[i - 1], result[2 * i - 1] = result[2 * i - 1], result[i - 1]
  22.  
  23. return ' '.join(map(str, result))
  24.  
  25. def main():
  26. import sys
  27. input = sys.stdin.read
  28. data = input().strip().split()
  29.  
  30. T = int(data[0])
  31. results = []
  32. for i in range(1, T + 1):
  33. N = int(data[i])
  34. results.append(construct_doubled_sequence(N))
  35.  
  36. print('\n'.join(results))
  37.  
  38. if __name__ == "__main__":
  39. main()
  40.  
Success #stdin #stdout 0.04s 9788KB
stdin
4
1
2
3
4
stdout
-1
1 2 2 1
-1
1 2 3 4 3 2 4 1