#include <bits/stdc++.h>

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
	read(first);
	read(args...);
}
int n,a[200020];
map<int,int> cmp;
int main() {
	read(n);
	for(int i=0;i<n;i++){
		read(a[i]);
		cmp[a[i]]+=1;
	}
	sort(a,a+n);
	int ans  =0;
	for(int i=n-1;i>=0;i--){
		if(!cmp[a[i]])continue;
		cmp[a[i]]-=1;
		int b = a[i];
		b+=b&(-b);
		while(b!=(b&(-b)))b+=b&(-b);
		if(cmp[b-a[i]]){
			ans++;
			cmp[b-a[i]]--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n,m;cin>>n>>m;
  vector<int> a(n+1,0);
  vector<int> sum(n+5,0);
  map<int,int> memo;
  memo[0]=1;
  rep1(i,n){
    cin>>a[i];
    sum[i]=sum[i-1]+a[i];
    sum[i]%=m;
    memo[sum[i]]+=1;
  }
  int res=0;
  for(auto it=memo.begin();it!=memo.end();++it){
      res+=it->second*(it->second-1)/2;
  }
  cout<<res<<"\n";
  return 0;
}