Problem:
B: ANDをとって引く
問題文
長さ \(N\) の数列 \(A=(A_{1},...,A_{N})\) が与えられます。
以下の操作を好きなだけ行うことができます。
\(1 \leq i \lt j \leq N\) を満たす \(i,j\) を選び，\(A_{i}\) と \(A_{j}\) のビットごとの論理積を \(A_{i}\) または \(A_{j}\) から引く
最大で何個の要素を \(0\) にすることができますか？
制約
\(1\leq N \leq 3\times 10^5\)
\(1\leq A_i \leq 3\times 10^5\)
入力はすべて整数である。
入力形式
N
A_1 A_2 ... A_n
出力形式
\(0\) にできる要素数の最大値を求めてください。
入力例1
3
2 3 7
出力例1
2
\(x\ \mathrm{AND}\ y\) を \(x\) と \(y\) のビットごとの論理積とします。
\(1\) 回目の操作として、\((i, j) = (1, 2)\) を選び、\(A_1\) から \(A_1\) と \(A_2\) のビットごとの論理積を引きます。
\(A_1 = 2 - (2\ \mathrm{AND}\ 3) = 2 - 2 = 0\) です。
\(1\) 回目の操作のあと、\(A = (0, 3, 7)\) です。
\(2\) 回目の操作として、\((i, j) = (2, 3)\) を選び、\(A_2\) から \(A_2\) と \(A_3\) のビットごとの論理積を引きます。
\(A_1 = 3 - (3\ \mathrm{AND}\ 7) = 3 - 3 = 0\) です。
\(2\) 回目の操作のあと、\(A = (0, 0, 7)\) です。
\(2\) 個の要素が \(0\) になりました。これが最大値で、答えは \(2\) です。
入力例2
5
11 2 14 14 8
出力例2
3
入力例3
10
1 415 9 265 35 897 932 384 626 43
出力例3
8

Submitted solutions:

code_snippet: // AOJ #3230 AND Subtraction
// 2025.4.19

