QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#597489#9420. Find Yourselfucup-team159#AC ✓1478ms563668kbC++2347.8kb2024-09-28 17:55:362024-09-28 17:55:38

Judging History

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

  • [2024-09-28 17:55:38]
  • 评测
  • 测评结果:AC
  • 用时:1478ms
  • 内存:563668kb
  • [2024-09-28 17:55:36]
  • 提交

answer

#line 1 "ucup3-10/I/main.cpp"
#include <bit>
#define YOSUPO_AVX2_PRAGMA
// #undef YOSUPO_LOCAL

#line 2 "/home/vscode/yosupo-library/src/yosupo/fastio.hpp"

#include <unistd.h>
#include <algorithm>
#include <array>
#line 7 "/home/vscode/yosupo-library/src/yosupo/fastio.hpp"
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstring>
#include <sstream>
#include <string>
#include <type_traits>
#include <vector>

#line 2 "/home/vscode/yosupo-library/src/yosupo/internal_type_traits.hpp"

#line 5 "/home/vscode/yosupo-library/src/yosupo/internal_type_traits.hpp"

namespace yosupo {

namespace internal {

template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;

template <class T>
using is_integral =
    typename std::conditional<std::is_integral<T>::value ||
                                  internal::is_signed_int128<T>::value ||
                                  internal::is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;

template <class T>
using is_integral_t = std::enable_if_t<is_integral<T>::value>;

template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;

template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;

template <class T> using to_unsigned_t = typename to_unsigned<T>::type;

}  // namespace internal

}  // namespace yosupo
#line 17 "/home/vscode/yosupo-library/src/yosupo/fastio.hpp"

namespace yosupo {

struct Scanner {
  public:
    Scanner(const Scanner&) = delete;
    Scanner& operator=(const Scanner&) = delete;

    Scanner(FILE* fp) : fd(fileno(fp)) { line[0] = 127; }

    void read() {}
    template <class H, class... T> void read(H& h, T&... t) {
        bool f = read_single(h);
        assert(f);
        read(t...);
    }

    int read_unsafe() { return 0; }
    template <class H, class... T> int read_unsafe(H& h, T&... t) {
        bool f = read_single(h);
        if (!f) return 0;
        return 1 + read_unsafe(t...);
    }

    int close() { return ::close(fd); }

  private:
    static constexpr int SIZE = 1 << 15;

    int fd = -1;
    std::array<char, SIZE + 1> line;
    int st = 0, ed = 0;
    bool eof = false;

    bool read_single(std::string& ref) {
        if (!skip_space()) return false;
        ref = "";
        while (true) {
            char c = top();
            if (c <= ' ') break;
            ref += c;
            st++;
        }
        return true;
    }
    bool read_single(double& ref) {
        std::string s;
        if (!read_single(s)) return false;
        ref = std::stod(s);
        return true;
    }

    template <class T,
              std::enable_if_t<std::is_same<T, char>::value>* = nullptr>
    bool read_single(T& ref) {
        if (!skip_space<50>()) return false;
        ref = top();
        st++;
        return true;
    }

    template <class T,
              internal::is_signed_int_t<T>* = nullptr,
              std::enable_if_t<!std::is_same<T, char>::value>* = nullptr>
    bool read_single(T& sref) {
        using U = internal::to_unsigned_t<T>;
        if (!skip_space<50>()) return false;
        bool neg = false;
        if (line[st] == '-') {
            neg = true;
            st++;
        }
        U ref = 0;
        do {
            ref = 10 * ref + (line[st++] & 0x0f);
        } while (line[st] >= '0');
        sref = neg ? -ref : ref;
        return true;
    }
    template <class U,
              internal::is_unsigned_int_t<U>* = nullptr,
              std::enable_if_t<!std::is_same<U, char>::value>* = nullptr>
    bool read_single(U& ref) {
        if (!skip_space<50>()) return false;
        ref = 0;
        do {
            ref = 10 * ref + (line[st++] & 0x0f);
        } while (line[st] >= '0');
        return true;
    }

    bool reread() {
        if (ed - st >= 50) return true;
        if (st > SIZE / 2) {
            std::memmove(line.data(), line.data() + st, ed - st);
            ed -= st;
            st = 0;
        }
        if (eof) return false;
        auto u = ::read(fd, line.data() + ed, SIZE - ed);
        if (u == 0) {
            eof = true;
            line[ed] = '\0';
            u = 1;
        }
        ed += int(u);
        line[ed] = char(127);
        return true;
    }

    char top() {
        if (st == ed) {
            bool f = reread();
            assert(f);
        }
        return line[st];
    }

    template <int TOKEN_LEN = 0> bool skip_space() {
        while (true) {
            while (line[st] <= ' ') st++;
            if (ed - st > TOKEN_LEN) return true;
            if (st > ed) st = ed;
            for (auto i = st; i < ed; i++) {
                if (line[i] <= ' ') return true;
            }
            if (!reread()) return false;
        }
    }
};

struct Printer {
  public:
    template <char sep = ' ', bool F = false> void write() {}
    template <char sep = ' ', bool F = false, class H, class... T>
    void write(const H& h, const T&... t) {
        if (F) write_single(sep);
        write_single(h);
        write<true>(t...);
    }
    template <char sep = ' ', class... T> void writeln(const T&... t) {
        write<sep>(t...);
        write_single('\n');
    }

    Printer(FILE* _fp) : fd(fileno(_fp)) {}
    ~Printer() { flush(); }

    int close() {
        flush();
        return ::close(fd);
    }

    void flush() {
        if (pos) {
            auto res = ::write(fd, line.data(), pos);
            assert(res != -1);
            pos = 0;
        }
    }

  private:
    static std::array<std::array<char, 2>, 100> small;
    static std::array<unsigned long long, 20> tens;

    static constexpr size_t SIZE = 1 << 15;
    int fd;
    std::array<char, SIZE> line;
    size_t pos = 0;
    std::stringstream ss;

    template <class T,
              std::enable_if_t<std::is_same<char, T>::value>* = nullptr>
    void write_single(const T& val) {
        if (pos == SIZE) flush();
        line[pos++] = val;
    }

    template <class T,
              internal::is_signed_int_t<T>* = nullptr,
              std::enable_if_t<!std::is_same<char, T>::value>* = nullptr>
    void write_single(const T& val) {
        using U = internal::to_unsigned_t<T>;
        if (val == 0) {
            write_single('0');
            return;
        }
        if (pos > SIZE - 50) flush();
        U uval = val;
        if (val < 0) {
            write_single('-');
            uval = -uval;
        }
        write_unsigned(uval);
    }

    template <class U,
              internal::is_unsigned_int_t<U>* = nullptr,
              std::enable_if_t<!std::is_same<char, U>::value>* = nullptr>
    void write_single(U uval) {
        if (uval == 0) {
            write_single('0');
            return;
        }
        if (pos > SIZE - 50) flush();

        write_unsigned(uval);
    }

    static int calc_len(uint64_t x) {
        int i = ((63 - std::countl_zero(x)) * 3 + 3) / 10;
        if (x < tens[i])
            return i;
        else
            return i + 1;
    }

