QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#541927#8936. Team Arrangementucup-team180#AC ✓645ms106756kbC++2035.6kb2024-08-31 21:32:482024-08-31 21:32:48

Judging History

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

  • [2024-08-31 21:32:48]
  • 评测
  • 测评结果:AC
  • 用时:645ms
  • 内存:106756kb
  • [2024-08-31 21:32:48]
  • 提交

answer

#pragma region Macros
#ifdef noimi
#pragma comment(linker, "/stack:256000000")
#include "my_template.hpp"
#else
// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <immintrin.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <immintrin.h>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <variant>

#ifdef noimi
#define oj_local(a, b) b
#else
#define oj_local(a, b) a
#endif

#define LOCAL if(oj_local(0, 1))
#define OJ if(oj_local(1, 0))

using namespace std;
using ll = long long;
using ull = unsigned long long int;
using i128 = __int128_t;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vc<T>>;
template <typename T> using vvvc = vector<vvc<T>>;
using vi = vc<int>;
using vl = vc<ll>;
using vpi = vc<pii>;
using vpl = vc<pll>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename T> int si(const T &x) { return x.size(); }
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 iota(int n) {
    vi a(n);
    return iota(a.begin(), a.end(), 0), a;
}
template <typename T> vi iota(const vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(res.begin(), res.end(), 0);
    sort(res.begin(), res.end(), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}

// macros
#define overload5(a, b, c, d, e, name, ...) name
#define overload4(a, b, c, d, name, ...) name
#define endl '\n'
#define REP0(n) for(ll jidlsjf = 0; jidlsjf < n; ++jidlsjf)
#define REP1(i, n) for(ll i = 0; i < (n); ++i)
#define REP2(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define per0(n) for(int jidlsjf = 0; jidlsjf < (n); ++jidlsjf)
#define per1(i, n) for(ll i = (n) - 1; i >= 0; --i)
#define per2(i, a, b) for(ll i = (a) - 1; i >= b; --i)
#define per3(i, a, b, c) for(ll i = (a) - 1; i >= (b); i -= (c))
#define per(...) overload4(__VA_ARGS__, per3, per2, per1, per0)(__VA_ARGS__)
#define fore0(a) rep(a.size())
#define fore1(i, a) for(auto &&i : a)
#define fore2(a, b, v) for(auto &&[a, b] : v)
#define fore3(a, b, c, v) for(auto &&[a, b, c] : v)
#define fore4(a, b, c, d, v) for(auto &&[a, b, c, d] : v)
#define fore(...) overload5(__VA_ARGS__, fore4, fore3, fore2, fore1, fore0)(__VA_ARGS__)
#define setbits(j, n) for(ll iiiii = (n), j = lowbit(iiiii); iiiii; iiiii ^= 1 << j, j = lowbit(iiiii))
#define perm(v) for(bool permrepflag = true; (permrepflag ? exchange(permrepflag, false) : next_permutation(all(v)));)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define drop(s) cout << #s << endl, exit(0)
#define si(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
#define rng(v, l, r) v.begin() + (l), v.begin() + (r)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define SORT(v) sort(all(v))
#define REV(v) reverse(all(v))
#define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end())
template <typename T = ll, typename S> T SUM(const S &v) { return accumulate(all(v), T(0)); }
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define overload2(_1, _2, name, ...) name
#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__))))
constexpr pii dx4[4] = {pii{1, 0}, pii{0, 1}, pii{-1, 0}, pii{0, -1}};
constexpr pii dx8[8] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

namespace yesno_impl {
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
const string firstsecond[2] = {"second", "first"};
const string FirstSecond[2] = {"Second", "First"};
const string possiblestr[2] = {"impossible", "possible"};
const string Possiblestr[2] = {"Impossible", "Possible"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { cout << YesNo[t] << endl; }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { cout << yesno[t] << endl; }
void no(bool t = 1) { yes(!t); }
void first(bool t = 1) { cout << firstsecond[t] << endl; }
void First(bool t = 1) { cout << FirstSecond[t] << endl; }
void possible(bool t = 1) { cout << possiblestr[t] << endl; }
void Possible(bool t = 1) { cout << Possiblestr[t] << endl; }
}; // namespace yesno_impl
using namespace yesno_impl;

#define INT(...)                                                                                                                                               \
    int __VA_ARGS__;                                                                                                                                           \
    IN(__VA_ARGS__)
#define INTd(...)                                                                                                                                              \
    int __VA_ARGS__;                                                                                                                                           \
    IN2(__VA_ARGS__)
#define LL(...)                                                                                                                                                \
    ll __VA_ARGS__;                                                                                                                                            \
    IN(__VA_ARGS__)
#define LLd(...)                                                                                                                                               \
    ll __VA_ARGS__;                                                                                                                                            \
    IN2(__VA_ARGS__)
#define STR(...)                                                                                                                                               \
    string __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define CHR(...)                                                                                                                                               \
    char __VA_ARGS__;                                                                                                                                          \
    IN(__VA_ARGS__)
#define DBL(...)                                                                                                                                               \
    double __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define VEC(type, name, size)                                                                                                                                  \
    vector<type> name(size);                                                                                                                                   \
    IN(name)
#define VECd(type, name, size)                                                                                                                                 \
    vector<type> name(size);                                                                                                                                   \
    IN2(name)
#define VEC2(type, name1, name2, size)                                                                                                                         \
    vector<type> name1(size), name2(size);                                                                                                                     \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i])
#define VEC2d(type, name1, name2, size)                                                                                                                        \
    vector<type> name1(size), name2(size);                                                                                                                     \
    for(int i = 0; i < size; i++) IN2(name1[i], name2[i])
#define VEC3(type, name1, name2, name3, size)                                                                                                                  \
    vector<type> name1(size), name2(size), name3(size);                                                                                                        \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i])
#define VEC3d(type, name1, name2, name3, size)                                                                                                                 \
    vector<type> name1(size), name2(size), name3(size);                                                                                                        \
    for(int i = 0; i < size; i++) IN2(name1[i], name2[i], name3[i])
#define VEC4(type, name1, name2, name3, name4, size)                                                                                                           \
    vector<type> name1(size), name2(size), name3(size), name4(size);                                                                                           \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i], name4[i]);
#define VEC4d(type, name1, name2, name3, name4, size)                                                                                                          \
    vector<type> name1(size), name2(size), name3(size), name4(size);                                                                                           \
    for(int i = 0; i < size; i++) IN2(name1[i], name2[i], name3[i], name4[i]);
#define VV(type, name, h, w)                                                                                                                                   \
    vector<vector<type>> name(h, vector<type>(w));                                                                                                             \
    IN(name)
#define VVd(type, name, h, w)                                                                                                                                  \
    vector<vector<type>> name(h, vector<type>(w));                                                                                                             \
    IN2(name)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
void IN2() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {
    scan(head);
    IN(tail...);
}
template <class Head, class... Tail> void IN2(Head &head, Tail &...tail) {
    scan(head);
    --head;
    IN2(tail...);
}

template <int p = -1> void pat() {}
template <int p = -1, class Head, class... Tail> void pat(Head &h, Tail &...tail) {
    h += p;
    pat<p>(tail...);
}

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

template <typename T, typename S> T floor(T x, S y) {
    assert(y);
    return (y < 0 ? floor(-x, -y) : (x > 0 ? x / y : x / y - (x % y == 0 ? 0 : 1)));
}
template <typename T, typename S, typename U> U bigmul(const T &x, const S &y, const U &lim) { // clamp(x * y, -lim, lim)
    if(x < 0 and y < 0) return bigmul(-x, -y, lim);
    if(x < 0) return -bigmul(-x, y, lim);
    if(y < 0) return -bigmul(x, -y, lim);
    return y == 0 or x <= lim / y ? x * y : lim;
}
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
template <class T, class S> T POW(T x, S n, const ll &mod) {
    T res = 1;
    x %= mod;
    for(; n; n >>= 1, x = x * x % mod)
        if(n & 1) res = res * x % mod;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    UNIQUE(y);
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
template <class S> void fold_in(vector<S> &v) {}
template <typename Head, typename... Tail, class S> void fold_in(vector<S> &v, Head &&a, Tail &&...tail) {
    for(auto e : a) v.emplace_back(e);
    fold_in(v, tail...);
}
template <class S> void renumber(vector<S> &v) {}
template <typename Head, typename... Tail, class S> void renumber(vector<S> &v, Head &&a, Tail &&...tail) {
    for(auto &&e : a) e = lb(v, e);
    renumber(v, tail...);
}
template <class S, class... Args> vector<S> zip(vector<S> &head, Args &&...args) {
    vector<S> v;
    fold_in(v, head, args...);
    sort(all(v)), v.erase(unique(all(v)), v.end());
    renumber(v, head, args...);
    return v;
}

template <typename S> void rearrange(const vector<S> &id) {}
template <typename S, typename T> void rearrange_exec(const vector<S> &id, vector<T> &v) {
    vector<T> w(v.size());
    rep(i, si(id)) w[i] = v[id[i]];
    v.swap(w);
}
// 並び替える順番, 並び替える vector 達
template <typename S, typename Head, typename... Tail> void rearrange(const vector<S> &id, Head &a, Tail &...tail) {
    rearrange_exec(id, a);
    rearrange(id, tail...);
}

template <typename T> vector<T> RUI(const vector<T> &v) {
    vector<T> res(v.size() + 1);
    for(int i = 0; i < v.size(); i++) res[i + 1] = res[i] + v[i];
    return res;
}
template <typename T> void zeta_supersetsum(vector<T> &f) {
    int n = f.size();
    for(int i = 1; i < n; i <<= 1) rep(b, n) if(!(i & b)) f[b] += f[b | i];
}

template <typename T> void zeta_subsetsum(vector<T> &f) {
    int n = f.size();
    for(int i = 1; i < n; i <<= 1) rep(b, n) if(!(i & b)) f[b | i] += f[b];
}
template <typename T> void mobius_subset(vector<T> &f) {
    int n = f.size();
    for(int i = 1; i < n; i <<= 1) rep(b, n) if(!(i & b)) f[b] -= f[b | i];
}
template <typename T> void mobius_superset(vector<T> &f) {
    int n = f.size();
    for(int i = 1; i < n; i <<= 1) rep(b, n) if(!(i & b)) f[b | i] -= f[b];
}
// 反時計周りに 90 度回転
template <typename T> void rot(vector<vector<T>> &v) {
    if(empty(v)) return;
    int n = v.size(), m = v[0].size();
    vector<vector<T>> res(m, vector<T>(n));
    rep(i, n) rep(j, m) res[m - 1 - j][i] = v[i][j];
    v.swap(res);
}

vector<int> counter(const vector<int> &v, int max_num = -1) {
    if(max_num == -1) max_num = MAX(v);
    vector<int> res(max_num + 1);
    fore(e, v) res[e]++;
    return res;
}

// x in [l, r)
template <class T, class S> bool inc(const T &x, const S &l, const S &r) { return l <= x and x < r; }
template <class T, class S> bool inc(const T &x, const pair<S, S> &p) { return p.first <= x and x < p.second; }

// 便利関数
constexpr ll ten(int n) { return n == 0 ? 1 : ten(n - 1) * 10; }
constexpr ll tri(ll n) { return n * (n + 1) / 2; }
// l + ... + r
constexpr ll tri(ll l, ll r) { return (l + r) * (r - l + 1) / 2; }
ll max(int x, ll y) { return max((ll)x, y); }
ll max(ll x, int y) { return max(x, (ll)y); }
int min(int x, ll y) { return min((ll)x, y); }
int min(ll x, int y) { return min(x, (ll)y); }
// bit 演算系
#define bit(i) (1LL << i)       // (1 << i)
#define test(b, i) (b >> i & 1) // b の i bit 目が立っているか
ll pow2(int i) { return 1LL << i; }
int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
// int lowbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }
int lowbit(ull a) { return a == 0 ? 64 : __builtin_ctzll(a); }
// int allbit(int n) { return (1 << n) - 1; }
constexpr ll mask(int n) { return (1LL << n) - 1; }
// int popcount(signed t) { return __builtin_popcount(t); }
// int popcount(ll t) { return __builtin_popcountll(t); }
int popcount(uint64_t t) { return __builtin_popcountll(t); }
static inline uint64_t popcount64(uint64_t x) {
    uint64_t m1 = 0x5555555555555555ll;
    uint64_t m2 = 0x3333333333333333ll;
    uint64_t m4 = 0x0F0F0F0F0F0F0F0Fll;
    uint64_t h01 = 0x0101010101010101ll;

    x -= (x >> 1) & m1;
    x = (x & m2) + ((x >> 2) & m2);
    x = (x + (x >> 4)) & m4;

    return (x * h01) >> 56;
}
bool ispow2(int i) { return i && (i & -i) == i; }

ll rnd(ll l, ll r) { //[l, r)
#ifdef noimi
    static mt19937_64 gen;
#else
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
#endif
    return uniform_int_distribution<ll>(l, r - 1)(gen);
}
ll rnd(ll n) { return rnd(0, n); }

template <class t> void random_shuffle(vc<t> &a) { rep(i, si(a)) swap(a[i], a[rnd(0, i + 1)]); }

int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}

