QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#719459#1839. JokemaspyAC ✓3ms3932kbC++2319.6kb2024-11-07 01:22:492024-11-07 01:22:49

Judging History

This is the latest submission verdict.

  • [2024-11-07 01:22:49]
  • Judged
  • Verdict: AC
  • Time: 3ms
  • Memory: 3932kb
  • [2024-11-07 01:22:49]
  • Submitted

answer

#line 1 "library/my_template.hpp"
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;

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 vec(type, name, ...) vector<type> name(__VA_ARGS__)
#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 FOR4_R(i, a, b, c) for (ll i = (b)-1; i >= ll(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) \
  overload4(__VA_ARGS__, FOR4_R, 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

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

#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())

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); }
// (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, typename U>
T ceil(T x, U y) {
  return (x > 0 ? (x + y - 1) / y : x / y);
}

template <typename T, typename U>
T floor(T x, U y) {
  return (x > 0 ? x / y : (x - y + 1) / y);
}

template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

ll binary_search(function<bool(ll)> check, ll ok, ll ng) {
  assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    if (check(x))
      ok = x;
    else
      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;
    if (check(x)) {
      ok = x;
    } else {
      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);
}

vi s_to_vi(const string &S, char first_char) {
  vi A(S.size());
  FOR(i, S.size()) { A[i] = S[i] - first_char; }
  return A;
}

template <typename T>
vector<T> cumsum(vector<T> &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;
}

template <typename CNT, typename T>
vc<CNT> bincount(const vc<T> &A, int size) {
  vc<CNT> C(size);
  for (auto &&x: A) { ++C[x]; }
  return C;
}

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

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  int n = len(A);
  assert(len(I) == n);
  vc<T> B(n);
  FOR(i, n) B[i] = A[I[i]];
  return B;
}
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>

namespace detail {
template <typename T, decltype(&T::is_modint) = &T::is_modint>
std::true_type check_value(int);
template <typename T>
std::false_type check_value(long);
} // namespace detail

template <typename T>
struct is_modint : decltype(detail::check_value<T>(0)) {};
template <typename T>
using is_modint_t = enable_if_t<is_modint<T>::value>;
template <typename T>
using is_not_modint_t = enable_if_t<!is_modint<T>::value>;

