fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.Scanner;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Scanner in = new Scanner(System.in);
  14. int n, h=0, k=0;
  15. n = in.nextInt();
  16. int[] A = new int [n];
  17. for ( int i = 0; i < n; i++ ) {
  18. A[i] = in.nextInt();
  19. }
  20. for ( int i = 0; i < n; i++ ) {
  21. if ( A[n-1] == A[i] )
  22. {
  23. int t = 1;
  24. for ( int j = i + 1; j < n - 1; j++ )
  25. {
  26. if ( A[j] != A[ n - 1 - t ] )
  27. {
  28. k++;
  29. }
  30. t++;
  31. }
  32. if ( k == 0 )
  33. {
  34. h = i;
  35. break;
  36. }
  37. else k = 0;
  38. }
  39. }
  40. System.out.print(h);
  41. }
  42. }
Success #stdin #stdout 0.06s 2184192KB
stdin
3
1 2 3
stdout
2