#include <bits/stdc++.h>
using namespace std;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) {
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int main(){
    int n = Cin();
    vector<int> a(n);
    int M = 0;
    for(int i = 0; i < n; i++){
        a[i] = Cin();
        M |= a[i];
    }
    vector<int> bitpos;
    for(int b = 0; b < 30; b++) if(M >> b & 1) bitpos.push_back(b);

    int B = bitpos.size();
    int ALL = (1<<B) - 1;
    vector<unsigned char> has(1<<B, 0);
    for(int x : a){
        int m = 0;
        for(int i = 0; i < B; i++) if(x >> bitpos[i] & 1) m |= 1<<i;
        has[m] = 1;
    }

    vector<unsigned char> sup(1<<B, 0);
    for(int s = 0; s <= ALL; s++) sup[s] = has[s];
    for(int i = 0; i < B; i++){
        for(int s = 0; s <= ALL; s++){
            if(!(s & (1<<i))) sup[s] |= sup[s | (1<<i)];
        }
    }

    const unsigned char INF = B + 1;
    vector<unsigned char> dp(1<<B, INF);
    dp[0] = 0;
    for(int s = 1; s <= ALL; s++) if(sup[s]) dp[s] = 1;

    for(int s = 1; s <= ALL; s++){
        if(dp[s] == 1) continue;
        for(int t = (s-1)&s; t; t = (t-1)&s){
            unsigned char c = dp[t] + dp[s^t];
            if(c < dp[s]) dp[s] = c;
        }
    }
    Cout(n - dp[ALL]);
    return 0;
}
accuracy: 1
time_ms: 830
memory_kb: 5660
final_rank: 5

code_snippet: // AOJ #3230 AND Subtraction
// 2025.4.19

#include <bits/stdc++.h>
using namespace std;
const int INF = 100;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) {
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int main(){
    int n = Cin();
    vector<int> a(n);
    for(int i = 0; i < n; i++) a[i] = Cin();

    const int B = 19;
    vector<int> cnt(B, 0), cap(B, 0), sc(B, 0);
    for(int x : a){
        for(int b = 0; b < B; b++) if(x & (1<<b)) cnt[b]++;
    }
    for(int b = 0; b < B; b++) cap[b] = max(0, cnt[b] - 1);

    vector<int> idx(n);
    iota(idx.begin(), idx.end(), 0);
    sort(idx.begin(), idx.end(), [&](int i, int j){
        return __builtin_popcount(a[i]) < __builtin_popcount(a[j]);
    });

    int ans = 0;
    for(int i : idx){
        bool ok = true;
        int x = a[i];
        for(int b = 0; b < B; b++){
            if(x & (1<<b)){
                if(sc[b] >= cap[b]){
                    ok = false;
                    break;
                }
            }
        }
        if(ok){
            ans++;
            for(int b = 0; b < B; b++) if(x & (1<<b)) sc[b]++;
        }
    }
    Cout(ans);
    return 0;
}
accuracy: 0.2972972972972973
time_ms: 70
memory_kb: 5356
final_rank: 10

code_snippet: // AOJ #3230
// AND Subtraction 2025.2.4

#include <bits/stdc++.h>
using namespace std;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) { // 整数の表示（出力）
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int main() {
    int N = Cin();
    vector<int> A(N);
    for (int &a : A) a = Cin();

    vector<int> cnt(20, 0);
    for (int a : A) {
        for (int b = 0; b < 20; ++b) {
            if (a & (1 << b)) cnt[b]++;
        }
    }

    vector<bool> is_required(N, false);
    vector<int> required;
    for (int i = 0; i < N; ++i) {
        int a = A[i];
        bool req = false;
        for (int b = 0; b < 20; ++b) {
            if ((a & (1 << b)) && cnt[b] == 1) {
                req = true;
                break;
            }
        }
        if (req) {
            is_required[i] = true;
            required.push_back(i);
        }
    }

    unordered_set<int> covered_bits;
    for (int i : required) {
        int a = A[i];
        for (int b = 0; b < 20; ++b) {
            if (a & (1 << b)) {
                covered_bits.insert(b);
            }
        }
    }

    vector<int> B;
    for (int b = 0; b < 20; ++b) {
        if (cnt[b] >= 1 && !covered_bits.count(b)) {
            B.push_back(b);
        }
    }

    if (B.empty()) {
        Cout(N - required.size());
        return 0;
    }

    vector<int> candidates;
    for (int i = 0; i < N; ++i) {
        if (!is_required[i]) {
            candidates.push_back(A[i]);
        }
    }

    int target = 0;
    for (int b : B) target |= (1 << b);

    int current_target = target;
    int selected = 0;

    while (current_target) {
        int best_mask = 0;
        int best_count = 0;
        for (int a : candidates) {
            int mask = a & current_target;
            int cnt = __builtin_popcount(mask);
            if (cnt > best_count) {
                best_count = cnt;
                best_mask = mask;
            }
        }
        if (best_count == 0) break;
        selected++;
        current_target &= ~best_mask;
    }
    Cout(N - (required.size() + selected));
    return 0;
}
accuracy: 0.581081081081081
time_ms: 40
memory_kb: 6256
final_rank: 7

code_snippet: // AOJ #3230
// AND Subtraction 2025.2.3

#include <bits/stdc++.h>
using namespace std;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) { // 整数の表示（出力）
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

using ll = long long;

// ビット数：最大入力値が300,000 < 2^19 であるため、19ビットで十分
const int B = 19;
const int M = 1 << B;
ll C[20][M];
ll D[20][M];

inline bool in(int S, int a) { return ((S >> a) & 1) != 0; }

int main() {
    int N = Cin();
    
    int mx = 0;
    for (int i = 0; i < N; i++){
        int S = Cin();
        mx |= S;
        D[1][S]++;
    }
    
    for (int i = 0; i < B; i++){
        for (int S = 0; S < M; S++){
            if (in(S, i)) D[1][S] += D[1][S ^ (1 << i)];
        }
    }
    
    for (int k = 2; k <= B; k++){
        for (int S = 0; S < M; S++){
            D[k][S] = D[k-1][S] * D[1][S];
        }
    }
    
    for (int k = 1; k <= B; k++){
        for (int S = 0; S < M; S++){
            C[k][S] = D[k][S];
        }
        for (int i = 0; i < B; i++){
            for (int S = 0; S < M; S++){
                if (((S & mx) == S) && in(S, i)) {
                    C[k][S] -= C[k][S ^ (1 << i)];
                }
            }
        }
        if (C[k][mx] > 0) {
            Cout(N - k);
            return 0;
        }
    }
    return 0;
}
accuracy: 0.2702702702702703
time_ms: 140
memory_kb: 160876
final_rank: 11

code_snippet: // AOJ #3230
// AND Subtraction 2025.2.3

#include <bits/stdc++.h>
using namespace std;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) { // 整数の表示（出力）
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int main(){
    int N = Cin();
    vector<int> A(N);
    int globalOR = 0;
    for (int i = 0; i < N; i++){
        A[i] = Cin();
        globalOR |= A[i];
    }
    
    // A[i] の最大値は 300,000 なので、20 ビットで十分 (2^20 = 1,048,576)
    const int B = 20;
    vector<int> bitFreq(B, 0);
    // 各ビットが何回現れるかを数える
    for (int i = 0; i < N; i++){
        for (int b = 0; b < B; b++){
            if (A[i] & (1 << b)) bitFreq[b]++;
        }
    }
    
    // forcedMark[i] = true なら、A[i] は入力中で唯一のビットを持っているため、必ず残らなければならない
    vector<bool> forcedMark(N, false);
    for (int i = 0; i < N; i++){
        for (int b = 0; b < B; b++){
            if (A[i] & (1 << b)){
                if (bitFreq[b] == 1){
                    forcedMark[i] = true;
                    break;
                }
            }
        }
    }
    
    // 同じ値の forced な数は、ひとつだけあれば十分なので、値の集合として登録する
    unordered_set<int> forcedVals;
    int forcedOR = 0;
    for (int i = 0; i < N; i++){
        if (forcedMark[i]){
            forcedVals.insert(A[i]);
        }
    }
    for (auto v : forcedVals) forcedOR |= v;
    int forcedCount = forcedVals.size();
    
    // survivors（最終的に 0 にできず残る必要のある最小個数）の決定
    int survivors;
    if (forcedCount > 0) {
        if (forcedOR == globalOR) survivors = forcedCount;
        else                      survivors = forcedCount + 1;
    } else                        survivors = 1;
    int ans = N - survivors;
    Cout(ans);
    return 0;
}
accuracy: 0.08108108108108109
time_ms: 30
memory_kb: 3904
final_rank: 18

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 3230.cc: AND Subtraction
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 300000;
const int MAX_A = 300000;
const int BN = 19;
const int BBITS = 1 << BN;

/* typedef */

/* global variables */

int as[MAX_N], bcs[BN], bss[BBITS], tmp[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", as + i);
    for (int j = 0, bj = 1; j < BN; j++, bj <<= 1)
      if (as[i] & bj) bcs[j]++;
  }

  bss[0] = 0;
  for (int bits = 1, msb = 1, msi = 0; bits < BBITS; bits++) {
    if ((msb << 1) <= bits) msb <<= 1, msi++;
    bss[bits] = bss[bits ^ msb] + bcs[msi];
   }
  
  int cnt = 0, msk = 0;
  for (int m = n; m > 0;) {
    cnt++;
    int maxb = -1, maxi = -1;
    for (int i = 0; i < m; i++)
      if (maxb < bss[as[i]]) maxb = bss[as[i]], maxi = i;
    msk |= as[maxi];

    int l = 0;
    for (int i = 0; i < m; i++) {
      int x = as[i] ^ (as[i] & msk);
      if (x != 0) tmp[l++] = x;
    }

    copy(tmp, tmp + l, as);
    m = l;
  }

  printf("%d\n", n - cnt);

  return 0;
}
accuracy: 0.10810810810810811
time_ms: 30
memory_kb: 6236
final_rank: 17

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 3230.cc: AND Subtraction
 */

