QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#767672#3542. Very Simple SummaspyAC ✓53ms8372kbC++2332.7kb2024-11-20 21:40:442024-11-20 21:40:46

Judging History

This is the latest submission verdict.

  • [2024-11-20 21:40:46]
  • Judged
  • Verdict: AC
  • Time: 53ms
  • Memory: 8372kb
  • [2024-11-20 21:40:44]
  • Submitted

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 u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
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_sgn(int x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(ll x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u64 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
// (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 kth_bit(int k) {
  return T(1) << k;
}
template <typename T>
bool has_kth_bit(T x, int k) {
  return x >> k & 1;
}

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 3 "main.cpp"

#line 2 "/home/maspy/compro/library/mod/modint_common.hpp"

struct has_mod_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.get_mod(), std::true_type{});
  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_mod : public decltype(has_mod_impl::check<T>(std::declval<T>())) {};

template <typename mint>
mint inv(int n) {
  static const int mod = mint::get_mod();
  static vector<mint> dat = {0, 1};
  assert(0 <= n);
  if (n >= mod) n %= mod;
  while (len(dat) <= n) {
    int k = len(dat);
    int q = (mod + k - 1) / k;
    dat.eb(dat[k * q - mod] * mint::raw(q));
  }
  return dat[n];
}

template <typename mint>
mint fact(int n) {
  static const int mod = mint::get_mod();
  assert(0 <= n && n < mod);
  static vector<mint> dat = {1, 1};
  while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * mint::raw(len(dat)));
  return dat[n];
}

template <typename mint>
mint fact_inv(int n) {
  static vector<mint> dat = {1, 1};
  if (n < 0) return mint(0);
  while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * inv<mint>(len(dat)));
  return dat[n];
}

template <class mint, class... Ts>
mint fact_invs(Ts... xs) {
  return (mint(1) * ... * fact_inv<mint>(xs));
}

template <typename mint, class Head, class... Tail>
mint multinomial(Head &&head, Tail &&... tail) {
  return fact<mint>(head) * fact_invs<mint>(std::forward<Tail>(tail)...);
}

template <typename mint>
mint C_dense(int n, int k) {
  assert(n >= 0);
  if (k < 0 || n < k) return 0;
  static vvc<mint> C;
  static int H = 0, W = 0;
  auto calc = [&](int i, int j) -> mint {
    if (i == 0) return (j == 0 ? mint(1) : mint(0));
    return C[i - 1][j] + (j ? C[i - 1][j - 1] : 0);
  };
  if (W <= k) {
    FOR(i, H) {
      C[i].resize(k + 1);
      FOR(j, W, k + 1) { C[i][j] = calc(i, j); }
    }
    W = k + 1;
  }
  if (H <= n) {
    C.resize(n + 1);
    FOR(i, H, n + 1) {
      C[i].resize(W);
      FOR(j, W) { C[i][j] = calc(i, j); }
    }
    H = n + 1;
  }
  return C[n][k];
}

template <typename mint, bool large = false, bool dense = false>
mint C(ll n, ll k) {
  assert(n >= 0);
  if (k < 0 || n < k) return 0;
  if constexpr (dense) return C_dense<mint>(n, k);
  if constexpr (!large) return multinomial<mint>(n, k, n - k);
  k = min(k, n - k);
  mint x(1);
  FOR(i, k) x *= mint(n - i);
  return x * fact_inv<mint>(k);
}

template <typename mint, bool large = false>
mint C_inv(ll n, ll k) {
  assert(n >= 0);
  assert(0 <= k && k <= n);
  if (!large) return fact_inv<mint>(n) * fact<mint>(k) * fact<mint>(n - k);
  return mint(1) / C<mint, 1>(n, k);
}

// [x^d](1-x)^{-n}
template <typename mint, bool large = false, bool dense = false>
mint C_negative(ll n, ll d) {
  assert(n >= 0);
  if (d < 0) return mint(0);
  if (n == 0) { return (d == 0 ? mint(1) : mint(0)); }
  return C<mint, large, dense>(n + d - 1, d);
}
#line 3 "/home/maspy/compro/library/mod/modint.hpp"

template <int mod>
struct modint {
  static constexpr u32 umod = u32(mod);
  static_assert(umod < u32(1) << 31);
  u32 val;

  static modint raw(u32 v) {
    modint x;
    x.val = v;
    return x;
  }
  constexpr modint() : val(0) {}
  constexpr modint(u32 x) : val(x % umod) {}
  constexpr modint(u64 x) : val(x % umod) {}
  constexpr modint(u128 x) : val(x % umod) {}
  constexpr modint(int x) : val((x %= mod) < 0 ? x + mod : x){};
  constexpr modint(ll x) : val((x %= mod) < 0 ? x + mod : x){};
  constexpr modint(i128 x) : val((x %= mod) < 0 ? x + mod : x){};
  bool operator<(const modint &other) const { return val < other.val; }
  modint &operator+=(const modint &p) {
    if ((val += p.val) >= umod) val -= umod;
    return *this;
  }
  modint &operator-=(const modint &p) {
    if ((val += umod - p.val) >= umod) val -= umod;
    return *this;
  }
  modint &operator*=(const modint &p) {
    val = u64(val) * p.val % umod;
    return *this;
  }
  modint &operator/=(const modint &p) {
    *this *= p.inverse();
    return *this;
  }
  modint operator-() const { return modint::raw(val ? mod - val : u32(0)); }
  modint operator+(const modint &p) const { return modint(*this) += p; }
  modint operator-(const modint &p) const { return modint(*this) -= p; }
  modint operator*(const modint &p) const { return modint(*this) *= p; }
  modint operator/(const modint &p) const { return modint(*this) /= p; }
  bool operator==(const modint &p) const { return val == p.val; }
  bool operator!=(const modint &p) const { return val != p.val; }
  modint inverse() const {
    int a = val, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b), swap(u -= t * v, v);
    }
    return modint(u);
  }
  modint pow(ll n) const {
    assert(n >= 0);
    modint ret(1), mul(val);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  static constexpr int get_mod() { return mod; }
  // (n, r), r は 1 の 2^n 乗根
  static constexpr pair<int, int> ntt_info() {
    if (mod == 120586241) return {20, 74066978};
    if (mod == 167772161) return {25, 17};
    if (mod == 469762049) return {26, 30};
    if (mod == 754974721) return {24, 362};
    if (mod == 880803841) return {23, 211};
    if (mod == 943718401) return {22, 663003469};
    if (mod == 998244353) return {23, 31};
    if (mod == 1004535809) return {21, 582313106};
    if (mod == 1012924417) return {21, 368093570};
    return {-1, -1};
  }
  static constexpr bool can_ntt() { return ntt_info().fi != -1; }
};

