QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630868#9118. Flip or NotmaspyAC ✓1640ms12104kbC++2024.8kb2024-10-11 20:44:582024-10-11 20:44:59

Judging History

你现在查看的是最新测评结果

  • [2024-10-11 20:44:59]
  • 评测
  • 测评结果:AC
  • 用时:1640ms
  • 内存:12104kb
  • [2024-10-11 20:44:58]
  • 提交

answer

#line 1 "/home/maspy/compro/library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else

// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...) \
  vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sm = 0;
  for (auto &&a: A) sm += a;
  return sm;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(len(A));
  iota(all(ids), 0);
  sort(all(ids), [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  vc<T> B(len(I));
  FOR(i, len(I)) B[i] = A[I[i]];
  return B;
}

template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
  vc<T> &res = first;
  (res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "/home/maspy/compro/library/other/io.hpp"
#define FASTIO
#include <unistd.h>

// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
  char num[10000][4];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i][j] = n % 10 | '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
  pil = 0;
  if (pir < SZ) ibuf[pir++] = '\n';
}

inline void flush() {
  fwrite(obuf, 1, por, stdout);
  por = 0;
}

void rd(char &c) {
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
}

void rd(string &x) {
  x.clear();
  char c;
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
  do {
    x += c;
    if (pil == pir) load();
    c = ibuf[pil++];
  } while (!isspace(c));
}

template <typename T>
void rd_real(T &x) {
  string s;
  rd(s);
  x = stod(s);
}

template <typename T>
void rd_integer(T &x) {
  if (pil + 100 > pir) load();
  char c;
  do
    c = ibuf[pil++];
  while (c < '-');
  bool minus = 0;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (c == '-') { minus = 1, c = ibuf[pil++]; }
  }
  x = 0;
  while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (minus) x = -x;
  }
}

void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }

template <class T, class U>
void rd(pair<T, U> &p) {
  return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
  if constexpr (N < std::tuple_size<T>::value) {
    auto &x = std::get<N>(t);
    rd(x);
    rd_tuple<N + 1>(t);
  }
}
template <class... T>
void rd(tuple<T...> &tpl) {
  rd_tuple(tpl);
}

template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
  for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
  for (auto &d: x) rd(d);
}

void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
  rd(h), read(t...);
}

void wt(const char c) {
  if (por == SZ) flush();
  obuf[por++] = c;
}
void wt(const string s) {
  for (char c: s) wt(c);
}
void wt(const char *s) {
  size_t len = strlen(s);
  for (size_t i = 0; i < len; i++) wt(s[i]);
}

template <typename T>
void wt_integer(T x) {
  if (por > SZ - 100) flush();
  if (x < 0) { obuf[por++] = '-', x = -x; }
  int outi;
  for (outi = 96; x >= 10000; outi -= 4) {
    memcpy(out + outi, pre.num[x % 10000], 4);
    x /= 10000;
  }
  if (x >= 1000) {
    memcpy(obuf + por, pre.num[x], 4);
    por += 4;
  } else if (x >= 100) {
    memcpy(obuf + por, pre.num[x] + 1, 3);
    por += 3;
  } else if (x >= 10) {
    int q = (x * 103) >> 10;
    obuf[por] = q | '0';
    obuf[por + 1] = (x - q * 10) | '0';
    por += 2;
  } else
    obuf[por++] = x | '0';
  memcpy(obuf + por, out + outi + 4, 96 - outi);
  por += 96 - outi;
}

template <typename T>
void wt_real(T x) {
  ostringstream oss;
  oss << fixed << setprecision(15) << double(x);
  string s = oss.str();
  wt(s);
}

void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first);
  wt(' ');
  wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;

#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define U32(...)   \
  u32 __VA_ARGS__; \
  read(__VA_ARGS__)
#define U64(...)   \
  u64 __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 2 "/home/maspy/compro/library/ds/my_bitset.hpp"

// https://codeforces.com/contest/914/problem/F
// https://yukicoder.me/problems/no/142
// わずかに普通の bitset より遅いときもあるようだが,
// 固定長にしたくないときや slice 操作が必要なときに使う
struct My_Bitset {
  using T = My_Bitset;
  int N;
  vc<u64> dat;

  // x で埋める
  My_Bitset(int N = 0, int x = 0) : N(N) {
    assert(x == 0 || x == 1);
    u64 v = (x == 0 ? 0 : -1);
    dat.assign((N + 63) >> 6, v);
    if (N) dat.back() >>= (64 * len(dat) - N);
  }

  int size() { return N; }

  void resize(int size) {
    dat.resize((size + 63) >> 6);
    int remainingBits = size & 63;
    if (remainingBits != 0) {
      u64 mask = (u64(1) << remainingBits) - 1;
      dat.back() &= mask;
    }
    N = size;
  }

