fork download
  1. #include<bits/stdc++.h>
  2. #define FOR(i,a,b) for(long long int i=(a);i<=(b);++i)
  3. #define NFOR(i,a,b) for(long long int i=(a);i>=(b);--i)
  4. #define pb push_back
  5. #define ll long long
  6. #define F first
  7. #define PI 3.14159265358979323846264338327
  8. #define S second
  9. #define all(v) v.begin(),v.end()
  10. #define trace(x) cout << '>' << #x << ':' << x << endl;
  11. #define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;
  12. #define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
  13. #define MOD 1000000007
  14. using namespace std;
  15. ll brr[10004];
  16. void solve()
  17. {
  18. ll t,n,m,x,y;
  19. cin>>n>>m;
  20. ll arr[n+1];
  21. FOR(i,1,n)
  22. cin>>arr[i];
  23.  
  24. FOR(i,1,n)
  25. {
  26. arr[i]%=m;
  27. brr[arr[i]]++;
  28. }
  29. long long sum=0;
  30. FOR(i,0,m-1)
  31. {
  32. if(brr[i]<=0)continue;
  33. FOR(j,i,m-1)
  34. {
  35. if(brr[j]<=0)continue;
  36. ll v1=(i+j)%m;
  37. ll k=(m-v1)%m;
  38. if(k>=j){
  39. long long ans=0;
  40. if(i==j&&i==k)
  41. {
  42. if(brr[i]>=2)
  43. ans+=(1LL*brr[i]*(brr[i]-1)*(brr[i]-2))/6;
  44. }
  45. else if(i==j)
  46. {
  47. if(brr[i]>=1){
  48. ans+=(1LL*(brr[i])*(brr[i]-1))/2;
  49. ans*=brr[k];}
  50. }
  51. else if(i==k)
  52. {
  53. if(brr[i]>=1){
  54. ans+=(1LL*(brr[i])*(brr[i]-1))/2;
  55. ans*=brr[j];}
  56. }
  57. else if(j==k)
  58. {
  59. if(brr[j]>=1){
  60. ans+=(1LL*(brr[j])*(brr[j]-1))/2;
  61. ans*=brr[i];}
  62. }
  63. else
  64. ans+=(1LL*brr[i]*brr[j]*brr[k]);
  65. ans=max(ans,0LL);
  66. sum+=ans;
  67.  
  68. }
  69. }
  70. }
  71. cout<<sum<<endl;
  72.  
  73. }
  74.  
  75. int main()
  76. {
  77. fast;
  78.  
  79. solve();
  80. return 0;
  81. }
Runtime error #stdin #stdout 0s 16144KB
stdin
Standard input is empty
stdout
Standard output is empty