fork download
  1. import java.io.*;
  2. import java.util.*;
  3. public class Main{
  4. static class FastReader {
  5.  
  6. public FastReader() {
  7. }
  8.  
  9. String next() {
  10. while (st == null || !st.hasMoreElements()) {
  11. try{
  12. st = new StringTokenizer(br.readLine());
  13. }
  14. catch (IOException e) {
  15. e.printStackTrace();
  16. }
  17. }
  18. return st.nextToken();
  19. }
  20.  
  21. int nextInt() {
  22. return Integer.parseInt(next());
  23. }
  24.  
  25. long nextLong() {
  26. return Long.parseLong(next());
  27. }
  28.  
  29. double nextDouble() {
  30. return Double.parseDouble(next());
  31. }
  32.  
  33. String nextLine() {
  34. String str = "";
  35. try
  36. {
  37. str = br.readLine();
  38. }
  39. catch (IOException e)
  40. {
  41. e.printStackTrace();
  42. }
  43. return str;
  44. }
  45. }
  46. static class FastWriter {
  47. private final PrintWriter writer;
  48.  
  49. public FastWriter(){
  50. writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  51. }
  52. public FastWriter(OutputStream outputStream) {
  53. writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
  54. }
  55.  
  56. public FastWriter(Writer writer) {
  57. this.writer = new PrintWriter(writer);
  58. }
  59.  
  60. public void print(Object...objects) {
  61. for (int i = 0; i < objects.length; i++) {
  62. if (i != 0)
  63. writer.print(' ');
  64. writer.print(objects[i]);
  65. }
  66. }
  67.  
  68. public void printLine(Object...objects) {
  69. print(objects);
  70. writer.println();
  71. }
  72.  
  73. public void close() {
  74. writer.close();
  75. }
  76.  
  77. public void flush() {
  78. writer.flush();
  79. }
  80. }
  81.  
  82.  
  83. public static void main(String args[]) throws IOException {
  84. FastReader fi = new FastReader();
  85. FastWriter fo = new FastWriter();
  86. int zeroCounter=0;
  87. int ind=-1;
  88. int n=fi.nextInt();
  89. long arr[]=new long[n];
  90. for(int i=0;i<n;i++){
  91. arr[i]=fi.nextInt();
  92. if(arr[i]==0){
  93. zeroCounter++;
  94. }
  95. }
  96. if(zeroCounter>=2){
  97. Arrays.fill(arr,0);
  98. }
  99. else if(zeroCounter==1){
  100. long prod=1;
  101. for(int i=0;i<arr.length;i++){
  102. if(arr[i]==0){
  103. ind=i;
  104. continue;
  105. }
  106. prod*=arr[i];
  107. }
  108. Arrays.fill(arr,0);
  109. arr[ind]=prod;
  110. }
  111. else{
  112. long prod=1;
  113. for(int i=0;i<arr.length;i++){
  114. prod*=arr[i];
  115. }
  116. for(int i=0;i<arr.length;i++){
  117. arr[i]=prod/arr[i];
  118. }
  119. }
  120. for(int i=0;i<arr.length;i++){
  121. fo.print(arr[i] +" " );
  122. }
  123. fo.flush();
  124. }
  125. }
Success #stdin #stdout 0.18s 34020KB
stdin
10
-3 2 1 -1 1 -2 1 -1 1 -1
stdout
4 -6 -12 12 -12 6 -12 12 -12 12