#include<cstdio>
#include<queue>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 300000;
const int MAX_A = 300000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

int as[MAX_N], bnums[MAX_A + 1];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  int maxa = *max_element(as, as + n);

  bnums[0] = 0;
  for (int bits = 1, msb = 1; bits <= maxa; bits++) {
    if ((msb << 1) <= bits) msb <<= 1;
    bnums[bits] = bnums[bits ^ msb] + 1;
  }
  
  priority_queue<pii> q;
  for (int i = 0; i < n; i++) q.push(pii(bnums[as[i]], as[i]));
  
  int cnt = 0, msk = 0;
  while (! q.empty()) {
    pii ca = q.top(); q.pop();
    int a = ca.second;
    int x = a & msk;

    if (x == a) cnt++;
    else if (x == 0) msk |= a;
    else q.push(pii(bnums[a ^ x], a ^ x));
  }

  printf("%d\n", cnt);

  return 0;
}
accuracy: 0.47297297297297297
time_ms: 80
memory_kb: 10924
final_rank: 9

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

template<typename T>
void fwt(vector<T>& f){
    int n = f.size();
    for(int i=1;i<n;i*=2){
        for(int j=0;j<n;j++){
            if((i&j) == 0){
                f[j|i] += f[j];
            }
        }
    }
}
template<typename T>
void ifwt(vector<T>& f){
    int n = f.size();
    for(int i=1;i<n;i*=2){
        for(int j=0;j<n;j++){
            if((i&j) == 0){
                f[j|i] -= f[j];
            }
        }
    }
}
template<typename T>
vector<T> or_convolution(vector<T> a, vector<T> b){
    int n = a.size();
    fwt(a); fwt(b);
    vector<T> c(n);
    for(int i=0;i<n;i++){
        c[i] = a[i]*b[i];
    }
    ifwt(c);
    return c;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> f(1<<20);
    int o = 0;
    for(int i=0;i<n;i++){
        int a; cin >> a;
        o |= a; f[a] = 1;
    }
    vector<int> ff = f;
    for(int i=1;;i++){
        if(f[o] != 0){
            cout << n-i << endl;
            break;
        }
        f = or_convolution(f, ff);
    }
}
accuracy: 1
time_ms: 690
memory_kb: 23712
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <assert.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }


template<typename T>
void fwt(vector<T> &f) {
    int n = f.size();
    for(int i=1; i<n; i <<= 1) {
        for(int j=0; j<n; ++j) {
            if ((j & i) == 0) f[j | i] += f[j];
        }
    }
}

template<typename T>
void ifwt(vector<T> &f) {
    int n = f.size();
    for(int i=1; i<n; i <<= 1) {
        for(int j=0; j<n; ++j) {
            if ((j & i) == 0) f[j | i] + f[j];
        }
    }
}

template<typename T>
void convolve(vector<T> &F, vector<T> &G) {
    assert(F.size() == G.size());
    fwt(F);
    fwt(G);
    for(int i=0; i<F.size(); ++i) F[i] *= G[i];
    ifwt(F);
    for(int i=0; i<F.size(); ++i) if(F[i] > 1) F[i] = 1;
    ifwt(G);
}


int main() {
    int n; cin >> n;
    int U = 524288;
    int x = 0;
    vector<ll> F(U, 0), G(U, 0);
    for(int i=0; i<n; ++i) {
        int a; cin >> a;
        x |= a;
        F[a] = 1;
        G[a] = 1;
    }

    for(int i=1; i<n; ++i) {
        if (F[x] > 0) {
            cout << n - i << endl;
            return 0;
        }
        convolve(F, G);
    }
    cout << 0 << endl;
    return 0;
}
accuracy: 0.25675675675675674
time_ms: 60
memory_kb: 11424
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <assert.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }


template<typename T>
void fwt(vector<T> &f) {
    int n = f.size();
    for(int i=1; i<n; i <<= 1) {
        for(int j=0; j<n; ++j) {
            if ((j & i) == 0) f[j | i] += f[j];
        }
    }
}

template<typename T>
void ifwt(vector<T> &f) {
    int n = f.size();
    for(int i=1; i<n; i <<= 1) {
        for(int j=0; j<n; ++j) {
            if ((j & i) == 0) f[j | i] + f[j];
        }
    }
}

template<typename T>
void convolve(vector<T> &F, vector<T> &G) {
    assert(F.size() == G.size());
    fwt(F);
    fwt(G);
    for(int i=0; i<F.size(); ++i) F[i] *= G[i];
    ifwt(F);
    ifwt(G);
}