#ifdef FASTIO
template <int mod>
void rd(modint<mod> &x) {
  fastio::rd(x.val);
  x.val %= mod;
  // assert(0 <= x.val && x.val < mod);
}
template <int mod>
void wt(modint<mod> x) {
  fastio::wt(x.val);
}
#endif

using modint107 = modint<1000000007>;
using modint998 = modint<998244353>;
#line 2 "/home/maspy/compro/library/mod/mod_inv.hpp"

// long でも大丈夫
// (val * x - 1) が mod の倍数になるようにする
// 特に mod=0 なら x=0 が満たす
ll mod_inv(ll val, ll mod) {
  if (mod == 0) return 0;
  mod = abs(mod);
  val %= mod;
  if (val < 0) val += mod;
  ll a = val, b = mod, u = 1, v = 0, t;
  while (b > 0) {
    t = a / b;
    swap(a -= t * b, b), swap(u -= t * v, v);
  }
  if (u < 0) u += mod;
  return u;
}
#line 2 "/home/maspy/compro/library/mod/crt3.hpp"

constexpr u32 mod_pow_constexpr(u64 a, u64 n, u32 mod) {
  a %= mod;
  u64 res = 1;
  FOR(32) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod, n /= 2;
  }
  return res;
}

template <typename T, u32 p0, u32 p1>
T CRT2(u64 a0, u64 a1) {
  static_assert(p0 < p1);
  static constexpr u64 x0_1 = mod_pow_constexpr(p0, p1 - 2, p1);
  u64 c = (a1 - a0 + p1) * x0_1 % p1;
  return a0 + c * p0;
}

template <typename T, u32 p0, u32 p1, u32 p2>
T CRT3(u64 a0, u64 a1, u64 a2) {
  static_assert(p0 < p1 && p1 < p2);
  static constexpr u64 x1 = mod_pow_constexpr(p0, p1 - 2, p1);
  static constexpr u64 x2 = mod_pow_constexpr(u64(p0) * p1 % p2, p2 - 2, p2);
  static constexpr u64 p01 = u64(p0) * p1;
  u64 c = (a1 - a0 + p1) * x1 % p1;
  u64 ans_1 = a0 + c * p0;
  c = (a2 - ans_1 % p2 + p2) * x2 % p2;
  return T(ans_1) + T(c) * T(p01);
}

template <typename T, u32 p0, u32 p1, u32 p2, u32 p3>
T CRT4(u64 a0, u64 a1, u64 a2, u64 a3) {
  static_assert(p0 < p1 && p1 < p2 && p2 < p3);
  static constexpr u64 x1 = mod_pow_constexpr(p0, p1 - 2, p1);
  static constexpr u64 x2 = mod_pow_constexpr(u64(p0) * p1 % p2, p2 - 2, p2);
  static constexpr u64 x3 = mod_pow_constexpr(u64(p0) * p1 % p3 * p2 % p3, p3 - 2, p3);
  static constexpr u64 p01 = u64(p0) * p1;
  u64 c = (a1 - a0 + p1) * x1 % p1;
  u64 ans_1 = a0 + c * p0;
  c = (a2 - ans_1 % p2 + p2) * x2 % p2;
  u128 ans_2 = ans_1 + c * static_cast<u128>(p01);
  c = (a3 - ans_2 % p3 + p3) * x3 % p3;
  return T(ans_2) + T(c) * T(p01) * T(p2);
}

template <typename T, u32 p0, u32 p1, u32 p2, u32 p3, u32 p4>
T CRT5(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4) {
  static_assert(p0 < p1 && p1 < p2 && p2 < p3 && p3 < p4);
  static constexpr u64 x1 = mod_pow_constexpr(p0, p1 - 2, p1);
  static constexpr u64 x2 = mod_pow_constexpr(u64(p0) * p1 % p2, p2 - 2, p2);
  static constexpr u64 x3 = mod_pow_constexpr(u64(p0) * p1 % p3 * p2 % p3, p3 - 2, p3);
  static constexpr u64 x4 = mod_pow_constexpr(u64(p0) * p1 % p4 * p2 % p4 * p3 % p4, p4 - 2, p4);
  static constexpr u64 p01 = u64(p0) * p1;
  static constexpr u64 p23 = u64(p2) * p3;
  u64 c = (a1 - a0 + p1) * x1 % p1;
  u64 ans_1 = a0 + c * p0;
  c = (a2 - ans_1 % p2 + p2) * x2 % p2;
  u128 ans_2 = ans_1 + c * static_cast<u128>(p01);
  c = static_cast<u64>(a3 - ans_2 % p3 + p3) * x3 % p3;
  u128 ans_3 = ans_2 + static_cast<u128>(c * p2) * p01;
  c = static_cast<u64>(a4 - ans_3 % p4 + p4) * x4 % p4;
  return T(ans_3) + T(c) * T(p01) * T(p23);
}
#line 2 "/home/maspy/compro/library/poly/convolution_naive.hpp"

template <class T, typename enable_if<!has_mod<T>::value>::type* = nullptr>
vc<T> convolution_naive(const vc<T>& a, const vc<T>& b) {
  int n = int(a.size()), m = int(b.size());
  if (n > m) return convolution_naive<T>(b, a);
  if (n == 0) return {};
  vector<T> ans(n + m - 1);
  FOR(i, n) FOR(j, m) ans[i + j] += a[i] * b[j];
  return ans;
}

