Problem:
D: Nose And Lung
問題文
あなたは謎の敵対的なエイリアンについて研究しています。
エイリアンには鼻の穴が $N$ 個あり、肺が $1$ 個以上あります。 
しかし、肺がいくつあるか、および、どの鼻の穴とどの肺が繋がっているかが分かっていません。
あなたはエイリアンに関して、以下の仮説を立てました:
それぞれの肺は $1$ 個以上の鼻の穴につながっている
それぞれ鼻の穴は $0$ 個以上の肺につながっている
全ての肺に対して酸素が供給されないと死んでしまう。すなわち、ある肺につながっている全ての鼻の穴を塞がれると、エイリアンは死ぬ
政府はあなたの仮説を検証するために、肺と鼻の穴の接続関係がわかっていないエイリアンを $1$ 匹捕獲し、$2^N$ 匹に複製しました。これらのエイリアンで以下のような実験を行いました:
$i$ 番目 $(i=0, \ldots, 2^N-1)$ のエイリアンに対しては、 $i$ を二進表記した際の $k$ 桁目が $1$ であるような $k$ 番目の鼻の穴を全て塞ぐ ($k = 0, \ldots, N-1$)。
その結果、エイリアンが生きたままか死んだかを記録する。
あなたはこれらの $2^N$ 個の実験の結果を全て与えられました。
実験の結果が仮説に矛盾していないか判定し、矛盾していない場合には
考えられる肺の最小個数を答えてください。
制約
全ての入力は整数である
$2 \leq N \leq 20$
$0 \leq a_i \leq 1$
$a_0 = 0$
$a_{2^N-1} = 1$
入力
入力は標準入力から以下の形式で与えられます。
ただし、$a_i=1$のとき、$i$番目のエイリアンは死亡し、$a_i=0$のとき、$i$番目のエイリアンは生きていることを表します。
$N$
$a_0$
$:$
$a_{2^N-1}$
出力
実験の結果が仮説に矛盾している場合には $-1$、そうでない場合はエイリアンが持つと考えられる肺の最小個数を答えてください。
入出力例
入力例1
2
0
1
0
1
出力例1
1
考えられる肺のつなげ方としては{{1},{1,2}}や{{1}}があり、最小の個数は1個です。
入力例2
3
0
1
1
1
1
0
0
1
出力例2
-1
2番目の鼻の穴だけを塞いでも3番目の鼻の穴だけを塞いでも死ぬが、両方の穴を塞いだエイリアンは生きているため、仮説に矛盾しています。

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;cin >> n;
  vi a(1 << n);cin >> a;
  bool is = true;
  int res = 0;
  rep(bit,0,1 << n){
    if(a[bit]){
      int C = 0;
      rep(i,0,n){
        if(!(bit >> i & 1) && !a[bit|(1 << i)])is = false;
        if(bit >> i & 1)C += (!a[bit-(1 << i)]);
      }
      if(C == __builtin_popcount(bit))res++;
    }else{
      rep(i,0,n)if((bit >> i & 1) && a[bit-(1 << i)])is = false;
    }
  }
  if(!is)res = -1;
  cout << res << endl;
  

  return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 11312
final_rank: 14

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

int main()
{
	int N;
	cin >> N;
	vector<int> f(1 << N);
	for (int i = 0; i < (1 << N); i++) {
		cin >> f[i];
	}
	auto dp = f;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < (1 << N); j++) if (j & (1 << i)) {
			dp[j] += dp[j - (1 << i)];
		}
	}
	for (int i = 0; i < (1 << N); i++) if (f[i] == 0 && dp[i] > 0) {
		puts("-1");
		return 0;
	}
	int res = 0;
	for (int i = 0; i < (1 << N); i++) {
		res += dp[i] == 1;
	}
	cout << res << endl;
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 11420
final_rank: 17

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

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

    int N;
    cin >> N;
    vector<int> A(1 << N);
    for (int i = 0; i < (1 << N); i++) {
        cin >> A[i];
    }

    int ans = 0;
    for (int i = 0; i < (1 << N); i++) {
        bool alive = true;
        for (int j = 0; j < N; j++) {
            if (!(i & (1 << j)))
                continue;

            int c = i ^ (1 << j);
            // ng
            if (A[i] == 0 && A[c] == 1) {
                cout << "-1\n";
                return 0;
            }

            // dead
            if (A[c] == 1) {
                alive = false;
            }
        }

        ans += (A[i] == 1 && alive);
    }

    cout << ans << "\n";

    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 7528
