fork download
  1. def generate_doubled_sequence(N):
  2. if N % 2 != 0:
  3. return "-1"
  4.  
  5. sequence = [0] * (2 * N) # Create an array of size 2N
  6.  
  7. # Place numbers from N down to 1
  8. for i in range(N, 0, -1):
  9. first_position = i - 1 # 0-indexed position for the first occurrence
  10. second_position = first_position + i # 0-indexed position for the second occurrence
  11.  
  12. sequence[first_position] = i
  13. sequence[second_position] = i
  14.  
  15. return ' '.join(map(str, sequence))
  16.  
  17. def main():
  18. import sys
  19. input = sys.stdin.read
  20. data = input().strip().split()
  21.  
  22. T = int(data[0]) # Number of test cases
  23. results = []
  24.  
  25. for i in range(1, T + 1):
  26. N = int(data[i])
  27. results.append(generate_doubled_sequence(N))
  28.  
  29. print("\n".join(results))
  30.  
  31. if __name__ == "__main__":
  32. main()
Success #stdin #stdout 0.03s 9688KB
stdin
4
1
2
3
4
stdout
-1
1 1 0 2
-1
1 1 3 2 0 3 0 4