aboutsummaryrefslogtreecommitdiff
path: root/41/balance.cc
blob: b379f0d35b650a8d0d54bea72e61c95c98f86503 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;

bool is_balance(int a) {
    int one_num = 0;
    int zero_num = 0;
    while (a != 0)
    {
        if ((a & 1) == 0) {
            zero_num++;
        } else {
            one_num++;
        }
        a = a >> 1;
    }
    if (one_num == zero_num) {
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (is_balance(a[i])) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}