  // thanks to chatgpt!
  class Proxy {
  public:
    Proxy(vc<u64> &d, int i) : dat(d), index(i) {}
    operator bool() const { return (dat[index >> 6] >> (index & 63)) & 1; }

    Proxy &operator=(u64 value) {
      dat[index >> 6] &= ~(u64(1) << (index & 63));
      dat[index >> 6] |= (value & 1) << (index & 63);
      return *this;
    }
    void flip() {
      dat[index >> 6] ^= (u64(1) << (index & 63)); // XOR to flip the bit
    }

  private:
    vc<u64> &dat;
    int index;
  };

  Proxy operator[](int i) { return Proxy(dat, i); }

  bool operator==(const T &p) {
    assert(N == p.N);
    FOR(i, len(dat)) if (dat[i] != p.dat[i]) return false;
    return true;
  }

  T &operator&=(const T &p) {
    assert(N == p.N);
    FOR(i, len(dat)) dat[i] &= p.dat[i];
    return *this;
  }
  T &operator|=(const T &p) {
    assert(N == p.N);
    FOR(i, len(dat)) dat[i] |= p.dat[i];
    return *this;
  }
  T &operator^=(const T &p) {
    assert(N == p.N);
    FOR(i, len(dat)) dat[i] ^= p.dat[i];
    return *this;
  }
  T operator&(const T &p) const { return T(*this) &= p; }
  T operator|(const T &p) const { return T(*this) |= p; }
  T operator^(const T &p) const { return T(*this) ^= p; }
  T operator~() const {
    T p = (*this);
    p.flip_range(0, N);
    return p;
  }

  int count() {
    int ans = 0;
    for (u64 val: dat) ans += popcnt(val);
    return ans;
  }

  int dot(T &p) {
    assert(N == p.N);
    int ans = 0;
    FOR(i, len(dat)) ans += popcnt(dat[i] & p.dat[i]);
    return ans;
  }

  int dot_mod_2(T &p) {
    assert(N == p.N);
    int ans = 0;
    FOR(i, len(dat)) ans ^= popcnt_mod_2(dat[i] & p.dat[i]);
    return ans;
  }

  int next(int i) {
    chmax(i, 0);
    if (i >= N) return N;
    int k = i >> 6;
    {
      u64 x = dat[k];
      int s = i & 63;
      x = (x >> s) << s;
      if (x) return (k << 6) | lowbit(x);
    }
    FOR(idx, k + 1, len(dat)) {
      if (dat[idx] == 0) continue;
      return (idx << 6) | lowbit(dat[idx]);
    }
    return N;
  }

  int prev(int i) {
    chmin(i, N - 1);
    if (i <= -1) return -1;
    int k = i >> 6;
    if ((i & 63) < 63) {
      u64 x = dat[k];
      x &= (u64(1) << ((i & 63) + 1)) - 1;
      if (x) return (k << 6) | topbit(x);
      --k;
    }
    FOR_R(idx, k + 1) {
      if (dat[idx] == 0) continue;
      return (idx << 6) | topbit(dat[idx]);
    }
    return -1;
  }

  My_Bitset range(int L, int R) {
    assert(L <= R);
    My_Bitset p(R - L);
    int rm = (R - L) & 63;
    FOR(rm) {
      p[R - L - 1] = bool((*this)[R - 1]);
      --R;
    }
    int n = (R - L) >> 6;
    int hi = L & 63;
    int lo = 64 - hi;
    int s = L >> 6;
    if (hi == 0) {
      FOR(i, n) { p.dat[i] ^= dat[s + i]; }
    } else {
      FOR(i, n) { p.dat[i] ^= (dat[s + i] >> hi) ^ (dat[s + i + 1] << lo); }
    }
    return p;
  }

  int count_range(int L, int R) {
    assert(L <= R);
    int cnt = 0;
    while ((L < R) && (L & 63)) cnt += (*this)[L++];
    while ((L < R) && (R & 63)) cnt += (*this)[--R];
    int l = L >> 6, r = R >> 6;
    FOR(i, l, r) cnt += popcnt(dat[i]);
    return cnt;
  }

  // [L,R) に p を代入
  void assign_to_range(int L, int R, My_Bitset &p) {
    assert(p.N == R - L);
    int a = 0, b = p.N;
    while (L < R && (L & 63)) { (*this)[L++] = bool(p[a++]); }
    while (L < R && (R & 63)) { (*this)[--R] = bool(p[--b]); }
    // p[a:b] を [L:R] に
    int l = L >> 6, r = R >> 6;
    int s = a >> 6, t = b >> t;
    int n = r - l;
    if (!(a & 63)) {
      FOR(i, n) dat[l + i] = p.dat[s + i];
    } else {
      int hi = a & 63;
      int lo = 64 - hi;
      FOR(i, n) dat[l + i] = (p.dat[s + i] >> hi) | (p.dat[1 + s + i] << lo);
    }
  }