template <class T, typename enable_if<has_mod<T>::value>::type* = nullptr>
vc<T> convolution_naive(const vc<T>& a, const vc<T>& b) {
  int n = int(a.size()), m = int(b.size());
  if (n > m) return convolution_naive<T>(b, a);
  if (n == 0) return {};
  vc<T> ans(n + m - 1);
  if (n <= 16 && (T::get_mod() < (1 << 30))) {
    for (int k = 0; k < n + m - 1; ++k) {
      int s = max(0, k - m + 1);
      int t = min(n, k + 1);
      u64 sm = 0;
      for (int i = s; i < t; ++i) { sm += u64(a[i].val) * (b[k - i].val); }
      ans[k] = sm;
    }
  } else {
    for (int k = 0; k < n + m - 1; ++k) {
      int s = max(0, k - m + 1);
      int t = min(n, k + 1);
      u128 sm = 0;
      for (int i = s; i < t; ++i) { sm += u64(a[i].val) * (b[k - i].val); }
      ans[k] = T::raw(sm % T::get_mod());
    }
  }
  return ans;
}
#line 2 "/home/maspy/compro/library/poly/convolution_karatsuba.hpp"

// 任意の環でできる
template <typename T>
vc<T> convolution_karatsuba(const vc<T>& f, const vc<T>& g) {
  const int thresh = 30;
  if (min(len(f), len(g)) <= thresh) return convolution_naive(f, g);
  int n = max(len(f), len(g));
  int m = ceil(n, 2);
  vc<T> f1, f2, g1, g2;
  if (len(f) < m) f1 = f;
  if (len(f) >= m) f1 = {f.begin(), f.begin() + m};
  if (len(f) >= m) f2 = {f.begin() + m, f.end()};
  if (len(g) < m) g1 = g;
  if (len(g) >= m) g1 = {g.begin(), g.begin() + m};
  if (len(g) >= m) g2 = {g.begin() + m, g.end()};
  vc<T> a = convolution_karatsuba(f1, g1);
  vc<T> b = convolution_karatsuba(f2, g2);
  FOR(i, len(f2)) f1[i] += f2[i];
  FOR(i, len(g2)) g1[i] += g2[i];
  vc<T> c = convolution_karatsuba(f1, g1);
  vc<T> F(len(f) + len(g) - 1);
  assert(2 * m + len(b) <= len(F));
  FOR(i, len(a)) F[i] += a[i], c[i] -= a[i];
  FOR(i, len(b)) F[2 * m + i] += b[i], c[i] -= b[i];
  if (c.back() == T(0)) c.pop_back();
  FOR(i, len(c)) if (c[i] != T(0)) F[m + i] += c[i];
  return F;
}
#line 2 "/home/maspy/compro/library/poly/ntt.hpp"

template <class mint>
void ntt(vector<mint>& a, bool inverse) {
  assert(mint::can_ntt());
  const int rank2 = mint::ntt_info().fi;
  const int mod = mint::get_mod();
  static array<mint, 30> root, iroot;
  static array<mint, 30> rate2, irate2;
  static array<mint, 30> rate3, irate3;

  assert(rank2 != -1 && len(a) <= (1 << max(0, rank2)));

  static bool prepared = 0;
  if (!prepared) {
    prepared = 1;
    root[rank2] = mint::ntt_info().se;
    iroot[rank2] = mint(1) / root[rank2];
    FOR_R(i, rank2) {
      root[i] = root[i + 1] * root[i + 1];
      iroot[i] = iroot[i + 1] * iroot[i + 1];
    }
    mint prod = 1, iprod = 1;
    for (int i = 0; i <= rank2 - 2; i++) {
      rate2[i] = root[i + 2] * prod;
      irate2[i] = iroot[i + 2] * iprod;
      prod *= iroot[i + 2];
      iprod *= root[i + 2];
    }
    prod = 1, iprod = 1;
    for (int i = 0; i <= rank2 - 3; i++) {
      rate3[i] = root[i + 3] * prod;
      irate3[i] = iroot[i + 3] * iprod;
      prod *= iroot[i + 3];
      iprod *= root[i + 3];
    }
  }

  int n = int(a.size());
  int h = topbit(n);
  assert(n == 1 << h);
  if (!inverse) {
    int len = 0;
    while (len < h) {
      if (h - len == 1) {
        int p = 1 << (h - len - 1);
        mint rot = 1;
        FOR(s, 1 << len) {
          int offset = s << (h - len);
          FOR(i, p) {
            auto l = a[i + offset];
            auto r = a[i + offset + p] * rot;
            a[i + offset] = l + r;
            a[i + offset + p] = l - r;
          }
          rot *= rate2[topbit(~s & -~s)];
        }
        len++;
      } else {
        int p = 1 << (h - len - 2);
        mint rot = 1, imag = root[2];
        for (int s = 0; s < (1 << len); s++) {
          mint rot2 = rot * rot;
          mint rot3 = rot2 * rot;
          int offset = s << (h - len);
          for (int i = 0; i < p; i++) {
            u64 mod2 = u64(mod) * mod;
            u64 a0 = a[i + offset].val;
            u64 a1 = u64(a[i + offset + p].val) * rot.val;
            u64 a2 = u64(a[i + offset + 2 * p].val) * rot2.val;
            u64 a3 = u64(a[i + offset + 3 * p].val) * rot3.val;
            u64 a1na3imag = (a1 + mod2 - a3) % mod * imag.val;
            u64 na2 = mod2 - a2;
            a[i + offset] = a0 + a2 + a1 + a3;
            a[i + offset + 1 * p] = a0 + a2 + (2 * mod2 - (a1 + a3));
            a[i + offset + 2 * p] = a0 + na2 + a1na3imag;
            a[i + offset + 3 * p] = a0 + na2 + (mod2 - a1na3imag);
          }
          rot *= rate3[topbit(~s & -~s)];
        }
        len += 2;
      }
    }
  } else {
    mint coef = mint(1) / mint(len(a));
    FOR(i, len(a)) a[i] *= coef;
    int len = h;
    while (len) {
      if (len == 1) {
        int p = 1 << (h - len);
        mint irot = 1;
        FOR(s, 1 << (len - 1)) {
          int offset = s << (h - len + 1);
          FOR(i, p) {
            u64 l = a[i + offset].val;
            u64 r = a[i + offset + p].val;
            a[i + offset] = l + r;
            a[i + offset + p] = (mod + l - r) * irot.val;
          }
          irot *= irate2[topbit(~s & -~s)];
        }
        len--;
      } else {
        int p = 1 << (h - len);
        mint irot = 1, iimag = iroot[2];
        FOR(s, (1 << (len - 2))) {
          mint irot2 = irot * irot;
          mint irot3 = irot2 * irot;
          int offset = s << (h - len + 2);
          for (int i = 0; i < p; i++) {
            u64 a0 = a[i + offset + 0 * p].val;
            u64 a1 = a[i + offset + 1 * p].val;
            u64 a2 = a[i + offset + 2 * p].val;
            u64 a3 = a[i + offset + 3 * p].val;
            u64 x = (mod + a2 - a3) * iimag.val % mod;
            a[i + offset] = a0 + a1 + a2 + a3;
            a[i + offset + 1 * p] = (a0 + mod - a1 + x) * irot.val;
            a[i + offset + 2 * p] = (a0 + a1 + 2 * mod - a2 - a3) * irot2.val;
            a[i + offset + 3 * p] = (a0 + 2 * mod - a1 - x) * irot3.val;
          }
          irot *= irate3[topbit(~s & -~s)];
        }
        len -= 2;
      }
    }
  }
}
#line 8 "/home/maspy/compro/library/poly/convolution.hpp"

