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