  // [L,R) に p を xor
  void xor_to_range(int L, int R, My_Bitset &p) {
    assert(p.N == R - L);
    int a = 0, b = p.N;
    while (L < R && (L & 63)) {
      dat[L >> 6] ^= u64(p[a]) << (L & 63);
      ++a, ++L;
    }
    while (L < R && (R & 63)) {
      --b, --R;
      dat[R >> 6] ^= u64(p[b]) << (R & 63);
    }
    // p[a:b] を [L:R] に
    int l = L >> 6, r = R >> 6;
    int s = a >> 6, t = b >> t;
    int n = r - l;
    if (!(a & 63)) {
      FOR(i, n) dat[l + i] ^= p.dat[s + i];
    } else {
      int hi = a & 63;
      int lo = 64 - hi;
      FOR(i, n) dat[l + i] ^= (p.dat[s + i] >> hi) | (p.dat[1 + s + i] << lo);
    }
  }

  // [L,R) に p を and
  void and_to_range(int L, int R, My_Bitset &p) {
    assert(p.N == R - L);
    int a = 0, b = p.N;
    while (L < R && (L & 63)) {
      if (!p[a]) (*this)[L] = 0;
      a++, L++;
    }
    while (L < R && (R & 63)) {
      --b, --R;
      if (!p[b]) (*this)[R] = 0;
    }
    // p[a:b] を [L:R] に
    int l = L >> 6, r = R >> 6;
    int s = a >> 6, t = b >> t;
    int n = r - l;
    if (!(a & 63)) {
      FOR(i, n) dat[l + i] &= p.dat[s + i];
    } else {
      int hi = a & 63;
      int lo = 64 - hi;
      FOR(i, n) dat[l + i] &= (p.dat[s + i] >> hi) | (p.dat[1 + s + i] << lo);
    }
  }

  // [L,R) に p を or
  void or_to_range(int L, int R, My_Bitset &p) {
    assert(p.N == R - L);
    int a = 0, b = p.N;
    while (L < R && (L & 63)) {
      dat[L >> 6] |= u64(p[a]) << (L & 63);
      ++a, ++L;
    }
    while (L < R && (R & 63)) {
      --b, --R;
      dat[R >> 6] |= u64(p[b]) << (R & 63);
    }
    // p[a:b] を [L:R] に
    int l = L >> 6, r = R >> 6;
    int s = a >> 6, t = b >> t;
    int n = r - l;
    if (!(a & 63)) {
      FOR(i, n) dat[l + i] |= p.dat[s + i];
    } else {
      int hi = a & 63;
      int lo = 64 - hi;
      FOR(i, n) dat[l + i] |= (p.dat[s + i] >> hi) | (p.dat[1 + s + i] << lo);
    }
  }

  // [L,R) を 1 に変更
  void set_range(int L, int R) {
    while (L < R && (L & 63)) { set(L++); }
    while (L < R && (R & 63)) { set(--R); }
    FOR(i, L >> 6, R >> 6) dat[i] = u64(-1);
  }

  // [L,R) を 1 に変更
  void reset_range(int L, int R) {
    while (L < R && (L & 63)) { reset(L++); }
    while (L < R && (R & 63)) { reset(--R); }
    FOR(i, L >> 6, R >> 6) dat[i] = u64(0);
  }

  // [L,R) を flip
  void flip_range(int L, int R) {
    while (L < R && (L & 63)) { flip(L++); }
    while (L < R && (R & 63)) { flip(--R); }
    FOR(i, L >> 6, R >> 6) dat[i] ^= u64(-1);
  }

  // bitset に仕様を合わせる
  void set(int i) { (*this)[i] = 1; }
  void reset(int i) { (*this)[i] = 0; }
  void flip(int i) { (*this)[i].flip(); }
  void set() {
    fill(all(dat), u64(-1));
    resize(N);
  }
  void reset() { fill(all(dat), 0); }
  void flip() {
    FOR(i, len(dat) - 1) { dat[i] = u64(-1) ^ dat[i]; }
    int i = len(dat) - 1;
    FOR(k, 64) {
      if (64 * i + k >= size()) break;
      flip(64 * i + k);
    }
  }
  bool any() {
    FOR(i, len(dat)) {
      if (dat[i]) return true;
    }
    return false;
  }

  int _Find_first() { return next(0); }
  int _Find_next(int p) { return next(p + 1); }

  static string TO_STR[256];
  string to_string() const {
    if (TO_STR[0].empty()) precompute();
    string S;
    for (auto &x: dat) { FOR(i, 8) S += TO_STR[(x >> (8 * i) & 255)]; }
    S.resize(N);
    return S;
  }

  static void precompute() {
    FOR(s, 256) {
      string x;
      FOR(i, 8) x += '0' + (s >> i & 1);
      TO_STR[s] = x;
    }
  }
};
string My_Bitset::TO_STR[256];
#line 2 "/home/maspy/compro/library/random/base.hpp"