    template <class U,
              internal::is_unsigned_int_t<U>* = nullptr,
              std::enable_if_t<2 >= sizeof(U)>* = nullptr>
    void write_unsigned(U uval) {
        size_t len = calc_len(uval);
        pos += len;

        char* ptr = line.data() + pos;
        while (uval >= 100) {
            ptr -= 2;
            memcpy(ptr, small[uval % 100].data(), 2);
            uval /= 100;
        }
        if (uval >= 10) {
            memcpy(ptr - 2, small[uval].data(), 2);
        } else {
            *(ptr - 1) = char('0' + uval);
        }
    }

    template <class U,
              internal::is_unsigned_int_t<U>* = nullptr,
              std::enable_if_t<4 == sizeof(U)>* = nullptr>
    void write_unsigned(U uval) {
        std::array<char, 8> buf;
        memcpy(buf.data() + 6, small[uval % 100].data(), 2);
        memcpy(buf.data() + 4, small[uval / 100 % 100].data(), 2);
        memcpy(buf.data() + 2, small[uval / 10000 % 100].data(), 2);
        memcpy(buf.data() + 0, small[uval / 1000000 % 100].data(), 2);

        if (uval >= 100000000) {
            if (uval >= 1000000000) {
                memcpy(line.data() + pos, small[uval / 100000000 % 100].data(),
                       2);
                pos += 2;
            } else {
                line[pos] = char('0' + uval / 100000000);
                pos++;
            }
            memcpy(line.data() + pos, buf.data(), 8);
            pos += 8;
        } else {
            size_t len = calc_len(uval);
            memcpy(line.data() + pos, buf.data() + (8 - len), len);
            pos += len;
        }
    }

    template <class U,
              internal::is_unsigned_int_t<U>* = nullptr,
              std::enable_if_t<8 == sizeof(U)>* = nullptr>
    void write_unsigned(U uval) {
        size_t len = calc_len(uval);
        pos += len;

        char* ptr = line.data() + pos;
        while (uval >= 100) {
            ptr -= 2;
            memcpy(ptr, small[uval % 100].data(), 2);
            uval /= 100;
        }
        if (uval >= 10) {
            memcpy(ptr - 2, small[uval].data(), 2);
        } else {
            *(ptr - 1) = char('0' + uval);
        }
    }

    template <
        class U,
        std::enable_if_t<internal::is_unsigned_int128<U>::value>* = nullptr>
    void write_unsigned(U uval) {
        static std::array<char, 50> buf;
        size_t len = 0;
        while (uval > 0) {
            buf[len++] = char((uval % 10) + '0');
            uval /= 10;
        }
        std::reverse(buf.begin(), buf.begin() + len);
        memcpy(line.data() + pos, buf.data(), len);
        pos += len;
    }

    void write_single(const std::string& s) {
        for (char c : s) write_single(c);
    }
    void write_single(const char* s) {
        size_t len = strlen(s);
        for (size_t i = 0; i < len; i++) write_single(s[i]);
    }
    template <class T> void write_single(const std::vector<T>& val) {
        auto n = val.size();
        for (size_t i = 0; i < n; i++) {
            if (i) write_single(' ');
            write_single(val[i]);
        }
    }
};

inline std::array<std::array<char, 2>, 100> Printer::small = [] {
    std::array<std::array<char, 2>, 100> table;
    for (int i = 0; i <= 99; i++) {
        table[i][1] = char('0' + (i % 10));
        table[i][0] = char('0' + (i / 10 % 10));
    }
    return table;
}();
inline std::array<unsigned long long, 20> Printer::tens = [] {
    std::array<unsigned long long, 20> table;
    for (int i = 0; i < 20; i++) {
        table[i] = 1;
        for (int j = 0; j < i; j++) {
            table[i] *= 10;
        }
    }
    return table;
}();

}  // namespace yosupo
#line 2 "/home/vscode/yosupo-library/src/yosupo/hashmap.hpp"

#include <iterator>
#include <utility>
#line 6 "/home/vscode/yosupo-library/src/yosupo/hashmap.hpp"

#line 2 "/home/vscode/yosupo-library/src/yosupo/hash.hpp"

#line 5 "/home/vscode/yosupo-library/src/yosupo/hash.hpp"
#include <tuple>
#line 7 "/home/vscode/yosupo-library/src/yosupo/hash.hpp"
#include <set>
#include <map>

#line 2 "/home/vscode/yosupo-library/src/yosupo/random.hpp"

#line 6 "/home/vscode/yosupo-library/src/yosupo/random.hpp"
#include <chrono>
#line 8 "/home/vscode/yosupo-library/src/yosupo/random.hpp"
#include <random>
#line 10 "/home/vscode/yosupo-library/src/yosupo/random.hpp"

namespace yosupo {

struct Xoshiro256StarStar {
  public:
    using result_type = uint64_t;
    Xoshiro256StarStar() : Xoshiro256StarStar(0) {}
    explicit Xoshiro256StarStar(uint64_t seed) {
        // use splitmix64
        // Reference: http://xoshiro.di.unimi.it/splitmix64.c
        for (int i = 0; i < 4; i++) {
            uint64_t z = (seed += 0x9e3779b97f4a7c15);
            z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
            z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
            s[i] = z ^ (z >> 31);
        }
    }

    static constexpr result_type min() { return 0; }
    static constexpr result_type max() { return -1; }

    result_type operator()() {
        const uint64_t result_starstar = rotl(s[1] * 5, 7) * 9;

        const uint64_t t = s[1] << 17;

        s[2] ^= s[0];
        s[3] ^= s[1];
        s[1] ^= s[2];
        s[0] ^= s[3];

        s[2] ^= t;

        s[3] = rotl(s[3], 45);

        return result_starstar;
    }

  private:
    // Use xoshiro256**
    // Refereces: http://xoshiro.di.unimi.it/xoshiro256starstar.c
    static uint64_t rotl(const uint64_t x, int k) {
        return (x << k) | (x >> (64 - k));
    }

    std::array<uint64_t, 4> s;
};

// https://github.com/wangyi-fudan/wyhash
struct WYRand {
  public:
    using result_type = uint64_t;
    explicit WYRand(uint64_t seed) : s(seed) {}

    static constexpr result_type min() { return 0; }
    static constexpr result_type max() { return -1; }

    result_type operator()() {
        s += 0x2d358dccaa6c78a5;
        auto x = (unsigned __int128)s * (s ^ 0x8bb84b93962eacc9);
        return (uint64_t)(x ^ (x >> 64));
    }

