fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone {
  6. public static void main ( String[] arg s ) {
  7. Scanner in = new Scanner( System.in );
  8. int n = in.nextInt();
  9. int[] array = new int[n];
  10. if(n >= 3) {
  11. for( int i = 0; i < n; i++ ) array[i] = in.nextInt();
  12. for( int i=2; i<n; i=i+3 ) {
  13. int elem = array[i-1];
  14. array[i-1] = ( array[i-2] + array[i] ) / 2;
  15. array[i] = ( array[i-2] + elem ) / 2;
  16. }
  17. String ArrayString = Arrays.toString(array);
  18. System.out.print( ArrayString );
  19. } else System.out.print( "Try again" );
  20. }
  21. }
Success #stdin #stdout 0.15s 321280KB
stdin
5 
1 2 3 4 5
stdout
[1, 2, 1, 4, 5]