#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    multiset<int> s;
    rep(i, N){
        int A; cin >> A;
        s.insert(-A);
    }
    int ans = 0;
    multiset<int>::iterator it;
    for(it = s.begin(); sz(s);){
        int A = -(*it);
        s.erase(it);
        rep3(j, 29, 0){
            if(A & (1<<j)){
                int B = -((1<<(j+1))-A);
                if(s.count(B)){
                    s.erase(s.find(B));
                    ans++;
                }
                break;
            }
        }
        it = s.begin();
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long n, long long m, vector<long long> x, vector<long long> y){
	ll sumx = 0, sumy = 0;
	rep(i, n) {
		sumx = (sumx + (2*i-n+1) * x[i]) % mod;
	}
	rep(i, m) {
		sumy = (sumy + (2*i-m+1) * y[i]) % mod;
	}
	cout << sumx * sumy % mod << endl;
}

int main(){	
	long long m;
	long long n;
	scanf("%lld",&n);
	vector<long long> x(n-1+1);
	scanf("%lld",&m);
	vector<long long> y(m-1+1);
	for(int i = 0 ; i <= n-1 ; i++){
		scanf("%lld",&x[i]);
	}
	for(int i = 0 ; i <= m-1 ; i++){
		scanf("%lld",&y[i]);
	}
	solve(n, m, x, y);
	return 0;
}

