QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#513802#9173. Touching Grassucup-team159#AC ✓1312ms28988kbC++2321.6kb2024-08-10 19:50:532024-08-10 19:50:53

Judging History

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

  • [2024-08-10 19:50:53]
  • 评测
  • 测评结果:AC
  • 用时:1312ms
  • 内存:28988kb
  • [2024-08-10 19:50:53]
  • 提交

answer

#line 1 "G/main.cpp"
#include <algorithm>
#define YOSUPO_AVX2_PRAGMA
// #undef YOSUPO_LOCAL

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

#include <unistd.h>
#line 5 "/home/vscode/yosupo-library/src/yosupo/fastio.hpp"
#include <array>
#include <bit>
#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 6 "G/main.cpp"
using namespace yosupo;

#line 2 "G/base.hpp"

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

#line 11 "G/base.hpp"
#include <bitset>
#line 13 "G/base.hpp"
#include <cmath>
#include <cstdio>
#line 16 "G/base.hpp"
#include <iostream>
#include <map>
#include <queue>
#include <ranges>
#include <set>
#line 22 "G/base.hpp"
#include <utility>
#line 24 "G/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 9 "G/main.cpp"

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

using D = int;
const D EPS = 0;

int sgn(D a) { return (a < -EPS) ? -1 : (a > EPS); }
int sgn(D a, D b) { return sgn(a - b); }
struct P {
    D x, y;
    P(D _x = D(), D _y = D()) : x(_x), y(_y) {}
    P operator+(const P& r) const { return {x + r.x, y + r.y}; }
    P operator-(const P& r) const { return {x - r.x, y - r.y}; }
    P operator*(const P& r) const {
        return {x * r.x - y * r.y, x * r.y + y * r.x};
    }

    P operator*(const D& r) const { return {x * r, y * r}; }
    P operator/(const D& r) const { return {x / r, y / r}; }

    P& operator+=(const P& r) { return *this = *this + r; }
    P& operator-=(const P& r) { return *this = *this - r; }
    P& operator*=(const P& r) { return *this = *this * r; }
    P& operator*=(const D& r) { return *this = *this * r; }
    P& operator/=(const D& r) { return *this = *this / r; }

    P operator-() const { return {-x, -y}; }

    bool operator<(const P& r) const {
        return 2 * sgn(x, r.x) + sgn(y, r.y) < 0;
    }
    bool operator==(const P& r) const { return sgn((*this - r).rabs()) == 0; }
    bool operator!=(const P& r) const { return !(*this == r); }

    D norm() const { return x * x + y * y; }
    D rabs() const { return max(std::abs(x), std::abs(y)); }  // robust abs

    pair<D, D> to_pair() const { return {x, y}; }
};
ostream& operator<<(ostream& os, const P& p) {
    return os << "P(" << p.x << ", " << p.y << ")";
}

ll crs(P a, P b) { return 1LL * a.x * b.y - 1LL * a.y * b.x; }

int main() {
    int n;
    sc.read(n);

    using Pi = pair<P, int>;
    V<Pi> ps(n);
    {
        for (int i : iota(0, n)) {
            int x, y;
            sc.read(x, y);
            ps[i] = Pi(P(x, y), i + 1);
        }
        sort(ps, [&](Pi l, Pi r) {
            if (l.first.x != r.first.x) return l.first.x < r.first.x;
            return l.first.y > r.first.y;
        });
        ps.erase(std::unique(ps.begin(), ps.end(),
                            [&](Pi l, Pi r) { return l.first.x == r.first.x; }),
                ps.end());
    }
    dbg(ps);

    int q;
    sc.read(q);

    struct Q {
        int l, r, idx;
        // cross: dy * X - dx * Y <= c
        int dx, dy;
        ll c;
    };

    dbg(sizeof(P), sizeof(Pi), sizeof(Q));

    V<Q> ques(q);
    {
        V<int> xs(n);
        for (int i : iota(0, n)) {
            xs[i] = ps[i].first.x;
        }
        for (int i : iota(0, q)) {
            int x1, y1, x2, y2;
            sc.read(x1, y1, x2, y2);
            if (x1 > x2) {
                swap(x1, x2);
                swap(y1, y2);
            }
            int l =
                int(std::lower_bound(xs.begin(), xs.end(), x1) - xs.begin());
            int r =
                int(std::lower_bound(xs.begin(), xs.end(), x2) - xs.begin());
            ll c = 1LL * x1 * y2 - 1LL * y1 * x2;
            ques[i] = {l, r, i, x2 - x1, y2 - y1, c};
        }
    }

    V<int> ans(q, -1);

    using QI = pair<int, int>;

    V<QI> qv;
    qv.reserve(2 * q);
    for (int layer = 0; (1 << layer) <= n; layer++) {
        int len = 1 << layer;

        qv.clear();
        for (int i : iota(0, q)) {
            if (ques[i].l + len <= ques[i].r) {
                if ((ques[i].l >> layer) & 1) {
                    qv.push_back({ques[i].l, i});
                    ques[i].l += len;
                }
            }
            if (ques[i].l + len <= ques[i].r) {
                if ((ques[i].r >> layer) & 1) {
                    ques[i].r -= len;
                    qv.push_back({ques[i].r, i});
                }
            }
        }
        sort(qv.begin(), qv.end());
        int qi = 0;

        V<int> pol;
        pol.reserve(len);
        for (int l = 0; l + len <= n; l += len) {
            int r = l + len;

            // convex
            pol.clear();
            for (int i : iota(l, r)) {
                int m;
                while ((m = int(pol.size())) > 1) {
                    if (crs(ps[pol[m - 1]].first - ps[pol[m - 2]].first,
                            ps[i].first - ps[pol[m - 2]].first) < 0)
                        break;
                    pol.pop_back();
                }
                pol.push_back(i);
            }

            // query
            int m = int(pol.size());
            while (qi < int(qv.size()) && qv[qi].first == l) {
                Q que = ques[qv[qi].second];
                qi++;

                auto check = [&](int idx) {
                    P p = ps[pol[idx]].first;
                    ll z = 1LL * que.dy * p.x - 1LL * que.dx * p.y;
                    if (z <= que.c) {
                        ans[que.idx] = ps[pol[idx]].second;
                    }
                    return z;
                };
                int lw = 0, up = (m - 1);
                while (up - lw > 2) {
                    int md1 = (lw + lw + up) / 3;
                    int md2 = (lw + up + up) / 3;
                    if (check(md1) > check(md2)) {
                        lw = md1;
                    } else {
                        up = md2;
                    }
                }
                for (int i : iota(lw, up + 1)) {
                    check(i);
                }
            }
        }
    }

    for (int i : iota(0, q)) {
        pr.writeln(ans[i]);
    }
    return 0;
}

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