template <class T, class S> pair<T, S> operator-(const pair<T, S> &x) { return pair<T, S>(-x.first, -x.second); }
template <class T, class S> pair<T, S> operator-(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi - y.fi, x.se - y.se); }
template <class T, class S> pair<T, S> operator+(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi + y.fi, x.se + y.se); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.fi, r.fi), min(l.se, r.se)); }
template <class T, class S> pair<T, S> operator+=(pair<T, S> &l, const pair<T, S> &r) { return l = l + r; }
template <class T, class S> pair<T, S> operator-=(pair<T, S> &l, const pair<T, S> &r) { return l = l - r; }
// 開閉
template <class T> bool intersect(const pair<T, T> &l, const pair<T, T> &r) { return (l.se < r.se ? r.fi < l.se : l.fi < r.se); }

template <class T> vector<T> &operator++(vector<T> &v) {
    fore(e, v) e++;
    return v;
}
template <class T> vector<T> operator++(vector<T> &v, int) {
    auto res = v;
    fore(e, v) e++;
    return res;
}
template <class T> vector<T> &operator--(vector<T> &v) {
    fore(e, v) e--;
    return v;
}
template <class T> vector<T> operator--(vector<T> &v, int) {
    auto res = v;
    fore(e, v) e--;
    return res;
}
template <class T> void connect(vector<T> &l, const vector<T> &r) { fore(e, r) l.eb(e); }
template <class T> vector<T> operator+(const vector<T> &l, const vector<T> &r) {
    vector<T> res(max(si(l), si(r)));
    rep(i, si(l)) res[i] += l[i];
    rep(i, si(r)) res[i] += r[i];
    return res;
}
template <class T> vector<T> operator-(const vector<T> &l, const vector<T> &r) {
    vector<T> res(max(si(l), si(r)));
    rep(i, si(l)) res[i] += l[i];
    rep(i, si(r)) res[i] -= r[i];
    return res;
}
template <class T> vector<T> &operator+=(const vector<T> &l, const vector<T> &r) {
    if(si(l) < si(r)) l.resize(si(r));
    rep(i, si(r)) l[i] += r[i];
    return l;
}
template <class T> vector<T> &operator-=(const vector<T> &l, const vector<T> &r) {
    if(si(l) < si(r)) l.resize(si(r));
    rep(i, si(r)) l[i] -= r[i];
    return l;
}
template <class T> vector<T> &operator+=(vector<T> &v, const T &x) {
    fore(e, v) e += x;
    return v;
}
template <class T> vector<T> &operator-=(vector<T> &v, const T &x) {
    fore(e, v) e -= x;
    return v;
}

template <typename T> struct edge {
    int from, to;
    T cost;
    int id;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id) {}
    constexpr bool operator<(const edge<T> &rhs) const noexcept { return cost < rhs.cost; }
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
    friend ostream operator<<(ostream &os, const edge &e) { return os << e.to; }
};
template <typename T> using Edges = vector<edge<T>>;

template <typename T = int> Edges<T> read_edges(int m, bool weighted = false) {
    Edges<T> res;
    res.reserve(m);
    for(int i = 0; i < m; i++) {
        int u, v, c = 0;
        scan(u), scan(v), u--, v--;
        if(weighted) scan(c);
        res.eb(u, v, c, i);
    }
    return res;
}

using Tree = vector<vector<int>>;
using Graph = vector<vector<int>>;
template <class T> using Wgraph = vector<vector<edge<T>>>;
Graph getG(int n, int m = -1, bool directed = false, int margin = 1) {
    Tree res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        cin >> a >> b;
        a -= margin, b -= margin;
        res[a].emplace_back(b);
        if(!directed) res[b].emplace_back(a);
    }
    return res;
}
Graph getTreeFromPar(int n, int margin = 1) {
    Graph res(n);
    for(int i = 1; i < n; i++) {
        int a;
        cin >> a;
        res[a - margin].emplace_back(i);
    }
    return res;
}
template <class T> Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) {
    Wgraph<T> res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        T c;
        scan(a), scan(b), scan(c);
        a -= margin, b -= margin;
        res[a].emplace_back(b, c);
        if(!directed) res[b].emplace_back(a, c);
    }
    return res;
}
void add(Graph &G, int x, int y) { G[x].eb(y), G[y].eb(x); }
template <class S, class T> void add(Wgraph<S> &G, int x, int y, T c) { G[x].eb(y, c), G[y].eb(x, c); }

#define TEST                                                                                                                                                   \
    INT(testcases);                                                                                                                                            \
    while(testcases--)

i128 abs(const i128 &x) { return x > 0 ? x : -x; }
istream &operator>>(istream &is, i128 &v) {
    string s;
    is >> s;
    v = 0;
    for(int i = 0; i < (int)s.size(); i++) {
        if(isdigit(s[i])) { v = v * 10 + s[i] - '0'; }
    }
    if(s[0] == '-') { v *= -1; }
    return is;
}

ostream &operator<<(ostream &os, const i128 &v) {
    if(v == 0) { return (os << "0"); }
    i128 num = v;
    if(v < 0) {
        os << '-';
        num = -num;
    }
    string s;
    for(; num > 0; num /= 10) { s.push_back((char)(num % 10) + '0'); }
    reverse(s.begin(), s.end());
    return (os << s);
}
namespace aux {
template <typename T, unsigned N, unsigned L> struct tp {
    static void output(std::ostream &os, const T &v) {
        os << std::get<N>(v) << (&os == &cerr ? ", " : " ");
        tp<T, N + 1, L>::output(os, v);
    }
};
template <typename T, unsigned N> struct tp<T, N, N> {
    static void output(std::ostream &os, const T &v) { os << std::get<N>(v); }
};
} // namespace aux
template <typename... Ts> std::ostream &operator<<(std::ostream &os, const std::tuple<Ts...> &t) {
    if(&os == &cerr) { os << '('; }
    aux::tp<std::tuple<Ts...>, 0, sizeof...(Ts) - 1>::output(os, t);
    if(&os == &cerr) { os << ')'; }
    return os;
}
template <typename T, typename S, typename U> std::ostream &operator<<(std::ostream &os, const priority_queue<T, S, U> &_pq) {
    auto pq = _pq;
    vector<T> res;
    while(!empty(pq)) res.emplace_back(pq.top()), pq.pop();
    return os << res;
}
template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &p) {
    if(&os == &cerr) { return os << "(" << p.first << ", " << p.second << ")"; }
    return os << p.first << " " << p.second;
}
template <class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, const Container &x) {
    bool f = true;
    if(&os == &cerr) os << "[";
    for(auto &y : x) {
        if(&os == &cerr)
            os << (f ? "" : ", ") << y;
        else
            os << (f ? "" : " ") << y;
        f = false;
    }
    if(&os == &cerr) os << "]";
    return os;
}

#define dump(...) static_cast<void>(0)
#define dbg(...) static_cast<void>(0)

void OUT() { cout << endl; }
template <class Head, class... Tail> void OUT(const Head &head, const Tail &...tail) {
    cout << head;
    if(sizeof...(tail)) cout << ' ';
    OUT(tail...);
}

template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
template <class T, class S> constexpr pair<T, S> inf<pair<T, S>> = {inf<T>, inf<S>};

template <class T> void OUT2(const T &t, T INF = inf<T>, T res = -1) { OUT(t != INF ? t : res); }
template <class T> void OUT2(vector<T> &v, T INF = inf<T>, T res = -1) {
    fore(e, v) if(e == INF) e = res;
    OUT(v);
    fore(e, v) if(e == res) e = INF;
}

