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 Ideone
  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.  
  16. int a[]=new int[n];
  17. int b[]=new int[n];
  18. int c[]=new int[n];
  19. int d[]=new int[n];
  20. int e[]=new int[n];
  21.  
  22. for(int i=0;i<n;i++)
  23. a[i]=sc.nextInt();
  24.  
  25. for(int j=0;j<n;j++)
  26. b[j]=sc.nextInt();
  27.  
  28. for(int k=0;k<n;k++)
  29. c[k]=sc.nextInt();
  30.  
  31. for(int l=0;l<n;l++)
  32. d[l]=sc.nextInt();
  33.  
  34. for(int m=0;m<n;m++)
  35. e[m]=sc.nextInt();
  36.  
  37. //storing the sum of the last 2 array values in hashmap
  38. Map<Integer,Integer> m=new HashMap<>();
  39.  
  40. //storing the sum of the last 2 array values in hashmap
  41. for(int i=0;i<n;i++)
  42. {
  43. for(int j=0;j<n;j++)
  44. {
  45. int sum=d[i]+e[j];
  46. m.put(sum,m.getOrDefault(sum,0)+1);
  47. }
  48. }
  49.  
  50.  
  51. int ans=0;
  52. for(int i=0;i<n;i++)
  53. {
  54. for(int j=0;j<n;j++)
  55. {
  56. for(int k=0;k<n;k++)
  57. {
  58. int val=a[i]+b[j]+c[k];
  59. if(m.containsKey(-val))
  60. ans+=m.get(-val);
  61. }
  62. }
  63. }
  64.  
  65. System.out.println(ans);
  66.  
  67.  
  68. }
  69. }
Success #stdin #stdout 0.14s 56496KB
stdin
2
2 5 
3 8
-5 8
5 10
-10 100
stdout
2