final_rank: 5

code_snippet: // AOJ #2981 Nose And Lung
// 2025.2.15

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

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

    int N; 
    cin >> N;
    int total = 1 << N;
    vector<int> f(total);
    for (int i = 0; i < total; i++) cin >> f[i];
    
    for (int mask = 0; mask < total; mask++){
        for (int bit = 0; bit < N; bit++){
            if (!(mask & (1 << bit))){
                int sup = mask | (1 << bit);
                if(f[mask] > f[sup]){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    int lungCnt = 0;
    for (int mask = 1; mask < total; mask++){
        if(f[mask] == 1){
            bool minimal = true;
            for (int bit = 0; bit < N; bit++){
                if(mask & (1 << bit)){
                    int sub = mask & ~(1 << bit);
                    if(f[sub] == 1){
                        minimal = false;
                        break;
                    }
                }
            }
            if(minimal) lungCnt++;
        }
    }
    cout << lungCnt << endl;
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 7260
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	int N; cin >> N;
	int M = 1<<N;
	vector<int> A(M);
	for(int i=0; i<M; i++) cin >> A[i];

	auto B = A;
	int ans = 0;
	bool flag = true;
	for(int i=0; i<M; i++){
		if(B[i]) ans++;
		
		if(A[i]){
			for(int j=0; j<N; j++){
				if(!(i>>j&1)){
					if(B[i|1<<j]) B[i|1<<j] = 0;
					if(!A[i|1<<j]) flag = false;
				}
			}
		}
	}

	if(!flag) ans = -1;
	cout << ans << endl;
}
accuracy: 1
time_ms: 110
memory_kb: 11424
final_rank: 18

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

ll Mod = 1000000007;

ll Pow(ll X) {
    if (X == 0) return 1;
    if (X % 2 == 0) {
        ll Y = Pow(X/2);
        return (Y*Y) % Mod;
    }
    return (26*Pow(X-1))%Mod;
}

bool isPalindrome(string S) {
    int N = S.size();
    rep(i,0,N) {
        if (S[i] != S[S.size()-1-i]) return false;
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(1<<N);
    rep(i,0,1<<N) cin >> A[i];
    auto B = A;
    rep(i,0,N) {
        rep(j,0,1<<N) {
            if ((j&(1<<i)) == 0) {
                B[j|(1<<i)] += B[j];
            }
        }
    }
    vector<int> ANS, C(1<<N,0);
    rep(i,0,1<<N) {
        if (A[i] == 1 && B[i] == 1) ANS.push_back(i), C[i] = 1;
    }
    rep(i,0,N) {
        rep(j,0,1<<N) {
            if ((j&(1<<i)) == 0) {
                chmax(C[j|(1<<i)],C[j]);
            }
        }
    }
    if (A == C) cout << ANS.size() << endl;
    else cout << -1 << endl;
}
accuracy: 1
time_ms: 110
memory_kb: 16420
final_rank: 19

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

int main() {
  int N; cin >> N;
  int M = (1<<N);
  vector<int> A(M, 0);
  for (auto &a : A) cin >> a;
  
  vector<int> g(M, 0);
  int cnt = 0;
  bool ng = false;
  
  for (int bit = 0; bit < M; ++bit) {
    if (A[bit] == 0) {
      if (g[bit] == 1) ng = true;
    }
    
    if (A[bit] == 1) {
      if (g[bit] == 0) cnt++;
      
      for (int v = 0; v < N; ++v) {
        int nbit = (bit | (1<<v));
        g[nbit] = 1;
      }
    }
  }
  
  if (ng) cnt = -1;
  cout << cnt << endl;
    
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 11608
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);i++)

int main(){
    int N,an=0,OK=1,P;
    cin>>N;
    vector<int> D(1<<N);
    for(auto &d:D)cin>>d;
    rep(b,1<<N){
        if(D[b]){
            P=1;
            rep(i,N){
                if(b&(1<<i)){
                    if(D[b-(1<<i)])P=0;
                }
                else if(!D[b+(1<<i)])OK=0;
            }
            if(P)an++;
        }
        else rep(i,N)if(b&(1<<i)&&D[b-(1<<i)])OK=0;
    }
    cout<<(OK?an:-1)<<endl;
}
accuracy: 1
time_ms: 120
memory_kb: 7264
final_rank: 16

code_snippet: // competitive-verifier: PROBLEM
#ifdef ATCODER
#pragma GCC target("sse4.2,avx512f,avx512dq,avx512ifma,avx512cd,avx512bw,avx512vl,bmi2")
#endif
#pragma GCC optimize("Ofast,fast-math,unroll-all-loops")
#include <bits/stdc++.h>
#ifndef ATCODER
#pragma GCC target("sse4.2,avx2,bmi2")
#endif
template <class T, class U>
constexpr bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
constexpr bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr double EPS = 1e-7;
constexpr double PI = 3.14159265358979323846;
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(20);
    }
    constexpr void operator()() const {}
} sonic;
using namespace std;
using ll = std::int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) os << (it == v.begin() ? "" : " ") << *it;
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
void Yes(bool is_correct = true) { std::cout << (is_correct ? "Yes\n" : "No\n"); }
void No(bool is_not_correct = true) { Yes(!is_not_correct); }
void YES(bool is_correct = true) { std::cout << (is_correct ? "YES\n" : "NO\n"); }
void NO(bool is_not_correct = true) { YES(!is_not_correct); }
void Takahashi(bool is_correct = true) { std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n'; }
void Aoki(bool is_not_correct = true) { Takahashi(!is_not_correct); }
int main(void) {
    int n;
    cin >> n;
    int m = 1 << n;
    vector<int> a(m);
    cin >> a;
    int ans = 0;
    rep (bit, m) {
        if (a[bit] == 0)
            continue;
        bool f = true;
        rep (i, n) {
            if (bit >> i & 1) {
                if (a[bit ^ (1 << i)] == 1) {
                    f = false;
                }
            }
        }
        ans += f;
    }
    rep (bit, m) {
        if (a[bit] == 0)
            continue;
        rep (i, n) {
            if (~bit >> i & 1) {
                if (a[bit ^ (1 << i)] == 0) {
                    co(-1);
                    return 0;
                }
            }
        }
    }
    co(ans);
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 7212
final_rank: 6

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

template < class T > vector< T >& operator++(vector< T >& a) { for(T& x : a) x++; return a; }
template < class T > vector< T >& operator--(vector< T >& a) { for(T& x : a) x--; return a; }
template < class T > vector< T >  operator++(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x++; return res; }
template < class T > vector< T >  operator--(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x--; return res; }

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

int main() {
    int N = in();
    vector<int> A = in(1 << N);

    vector<int> B = A;
    for(int i : rep(N)) {
        for(int S : rep(1 << N)) {
            if(not(S & (1 << i))) {
                B[S | (1 << i)] += B[S];
            }
        }
    }

    int ans = [&] {
        int sum = 0;
        for(int S : rep(1 << N)) {
            if(A[S] == 1 and B[S] == 1) {
                sum += 1;
            } else if(A[S] == 0 and B[S] > 0) {
                return -1;
            }
        }
        return sum;
    }();
    print(ans);
}
accuracy: 1
time_ms: 50
memory_kb: 11396
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);i++)