template <class mint>
vector<mint> convolution_ntt(vector<mint> a, vector<mint> b) {
  if (a.empty() || b.empty()) return {};
  int n = int(a.size()), m = int(b.size());
  int sz = 1;
  while (sz < n + m - 1) sz *= 2;

  // sz = 2^k のときの高速化。分割統治的なやつで損しまくるので。
  if ((n + m - 3) <= sz / 2) {
    auto a_last = a.back(), b_last = b.back();
    a.pop_back(), b.pop_back();
    auto c = convolution(a, b);
    c.resize(n + m - 1);
    c[n + m - 2] = a_last * b_last;
    FOR(i, len(a)) c[i + len(b)] += a[i] * b_last;
    FOR(i, len(b)) c[i + len(a)] += b[i] * a_last;
    return c;
  }

  a.resize(sz), b.resize(sz);
  bool same = a == b;
  ntt(a, 0);
  if (same) {
    b = a;
  } else {
    ntt(b, 0);
  }
  FOR(i, sz) a[i] *= b[i];
  ntt(a, 1);
  a.resize(n + m - 1);
  return a;
}

template <typename mint>
vector<mint> convolution_garner(const vector<mint>& a, const vector<mint>& b) {
  int n = len(a), m = len(b);
  if (!n || !m) return {};
  static constexpr int p0 = 167772161;
  static constexpr int p1 = 469762049;
  static constexpr int p2 = 754974721;
  using mint0 = modint<p0>;
  using mint1 = modint<p1>;
  using mint2 = modint<p2>;
  vc<mint0> a0(n), b0(m);
  vc<mint1> a1(n), b1(m);
  vc<mint2> a2(n), b2(m);
  FOR(i, n) a0[i] = a[i].val, a1[i] = a[i].val, a2[i] = a[i].val;
  FOR(i, m) b0[i] = b[i].val, b1[i] = b[i].val, b2[i] = b[i].val;
  auto c0 = convolution_ntt<mint0>(a0, b0);
  auto c1 = convolution_ntt<mint1>(a1, b1);
  auto c2 = convolution_ntt<mint2>(a2, b2);
  vc<mint> c(len(c0));
  FOR(i, n + m - 1) { c[i] = CRT3<mint, p0, p1, p2>(c0[i].val, c1[i].val, c2[i].val); }
  return c;
}

vector<ll> convolution(vector<ll> a, vector<ll> b) {
  int n = len(a), m = len(b);
  if (!n || !m) return {};
  if (min(n, m) <= 2500) return convolution_naive(a, b);

  ll mi_a = MIN(a), mi_b = MIN(b);
  for (auto& x: a) x -= mi_a;
  for (auto& x: b) x -= mi_b;
  assert(MAX(a) * MAX(b) <= 1e18);

  auto Ac = cumsum<ll>(a), Bc = cumsum<ll>(b);
  vi res(n + m - 1);
  for (int k = 0; k < n + m - 1; ++k) {
    int s = max(0, k - m + 1);
    int t = min(n, k + 1);
    res[k] += (t - s) * mi_a * mi_b;
    res[k] += mi_a * (Bc[k - s + 1] - Bc[k - t + 1]);
    res[k] += mi_b * (Ac[t] - Ac[s]);
  }

  static constexpr u32 MOD1 = 1004535809;
  static constexpr u32 MOD2 = 1012924417;
  using mint1 = modint<MOD1>;
  using mint2 = modint<MOD2>;

  vc<mint1> a1(n), b1(m);
  vc<mint2> a2(n), b2(m);
  FOR(i, n) a1[i] = a[i], a2[i] = a[i];
  FOR(i, m) b1[i] = b[i], b2[i] = b[i];

  auto c1 = convolution_ntt<mint1>(a1, b1);
  auto c2 = convolution_ntt<mint2>(a2, b2);

  FOR(i, n + m - 1) { res[i] += CRT2<u64, MOD1, MOD2>(c1[i].val, c2[i].val); }
  return res;
}

template <typename mint>
vc<mint> convolution(const vc<mint>& a, const vc<mint>& b) {
  int n = len(a), m = len(b);
  if (!n || !m) return {};
  if (mint::can_ntt()) {
    if (min(n, m) <= 50) return convolution_karatsuba<mint>(a, b);
    return convolution_ntt(a, b);
  }
  if (min(n, m) <= 200) return convolution_karatsuba<mint>(a, b);
  return convolution_garner(a, b);
}
#line 6 "main.cpp"