int main() {
    int n; cin >> n;
    int U = 524288;
    int x = 0;
    vector<ll> F(U, 0), G(U, 0);
    for(int i=0; i<n; ++i) {
        int a; cin >> a;
        x |= a;
        F[a] += 1;
        G[a] += 1;
    }

    for(int i=1; i<n; ++i) {
        if (F[x] > 0) {
            cout << n - i << endl;
            return 0;
        }
        convolve(F, G);
    }
    cout << 0 << endl;
    return 0;
}
accuracy: 0.25675675675675674
time_ms: 60
memory_kb: 11428
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <assert.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }


template<typename T>
void fwt(vector<T> &f) {
    int n = f.size();
    for(int i=1; i<n; i <<= 1) {
        for(int j=0; j<n; ++j) {
            if ((j & i) == 0) f[j | i] += f[j];
        }
    }
}

template<typename T>
void ifwt(vector<T> &f) {
    int n = f.size();
    for(int i=1; i<n; i <<= 1) {
        for(int j=0; j<n; ++j) {
            if ((j & i) == 0) f[j | i] + f[j];
        }
    }
}

template<typename T>
void convolve(vector<T> &F, vector<T> &G) {
    assert(F.size() == G.size());
    fwt(F);
    fwt(G);
    for(int i=0; i<F.size(); ++i) F[i] *= G[i];
    ifwt(F);
    ifwt(G);
}


int main() {
    int n; cin >> n;
    int U = 524288;
    int x = 0;
    vector<ll> F(U, 0), G(U, 0);
    for(int i=0; i<n; ++i) {
        int a; cin >> a;
        x |= a;
        F[a] += 1;
        G[a] += 1;
    }

    for(int i=1; i<n; ++i) {
        if (F[x] > 0) {
            cout << n - i << endl;
            return 0;
        }
        convolve(F, G);
    }
    return 0;
}
accuracy: 0.04054054054054054
time_ms: 10
memory_kb: 11388
final_rank: 20

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <assert.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }


template<typename T>
void fwt(vector<T> &f) {
    int n = f.size();
    for(int i=1; i<n; i <<= 1) {
        for(int j=0; j<n; ++j) {
            if ((j & i) == 0) f[j | i] += f[j];
        }
    }
}

template<typename T>
void ifwt(vector<T> &f) {
    int n = f.size();
    for(int i=1; i<n; i <<= 1) {
        for(int j=0; j<n; ++j) {
            if ((j & i) == 0) f[j | i] + f[j];
        }
    }
}

template<typename T>
void convolve(vector<T> &F, vector<T> &G) {
    assert(F.size() == G.size());
    fwt(F);
    fwt(G);
    for(int i=0; i<F.size(); ++i) F[i] *= G[i];
    ifwt(F);
    ifwt(G);
}