  private:
    uint64_t s;
};
using Random = WYRand;
inline Random& global_gen() {
    static Random gen(
        std::chrono::steady_clock::now().time_since_epoch().count());
    return gen;
}

template <class G>
concept random_64 = std::uniform_random_bit_generator<G> &&
                    std::same_as<uint64_t, std::invoke_result_t<G&>> &&
                    G::min() == uint64_t(0) && G::max() == uint64_t(-1);

namespace internal {

// random choice from [0, upper]
template <random_64 G> uint64_t uniform_u64(uint64_t upper, G& gen) {
    if (!(upper & (upper + 1))) {
        // b = 00..0011..11
        return gen() & upper;
    }
    int log = 63 - std::countl_zero(upper);
    uint64_t mask = (log == 63) ? ~0ULL : (1ULL << (log + 1)) - 1;
    while (true) {
        uint64_t r = gen() & mask;
        if (r <= upper) return r;
    }
}

// random choice from [0, upper], faster than uniform_u64
template <random_64 G> uint64_t random_u64(uint64_t upper, G& gen) {
    return (uint64_t)(((unsigned __int128)(upper) + 1) * gen() >> 64);
}

}  // namespace internal

template <class T, random_64 G> T uniform(T lower, T upper, G& gen) {
    return T(lower +
             internal::uniform_u64(uint64_t(upper) - uint64_t(lower), gen));
}
template <class T> T uniform(T lower, T upper) {
    return uniform(lower, upper, global_gen());
}
template <class T, random_64 G> T random(T lower, T upper, G& gen) {
    return T(lower +
             internal::random_u64(uint64_t(upper) - uint64_t(lower), gen));
}
template <class T> T random(T lower, T upper) {
    return random(lower, upper, global_gen());
}

template <random_64 G> bool uniform_bool(G& gen) { return gen() & 1; }
inline bool uniform_bool() { return uniform_bool(global_gen()); }

// select 2 elements from [lower, uppper]
template <class T, random_64 G>
std::pair<T, T> uniform_pair(T lower, T upper, G& gen) {
    assert(upper - lower >= 1);
    T a, b;
    do {
        a = uniform(lower, upper, gen);
        b = uniform(lower, upper, gen);
    } while (a == b);
    if (a > b) std::swap(a, b);
    return {a, b};
}
template <class T> std::pair<T, T> uniform_pair(T lower, T upper) {
    return uniform_pair(lower, upper, global_gen());
}

// random value in the interval (0.0, 1.0]
template <class G> inline double open_closed_01(G& gen) {
    union {
        uint64_t i;
        double f;
    } u = {0xbff0000000000000 | (gen() >> 12)};
    return 2.0 + u.f;
}
inline double open_closed_01() {
    return open_closed_01(global_gen());
}

}  // namespace yosupo
#line 2 "/home/vscode/yosupo-library/src/yosupo/bitvector.hpp"

#line 7 "/home/vscode/yosupo-library/src/yosupo/bitvector.hpp"

namespace yosupo {

struct BitVec {
  public:
    BitVec() : BitVec(0) {}
    explicit BitVec(size_t _n) : n(_n), d((n + B - 1) / B) {}
    size_t size() const { return n; }

    void reset() { fill(d.begin(), d.end(), 0); }
    void reset(size_t i) { set(i, false); }
    BitVec& set() {
        for (auto& x : d) {
            x = -1ULL;
        }
        erase_last();
        return *this;
    }
    BitVec& set(size_t i, bool f = true) {
        assert(i < n);
        if (f) {
            d[i / B] |= 1ULL << (i % B);
        } else {
            d[i / B] &= ~(1ULL << (i % B));
        }
        return *this;
    }
    bool test(size_t i) const {
        assert(i < n);
        return (d[i / B] >> (i % B) & 1) != 0;
    }

    size_t count() const {
        size_t sm = 0;
        for (auto x : d) sm += std::popcount(x);
        return sm;
    }
    bool any() const {
        for (auto& x : d)
            if (x) return true;
        return false;
    }
    int find_first() const {
        auto m = d.size();
        for (size_t i = 0; i < m; i++) {
            if (d[i]) return int(i * B + std::countr_zero(d[i]));
        }
        return int(size());
    }

    BitVec& flip() {
        op1(std::bit_not<unsigned long long>());
        if (n % B) d.back() &= ~(-1ULL << (n % B));
        return *this;
    }
    BitVec& flip(size_t i) {
        return set(i, !test(i));
    }

    // operators
    BitVec& operator~() const { return BitVec(*this).flip(); }
    BitVec& operator&=(const BitVec& r) {
        return op2(r, std::bit_and<unsigned long long>());
    }
    BitVec& operator|=(const BitVec& r) {
        return op2(r, std::bit_or<unsigned long long>());
    }
    BitVec& operator^=(const BitVec& r) {
        return op2(r, std::bit_xor<unsigned long long>());
    }
    BitVec& operator<<=(const size_t& s) {
        auto block = s / B, rem = s % B;
        if (d.size() <= block) {
            reset();
            return *this;
        }
        for (size_t i = d.size() - 1; i > block; i--) {
            if (rem == 0)
                d[i] = d[i - block];
            else
                d[i] = d[i - block] << rem | d[i - block - 1] >> (B - rem);
        }
        d[block] = d[0] << rem;
        erase_last();
        fill(d.begin(), d.begin() + block, 0ULL);
        return *this;
    }
    BitVec& operator>>=(const size_t& s) {
        auto block = s / B, rem = s % B;
        if (d.size() <= block) {
            reset();
            return *this;
        }
        for (size_t i = 0; i < d.size() - block - 1; i++) {
            if (rem == 0)
                d[i] = d[i + block];
            else
                d[i] = d[i + block + 1] << (B - rem) | d[i + block] >> rem;
        }
        d[d.size() - block - 1] = d.back() >> rem;
        fill(d.begin() + d.size() - block, d.end(), 0ULL);
        return *this;
    }
    BitVec operator&(const BitVec& r) const { return BitVec(*this) &= r; }
    BitVec operator|(const BitVec& r) const { return BitVec(*this) |= r; }
    BitVec operator^(const BitVec& r) const { return BitVec(*this) ^= r; }
    BitVec operator<<(const size_t& s) const { return BitVec(*this) <<= s; }
    BitVec operator>>(const size_t& s) const { return BitVec(*this) >>= s; }
    bool operator==(const BitVec& r) const { return d == r.d; }
    bool operator!=(const BitVec& r) const { return !(d == r.d); }

    void push_back(bool f) {
        if (n % B == 0) d.push_back(0);
        set(n, f);
        n++;
    }

    BitVec substr(size_t st, size_t le) const {
        assert(st + le <= n);
        BitVec res(le);
        size_t i = 0;
        while (i < le) {
            res.d[i / B] |= d[(st + i) / B] >> ((st + i) % B) << (i % B);
            i += std::min(B - i % B, B - (st + i) % B);
        }
        res.erase_last();
        return res;
    }
    bool substr_match(size_t st, const BitVec& pat) const {
        size_t le = pat.size();
        assert(st + le <= n);
        size_t i = 0;
        while (i < le) {
            size_t u = std::min({le - i, B - i % B, B - (st + i) % B});
            unsigned long long z = pat.d[i / B] >> (i % B) ^ d[(st + i) / B] >> ((st + i) % B);
            if (z << (B - u)) return false;
            i += u;
        }
        return true;
    }

    const std::vector<unsigned long long>& raw_data() const { return d; }

  private:
    static constexpr size_t B = 64;
    size_t n;
    std::vector<unsigned long long> d;
    void erase_last() {
        if (n % B) d.back() &= (unsigned long long)(-1) >> (B - n % B);
    }

    template <class OP> BitVec& op1(OP op) {
        for (auto& x : d) x = op(x);
        return *this;
    }

    template <class OP> BitVec& op2(const BitVec& r, OP op) {
        assert(n == r.n);
        for (size_t i = 0; i < d.size(); i++) d[i] = op(d[i], r.d[i]);
        return *this;
    }
};

namespace internal {

// bitvec
template <class H> auto update(const H& h, const BitVec& bs) {
    return update(h, bs.raw_data());
}

}  // namespace internal

}  // namespace yosupo
#line 13 "/home/vscode/yosupo-library/src/yosupo/hash.hpp"