详细

Test #1:

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

input:

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

output:

3
3
-1

result:

ok 3 queries

Test #2:

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

input:

1
7 10
1
5 3 9 7

output:

1

result:

ok 1 queries

Test #3:

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

input:

2
33 7
86 14
2
72 74 56 83
70 95 100 66

output:

-1
-1

result:

ok 2 queries

Test #4:

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

input:

3
590 27
77 202
795 527
3
76 639 304 621
275 361 860 959
788 734 405 422

output:

-1
-1
-1

result:

ok 3 queries

Test #5:

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

input:

5
258 931
102 85
383 957
124 128
796 906
5
329 73 759 927
480 626 118 591
440 370 595 676
407 887 608 182
399 850 65 102

output:

3
3
-1
-1
3

result:

ok 5 queries

Test #6:

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

input:

8
515 549
180 48
6 444
280 37
860 488
17 622
457 161
915 348
8
424 777 116 971
323 964 277 458
4 482 804 312
770 206 244 512
971 178 688 265
531 426 320 591
736 230 865 762
552 762 454 129

output:

-1
-1
6
1
8
1
-1
1

result:

ok 8 queries

Test #7:

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

input:

13
335 343
437 210
961 689
756 260
716 897
899 129
424 638
179 109
742 319
135 378
561 658
205 18
598 724
13
911 515 141 839
78 158 981 973
571 643 962 720
112 604 755 516
80 339 410 773
192 638 458 45
347 818 629 857
44 606 76 950
269 990 644 872
556 97 298 783
44 619 752 978
119 74 28 214
902 226 ...

output:

5
13
5
13
-1
2
-1
-1
-1
7
-1
-1
13

result:

ok 13 queries

Test #8:

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

input:

10
92 583
165 167
58 286
62 426
156 591
673 825
640 518
254 791
102 651
197 154
10
798 988 642 805
637 34 533 820
926 453 952 99
289 626 798 261
489 612 719 420
441 522 975 262
845 782 988 920
229 807 454 810
270 720 967 281
945 187 250 604

output:

-1
-1
-1
6
6
6
-1
-1
6
6

result:

ok 10 queries

Test #9:

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

input:

10
580 141
638 496
866 385
438 257
759 113
479 705
963 957
812 555
616 986
548 992
10
612 256 901 196
809 867 277 212
995 108 957 8
292 194 922 835
934 864 838 966
972 483 649 763
568 762 19 827
712 894 961 920
514 519 734 947
276 698 492 827

output:

8
10
7
9
-1
7
10
-1
9
-1

result:

ok 10 queries

Test #10:

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

input:

10
411 160
78 181
160 292
586 903
76 152
337 349
603 339
245 326
734 532
812 18
10
735 47 816 111
799 113 664 236
490 291 28 392
419 672 795 228
473 66 583 800
520 12 157 224
59 18 617 507
690 383 744 83
22 306 545 123
819 137 22 23

output:

-1
9
6
4
-1
1
4
9
8
7

result:

ok 10 queries

Test #11:

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

input:

10
65 315
794 631
93 430
241 748
627 717
17 796
293 158
5 316
726 566
341 597
10
649 66 383 213
995 178 432 719
444 692 427 839
579 583 210 240
701 572 237 10
589 127 591 243
468 32 10 86
888 600 568 324
402 267 935 56
292 261 127 348

output:

5
2
-1
4
5
-1
7
2
2
4

result:

ok 10 queries

Test #12:

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

input:

10
1 731
733 836
217 848
666 864
864 698
740 427
464 695
369 694
356 707
316 594
10
40 485 971 195
124 99 694 29
747 235 841 73
831 105 619 128
840 220 770 154
690 649 9 21
163 400 280 398
247 610 475 325
824 258 62 684
259 673 911 370

output:

2
7
-1
2
-1
7
3
7
2
2

result:

ok 10 queries

Test #13:

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

input:

10
36 458
114 866
202 362
687 667
82 766
515 524
254 847
316 914
404 884
439 806
10
765 141 658 35
394 79 867 542
182 194 657 52
536 32 860 552
662 717 901 80
882 746 790 717
626 349 704 702
819 198 730 79
620 144 805 773
890 264 708 199

output:

4
4
9
4
4
-1
4
-1
4
-1

result:

ok 10 queries

Test #14:

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

input:

100
104375211 269633504
751249866 429319365
689374899 460732977
314375099 460732977
809374835 384816748
621874935 481675385
98750214 259162300
526249986 497382191
869374803 319371723
978124745 36649215
235625141 418848161
61250234 175392668
959374755 120418847
940624765 180628270
708124889 452879574...

output:

-1
-1
-1
80
95
-1
-1
85
-1
74
18
3
77
-1
31
-1
91
-1
-1
-1
-1
19
-1
93
-1
80
-1
-1
16
57
-1
-1
-1
92
24
58
93
93
80
80
-1
33
20
85
-1
39
57
92
3
80
-1
63
-1
-1
21
93
-1
93
-1
11
77
56
93
4
-1
39
6
11
-1
83
33
17
-1
-1
91
-1
80
32
8
57
25
53
-1
-1
-1
80
-1
93
-1
80
25
-1
21
16
32
-1
80
-1
-1
-1

result:

ok 100 queries

Test #15:

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

input:

100
578906149 184293121
327343971 93193681
311718991 53403121
527343715 196858561
687499760 60732961
628906085 153926641
382812650 162303601
310156493 48167521
674218527 93193681
559374924 190575841
693749752 39790561
442187574 190575841
613281105 166492081
455468807 193717201
378906405 159162241
40...

output:

-1
-1
-1
-1
-1
-1
-1
-1
79
32
27
53
10
80
-1
79
-1
100
47
-1
-1
-1
50
-1
100
52
45
35
32
53
100
45
97
4
-1
-1
-1
79
95
-1
49
45
71
93
53
-1
80
22
32
-1
-1
-1
-1
35
95
-1
-1
100
-1
-1
4
79
-1
-1
-1
-1
10
-1
35
-1
80
-1
-1
53
100
53
97
-1
-1
-1
-1
53
35
1
-1
55
-1
79
53
-1
-1
-1
-1
-1
100
79
71
-1
-1
80