int main() {
    int n; cin >> n;
    int U = 524288;
    int x = 0;
    vector<int> F(U, 0), G(U, 0);
    for(int i=0; i<n; ++i) {
        int a; cin >> a;
        x |= a;
        F[a] += 1;
        G[a] += 1;
    }

    for(int i=1; i<n; ++i) {
        if (F[x] > 0) {
            cout << n - i << endl;
            return 0;
        }
        convolve(F, G);
    }
    return 0;
}
accuracy: 0.04054054054054054
time_ms: 10
memory_kb: 7308
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define vector4d(type,name,h,w,d,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(d,vector<type>(__VA_ARGS__))))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<'\n';}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n);
    vector<int> dp(1<<19,n+1),a(n);
    in(a);
    int s=0;
    rep(i,n){
        dp[a[i]]=1;
        s|=a[i];
    }
    for(int i=s;i>=1;i--){
        if(dp[i]>n)continue;
        for(int j=0;j<19;j++){
            if(i>>j&1)dp[i^(1<<j)]=1;
        }
    }
    dp[0]=0;
    for(int i=3;i<=s;i++){
        if(dp[i]==1||(s&i)!=i)continue;
        for(int j=(i-1)&i;j>0;j=(j-1)&i){
            chmin(dp[i],dp[j]+dp[j^i]);
        }
    }
    out(n-dp[s]);
}
accuracy: 1
time_ms: 980
memory_kb: 6308
final_rank: 6

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define vector4d(type,name,h,w,d,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(d,vector<type>(__VA_ARGS__))))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<'\n';}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n);
    vector<int> dp(1<<19,n+1),a(n);
    in(a);
    int s=0;
    rep(i,n){
        dp[a[i]]=1;
        s|=a[i];
    }
    for(int i=0;i<(1<<19);i++){
        if(dp[i]>n)continue;
        for(int j=0;j<19;j++){
            if(i>>j&1)dp[i^(1<<j)]=1;
        }
    }
    dp[0]=0;
    for(int i=3;i<=s;i++){
        if(dp[i]==1||(s&i)!=i)continue;
        for(int j=(i-1)&i;j>0;j=(j-1)&i){
            chmin(dp[i],dp[j]+dp[j^i]);
        }
    }
    out(n-dp[s]);
}
accuracy: 0.5405405405405406
time_ms: 890
memory_kb: 6276
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define vector4d(type,name,h,w,d,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(d,vector<type>(__VA_ARGS__))))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<'\n';}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n);
    vector<int> dp(1<<19,INF-1),a(n);
    in(a);
    int s=0;
    rep(i,n){
        dp[a[i]]=1;
        s|=a[i];
    }
    for(int i=(1<<19)-1;i>=1;i--){
        if(dp[i]!=1)continue;
        for(int j=0;j<20;j++){
            if(i>>j&1)dp[i^(1<<j)]=1;
        }
    }
    dp[0]=0;
    int ans=0;
    for(int j=s;j>0;j=(j-1)&s){
        chmax(ans,n-dp[j]-dp[s^j]);
    }
    out(ans);
}
accuracy: 0.25675675675675674
time_ms: 30
memory_kb: 6208
final_rank: 12

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define vector4d(type,name,h,w,d,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(d,vector<type>(__VA_ARGS__))))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<'\n';}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n);
    vector<int> dp(1<<20,INF-1),a(n);
    in(a);
    int s=0;
    rep(i,n){
        dp[a[i]]=1;
        s|=a[i];
    }
    for(int i=(1<<20)-1;i>=1;i--){
        if(dp[i]!=1)continue;
        for(int j=0;j<20;j++){
            if(i>>j&1)dp[i^(1<<j)]=1;
        }
    }
    dp[0]=0;
    int ans=0;
    for(int j=s;j>0;j=(j-1)&s){
        chmax(ans,n-dp[j]-dp[s^j]);
    }
    out(ans);
}
accuracy: 0.25675675675675674
time_ms: 30
memory_kb: 8320
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define vector4d(type,name,h,w,d,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(d,vector<type>(__VA_ARGS__))))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<'\n';}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n);
    vector<int> dp(1<<19,INF-1),a(n);
    in(a);
    int s=0;
    rep(i,n){
        dp[a[i]]=1;
        s|=a[i];
    }
    for(int i=(1<<19)-1;i>=1;i--){
        if(dp[i]==(INF-1))continue;
        for(int j=0;j<19;j++){
            if(i>>j&1)dp[i^(1<<j)]=1;
        }
    }
    dp[0]=0;
    int ans=0;
    for(int j=s;j>0;j=(j-1)&s){
        chmax(ans,n-dp[j]-dp[s^j]);
    }
    out(ans);
}
accuracy: 0.25675675675675674
time_ms: 30
memory_kb: 6212
final_rank: 13

code_snippet: #include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>
#include <string>
#include <random>
#include <array>
#include <climits>
#include <map>
#include <cassert>
#include <stack>
#include <iomanip>
#include <cfloat>
#include <bitset>
#include <fstream>
#include <chrono>