template <class F> struct REC {
    F f;
    REC(F &&f_) : f(forward<F>(f_)) {}
    template <class... Args> auto operator()(Args &&...args) const { return f(*this, forward<Args>(args)...); }
};

template <class S> vector<pair<S, int>> runLength(const vector<S> &v) {
    vector<pair<S, int>> res;
    for(auto &e : v) {
        if(res.empty() or res.back().fi != e)
            res.eb(e, 1);
        else
            res.back().se++;
    }
    return res;
}
vector<pair<char, int>> runLength(const string &v) {
    vector<pair<char, int>> res;
    for(auto &e : v) {
        if(res.empty() or res.back().fi != e)
            res.eb(e, 1);
        else
            res.back().se++;
    }
    return res;
}

struct string_converter {
    char start = 0;
    char type(const char &c) const { return (islower(c) ? 'a' : isupper(c) ? 'A' : isdigit(c) ? '0' : 0); }
    int convert(const char &c) {
        if(!start) start = type(c);
        return c - start;
    }
    int convert(const char &c, const string &chars) { return chars.find(c); }
    template <typename T> auto convert(const T &v) {
        vector<decltype(convert(v[0]))> ret;
        ret.reserve(size(v));
        for(auto &&e : v) ret.emplace_back(convert(e));
        return ret;
    }
    template <typename T> auto convert(const T &v, const string &chars) {
        vector<decltype(convert(v[0], chars))> ret;
        ret.reserve(size(v));
        for(auto &&e : v) ret.emplace_back(convert(e, chars));
        return ret;
    }
    int operator()(const char &v, char s = 0) {
        start = s;
        return convert(v);
    }
    int operator()(const char &v, const string &chars) { return convert(v, chars); }
    template <typename T> auto operator()(const T &v, char s = 0) {
        start = s;
        return convert(v);
    }
    template <typename T> auto operator()(const T &v, const string &chars) { return convert(v, chars); }
} toint;

template <class T, class F> T bin_search(T ok, T ng, const F &f) {
    while(abs(ok - ng) > 1) {
        T mid = ok + ng >> 1;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
template <class T, class F> T bin_search_double(T ok, T ng, const F &f, int iter = 80) {
    while(iter--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(11);
    }
} setup_io;

#endif

#pragma endregion


#include <algorithm>
#include <cassert>
#include <limits>
#include <queue>
#include <vector>


#include <vector>

namespace atcoder {

namespace internal {

template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();
        pos = 0;
    }
    void pop() { pos++; }
};

}  // namespace internal

}  // namespace atcoder


namespace atcoder {

template <class Cap> struct mf_graph {
  public:
    mf_graph() : _n(0) {}
    explicit mf_graph(int n) : _n(n), g(n) {}

    int add_edge(int from, int to, Cap cap) {
        assert(0 <= from && from < _n);
        assert(0 <= to && to < _n);
        assert(0 <= cap);
        int m = int(pos.size());
        pos.push_back({from, int(g[from].size())});
        int from_id = int(g[from].size());
        int to_id = int(g[to].size());
        if (from == to) to_id++;
        g[from].push_back(_edge{to, to_id, cap});
        g[to].push_back(_edge{from, from_id, 0});
        return m;
    }

    struct edge {
        int from, to;
        Cap cap, flow;
    };

    edge get_edge(int i) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        auto _e = g[pos[i].first][pos[i].second];
        auto _re = g[_e.to][_e.rev];
        return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
    }
    std::vector<edge> edges() {
        int m = int(pos.size());
        std::vector<edge> result;
        for (int i = 0; i < m; i++) {
            result.push_back(get_edge(i));
        }
        return result;
    }
    void change_edge(int i, Cap new_cap, Cap new_flow) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        assert(0 <= new_flow && new_flow <= new_cap);
        auto& _e = g[pos[i].first][pos[i].second];
        auto& _re = g[_e.to][_e.rev];
        _e.cap = new_cap - new_flow;
        _re.cap = new_flow;
    }

    Cap flow(int s, int t) {
        return flow(s, t, std::numeric_limits<Cap>::max());
    }
    Cap flow(int s, int t, Cap flow_limit) {
        assert(0 <= s && s < _n);
        assert(0 <= t && t < _n);
        assert(s != t);

        std::vector<int> level(_n), iter(_n);
        internal::simple_queue<int> que;

        auto bfs = [&]() {
            std::fill(level.begin(), level.end(), -1);
            level[s] = 0;
            que.clear();
            que.push(s);
            while (!que.empty()) {
                int v = que.front();
                que.pop();
                for (auto e : g[v]) {
                    if (e.cap == 0 || level[e.to] >= 0) continue;
                    level[e.to] = level[v] + 1;
                    if (e.to == t) return;
                    que.push(e.to);
                }
            }
        };
        auto dfs = [&](auto self, int v, Cap up) {
            if (v == s) return up;
            Cap res = 0;
            int level_v = level[v];
            for (int& i = iter[v]; i < int(g[v].size()); i++) {
                _edge& e = g[v][i];
                if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
                Cap d =
                    self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
                if (d <= 0) continue;
                g[v][i].cap += d;
                g[e.to][e.rev].cap -= d;
                res += d;
                if (res == up) return res;
            }
            level[v] = _n;
            return res;
        };

        Cap flow = 0;
        while (flow < flow_limit) {
            bfs();
            if (level[t] == -1) break;
            std::fill(iter.begin(), iter.end(), 0);
            Cap f = dfs(dfs, t, flow_limit - flow);
            if (!f) break;
            flow += f;
        }
        return flow;
    }

    std::vector<bool> min_cut(int s) {
        std::vector<bool> visited(_n);
        internal::simple_queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int p = que.front();
            que.pop();
            visited[p] = true;
            for (auto e : g[p]) {
                if (e.cap && !visited[e.to]) {
                    visited[e.to] = true;
                    que.push(e.to);
                }
            }
        }
        return visited;
    }

  private:
    int _n;
    struct _edge {
        int to, rev;
        Cap cap;
    };
    std::vector<std::pair<int, int>> pos;
    std::vector<std::vector<_edge>> g;
};

}  // namespace atcoder


using namespace atcoder;

int main() {
    INT(n);
    VEC2(int, l, r, n);
    VEC(ll, w, n);
    w.insert(begin(w), 0);
    vector<pair<ll, vi>> v;
    v.reserve(ten(6));

    vi cnt(n + 1);
    r++;
    rep(i, n) rep(j, l[i], r[i]) cnt[j]++;

    auto id = iota(l);
    rearrange(id, l, r);

    vi a;
    REC([&](auto &&f, int x, int sum) -> void {
        if(sum == n) {
            ll c = 0;
            fore(e, a) c += w[e];
            v.eb(c, a);
            return;
        }
        if(sum + x <= n) {
            if(cnt[x] >= x) {
                a.eb(x);
                f(x, sum + x);
                a.pop_back();
            }
            f(x + 1, sum);
        } else {
            return;
        }
    })
    (1, 0);

    SORT(v);
    REV(v);

    dump(si(v));

    pqg<int> pq;
    fore(c, a, v) {
        bool flag = true;
        int j = 0;
        rep(i, si(a)) {
            while(j < n and l[j] <= a[i]) {
                pq.emplace(r[j]);
                j++;
            }
            rep(a[i]) {
                if(empty(pq) or pq.top() <= a[i]) {
                    flag = false;
                    break;
                }
                pq.pop();
            }
            if(!flag) break;
        }
        while(!empty(pq)) pq.pop();
        if(flag) {
            OUT(c);
            exit(0);
        }
    }
    OUT("impossible");
}

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

詳細信息

Test #1:

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

input:

3
2 3
1 2
2 2
4 5 100

output:

9

result:

ok single line: '9'

Test #2:

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

input:

3
1 3
3 3
2 3
1 1 100

output:

100

result:

ok single line: '100'

Test #3:

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

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

input:

3
2 3
1 2
2 2
-100 -200 100000

output:

-300

result:

ok single line: '-300'

Test #5:

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

input:

9
1 4
2 5
3 4
1 5
1 1
2 5
3 5
1 3
1 1
1 1 1 1 1 1 1 1 1

output:

6

result:

ok single line: '6'

Test #6:

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

input:

14
3 3
1 2
2 3
2 3
2 3
1 1
2 3
1 3
3 3
1 3
1 3
1 2
2 3
1 3
-9807452 -9610069 4156341 2862447 6969109 -7245265 -2653530 -5655094 6467527 -6872459 3971784 7312155 9766298 -2719573

output:

-16558567

result:

ok single line: '-16558567'

Test #7:

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

input:

14
1 2
1 4
2 3
3 5
4 5
2 5
2 4
2 4
1 2
3 4
1 5
2 4
1 1
4 5
-13763 -7354207 1096407 -9063321 -4824546 -6275546 1258145 -5272834 -8631107 3581157 2320771 -7714508 8446625 -6816167

output:

-2673021

result:

ok single line: '-2673021'

Test #8:

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

input:

14
2 3
4 4
1 7
3 6
3 4
1 1
1 4
4 7
3 7
1 7
2 3
6 6
1 1
3 6
2923142 1686477 640352 2848353 9202543 -4441381 4866381 -3610520 8124124 -1372894 1111310 -7538627 466143 9937961

output:

5939733

result:

ok single line: '5939733'

Test #9:

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

input:

14
1 7
1 2
8 8
1 1
7 8
6 9
7 8
1 4
6 9
3 3
1 1
3 7
5 8
4 8
-7139089 6365816 -9893288 5936146 -2803918 -4961415 1495365 -2564851 -2630365 -8608883 5813455 -4005459 -8844054 6703783

output:

impossible

result:

ok single line: 'impossible'

Test #10:

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

input:

14
6 13
3 7
2 13
6 8
4 5
12 13
3 10
4 11
2 14
3 4
5 13
10 14
10 14
3 12
-8599727 -1496394 855072 -7439122 -5170228 8009298 -250221 5841035 2949765 7166358 -3516548 -6851737 8173765 -917122

output:

impossible

result:

ok single line: 'impossible'

Test #11:

score: 0
Accepted
time: 349ms
memory: 104292kb

input:

60
21 34
13 34
48 49
31 42
5 6
16 30
1 25
35 37
3 14
3 32
25 54
2 41
24 44
27 52
26 55
8 35
31 47
41 42
4 35
53 59
13 19
11 51
36 48
5 59
40 44
28 50
5 51
37 53
50 60
14 50
22 58
20 50
20 21
5 20
19 55
5 45
19 35
7 29
5 53
25 33
19 51
37 41
13 29
12 24
13 40
10 22
1 5
22 32
14 42
11 41
16 60
35 43
3...

output:

impossible

result:

ok single line: 'impossible'

Test #12:

score: 0
Accepted
time: 332ms
memory: 98568kb

input:

60
4 11
1 7
8 24
2 18
11 26
6 18
5 26
5 11
6 21
17 30
9 22
1 29
7 14
9 18
23 26
3 28
3 14
4 16
7 18
2 3
8 8
10 20
8 29
5 28
5 7
16 19
16 18
8 11
5 28
12 21
8 20
8 27
9 23
15 28
1 4
6 27
10 15
10 20
2 7
4 21
9 23
23 25
20 23
19 29
16 25
12 15
3 27
3 9
1 26
9 11
12 14
14 24
16 22
7 7
9 26
24 29
3 27
1...

output:

impossible

result:

ok single line: 'impossible'

Test #13:

score: 0
Accepted
time: 434ms
memory: 77376kb

input:

60
2 4
15 18
1 17
3 10
11 19
3 14
14 14
9 10
9 15
1 17
10 17
3 9
4 10
6 10
7 14
3 20
20 20
5 14
1 9
3 17
10 14
3 13
8 15
9 13
5 9
2 16
4 9
9 19
13 18
4 20
8 19
13 18
9 11
11 14
8 17
7 11
1 11
5 7
10 12
3 8
8 18
9 20
11 19
1 16
1 17
3 20
3 3
2 10
7 7
4 18
8 16
5 7
16 20
1 5
10 15
9 11
2 6
11 19
6 16
...

output:

impossible

result:

ok single line: 'impossible'

Test #14:

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

input:

60
1 3
1 3
3 5
2 6
5 5
2 5
5 6
1 5
3 6
6 6
2 6
2 2
2 3
1 6
2 4
2 3
1 3
4 5
2 4
5 5
3 5
3 5
1 5
2 6
3 6
1 6
1 4
3 3
2 2
1 6
2 3
2 6
4 6
5 5
1 6
2 3
1 2
4 4
2 5
1 4
4 4
4 6
2 6
2 3
2 4
1 2
1 4
3 6
2 5
2 6
1 1
1 5
5 6
3 6
1 2
3 5
5 6
5 6
1 6
3 4
-9765941 -9284625 -9136963 -1872925 -9334679 -67293 96416...

output:

-87758107

result:

ok single line: '-87758107'

Test #15:

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

input:

60
1 1
1 4
2 2
3 4
1 2
1 2
1 4
2 3
1 4
1 2
4 4
1 3
2 4
2 2
2 3
2 4
1 4
3 4
1 2
3 3
2 3
1 1
2 4
2 4
2 4
1 2
1 2
3 3
3 4
2 3
1 3
2 4
1 2
1 3
1 2
3 4
2 2
2 4
1 3
1 1
2 4
2 3
2 3
4 4
1 2
1 4
1 2
2 4
2 3
4 4
2 4
3 4
3 4
1 1
2 3
3 4
2 4
2 3
3 4
2 2
-8959736 5094365 2567070 -9106790 9323252 -7495337 818129...

output:

67209846

result:

ok single line: '67209846'

Test #16:

score: 0
Accepted
time: 142ms
memory: 106684kb

input:

60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 ...

output:

154133500

result:

ok single line: '154133500'

Test #17:

score: 0
Accepted
time: 144ms
memory: 105792kb

input:

60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 ...

output:

281129340

result:

ok single line: '281129340'

Test #18:

score: 0
Accepted
time: 137ms
memory: 106308kb

input:

60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 ...

output:

191361510

result:

ok single line: '191361510'

Test #19:

score: 0
Accepted
time: 151ms
memory: 106756kb

input:

60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 ...

output:

-1693012

result:

ok single line: '-1693012'

Test #20:

score: 0
Accepted
time: 145ms
memory: 105632kb

input:

60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 ...

output:

-354498

result:

ok single line: '-354498'

Test #21:

score: 0
Accepted
time: 129ms
memory: 106240kb

input:

60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 ...

output:

178078620

result:

ok single line: '178078620'

Test #22:

score: 0
Accepted
time: 145ms
memory: 105864kb

input:

60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 60
1 ...

output:

267872880

result:

ok single line: '267872880'

Test #23:

score: 0
Accepted
time: 149ms
memory: 105852kb

input:

60
1 60
2 55
5 60
5 55
3 58
1 57
5 57
3 57
2 55
4 55
3 57
1 57
1 56
3 60
5 57
1 55
4 60
2 60
3 58
1 55
5 56
2 60
2 59
2 58
4 59
5 59
4 58
4 58
2 56
2 59
4 55
4 56
3 60
5 57
4 56
3 56
4 57
2 55
1 55
1 56
2 58
4 59
5 56
1 57
3 55
1 55
2 59
3 56
2 58
5 55
5 57
5 58
5 58
4 58
5 58
2 60
1 59
1 55
3 58
1 ...

output:

101249576

result:

ok single line: '101249576'

Test #24:

score: 0
Accepted
time: 154ms
memory: 106364kb

input:

60
4 57
2 57
3 56
5 52
2 59
9 50
4 60
7 52
3 57
4 56
7 59
1 52
8 59
7 53
1 50
4 56
9 52
6 54
5 53
3 55
7 52
2 56
4 57
1 54
2 51
8 58
7 50
8 52
4 53
4 50
3 52
2 51
7 58
9 59
2 54
3 56
8 53
8 59
1 55
4 58
4 56
5 50
4 57
3 50
3 56
3 59
2 50
10 52
10 53
8 60
8 50
4 51
6 55
3 54
3 51
10 53
1 58
6 54
8 54...

output:

84670208

result:

ok single line: '84670208'

Test #25:

score: 0
Accepted
time: 135ms
memory: 105552kb

input:

60
19 58
18 40
7 53
1 56
15 53
18 47
6 56
6 52
9 43
12 41
13 46
12 59
13 52
15 51
5 51
12 42
18 41
11 60
8 50
15 42
16 57
3 41
6 57
11 41
12 46
12 48
7 52
9 60
9 53
13 55
8 53
1 53
1 43
18 51
3 49
2 44
8 56
8 47
20 48
19 52
3 56
18 55
9 42
20 43
15 59
9 57
17 46
10 48
14 40
16 45
17 46
9 53
2 47
4 5...

output:

35924238

result:

ok single line: '35924238'

Test #26:

score: 0
Accepted
time: 158ms
memory: 105596kb

input:

60
8 44
25 53
22 41
14 38
9 40
8 36
4 44
13 52
12 55
19 40
16 55
4 55
22 51
12 57
16 45
11 48
18 55
11 35
13 39
8 52
20 42
15 47
2 57
15 36
9 48
23 52
5 60
20 56
4 35
14 44
1 57
8 46
3 53
12 55
21 44
14 60
17 47
3 57
10 58
1 43
2 39
4 43
19 51
10 48
19 56
17 45
22 36
14 58
9 52
20 58
3 41
2 38
3 36
...

output:

39803807

result:

ok single line: '39803807'

Test #27:

score: 0
Accepted
time: 139ms
memory: 106432kb

input:

60
1 52
5 45
2 53
2 59
5 53
2 26
2 56
2 27
2 24
5 31
5 24
4 46
4 42
2 35
2 44
5 52
4 27
1 36
1 47
3 38
1 27
4 38
4 37
3 50
3 40
4 44
1 57
4 48
1 28
2 39
1 47
2 37
1 31
5 29
3 35
3 54
1 55
4 30
5 44
2 54
5 33
2 31
3 49
3 28
3 33
1 58
5 36
4 22
3 33
4 32
1 30
1 54
5 28
5 50
2 43
5 35
4 37
1 44
3 20
1 ...

output:

232766818

result:

ok single line: '232766818'

Test #28:

score: 0
Accepted
time: 140ms
memory: 106304kb

input:

60
1 41
1 28
2 24
1 33
3 55
5 32
5 26
3 31
1 22
1 43
3 27
1 36
5 45
1 55
1 22
2 24
4 26
3 52
2 58
2 32
3 59
3 46
4 33
5 59
5 42
2 46
3 49
4 40
5 40
4 21
3 45
5 47
5 42
5 44
2 56
4 29
5 52
3 43
5 23
1 49
4 38
2 20
4 31
1 49
2 24
3 48
5 52
2 36
3 44
4 48
5 44
4 34
4 47
1 51
5 47
3 23
3 40
5 38
5 52
1 ...

output:

-2774013

result:

ok single line: '-2774013'

Test #29:

score: 0
Accepted
time: 138ms
memory: 105776kb

input:

60
5 33
4 48
3 44
3 21
1 51
2 56
5 30
4 33
1 31
5 43
1 47
5 23
5 23
1 47
1 27
2 51
2 58
5 33
4 53
5 36
2 42
4 43
2 51
3 52
1 22
3 49
5 30
2 39
2 47
2 56
4 35
4 20
5 50
1 22
2 35
4 28
5 25
2 45
3 23
2 37
2 27
4 47
3 41
2 40
2 32
3 37
5 31
1 55
1 25
4 34
5 37
4 31
3 37
3 56
4 56
5 28
4 59
1 50
4 43
4 ...

output:

-3135271

result:

ok single line: '-3135271'

Test #30:

score: 0
Accepted
time: 154ms
memory: 105624kb

input:

60
4 52
2 58
4 33
1 39
5 59
1 52
3 44
5 57
5 54
4 46
4 36
3 42
1 50
1 37
3 20
4 24
3 48
2 58
1 33
5 47
2 27
3 24
4 37
3 57
2 52
2 56
3 45
2 24
4 35
3 23
2 21
4 52
4 44
4 54
3 51
2 49
1 46
5 49
2 25
5 58
5 44
4 42
5 23
5 57
3 38
4 60
1 46
2 36
5 48
2 40
5 28
4 45
3 35
3 50
4 25
3 27
5 55
3 57
3 51
2 ...

output:

193174547

result:

ok single line: '193174547'

Test #31:

score: 0
Accepted
time: 159ms
memory: 105296kb

input:

60
2 33
2 52
5 45
1 49
3 33
5 39
3 22
5 22
1 44
5 31
4 37
2 28
5 26
2 56
2 40
1 45
5 27
1 46
1 52
2 59
2 49
4 38
1 50
3 60
1 32
1 22
2 57
2 58
4 21
3 46
4 31
3 50
5 31
4 35
3 38
2 41
3 37
4 40
2 46
3 55
5 31
5 34
1 31
5 55
3 29
5 48
3 22
1 32
2 57
2 43
3 24
3 59
3 31
5 51
5 31
2 24
2 43
1 23
2 30
4 ...

output:

202290067

result:

ok single line: '202290067'

Test #32:

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

input:

60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 60
60 ...

output:

2785355

result:

ok single line: '2785355'

Test #33:

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

input:

60
48 53
6 7
47 50
2 12
47 55
45 53
49 53
47 52
46 54
45 50
46 51
47 52
47 52
47 52
49 54
48 52
49 54
49 55
50 52
2 11
46 55
4 12
46 52
45 53
50 53
46 55
2 8
4 9
3 8
50 55
46 55
48 52
50 55
45 54
50 55
5 9
50 50
48 53
50 55
3 7
45 55
48 53
49 53
45 51
46 55
50 52
48 53
49 55
48 51
48 54
45 55
47 52
...

output:

6626637

result:

ok single line: '6626637'

Test #34:

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

input:

60
30 30
29 32
27 32
29 32
30 30
28 31
27 34
27 33
25 31
30 31
26 35
30 31
27 31
27 30
29 34
26 35
29 30
27 35
28 30
27 34
27 33
26 32
29 35
29 34
25 34
28 34
25 33
25 35
29 30
26 33
30 33
30 34
26 30
25 34
28 32
28 34
27 30
28 31
29 35
27 35
29 34
29 34
29 33
30 35
28 33
29 33
25 33
27 31
25 32
30 ...

output:

-1006632

result:

ok single line: '-1006632'

Test #35:

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

input:

60
26 34
30 34
26 31
30 33
25 32
30 32
27 32
25 30
30 31
25 33
28 31
28 33
30 33
28 35
25 34
29 34
30 30
30 35
25 35
28 35
26 31
26 35
28 31
26 34
25 34
29 31
25 31
28 33
27 34
27 33
26 32
29 34
29 30
30 30
27 32
30 31
28 33
28 30
27 33
25 32
27 30
25 34
28 30
26 33
29 32
29 34
26 34
28 33
26 32
25 ...

output:

-14968700

result:

ok single line: '-14968700'

Test #36:

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

input:

60
25 31
25 32
29 31
29 31
25 34
26 34
25 35
28 33
25 32
26 31
29 34
29 30
25 30
29 30
25 30
29 31
30 30
30 34
27 33
25 35
26 31
26 32
30 34
27 31
30 35
29 30
27 33
29 34
26 33
29 33
27 31
29 32
25 30
29 31
25 32
29 34
29 33
30 34
28 34
30 33
30 34
29 34
27 30
25 35
30 30
25 34
28 34
28 30
27 30
30 ...

output:

13397614

result:

ok single line: '13397614'

Test #37:

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

input:

60
19 23
20 20
16 25
20 24
20 22
19 23
19 20
20 21
18 20
16 20
15 25
15 24
17 21
16 25
20 25
19 20
19 25
16 25
19 23
18 21
18 24
19 23
19 20
18 25
18 23
16 20
17 24
17 23
17 23
19 23
19 20
17 22
17 20
20 25
18 20
18 24
18 23
18 25
16 22
17 23
19 20
20 25
16 23
16 25
17 25
17 20
20 25
16 23
18 23
17 ...

output:

21787020

result:

ok single line: '21787020'

Test #38:

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

input:

60
17 34
20 27
4 15
25 25
15 33
17 32
18 28
25 26
23 27
17 29
23 35
23 29
21 25
15 25
24 31
25 34
22 28
21 26
19 35
24 33
21 34
20 32
25 32
16 25
1 6
6 11
18 33
15 32
2 16
19 29
17 27
1 6
17 32
22 34
4 15
23 35
16 29
16 27
1 12
25 26
20 26
16 33
22 25
20 27
4 16
22 34
21 34
16 29
20 25
23 28
15 35
2...

output:

35420991

result:

ok single line: '35420991'

Test #39:

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

input:

60
11 20
14 16
12 15
10 14
13 16
14 17
11 14
11 17
14 16
12 15
10 17
13 19
5 9
10 18
15 19
9 15
8 11
10 13
10 17
9 14
7 12
9 13
11 16
7 15
7 12
7 11
9 14
12 17
6 11
9 13
10 18
13 18
8 10
9 14
8 12
9 13
12 14
7 12
7 15
4 14
11 15
14 19
12 16
10 11
8 14
11 15
4 14
8 13
12 16
12 15
10 16
9 15
13 17
14 ...

output:

11527150

result:

ok single line: '11527150'

Test #40:

score: 0
Accepted
time: 111ms
memory: 87360kb

input:

60
13 14
3 14
5 17
6 12
5 18
8 20
8 24
10 16
12 22
8 24
3 21
4 15
10 19
13 20
4 10
1 12
11 23
1 15
5 18
11 25
7 18
5 18
9 16
3 14
10 18
9 13
8 15
8 15
10 22
3 17
14 22
13 20
2 15
14 17
11 16
10 20
10 22
3 14
12 19
13 19
4 23
2 13
12 15
9 13
5 12
10 22
4 16
4 19
5 22
10 22
5 22
1 16
15 18
9 18
4 21
5...

output:

52962660

result:

ok single line: '52962660'

Test #41:

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

input:

60
7 7
7 8
9 10
7 9
8 9
7 9
6 7
6 7
10 10
7 7
9 11
10 11
7 9
9 10
9 11
8 9
10 10
10 11
10 10
9 10
10 10
10 11
10 10
7 9
10 10
10 11
7 7
10 11
9 11
6 8
10 10
8 9
8 9
7 7
8 9
9 10
7 7
8 9
7 8
6 7
10 10
7 8
8 8
9 11
10 10
9 10
6 7
10 11
7 9
6 7
7 8
9 10
10 11
10 11
9 10
9 11
7 9
8 8
6 7
9 11
9903784 75...

output:

7444173

result:

ok single line: '7444173'

Test #42:

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

input:

60
6 13
9 9
9 12
5 12
5 13
9 9
6 9
7 14
6 14
6 13
4 9
8 12
6 9
3 8
8 11
9 14
4 7
9 11
4 12
9 12
9 10
8 12
8 11
3 8
7 9
7 14
8 10
7 9
7 12
4 13
8 14
4 11
9 14
5 12
8 14
6 10
7 11
6 12
6 8
9 10
8 12
6 9
5 12
5 8
5 13
9 9
9 14
7 13
4 12
7 11
7 11
6 13
5 10
2 11
7 8
6 14
6 9
6 11
5 12
8 10
-7135770 -612...

output:

36399356

result:

ok single line: '36399356'

Test #43:

score: 0
Accepted
time: 120ms
memory: 78532kb

input:

60
9 15
6 12
4 11
4 15
6 15
3 16
6 18
6 17
2 18
4 18
6 12
2 18
9 14
1 10
1 10
8 16
4 16
3 19
4 13
6 15
6 18
5 17
10 19
1 11
4 16
4 19
6 19
6 19
1 17
2 14
7 17
2 15
6 11
4 13
5 10
3 20
6 15
2 17
2 14
8 12
10 20
3 17
5 9
4 13
8 19
2 18
1 15
7 18
9 9
6 10
1 4
2 17
5 12
6 8
2 16
3 12
9 14
6 15
8 13
2 14...

output:

108116159

result:

ok single line: '108116159'

Test #44:

score: 0
Accepted
time: 119ms
memory: 83820kb

input:

60
6 17
5 16
7 14
1 17
2 9
4 5
7 13
4 12
9 14
5 7
5 21
7 13
2 13
1 9
5 18
1 19
2 9
6 22
7 20
2 11
10 15
7 10
8 19
8 10
1 10
1 18
2 17
5 15
8 15
5 18
5 14
10 16
10 15
1 20
3 14
8 19
3 12
8 18
8 14
2 12
7 14
6 16
6 24
6 19
4 10
5 8
4 15
4 21
10 24
5 8
4 19
3 22
1 9
5 10
7 16
1 14
6 21
6 15
5 20
5 20
7...

output:

112278556

result:

ok single line: '112278556'

Test #45:

score: 0
Accepted
time: 128ms
memory: 92968kb

input:

60
2 13
8 21
8 29
3 11
2 10
1 15
4 24
1 24
3 6
7 16
5 29
2 15
3 26
6 19
7 17
10 14
4 20
9 9
7 10
10 19
5 24
8 23
4 16
5 16
6 12
4 26
2 29
8 22
2 15
4 11
8 29
4 20
8 22
4 14
1 17
8 11
9 18
4 15
10 30
9 25
10 21
7 14
9 14
2 26
6 13
3 18
5 18
8 16
9 9
6 29
2 16
10 14
1 24
3 27
1 10
6 14
2 25
5 10
4 15
...

output:

42617774

result:

ok single line: '42617774'

Test #46:

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

input:

60
4 4
4 4
4 4
4 4
3 3
5 5
3 3
4 4
4 4
3 3
5 5
5 5
4 4
5 5
5 5
5 5
3 3
4 4
4 4
3 3
4 4
4 4
4 4
3 3
5 5
3 3
4 4
4 4
4 4
3 3
5 5
5 5
4 4
4 4
5 5
4 4
4 4
5 5
5 5
4 4
5 5
4 4
3 3
4 4
5 5
4 4
4 4
4 4
5 5
5 5
4 4
4 4
4 4
5 5
3 3
5 5
5 5
3 3
5 5
3 3
2902337 6482772 -92449 1451420 -7023253 8460311 -7289352 ...

output:

-18302868

result:

ok single line: '-18302868'

Test #47:

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

input:

60
3 4
4 5
5 6
2 3
3 4
4 5
3 3
4 4
3 4
3 4
3 5
5 6
2 3
5 5
5 6
4 5
3 4
3 3
3 4
5 6
4 5
3 5
5 5
5 5
3 5
4 6
3 5
3 4
3 3
4 4
4 5
4 4
3 5
2 4
5 6
1 1
5 5
4 6
3 4
4 4
4 4
4 6
4 5
3 5
4 5
2 3
3 5
4 5
3 4
4 6
3 4
2 4
3 3
4 4
5 5
4 5
3 4
4 5
5 5
4 5
7873169 -2034482 -5068361 -5262215 -6149325 5383141 84508...

output:

-55972594

result:

ok single line: '-55972594'

Test #48:

score: 0
Accepted
time: 15ms
memory: 15396kb

input:

60
2 6
2 6
1 6
2 6
3 8
3 5
2 5
1 3
3 6
2 3
3 7
4 8
1 4
2 3
3 6
3 4
3 5
5 8
1 3
4 5
2 8
4 5
2 6
1 6
1 4
2 6
5 6
3 5
3 6
1 4
2 3
2 4
2 7
2 8
4 5
2 3
3 5
2 5
5 7
5 6
3 5
1 5
2 8
5 6
3 7
1 4
3 7
4 8
1 6
2 3
1 5
5 5
4 7
5 5
4 8
2 4
4 5
4 6
3 5
2 3
-5678547 9840116 -8656673 156201 -9471511 -762354 -956848...

output:

129439723

result:

ok single line: '129439723'

Test #49:

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

input:

60
3 7
3 7
1 8
3 10
3 3
3 3
4 8
3 5
3 5
3 10
1 6
2 5
3 7
3 5
2 9
2 5
4 5
2 7
1 8
1 8
3 10
4 7
3 7
4 9
2 5
2 9
4 8
2 5
2 4
2 11
5 6
4 6
4 10
2 8
2 5
1 7
2 3
3 6
2 4
1 8
2 6
3 5
2 11
1 8
2 11
4 8
2 10
1 9
2 5
3 11
4 9
3 11
3 9
2 6
5 6
2 4
1 8
2 7
5 10
3 11
-4317498 4813470 239792 -7271480 9176085 -837...

output:

117420557

result:

ok single line: '117420557'

Test #50:

score: 0
Accepted
time: 92ms
memory: 72844kb

input:

60
3 19
2 5
1 4
2 17
5 7
2 7
4 19
3 5
1 13
5 18
2 7
3 11
1 9
5 8
1 3
3 9
4 6
2 11
2 10
1 11
2 7
3 7
1 20
3 14
4 12
2 7
5 17
4 9
2 4
1 11
1 8
1 10
1 9
4 17
2 19
2 5
2 5
2 5
4 10
2 10
5 5
4 20
3 18
5 11
2 3
1 4
3 14
2 20
4 5
2 19
4 4
3 9
1 20
4 8
1 16
1 14
1 16
2 10
3 11
3 18
-7004406 -4767571 1639847...

output:

33678782

result:

ok single line: '33678782'

Test #51:

score: 0
Accepted
time: 4ms
memory: 13952kb

input:

60
5 11
4 7
5 8
3 11
4 6
3 3
5 10
4 9
4 14
5 14
3 13
5 12
5 13
5 6
4 11
5 11
4 11
3 10
5 12
4 10
5 10
5 10
5 7
3 5
4 11
4 6
5 13
5 11
5 13
5 7
5 7
5 10
3 12
4 7
5 12
4 12
4 7
3 10
3 10
5 8
5 13
5 6
5 9
1 1
4 13
5 9
4 11
5 6
5 10
4 8
4 5
5 7
4 6
4 9
4 14
4 4
5 15
5 12
3 12
5 14
-1055954 -5486490 7038...

output:

74766831

result:

ok single line: '74766831'

Test #52:

score: 0
Accepted
time: 130ms
memory: 86848kb

input:

60
4 23
4 5
3 16
4 20
3 16
3 24
2 17
4 15
5 21
4 11
4 28
5 12
4 4
3 12
2 11
2 8
4 25
4 9
3 9
3 18
5 12
3 24
4 15
5 25
4 26
4 26
4 28
5 5
4 16
4 6
4 23
2 16
5 11
5 16
5 16
3 10
3 16
4 8
3 4
5 20
4 19
5 5
3 15
5 22
4 24
4 8
3 26
3 6
5 14
3 16
5 13
4 6
4 4
4 19
4 19
1 7
4 15
3 26
3 25
1 5
2746929 58110...

output:

66104265

result:

ok single line: '66104265'

Test #53:

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

input:

1
1 1
-10000000

output:

-10000000

result:

ok single line: '-10000000'

Test #54:

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

input:

1
1 1
10000000

output:

10000000

result:

ok single line: '10000000'

Test #55:

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

input:

1
1 1
-1

output:

-1

result:

ok single line: '-1'

Test #56:

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

input:

1
1 1
0

output:

0

result:

ok single line: '0'

Test #57:

score: 0
Accepted
time: 14ms
memory: 15984kb

input:

60
1 6
2 5
1 1
3 3
1 3
2 2
1 3
1 2
1 7
1 2
2 2
2 6
4 5
1 6
2 10
1 4
2 8
1 1
7 11
4 4
1 5
1 5
1 4
1 2
4 7
1 2
2 2
2 2
2 3
2 6
2 2
2 3
1 6
3 7
5 7
5 7
3 4
1 6
1 10
1 4
1 2
1 5
1 11
6 9
2 3
1 2
1 2
1 10
1 2
2 3
2 3
2 2
1 4
4 4
2 2
3 4
5 7
1 10
2 3
1 7
4844423 8958258 3565244 -1792980 -462605 -4408861 -...

output:

215303015

result:

ok single line: '215303015'

Test #58:

score: 0
Accepted
time: 207ms
memory: 29056kb

input:

60
1 7
3 10
2 4
4 12
9 14
2 3
3 3
2 3
6 9
11 11
4 5
4 4
4 6
2 2
4 10
2 4
1 2
3 7
7 8
1 4
5 9
1 6
2 11
2 2
2 2
1 7
4 8
3 6
5 7
1 4
4 5
1 1
1 4
1 2
1 5
1 3
1 4
6 7
1 9
1 13
1 3
1 2
2 15
2 3
5 6
2 11
1 1
1 5
4 8
3 3
8 10
1 1
1 12
3 7
2 7
1 3
4 10
2 3
2 4
1 3
3228021 -6123699 7168820 -329946 1163554 725...

output:

impossible

result:

ok single line: 'impossible'

Test #59:

score: 0
Accepted
time: 37ms
memory: 29340kb

input:

60
5 9
2 2
1 13
1 2
1 2
9 10
3 5
1 3
1 11
2 3
4 10
1 1
4 7
8 10
8 9
1 2
7 12
2 7
1 4
1 10
5 8
2 8
1 6
1 5
1 7
1 3
1 3
2 5
1 10
4 9
4 5
2 5
1 1
1 5
4 11
2 4
2 4
3 4
1 1
3 3
6 7
2 2
2 2
2 5
3 11
1 1
2 2
4 6
1 1
7 8
1 5
1 10
1 3
3 3
1 1
2 7
4 5
3 3
1 8
5 10
-126737 -8297654 3259252 6111803 1693231 -665...

output:

37897439

result:

ok single line: '37897439'

Test #60:

score: 0
Accepted
time: 54ms
memory: 36012kb

input:

60
1 3
4 6
8 15
2 8
2 2
2 11
3 3
3 5
9 14
5 11
2 5
4 6
3 10
1 16
6 7
5 6
3 5
1 2
5 10
1 4
7 14
1 6
4 6
5 11
2 6
5 11
4 5
1 11
5 6
2 2
3 11
3 11
1 11
4 4
5 6
3 6
8 8
2 4
2 9
1 1
6 7
2 5
10 10
1 4
1 12
3 3
5 8
3 4
2 9
3 8
2 5
5 11
3 4
2 4
1 16
4 5
2 4
2 12
3 6
2 13
9643492 -4432745 3565467 9943593 -60...

output:

153207236

result:

ok single line: '153207236'

Test #61:

score: 0
Accepted
time: 44ms
memory: 37232kb

input:

60
2 4
4 14
1 3
4 6
3 3
2 2
1 2
2 4
8 13
3 4
6 7
2 6
11 15
2 2
3 7
9 11
1 6
4 9
2 2
6 8
3 6
3 6
1 10
1 7
3 10
1 1
6 13
2 5
1 6
2 2
1 13
3 5
3 5
1 10
5 9
1 3
4 4
2 5
5 5
6 7
3 13
2 3
1 15
2 7
1 2
2 3
5 20
5 7
2 10
2 3
9 15
1 1
1 2
1 5
4 11
3 6
1 13
2 6
4 6
11 13
-3229162 641141 967562 5991113 955582 ...

output:

28903238

result:

ok single line: '28903238'

Test #62:

score: 0
Accepted
time: 137ms
memory: 101976kb

input:

60
4 8
4 17
8 12
9 26
2 14
5 48
8 22
1 14
6 27
8 57
1 12
5 39
8 18
3 8
4 8
4 58
6 34
6 32
8 9
4 27
8 37
6 6
3 46
5 19
1 53
3 8
4 7
8 25
7 8
2 40
4 24
1 47
4 5
10 41
3 30
4 14
5 40
6 29
1 32
9 14
5 9
1 18
1 4
7 22
6 12
7 42
6 22
8 10
6 7
7 29
1 49
7 39
5 31
2 49
4 46
7 21
3 51
8 36
9 39
3 14
-4341326...

output:

55144633

result:

ok single line: '55144633'

Test #63:

score: 0
Accepted
time: 156ms
memory: 102728kb

input:

60
1 10
3 7
10 26
5 47
10 22
10 29
1 40
5 17
5 34
6 37
2 14
5 38
6 7
3 13
3 38
8 32
2 9
2 5
4 25
1 48
10 20
1 36
5 20
3 6
9 16
10 38
10 34
8 37
8 33
2 36
2 43
10 15
3 42
2 3
9 27
9 43
5 21
4 18
7 16
3 4
6 35
5 31
8 12
4 21
5 33
6 27
4 19
4 19
7 45
3 6
8 32
1 30
3 5
1 15
6 10
1 4
1 35
5 27
8 40
2 2
5...

output:

67431765

result:

ok single line: '67431765'

Test #64:

score: 0
Accepted
time: 126ms
memory: 95392kb

input:

60
6 15
7 23
6 12
1 33
9 25
5 7
9 25
6 26
8 21
8 33
5 27
8 27
5 7
4 8
4 19
7 13
10 17
2 12
1 17
10 27
4 16
7 21
8 11
5 6
3 6
4 5
10 18
8 27
7 22
3 5
6 23
2 31
8 31
1 13
7 28
1 9
7 28
7 14
10 20
8 24
2 12
4 20
9 18
5 8
3 34
7 9
9 23
10 21
7 10
8 23
8 34
7 14
10 13
6 7
5 14
7 28
8 19
6 9
3 19
1 20
384...

output:

58924621

result:

ok single line: '58924621'

Test #65:

score: 0
Accepted
time: 132ms
memory: 90160kb

input:

60
7 26
5 8
6 27
1 23
1 29
10 24
1 11
4 26
1 3
3 7
9 30
8 8
8 29
6 19
7 27
3 12
12 20
10 10
12 26
10 11
5 28
12 16
5 20
2 12
1 30
10 17
2 20
11 16
3 20
5 18
8 10
1 15
3 4
1 18
8 26
6 9
2 3
8 24
2 3
1 9
6 27
6 21
3 5
10 11
8 14
4 5
5 7
3 3
10 11
10 10
9 18
7 17
10 23
5 10
8 11
12 12
8 14
2 4
10 12
8 ...

output:

58334518

result:

ok single line: '58334518'

Test #66:

score: 0
Accepted
time: 126ms
memory: 87812kb

input:

60
4 13
8 25
8 10
5 8
4 4
8 15
7 7
8 23
7 14
7 21
8 10
6 8
6 20
1 19
2 22
1 13
9 15
1 9
9 24
9 22
9 17
3 6
4 13
6 23
7 12
3 17
2 22
6 23
2 13
9 16
1 16
9 20
6 17
9 18
5 19
3 14
3 6
6 15
1 15
6 9
5 13
9 25
2 3
7 20
6 17
3 11
2 18
8 9
5 15
5 6
9 20
5 15
9 16
6 16
7 13
8 19
2 19
7 14
7 22
2 3
7806876 6...

output:

88264142

result:

ok single line: '88264142'

Test #67:

score: 0
Accepted
time: 143ms
memory: 82604kb

input:

60
3 22
1 15
4 4
9 17
7 14
7 24
8 17
2 8
8 16
8 15
2 13
1 20
2 8
8 12
6 24
4 7
5 23
3 26
5 24
3 19
1 18
4 20
7 23
9 12
9 14
7 7
3 13
3 13
6 18
5 9
2 13
1 21
5 10
5 23
5 6
3 7
4 23
6 26
1 13
7 25
4 6
1 8
3 11
3 4
4 6
7 15
6 21
5 16
3 8
5 8
1 22
7 13
3 9
8 17
3 3
2 25
4 5
1 12
5 6
2 11
6685926 8572594...

output:

97785281

result:

ok single line: '97785281'

Test #68:

score: 0
Accepted
time: 108ms
memory: 73092kb

input:

60
9 14
1 14
3 8
3 16
1 11
7 19
3 7
5 11
3 11
5 10
2 13
5 9
6 10
2 14
4 19
6 8
5 7
5 5
6 18
9 19
8 18
4 10
11 18
6 10
10 20
5 6
1 13
1 5
4 6
8 17
6 12
8 11
1 17
3 5
6 8
6 8
3 12
8 10
8 10
10 16
4 18
10 11
5 10
7 16
9 11
11 13
9 18
11 17
5 16
3 13
9 11
3 10
1 11
9 18
8 13
5 10
10 20
2 6
9 19
2 12
795...

output:

112064463

result:

ok single line: '112064463'

Test #69:

score: 0
Accepted
time: 140ms
memory: 105380kb

input:

60
4 22
4 21
4 42
5 48
5 57
5 11
4 23
3 20
2 55
4 23
6 9
1 29
5 37
3 19
2 48
6 54
4 15
3 29
4 47
4 29
4 56
2 16
5 47
1 45
6 30
3 39
4 18
5 23
4 25
4 11
6 55
2 46
1 8
1 20
2 29
2 17
1 27
1 43
3 49
5 22
5 16
2 35
1 44
3 28
2 39
2 54
3 37
6 53
1 26
4 33
3 32
2 56
5 48
5 57
1 20
5 52
1 19
4 23
6 50
1 54...

output:

35711630

result:

ok single line: '35711630'

Test #70:

score: 0
Accepted
time: 135ms
memory: 105100kb

input:

60
1 57
5 28
5 16
8 36
1 35
7 36
5 54
3 42
6 57
3 33
2 8
1 20
7 10
3 9
4 38
2 45
5 57
6 18
3 41
7 35
2 17
6 30
2 49
2 8
7 46
4 11
1 35
4 43
5 40
8 53
1 32
4 49
4 33
5 44
4 52
5 25
5 28
3 24
1 29
7 53
3 30
2 55
3 54
4 17
5 57
4 45
1 6
4 50
4 20
3 44
6 21
1 43
3 53
6 8
2 5
3 49
1 34
7 53
6 23
3 39
-41...

output:

56139879

result:

ok single line: '56139879'

Test #71:

score: 0
Accepted
time: 128ms
memory: 105956kb

input:

60
3 55
1 44
1 30
5 59
2 7
2 9
3 32
6 44
1 22
3 52
1 23
6 54
4 23
4 23
3 8
5 35
5 28
1 7
4 52
4 39
4 53
1 8
1 50
4 59
6 44
4 25
4 13
3 31
5 12
3 32
2 15
4 15
3 36
1 16
4 51
1 44
5 60
4 29
4 60
4 40
1 11
3 20
5 52
6 31
5 21
3 15
6 21
1 20
2 8
1 26
2 28
1 45
4 55
4 41
5 32
2 45
1 42
2 27
6 33
4 30
-54...

output:

96501164

result:

ok single line: '96501164'

Test #72:

score: 0
Accepted
time: 146ms
memory: 105328kb

input:

60
6 10
6 49
4 11
2 29
3 18
2 26
2 46
4 10
2 9
5 17
3 32
4 29
2 24
6 38
5 45
1 11
3 15
2 53
4 50
5 19
2 55
2 29
4 13
1 41
6 56
2 20
6 13
4 49
2 56
1 41
2 11
3 35
1 16
6 35
6 17
1 43
4 38
1 51
6 16
3 37
1 22
5 22
5 37
1 14
5 32
5 51
3 13
3 24
3 28
4 25
6 36
4 10
2 8
1 56
6 23
6 21
5 30
2 42
1 13
6 40...

output:

166647004

result:

ok single line: '166647004'

Test #73:

score: 0
Accepted
time: 146ms
memory: 105072kb

input:

60
4 46
1 50
1 8
4 57
1 40
4 12
1 43
3 45
3 31
1 11
4 17
2 5
1 34
5 50
5 20
4 28
2 37
3 34
3 34
4 39
3 27
5 15
5 14
3 19
4 30
2 17
4 8
2 29
5 33
2 30
1 4
2 36
1 49
2 50
4 25
2 52
5 28
4 40
3 35
3 16
2 37
5 24
5 39
1 6
1 56
3 37
1 19
3 38
2 10
1 17
4 33
5 51
2 26
4 53
2 52
3 48
4 38
3 23
3 26
3 44
-2...

output:

136750820

result:

ok single line: '136750820'

Test #74:

score: 0
Accepted
time: 130ms
memory: 106300kb

input:

60
4 28
1 34
2 45
7 36
5 32
4 31
8 37
3 19
11 45
8 33
3 51
3 58
3 57
6 44
1 35
2 58
12 40
9 50
8 47
5 32
2 25
11 55
7 58
17 46
2 57
1 54
7 54
8 20
6 57
4 37
1 45
5 41
2 54
1 36
3 22
1 35
10 53
8 30
2 43
2 42
2 37
5 41
2 24
6 48
4 29
1 44
4 57
3 36
6 41
1 37
4 43
2 52
3 40
6 53
7 18
5 46
13 58
1 42
2...

output:

64952118

result:

ok single line: '64952118'

Test #75:

score: 0
Accepted
time: 137ms
memory: 105448kb

input:

60
2 36
3 53
1 50
3 54
7 56
2 49
4 38
6 54
6 40
8 33
3 51
3 58
7 50
6 44
2 42
9 59
3 42
9 50
8 47
1 40
2 48
11 55
5 41
2 31
2 57
1 54
7 54
4 44
6 57
4 37
4 40
5 41
6 43
4 48
7 43
1 35
1 44
3 39
2 43
12 34
8 60
5 41
7 43
6 48
1 46
1 44
4 57
3 36
6 41
2 60
4 43
8 56
3 40
1 33
10 31
5 46
13 58
1 42
2 5...

output:

121501608

result:

ok single line: '121501608'

Test #76:

score: 0
Accepted
time: 135ms
memory: 105212kb

input:

60
8 43
1 60
1 45
7 36
3 58
6 56
2 50
1 58
2 54
1 24
3 10
3 40
1 16
1 32
3 22
8 33
4 56
3 21
1 31
3 38
1 19
1 37
2 23
2 52
4 53
3 20
3 45
3 53
1 47
1 42
2 40
2 53
1 59
7 38
7 60
3 11
2 44
2 43
2 22
2 58
2 44
1 60
1 46
1 54
1 46
5 47
2 46
1 36
1 44
1 50
1 15
1 1
1 31
3 31
1 18
1 36
1 12
1 11
1 20
1 5...

output:

193009164

result:

ok single line: '193009164'

Test #77:

score: 0
Accepted
time: 139ms
memory: 105464kb

input:

60
2 53
1 60
1 45
1 4
3 58
2 15
2 50
1 58
2 54
1 24
1 1
3 40
1 16
1 32
3 22
4 23
4 56
3 21
1 31
3 38
1 19
1 37
2 23
2 52
4 53
3 20
3 45
3 53
1 47
1 42
1 26
2 53
1 59
1 30
1 50
1 22
2 44
2 43
2 22
2 58
2 44
1 60
1 46
1 54
1 46
5 47
2 46
1 36
1 44
1 50
1 15
1 1
1 31
2 12
1 18
1 36
1 12
1 11
1 20
1 57
...

output:

208517940

result:

ok single line: '208517940'

Test #78:

score: 0
Accepted
time: 619ms
memory: 103796kb

input:

60
7 49
7 8
10 11
6 25
6 26
3 17
6 23
4 31
15 44
9 21
2 14
4 34
7 55
4 52
1 35
4 4
3 3
6 6
1 59
9 10
6 33
3 59
5 39
5 42
12 19
1 31
6 51
2 59
4 40
1 31
11 13
4 50
7 20
1 46
3 12
4 52
8 9
3 39
7 22
5 5
5 31
5 14
7 30
4 51
13 16
3 12
6 12
2 10
1 46
6 42
2 14
5 7
2 2
6 23
7 18
7 24
4 15
6 31
1 47
3 43
...

output:

impossible

result:

ok single line: 'impossible'

Test #79:

score: 0
Accepted
time: 629ms
memory: 104888kb

input:

60
7 49
7 8
10 11
6 25
6 26
3 17
6 23
4 31
15 44
9 21
2 14
4 34
7 55
4 52
1 35
4 4
3 3
6 6
1 59
9 10
6 33
3 59
5 39
5 42
12 19
1 31
6 51
2 59
4 40
1 31
11 13
4 50
7 20
1 46
3 12
4 52
8 9
3 39
7 22
5 5
5 55
5 14
7 30
4 51
13 16
3 12
6 12
2 10
1 46
6 42
2 14
5 7
2 2
6 23
7 18
7 24
4 15
6 31
1 47
3 43
...

output:

impossible

result:

ok single line: 'impossible'

Test #80:

score: 0
Accepted
time: 645ms
memory: 104212kb

input:

60
7 49
7 8
10 11
6 25
6 26
3 17
6 23
4 31
15 44
9 21
2 14
4 34
7 55
4 52
1 35
4 4
3 3
6 6
1 59
9 10
6 33
3 59
5 39
5 42
12 19
1 31
6 51
2 59
4 40
1 31
11 13
4 50
7 20
1 46
3 12
4 52
8 9
3 39
7 22
5 5
5 31
5 14
7 30
4 51
13 16
3 12
6 12
2 10
1 46
6 42
2 14
5 7
2 2
6 23
7 18
7 24
4 15
6 31
1 47
3 43
...

output:

impossible

result:

ok single line: 'impossible'

Test #81:

score: 0
Accepted
time: 597ms
memory: 102988kb

input:

60
7 45
7 8
10 11
6 25
6 26
3 17
6 23
4 49
15 44
9 21
2 14
4 34
7 55
4 52
1 35
4 4
3 3
6 6
1 59
9 10
6 33
3 59
5 39
5 42
12 19
1 31
6 51
2 59
4 40
1 31
11 13
4 50
7 20
1 46
3 12
4 52
8 9
3 39
7 22
5 5
5 31
5 14
7 30
4 51
13 16
3 12
6 12
2 10
1 46
6 42
2 14
5 7
2 2
6 23
7 18
7 24
4 15
6 31
1 47
3 43
...

output:

impossible

result:

ok single line: 'impossible'

Test #82:

score: 0
Accepted
time: 620ms
memory: 103988kb

input:

60
7 49
7 8
10 11
6 25
6 26
3 17
6 23
4 31
15 44
9 21
2 14
4 34
7 55
4 52
1 35
4 4
3 3
6 6
1 59
9 10
6 33
3 59
5 39
5 42
12 19
1 31
6 51
2 59
4 40
1 31
11 13
4 50
7 20
1 46
3 12
4 52
8 9
3 39
7 22
5 5
5 31
5 14
7 30
4 51
13 16
3 12
6 12
2 10
1 46
6 42
2 14
5 7
2 2
6 23
7 18
7 24
4 15
6 31
1 47
3 43
...

output:

impossible

result:

ok single line: 'impossible'

Test #83:

score: 0
Accepted
time: 138ms
memory: 105476kb

input:

60
2 47
5 50
2 37
7 36
7 56
5 42
4 38
6 54
6 40
6 38
3 51
3 58
5 40
6 44
3 45
1 44
2 35
9 50
8 47
7 45
2 48
6 53
7 57
3 36
2 57
1 54
7 54
4 44
6 57
7 40
4 40
1 36
2 54
1 36
2 47
1 35
1 44
3 39
3 43
12 34
8 48
5 41
7 34
6 48
1 46
1 44
4 45
3 36
6 41
5 45
4 53
7 55
2 45
11 39
10 31
5 46
13 58
1 42
2 5...

output:

96758133

result:

ok single line: '96758133'

Test #84:

score: 0
Accepted
time: 139ms
memory: 105588kb

input:

60
1 49
1 60
1 45
1 57
1 51
1 49
1 57
1 58
1 59
1 24
1 1
1 56
1 28
1 32
1 49
1 49
3 50
1 60
1 50
1 42
1 33
1 50
1 50
1 48
3 60
1 54
1 56
1 54
1 47
1 42
1 52
1 51
1 59
1 45
1 50
1 30
1 51
1 49
1 38
1 44
1 45
1 60
1 46
1 54
1 46
1 52
1 50
1 36
1 44
1 57
3 55
1 1
1 31
1 57
1 48
1 36
1 40
1 42
1 30
1 57...

output:

109906392

result:

ok single line: '109906392'

Test #85:

score: 0
Accepted
time: 136ms
memory: 106364kb

input:

60
1 58
1 60
1 60
1 59
1 59
1 49
1 60
1 58
1 59
2 56
1 1
1 59
1 54
1 31
1 56
1 57
1 29
1 60
1 58
1 56
1 33
1 56
1 60
1 60
1 50
1 59
1 60
1 54
1 59
1 60
1 58
1 60
1 59
1 30
1 57
1 30
1 57
1 60
1 35
1 60
1 58
1 60
1 60
1 54
1 59
1 60
1 59
1 56
2 56
1 60
1 60
1 1
1 31
1 60
1 29
1 60
1 60
1 58
1 30
1 57...

output:

77646204

result:

ok single line: '77646204'

Test #86:

score: 0
Accepted
time: 136ms
memory: 105640kb

input:

60
1 58
1 60
1 60
1 59
1 59
1 54
1 60
1 60
1 59
2 56
1 1
1 59
1 54
1 31
1 56
1 57
1 29
1 60
1 58
1 56
1 33
1 60
1 60
1 60
1 50
1 59
1 60
1 54
1 59
1 60
1 58
1 60
1 59
1 30
1 57
1 50
1 57
1 60
1 35
1 60
1 58
1 60
1 60
1 54
1 59
1 60
1 59
1 56
2 56
1 60
1 60
1 1
1 31
1 60
1 29
1 60
1 60
1 58
1 30
1 57...

output:

219296961

result:

ok single line: '219296961'

Test #87:

score: 0
Accepted
time: 139ms
memory: 105632kb

input:

60
1 58
1 60
1 60
1 59
1 59
2 60
1 60
1 60
1 59
2 56
1 1
1 59
1 54
1 31
1 56
1 59
1 29
1 60
1 58
1 56
1 33
1 60
1 60
1 60
1 50
1 59
1 60
1 54
1 59
1 60
1 58
1 60
1 59
1 30
1 57
1 50
1 57
1 60
1 35
1 60
1 58
1 60
1 60
1 54
1 59
1 60
1 59
1 56
1 59
1 60
1 60
1 1
1 31
1 60
1 29
1 60
1 60
1 58
1 30
1 57...

output:

104737366

result:

ok single line: '104737366'

Test #88:

score: 0
Accepted
time: 137ms
memory: 105576kb

input:

60
2 47
3 53
2 51
7 55
7 56
5 54
4 55
6 54
6 49
6 56
4 55
3 58
5 47
7 54
2 50
1 57
2 51
9 50
8 60
1 49
2 56
6 53
7 57
3 60
2 57
1 54
7 54
4 58
6 57
7 55
1 47
5 49
2 54
4 53
7 52
1 49
1 56
3 56
1 58
12 49
3 53
5 45
7 57
6 48
1 58
1 52
4 57
3 52
6 49
5 54
4 53
7 55
3 59
11 58
10 48
5 52
13 58
1 54
2 5...

output:

78379727

result:

ok single line: '78379727'

Test #89:

score: 0
Accepted
time: 122ms
memory: 106172kb

input:

60
2 47
3 53
2 51
7 55
7 56
5 54
4 55
6 54
6 49
6 56
4 55
3 58
5 47
7 54
2 50
1 57
2 51
9 50
8 60
1 49
2 56
6 53
7 57
3 60
2 57
1 54
7 54
4 58
6 57
7 55
1 58
5 49
2 54
4 53
7 52
1 49
1 56
3 56
1 58
12 49
3 53
5 45
7 57
6 52
1 58
1 52
4 57
3 52
6 49
5 54
4 53
7 55
3 59
11 54
10 53
5 52
13 58
1 54
2 5...

output:

70922457

result:

ok single line: '70922457'

Test #90:

score: 0
Accepted
time: 145ms
memory: 105504kb

input:

60
2 47
3 53
2 51
7 55
7 56
5 54
4 55
6 54
6 49
6 56
4 55
3 58
5 47
7 54
2 50
1 57
2 51
9 50
8 60
1 53
2 56
6 53
7 57
3 60
2 57
1 54
7 54
4 58
6 57
7 55
1 58
5 49
2 54
4 53
7 52
1 49
1 56
3 56
1 58
12 49
3 53
5 45
7 57
6 52
1 58
1 52
4 57
3 52
6 49
5 60
4 53
7 55
3 59
11 58
10 53
5 52
13 58
1 54
2 5...

output:

86159811

result:

ok single line: '86159811'

Test #91:

score: 0
Accepted
time: 144ms
memory: 106504kb

input:

60
2 47
3 53
2 51
7 55
7 56
5 54
4 55
6 54
6 53
6 56
4 55
3 58
5 47
7 54
2 50
1 57
2 51
9 60
8 60
1 53
2 56
6 53
7 57
3 60
2 57
1 54
7 54
4 58
6 57
7 55
1 58
5 57
2 54
4 53
7 52
1 49
1 56
3 56
1 58
12 49
3 53
5 45
7 57
6 52
1 58
1 52
4 57
3 52
6 49
5 54
4 53
7 55
3 59
11 54
10 53
5 52
13 58
1 54
2 5...

output:

83773947

result:

ok single line: '83773947'

Extra Test:

score: 0
Extra Test Passed