result:

ok 100 queries

Test #16:

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

input:

100
689374899 184293121
290000112 180104641
610624941 193717201
361250074 190575841
38750246 39790561
265625125 174869041
21875255 5235601
44375243 48167521
194375163 153926641
168125177 143455441
809374835 153926641
942499764 70157041
98750214 103664881
882499796 119371681
209375155 159162241
90499...

output:

-1
-1
1
46
61
46
-1
-1
-1
70
9
3
-1
-1
-1
36
-1
57
76
63
-1
-1
-1
70
-1
25
79
-1
61
-1
70
70
-1
57
17
-1
57
4
70
-1
70
62
-1
-1
87
95
-1
25
99
22
25
25
-1
-1
70
-1
70
-1
25
-1
32
45
63
-1
-1
73
-1
70
90
40
97
-1
25
45
97
82
-1
70
69
-1
96
96
88
22
-1
35
4
-1
-1
-1
48
-1
-1
25
-1
34
6
-1
60
-1

result:

ok 100 queries

Test #17:

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

input:

100
464062523 494764390
206250188 335078529
832812287 269633504
860937269 198952877
193750196 316753922
154687721 232984290
245312663 384816748
673437389 452879574
554687465 492146589
410937557 484293186
898437245 36649215
826562291 282722509
867187265 180628270
176562707 282722509
101562755 1308900...

output:

70
75
-1
-1
-1
75
52
89
75
-1
-1
-1
-1
80
-1
85
72
-1
-1
71
-1
92
-1
24
86
-1
77
52
-1
52
75
62
62
5
80
72
-1
-1
-1
-1
-1
65
52
75
40
52
7
7
-1
68
-1
-1
52
70
64
77
-1
80
75
5
-1
-1
-1
-1
-1
52
-1
23
52
-1
-1
48
52
14
89
-1
-1
-1
-1
52
52
-1
-1
-1
-1
-1
27
53
-1
85
-1
-1
-1
100
-1
53
-1
-1
97
20

result:

ok 100 queries

Test #18:

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

input:

1000
99265 42424
6525 80276
43140 68127
51964 40908
9094 12209
56077 44140
35448 98852
28625 82098
19575 99100
71555 84605
82554 53440
66211 96383
32553 56834
24935 45751
93854 42815
48816 77595
43061 84311
28790 91865
82689 42188
14193 68109
25414 35706
42978 37435
95707 24033
5230 8768
98110 60382...

output:

436
685
289
168
819
671
576
568
633
564
321
164
321
671
436
505
671
671
633
484
625
868
164
671
505
543
227
819
418
436
702
827
543
164
996
32
543
229
436
671
633
543
749
182
671
633
633
126
164
543
32
671
227
168
164
702
999
633
633
436
702
803
436
633
9
418
95
192
227
827
843
543
507
671
567
543
4...

result:

ok 1000 queries

Test #19:

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

input:

1000
28300 86536
22994 53484
20020 15737
26356 89356
26753 11847
30605 50013
42932 18585
8899 72465
4411 49361
26585 90626
51327 84833
52365 90943
401 48310
10162 38550
50430 95099
1622 24788
12739 10766
14862 73531
33902 46319
32354 4223
11820 34406
45407 20670
14396 75226
75914 58613
8972 69295
27...

output:

941
941
715
731
626
715
850
731
941
731
947
575
715
398
731
731
390
410
358
850
731
731
382
731
382
941
850
617
826
490
134
626
941
731
904
488
382
544
626
731
390
715
731
731
490
668
941
715
544
731
410
826
595
799
941
941
575
941
941
850
399
993
935
731
717
731
595
382
731
575
941
731
382
941
410
...

result:

ok 1000 queries

Test #20:

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

input:

1000
78977 2074
66043 47947
64156 52000
51800 85017
72769 95309
46109 79414
36736 33830
49795 80993
55338 34213
43064 76999
65173 82889
66315 3970
99433 51579
66787 4438
58356 6041
93272 76919
50078 59284
56182 1396
67908 10035
43286 8887
97186 26326
96899 31500
63434 29455
48732 30636
35450 11558
9...

output:

435
408
248
625
312
173
396
746
173
590
37
590
882
972
762
725
627
458
345
268
972
248
836
445
627
447
173
952
445
37
762
408
763
248
860
268
248
194
972
408
458
443
345
445
445
590
627
763
312
173
972
627
763
248
248
423
272
169
763
173
972
952
248
489
248
268
972
646
485
763
268
625
268
141
312
75...

result:

ok 1000 queries

Test #21:

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

input:

1000
36848 40244
44170 64859
73782 6532
73472 36699
46777 34630
63459 23868
78986 72094
26865 4675
77925 17395
47410 23785
94705 11395
33118 67032
22374 19144
80516 8954
18542 45485
98758 26287
74867 20978
12033 1526
46253 7927
98382 56613
5121 17203
79008 36907
43003 28552
26916 58370
19889 4914
67...

output:

273
278
60
782
166
894
166
972
166
972
118
118
972
278
732
632
894
260
972
972
676
703
501
277
994
10
470
495
972
371
30
278
676
930
994
166
30
994
972
166
894
972
676
732
676
972
972
703
894
166
703
676
972
994
693
270
972
45
329
639
30
676
894
495
260
30
894
241
972
963
894
821
371
470
587
972
30
...

result:

ok 1000 queries

Test #22:

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

input:

1000
68145 63988
20049 98052
65320 22484
51398 26637
97914 51952
59106 47893
72627 33233
29799 7761
46724 11815
12844 6192
33841 34192
77477 42156
34099 67744
35764 32534
48996 75348
2282 58347
88521 63517
52160 16252
4725 36435
49709 34142
24477 86718
15505 15637
92399 27917
93836 96166
15947 48818...

output:

-1
368
540
540
607
279
635
635
-1
540
659
460
59
279
-1
164
460
2
322
635
659
444
63
460
635
900
635
370
59
659
659
356
861
623
315
781
59
739
635
315
635
443
279
537
460
256
621
197
197
233
59
711
659
444
635
550
776
776
468
175
540
368
607
540
540
356
468
659
635
-1
322
659
175
607
197
659
215
659...