int pop_count(int value) {
	auto result{ 0 };
	while (value > 0) {
		result += value & 1;
		value >>= 1;
	}
	return result;
}
int max_count(const int n, const std::vector<int>& num, const int hash) {
	std::vector<int> count(1 << 19, 0);
	for (const auto a : num) {
		count[a] += 1;
	}
	for (auto d = 0; d < 19; ++d) {
		for (auto i = 0; i < count.size(); ++i) {
			if ((i >> d) & 1) {
				count[i] = count[i] + count[i - (1 << d)];
			}
		}
	}
	const auto all = std::accumulate(num.begin(), num.end(), 0, [](const auto a, const auto v) {return a | v; });
	std::vector<long long int> memo(1 << 19, 1);
	for (auto c = n - 1; c > 0; --c) {
		for (auto i = 0; i < count.size(); ++i) {
			memo[i] = memo[i] * count[i] % hash;
		}
		long long int all_count{ 0 };
		for (auto i = 0; i < memo.size(); ++i) {
			if ((~all & i)) continue;
			if (pop_count(i) & 1) {
				all_count += memo[i];
			}
			else {
				all_count -= memo[i];
			}
		}
		if (all_count % hash != 0) 
			return c;
	}
	return 0;
}

int main() {
	int n; std::cin >> n;
	std::vector<int> num(n);
	for (auto& a : num) {
		std::cin >> a;
	}
	int min = n;
	for (const auto hash: {1'000'000'007}) {
		min = std::min(min, max_count(n, num, hash));
	}
	std::cout << min << '\n';
}
accuracy: 1
time_ms: 130
memory_kb: 10400
final_rank: 2

code_snippet: #include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>
#include <string>
#include <random>
#include <array>
#include <climits>
#include <map>
#include <cassert>
#include <stack>
#include <iomanip>
#include <cfloat>
#include <bitset>
#include <fstream>
#include <chrono>

int pop_count(int value) {
	auto result{ 0 };
	while (value > 0) {
		result += value & 1;
		value >>= 1;
	}
	return result;
}
int max_count(const int n, const std::vector<int>& num, const int hash) {
	std::vector<int> count(1 << 19, 0);
	for (const auto a : num) {
		count[a] += 1;
	}
	for (auto d = 0; d < 19; ++d) {
		for (auto i = 0; i < count.size(); ++i) {
			if ((i >> d) & 1) {
				count[i] = count[i] + count[i - (1 << d)];
			}
		}
	}
	const auto all = std::accumulate(num.begin(), num.end(), 0, [](const auto a, const auto v) {return a | v; });
	std::vector<long long int> memo(1 << 19, 1);
	for (auto c = n - 1; c > 0; --c) {
		for (auto i = 0; i < count.size(); ++i) {
			memo[i] = memo[i] * count[i] % hash;
		}
		long long int all_count{ 0 };
		for (auto i = 0; i < memo.size(); ++i) {
			if ((~all & i)) continue;
			if (pop_count(i) & 1) {
				all_count += memo[i];
			}
			else {
				all_count -= memo[i];
			}
		}
		if (all_count % hash != 0) 
			return c;
	}
	return 0;
}

int main() {
	int n; std::cin >> n;
	std::vector<int> num(n);
	for (auto& a : num) {
		std::cin >> a;
	}
	int min = n;
	for (const auto hash: {1'000'000'007, 1'000'000'009, 1'000'000'021}) {
		min = std::min(min, max_count(n, num, hash));
	}
	std::cout << min << '\n';
}
accuracy: 1
time_ms: 390
memory_kb: 10436
final_rank: 3

code_snippet: // #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
const int inf = 1e9;
const ll lim = 1e18;
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

void zeta(vi& a, int n) {
  for (int i = 1; i < n; i <<= 1) rep(j, n) if (i & j) a[j] += a[i ^ j];
}

int mobius(vi a, int n) {
  for (int i = 1; i < n; i <<= 1) rep(j, n) if (i & j) a[j] -= a[i ^ j];
  return a[n - 1];
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, s=0, now, ans = 1;
  cin >> n;
  vi c(1 << 19);
  rep(i, n) {
    int a;
    cin >> a;
    c[a] = 1;
    s |= a;
  }

  now = c[s];
  zeta(c, s + 1);
  vi cx = c;

  while (now == 0) {
    rep(i, s + 1) cx[i] = c[i] * cx[i];
    ans += 1;
    now = mobius(cx, s + 1);
  }

  cout << n - ans << endl;

  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 9188
final_rank: 1