namespace yosupo {

namespace internal {

constexpr int THRESHOLD_HASH = 100;

// Reference: Lemire, Daniel., and Owen, Kaser.
// Strongly Universal String Hashing Is Fast.
inline uint64_t get_seed(int i) {
    static std::array<uint64_t, THRESHOLD_HASH> seed = []() {
        std::array<uint64_t, THRESHOLD_HASH> _seed;
        for (auto& x : _seed) {
            x = yosupo::uniform(uint64_t(0), uint64_t(-1));
        }
        return _seed;
    }();
    static std::vector<uint64_t> long_seed;

    if (i < THRESHOLD_HASH) return seed[i];

    while (THRESHOLD_HASH + int(long_seed.size()) <= i) {
        long_seed.push_back(yosupo::uniform(uint64_t(0), uint64_t(-1)));
    }

    return long_seed[i - THRESHOLD_HASH];
}

struct DynHasher32 {
    int len = 0;
    uint64_t v = get_seed(0);

    DynHasher32 update32(uint32_t x) const {
        return DynHasher32{len + 1, v + x * get_seed(len)};
    }

    DynHasher32 to_dyn() const { return *this; }
    uint32_t digest() const { return uint32_t(v >> 32); }
};

template <int I = 1> struct Hasher32 {
    uint64_t v = get_seed(0);

    Hasher32<I + 1> update32(uint32_t x) const {
        return Hasher32<I + 1>{v + x * get_seed(I)};
    }

    DynHasher32 to_dyn() const { return DynHasher32{I, v}; }
    uint32_t digest() const { return uint32_t(v >> 32); }
};

// integer
template <class H,
          class T,
          is_integral_t<T>* = nullptr,
          std::enable_if_t<4 >= sizeof(T)>* = nullptr>
auto update(const H& h, const T& x) {
    return h.update32(uint32_t(x));
}
template <class H,
          class T,
          is_integral_t<T>* = nullptr,
          std::enable_if_t<sizeof(T) == 8>* = nullptr>
auto update(const H& h, const T& x) {
    return update(update(h, uint32_t(x)), uint32_t(uint64_t(x) >> 32));
}
template <class H,
          class T,
          is_integral_t<T>* = nullptr,
          std::enable_if_t<sizeof(T) == 16>* = nullptr>
auto update(const H& h, const T& x) {
    return update(update(h, uint64_t(x)), uint64_t((__uint128_t)(x) >> 64));
}

// pair
template <class H, class S, class T>
auto update(const H& h, const std::pair<S, T>& x) {
    return update(update(h, x.first), x.second);
}

// tuple
template <int I,
          class H,
          class T,
          std::enable_if_t<(I == std::tuple_size<T>::value)>* = nullptr>
auto update(const H& h, const T&) {
    return h;
}
template <int I = 0,
          class H,
          class T,
          std::enable_if_t<(I != std::tuple_size<T>::value)>* = nullptr>
auto update(const H& h, const T& x) {
    return update<I + 1>(update(h, std::get<I>(x)), x);
}

// array
template <int I = 0,
          class H,
          class T,
          int N>
auto update(const H& h, const std::array<T, N>& x) {
    return I == N ? h : update<I + 1>(update(h, x[I]), x);
}

// vector
template <class H, class T> auto update(const H& h, const std::vector<T>& v) {
    auto h2 = update(h, v.size()).to_dyn();
    for (const auto& x : v) {
        h2 = update(h2, x);
    }
    return h2;
}

// set
template <class H, class T> auto update(const H& h, const std::set<T>& s) {
    auto h2 = update(h, s.size()).to_dyn();
    for (const auto& x : s) {
        h2 = update(h2, x);
    }
    return h2;
}

// map
template <class H, class T, class U> auto update(const H& h, const std::map<T, U>& m) {
    auto h2 = update(h, m.size()).to_dyn();
    for (const auto& x : m) {
        h2 = update(h2, x);
    }
    return h2;
}

}  // namespace internal

template <class T> struct UniversalHash32 {
    uint32_t operator()(const T& x) {
        return internal::update(internal::Hasher32<>{}, x).digest();
    }
};

}  // namespace yosupo
#line 8 "/home/vscode/yosupo-library/src/yosupo/hashmap.hpp"

namespace yosupo {

template <class K, class D, class H = UniversalHash32<K>>
struct IncrementalHashMap {
  public:
    using Data = std::pair<K, D>;

  private:
    struct Iterator {
      public:
        using difference_type = int;
        using value_type = Data;
        using pointer = Data*;
        using reference = Data&;
        using iterator_category = std::forward_iterator_tag;

        IncrementalHashMap& _mp;
        unsigned int _pos;
        Iterator(IncrementalHashMap& mp, unsigned int pos)
            : _mp(mp), _pos(pos) {}

        std::pair<K, D>& operator*() const { return _mp.data[_pos]; }
        std::pair<K, D>* operator->() const { return &_mp.data[_pos]; }

        Iterator& operator++() {
            _pos = _mp.next_bucket(_pos + 1);
            return *this;
        }
        Iterator operator++(int) {
            auto result = *this;
            ++*this;
            return result;
        }

        bool operator==(const Iterator& rhs) const { return _pos == rhs._pos; }
        bool operator!=(const Iterator& rhs) const { return !(*this == rhs); }
    };

  public:
    IncrementalHashMap(size_t s)
        : mask((1 << s) - 1), filled(0), used(mask + 1), data(mask + 1) {}
    IncrementalHashMap() : IncrementalHashMap(2) {}

    Iterator begin() { return Iterator(*this, next_bucket(0)); }
    Iterator end() { return Iterator(*this, mask + 1); }
    using iterator = Iterator;

    D& operator[](const K& k) {
        unsigned int i = H()(k) & mask;
        while (used[i] && data[i].first != k) {
            i = (i + 1) & mask;
        }
        if (!used[i]) {
            if (filled * 2 > mask) {
                rehash();
                return (*this)[k];
            }
            filled++;
            used[i] = true;
            data[i] = {k, D()};
        }
        return data[i].second;
    }

    Iterator find(const K& k) {
        unsigned int i = H()(k) & mask;
        while (used[i] && data[i].first != k) {
            i = (i + 1) & mask;
        }
        if (!used[i]) return end();
        return Iterator(*this, i);
    }

    size_t count(const K& k) {
        return find(k) == end() ? 0 : 1;
    }

    size_t size() const { return filled; }

  private:
    unsigned int mask, filled;  // data.size() == 1 << s

    std::vector<bool> used;
    std::vector<Data> data;

    void rehash() {
        unsigned int pmask = mask;
        mask = mask * 2 + 1;
        filled = 0;
        auto pused = std::exchange(used, std::vector<bool>(mask + 1));
        auto pdata = std::exchange(data, std::vector<Data>(mask + 1));
        for (unsigned int i = 0; i <= pmask; i++) {
            if (pused[i]) {
                (*this)[pdata[i].first] = pdata[i].second;
            }
        }
    }

    unsigned int next_bucket(unsigned int i) const {
        while (i <= mask && !used[i]) i++;
        return i;
    }
};

}  // namespace yosupo
#line 1 "/home/vscode/ac-library/atcoder/dsu.hpp"