result:

ok 1000 queries

Test #23:

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

input:

1000
32262 64303
61279 44889
65478 96756
56972 89836
44573 79202
44593 95816
14861 37219
39343 89033
9952 60289
45649 51122
97456 86044
9778 80279
67982 59088
9670 68241
96441 28060
21016 68624
39423 73225
42680 27947
13255 72628
99637 80438
47774 87915
22076 84626
92140 53091
87815 38151
13374 9221...

output:

498
786
800
977
371
528
612
203
677
981
498
371
430
203
150
860
612
498
518
430
518
786
21
800
146
615
612
203
518
498
518
612
430
612
81
624
203
800
719
742
371
371
612
518
800
719
203
877
518
732
371
203
430
953
518
203
612
498
619
981
498
981
498
612
786
498
203
203
518
612
719
612
612
690
203
37...

result:

ok 1000 queries

Test #24:

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

input:

1000
34857 67019
7415 19038
58888 94480
24948 36803
4940 97142
6746 73658
12646 64268
8936 83873
26881 43000
13264 45746
29912 79916
63241 96138
23329 38401
13070 78956
71587 84047
54276 87450
4314 66647
45825 75136
11422 96929
17321 83961
64272 56369
5721 67445
6924 54753
11517 42364
30176 46402
75...

output:

538
445
221
445
545
970
99
574
800
526
970
788
526
524
800
260
970
880
464
299
792
464
554
800
218
448
-1
526
538
99
99
649
464
218
464
574
445
684
135
800
504
238
699
445
645
800
299
645
260
445
260
353
800
950
445
800
534
990
218
534
545
853
99
792
135
800
464
659
950
273
445
218
218
792
645
554
2...

result:

ok 1000 queries

Test #25:

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

input:

10000
38272240 171963896
85763537 299021340
209046366 429572370
100566222 323438826
348521793 484670406
683539908 476578264
58128140 238845144
29955072 128921788
390127712 492238275
568014266 497017858
70914001 269704370
596910178 493996823
814144879 413794809
20346155 19534460
68799013 265021178
85...

output:

8602
4201
1274
7787
-1
3807
6942
-1
8012
-1
1953
-1
3471
126
-1
4688
8324
6881
2244
1448
-1
6981
-1
-1
-1
225
-1
-1
-1
9652
-1
3859
-1
3407
-1
6768
706
-1
5023
-1
3857
1993
8681
3627
-1
-1
-1
-1
-1
-1
3972
711
5245
3487
-1
7288
8607
8317
-1
7485
4741
-1
1274
4529
-1
511
-1
9958
-1
4729
9865
-1
6548
...

result:

ok 10000 queries

Test #26:

score: 0
Accepted
time: 16ms
memory: 3852kb

input:

10000
538046266 197784461
476080108 199045941
663791061 132905661
631533394 164931461
340414522 138392441
499419375 199834601
366910531 163795941
674331495 116306201
461428849 197724301
694164716 60114881
400704764 182737881
560764961 194261341
365066466 162412261
620699396 172029401
664760937 13156...

output:

5599
8776
140
-1
-1
5760
3980
-1
3591
1048
184
-1
895
-1
-1
692
-1
-1
-1
6318
-1
7520
3212
-1
-1
8961
-1
-1
4968
130
-1
-1
-1
8664
9472
-1
-1
8184
4917
-1
-1
-1
-1
-1
9512
8119
7078
314
-1
-1
2656
794
7243
9507
-1
3453
7320
1122
5608
-1
8992
-1
-1
-1
4550
6573
-1
-1
2822
-1
-1
3096
9560
-1
2578
9992...

result:

ok 10000 queries

Test #27:

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

input:

10000
966569030 59529261
112676090 136241721
793202482 171189981
571992139 198585341
732637525 183723941
20747735 12892101
683252109 190583121
907025871 124519921
48407673 83990881
254143800 181424701
155339503 155319021
751353384 180404801
120315034 140204761
918000160 116802521
99742983 128818541
...

output:

3871
2274
9704
-1
5758
-1
-1
9574
9439
-1
9040
2566
-1
9656
8283
-1
674
2951
3936
-1
6822
1027
-1
-1
3005
559
2700
1066
-1
-1
-1
-1
4305
-1
-1
-1
1967
9518
-1
-1
6040
4558
6531
3684
3739
537
-1
-1
7834
-1
-1
-1
6166
7209
5730
1227
4946
3857
-1
-1
-1
5156
8811
-1
5758
5547
-1
-1
-1
-1
700
7317
5749
-...

result:

ok 10000 queries

Test #28:

score: 0
Accepted
time: 17ms
memory: 4048kb

input:

10000
102060601 62886900
627280153 484390637
100184870 11682120
102434260 68830228
463939118 498680015
867963024 239597464
456246576 498153391
893113435 117470067
152868930 294737818
899722180 17406805
112567669 157035046
891276743 131860538
344381251 475642566
775896049 400445831
794264828 38029070...

output:

6145
-1
-1
3581
2094
3936
-1
2441
40
1407
-1
-1
5989
-1
-1
-1
-1
-1
2719
-1
-1
-1
5585
2805
4658
-1
-1
3776
2624
-1
4875
5639
5753
-1
4029
-1
-1
5823
6439
6394
-1
-1
9431
2952
-1
5588
3352
8297
-1
-1
3722
-1
927
-1
6570
-1
7946
4301
8059
8546
8729
416
8546
-1
-1
5485
-1
-1
-1
5562
6531
4057
5984
-1
...

result:

ok 10000 queries

Test #29:

score: 0
Accepted
time: 374ms
memory: 17960kb

input:

1000
950113785 186384430
159684420 380691928
423030085 495461044
956718680 161922916
650997055 482691826
96120480 297230473
28763630 87692221
222855990 430845724
250779655 446691862
416817560 494768737
980064695 1153846
34256810 120153727
789634455 422768809
456250745 498230272
231488130 436153411
2...

output:

813
-1
123
745
866
-1
-1
268
901
512
-1
-1
918
86
-1
71
-1
123
798
-1
-1
410
87
585
-1
606
700
-1
-1
352
-1
444
-1
902
-1
-1
-1
880
-1
-1
736
-1
-1
946
-1
448
-1
-1
-1
91
828
16
663
443
295
268
576
995
438
-1
236
-1
802
143
468
802
-1
-1
587
-1
-1
-1
273
552
365
780
457
400
754
-1
874
844
-1
-1
-1
-...