using mint = modint998;

void solve() {
  LL(N);
  vv(mint, F, 1 << 9, 1 << 11);
  VEC(int, A, N);
  VEC(int, B, N);
  FOR(i, N) F[B[i]][A[i]] += 1;
  FOR(i, 1 << 9) ntt(F[i], false);

  FOR(i, 9) {
    FOR(s, 1 << 9) {
      int t = s | 1 << i;
      if (s == t) continue;
      FOR(i, 1 << 11) { tie(F[s][i], F[t][i]) = mp(F[s][i] + F[t][i], F[s][i] - F[t][i]); }
    }
  }
  FOR(a, 1 << 9) FOR(b, 1 << 11) F[a][b] = F[a][b].pow(4);

  FOR(i, 9) {
    FOR(s, 1 << 9) {
      int t = s | 1 << i;
      if (s == t) continue;
      FOR(i, 1 << 11) { tie(F[s][i], F[t][i]) = mp(F[s][i] + F[t][i], F[s][i] - F[t][i]); }
    }
  }
  FOR(i, 1 << 9) ntt(F[i], true);

  mint ANS = 0;
  FOR(a, 1 << 9) FOR(b, 1 << 11) {
    mint x = F[a][b];
    if (x == 0) continue;
    ANS += x * mint(b).pow(a);
  }
  ANS /= 512;
  print(ANS);
}

signed main() { solve(); }

详细

Test #1:

score: 100
Accepted
time: 29ms
memory: 7508kb

input:

1
1
1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 33ms
memory: 7420kb

input:

5
227 67 445 67 213
297 171 324 493 354

output:

42

result:

ok 1 number(s): "42"

Test #3:

score: 0
Accepted
time: 29ms
memory: 7440kb

input:

20
93 84 58 43 46 90 86 67 86 1 20 69 91 49 5 97 81 61 81 42
60 73 35 61 94 88 53 52 66 3 5 32 14 48 10 32 86 72 52 32

output:

36313816

result:

ok 1 number(s): "36313816"

Test #4:

score: 0
Accepted
time: 36ms
memory: 7420kb

input:

20
17 24 8 24 99 67 57 51 46 87 63 8 85 83 20 10 95 23 99 83
1 51 48 36 51 97 70 13 79 69 35 15 1 84 23 44 16 35 85 42

output:

357580675

result:

ok 1 number(s): "357580675"

Test #5:

score: 0
Accepted
time: 33ms
memory: 7576kb

input:

20
41 72 62 98 49 32 45 39 1 70 3 52 76 20 43 27 22 70 18 28
53 29 58 15 12 5 95 74 99 40 49 85 100 17 28 44 49 10 23 57

output:

173357999

result:

ok 1 number(s): "173357999"

Test #6:

score: 0
Accepted
time: 33ms
memory: 7460kb

input:

20
69 13 15 72 10 13 28 31 57 48 42 4 62 57 66 44 36 32 40 77
2 15 67 99 69 29 16 27 11 10 75 59 91 49 33 48 79 85 64 64

output:

649835489

result:

ok 1 number(s): "649835489"

Test #7:

score: 0
Accepted
time: 33ms
memory: 7368kb

input:

20
97 65 65 49 64 90 3 15 12 34 90 47 56 94 81 61 63 90 62 21
42 92 76 82 30 37 33 88 20 76 1 30 78 81 41 53 9 55 2 74

output:

304078125

result:

ok 1 number(s): "304078125"

Test #8:

score: 0
Accepted
time: 29ms
memory: 7292kb

input:

100
16 97 48 43 62 18 55 65 37 3 49 84 31 35 20 87 65 4 42 24 77 66 61 70 85 2 1 64 66 4 17 75 47 53 10 40 63 77 94 75 86 90 78 97 72 71 49 63 100 42 55 61 91 63 91 88 7 11 25 76 8 13 80 3 86 32 37 28 73 40 59 33 44 4 53 61 23 62 27 3 21 43 69 5 46 39 94 5 57 86 82 92 35 26 81 6 15 55 30 19
33 13 4 ...

output:

391854458

result:

ok 1 number(s): "391854458"

Test #9:

score: 0
Accepted
time: 30ms
memory: 7280kb

input:

100
36 41 6 24 15 95 34 49 93 85 89 24 21 73 39 96 80 55 60 65 18 44 66 53 42 10 22 29 79 70 43 54 34 89 23 44 93 52 32 82 75 8 59 51 65 55 60 7 14 97 65 9 80 87 95 23 86 32 80 92 15 23 15 81 22 98 18 51 64 66 3 15 63 20 36 95 75 45 80 19 71 99 95 28 89 3 66 56 7 5 20 4 47 95 86 92 32 6 72 43
14 83 ...

output:

782881333

result:

ok 1 number(s): "782881333"

Test #10:

score: 0
Accepted
time: 29ms
memory: 7296kb

input:

100
64 85 59 2 77 64 13 41 48 68 28 67 23 6 58 13 2 17 79 6 66 30 75 33 3 27 39 82 95 41 57 20 29 22 36 44 22 31 69 93 80 23 44 10 53 38 72 51 32 68 79 60 61 12 87 57 76 57 31 96 19 36 54 63 45 63 3 75 63 100 52 2 78 32 12 25 35 32 33 30 18 48 26 48 24 75 37 98 57 36 58 17 54 56 95 91 40 57 18 56
87...

output:

434198484

result:

ok 1 number(s): "434198484"

Test #11:

score: 0
Accepted
time: 33ms
memory: 7572kb

input:

100
92 30 9 79 30 41 97 25 12 50 68 15 13 43 77 30 17 75 93 58 15 12 97 16 64 39 61 42 11 11 83 94 24 54 32 52 56 2 7 7 72 45 33 64 50 26 83 79 54 22 96 12 58 36 87 3 67 78 82 1 30 49 90 41 76 16 88 99 54 38 9 88 1 35 87 56 83 19 78 42 68 4 52 72 59 43 1 45 2 55 96 33 57 21 16 81 48 1 56 80
52 35 8 ...