u64 RNG_64() {
  static uint64_t x_
      = uint64_t(chrono::duration_cast<chrono::nanoseconds>(
                     chrono::high_resolution_clock::now().time_since_epoch())
                     .count())
        * 10150724397891781847ULL;
  x_ ^= x_ << 7;
  return x_ ^= x_ >> 9;
}

u64 RNG(u64 lim) { return RNG_64() % lim; }

ll RNG(ll l, ll r) { return l + RNG_64() % (r - l); }
#line 5 "main.cpp"

/*
A sparse matrix
Find k : T in A^kS + span(b,Ab,...,A^{k-1}b)

T - A^kS in span(A^ib)

LHS: 5000/64
RHS: prefix matrix rank 5000^3/64

判定
三角化されているとすると2乗時間
k が小さいところ:できる

k が大きいところ:
解空間から乱択しておく
*/

using BS = My_Bitset;

void solve() {
  LL(N);
  auto get = [&]() -> BS {
    STR(S);
    BS A(N);
    FOR(i, N) A[i] = (S[i] == '1');
    return A;
  };
  BS S = get(), T = get();
  BS A(N), B(N);
  {
    INT(p);
    FOR(p) {
      INT(i);
      A[i - 1] = 1;
    }
  }
  {
    INT(p);
    FOR(p) {
      INT(i);
      B[i - 1] = 1;
    }
  }
  auto apply = [&](BS x) -> BS {
    bool last = x[N - 1];
    BS nxt(N);
    x.resize(N - 1);
    nxt.assign_to_range(1, N, x);
    nxt[0] = last;
    if (last) nxt ^= A;
    return nxt;
  };
  vc<BS> basis(N, BS(N));
  vc<BS> way(N, BS(N));

  vc<int> pos;
  auto add_basis = [&](int k, BS x) -> bool {
    BS y(N);
    y[k] = 1;
    FOR(i, N) {
      if (!x[i]) continue;
      if (!basis[i][i]) {
        basis[i] = x;
        way[i] = y;
        return 1;
      }
      y = y ^ way[i];
      x = x ^ basis[i];
    }
    return false;
  };
  bool end = 0;
  vc<BS> dual;

  ll LIM = 1'000'000;
  FOR(n, 1, LIM + 1) {
    S = apply(S);
    if (!end) {
      if (!add_basis(n - 1, B)) {
        end = 1;
        // build dual
        vc<int> I;
        FOR(i, N) if (!basis[i][i]) I.eb(i);
        if (len(I) < 10) {
          for (auto& k: I) {
            BS v(N);
            v[k] = 1;
            FOR_R(i, k) {
              if (!basis[i][i]) continue;
              v[i] = basis[i].dot_mod_2(v);
            }
            dual.eb(v);
          }
        } else {
          FOR(10) {
            BS v(N);
            for (auto& i: I) v[i] = RNG(0, 2);
            FOR_R(i, N) {
              if (!basis[i][i]) continue;
              v[i] = basis[i].dot_mod_2(v);
            }
            dual.eb(v);
          }
        }
      }
      B = apply(B);
    }
    // check
    bool ok = [&]() -> bool {
      BS x = T ^ S;
      if (end) {
        for (auto& v: dual) {
          if (v.dot_mod_2(x)) return false;
        }
      }
      FOR(i, N) {
        if (!x[i]) continue;
        if (!basis[i][i]) return false;
        x ^= basis[i];
      }
      return true;
    }();
    if (!ok) continue;
    string ANS(n, '0');
    BS bs(N);
    BS x = T ^ S;
    // SHOW(x.to_string());
    FOR(i, N) if (basis[i][i] && x[i]) x ^= basis[i], bs ^= way[i];
    FOR(i, n) ANS[i] = (i < N && bs[i] ? '1' : '0');
    // SHOW(x.to_string());
    // FOR(i, N) SHOW(basis[i].to_string());
    // FOR(i, N) SHOW(way[i].to_string());

    reverse(all(ANS));
    print(n);
    print(ANS);
    return;
  }
  print(-1);
}