#line 7 "/home/vscode/ac-library/atcoder/dsu.hpp"

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
  public:
    dsu() : _n(0) {}
    explicit dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

}  // namespace atcoder


#line 9 "ucup3-10/I/main.cpp"
using namespace yosupo;

#line 2 "ucup3-10/I/base.hpp"

#ifdef YOSUPO_AVX2_PRAGMA
#line 5 "ucup3-10/I/base.hpp"
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif

#line 11 "ucup3-10/I/base.hpp"
#include <bitset>
#line 13 "ucup3-10/I/base.hpp"
#include <cmath>
#include <cstdio>
#line 16 "ucup3-10/I/base.hpp"
#include <iostream>
#line 18 "ucup3-10/I/base.hpp"
#include <queue>
#include <ranges>
#line 24 "ucup3-10/I/base.hpp"

using std::abs, std::pow, std::sqrt;
using std::array, std::vector, std::string, std::queue, std::deque;
using std::countl_zero, std::countl_one, std::countr_zero, std::countr_one;
using std::istream, std::ostream, std::cerr, std::endl;
using std::min, std::max, std::swap;
using std::pair, std::tuple, std::bitset;
using std::popcount;
using std::priority_queue, std::set, std::multiset, std::map;
using std::views::iota, std::views::reverse;

namespace ranges = std::ranges;
using ranges::sort, ranges::copy_n;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef YOSUPO_LOCAL

inline ostream& operator<<(ostream& os, __int128_t x) {
    if (x < 0) {
        os << "-";
        x *= -1;
    }
    if (x == 0) {
        return os << "0";
    }
    string s;
    while (x) {
        s += char(x % 10 + '0');
        x /= 10;
    }
    ranges::reverse(s);
    return os << s;
}
inline ostream& operator<<(ostream& os, __uint128_t x) {
    if (x == 0) {
        return os << "0";
    }
    string s;
    while (x) {
        s += char(x % 10 + '0');
        x /= 10;
    }
    ranges::reverse(s);
    return os << s;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p);
template <class T> ostream& operator<<(ostream& os, const V<T>& v);
template <class T> ostream& operator<<(ostream& os, const deque<T>& v);
template <class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N>& a);
template <class T> ostream& operator<<(ostream& os, const set<T>& s);
template <class T, class U>
ostream& operator<<(ostream& os, const map<T, U>& m);

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    bool f = false;
    for (auto d : v) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "]";
}

template <class T> ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "[";
    bool f = false;
    for (auto d : v) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "]";
}
template <class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N>& a) {
    os << "[";
    bool f = false;
    for (auto d : a) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "]";
}

template <class T> ostream& operator<<(ostream& os, const set<T>& s) {
    os << "{";
    bool f = false;
    for (auto d : s) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "}";
}
template <class T> ostream& operator<<(ostream& os, const multiset<T>& s) {
    os << "{";
    bool f = false;
    for (auto d : s) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "}";
}

template <class T, class U>
ostream& operator<<(ostream& os, const map<T, U>& s) {
    os << "{";
    bool f = false;
    for (auto p : s) {
        if (f) os << ", ";
        f = true;
        os << p.first << ": " << p.second;
    }
    return os << "}";
}