output:

234628493

result:

ok 1 number(s): "234628493"

Test #12:

score: 0
Accepted
time: 33ms
memory: 7280kb

input:

100
12 78 63 53 80 18 76 13 67 32 7 59 4 76 96 51 43 29 15 3 63 89 6 87 21 51 82 3 28 81 10 73 11 86 45 52 86 77 48 18 73 56 18 19 39 2 95 23 72 93 6 64 44 60 79 38 54 99 37 17 33 62 25 26 11 82 69 23 53 72 54 74 16 51 55 90 43 2 35 50 23 56 91 96 97 11 77 92 56 73 30 46 68 90 25 75 64 52 98 96
33 1...

output:

561690167

result:

ok 1 number(s): "561690167"

Test #13:

score: 0
Accepted
time: 30ms
memory: 7556kb

input:

1000
6 11 90 9 40 28 25 17 8 36 92 33 93 41 57 33 2 98 59 45 80 48 50 80 3 97 5 60 94 65 75 61 76 8 67 41 59 9 68 34 88 18 93 84 13 26 29 27 50 1 36 30 37 20 25 71 90 63 42 1 67 32 43 32 25 83 40 80 41 96 70 18 61 31 58 37 37 56 86 15 66 3 61 18 1 22 55 24 53 94 91 51 89 26 16 61 35 24 17 61 12 85 5...

output:

603293709

result:

ok 1 number(s): "603293709"

Test #14:

score: 0
Accepted
time: 34ms
memory: 7404kb

input:

1000
34 56 44 86 94 1 1 1 67 22 39 77 92 75 80 42 21 48 77 85 21 26 64 64 60 6 22 21 2 31 97 31 67 40 79 49 89 84 5 45 81 37 78 39 2 9 37 63 68 64 54 82 18 40 21 5 77 88 97 13 78 49 83 9 60 48 29 8 32 30 19 100 76 42 33 68 85 43 39 23 16 60 92 46 36 86 23 70 94 9 29 68 96 91 21 59 51 75 51 85 93 59 ...

output:

82406712

result:

ok 1 number(s): "82406712"

Test #15:

score: 0
Accepted
time: 34ms
memory: 7432kb

input:

1000
58 4 97 68 56 70 84 93 27 5 83 16 86 12 95 59 47 10 95 38 69 3 73 35 21 14 44 82 22 97 15 9 54 77 84 49 22 59 47 60 86 51 67 97 2 97 60 7 86 27 64 26 15 64 17 40 68 9 56 21 82 59 18 87 84 13 13 27 31 64 64 99 95 58 4 98 41 22 84 35 63 16 18 70 67 58 95 17 44 31 67 84 3 56 30 49 60 22 97 97 67 3...

output:

30095324

result:

ok 1 number(s): "30095324"

Test #16:

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

input:

1000
82 44 43 38 9 47 67 81 82 83 23 68 76 45 18 76 62 73 18 83 18 93 82 18 78 22 61 39 35 76 45 80 49 5 97 54 48 34 84 66 79 66 52 51 91 72 68 51 100 90 81 78 96 89 9 86 58 30 99 25 97 76 53 69 11 75 90 51 30 94 20 81 10 62 80 32 1 9 41 43 13 64 48 90 10 18 59 63 98 58 5 97 15 17 52 43 68 70 31 22 ...

output:

707881863

result:

ok 1 number(s): "707881863"

Test #17:

score: 0
Accepted
time: 33ms
memory: 7472kb

input:

1000
11 89 1 19 67 19 46 69 42 69 66 8 62 82 33 93 84 23 28 28 66 71 92 1 39 42 82 96 55 46 72 58 40 41 98 58 82 5 18 73 67 88 33 6 80 60 79 87 18 52 3 33 86 13 5 20 45 51 54 37 100 89 88 55 46 28 79 75 21 28 65 63 29 73 55 58 57 92 94 58 68 16 75 10 45 94 35 10 47 77 43 17 22 86 61 46 84 21 77 46 1...

output:

26750840

result:

ok 1 number(s): "26750840"

Test #18:

score: 0
Accepted
time: 30ms
memory: 7528kb

input:

10000
73 78 73 17 28 75 67 8 100 99 30 90 10 19 65 58 90 37 46 41 30 86 85 33 38 12 39 39 81 5 27 93 10 83 16 25 69 66 92 20 98 13 11 68 26 25 38 67 1 92 49 25 9 51 58 74 97 89 59 98 7 38 39 23 35 48 6 34 46 6 17 51 100 100 19 24 69 56 6 1 84 60 38 87 27 38 26 5 29 3 46 86 4 28 75 26 63 16 43 97 90 ...

output:

636404192

result:

ok 1 number(s): "636404192"

Test #19:

score: 0
Accepted
time: 33ms
memory: 7652kb

input:

10000
1 22 27 94 89 48 50 96 55 77 74 33 96 48 76 67 9 87 69 81 71 64 94 8 95 20 64 100 2 83 41 68 98 19 17 33 99 37 30 39 87 31 92 27 27 8 54 11 15 59 71 77 98 76 54 9 88 14 10 2 23 55 79 1 66 6 95 62 37 40 73 41 11 100 2 58 21 43 55 17 38 17 73 15 70 98 97 56 82 21 80 3 11 93 88 20 79 63 85 13 67 ...

output:

774907182

result:

ok 1 number(s): "774907182"

Test #20:

score: 0
Accepted
time: 26ms
memory: 7700kb

input:

10000
25 67 72 76 39 25 34 84 15 59 13 85 86 89 3 84 31 49 87 26 19 45 7 91 52 33 77 49 10 54 67 42 1 55 25 41 33 16 71 46 92 46 77 73 15 96 65 51 33 17 84 29 87 100 46 47 75 35 69 6 26 64 14 87 93 67 84 82 36 74 18 23 34 11 77 92 82 26 8 21 89 65 99 39 1 74 57 98 32 40 14 15 23 58 98 15 84 10 19 37...