struct Scanner {
  FILE *fp;
  char line[(1 << 15) + 1];
  size_t st = 0, ed = 0;
  void reread() {
    memmove(line, line + st, ed - st);
    ed -= st;
    st = 0;
    ed += fread(line + ed, 1, (1 << 15) - ed, fp);
    line[ed] = '\0';
  }
  bool succ() {
    while (true) {
      if (st == ed) {
        reread();
        if (st == ed) return false;
      }
      while (st != ed && isspace(line[st])) st++;
      if (st != ed) break;
    }
    if (ed - st <= 50) {
      bool sep = false;
      for (size_t i = st; i < ed; i++) {
        if (isspace(line[i])) {
          sep = true;
          break;
        }
      }
      if (!sep) reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    while (true) {
      size_t sz = 0;
      while (st + sz < ed && !isspace(line[st + sz])) sz++;
      ref.append(line + st, sz);
      st += sz;
      if (!sz || st != ed) break;
      reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    bool neg = false;
    if (line[st] == '-') {
      neg = true;
      st++;
    }
    ref = T(0);
    while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
    if (neg) ref = -ref;
    return true;
  }
  template <class T, is_modint_t<T> * = nullptr>
  bool read_single(T &ref) {
    long long val = 0;
    bool f = read_single(val);
    ref = T(val);
    return f;
  }
  bool read_single(double &ref) {
    string s;
    if (!read_single(s)) return false;
    ref = std::stod(s);
    return true;
  }
  bool read_single(char &ref) {
    string s;
    if (!read_single(s) || s.size() != 1) return false;
    ref = s[0];
    return true;
  }
  template <class T>
  bool read_single(vector<T> &ref) {
    for (auto &d: ref) {
      if (!read_single(d)) return false;
    }
    return true;
  }
  template <class T, class U>
  bool read_single(pair<T, U> &p) {
    return (read_single(p.first) && read_single(p.second));
  }
  template <class A, class B, class C>
  bool read_single(tuple<A, B, C> &p) {
    return (read_single(get<0>(p)) && read_single(get<1>(p))
            && read_single(get<2>(p)));
  }
  template <class A, class B, class C, class D>
  bool read_single(tuple<A, B, C, D> &p) {
    return (read_single(get<0>(p)) && read_single(get<1>(p))
            && read_single(get<2>(p)) && read_single(get<3>(p)));
  }
  void read() {}
  template <class H, class... T>
  void read(H &h, T &... t) {
    bool f = read_single(h);
    assert(f);
    read(t...);
  }
  Scanner(FILE *fp) : fp(fp) {}
};

struct Printer {
  Printer(FILE *_fp) : fp(_fp) {}
  ~Printer() { flush(); }

  static constexpr size_t SIZE = 1 << 15;
  FILE *fp;
  char line[SIZE], small[50];
  size_t pos = 0;
  void flush() {
    fwrite(line, 1, pos, fp);
    pos = 0;
  }
  void write(const char &val) {
    if (pos == SIZE) flush();
    line[pos++] = val;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  void write(T val) {
    if (pos > (1 << 15) - 50) flush();
    if (val == 0) {
      write('0');
      return;
    }
    if (val < 0) {
      write('-');
      val = -val; // todo min
    }
    size_t len = 0;
    while (val) {
      small[len++] = char(0x30 | (val % 10));
      val /= 10;
    }
    for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
    pos += len;
  }
  void write(const string &s) {
    for (char c: s) write(c);
  }
  void write(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++) write(s[i]);
  }
  void write(const double &x) {
    ostringstream oss;
    oss << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  void write(const long double &x) {
    ostringstream oss;
    oss << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  template <class T, is_modint_t<T> * = nullptr>
  void write(T &ref) {
    write(ref.val);
  }
  template <class T>
  void write(const vector<T> &val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  template <class T, class U>
  void write(const pair<T, U> &val) {
    write(val.first);
    write(' ');
    write(val.second);
  }
  template <class A, class B, class C>
  void write(const tuple<A, B, C> &val) {
    auto &[a, b, c] = val;
    write(a), write(' '), write(b), write(' '), write(c);
  }
  template <class A, class B, class C, class D>
  void write(const tuple<A, B, C, D> &val) {
    auto &[a, b, c, d] = val;
    write(a), write(' '), write(b), write(' '), write(c), write(' '), write(d);
  }
  template <class A, class B, class C, class D, class E>
  void write(const tuple<A, B, C, D, E> &val) {
    auto &[a, b, c, d, e] = val;
    write(a), write(' '), write(b), write(' '), write(c), write(' '), write(d), write(' '), write(e);
  }
  template <class A, class B, class C, class D, class E, class F>
  void write(const tuple<A, B, C, D, E, F> &val) {
    auto &[a, b, c, d, e, f] = val;
    write(a), write(' '), write(b), write(' '), write(c), write(' '), write(d), write(' '), write(e), write(' '), write(f);
  }
  template <class T, size_t S>
  void write(const array<T, S> &val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  void write(i128 val) {
    string s;
    bool negative = 0;
    if(val < 0){
      negative = 1;
      val = -val;
    }
    while (val) {
      s += '0' + int(val % 10);
      val /= 10;
    }
    if(negative) s += "-";
    reverse(all(s));
    if (len(s) == 0) s = "0";
    write(s);
  }
};

Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);

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

void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
  scanner.read(head);
  read(tail...);
}

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __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 "library/mod/modint.hpp"

template <unsigned int mod>
struct modint {
  static constexpr bool is_modint = true;
  unsigned int val;
  constexpr modint(const long long val = 0) noexcept
      : val(val >= 0 ? val % mod : (mod - (-val) % mod) % mod) {}
  bool operator<(const modint &other) const {
    return val < other.val;
  } // To use std::map
  modint &operator+=(const modint &p) {
    if ((val += p.val) >= mod) val -= mod;
    return *this;
  }
  modint &operator-=(const modint &p) {
    if ((val += mod - p.val) >= mod) val -= mod;
    return *this;
  }
  modint &operator*=(const modint &p) {
    val = (unsigned int)(1LL * val * p.val % mod);
    return *this;
  }
  modint &operator/=(const modint &p) {
    *this *= p.inverse();
    return *this;
  }
  modint operator-() const { return modint(get_mod() - val); }
  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(int64_t n) const {
    modint ret(1), mul(val);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  static constexpr unsigned int get_mod() { return mod; }
};

struct ArbitraryModInt {
  static constexpr bool is_modint = true;
  unsigned int val;
  ArbitraryModInt() : val(0) {}
  ArbitraryModInt(int64_t y)
      : val(y >= 0 ? y % get_mod()
                   : (get_mod() - (-y) % get_mod()) % get_mod()) {}
  bool operator<(const ArbitraryModInt &other) const {
    return val < other.val;
  } // To use std::map<ArbitraryModInt, T>
  static unsigned int &get_mod() {
    static unsigned int mod = 0;
    return mod;
  }
  static void set_mod(int md) { get_mod() = md; }
  ArbitraryModInt &operator+=(const ArbitraryModInt &p) {
    if ((val += p.val) >= get_mod()) val -= get_mod();
    return *this;
  }
  ArbitraryModInt &operator-=(const ArbitraryModInt &p) {
    if ((val += get_mod() - p.val) >= get_mod()) val -= get_mod();
    return *this;
  }
  ArbitraryModInt &operator*=(const ArbitraryModInt &p) {
    unsigned long long a = (unsigned long long)val * p.val;
    unsigned xh = (unsigned)(a >> 32), xl = (unsigned)a, d, m;
    asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(get_mod()));
    val = m;
    return *this;
  }
  ArbitraryModInt &operator/=(const ArbitraryModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ArbitraryModInt operator-() const { return ArbitraryModInt(get_mod() - val); }
  ArbitraryModInt operator+(const ArbitraryModInt &p) const {
    return ArbitraryModInt(*this) += p;
  }
  ArbitraryModInt operator-(const ArbitraryModInt &p) const {
    return ArbitraryModInt(*this) -= p;
  }
  ArbitraryModInt operator*(const ArbitraryModInt &p) const {
    return ArbitraryModInt(*this) *= p;
  }
  ArbitraryModInt operator/(const ArbitraryModInt &p) const {
    return ArbitraryModInt(*this) /= p;
  }
  bool operator==(const ArbitraryModInt &p) const { return val == p.val; }
  bool operator!=(const ArbitraryModInt &p) const { return val != p.val; }
  ArbitraryModInt inverse() const {
    int a = val, b = get_mod(), u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b), swap(u -= t * v, v);
    }
    return ArbitraryModInt(u);
  }
  ArbitraryModInt pow(int64_t n) const {
    ArbitraryModInt ret(1), mul(val);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
};

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 (int(dat.size()) <= n) {
    int k = dat.size();
    auto q = (mod + k - 1) / k;
    int r = k * q - mod;
    dat.emplace_back(dat[r] * mint(q));
  }
  return dat[n];
}

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

template <typename mint>
mint fact_inv(int n) {
  static const int mod = mint::get_mod();
  static vector<mint> dat = {1, 1};
  assert(0 <= n && n < mod);
  while (int(dat.size()) <= n) {
    int k = dat.size();
    dat.emplace_back(dat[k - 1] * inv<mint>(k));
  }
  return dat[n];
}

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

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);
}

using modint107 = modint<1000000007>;
using modint998 = modint<998244353>;
using amint = ArbitraryModInt;
#line 5 "main.cpp"

using mint = modint998;

void solve() {
  LL(N);
  VEC(ll, P, N);
  VEC(ll, Q, N);
  auto I = argsort(P);
  auto A = rearrange(Q, I);
  for (auto&& x: A)
    if (x == 0) x = -1;
  A.insert(A.begin(), 0);
  A.eb(N + 1);
  N += 2;

  vi C_pos(N);
  FOR(i, N) if (A[i] == -1) C_pos[i] = 1;
  C_pos = cumsum(C_pos, 0);

  vi C_num(N, 1);
  FOR(i, N) if (A[i] != -1) C_num[A[i]] = 0;
  C_num = cumsum(C_num, 0);

  vv(mint, DP, N, N);
  DP[0][0] = mint(1);
  FOR(j, 1, N) if (A[j] != -1) {
    FOR(i, j) {
      if (A[i] == -1) continue;
      if (A[i] > A[j]) continue;
      auto& dp = DP[i];
      auto& newdp = DP[j];

      FOR(a, N) {
        if (dp[a] == mint(0)) continue;
        int n = C_pos[j] - C_pos[i];
        FOR(b, n + 1) {
          mint cf = C<mint>(n, b);
          int k = C_num[A[j]] - C_num[A[i]];
          cf *= C<mint>(k, b);
          newdp[a + b] += dp[a] * cf;
        }
      }
    }
  }
  auto& dp = DP.back();
  mint ANS = 0;
  FOR(k, N) {
    if (dp[k] == mint(0)) continue;
    int n = C_pos.back() - k;
    ANS += dp[k] * fact<mint>(n);
  }
  print(ANS);
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15);