int main(){
    int N,an=0,s;
    cin>>N;
    vector<bool> D(1<<N,0);
    rep(i,1<<N){
        cin>>s;
        D[i]=s;
    }
    bool OK=1;
    rep(bit,1<<N){
        if(D[bit]){
            bool P=1;
            rep(i,N){
                if(bit&(1<<i)){
                    if(D[bit-(1<<i)])P=0;
                }
                else if(!D[bit+(1<<i)])OK=0;
            }
            if(P)an++;
        }
        else{
            rep(i,N)if(bit&(1<<i))if(D[bit-(1<<i)])OK=0;
        }
    }
    cout<<(OK?an:-1)<<endl;
}
accuracy: 1
time_ms: 130
memory_kb: 3448
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vll=vector<ll>;
using vvll=vector<vll>;
#define rep(i,n) for(ll i=0;i<ll(n);i++)



int main(){
    ll N;
    cin>>N;
    vector<bool> D(1<<N,0);
    rep(i,1<<N){
        ll s;
        cin>>s;
        D[i]=s;
    }
    bool OK=1;
    ll an=0;
    rep(bit,1<<N){
        if(D[bit]){
            bool P=1;
            rep(i,N){
                if(bit&(1<<i)){
                    if(D[bit-(1<<i)])P=0;
                }
                else if(!D[bit+(1<<i)])OK=0;
            }
            if(P)an++;
        }
        else{
            rep(i,N){
                if(bit&(1<<i)){
                    if(D[bit-(1<<i)])OK=0;
                }
            }
        }
    }
    cout<<(OK?an:-1)<<endl;
}
accuracy: 1
time_ms: 130
memory_kb: 3448
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = (ll)4e18 + 10;;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
    if(x > y) {
        x = y;
        return true;
    } else return false;
}
template<class T> bool chmax(T& x, T y){
    if(x < y) {
        x = y;
        return true;
    } else return false;
}

// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )

#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )

#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)

// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)

// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)

// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = (b) - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = (b) - 1; i >= a; i -= c)

// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = (b) - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = (b) - 1; i >= (ll)(a); i -= c)

// for_earh
#define fore(e, v) for (auto&& e : v)

// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

int N;
int dl[1 << 20];
int sub[1 << 20], sup[1 << 20];
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> N;
    rep (i, 1 << N) {
        cin >> dl[i];
        sub[i] = dl[i];
        sup[i] = 1 - dl[i];
    }

    rep (j, N) {
        rep (i, 1 << N) {
            if (i >> j & 1) {
                sub[i] += sub[i - (1 << j)];
            } else {
                sup[i] += sup[i + (1 << j)];
            }
        }
    }

    int ans = 0;
    bool flag = true;
    rep (i, 1 << N) {
        if (dl[i] == 1) flag &= dl[i] == 1 && sup[i] == 0;
        ans += dl[i] == 1 && sub[i] == 1;
    }
    cout << (flag ? ans : -1) << '\n';
}
accuracy: 1
time_ms: 50
memory_kb: 15752
final_rank: 15

code_snippet: #include <bits/stdc++.h>




namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa


namespace zawa {

void SetFastIO() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
}

void SetPrecision(u32 dig) {
    std::cout << std::fixed << std::setprecision(dig);
}

} // namespace zawa
using namespace zawa;

int main() {
    SetFastIO();

    int n; std::cin >> n;
    std::vector<bool> a((1 << n));
    for (int i{} ; i < (1 << n) ; i++) {
        int v; std::cin >> v;
        a[i] = v;
    }
    std::vector<bool> death{a};
    for (int i{} ; i < n ; i++) {
        for (int bit{} ; bit < (1 << n) ; bit++) {
            if (!death[bit]) continue;
            if (!(bit & (1 << i))) {
                if (a[bit | (1 << i)] == false) {
                    std::cout << -1 << '\n';
                    return 0;
                }
                else {
                    death[bit] = true;
                }
            }
        }
    }
    int ans{};
    for (int bit{} ; bit < (1 << n) ; bit++) if (a[bit]) {
        bool ok{true};
        for (int i{} ; i < n ; i++) if (bit & (1 << i)) {
            ok &= a[bit ^ (1 << i)] == false;
        }
        ans += ok;
    }
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 80
memory_kb: 3492
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int INF = 1e9;

template<class T> pair<vector<T> ,bool> fast_zeta(int N, vector<T> A){
    vector<T> dp(1 << N);
    for(int i = 0; i < (1 << N); i++){
        dp[i] = A[i];
    }
    for(int j = 0; j < N; j++){
        for(int i = 0; i < (1 << N); i++){
            if(i & (1 << j)){
                if(dp[i] == INF && dp[i & ~(1 << j)] != INF){
                    return make_pair(vector<T>(0), false);
                }
                dp[i] = min(dp[i], dp[i & ~(1 << j)]);
            }
        }
    }
    return make_pair(dp, true);
}

int main(){
    int N; cin >> N;
    int M = (1 << N);
    vector<int> A(M);
    for(int i = 0; i < M; i++) cin >> A[i];

    vector<int> B(M, 1e9);
    for(int i = 0; i < M; i++){
        if(A[i] == 1) B[i] = i;
    }

    auto res = fast_zeta(N, B);
    if(res.second == false){
        cout << -1 << endl;
        return 0;
    }

    set<int> st;
    for(auto it : res.first){
        st.insert(it);
    }

    cout << (int)st.size() - 1 << endl;
}
accuracy: 1
time_ms: 200
memory_kb: 23992
final_rank: 20

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int 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;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(1<<n);
    for (int i = 0; i < (1<<n); ++i) {
        cin >> a[i];
    }
    int res = 0;
    for (int i = 0; i < (1<<n); ++i) {
        if (a[i]) {
            bool f = false;
            for (int j = 0; j < n; ++j) {
                if ((1<<j)&i) {
                    if (a[(1<<j)^i]) {
                        f = true;
                    }
                }
                if (!a[(1<<j)|i]) {
                    cout << -1 << endl;
                    return 0;
                }
            }
            if (!f) res++;
        }
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 7232
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define foa(c, v) for (auto &c : v)
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) int(size(v))

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
    os << "{ ";
    foa(c, vec)
    {
        os << c << ", ";
    }
    os << "}";
    return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<vector<T>> &vv)
{
    os << "{ ";
    foa(v, vv)
    {
        os << "\n\t" << v << ", ";
    }
    os << "\n}";
    return os;
}