result:

ok 300000 queries

Test #30:

score: 0
Accepted
time: 327ms
memory: 16828kb

input:

1000
697377268 28215174
392183621 176644830
692908760 53845751
570106531 191260105
355781629 149906569
345427769 138460501
699230064 11261455
529617489 198429282
557845381 194213929
388913981 174890997
651248097 142522009
310115657 66122582
475750170 198890817
388178312 174491000
673645131 109291489...

output:

541
897
825
-1
853
841
929
564
-1
107
827
-1
-1
170
298
335
411
-1
-1
-1
703
141
-1
-1
-1
-1
107
-1
687
845
-1
201
726
-1
853
386
20
314
851
-1
-1
-1
-1
955
-1
653
572
494
-1
13
933
532
654
841
482
-1
-1
-1
170
814
277
934
-1
-1
386
121
236
897
-1
726
147
94
386
-1
-1
-1
892
386
-1
107
959
-1
-1
-1
...

result:

ok 300000 queries

Test #31:

score: 0
Accepted
time: 375ms
memory: 16968kb

input:

1000
271640660 182644785
671792665 190860108
39096040 57476493
66104175 93568530
77025140 103937683
73755390 101014628
597046180 197198522
756217610 177229441
28044285 33107445
63030610 90337785
68916160 96399278
20981625 6092263
728490130 182644785
922647885 104337680
58060590 84737827
23074265 162...

output:

670
-1
211
338
-1
160
86
846
183
35
706
750
206
730
500
541
-1
-1
846
-1
630
147
-1
669
-1
-1
-1
-1
649
472
483
665
-1
-1
-1
319
326
-1
-1
1
-1
21
-1
670
284
-1
952
643
-1
915
-1
553
527
361
-1
-1
959
-1
730
-1
326
-1
826
-1
-1
-1
-1
-1
117
984
650
-1
7
378
307
-1
984
569
-1
-1
310
-1
-1
-1
348
-1
-...

result:

ok 300000 queries

Test #32:

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

input:

800000
784741874 210533410
353085426 422755675
781708646 222556219
506812566 458364034
622169826 435235123
805863650 34374448
645900698 423339673
605188280 441890482
729903354 343317577
516837948 458064559
207100590 171244993
805215474 52868296
323627088 402563830
193698202 8877208
731245436 3412825...

output:

453323
-1
425170
263915
282800
719318
722468
-1
-1
381427
-1
42052
771236
269685
-1
223061
318985
-1
-1
493323
360078
-1
-1
400290
-1
667353
588454
-1
313798
788163
124584
204894
519026
581250
625883
208948
799410
-1
-1
30266
-1
515671
127478
445607
707364
200549
-1
268650
-1
206383
12109
559239
-1
...

result:

ok 1000 queries

Test #33:

score: 0
Accepted
time: 1074ms
memory: 26872kb

input:

800000
15080485 373982169
614292757 749424468
378357740 628541521
79381350 843893217
453124596 119687443
484302417 974146980
516574553 714424410
430785761 282534933
619155709 566316775
649254128 947571187
579369273 470081889
732948204 583913287
625089279 367784769
945725299 140561959
209803202 62339...

output:

688244
497225
711909
87162
400412
688244
186891
433031
360168
195767
411049
407159
595461
433031
744265
595350
87162
195767
305582
497225
587031
433031
195767
459281
347988
541571
497225
360168
744265
360168
400412
300552
187231
190365
530150
400412
714326
360168
711909
497225
497225
433031
711909
1...

result:

ok 300000 queries

Test #34:

score: 0
Accepted
time: 1053ms
memory: 26420kb

input:

800000
970862261 177937361
320989261 359990571
312920234 84857429
506272064 53645521
670985814 111918467
981396383 144694379
874534410 89958190
632186002 67853132
401513257 615236965
950421177 140354653
163951033 125742729
346216429 321373855
348435258 69323315
197782340 66308601
320792790 185377967...

output:

658623
152152
439150
489840
152152
152152
755562
152152
742645
748335
258734
301532
535767
144199
343766
544332
152152
439150
152152
152152
584661
166728
152152
755562
343766
634497
301532
152152
35882
144199
343766
144199
144199
258734
144199
677738
166728
95713
357938
152152
301532
144199
343766
1...

result:

ok 300000 queries

Test #35:

score: 0
Accepted
time: 1051ms
memory: 26348kb

input:

800000
356316339 447808912
751110608 792107918
99787335 360590392
635903936 892982116
589354691 432044768
736118372 905462318
115688455 353611127
468465955 811503516
684297455 707955369
406557555 800894802
377108926 805379888
485562074 944224487
852274684 653824477
205450280 368507930
406144647 7949...

output:

485322
153649
609532
153649
164033
687588
356293
337998
153649
593037
485322
164033
721096
164033
164033
734146
519416
356293
164033
164033
164033
164033
164033
337998
388666
478698
227462
153649
125899
39392
527375
93828
609532
24364
734146
768400
63791
153649
687588
135959
164033
609532
153649
420...

result:

ok 300000 queries

Test #36:

score: 0
Accepted
time: 984ms
memory: 25616kb

input:

800000
435968634 684362547
441064604 505046464
620484857 319028341
792345009 848373099
406573813 192217214
787140656 668338086
230367139 87502268
7703404 901849512
455820381 774559804
562289268 135429218
520747368 875359996
432291380 821751357
648738114 190011349
727553490 530479798
407700356 797048...

output:

508962
446214
517087
446214
120767
217840
552091
552536
576568
650884
120767
691669
420811
223405
278647
63493
446214
517087
679250
446214
256761
89943
576568
217840
460304
671409
120767
132938
456251
756250
723652
61485
401425
217840
89943
191613
287950
217840
409126
2587
115350
63493
217840
401425...

result:

ok 300000 queries

Test #37:

score: 0
Accepted
time: 984ms
memory: 25820kb

input:

800000
143880629 433393385
193643808 401935625
734144605 58191320
190108233 190306639
307572084 749789023
121817450 260320727
134903541 534247251
409365097 625924172
424385045 60106896
252114717 122961448
42626244 383252808
751403226 173229739
46834403 459189568
359323778 215474092
882772085 3671827...

output:

