Problem p03174 (C++)

Buggy submission (status: Runtime Error):
// People only find me interesting because they can't tell whether I'm serious
// or not #include <boost/multiprecision/cpp_int.hpp>
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
typedef __int128 s128;
typedef __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define P 1000000007
#define Q 1000000006
#define sz(a) (ll) a.size()
#define lt(a) (ll) a.length()
#define pll pair<ll, ll>
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define bac(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define mll map<ll, ll>
#define umll unordered_map<ll, ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define teevra_gati                                                            \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define N 100005
#define PI 3.14159265359
#define inf LLONG_MAX
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
ll dp[22][(1 << 22)];
vl adj[22];
void solve() {
  f(i, 0, (1 << 22)) {
    ll p = __builtin_popcount(i);
    adj[p].pb(i);
  }

  ll n;
  cin >> n;
  ll a[n + 1][n + 1];
  f(i, 1, n + 1) {
    f(j, 1, n + 1) { cin >> a[i][j]; }
  }
  dp[0][0] = 1;

  f(i, 1, n + 1) {
    for (auto u : adj[i]) {
      f(j, 1, n + 1) {
        if (a[i][j] && (u & (1 << j))) {
          ll s = ~(1 << j);
          s &= u;
          (dp[i][u] += dp[i - 1][s]) %= P;
        }
      }
    }
  }

  cout << dp[n][(1 << (n + 1)) - 2];
}
signed main() {
  teevra_gati
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  solve();

  return 0;
}

Fixed submission:
// People only find me interesting because they can't tell whether I'm serious
// or not #include <boost/multiprecision/cpp_int.hpp>
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
typedef __int128 s128;
typedef __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define P 1000000007
#define Q 1000000006
#define sz(a) (ll) a.size()
#define lt(a) (ll) a.length()
#define pll pair<ll, ll>
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define bac(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define mll map<ll, ll>
#define umll unordered_map<ll, ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define teevra_gati                                                            \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define N 100005
#define PI 3.14159265359
#define inf LLONG_MAX
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
ll dp[22][(1 << 22)];
vl adj[22];
void solve() {
  f(i, 0, (1 << 22)) {
    ll p = __builtin_popcount(i);
    adj[p].pb(i);
  }

  ll n;
  cin >> n;
  ll a[n + 1][n + 1];
  f(i, 1, n + 1) {
    f(j, 1, n + 1) { cin >> a[i][j]; }
  }
  dp[0][0] = 1;

  f(i, 1, n + 1) {
    for (auto u : adj[i]) {
      f(j, 1, n + 1) {
        if (a[i][j] && (u & (1 << j))) {
          ll s = ~(1 << j);
          s &= u;
          (dp[i][u] += dp[i - 1][s]) %= P;
        }
      }
    }
  }

  cout << dp[n][(1 << (n + 1)) - 2];
}
signed main() {
  teevra_gati

  solve();

  return 0;
}