signed main() {
  int T = 1;
  // INT(T);
  FOR(T) solve();
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3908kb

input:

5
00001
00111
3
1 2 3
2
3 5

output:

4
1001

result:

ok output is valid

Test #2:

score: 0
Accepted
time: 68ms
memory: 3760kb

input:

4
0110
1000
2
1 2
4
1 2 3 4

output:

-1

result:

ok output is valid

Test #3:

score: 0
Accepted
time: 0ms
memory: 3900kb

input:

1
0
1
1
1
1
1

output:

1
1

result:

ok output is valid

Test #4:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

8
11110000
10101011
6
2 3 5 6 7 8
3
4 7 8

output:

5
01110

result:

ok output is valid

Test #5:

score: 0
Accepted
time: 76ms
memory: 3660kb

input:

8
00010010
11000111
3
1 4 5
4
2 4 6 8

output:

-1

result:

ok output is valid

Test #6:

score: 0
Accepted
time: 73ms
memory: 3656kb

input:

8
00000111
10110100
6
3 4 5 6 7 8
4
1 3 7 8

output:

-1

result:

ok output is valid

Test #7:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

8
00101100
11100111
3
1 2 6
6
1 3 4 5 7 8

output:

8
10100111

result:

ok output is valid

Test #8:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

9
111001001
100001000
7
1 3 4 5 6 7 8
4
1 3 7 9

output:

2
01

result:

ok output is valid

Test #9:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

8
01100110
00000101
3
4 5 7
5
2 3 6 7 8

output:

13
0000000000000

result:

ok output is valid

Test #10:

score: 0
Accepted
time: 75ms
memory: 3540kb

input:

10
1001011001
0101100100
4
4 5 7 9
4
4 5 7 10

output:

-1

result:

ok output is valid

Test #11:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

7
1000010
1010101
4
3 4 5 6
4
1 2 4 5

output:

5
00110

result:

ok output is valid

Test #12:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

6
101011
101000
1
6
4
2 3 4 6

output:

2
11

result:

ok output is valid

Test #13:

score: 0
Accepted
time: 61ms
memory: 3724kb

input:

3
000
110
2
2 3
2
1 3

output:

-1

result:

ok output is valid

Test #14:

score: 0
Accepted
time: 0ms
memory: 3900kb

input:

19
1100010001111111100
0001101011001010110
10
2 3 4 5 6 7 9 14 15 19
10
3 5 6 8 10 11 12 17 18 19

output:

15
011001011010111

result:

ok output is valid

Test #15:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

7
0111111
0101011
6
2 3 4 5 6 7
4
1 3 5 7

output:

7
0000001

result:

ok output is valid

Test #16:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

17
10010100010100010
10101101101001101
8
3 5 8 9 12 14 15 17
8
1 3 5 8 10 12 14 15

output:

15
000001111100100

result:

ok output is valid

Test #17:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

13
1101000011011
1010001110110
4
3 5 6 13
8
2 3 4 7 8 10 11 13

output:

146
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010

result:

ok output is valid

Test #18:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

15
101011111011111
110110110101110
8
3 6 8 9 11 12 13 15
10
1 4 5 6 7 11 12 13 14 15

output:

13
0000010101111

result:

ok output is valid

Test #19:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

18
000000100100001110
011101100101001001
6
5 6 7 8 10 15
12
1 2 4 5 7 9 10 13 14 15 16 17

output:

13
1011100001110

result:

ok output is valid

Test #20:

score: 0
Accepted
time: 0ms
memory: 3752kb

input:

14
10111010011001
01010010010001
5
4 7 11 12 14
7
3 7 8 9 11 12 14

output:

485
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #21:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

11
00011011101
00100111111
3
2 4 10
7
3 4 5 7 8 10 11

output:

11
00001001101

result:

ok output is valid

Test #22:

score: 0
Accepted
time: 0ms
memory: 3904kb

input:

8
00101000
01010101
4
2 6 7 8
4
1 3 4 6

output:

7
0010110

result:

ok output is valid

Test #23:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

15
100101100001100
001111110110000
10
2 4 5 6 7 8 9 12 14 15
6
3 6 9 10 13 14

output:

12
111010011101

result:

ok output is valid

Test #24:

score: 0
Accepted
time: 424ms
memory: 4628kb

input:

1910
0100011011011000010100001001000111111011010010111110101110001001010100001011001110011000000100011000111011010100011000101111100110011110001111000011100110001011010101011001010001001001011001110100101100010110111100110101110101101010110011100101101000001111100000000011110011100110101000101011000...

output:

-1

result:

ok output is valid

Test #25:

score: 0
Accepted
time: 656ms
memory: 8056kb

input:

4123
1000001000000011111010101100100111001110111010001100010000000111101101101101011101100001110011111011101010011001011010010101100110100101110100101100110110110101000100011110111100111101010110001000110000101110011001111011011101111011100101111101000111011110110011110000111000001011000011111101000...

output:

4122
0011010000011100001001110010000111111010101011000100100111101010010111100010010100010001111100110000011011011000011111001010110000011011001110011101001000001100011011000001001101111100101101100010100101001101011010111001001111100111110000111010110100100000011000100000000010000100101110011010010...

result:

ok output is valid

Test #26:

score: 0
Accepted
time: 825ms
memory: 8732kb

input:

4474
1011011010101101101000001000000111010011100001101010100010100111111100011101001000010010010110000101010011100001010001011111101111110011011000011001101110010111110100111011010100101100001111101111111010000110001010110001111111011000110100101100000111110000110011010010001100110110011100010011100...

output:

4471
1100101001110000010101100100100011000101000000110010110011111111111111000000110001110101100111011110110111101100001100110011100000100000110100111110111011011111111001110101111010010100100100111110100000000011000001011100101100110101100000111100010010111010001011001101101001001000110111101111000...

result:

ok output is valid

Test #27:

score: 0
Accepted
time: 185ms
memory: 5776kb

input:

2514
0010101111011001011010111000011011011000001001110001111100011100100110111110101000000100011011000110010011011100010000110000101001000110000010110011011100001010101011100100011010011111011011100111011111111100011110001000000000110100001000111110111101010100110010000001001101000100101001110111111...

output:

2513
0001010100001010010010011011101010110011010111100010000101010100000111010101001011001111101000100101001011010100101101000101011111110001000101010001110100011101011100000100000101111110111010110101000111010110111011011000110000001001001101110000111110010001000011000010010101100001101111100110001...

result:

ok output is valid

Test #28:

score: 0
Accepted
time: 1026ms
memory: 9824kb

input:

4813
0010010010001011101101000111110101101010100111111010001000001010011010110111000100101100010001110010100101010011111010001111110001110011010010111000111110001011011100111010110101100000101000110001010110111011000101011001000111000001011000000010111011010001101001011010001011100010010011011101101...

output:

4817
0000000010011000110101000011101011011101100110100111011101000111001000000110101111111111000010101011100010101010101110110101111010100001011111110000010100110100000101010101110001011001111100001000110111011111101000000101010111001110111000101100000001111001101110011001100100101001110110110111101...

result:

ok output is valid

Test #29:

score: 0
Accepted
time: 1058ms
memory: 8400kb

input:

4352
0011111100110101100101000100100010000111101010000100001011111110011101011011001001110110001111011101101101010011111011011000101010100011110011010001011100111110111001010010101100111011111101011000101011011100101011010100000011110000010000100001000111101100001101101010000100110100101000111100100...

output:

-1

result:

ok output is valid

Test #30:

score: 0
Accepted
time: 382ms
memory: 6752kb

input:

3281
0010001100110001110100111011111010111010011010100011101101001000011001110010100000000000001110110001110101110001001011110101010110010100100110111010011100100010010101010111011110011000001011100111111110001010011101000001000011111110001001011101010000101101100011000110100011101011001010010011010...

output:

-1

result:

ok output is valid

Test #31:

score: 0
Accepted
time: 366ms
memory: 7024kb

input:

3520
1101100010110110001010100100011100001100001100010100101111111000010100011001110010110110001000101110011101001100010110001001101000101101110110010011100100001011011011111011000000100111111110111110111111110100001001011101111010100101100110011010001001001001101100011010000110101100111101111111010...

output:

-1

result:

ok output is valid

Test #32:

score: 0
Accepted
time: 547ms
memory: 6496kb

input:

3051
1011110101011100000100011100010100000011110001010011011011001111100101001000111101110011111000000001101010000100010100000110000011111101010000010111001011000001111111000010001100100011011011001111000010010010100100001110010000000111111001010000010011011111000010101101011110011001101101001110010...

output:

-1

result:

ok output is valid

Test #33:

score: 0
Accepted
time: 280ms
memory: 3648kb

input:

226
1001011011001011001110011000001000001101110110101110001111100011100001101011111100011011000110001100000000110010110100111101110101001001010001110010101101101100101000101010100010001100101100111111010100111010010010010111011001
011100010011011111111011001101001110101010001011111101000100010010001...

output:

-1

result:

ok output is valid

Test #34:

score: 0
Accepted
time: 58ms
memory: 6880kb

input:

3346
1010101010011101100001001100100101101000110010100010110100011001100100101111100011000111111101010011010100000011101110010111110111011011011001100001001000011001001001010001010001111110100100010100001011010011011001101000001110101010100100011100110011111100110010010100101110011010011000101000100...

output:

40284
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #35:

score: 0
Accepted
time: 223ms
memory: 7416kb

input:

3512
1111001111010100101010010010001101000010110111001110010101001110010011111001010100111110100001001011100011011000111010000010111011111001101100101010010111000000001101011000101100101110000010101110000011111110001000110011001111111000110001100111101001011010001001000101001101110011011010111111110...

output:

107254
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #36:

score: 0
Accepted
time: 155ms
memory: 5252kb

input:

1229
0001101010000100011110001101000010111101111010001100101000101101010010101111110101000100001011100100011011101010101111110001010111100011100000110101011100100100001110101001001000011100000100111011000010101110111111101110111001100001110000100111101000010110001110110110001000110101111011010011110...

output:

554058
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #37:

score: 0
Accepted
time: 280ms
memory: 5764kb

input:

1413
1100001101111110001001101100000001010110110101100111110100010010111101011000111111010011110001111001111001111001101011000000100101001001001010111011011111101110011001110001011000100000101000101100101011100010010110111100110001101011111111111110001001110001010001110110100001010101001101011011001...

output:

828897
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #38:

score: 0
Accepted
time: 265ms
memory: 6128kb

input:

2012
0010011100011101010000000000011110001110011101001001100101111111011011011111111110011000111100101111110011100110011101001111011101010101100110111101000000101100000000110000001000010100111000010001101000010011110010000100100101101000000111000101101111110111001010100000011010010010010110101000001...

output:

772524
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #39:

score: 0
Accepted
time: 1123ms
memory: 10004kb

input:

5000
0010110110110101100000011110100001111011111100010101011001010000101100000111111111101010111111101100110100100001110010111101001011011011100011000101100000101110000100100001001111100000000100010100111000011111101000111101000110011100100100110111111100011011010001011000100000110110000110000001001...

output:

4997
1111011010110101001011111001100000110010101001011101001101010111101101111011110101011101101001111001011110000100001110100111010000001000101010000001010001011010100001000111001110110011011101101100011001100100001101111011011100000111110101111011010111101000100101001101000101001000000110100000111...

result:

ok output is valid

Test #40:

score: 0
Accepted
time: 1129ms
memory: 9968kb

input:

5000
0100011111111000101011101101100110101110010100111100011100011001010011111000110101010110010101101010110000001011101111100010010110010111101111001101011000001010101011010010001101100010001100011001011010001000010011101001001110101011011100011110011110011101011010000000111101011100110001101001001...

output:

5000
1110000000110110110110111010011010000000100000011100111001000001001101111010101010100111110010101110111010101101100101000000000010100110101100110000101001011001010111000100100101000101010010110101000100011110100011110111111001110110101010101111001001001111110111011010110110110101000110010011011...

result:

ok output is valid

Test #41:

score: 0
Accepted
time: 1126ms
memory: 10100kb

input:

5000
1100000110100010110110001010000111110010101001101011001111111100000101000101000001100110010110101110011010100101001000010001111010010001000010011011101010010100011100011110011100101111000101000100000001001111000011011100110000111101111000010001110001111110111011010001011101011011110010001001101...

output:

4999
1010111111010101110110101110100111100101110011000110101011100100111010011001001110111100010011110010110101110100101100100011110111101010000111010101111101100001100000100100111111010000010001011101111011101010000110110010000010011110000011100010001011000111110000000111111101111111001001110100000...

result:

ok output is valid

Test #42:

score: 0
Accepted
time: 1124ms
memory: 10008kb

input:

5000
0011000100010111001100001101111101001111010110001000100011101110000111101000100011000001101111111100010011011111001111011001001010010100110010001010010010100010110101111011110011010111110101101010100111010011111000011110101010011101111111111110101010011100011100111001001010001110011000011000110...

output:

4998
0111010011100011000111001110110001010001001111110010011100010000101110000110110000111111001101010001011101101111010111111111011111001101100100110010110000011000010110011001101011111001110001111101000001101100001001001000100000101001001000110101010010100100111101011001000110111001011110001111100...

result:

ok output is valid

Test #43:

score: 0
Accepted
time: 1136ms
memory: 9952kb

input:

5000
1110101110110100110111100110101010100001001101111000100111111000010101011110011000010101010001001011000111100111111101000110000011110110100111000100101110110010110000101100111001110101111110101000101111001001100001000100100111010010011100001001101010110011000000101111011011001000100111100101100...

output:

4997
0010101101100101010110101000111010011011101101001110010001010101010100010101101101101100000001011101011011111001101111000110110001101101101100101011100011100100110110000100010101001000101001100010010000001100010101011011100011100100001001100011111000000111101010001111001100000000011011011111001...

result:

ok output is valid

Test #44:

score: 0
Accepted
time: 1477ms
memory: 9908kb

input:

5000
0001110110001011011100000001000110001111000010010001000000110000110101000011000000001100111000110110000001100000000001001110101110001000111001111110010101001000101011011001011001111000101000100000100101000000000111011000110101000000101101011111100000001000111101001100010111110110101001000101010...

output:

-1

result:

ok output is valid

Test #45:

score: 0
Accepted
time: 1470ms
memory: 11952kb

input:

5000
1111001110111001001111010000111101100011101100001010111000001101100000001100100011110110000010110101111010101111011010000110110001101011110111011110001100011111100001101010101100100110111110011101101011101101101111010101101111111011001101010110110010011001001100000111100110001000001101000011000...

output:

1000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #46:

score: 0
Accepted
time: 480ms
memory: 10204kb

input:

5000
1011010010010111011110001100101001110111000111010111010011001001001101010101001100110111011110010111011111111100110000011110101100011110101001101011000011111001011011101100001011100111110010011010101101001110011110111100011101110110000000100111000011100011110000000010011111101111000011010010101...

output:

-1

result:

ok output is valid

Test #47:

score: 0
Accepted
time: 1605ms
memory: 12104kb

input:

5000
0000101100001110000110000110000110010100111111011010110110110101000100100000010001100110001110100111011111010111010011010100011101101001000011001110010100000000000001110110001110101110001001011110101010110010100100110111010011100100010010101010111011110011000001011100111111110001010011101000001...

output:

1000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #48:

score: 0
Accepted
time: 591ms
memory: 12024kb

input:

5000
1001101111001100101001110100011110111011100101100011101000011000100110000001100010011110111111001010110111000001000010110111000001101111100110111001110110101100100111000110110011010001001110000100100010111111010001000010010110011011001110011101100010010100111001101001110000010001011110001011011...

output:

999999
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #49:

score: 0
Accepted
time: 793ms
memory: 8496kb

input:

4393
1001111101111001101101011101010111000101000000000001101010101010001101000011111111100111011101000010100111111101101110011110101001010000010101100100111110000000111001101111110000011101000100101111100100111101000111111111000101001001001001001001111010010000100001010100010011010110001001110101101...

output:

4724
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #50:

score: 0
Accepted
time: 968ms
memory: 9416kb

input:

4710
1001110101100001110110101111110111000001000110011100010010000111000110011111111110110110100000000100001010100110100100000101001111110110111101001011011000111110001111000101001111010111011010110110111000100011110010000011001110111110111000011000101100111111111101000110001001011110001011001010000...

output:

5807
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #51:

score: 0
Accepted
time: 937ms
memory: 9176kb

input:

4655
1010111101111011010100000110010010111001101000010100010001000100001000001001101001110010011001100111011000011001011100011010001100101110000010000011110111100110110001100110010000000110001111001011000011101100010011011111010000001100101111011011001101010001111000100101101010010000101101100001010...

output:

4652
0000000000101110111111110001111100000000110100100110111101011001000000000010000101111011010011011111011110000101110110111110000110000010110110110000010100001010000110001000000001010010000111000101001110111001011001101011100010110101000110100100011010000010001100001101111000110110010000111010111...

result:

ok output is valid

Test #52:

score: 0
Accepted
time: 805ms
memory: 8580kb

input:

4400
1010110111000011001010010011000011011101000001010000000011011011111001001100000110111011001011001011110011010110001110011111001100111110100111111011101010101100100101100000001100101001000110010011010010000111100000001101000010010010110001100000000110011001101000101111101111111001011100011011010...

output:

8604
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #53:

score: 0
Accepted
time: 921ms
memory: 9180kb

input:

4630
1001010101000111111001101000011111011011011000101110110110100010101001010101000010111011001011001010011110011111011011000011100001111010100111101000011101001111110011010000010111100001110100001000100001000000111010001000010101110101011000001010110101101010010101101001100011011000111000101011111...

output:

5004
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #54:

score: 0
Accepted
time: 1630ms
memory: 12060kb

input:

5000
1111011000010110001111110011111001110011110101110111101001110111010010101110101010111010110110111101101011000011110111111001010001100111011010100001110010100110000101110100000001110110011101001011000010000000011110010010111110011001010010001010001110011011111100010000001010001111010100110101110...

output:

999999
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #55:

score: 0
Accepted
time: 1615ms
memory: 12000kb

input:

5000
0000010010000111001100111011101110110101101010011110110111111101111111011111001000100101101001110101111111011010101111100010011101001011111101111001000111110100000001010010011010011000001001011111011100000110000001111011001110101101011000001010000010000100111100110000001010101111111100001111010...

output:

1000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #56:

score: 0
Accepted
time: 1627ms
memory: 12032kb

input:

5000
0000100110010100101001010000000001101101100100101100000111101111010011100000110000010101011001010000110110000011100000000111010111011011101010011111010101011111110000000001001010100001110000110001110000110111001110000011011111100000000000011110111001111101111110100100001001111001011011010010111...

output:

1000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #57:

score: 0
Accepted
time: 1640ms
memory: 10008kb

input:

5000
0111010101110101010100011011111111111101001110101011000000011100011110001100001100101101111101011101110001000100110011001101100000010111111000010010110100011111101000010001000010100011111100010010001101110111010000111111011001100000000010101101111100100100010101100111111011000001010011000011110...

output:

-1

result:

ok output is valid

Test #58:

score: 0
Accepted
time: 1615ms
memory: 12100kb

input:

5000
0000010001101010111111001011011011010010101111100101011101000011000011110000011100110000111010101110100100001111010110001000010011101001010110111010101001111111001001000110100011101110000111001100011010111100011001101110001111010110110011010100001101100010001110110110010000101110010001110011101...

output:

1000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Extra Test:

score: 0
Extra Test Passed