441804
37359
329972
96467
317696
614503
480541
371211
480541
343388
296767
15645
639128
181151
11217
92223
317696
96467
317696
15645
15645
432291
181068
11217
241396
317696
377021
15645
296767
709519
296767
441804
276551
251414
106129
480541
329972
11217
536566
67887
432291
614503
536566
441804
3003...

result:

ok 300000 queries

Test #38:

score: 0
Accepted
time: 980ms
memory: 26184kb

input:

800000
120950448 879584359
488651784 384240390
50352543 580051609
684557638 854032618
100203234 982242049
217991920 559662067
213687995 844385542
640792989 809993298
293538395 394639002
55549277 500280434
233493640 173065576
282807645 701191513
358926465 109895126
302448777 536794411
48385886 772998...

output:

780611
750215
523343
750215
750215
327653
780611
139685
750215
750215
750215
296074
696482
613671
619023
748862
29325
780611
780611
613671
750215
649682
748862
748862
228420
731178
372614
523343
523343
567573
345734
327653
172346
228420
345734
780611
750215
334605
748862
523343
613671
750215
618551
...

result:

ok 300000 queries

Test #39:

score: 0
Accepted
time: 1061ms
memory: 27320kb

input:

800000
258986337 48032349
495126669 937655014
363138946 448769089
947944161 53929755
695238886 486364930
892505590 867548021
875030640 945391816
977957428 818317778
651160767 12263458
769679148 273876574
587102465 436376813
886111321 650487953
923548509 996735880
941414107 662118453
515705115 756515...

output:

140474
385288
568655
640409
180799
572193
308807
453489
474684
444646
444646
44726
568655
140474
709139
3236
412729
568655
375110
709139
106635
104199
78460
104199
331815
81096
656366
709139
412729
355244
520331
444646
501811
444646
568655
572193
568655
576955
104199
453489
574691
716626
140474
5842...

result:

ok 300000 queries

Test #40:

score: 0
Accepted
time: 1057ms
memory: 27448kb

input:

800000
641334233 187074003
875766628 667554002
336586126 18610447
676448239 499188275
621023240 769515237
625565226 349609934
308558729 152015742
452394191 284105986
984185478 657079647
11781168 368322295
713554606 117993246
985186221 94429578
923572297 942840885
977883542 451479220
601049999 244349...

output:

530267
657402
766795
26110
147320
580160
766795
766795
638230
82796
113931
766795
422794
766795
169405
746665
790198
429805
766795
113931
766795
26110
746665
339267
638230
755680
755680
638230
746665
180419
756240
717009
766795
110363
746665
717009
232254
353954
638230
766795
530267
638230
782677
74...

result:

ok 300000 queries

Test #41:

score: 0
Accepted
time: 1047ms
memory: 27308kb

input:

800000
682431823 998431836
406575665 715536389
841120406 907463684
793426356 829068871
934050284 751400755
623576408 532345158
336831574 979273896
267559821 851441101
580059710 848375997
857971070 917959840
997245552 635406298
989754491 416304670
767863602 676672360
967769179 400935506
401530137 450...

output:

514109
738295
471721
477391
798969
68143
738295
753462
92492
267240
187978
377811
38811
738295
701426
112437
377811
377811
726219
17578
17578
701426
701426
9006
92492
17578
705716
705716
329892
732202
329892
182826
419153
584543
187978
701426
347279
773593
17578
92492
701426
38811
648426
709347
6814...

result:

ok 300000 queries

Test #42:

score: 0
Accepted
time: 1051ms
memory: 26080kb

input:

800000
260900518 163178668
316985323 38366297
864012643 36553540
639356817 372141031
901980026 653040850
979372608 57617402
463572691 67613183
465802714 237038526
984756848 217872622
400002897 37109692
508000917 448629376
807796704 247261183
374507931 33039202
376743300 20719885
182372501 150756837
...

output:

155959
598773
380869
610701
281583
766551
766261
611481
56151
715148
354325
56151
715148
247062
56151
189014
35482
611481
189014
344978
549299
292027
40462
344978
766551
371449
344978
766551
327338
696051
506758
766551
611481
766551
6665
715148
98741
344978
-1
189014
6665
766551
766551
344978
80336
...

result:

ok 300000 queries

Test #43:

score: 0
Accepted
time: 835ms
memory: 26360kb

input:

800000
251619778 603625954
88806435 329362117
123326212 392067283
296890364 355020689
453945473 85562108
371565146 158989343
6919200 580245649
73059719 45172878
328198756 4456177
616630236 812681826
508575995 177693374
50473678 49420471
33162113 377776961
389279708 556666414
400663114 454419600
2785...

output:

789214
699677
505631
699677
253797
231755
538505
789214
30064
9106
241183
367924
699677
455063
228836
699677
180966
482284
6903
455063
455063
795822
168202
699677
465562
45102
465562
45102
30064
538505
465562
455063
287156
482284
40346
40346
699677
488689
253797
12739
228836
367924
538505
465562
403...

result:

ok 300000 queries

Test #44:

score: 0
Accepted
time: 1042ms
memory: 25820kb

input:

800000
431411522 229477104
848697968 348780310
898224829 132660945
507266195 347040936
993745897 80751505
321545732 33082073
878225728 84657346
209237198 82627583
841969289 207966358
624596318 250828990
996107002 180430843
358130378 12508253
441659996 123282966
194576559 234455130
980404912 38272182...

output:

169228
498088
48160
169228
564897
564897
564008
508226
379112
479565
579564
558378
16760
-1
600429
318471
558378
169228
16760
1400
564897
564897
479565
793063
266711
379112
48160
564897
144915
564897
379112
508226
766394
600429
564897
564897
-1
558378
558378
558378
754868
564897
-1
171250
508226
259...

result:

ok 300000 queries

Test #45:

score: 0
Accepted
time: 690ms
memory: 25352kb

input:

800000
188938795 288699575
67887586 105641896
32659451 156569107
296727786 203608279
484158735 163446877
566391153 534307510
307733866 600060663
20710145 929949
432850012 187395623
139988134 18857803
40336164 528819843
33665824 69337269
458879498 322488348
293366055 70654341
374090214 494658918
2922...

output:

638686
319061
105828
-1
459541
21258
243098
-1
133087
-1
105828
133087
105828
105828
310797
-1
-1
638686
-1
208626
234712
342543
133087
105828
234712
638686
-1
105828
-1
-1
-1
-1
133087
509079
133087
638686
133087
59955
459541
21258
-1
-1
638686
133087
133087
638686
-1
-1
638686
509079
-1
105828
133...