  ll T = 1;
  // LL(T);
  FOR(T) solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3568kb

input:

2
1 2
2 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

4
4 3 2 1
4 3 2 1

output:

16

result:

ok 1 number(s): "16"

Test #3:

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

input:

5
1 2 3 4 5
0 0 0 0 0

output:

1546

result:

ok 1 number(s): "1546"

Test #4:

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

input:

6
1 6 2 5 3 4
0 1 0 2 0 3

output:

52

result:

ok 1 number(s): "52"

Test #5:

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

input:

10
8 2 10 3 4 6 1 7 9 5
0 0 0 0 0 0 0 0 0 0

output:

234662231

result:

ok 1 number(s): "234662231"

Test #6:

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

input:

10
5 8 4 9 6 1 2 7 3 10
8 3 0 5 0 9 0 0 6 0

output:

5294

result:

ok 1 number(s): "5294"

Test #7:

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

input:

10
4 2 6 9 5 3 8 1 10 7
0 9 8 0 7 3 4 2 1 10

output:

166

result:

ok 1 number(s): "166"

Test #8:

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

input:

10
8 2 7 1 5 9 3 4 10 6
7 0 2 9 5 1 8 4 3 6

output:

26

result:

ok 1 number(s): "26"

Test #9:

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

input:

10
10 1 6 7 9 8 4 3 5 2
2 5 1 3 9 10 4 8 6 7

output:

47

result:

ok 1 number(s): "47"

Test #10:

score: 0
Accepted
time: 1ms
memory: 3892kb

input:

50
41 15 17 1 5 31 7 38 30 39 43 35 2 26 20 42 48 25 19 32 50 4 8 10 44 12 9 18 13 36 28 6 27 23 40 24 3 14 29 11 49 47 45 46 34 21 37 16 22 33
0 0 0 0 0 0 0 0 0 33 34 0 0 0 0 0 0 0 0 0 0 2 0 0 0 20 0 0 28 0 0 0 9 0 0 0 48 0 0 0 50 0 0 0 0 5 0 0 32 0

output:

976189245

result:

ok 1 number(s): "976189245"

Test #11:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

50
36 35 13 14 45 44 22 10 30 23 15 17 6 42 8 49 21 46 5 32 25 34 38 4 48 50 28 3 9 24 43 47 20 2 40 37 29 41 26 7 39 33 31 19 27 16 11 12 1 18
0 0 0 19 20 42 0 18 9 0 27 0 38 0 0 45 0 33 0 0 0 0 0 7 0 0 37 41 0 2 0 1 0 0 5 13 8 0 0 0 0 0 0 15 17 0 12 0 0 0

output:

861991745

result:

ok 1 number(s): "861991745"

Test #12:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

50
24 4 17 27 45 5 8 33 7 23 19 42 11 2 39 38 48 37 32 29 18 47 6 36 25 15 31 50 12 3 44 28 30 41 40 16 14 21 46 22 34 9 43 26 49 35 10 1 20 13
15 0 0 19 0 0 0 0 0 5 3 0 31 0 25 26 41 7 9 0 22 0 11 49 24 0 43 13 14 35 16 0 27 0 0 0 47 0 0 18 20 23 33 42 36 8 0 30 44 0

output:

231982952

result:

ok 1 number(s): "231982952"

Test #13:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

50
37 9 29 2 13 35 7 16 12 42 34 47 14 46 27 6 21 32 15 49 20 10 31 48 18 4 23 40 25 30 50 41 24 26 11 5 33 36 8 22 39 3 17 43 44 1 45 28 19 38
50 33 0 0 14 10 13 15 16 0 35 12 5 9 34 6 0 38 21 22 45 0 0 28 31 36 0 43 29 37 7 1 20 44 11 4 40 2 0 17 27 39 0 3 30 0 24 26 25 18

output:

31263262

result:

ok 1 number(s): "31263262"

Test #14:

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

input:

50
24 47 6 19 1 25 42 38 18 2 7 3 13 27 23 48 28 36 45 39 37 29 16 12 15 10 8 46 33 34 43 14 50 9 31 32 44 20 26 4 40 22 17 49 35 41 11 21 5 30
7 47 5 19 31 9 48 14 32 11 12 13 33 36 42 29 26 24 39 46 28 15 50 8 30 22 35 3 4 43 10 38 41 6 21 20 2 27 16 37 23 17 45 34 49 40 25 18 44 1

output:

78388

result:

ok 1 number(s): "78388"

Test #15:

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

input:

100
11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 81 52 87 83 73 44 49 23 82 85 75 86 33 47 19 58 97 37 20 40 10 92 4 6 68 77 54 71 12 62 60 100 39 41 99 72 29 57 8 70 32 66 98
0 0 ...

output:

452312947

result:

ok 1 number(s): "452312947"

Test #16:

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

input:

100
78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 21 54 39 68 43 4 32 28 73 6 16 62 72 84 65 86 98 75 33 45 25 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 31 37 12 35 99 67 94 1 87 57 8 61 19 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30
0 0 ...

output:

366370216

result:

ok 1 number(s): "366370216"

Test #17:

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

input:

100
62 70 29 14 12 87 94 78 39 92 84 91 61 49 60 33 69 37 19 82 42 8 45 97 81 43 54 67 1 22 77 58 65 17 18 28 25 57 16 90 40 13 4 21 68 35 15 76 73 93 56 95 79 47 74 75 30 71 66 99 41 24 88 83 5 6 31 96 38 80 27 46 51 53 2 86 32 9 20 100 26 36 63 7 52 55 23 3 50 59 48 89 85 44 34 64 10 72 11 98
0 0 ...

output:

351981437

result:

ok 1 number(s): "351981437"

Test #18:

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

input:

100
100 6 41 33 5 32 39 58 95 48 27 17 90 73 10 81 56 87 79 91 43 42 47 75 57 98 22 49 67 28 94 86 89 60 65 96 11 46 13 23 85 61 9 99 63 52 15 66 40 31 12 72 93 20 77 44 88 55 16 54 38 7 26 19 97 36 14 92 3 4 1 24 2 8 50 76 82 34 51 53 64 45 70 37 18 62 25 21 69 35 74 30 71 84 59 80 83 29 78 68
0 0 ...

output:

195404592

result:

ok 1 number(s): "195404592"

Test #19:

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

input:

100
80 78 96 22 39 21 74 48 61 16 55 32 27 52 34 51 98 4 72 47 42 46 28 90 43 33 44 99 91 11 29 85 92 19 58 73 65 12 87 97 54 59 75 15 9 63 24 67 71 84 36 6 60 94 82 89 70 95 31 5 10 3 37 49 45 18 83 53 64 17 100 1 81 86 88 38 20 40 66 77 50 7 30 69 14 13 79 35 23 68 57 25 8 93 41 62 56 2 76 26
0 48...

output:

119407737

result:

ok 1 number(s): "119407737"

Test #20:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

100
73 72 15 88 11 48 18 17 52 10 75 99 71 80 97 57 47 32 31 12 64 45 85 26 41 14 21 66 27 84 82 6 29 38 37 62 91 65 92 3 40 1 4 13 42 63 44 68 67 46 87 5 9 50 93 36 7 51 79 58 98 70 56 81 83 96 35 54 74 20 55 2 49 43 59 53 30 94 16 89 19 39 61 22 77 23 90 28 34 8 78 100 76 24 33 69 95 25 60 86
0 0 ...

output:

916702910

result:

ok 1 number(s): "916702910"

Test #21:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

100
53 38 68 92 52 62 98 90 50 29 20 56 69 89 85 66 12 13 4 57 34 88 73 32 22 44 26 7 55 2 75 6 21 96 25 46 28 58 40 72 19 24 59 37 91 63 10 77 84 3 67 14 9 70 93 97 48 17 80 43 27 100 35 87 8 95 83 33 47 54 18 65 78 36 60 30 23 42 79 15 86 71 1 41 49 64 39 16 31 82 45 5 81 76 99 51 74 94 11 61
0 0 ...

output:

379434745

result:

ok 1 number(s): "379434745"

Test #22:

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

input:

100
96 67 6 71 66 85 72 38 11 47 13 59 17 40 58 39 7 48 28 95 53 42 49 19 33 64 68 5 84 51 97 12 18 43 76 44 89 27 62 88 4 65 74 79 32 70 25 3 20 23 60 98 50 91 26 93 54 21 31 45 73 92 10 29 14 82 37 83 16 77 90 80 56 75 24 61 63 55 99 57 78 9 100 87 41 36 69 30 86 15 22 2 35 81 34 52 94 1 8 46
0 0 ...

output:

831372413

result:

ok 1 number(s): "831372413"

Test #23:

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

input:

100
28 4 61 67 32 97 47 10 53 87 46 35 33 54 45 48 1 77 75 52 8 81 42 14 9 44 92 94 26 43 74 3 50 55 18 40 49 80 70 25 56 98 82 90 69 13 31 84 6 68 34 57 100 39 5 38 93 12 20 89 21 91 99 96 58 78 2 16 83 71 41 95 62 37 7 59 24 60 86 19 22 85 17 23 15 27 73 29 64 63 72 51 88 30 66 79 11 65 76 36
30 3...

output:

842694516

result:

ok 1 number(s): "842694516"

Test #24:

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

input:

100
9 33 80 5 79 68 56 12 17 3 58 39 1 48 76 52 23 74 38 15 82 87 51 78 34 95 26 72 60 64 96 61 43 7 36 44 25 18 75 77 62 22 70 86 50 20 99 73 45 55 66 94 49 90 57 37 53 93 16 24 13 46 6 41 63 71 84 67 54 91 83 8 85 100 88 29 32 81 31 47 42 69 35 89 92 65 98 21 10 2 27 19 40 4 14 30 11 28 97 59
0 0 ...

output:

982762140

result:

ok 1 number(s): "982762140"

Test #25:

score: 0
Accepted
time: 1ms
memory: 3924kb

input:

100
19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43
0 0 ...

output:

66690913

result:

ok 1 number(s): "66690913"

Test #26:

score: 0
Accepted
time: 3ms
memory: 3916kb

input:

100
38 39 59 95 16 6 33 55 11 10 100 43 77 52 34 1 90 5 37 24 28 22 35 63 71 49 97 79 19 54 21 85 56 13 40 17 57 76 91 99 53 88 20 29 65 81 94 96 89 47 30 80 84 58 9 31 51 61 42 60 73 23 4 74 3 78 8 67 86 14 87 66 2 45 26 70 48 46 72 44 82 69 27 12 92 36 50 62 41 64 75 7 98 15 25 68 18 32 83 93
0 0 ...

output:

899036040

result:

ok 1 number(s): "899036040"

Test #27:

score: 0
Accepted
time: 2ms
memory: 3932kb

input:

100
17 97 68 44 14 16 38 4 29 52 55 93 62 34 96 41 80 40 66 71 47 81 85 99 57 73 5 39 53 9 70 24 86 49 77 50 54 13 7 21 83 25 3 23 42 10 91 79 67 35 92 12 95 26 48 56 27 30 88 1 8 69 20 15 2 76 72 31 19 94 11 89 61 64 28 60 59 18 37 100 63 75 98 36 78 51 22 82 84 32 65 74 46 58 33 43 45 87 6 90
0 0 ...

output:

517437875

result:

ok 1 number(s): "517437875"

Test #28:

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

input:

100
90 100 46 75 59 41 89 99 95 35 5 11 93 85 24 92 87 47 26 4 64 63 70 37 25 39 68 57 52 98 31 45 40 82 30 28 36 19 83 12 21 29 97 54 14 96 43 73 72 49 10 17 33 2 44 91 7 77 78 3 23 80 56 34 22 13 79 27 48 32 15 65 50 60 86 53 88 9 20 42 38 18 74 66 55 6 76 58 84 67 61 71 81 94 69 62 16 51 8 1
0 83...

output:

958635644

result:

ok 1 number(s): "958635644"

Test #29:

score: 0
Accepted
time: 2ms
memory: 3684kb

input:

100
26 67 2 42 77 85 88 49 45 50 71 82 73 96 62 93 78 97 12 34 35 92 94 61 69 74 31 70 87 89 86 10 79 58 3 1 59 41 30 16 83 4 23 25 76 20 75 40 65 68 54 5 6 51 32 64 13 95 21 24 39 66 43 91 18 47 22 15 81 56 100 57 19 98 80 9 53 28 46 37 52 14 27 11 33 29 55 48 36 7 90 63 99 44 60 17 38 8 72 84
63 1...

output:

735454002

result:

ok 1 number(s): "735454002"

Test #30:

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

input:

100
30 14 58 67 48 84 15 16 26 35 47 19 74 9 95 93 60 34 1 98 52 50 63 88 8 64 28 77 25 40 6 55 4 24 73 27 90 31 45 2 80 87 23 10 3 53 94 51 62 56 7 78 89 36 12 13 42 57 5 46 81 29 22 18 49 61 75 59 37 82 39 91 76 86 32 20 99 65 66 92 43 85 21 68 72 44 83 38 79 97 54 69 100 71 11 41 33 70 96 17
45 2...

output:

477087154

result:

ok 1 number(s): "477087154"

Test #31:

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

input:

100
2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34
0 37...

output:

316550008

result:

ok 1 number(s): "316550008"

Test #32:

score: 0
Accepted
time: 1ms
memory: 3720kb

input:

100
45 56 48 36 81 10 94 70 86 92 90 1 82 2 5 31 17 98 57 53 100 14 16 55 11 59 61 39 77 44 26 65 79 46 66 21 40 23 64 72 76 38 58 30 71 74 52 20 47 78 18 49 68 8 91 60 12 15 87 4 89 19 13 80 42 96 32 63 67 37 84 7 6 24 34 85 54 83 93 50 3 97 51 43 35 29 27 25 99 75 28 95 9 41 33 69 22 88 73 62
71 8...

output:

104300725

result:

ok 1 number(s): "104300725"

Test #33:

score: 0
Accepted
time: 1ms
memory: 3688kb

input:

100
70 5 29 43 3 84 78 68 64 73 31 49 18 69 60 92 48 15 35 58 13 90 22 66 12 55 8 27 14 80 94 65 96 74 10 88 23 38 41 44 25 52 19 47 26 45 11 28 95 9 86 77 79 37 4 61 97 51 59 6 53 98 91 24 33 46 50 85 76 67 34 30 99 2 36 32 62 72 93 75 21 71 63 89 56 16 83 54 57 1 100 39 87 17 40 42 7 81 82 20
87 8...

output:

131305690

result:

ok 1 number(s): "131305690"

Test #34:

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

input:

100
97 23 19 13 87 95 35 46 98 6 1 100 66 39 48 86 51 89 67 49 76 22 21 62 61 84 29 9 41 69 16 68 30 65 7 36 4 52 25 24 47 55 80 64 5 58 28 82 53 20 57 26 88 94 43 44 99 45 85 42 2 72 70 15 60 50 27 59 56 32 17 91 92 33 18 77 74 54 14 93 63 73 78 40 90 3 71 81 8 10 79 75 83 11 38 96 12 31 34 37
83 1...

output:

121844310

result:

ok 1 number(s): "121844310"

Test #35:

score: 0
Accepted
time: 1ms
memory: 3880kb

input:

100
78 66 37 31 84 90 17 80 40 14 1 38 79 64 26 34 87 75 3 41 67 77 58 6 50 82 8 81 27 9 13 22 16 52 42 65 53 46 92 44 99 18 11 33 55 45 23 21 76 85 48 56 98 61 95 70 62 86 39 43 57 15 47 96 32 60 10 24 5 73 88 30 97 4 35 12 29 94 83 91 93 100 51 2 54 19 20 71 28 69 74 7 72 59 68 25 49 63 89 36
22 3...

output:

18919311

result:

ok 1 number(s): "18919311"

Test #36:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

100
88 31 100 15 92 44 94 22 24 51 95 41 30 86 34 37 38 12 4 81 60 69 45 40 99 62 6 46 35 27 96 36 59 47 73 78 65 87 3 9 85 57 2 77 26 20 55 97 64 58 63 21 80 19 42 54 49 79 66 70 75 17 16 13 89 28 72 48 90 74 61 71 1 23 5 76 43 32 29 83 18 93 8 7 14 10 39 91 50 67 82 53 52 11 68 33 98 25 84 56
18 8...

output:

8454871

result:

ok 1 number(s): "8454871"

Test #37:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

100
70 54 10 72 81 84 56 15 27 19 43 100 49 44 52 33 63 40 95 17 58 2 51 39 22 18 82 1 16 99 32 29 24 94 9 98 5 37 47 14 42 73 41 31 79 64 12 6 53 26 68 67 89 13 90 4 21 93 46 74 75 88 66 57 23 7 25 48 92 62 30 8 50 61 38 87 71 34 97 28 80 11 60 91 3 35 86 96 36 20 59 65 83 45 76 77 78 69 85 55
29 7...

output:

42741099

result:

ok 1 number(s): "42741099"