#ifdef LOCAL
#define debug(x) cerr << __LINE__ << ", " << #x << ": " << x << endl;
#else
#define debug(x) void(0)
#endif

int n;
int solve()
{
    int m = 1 << n;
    vector<int> dead(m);
    foa(c, dead) cin >> c;

    int lungs = 0;

    rep(bits, m)
    {
        bool has_less_dead = false;
        rep(bit_place, n)
        {
            int bit = 1 << bit_place;
            if (bits & bit)
            {
                int less = bits - bit;
                if (dead[less])
                    has_less_dead = true;
            }
            else
            {

                int more = bits | bit;
                if (dead[bits] && !dead[more])
                    return -1;
            }
        }

        if (!has_less_dead && dead[bits])
        {
            lungs++;
        }
    }

    return lungs;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (cin >> n)
        cout << solve() << '\n';
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 7236
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T> bool chmax(T& a, const T& b) { return a < b ? (a = b, 1) : 0; }
template <typename T> bool chmin(T& a, const T& b) { return a > b ? (a = b, 1) : 0; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int N;
    cin >> N;
    vector<int> a(1<<N);
    for (auto& x : a) cin >> x;
    vector<bool> smallest(1<<N, true);
    int ans = 0;
    rep(S,0,1<<N) {
        if (!a[S]) {
            smallest[S] = false;
        } else {
            if (smallest[S]) ++ans;
            rep(i,0,N) {
                if (!(S>>i&1)) {
                    if (!a[S|(1<<i)]) {
                        cout << -1 << endl;
                        return 0;
                    }
                    smallest[S|(1<<i)] = false;
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 7372
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(1 << N);
    for(int& a : A) cin >> a;
    int ans = 0;
    for(int bit = 1; bit < 1 << N; bit++) if(A[bit]){
        if([&]{
            for(int i = 0; i < N; i++){
                if(bit & 1 << i && A[bit ^ 1 << i]) return 0;
            }
            return 1;
        }()) ans++;
        for(int i = 0; i < N; i++){
            if(!A[bit | 1 << i]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 7228
final_rank: 1

code_snippet: #include<cstdio>
#include<vector>
using namespace std;
int n, a[1<<20];


int solve() {
  int ans = 0;
  for (int i = 1; i < (1 << n); i++) {
    if (__builtin_popcount(i) == 1) {
      if (a[i]) ans++;
      continue;
    }
    int tmp = 1;
    for (int j = 0; j < n; j++) if (i & (1 << j)) {
      int B = 1 << j;
      if (a[B]) {
        if (a[i] == 0) return -1;
        tmp = -1;
        continue;
      }
      int A = i xor B;
      if (a[i]) {
        if (a[A]) {
          tmp = -1;
        }
      } else {
        if (a[A]) return -1;
        tmp = -1;
      }
    }
    if (tmp == 1) {
      ans++;
      for (int j = 0; j < n; j++) if (i & (1 << j)) {
        if (a[i xor (1 << j)]) return -1;
      }
    }
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (1 << n); i++) scanf("%d", &a[i]);
  printf("%d\n", solve());
}
accuracy: 1
time_ms: 100
memory_kb: 6852
final_rank: 10