result:

ok 300000 queries

Test #46:

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

input:

800000
360084296 195820110
910757589 108972900
308092165 6844895
671280725 135888029
391985030 78719755
793012367 138559273
832866938 99804758
784742353 332383861
644722058 59402949
412571121 24988121
678975223 547753759
255669626 46173402
668079205 198930675
336540127 145350434
607058233 34893572
3...

output:

328857
-1
149819
-1
-1
246178
149819
789906
-1
-1
-1
-1
-1
328857
577336
525801
577336
-1
-1
402760
402760
328857
798088
578149
-1
229306
294608
273416
-1
569836
-1
533744
-1
328857
798088
-1
-1
149819
-1
525801
-1
-1
607982
793444
-1
-1
533744
666677
708066
525801
437920
471601
149819
-1
607982
789...

result:

ok 300000 queries

Test #47:

score: 0
Accepted
time: 806ms
memory: 27336kb

input:

800000
152842815 74697484
203259578 28007914
411824102 137543311
438454387 197483150
336272234 310863327
17202834 532334222
619796690 62775834
394092189 99135257
349748840 122319719
167450725 108884484
658117474 69039084
98604967 161108018
287641562 13743817
447122406 190157107
325304405 218288364
6...

output:

-1
-1
-1
461628
461628
-1
554340
-1
-1
-1
-1
-1
391890
-1
-1
-1
218926
-1
-1
-1
-1
218926
-1
698033
-1
328468
706641
-1
218926
-1
-1
-1
-1
218926
-1
-1
698033
305149
-1
-1
554340
-1
698033
-1
-1
124715
305149
-1
721687
-1
698033
-1
-1
-1
-1
-1
698033
-1
-1
-1
-1
-1
218926
-1
-1
391890
-1
-1
-1
76093...

result:

ok 300000 queries

Test #48:

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

input:

800000
452584216 922884157
457016389 40191615
541267135 947490269
900953178 784029360
473550884 368219633
128951937 356906008
193915529 753085777
73540235 582645630
25564006 145574750
221031041 782127628
202616412 683241591
515050143 344401923
92110669 153190440
767616743 12663196
817130062 97449849...

output:

629742

result:

ok 1 queries

Test #49:

score: 0
Accepted
time: 28ms
memory: 14648kb

input:

1
693086739 667763491
300000
852876012 399679873 98139376 514550845
629716446 118469668 422688498 675874478
191667130 784447016 910409525 191474380
733775741 334768736 577278115 159083409
942644283 632600216 227316798 70214581
217095745 317102913 744033805 549805139
573318369 63393487 979854392 9169...

output:

1
-1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
1
1
-1
-1
-1
1
1
-1
-1
1
-1
1
-1
-1
1
-1
1
-1
1
-1
-1
1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
1
-1
1
1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
1
-1
1
1
-1
1
-1
-1
1
1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
1
-1
-1
1
1
-1
1
1
-1
-1
1
1
1
-1
-1
-1
-1
-1
1
...

result:

ok 300000 queries

Test #50:

score: 0
Accepted
time: 1045ms
memory: 25632kb

input:

800000
41248511 34357201
574577849 454048096
517186397 457183807
950307677 118677109
884752946 293758867
523251953 457045759
40963937 26801584
830652521 355644061
44452118 79190785
210502025 386830117
660988142 440055658
856475984 329978251
886582946 291023758
40526786 5722294
45751877 90901372
1542...

output:

635146
492833
743788
496594
492833
700905
625679
568557
322175
496594
635146
322175
205056
635146
492833
322175
568557
635146
568557
492833
156465
492833
635146
322175
625679
568557
625679
420601
238770
700905
523507
625679
635146
743788
568557
625679
238770
568557
700905
492833
625679
635146
568557...

result:

ok 300000 queries

Test #51:

score: 0
Accepted
time: 764ms
memory: 27012kb

input:

800000
632173228 91701637
346877067 4551964
458234225 149131846
357215851 68661617
652055837 24284057
352179990 51178978
636843939 82964895
347145301 12845078
354979892 61790667
361791238 80058138
593478354 130824625
368260289 92433013
359998066 75930841
600766613 126057656
644994608 61875640
597806...

output:

668434
668434
668434
406469
743773
406469
743773
668434
441150
406469
406469
743773
743773
406469
406469
668434
441150
668434
743773
406469
743773
743773
668434
406469
406469
406469
569863
743773
406469
719645
406469
406469
668434
406469
719645
406469
406469
719645
668434
668434
668434
406469
406469...

result:

ok 300000 queries

Test #52:

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

input:

800000
65757188 62689869
269370626 139188157
955510583 26518114
885050060 97772881
496458959 152446911
52161959 44208254
803719241 125720052
165125090 117275485
383955854 149639430
679628288 145065526
446211764 151891384
55291808 49323469
669690275 145960450
951580034 36874392
922974215 73479708
124...

output:

8666
407345
408473
227146
408473
341516
360756
368891
368891
360756
8666
408473
368891
368891
87279
368891
341516
341516
375628
341516
798462
227146
66656
794840
368891
341516
341516
168574
408473
408473
122286
227146
122286
375628
408473
368891
368891
8666
408473
66656
66656
87279
341516
66656
2271...

result:

ok 300000 queries

Test #53:

score: 0
Accepted
time: 996ms
memory: 26212kb

input:

800000
626237280 432349696
757003288 292641805
789494698 188072122
530105498 456180097
745028798 317009065
358140544 424528240
737435850 330335983
765006744 273409711
749242508 308949679
803641694 80019814
802061922 100008973
586576564 446588914
806114548 22337197
741009196 324243457
242852116 29231...

output:

142341
17173
643776
315351
315351
142341
187875
113961
142341
17173
346624
17173
315351
315205
17173
315351
315351
643776
142341
315205
17173
17173
17173
473478
142341
142341
187875
142341
17173
142341
142341
315351
17173
28651
274977
643776
315351
315351
315351
142341
315351
473478
28651
142341
315...

result:

ok 300000 queries

Test #54:

score: 0
Accepted
time: 1221ms
memory: 26380kb

input:

800000
834077927 353574577
845292725 342821431
179770262 365538184
41078210 31078891
501405284 458363770
154508981 342621811
99047747 268364593
98591429 267540160
153833189 341938897
71886272 207678379
349756385 443540857
957461744 58130191
518351111 458177836
911861876 247140037
427626734 455265973...

output:

757331
417565
417565
755992
269298
269298
755992
757331
269298
757331
757331
755992
720073
417565
284530
757331
149415
757331
269298
757331
755992
417565
269298
394409
257313
269298
269298
257313
269298
269298
757331
411616
269298
755992
757331
269298
269298
417565
755992
269298
745574
755992
720073...

result:

ok 300000 queries

Test #55:

score: 0
Accepted
time: 823ms
memory: 27932kb

input:

800000
407480143 131734528
652650345 16928867
612352630 116938859
359609733 75323895
646223710 57906840
511991534 152543911
644199740 64780746
570662214 141945763
386352125 115704752
349585185 37944390
507601730 152691542
573150238 141017833
416490931 136548124
597131713 128872230
347033667 10562730...

output:

574427
251373
251373
251373
574427
251373
626271
626271
251373
251373
626271
626271
626271
626271
251373
251373
626271
626271
251373
626271
251373
626271
251373
626271
574427
251373
574427
626271
251373
251373
251373
626271
626271
251373
574427
794779
574427
251373
626271
251373
251373
626271
251373...

result:

ok 300000 queries

Test #56:

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

input:

800000
452109830 152349175
421461659 151562477
679460231 145420349
905086145 86902172
911099447 82911948
659512748 147141905
811841360 124054540
50505656 41502399
941064599 54843818
45837596 30876979
56107313 50885233
82921988 78562940
51926471 44130724
714515573 141637218
654484334 147531551
735109...

output:

166787
56629
56629
56629
166787
412527
412527
56629
177905
638268
412527
412527
760697
635094
70503
70503
727049
727049
412527
412527
56629
56629
727049
166787
671302
520134
166787
543717
166787
638268
56629
70503
727049
591404
56629
727049
727049
166787
635094
177905
412527
727049
727049
177905
566...

result:

ok 300000 queries

Test #57:

score: 0
Accepted
time: 1217ms
memory: 28056kb

input:

800000
674001270 404386768
228695254 257093488
389105760 439754404
805760572 37898605
206735694 169104463
278383528 355075291
238806822 283935898
590873178 446404279
403785632 444803128
327998240 405933757
765596692 272894146
527142576 457420696
194319074 40442080
208239930 177472858
759287872 28844...

output:

620042
522687
620042
660170
522687
660170
780979
660170
413427
522687
620042
620042
660170
522687
620042
660170
660170
522687
620042
620042
620042
660170
620042
620042
522687
660170
660170
708326
522687
660170
620042
522687
660170
620042
660170
620042
660170
620042
522687
588867
522687
660170
660170...

result:

ok 300000 queries

Test #58:

score: 0
Accepted
time: 1302ms
memory: 28988kb

input:

800000
859533899 327603466
851289878 336683992
876400955 306639541
591665207 453328054
959458490 8337028
921461738 225310183
422223389 454818562
958886141 32083630
79088063 226664203
953797097 95653528
48485471 112129198
107408054 282698995
228135032 398545966
168306428 355789126
949788818 122848741...

output:

-1
-1
252703
421435
-1
43479
-1
-1
764735
484893
-1
759161
-1
528972
187535
-1
-1
129356
-1
665458
-1
-1
507615
211661
-1
347055
773603
-1
730580
-1
620842
798751
-1
-1
-1
725437
555622
529169
603444
400716
181591
-1
331363
126606
-1
-1
-1
117026
122209
639230
350593
592455
748180
-1
449204
228329
1...

result:

ok 300000 queries

Test #59:

score: 0
Accepted
time: 858ms
memory: 27468kb

input:

800000
562323617 144714102
519118500 152170180
420817041 138559378
637109217 82772283
625699939 101897203
364847052 86683695
467069436 150816840
616415019 112944366
364663264 86330245
374592794 102293891
456788435 149234789
438903897 145075132
580187050 138113766
347406498 17842146
598689659 1278551...

output:

447950
609320
56771
-1
717987
-1
-1
322324
480254
344055
751346
-1
186790
300138
-1
697638
247862
-1
-1
571678
668002
-1
-1
-1
-1
671974
-1
-1
-1
-1
-1
476865
798777
585395
-1
-1
5364
670737
466558
425238
-1
-1
659118
667872
149097
-1
771669
476021
-1
743716
-1
221823
525953
-1
-1
-1
-1
771712
58909...

result:

ok 300000 queries

Test #60:

score: 0
Accepted
time: 1312ms
memory: 28696kb

input:

800000
942756512 52543924
44606774 27253318
536381699 152557131
43053236 21652509
908162630 84923465
932345795 65063433
955505426 26892791
184184135 123045270
50861096 42198411
874591718 103020582
129816644 104926195
137604293 108095080
197493518 126366707
900724946 89610039
227731463 132772548
8126...

output:

4411
778200
114925
313092
15284
609256
-1
-1
701570
732976
358016
196510
327965
-1
31724
354096
27372
243713
-1
424359
-1
21114
-1
-1
-1
339017
-1
200730
40279
-1
-1
-1
529720
-1
-1
590561
263409
539337
-1
-1
174161
-1
432406
-1
-1
358489
370200
53961
-1
554460
197871
-1
690731
679796
-1
-1
87340
28...

result:

ok 300000 queries

Test #61:

score: 0
Accepted
time: 1091ms
memory: 27472kb

input:

800000
795839484 153301438
429074202 451427452
443716494 454140505
498466270 458418625
770201744 260350057
196131196 77723965
294429446 374847478
793911864 165371065
738981738 328811518
436369790 452872345
244166796 296308363
195403854 65605399
510419398 458286268
311913826 392521549
281041900 35866...

output:

332303
-1
601059
-1
384476
-1
-1
-1
48752
-1
-1
557152
664438
728745
323513
-1
-1
-1
-1
116698
441539
-1
-1
-1
675433
245144
570487
-1
-1
183207
-1
489627
184970
-1
570932
413552
-1
66735
720163
677460
418334
793998
-1
93544
-1
-1
-1
-1
-1
-1
-1
528222
-1
510427
797317
-1
-1
250410
443792
121963
693...

result:

ok 300000 queries

Extra Test:

score: 0
Extra Test Passed