struct PrettyOS {
    ostream& os;
    bool first;

    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif
#line 12 "ucup3-10/I/main.cpp"

Scanner sc = Scanner(stdin);
Printer pr = Printer(stdout);

bool solve(int n, V<pair<int, int>> es) {
    VV<int> gv(n);
    for (auto [u, v] : es) {
        gv[u].push_back(v);
        gv[v].push_back(u);
    }

    V<set<int>> g(n);
    for (int i : iota(0, n)) {
        g[i] = set<int>(gv[i].begin(), gv[i].end());
    }

    V<int> deg(n);
    for (int u : iota(0, n)) {
        deg[u] = int(g[u].size());
    }

/*
    while (true) {
        auto update = [&]() {
            for (int u : iota(0, n)) {
                if (erased[u]) continue;
                for (int v : iota(0, n)) {
                    if (u == v) continue;
                    if (erased[v]) continue;
                    if (deg[u] == 1 && deg[v] == 1) {
                        if (g[u] == g[v]) {
                            era(v);
                            return true;
                        }

                        int a = *g[u].begin();
                        int b = *g[v].begin();
                        if (a == b) {
                            era(v);
                            return true;
                        }

                        if (deg[a] == 2 && deg[b] == 2) {
                            int c = *g[a].begin();
                            if (c == u) c = *g[a].rbegin();

                            int d = *g[b].begin();
                            if (d == v) d = *g[b].rbegin();

                            if (c == d) {
                                era(v);
                                return true;
                            }
                        }
                    }
                    if (deg[u] == 2 && deg[v] == 1) {
                        int a = *g[v].begin();
                        if (g[u].count(a)) {
                            era(v);
                            return true;
                        }
                    }
                    if (deg[u] == 2 && deg[v] == 2) {
                        if (g[u] == g[v]) {
                            era(v);
                            return true;
                        }
                    }
                }
            }
            return false;
        }();

        if (!update) break;
    }
*/
    V<pair<int, int>> que;

    V<set<int>> p1(n);
    V<set<int>> p2(n);
    //V<set<int>> near2(n);
    V<int> near2(n);
    IncrementalHashMap<pair<int, int>, set<int>> v2;
    //IncrementalHashMap<pair<int, int>, V<int>> v2;

    auto eff = [&](int u, bool inc) {
        int d = deg[u];
        if (d >= 3) return;

        int a = *g[u].begin();
        if (d == 1) {
            if (inc) {
                p1[a].insert(u);
                que.push_back({a, -1});
            } else {
                p1[a].erase(u);
            }
        } else {
            int b = *g[u].rbegin();
            if (a > b) swap(a, b);

            if (inc) {
                v2[{a, b}].insert(u);
                que.push_back({a, b});
            } else {
                v2[{a, b}].erase(u);
            }

            if (deg[a] == 1) {
                if (inc) {
                    p2[b].insert(u);
                    que.push_back({b, -1});
                } else {
                    p2[b].erase(u);
                }
            }
            if (deg[b] == 1) {
                if (inc) {
                    p2[a].insert(u);
                    que.push_back({a, -1});
                } else {
                    p2[a].erase(u);
                }
            }


            if (inc) {
                near2[b]++;
                que.push_back({b, -1});
            } else {
                near2[b]--;
            }
            if (inc) {
                near2[a]++;
                que.push_back({a, -1});
            } else {
                near2[a]--;
            }
        }
    };

    for (int u : iota(0, n)) {
        eff(u, true);
    }

    V<bool> erased(n);
    auto era = [&](int u) {
        assert(!erased[u]);
        erased[u] = true;

        eff(u, false);
        for (int v : g[u]) {
            eff(v, false);
            if (deg[v] == 2) {
                int a = *g[v].begin();
                if (a == u) a = *g[v].rbegin();
                eff(a, false);
            }
        }
        for (int v : g[u]) {
            g[v].erase(u);
            deg[v]--;
        }
        for (int v : g[u]) {
            eff(v, true);
            if (deg[v] == 1) {
                eff(*g[v].begin(), true);
            }
        }

        return true;
    };

    for (int u : iota(0, n)) {
        que.push_back({u, -1});
    }
    for (auto p : v2) {
        que.push_back(p.first);
    }

    while (que.size()) {
        auto [u, v] = que.back();
        que.pop_back();

        if (v == -1) {
            // single
            // check p1
            while (true) {
                bool update = false;
                while (int(p2[u].size()) >= 2) {
                    int w = *p2[u].begin();
                    assert(deg[w] == 2);
                    int z = *g[w].begin();
                    if (z == u) z = *g[w].rbegin();
                    era(z);
                }
                while (int(p1[u].size()) >= 2) {
                    era(*p1[u].begin());
                }
                if (near2[u] >= 1 && p1[u].size() >= 1) {
                    era(*p1[u].begin());
                }
                if (!update) break;
            }
        } else {
            while (int(v2[{u, v}].size()) >= 2) {
                era(*v2[{u, v}].begin());
            }
        }
    }

    // for (int i : iota(0, n)) {
    //     assert(deg[i] == int(g[i].size()));
    // }

    // while (true) {
    //     auto update = [&]() {
    //         for (int u : iota(0, n)) {
    //             if (erased[u]) continue;
    //             for (int v : iota(0, n)) {
    //                 if (u == v) continue;
    //                 if (erased[v]) continue;
    //                 if (deg[u] == 1 && deg[v] == 1) {
    //                     if (g[u] == g[v]) {
    //                         era(v);
    //                         assert(false);
    //                         return true;
    //                     }

    //                     int a = *g[u].begin();
    //                     int b = *g[v].begin();
    //                     if (a == b) {
    //                         era(v);
    //                         assert(false);
    //                         return true;
    //                     }

    //                     if (deg[a] == 2 && deg[b] == 2) {
    //                         int c = *g[a].begin();
    //                         if (c == u) c = *g[a].rbegin();

    //                         int d = *g[b].begin();
    //                         if (d == v) d = *g[b].rbegin();

    //                         if (c == d) {
    //                             dbg(u, a, v, b, c);
    //                             dbg(p2[c], deg[a], deg[b], deg[c]);
    //                             eff(a, true);
    //                             dbg(u, a, v, b, c);
    //                             dbg(p2[c], deg[a], deg[b], deg[c]);
    //                             assert(false);
    //                             era(v);
    //                             return true;
    //                         }
    //                     }
    //                 }
    //                 if (deg[u] == 2 && deg[v] == 1) {
    //                     int a = *g[v].begin();
    //                     if (g[u].count(a)) {
    //                         era(v);
    //                         assert(false);
    //                         return true;
    //                     }
    //                 }
    //                 if (deg[u] == 2 && deg[v] == 2) {
    //                     if (g[u] == g[v]) {
    //                         era(v);
    //                         assert(false);
    //                         return true;
    //                     }
    //                 }
    //             }
    //         }
    //         return false;
    //     }();
    //     assert(!update);

    //     if (!update) break;
    // }

    int cnt = 0;
    for (int i : iota(0, n)) {
        if (!erased[i]) {
            cnt++;
        }
    }

    return cnt == 2;
}

bool naive(int n, V<pair<int, int>> es) {
    V<set<int>> g(n);
    for (auto [u, v] : es) {
        g[u].insert(v);
        g[v].insert(u);
    }
    V<int> c11(n);
    V<int> c21(n);
    IncrementalHashMap<pair<int, int>, int> c22;

    VV<int> r1(n);
    for (int u : iota(0, n)) {
        int d = int(g[u].size());
        if (d == 1) {
            r1[*g[u].begin()].push_back(u);
        }
    }
    V<bool> f1(n);

    V<int> que(n);
    for (int i : iota(0, n)) {
        que[i] = i;
    }

    auto eff = [&](int u, int f) {
        int d = int(g[u].size());
        if (d >= 3) return;
        int a = *g[u].begin();
        if (d == 1) {
            c11[a] += f;
        } else {
            int b = *g[u].rbegin();
            if (a > b) swap(a, b);
            c21[a] += f;
            c21[b] += f;
            c22[{a, b}] += f;

            if (f == 1) {
                if (!f1[a]) {
                    f1[a] = true;
                    for (int v : r1[a]) {
                        que.push_back(v);
                    }
                }
                if (!f1[b]) {
                    f1[b] = true;
                    for (int v : r1[b]) {
                        que.push_back(v);
                    }
                }
            }
        }
    };
    for (int u : iota(0, n)) {
        eff(u, 1);
    }

    V<bool> erased(n);
    auto era = [&](int u) {
        assert(!erased[u]);
        erased[u] = true;

        eff(u, -1);
        for (int v : g[u]) {
            eff(v, -1);
        }
        for (int v : g[u]) {
            g[v].erase(u);
            eff(v, 1);
            que.push_back(v);
        }
    };

    while (que.size()) {
        int u = que.back();
        que.pop_back();
        if (erased[u]) continue;
        int deg = int(g[u].size());
        if (deg >= 3) continue;
        assert(deg >= 1);

        int a = *g[u].begin();
        if (deg == 1) {
            if (c21[a] || c11[a] >= 2) {
                // erase
                era(u);
            }
        } else {
            int b = *g[u].rbegin();
            if (a > b) swap(a, b);
            if (c22[{a, b}] >= 2) {
                // erase
                era(u);
            }
        }
    }

    for (int u : iota(0, n)) {
        if (erased[u]) continue;
        int deg = int(g[u].size());
        if (deg >= 3) continue;
        assert(deg >= 1);

        int a = *g[u].begin();
        if (deg == 1) {
            if (c21[a] || c11[a] >= 2) {
                // erase
                assert(false);
            }
        } else {
            int b = *g[u].rbegin();
            if (a > b) swap(a, b);
            if (c22[{a, b}] >= 2) {
                // erase
                assert(false);
            }
        }
    }

    int cnt = 0;
    for (int i : iota(0, n)) {
        if (!erased[i]) {
            cnt++;
        }
    }

    return cnt == 2;
}

bool naive(V<int> g) {
    int n = int(g.size());
    assert(n <= 20);

    V<bool> ok(1 << n);
    V<int> near(1 << n);
    for (int f : iota(0, 1 << n)) {
        if (popcount(uint(f)) <= 2) {
            ok[f] = true;
        }
        for (int i : iota(0, n)) {
            if (f & (1 << i)) {
                near[f] |= g[i];
            }
        }
    }

    while (true) {
        bool update = false;
        for (int f0 : iota(0, 1 << n)) {
            for (int f1 : iota(0, 1 << n)) {
                if (f0 & f1) continue;
                if (ok[f0 | f1]) continue;

                bool ok0 = (popcount(uint(f0))) == 1 || ok[near[f0]];
                bool ok1 = (popcount(uint(f1))) == 1 || ok[near[f1]];

                if (ok0 && ok1) {
                    update = true;
                    ok[f0 | f1] = true;
                }
            }
        }
        if (!update) break;
    }

    return ok[(1 << n) - 1];
}

void stress() {
    int n = uniform(5, 13);
    int m = uniform(1, 20);

    atcoder::dsu uf(n);
    set<pair<int, int>> es;
    for (int _ : iota(0, m)) {
        auto [u, v] = uniform_pair(0, n - 1);
        if (es.count({u, v})) continue;
        es.insert({u, v});
        uf.merge(u, v);
    }
    for (int i : iota(0, n - 1)) {
        if (uf.same(i, i + 1)) continue;
        es.insert({i, i + 1});
    }

    V<int> g(n);
    for (auto [u, v] : es) {
        g[u] |= 1 << v;
        g[v] |= 1 << u;
    }

    V<pair<int, int>> ev(es.begin(), es.end());
    bool expect = naive(g);
    bool actual = solve(n, ev);

    if (expect != actual) {
        dbg(n);
        dbg(es);
        dbg(expect, actual);
    }
    assert(expect == actual);
}

int main() {
    // for (int _ : iota(0, 1000000)) {
    //     dbg(_);
    //     stress();
    // }


    int t;
    sc.read(t);

    for (int _ : iota(0, t)) {
        int n, m;
        sc.read(n, m);
        V<pair<int, int>> es(m);
        for (int i : iota(0, m)) {
            sc.read(es[i].first, es[i].second);
            es[i].first--;
            es[i].second--;
        }
        bool ans = solve(n, es);
        if (ans) {
            pr.writeln("YES");
        } else {
            pr.writeln("NO");
        }
    }   
    return 0;
}

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

详细

Test #1:

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

input:

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

output:

NO
YES
NO

result:

ok 3 token(s): yes count is 1, no count is 2

Test #2:

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

input:

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

output:

NO
NO
NO
NO
YES
YES
NO
YES
YES
YES

result:

ok 10 token(s): yes count is 5, no count is 5

Test #3:

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

input:

10
11 12
1 3
1 4
1 5
2 3
2 4
2 5
1 6
6 7
2 8
2 9
3 10
3 11
11 12
1 2
2 3
3 4
3 5
3 6
3 7
5 8
6 8
7 8
7 9
8 10
10 11
11 12
1 2
2 3
3 4
3 5
3 6
3 7
5 8
6 8
7 8
8 9
8 10
10 11
8 12
1 3
2 3
1 4
2 4
1 5
2 5
1 6
2 6
1 7
2 7
1 8
2 8
6 7
1 2
1 3
3 4
4 2
1 5
5 6
6 2
12 12
1 2
2 3
3 4
4 1
1 5
1 6
2 7
2 8
3 9
...

output:

YES
NO
YES
YES
NO
YES
NO
YES
YES
YES

result:

ok 10 token(s): yes count is 7, no count is 3

Test #4:

score: 0
Accepted
time: 583ms
memory: 29452kb

input:

5518
8 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
9 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
3 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
4 8
3 3
1 2
2 3
3 1
6 6
1 2
2 3
3 4
4 5
5 6
6 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
2 6
3 7...

output:

NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
NO
NO
NO
NO
YES
NO
YES
NO
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
NO
NO
YES
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
YES
NO
NO
NO
NO
YES
Y...

result:

ok 5518 token(s): yes count is 3676, no count is 1842

Test #5:

score: 0
Accepted
time: 606ms
memory: 30196kb

input:

5518
8 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
9 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
3 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
4 8
3 3
1 2
2 3
3 1
6 6
1 2
2 3
3 4
4 5
5 6
6 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
2 6
3 7...

output:

NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
NO
YES
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
YES
YES
NO
YES
YES
YES
NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
NO
NO...

result:

ok 5518 token(s): yes count is 3671, no count is 1847

Test #6:

score: 0
Accepted
time: 659ms
memory: 89912kb

input:

415
8 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
9 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
3 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
4 8
3 3
1 2
2 3
3 1
6 6
1 2
2 3
3 4
4 5
5 6
6 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
2 6
3 7
...

output:

NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
YES
NO
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
...

result:

ok 415 token(s): yes count is 271, no count is 144

Test #7:

score: 0
Accepted
time: 694ms
memory: 90692kb

input:

415
8 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
9 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
3 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
4 8
3 3
1 2
2 3
3 1
6 6
1 2
2 3
3 4
4 5
5 6
6 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
2 6
3 7
...

output:

NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 415 token(s): yes count is 287, no count is 128

Test #8:

score: 0
Accepted
time: 751ms
memory: 90196kb

input:

415
8 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
9 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
3 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
4 8
3 3
1 2
2 3
3 1
6 6
1 2
2 3
3 4
4 5
5 6
6 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
2 6
3 7
...

output:

NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
YES
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
...

result:

ok 415 token(s): yes count is 274, no count is 141

Test #9:

score: 0
Accepted
time: 541ms
memory: 27156kb

input:

9132
8 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
9 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
2 6
3 7
4 8
9 9
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
2 9
7 8
1 3
1 4
1 5
2 3
2 4
2 5
3 6
4 7
9 9
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
2 9
8 8
1 2
2 3
3 4
4 1
1 5
5 6
3 7...

output:

NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
NO
NO
YES
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
...

result:

ok 9132 token(s): yes count is 2509, no count is 6623

Test #10:

score: 0
Accepted
time: 551ms
memory: 27708kb

input:

9136
8 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
9 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
2 6
3 7
4 8
9 9
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
2 9
7 8
1 3
1 4
1 5
2 3
2 4
2 5
3 6
4 7
9 9
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
2 9
8 8
1 2
2 3
3 4
4 1
1 5
5 6
3 7...

output:

NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
NO
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
NO
YES
NO
NO
YES
YES
NO
NO
YES
YES
YES...

result:

ok 9136 token(s): yes count is 2514, no count is 6622

Test #11:

score: 0
Accepted
time: 541ms
memory: 27348kb

input:

9130
8 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
9 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 1
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
2 6
3 7
4 8
9 9
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
2 9
7 8
1 3
1 4
1 5
2 3
2 4
2 5
3 6
4 7
9 9
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
2 9
8 8
1 2
2 3
3 4
4 1
1 5
5 6
3 7...

output:

NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
NO
NO
YES
NO
YES
YES
NO
YES
NO
NO
...

result:

ok 9130 token(s): yes count is 2452, no count is 6678

Test #12:

score: 0
Accepted
time: 282ms
memory: 3716kb

input:

100000
9 12
3 2
2 6
7 6
3 7
9 4
1 5
1 2
4 2
5 2
6 3
9 6
2 8
8 8
4 3
1 2
2 3
1 7
7 6
2 8
6 3
5 3
7 11
1 2
6 5
4 6
4 2
2 7
3 4
6 7
3 2
1 3
5 2
3 6
7 10
1 6
4 6
7 6
7 5
1 2
3 1
3 7
2 4
4 5
1 7
7 9
3 2
2 1
1 6
2 5
7 3
4 1
5 3
5 6
7 1
7 10
6 3
6 7
7 3
2 6
1 4
5 2
3 5
1 2
3 1
5 1
8 11
8 3
3 5
1 2
1 6
8 7
...

output:

NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO...

result:

ok 100000 token(s): yes count is 12069, no count is 87931

Test #13:

score: 0
Accepted
time: 183ms
memory: 3712kb

input:

50000
11 22
10 6
7 1
6 9
1 10
3 10
11 8
1 3
2 9
9 5
2 3
2 1
5 2
4 10
3 6
4 1
6 11
5 4
11 1
8 4
10 2
1 6
1 9
10 18
2 3
3 4
7 5
8 5
10 4
9 10
9 7
2 10
6 2
8 1
2 7
5 2
9 3
2 1
10 7
1 3
4 8
5 9
10 19
5 10
3 7
5 1
3 4
3 8
9 4
2 3
8 1
8 10
7 6
4 7
2 7
6 3
1 2
9 1
10 9
7 1
1 3
4 2
8 19
4 7
1 2
7 3
4 6
1 6
...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 50000 token(s): yes count is 0, no count is 50000

Test #14:

score: 0
Accepted
time: 186ms
memory: 3908kb

input:

50000
11 19
7 6
8 11
2 1
7 10
6 5
9 1
3 1
10 5
7 9
4 3
5 4
4 6
9 2
11 1
8 1
9 3
5 2
1 6
5 3
8 18
1 6
6 5
4 6
8 4
2 1
7 4
8 2
3 8
4 2
6 2
1 7
1 5
5 3
5 8
2 5
2 3
7 5
8 6
14 19
7 5
6 8
11 14
4 3
2 9
2 12
13 10
2 6
4 9
11 10
8 13
2 1
2 11
4 10
13 4
14 1
1 5
12 1
2 3
8 19
2 1
8 2
5 2
4 3
5 4
7 4
8 4
4 6...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 50000 token(s): yes count is 0, no count is 50000

Test #15:

score: 0
Accepted
time: 208ms
memory: 3788kb

input:

50000
10 18
2 5
2 4
6 8
4 1
1 2
9 6
1 3
7 6
9 1
2 6
10 1
2 7
7 8
1 5
2 10
8 4
8 1
10 5
9 18
7 2
5 1
1 4
8 5
9 2
6 9
3 4
3 1
9 7
1 2
1 8
3 6
8 9
8 2
7 3
7 1
6 7
3 2
15 21
2 8
2 1
9 2
13 4
15 8
6 5
6 14
12 2
8 9
4 7
4 6
15 5
7 5
11 8
10 8
4 2
4 9
13 12
1 3
8 6
5 1
8 18
6 2
4 2
7 2
4 7
1 2
1 8
5 8
2 8
...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 50000 token(s): yes count is 0, no count is 50000

Test #16:

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

input:

100000
8 12
3 7
4 2
1 2
6 3
8 5
3 4
8 3
7 5
5 1
6 5
3 1
2 6
9 12
2 4
2 7
3 2
1 2
8 3
8 7
3 9
2 5
5 6
1 9
7 9
6 7
9 11
7 4
2 1
2 5
6 4
2 3
3 9
8 7
6 8
9 5
2 4
9 4
9 9
3 9
1 6
2 1
8 2
7 4
3 4
3 5
8 5
2 3
8 10
8 4
3 2
1 2
5 2
7 2
2 4
5 6
1 6
3 6
4 6
8 11
2 1
1 3
1 7
2 8
5 4
3 4
5 8
6 5
3 8
6 2
3 6
8 9
...

output:

NO
NO
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
NO
NO
YES
YES
YES...

result:

ok 100000 token(s): yes count is 34776, no count is 65224

Test #17:

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

input:

58000
10 16
10 3
9 3
9 1
2 8
5 6
8 4
9 8
6 2
7 9
2 1
1 10
3 4
5 1
3 2
5 7
7 10
10 18
9 2
3 5
10 2
6 4
1 5
4 5
3 2
6 7
6 9
1 8
8 3
10 6
2 1
8 9
2 4
8 10
4 8
7 5
13 18
5 9
4 12
1 2
12 11
4 3
13 11
7 10
3 11
2 7
6 8
1 4
2 3
4 7
2 5
13 10
13 2
9 3
2 6
11 17
8 1
2 1
10 5
4 1
9 11
5 4
6 1
1 10
6 11
3 9
11...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO...

result:

ok 58000 token(s): yes count is 822, no count is 57178

Test #18:

score: 0
Accepted
time: 1478ms
memory: 472104kb

input:

1
1000001 1000000
75323 899203
532596 656242
154951 354315
940187 69090
81695 56960
680563 733660
6795 18583
618176 81766
966333 66337
526616 512574
296179 581283
369416 262888
617387 502024
194775 382106
79394 284916
36706 17157
672152 983496
326170 36407
574557 76932
556564 41755
614817 269172
464...

output:

YES

result:

ok YES

Test #19:

score: 0
Accepted
time: 1443ms
memory: 471972kb

input:

1
1000000 1000000
87109 747393
109821 106613
147275 41633
242825 184874
18168 387743
128090 318244
294954 57905
971907 69957
72090 259657
514857 327272
87028 132775
18548 16405
188795 134920
32492 144111
292966 790905
291204 661324
59848 26383
474817 372099
195521 117902
876185 837421
68934 115446
1...

output:

NO

result:

ok NO

Test #20:

score: 0
Accepted
time: 1216ms
memory: 562340kb

input:

1
1000000 1000000
372528 372529
570332 570331
2574 2573
859851 859852
767997 767996
200383 200384
474830 474829
875254 875255
559145 559146
136847 136848
945683 945682
372718 372719
38032 38033
553293 553294
140703 140704
65059 65060
10663 10664
521738 521737
202404 202403
550539 550540
688993 68899...

output:

NO

result:

ok NO

Test #21:

score: 0
Accepted
time: 1171ms
memory: 383504kb

input:

1
1000000 1000000
1 7525
1 114847
250651 1
722357 1
331797 1
257631 1
621413 1
831588 1
929858 1
119517 1
1 509852
1 88909
1 530948
733605 1
570510 1
313622 1
712015 1
1 400615
1 818527
1 996703
223147 1
609952 1
523399 1
131394 1
1 984360
32918 1
188874 1
324753 1
314000 1
1 84010
1 301130
44093 1
...

output:

NO

result:

ok NO

Test #22:

score: 0
Accepted
time: 1169ms
memory: 383200kb

input:

1
1000000 1000000
1 780175
1 840819
1 106085
1 923792
1 291856
1 869323
1 2586
1 486969
1 909106
745668 1
1 65605
193929 1
1 763755
629994 1
66006 1
1 949317
869692 1
660866 1
1 41144
1 692261
52010 1
140409 1
713499 1
1 569250
510266 1
1 492147
16321 1
989831 1
783927 1
910647 1
445016 1
769429 1
2...

output:

NO

result:

ok NO

Test #23:

score: 0
Accepted
time: 1227ms
memory: 563668kb

input:

1
1000000 1000000
696689 696690
127021 127022
39865 39864
780012 780013
575968 575967
734929 734928
979468 979467
182690 182691
632155 632156
129484 129485
968873 968872
681622 681621
529233 529232
215439 215438
414760 414761
254604 254603
969773 969774
343930 343931
636992 636993
146798 146799
3175...

output:

NO

result:

ok NO

Test #24:

score: 0
Accepted
time: 1229ms
memory: 563372kb

input:

1
1000000 1000000
744914 744915
304488 304487
143074 143075
178003 178004
130146 130147
182117 182118
398123 398124
215960 215959
146693 146694
526037 526038
109328 109329
707869 707868
223250 223249
421693 421694
354351 354352
42186 42187
455120 455121
685884 685883
626559 626558
109244 109243
2404...

output:

YES

result:

ok YES

Extra Test:

score: 0
Extra Test Passed