output:

879052589

result:

ok 1 number(s): "879052589"

Test #21:

score: 0
Accepted
time: 34ms
memory: 7648kb

input:

10000
53 11 30 46 92 97 9 76 70 46 53 29 81 18 22 1 54 99 9 79 68 27 17 71 13 53 94 13 35 24 85 21 88 92 38 37 62 91 9 57 84 56 66 27 4 76 77 91 47 84 98 73 77 24 46 89 62 56 16 22 37 77 49 65 25 32 56 5 31 100 75 6 53 27 45 18 42 9 65 29 35 25 26 67 36 42 33 45 81 59 52 32 30 19 15 9 100 61 61 58 1...

output:

222383782

result:

ok 1 number(s): "222383782"

Test #22:

score: 0
Accepted
time: 34ms
memory: 7516kb

input:

10000
77 63 76 27 54 70 92 60 26 24 1 68 71 60 41 18 68 61 31 24 20 5 26 54 66 61 15 74 47 86 11 87 75 24 47 49 92 62 46 75 85 79 47 86 1 59 88 35 65 43 12 29 66 41 38 24 49 77 71 31 40 90 88 46 56 98 45 37 29 38 20 96 68 39 24 53 98 96 11 45 86 77 64 91 79 6 5 91 23 89 90 40 41 88 20 95 8 13 95 74 ...

output:

977802728

result:

ok 1 number(s): "977802728"

Test #23:

score: 0
Accepted
time: 32ms
memory: 8204kb

input:

100000
92 20 39 95 30 50 19 78 37 50 83 52 8 47 11 99 84 53 67 44 12 71 95 47 21 4 39 62 50 63 4 22 65 43 17 21 97 51 55 27 26 35 98 9 84 9 2 21 61 85 18 75 66 77 44 65 49 6 83 53 34 1 60 62 86 51 58 3 2 17 10 67 18 89 95 42 59 15 11 42 44 45 56 47 10 96 44 4 36 7 10 44 100 63 42 46 32 90 81 76 62 1...

output:

143863540

result:

ok 1 number(s): "143863540"

Test #24:

score: 0
Accepted
time: 36ms
memory: 8372kb

input:

100000
16 60 93 73 91 26 95 70 1 36 23 100 98 85 22 16 2 4 93 84 52 49 100 26 82 25 56 27 63 33 26 93 61 79 18 29 31 22 93 37 19 50 83 67 73 97 13 61 75 48 36 15 51 10 40 100 36 31 38 65 41 14 7 40 17 16 47 26 1 51 58 50 37 100 63 72 15 2 64 58 98 1 82 63 53 55 11 47 86 30 47 56 15 28 51 44 48 42 23...

output:

178713544

result:

ok 1 number(s): "178713544"

Test #25:

score: 0
Accepted
time: 36ms
memory: 8020kb

input:

100000
44 5 42 51 49 95 78 58 60 14 66 48 88 18 49 29 25 66 11 29 1 39 10 9 39 33 78 76 79 4 44 71 52 12 27 33 60 89 26 52 24 64 68 22 70 68 25 5 93 10 50 71 40 26 32 38 27 52 93 73 57 27 42 18 52 81 28 50 96 77 11 40 60 8 42 6 76 89 21 66 49 61 21 91 88 31 75 93 35 49 81 61 27 93 60 34 56 89 57 17 ...

output:

641634039

result:

ok 1 number(s): "641634039"

Test #26:

score: 0
Accepted
time: 31ms
memory: 8292kb

input:

100000
68 49 96 32 98 68 61 46 15 96 2 87 82 55 68 46 47 16 33 82 53 17 23 89 96 41 99 41 95 78 71 42 39 48 40 37 90 60 68 63 17 82 53 76 58 52 36 45 19 73 68 27 29 50 28 73 18 73 36 77 60 33 77 8 83 43 9 82 95 11 60 22 75 20 17 32 36 68 66 82 96 13 47 10 19 99 47 40 77 68 19 77 26 58 69 29 73 36 3 ...

output:

767591848

result:

ok 1 number(s): "767591848"

Test #27:

score: 0
Accepted
time: 31ms
memory: 8208kb

input:

100000
92 97 46 2 60 45 36 34 71 83 46 31 73 88 87 64 66 78 51 27 94 94 40 72 57 61 16 2 12 48 1 20 38 81 53 42 24 39 6 69 10 97 38 27 55 39 48 85 33 36 77 66 19 75 24 15 5 94 95 94 63 54 16 85 6 100 98 1 86 49 5 9 94 31 85 67 88 55 19 86 46 69 73 34 62 63 23 86 31 98 57 94 37 23 87 19 81 96 45 53 5...

output:

892026304

result:

ok 1 number(s): "892026304"

Test #28:

score: 0
Accepted
time: 48ms
memory: 8368kb

input:

100000
331 189 193 359 300 308 73 248 186 178 432 261 320 358 450 100 274 350 331 226 69 331 302 353 144 307 93 360 340 29 75 42 49 320 120 251 430 441 309 386 205 104 181 269 176 31 289 49 497 380 481 347 452 206 317 463 380 291 181 477 357 489 105 363 161 392 78 485 66 370 131 65 469 207 313 139 6...

output:

278716273

result:

ok 1 number(s): "278716273"

Test #29:

score: 0
Accepted
time: 49ms
memory: 8156kb

input:

100000
459 33 246 336 54 381 260 440 46 360 372 4 410 87 261 221 393 112 349 467 318 109 323 32 397 15 110 413 164 399 301 121 136 253 421 456 56 16 250 293 497 15 166 416 365 319 305 89 423 334 403 103 45 38 317 198 471 104 36 293 369 94 236 141 396 449 259 108 357 4 180 455 188 423 188 377 223 132...

output:

313532445

result:

ok 1 number(s): "313532445"

Test #30:

score: 0
Accepted
time: 53ms
memory: 8160kb

input:

100000
179 378 196 18 116 158 231 428 201 246 311 248 309 328 288 330 115 362 367 220 66 387 332 415 254 427 331 478 477 66 323 391 235 389 234 260 286 79 284 7 494 437 447 74 258 403 412 333 41 301 17 347 330 358 213 444 357 225 379 97 276 211 275 227 119 315 340 232 456 238 24 445 204 127 64 307 1...

output:

265253308

result:

ok 1 number(s): "265253308"

Test #31:

score: 0
Accepted
time: 53ms
memory: 8220kb

input:

100000
307 18 250 187 369 127 419 416 357 225 455 299 399 58 407 247 30 421 89 460 7 472 342 94 315 147 53 135 85 436 241 266 26 129 343 464 15 154 21 414 95 348 228 233 254 474 224 373 455 460 131 398 319 487 109 178 448 346 439 402 287 20 111 4 150 180 329 356 55 372 381 28 15 138 143 237 31 2 434...

output:

68747756

result:

ok 1 number(s): "68747756"

Test #32:

score: 0
Accepted
time: 53ms
memory: 8188kb

input:

100000
231 362 199 369 123 200 94 404 420 407 203 339 489 491 422 165 252 171 311 201 459 46 455 170 172 356 70 188 205 306 467 240 113 266 143 64 245 229 463 25 388 462 317 187 443 262 35 413 73 426 448 450 209 307 5 117 39 467 294 410 491 137 150 486 385 137 306 479 346 6 226 110 234 354 210 372 4...

output:

231738288

result:

ok 1 number(s): "231738288"

Test #33:

score: 0
Accepted
time: 31ms
memory: 8336kb

input:

100000
492 500 491 489 494 490 484 488 495 484 486 492 485 499 484 498 487 489 500 493 499 499 488 492 488 489 487 483 500 491 488 499 485 491 489 485 485 496 484 483 488 487 485 499 495 484 492 483 493 496 491 483 487 484 490 486 493 491 499 491 490 493 495 491 498 495 496 493 488 488 493 485 498 4...

output:

736020263

result:

ok 1 number(s): "736020263"

Test #34:

score: 0
Accepted
time: 27ms
memory: 8352kb

input:

100000
496 490 493 491 489 498 499 498 496 493 499 495 483 490 487 487 492 495 498 500 497 491 488 488 493 495 492 494 490 489 488 488 484 493 500 493 494 483 490 500 487 489 490 488 489 490 485 491 497 485 498 492 496 500 500 492 500 494 498 496 496 494 500 486 498 486 485 496 493 494 498 487 498 4...

output:

334641190

result:

ok 1 number(s): "334641190"

Test #35:

score: 0
Accepted
time: 31ms
memory: 8088kb

input:

100000
486 491 485 492 491 485 489 490 498 483 491 495 486 488 490 498 486 497 496 484 486 483 497 487 494 497 483 499 484 498 494 484 489 492 487 493 500 492 485 486 496 484 491 498 484 486 489 499 488 492 488 484 483 490 500 488 485 497 487 496 497 495 489 486 485 499 487 500 498 490 488 487 497 4...

output:

876638994

result:

ok 1 number(s): "876638994"

Test #36:

score: 0
Accepted
time: 31ms
memory: 8256kb

input:

100000
494 495 490 490 492 484 486 500 495 491 486 499 498 493 483 495 491 486 498 487 492 486 488 492 499 500 498 496 497 496 491 490 494 494 488 483 496 497 495 485 491 490 496 491 483 495 500 485 492 498 488 494 489 499 500 491 492 496 498 496 488 496 483 486 484 483 490 486 495 487 483 493 492 4...

output:

69597429

result:

ok 1 number(s): "69597429"

Test #37:

score: 0
Accepted
time: 35ms
memory: 8092kb

input:

100000
498 495 486 491 484 497 493 492 493 499 496 498 486 490 496 492 495 488 488 494 495 496 498 487 486 484 489 489 495 486 487 491 493 493 485 487 484 484 483 490 486 485 491 497 495 491 486 493 492 487 492 486 484 497 496 497 498 499 497 500 489 497 490 496 483 496 493 489 500 497 492 500 491 4...

output:

895027375

result:

ok 1 number(s): "895027375"

Test #38:

score: 0
Accepted
time: 29ms
memory: 7456kb

input:

20
496 485 485 495 496 483 490 489 490 493 496 491 487 487 492 497 487 489 494 496
485 489 484 493 500 500 499 493 484 496 494 488 490 488 487 488 499 492 497 483

output:

632858349

result:

ok 1 number(s): "632858349"

Test #39:

score: 0
Accepted
time: 29ms
memory: 7552kb

input:

20
500 489 494 497 498 495 494 499 488 487 491 491 494 492 495 494 495 500 496 488
483 489 484 489 483 484 486 500 492 486 490 488 485 490 487 492 491 497 497 488

output:

62917734

result:

ok 1 number(s): "62917734"

Test #40:

score: 0
Accepted
time: 29ms
memory: 7372kb

input:

20
494 494 490 486 490 500 495 491 489 495 483 494 488 490 498 491 500 498 486 483
490 499 489 498 488 487 491 483 500 485 486 495 490 489 492 496 483 488 488 500

output:

641490407

result:

ok 1 number(s): "641490407"

Test #41:

score: 0
Accepted
time: 33ms
memory: 7576kb

input:

20
498 494 496 488 491 499 498 483 487 499 497 490 486 499 491 488 490 494 485 486
496 490 484 489 489 493 500 484 499 497 492 487 499 491 485 500 484 485 494 491

output:

351781878

result:

ok 1 number(s): "351781878"

Test #42:

score: 0
Accepted
time: 29ms
memory: 7372kb

input:

20
488 495 491 489 497 494 496 499 488 494 492 494 484 496 490 485 495 492 487 493
491 490 494 488 500 495 487 495 489 487 493 497 494 489 486 486 490 490 489 486

output:

915968356

result:

ok 1 number(s): "915968356"