fork download
  1. import java.util.*;
  2. import java.io.*;
  3. //Solution Credits: Taranpreet Singh
  4. class Editorial{
  5. //SOLUTION BEGIN
  6. void solve(int TC) throws Exception{
  7. int n = ni();
  8. long[] a = new long[n];
  9. for(int i = 0; i< n; i++)a[i] = nl();
  10. if(n%2==1)pn("NO");
  11. else{
  12. boolean yes = true;
  13. for(int i = 0; i< n/2; i++){
  14. if(Math.min(a[i], a[i+n/2])>0){
  15. if(a[i]!=a[i+n/2])
  16. yes = false;
  17. }else if(Math.max(a[i], a[i+n/2])==-1)a[i] = a[i+n/2] = 1;
  18. else{
  19. long m = Math.max(a[i], a[i+n/2]);
  20. a[i] = a[i+n/2] = m;
  21. }
  22. }
  23. if(yes){
  24. pn("YES");
  25. for(long l:a)p(l+" ");pn("");
  26. }else pn("NO");
  27. }
  28. }
  29. //SOLUTION ENDS
  30. boolean multipleTC = true;
  31. FastReader in;PrintWriter out;
  32. void run() throws Exception{
  33. in = new FastReader();
  34. out = new PrintWriter(System.out);
  35. for(int i = 1, T = (multipleTC)?ni():1; i<= T; i++)solve(i);
  36. out.flush();
  37. out.close();
  38. }
  39. public static void main(String[] args) throws Exception{
  40. new Editorial().run();
  41. }
  42. void p(Object o){out.print(o);}
  43. void pn(Object o){out.println(o);}
  44. void pni(Object o){out.println(o);out.flush();}
  45. String n(){return in.next();}
  46. String nln(){return in.nextLine();}
  47. int ni(){return Integer.parseInt(in.next());}
  48. long nl(){return Long.parseLong(in.next());}
  49. double nd(){return Double.parseDouble(in.next());}
  50. class FastReader{
  51. public FastReader(){
  52. }
  53.  
  54. public FastReader(String s) throws Exception{
  55. br = new BufferedReader(new FileReader(s));
  56. }
  57.  
  58. String next(){
  59. while (st == null || !st.hasMoreElements()){
  60. try{
  61. st = new StringTokenizer(br.readLine());
  62. }catch (IOException e){
  63. e.printStackTrace();
  64. }
  65. }
  66. return st.nextToken();
  67. }
  68.  
  69. String nextLine(){
  70. String str = "";
  71. try{
  72. str = br.readLine();
  73. }catch (IOException e){
  74. e.printStackTrace();
  75. }
  76. return str;
  77. }
  78. }
  79. }
Success #stdin #stdout 0.04s 2184192KB
stdin
4
4
1 1 1 1
4
1 1 1 2
4
1 -1 -1 4
4
1 -1 2 -1
stdout
YES
1 1 1 1 
NO
YES
1 4 1 4 
NO